@@ -100,6 +100,7 @@ static int Phy_GetPhyId(luos_phy_t *phy_ptr);
100
100
static bool Phy_IndexFilter (uint8_t * index , uint16_t id );
101
101
static bool Phy_Need (luos_phy_t * phy_ptr , header_t * header );
102
102
static phy_target_t Phy_ComputeTargets (luos_phy_t * phy_ptr , header_t * header );
103
+ static void Phy_IndexRm (uint8_t * index , uint16_t id );
103
104
104
105
/*******************************************************************************
105
106
* Variables
@@ -527,7 +528,7 @@ bool Phy_Need(luos_phy_t *phy_ptr, header_t *header)
527
528
// To avoid to spend precious computing time, instead of checking all the phy we will only check if this concern only the receiving phy.
528
529
// We need to keep this message only if the message target is not only for the phy_ptr, except if it is Luos because Luos can do localhost.
529
530
530
- // If this phy is Luos phy, we need to keep all the messages
531
+ // If this phy is Luos phy, we need to keep all the messages no matter what.
531
532
if (Phy_GetPhyId (phy_ptr ) == 0 )
532
533
{
533
534
return true;
@@ -543,19 +544,27 @@ bool Phy_Need(luos_phy_t *phy_ptr, header_t *header)
543
544
break ;
544
545
case SERVICEIDACK :
545
546
case SERVICEID :
546
- // If the target is not the phy_ptr, we need to keep this message
547
- return !Phy_IndexFilter (phy_ptr -> services , header -> target );
547
+ // If the target is not the phy_ptr, and the source service is known, we need to keep this message
548
+ return ( !Phy_IndexFilter (phy_ptr -> services , header -> target )) && ( Phy_IndexFilter ( phy_ptr -> services , header -> source ) );
548
549
break ;
549
550
case NODEIDACK :
550
551
case NODEID :
551
552
if (header -> target == 0 )
552
553
{
553
- return Node_DoWeWaitId () || (phy_ctx .PhyExeptSourceDone == false); // or we are waiting for child branches ((phy_ctx.topology_running == true) && (header->source == 1))
554
+ return Node_DoWeWaitId () || (phy_ctx .PhyExeptSourceDone == false);
554
555
}
555
556
else
556
557
{
557
- // If the target is not for the receiving phy, we need to keep this message
558
- return (!Phy_IndexFilter (phy_ptr -> nodes , header -> target ) && (Node_Get ()-> node_id != 0 ));
558
+ if (Luos_IsDetected ())
559
+ {
560
+ // If the target is not for the receiving phy, and the source service is known, we need to keep this message
561
+ return (!Phy_IndexFilter (phy_ptr -> nodes , header -> target ) && (Node_Get ()-> node_id != 0 ) && (Phy_IndexFilter (phy_ptr -> services , header -> source )));
562
+ }
563
+ else
564
+ {
565
+ // If the target is not for the receiving phy, we need to keep this message
566
+ return (!Phy_IndexFilter (phy_ptr -> nodes , header -> target ) && (Node_Get ()-> node_id != 0 ));
567
+ }
559
568
}
560
569
break ;
561
570
default :
@@ -1199,8 +1208,8 @@ void Phy_AddLocalServices(uint16_t service_id, uint16_t service_number)
1199
1208
1200
1209
/******************************************************************************
1201
1210
* @brief check if the given id value concern this phy index
1202
- * @param index Pointer to the index of the node
1203
- * @param id id of the service concerned by this message
1211
+ * @param index Pointer to the index of the node or service
1212
+ * @param id id of the node or service concerned by this message
1204
1213
* @return phy concerned by this message
1205
1214
******************************************************************************/
1206
1215
inline bool Phy_IndexFilter (uint8_t * index , uint16_t id )
@@ -1212,8 +1221,8 @@ inline bool Phy_IndexFilter(uint8_t *index, uint16_t id)
1212
1221
1213
1222
/******************************************************************************
1214
1223
* @brief Set a given id value in the index
1215
- * @param index Pointer to the index of the node
1216
- * @param id id of the service concerned by this message
1224
+ * @param index Pointer to the index of the node or service
1225
+ * @param id id of the node or service concerned by this message
1217
1226
* @return phy concerned by this message
1218
1227
******************************************************************************/
1219
1228
inline void Phy_IndexSet (uint8_t * index , uint16_t id )
@@ -1223,6 +1232,49 @@ inline void Phy_IndexSet(uint8_t *index, uint16_t id)
1223
1232
index [bit_index / 8 ] |= 1 << (bit_index % 8 );
1224
1233
}
1225
1234
1235
+ /******************************************************************************
1236
+ * @brief Remove a given id value in the index
1237
+ * @param index Pointer to the index of the node or service
1238
+ * @param id id of the service concerned by this message
1239
+ * @return phy concerned by this message
1240
+ ******************************************************************************/
1241
+ inline void Phy_IndexRm (uint8_t * index , uint16_t id )
1242
+ {
1243
+ LUOS_ASSERT ((index != NULL ) && (id <= 0x0FFF ) && (id != 0 ));
1244
+ uint8_t bit_index = id - 1 ; // Because 1 represent bit index 0.
1245
+ index [bit_index / 8 ] &= ~(1 << (bit_index % 8 ));
1246
+ }
1247
+
1248
+ /******************************************************************************
1249
+ * @brief Remove a given service id value in the index of all phys
1250
+ * @param id id of the service concerned by this message
1251
+ * @return phy concerned by this message
1252
+ ******************************************************************************/
1253
+ inline void Phy_ServiceIndexRm (uint16_t id )
1254
+ {
1255
+ LUOS_ASSERT ((id <= 0x0FFF ) && (id != 0 ));
1256
+ // for all phy
1257
+ for (int i = 0 ; i < phy_ctx .phy_nb ; i ++ )
1258
+ {
1259
+ Phy_IndexRm (phy_ctx .phy [i ].services , id );
1260
+ }
1261
+ }
1262
+
1263
+ /******************************************************************************
1264
+ * @brief Remove a given node id value in the index of all phys
1265
+ * @param id id of the node concerned by this message
1266
+ * @return phy concerned by this message
1267
+ ******************************************************************************/
1268
+ inline void Phy_NodeIndexRm (uint16_t id )
1269
+ {
1270
+ LUOS_ASSERT ((id <= 0x0FFF ) && (id != 0 ));
1271
+ // for all phy
1272
+ for (int i = 0 ; i < phy_ctx .phy_nb ; i ++ )
1273
+ {
1274
+ Phy_IndexRm (phy_ctx .phy [i ].nodes , id );
1275
+ }
1276
+ }
1277
+
1226
1278
/******************************************************************************
1227
1279
* @brief Parse all services type to find if target exists
1228
1280
* @param type_id of message
0 commit comments