|
| 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_MKRGSM |
| 24 | + |
| 25 | +#include "OTAStorage_MKRGSM.h" |
| 26 | + |
| 27 | +/****************************************************************************** |
| 28 | + CONSTANTS |
| 29 | + ******************************************************************************/ |
| 30 | + |
| 31 | +static char const SSU_UPDATE_FILENAME[] = "UPDATE.BIN"; |
| 32 | +static char const SSU_CHECK_FILE_NAME[] = "UPDATE.OK"; |
| 33 | + |
| 34 | +/****************************************************************************** |
| 35 | + PUBLIC MEMBER FUNCTIONS |
| 36 | + ******************************************************************************/ |
| 37 | + |
| 38 | +bool OTAStorage_MKRGSM::init() |
| 39 | +{ |
| 40 | + if (!_fileUtils.begin()) |
| 41 | + return false; |
| 42 | + |
| 43 | + if (_fileUtils.listFile(SSU_UPDATE_FILENAME) > 0) |
| 44 | + if (!_fileUtils.deleteFile(SSU_UPDATE_FILENAME)) |
| 45 | + return false; |
| 46 | + |
| 47 | + if (_fileUtils.listFile(SSU_CHECK_FILE_NAME) > 0) |
| 48 | + if (!_fileUtils.deleteFile(SSU_CHECK_FILE_NAME)) |
| 49 | + return false; |
| 50 | +} |
| 51 | + |
| 52 | +bool OTAStorage_MKRGSM::open(char const * /* file_name */) |
| 53 | +{ |
| 54 | + return true; |
| 55 | +} |
| 56 | + |
| 57 | +size_t OTAStorage_MKRGSM::write(uint8_t const* const buf, size_t const num_bytes) |
| 58 | +{ |
| 59 | + _fileUtils.appendFile(SSU_UPDATE_FILENAME, (const char*)buf, num_bytes); |
| 60 | + return num_bytes; |
| 61 | +} |
| 62 | + |
| 63 | +void OTAStorage_MKRGSM::close() |
| 64 | +{ |
| 65 | + /* Nothing to do */ |
| 66 | +} |
| 67 | + |
| 68 | +void OTAStorage_MKRGSM::remove(char const * /* file_name */) |
| 69 | +{ |
| 70 | + _fileUtils.deleteFile(SSU_UPDATE_FILENAME); |
| 71 | +} |
| 72 | + |
| 73 | +bool OTAStorage_MKRGSM::rename(char const * /* old_file_name */, char const * /* new_file_name */) |
| 74 | +{ |
| 75 | + /* Create a file 'UPDATE.OK' which is used by the SSU |
| 76 | + * 2nd stage bootloader to recognise that the update |
| 77 | + * went okay. Normally this is done by renaming 'UPDATE.BIN.TMP' |
| 78 | + * to 'UPDATE.BIN' but the SARE module does not support |
| 79 | + * a rename function. |
| 80 | + */ |
| 81 | + char c = 'X'; |
| 82 | + return (_fileUtils.appendFile(SSU_CHECK_FILE_NAME, &c, sizeof(c)) == sizeof(c)); |
| 83 | +} |
| 84 | + |
| 85 | +void OTAStorage_MKRGSM::deinit() |
| 86 | +{ |
| 87 | + /* Nothing to do */ |
| 88 | +} |
| 89 | + |
| 90 | +#endif /* OTA_STORAGE_MKRGSM */ |
0 commit comments