Skip to content

Commit 2219137

Browse files
committed
Fix filesystem operation for 8bit architectures
1 parent 32de705 commit 2219137

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

src/WiFiStorage.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
WiFiStorage.cpp - Library for Arduino boards based on NINA wifi module.
3+
Copyright (c) 2018 Arduino SA. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
120
#include "WiFiStorage.h"
221

322
WiFiStorageFile WiFiStorageClass::open(const char *filename) {

src/WiFiStorage.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/*
2+
WiFiStorage.h - Library for Arduino boards based on NINA wifi module.
3+
Copyright (c) 2018 Arduino SA. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef wifistorage_h
21+
#define wifistorage_h
22+
123
#include "utility/wifi_drv.h"
224

325
class WiFiStorageFile;
@@ -11,21 +33,21 @@ class WiFiStorageClass
1133
static WiFiStorageFile open(String filename);
1234

1335
static bool exists(const char *filename) {
14-
size_t len;
36+
uint32_t len;
1537
return (WiFiDrv::existsFile(filename, strlen(filename), &len) > 0);
1638
}
17-
static bool exists(const char *filename, size_t* len) {
39+
static bool exists(const char *filename, uint32_t* len) {
1840
return (WiFiDrv::existsFile(filename, strlen(filename), len) > 0);
1941
}
2042
static bool remove(const char *filename) {
2143
WiFiDrv::deleteFile(filename, strlen(filename));
2244
return true;
2345
}
24-
static bool read(const char *filename, size_t offset, uint8_t* buffer, size_t buffer_len) {
46+
static bool read(const char *filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
2547
WiFiDrv::readFile(filename, strlen(filename), offset, buffer, buffer_len);
2648
return true;
2749
}
28-
static bool write(const char *filename, size_t offset, uint8_t* buffer, size_t buffer_len) {
50+
static bool write(const char *filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
2951
WiFiDrv::writeFile(filename, strlen(filename), offset, buffer, buffer_len);
3052
return true;
3153
}
@@ -37,10 +59,10 @@ class WiFiStorageClass
3759
static bool remove(String filename) {
3860
return remove(filename.c_str());
3961
}
40-
static bool read(String filename, size_t offset, uint8_t* buffer, size_t buffer_len) {
62+
static bool read(String filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
4163
return read(filename.c_str(), offset, buffer, buffer_len);
4264
}
43-
static bool write(String filename, size_t offset, uint8_t* buffer, size_t buffer_len) {
65+
static bool write(String filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
4466
return write(filename.c_str(), offset, buffer, buffer_len);
4567
}
4668
static bool download(String url, String filename) {
@@ -55,6 +77,7 @@ class WiFiStorageFile
5577
{
5678
public:
5779
constexpr WiFiStorageFile(const char* _filename) : filename(_filename) { }
80+
5881
operator bool() {
5982
return WiFiStorage.exists(filename, &length);
6083
}
@@ -96,7 +119,9 @@ class WiFiStorageFile
96119
}
97120
protected:
98121
friend class WiFiStorageClass;
99-
size_t offset = 0;
100-
size_t length = 0;
122+
uint32_t offset = 0;
123+
uint32_t length = 0;
101124
const char* filename;
102125
};
126+
127+
#endif

src/utility/wifi_drv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ int8_t WiFiDrv::downloadFile(const char* url, uint8_t url_len, const char *filen
11101110
return _data;
11111111
}
11121112

1113-
int8_t WiFiDrv::fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t len)
1113+
int8_t WiFiDrv::fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t len)
11141114
{
11151115
WAIT_FOR_SLAVE_SELECT();
11161116
// Send Command

src/utility/wifi_drv.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,18 @@ class WiFiDrv
288288

289289
static int8_t downloadFile(const char* url, uint8_t url_len, const char *filename, uint8_t filename_len);
290290

291-
static int8_t fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t len);
291+
static int8_t fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t len);
292292

293-
static int8_t readFile(const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t buffer_len) {
293+
static int8_t readFile(const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
294294
return fileOperation(READ_FILE, filename, filename_len, offset, buffer, buffer_len);
295295
};
296-
static int8_t writeFile(const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t buffer_len) {
296+
static int8_t writeFile(const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
297297
return fileOperation(WRITE_FILE, filename, filename_len, offset, buffer, buffer_len);
298298
};
299299
static int8_t deleteFile(const char *filename, uint8_t filename_len) {
300300
return fileOperation(DELETE_FILE, filename, filename_len, 0, NULL, 0);
301301
};
302-
static int8_t existsFile(const char *filename, uint8_t filename_len, size_t* len) {
302+
static int8_t existsFile(const char *filename, uint8_t filename_len, uint32_t* len) {
303303
int32_t length = 0;
304304
fileOperation(EXISTS_FILE, filename, filename_len, 0, (uint8_t*)&length, sizeof(length));
305305
*len = length;

0 commit comments

Comments
 (0)