@@ -1280,8 +1280,9 @@ static canard_tree_t* rx_session_factory(void* const user)
12801280 FOREACH_SLOT (i ) {
12811281 ses -> slots [i ] = NULL ;
12821282 }
1283- ses -> owner = ctx -> owner ;
1284- ses -> node_id = ctx -> node_id ;
1283+ ses -> last_admitted_start_ts = BIG_BANG ;
1284+ ses -> owner = ctx -> owner ;
1285+ ses -> node_id = ctx -> node_id ;
12851286 enlist_tail (& ctx -> owner -> owner -> rx .list_session_by_animation , & ses -> list_animation );
12861287 return & ses -> index ;
12871288}
@@ -1356,16 +1357,15 @@ static bool rx_session_update(canard_subscription_t* const sub,
13561357
13571358 // Frame admittance state machine. A highly complex piece, redesigned after v4 to support priority preemption.
13581359 // TID forward difference illustration: f(2,3)==31, f(2,2)==0, f(2,1)==1
1359- const bool tid_new = rx_transfer_id_forward_difference (ses -> last_admitted_transfer_id , frame -> transfer_id ) > 1 ;
1360- const canard_us_t timed_out = (ts - ses -> last_admitted_start_ts ) > ses -> owner -> transfer_id_timeout ;
1361- bool accept = false;
1360+ const bool tid_new = rx_transfer_id_forward_difference (ses -> last_admitted_transfer_id , frame -> transfer_id ) > 1 ;
1361+ const bool timed_out = ts > (ses -> last_admitted_start_ts + ses -> owner -> transfer_id_timeout );
1362+ bool accept = false;
1363+ const rx_slot_t * const slot = ses -> slots [frame -> priority ];
13621364 if (!frame -> start ) {
1363- const rx_slot_t * const slot = ses -> slots [frame -> priority ];
13641365 accept = (slot != NULL ) && (slot -> transfer_id == frame -> transfer_id ) && (slot -> iface_index == iface_index ) &&
13651366 (slot -> expected_toggle == frame -> toggle );
13661367 } else {
1367- const rx_slot_t * const slot = ses -> slots [frame -> priority ];
1368- accept = (slot == NULL ) || (slot -> transfer_id != frame -> transfer_id ) || tid_new || timed_out ; // --
1368+ accept = ((slot == NULL ) || (slot -> transfer_id != frame -> transfer_id )) && (tid_new || timed_out );
13691369 }
13701370 if (!accept ) {
13711371 return true; // Frame not needed; not a failure to accept.
@@ -1374,8 +1374,6 @@ static bool rx_session_update(canard_subscription_t* const sub,
13741374 // The frame must be accepted. If this is the start of a new transfer, we must update state.
13751375 enlist_tail (& sub -> owner -> rx .list_session_by_animation , & ses -> list_animation );
13761376 if (frame -> start ) {
1377- ses -> last_admitted_start_ts = ts ;
1378- ses -> last_admitted_transfer_id = frame -> transfer_id ;
13791377 rx_slot_destroy (sub , ses -> slots [frame -> priority ]);
13801378 ses -> slots [frame -> priority ] = NULL ;
13811379 if (!frame -> end ) { // more frames to follow, must store in-progress state
@@ -1385,6 +1383,8 @@ static bool rx_session_update(canard_subscription_t* const sub,
13851383 return false;
13861384 }
13871385 }
1386+ ses -> last_admitted_start_ts = ts ;
1387+ ses -> last_admitted_transfer_id = frame -> transfer_id ;
13881388 }
13891389
13901390 // TODO acceptance
0 commit comments