@@ -182,7 +182,8 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t buf_len)
182
182
183
183
break ;
184
184
}
185
- case OtaDownloadFile:
185
+ case OtaDownloadFile: {
186
+ uint32_t contentLength = http_client->contentLength ();
186
187
context->decoder .decompress (cursor, buf_len - (cursor-buffer)); // TODO verify return value
187
188
188
189
context->calculatedCrc32 = crc_update (
@@ -195,22 +196,23 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t buf_len)
195
196
context->downloadedSize += (cursor-buffer);
196
197
197
198
if ((millis () - context->lastReportTime ) > 10000 ) { // Report the download progress each X millisecond
198
- DEBUG_VERBOSE (" OTA Download Progress %d/%d" , context->downloadedSize , http_client-> contentLength () );
199
+ DEBUG_VERBOSE (" OTA Download Progress %d/%d" , context->downloadedSize , contentLength);
199
200
200
201
reportStatus (context->downloadedSize );
201
202
context->lastReportTime = millis ();
202
203
}
203
204
204
205
// TODO there should be no more bytes available when the download is completed
205
- if (context->downloadedSize == http_client-> contentLength () ) {
206
+ if (context->downloadedSize == contentLength) {
206
207
context->downloadState = OtaDownloadCompleted;
207
208
}
208
209
209
- if (context->downloadedSize > http_client-> contentLength () ) {
210
+ if (context->downloadedSize > contentLength) {
210
211
context->downloadState = OtaDownloadError;
211
212
}
212
213
// TODO fail if we exceed a timeout? and available is 0 (client is broken)
213
214
break ;
215
+ }
214
216
case OtaDownloadCompleted:
215
217
return ;
216
218
default :
0 commit comments