Skip to content

Commit

Permalink
Harmonize transport code (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
tekka007 authored and henrikekblad committed Dec 29, 2016
1 parent 01711be commit 8fabae9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 51 deletions.
57 changes: 27 additions & 30 deletions core/MyTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/**
Expand Down Expand Up @@ -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);
/**
Expand Down Expand Up @@ -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);
/**
Expand Down Expand Up @@ -462,41 +462,55 @@ 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

/**
* @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
* @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);
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)
Expand All @@ -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
/** @}*/
10 changes: 5 additions & 5 deletions core/MyTransportNRF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions core/MyTransportRFM69.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -80,7 +80,7 @@ uint8_t transportReceive(void* data)
return dataLen;
}

void transportPowerDown()
void transportPowerDown(void)
{
_radio.sleep();
}
4 changes: 2 additions & 2 deletions core/MyTransportRFM95.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool transportInit(void)
return result;
}

void transportSetAddress(uint8_t address)
void transportSetAddress(const uint8_t address)
{
RFM95_setAddress(address);
}
Expand All @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions core/MyTransportRS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -365,7 +365,7 @@ uint8_t transportReceive(void* data)
}
}

void transportPowerDown()
void transportPowerDown(void)
{
// Nothing to shut down here
}

0 comments on commit 8fabae9

Please sign in to comment.