Skip to content

Non blocking ota download #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
implementing non blocking download functions in ota interface
  • Loading branch information
andreagilardoni authored and pennam committed Nov 28, 2024
commit 8094bbfca2953e1e9147bbc1ef528ab2d63532ca
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