-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGSMOTAUpdater.h
74 lines (60 loc) · 2.14 KB
/
GSMOTAUpdater.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
#ifndef GSMOTAUPDATER_H
#define GSMOTAUPDATER_H
#include <Arduino.h>
#include <MD5Builder.h>
#include <FS.h>
#include <Update.h>
#define DEBUG true
class GSMOTAUpdater
{
public:
GSMOTAUpdater();
int chunkSize = 25000; // bytes
char md5Hash[33] = ""; // md5 hash for verification
void init(const char *, int, const char *, unsigned long, HardwareSerial *, FS *);
bool download(const char *);
bool verifyMD5(const char *, char *);
bool performUpdate(const char *);
typedef std::function<void(unsigned long, unsigned long)> GSMOTAUpdater_Progress;
void onDownloadFirmwareProgress(GSMOTAUpdater_Progress fn);
private:
HardwareSerial *SerialAT;
fs::FS *fileSystem = nullptr;
bool isInitialized;
bool isTCPConnected;
bool wasConnectionLost;
bool waitingForData;
bool isHeadersRead;
bool chunkDownloaded;
bool isDownloadComplete;
unsigned long fileSize;
unsigned long currentChunkByte;
unsigned long currentByte;
unsigned long rangeStart;
unsigned long rangeEnd;
String serverAddress;
int serverPort;
String downloadPath;
String ATResponse;
bool sendATCommand(const char *, const char *, unsigned long);
void writeDataToFile(File &, String &);
void connectionClosed();
void rstATResponse();
void hexStringToBinary(const char*, unsigned char*);
static void downloadFirmwareProgress(unsigned long, unsigned long);
static GSMOTAUpdater_Progress _progress_callback;
};
#endif
#if defined ESP32
#define HEAP_AVAILABLE() ESP.getFreeHeap()
#ifdef ESP32
#define GOTA_LOG_FORMAT(letter, format) "[" #letter "][%s:%u][H:%u] %s(): " format "\r\n", __FILE__, __LINE__, HEAP_AVAILABLE(), __FUNCTION__
#if defined DEBUG_ESP_PORT
#define gota_log_d(format, ...) DEBUG_ESP_PORT.printf(GOTA_LOG_FORMAT(N, format), ##__VA_ARGS__);
#define gota_log_e(format, ...) DEBUG_ESP_PORT.printf(GOTA_LOG_FORMAT(E, format), ##__VA_ARGS__);
#else
#define gota_log_d(format, ...) Serial.printf(GOTA_LOG_FORMAT(N, format), ##__VA_ARGS__);
#define gota_log_e(format, ...) Serial.printf(GOTA_LOG_FORMAT(E, format), ##__VA_ARGS__);
#endif
#endif
#endif