Skip to content

Commit df570f1

Browse files
committed
Adjusted Classes BootloaderCom and FlashManager
1 parent 9748000 commit df570f1

8 files changed

+350
-86
lines changed

lib/ZumoOta/doc/Sequenz_diagramm

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@startuml
2+
autoactivate on
3+
participant "App" as App
4+
participant Board
5+
participant USBStream
6+
participant "FlashManager" as FM
7+
participant "BootloaderCom" as BC
8+
9+
10+
App -> Board: Process
11+
Board --> App
12+
Board -> USBStream: Process
13+
USBStream--> Board
14+
15+
alt if(Idle)
16+
App -> BC: Process
17+
BC -> FM: sendcommand()
18+
FM -> USBStream: write()
19+
USBStream --> FM: writtenbytes
20+
FM --> BC: true
21+
BC --> App
22+
end alt
23+
24+
alt if (waitingforResponse)
25+
App -> BC: Process
26+
27+
BC -> FM: readResponse()
28+
FM -> USBStream: read
29+
USBStream --> FM:
30+
BC -> FM : isComplete()
31+
FM --> BC: true
32+
BC-> BC: checkresponse()
33+
BC -> FM: set Idle
34+
BC --> App: true
35+
end alt
36+
37+
@enduml

lib/ZumoOta/src/App.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ void App::loop()
209209

210210
m_webServer.handleUploadRequest();
211211
m_isWebServerInitialized = true;
212-
m_webServer.handleUpdateRequest();
212+
Board::getInstance().process();
213+
m_bootloader.enterBootloader();
214+
m_bootloader.process();
213215
}
214216

215217

lib/ZumoOta/src/App.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include <Board.h>
4747
#include "FileManager.h"
4848
#include "WebServerCustom.h"
49-
#include "FlashManager.h"
49+
#include "BootloaderCom.h"
5050

5151
/******************************************************************************
5252
* Macros
@@ -119,9 +119,9 @@ class App
119119
Upload m_upload;
120120

121121
/**
122-
* Instance of the FlashManager class
122+
* Instance of the BootloaderCom class
123123
*/
124-
FlashManager m_flashManager;
124+
BootloaderCom m_bootloader;
125125
};
126126

127127
#endif /* APP_H */

lib/ZumoOta/src/BootloaderCom.cpp

+53-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ static const uint16_t PAGE_SIZE_BYTES = 128U;
6565
* Public Methods
6666
*****************************************************************************/
6767

68-
BootloaderCom::BootloaderCom()
68+
BootloaderCom::BootloaderCom():
69+
m_state(Idle),
70+
m_waitingForResponse(false)
6971
{
7072

7173
}
@@ -88,6 +90,56 @@ void BootloaderCom::exitBootloader()
8890
LOG_INFO(" bootloader mode is exited");
8991

9092
}
93+
94+
void BootloaderCom::process()
95+
{
96+
switch(m_state)
97+
{
98+
99+
case Idle:
100+
/*Handle Idle state*/
101+
m_waitingForResponse = false;
102+
myFlashManager.sendCommand(Zumo32U4Specification::READ_SW_ID, sizeof(Zumo32U4Specification::READ_SW_ID));
103+
break;
104+
105+
case Pending:
106+
/*Handle Pending state*/
107+
m_state = ReadingResponse;
108+
m_waitingForResponse = true;
109+
break;
110+
111+
case ReadingResponse:
112+
/*Handle Complete state*/
113+
uint8_t expectedSW[sizeof(&Zumo32U4Specification::EXPECTED_SOFTWARE_ID)];
114+
myFlashManager.readingStream(expectedSW);
115+
m_state = Complete;
116+
m_waitingForResponse = false;
117+
118+
if (compareExpectedAndReceivedResponse(Zumo32U4Specification::READ_SW_ID, sizeof(Zumo32U4Specification::READ_SW_ID),Zumo32U4Specification::EXPECTED_SOFTWARE_ID, sizeof(Zumo32U4Specification::EXPECTED_SOFTWARE_ID)))
119+
{
120+
LOG_INFO("Received expected response.");
121+
}
122+
else
123+
{
124+
LOG_ERROR("Received response does not match the expected response.");
125+
}
126+
break;
127+
128+
case Complete:
129+
m_state = Idle;
130+
break;
131+
132+
default:
133+
break;
134+
}
135+
}
136+
137+
bool BootloaderCom::compareExpectedAndReceivedResponse(const uint8_t command[], size_t commandSize, const uint8_t expectedResponse[], size_t expectedResponseSize)
138+
{
139+
140+
myFlashManager.Check( command, commandSize, expectedResponse, expectedResponseSize);
141+
return true;
142+
}
91143

92144

93145

lib/ZumoOta/src/BootloaderCom.h

+31-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
/******************************************************************************
4444
* Includes
4545
******************************************************************************/
46-
46+
#include "FlashManager.h"
4747
/******************************************************************************
4848
* Macros
4949
*****************************************************************************/
@@ -76,7 +76,37 @@ class BootloaderCom
7676
*/
7777
void exitBootloader();
7878

79+
/**
80+
* @brief Process the flash manager state machine.
81+
*/
82+
void process();
83+
84+
/**
85+
*@brief Compare the received response against the expected response after sending a command.
86+
*@param command The command to be sent.
87+
*@param commandSize The size of the command.
88+
*@param expectedResponse The expected response to compare against.
89+
*@param expectedResponseSize The size of the expected response.
90+
*@return True if the received response matches the expected response, false otherwise.
91+
*/
92+
bool compareExpectedAndReceivedResponse(const uint8_t command[], size_t commandSize, const uint8_t expectedResponse[], size_t expectedResponseSize);
93+
7994
private:
95+
enum State
96+
{
97+
Idle,
98+
Pending,
99+
ReadingResponse,
100+
Complete
101+
};
102+
State m_state;
103+
104+
FlashManager myFlashManager;
105+
106+
/*
107+
* Flag indicating whether the FlashManager is currently waiting for a response.
108+
*/
109+
bool m_waitingForResponse;
80110

81111
};
82112

0 commit comments

Comments
 (0)