Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transport update #722

Merged
merged 17 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
445 changes: 320 additions & 125 deletions MyConfig.h

Large diffs are not rendered by default.

170 changes: 118 additions & 52 deletions MySensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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-2017 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
Expand All @@ -25,6 +25,7 @@
#ifndef MySensors_h
#define MySensors_h

#include <Arduino.h>
#include "core/MySensorsCore.h"

// Detect node type
Expand All @@ -38,8 +39,9 @@
*/
/**
* @def MY_NODE_TYPE
* @brief Contain a string describing the class of sketch/node (gateway/repeater/sensor).
* @brief Contain a string describing the class of sketch/node (gateway/repeater/node).
*/

#if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100) || defined(MY_GATEWAY_ENC28J60) || defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX) || defined(MY_GATEWAY_MQTT_CLIENT)
#define MY_GATEWAY_FEATURE
#define MY_IS_GATEWAY (true)
Expand All @@ -52,8 +54,27 @@
#define MY_NODE_TYPE "NODE"
#endif

// Enable radio "feature" if one of the radio types was enabled
#if defined(MY_RADIO_NRF24) || defined(MY_RADIO_RFM69) || defined(MY_RADIO_RFM95) || defined(MY_RS485)
// DEBUG
#if defined(MY_DEBUG)
// standard debug output
#define MY_DEBUG_VERBOSE_CORE
#define MY_DEBUG_VERBOSE_TRANSPORT
#define MY_DEBUG_VERBOSE_OTA_UPDATE
#endif

#if defined(MY_DEBUG) || defined(MY_DEBUG_VERBOSE_CORE) || defined(MY_DEBUG_VERBOSE_TRANSPORT) || defined(MY_DEBUG_VERBOSE_SIGNING) || defined(MY_DEBUG_VERBOSE_OTA_UPDATE) || defined(MY_DEBUG_VERBOSE_RF24) || defined(MY_DEBUG_VERBOSE_RFM69) || defined(MY_DEBUG_VERBOSE_RFM95)
#define DEBUG_OUTPUT_ENABLED
#define DEBUG_OUTPUT(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug
#else
#define DEBUG_OUTPUT(x,...) //!< debug NULL
#endif

// transport layer files
#define debug(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__) //!< debug


// Enable sensor network "feature" if one of the transport types was enabled
#if defined(MY_RADIO_RF24) || defined(MY_RADIO_RFM69) || defined(MY_RADIO_RFM95) || defined(MY_RS485)
#define MY_SENSOR_NETWORK
#endif

Expand Down Expand Up @@ -91,6 +112,7 @@ define MY_DEFAULT_ERR_LED_PIN, MY_DEFAULT_TX_LED_PIN or\
MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#endif

