30
30
31
31
#ifndef HOST
32
32
#include < Arduino.h>
33
+ #include < Arduino_DebugUtils.h>
33
34
#else
34
35
#include < algorithm> /* for std::min, otherwise Arduino defines min() */
35
36
using namespace std ;
@@ -123,6 +124,9 @@ void OTALogic::onOTADataReceived(uint8_t const * const data, size_t const length
123
124
124
125
OTAState OTALogic::handle_Init ()
125
126
{
127
+ #ifndef HOST
128
+ DBG_VERBOSE (__PRETTY_FUNCTION__);
129
+ #endif
126
130
if (_ota_storage->init ()) {
127
131
return OTAState::Idle;
128
132
} else {
@@ -141,6 +145,9 @@ OTAState OTALogic::handle_Idle()
141
145
142
146
OTAState OTALogic::handle_StartDownload ()
143
147
{
148
+ #ifndef HOST
149
+ DBG_VERBOSE (__PRETTY_FUNCTION__);
150
+ #endif
144
151
if (_ota_storage->open ()) {
145
152
return OTAState::WaitForHeader;
146
153
} else {
@@ -151,6 +158,9 @@ OTAState OTALogic::handle_StartDownload()
151
158
152
159
OTAState OTALogic::handle_WaitForHeader ()
153
160
{
161
+ #ifndef HOST
162
+ DBG_VERBOSE (__PRETTY_FUNCTION__);
163
+ #endif
154
164
if (_mqtt_ota_buf.num_bytes >= OTA_BINARY_HEADER_SIZE) {
155
165
return OTAState::HeaderReceived;
156
166
}
@@ -179,6 +189,11 @@ OTAState OTALogic::handle_HeaderReceived()
179
189
_ota_bin_data.hdr_len = ota_header.header .len ;
180
190
_ota_bin_data.hdr_crc32 = ota_header.header .crc32 ;
181
191
192
+ #ifndef HOST
193
+ DBG_VERBOSE (" %s: header length = %d" , __PRETTY_FUNCTION__, _ota_bin_data.hdr_len );
194
+ DBG_VERBOSE (" %s: header CRC32 = %d" , __PRETTY_FUNCTION__, _ota_bin_data.hdr_crc32 );
195
+ #endif
196
+
182
197
/* Reset the counter which is responsible for keeping tabs on how many bytes have been received */
183
198
_ota_bin_data.bytes_received = 0 ;
184
199
@@ -218,6 +233,10 @@ OTAState OTALogic::handle_BinaryReceived()
218
233
_ota_bin_data.bytes_received += _mqtt_ota_buf.num_bytes ;
219
234
_mqtt_ota_buf.num_bytes = 0 ;
220
235
236
+ #ifndef HOST
237
+ DBG_VERBOSE (" %s: %d bytes written" , __PRETTY_FUNCTION__, _ota_bin_data.bytes_received );
238
+ #endif
239
+
221
240
if (_ota_bin_data.bytes_received >= _ota_bin_data.hdr_len ) {
222
241
_ota_storage->close ();
223
242
_ota_bin_data.crc32 = crc_finalize (_ota_bin_data.crc32 );
@@ -229,6 +248,9 @@ OTAState OTALogic::handle_BinaryReceived()
229
248
230
249
OTAState OTALogic::handle_Verify ()
231
250
{
251
+ #ifndef HOST
252
+ DBG_VERBOSE (__PRETTY_FUNCTION__);
253
+ #endif
232
254
if (_ota_bin_data.crc32 == _ota_bin_data.hdr_crc32 ) {
233
255
return OTAState::Rename;
234
256
} else {
@@ -240,6 +262,9 @@ OTAState OTALogic::handle_Verify()
240
262
241
263
OTAState OTALogic::handle_Rename ()
242
264
{
265
+ #ifndef HOST
266
+ DBG_VERBOSE (__PRETTY_FUNCTION__);
267
+ #endif
243
268
if (_ota_storage->rename ()) {
244
269
_ota_storage->deinit ();
245
270
return OTAState::Reset;
@@ -260,6 +285,10 @@ OTAState OTALogic::handle_Reset()
260
285
* update before starting the application, otherwise the app
261
286
* is started directly.
262
287
*/
288
+ #ifndef HOST
289
+ DBG_VERBOSE (__PRETTY_FUNCTION__);
290
+ delay (250 );
291
+ #endif
263
292
NVIC_SystemReset ();
264
293
#endif /* HOST */
265
294
return OTAState::Reset;
0 commit comments