Skip to content

Commit dd9dff7

Browse files
tekka007henrikekblad
authored andcommitted
Minor optimizations & code harmonization (#708)
1 parent 7445b06 commit dd9dff7

15 files changed

+65
-53
lines changed

MySensors.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@
5959

6060
// HARDWARE
6161
#if defined(ARDUINO_ARCH_ESP8266)
62-
// Remove PSTR macros from debug prints
63-
#undef PSTR
64-
#define PSTR(x) (x)
65-
//#undef F
66-
//#define F(x) (x)
6762
#include "core/MyHwESP8266.cpp"
6863
#elif defined(ARDUINO_ARCH_AVR)
6964
#include "drivers/AVR/DigitalWriteFast/digitalWriteFast.h"

core/MyGatewayTransport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern bool transportSendRoute(MyMessage &message);
2525
extern MyMessage _msg;
2626
extern MyMessage _msgTmp;
2727

28-
inline void gatewayTransportProcess()
28+
inline void gatewayTransportProcess(void)
2929
{
3030
if (gatewayTransportAvailable()) {
3131
_msg = gatewayTransportReceive();

core/MyGatewayTransport.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@
2323
#include "MyProtocol.h"
2424
#include "MySensorsCore.h"
2525

26+
#define MSG_GW_STARTUP_COMPLETE "Gateway startup complete."
27+
2628
// Common gateway functions
2729

28-
void gatewayTransportProcess();
30+
void gatewayTransportProcess(void);
2931

3032

3133
// Gateway "interface" functions
3234

3335
/**
3436
* initialize the driver
3537
*/
36-
bool gatewayTransportInit();
38+
bool gatewayTransportInit(void);
3739

3840
/**
3941
* Send message to controller
@@ -43,11 +45,11 @@ bool gatewayTransportSend(MyMessage &message);
4345
/*
4446
* Check if a new message is available from controller
4547
*/
46-
bool gatewayTransportAvailable();
48+
bool gatewayTransportAvailable(void);
4749

4850
/*
4951
* Pick up last message received from controller
5052
*/
51-
MyMessage& gatewayTransportReceive();
53+
MyMessage& gatewayTransportReceive(void);
5254

5355
#endif /* MyGatewayTransportEthernet_h */

core/MyGatewayTransportEthernet.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void _w5100_spi_en(bool enable)
9797
#define _w5100_spi_en(x)
9898
#endif
9999

100-
bool gatewayTransportInit()
100+
bool gatewayTransportInit(void)
101101
{
102102
_w5100_spi_en(true);
103103
#if defined(MY_GATEWAY_ESP8266)
@@ -147,7 +147,7 @@ bool gatewayTransportInit()
147147
#endif
148148
debug(PSTR("Eth: connect\n"));
149149
_w5100_spi_en(false);
150-
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
150+
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
151151
_w5100_spi_en(true);
152152
presentNode();
153153
} else {
@@ -194,7 +194,7 @@ bool gatewayTransportSend(MyMessage &message)
194194
#endif
195195
debug(PSTR("Eth: connect\n"));
196196
_w5100_spi_en(false);
197-
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
197+
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
198198
_w5100_spi_en(true);
199199
presentNode();
200200
} else {
@@ -226,7 +226,7 @@ bool gatewayTransportSend(MyMessage &message)
226226
bool _readFromClient(uint8_t i)
227227
{
228228
while (clients[i].connected() && clients[i].available()) {
229-
char inChar = clients[i].read();
229+
const char inChar = clients[i].read();
230230
if (inputString[i].idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
231231
// if newline then command is complete
232232
if (inChar == '\n' || inChar == '\r') {
@@ -253,10 +253,10 @@ bool _readFromClient(uint8_t i)
253253
return false;
254254
}
255255
#else
256-
bool _readFromClient()
256+
bool _readFromClient(void)
257257
{
258258
while (client.connected() && client.available()) {
259-
char inChar = client.read();
259+
const char inChar = client.read();
260260
if (inputString.idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
261261
// if newline then command is complete
262262
if (inChar == '\n' || inChar == '\r') {
@@ -285,7 +285,7 @@ bool _readFromClient()
285285
#endif
286286

287287

288-
bool gatewayTransportAvailable()
288+
bool gatewayTransportAvailable(void)
289289
{
290290
_w5100_spi_en(true);
291291
#if !defined(MY_IP_ADDRESS) && defined(MY_GATEWAY_W5100)
@@ -325,7 +325,7 @@ bool gatewayTransportAvailable()
325325
#endif
326326
debug(PSTR("Eth: connect\n"));
327327
_w5100_spi_en(false);
328-
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
328+
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
329329
_w5100_spi_en(true);
330330
presentNode();
331331
} else {
@@ -355,7 +355,7 @@ bool gatewayTransportAvailable()
355355
clients[i] = _ethernetServer.available();
356356
inputString[i].idx = 0;
357357
debug(PSTR("Client %d connected\n"), i);
358-
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
358+
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
359359
// Send presentation of locally attached sensors (and node if applicable)
360360
presentNode();
361361
}
@@ -388,7 +388,7 @@ bool gatewayTransportAvailable()
388388
client = newclient;
389389
debug(PSTR("Eth: connect\n"));
390390
_w5100_spi_en(false);
391-
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
391+
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
392392
_w5100_spi_en(true);
393393
presentNode();
394394
}
@@ -411,14 +411,14 @@ bool gatewayTransportAvailable()
411411
return false;
412412
}
413413

414-
MyMessage& gatewayTransportReceive()
414+
MyMessage& gatewayTransportReceive(void)
415415
{
416416
// Return the last parsed message
417417
return _ethernetMsg;
418418
}
419419

420420
#if !defined(MY_IP_ADDRESS) && !defined(MY_GATEWAY_ESP8266) && !defined(MY_GATEWAY_LINUX)
421-
void gatewayTransportRenewIP()
421+
void gatewayTransportRenewIP(void)
422422
{
423423
/* renew/rebind IP address
424424
0 - nothing happened

core/MyGatewayTransportMQTTClient.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* network topology allowing messages to be routed to nodes.
77
*
88
* Created by Henrik Ekblad <[email protected]>
9-
* Copyright (C) 2013-2015 Sensnology AB
9+
* Copyright (C) 2013-2016 Sensnology AB
1010
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
1111
*
1212
* Documentation: http://www.mysensors.org
@@ -65,7 +65,7 @@ void incomingMQTT(char* topic, uint8_t* payload, unsigned int length)
6565
_MQTT_available = protocolMQTTParse(_MQTT_msg, topic, payload, length);
6666
}
6767

68-
bool reconnectMQTT()
68+
bool reconnectMQTT(void)
6969
{
7070
debug(PSTR("Attempting MQTT connection...\n"));
7171
// Attempt to connect
@@ -88,14 +88,14 @@ bool reconnectMQTT()
8888
return false;
8989
}
9090

91-
bool gatewayTransportConnect()
91+
bool gatewayTransportConnect(void)
9292
{
9393
#if defined(MY_GATEWAY_ESP8266)
9494
while (WiFi.status() != WL_CONNECTED) {
9595
wait(500);
96-
MY_SERIALDEVICE.print(".");
96+
MY_SERIALDEVICE.print(F("."));
9797
}
98-
MY_SERIALDEVICE.print("IP: ");
98+
MY_SERIALDEVICE.print(F("IP: "));
9999
MY_SERIALDEVICE.println(WiFi.localIP());
100100
#elif defined(MY_GATEWAY_LINUX)
101101
#if defined(MY_IP_ADDRESS)
@@ -107,20 +107,20 @@ bool gatewayTransportConnect()
107107
#else
108108
// Get IP address from DHCP
109109
if (!Ethernet.begin(_MQTT_clientMAC)) {
110-
MY_SERIALDEVICE.print("DHCP FAILURE...");
110+
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
111111
_MQTT_connecting = false;
112112
return false;
113113
}
114114
#endif
115-
MY_SERIALDEVICE.print("IP: ");
115+
MY_SERIALDEVICE.print(F("IP: "));
116116
MY_SERIALDEVICE.println(Ethernet.localIP());
117117
// give the Ethernet interface a second to initialize
118118
delay(1000);
119119
#endif
120120
return true;
121121
}
122122

123-
bool gatewayTransportInit()
123+
bool gatewayTransportInit(void)
124124
{
125125
_MQTT_connecting = true;
126126
#if defined(MY_CONTROLLER_IP_ADDRESS)
@@ -149,7 +149,7 @@ bool gatewayTransportInit()
149149
return true;
150150
}
151151

152-
bool gatewayTransportAvailable()
152+
bool gatewayTransportAvailable(void)
153153
{
154154
if (_MQTT_connecting) {
155155
return false;
@@ -167,7 +167,7 @@ bool gatewayTransportAvailable()
167167
return _MQTT_available;
168168
}
169169

170-
MyMessage & gatewayTransportReceive()
170+
MyMessage & gatewayTransportReceive(void)
171171
{
172172
// Return the last parsed message
173173
_MQTT_available = false;

core/MyGatewayTransportSerial.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* network topology allowing messages to be routed to nodes.
77
*
88
* Created by Henrik Ekblad <[email protected]>
9-
* Copyright (C) 2013-2015 Sensnology AB
9+
* Copyright (C) 2013-2016 Sensnology AB
1010
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
1111
*
1212
* Documentation: http://www.mysensors.org
@@ -38,26 +38,25 @@ bool gatewayTransportSend(MyMessage &message)
3838
return true;
3939
}
4040

41-
bool gatewayTransportInit()
41+
bool gatewayTransportInit(void)
4242
{
43-
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
43+
(void)gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
4444
// Send presentation of locally attached sensors (and node if applicable)
4545
presentNode();
46-
4746
return true;
4847
}
4948

50-
bool gatewayTransportAvailable()
49+
bool gatewayTransportAvailable(void)
5150
{
5251
while (MY_SERIALDEVICE.available()) {
5352
// get the new byte:
54-
char inChar = (char) MY_SERIALDEVICE.read();
53+
const char inChar = (char)MY_SERIALDEVICE.read();
5554
// if the incoming character is a newline, set a flag
5655
// so the main loop can do something about it:
5756
if (_serialInputPos < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
5857
if (inChar == '\n') {
5958
_serialInputString[_serialInputPos] = 0;
60-
bool ok = protocolParse(_serialMsg, _serialInputString);
59+
const bool ok = protocolParse(_serialMsg, _serialInputString);
6160
if (ok) {
6261
setIndication(INDICATION_GW_RX);
6362
}
@@ -76,7 +75,7 @@ bool gatewayTransportAvailable()
7675
return false;
7776
}
7877

79-
MyMessage & gatewayTransportReceive()
78+
MyMessage & gatewayTransportReceive(void)
8079
{
8180
// Return the last parsed message
8281
return _serialMsg;

core/MyHwATMega328.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
#include <Arduino.h>
3535
#endif
3636

37+
#ifndef MY_SERIALDEVICE
3738
#define MY_SERIALDEVICE Serial
39+
#endif
3840

3941
#if defined __AVR_ATmega328P__
4042
#ifndef sleep_bod_disable

core/MyHwESP8266.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include <Arduino.h>
2626
#endif
2727

28+
#ifndef MY_SERIALDEVICE
2829
#define MY_SERIALDEVICE Serial
30+
#endif
2931

3032
#define min(a,b) ((a)<(b)?(a):(b))
3133
#define max(a,b) ((a)>(b)?(a):(b))

core/MyHwLinuxGeneric.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ SerialPort Serial = SerialPort(MY_LINUX_SERIAL_PTY, true);
3131
SerialPort Serial = SerialPort(MY_LINUX_SERIAL_PORT);
3232
#endif
3333

34+
#ifndef MY_SERIALDEVICE
3435
#define MY_SERIALDEVICE Serial
36+
#endif
3537

3638
// Define these as macros (do nothing)
3739
#define hwWatchdogReset()

core/MyHwSAMD.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ void hwWriteConfigBlock(void* buf, void* adr, size_t length);
5151
void hwWriteConfig(int adr, uint8_t value);
5252
uint8_t hwReadConfig(int adr);
5353

54+
#ifndef MY_SERIALDEVICE
5455
#define MY_SERIALDEVICE SerialUSB
56+
#endif
5557

5658
/**
5759
* Disable all interrupts.

0 commit comments

Comments
 (0)