Skip to content

Commit

Permalink
OTA: handle fwrite error
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Jun 4, 2024
1 parent dd4c09d commit 45b1120
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ota/interface/OTAInterfaceDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
context = new Context(
OTACloudProcessInterface::context->url,
[this](uint8_t c) {
// int res =
this->writeFlash(&c, 1);

// TODO report error in write flash, throw it?
if (this->writeFlash(&c, 1) != 1) {
this->context->writeError = true;
}
}
);

Expand Down Expand Up @@ -107,6 +106,12 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
}

parseOta(context->buffer, http_res);

if(context->writeError) {
DEBUG_VERBOSE("OTA ERROR: File write error");
res = ErrorWriteUpdateFileFail;
goto exit;
}
} while((context->downloadState == OtaDownloadFile || context->downloadState == OtaDownloadHeader) &&
millis() - start < downloadTime);

Expand Down Expand Up @@ -234,6 +239,7 @@ OTADefaultCloudProcessInterface::Context::Context(
, headerCopiedBytes(0)
, downloadedSize(0)
, lastReportTime(0)
, writeError(false)
, decoder(putc) { }

static const uint32_t crc_table[256] = {
Expand Down
1 change: 1 addition & 0 deletions src/ota/interface/OTAInterfaceDefault.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface {
uint32_t headerCopiedBytes;
uint32_t downloadedSize;
uint32_t lastReportTime;
bool writeError;

// LZSS decoder
LZSSDecoder decoder;
Expand Down

0 comments on commit 45b1120

Please sign in to comment.