@@ -98,7 +98,11 @@ void stInitTransition(void)
98
98
void stInitUpdate (void )
99
99
{
100
100
// initialise radio
101
- if (!transportHALInit ()) {
101
+ #if defined(MY_BRIDGE_FEATURE)
102
+ if (!transportInit () || !bridgeTransportHALInit ()) {
103
+ #else
104
+ if (!transportInit ()) {
105
+ #endif
102
106
TRANSPORT_DEBUG (PSTR (" !TSM:INIT:TSP FAIL\n " ));
103
107
setIndication (INDICATION_ERR_INIT_TRANSPORT);
104
108
transportSwitchSM (stFailure);
@@ -438,6 +442,9 @@ void transportReInitialise(void)
438
442
TRANSPORT_DEBUG (PSTR (" TSF:TRI:TPU\n " )); // transport power up
439
443
transportHALPowerUp ();
440
444
transportHALSetAddress (_transportConfig.nodeId );
445
+ #if defined(MY_BRIDGE_FEATURE)
446
+ bridgeTransportHALSetAddress (_transportConfig.nodeId );
447
+ #endif
441
448
} else {
442
449
TRANSPORT_DEBUG (PSTR (" TSF:TRI:TSB\n " )); // transport standby
443
450
transportHALStandBy ();
@@ -499,6 +506,9 @@ bool transportAssignNodeID(const uint8_t newNodeId)
499
506
if (newNodeId != GATEWAY_ADDRESS && newNodeId != AUTO) {
500
507
_transportConfig.nodeId = newNodeId;
501
508
transportHALSetAddress (newNodeId);
509
+ #if defined(MY_BRIDGE_FEATURE)
510
+ bridgeTransportHALSetAddress (newNodeId);
511
+ #endif
502
512
// Write ID to EEPROM
503
513
hwWriteConfig (EEPROM_NODE_ID_ADDRESS, newNodeId);
504
514
TRANSPORT_DEBUG (PSTR (" TSF:SID:OK,ID=%" PRIu8 " \n " ),newNodeId); // Node ID assigned
@@ -513,6 +523,7 @@ bool transportAssignNodeID(const uint8_t newNodeId)
513
523
bool transportRouteMessage (MyMessage &message)
514
524
{
515
525
const uint8_t destination = message.getDestination ();
526
+ bool routeToBridge = false ;
516
527
517
528
if (_transportSM.findingParentNode && destination != BROADCAST_ADDRESS) {
518
529
TRANSPORT_DEBUG (PSTR (" !TSF:RTE:FPAR ACTIVE\n " )); // find parent active, message not sent
@@ -529,7 +540,7 @@ bool transportRouteMessage(MyMessage &message)
529
540
} else {
530
541
#if defined(MY_REPEATER_FEATURE)
531
542
// destination not GW & not BC, get route
532
- route = transportGetRoute (destination);
543
+ route = transportGetRoute (destination, &routeToBridge );
533
544
if (route == AUTO) {
534
545
TRANSPORT_DEBUG (PSTR (" !TSF:RTE:%" PRIu8 " UNKNOWN\n " ), destination); // route unknown
535
546
#if !defined(MY_GATEWAY_FEATURE)
@@ -562,7 +573,7 @@ bool transportRouteMessage(MyMessage &message)
562
573
#endif
563
574
}
564
575
// send message
565
- const bool result = transportSendWrite (route, message);
576
+ const bool result = transportSendWrite (route, message, routeToBridge );
566
577
#if !defined(MY_GATEWAY_FEATURE)
567
578
// update counter
568
579
if (route == _transportConfig.parentNodeId ) {
@@ -647,16 +658,23 @@ uint32_t transportGetHeartbeat(void)
647
658
return transportTimeInState ();
648
659
}
649
660
650
- void transportProcessMessage (void )
661
+ void transportProcessMessage (bool fromBridge )
651
662
{
652
663
// Manage signing timeout
653
664
(void )signerCheckTimer ();
654
665
// receive message
655
666
setIndication (INDICATION_RX);
656
667
uint8_t payloadLength;
657
- // last is the first byte of the payload buffer
658
- if (!transportHALReceive (&_msg, &payloadLength)) {
659
- return ;
668
+ if (fromBridge) {
669
+ #if defined(MY_BRIDGE_FEATURE)
670
+ if (!bridgeTransportHALReceive (&_msg, &payloadLength)) {
671
+ return ;
672
+ }
673
+ #endif
674
+ } else {
675
+ if (!transportHALReceive (&_msg, &payloadLength)) {
676
+ return ;
677
+ }
660
678
}
661
679
// get message length and limit size
662
680
const uint8_t msgLength = _msg.getLength ();
@@ -692,7 +710,7 @@ void transportProcessMessage(void)
692
710
// Message is from one of the child nodes and not sent from this node. Add it to routing table.
693
711
if (sender != _transportConfig.nodeId )
694
712
{
695
- transportSetRoute (sender, last);
713
+ transportSetRoute (sender, last, fromBridge );
696
714
}
697
715
}
698
716
#endif // MY_REPEATER_FEATURE
@@ -950,7 +968,11 @@ void transportInvokeSanityCheck(void)
950
968
{
951
969
// Suppress this because the function may return a variable value in some configurations
952
970
// cppcheck-suppress knownConditionTrueFalse
971
+ #if defined(MY_BRIDGE_FEATURE)
972
+ if (!transportHALSanityCheck () || !bridgeTransportHALSanityCheck ()) {
973
+ #else
953
974
if (!transportHALSanityCheck ()) {
975
+ #endif
954
976
TRANSPORT_DEBUG (PSTR (" !TSF:SAN:FAIL\n " )); // sanity check fail
955
977
transportSwitchSM (stFailure);
956
978
} else {
@@ -975,8 +997,15 @@ void transportProcessFIFO(void)
975
997
uint8_t _processedMessages = MAX_SUBSEQ_MSGS;
976
998
// process all msgs in FIFO or counter exit
977
999
while (transportHALDataAvailable () && _processedMessages--) {
978
- transportProcessMessage ();
1000
+ transportProcessMessage (false );
1001
+ }
1002
+ #if defined(MY_BRIDGE_FEATURE)
1003
+ _processedMessages = MAX_SUBSEQ_MSGS;
1004
+ // process all msgs in FIFO or counter exit
1005
+ while (bridgeTransportHALDataAvailable () && _processedMessages--) {
1006
+ transportProcessMessage (true );
979
1007
}
1008
+ #endif
980
1009
#if defined(MY_OTA_FIRMWARE_FEATURE)
981
1010
if (isTransportReady ()) {
982
1011
// only process if transport ok
@@ -985,7 +1014,7 @@ void transportProcessFIFO(void)
985
1014
#endif
986
1015
}
987
1016
988
- bool transportSendWrite (const uint8_t to, MyMessage &message)
1017
+ bool transportSendWrite (const uint8_t to, MyMessage &message, const bool routeToBridge )
989
1018
{
990
1019
message.setLast (_transportConfig.nodeId ); // Update last
991
1020
@@ -1002,8 +1031,16 @@ bool transportSendWrite(const uint8_t to, MyMessage &message)
1002
1031
const bool noACK = _transportConfig.passiveMode || (to == BROADCAST_ADDRESS);
1003
1032
// send
1004
1033
setIndication (INDICATION_TX);
1005
- const bool result = transportHALSend (to, &message, totalMsgLength,
1006
- noACK);
1034
+ bool result = false ;
1035
+ // if to is BC (AUTO) then send to both transport and bridge transport media
1036
+ #if defined(MY_BRIDGE_FEATURE)
1037
+ if (routeToBridge || to == AUTO) {
1038
+ result = bridgeTransportHALSend (to, &message, totalMsgLength, noACK);
1039
+ }
1040
+ #endif
1041
+ if (!routeToBridge || to == AUTO) {
1042
+ result = transportHALSend (to, &message, totalMsgLength, noACK);
1043
+ }
1007
1044
1008
1045
TRANSPORT_DEBUG (PSTR (" %sTSF:MSG:SEND,%" PRIu8 " -%" PRIu8 " -%" PRIu8 " -%" PRIu8 " ,s=%" PRIu8 " ,c=%"
1009
1046
PRIu8 " ,t=%" PRIu8 " ,pt=%" PRIu8 " ,l=%" PRIu8 " ,sg=%" PRIu8 " ,ft=%" PRIu8 " ,st=%s:%s\n " ),
@@ -1043,7 +1080,7 @@ uint8_t transportGetDistanceGW(void)
1043
1080
void transportClearRoutingTable (void )
1044
1081
{
1045
1082
for (uint16_t i = 0 ; i < SIZE_ROUTES; i++) {
1046
- transportSetRoute ((uint8_t )i, BROADCAST_ADDRESS);
1083
+ transportSetRoute ((uint8_t )i, BROADCAST_ADDRESS, false );
1047
1084
}
1048
1085
transportSaveRoutingTable (); // save cleared routing table to EEPROM (if feature enabled)
1049
1086
TRANSPORT_DEBUG (PSTR (" TSF:CRT:OK\n " )); // clear routing table
@@ -1053,6 +1090,8 @@ void transportLoadRoutingTable(void)
1053
1090
{
1054
1091
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
1055
1092
hwReadConfigBlock ((void *)&_transportRoutingTable.route , (void *)EEPROM_ROUTES_ADDRESS, SIZE_ROUTES);
1093
+ hwReadConfigBlock ((void *)&_transportRoutingTable.bridged , (void *)EEPROM_BRIDGED_ADDRESS,
1094
+ SIZE_ROUTES);
1056
1095
TRANSPORT_DEBUG (PSTR (" TSF:LRT:OK\n " )); // load routing table
1057
1096
#endif
1058
1097
}
@@ -1061,24 +1100,32 @@ void transportSaveRoutingTable(void)
1061
1100
{
1062
1101
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
1063
1102
hwWriteConfigBlock ((void *)&_transportRoutingTable.route , (void *)EEPROM_ROUTES_ADDRESS, SIZE_ROUTES);
1103
+ hwWriteConfigBlock ((void *)&_transportRoutingTable.bridged , (void *)EEPROM_BRIDGED_ADDRESS,
1104
+ SIZE_ROUTES);
1064
1105
TRANSPORT_DEBUG (PSTR (" TSF:SRT:OK\n " )); // save routing table
1065
1106
#endif
1066
1107
}
1067
1108
1068
- void transportSetRoute (const uint8_t node, const uint8_t route)
1109
+ void transportSetRoute (const uint8_t node, const uint8_t route, const bool fromBridge )
1069
1110
{
1070
1111
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
1071
1112
_transportRoutingTable.route [node] = route;
1113
+ _transportRoutingTable.bridged [node] = fromBridge;
1072
1114
#else
1073
1115
hwWriteConfig (EEPROM_ROUTES_ADDRESS + node, route);
1074
1116
#endif
1075
1117
}
1076
1118
1077
- uint8_t transportGetRoute (const uint8_t node)
1119
+ uint8_t transportGetRoute (const uint8_t node, bool * toBridge )
1078
1120
{
1079
1121
uint8_t result;
1080
1122
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
1081
1123
result = _transportRoutingTable.route [node];
1124
+ #if defined(MY_BRIDGE_FEATURE)
1125
+ *toBridge = _transportRoutingTable.bridged [node];
1126
+ #else
1127
+ *toBridge = false ;
1128
+ #endif
1082
1129
#else
1083
1130
result = hwReadConfig (EEPROM_ROUTES_ADDRESS + node);
1084
1131
#endif
@@ -1089,7 +1136,8 @@ void transportReportRoutingTable(void)
1089
1136
{
1090
1137
#if defined(MY_REPEATER_FEATURE)
1091
1138
for (uint16_t cnt = 0 ; cnt < SIZE_ROUTES; cnt++) {
1092
- const uint8_t route = transportGetRoute (cnt);
1139
+ bool toBridge;
1140
+ const uint8_t route = transportGetRoute ((uint8_t )cnt, &toBridge);
1093
1141
if (route != BROADCAST_ADDRESS) {
1094
1142
TRANSPORT_DEBUG (PSTR (" TSF:RRT:ROUTE N=%" PRIu8 " ,R=%" PRIu8 " \n " ), cnt, route);
1095
1143
uint8_t outBuf[2 ] = { (uint8_t )cnt,route };
0 commit comments