|
| 1 | +/* |
| 2 | + This file is part of ArduinoIoTCloud. |
| 3 | +
|
| 4 | + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 5 | +
|
| 6 | + This software is released under the GNU General Public License version 3, |
| 7 | + which covers the main part of arduino-cli. |
| 8 | + The terms of this license can be found at: |
| 9 | + https://www.gnu.org/licenses/gpl-3.0.en.html |
| 10 | +
|
| 11 | + You can be released from the requirements of the above licenses by purchasing |
| 12 | + a commercial license. Buying such a license is mandatory if you want to modify or |
| 13 | + otherwise use the software for commercial activities involving the Arduino |
| 14 | + software without disclosing the source code of your own applications. To purchase |
| 15 | + a commercial license, send an email to [email protected]. |
| 16 | +*/ |
| 17 | + |
| 18 | +/****************************************************************************** |
| 19 | + * INCLUDE |
| 20 | + ******************************************************************************/ |
| 21 | + |
| 22 | +#include <ArduinoIoTCloud_Config.h> |
| 23 | +#if OTA_STORAGE_NINA |
| 24 | + |
| 25 | +#include "OTAStorage_Nina.h" |
| 26 | + |
| 27 | +/****************************************************************************** |
| 28 | + * CTOR/DTOR |
| 29 | + ******************************************************************************/ |
| 30 | + |
| 31 | +OTAStorage_Nina::OTAStorage_Nina() |
| 32 | +: _file{nullptr} |
| 33 | +{ |
| 34 | + |
| 35 | +} |
| 36 | + |
| 37 | +/****************************************************************************** |
| 38 | + * PUBLIC MEMBER FUNCTIONS |
| 39 | + ******************************************************************************/ |
| 40 | + |
| 41 | +bool OTAStorage_Nina::init() |
| 42 | +{ |
| 43 | + /* Nothing to do */ |
| 44 | +} |
| 45 | + |
| 46 | +bool OTAStorage_Nina::open(char const * file_name) |
| 47 | +{ |
| 48 | + /* It is necessary to prepend "/fs/" when opening a file on the nina |
| 49 | + * for the rename operation "/fs/"" does not need to be prepended. |
| 50 | + */ |
| 51 | + char nina_file_name[32] = {0}; |
| 52 | + strcpy(nina_file_name, "/fs/"); |
| 53 | + strcat(nina_file_name, file_name); |
| 54 | + |
| 55 | + WiFiStorageFile file = WiFiStorage.open(nina_file_name); |
| 56 | + if(!file) |
| 57 | + return false; |
| 58 | + |
| 59 | + _file = new WiFiStorageFile(file); |
| 60 | + return true; |
| 61 | +} |
| 62 | + |
| 63 | +size_t OTAStorage_Nina::write(uint8_t const * const buf, size_t const num_bytes) |
| 64 | +{ |
| 65 | + return _file->write(buf, num_bytes); |
| 66 | +} |
| 67 | + |
| 68 | +void OTAStorage_Nina::close() |
| 69 | +{ |
| 70 | + /* There is no close API within WiFiNiNa */ |
| 71 | + delete _file; |
| 72 | +} |
| 73 | + |
| 74 | +void OTAStorage_Nina::remove(char const * file_name) |
| 75 | +{ |
| 76 | + WiFiStorage.remove(file_name); |
| 77 | +} |
| 78 | + |
| 79 | +bool OTAStorage_Nina::rename(char const * old_file_name, char const * new_file_name) |
| 80 | +{ |
| 81 | + return WiFiStorage.rename(old_file_name, new_file_name); |
| 82 | +} |
| 83 | + |
| 84 | +void OTAStorage_Nina::deinit() |
| 85 | +{ |
| 86 | + /* Nothing to do */ |
| 87 | +} |
| 88 | + |
| 89 | +#endif /* OTA_STORAGE_NINA */ |
0 commit comments