Skip to content

Commit 7648544

Browse files
Ota default interface: making the download run at least a configurable amount of time
1 parent c4b0110 commit 7648544

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Diff for: src/ota/interface/OTAInterfaceDefault.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,24 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
9191
OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
9292
OTACloudProcessInterface::State res = Fetch;
9393
int http_res = 0;
94+
uint32_t start = millis();
9495

95-
if(http_client->available() == 0) {
96-
goto exit;
97-
}
96+
do {
97+
if(http_client->available() == 0) {
98+
goto exit;
99+
}
98100

99-
http_res = http_client->read(context->buffer, context->buf_len);
101+
http_res = http_client->read(context->buffer, context->buf_len);
100102

101-
if(http_res < 0) {
102-
DEBUG_VERBOSE("OTA ERROR: Download read error %d", http_res);
103-
res = OtaDownloadFail;
104-
goto exit;
105-
}
103+
if(http_res < 0) {
104+
DEBUG_VERBOSE("OTA ERROR: Download read error %d", http_res);
105+
res = OtaDownloadFail;
106+
goto exit;
107+
}
106108

107-
parseOta(context->buffer, http_res);
109+
parseOta(context->buffer, http_res);
110+
} while((context->downloadState == OtaDownloadFile || context->downloadState == OtaDownloadHeader) &&
111+
millis() - start < downloadTime);
108112

109113
// TODO verify that the information present in the ota header match the info in context
110114
if(context->downloadState == OtaDownloadCompleted) {

Diff for: src/ota/interface/OTAInterfaceDefault.h

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface {
4949

5050
const char *username, *password;
5151

52+
// The amount of time that each iteration of Fetch has to take at least
53+
// This mitigate the issues arising from tasks run in main loop that are using all the computing time
54+
static constexpr uint32_t downloadTime = 100;
55+
5256
enum OTADownloadState: uint8_t {
5357
OtaDownloadHeader,
5458
OtaDownloadFile,

0 commit comments

Comments
 (0)