Skip to content

Commit

Permalink
Ota default interface: making the download run at least a configurabl…
Browse files Browse the repository at this point in the history
…e amount of time
  • Loading branch information
andreagilardoni authored and pennam committed May 17, 2024
1 parent a33cd85 commit 613eae2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/ota/interface/OTAInterfaceDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,24 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
OTACloudProcessInterface::State res = Fetch;
int http_res = 0;
uint32_t start = millis();

if(http_client->available() == 0) {
goto exit;
}
do {
if(http_client->available() == 0) {
goto exit;
}

http_res = http_client->read(context->buffer, context->buf_len);
http_res = http_client->read(context->buffer, context->buf_len);

if(http_res < 0) {
DEBUG_VERBOSE("OTA ERROR: Download read error %d", http_res);
res = OtaDownloadFail;
goto exit;
}
if(http_res < 0) {
DEBUG_VERBOSE("OTA ERROR: Download read error %d", http_res);
res = OtaDownloadFail;
goto exit;
}

parseOta(context->buffer, http_res);
parseOta(context->buffer, http_res);
} while((context->downloadState == OtaDownloadFile || context->downloadState == OtaDownloadHeader) &&
millis() - start < downloadTime);

// TODO verify that the information present in the ota header match the info in context
if(context->downloadState == OtaDownloadCompleted) {
Expand Down
4 changes: 4 additions & 0 deletions src/ota/interface/OTAInterfaceDefault.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface {

const char *username, *password;

// The amount of time that each iteration of Fetch has to take at least
// This mitigate the issues arising from tasks run in main loop that are using all the computing time
static constexpr uint32_t downloadTime = 100;

enum OTADownloadState: uint8_t {
OtaDownloadHeader,
OtaDownloadFile,
Expand Down

0 comments on commit 613eae2

Please sign in to comment.