Skip to content

Add verbose debug output for OTA logic #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/utility/ota/OTALogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

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

OTAState OTALogic::handle_Init()
{
#ifndef HOST
DBG_VERBOSE(__PRETTY_FUNCTION__);
#endif
if (_ota_storage->init()) {
return OTAState::Idle;
} else {
Expand All @@ -141,6 +145,9 @@ OTAState OTALogic::handle_Idle()

OTAState OTALogic::handle_StartDownload()
{
#ifndef HOST
DBG_VERBOSE(__PRETTY_FUNCTION__);
#endif
if(_ota_storage->open()) {
return OTAState::WaitForHeader;
} else {
Expand All @@ -151,6 +158,9 @@ OTAState OTALogic::handle_StartDownload()

OTAState OTALogic::handle_WaitForHeader()
{
#ifndef HOST
DBG_VERBOSE(__PRETTY_FUNCTION__);
#endif
if(_mqtt_ota_buf.num_bytes >= OTA_BINARY_HEADER_SIZE) {
return OTAState::HeaderReceived;
}
Expand Down Expand Up @@ -179,6 +189,11 @@ OTAState OTALogic::handle_HeaderReceived()
_ota_bin_data.hdr_len = ota_header.header.len;
_ota_bin_data.hdr_crc32 = ota_header.header.crc32;

#ifndef HOST
DBG_VERBOSE("%s: header length = %d", __PRETTY_FUNCTION__, _ota_bin_data.hdr_len);
DBG_VERBOSE("%s: header CRC32 = %d", __PRETTY_FUNCTION__, _ota_bin_data.hdr_crc32);
#endif

/* Reset the counter which is responsible for keeping tabs on how many bytes have been received */
_ota_bin_data.bytes_received = 0;

Expand Down Expand Up @@ -218,6 +233,10 @@ OTAState OTALogic::handle_BinaryReceived()
_ota_bin_data.bytes_received += _mqtt_ota_buf.num_bytes;
_mqtt_ota_buf.num_bytes = 0;

#ifndef HOST
DBG_VERBOSE("%s: %d bytes written", __PRETTY_FUNCTION__, _ota_bin_data.bytes_received);
#endif

if(_ota_bin_data.bytes_received >= _ota_bin_data.hdr_len) {
_ota_storage->close();
_ota_bin_data.crc32 = crc_finalize(_ota_bin_data.crc32);
Expand All @@ -229,6 +248,9 @@ OTAState OTALogic::handle_BinaryReceived()

OTAState OTALogic::handle_Verify()
{
#ifndef HOST
DBG_VERBOSE(__PRETTY_FUNCTION__);
#endif
if(_ota_bin_data.crc32 == _ota_bin_data.hdr_crc32) {
return OTAState::Rename;
} else {
Expand All @@ -240,6 +262,9 @@ OTAState OTALogic::handle_Verify()

OTAState OTALogic::handle_Rename()
{
#ifndef HOST
DBG_VERBOSE(__PRETTY_FUNCTION__);
#endif
if(_ota_storage->rename()) {
_ota_storage->deinit();
return OTAState::Reset;
Expand All @@ -260,6 +285,10 @@ OTAState OTALogic::handle_Reset()
* update before starting the application, otherwise the app
* is started directly.
*/
#ifndef HOST
DBG_VERBOSE(__PRETTY_FUNCTION__);
delay(250);
#endif
NVIC_SystemReset();
#endif /* HOST */
return OTAState::Reset;
Expand Down