Harmonize transport code (#710)

This commit is contained in:
Olivier
2016-12-29 14:50:12 +01:00
committed by Henrik Ekblad
parent 01711becd1
commit 8fabae979a
5 changed files with 67 additions and 70 deletions
+46 -49
View File
@@ -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,51 +462,6 @@ void transportSetRoute(const uint8_t node, const uint8_t route);
* @return route to 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
* @return node ID
@@ -523,6 +478,48 @@ uint8_t transportGetParentNodeId(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
/** @}*/
+5 -5
View File
@@ -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
}
+7 -7
View File
@@ -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();
}
+2 -2
View File
@@ -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);
}
+7 -7
View File
@@ -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<char const *>(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
}