diff --git a/core/MyTransport.h b/core/MyTransport.h index 3355db081..02a3f0eca 100644 --- a/core/MyTransport.h +++ b/core/MyTransport.h @@ -269,11 +269,11 @@ typedef struct { // PRIVATE functions /** -* @brief Initialise SM variables and transport HW +* @brief Initialize SM variables and transport HW */ void stInitTransition(void); /** -* @brief Initialise transport +* @brief Initialize transport */ void stInitUpdate(void); /** @@ -345,7 +345,7 @@ void transportProcessMessage(void); /** * @brief Assign node ID * @param newNodeId New node ID -* @return true if node ID valid and successfully assigned +* @return true if node ID is valid and successfully assigned */ bool transportAssignNodeID(const uint8_t newNodeId); /** @@ -409,7 +409,7 @@ void transportInitialize(void); void transportProcess(void); /** * @brief Flag transport ready -* @return true if transport is initialize and ready +* @return true if transport is initialized and ready */ bool isTransportReady(void); /** @@ -462,7 +462,21 @@ void transportSetRoute(const uint8_t node, const uint8_t route); * @return route to node */ uint8_t transportGetRoute(const uint8_t node); - +/** +* @brief Get node ID +* @return node ID +*/ +uint8_t transportGetNodeId(void); +/** +* @brief Get parent node ID +* @return parent node ID +*/ +uint8_t transportGetParentNodeId(void); +/** +* @brief Get distance to GW +* @return distance (=hops) to GW +*/ +uint8_t transportGetDistanceGW(void); // interface functions for radio driver @@ -470,15 +484,15 @@ uint8_t transportGetRoute(const uint8_t node); * @brief Initialize transport HW * @return true if initialization successful */ -bool transportInit(); +bool transportInit(void); /** * @brief Set node address */ -void transportSetAddress(uint8_t address); +void transportSetAddress(const uint8_t address); /** * @brief Retrieve node address */ -uint8_t transportGetAddress(); +uint8_t transportGetAddress(void); /** * @brief Send message * @param to recipient @@ -486,17 +500,17 @@ uint8_t transportGetAddress(); * @param len length of message (header + payload) * @return true if message sent successfully */ -bool transportSend(uint8_t to, const void* data, uint8_t len); +bool transportSend(const uint8_t to, const void* data, const uint8_t len); /** * @brief Verify if RX FIFO has pending messages * @return true if message available in RX FIFO */ -bool transportAvailable(); +bool transportAvailable(void); /** * @brief Sanity check for transport: is transport still responsive? -* @return true transport ok +* @return true if transport HW is ok */ -bool transportSanityCheck(); +bool transportSanityCheck(void); /** * @brief Receive message from FIFO * @return length of recevied message (header + payload) @@ -505,24 +519,7 @@ uint8_t transportReceive(void* data); /** * @brief Power down transport HW */ -void transportPowerDown(); - -/** -* @brief Get node ID -* @return node ID -*/ -uint8_t transportGetNodeId(void); -/** -* @brief Get parent node ID -* @return parent node ID -*/ -uint8_t transportGetParentNodeId(void); -/** -* @brief Get distance to GW -* @return distance (=hops) to GW -*/ -uint8_t transportGetDistanceGW(void); - +void transportPowerDown(void); #endif // MyTransport_h /** @}*/ diff --git a/core/MyTransportNRF24.cpp b/core/MyTransportNRF24.cpp index 65230da36..14e8d257b 100644 --- a/core/MyTransportNRF24.cpp +++ b/core/MyTransportNRF24.cpp @@ -94,19 +94,19 @@ uint8_t transportGetAddress(void) return RF24_getNodeID(); } -bool transportSend(const uint8_t recipient, const void* data, uint8_t len) +bool transportSend(const uint8_t to, const void* data, const uint8_t len) { #if defined(MY_RF24_ENABLE_ENCRYPTION) // copy input data because it is read-only (void)memcpy(_dataenc,data,len); // has to be adjusted, WIP! _aes.set_IV(0); - len = len > 16 ? 32 : 16; + const uint8_t finalLength = len > 16 ? 32 : 16; //encrypt data - _aes.cbc_encrypt(_dataenc, _dataenc, len/16); - return RF24_sendMessage(recipient, _dataenc, len); + _aes.cbc_encrypt(_dataenc, _dataenc, finalLength /16); + return RF24_sendMessage(to, _dataenc, finalLength); #else - return RF24_sendMessage(recipient, data, len); + return RF24_sendMessage(to, data, len); #endif } diff --git a/core/MyTransportRFM69.cpp b/core/MyTransportRFM69.cpp index b5ff53fab..905ee8b1a 100644 --- a/core/MyTransportRFM69.cpp +++ b/core/MyTransportRFM69.cpp @@ -26,7 +26,7 @@ RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_RFM69HW, MY_RF69_IRQ_NUM); uint8_t _address; -bool transportInit() +bool transportInit(void) { // Start up the radio library (_address will be set later by the MySensors library) if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) { @@ -41,28 +41,28 @@ bool transportInit() return false; } -void transportSetAddress(uint8_t address) +void transportSetAddress(const uint8_t address) { _address = address; _radio.setAddress(address); } -uint8_t transportGetAddress() +uint8_t transportGetAddress(void) { return _address; } -bool transportSend(uint8_t to, const void* data, uint8_t len) +bool transportSend(const uint8_t to, const void* data, const uint8_t len) { return _radio.sendWithRetry(to,data,len); } -bool transportAvailable() +bool transportAvailable(void) { return _radio.receiveDone(); } -bool transportSanityCheck() +bool transportSanityCheck(void) { // not implemented yet return true; @@ -80,7 +80,7 @@ uint8_t transportReceive(void* data) return dataLen; } -void transportPowerDown() +void transportPowerDown(void) { _radio.sleep(); } diff --git a/core/MyTransportRFM95.cpp b/core/MyTransportRFM95.cpp index 9981bd5ce..3b88994e9 100644 --- a/core/MyTransportRFM95.cpp +++ b/core/MyTransportRFM95.cpp @@ -32,7 +32,7 @@ bool transportInit(void) return result; } -void transportSetAddress(uint8_t address) +void transportSetAddress(const uint8_t address) { RFM95_setAddress(address); } @@ -42,7 +42,7 @@ uint8_t transportGetAddress(void) return RFM95_getAddress(); } -bool transportSend(uint8_t to, const void* data, uint8_t len) +bool transportSend(const uint8_t to, const void* data, const uint8_t len) { return RFM95_sendWithRetry(to, data, len); } diff --git a/core/MyTransportRS485.cpp b/core/MyTransportRS485.cpp index b86560222..976bc867c 100644 --- a/core/MyTransportRS485.cpp +++ b/core/MyTransportRS485.cpp @@ -239,7 +239,7 @@ bool _serialProcess() return true; } -bool transportSend(uint8_t to, const void* data, uint8_t len) +bool transportSend(const uint8_t to, const void* data, const uint8_t len) { const char *datap = static_cast(data); unsigned char i; @@ -319,7 +319,7 @@ bool transportSend(uint8_t to, const void* data, uint8_t len) -bool transportInit() +bool transportInit(void) { // Reset the state machine _dev.begin(MY_RS485_BAUD_RATE); @@ -331,24 +331,24 @@ bool transportInit() return true; } -void transportSetAddress(uint8_t address) +void transportSetAddress(const uint8_t address) { _nodeId = address; } -uint8_t transportGetAddress() +uint8_t transportGetAddress(void) { return _nodeId; } -bool transportAvailable() +bool transportAvailable(void) { _serialProcess(); return _packet_received; } -bool transportSanityCheck() +bool transportSanityCheck(void) { // not implemented yet return true; @@ -365,7 +365,7 @@ uint8_t transportReceive(void* data) } } -void transportPowerDown() +void transportPowerDown(void) { // Nothing to shut down here }