@@ -98,7 +98,11 @@ void stInitTransition(void)
9898void stInitUpdate (void )
9999{
100100 // initialise radio
101- if (!transportHALInit ()) {
101+ #if defined(MY_BRIDGE_FEATURE)
102+ if (!transportInit () || !bridgeTransportHALInit ()) {
103+ #else
104+ if (!transportInit ()) {
105+ #endif
102106 TRANSPORT_DEBUG (PSTR (" !TSM:INIT:TSP FAIL\n " ));
103107 setIndication (INDICATION_ERR_INIT_TRANSPORT);
104108 transportSwitchSM (stFailure);
@@ -438,6 +442,9 @@ void transportReInitialise(void)
438442 TRANSPORT_DEBUG (PSTR (" TSF:TRI:TPU\n " )); // transport power up
439443 transportHALPowerUp ();
440444 transportHALSetAddress (_transportConfig.nodeId );
445+ #if defined(MY_BRIDGE_FEATURE)
446+ bridgeTransportHALSetAddress (_transportConfig.nodeId );
447+ #endif
441448 } else {
442449 TRANSPORT_DEBUG (PSTR (" TSF:TRI:TSB\n " )); // transport standby
443450 transportHALStandBy ();
@@ -499,6 +506,9 @@ bool transportAssignNodeID(const uint8_t newNodeId)
499506 if (newNodeId != GATEWAY_ADDRESS && newNodeId != AUTO) {
500507 _transportConfig.nodeId = newNodeId;
501508 transportHALSetAddress (newNodeId);
509+ #if defined(MY_BRIDGE_FEATURE)
510+ bridgeTransportHALSetAddress (newNodeId);
511+ #endif
502512 // Write ID to EEPROM
503513 hwWriteConfig (EEPROM_NODE_ID_ADDRESS, newNodeId);
504514 TRANSPORT_DEBUG (PSTR (" TSF:SID:OK,ID=%" PRIu8 " \n " ),newNodeId); // Node ID assigned
@@ -513,6 +523,7 @@ bool transportAssignNodeID(const uint8_t newNodeId)
513523bool transportRouteMessage (MyMessage &message)
514524{
515525 const uint8_t destination = message.getDestination ();
526+ bool routeToBridge = false ;
516527
517528 if (_transportSM.findingParentNode && destination != BROADCAST_ADDRESS) {
518529 TRANSPORT_DEBUG (PSTR (" !TSF:RTE:FPAR ACTIVE\n " )); // find parent active, message not sent
@@ -529,7 +540,7 @@ bool transportRouteMessage(MyMessage &message)
529540 } else {
530541#if defined(MY_REPEATER_FEATURE)
531542 // destination not GW & not BC, get route
532- route = transportGetRoute (destination);
543+ route = transportGetRoute (destination, &routeToBridge );
533544 if (route == AUTO) {
534545 TRANSPORT_DEBUG (PSTR (" !TSF:RTE:%" PRIu8 " UNKNOWN\n " ), destination); // route unknown
535546#if !defined(MY_GATEWAY_FEATURE)
@@ -562,7 +573,7 @@ bool transportRouteMessage(MyMessage &message)
562573#endif
563574 }
564575 // send message
565- const bool result = transportSendWrite (route, message);
576+ const bool result = transportSendWrite (route, message, routeToBridge );
566577#if !defined(MY_GATEWAY_FEATURE)
567578 // update counter
568579 if (route == _transportConfig.parentNodeId ) {
@@ -647,16 +658,23 @@ uint32_t transportGetHeartbeat(void)
647658 return transportTimeInState ();
648659}
649660
650- void transportProcessMessage (void )
661+ void transportProcessMessage (bool fromBridge )
651662{
652663 // Manage signing timeout
653664 (void )signerCheckTimer ();
654665 // receive message
655666 setIndication (INDICATION_RX);
656667 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+ }
660678 }
661679 // get message length and limit size
662680 const uint8_t msgLength = _msg.getLength ();
@@ -692,7 +710,7 @@ void transportProcessMessage(void)
692710 // Message is from one of the child nodes and not sent from this node. Add it to routing table.
693711 if (sender != _transportConfig.nodeId )
694712 {
695- transportSetRoute (sender, last);
713+ transportSetRoute (sender, last, fromBridge );
696714 }
697715 }
698716#endif // MY_REPEATER_FEATURE
@@ -950,7 +968,11 @@ void transportInvokeSanityCheck(void)
950968{
951969 // Suppress this because the function may return a variable value in some configurations
952970 // cppcheck-suppress knownConditionTrueFalse
971+ #if defined(MY_BRIDGE_FEATURE)
972+ if (!transportHALSanityCheck () || !bridgeTransportHALSanityCheck ()) {
973+ #else
953974 if (!transportHALSanityCheck ()) {
975+ #endif
954976 TRANSPORT_DEBUG (PSTR (" !TSF:SAN:FAIL\n " )); // sanity check fail
955977 transportSwitchSM (stFailure);
956978 } else {
@@ -975,8 +997,15 @@ void transportProcessFIFO(void)
975997 uint8_t _processedMessages = MAX_SUBSEQ_MSGS;
976998 // process all msgs in FIFO or counter exit
977999 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 );
9791007 }
1008+ #endif
9801009#if defined(MY_OTA_FIRMWARE_FEATURE)
9811010 if (isTransportReady ()) {
9821011 // only process if transport ok
@@ -985,7 +1014,7 @@ void transportProcessFIFO(void)
9851014#endif
9861015}
9871016
988- bool transportSendWrite (const uint8_t to, MyMessage &message)
1017+ bool transportSendWrite (const uint8_t to, MyMessage &message, const bool routeToBridge )
9891018{
9901019 message.setLast (_transportConfig.nodeId ); // Update last
9911020
@@ -1002,8 +1031,16 @@ bool transportSendWrite(const uint8_t to, MyMessage &message)
10021031 const bool noACK = _transportConfig.passiveMode || (to == BROADCAST_ADDRESS);
10031032 // send
10041033 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+ }
10071044
10081045 TRANSPORT_DEBUG (PSTR (" %sTSF:MSG:SEND,%" PRIu8 " -%" PRIu8 " -%" PRIu8 " -%" PRIu8 " ,s=%" PRIu8 " ,c=%"
10091046 PRIu8 " ,t=%" PRIu8 " ,pt=%" PRIu8 " ,l=%" PRIu8 " ,sg=%" PRIu8 " ,ft=%" PRIu8 " ,st=%s:%s\n " ),
@@ -1043,7 +1080,7 @@ uint8_t transportGetDistanceGW(void)
10431080void transportClearRoutingTable (void )
10441081{
10451082 for (uint16_t i = 0 ; i < SIZE_ROUTES; i++) {
1046- transportSetRoute ((uint8_t )i, BROADCAST_ADDRESS);
1083+ transportSetRoute ((uint8_t )i, BROADCAST_ADDRESS, false );
10471084 }
10481085 transportSaveRoutingTable (); // save cleared routing table to EEPROM (if feature enabled)
10491086 TRANSPORT_DEBUG (PSTR (" TSF:CRT:OK\n " )); // clear routing table
@@ -1053,6 +1090,8 @@ void transportLoadRoutingTable(void)
10531090{
10541091#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
10551092 hwReadConfigBlock ((void *)&_transportRoutingTable.route , (void *)EEPROM_ROUTES_ADDRESS, SIZE_ROUTES);
1093+ hwReadConfigBlock ((void *)&_transportRoutingTable.bridged , (void *)EEPROM_BRIDGED_ADDRESS,
1094+ SIZE_ROUTES);
10561095 TRANSPORT_DEBUG (PSTR (" TSF:LRT:OK\n " )); // load routing table
10571096#endif
10581097}
@@ -1061,24 +1100,32 @@ void transportSaveRoutingTable(void)
10611100{
10621101#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
10631102 hwWriteConfigBlock ((void *)&_transportRoutingTable.route , (void *)EEPROM_ROUTES_ADDRESS, SIZE_ROUTES);
1103+ hwWriteConfigBlock ((void *)&_transportRoutingTable.bridged , (void *)EEPROM_BRIDGED_ADDRESS,
1104+ SIZE_ROUTES);
10641105 TRANSPORT_DEBUG (PSTR (" TSF:SRT:OK\n " )); // save routing table
10651106#endif
10661107}
10671108
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 )
10691110{
10701111#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
10711112 _transportRoutingTable.route [node] = route;
1113+ _transportRoutingTable.bridged [node] = fromBridge;
10721114#else
10731115 hwWriteConfig (EEPROM_ROUTES_ADDRESS + node, route);
10741116#endif
10751117}
10761118
1077- uint8_t transportGetRoute (const uint8_t node)
1119+ uint8_t transportGetRoute (const uint8_t node, bool * toBridge )
10781120{
10791121 uint8_t result;
10801122#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
10811123 result = _transportRoutingTable.route [node];
1124+ #if defined(MY_BRIDGE_FEATURE)
1125+ *toBridge = _transportRoutingTable.bridged [node];
1126+ #else
1127+ *toBridge = false ;
1128+ #endif
10821129#else
10831130 result = hwReadConfig (EEPROM_ROUTES_ADDRESS + node);
10841131#endif
@@ -1089,7 +1136,8 @@ void transportReportRoutingTable(void)
10891136{
10901137#if defined(MY_REPEATER_FEATURE)
10911138 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);
10931141 if (route != BROADCAST_ADDRESS) {
10941142 TRANSPORT_DEBUG (PSTR (" TSF:RRT:ROUTE N=%" PRIu8 " ,R=%" PRIu8 " \n " ), cnt, route);
10951143 uint8_t outBuf[2 ] = { (uint8_t )cnt,route };
0 commit comments