Minor optimizations & code harmonization (#708)
This commit is contained in:
@@ -59,11 +59,6 @@
|
||||
|
||||
// HARDWARE
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
// Remove PSTR macros from debug prints
|
||||
#undef PSTR
|
||||
#define PSTR(x) (x)
|
||||
//#undef F
|
||||
//#define F(x) (x)
|
||||
#include "core/MyHwESP8266.cpp"
|
||||
#elif defined(ARDUINO_ARCH_AVR)
|
||||
#include "drivers/AVR/DigitalWriteFast/digitalWriteFast.h"
|
||||
|
||||
@@ -25,7 +25,7 @@ extern bool transportSendRoute(MyMessage &message);
|
||||
extern MyMessage _msg;
|
||||
extern MyMessage _msgTmp;
|
||||
|
||||
inline void gatewayTransportProcess()
|
||||
inline void gatewayTransportProcess(void)
|
||||
{
|
||||
if (gatewayTransportAvailable()) {
|
||||
_msg = gatewayTransportReceive();
|
||||
|
||||
@@ -23,9 +23,11 @@
|
||||
#include "MyProtocol.h"
|
||||
#include "MySensorsCore.h"
|
||||
|
||||
#define MSG_GW_STARTUP_COMPLETE "Gateway startup complete."
|
||||
|
||||
// Common gateway functions
|
||||
|
||||
void gatewayTransportProcess();
|
||||
void gatewayTransportProcess(void);
|
||||
|
||||
|
||||
// Gateway "interface" functions
|
||||
@@ -33,7 +35,7 @@ void gatewayTransportProcess();
|
||||
/**
|
||||
* initialize the driver
|
||||
*/
|
||||
bool gatewayTransportInit();
|
||||
bool gatewayTransportInit(void);
|
||||
|
||||
/**
|
||||
* Send message to controller
|
||||
@@ -43,11 +45,11 @@ bool gatewayTransportSend(MyMessage &message);
|
||||
/*
|
||||
* Check if a new message is available from controller
|
||||
*/
|
||||
bool gatewayTransportAvailable();
|
||||
bool gatewayTransportAvailable(void);
|
||||
|
||||
/*
|
||||
* Pick up last message received from controller
|
||||
*/
|
||||
MyMessage& gatewayTransportReceive();
|
||||
MyMessage& gatewayTransportReceive(void);
|
||||
|
||||
#endif /* MyGatewayTransportEthernet_h */
|
||||
|
||||
@@ -97,7 +97,7 @@ void _w5100_spi_en(bool enable)
|
||||
#define _w5100_spi_en(x)
|
||||
#endif
|
||||
|
||||
bool gatewayTransportInit()
|
||||
bool gatewayTransportInit(void)
|
||||
{
|
||||
_w5100_spi_en(true);
|
||||
#if defined(MY_GATEWAY_ESP8266)
|
||||
@@ -147,7 +147,7 @@ bool gatewayTransportInit()
|
||||
#endif
|
||||
debug(PSTR("Eth: connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||
_w5100_spi_en(true);
|
||||
presentNode();
|
||||
} else {
|
||||
@@ -194,7 +194,7 @@ bool gatewayTransportSend(MyMessage &message)
|
||||
#endif
|
||||
debug(PSTR("Eth: connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||
_w5100_spi_en(true);
|
||||
presentNode();
|
||||
} else {
|
||||
@@ -226,7 +226,7 @@ bool gatewayTransportSend(MyMessage &message)
|
||||
bool _readFromClient(uint8_t i)
|
||||
{
|
||||
while (clients[i].connected() && clients[i].available()) {
|
||||
char inChar = clients[i].read();
|
||||
const char inChar = clients[i].read();
|
||||
if (inputString[i].idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
|
||||
// if newline then command is complete
|
||||
if (inChar == '\n' || inChar == '\r') {
|
||||
@@ -253,10 +253,10 @@ bool _readFromClient(uint8_t i)
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
bool _readFromClient()
|
||||
bool _readFromClient(void)
|
||||
{
|
||||
while (client.connected() && client.available()) {
|
||||
char inChar = client.read();
|
||||
const char inChar = client.read();
|
||||
if (inputString.idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
|
||||
// if newline then command is complete
|
||||
if (inChar == '\n' || inChar == '\r') {
|
||||
@@ -285,7 +285,7 @@ bool _readFromClient()
|
||||
#endif
|
||||
|
||||
|
||||
bool gatewayTransportAvailable()
|
||||
bool gatewayTransportAvailable(void)
|
||||
{
|
||||
_w5100_spi_en(true);
|
||||
#if !defined(MY_IP_ADDRESS) && defined(MY_GATEWAY_W5100)
|
||||
@@ -325,7 +325,7 @@ bool gatewayTransportAvailable()
|
||||
#endif
|
||||
debug(PSTR("Eth: connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||
_w5100_spi_en(true);
|
||||
presentNode();
|
||||
} else {
|
||||
@@ -355,7 +355,7 @@ bool gatewayTransportAvailable()
|
||||
clients[i] = _ethernetServer.available();
|
||||
inputString[i].idx = 0;
|
||||
debug(PSTR("Client %d connected\n"), i);
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||
// Send presentation of locally attached sensors (and node if applicable)
|
||||
presentNode();
|
||||
}
|
||||
@@ -388,7 +388,7 @@ bool gatewayTransportAvailable()
|
||||
client = newclient;
|
||||
debug(PSTR("Eth: connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||
_w5100_spi_en(true);
|
||||
presentNode();
|
||||
}
|
||||
@@ -411,14 +411,14 @@ bool gatewayTransportAvailable()
|
||||
return false;
|
||||
}
|
||||
|
||||
MyMessage& gatewayTransportReceive()
|
||||
MyMessage& gatewayTransportReceive(void)
|
||||
{
|
||||
// Return the last parsed message
|
||||
return _ethernetMsg;
|
||||
}
|
||||
|
||||
#if !defined(MY_IP_ADDRESS) && !defined(MY_GATEWAY_ESP8266) && !defined(MY_GATEWAY_LINUX)
|
||||
void gatewayTransportRenewIP()
|
||||
void gatewayTransportRenewIP(void)
|
||||
{
|
||||
/* renew/rebind IP address
|
||||
0 - nothing happened
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Copyright (C) 2013-2016 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
@@ -65,7 +65,7 @@ void incomingMQTT(char* topic, uint8_t* payload, unsigned int length)
|
||||
_MQTT_available = protocolMQTTParse(_MQTT_msg, topic, payload, length);
|
||||
}
|
||||
|
||||
bool reconnectMQTT()
|
||||
bool reconnectMQTT(void)
|
||||
{
|
||||
debug(PSTR("Attempting MQTT connection...\n"));
|
||||
// Attempt to connect
|
||||
@@ -88,14 +88,14 @@ bool reconnectMQTT()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool gatewayTransportConnect()
|
||||
bool gatewayTransportConnect(void)
|
||||
{
|
||||
#if defined(MY_GATEWAY_ESP8266)
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
wait(500);
|
||||
MY_SERIALDEVICE.print(".");
|
||||
MY_SERIALDEVICE.print(F("."));
|
||||
}
|
||||
MY_SERIALDEVICE.print("IP: ");
|
||||
MY_SERIALDEVICE.print(F("IP: "));
|
||||
MY_SERIALDEVICE.println(WiFi.localIP());
|
||||
#elif defined(MY_GATEWAY_LINUX)
|
||||
#if defined(MY_IP_ADDRESS)
|
||||
@@ -107,12 +107,12 @@ bool gatewayTransportConnect()
|
||||
#else
|
||||
// Get IP address from DHCP
|
||||
if (!Ethernet.begin(_MQTT_clientMAC)) {
|
||||
MY_SERIALDEVICE.print("DHCP FAILURE...");
|
||||
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
|
||||
_MQTT_connecting = false;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
MY_SERIALDEVICE.print("IP: ");
|
||||
MY_SERIALDEVICE.print(F("IP: "));
|
||||
MY_SERIALDEVICE.println(Ethernet.localIP());
|
||||
// give the Ethernet interface a second to initialize
|
||||
delay(1000);
|
||||
@@ -120,7 +120,7 @@ bool gatewayTransportConnect()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gatewayTransportInit()
|
||||
bool gatewayTransportInit(void)
|
||||
{
|
||||
_MQTT_connecting = true;
|
||||
#if defined(MY_CONTROLLER_IP_ADDRESS)
|
||||
@@ -149,7 +149,7 @@ bool gatewayTransportInit()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gatewayTransportAvailable()
|
||||
bool gatewayTransportAvailable(void)
|
||||
{
|
||||
if (_MQTT_connecting) {
|
||||
return false;
|
||||
@@ -167,7 +167,7 @@ bool gatewayTransportAvailable()
|
||||
return _MQTT_available;
|
||||
}
|
||||
|
||||
MyMessage & gatewayTransportReceive()
|
||||
MyMessage & gatewayTransportReceive(void)
|
||||
{
|
||||
// Return the last parsed message
|
||||
_MQTT_available = false;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Copyright (C) 2013-2016 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
@@ -38,26 +38,25 @@ bool gatewayTransportSend(MyMessage &message)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gatewayTransportInit()
|
||||
bool gatewayTransportInit(void)
|
||||
{
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
(void)gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||
// Send presentation of locally attached sensors (and node if applicable)
|
||||
presentNode();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gatewayTransportAvailable()
|
||||
bool gatewayTransportAvailable(void)
|
||||
{
|
||||
while (MY_SERIALDEVICE.available()) {
|
||||
// get the new byte:
|
||||
char inChar = (char) MY_SERIALDEVICE.read();
|
||||
const char inChar = (char)MY_SERIALDEVICE.read();
|
||||
// if the incoming character is a newline, set a flag
|
||||
// so the main loop can do something about it:
|
||||
if (_serialInputPos < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
|
||||
if (inChar == '\n') {
|
||||
_serialInputString[_serialInputPos] = 0;
|
||||
bool ok = protocolParse(_serialMsg, _serialInputString);
|
||||
const bool ok = protocolParse(_serialMsg, _serialInputString);
|
||||
if (ok) {
|
||||
setIndication(INDICATION_GW_RX);
|
||||
}
|
||||
@@ -76,7 +75,7 @@ bool gatewayTransportAvailable()
|
||||
return false;
|
||||
}
|
||||
|
||||
MyMessage & gatewayTransportReceive()
|
||||
MyMessage & gatewayTransportReceive(void)
|
||||
{
|
||||
// Return the last parsed message
|
||||
return _serialMsg;
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#ifndef MY_SERIALDEVICE
|
||||
#define MY_SERIALDEVICE Serial
|
||||
#endif
|
||||
|
||||
#if defined __AVR_ATmega328P__
|
||||
#ifndef sleep_bod_disable
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#ifndef MY_SERIALDEVICE
|
||||
#define MY_SERIALDEVICE Serial
|
||||
#endif
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
|
||||
@@ -31,7 +31,9 @@ SerialPort Serial = SerialPort(MY_LINUX_SERIAL_PTY, true);
|
||||
SerialPort Serial = SerialPort(MY_LINUX_SERIAL_PORT);
|
||||
#endif
|
||||
|
||||
#ifndef MY_SERIALDEVICE
|
||||
#define MY_SERIALDEVICE Serial
|
||||
#endif
|
||||
|
||||
// Define these as macros (do nothing)
|
||||
#define hwWatchdogReset()
|
||||
|
||||
@@ -51,7 +51,9 @@ void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
||||
void hwWriteConfig(int adr, uint8_t value);
|
||||
uint8_t hwReadConfig(int adr);
|
||||
|
||||
#ifndef MY_SERIALDEVICE
|
||||
#define MY_SERIALDEVICE SerialUSB
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Disable all interrupts.
|
||||
|
||||
+13
-5
@@ -39,7 +39,9 @@ char _convBuf[MAX_PAYLOAD*2+1];
|
||||
void _callbackTransportReady(void)
|
||||
{
|
||||
if (!_coreConfig.presentationSent) {
|
||||
#if !defined(MY_GATEWAY_FEATURE) // GW calls presentNode() when client connected
|
||||
presentNode();
|
||||
#endif
|
||||
_registerNode();
|
||||
_coreConfig.presentationSent = true;
|
||||
}
|
||||
@@ -94,7 +96,7 @@ void _begin(void)
|
||||
// set defaults
|
||||
_coreConfig.presentationSent = false;
|
||||
|
||||
// Call before() in sketch (if it exists)
|
||||
// Call sketch before() (if defined)
|
||||
if (before) {
|
||||
CORE_DEBUG(PSTR("MCO:BGN:BFR\n")); // before callback
|
||||
before();
|
||||
@@ -143,7 +145,7 @@ void _begin(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Call sketch setup
|
||||
// Call sketch setup() (if defined)
|
||||
if (setup) {
|
||||
CORE_DEBUG(PSTR("MCO:BGN:STP\n")); // setup callback
|
||||
setup();
|
||||
@@ -223,33 +225,39 @@ void presentNode(void)
|
||||
|
||||
uint8_t getNodeId(void)
|
||||
{
|
||||
uint8_t result = VALUE_NOT_DEFINED;
|
||||
uint8_t result;
|
||||
#if defined(MY_GATEWAY_FEATURE)
|
||||
result = GATEWAY_ADDRESS;
|
||||
#elif defined(MY_SENSOR_NETWORK)
|
||||
result = transportGetNodeId();
|
||||
#else
|
||||
result = VALUE_NOT_DEFINED;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t getParentNodeId(void)
|
||||
{
|
||||
uint8_t result = VALUE_NOT_DEFINED;
|
||||
uint8_t result;
|
||||
#if defined(MY_GATEWAY_FEATURE)
|
||||
result = VALUE_NOT_DEFINED; // GW doesn't have a parent
|
||||
#elif defined(MY_SENSOR_NETWORK)
|
||||
result = transportGetParentNodeId();
|
||||
#else
|
||||
result = VALUE_NOT_DEFINED;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t getDistanceGW(void)
|
||||
{
|
||||
uint8_t result = VALUE_NOT_DEFINED;
|
||||
uint8_t result;
|
||||
#if defined(MY_GATEWAY_FEATURE)
|
||||
result = 0;
|
||||
#elif defined(MY_SENSOR_NETWORK)
|
||||
result = transportGetDistanceGW();
|
||||
#else
|
||||
result = VALUE_NOT_DEFINED;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -85,13 +85,13 @@
|
||||
#define __atomicWrite(A,P,V) do { if ((A) < 0x40) {bitWrite((A), (P), (V) );} else {uint8_t register saveSreg = SREG;cli();bitWrite((A), (P), (V));SREG = saveSreg;}} while(0)
|
||||
#endif
|
||||
#if !defined(digitalWriteFast)
|
||||
#define digitalWriteFast(__pin, __value) do { if (__builtin_constant_p(__pin) && __builtin_constant_p(__value)) { bitWrite(*__digitalPinToPortReg(__pin), __digitalPinToBit(__pin), (__value)); } else { digitalWrite((__pin), (__value)); } } while (0)
|
||||
#define digitalWriteFast(__pin, __value) do { if (__builtin_constant_p(__pin) && __builtin_constant_p(__value)) { bitWrite(*__digitalPinToPortReg(__pin), (uint8_t)__digitalPinToBit(__pin), (__value)); } else { digitalWrite((__pin), (__value)); } } while (0)
|
||||
#endif
|
||||
#if !defined(pinModeFast)
|
||||
#define pinModeFast(__pin, __mode) do { if (__builtin_constant_p(__pin) && __builtin_constant_p(__mode) && (__mode!=INPUT_PULLUP)) { bitWrite(*__digitalPinToDDRReg(__pin), __digitalPinToBit(__pin), (__mode)); } else { pinMode((__pin), (__mode)); } } while (0)
|
||||
#define pinModeFast(__pin, __mode) do { if (__builtin_constant_p(__pin) && __builtin_constant_p(__mode) && (__mode!=INPUT_PULLUP)) { bitWrite(*__digitalPinToDDRReg(__pin), (uint8_t)__digitalPinToBit(__pin), (__mode)); } else { pinMode((__pin), (__mode)); } } while (0)
|
||||
#endif
|
||||
#if !defined(digitalReadFast)
|
||||
#define digitalReadFast(__pin) ( (bool) (__builtin_constant_p(__pin) ) ? (( bitRead(*__digitalPinToPINReg(__pin), __digitalPinToBit(__pin))) ) : digitalRead((__pin)) )
|
||||
#define digitalReadFast(__pin) ( (bool) (__builtin_constant_p(__pin) ) ? (( bitRead(*__digitalPinToPINReg(__pin), (uint8_t)__digitalPinToBit(__pin))) ) : digitalRead((__pin)) )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -299,7 +299,7 @@ LOCAL uint8_t RF24_getDynamicPayloadSize(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
LOCAL bool RF24_isDataAvailable()
|
||||
LOCAL bool RF24_isDataAvailable(void)
|
||||
{
|
||||
return (!(RF24_getFIFOStatus() & _BV(0)) );
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Copyright (C) 2013-2016 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
@@ -249,13 +249,13 @@ LOCAL void RF24_flushRX(void);
|
||||
LOCAL void RF24_flushTX(void);
|
||||
LOCAL uint8_t RF24_getStatus(void);
|
||||
LOCAL uint8_t RF24_getFIFOStatus(void);
|
||||
LOCAL void RF24_openWritingPipe(uint8_t recipient);
|
||||
LOCAL void RF24_openWritingPipe(const uint8_t recipient);
|
||||
LOCAL void RF24_startListening(void);
|
||||
LOCAL void RF24_stopListening(void);
|
||||
LOCAL void RF24_powerDown(void);
|
||||
LOCAL bool RF24_sendMessage(const uint8_t recipient, const void* buf, const uint8_t len);
|
||||
LOCAL uint8_t RF24_getDynamicPayloadSize(void);
|
||||
LOCAL bool RF24_isDataAvailable();
|
||||
LOCAL bool RF24_isDataAvailable(void);
|
||||
LOCAL uint8_t RF24_readMessage(void* buf);
|
||||
LOCAL void RF24_setNodeAddress(const uint8_t address);
|
||||
LOCAL uint8_t RF24_getNodeID(void);
|
||||
|
||||
@@ -111,7 +111,7 @@ void setup()
|
||||
void presentation()
|
||||
{
|
||||
sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0");
|
||||
present(CHILD_ID, S_HUM);
|
||||
present(CHILD_ID, S_MOISTURE);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
Reference in New Issue
Block a user