diff --git a/src/WiFiStorage.cpp b/src/WiFiStorage.cpp index 9d2ea4b7..9d3d13ea 100644 --- a/src/WiFiStorage.cpp +++ b/src/WiFiStorage.cpp @@ -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) { diff --git a/src/WiFiStorage.h b/src/WiFiStorage.h index 2479c44c..72e1975f 100644 --- a/src/WiFiStorage.h +++ b/src/WiFiStorage.h @@ -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; @@ -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; } @@ -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) { @@ -55,6 +77,7 @@ class WiFiStorageFile { public: constexpr WiFiStorageFile(const char* _filename) : filename(_filename) { } + operator bool() { return WiFiStorage.exists(filename, &length); } @@ -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 \ No newline at end of file diff --git a/src/utility/wifi_drv.cpp b/src/utility/wifi_drv.cpp index 336076c7..de856e24 100644 --- a/src/utility/wifi_drv.cpp +++ b/src/utility/wifi_drv.cpp @@ -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 diff --git a/src/utility/wifi_drv.h b/src/utility/wifi_drv.h index f10af3c0..883b7e68 100644 --- a/src/utility/wifi_drv.h +++ b/src/utility/wifi_drv.h @@ -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;