From 9bb4dcc417ed759804025361fee85b0deff1afbf Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 11 Mar 2022 08:52:00 +0100 Subject: [PATCH 1/2] Make NINA FW OTA error available as OTA_ERROR property --- src/utility/ota/OTA-samd.cpp | 2 +- src/utility/ota/OTA.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utility/ota/OTA-samd.cpp b/src/utility/ota/OTA-samd.cpp index 4ef214f32..633759f17 100644 --- a/src/utility/ota/OTA-samd.cpp +++ b/src/utility/ota/OTA-samd.cpp @@ -53,7 +53,7 @@ int samd_onOTARequest(char const * ota_url) if (!WiFiStorage.downloadOTA(ota_url, &nina_ota_err_code)) { DEBUG_ERROR("ArduinoIoTCloudTCP::%s error download to nina: %d", __FUNCTION__, nina_ota_err_code); - return static_cast(OTAError::DownloadFailed); + return (NINAFW_OTA_ERROR_BASE - nina_ota_err_code); } /* Perform the reset to reboot to SxU. */ diff --git a/src/utility/ota/OTA.h b/src/utility/ota/OTA.h index 88c7229b9..8bcddc3e7 100644 --- a/src/utility/ota/OTA.h +++ b/src/utility/ota/OTA.h @@ -33,6 +33,7 @@ ******************************************************************************/ #define RP2040_OTA_ERROR_BASE (-100) +#define NINAFW_OTA_ERROR_BASE (-200) /****************************************************************************** * TYPEDEF From 2443207771c7a893a2e69a260cb36a20cea234f7 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 24 Oct 2023 10:01:16 +0200 Subject: [PATCH 2/2] Reorder SAMD OTA error codes --- src/utility/ota/OTA-samd.cpp | 44 +++++++++++++++++++++++++++++++++++- src/utility/ota/OTA.h | 1 - 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/utility/ota/OTA-samd.cpp b/src/utility/ota/OTA-samd.cpp index 633759f17..8d9e78217 100644 --- a/src/utility/ota/OTA-samd.cpp +++ b/src/utility/ota/OTA-samd.cpp @@ -33,10 +33,51 @@ # include /* WiFiStorage */ #endif +/****************************************************************************** + * DEFINES + ******************************************************************************/ + +#define SAMD_OTA_ERROR_BASE (-200) + +/****************************************************************************** + * TYPEDEF + ******************************************************************************/ + +enum class samdOTAError : int +{ + None = 0, + OtaHeaderCrc = SAMD_OTA_ERROR_BASE - 6, + OtaDownload = SAMD_OTA_ERROR_BASE - 12, + OpenUpdateFile = SAMD_OTA_ERROR_BASE - 19, + Rename = SAMD_OTA_ERROR_BASE - 23, +}; + +enum class ninaOTAError : int +{ + None = 0, + Open = 1, + Length = 2, + CRC = 3, + Rename = 4, +}; + /****************************************************************************** * FUNCTION DEFINITION ******************************************************************************/ +samdOTAError samd_getOTAError(ninaOTAError nina_ota_error_code) +{ + switch(nina_ota_error_code) + { + case ninaOTAError::None: return samdOTAError::None; + case ninaOTAError::Open: return samdOTAError::OpenUpdateFile; + case ninaOTAError::Length: return samdOTAError::OtaDownload; + case ninaOTAError::CRC: return samdOTAError::OtaHeaderCrc; + case ninaOTAError::Rename: return samdOTAError::Rename; + default: return samdOTAError::OtaDownload; + } +} + int samd_onOTARequest(char const * ota_url) { watchdog_reset(); @@ -53,7 +94,8 @@ int samd_onOTARequest(char const * ota_url) if (!WiFiStorage.downloadOTA(ota_url, &nina_ota_err_code)) { DEBUG_ERROR("ArduinoIoTCloudTCP::%s error download to nina: %d", __FUNCTION__, nina_ota_err_code); - return (NINAFW_OTA_ERROR_BASE - nina_ota_err_code); + samdOTAError samd_ota_err_code = samd_getOTAError(static_cast(nina_ota_err_code)); + return static_cast(samd_ota_err_code); } /* Perform the reset to reboot to SxU. */ diff --git a/src/utility/ota/OTA.h b/src/utility/ota/OTA.h index 8bcddc3e7..88c7229b9 100644 --- a/src/utility/ota/OTA.h +++ b/src/utility/ota/OTA.h @@ -33,7 +33,6 @@ ******************************************************************************/ #define RP2040_OTA_ERROR_BASE (-100) -#define NINAFW_OTA_ERROR_BASE (-200) /****************************************************************************** * TYPEDEF