Skip to content

Commit dda2480

Browse files
committed
Cleaning up OTA logic necessary for parsing chunked download from MQTT broker
1 parent f732e66 commit dda2480

11 files changed

+18
-903
lines changed

src/ArduinoIoTCloudTCP.cpp

+7-48
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,11 @@
2828
#include "tls/utility/CryptoUtil.h"
2929
#endif
3030

31+
#include "utility/ota/OTA.h"
3132
#include "utility/ota/FlashSHA256.h"
32-
#include "utility/ota/OTAStorage_SNU.h"
33-
#include "utility/ota/OTAStorage_SFU.h"
34-
#include "utility/ota/OTAStorage_SSU.h"
3533

3634
#include "cbor/CBOREncoder.h"
3735

38-
/******************************************************************************
39-
GLOBAL VARIABLES
40-
******************************************************************************/
41-
42-
#if OTA_STORAGE_SSU
43-
static OTAStorage_SSU ota_storage_ssu;
44-
#elif OTA_STORAGE_SFU
45-
static OTAStorage_SFU ota_storage_sfu;
46-
#elif OTA_STORAGE_SNU
47-
static OTAStorage_SNU ota_storage_snu;
48-
#endif
49-
5036
/******************************************************************************
5137
GLOBAL CONSTANTS
5238
******************************************************************************/
@@ -155,28 +141,18 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
155141
_dataTopicIn = getTopic_datain();
156142
_ota_topic_in = getTopic_ota_in();
157143

158-
#if OTA_STORAGE_SSU
159-
setOTAStorage(ota_storage_ssu);
160-
#elif OTA_STORAGE_SFU
161-
setOTAStorage(ota_storage_sfu);
162-
#elif OTA_STORAGE_SNU
163-
setOTAStorage(ota_storage_snu);
164-
#endif
144+
#if OTA_ENABLED
145+
addPropertyReal(_ota_error, "OTA_ERROR", Permission::Read);
146+
addPropertyReal(_ota_img_sha256, "OTA_SHA256", Permission::Read);
147+
addPropertyReal(_ota_url, "OTA_URL", Permission::ReadWrite).onSync(DEVICE_WINS);
148+
addPropertyReal(_ota_req, "OTA_REQ", Permission::ReadWrite).onSync(DEVICE_WINS).onUpdate(ArduinoIoTCloudTCP::on_OTA_REQ_Update);
149+
#endif /* OTA_ENABLED */
165150

166151
return 1;
167152
}
168153

169154
void ArduinoIoTCloudTCP::update()
170155
{
171-
#if OTA_ENABLED
172-
/* If a _ota_logic object has been instantiated then we are spinning its
173-
* 'update' method here in order to process incoming data and generally
174-
* to transition to the OTA logic update states.
175-
*/
176-
//OTAError const err = _ota_logic.update();
177-
//_ota_error = static_cast<int>(err);
178-
#endif /* OTA_ENABLED */
179-
180156
/* Run through the state machine. */
181157
State next_state = _state;
182158
switch (_state)
@@ -208,17 +184,6 @@ void ArduinoIoTCloudTCP::printDebugInfo()
208184
DBG_INFO("MQTT Broker: %s:%d", _brokerAddress.c_str(), _brokerPort);
209185
}
210186

211-
#if OTA_ENABLED
212-
void ArduinoIoTCloudTCP::setOTAStorage(OTAStorage & ota_storage)
213-
{
214-
addPropertyReal(_ota_error, "OTA_ERROR", Permission::Read);
215-
addPropertyReal(_ota_img_sha256, "OTA_SHA256", Permission::Read);
216-
addPropertyReal(_ota_url, "OTA_URL", Permission::ReadWrite).onSync(DEVICE_WINS);
217-
addPropertyReal(_ota_req, "OTA_REQ", Permission::ReadWrite).onSync(DEVICE_WINS).onUpdate(ArduinoIoTCloudTCP::on_OTA_REQ_Update);
218-
_ota_logic.setOTAStorage(ota_storage);
219-
}
220-
#endif /* OTA_ENABLED */
221-
222187
/******************************************************************************
223188
* PRIVATE MEMBER FUNCTIONS
224189
******************************************************************************/
@@ -372,12 +337,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
372337
execCloudEventCallback(ArduinoIoTCloudEvent::SYNC);
373338
_state = State::Connected;
374339
}
375-
376-
#if OTA_ENABLED
377-
if (_ota_topic_in == topic) {
378-
_ota_logic.onOTADataReceived(bytes, length);
379-
}
380-
#endif /* OTA_ENABLED */
381340
}
382341

383342
void ArduinoIoTCloudTCP::sendPropertiesToCloud()

src/ArduinoIoTCloudTCP.h

-10
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535

3636
#include <ArduinoMqttClient.h>
3737

38-
#if OTA_ENABLED
39-
#include "utility/ota/OTALogic.h"
40-
#include "utility/ota/OTAStorage.h"
41-
#endif /* OTA_ENABLED */
42-
4338
/******************************************************************************
4439
CONSTANTS
4540
******************************************************************************/
@@ -80,10 +75,6 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
8075
inline String getBrokerAddress() const { return _brokerAddress; }
8176
inline uint16_t getBrokerPort () const { return _brokerPort; }
8277

83-
#if OTA_ENABLED
84-
void setOTAStorage(OTAStorage & ota_storage);
85-
#endif /* OTA_ENABLED */
86-
8778

8879
private:
8980
static const int MQTT_TRANSMIT_BUFFER_SIZE = 256;
@@ -127,7 +118,6 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
127118
String _ota_topic_in;
128119

129120
#if OTA_ENABLED
130-
OTALogic _ota_logic;
131121
int _ota_error;
132122
String _ota_img_sha256;
133123
String _ota_url;

src/utility/ota/OTAStorage.h renamed to src/utility/ota/OTA.h

+11-21
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,26 @@
1515
a commercial license, send an email to [email protected].
1616
*/
1717

18-
#ifndef ARDUINO_OTA_STORAGE_H_
19-
#define ARDUINO_OTA_STORAGE_H_
18+
#ifndef ARDUINO_OTA_LOGIC_H_
19+
#define ARDUINO_OTA_LOGIC_H_
2020

2121
/******************************************************************************
2222
* INCLUDE
2323
******************************************************************************/
2424

25-
#include <stdlib.h>
26-
#include <stdint.h>
27-
#include <stdbool.h>
25+
#include <AIoTC_Config.h>
26+
#if OTA_ENABLED
2827

2928
/******************************************************************************
30-
* CLASS DECLARATION
29+
* TYPEDEF
3130
******************************************************************************/
3231

33-
class OTAStorage
32+
enum class OTAError : int
3433
{
35-
public:
36-
37-
virtual ~OTAStorage() { }
38-
39-
40-
virtual bool init () = 0;
41-
virtual bool open () = 0;
42-
virtual size_t write (uint8_t const * const buf, size_t const num_bytes) = 0;
43-
virtual void close () = 0;
44-
virtual void remove() = 0;
45-
virtual bool rename() = 0;
46-
virtual void deinit() = 0;
47-
34+
None = 0,
35+
DownloadFailed = 1,
4836
};
4937

50-
#endif /* ARDUINO_OTA_STORAGE_H_ */
38+
#endif /* OTA_ENABLED */
39+
40+
#endif /* ARDUINO_OTA_LOGIC_H_ */

0 commit comments

Comments
 (0)