@@ -32,6 +32,7 @@ UNOR4OTACloudProcess::UNOR4OTACloudProcess(MessageStream *ms)
32
32
}
33
33
34
34
OTACloudProcessInterface::State UNOR4OTACloudProcess::resume (Message* msg) {
35
+ (void )msg;
35
36
return OtaBegin;
36
37
}
37
38
@@ -57,22 +58,25 @@ OTACloudProcessInterface::State UNOR4OTACloudProcess::startOTA() {
57
58
}
58
59
59
60
OTACloudProcessInterface::State UNOR4OTACloudProcess::fetch () {
60
- int ota_err = OTAUpdate::OTA_ERROR_NONE;
61
-
62
61
String fv = WiFi.firmwareVersion ();
63
- if (fv >= " 0.5.0" ) {
62
+ /* Firmware supports non blocking OTA */
63
+ if (fv >= " 0.5.0" ) {
64
64
auto progress = ota.downloadProgress ();
65
+ if (progress < 0 ) {
66
+ return OtaDownloadFail;
67
+ }
65
68
66
- if ((millis () - context->lastReportTime ) > 5000 ) { // Report the download progress each X millisecond
69
+ if ((millis () - context->lastReportTime ) > 5000 ) { // Report the download progress each X millisecond
67
70
DEBUG_VERBOSE (" OTA Download Progress %d/%d" , progress, context->downloadSize );
68
71
69
72
reportStatus (progress);
70
73
context->lastReportTime = millis ();
71
74
}
72
75
73
- if (progress < context->downloadSize ) {
76
+ /* It is safe to cast progress here because we are sure that is positive */
77
+ if ((size_t )progress < context->downloadSize ) {
74
78
return Fetch;
75
- } else if ( progress > context->downloadSize || progress < 0 ) {
79
+ } else if (( size_t ) progress > context->downloadSize ) {
76
80
return OtaDownloadFail;
77
81
} else {
78
82
return FlashOTA;
@@ -85,7 +89,6 @@ OTACloudProcessInterface::State UNOR4OTACloudProcess::fetch() {
85
89
}
86
90
87
91
DEBUG_VERBOSE (" OTAUpdate::download() %d bytes downloaded" , ota_download);
88
-
89
92
return FlashOTA;
90
93
}
91
94
}
@@ -99,13 +102,18 @@ OTACloudProcessInterface::State UNOR4OTACloudProcess::flashOTA() {
99
102
}
100
103
101
104
/* Flash new firmware */
102
- if ((ota_err = ota.update (UPDATE_FILE_NAME)) != OTAUpdate::OTA_ERROR_NONE) { // This reboots the MCU
105
+ if ((ota_err = ota.update (UPDATE_FILE_NAME)) != OTAUpdate::OTA_ERROR_NONE) {
103
106
DEBUG_VERBOSE (" OTAUpdate::update() failed with %d" , ota_err);
104
107
return convertUnor4ErrorToState (ota_err);
105
108
}
109
+
110
+ /* This is never called because ota.uptade reboots the microcontroller */
111
+ return Resume;
106
112
}
107
113
108
114
OTACloudProcessInterface::State UNOR4OTACloudProcess::reboot () {
115
+ /* This is never called; the microcontroller reboots in flashOTA state */
116
+ return Resume;
109
117
}
110
118
111
119
void UNOR4OTACloudProcess::reset () {
0 commit comments