Skip to content

Commit 2857c98

Browse files
committed
Conditional compilation of OTA logic only if OTA_ENABLED is defined to 1
1 parent 14a8f54 commit 2857c98

File tree

6 files changed

+54
-21
lines changed

6 files changed

+54
-21
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,29 @@ static unsigned long getTime()
5959
CTOR/DTOR
6060
******************************************************************************/
6161

62-
ArduinoIoTCloudTCP::ArduinoIoTCloudTCP():
63-
_lastSyncRequestTickTime{0},
64-
_mqtt_data_buf{0},
65-
_mqtt_data_len{0},
66-
_mqtt_data_request_retransmit{false},
67-
_sslClient(NULL),
62+
ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
63+
: _lastSyncRequestTickTime{0}
64+
, _mqtt_data_buf{0}
65+
, _mqtt_data_len{0}
66+
, _mqtt_data_request_retransmit{false}
67+
, _sslClient(NULL)
6868
#ifdef BOARD_ESP
69-
_password(""),
69+
, _password("")
7070
#endif
71-
_mqttClient(NULL),
72-
_syncStatus{ArduinoIoTSynchronizationStatus::SYNC_STATUS_SYNCHRONIZED},
73-
_stdinTopic(""),
74-
_stdoutTopic(""),
75-
_shadowTopicOut(""),
76-
_shadowTopicIn(""),
77-
_dataTopicOut(""),
78-
_dataTopicIn(""),
79-
_ota_topic_in{""},
80-
_ota_logic{nullptr},
81-
_ota_storage_type{static_cast<int>(OTAStorage::Type::NotAvailable)},
82-
_ota_error{static_cast<int>(OTAError::None)}
71+
, _mqttClient(NULL)
72+
, _syncStatus{ArduinoIoTSynchronizationStatus::SYNC_STATUS_SYNCHRONIZED}
73+
, _stdinTopic("")
74+
, _stdoutTopic("")
75+
, _shadowTopicOut("")
76+
, _shadowTopicIn("")
77+
, _dataTopicOut("")
78+
, _dataTopicIn("")
79+
, _ota_topic_in{""}
80+
#if OTA_ENABLED
81+
, _ota_logic{nullptr}
82+
, _ota_storage_type{static_cast<int>(OTAStorage::Type::NotAvailable)}
83+
, _ota_error{static_cast<int>(OTAError::None)}
84+
#endif /* OTA_ENABLED */
8385
{
8486

8587
}
@@ -207,6 +209,7 @@ void ArduinoIoTCloudTCP::printDebugInfo()
207209
Debug.print(DBG_INFO, "MQTT Broker: %s:%d", _brokerAddress.c_str(), _brokerPort);
208210
}
209211

212+
#if OTA_ENABLED
210213
void ArduinoIoTCloudTCP::setOTAStorage(OTAStorage & ota_storage)
211214
{
212215
_ota_storage_type = static_cast<int>(ota_storage.type());
@@ -215,6 +218,7 @@ void ArduinoIoTCloudTCP::setOTAStorage(OTAStorage & ota_storage)
215218
if(_ota_logic) delete _ota_logic;
216219
_ota_logic = new OTALogic(ota_storage);
217220
}
221+
#endif /* OTA_ENABLED */
218222

219223
int ArduinoIoTCloudTCP::reconnect()
220224
{

src/ArduinoIoTCloudTCP.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* INCLUDE
2323
******************************************************************************/
2424

25+
#include <ArduinoIoTCloud_Config.h>
26+
2527
#include <ArduinoIoTCloud.h>
2628

2729
#ifdef BOARD_HAS_ECCX08
@@ -33,8 +35,10 @@
3335

3436
#include <ArduinoMqttClient.h>
3537

36-
#include "utility/ota/OTALogic.h"
37-
#include "utility/ota/OTAStorage.h"
38+
#if OTA_ENABLED
39+
#include "utility/ota/OTALogic.h"
40+
#include "utility/ota/OTAStorage.h"
41+
#endif /* OTA_ENABLED */
3842

3943
/******************************************************************************
4044
CONSTANTS
@@ -76,7 +80,9 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
7680
inline String getBrokerAddress() const { return _brokerAddress; }
7781
inline uint16_t getBrokerPort () const { return _brokerPort; }
7882

83+
#if OTA_ENABLED
7984
void setOTAStorage(OTAStorage & ota_storage);
85+
#endif /* OTA_ENABLED */
8086

8187
// Clean up existing Mqtt connection, create a new one and initialize it
8288
int reconnect();
@@ -121,9 +127,11 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
121127
String _dataTopicIn;
122128
String _ota_topic_in;
123129

130+
#if OTA_ENABLED
124131
OTALogic * _ota_logic;
125132
int _ota_storage_type;
126133
int _ota_error;
134+
#endif /* OTA_ENABLED */
127135

128136
inline String getTopic_stdin () { return String("/a/d/" + getDeviceId() + "/s/i"); }
129137
inline String getTopic_stdout () { return String("/a/d/" + getDeviceId() + "/s/o"); }

src/utility/ota/OTALogic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* INCLUDE
2020
******************************************************************************/
2121

22+
#include <ArduinoIoTCloud_Config.h>
23+
#if OTA_ENABLED
24+
2225
#include "OTALogic.h"
2326

2427
#ifndef HOST
@@ -242,3 +245,5 @@ void OTALogic::init_ota_binary_data()
242245
_ota_bin_data.bytes_received = 0;
243246
_ota_bin_data.crc32 = crc_init();
244247
}
248+
249+
#endif /* OTA_ENABLED */

src/utility/ota/OTALogic.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
* INCLUDE
2323
******************************************************************************/
2424

25+
#include <ArduinoIoTCloud_Config.h>
26+
#if OTA_ENABLED
27+
2528
#include "OTAStorage.h"
2629

2730
#include "crc.h"
@@ -111,4 +114,6 @@ class OTALogic
111114

112115
};
113116

117+
#endif /* OTA_ENABLED */
118+
114119
#endif /* ARDUINO_OTA_LOGIC_H_ */

src/utility/ota/crc.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
* - ReflectOut = True
1414
* - Algorithm = table-driven
1515
*/
16+
17+
#include <ArduinoIoTCloud_Config.h>
18+
#if OTA_ENABLED
19+
1620
#include "crc.h" /* include the header file generated with pycrc */
1721
#include <stdlib.h>
1822
#include <stdint.h>
@@ -70,3 +74,5 @@ crc_t crc_update(crc_t crc, const void *data, size_t data_len)
7074
}
7175
return crc & 0xffffffff;
7276
}
77+
78+
#endif /* OTA_ENABLED */

src/utility/ota/crc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
#ifndef CRC_H
4141
#define CRC_H
4242

43+
#include <ArduinoIoTCloud_Config.h>
44+
#if OTA_ENABLED
45+
4346
#include <stdlib.h>
4447
#include <stdint.h>
4548

@@ -104,3 +107,5 @@ static inline crc_t crc_finalize(crc_t crc)
104107
#endif
105108

106109
#endif /* CRC_H */
110+
111+
#endif /* OTA_ENABLED */

0 commit comments

Comments
 (0)