9
9
*/
10
10
#include < AIoTC_Config.h>
11
11
12
- #if OTA_ENABLED && ! defined(OFFLOADED_DOWNLOAD)
12
+ #if OTA_ENABLED && ! defined(OFFLOADED_DOWNLOAD) && ! defined(HAS_NOTECARD)
13
13
#include " OTAInterfaceDefault.h"
14
14
#include " ../OTA.h"
15
15
@@ -32,6 +32,8 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
32
32
assert (OTACloudProcessInterface::context != nullptr );
33
33
assert (context == nullptr );
34
34
35
+ DEBUG_DEBUG (" OTADefaultCloudProcessInterface::%s initializing download from \" %s\" " , __FUNCTION__, OTACloudProcessInterface::context->url );
36
+
35
37
context = new Context (
36
38
OTACloudProcessInterface::context->url ,
37
39
[this ](uint8_t c) {
@@ -58,27 +60,27 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
58
60
http_client->endRequest ();
59
61
60
62
if (res == HTTP_ERROR_CONNECTION_FAILED) {
61
- DEBUG_VERBOSE (" OTA ERROR: http client error connecting to server \" %s:%d\" " ,
63
+ DEBUG_ERROR (" OTA ERROR: HTTP client error connecting to server \" %s:%d\" " ,
62
64
context->parsed_url .host (), context->parsed_url .port ());
63
65
return ServerConnectErrorFail;
64
66
} else if (res == HTTP_ERROR_TIMED_OUT) {
65
- DEBUG_VERBOSE (" OTA ERROR: http client timeout \" %s\" " , OTACloudProcessInterface::context->url );
67
+ DEBUG_ERROR (" OTA ERROR: HTTP client timeout \" %s\" " , OTACloudProcessInterface::context->url );
66
68
return OtaHeaderTimeoutFail;
67
69
} else if (res != HTTP_SUCCESS) {
68
- DEBUG_VERBOSE (" OTA ERROR: http client returned %d on get \" %s\" " , res, OTACloudProcessInterface::context->url );
70
+ DEBUG_ERROR (" OTA ERROR: HTTP client returned %d on GET \" %s\" " , res, OTACloudProcessInterface::context->url );
69
71
return OtaDownloadFail;
70
72
}
71
73
72
74
int statusCode = http_client->responseStatusCode ();
73
75
74
76
if (statusCode != 200 ) {
75
- DEBUG_VERBOSE (" OTA ERROR: get response on \" %s\" returned status %d" , OTACloudProcessInterface::context->url , statusCode);
77
+ DEBUG_ERROR (" OTA ERROR: GET response on \" %s\" returned status %d" , OTACloudProcessInterface::context->url , statusCode);
76
78
return HttpResponseFail;
77
79
}
78
80
79
- // The following call is required to save the header value , keep it
81
+ // The following call is required to save the header value ( keep it)
80
82
if (http_client->contentLength () == HttpClient::kNoContentLengthHeader ) {
81
- DEBUG_VERBOSE (" OTA ERROR: the response header doesn't contain \" ContentLength\" field" );
83
+ DEBUG_ERROR (" OTA ERROR: The response header doesn't contain \" ContentLength\" field" );
82
84
return HttpHeaderErrorFail;
83
85
}
84
86
@@ -107,15 +109,15 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
107
109
http_res = http_client->read (context->buffer , context->buf_len );
108
110
109
111
if (http_res < 0 ) {
110
- DEBUG_VERBOSE (" OTA ERROR: Download read error %d" , http_res);
112
+ DEBUG_ERROR (" OTA ERROR: Download read error %d" , http_res);
111
113
res = OtaDownloadFail;
112
114
goto exit ;
113
115
}
114
116
115
117
parseOta (context->buffer , http_res);
116
118
117
119
if (context->writeError ) {
118
- DEBUG_VERBOSE (" OTA ERROR: File write error" );
120
+ DEBUG_ERROR (" OTA ERROR: File write error" );
119
121
res = ErrorWriteUpdateFileFail;
120
122
goto exit ;
121
123
}
@@ -130,17 +132,17 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
130
132
// validate CRC
131
133
context->calculatedCrc32 ^= 0xFFFFFFFF ; // finalize CRC
132
134
if (context->header .header .crc32 == context->calculatedCrc32 ) {
133
- DEBUG_VERBOSE ( " Ota download completed successfully" );
135
+ DEBUG_DEBUG ( " OTADefaultCloudProcessInterface::%s OTA download completed successfully" , __FUNCTION__ );
134
136
res = FlashOTA;
135
137
} else {
136
138
res = OtaHeaderCrcFail;
137
139
}
138
140
} else if (context->downloadState == OtaDownloadError) {
139
- DEBUG_VERBOSE (" OTA ERROR: OtaDownloadError" );
141
+ DEBUG_ERROR (" OTA ERROR: OtaDownloadError" );
140
142
141
143
res = OtaDownloadFail;
142
144
} else if (context->downloadState == OtaDownloadMagicNumberMismatch) {
143
- DEBUG_VERBOSE (" OTA ERROR: Magic number mismatch" );
145
+ DEBUG_ERROR (" OTA ERROR: Magic number mismatch" );
144
146
res = OtaHeaderMagicNumberFail;
145
147
}
146
148
@@ -196,7 +198,7 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t buf_len)
196
198
context->downloadedSize += (cursor-buffer);
197
199
198
200
if ((millis () - context->lastReportTime ) > 10000 ) { // Report the download progress each X millisecond
199
- DEBUG_VERBOSE (" OTA Download Progress %d/%d" , context->downloadedSize , contentLength);
201
+ DEBUG_VERBOSE (" OTADefaultCloudProcessInterface::%s [%d] OTA Download Progress %d/%d" , __FUNCTION__, :: millis () , context->downloadedSize , contentLength);
200
202
201
203
reportStatus (context->downloadedSize );
202
204
context->lastReportTime = millis ();
0 commit comments