forked from arduino-libraries/Arduino_ESP32_OTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino_ESP32_OTA.h
101 lines (82 loc) · 3.23 KB
/
Arduino_ESP32_OTA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
This file is part of Arduino_ESP32_OTA.
Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
This software is released under the GNU General Public License version 3,
which covers the main part of arduino-cli.
The terms of this license can be found at:
https://www.gnu.org/licenses/gpl-3.0.en.html
You can be released from the requirements of the above licenses by purchasing
a commercial license. Buying such a license is mandatory if you want to modify or
otherwise use the software for commercial activities involving the Arduino
software without disclosing the source code of your own applications. To purchase
a commercial license, send an email to [email protected].
*/
#ifndef ARDUINO_ESP32_OTA_H_
#define ARDUINO_ESP32_OTA_H_
/******************************************************************************
* INCLUDE
******************************************************************************/
#include <Arduino_DebugUtils.h>
#include <WiFiClientSecure.h>
#include "decompress/utility.h"
/******************************************************************************
DEFINES
******************************************************************************/
#if defined (ARDUINO_NANO_ESP32)
#define ARDUINO_ESP32_OTA_MAGIC 0x23410070
#else
#define ARDUINO_ESP32_OTA_MAGIC 0x45535033
#endif
/******************************************************************************
CONSTANTS
******************************************************************************/
static uint32_t const ARDUINO_ESP32_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms = 10000;
static uint32_t const ARDUINO_ESP32_OTA_BINARY_HEADER_RECEIVE_TIMEOUT_ms = 10000;
static uint32_t const ARDUINO_ESP32_OTA_BINARY_BYTE_RECEIVE_TIMEOUT_ms = 2000;
/******************************************************************************
* TYPEDEF
******************************************************************************/
typedef uint8_t(*ArduinoEsp32OtaReadByteFuncPointer)(void);
typedef void(*ArduinoEsp32OtaWriteByteFuncPointer)(uint8_t);
/******************************************************************************
* CLASS DECLARATION
******************************************************************************/
class Arduino_ESP32_OTA
{
public:
enum class Error : int
{
None = 0,
NoOtaStorage = -2,
OtaStorageInit = -3,
OtaHeaderLength = -5,
OtaHeaderCrc = -6,
OtaHeaterMagicNumber = -7,
ParseHttpHeader = -8,
UrlParse = -9,
ServerConnect = -10,
HttpHeader = -11,
OtaDownload = -12,
OtaHeaderTimeout = -13,
HttpResponse = -14,
OtaStorageEnd = -15,
};
Arduino_ESP32_OTA();
virtual ~Arduino_ESP32_OTA() { }
Arduino_ESP32_OTA::Error begin();
void setCACert (const char *rootCA);
void setCACertBundle(const uint8_t * bundle);
int download(const char * ota_url);
uint8_t read_byte_from_network();
void write_byte_to_flash(uint8_t data);
Arduino_ESP32_OTA::Error update();
void reset();
private:
Client * _client;
OtaHeader _ota_header;
size_t _ota_size;
uint32_t _crc32;
const char * _ca_cert;
const uint8_t * _ca_cert_bundle;
};
#endif /* ARDUINO_ESP32_OTA_H_ */