Skip to content

Commit 0200920

Browse files
authored
Merge pull request #67 from pennam/ota-format-flag
OTA: add format on failure flag
2 parents 403d874 + 951db3d commit 0200920

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

UNOR4USBBridge/OTA.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ Arduino_UNOWIFIR4_OTA::~Arduino_UNOWIFIR4_OTA() {
4141
closeStorage();
4242
}
4343

44-
Arduino_ESP32_OTA::Error Arduino_UNOWIFIR4_OTA::begin(const char* file_path, uint32_t magic)
44+
Arduino_ESP32_OTA::Error Arduino_UNOWIFIR4_OTA::begin(const char* file_path, uint32_t magic, bool formatOnFail)
4545
{
4646
/* ... configure board Magic number */
4747
setMagic(magic);
4848

49-
if(!SPIFFS.begin()) {
49+
if(!SPIFFS.begin(formatOnFail)) {
5050
DEBUG_ERROR("%s: failed to initialize SPIFFS", __FUNCTION__);
5151
return Error::OtaStorageInit;
5252
}

UNOR4USBBridge/OTA.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Arduino_UNOWIFIR4_OTA : public Arduino_ESP32_OTA
4646
};
4747

4848
using Arduino_ESP32_OTA::begin;
49-
Arduino_ESP32_OTA::Error begin(const char* file_path, uint32_t magic = ARDUINO_RA4M1_OTA_MAGIC);
49+
Arduino_ESP32_OTA::Error begin(const char* file_path, uint32_t magic = ARDUINO_RA4M1_OTA_MAGIC, bool formatOnfail = false);
5050

5151
using Arduino_ESP32_OTA::download;
5252
int download(const char * ota_url, const char* file_path);

UNOR4USBBridge/cmds_ota.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void CAtHandler::add_cmds_ota() {
5757
return chAT::CommandStatus::OK;
5858
}
5959
case chAT::CommandMode::Write: {
60-
if (parser.args.size() != 1) {
60+
if (parser.args.size() != 1 && parser.args.size() != 2) {
6161
return chAT::CommandStatus::ERROR;
6262
}
6363

@@ -66,7 +66,16 @@ void CAtHandler::add_cmds_ota() {
6666
return chAT::CommandStatus::ERROR;
6767
}
6868

69-
Arduino_ESP32_OTA::Error ota_error = OTA.begin(path.c_str());
69+
bool formatOnFail = false;
70+
if (parser.args.size() == 2) {
71+
auto &format = parser.args[1];
72+
if (format.empty()) {
73+
return chAT::CommandStatus::ERROR;
74+
}
75+
formatOnFail = strtol(format.c_str(), NULL, 10) != 0;
76+
}
77+
78+
Arduino_ESP32_OTA::Error ota_error = OTA.begin(path.c_str(), ARDUINO_RA4M1_OTA_MAGIC, formatOnFail);
7079
String error = String((int)ota_error) + _ENDL;
7180
srv.write_response_prompt();
7281
srv.write_str((const char *)(error.c_str()));

0 commit comments

Comments
 (0)