Skip to content

Commit

Permalink
Fix filesystem operation for 8bit architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm committed Aug 8, 2019
1 parent 32de705 commit 2219137
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
19 changes: 19 additions & 0 deletions src/WiFiStorage.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
WiFiStorage.cpp - Library for Arduino boards based on NINA wifi module.
Copyright (c) 2018 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "WiFiStorage.h"

WiFiStorageFile WiFiStorageClass::open(const char *filename) {
Expand Down
41 changes: 33 additions & 8 deletions src/WiFiStorage.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
WiFiStorage.h - Library for Arduino boards based on NINA wifi module.
Copyright (c) 2018 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef wifistorage_h
#define wifistorage_h

#include "utility/wifi_drv.h"

class WiFiStorageFile;
Expand All @@ -11,21 +33,21 @@ class WiFiStorageClass
static WiFiStorageFile open(String filename);

static bool exists(const char *filename) {
size_t len;
uint32_t len;
return (WiFiDrv::existsFile(filename, strlen(filename), &len) > 0);
}
static bool exists(const char *filename, size_t* len) {
static bool exists(const char *filename, uint32_t* len) {
return (WiFiDrv::existsFile(filename, strlen(filename), len) > 0);
}
static bool remove(const char *filename) {
WiFiDrv::deleteFile(filename, strlen(filename));
return true;
}
static bool read(const char *filename, size_t offset, uint8_t* buffer, size_t buffer_len) {
static bool read(const char *filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
WiFiDrv::readFile(filename, strlen(filename), offset, buffer, buffer_len);
return true;
}
static bool write(const char *filename, size_t offset, uint8_t* buffer, size_t buffer_len) {
static bool write(const char *filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
WiFiDrv::writeFile(filename, strlen(filename), offset, buffer, buffer_len);
return true;
}
Expand All @@ -37,10 +59,10 @@ class WiFiStorageClass
static bool remove(String filename) {
return remove(filename.c_str());
}
static bool read(String filename, size_t offset, uint8_t* buffer, size_t buffer_len) {
static bool read(String filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
return read(filename.c_str(), offset, buffer, buffer_len);
}
static bool write(String filename, size_t offset, uint8_t* buffer, size_t buffer_len) {
static bool write(String filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
return write(filename.c_str(), offset, buffer, buffer_len);
}
static bool download(String url, String filename) {
Expand All @@ -55,6 +77,7 @@ class WiFiStorageFile
{
public:
constexpr WiFiStorageFile(const char* _filename) : filename(_filename) { }

operator bool() {
return WiFiStorage.exists(filename, &length);
}
Expand Down Expand Up @@ -96,7 +119,9 @@ class WiFiStorageFile
}
protected:
friend class WiFiStorageClass;
size_t offset = 0;
size_t length = 0;
uint32_t offset = 0;
uint32_t length = 0;
const char* filename;
};

#endif
2 changes: 1 addition & 1 deletion src/utility/wifi_drv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ int8_t WiFiDrv::downloadFile(const char* url, uint8_t url_len, const char *filen
return _data;
}

int8_t WiFiDrv::fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t len)
int8_t WiFiDrv::fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t len)
{
WAIT_FOR_SLAVE_SELECT();
// Send Command
Expand Down
8 changes: 4 additions & 4 deletions src/utility/wifi_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,18 @@ class WiFiDrv

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

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

static int8_t readFile(const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t buffer_len) {
static int8_t readFile(const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
return fileOperation(READ_FILE, filename, filename_len, offset, buffer, buffer_len);
};
static int8_t writeFile(const char *filename, uint8_t filename_len, size_t offset, uint8_t* buffer, size_t buffer_len) {
static int8_t writeFile(const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
return fileOperation(WRITE_FILE, filename, filename_len, offset, buffer, buffer_len);
};
static int8_t deleteFile(const char *filename, uint8_t filename_len) {
return fileOperation(DELETE_FILE, filename, filename_len, 0, NULL, 0);
};
static int8_t existsFile(const char *filename, uint8_t filename_len, size_t* len) {
static int8_t existsFile(const char *filename, uint8_t filename_len, uint32_t* len) {
int32_t length = 0;
fileOperation(EXISTS_FILE, filename, filename_len, 0, (uint8_t*)&length, sizeof(length));
*len = length;
Expand Down

0 comments on commit 2219137

Please sign in to comment.