3333# include < WiFiNINA.h> /* WiFiStorage */
3434#endif
3535
36+ /* *****************************************************************************
37+ * DEFINES
38+ ******************************************************************************/
39+
40+ #define SAMD_OTA_ERROR_BASE (-200 )
41+
42+ /* *****************************************************************************
43+ * TYPEDEF
44+ ******************************************************************************/
45+
46+ enum class samdOTAError : int
47+ {
48+ None = 0 ,
49+ OtaHeaderCrc = SAMD_OTA_ERROR_BASE - 6 ,
50+ OtaDownload = SAMD_OTA_ERROR_BASE - 12 ,
51+ OpenUpdateFile = SAMD_OTA_ERROR_BASE - 19 ,
52+ Rename = SAMD_OTA_ERROR_BASE - 23 ,
53+ };
54+
55+ enum class ninaOTAError : int
56+ {
57+ None = 0 ,
58+ Open = 1 ,
59+ Length = 2 ,
60+ CRC = 3 ,
61+ Rename = 4 ,
62+ };
63+
3664/* *****************************************************************************
3765 * FUNCTION DEFINITION
3866 ******************************************************************************/
3967
68+ samdOTAError samd_getOTAError (ninaOTAError nina_ota_error_code)
69+ {
70+ switch (nina_ota_error_code)
71+ {
72+ case ninaOTAError::None: return samdOTAError::None;
73+ case ninaOTAError::Open: return samdOTAError::OpenUpdateFile;
74+ case ninaOTAError::Length: return samdOTAError::OtaDownload;
75+ case ninaOTAError::CRC: return samdOTAError::OtaHeaderCrc;
76+ case ninaOTAError::Rename: return samdOTAError::Rename;
77+ default : return samdOTAError::OtaDownload;
78+ }
79+ }
80+
4081int samd_onOTARequest (char const * ota_url)
4182{
4283 watchdog_reset ();
@@ -53,7 +94,8 @@ int samd_onOTARequest(char const * ota_url)
5394 if (!WiFiStorage.downloadOTA (ota_url, &nina_ota_err_code))
5495 {
5596 DEBUG_ERROR (" ArduinoIoTCloudTCP::%s error download to nina: %d" , __FUNCTION__, nina_ota_err_code);
56- return (NINAFW_OTA_ERROR_BASE - nina_ota_err_code);
97+ samdOTAError samd_ota_err_code = samd_getOTAError (static_cast <ninaOTAError>(nina_ota_err_code));
98+ return static_cast <int >(samd_ota_err_code);
5799 }
58100
59101 /* Perform the reset to reboot to SxU. */
0 commit comments