Skip to content

Commit b409cf3

Browse files
committed
Doing various adjustments in order to deal with the nina storage pecularities
1 parent 22c50fb commit b409cf3

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/utility/ota/OTAStorage_Nina.cpp

+33-8
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,47 @@ OTAStorage_Nina::OTAStorage_Nina()
4141
bool OTAStorage_Nina::init()
4242
{
4343
/* Nothing to do */
44+
return true;
4445
}
4546

4647
bool OTAStorage_Nina::open(char const * file_name)
4748
{
4849
/* It is necessary to prepend "/fs/" when opening a file on the nina
4950
* for the rename operation "/fs/"" does not need to be prepended.
5051
*/
52+
5153
char nina_file_name[32] = {0};
5254
strcpy(nina_file_name, "/fs/");
5355
strcat(nina_file_name, file_name);
54-
55-
WiFiStorageFile file = WiFiStorage.open(nina_file_name);
56-
if(!file)
56+
57+
WiFiStorage.remove(nina_file_name);
58+
WiFiStorageFile f = WiFiStorage.open(nina_file_name);
59+
60+
if (!f)
5761
return false;
58-
59-
_file = new WiFiStorageFile(file);
62+
63+
_file = new WiFiStorageFile(f);
64+
6065
return true;
6166
}
6267

6368
size_t OTAStorage_Nina::write(uint8_t const * const buf, size_t const num_bytes)
6469
{
65-
return _file->write(buf, num_bytes);
70+
/* We have to write in chunks because otherwise we exceed the size of
71+
* the SPI buffer within the nina module.
72+
*/
73+
size_t bytes_written = 0;
74+
size_t const WRITE_CHUNK_SIZE = 32;
75+
76+
for(; bytes_written < (num_bytes - WRITE_CHUNK_SIZE); bytes_written += WRITE_CHUNK_SIZE)
77+
{
78+
if (_file->write(buf + bytes_written, WRITE_CHUNK_SIZE) != WRITE_CHUNK_SIZE)
79+
return bytes_written;
80+
}
81+
82+
bytes_written += _file->write(buf + bytes_written, num_bytes - bytes_written);
83+
84+
return bytes_written;
6685
}
6786

6887
void OTAStorage_Nina::close()
@@ -73,12 +92,18 @@ void OTAStorage_Nina::close()
7392

7493
void OTAStorage_Nina::remove(char const * file_name)
7594
{
76-
WiFiStorage.remove(file_name);
95+
/* Prepend "/fs/" */
96+
char nina_file_name[32] = {0};
97+
strcpy(nina_file_name, "/fs/");
98+
strcat(nina_file_name, file_name);
99+
100+
/* Remove file */
101+
WiFiStorage.remove(nina_file_name);
77102
}
78103

79104
bool OTAStorage_Nina::rename(char const * old_file_name, char const * new_file_name)
80105
{
81-
return WiFiStorage.rename(old_file_name, new_file_name);
106+
return (WiFiStorage.rename(old_file_name, new_file_name) == 0);
82107
}
83108

84109
void OTAStorage_Nina::deinit()

src/utility/ota/OTAStorage_Nina.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include "OTAStorage.h"
2929

30-
#include <WiFiNINA.h>
30+
#include <WiFiStorage.h>
3131

3232
/******************************************************************************
3333
* CLASS DECLARATION

0 commit comments

Comments
 (0)