@@ -66,6 +66,8 @@ OTACloudProcessInterface::OTACloudProcessInterface(MessageStream *ms)
66
66
, policies(None)
67
67
, state(Resume)
68
68
, previous_state(Resume)
69
+ , report_last_timestamp(0 )
70
+ , report_counter(0 )
69
71
, context(nullptr ) {
70
72
}
71
73
@@ -76,35 +78,34 @@ OTACloudProcessInterface::~OTACloudProcessInterface() {
76
78
void OTACloudProcessInterface::handleMessage (Message* msg) {
77
79
78
80
if ((state >= OtaAvailable || state < 0 ) && previous_state != state) {
79
- reportStatus ();
81
+ reportStatus (static_cast < int32_t >(state< 0 ? state : 0 ) );
80
82
}
81
83
82
84
// this allows to do status report only when the state changes
83
85
previous_state = state;
84
86
85
87
switch (state) {
86
- case Resume: updateState (resume (msg)); break ;
87
- case OtaBegin: updateState (otaBegin ()); break ;
88
- case Idle: updateState (idle (msg)); break ;
89
- case OtaAvailable: updateState (otaAvailable ()); break ;
90
- case StartOTA: updateState (startOTA ()); break ;
91
- case Fetch: updateState (fetch ()); break ;
92
- case FlashOTA: updateState (flashOTA ()); break ;
93
- case Reboot: updateState (reboot ()); break ;
94
- default : updateState (fail ()); // all the states that are not defined are failures
88
+ case Resume: updateState (resume (msg)); break ;
89
+ case OtaBegin: updateState (otaBegin ()); break ;
90
+ case Idle: updateState (idle (msg)); break ;
91
+ case OtaAvailable: updateState (otaAvailable ()); break ;
92
+ case StartOTA: updateState (startOTA ()); break ;
93
+ case Fetch: updateState (fetch ()); break ;
94
+ case FlashOTA: updateState (flashOTA ()); break ;
95
+ case Reboot: updateState (reboot ()); break ;
96
+ case OTAUnavailable: break ;
97
+ default : updateState (fail ()); // all the states that are not defined are failures
95
98
}
96
99
}
97
100
98
101
OTACloudProcessInterface::State OTACloudProcessInterface::otaBegin () {
99
102
if (!isOtaCapable ()) {
100
- // FIXME What do we have to do in this case?
101
- DEBUG_WARNING (" OTA is not available on this board" );
102
- return OtaBegin;
103
+ DEBUG_VERBOSE (" OTA is not available on this board" );
104
+ return OTAUnavailable;
103
105
}
104
106
105
107
struct OtaBeginUp msg = {
106
108
OtaBeginUpId,
107
- {}
108
109
};
109
110
110
111
SHA256 sha256_calc;
@@ -113,12 +114,16 @@ OTACloudProcessInterface::State OTACloudProcessInterface::otaBegin() {
113
114
sha256_calc.finalize (sha256);
114
115
memcpy (msg.params .sha , sha256, SHA256::HASH_SIZE);
115
116
116
- DEBUG_VERBOSE (" calculated SHA256: 0x%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X" ,
117
- this ->sha256 [0 ], this ->sha256 [1 ], this ->sha256 [2 ], this ->sha256 [3 ], this ->sha256 [4 ], this ->sha256 [5 ], this ->sha256 [6 ], this ->sha256 [7 ], this ->sha256 [8 ], this ->sha256 [9 ], this ->sha256 [10 ], this ->sha256 [11 ], this ->sha256 [12 ], this ->sha256 [13 ], this ->sha256 [14 ], this ->sha256 [15 ], this ->sha256 [16 ], this ->sha256 [17 ], this ->sha256 [18 ], this ->sha256 [19 ], this ->sha256 [20 ], this ->sha256 [21 ], this ->sha256 [22 ], this ->sha256 [23 ], this ->sha256 [24 ], this ->sha256 [25 ], this ->sha256 [26 ], this ->sha256 [27 ], this ->sha256 [28 ], this ->sha256 [29 ], this ->sha256 [30 ], this ->sha256 [31 ]
117
+ DEBUG_VERBOSE (" calculated SHA256: "
118
+ " 0x%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
119
+ " %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X" ,
120
+ sha256[0 ], sha256[1 ], sha256[2 ], sha256[3 ], sha256[4 ], sha256[5 ], sha256[6 ], sha256[7 ],
121
+ sha256[8 ], sha256[9 ], sha256[10 ], sha256[11 ], sha256[12 ], sha256[13 ], sha256[14 ], sha256[15 ],
122
+ sha256[16 ], sha256[17 ], sha256[18 ], sha256[19 ], sha256[20 ], sha256[21 ], sha256[22 ], sha256[23 ],
123
+ sha256[24 ], sha256[25 ], sha256[26 ], sha256[27 ], sha256[28 ], sha256[29 ], sha256[30 ], sha256[31 ]
118
124
);
119
125
120
126
deliver ((Message*)&msg);
121
- // TODO msg object do not exist after this call make sure it gets copied somewhere
122
127
123
128
return Idle;
124
129
}
@@ -148,8 +153,8 @@ OTACloudProcessInterface::State OTACloudProcessInterface::idle(Message* msg) {
148
153
struct OtaUpdateCmdDown * ota_msg = (struct OtaUpdateCmdDown *)msg;
149
154
150
155
context = new OtaContext (
151
- ota_msg->params .id , ota_msg->params .url ,
152
- ota_msg->params .initialSha256 , ota_msg->params .finalSha256
156
+ ota_msg->params .id , ota_msg->params .url ,
157
+ ota_msg->params .initialSha256 , ota_msg->params .finalSha256
153
158
);
154
159
155
160
// TODO verify that initialSha256 is the sha256 on board
@@ -186,35 +191,31 @@ void OTACloudProcessInterface::clean() {
186
191
}
187
192
}
188
193
189
- void OTACloudProcessInterface::reportStatus () {
194
+ void OTACloudProcessInterface::reportStatus (int32_t state_data ) {
190
195
if (context == nullptr ) {
191
196
// FIXME handle this case: ota not in progress
192
197
return ;
193
198
}
194
- static uint32_t last_timestamp = getTime ();
195
- static uint32_t counter = 0 ;
196
199
uint32_t new_timestamp = getTime ();
197
200
198
201
struct OtaProgressCmdUp msg = {
199
202
OtaProgressCmdUpId,
200
- {}
201
203
};
202
204
203
205
memcpy (msg.params .id , context->id , ID_SIZE);
204
- msg.params .state = state>=0 ? state : State::Fail;
206
+ msg.params .state = state>=0 ? state : State::Fail;
205
207
206
- if (new_timestamp == last_timestamp ) {
207
- msg.params .time = new_timestamp*1e6 + ++counter ;
208
+ if (new_timestamp == report_last_timestamp ) {
209
+ msg.params .time = new_timestamp*1e6 + ++report_counter ;
208
210
} else {
209
211
msg.params .time = new_timestamp*1e6 ;
210
- counter = 0 ;
211
- last_timestamp = new_timestamp;
212
+ report_counter = 0 ;
213
+ report_last_timestamp = new_timestamp;
212
214
}
213
215
214
- msg.params .state_data = static_cast < int32_t >(state< 0 ? state : 0 ) ;
216
+ msg.params .state_data = state_data ;
215
217
216
218
deliver ((Message*)&msg);
217
- // TODO msg object do not exist after this call make sure it gets copied somewhere
218
219
}
219
220
220
221
OTACloudProcessInterface::OtaContext::OtaContext (
0 commit comments