KPN Things Device SDK
thingsml_http_firmware.h
Go to the documentation of this file.
1/* _ __ ____ _ _
2 * | |/ / | _ \ | \ | |
3 * | ' / | |_) | | \| |
4 * | . \ | __/ | |\ |
5 * |_|\_\ |_| |_| \_|
6 *
7 * (c) 2021 KPN
8 * License: MIT License.
9 * Author: Joseph Verburg, Jan Bogaerts
10 *
11 *
12 * ThingsML helper for http firmware downloads
13 *
14 */
15#ifndef THINGSML_HTTP_FIRMWARE
16#define THINGSML_HTTP_FIRMWARE
17
18#include "thingsml_http.h"
19#include <string.h>
20#include <stdio.h>
21
22namespace ThingsML {
24 public:
25
26 HttpFirmwareDownload(const char baseName[]): _firmwareMessage(baseName), _url(SENML_NAME_URL), _token(SENML_NAME_TOKEN), _partSize(256) {
27 _firmwareMessage.add(_url);
28 _firmwareMessage.add(_token);
29 };
30 HttpFirmwareDownload(const char baseName[], int partSize): _firmwareMessage(baseName), _url(SENML_NAME_URL), _token(SENML_NAME_TOKEN), _partSize(partSize) {
31 _firmwareMessage.add(_url);
32 _firmwareMessage.add(_token);
33 };
34
38 void setPartSize(int partSize) {
39 this->_partSize = partSize;
40 }
41
46 return this->_partSize;
47 }
48
52 int getNumParts(int totalSize) {
53 return (totalSize / _partSize) + (totalSize % _partSize == 0 ? 0 : 1);
54 }
55
60 size_t getFirmwarePartRequest(int partIndex, char buffer[], int bufferLength, const char host[]);
61
67 bool parseFirmwareMessage(const char message[], int messageLength);
68
72 static bool isFirmwareMessage(const char message[], int messageLength);
73
80 static int getTotalSizeFromResponse(const char message[], int messageLength);
81
82
83 static uint32_t getCRC32FromResponse(const char message[], int messageLength);
84
85 static uint32_t calculateCRC32FromBody(const char body[], int bodyLength);
86
93
99 int getPort();
100
101 private:
102 SenMLPack _firmwareMessage;
104 SenMLStringActuator _token;
105 int _partSize = 256;
106 const char * getUrlPath();
107 };
108}
109
110#endif
bool add(SenMLBase &item)
Definition: senml_basepack.cpp:33
Definition: senml_pack.h:68
Definition: senml_string_actuator.h:24
Definition: thingsml_http_firmware.h:23
static bool isFirmwareMessage(const char message[], int messageLength)
Definition: thingsml_http_firmware.cpp:188
int getPort()
Definition: thingsml_http_firmware.cpp:161
size_t getFirmwarePartRequest(int partIndex, char buffer[], int bufferLength, const char host[])
Definition: thingsml_http_firmware.cpp:43
static uint32_t calculateCRC32FromBody(const char body[], int bodyLength)
Definition: thingsml_http_firmware.cpp:289
void setPartSize(int partSize)
Definition: thingsml_http_firmware.h:38
HttpFirmwareDownload(const char baseName[], int partSize)
Definition: thingsml_http_firmware.h:30
String getHost()
Definition: thingsml_http_firmware.cpp:137
HttpFirmwareDownload(const char baseName[])
Definition: thingsml_http_firmware.h:26
bool parseFirmwareMessage(const char message[], int messageLength)
Definition: thingsml_http_firmware.cpp:112
int getNumParts(int totalSize)
Definition: thingsml_http_firmware.h:52
int getPartSize()
Definition: thingsml_http_firmware.h:45
static uint32_t getCRC32FromResponse(const char message[], int messageLength)
Definition: thingsml_http_firmware.cpp:256
static int getTotalSizeFromResponse(const char message[], int messageLength)
Definition: thingsml_http_firmware.cpp:205
#define String
Definition: defaults.h:47
Definition: thingsml_http.cpp:4
#define SENML_NAME_TOKEN
Definition: senml_enums.h:200
#define SENML_NAME_URL
Definition: senml_enums.h:199