@@ -20,7 +20,6 @@ OTADefaultCloudProcessInterface::OTADefaultCloudProcessInterface(MessageStream *
2020, client(client)
2121, http_client(nullptr )
2222, username(nullptr ), password(nullptr )
23- , fetchMode(OtaFetchTime)
2423, context(nullptr ) {
2524}
2625
@@ -50,7 +49,7 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
5049 }
5150
5251 // make the http get request
53- OTACloudProcessInterface::State res = requestOta (OtaFetchTime );
52+ OTACloudProcessInterface::State res = requestOta ();
5453 if (res != Fetch) {
5554 return res;
5655 }
@@ -70,8 +69,8 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
7069OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch () {
7170 OTACloudProcessInterface::State res = Fetch;
7271
73- if (fetchMode == OtaFetchChunk ) {
74- res = requestOta (OtaFetchChunk );
72+ if (getOtaPolicy (ChunkDownload) ) {
73+ res = requestOta (ChunkDownload );
7574 }
7675
7776 context->downloadedChunkSize = 0 ;
@@ -145,7 +144,7 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
145144 return res;
146145}
147146
148- OTACloudProcessInterface::State OTADefaultCloudProcessInterface::requestOta (OTAFetchMode mode) {
147+ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::requestOta (OtaFlags mode) {
149148 int http_res = 0 ;
150149
151150 /* stop connected client */
@@ -159,7 +158,7 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::requestOta(OTAF
159158 http_client->sendBasicAuth (username, password);
160159 }
161160
162- if (mode == OtaFetchChunk ) {
161+ if (( mode & ChunkDownload) == ChunkDownload ) {
163162 char range[128 ] = {0 };
164163 size_t rangeSize = context->downloadedSize + maxChunkSize > context->contentLength ? context->contentLength - context->downloadedSize : maxChunkSize;
165164 sprintf (range, " bytes=%d-%d" , context->downloadedSize , context->downloadedSize + rangeSize);
@@ -183,18 +182,18 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::requestOta(OTAF
183182
184183 int statusCode = http_client->responseStatusCode ();
185184
186- if (((mode == OtaFetchChunk) && (statusCode != 206 )) || ((mode == OtaFetchTime) && (statusCode != 200 ))) {
185+ if ((((mode & ChunkDownload) == ChunkDownload) && (statusCode != 206 )) ||
186+ (((mode & ChunkDownload) != ChunkDownload) && (statusCode != 200 ))) {
187187 DEBUG_VERBOSE (" OTA ERROR: get response on \" %s\" returned status %d" , OTACloudProcessInterface::context->url , statusCode);
188188 return HttpResponseFail;
189189 }
190190
191191 http_client->skipResponseHeaders ();
192-
193192 return Fetch;
194193}
195194
196195bool OTADefaultCloudProcessInterface::fetchMore () {
197- if (fetchMode == OtaFetchChunk ) {
196+ if (getOtaPolicy (ChunkDownload) ) {
198197 return context->downloadedChunkSize < maxChunkSize;
199198 } else {
200199 return (millis () - context->downloadedChunkStartTime ) < downloadTime;
0 commit comments