Skip to content

Commit 49f9738

Browse files
committed
Adding 'rename' operation necessary for using the WiFiNiNa for OTA
1 parent 2219137 commit 49f9738

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/WiFiStorage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class WiFiStorageClass
4343
WiFiDrv::deleteFile(filename, strlen(filename));
4444
return true;
4545
}
46+
static bool rename(const char * old_file_name, const char * new_file_name) {
47+
return (WiFiDrv::renameFile(old_file_name, strlen(old_file_name), new_file_name, strlen(new_file_name)) == 0);
48+
}
4649
static bool read(const char *filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
4750
WiFiDrv::readFile(filename, strlen(filename), offset, buffer, buffer_len);
4851
return true;
@@ -59,6 +62,9 @@ class WiFiStorageClass
5962
static bool remove(String filename) {
6063
return remove(filename.c_str());
6164
}
65+
static bool rename(String old_file_name, String new_file_name) {
66+
return rename(old_file_name.c_str(), new_file_name.c_str());
67+
}
6268
static bool read(String filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
6369
return read(filename.c_str(), offset, buffer, buffer_len);
6470
}

src/utility/wifi_drv.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,38 @@ int8_t WiFiDrv::downloadFile(const char* url, uint8_t url_len, const char *filen
11101110
return _data;
11111111
}
11121112

1113+
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)
1114+
{
1115+
WAIT_FOR_SLAVE_SELECT();
1116+
/* Send Command */
1117+
SpiDrv::sendCmd(RENAME_FILE, PARAM_NUMS_2);
1118+
SpiDrv::sendParam((uint8_t*)old_file_name, old_file_name_len, NO_LAST_PARAM);
1119+
SpiDrv::sendParam((uint8_t*)new_file_name, new_file_name_len, LAST_PARAM);
1120+
1121+
/* pad to multiple of 4 */
1122+
int commandSize = 6 + old_file_name_len + new_file_name_len;
1123+
while (commandSize % 4) {
1124+
SpiDrv::readChar();
1125+
commandSize++;
1126+
}
1127+
1128+
SpiDrv::spiSlaveDeselect();
1129+
/* Wait the reply elaboration */
1130+
SpiDrv::waitForSlaveReady();
1131+
SpiDrv::spiSlaveSelect();
1132+
1133+
/* Wait for reply */
1134+
uint8_t data = 0;
1135+
uint8_t dataLen = 0;
1136+
if (!SpiDrv::waitResponseCmd(DOWNLOAD_FILE, PARAM_NUMS_1, &data, &dataLen))
1137+
{
1138+
WARN("error waitResponse");
1139+
data = WL_FAILURE;
1140+
}
1141+
SpiDrv::spiSlaveDeselect();
1142+
return data;
1143+
}
1144+
11131145
int8_t WiFiDrv::fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t len)
11141146
{
11151147
WAIT_FOR_SLAVE_SELECT();

src/utility/wifi_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ class WiFiDrv
287287
static void analogWrite(uint8_t pin, uint8_t value);
288288

289289
static int8_t downloadFile(const char* url, uint8_t url_len, const char *filename, uint8_t filename_len);
290+
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);
290291

291292
static int8_t fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t len);
292293

src/utility/wifi_spi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ enum {
109109
EXISTS_FILE = 0x63,
110110
DOWNLOAD_FILE = 0x64,
111111
APPLY_OTA_COMMAND = 0x65,
112+
RENAME_FILE = 0x66,
112113
};
113114

114115

0 commit comments

Comments
 (0)