Skip to content

Commit 8fabae9

Browse files
tekka007henrikekblad
authored andcommitted
Harmonize transport code (#710)
1 parent 01711be commit 8fabae9

File tree

5 files changed

+48
-51
lines changed

5 files changed

+48
-51
lines changed

core/MyTransport.h

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ typedef struct {
269269
// PRIVATE functions
270270

271271
/**
272-
* @brief Initialise SM variables and transport HW
272+
* @brief Initialize SM variables and transport HW
273273
*/
274274
void stInitTransition(void);
275275
/**
276-
* @brief Initialise transport
276+
* @brief Initialize transport
277277
*/
278278
void stInitUpdate(void);
279279
/**
@@ -345,7 +345,7 @@ void transportProcessMessage(void);
345345
/**
346346
* @brief Assign node ID
347347
* @param newNodeId New node ID
348-
* @return true if node ID valid and successfully assigned
348+
* @return true if node ID is valid and successfully assigned
349349
*/
350350
bool transportAssignNodeID(const uint8_t newNodeId);
351351
/**
@@ -409,7 +409,7 @@ void transportInitialize(void);
409409
void transportProcess(void);
410410
/**
411411
* @brief Flag transport ready
412-
* @return true if transport is initialize and ready
412+
* @return true if transport is initialized and ready
413413
*/
414414
bool isTransportReady(void);
415415
/**
@@ -462,41 +462,55 @@ void transportSetRoute(const uint8_t node, const uint8_t route);
462462
* @return route to node
463463
*/
464464
uint8_t transportGetRoute(const uint8_t node);
465-
465+
/**
466+
* @brief Get node ID
467+
* @return node ID
468+
*/
469+
uint8_t transportGetNodeId(void);
470+
/**
471+
* @brief Get parent node ID
472+
* @return parent node ID
473+
*/
474+
uint8_t transportGetParentNodeId(void);
475+
/**
476+
* @brief Get distance to GW
477+
* @return distance (=hops) to GW
478+
*/
479+
uint8_t transportGetDistanceGW(void);
466480

467481
// interface functions for radio driver
468482

469483
/**
470484
* @brief Initialize transport HW
471485
* @return true if initialization successful
472486
*/
473-
bool transportInit();
487+
bool transportInit(void);
474488
/**
475489
* @brief Set node address
476490
*/
477-
void transportSetAddress(uint8_t address);
491+
void transportSetAddress(const uint8_t address);
478492
/**
479493
* @brief Retrieve node address
480494
*/
481-
uint8_t transportGetAddress();
495+
uint8_t transportGetAddress(void);
482496
/**
483497
* @brief Send message
484498
* @param to recipient
485499
* @param data message to be sent
486500
* @param len length of message (header + payload)
487501
* @return true if message sent successfully
488502
*/
489-
bool transportSend(uint8_t to, const void* data, uint8_t len);
503+
bool transportSend(const uint8_t to, const void* data, const uint8_t len);
490504
/**
491505
* @brief Verify if RX FIFO has pending messages
492506
* @return true if message available in RX FIFO
493507
*/
494-
bool transportAvailable();
508+
bool transportAvailable(void);
495509
/**
496510
* @brief Sanity check for transport: is transport still responsive?
497-
* @return true transport ok
511+
* @return true if transport HW is ok
498512
*/
499-
bool transportSanityCheck();
513+
bool transportSanityCheck(void);
500514
/**
501515
* @brief Receive message from FIFO
502516
* @return length of recevied message (header + payload)
@@ -505,24 +519,7 @@ uint8_t transportReceive(void* data);
505519
/**
506520
* @brief Power down transport HW
507521
*/
508-
void transportPowerDown();
509-
510-
/**
511-
* @brief Get node ID
512-
* @return node ID
513-
*/
514-
uint8_t transportGetNodeId(void);
515-
/**
516-
* @brief Get parent node ID
517-
* @return parent node ID
518-
*/
519-
uint8_t transportGetParentNodeId(void);
520-
/**
521-
* @brief Get distance to GW
522-
* @return distance (=hops) to GW
523-
*/
524-
uint8_t transportGetDistanceGW(void);
525-
522+
void transportPowerDown(void);
526523

527524
#endif // MyTransport_h
528525
/** @}*/

core/MyTransportNRF24.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ uint8_t transportGetAddress(void)
9494
return RF24_getNodeID();
9595
}
9696

97-
bool transportSend(const uint8_t recipient, const void* data, uint8_t len)
97+
bool transportSend(const uint8_t to, const void* data, const uint8_t len)
9898
{
9999
#if defined(MY_RF24_ENABLE_ENCRYPTION)
100100
// copy input data because it is read-only
101101
(void)memcpy(_dataenc,data,len);
102102
// has to be adjusted, WIP!
103103
_aes.set_IV(0);
104-
len = len > 16 ? 32 : 16;
104+
const uint8_t finalLength = len > 16 ? 32 : 16;
105105
//encrypt data
106-
_aes.cbc_encrypt(_dataenc, _dataenc, len/16);
107-
return RF24_sendMessage(recipient, _dataenc, len);
106+
_aes.cbc_encrypt(_dataenc, _dataenc, finalLength /16);
107+
return RF24_sendMessage(to, _dataenc, finalLength);
108108
#else
109-
return RF24_sendMessage(recipient, data, len);
109+
return RF24_sendMessage(to, data, len);
110110
#endif
111111
}
112112

core/MyTransportRFM69.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_RFM69HW, MY_RF69_IRQ_NUM);
2626
uint8_t _address;
2727

