ThingsBoard Client SDK 0.16.0
Client SDK to connect with ThingsBoard IoT Platform from IoT devices (Arduino, Espressif, etc.)
Loading...
Searching...
No Matches
OTA_Update_Callback.h
Go to the documentation of this file.
1#ifndef OTA_Update_Callback_h
2#define OTA_Update_Callback_h
3
4// Local includes.
5#include "Callback.h"
6#include "IUpdater.h"
8
9
10// OTA default values.
11uint8_t constexpr CHUNK_RETRIES = 12U;
12uint16_t constexpr CHUNK_SIZE = (4U * 1024U);
13uint64_t constexpr REQUEST_TIMEOUT_MS = (5U * 1000U * 1000U);
14
15
19class OTA_Update_Callback : public Callback<void, bool const &> {
20 public:
23
45 // because the whole chunk is saved into the heap before it can be processed and is then erased again after it has been used, default = CHUNK_SIZE
48 OTA_Update_Callback(char const * current_fw_title, char const * current_fw_version, IUpdater * updater, function finished_callback, Callback<void, size_t const &, size_t const &>::function progress_callback = nullptr, Callback<void>::function update_starting_callback = nullptr, uint8_t chunk_retries = CHUNK_RETRIES, uint16_t chunk_size = CHUNK_SIZE, uint64_t const & timeout_microseconds = REQUEST_TIMEOUT_MS);
49
50 ~OTA_Update_Callback() override = default;
51
57 char const * Get_Firmware_Title() const;
58
64 void Set_Firmware_Title(const char * current_fw_title);
65
71 char const * Get_Firmware_Version() const;
72
78 void Set_Firmware_Version(const char *current_fw_version);
79
84 IUpdater * Get_Updater() const;
85
90 void Set_Updater(IUpdater * updater);
91
95 size_t const & Get_Request_ID() const;
96
102 void Set_Request_ID(size_t const & request_id);
103
107 void Call_Progress_Callback(size_t const & current, size_t const & total) const;
108
114
117
124 void Set_Update_Starting_Callback(Callback<void>::function update_starting_callback);
125
131
136 void Set_Chunk_Retries(uint8_t chunk_retries);
137
143 uint16_t Get_Chunk_Size() const;
144
150 void Set_Chunk_Size(uint16_t chunk_size);
151
157
158 private:
159 char const *m_current_fw_title = {}; // Current firmware title of device
160 char const *m_current_fw_version = {}; // Current firmware version of device
161 IUpdater *m_updater = {}; // Updater implementation used to write firmware data
162 size_t m_request_id = {}; // Id the request was called with
163 Callback<void, size_t const &, size_t const &> m_progress_callback = {}; // Callback called when amount of downloaded chunks increased
164 Callback<void> m_update_starting_callback = {}; // Callback called when update is about to start (moment before topic subscription)
165 uint8_t m_chunk_retries = {}; // Maximum amount of retries for a single chunk to be downloaded and flashed successfully
166 uint16_t m_chunk_size = {}; // Size of chunks the firmware data will be split into
167 Timeoutable_Request m_request_timeout = {}; // Handles callback that will be called if request times out
168};
169
170#endif // OTA_Update_Callback_h
uint8_t constexpr CHUNK_RETRIES
Definition: OTA_Update_Callback.h:11
uint16_t constexpr CHUNK_SIZE
Definition: OTA_Update_Callback.h:12
uint64_t constexpr REQUEST_TIMEOUT_MS
Definition: OTA_Update_Callback.h:13
General purpose safe callback wrapper. Expects either c-style or c++ style function pointer,...
Definition: Callback.h:30
std::function< void(argument_types... arguments)> function
Callback signature.
Definition: Callback.h:34
Updater interface that contains the method that a class that can be used to flash given binary data o...
Definition: IUpdater.h:14
Over the air firmware update callback wrapper.
Definition: OTA_Update_Callback.h:19
Timeoutable_Request & Get_Request_Timeout()
Gets the request timeout callback.
Definition: OTA_Update_Callback.cpp:83
void Set_Firmware_Version(const char *current_fw_version)
Sets the current firmware version.
Definition: OTA_Update_Callback.cpp:31
void Call_Progress_Callback(size_t const &current, size_t const &total) const
Calls the progress callback that was subscribed, when this class instance was initally created.
Definition: OTA_Update_Callback.cpp:51
uint8_t Get_Chunk_Retries() const
Gets the amount of times we attempt to download each chunk of the OTA firmware binary file.
Definition: OTA_Update_Callback.cpp:67
void Set_Request_ID(size_t const &request_id)
Sets the unique request identifier that is connected to the original request.
Definition: OTA_Update_Callback.cpp:47
void Set_Firmware_Title(const char *current_fw_title)
Sets the current firmware title.
Definition: OTA_Update_Callback.cpp:23
uint16_t Get_Chunk_Size() const
Gets the size of the chunks that the firmware binary data will be split into.
Definition: OTA_Update_Callback.cpp:75
OTA_Update_Callback()=default
Constructs empty callbacks, will result in never being called. Internals are simply default construct...
void Set_Chunk_Size(uint16_t chunk_size)
Sets the size of the chunks that the firmware binary data will be split into.
Definition: OTA_Update_Callback.cpp:79
IUpdater * Get_Updater() const
Gets the updater implementation, used to write the actual firmware data into the needed memory locati...
Definition: OTA_Update_Callback.cpp:35
void Set_Updater(IUpdater *updater)
Sets the updater implementation, used to write the actual firmware data into the needed memory locati...
Definition: OTA_Update_Callback.cpp:39
void Set_Update_Starting_Callback(Callback< void >::function update_starting_callback)
Sets the update starting callback method.
Definition: OTA_Update_Callback.cpp:63
size_t const & Get_Request_ID() const
Gets the unique request identifier that is connected to the original request.
Definition: OTA_Update_Callback.cpp:43
~OTA_Update_Callback() override=default
char const * Get_Firmware_Version() const
Gets the current firmware version.
Definition: OTA_Update_Callback.cpp:27
void Call_Update_Starting_Callback() const
Calls the update starting callback that was subscribed, when this class instance was initally created...
Definition: OTA_Update_Callback.cpp:59
void Set_Progress_Callback(Callback< void, size_t const &, size_t const & >::function progress_callback)
Sets the progress callback method.
Definition: OTA_Update_Callback.cpp:55
void Set_Chunk_Retries(uint8_t chunk_retries)
Sets the amount of times we attempt to download each chunk of the OTA firmware binary file.
Definition: OTA_Update_Callback.cpp:71
char const * Get_Firmware_Title() const
Gets the current firmware title.
Definition: OTA_Update_Callback.cpp:19
General purpose request callback that can timeout if the response to the request is not received in t...
Definition: Timeoutable_Request.h:10