Merge pull request #359 from fallberg/doxygen

Cleaned up Doxygen warnings
This commit is contained in:
Patrick Fallberg
2016-01-20 01:06:50 +01:00
26 changed files with 542 additions and 293 deletions
+154 -24
View File
@@ -56,7 +56,10 @@
#undef MY_DEBUG
#endif
// Serial output baud rate (debug prints and serial gateway speed)
/**
* @def MY_BAUD_RATE
* @brief Serial output baud rate (debug prints and serial gateway speed).
*/
#ifndef MY_BAUD_RATE
#define MY_BAUD_RATE 115200
#endif
@@ -74,12 +77,18 @@
//#define MY_RADIO_RFM69
//#define MY_RS485
// Node id defaults to AUTO (tries to fetch id from controller)
/**
* @def MY_NODE_ID
* @brief Node id defaults to AUTO (tries to fetch id from controller).
*/
#ifndef MY_NODE_ID
#define MY_NODE_ID AUTO
#endif
// Node parent defaults to AUTO (tries to find a parent automatically)
/**
* @def MY_PARENT_NODE_ID
* @brief Node parent defaults to AUTO (tries to find a parent automatically).
*/
#ifndef MY_PARENT_NODE_ID
#define MY_PARENT_NODE_ID AUTO
#endif
@@ -87,9 +96,13 @@
// Enables repeater functionality (relays messages from other nodes)
// #define MY_REPEATER_FEATURE
// The wait period before going to sleep when using smartSleep-functions
// This period has to be long enough for controller to be able to send out
// potential buffered messages.
/**
* @def MY_SMART_SLEEP_WAIT_DURATION
* @brief The wait period before going to sleep when using smartSleep-functions.
*
* This period has to be long enough for controller to be able to send out
* potential buffered messages.
*/
#ifndef MY_SMART_SLEEP_WAIT_DURATION
#define MY_SMART_SLEEP_WAIT_DURATION 500
#endif
@@ -104,12 +117,18 @@
// requires the MYSBootloader and disabled MY_OTA_FIRMWARE_FEATURE
//#define MY_OTA_FIRMWARE_FEATURE
// Slave select pin for external flash
/**
* @def MY_OTA_FLASH_SS
* @brief Slave select pin for external flash.
*/
#ifndef MY_OTA_FLASH_SS
#define MY_OTA_FLASH_SS 8
#endif
// Flash jdecid
/**
* @def MY_OTA_FLASH_JDECID
* @brief Flash jdecid.
*/
#ifndef MY_OTA_FLASH_JDECID
#define MY_OTA_FLASH_JDECID 0x1F65
#endif
@@ -119,17 +138,26 @@
* Gateway config
***********************************/
// Max buffersize needed for messages coming from controller
/**
* @def MY_GATEWAY_MAX_RECEIVE_LENGTH
* @brief Max buffersize needed for messages coming from controller.
*/
#ifndef MY_GATEWAY_MAX_RECEIVE_LENGTH
#define MY_GATEWAY_MAX_RECEIVE_LENGTH 100
#endif
// Max buffer size when sending messages
/**
* @def MY_GATEWAY_MAX_SEND_LENGTH
* @brief Max buffer size when sending messages.
*/
#ifndef MY_GATEWAY_MAX_SEND_LENGTH
#define MY_GATEWAY_MAX_SEND_LENGTH 120
#endif
// Max number of parallel clients (sever mode)
/**
* @def MY_GATEWAY_MAX_CLIENTS
* @brief Max number of parallel clients (sever mode).
*/
#ifndef MY_GATEWAY_MAX_CLIENTS
#define MY_GATEWAY_MAX_CLIENTS 1
#endif
@@ -173,7 +201,10 @@
#undef MY_INCLUSION_BUTTON_FEATURE
#endif
// The default input pin used for the inclusion mode button
/**
* @def MY_INCLUSION_MODE_BUTTON_PIN
* @brief The default input pin used for the inclusion mode button.
*/
#ifndef MY_INCLUSION_MODE_BUTTON_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_INCLUSION_MODE_BUTTON_PIN 5
@@ -181,11 +212,20 @@
#define MY_INCLUSION_MODE_BUTTON_PIN 3
#endif
#endif
// Number of seconds (default one minute) inclusion mode should be enabled
/**
* @def MY_INCLUSION_MODE_DURATION
* @brief Number of seconds (default one minute) inclusion mode should be enabled.
*/
#ifndef MY_INCLUSION_MODE_DURATION
#define MY_INCLUSION_MODE_DURATION 60
#endif
/**
* @def MY_INCLUSION_BUTTON_PRESSED
* @brief The logical level indicating a pressed inclusion mode button.
*/
#if defined(MY_INCLUSION_BUTTON_EXTERNAL_PULLUP)
#define MY_INCLUSION_BUTTON_PRESSED HIGH
#else
@@ -270,10 +310,18 @@
* RS485 Driver Defaults
***********************************/
/**
* @def MY_RS485_BAUD_RATE
* @brief The RS485 BAUD rate.
*/
#ifndef MY_RS485_BAUD_RATE
#define MY_RS485_BAUD_RATE 9600
#endif
/**
* @def MY_RS485_MAX_MESSAGE_LENGTH
* @brief The maximum message length used for RS485.
*/
#ifndef MY_RS485_MAX_MESSAGE_LENGTH
#define MY_RS485_MAX_MESSAGE_LENGTH 40
#endif
@@ -285,7 +333,10 @@
// Enables RF24 encryption (all nodes and gateway must have this enabled, and all must be personalized with the same AES key)
//#define MY_RF24_ENABLE_ENCRYPTION
// Default pin settings. Override in sketch if needed.
/**
* @def MY_RF24_CE_PIN
* @brief Default RF24 chip enable pin setting. Override in sketch if needed.
*/
#ifndef MY_RF24_CE_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_RF24_CE_PIN 4
@@ -296,6 +347,10 @@
#endif
#endif
/**
* @def MY_RF24_CS_PIN
* @brief Default RF24 chip select pin setting. Override in sketch if needed.
*/
#ifndef MY_RF24_CS_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_RF24_CS_PIN 15
@@ -306,18 +361,36 @@
#endif
#endif
/**
* @def MY_RF24_PA_LEVEL
* @brief Default RF24 PA level. Override in sketch if needed.
*/
#ifndef MY_RF24_PA_LEVEL
#define MY_RF24_PA_LEVEL RF24_PA_MAX
#endif
// RF channel for the sensor net, 0-127
/**
* @def MY_RF24_CHANNEL
* @brief RF channel for the sensor net, 0-127.
*/
#ifndef MY_RF24_CHANNEL
#define MY_RF24_CHANNEL 76
#endif
//RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
/**
* @def MY_RF24_DATARATE
* @brief RF24 datarate (RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps or RF24_2MBPS for 2Mbps).
*/
#ifndef MY_RF24_DATARATE
#define MY_RF24_DATARATE RF24_250KBPS
#endif
// This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
/**
* @def MY_RF24_BASE_RADIO_ID
* @brief RF24 radio network identifier.
*
* This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
*/
#ifndef MY_RF24_BASE_RADIO_ID
#define MY_RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL)
#endif
@@ -325,12 +398,26 @@
// Enable SOFTSPI for NRF24L01, useful for the W5100 Ethernet module
//#define MY_SOFTSPI
/**
* @def MY_SOFT_SPI_SCK_PIN
* @brief Soft SPI SCK pin.
*/
#ifndef MY_SOFT_SPI_SCK_PIN
#define MY_SOFT_SPI_SCK_PIN 14
#endif
/**
* @def MY_SOFT_SPI_MISO_PIN
* @brief Soft SPI MISO pin.
*/
#ifndef MY_SOFT_SPI_MISO_PIN
#define MY_SOFT_SPI_MISO_PIN 16
#endif
/**
* @def MY_SOFT_SPI_MOSI_PIN
* @brief Soft SPI MOSI pin.
*/
#ifndef MY_SOFT_SPI_MOSI_PIN
#define MY_SOFT_SPI_MOSI_PIN 15
#endif
@@ -339,30 +426,60 @@
* RFM69 Driver Defaults
***********************************/
// Default frequency to use. This must match the hardware version of the RFM69 radio (uncomment one):
/**
* @def MY_RFM69_FREQUENCY
* @brief RFM69 frequency to use (RF69_433MHZ for 433MHz, RF69_868MHZ for 868MHz or RF69_915MHZ for 915MHz).
*
* This must match the hardware version of the RFM69 radio.
*/
#ifndef MY_RFM69_FREQUENCY
// #define MY_RFM69_FREQUENCY RF69_433MHZ
#define MY_RFM69_FREQUENCY RF69_868MHZ
//#define MY_RFM69_FREQUENCY RF69_915MHZ
#endif
// Enable this if you're running the RFM69HW model
/**
* @def MY_IS_RFM69HW
* @brief Enable this if you're running the RFM69HW model.
*/
//#define MY_IS_RFM69HW
/**
* @def MY_RFM69HW
* @brief Set to true if @ref MY_IS_RFM69HW is set.
*/
#ifdef MY_IS_RFM69HW
#define MY_RFM69HW true
#else
#define MY_RFM69HW false
#endif
// Default network id. Use the same for all nodes that will talk to each other
/**
* @def MY_RFM69_NETWORKID
* @brief RFM69 Network ID. Use the same for all nodes that will talk to each other.
*/
#ifndef MY_RFM69_NETWORKID
#define MY_RFM69_NETWORKID 100
#endif
/**
* @def MY_RF69_IRQ_PIN
* @brief RF69 IRQ pin.
*/
#ifndef MY_RF69_IRQ_PIN
#define MY_RF69_IRQ_PIN RF69_IRQ_PIN
#endif
/**
* @def MY_RF69_SPI_CS
* @brief RF69 SPI chip select pin.
*/
#ifndef MY_RF69_SPI_CS
#define MY_RF69_SPI_CS RF69_SPI_CS
#endif
/**
* @def MY_RF69_IRQ_NUM
* @brief RF69 IRQ pin number.
*/
#ifndef MY_RF69_IRQ_NUM
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_RF69_IRQ_NUM MY_RF69_IRQ_PIN
@@ -383,7 +500,10 @@
//#define MY_GATEWAY_ENC28J60
//#define MY_GATEWAY_ESP8266
// The port to open on controller or gateway
/**
* @def MY_PORT
* @brief The Ethernet TCP/UDP port to open on controller or gateway.
*/
#ifndef MY_PORT
#define MY_PORT 5003
#endif
@@ -394,11 +514,20 @@
// Enables UDP mode for Ethernet gateway (W5100)
//#define MY_USE_UDP
// DHCP, default renewal setting
/**
* @def MY_IP_RENEWAL_INTERVAL
* @brief DHCP, default renewal setting in milliseconds.
*/
#ifndef MY_IP_RENEWAL_INTERVAL
#define MY_IP_RENEWAL_INTERVAL 60000
#endif
/**
* @def MY_MAC_ADDRESS
* @brief Ethernet MAC address.
*
* This needs to be unique on the network.
*/
#ifndef MY_MAC_ADDRESS
#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
#endif
@@ -414,4 +543,5 @@
#define MY_SIGNING_ATSHA204
#define MY_SIGNING_SOFT
#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
#define MY_IS_RFM69HW
#endif
+40 -6
View File
@@ -1,4 +1,4 @@
/**
/*
* 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
@@ -16,13 +16,30 @@
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*/
/**
* @file MySensor.h
*
* MySensors main interface (includes all necessary code for the library)
*/
#ifndef MySensor_h
#define MySensor_h
#include "MyConfig.h"
#include "core/MySensorCore.h"
// Detect node type
/**
* @def MY_GATEWAY_FEATURE
* @brief Is set for gateway sketches.
*/
/**
* @def MY_IS_GATEWAY
* @brief Is true when @ref MY_GATEWAY_FEATURE is set.
*/
/**
* @def MY_NODE_TYPE
* @brief Contain a string describing the class of sketch/node (gateway/repeater/sensor).
*/
#if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100) || defined(MY_GATEWAY_ENC28J60) || defined(ARDUINO_ARCH_ESP8266) || defined(MY_GATEWAY_MQTT_CLIENT)
#define MY_GATEWAY_FEATURE
#define MY_IS_GATEWAY (true)
@@ -82,11 +99,17 @@
#endif
// default LEDs blinking period in milliseconds
/**
* @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
// The RX LED default pin
/**
* @def MY_DEFAULT_RX_LED_PIN
* @brief The RX LED default pin.
*/
#ifndef MY_DEFAULT_RX_LED_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_DEFAULT_RX_LED_PIN 8
@@ -94,7 +117,10 @@
#define MY_DEFAULT_RX_LED_PIN 6
#endif
#endif
// The TX LED default pin
/**
* @def MY_DEFAULT_TX_LED_PIN
* @brief The TX LED default pin.
*/
#ifndef MY_DEFAULT_TX_LED_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_DEFAULT_TX_LED_PIN 9
@@ -102,7 +128,10 @@
#define MY_DEFAULT_TX_LED_PIN 5
#endif
#endif
// The Error LED default pin
/**
* @def MY_DEFAULT_ERR_LED_PIN
* @brief The Error LED default pin.
*/
#ifndef MY_DEFAULT_ERR_LED_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_DEFAULT_ERR_LED_PIN 7
@@ -275,3 +304,8 @@
#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
#define MY_GATEWAY_FEATURE
#endif
@@ -20,10 +20,7 @@
#ifndef MyGatewayTransport_h
#define MyGatewayTransport_h
#include "MyConfig.h"
#include "MyMessage.h"
#include "MyProtocol.h"
#include "MySensorCore.h"
// Common gateway functions
-2
View File
@@ -21,8 +21,6 @@
#define MyHwATMega328_h
#include "MyHw.h"
#include "MyConfig.h"
#include "MyMessage.h"
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include <avr/sleep.h>
-4
View File
@@ -20,10 +20,6 @@
#define MyHwESP8266_h
#include "MyHw.h"
#include "MyConfig.h"
#include "MyMessage.h"
#ifdef __cplusplus
#include <Arduino.h>
-3
View File
@@ -20,9 +20,6 @@
#define MyHwSAMD_h
#include "MyHw.h"
#include "MyConfig.h"
#include "MyMessage.h"
#include <Wire.h>
#ifdef __cplusplus
+36 -40
View File
@@ -50,7 +50,7 @@ typedef enum {
C_STREAM = 4 //!< For firmware and other larger chunks of data that need to be divided into pieces.
} mysensor_command;
// Type of sensor (used when presenting sensors)
/// @brief Type of sensor (used when presenting sensors)
typedef enum {
S_DOOR, // Door sensor, V_TRIPPED, V_ARMED
S_MOTION, // Motion sensor, V_TRIPPED, V_ARMED
@@ -94,7 +94,7 @@ typedef enum {
S_GPS, // GPS Sensor, V_POSITION
} mysensor_sensor;
// Type of sensor data (for set/req/ack messages)
/// @brief Type of sensor data (for set/req/ack messages)
typedef enum {
V_TEMP, // S_TEMP. Temperature S_TEMP, S_HEATER, S_HVAC
V_HUM, // S_HUM. Humidity
@@ -163,19 +163,20 @@ typedef enum {
I_INCLUSION_MODE, I_CONFIG, I_FIND_PARENT, I_FIND_PARENT_RESPONSE,
I_LOG_MESSAGE, I_CHILDREN, I_SKETCH_NAME, I_SKETCH_VERSION,
I_REBOOT, I_GATEWAY_READY,
I_SIGNING_PRESENTATION, /*!< Provides signing related preferences (first byte is preference version) */
I_NONCE_REQUEST, /*!< Request for a nonce */
I_NONCE_RESPONSE, /*!< Payload is nonce data */
I_SIGNING_PRESENTATION, //!< Provides signing related preferences (first byte is preference version)
I_NONCE_REQUEST, //!< Request for a nonce
I_NONCE_RESPONSE, //!< Payload is nonce data
I_HEARTBEAT, I_PRESENTATION, I_DISCOVER, I_DISCOVER_RESPONSE, I_HEARTBEAT_RESPONSE
} mysensor_internal;
// Type of data stream (for streamed message)
/// @brief Type of data stream (for streamed message)
typedef enum {
ST_FIRMWARE_CONFIG_REQUEST, ST_FIRMWARE_CONFIG_RESPONSE, ST_FIRMWARE_REQUEST, ST_FIRMWARE_RESPONSE,
ST_SOUND, ST_IMAGE
} mysensor_stream;
/// @brief Type of payload
typedef enum {
P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM, P_FLOAT32
} mysensor_payload;
@@ -183,57 +184,52 @@ typedef enum {
#ifndef BIT
#define BIT(n) ( 1<<(n) )
#define BIT(n) ( 1<<(n) ) //!< Bit indexing macro
#endif
// Create a bitmask of length len.
#define BIT_MASK(len) ( BIT(len)-1 )
// Create a bitfield mask of length starting at bit 'start'.
#define BF_MASK(start, len) ( BIT_MASK(len)<<(start) )
#define BIT_MASK(len) ( BIT(len)-1 ) //!< Create a bitmask of length 'len'
#define BF_MASK(start, len) ( BIT_MASK(len)<<(start) ) //!< Create a bitfield mask of length starting at bit 'start'
// Prepare a bitmask for insertion or combining.
#define BF_PREP(x, start, len) ( ((x)&BIT_MASK(len)) << (start) )
// Extract a bitfield of length len starting at bit 'start' from y.
#define BF_GET(y, start, len) ( ((y)>>(start)) & BIT_MASK(len) )
// Insert a new bitfield value x into y.
#define BF_SET(y, x, start, len) ( y= ((y) &~ BF_MASK(start, len)) | BF_PREP(x, start, len) )
#define BF_PREP(x, start, len) ( ((x)&BIT_MASK(len)) << (start) ) //!< Prepare a bitmask for insertion or combining
#define BF_GET(y, start, len) ( ((y)>>(start)) & BIT_MASK(len) ) //!< Extract a bitfield of length 'len' starting at bit 'start' from 'y'
#define BF_SET(y, x, start, len) ( y= ((y) &~ BF_MASK(start, len)) | BF_PREP(x, start, len) ) //!< Insert a new bitfield value 'x' into 'y'
// Getters/setters for special bit fields in header
#define mSetVersion(_msg,_version) BF_SET(_msg.version_length, _version, 0, 2)
#define mGetVersion(_msg) BF_GET(_msg.version_length, 0, 2)
#define mSetVersion(_msg,_version) BF_SET(_msg.version_length, _version, 0, 2) //!< Set version field
#define mGetVersion(_msg) BF_GET(_msg.version_length, 0, 2) //!< Get version field
#define mSetSigned(_msg,_signed) BF_SET(_msg.version_length, _signed, 2, 1)
#define mGetSigned(_msg) BF_GET(_msg.version_length, 2, 1)
#define mSetSigned(_msg,_signed) BF_SET(_msg.version_length, _signed, 2, 1) //!< Set signed field
#define mGetSigned(_msg) BF_GET(_msg.version_length, 2, 1) //!< Get versignedsion field
#define mSetLength(_msg,_length) BF_SET(_msg.version_length, _length, 3, 5)
#define mGetLength(_msg) BF_GET(_msg.version_length, 3, 5)
#define mSetLength(_msg,_length) BF_SET(_msg.version_length, _length, 3, 5) //!< Set length field
#define mGetLength(_msg) BF_GET(_msg.version_length, 3, 5) //!< Get length field
#define mSetCommand(_msg,_command) BF_SET(_msg.command_ack_payload, _command, 0, 3)
#define mGetCommand(_msg) BF_GET(_msg.command_ack_payload, 0, 3)
#define mSetCommand(_msg,_command) BF_SET(_msg.command_ack_payload, _command, 0, 3) //!< Set command field
#define mGetCommand(_msg) BF_GET(_msg.command_ack_payload, 0, 3) //!< Get command field
#define mSetRequestAck(_msg,_rack) BF_SET(_msg.command_ack_payload, _rack, 3, 1)
#define mGetRequestAck(_msg) BF_GET(_msg.command_ack_payload, 3, 1)
#define mSetRequestAck(_msg,_rack) BF_SET(_msg.command_ack_payload, _rack, 3, 1) //!< Set ack-request field
#define mGetRequestAck(_msg) BF_GET(_msg.command_ack_payload, 3, 1) //!< Get ack-request field
#define mSetAck(_msg,_ackMsg) BF_SET(_msg.command_ack_payload, _ackMsg, 4, 1)
#define mGetAck(_msg) BF_GET(_msg.command_ack_payload, 4, 1)
#define mSetAck(_msg,_ackMsg) BF_SET(_msg.command_ack_payload, _ackMsg, 4, 1) //!< Set ack field
#define mGetAck(_msg) BF_GET(_msg.command_ack_payload, 4, 1) //!< Get ack field
#define mSetPayloadType(_msg, _pt) BF_SET(_msg.command_ack_payload, _pt, 5, 3)
#define mGetPayloadType(_msg) BF_GET(_msg.command_ack_payload, 5, 3)
#define mSetPayloadType(_msg, _pt) BF_SET(_msg.command_ack_payload, _pt, 5, 3) //!< Set payload type field
#define mGetPayloadType(_msg) BF_GET(_msg.command_ack_payload, 5, 3) //!< Get payload type field
// internal access for special fields
#define miGetCommand() BF_GET(command_ack_payload, 0, 3)
#define miGetCommand() BF_GET(command_ack_payload, 0, 3) //!< Internal getter for command field
#define miSetLength(_length) BF_SET(version_length, _length, 3, 5)
#define miGetLength() BF_GET(version_length, 3, 5)
#define miSetLength(_length) BF_SET(version_length, _length, 3, 5) //!< Internal setter for length field
#define miGetLength() BF_GET(version_length, 3, 5) //!< Internal getter for length field
#define miSetRequestAck(_rack) BF_SET(command_ack_payload, _rack, 3, 1)
#define miGetRequestAck() BF_GET(command_ack_payload, 3, 1)
#define miSetRequestAck(_rack) BF_SET(command_ack_payload, _rack, 3, 1) //!< Internal setter for ack-request field
#define miGetRequestAck() BF_GET(command_ack_payload, 3, 1) //!< Internal getter for ack-request field
#define miSetAck(_ack) BF_SET(command_ack_payload, _ack, 4, 1)
#define miGetAck() BF_GET(command_ack_payload, 4, 1)
#define miSetAck(_ack) BF_SET(command_ack_payload, _ack, 4, 1) //!< Internal setter for ack field
#define miGetAck() BF_GET(command_ack_payload, 4, 1) //!< Internal getter for ack field
#define miSetPayloadType(_pt) BF_SET(command_ack_payload, _pt, 5, 3)
#define miGetPayloadType() BF_GET(command_ack_payload, 5, 3)
#define miSetPayloadType(_pt) BF_SET(command_ack_payload, _pt, 5, 3) //!< Internal setter for payload type field
#define miGetPayloadType() BF_GET(command_ack_payload, 5, 3) //!< Internal getter for payload type field
#if !DOXYGEN
+1 -2
View File
@@ -20,8 +20,7 @@
#ifndef MyProtocol_h
#define MyProtocol_h
#include "MyConfig.h"
#include "MyMessage.h"
#include "MySensorCore.h"
// parse(message, inputString)
+16 -7
View File
@@ -1,4 +1,4 @@
/**
/*
* 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
@@ -44,15 +44,24 @@
#define NODE_SENSOR_ID 0xFF
struct NodeConfig
{
uint8_t nodeId; // Current node id
uint8_t parentNodeId; // Where this node sends its messages
uint8_t distance; // This nodes distance to sensor net gateway (number of hops)
/**
* @brief Node configuration
*
* This structure stores node-related configurations
*/
struct NodeConfig {
uint8_t nodeId; //!< Current node id
uint8_t parentNodeId; //!< Where this node sends its messages
uint8_t distance; //!< This nodes distance to sensor net gateway (number of hops)
};
/**
* @brief Controller configuration
*
* This structure stores controllerrelated configurations
*/
struct ControllerConfig {
uint8_t isMetric;
uint8_t isMetric; //!< Flag indicating if metric or imperial measurements are used
};
+1 -4
View File
@@ -473,11 +473,8 @@
#ifndef MySigning_h
#define MySigning_h
#include "MyConfig.h"
#include <stdint.h>
#include "MyMessage.h"
#include "drivers/ATSHA204/ATSHA204.h"
#include "MySensorCore.h"
#include "drivers/ATSHA204/ATSHA204.h"
#ifdef MY_SIGNING_NODE_WHITELISTING
typedef struct {
+21 -18
View File
@@ -1,4 +1,4 @@
/**
/*
* 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
@@ -42,33 +42,36 @@
#define SEARCH_FAILURES 5
// FW config structure, stored in eeprom
/// @brief FW config structure, stored in eeprom
typedef struct {
uint16_t type;
uint16_t version;
uint16_t blocks;
uint16_t crc;
uint16_t type; //!< Type of config
uint16_t version; //!< Version of config
uint16_t blocks; //!< Number of blocks
uint16_t crc; //!< CRC of block data
} __attribute__((packed)) NodeFirmwareConfig;
/// @brief FW config request structure
typedef struct {
uint16_t type;
uint16_t version;
uint16_t blocks;
uint16_t crc;
uint16_t BLVersion;
uint16_t type; //!< Type of config
uint16_t version; //!< Version of config
uint16_t blocks; //!< Number of blocks
uint16_t crc; //!< CRC of block data
uint16_t BLVersion; //!< Bootloader version
} __attribute__((packed)) RequestFirmwareConfig;
/// @brief FW block request structure
typedef struct {
uint16_t type;
uint16_t version;
uint16_t block;
uint16_t type; //!< Type of config
uint16_t version; //!< Version of config
uint16_t block; //!< Block index
} __attribute__((packed)) RequestFWBlock;
/// @brief FW block reply structure
typedef struct {
uint16_t type;
uint16_t version;
uint16_t block;
uint8_t data[FIRMWARE_BLOCK_SIZE];
uint16_t type; //!< Type of config
uint16_t version; //!< Version of config
uint16_t block; //!< Block index
uint8_t data[FIRMWARE_BLOCK_SIZE]; //!< Block data
} __attribute__((packed)) ReplyFWBlock;
@@ -41,8 +41,24 @@ class PinIO {
public:
/** Create a PinIO object with no assigned pin. */
PinIO() : bit_(0), mask_(0XFF) {}
/** Constructor
* @param[in] pin Pin assigned to this object.
*/
explicit PinIO(uint8_t pin);
/** Initialize pin bit mask and port address.
* @param[in] pin Arduino board pin number.
* @return true for success or false if invalid pin number.
*/
bool begin(uint8_t pin);
/** Configure the pin
*
* @param[in] mode Configure as output mode if true else input mode.
* @param[in] data For output mode set pin high if true else low.
* For input mode enable 20K pullup if true else Hi-Z.
*
* This function may be used with interrupts enabled or disabled.
* The previous interrupt state will be restored.
*/
void config(bool mode, bool data);
//----------------------------------------------------------------------------
/** @return Pin's level */
@@ -91,9 +91,45 @@ class I2cMasterBase {
*/
virtual void stop() = 0;
/**
* Start an I2C transfer with possible continuation.
*
* @param[in] addressRW I2C slave address plus R/W bit.
* The I2C slave address is in the high seven bits
* and is ORed with on of the following:
* - I2C_READ for a read transfer.
* - I2C_WRITE for a write transfer.
* .
* @param[in,out] buf Source or destination for transfer.
* @param[in] nbyte Number of bytes to transfer (may be zero).
* @param[in] option Option for ending the transfer, one of:
* - I2C_STOP end the transfer with an I2C stop
* condition.
* - I2C_REP_START end the transfer with an I2C
* repeated start condition.
* - I2C_CONTINUE allow additional transferContinue()
* calls.
* .
* @return true for success else false.
*/
bool transfer(uint8_t addressRW, void *buf,
size_t nbyte, uint8_t option = I2C_STOP);
/**
* Continue an I2C transfer.
*
* @param[in,out] buf Source or destination for transfer.
* @param[in] nbyte Number of bytes to transfer (may be zero).
* @param[in] option Option for ending the transfer, one of:
* - I2C_STOP end the transfer with an I2C stop
* condition.
* - I2C_REP_START end the transfer with an I2C
* repeated start condition.
* - I2C_CONTINUE allow additional transferContinue()
* calls.
* .
* @return true for success else false.
*/
bool transferContinue(void *buf, size_t nbyte, uint8_t option = I2C_STOP);
/** Write a byte
*
@@ -115,7 +151,21 @@ class I2cMasterBase {
class SoftI2cMaster : public I2cMasterBase {
public:
SoftI2cMaster() {}
/**
* Constructor, initialize SCL/SDA pins and set the bus high.
*
* @param[in] sdaPin The software SDA pin number.
*
* @param[in] sclPin The software SCL pin number.
*/
SoftI2cMaster(uint8_t sclPin, uint8_t sdaPin);
/**
* Initialize SCL/SDA pins and set the bus high.
*
* @param[in] sdaPin The software SDA pin number.
*
* @param[in] sclPin The software SCL pin number.
*/
void begin(uint8_t sclPin, uint8_t sdaPin);
uint8_t read(uint8_t last);
void start();
@@ -8,8 +8,11 @@
#define STATIC_ALWAYS_INLINE static inline __attribute__((always_inline))
//------------------------------------------------------------------------------
template<uint8_t ClkPin, uint8_t ConvPin, uint8_t DataPin>
/** ADS7818 class */
class ADS7818 {
public:
//----------------------------------------------------------------------------
/** Set pin modes and initial levels. */
void begin() {
fastPinMode(ClkPin, 1);
fastDigitalWrite(ClkPin, 0);
@@ -18,6 +21,9 @@ class ADS7818 {
fastPinMode(DataPin, 0);
}
//----------------------------------------------------------------------------
/** Read ADS7818 12-bit ADC
* \return 16-bit value read.
*/
inline __attribute__((always_inline))
uint16_t read() {
uint16_t v = 0;
@@ -3,6 +3,7 @@
#include <DigitalIO.h>
//==============================================================================
template<uint8_t CsPin, uint8_t ClkPin, uint8_t DoutPin, uint8_t UsecDelay = 0>
/** MCP3201 class */
class MCP3201 {
public:
//----------------------------------------------------------------------------
@@ -81,6 +82,7 @@ class MCP3201 {
//==============================================================================
template<uint8_t CsPin, uint8_t ClkPin,
uint8_t DoutPin, uint8_t DinPin, uint8_t UsecDelay = 0>
/** MCP3202 class */
class MCP3202 {
public:
//----------------------------------------------------------------------------
@@ -165,6 +167,7 @@ class MCP3202 {
//==============================================================================
template<uint8_t CsPin, uint8_t ClkPin,
uint8_t DoutPin, uint8_t DinPin, uint8_t UsecDelay = 0>
/** MCP3204 class */
class MCP3204 {
public:
//----------------------------------------------------------------------------
@@ -8,6 +8,7 @@ const int32_t MCP355X_ERR = 0X80000000;
const uint8_t MCP355X_TO_MS = 100;
//==============================================================================
template<uint8_t CsPin, uint8_t SckPin, uint8_t SdoPin>
/** MCP355X class */
class MCP355X {
public:
//----------------------------------------------------------------------------
@@ -39,34 +39,35 @@
#define ALTSS_BASE_FREQ F_CPU
#endif
/** AltSoftSerial class */
class AltSoftSerial : public Stream
{
public:
AltSoftSerial() { }
~AltSoftSerial() { end(); }
static void begin(uint32_t baud) { init((ALTSS_BASE_FREQ + baud / 2) / baud); }
static void end();
int peek();
int read();
int available();
AltSoftSerial() { } //!< Constructor
~AltSoftSerial() { end(); } //!< Destructor
static void begin(uint32_t baud) { init((ALTSS_BASE_FREQ + baud / 2) / baud); } //!< begin
static void end(); //!< end
int peek(); //!< peek
int read(); //!< read
int available(); //!< available
#if ARDUINO >= 100
size_t write(uint8_t byte) { writeByte(byte); return 1; }
void flush() { flushOutput(); }
size_t write(uint8_t byte) { writeByte(byte); return 1; } //!< write
void flush() { flushOutput(); } //!< flush
#else
void write(uint8_t byte) { writeByte(byte); }
void flush() { flushInput(); }
void write(uint8_t byte) { writeByte(byte); } //!< write
void flush() { flushInput(); } //!< flush
#endif
using Print::write;
static void flushInput();
static void flushOutput();
static void flushInput(); //!< flushInput
static void flushOutput(); //!< flushOutput
// for drop-in compatibility with NewSoftSerial, rxPin & txPin ignored
//AltSoftSerial(uint8_t rxPin, uint8_t txPin, bool inverse = false) { }
bool listen() { return false; }
bool isListening() { return true; }
bool overflow() { bool r = timing_error; timing_error = false; return r; }
static int library_version() { return 1; }
static void enable_timer0(bool) { }
static bool timing_error;
bool listen() { return false; } //!< listen
bool isListening() { return true; } //!< isListening
bool overflow() { bool r = timing_error; timing_error = false; return r; } //!< overflow
static int library_version() { return 1; } //!< library_version
static void enable_timer0(bool) { } //!< enable_timer0
static bool timing_error; //!< timing_error
private:
static void init(uint32_t cycles_per_bit);
static void writeByte(uint8_t byte);
+51 -50
View File
@@ -72,19 +72,20 @@
#define RF69_BROADCAST_ADDR 255
#define RF69_CSMA_LIMIT_MS 1000
/** RFM69 class */
class RFM69 {
public:
static volatile byte DATA[RF69_MAX_DATA_LEN]; // recv/xmit buf, including hdr & crc bytes
static volatile byte DATALEN;
static volatile byte SENDERID;
static volatile byte TARGETID; //should match _address
static volatile byte PAYLOADLEN;
static volatile byte ACK_REQUESTED;
static volatile byte ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request
static volatile int RSSI; //most accurate RSSI during reception (closest to the reception)
static volatile byte _mode; //should be protected?
static volatile byte DATA[RF69_MAX_DATA_LEN]; //!< recv/xmit buf, including hdr & crc bytes
static volatile byte DATALEN; //!< DATALEN
static volatile byte SENDERID; //!< SENDERID
static volatile byte TARGETID; //!< should match _address
static volatile byte PAYLOADLEN; //!< PAYLOADLEN
static volatile byte ACK_REQUESTED; //!< ACK_REQUESTED
static volatile byte ACK_RECEIVED; //!< Should be polled immediately after sending a packet with ACK request
static volatile int RSSI; //!< most accurate RSSI during reception (closest to the reception)
static volatile byte _mode; //!< should be protected?
RFM69(byte slaveSelectPin=RF69_SPI_CS, byte interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false, byte interruptNum=RF69_IRQ_NUM) {
RFM69(byte slaveSelectPin=RF69_SPI_CS, byte interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false, byte interruptNum=RF69_IRQ_NUM) { //!< Constructor
_slaveSelectPin = slaveSelectPin;
_interruptPin = interruptPin;
_interruptNum = interruptNum;
@@ -94,52 +95,52 @@ class RFM69 {
_isRFM69HW = isRFM69HW;
}
bool initialize(byte freqBand, byte ID, byte networkID=1);
void setAddress(byte addr);
bool canSend();
void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false);
bool sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries=2, byte retryWaitTime=40); //40ms roundtrip req for 61byte packets
bool receiveDone();
bool ACKReceived(byte fromNodeID);
bool ACKRequested();
void sendACK(const void* buffer = "", uint8_t bufferSize=0);
void setFrequency(uint32_t FRF);
void encrypt(const char* key);
void setCS(byte newSPISlaveSelect);
int readRSSI(bool forceTrigger=false);
void promiscuous(bool onOff=true);
void setHighPower(bool onOFF=true); //have to call it after initialize for RFM69HW
void setPowerLevel(byte level); //reduce/increase transmit power level
void sleep();
byte readTemperature(byte calFactor=0); //get CMOS temperature (8bit)
void rcCalibration(); //calibrate the internal RC oscillator for use in wide temperature variations - see datasheet section [4.3.5. RC Timer Accuracy]
bool initialize(byte freqBand, byte ID, byte networkID=1); //!< initialize
void setAddress(byte addr); //!< setAddress
bool canSend(); //!< canSend
void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false); //!< send
bool sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries=2, byte retryWaitTime=40); //!< sendWithRetry (40ms roundtrip req for 61byte packets)
bool receiveDone(); //!< receiveDone
bool ACKReceived(byte fromNodeID); //!< ACKReceived
bool ACKRequested(); //!< ACKRequested
void sendACK(const void* buffer = "", uint8_t bufferSize=0); //!< sendACK
void setFrequency(uint32_t FRF); //!< setFrequency
void encrypt(const char* key); //!< encrypt
void setCS(byte newSPISlaveSelect); //!< setCS
int readRSSI(bool forceTrigger=false); //!< readRSSI
void promiscuous(bool onOff=true); //!< promiscuous
void setHighPower(bool onOFF=true); //!< setHighPower (have to call it after initialize for RFM69HW)
void setPowerLevel(byte level); //!< setPowerLevel (reduce/increase transmit power level)
void sleep(); //!< sleep
byte readTemperature(byte calFactor=0); //!< readTemperature (get CMOS temperature (8bit))
void rcCalibration(); //!< rcCalibration (calibrate the internal RC oscillator for use in wide temperature variations - see datasheet section [4.3.5. RC Timer Accuracy])
// allow hacking registers by making these public
byte readReg(byte addr);
void writeReg(byte addr, byte val);
void readAllRegs();
byte readReg(byte addr); //!< readReg
void writeReg(byte addr, byte val); //!< writeReg
void readAllRegs(); //!< readAllRegs
protected:
static void isr0();
void virtual interruptHandler();
void sendFrame(byte toAddress, const void* buffer, byte size, bool requestACK=false, bool sendACK=false);
static void isr0(); //!< isr0
void virtual interruptHandler(); //!< interruptHandler
void sendFrame(byte toAddress, const void* buffer, byte size, bool requestACK=false, bool sendACK=false); //!< sendFrame
static RFM69* selfPointer;
byte _slaveSelectPin;
byte _interruptPin;
byte _interruptNum;
byte _address;
bool _promiscuousMode;
byte _powerLevel;
bool _isRFM69HW;
byte _SPCR;
byte _SPSR;
static RFM69* selfPointer; //!< selfPointer
byte _slaveSelectPin; //!< _slaveSelectPin
byte _interruptPin; //!< _interruptPin
byte _interruptNum; //!< _interruptNum
byte _address; //!< _address
bool _promiscuousMode; //!< _promiscuousMode
byte _powerLevel; //!< _powerLevel
bool _isRFM69HW; //!< _isRFM69HW
byte _SPCR; //!< _SPCR
byte _SPSR; //!< _SPSR
void receiveBegin();
void setMode(byte mode);
void setHighPowerRegs(bool onOff);
void select();
void unselect();
void receiveBegin(); //!< receiveBegin
void setMode(byte mode); //!< setMode
void setHighPowerRegs(bool onOff); //!< setHighPowerRegs
void select(); //!< select
void unselect(); //!< unselect
};
#endif
+25 -24
View File
@@ -87,34 +87,35 @@
// Example for Winbond 4Mbit W25X40CL: 0xEF30 (page 14: http://www.winbond.com/NR/rdonlyres/6E25084C-0BFE-4B25-903D-AE10221A0929/0/W25X40CL.pdf)
#define SPIFLASH_MACREAD 0x4B // read unique ID number (MAC)
/** SPIFlash class */
class SPIFlash {
public:
static uint8_t UNIQUEID[8];
SPIFlash(uint8_t slaveSelectPin, uint16_t jedecID=0);
boolean initialize();
void command(uint8_t cmd, boolean isWrite=false);
uint8_t readStatus();
uint8_t readByte(uint32_t addr);
void readBytes(uint32_t addr, void* buf, uint16_t len);
void writeByte(uint32_t addr, uint8_t byt);
void writeBytes(uint32_t addr, const void* buf, uint16_t len);
boolean busy();
void chipErase();
void blockErase4K(uint32_t address);
void blockErase32K(uint32_t address);
uint16_t readDeviceId();
uint8_t* readUniqueId();
static uint8_t UNIQUEID[8]; //!< Storage for unique identifier
SPIFlash(uint8_t slaveSelectPin, uint16_t jedecID=0); //!< Constructor
boolean initialize(); //!< setup SPI, read device ID etc...
void command(uint8_t cmd, boolean isWrite=false); //!< Send a command to the flash chip, pass TRUE for isWrite when its a write command
uint8_t readStatus(); //!< return the STATUS register
uint8_t readByte(uint32_t addr); //!< read 1 byte from flash memory
void readBytes(uint32_t addr, void* buf, uint16_t len); //!< read unlimited # of bytes
void writeByte(uint32_t addr, uint8_t byt); //!< Write 1 byte to flash memory
void writeBytes(uint32_t addr, const void* buf, uint16_t len); //!< write multiple bytes to flash memory (up to 64K)
boolean busy(); //!< check if the chip is busy erasing/writing
void chipErase(); //!< erase entire flash memory array
void blockErase4K(uint32_t address); //!< erase a 4Kbyte block
void blockErase32K(uint32_t address); //!< erase a 32Kbyte block
uint16_t readDeviceId(); //!< Get the manufacturer and device ID bytes (as a short word)
uint8_t* readUniqueId(); //!< Get the 64 bit unique identifier, stores it in @ref UNIQUEID[8]
void sleep();
void wakeup();
void end();
void sleep(); //!< Put device to sleep
void wakeup(); //!< Wake device
void end(); //!< end
protected:
void select();
void unselect();
uint8_t _slaveSelectPin;
uint16_t _jedecID;
uint8_t _SPCR;
uint8_t _SPSR;
void select(); //!< select
void unselect(); //!< unselect
uint8_t _slaveSelectPin; //!< Slave select pin
uint16_t _jedecID; //!< JEDEC ID
uint8_t _SPCR; //!< SPCR
uint8_t _SPSR; //!< SPSR
#ifdef SPI_HAS_TRANSACTION
SPISettings _settings;
#endif
@@ -64,6 +64,7 @@
#define MQTT_CALLBACK_SIGNATURE void (*callback)(char*,uint8_t*,unsigned int)
/** PubSubClient class */
class PubSubClient {
private:
Client* _client;
@@ -83,44 +84,44 @@ private:
Stream* stream;
int _state;
public:
PubSubClient();
PubSubClient(Client& client);
PubSubClient(IPAddress, uint16_t, Client& client);
PubSubClient(IPAddress, uint16_t, Client& client, Stream&);
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
PubSubClient(uint8_t *, uint16_t, Client& client);
PubSubClient(uint8_t *, uint16_t, Client& client, Stream&);
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
PubSubClient(const char*, uint16_t, Client& client);
PubSubClient(const char*, uint16_t, Client& client, Stream&);
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
PubSubClient(); //!< PubSubClient
PubSubClient(Client& client); //!< PubSubClient
PubSubClient(IPAddress, uint16_t, Client& client); //!< PubSubClient
PubSubClient(IPAddress, uint16_t, Client& client, Stream&); //!< PubSubClient
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client); //!< PubSubClient
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&); //!< PubSubClient
PubSubClient(uint8_t *, uint16_t, Client& client); //!< PubSubClient
PubSubClient(uint8_t *, uint16_t, Client& client, Stream&); //!< PubSubClient
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client); //!< PubSubClient
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&); //!< PubSubClient
PubSubClient(const char*, uint16_t, Client& client); //!< PubSubClient
PubSubClient(const char*, uint16_t, Client& client, Stream&); //!< PubSubClient
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client); //!< PubSubClient
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&); //!< PubSubClient
PubSubClient& setServer(IPAddress ip, uint16_t port);
PubSubClient& setServer(uint8_t * ip, uint16_t port);
PubSubClient& setServer(const char * domain, uint16_t port);
PubSubClient& setCallback(MQTT_CALLBACK_SIGNATURE);
PubSubClient& setClient(Client& client);
PubSubClient& setStream(Stream& stream);
PubSubClient& setServer(IPAddress ip, uint16_t port); //!< setServer
PubSubClient& setServer(uint8_t * ip, uint16_t port); //!< setServer
PubSubClient& setServer(const char * domain, uint16_t port); //!< setServer
PubSubClient& setCallback(MQTT_CALLBACK_SIGNATURE); //!< setCallback
PubSubClient& setClient(Client& client); //!< setClient
PubSubClient& setStream(Stream& stream); //!< setStream
boolean connect(const char* id);
boolean connect(const char* id, const char* user, const char* pass);
boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
void disconnect();
boolean publish(const char* topic, const char* payload);
boolean publish(const char* topic, const char* payload, boolean retained);
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
boolean subscribe(const char* topic);
boolean subscribe(const char* topic, uint8_t qos);
boolean unsubscribe(const char* topic);
boolean loop();
boolean connected();
int state();
boolean connect(const char* id); //!< connect
boolean connect(const char* id, const char* user, const char* pass); //!< connect
boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage); //!< connect
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage); //!< connect
void disconnect(); //!< disconnect
boolean publish(const char* topic, const char* payload); //!< publish
boolean publish(const char* topic, const char* payload, boolean retained); //!< publish
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength); //!< publish
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained); //!< publish
boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained); //!< publish_P
boolean subscribe(const char* topic); //!< subscribe
boolean subscribe(const char* topic, uint8_t qos); //!< subscribe
boolean unsubscribe(const char* topic); //!< unsubscribe
boolean loop(); //!< loop
boolean connected(); //!< connected
int state(); //!< state
};
@@ -3,6 +3,7 @@
#include "Arduino.h"
/** Buffer class */
class Buffer {
private:
uint8_t buffer[1024];
@@ -10,14 +11,14 @@ private:
uint16_t length;
public:
Buffer();
Buffer(uint8_t* buf, size_t size);
Buffer(); //!< Buffer
Buffer(uint8_t* buf, size_t size); //!< Buffer
virtual bool available();
virtual uint8_t next();
virtual void reset();
virtual bool available(); //!< available
virtual uint8_t next(); //!< next
virtual void reset(); //!< reset
virtual void add(uint8_t* buf, size_t size);
virtual void add(uint8_t* buf, size_t size); //!< add
};
#endif
@@ -2,20 +2,21 @@
#define client_h
#include "IPAddress.h"
/** Client class */
class Client {
public:
virtual int connect(IPAddress ip, uint16_t port) =0;
virtual int connect(const char *host, uint16_t port) =0;
virtual size_t write(uint8_t) =0;
virtual size_t write(const uint8_t *buf, size_t size) =0;
virtual int available() = 0;
virtual int read() = 0;
virtual int read(uint8_t *buf, size_t size) = 0;
virtual int peek() = 0;
virtual void flush() = 0;
virtual void stop() = 0;
virtual uint8_t connected() = 0;
virtual operator bool() = 0;
virtual int connect(IPAddress ip, uint16_t port) =0; //!< connect
virtual int connect(const char *host, uint16_t port) =0; //!< connect
virtual size_t write(uint8_t) =0; //!< write
virtual size_t write(const uint8_t *buf, size_t size) =0; //!< write
virtual int available() = 0; //!< available
virtual int read() = 0; //!< read
virtual int read(uint8_t *buf, size_t size) = 0; //!< read
virtual int peek() = 0; //!< peek
virtual void flush() = 0; //!< flush
virtual void stop() = 0; //!< stop
virtual uint8_t connected() = 0; //!< connected
virtual operator bool() = 0; //!< bool operator
};
#endif
@@ -29,6 +29,7 @@
// A class to make it easier to handle and pass around IP addresses
/** IPAddress class */
class IPAddress {
private:
uint8_t _address[4]; // IPv4 address
@@ -40,23 +41,30 @@ private:
public:
// Constructors
IPAddress();
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
IPAddress(uint32_t address);
IPAddress(const uint8_t *address);
IPAddress(); //!< IPAddress
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); //!< IPAddress
IPAddress(uint32_t address); //!< IPAddress
IPAddress(const uint8_t *address); //!< IPAddress
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
// to a four-byte uint8_t array is expected
/** @brief operator overload */
operator uint32_t() { return *((uint32_t*)_address); };
/** @brief operator overload */
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
/** @brief operator overload */
bool operator==(const uint8_t* addr);
// Overloaded index operator to allow getting and setting individual octets of the address
/** @brief operator overload */
uint8_t operator[](int index) const { return _address[index]; };
/** @brief operator overload */
uint8_t& operator[](int index) { return _address[index]; };
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
/** @brief operator overload */
IPAddress& operator=(const uint8_t *address);
/** @brief operator overload */
IPAddress& operator=(uint32_t address);
@@ -7,6 +7,7 @@
#include "Buffer.h"
/** ShimClient class */
class ShimClient : public Client {
private:
Buffer* responseBuffer;
@@ -22,30 +23,30 @@ private:
public:
ShimClient();
virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char *host, uint16_t port);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);
virtual int available();
virtual int read();
virtual int read(uint8_t *buf, size_t size);
virtual int peek();
virtual void flush();
virtual void stop();
virtual uint8_t connected();
virtual operator bool();
virtual int connect(IPAddress ip, uint16_t port); //!< connect
virtual int connect(const char *host, uint16_t port); //!< connect
virtual size_t write(uint8_t); //!< write
virtual size_t write(const uint8_t *buf, size_t size); //!< write
virtual int available(); //!< available
virtual int read(); //!< read
virtual int read(uint8_t *buf, size_t size); //!< read
virtual int peek(); //!< peek
virtual void flush(); //!< flush
virtual void stop(); //!< stop
virtual uint8_t connected(); //!< connected
virtual operator bool(); //!< bool operator
virtual ShimClient* respond(uint8_t *buf, size_t size);
virtual ShimClient* expect(uint8_t *buf, size_t size);
virtual ShimClient* respond(uint8_t *buf, size_t size); //!< respond
virtual ShimClient* expect(uint8_t *buf, size_t size); //!< expect
virtual void expectConnect(IPAddress ip, uint16_t port);
virtual void expectConnect(const char *host, uint16_t port);
virtual void expectConnect(IPAddress ip, uint16_t port); //!< expectConnect
virtual void expectConnect(const char *host, uint16_t port); //!< expectConnect
virtual uint16_t received();
virtual bool error();
virtual uint16_t received(); //!< received
virtual bool error(); //!< error
virtual void setAllowConnect(bool b);
virtual void setConnected(bool b);
virtual void setAllowConnect(bool b); //!< setAllowConnect
virtual void setConnected(bool b); //!< setConnected
};
#endif
@@ -4,6 +4,7 @@
#include "Arduino.h"
#include "Buffer.h"
/** Stream class */
class Stream {
private:
Buffer* expectBuffer;
@@ -12,11 +13,11 @@ private:
public:
Stream();
virtual size_t write(uint8_t);
virtual size_t write(uint8_t); //!< write
virtual bool error();
virtual void expect(uint8_t *buf, size_t size);
virtual uint16_t length();
virtual bool error(); //!< error
virtual void expect(uint8_t *buf, size_t size); //!< expect
virtual uint16_t length(); //!< length
};
#endif
@@ -1,4 +1,4 @@
/**
/*
* 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
@@ -45,7 +45,7 @@
* Reinier van der Lee and Theodore Kaskalis
* www.vanderleevineyard.com
* Contributor: epierre
**/
*/
// Copyright (C) 2015, Reinier van der Lee
// www.vanderleevineyard.com
@@ -81,9 +81,10 @@ unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
long buffer[NUM_READS];
int index;
typedef struct { // Structure to be used in percentage and resistance values matrix to be filtered (have to be in pairs)
int moisture;
long resistance;
/// @brief Structure to be used in percentage and resistance values matrix to be filtered (have to be in pairs)
typedef struct {
int moisture; //!< Moisture
long resistance; //!< Resistance
} values;
const long knownResistor = 4700; // Constant value of known resistor in Ohms