Skip to content

Commit f214215

Browse files
committed
Changing interface of OTAStorage_MRKGSM to be compliant with the latest version of OTAStorage
1 parent 44c9987 commit f214215

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

src/utility/ota/OTAStorage.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class OTAStorage
4040
enum class Type : int
4141
{
4242
NotAvailable = -1,
43-
MKRMEM = 0
43+
MKRMEM = 0,
44+
MKRGSMFile = 2,
4445
};
4546

4647
virtual Type type () = 0;

src/utility/ota/OTAStorage_MKRGSM.cpp

+33-21
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,65 @@
2121

2222
#include "OTAStorage_MKRGSM.h"
2323

24-
#include <Arduino_DebugUtils.h>
25-
2624
/******************************************************************************
27-
CTOR/DTOR
25+
CONSTANTS
2826
******************************************************************************/
2927

30-
OTAStorage_MKRGSM::OTAStorage_MKRGSM()
31-
{
32-
}
28+
static char const SSU_UPDATE_FILENAME[] = "UPDATE.BIN";
29+
static char const SSU_CHECK_FILE_NAME[] = "UPDATE.OK";
3330

34-
// GSMFileUtils _fileUtils;
35-
// String filename = "UPDATE.BIN";
36-
constexpr char * filename { "UPDATE.BIN" };
3731
/******************************************************************************
3832
PUBLIC MEMBER FUNCTIONS
3933
******************************************************************************/
4034

4135
bool OTAStorage_MKRGSM::init()
4236
{
43-
return _fileUtils.begin();
37+
if (!_fileUtils.begin())
38+
return false;
39+
40+
if (_fileUtils.listFile(SSU_UPDATE_FILENAME) > 0)
41+
if (!_fileUtils.deleteFile(SSU_UPDATE_FILENAME))
42+
return false;
43+
44+
if (_fileUtils.listFile(SSU_CHECK_FILE_NAME) > 0)
45+
if (!_fileUtils.deleteFile(SSU_CHECK_FILE_NAME))
46+
return false;
4447
}
4548

46-
bool OTAStorage_MKRGSM::open()
49+
bool OTAStorage_MKRGSM::open(char const * /* file_name */)
4750
{
48-
auto size = _fileUtils.listFile(filename);
49-
_fileUtils.deleteFile(filename);
50-
return true;
51+
return true;
5152
}
5253

5354
size_t OTAStorage_MKRGSM::write(uint8_t const* const buf, size_t const num_bytes)
5455
{
55-
// Serial.print("size: ");
56-
// Serial.println(num_bytes);
57-
_fileUtils.appendFile(filename, (const char*)buf, num_bytes);
58-
59-
return num_bytes;
56+
_fileUtils.appendFile(SSU_UPDATE_FILENAME, (const char*)buf, num_bytes);
57+
return num_bytes;
6058
}
6159

6260
void OTAStorage_MKRGSM::close()
6361
{
62+
/* Nothing to do */
63+
}
64+
65+
void OTAStorage_MKRGSM::remove(char const * /* file_name */)
66+
{
67+
_fileUtils.deleteFile(SSU_UPDATE_FILENAME);
6468
}
6569

66-
void OTAStorage_MKRGSM::remove()
70+
bool OTAStorage_MKRGSM::rename(char const * /* old_file_name */, char const * /* new_file_name */)
6771
{
68-
_fileUtils.deleteFile(filename);
72+
/* Create a file 'UPDATE.OK' which is used by the SSU
73+
* 2nd stage bootloader to recognise that the update
74+
* went okay. Normally this is done by renaming 'UPDATE.BIN.TMP'
75+
* to 'UPDATE.BIN' but the SARE module does not support
76+
* a rename function.
77+
*/
78+
char c = 'X';
79+
return (_fileUtils.appendFile(SSU_CHECK_FILE_NAME, &c, sizeof(c)) == sizeof(c));
6980
}
7081

7182
void OTAStorage_MKRGSM::deinit()
7283
{
84+
/* Nothing to do */
7385
}

src/utility/ota/OTAStorage_MKRGSM.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,20 @@ class OTAStorage_MKRGSM : public OTAStorage
3434
{
3535
public:
3636

37-
OTAStorage_MKRGSM();
3837
virtual ~OTAStorage_MKRGSM() { }
3938

4039

4140
virtual Type type () override { return Type::MKRGSMFile; }
4241
virtual bool init () override;
43-
virtual bool open () override;
42+
virtual bool open (char const * file_name) override;
4443
virtual size_t write (uint8_t const * const buf, size_t const num_bytes) override;
4544
virtual void close () override;
46-
virtual void remove() override;
45+
virtual void remove(char const * file_name) override;
46+
virtual bool rename(char const * old_file_name, char const * new_file_name) override;
4747
virtual void deinit() override;
4848

4949
private:
50+
5051
GSMFileUtils _fileUtils;
5152

5253
};

0 commit comments

Comments
 (0)