Skip to content

Commit a9c49f0

Browse files
tekka007mfalkvidd
authored andcommitted
Harmonize debug outputs (#1002)
1 parent bfcb125 commit a9c49f0

9 files changed

+86
-62
lines changed

MyConfig.h

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,18 @@
166166
/** @}*/ // End of SerialDebugGrpPub group
167167

168168
/**
169-
* @defgroup RadioSettingGrpPub Radio selection
170-
* @ingroup MyConfigGrp
171-
* @brief These options control what radio type to use and various radio specific customisations.
172-
* @{
169+
* @def MY_DEBUG_VERBOSE_OTA_UPDATE
170+
* @brief Define this for verbose debug prints related to FOTA updates.
173171
*/
172+
//#define MY_DEBUG_VERBOSE_OTA_UPDATE
174173

175-
// Define or uncomment MY_OTA_USE_I2C_EEPROM below if you want I2C EEPROM instead
176-
// of a SPI flash. Used EEPROM needs to be large enough, an 24(L)C256 will do as minimum.
177-
// HW I2C assumed. This will exclude the SPI flash code.
178-
// Note that you also need an updated DualOptiboot supporting I2C EEPROM!
174+
/**
175+
* @def MY_OTA_USE_I2C_EEPROM
176+
* @brief Define this if you want I2C EEPROM instead
177+
* of a SPI flash. Used EEPROM needs to be large enough, an 24(L)C256 will do as minimum.
178+
* HW I2C assumed. This will exclude the SPI flash code.
179+
* Note that you also need an updated DualOptiboot supporting I2C EEPROM!
180+
*/
179181
//#define MY_OTA_USE_I2C_EEPROM
180182

181183
#ifdef MY_OTA_USE_I2C_EEPROM
@@ -185,6 +187,15 @@
185187
#endif
186188
#endif
187189

190+
191+
/**
192+
* @defgroup RadioSettingGrpPub Radio selection
193+
* @ingroup MyConfigGrp
194+
* @brief These options control what radio type to use and various radio specific customisations.
195+
* @{
196+
*/
197+
198+
188199
/**
189200
* @defgroup RS485SettingGrpPub RS485
190201
* @ingroup RadioSettingGrpPub
@@ -1326,6 +1337,13 @@
13261337
//#define MY_GATEWAY_ESP8266
13271338
//#define MY_GATEWAY_LINUX
13281339

1340+
1341+
/**
1342+
* @def MY_DEBUG_VERBOSE_GATEWAY
1343+
* @brief Define this for verbose debug prints related to the gateway transport.
1344+
*/
1345+
//#define MY_DEBUG_VERBOSE_GATEWAY
1346+
13291347
/**
13301348
* @def MY_PORT
13311349
* @brief The Ethernet TCP/UDP port to open on controller or gateway.
@@ -1777,10 +1795,11 @@
17771795
// standard debug output
17781796
#define MY_DEBUG_VERBOSE_CORE //!< MY_DEBUG_VERBOSE_CORE
17791797
#define MY_DEBUG_VERBOSE_TRANSPORT //!< MY_DEBUG_VERBOSE_TRANSPORT
1780-
#define MY_DEBUG_VERBOSE_OTA_UPDATE //!< MY_DEBUG_VERBOSE_OTA_UPDATE
1798+
#define MY_DEBUG_VERBOSE_GATEWAY //!< MY_DEBUG_VERBOSE_GATEWAY
1799+
#define MY_DEBUG_VERBOSE_OTA_UPDATE //!< MY_DEBUG_VERBOSE_OTA_UPDATE
17811800
#endif
17821801

1783-
#if defined(MY_DEBUG) || defined(MY_DEBUG_VERBOSE_CORE) || defined(MY_DEBUG_VERBOSE_TRANSPORT) || defined(MY_DEBUG_VERBOSE_SIGNING) || defined(MY_DEBUG_VERBOSE_OTA_UPDATE) || defined(MY_DEBUG_VERBOSE_RF24) || defined(MY_DEBUG_VERBOSE_NRF5_ESB) || defined(MY_DEBUG_VERBOSE_RFM69) || defined(MY_DEBUG_VERBOSE_RFM95)
1802+
#if defined(MY_DEBUG) || defined(MY_DEBUG_VERBOSE_CORE) || defined(MY_DEBUG_VERBOSE_TRANSPORT) || defined(MY_DEBUG_VERBOSE_GATEWAY) || defined(MY_DEBUG_VERBOSE_SIGNING) || defined(MY_DEBUG_VERBOSE_OTA_UPDATE) || defined(MY_DEBUG_VERBOSE_RF24) || defined(MY_DEBUG_VERBOSE_NRF5_ESB) || defined(MY_DEBUG_VERBOSE_RFM69) || defined(MY_DEBUG_VERBOSE_RFM95)
17841803
#define DEBUG_OUTPUT_ENABLED //!< DEBUG_OUTPUT_ENABLED
17851804
#ifndef MY_DEBUG_OTA
17861805
#define DEBUG_OUTPUT(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug
@@ -1804,9 +1823,6 @@
18041823
#define DEBUG_OUTPUT(x,...) //!< debug NULL
18051824
#endif
18061825

1807-
// transport layer files
1808-
#define debug(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__) //!< debug
1809-
18101826
// temp. workaround for nRF5 verifier: redirect RF24 to NRF_ESB
18111827
#if defined(ARDUINO_ARCH_NRF5) && (defined(MY_RADIO_RF24) || defined(MY_RADIO_NRF24) )
18121828
#undef MY_RADIO_RF24
@@ -1908,6 +1924,7 @@
19081924
// core
19091925
#define MY_CORE_ONLY
19101926
// GW
1927+
#define MY_DEBUG_VERBOSE_GATEWAY
19111928
#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
19121929
#define MY_GATEWAY_W5100
19131930
#define MY_GATEWAY_ENC28J60
@@ -1930,6 +1947,9 @@
19301947
#define MY_DEBUG_VERBOSE_SIGNING
19311948
#define MY_SIGNING_FEATURE
19321949
#define MY_ENCRYPTION_FEATURE
1950+
// FOTA update
1951+
#define MY_DEBUG_VERBOSE_OTA_UPDATE
1952+
#define MY_OTA_USE_I2C_EEPROM
19331953
// RS485
19341954
#define MY_RS485
19351955
#define MY_RS485_HWSERIAL (Serial1)

core/MyGatewayTransport.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525

2626
#define MSG_GW_STARTUP_COMPLETE "Gateway startup complete."
2727

28+
// debug output
29+
#if defined(MY_DEBUG_VERBOSE_GATEWAY)
30+
#define GATEWAY_DEBUG(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__) //!< debug
31+
#else
32+
#define GATEWAY_DEBUG(x,...) //!< debug NULL
33+
#endif
34+
2835
// Common gateway functions
2936

3037
void gatewayTransportProcess(void);

core/MyGatewayTransportEthernet.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,9 @@ bool gatewayTransportInit(void)
132132
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD, 0, MY_ESP8266_BSSID);
133133
while (WiFi.status() != WL_CONNECTED) {
134134
wait(500);
135-
MY_SERIALDEVICE.print(F("."));
135+
GATEWAY_DEBUG(PSTR("."));
136136
}
137-
MY_SERIALDEVICE.print(F("IP: "));
138-
MY_SERIALDEVICE.println(WiFi.localIP());
137+
GATEWAY_DEBUG(PSTR("IP: %s\n"), WiFi.localIP().toString().c_str());
139138
#endif /* End of MY_ESP8266_SSID */
140139
#elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_ESP8266 */
141140
// Nothing to do here
@@ -148,13 +147,13 @@ bool gatewayTransportInit(void)
148147
#else /* Else part of MY_IP_GATEWAY_ADDRESS && MY_IP_SUBNET_ADDRESS */
149148
// Get IP address from DHCP
150149
if (!Ethernet.begin(_ethernetGatewayMAC)) {
151-
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
150+
GATEWAY_DEBUG(PSTR("DHCP FAILURE..."));
152151
_w5100_spi_en(false);
153152
return false;
154153
}
155154
#endif /* End of MY_IP_GATEWAY_ADDRESS && MY_IP_SUBNET_ADDRESS */
156-
MY_SERIALDEVICE.print(F("IP: "));
157-
MY_SERIALDEVICE.println(Ethernet.localIP());
155+
GATEWAY_DEBUG(PSTR("IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "\n"), Ethernet.localIP()[0],
156+
Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]);
158157
// give the Ethernet interface a second to initialize
159158
delay(1000);
160159
#endif /* End of MY_GATEWAY_ESP8266 */
@@ -171,14 +170,14 @@ bool gatewayTransportInit(void)
171170
#else
172171
if (client.connect(_ethernetControllerIP, MY_PORT)) {
173172
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
174-
debug(PSTR("Eth: connect\n"));
173+
GATEWAY_DEBUG(PSTR("Eth: connect\n"));
175174
_w5100_spi_en(false);
176175
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
177176
_w5100_spi_en(true);
178177
presentNode();
179178
} else {
180179
client.stop();
181-
debug(PSTR("Eth: Failed to connect\n"));
180+
GATEWAY_DEBUG(PSTR("Eth: Failed to connect\n"));
182181
}
183182
#endif /* End of MY_USE_UDP */
184183
#else /* Else part of MY_GATEWAY_CLIENT_MODE */
@@ -220,14 +219,14 @@ bool gatewayTransportSend(MyMessage &message)
220219
#else
221220
if (client.connect(_ethernetControllerIP, MY_PORT)) {
222221
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
223-
debug(PSTR("Eth: connect\n"));
222+
GATEWAY_DEBUG(PSTR("Eth: connect\n"));
224223
_w5100_spi_en(false);
225224
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
226225
_w5100_spi_en(true);
227226
presentNode();
228227
} else {
229228
// connecting to the server failed!
230-
debug(PSTR("Eth: Failed to connect\n"));
229+
GATEWAY_DEBUG(PSTR("Eth: Failed to connect\n"));
231230
_w5100_spi_en(false);
232231
return false;
233232
}
@@ -263,7 +262,7 @@ bool _readFromClient(uint8_t i)
263262
if (inChar == '\n' || inChar == '\r') {
264263
// Add string terminator and prepare for the next message
265264
inputString[i].string[inputString[i].idx] = 0;
266-
debug(PSTR("Client %" PRIu8 ": %s\n"), i, inputString[i].string);
265+
GATEWAY_DEBUG(PSTR("Client %" PRIu8 ": %s\n"), i, inputString[i].string);
267266
inputString[i].idx = 0;
268267
if (protocolParse(_ethernetMsg, inputString[i].string)) {
269268
return true;
@@ -275,7 +274,7 @@ bool _readFromClient(uint8_t i)
275274
}
276275
} else {
277276
// Incoming message too long. Throw away
278-
debug(PSTR("Client %" PRIu8 ": Message too long\n"), i);
277+
GATEWAY_DEBUG(PSTR("Client %" PRIu8 ": Message too long\n"), i);
279278
inputString[i].idx = 0;
280279
// Finished with this client's message. Next loop() we'll see if there's more to read.
281280
break;
@@ -293,7 +292,7 @@ bool _readFromClient(void)
293292
if (inChar == '\n' || inChar == '\r') {
294293
// Add string terminator and prepare for the next message
295294
inputString.string[inputString.idx] = 0;
296-
debug(PSTR("Eth: %s\n"), inputString.string);
295+
GATEWAY_DEBUG(PSTR("Eth: %s\n"), inputString.string);
297296
inputString.idx = 0;
298297
if (protocolParse(_ethernetMsg, inputString.string)) {
299298
return true;
@@ -305,7 +304,7 @@ bool _readFromClient(void)
305304
}
306305
} else {
307306
// Incoming message too long. Throw away
308-
debug(PSTR("Eth: Message too long\n"));
307+
GATEWAY_DEBUG(PSTR("Eth: Message too long\n"));
309308
inputString.idx = 0;
310309
// Finished with this client's message. Next loop() we'll see if there's more to read.
311310
break;
@@ -329,10 +328,10 @@ bool gatewayTransportAvailable(void)
329328
int packet_size = _ethernetServer.parsePacket();
330329

331330
if (packet_size) {
332-
//debug(PSTR("UDP packet available. Size:%" PRIu8 "\n"), packet_size);
331+
//GATEWAY_DEBUG(PSTR("UDP packet available. Size:%" PRIu8 "\n"), packet_size);
333332
_ethernetServer.read(inputString.string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
334333
inputString.string[packet_size] = 0;
335-
debug(PSTR("UDP packet received: %s\n"), inputString.string);
334+
GATEWAY_DEBUG(PSTR("UDP packet received: %s\n"), inputString.string);
336335
_w5100_spi_en(false);
337336
const bool ok = protocolParse(_ethernetMsg, inputString.string);
338337
if (ok) {
@@ -348,13 +347,13 @@ bool gatewayTransportAvailable(void)
348347
#else
349348
if (client.connect(_ethernetControllerIP, MY_PORT)) {
350349
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
351-
debug(PSTR("Eth: connect\n"));
350+
GATEWAY_DEBUG(PSTR("Eth: connect\n"));
352351
_w5100_spi_en(false);
353352
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
354353
_w5100_spi_en(true);
355354
presentNode();
356355
} else {
357-
debug(PSTR("Eth: Failed to connect\n"));
356+
GATEWAY_DEBUG(PSTR("Eth: Failed to connect\n"));
358357
_w5100_spi_en(false);
359358
return false;
360359
}
@@ -373,14 +372,14 @@ bool gatewayTransportAvailable(void)
373372
for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
374373
if (!clients[i].connected()) {
375374
if (clientsConnected[i]) {
376-
debug(PSTR("Client %" PRIu8 " disconnected\n"), i);
375+
GATEWAY_DEBUG(PSTR("Client %" PRIu8 " disconnected\n"), i);
377376
clients[i].stop();
378377
}
379378
//check if there are any new clients
380379
if (_ethernetServer.hasClient()) {
381380
clients[i] = _ethernetServer.available();
382381
inputString[i].idx = 0;
383-
debug(PSTR("Client %" PRIu8 " connected\n"), i);
382+
GATEWAY_DEBUG(PSTR("Client %" PRIu8 " connected\n"), i);
384383
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
385384
// Send presentation of locally attached sensors (and node if applicable)
386385
presentNode();
@@ -392,7 +391,7 @@ bool gatewayTransportAvailable(void)
392391
}
393392
if (allSlotsOccupied && _ethernetServer.hasClient()) {
394393
//no free/disconnected spot so reject
395-
debug(PSTR("No free slot available\n"));
394+
GATEWAY_DEBUG(PSTR("No free slot available\n"));
396395
EthernetClient c = _ethernetServer.available();
397396
c.stop();
398397
}
@@ -412,7 +411,7 @@ bool gatewayTransportAvailable(void)
412411
if (client != newclient) {
413412
client.stop();
414413
client = newclient;
415-
debug(PSTR("Eth: connect\n"));
414+
GATEWAY_DEBUG(PSTR("Eth: connect\n"));
416415
_w5100_spi_en(false);
417416
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
418417
_w5100_spi_en(true);
@@ -421,7 +420,7 @@ bool gatewayTransportAvailable(void)
421420
}
422421
if (client) {
423422
if (!client.connected()) {
424-
debug(PSTR("Eth: disconnect\n"));
423+
GATEWAY_DEBUG(PSTR("Eth: disconnect\n"));
425424
client.stop();
426425
} else {
427426
if (_readFromClient()) {
@@ -461,7 +460,7 @@ void gatewayTransportRenewIP(void)
461460
return;
462461
}
463462
if (Ethernet.maintain() & ~(0x06)) {
464-
debug(PSTR("IP was not renewed correctly\n"));
463+
GATEWAY_DEBUG(PSTR("IP was not renewed correctly\n"));
465464
/* Error occured -> IP was not renewed */
466465
return;
467466
}

core/MyGatewayTransportMQTTClient.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool gatewayTransportSend(MyMessage &message)
6363
}
6464
setIndication(INDICATION_GW_TX);
6565
char *topic = protocolFormatMQTTTopic(MY_MQTT_PUBLISH_TOPIC_PREFIX, message);
66-
debug(PSTR("Sending message on topic: %s\n"), topic);
66+
GATEWAY_DEBUG(PSTR("Sending message on topic: %s\n"), topic);
6767
#if defined(MY_MQTT_CLIENT_PUBLISH_RETAIN)
6868
bool retain = mGetCommand(message) == C_SET ||
6969
(mGetCommand(message) == C_INTERNAL && message.type == I_BATTERY_LEVEL);
@@ -75,20 +75,20 @@ bool gatewayTransportSend(MyMessage &message)
7575

7676
void incomingMQTT(char* topic, uint8_t* payload, unsigned int length)
7777
{
78-
debug(PSTR("Message arrived on topic: %s\n"), topic);
78+
GATEWAY_DEBUG(PSTR("Message arrived on topic: %s\n"), topic);
7979
_MQTT_available = protocolMQTTParse(_MQTT_msg, topic, payload, length);
8080
}
8181

8282
bool reconnectMQTT(void)
8383
{
84-
debug(PSTR("Attempting MQTT connection...\n"));
84+
GATEWAY_DEBUG(PSTR("Attempting MQTT connection...\n"));
8585
// Attempt to connect
8686
if (_MQTT_client.connect(MY_MQTT_CLIENT_ID
8787
#if defined(MY_MQTT_USER) && defined(MY_MQTT_PASSWORD)
8888
, MY_MQTT_USER, MY_MQTT_PASSWORD
8989
#endif
9090
)) {
91-
debug(PSTR("MQTT connected\n"));
91+
GATEWAY_DEBUG(PSTR("MQTT connected\n"));
9292

9393
// Send presentation of locally attached sensors (and node if applicable)
9494
presentNode();
@@ -107,10 +107,9 @@ bool gatewayTransportConnect(void)
107107
#if defined(MY_GATEWAY_ESP8266)
108108
while (WiFi.status() != WL_CONNECTED) {
109109
wait(500);
110-
MY_SERIALDEVICE.print(F("."));
110+
GATEWAY_DEBUG(PSTR("."));
111111
}
112-
MY_SERIALDEVICE.print(F("IP: "));
113-
MY_SERIALDEVICE.println(WiFi.localIP());
112+
GATEWAY_DEBUG(PSTR("IP: %s\n"),WiFi.localIP().toString().c_str());
114113
#elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_ESP8266 */
115114
#if defined(MY_IP_ADDRESS)
116115
_MQTT_ethClient.bind(_MQTT_clientIp);
@@ -121,13 +120,13 @@ bool gatewayTransportConnect(void)
121120
#else /* Else part of MY_IP_ADDRESS */
122121
// Get IP address from DHCP
123122
if (!Ethernet.begin(_MQTT_clientMAC)) {
124-
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
123+
GATEWAY_DEBUG(PSTR("DHCP FAILURE..."));
125124
_MQTT_connecting = false;
126125
return false;
127126
}
128127
#endif /* End of MY_IP_ADDRESS */
129-
MY_SERIALDEVICE.print(F("IP: "));
130-
MY_SERIALDEVICE.println(Ethernet.localIP());
128+
GATEWAY_DEBUG(PSTR("IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "\n"), Ethernet.localIP()[0],
129+
Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]);
131130
// give the Ethernet interface a second to initialize
132131
delay(1000);
133132
#endif /* End of MY_GATEWAY_ESP8266 */

core/MyOTAFirmwareUpdate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
#define MY_OTA_BOOTLOADER_VERSION (MY_OTA_BOOTLOADER_MINOR_VERSION * 256 + MY_OTA_BOOTLOADER_MAJOR_VERSION) //!< Bootloader version
7070

7171
#if defined(MY_DEBUG_VERBOSE_OTA_UPDATE)
72-
#define OTA_DEBUG(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug
72+
#define OTA_DEBUG(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__) //!< debug
7373
//#define OTA_EXTRA_FLASH_DEBUG //!< Dumps flash after each FW block
7474
#else
7575
#define OTA_DEBUG(x,...) //!< debug NULL

core/MySigning.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define SIGNING_PRESENTATION_REQUIRE_WHITELISTING (1 << 1)
2626

2727
#if defined(MY_DEBUG_VERBOSE_SIGNING)
28-
#define SIGN_DEBUG(x,...) hwDebugPrint(x, ##__VA_ARGS__)
28+
#define SIGN_DEBUG(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__)
2929
#else
3030
#define SIGN_DEBUG(x,...)
3131
#endif

core/MySigningAtsha204.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define SIGNING_IDENTIFIER (1) //HMAC-SHA256
3232

3333
#if defined(MY_DEBUG_VERBOSE_SIGNING)
34-
#define SIGN_DEBUG(x,...) hwDebugPrint(x, ##__VA_ARGS__)
34+
#define SIGN_DEBUG(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__)
3535
static char printStr[65];
3636
static char i2h(uint8_t i)
3737
{

core/MySigningAtsha204Soft.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define SIGNING_IDENTIFIER (1) //HMAC-SHA256
3636

3737
#if defined(MY_DEBUG_VERBOSE_SIGNING)
38-
#define SIGN_DEBUG(x,...) hwDebugPrint(x, ##__VA_ARGS__)
38+
#define SIGN_DEBUG(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__)
3939
static char printStr[65];
4040
static char i2h(uint8_t i)
4141
{

0 commit comments

Comments
 (0)