Skip to content

Commit

Permalink
implementing non blocking download functions in ota interface
Browse files Browse the repository at this point in the history
  • Loading branch information
andreagilardoni authored and pennam committed Nov 28, 2024
1 parent 428df2a commit 8094bbf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
43 changes: 43 additions & 0 deletions libraries/OTAUpdate/src/OTAUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,49 @@ int OTAUpdate::download(const char* url, const char* file_path) {
return ret;
}

int OTAUpdate::startDownload(const char* url) {
string res = "";
int ret = -1;
if ( url != nullptr && strlen(url) > 0) {
modem.timeout(EXTENDED_MODEM_TIMEOUT);
if(modem.write(string(PROMPT(_OTA_DOWNLOAD_START)), res, "%s%s\r\n", CMD_WRITE(_OTA_DOWNLOAD_START), url)) {
ret = atoi(res.c_str());
} else {
ret = static_cast<int>(Error::Modem);
}
} else {
ret = static_cast<int>(Error::Library);
}
modem.timeout(MODEM_TIMEOUT);
return ret;
}

int OTAUpdate::startDownload(const char* url, const char* file_path) {
string res = "";
int ret = -1;

if ( url != nullptr && strlen(url) > 0 && file_path != nullptr && strlen(file_path) >0) {
modem.timeout(EXTENDED_MODEM_TIMEOUT);
if(modem.write(string(PROMPT(_OTA_DOWNLOAD_START)), res, "%s%s,%s\r\n", CMD_WRITE(_OTA_DOWNLOAD_START), url, file_path)) {
ret = atoi(res.c_str());
} else {
ret = static_cast<int>(Error::Modem);
}
} else {
ret = static_cast<int>(Error::Library);
}
modem.timeout(MODEM_TIMEOUT);
return ret;
}

int OTAUpdate::downloadProgress() {
string res = "";
if (modem.write(string(PROMPT(_OTA_DOWNLOAD_PROGRESS)), res, "%s", CMD(_OTA_DOWNLOAD_PROGRESS))) {
return atoi(res.c_str());
}
return static_cast<int>(Error::Modem);
}

int OTAUpdate::verify() {
string res = "";
if (modem.write(string(PROMPT(_OTA_VERIFY)), res, "%s", CMD(_OTA_VERIFY))) {
Expand Down
6 changes: 6 additions & 0 deletions libraries/OTAUpdate/src/OTAUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class OTAUpdate {
int begin(const char* file_path);
int download(const char* url);
int download(const char* url, const char* file_path);

int startDownload(const char* url);
int startDownload(const char* url, const char* file_path);

int downloadProgress();

int verify();
int update();
int update(const char* file_path);
Expand Down

0 comments on commit 8094bbf

Please sign in to comment.