Harmonize transport code (#710)
This commit is contained in:
+46
-49
@@ -269,11 +269,11 @@ typedef struct {
|
|||||||
// PRIVATE functions
|
// PRIVATE functions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise SM variables and transport HW
|
* @brief Initialize SM variables and transport HW
|
||||||
*/
|
*/
|
||||||
void stInitTransition(void);
|
void stInitTransition(void);
|
||||||
/**
|
/**
|
||||||
* @brief Initialise transport
|
* @brief Initialize transport
|
||||||
*/
|
*/
|
||||||
void stInitUpdate(void);
|
void stInitUpdate(void);
|
||||||
/**
|
/**
|
||||||
@@ -345,7 +345,7 @@ void transportProcessMessage(void);
|
|||||||
/**
|
/**
|
||||||
* @brief Assign node ID
|
* @brief Assign node ID
|
||||||
* @param newNodeId New 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);
|
bool transportAssignNodeID(const uint8_t newNodeId);
|
||||||
/**
|
/**
|
||||||
@@ -409,7 +409,7 @@ void transportInitialize(void);
|
|||||||
void transportProcess(void);
|
void transportProcess(void);
|
||||||
/**
|
/**
|
||||||
* @brief Flag transport ready
|
* @brief Flag transport ready
|
||||||
* @return true if transport is initialize and ready
|
* @return true if transport is initialized and ready
|
||||||
*/
|
*/
|
||||||
bool isTransportReady(void);
|
bool isTransportReady(void);
|
||||||
/**
|
/**
|
||||||
@@ -462,51 +462,6 @@ void transportSetRoute(const uint8_t node, const uint8_t route);
|
|||||||
* @return route to node
|
* @return route to node
|
||||||
*/
|
*/
|
||||||
uint8_t transportGetRoute(const uint8_t node);
|
uint8_t transportGetRoute(const uint8_t node);
|
||||||
|
|
||||||
|
|
||||||
// interface functions for radio driver
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialize transport HW
|
|
||||||
* @return true if initialization successful
|
|
||||||
*/
|
|
||||||
bool transportInit();
|
|
||||||
/**
|
|
||||||
* @brief Set node address
|
|
||||||
*/
|
|
||||||
void transportSetAddress(uint8_t address);
|
|
||||||
/**
|
|
||||||
* @brief Retrieve node address
|
|
||||||
*/
|
|
||||||
uint8_t transportGetAddress();
|
|
||||||
/**
|
|
||||||
* @brief Send message
|
|
||||||
* @param to recipient
|
|
||||||
* @param data message to be sent
|
|
||||||
* @param len length of message (header + payload)
|
|
||||||
* @return true if message sent successfully
|
|
||||||
*/
|
|
||||||
bool transportSend(uint8_t to, const void* data, uint8_t len);
|
|
||||||
/**
|
|
||||||
* @brief Verify if RX FIFO has pending messages
|
|
||||||
* @return true if message available in RX FIFO
|
|
||||||
*/
|
|
||||||
bool transportAvailable();
|
|
||||||
/**
|
|
||||||
* @brief Sanity check for transport: is transport still responsive?
|
|
||||||
* @return true transport ok
|
|
||||||
*/
|
|
||||||
bool transportSanityCheck();
|
|
||||||
/**
|
|
||||||
* @brief Receive message from FIFO
|
|
||||||
* @return length of recevied message (header + payload)
|
|
||||||
*/
|
|
||||||
uint8_t transportReceive(void* data);
|
|
||||||
/**
|
|
||||||
* @brief Power down transport HW
|
|
||||||
*/
|
|
||||||
void transportPowerDown();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get node ID
|
* @brief Get node ID
|
||||||
* @return node ID
|
* @return node ID
|
||||||
@@ -523,6 +478,48 @@ uint8_t transportGetParentNodeId(void);
|
|||||||
*/
|
*/
|
||||||
uint8_t transportGetDistanceGW(void);
|
uint8_t transportGetDistanceGW(void);
|
||||||
|
|
||||||
|
// interface functions for radio driver
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize transport HW
|
||||||
|
* @return true if initialization successful
|
||||||
|
*/
|
||||||
|
bool transportInit(void);
|
||||||
|
/**
|
||||||
|
* @brief Set node address
|
||||||
|
*/
|
||||||
|
void transportSetAddress(const uint8_t address);
|
||||||
|
/**
|
||||||
|
* @brief Retrieve node address
|
||||||
|
*/
|
||||||
|
uint8_t transportGetAddress(void);
|
||||||
|
/**
|
||||||
|
* @brief Send message
|
||||||
|
* @param to recipient
|
||||||
|
* @param data message to be sent
|
||||||
|
* @param len length of message (header + payload)
|
||||||
|
* @return true if message sent successfully
|
||||||
|
*/
|
||||||
|
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(void);
|
||||||
|
/**
|
||||||
|
* @brief Sanity check for transport: is transport still responsive?
|
||||||
|
* @return true if transport HW is ok
|
||||||
|
*/
|
||||||
|
bool transportSanityCheck(void);
|
||||||
|
/**
|
||||||
|
* @brief Receive message from FIFO
|
||||||
|
* @return length of recevied message (header + payload)
|
||||||
|
*/
|
||||||
|
uint8_t transportReceive(void* data);
|
||||||
|
/**
|
||||||
|
* @brief Power down transport HW
|
||||||
|
*/
|
||||||
|
void transportPowerDown(void);
|
||||||
|
|
||||||
#endif // MyTransport_h
|
#endif // MyTransport_h
|
||||||
/** @}*/
|
/** @}*/
|
||||||
|
|||||||
@@ -94,19 +94,19 @@ uint8_t transportGetAddress(void)
|
|||||||
return RF24_getNodeID();
|
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)
|
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||||
// copy input data because it is read-only
|
// copy input data because it is read-only
|
||||||
(void)memcpy(_dataenc,data,len);
|
(void)memcpy(_dataenc,data,len);
|
||||||
// has to be adjusted, WIP!
|
// has to be adjusted, WIP!
|
||||||
_aes.set_IV(0);
|
_aes.set_IV(0);
|
||||||
len = len > 16 ? 32 : 16;
|
const uint8_t finalLength = len > 16 ? 32 : 16;
|
||||||
//encrypt data
|
//encrypt data
|
||||||
_aes.cbc_encrypt(_dataenc, _dataenc, len/16);
|
_aes.cbc_encrypt(_dataenc, _dataenc, finalLength /16);
|
||||||
return RF24_sendMessage(recipient, _dataenc, len);
|
return RF24_sendMessage(to, _dataenc, finalLength);
|
||||||
#else
|
#else
|
||||||
return RF24_sendMessage(recipient, data, len);
|
return RF24_sendMessage(to, data, len);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_RFM69HW, MY_RF69_IRQ_NUM);
|
|||||||
uint8_t _address;
|
uint8_t _address;
|
||||||
|
|
||||||
|
|
||||||
bool transportInit()
|
bool transportInit(void)
|
||||||
{
|
{
|
||||||
// Start up the radio library (_address will be set later by the MySensors library)
|
// Start up the radio library (_address will be set later by the MySensors library)
|
||||||
if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) {
|
if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) {
|
||||||
@@ -41,28 +41,28 @@ bool transportInit()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportSetAddress(uint8_t address)
|
void transportSetAddress(const uint8_t address)
|
||||||
{
|
{
|
||||||
_address = address;
|
_address = address;
|
||||||
_radio.setAddress(address);
|
_radio.setAddress(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t transportGetAddress()
|
uint8_t transportGetAddress(void)
|
||||||
{
|
{
|
||||||
return _address;
|
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);
|
return _radio.sendWithRetry(to,data,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool transportAvailable()
|
bool transportAvailable(void)
|
||||||
{
|
{
|
||||||
return _radio.receiveDone();
|
return _radio.receiveDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool transportSanityCheck()
|
bool transportSanityCheck(void)
|
||||||
{
|
{
|
||||||
// not implemented yet
|
// not implemented yet
|
||||||
return true;
|
return true;
|
||||||
@@ -80,7 +80,7 @@ uint8_t transportReceive(void* data)
|
|||||||
return dataLen;
|
return dataLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportPowerDown()
|
void transportPowerDown(void)
|
||||||
{
|
{
|
||||||
_radio.sleep();
|
_radio.sleep();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ bool transportInit(void)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportSetAddress(uint8_t address)
|
void transportSetAddress(const uint8_t address)
|
||||||
{
|
{
|
||||||
RFM95_setAddress(address);
|
RFM95_setAddress(address);
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ uint8_t transportGetAddress(void)
|
|||||||
return RFM95_getAddress();
|
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);
|
return RFM95_sendWithRetry(to, data, len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ bool _serialProcess()
|
|||||||
return true;
|
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<char const *>(data);
|
const char *datap = static_cast<char const *>(data);
|
||||||
unsigned char i;
|
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
|
// Reset the state machine
|
||||||
_dev.begin(MY_RS485_BAUD_RATE);
|
_dev.begin(MY_RS485_BAUD_RATE);
|
||||||
@@ -331,24 +331,24 @@ bool transportInit()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportSetAddress(uint8_t address)
|
void transportSetAddress(const uint8_t address)
|
||||||
{
|
{
|
||||||
_nodeId = address;
|
_nodeId = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t transportGetAddress()
|
uint8_t transportGetAddress(void)
|
||||||
{
|
{
|
||||||
return _nodeId;
|
return _nodeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool transportAvailable()
|
bool transportAvailable(void)
|
||||||
{
|
{
|
||||||
_serialProcess();
|
_serialProcess();
|
||||||
return _packet_received;
|
return _packet_received;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool transportSanityCheck()
|
bool transportSanityCheck(void)
|
||||||
{
|
{
|
||||||
// not implemented yet
|
// not implemented yet
|
||||||
return true;
|
return true;
|
||||||
@@ -365,7 +365,7 @@ uint8_t transportReceive(void* data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportPowerDown()
|
void transportPowerDown(void)
|
||||||
{
|
{
|
||||||
// Nothing to shut down here
|
// Nothing to shut down here
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user