Skip to content

Commit 0291835

Browse files
committed
Reorder Arduino Nano RP2040 OTA error codes
1 parent 6a9acc2 commit 0291835

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

src/utility/ota/OTA-nano-rp2040.cpp

+40-17
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,42 @@
2121
* INCLUDE
2222
******************************************************************************/
2323

24-
#include "OTA.h"
25-
26-
#include "../watchdog/Watchdog.h"
27-
28-
#include <Arduino_DebugUtils.h>
29-
3024
#include <SFU.h>
3125

3226
#include "mbed.h"
3327
#include "FATFileSystem.h"
3428
#include "FlashIAPBlockDevice.h"
3529
#include "utility/ota/FlashSHA256.h"
3630

31+
#include "../watchdog/Watchdog.h"
32+
33+
#include <Arduino_DebugUtils.h>
34+
35+
/******************************************************************************
36+
* DEFINES
37+
******************************************************************************/
38+
39+
#define RP2040_OTA_ERROR_BASE (-100)
40+
41+
/******************************************************************************
42+
* TYPEDEF
43+
******************************************************************************/
44+
45+
enum class rp2040OTAError : int
46+
{
47+
None = 0,
48+
ErrorFlashInit = RP2040_OTA_ERROR_BASE - 3,
49+
ErrorParseHttpHeader = RP2040_OTA_ERROR_BASE - 8,
50+
UrlParseError = RP2040_OTA_ERROR_BASE - 9,
51+
ServerConnectError = RP2040_OTA_ERROR_BASE - 10,
52+
HttpHeaderError = RP2040_OTA_ERROR_BASE - 11,
53+
HttpDataError = RP2040_OTA_ERROR_BASE - 12,
54+
ErrorOpenUpdateFile = RP2040_OTA_ERROR_BASE - 19,
55+
ErrorWriteUpdateFile = RP2040_OTA_ERROR_BASE - 20,
56+
ErrorReformat = RP2040_OTA_ERROR_BASE - 21,
57+
ErrorUnmount = RP2040_OTA_ERROR_BASE - 22,
58+
};
59+
3760
/******************************************************************************
3861
* FUNCTION DEFINITION
3962
******************************************************************************/
@@ -92,7 +115,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
92115
if ((err = flash.init()) < 0)
93116
{
94117
DEBUG_ERROR("%s: flash.init() failed with %d", __FUNCTION__, err);
95-
return static_cast<int>(OTAError::RP2040_ErrorFlashInit);
118+
return static_cast<int>(rp2040OTAError::ErrorFlashInit);
96119
}
97120

98121
watchdog_reset();
@@ -105,7 +128,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
105128
if ((err = fs.reformat(&flash)) != 0)
106129
{
107130
DEBUG_ERROR("%s: fs.reformat() failed with %d", __FUNCTION__, err);
108-
return static_cast<int>(OTAError::RP2040_ErrorReformat);
131+
return static_cast<int>(rp2040OTAError::ErrorReformat);
109132
}
110133

111134
watchdog_reset();
@@ -115,7 +138,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
115138
{
116139
DEBUG_ERROR("%s: fopen() failed", __FUNCTION__);
117140
fclose(file);
118-
return static_cast<int>(OTAError::RP2040_ErrorOpenUpdateFile);
141+
return static_cast<int>(rp2040OTAError::ErrorOpenUpdateFile);
119142
}
120143

121144
watchdog_reset();
@@ -133,7 +156,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
133156
} else {
134157
DEBUG_ERROR("%s: Failed to parse OTA URL %s", __FUNCTION__, ota_url);
135158
fclose(file);
136-
return static_cast<int>(OTAError::RP2040_UrlParseError);
159+
return static_cast<int>(rp2040OTAError::UrlParseError);
137160
}
138161

139162
watchdog_reset();
@@ -142,7 +165,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
142165
{
143166
DEBUG_ERROR("%s: Connection failure with OTA storage server %s", __FUNCTION__, url.host_.c_str());
144167
fclose(file);
145-
return static_cast<int>(OTAError::RP2040_ServerConnectError);
168+
return static_cast<int>(rp2040OTAError::ServerConnectError);
146169
}
147170