2828

29-
bool transportInit()
29+
bool transportInit(void)
3030
{
3131
// Start up the radio library (_address will be set later by the MySensors library)
3232
if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) {
@@ -41,28 +41,28 @@ bool transportInit()
4141
return false;
4242
}
4343

44-
void transportSetAddress(uint8_t address)
44+
void transportSetAddress(const uint8_t address)
4545
{
4646
_address = address;
4747
_radio.setAddress(address);
4848
}
4949

50-
uint8_t transportGetAddress()
50+
uint8_t transportGetAddress(void)
5151
{
5252
return _address;
5353
}
5454

55-
bool transportSend(uint8_t to, const void* data, uint8_t len)
55+
bool transportSend(const uint8_t to, const void* data, const uint8_t len)
5656
{
5757
return _radio.sendWithRetry(to,data,len);
5858
}
5959

60-
bool transportAvailable()
60+
bool transportAvailable(void)
6161
{
6262
return _radio.receiveDone();
6363
}
6464

65-
bool transportSanityCheck()
65+
bool transportSanityCheck(void)
6666
{
6767
// not implemented yet
6868
return true;
@@ -80,7 +80,7 @@ uint8_t transportReceive(void* data)
8080
return dataLen;
8181
}
8282

83-
void transportPowerDown()
83+
void transportPowerDown(void)
8484
{
8585
_radio.sleep();
8686
}

core/MyTransportRFM95.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool transportInit(void)
3232
return result;
3333
}
3434

35-
void transportSetAddress(uint8_t address)
35+
void transportSetAddress(const uint8_t address)
3636
{
3737
RFM95_setAddress(address);
3838
}
@@ -42,7 +42,7 @@ uint8_t transportGetAddress(void)
4242
return RFM95_getAddress();
4343
}
4444

45-
bool transportSend(uint8_t to, const void* data, uint8_t len)
45+
bool transportSend(const uint8_t to, const void* data, const uint8_t len)
4646
{
4747
return RFM95_sendWithRetry(to, data, len);
4848
}

core/MyTransportRS485.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ bool _serialProcess()
239239
return true;
240240
}
241241

242-
bool transportSend(uint8_t to, const void* data, uint8_t len)
242+
bool transportSend(const uint8_t to, const void* data, const uint8_t len)
243243
{
244244
const char *datap = static_cast<char const *>(data);
245245
unsigned char i;
@@ -319,7 +319,7 @@ bool transportSend(uint8_t to, const void* data, uint8_t len)
319319

320320

321321

322-
bool transportInit()
322+
bool transportInit(void)
323323
{
324324
// Reset the state machine
325325
_dev.begin(MY_RS485_BAUD_RATE);
@@ -331,24 +331,24 @@ bool transportInit()
331331
return true;
332332
}
333333

334-
void transportSetAddress(uint8_t address)
334+
void transportSetAddress(const uint8_t address)
335335
{
336336
_nodeId = address;
337337
}
338338

339-
uint8_t transportGetAddress()
339+
uint8_t transportGetAddress(void)
340340
{
341341
return _nodeId;
342342
}
343343

344344

345-
bool transportAvailable()
345+
bool transportAvailable(void)
346346
{
347347
_serialProcess();
348348
return _packet_received;
349349
}
350350

351-
bool transportSanityCheck()
351+
bool transportSanityCheck(void)
352352
{
353353
// not implemented yet
354354
return true;
@@ -365,7 +365,7 @@ uint8_t transportReceive(void* data)
365365
}
366366
}
367367

368-
void transportPowerDown()
368+
void transportPowerDown(void)
369369
{
370370
// Nothing to shut down here
371371
}

0 commit comments

Comments
 (0)