@@ -41,28 +41,47 @@ OTAStorage_Nina::OTAStorage_Nina()
41
41
bool OTAStorage_Nina::init ()
42
42
{
43
43
/* Nothing to do */
44
+ return true ;
44
45
}
45
46
46
47
bool OTAStorage_Nina::open (char const * file_name)
47
48
{
48
49
/* It is necessary to prepend "/fs/" when opening a file on the nina
49
50
* for the rename operation "/fs/"" does not need to be prepended.
50
51
*/
52
+
51
53
char nina_file_name[32 ] = {0 };
52
54
strcpy (nina_file_name, " /fs/" );
53
55
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)
57
61
return false ;
58
-
59
- _file = new WiFiStorageFile (file);
62
+
63
+ _file = new WiFiStorageFile (f);
64
+
60
65
return true ;
61
66
}
62
67
63
68
size_t OTAStorage_Nina::write (uint8_t const * const buf, size_t const num_bytes)
64
69
{
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;
66
85
}
67
86
68
87
void OTAStorage_Nina::close ()
@@ -73,12 +92,18 @@ void OTAStorage_Nina::close()
73
92
74
93
void OTAStorage_Nina::remove (char const * file_name)
75
94
{
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);
77
102
}
78
103
79
104
bool OTAStorage_Nina::rename (char const * old_file_name, char const * new_file_name)
80
105
{
81
- return WiFiStorage.rename (old_file_name, new_file_name);
106
+ return ( WiFiStorage.rename (old_file_name, new_file_name) == 0 );
82
107
}
83
108
84
109
void OTAStorage_Nina::deinit ()
0 commit comments