@@ -20,7 +20,6 @@ OTADefaultCloudProcessInterface::OTADefaultCloudProcessInterface(MessageStream *
20
20
, client(client)
21
21
, http_client(nullptr )
22
22
, username(nullptr ), password(nullptr )
23
- , fetchMode(OtaFetchTime)
24
23
, context(nullptr ) {
25
24
}
26
25
@@ -50,7 +49,7 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
50
49
}
51
50
52
51
// make the http get request
53
- OTACloudProcessInterface::State res = requestOta (OtaFetchTime );
52
+ OTACloudProcessInterface::State res = requestOta ();
54
53
if (res != Fetch) {
55
54
return res;
56
55
}
@@ -70,8 +69,8 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
70
69
OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch () {
71
70
OTACloudProcessInterface::State res = Fetch;
72
71
73
- if (fetchMode == OtaFetchChunk ) {
74
- res = requestOta (OtaFetchChunk );
72
+ if (getOtaPolicy (ChunkDownload) ) {
73
+ res = requestOta (ChunkDownload );
75
74
}
76
75
77
76
context->downloadedChunkSize = 0 ;
@@ -145,7 +144,7 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
145
144
return res;
146
145
}
147
146
148
- OTACloudProcessInterface::State OTADefaultCloudProcessInterface::requestOta (OTAFetchMode mode) {
147
+ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::requestOta (OtaFlags mode) {
149
148
int http_res = 0 ;
150
149
151
150
/* stop connected client */
@@ -159,7 +158,7 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::requestOta(OTAF
159
158
http_client->sendBasicAuth (username, password);
160
159
}
161
160
162
- if (mode == OtaFetchChunk ) {
161
+ if (( mode & ChunkDownload) == ChunkDownload ) {
163
162
char range[128 ] = {0 };
164
163
size_t rangeSize = context->downloadedSize + maxChunkSize > context->contentLength ? context->contentLength - context->downloadedSize : maxChunkSize;
165
164
sprintf (range, " bytes=%d-%d" , context->downloadedSize , context->downloadedSize + rangeSize);
@@ -183,18 +182,18 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::requestOta(OTAF
183
182
184
183
int statusCode = http_client->responseStatusCode ();
185
184
186
- if (((mode == OtaFetchChunk) && (statusCode != 206 )) || ((mode == OtaFetchTime) && (statusCode != 200 ))) {
185
+ if ((((mode & ChunkDownload) == ChunkDownload) && (statusCode != 206 )) ||
186
+ (((mode & ChunkDownload) != ChunkDownload) && (statusCode != 200 ))) {
187
187
DEBUG_VERBOSE (" OTA ERROR: get response on \" %s\" returned status %d" , OTACloudProcessInterface::context->url , statusCode);
188
188
return HttpResponseFail;
189
189
}
190
190
191
191
http_client->skipResponseHeaders ();
192
-
193
192
return Fetch;
194
193
}
195
194
196
195
bool OTADefaultCloudProcessInterface::fetchMore () {
197
- if (fetchMode == OtaFetchChunk ) {
196
+ if (getOtaPolicy (ChunkDownload) ) {
198
197
return context->downloadedChunkSize < maxChunkSize;
199
198
} else {
200
199
return (millis () - context->downloadedChunkStartTime ) < downloadTime;
0 commit comments