Skip to content

Commit

Permalink
Merge pull request #124 from arduino-libraries/nina-download-ota
Browse files Browse the repository at this point in the history
Add 'downloadOTA' command to download OTA file and verify length/CRC
  • Loading branch information
aentinger authored Aug 6, 2020
2 parents 114a48c + ee28a21 commit a8d4745
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
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

0 comments on commit a8d4745

Please sign in to comment.