Skip to content

Commit 923931a

Browse files
authored
Merge pull request #173 from arduino-libraries/dbg-ota-logic
Add verbose debug output for OTA logic
2 parents 1723c56 + 705f195 commit 923931a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Diff for: src/utility/ota/OTALogic.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#ifndef HOST
3232
#include <Arduino.h>
33+
#include <Arduino_DebugUtils.h>
3334
#else
3435
#include <algorithm> /* for std::min, otherwise Arduino defines min() */
3536
using namespace std;
@@ -123,6 +124,9 @@ void OTALogic::onOTADataReceived(uint8_t const * const data, size_t const length
123124

124125
OTAState OTALogic::handle_Init()
125126
{
127+
#ifndef HOST
128+
DBG_VERBOSE(__PRETTY_FUNCTION__);
129+
#endif
126130
if (_ota_storage->init()) {
127131
return OTAState::Idle;
128132
} else {
@@ -141,6 +145,9 @@ OTAState OTALogic::handle_Idle()
141145

142146
OTAState OTALogic::handle_StartDownload()
143147
{
148+
#ifndef HOST
149+
DBG_VERBOSE(__PRETTY_FUNCTION__);
150+
#endif
144151
if(_ota_storage->open()) {
145152
return OTAState::WaitForHeader;
146153
} else {
@@ -151,6 +158,9 @@ OTAState OTALogic::handle_StartDownload()
151158

152159
OTAState OTALogic::handle_WaitForHeader()
153160
{
161+
#ifndef HOST
162+
DBG_VERBOSE(__PRETTY_FUNCTION__);
163+
#endif
154164
if(_mqtt_ota_buf.num_bytes >= OTA_BINARY_HEADER_SIZE) {
155165
return OTAState::HeaderReceived;
156166
}
@@ -179,6 +189,11 @@ OTAState OTALogic::handle_HeaderReceived()
179189
_ota_bin_data.hdr_len = ota_header.header.len;
180190
_ota_bin_data.hdr_crc32 = ota_header.header.crc32;
181191

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+
182197
/* Reset the counter which is responsible for keeping tabs on how many bytes have been received */
183198
_ota_bin_data.bytes_received = 0;
184199

@@ -218,6 +233,10 @@ OTAState OTALogic::handle_BinaryReceived()
218233
_ota_bin_data.bytes_received += _mqtt_ota_buf.num_bytes;
219234
_mqtt_ota_buf.num_bytes = 0;
220235

236+
#ifndef HOST
237+
DBG_VERBOSE("%s: %d bytes written", __PRETTY_FUNCTION__, _ota_bin_data.bytes_received);
238+
#endif
239+
221240
if(_ota_bin_data.bytes_received >= _ota_bin_data.hdr_len) {
222241
_ota_storage->close();
223242
_ota_bin_data.crc32 = crc_finalize(_ota_bin_data.crc32);
@@ -229,6 +248,9 @@ OTAState OTALogic::handle_BinaryReceived()
229248

230249
OTAState OTALogic::handle_Verify()
231250
{
251+
#ifndef HOST
252+
DBG_VERBOSE(__PRETTY_FUNCTION__);
253+
#endif
232254
if(_ota_bin_data.crc32 == _ota_bin_data.hdr_crc32) {
233255
return OTAState::Rename;
234256
} else {
@@ -240,6 +262,9 @@ OTAState OTALogic::handle_Verify()
240262

241263
OTAState OTALogic::handle_Rename()
242264
{
265+
#ifndef HOST
266+
DBG_VERBOSE(__PRETTY_FUNCTION__);
267+
#endif
243268
if(_ota_storage->rename()) {
244269
_ota_storage->deinit();
245270
return OTAState::Reset;
@@ -260,6 +285,10 @@ OTAState OTALogic::handle_Reset()
260285
* update before starting the application, otherwise the app
261286
* is started directly.
262287
*/
288+
#ifndef HOST
289+
DBG_VERBOSE(__PRETTY_FUNCTION__);
290+
delay(250);
291+
#endif
263292
NVIC_SystemReset();
264293
#endif /* HOST */
265294
return OTAState::Reset;

0 commit comments

Comments
 (0)