Skip to content

Commit 1cbae74

Browse files
committed
Committing module OTAStorage_Nina which allows to store ota images on the storage space provided by the nina module
1 parent c2c0718 commit 1cbae74

File tree

4 files changed

+158
-2
lines changed

4 files changed

+158
-2
lines changed

src/ArduinoIoTCloud_Config.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#define OTA_STORAGE_MKRMEM (0)
2727
#endif
2828

29+
#ifndef OTA_STORAGE_NINA
30+
#define OTA_STORAGE_NINA (0)
31+
#endif
32+
2933
/******************************************************************************
3034
* AUTOMATIC CONFIGURED DEFINES
3135
******************************************************************************/
@@ -34,7 +38,7 @@
3438
#define OTA_STORAGE_MKRMEM (0)
3539
#endif
3640

37-
#if OTA_STORAGE_MKRMEM
41+
#if OTA_STORAGE_MKRMEM || OTA_STORAGE_NINA
3842
#define OTA_ENABLED (1)
3943
#else
4044
#define OTA_ENABLED (0)

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+
Nina = 1,
4445
};
4546

4647
virtual Type type () = 0;

src/utility/ota/OTAStorage_Nina.cpp

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 */

src/utility/ota/OTAStorage_Nina.h

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
#ifndef ARDUINO_OTA_STORAGE_NINA_H_
19+
#define ARDUINO_OTA_STORAGE_NINA_H_
20+
21+
/******************************************************************************
22+
* INCLUDE
23+
******************************************************************************/
24+
25+
#include <ArduinoIoTCloud_Config.h>
26+
#if OTA_STORAGE_NINA
27+
28+
#include "OTAStorage.h"
29+
30+
#include <WiFiNINA.h>
31+
32+
/******************************************************************************
33+
* CLASS DECLARATION
34+
******************************************************************************/
35+
36+
class OTAStorage_Nina : public OTAStorage
37+
{
38+
public:
39+
40+
OTAStorage_Nina();
41+
virtual ~OTAStorage_Nina() { }
42+
43+
44+
virtual Type type () override { return Type::Nina; }
45+
virtual bool init () override;
46+
virtual bool open (char const * file_name) override;
47+
virtual size_t write (uint8_t const * const buf, size_t const num_bytes) override;
48+
virtual void close () override;
49+
virtual void remove(char const * file_name) override;
50+
virtual bool rename(char const * old_file_name, char const * new_file_name) override;
51+
virtual void deinit() override;
52+
53+
54+
private:
55+
56+
WiFiStorageFile * _file;
57+
58+
};
59+
60+
#endif /* OTA_STORAGE_NINA */
61+
62+
#endif /* ARDUINO_OTA_STORAGE_NINA_H_ */

0 commit comments

Comments
 (0)