Skip to content

Commit ba5faf4

Browse files
committed
Add missing libraries
1 parent 543c75b commit ba5faf4

File tree

4 files changed

+148
-1
lines changed

4 files changed

+148
-1
lines changed

src/ArduinoCloud.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "CloudSerial.h"
77
#include "SerialFlashStorage.h"
8-
//#include "SFU.h"
8+
#include "SFU.h"
99

1010
const static char server[] = "a19g5nbe27wn47.iot.us-east-1.amazonaws.com"; //"xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com";
1111

src/OTAStorage.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright (c) 2017 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef _OTA_STORAGE_H_INCLUDED
20+
#define _OTA_STORAGE_H_INCLUDED
21+
22+
class OTAStorage {
23+
public:
24+
virtual int open(int length) = 0;
25+
virtual size_t write(uint8_t* data, size_t size) = 0;
26+
virtual void close() = 0;
27+
virtual void clear() = 0;
28+
virtual void apply() = 0;
29+
30+
virtual long maxSize() {
31+
return ((256 * 1024) - 0x2000);
32+
}
33+
};
34+
35+
#endif

src/SerialFlashStorage.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright (c) 2017 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "SerialFlashStorage.h"
20+
21+
#define UPDATE_FILE "UPDATE.BIN"
22+
23+
int SerialFlashStorageClass::open(int contentLength)
24+
{
25+
if (!SerialFlash.begin(SERIAL_FLASH_CS)) {
26+
return 0;
27+
}
28+
29+
while (!SerialFlash.ready()) {}
30+
31+
if (SerialFlash.exists(UPDATE_FILE)) {
32+
SerialFlash.remove(UPDATE_FILE);
33+
}
34+
35+
if (SerialFlash.create(UPDATE_FILE, contentLength)) {
36+
_file = SerialFlash.open(UPDATE_FILE);
37+
}
38+
39+
if (!_file) {
40+
return 0;
41+
}
42+
43+
return 1;
44+
}
45+
46+
size_t SerialFlashStorageClass::write(uint8_t *data, size_t size)
47+
{
48+
while (!SerialFlash.ready()) {}
49+
int ret = _file.write(data, size);
50+
return ret;
51+
}
52+
53+
void SerialFlashStorageClass::close()
54+
{
55+
_file.close();
56+
}
57+
58+
void SerialFlashStorageClass::clear()
59+
{
60+
SerialFlash.remove(UPDATE_FILE);
61+
}
62+
63+
void SerialFlashStorageClass::apply()
64+
{
65+
// just reset, SDU copies the data to flash
66+
NVIC_SystemReset();
67+
}
68+
69+
SerialFlashStorageClass SerialFlashStorage;

src/SerialFlashStorage.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright (c) 2017 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef _SERIALFLASH_STORAGE_H_INCLUDED
20+
#define _SERIALFLASH_STORAGE_H_INCLUDED
21+
22+
#include <SerialFlash.h>
23+
24+
#include "OTAStorage.h"
25+
26+
#define SERIAL_FLASH_BUFFER_SIZE 64
27+
#define SERIAL_FLASH_CS 5
28+
29+
class SerialFlashStorageClass : public OTAStorage {
30+
public:
31+
virtual int open(int length);
32+
virtual size_t write(uint8_t* data, size_t size);
33+
virtual void close();
34+
virtual void clear();
35+
virtual void apply();
36+
37+
private:
38+
SerialFlashFile _file;
39+
};
40+
41+
extern SerialFlashStorageClass SerialFlashStorage;
42+
43+
#endif

0 commit comments

Comments
 (0)