Skip to content

Commit 51e6568

Browse files
committed
OTA: add context contentLength
1 parent cc0d350 commit 51e6568

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/ota/interface/OTAInterfaceDefault.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
7676
return HttpResponseFail;
7777
}
7878

79+
context->contentLength = http_client->contentLength();
80+
7981
// The following call is required to save the header value , keep it
80-
if(http_client->contentLength() == HttpClient::kNoContentLengthHeader) {
82+
if(context->contentLength == HttpClient::kNoContentLengthHeader) {
8183
DEBUG_VERBOSE("OTA ERROR: the response header doesn't contain \"ContentLength\" field");
8284
return HttpHeaderErrorFail;
8385
}
@@ -184,7 +186,6 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t bufLen) {
184186
break;
185187
}
186188
case OtaDownloadFile: {
187-
const uint32_t contentLength = http_client->contentLength();
188189
const uint32_t dataLeft = bufLen - (cursor-buffer);
189190
context->decoder.decompress(cursor, dataLeft); // TODO verify return value
190191

@@ -198,18 +199,18 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t bufLen) {
198199
context->downloadedSize += dataLeft;
199200

200201
if((millis() - context->lastReportTime) > 10000) { // Report the download progress each X millisecond
201-
DEBUG_VERBOSE("OTA Download Progress %d/%d", context->downloadedSize, contentLength);
202+
DEBUG_VERBOSE("OTA Download Progress %d/%d", context->downloadedSize, context->contentLength);
202203

203204
reportStatus(context->downloadedSize);
204205
context->lastReportTime = millis();
205206
}
206207

207208
// TODO there should be no more bytes available when the download is completed
208-
if(context->downloadedSize == contentLength) {
209+
if(context->downloadedSize == context->contentLength) {
209210
context->downloadState = OtaDownloadCompleted;
210211
}
211212

212-
if(context->downloadedSize > contentLength) {
213+
if(context->downloadedSize > context->contentLength) {
213214
context->downloadState = OtaDownloadError;
214215
}
215216
// TODO fail if we exceed a timeout? and available is 0 (client is broken)
@@ -250,6 +251,7 @@ OTADefaultCloudProcessInterface::Context::Context(
250251
, headerCopiedBytes(0)
251252
, downloadedSize(0)
252253
, lastReportTime(0)
254+
, contentLength(0)
253255
, writeError(false)
254256
, decoder(putc) { }
255257

src/ota/interface/OTAInterfaceDefault.h

Lines changed: 1 addition & 0 deletions
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+
uint32_t contentLength;
7778
bool writeError;
7879

7980
// LZSS decoder

0 commit comments

Comments
 (0)