Skip to content

Commit

Permalink
Merge pull request #514 from pennam/ota-fix
Browse files Browse the repository at this point in the history
Fix ota download byte count
  • Loading branch information
pennam authored Nov 20, 2024
2 parents b7f9b33 + 9412661 commit 3333846
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/ota/interface/OTAInterfaceDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t buf_len)
for(uint8_t* cursor=(uint8_t*)buffer; cursor<buffer+buf_len; ) {
switch(context->downloadState) {
case OtaDownloadHeader: {
uint32_t copied = buf_len < sizeof(context->header.buf) ? buf_len : sizeof(context->header.buf);
memcpy(context->header.buf+context->headerCopiedBytes, buffer, copied);
cursor += copied;
context->headerCopiedBytes += copied;
const uint32_t headerLeft = context->headerCopiedBytes + buf_len <= sizeof(context->header.buf) ? buf_len : sizeof(context->header.buf) - context->headerCopiedBytes;
memcpy(context->header.buf+context->headerCopiedBytes, buffer, headerLeft);
cursor += headerLeft;
context->headerCopiedBytes += headerLeft;

// when finished go to next state
if(sizeof(context->header.buf) == context->headerCopiedBytes) {
Expand All @@ -178,22 +178,24 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t buf_len)
context->downloadState = OtaDownloadMagicNumberMismatch;
return;
}
context->downloadedSize += sizeof(context->header.buf);
}

break;
}
case OtaDownloadFile: {
uint32_t contentLength = http_client->contentLength();
context->decoder.decompress(cursor, buf_len - (cursor-buffer)); // TODO verify return value
const uint32_t contentLength = http_client->contentLength();
const uint32_t dataLeft = buf_len - (cursor-buffer);
context->decoder.decompress(cursor, dataLeft); // TODO verify return value

context->calculatedCrc32 = crc_update(
context->calculatedCrc32,
cursor,
buf_len - (cursor-buffer)
dataLeft
);

cursor += buf_len - (cursor-buffer);
context->downloadedSize += (cursor-buffer);
cursor += dataLeft;
context->downloadedSize += dataLeft;

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

0 comments on commit 3333846

Please sign in to comment.