Skip to content

Commit 8094bbf

Browse files
andreagilardonipennam
authored andcommitted
implementing non blocking download functions in ota interface
1 parent 428df2a commit 8094bbf

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

libraries/OTAUpdate/src/OTAUpdate.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,49 @@ int OTAUpdate::download(const char* url, const char* file_path) {
8787
return ret;
8888
}
8989

90+
int OTAUpdate::startDownload(const char* url) {
91+
string res = "";
92+
int ret = -1;
93+
if ( url != nullptr && strlen(url) > 0) {
94+
modem.timeout(EXTENDED_MODEM_TIMEOUT);
95+
if(modem.write(string(PROMPT(_OTA_DOWNLOAD_START)), res, "%s%s\r\n", CMD_WRITE(_OTA_DOWNLOAD_START), url)) {
96+
ret = atoi(res.c_str());
97+
} else {
98+
ret = static_cast<int>(Error::Modem);
99+
}
100+
} else {
101+
ret = static_cast<int>(Error::Library);
102+
}
103+
modem.timeout(MODEM_TIMEOUT);
104+
return ret;
105+
}
106+
107+
int OTAUpdate::startDownload(const char* url, const char* file_path) {
108+
string res = "";
109+
int ret = -1;
110+
111+
if ( url != nullptr && strlen(url) > 0 && file_path != nullptr && strlen(file_path) >0) {
112+
modem.timeout(EXTENDED_MODEM_TIMEOUT);
113+
if(modem.write(string(PROMPT(_OTA_DOWNLOAD_START)), res, "%s%s,%s\r\n", CMD_WRITE(_OTA_DOWNLOAD_START), url, file_path)) {
114+
ret = atoi(res.c_str());
115+
} else {
116+
ret = static_cast<int>(Error::Modem);
117+
}
118+
} else {
119+
ret = static_cast<int>(Error::Library);
120+
}
121+
modem.timeout(MODEM_TIMEOUT);
122+
return ret;
123+
}
124+
125+
int OTAUpdate::downloadProgress() {
126+
string res = "";
127+
if (modem.write(string(PROMPT(_OTA_DOWNLOAD_PROGRESS)), res, "%s", CMD(_OTA_DOWNLOAD_PROGRESS))) {
128+
return atoi(res.c_str());
129+
}
130+
return static_cast<int>(Error::Modem);
131+
}
132+
90133
int OTAUpdate::verify() {
91134
string res = "";
92135
if (modem.write(string(PROMPT(_OTA_VERIFY)), res, "%s", CMD(_OTA_VERIFY))) {

libraries/OTAUpdate/src/OTAUpdate.h

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class OTAUpdate {
4242
int begin(const char* file_path);
4343
int download(const char* url);
4444
int download(const char* url, const char* file_path);
45+
46+
int startDownload(const char* url);
47+
int startDownload(const char* url, const char* file_path);
48+
49+
int downloadProgress();
50+
4551
int verify();
4652
int update();
4753
int update(const char* file_path);

0 commit comments

Comments
 (0)