Skip to content

Commit 59fff5f

Browse files
authored
Merge pull request #475 from pennam/ota-fwrite
OTA: handle fwrite error
2 parents d4ae0a3 + 45b1120 commit 59fff5f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/ota/interface/OTAInterfaceDefault.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
3535
context = new Context(
3636
OTACloudProcessInterface::context->url,
3737
[this](uint8_t c) {
38-
// int res =
39-
this->writeFlash(&c, 1);
40-
41-
// TODO report error in write flash, throw it?
38+
if (this->writeFlash(&c, 1) != 1) {
39+
this->context->writeError = true;
40+
}
4241
}
4342
);
4443

@@ -107,6 +106,12 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
107106
}
108107

109108
parseOta(context->buffer, http_res);
109+
110+
if(context->writeError) {
111+
DEBUG_VERBOSE("OTA ERROR: File write error");
112+
res = ErrorWriteUpdateFileFail;
113+
goto exit;
114+
}
110115
} while((context->downloadState == OtaDownloadFile || context->downloadState == OtaDownloadHeader) &&
111116
millis() - start < downloadTime);
112117

@@ -234,6 +239,7 @@ OTADefaultCloudProcessInterface::Context::Context(
234239
, headerCopiedBytes(0)
235240
, downloadedSize(0)
236241
, lastReportTime(0)
242+
, writeError(false)
237243
, decoder(putc) { }
238244

239245
static const uint32_t crc_table[256] = {

src/ota/interface/OTAInterfaceDefault.h

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface {
7474
uint32_t headerCopiedBytes;
7575
uint32_t downloadedSize;
7676
uint32_t lastReportTime;
77+
bool writeError;
7778

7879
// LZSS decoder
7980
LZSSDecoder decoder;

0 commit comments

Comments
 (0)