From 818f887926e419a73b77863714c99d75aca6ba39 Mon Sep 17 00:00:00 2001 From: Olivier Date: Sun, 2 Apr 2017 20:03:59 +0200 Subject: [PATCH] Polishing code (#803) --- MyConfig.h | 365 ++++++++++-------- MySensors.h | 25 +- core/MyCapabilities.h | 6 +- core/MyGatewayTransportEthernet.cpp | 4 +- core/MyHw.h | 8 - core/MyTransport.cpp | 41 +- core/MyTransport.h | 17 +- core/MyTransportRFM69.cpp | 93 ----- core/MyTransportRFM95.cpp | 92 ----- drivers/RFM69/new/RFM69_new.cpp | 4 +- drivers/RFM69/new/RFM69_new.h | 12 +- drivers/RFM69/old/RFM69_old.cpp | 1 - drivers/RFM95/RFM95.cpp | 6 +- drivers/RFM95/RFM95.h | 12 +- .../RFM69_RFM95_ATC_SignalReport.ino | 99 +++++ hal/transport/MyTransportHAL.h | 21 +- hal/transport/MyTransportRF24.cpp | 6 +- hal/transport/MyTransportRFM69.cpp | 4 +- hal/transport/MyTransportRFM95.cpp | 8 +- hal/transport/MyTransportRS485.cpp | 8 +- keywords.txt | 4 + 21 files changed, 393 insertions(+), 443 deletions(-) delete mode 100644 core/MyTransportRFM69.cpp delete mode 100644 core/MyTransportRFM95.cpp create mode 100644 examples/RFM69_RFM95_ATC_SignalReport/RFM69_RFM95_ATC_SignalReport.ino diff --git a/MyConfig.h b/MyConfig.h index f39b4dd..7873e8f 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -6,7 +6,7 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * 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 @@ -32,34 +32,34 @@ ***********************************/ /** -* @def MY_DEBUG -* @brief Enable MY_DEBUG in sketch to show debug prints. This option will add a lot to the size of the -* final sketch but is helpful to see what is actually is happening during development -*/ + * @def MY_DEBUG + * @brief Enable MY_DEBUG in sketch to show debug prints. This option will add a lot to the size of the + * final sketch but is helpful to see what is actually is happening during development + */ //#define MY_DEBUG /** -* @def MY_SPECIAL_DEBUG -* @brief Enable MY_SPECIAL_DEBUG in sketch to activate I_DEBUG messages if MY_DEBUG is disabled. -* I_DEBUG requests are: -* R: routing info (only repeaters): received msg XXYY (as stream), where XX is the node and YY the routing node -* V: CPU voltage -* F: CPU frequency -* M: free memory -* E: clear MySensors EEPROM area and reboot (i.e. "factory" reset) -*/ + * @def MY_SPECIAL_DEBUG + * @brief Enable MY_SPECIAL_DEBUG to enable I_DEBUG messages. + * I_DEBUG requests are: + * R: routing info (only repeaters): received msg XXYY (as stream), where XX is the node and YY the routing node + * V: CPU voltage + * F: CPU frequency + * M: free memory + * E: clear MySensors EEPROM area and reboot (i.e. "factory" reset) + */ //#define MY_SPECIAL_DEBUG /** -* @def MY_DISABLED_SERIAL -* @brief Enable MY_DISABLED_SERIAL in sketch if you want to use TX(1), RX(0) as normal I/O pins -*/ + * @def MY_DISABLED_SERIAL + * @brief Enable MY_DISABLED_SERIAL in sketch if you want to use TX(1), RX(0) as normal I/O pins + */ //#define MY_DISABLED_SERIAL /** -* @def MY_CORE_ONLY -* @brief Enable MY_CORE_ONLY flag if you want to use core functions without loading the framework -*/ + * @def MY_CORE_ONLY + * @brief Enable MY_CORE_ONLY flag if you want to use core functions without loading the framework + */ //#define MY_CORE_ONLY // Turn off debug if serial pins is used for other stuff @@ -75,17 +75,17 @@ #define MY_BAUD_RATE (115200ul) #endif /** -* @def MY_SERIAL_OUTPUT_SIZE -* @brief Max. characters for serial output. -*/ + * @def MY_SERIAL_OUTPUT_SIZE + * @brief Max. characters for serial output. + */ #ifndef MY_SERIAL_OUTPUT_SIZE #define MY_SERIAL_OUTPUT_SIZE (120u) #endif /** -* @def MY_DISABLE_REMOTE_RESET -* @brief Disables over-the-air reset of node -*/ + * @def MY_DISABLE_REMOTE_RESET + * @brief Disables over-the-air reset of node + */ //#define MY_DISABLE_REMOTE_RESET /********************************** @@ -105,37 +105,37 @@ #endif /** -* @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 -*/ + * @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 -*/ + * @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 (30*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) -*/ + * @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) + */ //#define MY_TRANSPORT_SANITY_CHECK /** -* @def MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS -* @brief Interval (in ms) for transport sanity checks -*/ + * @def MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS + * @brief Interval (in ms) for transport sanity checks + */ #ifndef MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS #define MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS (15*60*1000ul) #endif /** -* @def MY_TRANSPORT_DISCOVERY_INTERVAL_MS -* @brief This is a gateway-only feature: Interval (in ms) to issue network discovery checks -*/ + * @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 (20*60*1000ul) #endif @@ -159,9 +159,9 @@ #define MY_REGISTRATION_FEATURE /** -* @def MY_REGISTRATION_RETRIES -* @brief Number of registration retries if no reply received from GW/controller -*/ + * @def MY_REGISTRATION_RETRIES + * @brief Number of registration retries if no reply received from GW/controller + */ #ifndef MY_REGISTRATION_RETRIES #define MY_REGISTRATION_RETRIES (3u) @@ -174,32 +174,32 @@ #define MY_REGISTRATION_DEFAULT true /** -* @def MY_REGISTRATION_CONTROLLER -* @brief If enabled, node registration request has to be handled by controller -*/ + * @def MY_REGISTRATION_CONTROLLER + * @brief If enabled, node registration request has to be handled by controller + */ // #define MY_REGISTRATION_CONTROLLER /** -* @def MY_CORE_COMPATIBILITY_CHECK -* @brief If enabled, library compatibility is checked during node registration. Incompatible libraries are unable to send sensor data. -*/ + * @def MY_CORE_COMPATIBILITY_CHECK + * @brief If enabled, library compatibility is checked during node registration. Incompatible libraries are unable to send sensor data. + */ #define MY_CORE_COMPATIBILITY_CHECK /** -* @def MY_TRANSPORT_WAIT_READY_MS -* @brief Timeout in MS until transport is ready during startup, set to 0 for no timeout -*/ + * @def MY_TRANSPORT_WAIT_READY_MS + * @brief Timeout in MS until transport is ready during startup, set to 0 for no timeout + */ #ifndef MY_TRANSPORT_WAIT_READY_MS #define MY_TRANSPORT_WAIT_READY_MS (0ul) #endif /** -* @def MY_PASSIVE_NODE -* @brief If enabled, the node operates fully autonomously, i.e. messages are sent without ACKing -* note: All transport-related checks and safety-mechanisms are disabled, also @ref MY_NODE_ID, -* @ref MY_PARENT_NODE_ID and @ref MY_PARENT_NODE_IS_STATIC need to be set. -* Singing, registration, and OTA FW update are disabled. -*/ + * @def MY_PASSIVE_NODE + * @brief If enabled, the node operates fully autonomously, i.e. messages are sent without ACKing. + * note: All transport-related checks and safety-mechanisms are disabled. + * Requirement: @ref MY_NODE_ID needs to be set, @ref MY_PARENT_NODE_ID and @ref MY_PARENT_NODE_IS_STATIC are optional. + * Singing, registration, and OTA FW update are disabled. + */ //#define MY_PASSIVE_NODE @@ -226,15 +226,15 @@ //#define MY_PARENT_NODE_IS_STATIC /** -* @def MY_REPEATER_FEATURE -* @brief Enables repeater functionality (relays messages from other nodes) -*/ + * @def MY_REPEATER_FEATURE + * @brief Enables repeater functionality (relays messages from other nodes) + */ //#define MY_REPEATER_FEATURE /** -* @def MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS -* @brief Timeout (in ms) to re-establish link if node is send to sleep and transport is not ready. -*/ + * @def MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS + * @brief Timeout (in ms) to re-establish link if node is send to sleep and transport is not ready. + */ #ifndef MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS #define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS (10*1000ul) #endif @@ -270,7 +270,7 @@ /** * @def MY_OTA_FLASH_JDECID - * @brief Flash jdecid. + * @brief Flash JDECID. Use (0x00) if unknown. */ #ifndef MY_OTA_FLASH_JDECID #define MY_OTA_FLASH_JDECID (0x1F65) @@ -320,26 +320,43 @@ //#define MY_DEFAULT_TX_LED_PIN x //#define MY_DEFAULT_RX_LED_PIN x -// The following setting allows you to inverse the LED blinking -// When MY_WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches -// off when blinking - +/** + * @def MY_WITH_LEDS_BLINKING_INVERSE + * @brief The following setting allows you to inverse the LED blinking. + * When MY_WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches off when blinking. + */ //#define MY_WITH_LEDS_BLINKING_INVERSE /** -* @def MY_INDICATION_HANDLER -* @brief Enable to use own indication handler -*/ + * @def MY_INDICATION_HANDLER + * @brief Enable to use own indication handler. + */ //#define MY_INDICATION_HANDLER +/** +* @def MY_DEFAULT_LED_BLINK_PERIOD +* @brief Default LEDs blinking period in milliseconds. +*/ +#ifndef MY_DEFAULT_LED_BLINK_PERIOD +#define MY_DEFAULT_LED_BLINK_PERIOD 300 +#endif + + /********************************************** * Gateway inclusion button/mode configuration **********************************************/ -// Enabled inclusion mode feature + +/** +* @def MY_INCLUSION_MODE_FEATURE +* @brief Enables inclusion mode feature. +*/ //#define MY_INCLUSION_MODE_FEATURE -// Enables inclusion-mode button feature on the gateway device +/** +* @def MY_INCLUSION_BUTTON_FEATURE +* @brief Enables inclusion-mode button feature on the gateway device +*/ //#define MY_INCLUSION_BUTTON_FEATURE // Disable inclusion mode button if inclusion mode feature is not enabled @@ -373,7 +390,7 @@ * @brief The logical level indicating a pressed inclusion mode button. */ #if defined(MY_INCLUSION_BUTTON_EXTERNAL_PULLUP) -#define MY_INCLUSION_BUTTON_PRESSED HIGH +#define MY_INCLUSION_BUTTON_PRESSED HIGH #else #define MY_INCLUSION_BUTTON_PRESSED LOW #endif @@ -382,9 +399,10 @@ * Message Signing Settings ***********************************/ /** -* @def MY_DEBUG_VERBOSE_SIGNING -* @brief Flag for verbose debug prints related to signing. Requires DEBUG to be enabled. This will add even more to the size of the final sketch! -*/ + * @def MY_DEBUG_VERBOSE_SIGNING + * @brief Flag for verbose debug prints related to signing. Requires DEBUG to be enabled. + * This will add even more to the size of the final sketch! + */ //#define MY_DEBUG_VERBOSE_SIGNING /** @@ -414,7 +432,8 @@ /** * @def MY_SIGNING_GW_REQUEST_SIGNATURES_FROM_ALL - * @brief Enable this to have gateway require all nodes in the network to sign messages sent to it. @ref MY_SIGNING_REQUEST_SIGNATURES must also be set. + * @brief Enable this to have gateway require all nodes in the network to sign messages sent to it. + * @ref MY_SIGNING_REQUEST_SIGNATURES must also be set. * * Use this for maximum security, but be aware that every single node will have to be personalized before they can be used. * Note that if this is enabled, and whitelisting is also enabled, whitelisting will also be in effect for all nodes. @@ -540,17 +559,17 @@ #endif /** -* @def MY_RF24_POWER_PIN -* @brief NRF24 power pin, uncomment if used -*/ + * @def MY_RF24_POWER_PIN + * @brief NRF24 power pin, uncomment if used + */ //#define MY_RF24_POWER_PIN (3) /** -* @def MY_RX_MESSAGE_BUFFER_FEATURE -* @brief This enabled the receiving buffer feature. -* -* This feature is currently not supported for RFM69 and RS485, for RF24 MY_RF24_IRQ_PIN has to be defined. -*/ + * @def MY_RX_MESSAGE_BUFFER_FEATURE + * @brief This enabled the receiving buffer feature. + * + * This feature is currently not supported for RFM69 and RS485, for RF24 MY_RF24_IRQ_PIN has to be defined. + */ //#define MY_RX_MESSAGE_BUFFER_FEATURE /** @@ -654,21 +673,22 @@ ***********************************/ /** -* @def MY_DEBUG_VERBOSE_RFM69 -* @brief Enable MY_DEBUG_VERBOSE_RFM69 flag for verbose debug prints related to the RFM69 driver. -*/ + * @def MY_DEBUG_VERBOSE_RFM69 + * @brief Enable MY_DEBUG_VERBOSE_RFM69 flag for verbose debug prints related to the RFM69 driver. + */ //#define MY_DEBUG_VERBOSE_RFM69 /** -* @def MY_DEBUG_VERBOSE_RFM69_REGISTERS -* @brief Enable MY_DEBUG_VERBOSE_RFM69_REGISTERS -*/ + * @def MY_DEBUG_VERBOSE_RFM69_REGISTERS + * @brief Print content of RFM69 radio registers. + */ //#define MY_DEBUG_VERBOSE_RFM69_REGISTERS /** -* @def MY_RFM69_NEW_DRIVER -* @brief Enable MY_RFM69_NEW_DRIVER to include the refactored RFM69 driver -*/ + * @def MY_RFM69_NEW_DRIVER + * @brief Enable MY_RFM69_NEW_DRIVER to enable the refactored RFM69 driver. + * IMPORTANT: This driver is not compatible with the old (=default) RFM69 driver. + */ //#define MY_RFM69_NEW_DRIVER /** @@ -676,6 +696,7 @@ * @brief RFM69 frequency to use: RFM69_433MHZ, RFM69_868MHZ, RFM69_915MHZ, or custom frequency in Hz (new RFM69 driver only). * * This must match the hardware version of the RFM69 radio. + * Additional information: https://en.wikipedia.org/wiki/Short_Range_Devices */ #ifndef MY_RFM69_FREQUENCY #define MY_RFM69_FREQUENCY RFM69_868MHZ @@ -699,7 +720,7 @@ /** * @def MY_RFM69_TX_POWER_DBM - * @brief Set TX power level (0..31), default 5 + * @brief Set TX power level, default 5dBm (overriden if ATC mode enabled). */ #ifndef MY_RFM69_TX_POWER_DBM #define MY_RFM69_TX_POWER_DBM (5) @@ -707,7 +728,7 @@ /** * @def MY_RFM69_ATC_TARGET_RSSI_DBM - * @brief MY_RFM69_ATC_TARGET_RSSI_DBM + * @brief Target RSSI level (in dBm) for RFM69 ATC mode. */ #ifndef MY_RFM69_ATC_TARGET_RSSI_DBM #define MY_RFM69_ATC_TARGET_RSSI_DBM (-80) @@ -715,16 +736,17 @@ /** * @def MY_RFM69_ATC_MODE_DISABLED - * @brief MY_RFM69_ATC_MODE_DISABLED + * @brief Switch to disable ATC mode of RFM69 driver. */ //#define MY_RFM69_ATC_MODE_DISABLED /** - * @def RFM69_MAX_POWER_LEVEL_DBM + * @def MY_RFM69_MAX_POWER_LEVEL_DBM * @brief Set max TX power in dBm if local legislation requires * 1mW = 0dBm, 10mW = 10dBm, 25mW = 14dBm, 100mW = 20dBm + * see here: https://en.wikipedia.org/wiki/Short_Range_Devices */ -//#define RFM69_MAX_POWER_LEVEL_DBM (10u) +//#define MY_RFM69_MAX_POWER_LEVEL_DBM (10u) /** * @def MY_RFM69_NETWORKID @@ -736,25 +758,24 @@ /** * @def MY_RFM69_RST_PIN - * @brief RFM69 Reset pin, uncomment if used + * @brief RFM69 reset pin, uncomment if used. */ //#define MY_RFM69_RST_PIN (9) -// legacy, older board files #ifdef MY_RF69_RESET +// legacy, older board files #define MY_RFM69_RST_PIN MY_RF69_RESET #endif /** -* @def MY_RFM69_POWER_PIN -* @brief RFM69 power pin, uncomment if used -*/ + * @def MY_RFM69_POWER_PIN + * @brief RFM69 power pin + */ //#define MY_RFM69_POWER_PIN (3) - /** * @def MY_RFM69_IRQ_PIN - * @brief RFM69 IRQ pin. + * @brief RFM69 IRQ pin */ #ifndef MY_RFM69_IRQ_PIN #ifdef MY_RF69_IRQ_PIN @@ -808,7 +829,7 @@ //#define MY_RFM69_ENABLE_ENCRYPTION /** - * Uncomment if you need listenmode. else comment it and save memory + * Uncomment if you need listenmode, else comment it and save memory */ //#define MY_RFM69_ENABLE_LISTENMODE @@ -842,9 +863,9 @@ ***********************************/ /** -* @def MY_DEBUG_VERBOSE_RFM95 -* @brief Enable MY_DEBUG_VERBOSE_RFM95 flag for verbose debug prints related to the RFM95 driver. -*/ + * @def MY_DEBUG_VERBOSE_RFM95 + * @brief Enable MY_DEBUG_VERBOSE_RFM95 flag for verbose debug prints related to the RFM95 driver. + */ //#define MY_DEBUG_VERBOSE_RFM95 /** @@ -852,111 +873,126 @@ * @brief RFM95 frequency to use: RFM95_169MHZ, RFM95_315MHZ, RFM95_434MHZ, RFM95_868MHZ, RFM95_915MHZ, or custom frequency in Hz. * * This must match the hardware version of the RFM95 radio. + * Additional information: https://en.wikipedia.org/wiki/Short_Range_Devices + */ #ifndef MY_RFM95_FREQUENCY #define MY_RFM95_FREQUENCY RFM95_868MHZ #endif /** -* @def MY_RFM95_MODEM_CONFIGRUATION -* @brief RFM95 modem configuration, see table. Default RFM95 modem configuration: RFM95_BW125CR45SF128 -* -* BW = Bandwidth in kHz -* CR = Error correction code -* SF = Spreading factor, chips / symbol -* -* | CONFIG | BW | CR | SF | Comment -* |-------------------------|-------|-----|------|----------------------------- -* | RFM95_BW125CR45SF128 | 125 | 4/5 | 128 | Default, medium range -* | RFM95_BW500CR45SF128 | 500 | 4/5 | 128 | Fast, short range -* | RFM95_BW31_25CR48SF512 | 31.25 | 4/8 | 512 | Slow, long range -* | RFM95_BW125CR48SF4096 | 125 | 4/8 | 4096 | Slow, long range -* -*/ + * @def MY_RFM95_MODEM_CONFIGRUATION + * @brief RFM95 modem configuration, see table. Default RFM95 modem configuration: @ref RFM95_BW125CR45SF128 + * + * BW = Bandwidth in kHz + * CR = Error correction code + * SF = Spreading factor, chips / symbol + * + * | CONFIG | BW | CR | SF | Comment + * |------------------------|-------|-----|------|----------------------------- + * | RFM95_BW125CR45SF128 | 125 | 4/5 | 128 | Default, medium range + * | RFM95_BW500CR45SF128 | 500 | 4/5 | 128 | Fast, short range + * | RFM95_BW31_25CR48SF512 | 31.25 | 4/8 | 512 | Slow, long range + * | RFM95_BW125CR48SF4096 | 125 | 4/8 | 4096 | Slow, long range + * + */ #ifndef MY_RFM95_MODEM_CONFIGRUATION #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128 #endif /** * @def MY_RFM95_RST_PIN - * @brief RFM95 reset pin, uncomment if used + * @brief RFM95 reset pin, uncomment if used. */ //#define MY_RFM95_RST_PIN (9) /** -* @def MY_RFM95_POWER_PIN -* @brief RFM95 power pin, uncomment if used -*/ + * @def MY_RFM95_POWER_PIN + * @brief RFM95 power pin, uncomment if used + */ //#define MY_RFM95_POWER_PIN (3) /** * @def MY_RFM95_IRQ_PIN - * @brief RFM95 IRQ pin + * @brief RFM95 IRQ pin. */ #ifndef MY_RFM95_IRQ_PIN #define MY_RFM95_IRQ_PIN DEFAULT_RFM95_IRQ_PIN #endif /** -* @def MY_RFM95_IRQ_NUM -* @brief RFM95 IRQ number -*/ + * @def MY_RFM95_IRQ_NUM + * @brief RFM95 IRQ number. + */ #ifndef MY_RFM95_IRQ_NUM #define MY_RFM95_IRQ_NUM DEFAULT_RFM95_IRQ_NUM #endif /** * @def MY_RFM95_CS_PIN - * @brief RFM95 SPI chip select pin + * @brief RFM95 SPI chip select pin. */ #ifndef MY_RFM95_CS_PIN #define MY_RFM95_CS_PIN DEFAULT_RFM95_CS_PIN #endif /** -* @def MY_RFM95_SPI_SPEED -* @brief Set to overrule default RFM95 SPI speed, default 4Mhz. -*/ + * @def MY_RFM95_SPI_SPEED + * @brief Set to overrule default RFM95 SPI speed, default 4Mhz. + */ #ifndef MY_RFM95_SPI_SPEED #define MY_RFM95_SPI_SPEED (4*1000000ul) #endif /** * @def MY_RFM95_TX_POWER_DBM - * @brief RFM95 TX power level. + * @brief Set TX power level, default 13dBm (overriden if ATC mode enabled) + * see here: https://en.wikipedia.org/wiki/Short_Range_Devices */ #ifndef MY_RFM95_TX_POWER_DBM #define MY_RFM95_TX_POWER_DBM (13u) // 20mW #endif /** -* @def MY_RFM95_ATC_MODE_DISABLED -* @brief Enable to disable ATC mode -*/ + * @def MY_RFM95_ATC_MODE_DISABLED + * @brief Switch to disable RFM95 ATC mode + */ //#define MY_RFM95_ATC_MODE_DISABLED /** -* @def MY_RFM95_ATC_TARGET_RSSI -* @brief Traget RSSI level for ATC mode -*/ + * @def MY_RFM95_ATC_TARGET_RSSI + * @brief Target RSSI level (in dBm) for RFM95 ATC mode + */ #ifndef MY_RFM95_ATC_TARGET_RSSI #define MY_RFM95_ATC_TARGET_RSSI (-60) #endif /** -* @def RFM95_MAX_POWER_LEVEL_DBM -* @brief Set max TX power in dBm if local legislation requires -* 1mW = 0dBm, 10mW = 10dBm, 25mW = 14dBm, 100mW = 20dBm -*/ -//#define RFM95_MAX_POWER_LEVEL_DBM (10u) + * @def MY_RFM95_MAX_POWER_LEVEL_DBM + * @brief Set max TX power in dBm if local legislation requires + * 1mW = 0dBm, 10mW = 10dBm, 25mW = 14dBm, 100mW = 20dBm + * see here: https://en.wikipedia.org/wiki/Short_Range_Devices + */ +//#define MY_RFM95_MAX_POWER_LEVEL_DBM (10u) /** -* @def MY_RFM95_TCXO -* @brief Enable to force your radio to use an external frequency source (e.g. TCXO, if present). -* This allows for better stability using SF 9 to 12. -*/ + * @def MY_RFM95_TCXO + * @brief Enable to force your radio to use an external frequency source (e.g. TCXO, if present). + * This allows for better stability using SF 9 to 12. + */ //#define MY_RFM95_TCXO +/************************************** +* Signal report +***************************************/ + +/** + * @def MY_SIGNAL_REPORT_ENABLED + * @brief Enables signal report functionality, see @ref transportSignalReport(). + * NOTE: This feature adds ~1kB code to the sketch. + */ +#define MY_SIGNAL_REPORT_ENABLED + /************************************** * Ethernet Gateway Transport Defaults @@ -993,11 +1029,11 @@ //#define MY_USE_UDP /** - * @def MY_IP_RENEWAL_INTERVAL + * @def MY_IP_RENEWAL_INTERVAL_MS * @brief DHCP, default renewal setting in milliseconds. */ -#ifndef MY_IP_RENEWAL_INTERVAL -#define MY_IP_RENEWAL_INTERVAL (60*1000ul) +#ifndef MY_IP_RENEWAL_INTERVAL_MS +#define MY_IP_RENEWAL_INTERVAL_MS (60*1000ul) #endif /** @@ -1146,6 +1182,9 @@ // linux #define MY_LINUX_SERIAL_GROUPNAME #define MY_LINUX_IS_SERIAL_PTY +// inclusion mode +#define MY_INCLUSION_MODE_FEATURE +#define MY_INCLUSION_BUTTON_FEATURE // transport #define MY_PARENT_NODE_IS_STATIC #define MY_REGISTRATION_CONTROLLER @@ -1156,6 +1195,7 @@ #define MY_PASSIVE_NODE #define MY_MQTT_CLIENT_PUBLISH_RETAIN // general +#define MY_WITH_LEDS_BLINKING_INVERSE #define MY_INDICATION_HANDLER #define MY_DISABLE_REMOTE_RESET // signing @@ -1179,7 +1219,7 @@ #define MY_RFM69_POWER_PIN #define MY_RFM69_ENABLE_ENCRYPTION #define MY_RFM69_ATC_MODE_DISABLED -#define RFM69_MAX_POWER_LEVEL_DBM +#define MY_RFM69_MAX_POWER_LEVEL_DBM #define MY_RFM69_RST_PIN #define MY_DEBUG_VERBOSE_RFM69 #define MY_DEBUG_VERBOSE_RFM69_REGISTERS @@ -1190,5 +1230,6 @@ #define MY_RFM95_MODEM_CONFIGRUATION #define MY_RFM95_POWER_PIN #define MY_RFM95_TCXO +#define MY_RFM95_MAX_POWER_LEVEL_DBM #endif diff --git a/MySensors.h b/MySensors.h index 0c37ccf..edd81fe 100644 --- a/MySensors.h +++ b/MySensors.h @@ -25,7 +25,11 @@ #ifndef MySensors_h #define MySensors_h +#ifdef __cplusplus #include +#endif + +#include "MyConfig.h" #include "core/MySensorsCore.h" // Detect node type @@ -57,13 +61,13 @@ // DEBUG #if defined(MY_DEBUG) // standard debug output -#define MY_DEBUG_VERBOSE_CORE -#define MY_DEBUG_VERBOSE_TRANSPORT -#define MY_DEBUG_VERBOSE_OTA_UPDATE +#define MY_DEBUG_VERBOSE_CORE //!< MY_DEBUG_VERBOSE_CORE +#define MY_DEBUG_VERBOSE_TRANSPORT //!< MY_DEBUG_VERBOSE_TRANSPORT +#define MY_DEBUG_VERBOSE_OTA_UPDATE //!< 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_ENABLED //!< DEBUG_OUTPUT_ENABLED #define DEBUG_OUTPUT(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug #else #define DEBUG_OUTPUT(x,...) //!< debug NULL @@ -112,17 +116,6 @@ 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. - */ -#ifndef MY_DEFAULT_LED_BLINK_PERIOD -#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 @@ -140,7 +133,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs // SIGNING #if defined(MY_SIGNING_ATSHA204) || defined(MY_SIGNING_SOFT) -#define MY_SIGNING_FEATURE +#define MY_SIGNING_FEATURE //!< MY_SIGNING_FEATURE #endif #include "core/MySigning.cpp" #include "drivers/ATSHA204/sha256.cpp" diff --git a/core/MyCapabilities.h b/core/MyCapabilities.h index 3ae003a..f84b92b 100644 --- a/core/MyCapabilities.h +++ b/core/MyCapabilities.h @@ -1,12 +1,12 @@ -/** +/* * 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 * network topology allowing messages to be routed to nodes. * - * Created by Tomas Hozza - * Copyright (C) 2015 Tomas Hozza + * Created by Henrik Ekblad + * Copyright (C) 2013-2017 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index ba85c27..141800b 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -428,7 +428,7 @@ void gatewayTransportRenewIP(void) 3 - rebinf failed 4 - rebind success */ - static unsigned long next_time = hwMillis() + MY_IP_RENEWAL_INTERVAL; + static unsigned long next_time = hwMillis() + MY_IP_RENEWAL_INTERVAL_MS; unsigned long now = hwMillis(); // http://playground.arduino.cc/Code/TimingRollover @@ -441,6 +441,6 @@ void gatewayTransportRenewIP(void) return; } _w5100_spi_en(false); - next_time = now + MY_IP_RENEWAL_INTERVAL; + next_time = now + MY_IP_RENEWAL_INTERVAL_MS; } #endif diff --git a/core/MyHw.h b/core/MyHw.h index 971c09c..a747b61 100644 --- a/core/MyHw.h +++ b/core/MyHw.h @@ -26,14 +26,6 @@ #ifndef MyHw_h #define MyHw_h -#include "MyConfig.h" -#include "MyMessage.h" - - -#ifdef __cplusplus -#include -#endif - // Implement these as functions or macros /* #define hwInit() MY_SERIALDEVICE.begin(BAUD_RATE) diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp index 63667f2..19482e5 100644 --- a/core/MyTransport.cpp +++ b/core/MyTransport.cpp @@ -559,12 +559,13 @@ bool transportRouteMessage(MyMessage &message) _transportSM.failedUplinkTransmissions++; } else { _transportSM.failedUplinkTransmissions = 0u; +#if defined(MY_SIGNAL_REPORT_ENABLED) // update uplink quality monitor const int16_t signalStrengthRSSI = transportGetSignalReport(SR_TX_RSSI); _transportSM.uplinkQualityRSSI = static_cast((1 - UPLINK_QUALITY_WEIGHT) * _transportSM.uplinkQualityRSSI + (UPLINK_QUALITY_WEIGHT * transportRSSItoInternal(signalStrengthRSSI))); - +#endif } } #else @@ -791,21 +792,27 @@ void transportProcessMessage(void) return; // no further processing required } if (type == I_SIGNAL_REPORT_REVERSE) { - if (_msg.data[1] == '!') { - const int16_t value = transportSignalReport(_msg.data[0]); - (void)_msg.set(value); - _msg.type = I_SIGNAL_REPORT_RESPONSE; - } + return; // no further processing required } if (type == I_SIGNAL_REPORT_REQUEST) { + const char command = _msg.data[0]; + int16_t value = INVALID_RSSI; +#if defined(MY_SIGNAL_REPORT_ENABLED) if (_msg.data[1] != '!') { - const int16_t value = transportSignalReport(_msg.data[0]); - (void)transportRouteMessage(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, - I_SIGNAL_REPORT_RESPONSE).set(value)); + value = transportSignalReport(command); } else { - (void)transportRouteMessage(build(_msgTmp, _msg.sender, NODE_SENSOR_ID, C_INTERNAL, - I_SIGNAL_REPORT_REVERSE).set(_msg.data, 2)); + // send request + if (transportRouteMessage(build(_msgTmp, _msg.last, NODE_SENSOR_ID, C_INTERNAL, + I_SIGNAL_REPORT_REVERSE).set((uint8_t)255))) { + // S>s, R>r, ascii delta = 32 + value = transportSignalReport(command + 32); // reverse + }; } +#else + (void)command; +#endif + (void)transportRouteMessage(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, + I_SIGNAL_REPORT_RESPONSE).set(value)); return; } } else if (command == C_STREAM) { @@ -1117,13 +1124,21 @@ int16_t transportSignalReport(const char command) signalReport_t reportCommand; switch (command) { case 'S': - // SNR (if available) of incoming message (this) + // SNR (if available) of incoming message reportCommand = SR_RX_SNR; break; + case 's': + // SNR (if available) of incoming ACK message + reportCommand = SR_TX_SNR; + break; case 'R': - // RSSI (if available) of incoming message (this) + // RSSI (if available) of incoming message reportCommand = SR_RX_RSSI; break; + case 'r': + // RSSI (if available) of incoming ACK message + reportCommand = SR_TX_RSSI; + break; case 'P': // TX powerlevel in % reportCommand = SR_TX_POWER_PERCENT; diff --git a/core/MyTransport.h b/core/MyTransport.h index 085aa2a..0c39e05 100644 --- a/core/MyTransport.h +++ b/core/MyTransport.h @@ -159,7 +159,6 @@ #ifndef MyTransport_h #define MyTransport_h -#include "MySensorsCore.h" #include "hal/transport/MyTransportHAL.h" #ifndef MY_TRANSPORT_MAX_TX_FAILURES @@ -520,13 +519,15 @@ void transportDisable(void); void transportReInitialise(void); /** * @brief Get transport signal report -* @param command -* S=SNR (if available) of incoming message (this) -* R=RSSI (if available) of incoming message (this) -* P=TX powerlevel in % -* T=TX powerlevel in dBm -* U=Uplink quality -* @return report +* @param command: +* R = RSSI (if available) of incoming @ref I_SIGNAL_REPORT_REQUEST message (from last hop) +* R! = RSSI (if available) of ACK to @ref I_SIGNAL_REPORT_REVERSE message received from last hop +* S = SNR (if available) of incoming @ref I_SIGNAL_REPORT_REQUEST message (from last hop) +* S! = SNR (if available) of ACK to @ref I_SIGNAL_REPORT_REVERSE message received from last hop +* P = TX powerlevel in % +* T = TX powerlevel in dBm +* U = Uplink quality (via ACK from parent node), avg. RSSI +* @return Signal report (if report is not available, INVALID_RSSI, INVALID_SNR, INVALID_PERCENT, or INVALID_LEVEL is sent instead) */ int16_t transportSignalReport(const char command); diff --git a/core/MyTransportRFM69.cpp b/core/MyTransportRFM69.cpp deleted file mode 100644 index 2ee9296..0000000 --- a/core/MyTransportRFM69.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 - * network topology allowing messages to be routed to nodes. - * - * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors - * - * Documentation: http://www.mysensors.org - * Support Forum: http://forum.mysensors.org - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - */ - -#include "MyConfig.h" -#include "MyTransport.h" -#include -#include "drivers/RFM69/RFM69.h" - -RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_RFM69HW, MY_RF69_IRQ_NUM); -uint8_t _address; - - -bool transportInit(void) -{ -#ifdef MY_RF69_RESET - pinMode(MY_RF69_RESET, OUTPUT); - digitalWrite(MY_RF69_RESET, LOW); -#endif -#ifdef MY_RF69_DIO5 - pinMode(MY_RF69_DIO5, INPUT); -#endif - // Start up the radio library (_address will be set later by the MySensors library) - if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) { -#ifdef MY_RFM69_ENABLE_ENCRYPTION - uint8_t _psk[16]; - hwReadConfigBlock((void*)_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16); - _radio.encrypt((const char*)_psk); - memset(_psk, 0, 16); // Make sure it is purged from memory when set -#endif - return true; - } - return false; -} - -void transportSetAddress(const uint8_t address) -{ - _address = address; - _radio.setAddress(address); -} - -uint8_t transportGetAddress(void) -{ - return _address; -} - -bool transportSend(const uint8_t to, const void* data, const uint8_t len) -{ - return _radio.sendWithRetry(to,data,len); -} - -bool transportAvailable(void) -{ - return _radio.receiveDone(); -} - -bool transportSanityCheck(void) -{ - // not implemented yet - return true; -} - -uint8_t transportReceive(void* data) -{ - memcpy(data,(const void *)_radio.DATA, _radio.DATALEN); - // save payload length - const uint8_t dataLen = _radio.DATALEN; - // Send ack back if this message wasn't a broadcast - if(_radio.ACKRequested()) { - _radio.sendACK(); - } - return dataLen; -} - -void transportPowerDown(void) -{ - _radio.sleep(); -} diff --git a/core/MyTransportRFM95.cpp b/core/MyTransportRFM95.cpp deleted file mode 100644 index 8437d71..0000000 --- a/core/MyTransportRFM95.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 - * network topology allowing messages to be routed to nodes. - * - * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors - * - * Documentation: http://www.mysensors.org - * Support Forum: http://forum.mysensors.org - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - * - */ - -#include "MyConfig.h" -#include "MyTransport.h" -#include "drivers/RFM95/RFM95.h" - -bool transportInit(void) -{ - const bool result = RFM95_initialise(MY_RFM95_FREQUENCY); -#if !defined(MY_GATEWAY_FEATURE) && !defined(MY_RFM95_ATC_MODE_DISABLED) - // only enable ATC mode nodes - RFM95_ATCmode(true, MY_RFM95_ATC_TARGET_RSSI); -#endif - return result; -} - -void transportSetAddress(const uint8_t address) -{ - RFM95_setAddress(address); -} - -uint8_t transportGetAddress(void) -{ - return RFM95_getAddress(); -} - -bool transportSend(const uint8_t to, const void* data, const uint8_t len) -{ - return RFM95_sendWithRetry(to, data, len); -} - -bool transportAvailable(void) -{ - return RFM95_available(); -} - -bool transportSanityCheck(void) -{ - return RFM95_sanityCheck(); -} - -uint8_t transportReceive(void* data) -{ - return RFM95_recv((uint8_t*)data); -} - -void transportPowerDown(void) -{ - (void)RFM95_sleep(); -} - -// experimental -// ********************************************** -int16_t transportGetReceivingSignalStrength(void) -{ - return RFM95_getReceivingRSSI(); -} -int16_t transportGetSendingSignalStrength(void) -{ - return RFM95_getSendingRSSI(); -} -int8_t transportGetReceivingSNR(void) -{ - return RFM95_getReceivingSNR(); -} -int8_t transportGetSendingSNR(void) -{ - return RFM95_getSendingSNR(); -} -uint8_t transportGetTxPower(void) -{ - return RFM95_getTxPowerPercent(); -} -// ********************************************** diff --git a/drivers/RFM69/new/RFM69_new.cpp b/drivers/RFM69/new/RFM69_new.cpp index 5497ca7..22cc838 100644 --- a/drivers/RFM69/new/RFM69_new.cpp +++ b/drivers/RFM69/new/RFM69_new.cpp @@ -1093,7 +1093,7 @@ LOCAL void RFM69_listenModeSendBurst(const uint8_t recipient, uint8_t* data, con RFM69_DEBUG(PSTR("RFM69:LSM:Send burst for %d ms\n"), cycleDurationMs); (void)RFM69_setRadioMode(RFM69_RADIO_MODE_TX); - uint32_t startTime = millis(); + uint32_t startTime = hwMillis(); while (timeRemaining.l > 0) { // send burst @@ -1119,7 +1119,7 @@ LOCAL void RFM69_listenModeSendBurst(const uint8_t recipient, uint8_t* data, con while ((RFM69_readReg(RFM69_REG_IRQFLAGS2) & RFM69_IRQFLAGS2_FIFONOTEMPTY) != 0x00); // make sure packet is sent before putting more into the FIFO - timeRemaining.l = cycleDurationMs - (millis() - startTime); + timeRemaining.l = cycleDurationMs - (hwMillis() - startTime); } (void)RFM69_setRadioMode(RFM69_RADIO_MODE_TX); diff --git a/drivers/RFM69/new/RFM69_new.h b/drivers/RFM69/new/RFM69_new.h index e83f807..8ad14a2 100644 --- a/drivers/RFM69/new/RFM69_new.h +++ b/drivers/RFM69/new/RFM69_new.h @@ -35,7 +35,7 @@ /** * @file RFM69.h * -* @defgroup RFM69grp RFM69 +* @defgroup RFM69Newgrp RFM69New * @ingroup internals * @{ * @@ -144,13 +144,17 @@ extern HardwareSPI SPI; //!< SPI // RFM69H(C)W #define RFM69_VERSION_HW //!< HW version #define RFM69_MIN_POWER_LEVEL_DBM ((rfm69_powerlevel_t)-2) //!< min. power level, -18dBm -#if !defined(RFM69_MAX_POWER_LEVEL_DBM) +#if defined(MY_RFM69_MAX_POWER_LEVEL_DBM) +#define RFM69_MAX_POWER_LEVEL_DBM MY_RFM69_MAX_POWER_LEVEL_DBM //!< MY_RFM69_MAX_POWER_LEVEL_DBM +#else #define RFM69_MAX_POWER_LEVEL_DBM ((rfm69_powerlevel_t)20) //!< max. power level, +20dBm #endif #else // RFM69(C)W #define RFM69_MIN_POWER_LEVEL_DBM ((rfm69_powerlevel_t)-18) //!< min. power level, -18dBm -#if !defined(RFM69_MAX_POWER_LEVEL_DBM) +#if defined(MY_RFM69_MAX_POWER_LEVEL_DBM) +#define RFM69_MAX_POWER_LEVEL_DBM MY_RFM69_MAX_POWER_LEVEL_DBM //!< MY_RFM69_MAX_POWER_LEVEL_DBM +#else #define RFM69_MAX_POWER_LEVEL_DBM ((rfm69_powerlevel_t)13) //!< max. power level, +13dBm #endif #endif @@ -352,7 +356,7 @@ LOCAL uint8_t RFM69_getAddress(void); /** * @brief Tests whether a new message is available -* @return True if a new, complete, error-free uncollected message is available to be retreived by @ref RFM95_recv() +* @return True if a new, complete, error-free uncollected message is available to be retreived by @ref RFM69_recv() */ LOCAL bool RFM69_available(void); diff --git a/drivers/RFM69/old/RFM69_old.cpp b/drivers/RFM69/old/RFM69_old.cpp index d498f4d..52b5761 100644 --- a/drivers/RFM69/old/RFM69_old.cpp +++ b/drivers/RFM69/old/RFM69_old.cpp @@ -325,7 +325,6 @@ bool RFM69::sendWithRetry(uint8_t toAddress, const void* buffer, uint8_t bufferS uint32_t sentTime = hwMillis(); while (hwMillis() - sentTime < retryWaitTime) { if (ACKReceived(toAddress)) { - //Serial.print(" ~ms:"); Serial.print(millis() - sentTime); return true; } } diff --git a/drivers/RFM95/RFM95.cpp b/drivers/RFM95/RFM95.cpp index 09de2ec..bdef583 100644 --- a/drivers/RFM95/RFM95.cpp +++ b/drivers/RFM95/RFM95.cpp @@ -128,7 +128,7 @@ LOCAL uint8_t RFM95_RAW_writeByteRegister(const uint8_t address, uint8_t value) #define RFM95_burstReadReg(__reg, __buf, __len) RFM95_spiMultiByteTransfer( __reg & RFM95_READ_REGISTER, (uint8_t*)__buf, __len, true ) #define RFM95_burstWriteReg(__reg, __buf, __len) RFM95_spiMultiByteTransfer( __reg | RFM95_WRITE_REGISTER, (uint8_t*)__buf, __len, false ) -LOCAL bool RFM95_initialise(const float frequency) +LOCAL bool RFM95_initialise(const uint32_t frequencyHz) { RFM95_DEBUG(PSTR("RFM95:INIT\n")); // reset radio module if rst pin defined @@ -181,7 +181,7 @@ LOCAL bool RFM95_initialise(const float frequency) const rfm95_modemConfig_t configuration = { MY_RFM95_MODEM_CONFIGRUATION }; RFM95_setModemRegisters(&configuration); RFM95_setPreambleLength(RFM95_PREAMBLE_LENGTH); - RFM95_setFrequency(frequency); + RFM95_setFrequency(frequencyHz); (void)RFM95_setTxPowerLevel(MY_RFM95_TX_POWER_DBM); // IRQ hwPinMode(MY_RFM95_IRQ_PIN, INPUT); @@ -438,7 +438,7 @@ LOCAL void RFM95_powerUp(void) LOCAL void RFM95_powerDown(void) { #if defined(MY_RFM95_POWER_PIN) - hwDigitalWrite(RFM69_POWER_PIN, LOW); + hwDigitalWrite(MY_RFM95_POWER_PIN, LOW); #endif } diff --git a/drivers/RFM95/RFM95.h b/drivers/RFM95/RFM95.h index 6438fe3..951212e 100644 --- a/drivers/RFM95/RFM95.h +++ b/drivers/RFM95/RFM95.h @@ -60,14 +60,14 @@ * CR = Error correction code * SF = Spreading factor, chips / symbol * -* | CONFIG | REG_1D | REG_1E | REG_26 | BW | CR | SF | Comment | air-time (~15 bytes) +* | CONFIG | REG_1D | REG_1E | REG_26 | BW | CR | SF | Comment | air-time (15 bytes) * |------------------|--------|--------|--------|-------|-----|------|------------------------------------------------ * | BW125CR45SF128 | 0x72 | 0x74 | 0x04 | 125 | 4/5 | 128 | Default, medium range | 50ms * | BW500CR45SF128 | 0x92 | 0x74 | 0x04 | 500 | 4/5 | 128 | Fast, short range | 15ms * | BW31_25CR48SF512 | 0x48 | 0x94 | 0x04 | 31.25 | 4/8 | 512 | Slow, long range | 900ms * | BW125CR48SF4096 | 0x78 | 0xC4 | 0x0C | 125 | 4/8 | 4096 | Slow, long range | 1500ms * -* See here for air-time calculation: https://docs.google.com/spreadsheets/d/1voGAtQAjC1qBmaVuP1ApNKs1ekgUjavHuVQIXyYSvNc/edit#gid=0 +* See here for air-time calculation: https://docs.google.com/spreadsheets/d/1voGAtQAjC1qBmaVuP1ApNKs1ekgUjavHuVQIXyYSvNc * * @brief API declaration for RFM95 * @@ -189,7 +189,9 @@ extern HardwareSPI SPI; //!< SPI #define RFM95_internalToSNR(__value) ((int8_t)(__value / 4)) //!< Convert internal SNR to SNR #define RFM95_MIN_POWER_LEVEL_DBM ((rfm95_powerLevel_t)5u) //!< min. power level -#if !defined(RFM95_MAX_POWER_LEVEL_DBM) +#if defined(MY_RFM95_MAX_POWER_LEVEL_DBM) +#define RFM95_MAX_POWER_LEVEL_DBM MY_RFM95_MAX_POWER_LEVEL_DBM //!< MY_RFM95_MAX_POWER_LEVEL_DBM +#else #define RFM95_MAX_POWER_LEVEL_DBM ((rfm95_powerLevel_t)23u) //!< max. power level #endif /** @@ -298,10 +300,10 @@ typedef struct { /** * @brief Initialise the driver transport hardware and software -* @param frequency +* @param frequencyHz Transmitter frequency in Hz * @return True if initialisation succeeded */ -LOCAL bool RFM95_initialise(const float frequency); +LOCAL bool RFM95_initialise(const uint32_t frequencyHz); /** * @brief Set the driver/node address * @param addr diff --git a/examples/RFM69_RFM95_ATC_SignalReport/RFM69_RFM95_ATC_SignalReport.ino b/examples/RFM69_RFM95_ATC_SignalReport/RFM69_RFM95_ATC_SignalReport.ino new file mode 100644 index 0000000..852f303 --- /dev/null +++ b/examples/RFM69_RFM95_ATC_SignalReport/RFM69_RFM95_ATC_SignalReport.ino @@ -0,0 +1,99 @@ +/** + * 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 + * network topology allowing messages to be routed to nodes. + * + * Created by Henrik Ekblad + * Copyright (C) 2013-2017 Sensnology AB + * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + ******************************* + * + * REVISION HISTORY + * Version 1.0 - tekka + * + * DESCRIPTION + * ATC mode settings and signal report functions, on RFM69 and RFM95 nodes + * + */ + +// Enable debug prints +#define MY_DEBUG + +// Enable and select radio type attached + +// RFM69 +//#define MY_RADIO_RFM69 +//#define MY_RFM69_NEW_DRIVER // ATC on RFM69 works only with the new driver (not compatible with old=default driver) +//#define MY_RFM69_ATC_TARGET_RSSI_DBM (-70) // target RSSI -70dBm +//#define MY_RFM69_MAX_POWER_LEVEL_DBM (10) // max. TX power 10dBm = 10mW + +// RFM95 +#define MY_RADIO_RFM95 +#define MY_RFM95_ATC_TARGET_RSSI_DBM (-70) // target RSSI -70dBm +#define MY_RFM95_MAX_POWER_LEVEL_DBM (10) // max. TX power 10dBm = 10mW + +#include + +// ID of the sensor child +#define CHILD_ID_UPLINK_QUALITY (0) +#define CHILD_ID_TX_LEVEL (1) +#define CHILD_ID_TX_PERCENT (2) +#define CHILD_ID_TX_RSSI (3) +#define CHILD_ID_RX_RSSI (4) +#define CHILD_ID_TX_SNR (5) +#define CHILD_ID_RX_SNR (6) + + +// Initialize general message +MyMessage msgTxRSSI(CHILD_ID_TX_RSSI, V_CUSTOM); +MyMessage msgRxRSSI(CHILD_ID_RX_RSSI, V_CUSTOM); +MyMessage msgTxSNR(CHILD_ID_TX_SNR, V_CUSTOM); +MyMessage msgRxSNR(CHILD_ID_RX_SNR, V_CUSTOM); +MyMessage msgTxLevel(CHILD_ID_TX_LEVEL, V_CUSTOM); +MyMessage msgTxPercent(CHILD_ID_TX_PERCENT, V_CUSTOM); +MyMessage msgUplinkQuality(CHILD_ID_UPLINK_QUALITY, V_CUSTOM); + +void setup() +{ +} + + +void presentation() +{ + // Send the sketch version information to the gateway and controller + sendSketchInfo("ATC", "1.0"); + + // Register all sensors to gw (they will be created as child devices) + present(CHILD_ID_UPLINK_QUALITY, S_CUSTOM, "UPLINK QUALITY RSSI"); + present(CHILD_ID_TX_LEVEL, S_CUSTOM, "TX LEVEL DBM"); + present(CHILD_ID_TX_PERCENT, S_CUSTOM, "TX LEVEL PERCENT"); + present(CHILD_ID_TX_RSSI, S_CUSTOM, "TX RSSI"); + present(CHILD_ID_RX_RSSI, S_CUSTOM, "RX RSSI"); + present(CHILD_ID_TX_SNR, S_CUSTOM, "TX SNR"); + present(CHILD_ID_RX_SNR, S_CUSTOM, "RX SNR"); +} + +void loop() +{ + // send messages to GW + send(msgUplinkQuality.set(transportGetSignalReport(SR_UPLINK_QUALITY))); + send(msgTxLevel.set(transportGetSignalReport(SR_TX_POWER_LEVEL))); + send(msgTxPercent.set(transportGetSignalReport(SR_TX_POWER_PERCENT))); + // retrieve RSSI / SNR reports from incoming ACK + send(msgTxRSSI.set(transportGetSignalReport(SR_TX_RSSI))); + send(msgRxRSSI.set(transportGetSignalReport(SR_RX_RSSI))); + send(msgTxSNR.set(transportGetSignalReport(SR_TX_SNR))); + send(msgRxSNR.set(transportGetSignalReport(SR_RX_SNR))); + // wait a bit + wait(5000); +} diff --git a/hal/transport/MyTransportHAL.h b/hal/transport/MyTransportHAL.h index 3bddb4a..ce0c58d 100644 --- a/hal/transport/MyTransportHAL.h +++ b/hal/transport/MyTransportHAL.h @@ -23,6 +23,7 @@ #define INVALID_SNR ((int16_t)-256) //!< INVALID_SNR #define INVALID_RSSI ((int16_t)-256) //!< INVALID_RSSI #define INVALID_PERCENT ((int16_t)-100) //!< INVALID_PERCENT +#define INVALID_LEVEL ((int16_t)-256) //!< INVALID_LEVEL #if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RADIO_RFM69) @@ -92,11 +93,11 @@ bool transportSanityCheck(void); */ uint8_t transportReceive(void* data); /** -* @brief Power down transport HW (if corresponding MY_XXXX_POWER_PIN defined) +* @brief Power down transport HW (if corresponding MY_XYZ_POWER_PIN defined) */ void transportPowerDown(void); /** -* @brief Power up transport HW (if corresponding MY_XXXX_POWER_PIN defined) +* @brief Power up transport HW (if corresponding MY_XYZ_POWER_PIN defined) */ void transportPowerUp(void); /** @@ -107,22 +108,6 @@ void transportSleep(void); * @brief Set transport HW to standby */ void transportStandBy(void); - - -// experimental - -/** -* @brief transportSignalReport -* @param command -* @return -*/ -int16_t transportSignalReport(const char command); -/** -* @brief transportGetSignalReport -* @param signalReport -* @return -*/ -int16_t transportGetSignalReport(const signalReport_t signalReport = SR_RX_RSSI); /** * @brief transportGetSendingRSSI * @return RSSI diff --git a/hal/transport/MyTransportRF24.cpp b/hal/transport/MyTransportRF24.cpp index 73d5ba3..ddebadc 100644 --- a/hal/transport/MyTransportRF24.cpp +++ b/hal/transport/MyTransportRF24.cpp @@ -174,17 +174,17 @@ int16_t transportGetSendingRSSI(void) int16_t transportGetReceivingRSSI(void) { // not available, only bool RPD - return static_cast(INVALID_RSSI); + return INVALID_RSSI; } int16_t transportGetSendingSNR(void) { - return static_cast(INVALID_SNR); + return INVALID_SNR; } int16_t transportGetReceivingSNR(void) { - return static_cast(INVALID_SNR); + return INVALID_SNR; } int16_t transportGetTxPowerPercent(void) diff --git a/hal/transport/MyTransportRFM69.cpp b/hal/transport/MyTransportRFM69.cpp index bd6efd9..7002e0e 100644 --- a/hal/transport/MyTransportRFM69.cpp +++ b/hal/transport/MyTransportRFM69.cpp @@ -252,12 +252,12 @@ int16_t transportGetReceivingSNR(void) int16_t transportGetTxPowerPercent(void) { - return 0; + return INVALID_PERCENT; } int16_t transportGetTxPowerLevel(void) { - return 0; + return INVALID_LEVEL; } #endif \ No newline at end of file diff --git a/hal/transport/MyTransportRFM95.cpp b/hal/transport/MyTransportRFM95.cpp index ee5c91a..5d6278f 100644 --- a/hal/transport/MyTransportRFM95.cpp +++ b/hal/transport/MyTransportRFM95.cpp @@ -106,22 +106,22 @@ int16_t transportGetReceivingRSSI(void) int16_t transportGetSendingSNR(void) { - return static_cast(RFM95_getSendingSNR()); + return RFM95_getSendingSNR(); } int16_t transportGetReceivingSNR(void) { - return static_cast(RFM95_getReceivingSNR()); + return RFM95_getReceivingSNR(); } int16_t transportGetTxPowerPercent(void) { - return static_cast(RFM95_getTxPowerPercent()); + return RFM95_getTxPowerPercent(); } int16_t transportGetTxPowerLevel(void) { - return static_cast(RFM95_getTxPowerLevel()); + return RFM95_getTxPowerLevel(); } bool transportSetTxPowerPercent(const uint8_t powerPercent) diff --git a/hal/transport/MyTransportRS485.cpp b/hal/transport/MyTransportRS485.cpp index 7b692d8..96de411 100644 --- a/hal/transport/MyTransportRS485.cpp +++ b/hal/transport/MyTransportRS485.cpp @@ -381,25 +381,25 @@ void transportStandBy(void) int16_t transportGetSendingRSSI(void) { // not implemented - return static_cast(INVALID_RSSI); + return INVALID_RSSI; } int16_t transportGetReceivingRSSI(void) { // not implemented - return static_cast(INVALID_RSSI); + return INVALID_RSSI; } int16_t transportGetSendingSNR(void) { // not implemented - return static_cast(INVALID_SNR); + return INVALID_SNR; } int16_t transportGetReceivingSNR(void) { // not implemented - return static_cast(INVALID_SNR); + return INVALID_SNR; } int16_t transportGetTxPowerPercent(void) diff --git a/keywords.txt b/keywords.txt index 4712536..a3c0718 100644 --- a/keywords.txt +++ b/keywords.txt @@ -115,10 +115,13 @@ MY_RFM95_MODEM_CONFIGRUATION LITERAL1 MY_RFM95_FREQUENCY LITERAL1 MY_RFM95_TX_POWER LITERAL1 MY_RFM95_CS_PIN LITERAL1 +MY_RFM95_RST_PIN LITERAL1 MY_RFM95_SPI_SPEED LITERAL1 MY_RFM95_IRQ_PIN LITERAL1 MY_RFM95_ATC_TARGET_RSSI LITERAL1 MY_RFM95_ATC_MODE_DISABLED LITERAL1 +MY_RFM95_ATC_TARGET_RSSI_DBM LITERAL1 +MY_RFM95_MAX_POWER_LEVEL_DBM LITERAL1 # RFM69 MY_RADIO_RFM69 LITERAL1 @@ -130,6 +133,7 @@ MY_RFM69_NEW_DRIVER LITERAL1 MY_RFM69_TX_POWER_DBM LITERAL1 MY_RFM69_ATC_TARGET_RSSI_DBM LITERAL1 MY_RFM69_ATC_MODE_DISABLED LITERAL1 +MY_RFM69_MAX_POWER_LEVEL_DBM LITERAL1 MY_RFM69_NETWORKID LITERAL1 MY_RFM69_RST_PIN LITERAL1 MY_RFM69_IRQ_PIN LITERAL1