Skip to content

Commit

Permalink
Add 'downloadOTA' command to download OTA file and verify length/CRC
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed Aug 4, 2020
1 parent 114a48c commit 1efcc58
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/WiFiStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class WiFiStorageClass
WiFiDrv::downloadFile(url, strlen(url), filename, strlen(filename));
return true;
}
static bool downloadOTA(const char * url) {
return (WiFiDrv::downloadOTA(url, strlen(url)) == 0);
}


static bool remove(String filename) {
return remove(filename.c_str());
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 = 6 + 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 1efcc58

Please sign in to comment.