Skip to content
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

Add 'downloadOTA' command to download OTA file and verify length/CRC #124

Merged
merged 4 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions src/WiFiStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class WiFiStorageClass
WiFiDrv::downloadFile(url, strlen(url), filename, strlen(filename));
return true;
}
static bool downloadOTA(const char * url, uint8_t * res_ota_download = NULL) {
uint8_t const res = WiFiDrv::downloadOTA(url, strlen(url));
if (res_ota_download)
*res_ota_download = res;
bool const success = (res == 0);
return success;
}


static bool remove(String filename) {
return remove(filename.c_str());
Expand All @@ -74,6 +82,9 @@ class WiFiStorageClass
static bool download(String url, String filename) {
return download(url.c_str(), filename.c_str());
}
static bool download(String url, uint8_t * res_ota_download = NULL) {
return downloadOTA(url.c_str(), res_ota_download);
}
};

extern WiFiStorageClass WiFiStorage;
Expand Down
31 changes: 31 additions & 0 deletions src/utility/wifi_drv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,37 @@ int8_t WiFiDrv::downloadFile(const char* url, uint8_t url_len, const char *filen
return _data;
}

int8_t WiFiDrv::downloadOTA(const char* url, uint8_t url_len)
{
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(DOWNLOAD_OTA, PARAM_NUMS_1);
SpiDrv::sendParam((uint8_t*)url, url_len, LAST_PARAM);

// pad to multiple of 4
int commandSize = 5 + url_len;
while (commandSize % 4) {
SpiDrv::readChar();
commandSize++;
}

SpiDrv::spiSlaveDeselect();
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
SpiDrv::spiSlaveSelect();

// Wait for reply
uint8_t _data = 0;
uint8_t _dataLen = 0;
if (!SpiDrv::waitResponseCmd(DOWNLOAD_OTA, PARAM_NUMS_1, &_data, &_dataLen))
{
WARN("error waitResponse");
_data = WL_FAILURE;
}
SpiDrv::spiSlaveDeselect();
return _data;
}

int8_t WiFiDrv::renameFile(const char * old_file_name, uint8_t const old_file_name_len, const char * new_file_name, uint8_t const new_file_name_len)
{
WAIT_FOR_SLAVE_SELECT();
Expand Down
1 change: 1 addition & 0 deletions src/utility/wifi_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class WiFiDrv
static void analogWrite(uint8_t pin, uint8_t value);

static int8_t downloadFile(const char* url, uint8_t url_len, const char *filename, uint8_t filename_len);
static int8_t downloadOTA(const char* url, uint8_t url_len);
static int8_t renameFile(const char * old_file_name, uint8_t const old_file_name_len, const char * new_file_name, uint8_t const new_file_name_len);

static int8_t fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t len);
Expand Down
1 change: 1 addition & 0 deletions src/utility/wifi_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ enum {
DOWNLOAD_FILE = 0x64,
APPLY_OTA_COMMAND = 0x65,
RENAME_FILE = 0x66,
DOWNLOAD_OTA = 0x67,
};


Expand Down