// tk: move to MyConfig.h
/**
* @def MY_DEFAULT_LED_BLINK_PERIOD
* @brief Default LEDs blinking period in milliseconds.
Expand All @@ -99,6 +121,8 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#define MY_DEFAULT_LED_BLINK_PERIOD 300
#endif

// ===

#if defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
#include "core/MyLeds.cpp"
#else
Expand Down Expand Up @@ -148,6 +172,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#if defined(MY_CONTROLLER_IP_ADDRESS) || defined(MY_CONTROLLER_URL_ADDRESS)
#define MY_GATEWAY_CLIENT_MODE
#endif

#if defined(MY_USE_UDP) && !defined(MY_GATEWAY_CLIENT_MODE)
#error You must specify MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS for UDP
#endif
Expand All @@ -156,6 +181,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#if defined(MY_SENSOR_NETWORK)
// We assume that a gateway having a radio also should act as repeater
#define MY_REPEATER_FEATURE

#endif
// GATEWAY - COMMON FUNCTIONS
// We support MQTT Client using W5100, ESP8266 and Linux
Expand All @@ -166,6 +192,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#if !defined(MY_MQTT_PUBLISH_TOPIC_PREFIX)
#error You must specify a topic publish prefix MY_MQTT_PUBLISH_TOPIC_PREFIX for this MQTT client
#endif

#if !defined(MY_MQTT_SUBSCRIBE_TOPIC_PREFIX)
#error You must specify a topic subscribe prefix MY_MQTT_SUBSCRIBE_TOPIC_PREFIX for this MQTT client
#endif
Expand Down Expand Up @@ -222,29 +249,69 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#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
// TRANSPORT
// count enabled transports
#if defined(MY_RADIO_RF24)
#define __RF24CNT 1 //!< __RF24CNT
#else
#define __RF24CNT 0 //!< __RF24CNT
#endif
#if defined(MY_RADIO_RFM69)
#define __RFM69CNT 1 //!< __RFM69CNT
#else
#define __RFM69CNT 0 //!< __RFM69CNT
#endif
#if defined(MY_RADIO_RFM95)
#define __RFM95CNT 1 //!< __RFM95CNT
#else
#define __RFM95CNT 0 //!< __RFM95CNT
#endif
#if defined(MY_RS485)
#define __RS485CNT 1 //!< __RS485CNT
#else
#define __RS485CNT 0 //!< __RS485CNT
#endif

#if (__RF24CNT + __RFM69CNT + __RFM95CNT + __RS485CNT > 1)
#error Only one forward link driver can be activated
#endif

// TRANSPORT INCLUDES
#if defined(MY_RADIO_RF24) || defined(MY_RADIO_RFM69) || defined(MY_RADIO_RFM95) || defined(MY_RS485)
#include "hal/transport/MyTransportHAL.h"
#include "core/MyTransport.h"


// SANITY CHECK FEATURE
#if defined(MY_REPEATER_FEATURE)
#define MY_TRANSPORT_SANITY_CHECK
#endif

// PARENT CHECK
#if defined(MY_PARENT_NODE_IS_STATIC) && (MY_PARENT_NODE_ID == AUTO)
#error Parent is static but no parent ID defined, set MY_PARENT_NODE_ID.
#endif

#if defined(MY_TRANSPORT_DONT_CARE_MODE)
#error This directive is deprecated, set MY_TRANSPORT_WAIT_READY_MS instead!
#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) || defined(__linux__)
#define MY_RAM_ROUTING_TABLE_ENABLED
#elif defined(ARDUINO_ARCH_AVR)
#if defined(__avr_atmega1280__) || defined(__avr_atmega1284__) || defined(__avr_atmega2560__)
// >4kb, enable it
#define MY_RAM_ROUTING_TABLE_ENABLED
#else
// memory limited, enable with care
// #define MY_RAM_ROUTING_TABLE_ENABLED
#endif // __avr_atmega1280__, __avr_atmega1284__, __avr_atmega2560__
#endif // ARDUINO_ARCH_AVR
#endif

// RADIO
#if defined(MY_RADIO_NRF24) || defined(MY_RADIO_RFM69) || defined(MY_RADIO_RFM95) ||defined(MY_RS485)
// SOFTSPI
#ifdef MY_SOFTSPI
#if defined(ARDUINO_ARCH_ESP8266)
Expand All @@ -253,64 +320,63 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#include "drivers/AVR/DigitalIO/DigitalIO.h"
#endif

#if defined(MY_RADIO_NRF24) && defined(__linux__) && !(defined(LINUX_SPI_BCM) || defined(LINUX_SPI_SPIDEV))
#error No support for nRF24 radio on this platform
#endif

#include "core/MyTransport.cpp"

// count enabled transports
#if defined(MY_RADIO_NRF24)
#define __RF24CNT 1
#else
#define __RF24CNT 0
#endif
#if defined(MY_RADIO_RFM69)
#define __RFM69CNT 1
#else
#define __RFM69CNT 0
#endif
#if defined(MY_RADIO_RFM95)
#define __RFM95CNT 1
#else
#define __RFM95CNT 0
#endif
#if defined(MY_RS485)
#define __RS485CNT 1
// POWER PIN
#if defined(MY_RF24_POWER_PIN) || defined(MY_RFM69_POWER_PIN) || defined(MY_RFM95_POWER_PIN)
#define RADIO_CAN_POWER_OFF (true)
#else
#define __RS485CNT 0
#define RADIO_CAN_POWER_OFF (false)
#endif


#if (__RF24CNT + __RFM69CNT + __RFM95CNT + __RS485CNT > 1)
#error Only one forward link driver can be activated
// Transport drivers
#if defined(MY_RADIO_RF24)
#if defined(__linux__) && !(defined(LINUX_SPI_BCM) || defined(LINUX_SPI_SPIDEV))
#error No support for nRF24 radio on this platform
#endif

#if defined(MY_RADIO_NRF24)
#if defined(MY_RF24_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.cpp"
#endif
#include "drivers/RF24/RF24.cpp"
#include "core/MyTransportNRF24.cpp"
#include "hal/transport/MyTransportRF24.cpp"
#elif defined(MY_RS485)
#if !defined(MY_RS485_HWSERIAL)
#if defined(__linux__)
#error You must specify MY_RS485_HWSERIAL for RS485 transport
#endif
#include "drivers/AltSoftSerial/AltSoftSerial.cpp"
#endif
#include "core/MyTransportRS485.cpp"
#include "hal/transport/MyTransportRS485.cpp"
#elif defined(MY_RADIO_RFM69)
#include "drivers/RFM69/RFM69.cpp"
#include "core/MyTransportRFM69.cpp"
#if defined(MY_RFM69_NEW_DRIVER)
#include "drivers/RFM69/new/RFM69_new.cpp"
#else
#include "drivers/RFM69/old/RFM69_old.cpp"
#endif
#include "hal/transport/MyTransportRFM69.cpp"
#elif defined(MY_RADIO_RFM95)
#if defined(MY_RFM95_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.cpp"
#endif
#include "drivers/RFM95/RFM95.cpp"
#include "core/MyTransportRFM95.cpp"
#include "hal/transport/MyTransportRFM95.cpp"
#endif

// PASSIVE MODE
#if defined(MY_PASSIVE_NODE)
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
#define MY_PARENT_NODE_IS_STATIC // prevents searching new parent
#undef MY_REGISTRATION_FEATURE
#undef MY_SIGNING_FEATURE
#undef MY_OTA_FIRMWARE_FEATURE
#if (defined(MY_GATEWAY_FEATURE) || defined(MY_REPEATER_FEATURE))
#error This node is configured as GW/repeater, MY_PASSIVE_NODE cannot be set simultaneously
#endif
#if (MY_NODE_ID == AUTO)
#error MY_PASSIVE_NODE configuration requires setting MY_NODE_ID
#endif
#endif

#if defined(MY_PARENT_NODE_IS_STATIC) && (MY_PARENT_NODE_ID == AUTO)
#error Parent is static but no parent ID defined.
#include "core/MyTransport.cpp"
#endif

// Make sure to disable child features when parent feature is disabled
Expand All @@ -336,8 +402,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#include "core/MyMessage.cpp"
#include "core/MySensorsCore.cpp"

#include <Arduino.h>

// HW mains
#if !defined(MY_CORE_ONLY)
#if defined(ARDUINO_ARCH_ESP8266)
#include "core/MyMainESP8266.cpp"
Expand All @@ -351,6 +416,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#endif

#endif

// Doxygen specific constructs, not included when built normally
// This is used to enable disabled macros/definitions to be included in the documentation as well.
#if DOXYGEN
Expand Down
8 changes: 7 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ MySensors options:
personalized with the same AES key
--my-rx-message-buffer-size=<SIZE>
Buffer size for incoming messages when using rf24 interrupts. [20]
--my-rs485-serial-port=<PORT>
--my-rf69-irq-pin=<PIN> Pin number connected to RFM69 IRQ pin.
--my-rs485-serial-port=<PORT>
RS485 serial port. You must provide a port.
--my-rs485-baudrate=<BAUD> RS485 baudrate. [9600]
--my-rs485-de-pin=<PIN> Pin number connected to RS485 driver enable pin.
Expand Down Expand Up @@ -379,6 +380,9 @@ for opt do
--my-rx-message-buffer-size=*)
CPPFLAGS="-DMY_RX_MESSAGE_BUFFER_SIZE=${optarg} $CPPFLAGS"
;;
--my-rf69-irq-pin=*)
CPPFLAGS="-DMY_RF69_IRQ_PIN=${optarg} $CPPFLAGS"
;;
--my-rs485-serial-port=*)
CPPFLAGS="-DMY_RS485_HWSERIAL=\\\"${optarg}\\\" $CPPFLAGS"
;;
Expand Down Expand Up @@ -502,6 +506,8 @@ if [[ ${transport_type} == "none" ]]; then
:
elif [[ ${transport_type} == "nrf24" ]]; then
CPPFLAGS="-DMY_RADIO_NRF24 $CPPFLAGS"
elif [[ ${transport_type} == "rfm69" ]]; then
CPPFLAGS="-DMY_RADIO_RFM69 $CPPFLAGS"
elif [[ ${transport_type} == "rs485" ]]; then
CPPFLAGS="-DMY_RS485 $CPPFLAGS"
elif [[ ${transport_type} == "rfm95" ]]; then
Expand Down
8 changes: 8 additions & 0 deletions core/MyCapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
#if defined(MY_RADIO_NRF24)
#define MY_CAP_RADIO "N"
#elif defined(MY_RADIO_RFM69)
#if !defined(MY_RFM69_NEW_DRIVER)
// old RFM69 driver
#define MY_CAP_RADIO "R"
#else
// new RFM69 driver
#define MY_CAP_RADIO "P"
#endif
#elif defined(MY_RADIO_RFM95)
#define MY_CAP_RADIO "L"
#elif defined(MY_RS485)
Expand All @@ -50,6 +56,8 @@
#define MY_CAP_TYPE "G"
#elif defined(MY_REPEATER_FEATURE)
#define MY_CAP_TYPE "R"
#elif defined(MY_PASSIVE_NODE)
#define MY_CAP_TYPE "P"
#else
#define MY_CAP_TYPE "N"
#endif
Expand Down
32 changes: 16 additions & 16 deletions core/MyEepromAddresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@
#define MyEepromAddresses_h

// EEPROM variable sizes, in bytes
#define SIZE_NODE_ID (1) //!< Size node ID
#define SIZE_PARENT_NODE_ID (1) //!< Size parent node ID
#define SIZE_DISTANCE (1) //!< Size GW distance
#define SIZE_ROUTES (256) //!< Size routing table
#define SIZE_CONTROLLER_CONFIG (24) //!< Size controller config
#define SIZE_FIRMWARE_TYPE (2) //!< Size firmware type
#define SIZE_FIRMWARE_VERSION (2) //!< Size firmware version
#define SIZE_FIRMWARE_BLOCKS (2) //!< Size firmware blocks
#define SIZE_FIRMWARE_CRC (2) //!< Size firmware CRC
#define SIZE_SIGNING_REQUIREMENT_TABLE (32) //!< Size signing requirement table
#define SIZE_WHITELIST_REQUIREMENT_TABLE (32) //!< Size whitelist requirement table
#define SIZE_SIGNING_SOFT_HMAC_KEY (32) //!< Size soft signing HMAC key
#define SIZE_SIGNING_SOFT_SERIAL (9) //!< Size soft signing serial
#define SIZE_RF_ENCRYPTION_AES_KEY (16) //!< Size RF AES encryption key
#define SIZE_NODE_LOCK_COUNTER (1) //!< Size node lock counter
#define SIZE_NODE_ID (1u) //!< Size node ID
#define SIZE_PARENT_NODE_ID (1u) //!< Size parent node ID
#define SIZE_DISTANCE (1u) //!< Size GW distance
#define SIZE_ROUTES (256u) //!< Size routing table
#define SIZE_CONTROLLER_CONFIG (24u) //!< Size controller config
#define SIZE_FIRMWARE_TYPE (2u) //!< Size firmware type
#define SIZE_FIRMWARE_VERSION (2u) //!< Size firmware version
#define SIZE_FIRMWARE_BLOCKS (2u) //!< Size firmware blocks
#define SIZE_FIRMWARE_CRC (2u) //!< Size firmware CRC
#define SIZE_SIGNING_REQUIREMENT_TABLE (32u) //!< Size signing requirement table
#define SIZE_WHITELIST_REQUIREMENT_TABLE (32u) //!< Size whitelist requirement table
#define SIZE_SIGNING_SOFT_HMAC_KEY (32u) //!< Size soft signing HMAC key
#define SIZE_SIGNING_SOFT_SERIAL (9u) //!< Size soft signing serial
#define SIZE_RF_ENCRYPTION_AES_KEY (16u) //!< Size RF AES encryption key
#define SIZE_NODE_LOCK_COUNTER (1u) //!< Size node lock counter


/** @brief EEPROM start address */
#define EEPROM_START 0
#define EEPROM_START (0u)
/** @brief Address node ID */
#define EEPROM_NODE_ID_ADDRESS EEPROM_START
/** @brief Address parent node ID */
Expand Down
Loading