Skip to content
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

Make NINA FW OTA error available as OTA_ERROR property #312

Closed
wants to merge 2 commits into from
Closed
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
44 changes: 43 additions & 1 deletion src/utility/ota/OTA-samd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,51 @@
# include <WiFiNINA.h> /* 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();
Expand All @@ -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 static_cast<int>(OTAError::DownloadFailed);
samdOTAError samd_ota_err_code = samd_getOTAError(static_cast<ninaOTAError>(nina_ota_err_code));
return static_cast<int>(samd_ota_err_code);
}

/* Perform the reset to reboot to SxU. */
Expand Down
Loading