Merge pull request #561 from tekka007/transportUpdate
Various MyTransport optimisations
This commit is contained in:
+60
-13
@@ -2,7 +2,7 @@
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* repeater and gateway builds a routing tables in RAM or EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
@@ -81,18 +81,60 @@
|
||||
//#define MY_RADIO_RFM69
|
||||
//#define MY_RS485
|
||||
|
||||
/**
|
||||
* @def MY_RAM_ROUTING_TABLE_FEATURE
|
||||
* @brief If enabled, the routing table is kept in RAM (if memory allows) and saved in regular intervals.
|
||||
* note: AVR has limited memory, use with care
|
||||
*/
|
||||
#define MY_RAM_ROUTING_TABLE_FEATURE
|
||||
|
||||
/**
|
||||
* @def MY_ROUTING_TABLE_SAVE_INTERVAL_MS
|
||||
* @brief Interval to dump content of routing table to eeprom
|
||||
*/
|
||||
#ifndef MY_ROUTING_TABLE_SAVE_INTERVAL_MS
|
||||
#define MY_ROUTING_TABLE_SAVE_INTERVAL_MS (10*60*1000ul)
|
||||
#endif
|
||||
/**
|
||||
* @def MY_TRANSPORT_SANITY_CHECK
|
||||
* @brief If enabled, node will check transport in regular intervals to detect HW issues and re-initialize in case of failure. This feature is enabled for all repeater nodes (incl. GW)
|
||||
* @brief If enabled, node will check transport in regular intervals to detect HW issues and re-initialize in case of failure.
|
||||
* This feature is enabled for all repeater nodes (incl. GW)
|
||||
*/
|
||||
//#define MY_TRANSPORT_SANITY_CHECK
|
||||
|
||||
/**
|
||||
* @def MY_TRANSPORT_SANITY_CHECK_INTERVAL
|
||||
* @def MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS
|
||||
* @brief Interval (in ms) of transport sanity checks
|
||||
*/
|
||||
#ifndef MY_TRANSPORT_SANITY_CHECK_INTERVAL
|
||||
#define MY_TRANSPORT_SANITY_CHECK_INTERVAL ((uint32_t)60000)
|
||||
#ifndef MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS
|
||||
#define MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS (60*1000ul)
|
||||
#endif
|
||||
/**
|
||||
* @def MY_TRANSPORT_DISCOVERY_INTERVAL_MS
|
||||
* @brief This is a gateway-only feature: Interval (in ms) to issue network discovery checks
|
||||
*/
|
||||
#ifndef MY_TRANSPORT_DISCOVERY_INTERVAL_MS
|
||||
#define MY_TRANSPORT_DISCOVERY_INTERVAL_MS (10*60*1000ul)
|
||||
#endif
|
||||
|
||||
/**
|
||||
*@def MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
||||
*@brief If set, uplink check to GW is disabled during transport initialisation
|
||||
*/
|
||||
//#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
||||
|
||||
/**
|
||||
*@def MY_TRANSPORT_DONT_CARE_MODE
|
||||
*@brief If set, transport traffic is unmonitored and GW connection is optional
|
||||
*/
|
||||
//#define MY_TRANSPORT_DONT_CARE_MODE
|
||||
|
||||
/**
|
||||
*@def MY_TRANSPORT_MAX_TX_FAILURES
|
||||
*@brief Set to override max. consecutive TX failures until SNP is initiated
|
||||
*/
|
||||
//#define MY_TRANSPORT_MAX_TX_FAILURES (10u)
|
||||
|
||||
/**
|
||||
* @def MY_REGISTRATION_FEATURE
|
||||
* @brief If enabled, node has to register to gateway/controller before allowed to send sensor data.
|
||||
@@ -105,14 +147,13 @@
|
||||
*/
|
||||
|
||||
#ifndef MY_REGISTRATION_RETRIES
|
||||
#define MY_REGISTRATION_RETRIES 3
|
||||
#define MY_REGISTRATION_RETRIES (3u)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def MY_REGISTRATION_DEFAULT
|
||||
* @brief Node registration default - this applies if no registration response is recieved from controller
|
||||
* @brief Node registration default - this applies if no registration response is received from controller
|
||||
*/
|
||||
|
||||
#define MY_REGISTRATION_DEFAULT true
|
||||
|
||||
/**
|
||||
@@ -149,8 +190,11 @@
|
||||
*/
|
||||
//#define MY_PARENT_NODE_IS_STATIC
|
||||
|
||||
// Enables repeater functionality (relays messages from other nodes)
|
||||
// #define MY_REPEATER_FEATURE
|
||||
/**
|
||||
* @def MY_REPEATER_FEATURE
|
||||
* @brief Enables repeater functionality (relays messages from other nodes)
|
||||
*/
|
||||
//#define MY_REPEATER_FEATURE
|
||||
|
||||
/**
|
||||
* @def MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS
|
||||
@@ -207,7 +251,7 @@
|
||||
* @brief Max buffersize needed for messages coming from controller.
|
||||
*/
|
||||
#ifndef MY_GATEWAY_MAX_RECEIVE_LENGTH
|
||||
#define MY_GATEWAY_MAX_RECEIVE_LENGTH 100
|
||||
#define MY_GATEWAY_MAX_RECEIVE_LENGTH (100u)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -215,7 +259,7 @@
|
||||
* @brief Max buffer size when sending messages.
|
||||
*/
|
||||
#ifndef MY_GATEWAY_MAX_SEND_LENGTH
|
||||
#define MY_GATEWAY_MAX_SEND_LENGTH 120
|
||||
#define MY_GATEWAY_MAX_SEND_LENGTH (120u)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -223,7 +267,7 @@
|
||||
* @brief Max number of parallel clients (sever mode).
|
||||
*/
|
||||
#ifndef MY_GATEWAY_MAX_CLIENTS
|
||||
#define MY_GATEWAY_MAX_CLIENTS 1
|
||||
#define MY_GATEWAY_MAX_CLIENTS (1u)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -794,5 +838,8 @@
|
||||
#define MY_RX_MESSAGE_BUFFER_FEATURE
|
||||
#define MY_RX_MESSAGE_BUFFER_SIZE
|
||||
#define MY_NODE_LOCK_FEATURE
|
||||
#define MY_REPEATER_FEATURE
|
||||
#define MY_TRANSPORT_DONT_CARE_MODE
|
||||
#define MY_LINUX_SERIAL_GROUPNAME
|
||||
#define MY_IS_SERIAL_PTY
|
||||
#endif
|
||||
|
||||
+33
@@ -236,6 +236,39 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// RAM ROUTING TABLE
|
||||
#if defined(MY_RAM_ROUTING_TABLE_FEATURE) && defined(MY_REPEATER_FEATURE)
|
||||
// activate feature based on architecture
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(LINUX_ARCH_RASPBERRYPI)
|
||||
#define MY_RAM_ROUTING_TABLE_ENABLED
|
||||
#elif defined(ARDUINO_ARCH_AVR)
|
||||
// memory limited, enable with care
|
||||
// #define MY_RAM_ROUTING_TABLE_ENABLED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MY_TRANSPORT_DONT_CARE_MODE) && !defined(MY_GATEWAY_FEATURE)
|
||||
// enables transport don't care mode, i.e. transport link is not monitored and GW connection optional
|
||||
#if !defined(MY_PARENT_NODE_ID) || MY_PARENT_NODE_ID==255
|
||||
#error MY_TRANSPORT_DONT_CARE_MODE requires MY_PARENT_NODE_ID set
|
||||
#endif
|
||||
#if !defined(MY_PARENT_NODE_IS_STATIC)
|
||||
#define MY_PARENT_NODE_IS_STATIC
|
||||
#endif
|
||||
#ifdef MY_REGISTRATION_FEATURE
|
||||
#undef MY_REGISTRATION_FEATURE
|
||||
#endif
|
||||
#ifdef MY_TRANSPORT_SANITY_CHECK
|
||||
#undef MY_TRANSPORT_SANITY_CHECK
|
||||
#endif
|
||||
#ifndef MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
||||
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
||||
#endif
|
||||
#ifdef MY_REGISTRATION_FEATURE
|
||||
#undef MY_REGISTRATION_FEATURE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// RADIO
|
||||
#if defined(MY_RADIO_NRF24) || defined(MY_RADIO_RFM69) || defined(MY_RS485)
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
#define MY_CAP_SIGN "-"
|
||||
#endif
|
||||
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_SIZE)
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
#define MY_CAP_RXBUF "Q"
|
||||
#else
|
||||
#define MY_CAP_RXBUF "-"
|
||||
@@ -79,4 +79,4 @@
|
||||
|
||||
#define MY_CAPABILITIES MY_CAP_RESET MY_CAP_RADIO MY_CAP_OTA_FW MY_CAP_TYPE MY_CAP_ARCH MY_CAP_SIGN MY_CAP_RXBUF
|
||||
|
||||
#endif /* MyGatewayTransportEthernet_h */
|
||||
#endif /* MyCapabilities_h */
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
extern MyMessage _msgTmp;
|
||||
|
||||
char _serialInputString[MY_GATEWAY_MAX_RECEIVE_LENGTH]; // A buffer for incoming commands from serial interface
|
||||
int _serialInputPos;
|
||||
uint8_t _serialInputPos;
|
||||
MyMessage _serialMsg;
|
||||
|
||||
bool gatewayTransportSend(MyMessage &message) {
|
||||
|
||||
@@ -203,6 +203,10 @@ void hwDebugPrint(const char *fmt, ... ) {
|
||||
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
||||
snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
|
||||
MY_SERIALDEVICE.print(fmtBuffer);
|
||||
#else
|
||||
// prepend timestamp (AVR nodes)
|
||||
MY_SERIALDEVICE.print(hwMillis());
|
||||
MY_SERIALDEVICE.print(" ");
|
||||
#endif
|
||||
va_list args;
|
||||
va_start (args, fmt );
|
||||
|
||||
+4
-1
@@ -34,11 +34,12 @@ typedef enum {
|
||||
INDICATION_GOT_PARENT, //!< Found parent node.
|
||||
INDICATION_REQ_NODEID, //!< Request node ID.
|
||||
INDICATION_GOT_NODEID, //!< Got a node ID.
|
||||
INDICATION_CHECK_UPLINK, //!< Check uplink
|
||||
INDICATION_REQ_REGISTRATION, //!< Request node registration.
|
||||
INDICATION_GOT_REGISTRATION, //!< Got registration reponse.
|
||||
INDICATION_REBOOT, //!< Rebooting node.
|
||||
INDICATION_PRESENT, //!< Presenting node to gateway.
|
||||
INDICATION_CLEAR_ROUTING, //!< Clear rrouting table requested.
|
||||
INDICATION_CLEAR_ROUTING, //!< Clear routing table requested.
|
||||
INDICATION_SLEEP, //!< Node goes to sleep.
|
||||
INDICATION_WAKEUP, //!< Node just woke from sleep.
|
||||
INDICATION_FW_UPDATE_START, //!< Start of OTA firmware update process.
|
||||
@@ -50,7 +51,9 @@ typedef enum {
|
||||
INDICATION_ERR_INIT_TRANSPORT, //!< MySensors transport hardware (radio) init failure.
|
||||
INDICATION_ERR_FIND_PARENT, //!< Failed to find parent node.
|
||||
INDICATION_ERR_GET_NODEID, //!< Failed to receive node ID.
|
||||
INDICATION_ERR_CHECK_UPLINK, //!< Failed to check uplink
|
||||
INDICATION_ERR_SIGN, //!< Error signing.
|
||||
INDICATION_ERR_LENGTH, //!< Invalid message length.
|
||||
INDICATION_ERR_VERSION, //!< Protocol version mismatch.
|
||||
INDICATION_ERR_NET_FULL, //!< Network full. All node ID's are taken.
|
||||
INDICATION_ERR_INIT_GWTRANSPORT, //!< Gateway transport hardware init failure.
|
||||
|
||||
+3
-3
@@ -35,9 +35,9 @@
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#define PROTOCOL_VERSION 2 //!< The version of the protocol
|
||||
#define MAX_MESSAGE_LENGTH 32 //!< The maximum size of a message (including header)
|
||||
#define HEADER_SIZE 7 //!< The size of the header
|
||||
#define PROTOCOL_VERSION (2u) //!< The version of the protocol
|
||||
#define MAX_MESSAGE_LENGTH (32u) //!< The maximum size of a message (including header)
|
||||
#define HEADER_SIZE (7u) //!< The size of the header
|
||||
#define MAX_PAYLOAD (MAX_MESSAGE_LENGTH - HEADER_SIZE) //!< The maximum size of a payload depends on #MAX_MESSAGE_LENGTH and #HEADER_SIZE
|
||||
|
||||
/// @brief The command field (message-type) defines the overall properties of a message
|
||||
|
||||
+14
-10
@@ -103,7 +103,7 @@ void _begin() {
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
// Save static parent id in eeprom (used by bootloader)
|
||||
hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID);
|
||||
transportInitialize();
|
||||
transportInitialise();
|
||||
while (!isTransportReady()) {
|
||||
hwWatchdogReset();
|
||||
transportProcess();
|
||||
@@ -146,7 +146,7 @@ void _begin() {
|
||||
inclusionInit();
|
||||
#endif
|
||||
|
||||
// initialize the transport driver
|
||||
// initialise the transport driver
|
||||
if (!gatewayTransportInit()) {
|
||||
setIndication(INDICATION_ERR_INIT_GWTRANSPORT);
|
||||
debug(PSTR("!MCO:BGN:TSP FAIL\n"));
|
||||
@@ -355,15 +355,15 @@ bool _processInternalMessages() {
|
||||
}
|
||||
else if (type == I_DEBUG) {
|
||||
#if defined(MY_DEBUG) || defined(MY_SPECIAL_DEBUG)
|
||||
char debug_msg = _msg.data[0];
|
||||
const char debug_msg = _msg.data[0];
|
||||
if (debug_msg == 'R') { // routing table
|
||||
#if defined(MY_REPEATER_FEATURE)
|
||||
for (uint8_t cnt = 0; cnt != 255; cnt++) {
|
||||
uint8_t route = hwReadConfig(EEPROM_ROUTES_ADDRESS + cnt);
|
||||
for (uint16_t cnt = 0; cnt < SIZE_ROUTES; cnt++) {
|
||||
const uint8_t route = transportGetRoute(cnt);
|
||||
if (route != BROADCAST_ADDRESS) {
|
||||
debug(PSTR("MCO:PIM:ROUTE N=%d,R=%d\n"), cnt, route);
|
||||
uint8_t OutBuf[2] = { cnt,route };
|
||||
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG, false).set(OutBuf, 2));
|
||||
uint8_t outBuf[2] = { (uint8_t)cnt,route };
|
||||
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG, false).set(outBuf, 2));
|
||||
wait(200);
|
||||
}
|
||||
}
|
||||
@@ -392,15 +392,19 @@ bool _processInternalMessages() {
|
||||
// sender is a node
|
||||
if (type == I_REGISTRATION_REQUEST) {
|
||||
#if defined(MY_GATEWAY_FEATURE)
|
||||
// register request are exclusively handled by GW/Controller
|
||||
// !!! eventually define if AUTO ACK or register request forwarded to controller
|
||||
// registeration requests are exclusively handled by GW/Controller
|
||||
#if !defined(MY_REGISTRATION_CONTROLLER)
|
||||
// auto register if version compatible
|
||||
// auto registration if version compatible
|
||||
bool approveRegistration = true;
|
||||
|
||||
#if defined(MY_CORE_COMPATIBILITY_CHECK)
|
||||
approveRegistration = (_msg.getByte() >= MY_CORE_MIN_VERSION);
|
||||
#endif
|
||||
|
||||
#if (F_CPU>16000000)
|
||||
// delay for fast GW and slow nodes
|
||||
delay(5);
|
||||
#endif
|
||||
_sendRoute(build(_msgTmp, _nc.nodeId, _msg.sender, NODE_SENSOR_ID, C_INTERNAL, I_REGISTRATION_RESPONSE, false).set(approveRegistration));
|
||||
#else
|
||||
return false; // processing of this request via controller
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
* @{
|
||||
*
|
||||
* MySensorsCore-related log messages, format: [!]SYSTEM:[SUB SYSTEM:]MESSAGE
|
||||
* - [!] Exclamation mark is prepended in case of error
|
||||
* - [!] Exclamation mark is prepended in case of error or warning
|
||||
* - SYSTEM:
|
||||
* - <b>MCO</b> messages emitted by MySensorsCore
|
||||
* - SUB SYSTEMS:
|
||||
|
||||
+413
-254
File diff suppressed because it is too large
Load Diff
+144
-59
@@ -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
|
||||
@@ -36,23 +36,27 @@
|
||||
* - TSM:ID from <b>stID</b> Check/request node ID, if dynamic node ID set
|
||||
* - TSM:UPL from <b>stUplink</b> Verify uplink connection by pinging GW
|
||||
* - TSM:READY from <b>stReady</b> Transport is ready and fully operational
|
||||
* - TSM:FAILURE from <b>stFailure</b> Failure in transport link or transport HW
|
||||
* - TSM:FAIL from <b>stFailure</b> Failure in transport link or transport HW
|
||||
* - Transport support function (<b>TSF</b>)
|
||||
* - TSF:CHKUPL from @ref transportCheckUplink(), checks connection to GW
|
||||
* - TSF:ASID from @ref transportAssignNodeID(), assigns node ID
|
||||
* - TSF:PING from @ref transportPingNode(), pings a node
|
||||
* - TSF:CRT from @ref transportClearRoutingTable(), clears routing table stored in EEPROM
|
||||
* - TSF:LRT from @ref transportLoadRoutingTable(), loads RAM routing table from EEPROM (only GW/repeaters)
|
||||
* - TSF:SRT from @ref transportSaveRoutingTable(), saves RAM routing table to EEPROM (only GW/repeaters)
|
||||
* - TSF:MSG from @ref transportProcessMessage(), processes incoming message
|
||||
* - TSF:SANCHK from @ref transportInvokeSanityCheck(), calls transport-specific sanity check
|
||||
* - TSF:ROUTE from @ref transportRouteMessage(), sends message
|
||||
* - TSF:SEND from @ref transportSendRoute(), sends message if transport is ready (exposed)
|
||||
|
||||
*
|
||||
* Transport debug log messages:
|
||||
*
|
||||
* |E| SYS | SUB | Message | Comment
|
||||
* |-|------|-----------|-----------------------|---------------------------------------------------------------------
|
||||
* | | TSM | INIT | | <b>Transition to stInit state</b>
|
||||
* | | TSM | INIT | STATID,ID=%%d | Node ID is static
|
||||
* | | TSM | INIT | TDC | Transport don't care mode
|
||||
* | | TSM | INIT | STATID=%%d | Node ID is static
|
||||
* | | TSM | INIT | TSP OK | Transport device configured and fully operational
|
||||
* | | TSM | INIT | GW MODE | Node is set up as GW, thus omitting ID and findParent states
|
||||
* |!| TSM | INIT | TSP FAIL | Transport device initialization failed
|
||||
@@ -67,13 +71,15 @@
|
||||
* |!| TSM | ID | FAIL,ID=%%d | ID verification failed, ID invalid
|
||||
* | | TSM | UPL | | <b>Transition to stUplink state</b>
|
||||
* | | TSM | UPL | OK | Uplink OK, GW returned ping
|
||||
* | | TSF | UPL | DGWC,O=%%d,N=%%d | Uplink check revealed changed network topology, old distance (O), new distance (N)
|
||||
* |!| TSM | UPL | FAIL | Uplink check failed, i.e. GW could not be pinged
|
||||
* | | TSM | READY | | <b>Transition to stReady</b>, i.e. transport is ready and fully operational
|
||||
* | | TSM | READY | SRT | Save routing table
|
||||
* |!| TSM | READY | UPL FAIL,SNP | Too many failed uplink transmissions, search new parent
|
||||
* |!| TSM | READY | FAIL,STATP | Too many failed uplink transmissions, static parent enforced
|
||||
* | | TSM | FAILURE | | <b>Transition to stFailure state</b>
|
||||
* | | TSM | FAILURE | PDT | Power-down transport
|
||||
* | | TSM | FAILURE | RE-INIT | Attempt to re-initialize transport
|
||||
* | | TSM | FAIL | CNT=%%d | <b>Transition to stFailure state</b>, consecutive failure counter (CNT)
|
||||
* | | TSM | FAIL | PDT | Power-down transport
|
||||
* | | TSM | FAIL | RE-INIT | Attempt to re-initialize transport
|
||||
* | | TSF | CHKUPL | OK | Uplink OK
|
||||
* | | TSF | CHKUPL | OK,FCTRL | Uplink OK, flood control prevents pinging GW in too short intervals
|
||||
* | | TSF | CHKUPL | DGWC,O=%%d,N=%%d | Uplink check revealed changed network topology, old distance (O), new distance (N)
|
||||
@@ -95,7 +101,8 @@
|
||||
* | | TSF | MSG | FWD BC MSG | Controlled broadcast message forwarding
|
||||
* | | TSF | MSG | REL MSG | Relay message
|
||||
* | | TSF | MSG | REL PxNG,HP=%%d | Relay PING/PONG message, increment hop counter (HP)
|
||||
* |!| TSF | MSG | PVER,%%d!=%%d | Message protocol version mismatch
|
||||
* |!| TSF | MSG | LEN,%%d!=%%d | Invalid message length, (actual!=expected)
|
||||
* |!| TSF | MSG | PVER,%%d!=%%d | Message protocol version mismatch (actual!=expected)
|
||||
* |!| TSF | MSG | SIGN VERIFY FAIL | Signing verification failed
|
||||
* |!| TSF | MSG | REL MSG,NORP | Node received a message for relaying, but node is not a repeater, message skipped
|
||||
* |!| TSF | MSG | SIGN FAIL | Signing message failed
|
||||
@@ -103,6 +110,8 @@
|
||||
* | | TSF | SANCHK | OK | Sanity check passed
|
||||
* |!| TSF | SANCHK | FAIL | Sanity check failed, attempt to re-initialize radio
|
||||
* | | TSF | CRT | OK | Clearing routing table successful
|
||||
* | | TSF | LRT | OK | Loading routing table successful
|
||||
* | | TSF | SRT | OK | Saving routing table successful
|
||||
* |!| TSF | ROUTE | FPAR ACTIVE | Finding parent active, message not sent
|
||||
* |!| TSF | ROUTE | DST %%d UNKNOWN | Routing for destination (DST) unknown, send message to parent
|
||||
* |!| TSF | SEND | TNR | Transport not ready, message cannot be sent
|
||||
@@ -123,8 +132,9 @@
|
||||
* - <b>t</b>=msg type
|
||||
* - <b>pt</b>=payload type
|
||||
* - <b>l</b>=length
|
||||
* - <b>ft</b>=failed uplink transmission counter
|
||||
* - <b>sg</b>=signing flag
|
||||
* - <b>ft</b>=failed uplink transmission counter
|
||||
* - <b>st</b>=send status, OK=success, NACK=no radio ACK received
|
||||
*
|
||||
* @brief API declaration for MyTransport
|
||||
*
|
||||
@@ -139,15 +149,50 @@
|
||||
#if defined(MY_DEBUG)
|
||||
#define TRANSPORT_DEBUG(x,...) debug(x, ##__VA_ARGS__) //!< debug
|
||||
#else
|
||||
#define TRANSPORT_DEBUG(x,...) //!< debug NULL
|
||||
#define TRANSPORT_DEBUG(x,...) //!< debug NULL
|
||||
#endif
|
||||
|
||||
#if defined(MY_REPEATER_FEATURE)
|
||||
#define TRANSMISSION_FAILURES 10 //!< search for a new parent node after this many transmission failures, higher threshold for repeating nodes
|
||||
#define MY_TRANSPORT_MAX_TX_FAILURES (10u) //!< search for a new parent node after this many transmission failures, higher threshold for repeating nodes
|
||||
#else
|
||||
#define TRANSMISSION_FAILURES 5 //!< search for a new parent node after this many transmission failures, lower threshold for non-repeating nodes
|
||||
#define MY_TRANSPORT_MAX_TX_FAILURES (5u) //!< search for a new parent node after this many transmission failures, lower threshold for non-repeating nodes
|
||||
#endif
|
||||
|
||||
#define MY_TRANSPORT_MAX_TSM_FAILURES (7u) //!< Max. number of consecutive TSM failure state entries (3bits)
|
||||
|
||||
#ifndef MY_TRANSPORT_TIMEOUT_FAILURE_STATE
|
||||
#define MY_TRANSPORT_TIMEOUT_FAILURE_STATE (10*1000ul) //!< Duration failure state (in ms)
|
||||
#endif
|
||||
#ifndef MY_TRANSPORT_TIMEOUT_EXT_FAILURE_STATE
|
||||
#define MY_TRANSPORT_TIMEOUT_EXT_FAILURE_STATE (60*1000ul) //!< Duration extended failure state (in ms)
|
||||
#endif
|
||||
#ifndef MY_TRANSPORT_STATE_TIMEOUT_MS
|
||||
#define MY_TRANSPORT_STATE_TIMEOUT_MS (2*1000ul) //!< general state timeout (in ms)
|
||||
#endif
|
||||
#ifndef MY_TRANSPORT_CHKUPL_INTERVAL_MS
|
||||
#define MY_TRANSPORT_CHKUPL_INTERVAL_MS (10*1000ul) //!< Interval to re-check uplink (in ms)
|
||||
#endif
|
||||
#ifndef MY_TRANSPORT_STATE_RETRIES
|
||||
#define MY_TRANSPORT_STATE_RETRIES (3u) //!< retries before switching to FAILURE
|
||||
#endif
|
||||
|
||||
#define AUTO (255u) //!< ID 255 is reserved
|
||||
#define BROADCAST_ADDRESS (255u) //!< broadcasts are addressed to ID 255
|
||||
#define DISTANCE_INVALID (255u) //!< invalid distance when searching for parent
|
||||
#define MAX_HOPS (254u) //!< maximal mumber of hops for ping/pong
|
||||
#define INVALID_HOPS (255u) //!< invalid hops
|
||||
#define MAX_SUBSEQ_MSGS (5u) //!< Maximum number of subsequentially processed messages in FIFO (to prevent transport deadlock if HW issue)
|
||||
|
||||
// parent node check
|
||||
#if defined(MY_PARENT_NODE_IS_STATIC) && !defined(MY_PARENT_NODE_ID)
|
||||
#error MY_PARENT_NODE_IS_STATIC but no MY_PARENT_NODE_ID defined!
|
||||
#endif
|
||||
|
||||
#define _autoFindParent (bool)(MY_PARENT_NODE_ID == AUTO) //!< returns true if static parent id is undefined
|
||||
#define isValidDistance(distance) (bool)(distance!=DISTANCE_INVALID) //!< returns true if distance is valid
|
||||
#define isValidParent(parent) (bool)(parent != AUTO) //!< returns true if parent is valid
|
||||
|
||||
// RX queue
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
#if defined(MY_RADIO_RFM69)
|
||||
#error Receive message buffering not supported for RFM69!
|
||||
@@ -159,20 +204,6 @@
|
||||
#error Receive message buffering requires message buffering feature enabled!
|
||||
#endif
|
||||
|
||||
#define TIMEOUT_FAILURE_STATE 10000 //!< duration failure state
|
||||
#define STATE_TIMEOUT 2000 //!< general state timeout
|
||||
#define STATE_RETRIES 3 //!< retries before switching to FAILURE
|
||||
#define AUTO 255 //!< ID 255 is reserved for auto initialization of nodeId.
|
||||
#define BROADCAST_ADDRESS ((uint8_t)255) //!< broadcasts are addressed to ID 255
|
||||
#define DISTANCE_INVALID ((uint8_t)255) //!< invalid distance when searching for parent
|
||||
#define MAX_HOPS ((uint8_t)254) //!< maximal mumber of hops for ping/pong
|
||||
#define INVALID_HOPS ((uint8_t)255) //!< invalid hops
|
||||
#define MAX_SUBSEQ_MSGS 5 //!< Maximum number of subsequentially processed messages in FIFO (to prevent transport deadlock if HW issue)
|
||||
#define CHKUPL_INTERVAL ((uint32_t)10000) //!< Minimum time interval to re-check uplink
|
||||
|
||||
#define _autoFindParent (bool)(MY_PARENT_NODE_ID == AUTO) //!< returns true if static parent id is undefined
|
||||
#define isValidDistance(distance) (bool)(distance!=DISTANCE_INVALID) //!< returns true if distance is valid
|
||||
#define isValidParent(parent) (bool)(parent != AUTO) //!< returns true if parent is valid
|
||||
|
||||
/**
|
||||
* @brief SM state
|
||||
@@ -190,67 +221,83 @@ struct transportState {
|
||||
* This structure stores transport status and SM variables
|
||||
*/
|
||||
typedef struct {
|
||||
// SM variables
|
||||
transportState* currentState; //!< pointer to current fsm state
|
||||
uint32_t stateEnter; //!< state enter timepoint
|
||||
// general transport variables
|
||||
uint32_t lastUplinkCheck; //!< last uplink check, required to prevent GW flooding
|
||||
uint32_t lastSanityCheck; //!< last sanity check
|
||||
// 8 bits
|
||||
bool findingParentNode : 1; //!< flag finding parent node is active
|
||||
bool preferredParentFound : 1; //!< flag preferred parent found
|
||||
bool uplinkOk : 1; //!< flag uplink ok
|
||||
bool pingActive : 1; //!< flag ping active
|
||||
bool transportActive : 1; //!< flag transport active
|
||||
uint8_t reserved : 3; //!< reserved
|
||||
uint8_t stateRetries : 3; //!< retries / state re-enter (max 7)
|
||||
// 8 bits
|
||||
uint8_t retries : 4; //!< retries / state re-enter
|
||||
uint8_t failedUplinkTransmissions : 4; //!< counter failed uplink transmissions
|
||||
uint8_t failedUplinkTransmissions : 4; //!< counter failed uplink transmissions (max 15)
|
||||
uint8_t failureCounter : 3; //!< counter for TSM failures (max 7)
|
||||
bool MsgReceived : 1; //!< flag message received
|
||||
// 8 bits
|
||||
uint8_t pingResponse; //!< stores hops received in I_PONG
|
||||
} __attribute__((packed)) transportSM;
|
||||
uint8_t pingResponse; //!< stores I_PONG hops
|
||||
} transportSM;
|
||||
|
||||
/**
|
||||
* @brief RAM routing table
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t route[SIZE_ROUTES]; //!< route for node
|
||||
} routingTable;
|
||||
|
||||
// PRIVATE functions
|
||||
|
||||
/**
|
||||
* @brief Initialize SM variables and transport HW
|
||||
* @brief Initialise SM variables and transport HW
|
||||
*/
|
||||
void stInitTransition();
|
||||
void stInitTransition(void);
|
||||
/**
|
||||
* @brief Initialise transport
|
||||
*/
|
||||
void stInitUpdate(void);
|
||||
/**
|
||||
* @brief Find parent
|
||||
*/
|
||||
void stParentTransition();
|
||||
void stParentTransition(void);
|
||||
/**
|
||||
* @brief Verify find parent responses
|
||||
*/
|
||||
void stParentUpdate();
|
||||
void stParentUpdate(void);
|
||||
/**
|
||||
* @brief Send ID request
|
||||
*/
|
||||
void stIDTransition();
|
||||
void stIDTransition(void);
|
||||
/**
|
||||
* @brief Verify ID response and GW link
|
||||
*/
|
||||
void stIDUpdate();
|
||||
void stIDUpdate(void);
|
||||
/**
|
||||
* @brief Send uplink ping request
|
||||
*/
|
||||
void stUplinkTransition();
|
||||
void stUplinkTransition(void);
|
||||
/**
|
||||
* @brief Verify uplink response
|
||||
*/
|
||||
void stUplinkUpdate(void);
|
||||
/**
|
||||
* @brief Set transport OK
|
||||
*/
|
||||
void stReadyTransition();
|
||||
void stReadyTransition(void);
|
||||
/**
|
||||
* @brief Monitor transport link
|
||||
*/
|
||||
void stReadyUpdate();
|
||||
void stReadyUpdate(void);
|
||||
/**
|
||||
* @brief Transport failure and power down radio
|
||||
*/
|
||||
void stFailureTransition();
|
||||
void stFailureTransition(void);
|
||||
/**
|
||||
* @brief Re-initialize transport after timeout
|
||||
*/
|
||||
void stFailureUpdate();
|
||||
void stFailureUpdate(void);
|
||||
/**
|
||||
* @brief Switch SM state
|
||||
* @param newState New state to switch SM to
|
||||
@@ -259,30 +306,30 @@ void transportSwitchSM(transportState& newState);
|
||||
/**
|
||||
* @brief Update SM state
|
||||
*/
|
||||
void transportUpdateSM();
|
||||
void transportUpdateSM(void);
|
||||
/**
|
||||
* @brief Request time in current SM state
|
||||
* @return ms in current state
|
||||
*/
|
||||
uint32_t transportTimeInState();
|
||||
uint32_t transportTimeInState(void);
|
||||
/**
|
||||
* @brief Call transport driver sanity check
|
||||
*/
|
||||
void transportInvokeSanityCheck();
|
||||
void transportInvokeSanityCheck(void);
|
||||
/**
|
||||
* @brief Process all pending messages in RX FIFO
|
||||
*/
|
||||
void transportProcessFIFO();
|
||||
void transportProcessFIFO(void);
|
||||
/**
|
||||
* @brief Receive message from RX FIFO and process
|
||||
*/
|
||||
void transportProcessMessage();
|
||||
void transportProcessMessage(void);
|
||||
/**
|
||||
* @brief Assign node ID
|
||||
* @param newNodeId New node ID
|
||||
* @return true if node ID valid and successfully assigned
|
||||
*/
|
||||
bool transportAssignNodeID(uint8_t newNodeId);
|
||||
bool transportAssignNodeID(const uint8_t newNodeId);
|
||||
/**
|
||||
* @brief Wait and process messages for a defined amount of time until specified message received
|
||||
* @param ms Time to wait and process incoming messages in ms
|
||||
@@ -290,13 +337,13 @@ bool transportAssignNodeID(uint8_t newNodeId);
|
||||
* @param msgtype Specific message type
|
||||
* @return true if specified command received within waiting time
|
||||
*/
|
||||
bool transportWait(uint32_t ms, uint8_t cmd, uint8_t msgtype);
|
||||
bool transportWait(const uint32_t ms, const uint8_t cmd, const uint8_t msgtype);
|
||||
/**
|
||||
* @brief Ping node
|
||||
* @param targetId Node to be pinged
|
||||
* @return hops from pinged node or 255 if no answer received within 2000ms
|
||||
*/
|
||||
uint8_t transportPingNode(uint8_t targetId);
|
||||
uint8_t transportPingNode(const uint8_t targetId);
|
||||
/**
|
||||
* @brief Send and route message according to destination
|
||||
*
|
||||
@@ -318,42 +365,80 @@ bool transportSendRoute(MyMessage &message);
|
||||
* @param message
|
||||
* @return true if message sent successfully
|
||||
*/
|
||||
bool transportSendWrite(uint8_t to, MyMessage &message);
|
||||
bool transportSendWrite(const uint8_t to, MyMessage &message);
|
||||
/**
|
||||
* @brief Check uplink to GW, includes flooding control
|
||||
* @param force to override flood control timer
|
||||
* @return true if uplink ok
|
||||
*/
|
||||
bool transportCheckUplink(bool force);
|
||||
bool transportCheckUplink(const bool force=false);
|
||||
|
||||
// PUBLIC functions
|
||||
|
||||
/**
|
||||
* @brief Initialize transport and SM
|
||||
*/
|
||||
void transportInitialize();
|
||||
void transportInitialize(void);
|
||||
/**
|
||||
* @brief Process FIFO msg and update SM
|
||||
*/
|
||||
void transportProcess();
|
||||
void transportProcess(void);
|
||||
/**
|
||||
* @brief Flag transport ready
|
||||
* @return true if transport is initialize and ready
|
||||
*/
|
||||
bool isTransportReady();
|
||||
bool isTransportReady(void);
|
||||
/**
|
||||
* @brief Flag searching parent ongoing
|
||||
* @return true if transport is searching for parent
|
||||
*/
|
||||
bool isTransportSearchingParent();
|
||||
bool isTransportSearchingParent(void);
|
||||
/**
|
||||
* @brief Flag TSM extended failure
|
||||
* @return true if TSM had too many consecutive failure state entries
|
||||
*/
|
||||
bool isTransportExtendedFailure(void);
|
||||
/**
|
||||
* @brief Flag valid message received
|
||||
* @return true if valid message received, needs to be reset if used
|
||||
*/
|
||||
bool isMessageReceived(void);
|
||||
/**
|
||||
* @brief Reset message received flag
|
||||
*/
|
||||
void resetMessageReceived(void);
|
||||
/**
|
||||
* @brief Clear routing table
|
||||
*/
|
||||
void transportClearRoutingTable();
|
||||
void transportClearRoutingTable(void);
|
||||
/**
|
||||
* @brief Return heart beat, i.e. ms in current state
|
||||
* @brief Return heart beat
|
||||
* @return MS in current state
|
||||
*/
|
||||
uint32_t transportGetHeartbeat();
|
||||
uint32_t transportGetHeartbeat(void);
|
||||
/**
|
||||
* @brief Load routing table from EEPROM to RAM.
|
||||
* Only for GW devices with enough RAM, i.e. ESP8266, RPI Sensebender GW, etc.
|
||||
* Atmega328 has only limited amount of RAM
|
||||
*/
|
||||
void transportLoadRoutingTable(void);
|
||||
/**
|
||||
* @brief Save routing table to EEPROM.
|
||||
*/
|
||||
void transportSaveRoutingTable(void);
|
||||
/**
|
||||
* @brief Update routing table
|
||||
* @param node
|
||||
* @param route
|
||||
*/
|
||||
void transportSetRoute(const uint8_t node, const uint8_t route);
|
||||
/**
|
||||
* @brief Load route to node
|
||||
* @param node
|
||||
* @return route to node
|
||||
*/
|
||||
uint8_t transportGetRoute(const uint8_t node);
|
||||
|
||||
|
||||
// interface functions for radio driver
|
||||
|
||||
|
||||
Reference in New Issue
Block a user