148171
watchdog_reset();
@@ -179,7 +202,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
179202
{
180203
DEBUG_ERROR("%s: Error receiving HTTP header %s", __FUNCTION__, is_http_header_timeout ? "(timeout)":"");
181204
fclose(file);
182-
return static_cast<int>(OTAError::RP2040_HttpHeaderError);
205+
return static_cast<int>(rp2040OTAError::HttpHeaderError);
183206
}
184207

185208
/* Extract concent length from HTTP header. A typical entry looks like
@@ -190,7 +213,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
190213
{
191214
DEBUG_ERROR("%s: Failure to extract content length from http header", __FUNCTION__);
192215
fclose(file);
193-
return static_cast<int>(OTAError::RP2040_ErrorParseHttpHeader);
216+
return static_cast<int>(rp2040OTAError::ErrorParseHttpHeader);
194217
}
195218
/* Find start of numerical value. */
196219
char * ptr = const_cast<char *>(content_length_ptr);
@@ -219,7 +242,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
219242
{
220243
DEBUG_ERROR("%s: Writing of firmware image to flash failed", __FUNCTION__);
221244
fclose(file);
222-
return static_cast<int>(OTAError::RP2040_ErrorWriteUpdateFile);
245+
return static_cast<int>(rp2040OTAError::ErrorWriteUpdateFile);
223246
}
224247

225248
bytes_received++;
@@ -229,7 +252,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
229252
if (bytes_received != content_length_val) {
230253
DEBUG_ERROR("%s: Error receiving HTTP data %s (%d bytes received, %d expected)", __FUNCTION__, is_http_data_timeout ? "(timeout)":"", bytes_received, content_length_val);
231254
fclose(file);
232-
return static_cast<int>(OTAError::RP2040_HttpDataError);
255+
return static_cast<int>(rp2040OTAError::HttpDataError);
233256
}
234257

235258
DEBUG_INFO("%s: %d bytes received", __FUNCTION__, ftell(file));
@@ -239,15 +262,15 @@ int rp2040_connect_onOTARequest(char const * ota_url)
239262
if ((err = fs.unmount()) != 0)
240263
{
241264
DEBUG_ERROR("%s: fs.unmount() failed with %d", __FUNCTION__, err);
242-
return static_cast<int>(OTAError::RP2040_ErrorUnmount);
265+
return static_cast<int>(rp2040OTAError::ErrorUnmount);
243266
}
244267

245268
/* Perform the reset to reboot to SFU. */
246269
mbed_watchdog_trigger_reset();
247270
/* If watchdog is enabled we should not reach this point */
248271
NVIC_SystemReset();
249272

250-
return static_cast<int>(OTAError::None);
273+
return static_cast<int>(rp2040OTAError::None);
251274
}
252275

253276
String rp2040_connect_getOTAImageSHA256()

src/utility/ota/OTA.h

-16
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
#include <Arduino.h>
2929
#include <Arduino_ConnectionHandler.h>
3030

31-
/******************************************************************************
32-
* DEFINES
33-
******************************************************************************/
34-
35-
#define RP2040_OTA_ERROR_BASE (-100)
36-
3731
/******************************************************************************
3832
* TYPEDEF
3933
******************************************************************************/
@@ -42,16 +36,6 @@ enum class OTAError : int
4236
{
4337
None = 0,
4438
DownloadFailed = 1,
45-
RP2040_UrlParseError = RP2040_OTA_ERROR_BASE - 0,
46-
RP2040_ServerConnectError = RP2040_OTA_ERROR_BASE - 1,
47-
RP2040_HttpHeaderError = RP2040_OTA_ERROR_BASE - 2,
48-
RP2040_HttpDataError = RP2040_OTA_ERROR_BASE - 3,
49-
RP2040_ErrorOpenUpdateFile = RP2040_OTA_ERROR_BASE - 4,
50-
RP2040_ErrorWriteUpdateFile = RP2040_OTA_ERROR_BASE - 5,
51-
RP2040_ErrorParseHttpHeader = RP2040_OTA_ERROR_BASE - 6,
52-
RP2040_ErrorFlashInit = RP2040_OTA_ERROR_BASE - 7,
53-
RP2040_ErrorReformat = RP2040_OTA_ERROR_BASE - 8,
54-
RP2040_ErrorUnmount = RP2040_OTA_ERROR_BASE - 9,
5539
};
5640

5741
/******************************************************************************

0 commit comments

Comments
 (0)