Skip to content

Commit e1adb79

Browse files
wip
1 parent 599b721 commit e1adb79

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ Keep code compact and add brief comments before non-obvious logic.
1919

2020
Treat warnings as errors and keep compatibility with strict warning flags.
2121

22+
**FORCE PUSH MUST NEVER BE USED**. The git history is sacrosanct and must not be rewritten. If you need to undo a change, make a new commit.
23+
2224
For agent-authored commits, set `GIT_AUTHOR_NAME="Agent"` and `GIT_COMMITTER_NAME="Agent"`.
2325

24-
**FORCE PUSH MUST NEVER BE USED**. The git history is sacrosanct and must not be rewritten. If you need to undo a change, make a new commit.
26+
The build system will reject code that is not clang-formatted; use build target `format` to invoke clang-format.
2527

2628
## Adversarial validation and verification
2729

libcanard/canard.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)