Skip to content

Commit aa74cf9

Browse files
committed
Adding comment based visual separators between the various sections of a C++ header/source file
1 parent 1d40d14 commit aa74cf9

13 files changed

+199
-31
lines changed

src/ArduinoIoTCloud.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@
1515
a commercial license, send an email to [email protected].
1616
*/
1717

18+
/******************************************************************************
19+
* INCLUDE
20+
******************************************************************************/
21+
1822
#include <ArduinoIoTCloud.h>
1923

24+
/******************************************************************************
25+
* PUBLIC MEMBER FUNCTIONS
26+
******************************************************************************/
27+
2028
void ArduinoIoTCloudClass::addPropertyReal(ArduinoCloudProperty& property, String name, permissionType permission_type, long seconds, void(*fn)(void), float minDelta, void(*synFn)(ArduinoCloudProperty & property)) {
2129
addPropertyReal(property, name, -1, permission_type, seconds, fn, minDelta, synFn);
2230
}
@@ -116,6 +124,10 @@ void ArduinoIoTCloudClass::addCallback(ArduinoIoTCloudEvent const event, OnCloud
116124
}
117125
};
118126

127+
/******************************************************************************
128+
* PRIVATE MEMBER FUNCTIONS
129+
******************************************************************************/
130+
119131
void ArduinoIoTCloudClass::execCloudEventCallback(OnCloudEventCallback& callback, void* callback_arg) {
120132
if (callback) {
121133
(*callback)(callback_arg);

src/ArduinoIoTCloud.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#ifndef ARDUINO_IOT_CLOUD_H
1919
#define ARDUINO_IOT_CLOUD_H
2020

21+
/******************************************************************************
22+
* INCLUDE
23+
******************************************************************************/
24+
2125
#include <ArduinoIoTCloud_Defines.h>
2226

2327

@@ -33,6 +37,9 @@
3337

3438
#include "CloudSerial.h"
3539

40+
/******************************************************************************
41+
TYPEDEF
42+
******************************************************************************/
3643

3744
typedef enum {
3845
READ = 0x01,
@@ -63,9 +70,10 @@ enum class ArduinoIoTCloudEvent {
6370
typedef void (*CallbackFunc)(void);
6471
typedef void (*OnCloudEventCallback)(void * /* arg */);
6572

66-
/*************************************************
67-
Pure Virtual Class Definition
68-
**************************************************/
73+
/******************************************************************************
74+
* CLASS DECLARATION
75+
******************************************************************************/
76+
6977
class ArduinoIoTCloudClass {
7078

7179
public:

src/ArduinoIoTCloudLPWAN.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
software without disclosing the source code of your own applications. To purchase
1515
a commercial license, send an email to [email protected].
1616
*/
17+
18+
/******************************************************************************
19+
* INCLUDE
20+
******************************************************************************/
21+
1722
#include "ArduinoIoTCloud_Defines.h"
23+
1824
#ifdef HAS_LORA
1925

2026
#include<ArduinoIoTCloudLPWAN.h>
@@ -24,12 +30,20 @@
2430
RTCZero rtc;
2531
#endif
2632

33+
/******************************************************************************
34+
CTOR/DTOR
35+
******************************************************************************/
36+
2737
ArduinoIoTCloudLPWAN::ArduinoIoTCloudLPWAN() :
2838
_connection(NULL) {}
2939

3040
ArduinoIoTCloudLPWAN::~ArduinoIoTCloudLPWAN() {
3141
}
3242

43+
/******************************************************************************
44+
* PUBLIC MEMBER FUNCTIONS
45+
******************************************************************************/
46+
3347
int ArduinoIoTCloudLPWAN::connect() {
3448
_connection->connect();
3549
const int state = _connection->getStatus() == NetworkConnectionState::INIT ? 1 : 0;
@@ -189,6 +203,10 @@ int ArduinoIoTCloudLPWAN::writeShadowOut(const byte data[], int length) {
189203
return 1;
190204
}
191205

206+
/******************************************************************************
207+
* PRIVATE MEMBER FUNCTIONS
208+
******************************************************************************/
209+
192210
void ArduinoIoTCloudLPWAN::sendPropertiesToCloud() {
193211
uint8_t data[DEFAULT_CBOR_LORA_MSG_SIZE];
194212
int const length = Thing.encode(data, sizeof(data), true);
@@ -197,6 +215,10 @@ void ArduinoIoTCloudLPWAN::sendPropertiesToCloud() {
197215
}
198216
}
199217

218+
/******************************************************************************
219+
* EXTERN DEFINITION
220+
******************************************************************************/
221+
200222
ArduinoIoTCloudLPWAN ArduinoCloud;
201223

202224
#endif

src/ArduinoIoTCloudLPWAN.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,23 @@
1818
#ifndef ARDUINO_IOT_CLOUD_LPWAN_H
1919
#define ARDUINO_IOT_CLOUD_LPWAN_H
2020

21+
/******************************************************************************
22+
* INCLUDE
23+
******************************************************************************/
24+
2125
#include <ArduinoIoTCloud.h>
2226
#include <Arduino_ConnectionHandler.h>
2327

28+
/******************************************************************************
29+
CONSTANTS
30+
******************************************************************************/
31+
2432
static uint8_t const DEFAULT_CBOR_LORA_MSG_SIZE = 255;
2533

34+
/******************************************************************************
35+
* CLASS DECLARATION
36+
******************************************************************************/
37+
2638
class ArduinoIoTCloudLPWAN : public ArduinoIoTCloudClass {
2739
public:
2840
ArduinoIoTCloudLPWAN();
@@ -75,7 +87,10 @@ class ArduinoIoTCloudLPWAN : public ArduinoIoTCloudClass {
7587

7688
};
7789

78-
extern ArduinoIoTCloudLPWAN ArduinoCloud;
90+
/******************************************************************************
91+
* EXTERN DECLARATION
92+
******************************************************************************/
7993

94+
extern ArduinoIoTCloudLPWAN ArduinoCloud;
8095

8196
#endif

src/ArduinoIoTCloudTCP.cpp

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
software without disclosing the source code of your own applications. To purchase
1515
a commercial license, send an email to [email protected].
1616
*/
17+
18+
/******************************************************************************
19+
* INCLUDE
20+
******************************************************************************/
21+
1722
#include "ArduinoIoTCloud_Defines.h"
1823

1924
#ifdef HAS_TCP
@@ -24,16 +29,32 @@
2429
#include "utility/crypto/BearSSLTrustAnchor.h"
2530
#endif
2631

32+
/******************************************************************************
33+
GLOBAL VARIABLES
34+
******************************************************************************/
35+
2736
TimeService time_service;
2837

38+
/******************************************************************************
39+
GLOBAL CONSTANTS
40+
******************************************************************************/
41+
2942
const static int CONNECT_SUCCESS = 1;
3043
const static int CONNECT_FAILURE = 0;
3144
const static int CONNECT_FAILURE_SUBSCRIBE = -1;
3245

46+
/******************************************************************************
47+
LOCAL MODULE FUNCTIONS
48+
******************************************************************************/
49+
3350
static unsigned long getTime() {
3451
return time_service.getTime();
3552
}
3653

54+
/******************************************************************************
55+
CTOR/DTOR
56+
******************************************************************************/
57+
3758
ArduinoIoTCloudTCP::ArduinoIoTCloudTCP():
3859
_connection(NULL),
3960
_mqtt_data_buf{0},
@@ -59,6 +80,10 @@ ArduinoIoTCloudTCP::~ArduinoIoTCloudTCP() {
5980
delete _sslClient; _sslClient = NULL;
6081
}
6182

83+
/******************************************************************************
84+
* PUBLIC MEMBER FUNCTIONS
85+
******************************************************************************/
86+
6287
int ArduinoIoTCloudTCP::begin(ConnectionHandler & connection, String brokerAddress, uint16_t brokerPort) {
6388
_connection = &connection;
6489
_brokerAddress = brokerAddress;
@@ -184,24 +209,13 @@ void ArduinoIoTCloudTCP::update() {
184209
}
185210
}
186211

187-
188-
189-
void ArduinoIoTCloudTCP::sendPropertiesToCloud() {
190-
uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE];
191-
int const length = Thing.encode(data, sizeof(data));
192-
if (length > 0)
193-
{
194-
/* If properties have been encoded store them in the back-up buffer
195-
* in order to allow retransmission in case of failure.
196-
*/
197-
_mqtt_data_len = length;
198-
memcpy(_mqtt_data_buf, data, _mqtt_data_len);
199-
/* Transmit the properties to the MQTT broker */
200-
writeProperties(_mqtt_data_buf, _mqtt_data_len);
201-
}
212+
void ArduinoIoTCloudTCP::printDebugInfo() {
213+
Debug.print(DBG_INFO, "***** Arduino IoT Cloud - configuration info *****");
214+
Debug.print(DBG_INFO, "Device ID: %s", getDeviceId().c_str());
215+
Debug.print(DBG_INFO, "Thing ID: %s", getThingId().c_str());
216+
Debug.print(DBG_INFO, "MQTT Broker: %s:%d", _brokerAddress.c_str(), _brokerPort);
202217
}
203218

204-
205219
int ArduinoIoTCloudTCP::reconnect() {
206220
if (_mqttClient->connected()) {
207221
_mqttClient->stop();
@@ -264,6 +278,10 @@ int ArduinoIoTCloudTCP::writeShadowOut(const byte data[], int length) {
264278
return 1;
265279
}
266280

281+
/******************************************************************************
282+
* PRIVATE MEMBER FUNCTIONS
283+
******************************************************************************/
284+
267285
void ArduinoIoTCloudTCP::onMessage(int length) {
268286
ArduinoCloud.handleMessage(length);
269287
}
@@ -290,6 +308,21 @@ void ArduinoIoTCloudTCP::handleMessage(int length) {
290308
}
291309
}
292310

311+
void ArduinoIoTCloudTCP::sendPropertiesToCloud() {
312+
uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE];
313+
int const length = Thing.encode(data, sizeof(data));
314+
if (length > 0)
315+
{
316+
/* If properties have been encoded store them in the back-up buffer
317+
* in order to allow retransmission in case of failure.
318+
*/
319+
_mqtt_data_len = length;
320+
memcpy(_mqtt_data_buf, data, _mqtt_data_len);
321+
/* Transmit the properties to the MQTT broker */
322+
writeProperties(_mqtt_data_buf, _mqtt_data_len);
323+
}
324+
}
325+
293326
void ArduinoIoTCloudTCP::requestLastValue() {
294327
// Send the getLastValues CBOR message to the cloud
295328
// [{0: "r:m", 3: "getLastValues"}] = 81 A2 00 63 72 3A 6D 03 6D 67 65 74 4C 61 73 74 56 61 6C 75 65 73
@@ -371,12 +404,9 @@ ArduinoIoTConnectionStatus ArduinoIoTCloudTCP::checkCloudConnection()
371404
return _iotStatus;
372405
}
373406

374-
void ArduinoIoTCloudTCP::printDebugInfo() {
375-
Debug.print(DBG_INFO, "***** Arduino IoT Cloud - configuration info *****");
376-
Debug.print(DBG_INFO, "Device ID: %s", getDeviceId().c_str());
377-
Debug.print(DBG_INFO, "Thing ID: %s", getThingId().c_str());
378-
Debug.print(DBG_INFO, "MQTT Broker: %s:%d", _brokerAddress.c_str(), _brokerPort);
379-
}
407+
/******************************************************************************
408+
* EXTERN DEFINITION
409+
******************************************************************************/
380410

381411
ArduinoIoTCloudTCP ArduinoCloud;
382412

src/ArduinoIoTCloudTCP.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#ifndef ARDUINO_IOT_CLOUD_TCP_H
1919
#define ARDUINO_IOT_CLOUD_TCP_H
2020

21+
/******************************************************************************
22+
* INCLUDE
23+
******************************************************************************/
2124

2225
#include <ArduinoIoTCloud.h>
2326
#include <Arduino_ConnectionHandler.h>
@@ -31,12 +34,19 @@
3134

3235
#include <ArduinoMqttClient.h>
3336

37+
/******************************************************************************
38+
CONSTANTS
39+
******************************************************************************/
3440

3541
static char const DEFAULT_BROKER_ADDRESS_SECURE_AUTH[] = "mqtts-sa.iot.arduino.cc";
3642
static uint16_t const DEFAULT_BROKER_PORT_SECURE_AUTH = 8883;
3743
static char const DEFAULT_BROKER_ADDRESS_USER_PASS_AUTH[] = "mqtts-up.iot.arduino.cc";
3844
static uint16_t const DEFAULT_BROKER_PORT_USER_PASS_AUTH = 8884;
3945

46+
/******************************************************************************
47+
* CLASS DECLARATION
48+
******************************************************************************/
49+
4050
class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass {
4151
public:
4252
ArduinoIoTCloudTCP();
@@ -127,7 +137,10 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass {
127137
ArduinoIoTConnectionStatus checkCloudConnection();
128138
};
129139

130-
extern ArduinoIoTCloudTCP ArduinoCloud;
140+
/******************************************************************************
141+
* EXTERN DECLARATION
142+
******************************************************************************/
131143

144+
extern ArduinoIoTCloudTCP ArduinoCloud;
132145

133146
#endif

src/CloudSerial.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,31 @@
1414
software without disclosing the source code of your own applications. To purchase
1515
a commercial license, send an email to [email protected].
1616
*/
17+
18+
/******************************************************************************
19+
* INCLUDE
20+
******************************************************************************/
21+
1722
#include "ArduinoIoTCloud_Defines.h"
1823
#ifndef HAS_LORA
1924

2025
#include "ArduinoIoTCloud.h"
2126
#include "CloudSerial.h"
2227

28+
/******************************************************************************
29+
CTOR/DTOR
30+
******************************************************************************/
31+
2332
CloudSerialClass::CloudSerialClass() {
2433
}
2534

2635
CloudSerialClass::~CloudSerialClass() {
2736
}
2837

38+
/******************************************************************************
39+
* PUBLIC MEMBER FUNCTIONS
40+
******************************************************************************/
41+
2942
void CloudSerialClass::begin(int /*baud*/) {
3043
_txBuffer.clear();
3144
_rxBuffer.clear();
@@ -87,6 +100,10 @@ void CloudSerialClass::appendStdin(const uint8_t *buffer, size_t size) {
87100
}
88101
}
89102

103+
/******************************************************************************
104+
* EXTERN DEFINITION
105+
******************************************************************************/
106+
90107
CloudSerialClass CloudSerial;
91108

92109
#endif

0 commit comments

Comments
 (0)