Merge branch 'development' into dev-raspberrypi
This commit is contained in:
@@ -20,7 +20,11 @@
|
|||||||
#include "MyGatewayTransport.h"
|
#include "MyGatewayTransport.h"
|
||||||
|
|
||||||
extern bool transportSendRoute(MyMessage &message);
|
extern bool transportSendRoute(MyMessage &message);
|
||||||
|
|
||||||
|
// global variables
|
||||||
extern MyMessage _msg;
|
extern MyMessage _msg;
|
||||||
|
extern MyMessage _msgTmp;
|
||||||
|
extern NodeConfig _nc;
|
||||||
|
|
||||||
|
|
||||||
inline void gatewayTransportProcess() {
|
inline void gatewayTransportProcess() {
|
||||||
@@ -41,7 +45,7 @@ inline void gatewayTransportProcess() {
|
|||||||
if (mGetCommand(_msg) == C_INTERNAL) {
|
if (mGetCommand(_msg) == C_INTERNAL) {
|
||||||
if (_msg.type == I_VERSION) {
|
if (_msg.type == I_VERSION) {
|
||||||
// Request for version. Create the response
|
// Request for version. Create the response
|
||||||
gatewayTransportSend(buildGw(_msg, I_VERSION).set(MYSENSORS_LIBRARY_VERSION));
|
gatewayTransportSend(buildGw(_msgTmp, I_VERSION).set(MYSENSORS_LIBRARY_VERSION));
|
||||||
#ifdef MY_INCLUSION_MODE_FEATURE
|
#ifdef MY_INCLUSION_MODE_FEATURE
|
||||||
} else if (_msg.type == I_INCLUSION_MODE) {
|
} else if (_msg.type == I_INCLUSION_MODE) {
|
||||||
// Request to change inclusion mode
|
// Request to change inclusion mode
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
|
|
||||||
#include "MyGatewayTransport.h"
|
#include "MyGatewayTransport.h"
|
||||||
|
|
||||||
|
// global variables
|
||||||
|
extern MyMessage _msgTmp;
|
||||||
|
|
||||||
|
|
||||||
#if defined(MY_CONTROLLER_IP_ADDRESS)
|
#if defined(MY_CONTROLLER_IP_ADDRESS)
|
||||||
IPAddress _ethernetControllerIP(MY_CONTROLLER_IP_ADDRESS);
|
IPAddress _ethernetControllerIP(MY_CONTROLLER_IP_ADDRESS);
|
||||||
#endif
|
#endif
|
||||||
@@ -32,8 +36,6 @@ MyMessage _ethernetMsg;
|
|||||||
|
|
||||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||||
|
|
||||||
// gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char string[MY_GATEWAY_MAX_RECEIVE_LENGTH];
|
char string[MY_GATEWAY_MAX_RECEIVE_LENGTH];
|
||||||
@@ -113,7 +115,7 @@ bool gatewayTransportInit() {
|
|||||||
while (WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
delay(500);
|
delay(500);
|
||||||
MY_SERIALDEVICE.print(".");
|
MY_SERIALDEVICE.print(F("."));
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
MY_SERIALDEVICE.print(F("IP: "));
|
MY_SERIALDEVICE.print(F("IP: "));
|
||||||
@@ -127,7 +129,7 @@ bool gatewayTransportInit() {
|
|||||||
#else
|
#else
|
||||||
// Get IP address from DHCP
|
// Get IP address from DHCP
|
||||||
if (!Ethernet.begin(_ethernetGatewayMAC)) {
|
if (!Ethernet.begin(_ethernetGatewayMAC)) {
|
||||||
MY_SERIALDEVICE.print("DHCP FAILURE...");
|
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -305,7 +307,7 @@ bool gatewayTransportAvailable()
|
|||||||
clients[i] = _ethernetServer.available();
|
clients[i] = _ethernetServer.available();
|
||||||
inputString[i].idx = 0;
|
inputString[i].idx = 0;
|
||||||
debug(PSTR("Client %d connected\n"), i);
|
debug(PSTR("Client %d connected\n"), i);
|
||||||
gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
|
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||||
// Send presentation of locally attached sensors (and node if applicable)
|
// Send presentation of locally attached sensors (and node if applicable)
|
||||||
presentNode();
|
presentNode();
|
||||||
}
|
}
|
||||||
@@ -338,7 +340,7 @@ bool gatewayTransportAvailable()
|
|||||||
client = newclient;
|
client = newclient;
|
||||||
debug(PSTR("Eth: connect\n"));
|
debug(PSTR("Eth: connect\n"));
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
|
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||||
_w5100_spi_en(true);
|
_w5100_spi_en(true);
|
||||||
presentNode();
|
presentNode();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include "MyMessage.h"
|
#include "MyMessage.h"
|
||||||
#include "MyProtocol.h"
|
#include "MyProtocol.h"
|
||||||
|
|
||||||
|
// global variables
|
||||||
|
extern MyMessage _msgTmp;
|
||||||
|
|
||||||
char _serialInputString[MY_GATEWAY_MAX_RECEIVE_LENGTH]; // A buffer for incoming commands from serial interface
|
char _serialInputString[MY_GATEWAY_MAX_RECEIVE_LENGTH]; // A buffer for incoming commands from serial interface
|
||||||
int _serialInputPos;
|
int _serialInputPos;
|
||||||
@@ -38,7 +40,7 @@ bool gatewayTransportSend(MyMessage &message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool gatewayTransportInit() {
|
bool gatewayTransportInit() {
|
||||||
gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
|
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||||
// Send presentation of locally attached sensors (and node if applicable)
|
// Send presentation of locally attached sensors (and node if applicable)
|
||||||
presentNode();
|
presentNode();
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
#include "MyInclusionMode.h"
|
#include "MyInclusionMode.h"
|
||||||
|
|
||||||
|
// global variables
|
||||||
|
extern MyMessage _msgTmp;
|
||||||
|
|
||||||
unsigned long _inclusionStartTime;
|
unsigned long _inclusionStartTime;
|
||||||
bool _inclusionMode;
|
bool _inclusionMode;
|
||||||
|
|
||||||
@@ -37,7 +40,7 @@ void inclusionModeSet(bool newMode) {
|
|||||||
if (newMode != _inclusionMode) {
|
if (newMode != _inclusionMode) {
|
||||||
_inclusionMode = newMode;
|
_inclusionMode = newMode;
|
||||||
// Send back mode change to controller
|
// Send back mode change to controller
|
||||||
gatewayTransportSend(buildGw(_msg, I_INCLUSION_MODE).set((uint8_t)(_inclusionMode?1:0)));
|
gatewayTransportSend(buildGw(_msgTmp, I_INCLUSION_MODE).set((uint8_t)(_inclusionMode?1:0)));
|
||||||
if (_inclusionMode) {
|
if (_inclusionMode) {
|
||||||
_inclusionStartTime = hwMillis();
|
_inclusionStartTime = hwMillis();
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -48,7 +48,10 @@ void MyMessage::clear()
|
|||||||
command_ack_payload = 0u;
|
command_ack_payload = 0u;
|
||||||
type = 0u;
|
type = 0u;
|
||||||
sensor = 0u;
|
sensor = 0u;
|
||||||
(void)memset(data, 0u, sizeof(data));
|
(void)memset(data, 0u, sizeof(data));
|
||||||
|
|
||||||
|
// set message protocol version
|
||||||
|
miSetVersion(PROTOCOL_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyMessage::isAck() const {
|
bool MyMessage::isAck() const {
|
||||||
|
|||||||
+22
-19
@@ -162,13 +162,13 @@ typedef enum {
|
|||||||
/// @brief Type of internal messages (for internal messages)
|
/// @brief Type of internal messages (for internal messages)
|
||||||
typedef enum {
|
typedef enum {
|
||||||
I_BATTERY_LEVEL = 0, //!< Battery level
|
I_BATTERY_LEVEL = 0, //!< Battery level
|
||||||
I_TIME = 1, //!< Time
|
I_TIME = 1, //!< Time (request/response)
|
||||||
I_VERSION = 2, //!< Version
|
I_VERSION = 2, //!< Version
|
||||||
I_ID_REQUEST = 3, //!< ID request
|
I_ID_REQUEST = 3, //!< ID request
|
||||||
I_ID_RESPONSE = 4, //!< ID response
|
I_ID_RESPONSE = 4, //!< ID response
|
||||||
I_INCLUSION_MODE = 5, //!< Inclusion mode
|
I_INCLUSION_MODE = 5, //!< Inclusion mode
|
||||||
I_CONFIG = 6, //!< Config
|
I_CONFIG = 6, //!< Config (request/response)
|
||||||
I_FIND_PARENT = 7, //!< Find parent
|
I_FIND_PARENT_REQUEST = 7, //!< Find parent
|
||||||
I_FIND_PARENT_RESPONSE = 8, //!< Find parent response
|
I_FIND_PARENT_RESPONSE = 8, //!< Find parent response
|
||||||
I_LOG_MESSAGE = 9, //!< Log message
|
I_LOG_MESSAGE = 9, //!< Log message
|
||||||
I_CHILDREN = 10, //!< Children
|
I_CHILDREN = 10, //!< Children
|
||||||
@@ -179,9 +179,9 @@ typedef enum {
|
|||||||
I_SIGNING_PRESENTATION = 15, //!< Provides signing related preferences (first byte is preference version)
|
I_SIGNING_PRESENTATION = 15, //!< Provides signing related preferences (first byte is preference version)
|
||||||
I_NONCE_REQUEST = 16, //!< Request for a nonce
|
I_NONCE_REQUEST = 16, //!< Request for a nonce
|
||||||
I_NONCE_RESPONSE = 17, //!< Payload is nonce data
|
I_NONCE_RESPONSE = 17, //!< Payload is nonce data
|
||||||
I_HEARTBEAT = 18, //!< Heartbeat request
|
I_HEARTBEAT_REQUEST = 18, //!< Heartbeat request
|
||||||
I_PRESENTATION = 19, //!< Presentation message
|
I_PRESENTATION = 19, //!< Presentation message
|
||||||
I_DISCOVER = 20, //!< Discover request
|
I_DISCOVER_REQUEST = 20, //!< Discover request
|
||||||
I_DISCOVER_RESPONSE = 21, //!< Discover response
|
I_DISCOVER_RESPONSE = 21, //!< Discover response
|
||||||
I_HEARTBEAT_RESPONSE = 22, //!< Heartbeat response
|
I_HEARTBEAT_RESPONSE = 22, //!< Heartbeat response
|
||||||
I_LOCKED = 23, //!< Node is locked (reason in string-payload)
|
I_LOCKED = 23, //!< Node is locked (reason in string-payload)
|
||||||
@@ -228,26 +228,26 @@ typedef enum {
|
|||||||
#define BF_SET(y, x, start, len) ( y= ((y) &~ BF_MASK(start, len)) | BF_PREP(x, start, len) ) //!< Insert a new bitfield value 'x' into 'y'
|
#define BF_SET(y, x, start, len) ( y= ((y) &~ BF_MASK(start, len)) | BF_PREP(x, start, len) ) //!< Insert a new bitfield value 'x' into 'y'
|
||||||
|
|
||||||
// Getters/setters for special bit fields in header
|
// Getters/setters for special bit fields in header
|
||||||
#define mSetVersion(_msg,_version) BF_SET(_msg.version_length, _version, 0, 2) //!< Set version field
|
#define mSetVersion(_message,_version) BF_SET(_message.version_length, _version, 0, 2) //!< Set version field
|
||||||
#define mGetVersion(_msg) ((uint8_t)BF_GET(_msg.version_length, 0, 2)) //!< Get version field
|
#define mGetVersion(_message) ((uint8_t)BF_GET(_message.version_length, 0, 2)) //!< Get version field
|
||||||
|
|
||||||
#define mSetSigned(_msg,_signed) BF_SET(_msg.version_length, _signed, 2, 1) //!< Set signed field
|
#define mSetSigned(_message,_signed) BF_SET(_message.version_length, _signed, 2, 1) //!< Set signed field
|
||||||
#define mGetSigned(_msg) ((bool)BF_GET(_msg.version_length, 2, 1)) //!< Get versignedsion field
|
#define mGetSigned(_message) ((bool)BF_GET(_message.version_length, 2, 1)) //!< Get versignedsion field
|
||||||
|
|
||||||
#define mSetLength(_msg,_length) BF_SET(_msg.version_length, _length, 3, 5) //!< Set length field
|
#define mSetLength(_message,_length) BF_SET(_message.version_length, _length, 3, 5) //!< Set length field
|
||||||
#define mGetLength(_msg) ((uint8_t)BF_GET(_msg.version_length, 3, 5)) //!< Get length field
|
#define mGetLength(_message) ((uint8_t)BF_GET(_message.version_length, 3, 5)) //!< Get length field
|
||||||
|
|
||||||
#define mSetCommand(_msg,_command) BF_SET(_msg.command_ack_payload, _command, 0, 3) //!< Set command field
|
#define mSetCommand(_message,_command) BF_SET(_message.command_ack_payload, _command, 0, 3) //!< Set command field
|
||||||
#define mGetCommand(_msg) ((uint8_t)BF_GET(_msg.command_ack_payload, 0, 3)) //!< Get command field
|
#define mGetCommand(_message) ((uint8_t)BF_GET(_message.command_ack_payload, 0, 3)) //!< Get command field
|
||||||
|
|
||||||
#define mSetRequestAck(_msg,_rack) BF_SET(_msg.command_ack_payload, _rack, 3, 1) //!< Set ack-request field
|
#define mSetRequestAck(_message,_rack) BF_SET(_message.command_ack_payload, _rack, 3, 1) //!< Set ack-request field
|
||||||
#define mGetRequestAck(_msg) ((bool)BF_GET(_msg.command_ack_payload, 3, 1)) //!< Get ack-request field
|
#define mGetRequestAck(_message) ((bool)BF_GET(_message.command_ack_payload, 3, 1)) //!< Get ack-request field
|
||||||
|
|
||||||
#define mSetAck(_msg,_ackMsg) BF_SET(_msg.command_ack_payload, _ackMsg, 4, 1) //!< Set ack field
|
#define mSetAck(_message,_ackMsg) BF_SET(_message.command_ack_payload, _ackMsg, 4, 1) //!< Set ack field
|
||||||
#define mGetAck(_msg) ((bool)BF_GET(_msg.command_ack_payload, 4, 1)) //!< Get ack field
|
#define mGetAck(_message) ((bool)BF_GET(_message.command_ack_payload, 4, 1)) //!< Get ack field
|
||||||
|
|
||||||
#define mSetPayloadType(_msg, _pt) BF_SET(_msg.command_ack_payload, _pt, 5, 3) //!< Set payload type field
|
#define mSetPayloadType(_message, _pt) BF_SET(_message.command_ack_payload, _pt, 5, 3) //!< Set payload type field
|
||||||
#define mGetPayloadType(_msg) ((uint8_t)BF_GET(_msg.command_ack_payload, 5, 3)) //!< Get payload type field
|
#define mGetPayloadType(_message) ((uint8_t)BF_GET(_message.command_ack_payload, 5, 3)) //!< Get payload type field
|
||||||
|
|
||||||
|
|
||||||
// internal access for special fields
|
// internal access for special fields
|
||||||
@@ -256,6 +256,9 @@ typedef enum {
|
|||||||
#define miSetLength(_length) BF_SET(version_length, _length, 3, 5) //!< Internal setter for length field
|
#define miSetLength(_length) BF_SET(version_length, _length, 3, 5) //!< Internal setter for length field
|
||||||
#define miGetLength() ((uint8_t)BF_GET(version_length, 3, 5)) //!< Internal getter for length field
|
#define miGetLength() ((uint8_t)BF_GET(version_length, 3, 5)) //!< Internal getter for length field
|
||||||
|
|
||||||
|
#define miSetVersion(_version) BF_SET(version_length, _version, 0, 2) //!< Internal setter for version field
|
||||||
|
#define miGetVersion() ((uint8_t)BF_GET(version_length, 0, 2)) //!< Internal getter for version field
|
||||||
|
|
||||||
#define miSetRequestAck(_rack) BF_SET(command_ack_payload, _rack, 3, 1) //!< Internal setter for ack-request field
|
#define miSetRequestAck(_rack) BF_SET(command_ack_payload, _rack, 3, 1) //!< Internal setter for ack-request field
|
||||||
#define miGetRequestAck() ((bool)BF_GET(command_ack_payload, 3, 1)) //!< Internal getter for ack-request field
|
#define miGetRequestAck() ((bool)BF_GET(command_ack_payload, 3, 1)) //!< Internal getter for ack-request field
|
||||||
|
|
||||||
|
|||||||
@@ -80,8 +80,10 @@ void _begin() {
|
|||||||
debug(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",VER=" MYSENSORS_LIBRARY_VERSION "\n"));
|
debug(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",VER=" MYSENSORS_LIBRARY_VERSION "\n"));
|
||||||
|
|
||||||
// Call before() in sketch (if it exists)
|
// Call before() in sketch (if it exists)
|
||||||
if (before)
|
if (before) {
|
||||||
|
debug(PSTR("MCO:BGN:BFR\n")); // before callback
|
||||||
before();
|
before();
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(MY_LEDS_BLINKING_FEATURE)
|
#if defined(MY_LEDS_BLINKING_FEATURE)
|
||||||
ledsInit();
|
ledsInit();
|
||||||
@@ -162,6 +164,7 @@ void _begin() {
|
|||||||
|
|
||||||
// Call sketch setup
|
// Call sketch setup
|
||||||
if (setup) {
|
if (setup) {
|
||||||
|
debug(PSTR("MCO:BGN:STP\n")); // setup callback
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,7 +337,7 @@ bool _processInternalMessages() {
|
|||||||
// Re-send node presentation to controller
|
// Re-send node presentation to controller
|
||||||
presentNode();
|
presentNode();
|
||||||
}
|
}
|
||||||
else if (type == I_HEARTBEAT) {
|
else if (type == I_HEARTBEAT_REQUEST) {
|
||||||
sendHeartbeat();
|
sendHeartbeat();
|
||||||
}
|
}
|
||||||
else if (type == I_TIME) {
|
else if (type == I_TIME) {
|
||||||
|
|||||||
+13
-8
@@ -40,6 +40,8 @@
|
|||||||
* |E| SYS | SUB | Message | Comment
|
* |E| SYS | SUB | Message | Comment
|
||||||
* |-|------|-------|-------------------------------------------|----------------------------------------------------------------------------
|
* |-|------|-------|-------------------------------------------|----------------------------------------------------------------------------
|
||||||
* | | MCO | BGN | INIT %%s,CP=%%s,LIB=%%s | Core initialization, capabilities (CP), library version (VER)
|
* | | MCO | BGN | INIT %%s,CP=%%s,LIB=%%s | Core initialization, capabilities (CP), library version (VER)
|
||||||
|
* | | MCO | BGN | BFR | Callback before()
|
||||||
|
* | | MCO | BGN | STP | Callback setup()
|
||||||
* | | MCO | BGN | INIT OK,ID=%%d,PAR=%%d,DIS=%%d,REG=%%d | Core initialized, parent ID (PAR), distance to GW (DIS), registration (REG)
|
* | | MCO | BGN | INIT OK,ID=%%d,PAR=%%d,DIS=%%d,REG=%%d | Core initialized, parent ID (PAR), distance to GW (DIS), registration (REG)
|
||||||
* | | MCO | BGN | NODE UNLOCKED | Node successfully unlocked (see signing chapter)
|
* | | MCO | BGN | NODE UNLOCKED | Node successfully unlocked (see signing chapter)
|
||||||
* |!| MCO | BGN | TSP FAIL | Transport initialization failed
|
* |!| MCO | BGN | TSP FAIL | Transport initialization failed
|
||||||
@@ -234,7 +236,8 @@ bool wait(unsigned long ms, uint8_t cmd, uint8_t msgtype);
|
|||||||
*/
|
*/
|
||||||
int8_t sleep(unsigned long ms);
|
int8_t sleep(unsigned long ms);
|
||||||
/**
|
/**
|
||||||
* Same as sleep(), send heartbeat upon wakeup and process incoming messages
|
* Same as sleep(), send heartbeat and process incoming messages before going to sleep.
|
||||||
|
* Specify the time to wait for incoming messages by defining MY_SMART_SLEEP_WAIT_DURATION to a time (ms).
|
||||||
* @param ms Number of milliseconds to sleep.
|
* @param ms Number of milliseconds to sleep.
|
||||||
* @return -1 if timer woke it up, -2 if not possible (e.g. ongoing FW update)
|
* @return -1 if timer woke it up, -2 if not possible (e.g. ongoing FW update)
|
||||||
*/
|
*/
|
||||||
@@ -247,15 +250,16 @@ int8_t smartSleep(unsigned long ms);
|
|||||||
* @param interrupt Interrupt that should trigger the wakeup
|
* @param interrupt Interrupt that should trigger the wakeup
|
||||||
* @param mode RISING, FALLING, CHANGE
|
* @param mode RISING, FALLING, CHANGE
|
||||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||||
* @return Interrupt number wake up was triggered by pin change, -1 if timer woke it up, -2 if not possible (e.g. ongoing FW update)
|
* @return Interrupt number if wake up was triggered by pin change, -1 if wake up was triggered by timer, -2 if sleep was not possible (e.g. ongoing FW update)
|
||||||
*/
|
*/
|
||||||
int8_t sleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
int8_t sleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
||||||
/**
|
/**
|
||||||
* Same as sleep(), send heartbeat upon wakeup and process incoming messages
|
* Same as sleep(), send heartbeat and process incoming messages before going to sleep.
|
||||||
|
* Specify the time to wait for incoming messages by defining MY_SMART_SLEEP_WAIT_DURATION to a time (ms).
|
||||||
* @param interrupt Interrupt that should trigger the wakeup
|
* @param interrupt Interrupt that should trigger the wakeup
|
||||||
* @param mode RISING, FALLING, CHANGE
|
* @param mode RISING, FALLING, CHANGE
|
||||||
* @param ms Number of milliseconds to sleep.
|
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||||
* @return -1 if timer woke it up, -2 if not possible (e.g. ongoing FW update)
|
* @return Interrupt number if wake up was triggered by pin change, -1 if wake up was triggered by timer, -2 if sleep was not possible (e.g. ongoing FW update)
|
||||||
*/
|
*/
|
||||||
int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
||||||
|
|
||||||
@@ -268,17 +272,18 @@ int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
|||||||
* @param interrupt2 Second interrupt that should trigger the wakeup
|
* @param interrupt2 Second interrupt that should trigger the wakeup
|
||||||
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
||||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||||
* @return Interrupt number wake up was triggered by pin change, -1 if timer woke it up, -2 if not possible (e.g. ongoing FW update)
|
* @return Interrupt number if wake up was triggered by pin change, -1 if wake up was triggered by timer, -2 if sleep was not possible (e.g. ongoing FW update)
|
||||||
*/
|
*/
|
||||||
int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
|
int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
|
||||||
/**
|
/**
|
||||||
* Same as sleep(), send heartbeat upon wakeup and process incoming messages
|
* Same as sleep(), send heartbeat and process incoming messages before going to sleep.
|
||||||
|
* Specify the time to wait for incoming messages by defining MY_SMART_SLEEP_WAIT_DURATION to a time (ms).
|
||||||
* @param interrupt1 First interrupt that should trigger the wakeup
|
* @param interrupt1 First interrupt that should trigger the wakeup
|
||||||
* @param mode1 Mode for first interrupt (RISING, FALLING, CHANGE)
|
* @param mode1 Mode for first interrupt (RISING, FALLING, CHANGE)
|
||||||
* @param interrupt2 Second interrupt that should trigger the wakeup
|
* @param interrupt2 Second interrupt that should trigger the wakeup
|
||||||
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
||||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||||
* @return Interrupt number wake up was triggered by pin change, -1 if timer woke it up, -2 if not possible (e.g. ongoing FW update)
|
* @return Interrupt number if wake up was triggered by pin change, -1 if wake up was triggered by timer, -2 if sleep was not possible (e.g. ongoing FW update)
|
||||||
*/
|
*/
|
||||||
int8_t smartSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
|
int8_t smartSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -84,11 +84,11 @@ static bool skipSign(MyMessage &msg) {
|
|||||||
SIGN_DEBUG(PSTR("Skipping security for ACK on command %d type %d\n"), mGetCommand(msg), msg.type);
|
SIGN_DEBUG(PSTR("Skipping security for ACK on command %d type %d\n"), mGetCommand(msg), msg.type);
|
||||||
return true;
|
return true;
|
||||||
} else if (mGetCommand(msg) == C_INTERNAL &&
|
} else if (mGetCommand(msg) == C_INTERNAL &&
|
||||||
(msg.type == I_NONCE_REQUEST || msg.type == I_NONCE_RESPONSE || msg.type == I_SIGNING_PRESENTATION ||
|
(msg.type == I_NONCE_REQUEST || msg.type == I_NONCE_RESPONSE || msg.type == I_SIGNING_PRESENTATION ||
|
||||||
msg.type == I_ID_REQUEST || msg.type == I_ID_RESPONSE ||
|
msg.type == I_ID_REQUEST || msg.type == I_ID_RESPONSE ||
|
||||||
msg.type == I_FIND_PARENT || msg.type == I_FIND_PARENT_RESPONSE ||
|
msg.type == I_FIND_PARENT_REQUEST || msg.type == I_FIND_PARENT_RESPONSE ||
|
||||||
msg.type == I_HEARTBEAT || msg.type == I_HEARTBEAT_RESPONSE ||
|
msg.type == I_HEARTBEAT_REQUEST || msg.type == I_HEARTBEAT_RESPONSE ||
|
||||||
msg.type == I_PING || msg.type == I_PONG ||
|
msg.type == I_PING || msg.type == I_PONG ||
|
||||||
msg.type == I_REGISTRATION_REQUEST )) {
|
msg.type == I_REGISTRATION_REQUEST )) {
|
||||||
SIGN_DEBUG(PSTR("Skipping security for command %d type %d\n"), mGetCommand(msg), msg.type);
|
SIGN_DEBUG(PSTR("Skipping security for command %d type %d\n"), mGetCommand(msg), msg.type);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void stParentTransition() {
|
|||||||
_nc.distance = DISTANCE_INVALID; // Set distance to max and invalidate parent node ID
|
_nc.distance = DISTANCE_INVALID; // Set distance to max and invalidate parent node ID
|
||||||
_nc.parentNodeId = AUTO;
|
_nc.parentNodeId = AUTO;
|
||||||
// Broadcast find parent request
|
// Broadcast find parent request
|
||||||
transportRouteMessage(build(_msgTmp, _nc.nodeId, BROADCAST_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT, false).set(""));
|
transportRouteMessage(build(_msgTmp, _nc.nodeId, BROADCAST_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_REQUEST, false).set(""));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,7 +509,7 @@ void transportProcessMessage() {
|
|||||||
if (type == I_FIND_PARENT_RESPONSE) {
|
if (type == I_FIND_PARENT_RESPONSE) {
|
||||||
#if !defined(MY_GATEWAY_FEATURE) && !defined(MY_PARENT_NODE_IS_STATIC)
|
#if !defined(MY_GATEWAY_FEATURE) && !defined(MY_PARENT_NODE_IS_STATIC)
|
||||||
if (_transportSM.findingParentNode) { // only process if find parent active
|
if (_transportSM.findingParentNode) { // only process if find parent active
|
||||||
// Reply to a I_FIND_PARENT message. Check if the distance is shorter than we already have.
|
// Reply to a I_FIND_PARENT_REQUEST message. Check if the distance is shorter than we already have.
|
||||||
uint8_t distance = _msg.getByte();
|
uint8_t distance = _msg.getByte();
|
||||||
TRANSPORT_DEBUG(PSTR("TSF:MSG:FPAR RES,ID=%d,D=%d\n"), sender, distance); // find parent response
|
TRANSPORT_DEBUG(PSTR("TSF:MSG:FPAR RES,ID=%d,D=%d\n"), sender, distance); // find parent response
|
||||||
if (isValidDistance(distance)) {
|
if (isValidDistance(distance)) {
|
||||||
@@ -579,7 +579,7 @@ void transportProcessMessage() {
|
|||||||
if (command == C_INTERNAL) {
|
if (command == C_INTERNAL) {
|
||||||
if (isTransportReady()) {
|
if (isTransportReady()) {
|
||||||
// only reply if node is fully operational
|
// only reply if node is fully operational
|
||||||
if (type == I_FIND_PARENT) {
|
if (type == I_FIND_PARENT_REQUEST) {
|
||||||
#if defined(MY_REPEATER_FEATURE)
|
#if defined(MY_REPEATER_FEATURE)
|
||||||
if (sender != _nc.parentNodeId) { // no circular reference
|
if (sender != _nc.parentNodeId) { // no circular reference
|
||||||
TRANSPORT_DEBUG(PSTR("TSF:MSG:FPAR REQ,ID=%d\n"), sender); // FPR: find parent request
|
TRANSPORT_DEBUG(PSTR("TSF:MSG:FPAR REQ,ID=%d\n"), sender); // FPR: find parent request
|
||||||
@@ -603,7 +603,7 @@ void transportProcessMessage() {
|
|||||||
return; // no further processing required
|
return; // no further processing required
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type == I_DISCOVER) {
|
if (type == I_DISCOVER_REQUEST) {
|
||||||
if (last == _nc.parentNodeId) {
|
if (last == _nc.parentNodeId) {
|
||||||
// random wait to minimize collisions
|
// random wait to minimize collisions
|
||||||
delay(hwMillis() & 0x3ff);
|
delay(hwMillis() & 0x3ff);
|
||||||
@@ -692,8 +692,7 @@ inline void transportProcessFIFO() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool transportSendWrite(uint8_t to, MyMessage &message) {
|
bool transportSendWrite(uint8_t to, MyMessage &message) {
|
||||||
// set protocol version and update last
|
// Update last
|
||||||
mSetVersion(message, PROTOCOL_VERSION);
|
|
||||||
message.last = _nc.nodeId;
|
message.last = _nc.nodeId;
|
||||||
|
|
||||||
// sign message if required
|
// sign message if required
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
|
unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
|
||||||
double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
|
double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
|
||||||
boolean pcReceived = false;
|
bool pcReceived = false;
|
||||||
volatile unsigned long pulseCount = 0;
|
volatile unsigned long pulseCount = 0;
|
||||||
volatile unsigned long lastBlink = 0;
|
volatile unsigned long lastBlink = 0;
|
||||||
volatile unsigned long watt = 0;
|
volatile unsigned long watt = 0;
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
|
|
||||||
// Global Vars
|
// Global Vars
|
||||||
unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds)
|
unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds)
|
||||||
boolean metric = true;
|
bool metric = true;
|
||||||
long randNumber;
|
long randNumber;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void presentation() {
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// Read digital motion value
|
// Read digital motion value
|
||||||
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
|
bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
|
||||||
|
|
||||||
Serial.println(tripped);
|
Serial.println(tripped);
|
||||||
send(msg.set(tripped?"1":"0")); // Send tripped value to gw
|
send(msg.set(tripped?"1":"0")); // Send tripped value to gw
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void presentation() {
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// Read digital motion value
|
// Read digital motion value
|
||||||
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
|
bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
|
||||||
|
|
||||||
Serial.println(tripped);
|
Serial.println(tripped);
|
||||||
send(msg.set(tripped?"1":"0")); // Send tripped value to gw
|
send(msg.set(tripped?"1":"0")); // Send tripped value to gw
|
||||||
|
|||||||
@@ -36,8 +36,8 @@
|
|||||||
|
|
||||||
unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
|
unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
|
||||||
float lastPH;
|
float lastPH;
|
||||||
boolean receivedConfig = false;
|
bool receivedConfig = false;
|
||||||
boolean metric = true;
|
bool metric = true;
|
||||||
// Initialize PH message
|
// Initialize PH message
|
||||||
MyMessage msg(0, V_PH);
|
MyMessage msg(0, V_PH);
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ const int knockComplete = 1200; // Longest time to wait for a knock before we
|
|||||||
byte secretCode[maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Initial setup: "Shave and a Hair Cut, two bits."
|
byte secretCode[maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Initial setup: "Shave and a Hair Cut, two bits."
|
||||||
int knockReadings[maximumKnocks]; // When someone knocks this array fills with the delays between knocks.
|
int knockReadings[maximumKnocks]; // When someone knocks this array fills with the delays between knocks.
|
||||||
int knockSensorValue = 0; // Last reading of the knock sensor.
|
int knockSensorValue = 0; // Last reading of the knock sensor.
|
||||||
boolean programModeActive = false; // True if we're trying to program a new knock.
|
bool programModeActive = false; // True if we're trying to program a new knock.
|
||||||
|
|
||||||
bool lockStatus;
|
bool lockStatus;
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ void setLockState(bool state, bool doSend){
|
|||||||
|
|
||||||
// Checks to see if our knock matches the secret.
|
// Checks to see if our knock matches the secret.
|
||||||
// Returns true if it's a good knock, false if it's not.
|
// Returns true if it's a good knock, false if it's not.
|
||||||
boolean validateKnock(){
|
bool validateKnock(){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
int currentKnockCount = 0;
|
int currentKnockCount = 0;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ double ppl = ((double)PULSE_FACTOR)/1000; // Pulses per liter
|
|||||||
volatile unsigned long pulseCount = 0;
|
volatile unsigned long pulseCount = 0;
|
||||||
volatile unsigned long lastBlink = 0;
|
volatile unsigned long lastBlink = 0;
|
||||||
volatile double flow = 0;
|
volatile double flow = 0;
|
||||||
boolean pcReceived = false;
|
bool pcReceived = false;
|
||||||
unsigned long oldPulseCount = 0;
|
unsigned long oldPulseCount = 0;
|
||||||
unsigned long newBlink = 0;
|
unsigned long newBlink = 0;
|
||||||
double oldflow = 0;
|
double oldflow = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user