From d327a103ef2b3a91bddf7c31a004b64fe5ca537b Mon Sep 17 00:00:00 2001 From: "Rule Timothy (VM/EMT3)" Date: Thu, 12 Sep 2024 11:43:24 +0200 Subject: [PATCH] Extend type NCodecCanMessage to include additional metadata. Signed-off-by: Rule Timothy (VM/EMT3) --- doc/content/apis/ncodec/index.md | 3 +++ dse/ncodec/codec.h | 18 ++++++++++++++++++ dse/ncodec/libs/automotive-bus/frame_can_fbs.c | 4 ++++ .../libs/automotive-bus/tests/test_can_fbs.c | 3 +++ 4 files changed, 28 insertions(+) diff --git a/doc/content/apis/ncodec/index.md b/doc/content/apis/ncodec/index.md index 4d92f57..8c4d853 100644 --- a/doc/content/apis/ncodec/index.md +++ b/doc/content/apis/ncodec/index.md @@ -81,6 +81,9 @@ typedef struct NCodecCanMessage { uint8_t* buffer; size_t len; NCodecCanFrameType frame_type; + uint64_t [2] __reserved__; + struct (anonymous struct at dse/ncodec/codec.h:206:5) sender; + struct (anonymous struct at dse/ncodec/codec.h:214:5) timing; } ``` diff --git a/dse/ncodec/codec.h b/dse/ncodec/codec.h index 0ba1454..ac5c4d1 100644 --- a/dse/ncodec/codec.h +++ b/dse/ncodec/codec.h @@ -198,6 +198,24 @@ typedef struct NCodecCanMessage { uint8_t* buffer; size_t len; NCodecCanFrameType frame_type; + + /* Reserved. */ + uint64_t __reserved__[2]; + + /* Sender metadata (optional). */ + struct { + /* RX node identification. */ + uint8_t bus_id; + uint8_t node_id; + uint8_t interface_id; + } sender; + + /* Timing metadata (optional), values in nSec. */ + struct { + uint64_t send; /* When the message is delivered to the Codec. */ + uint64_t arb; /* When the message is sent by the Codec. */ + uint64_t recv; /* When the message is received from the Codec. */ + } timing; } NCodecCanMessage; diff --git a/dse/ncodec/libs/automotive-bus/frame_can_fbs.c b/dse/ncodec/libs/automotive-bus/frame_can_fbs.c index c227b68..bf2df47 100644 --- a/dse/ncodec/libs/automotive-bus/frame_can_fbs.c +++ b/dse/ncodec/libs/automotive-bus/frame_can_fbs.c @@ -174,6 +174,10 @@ int32_t can_read(NCODEC* nc, NCodecMessage* msg) (uint8_t*)payload; // TODO think about this cast ... caller // should not modify ... restrict? _msg->len = flatbuffers_uint8_vec_len(payload); + _msg->sender.bus_id = ns(CanFrame_bus_id(can_frame)); + _msg->sender.node_id = ns(CanFrame_node_id(can_frame)); + _msg->sender.interface_id = ns(CanFrame_interface_id(can_frame)); + /* ... but don't forget to save the vector index either. */ _nc->vector_idx = _vi + 1; return _msg->len; diff --git a/dse/ncodec/libs/automotive-bus/tests/test_can_fbs.c b/dse/ncodec/libs/automotive-bus/tests/test_can_fbs.c index 3936d14..118741b 100644 --- a/dse/ncodec/libs/automotive-bus/tests/test_can_fbs.c +++ b/dse/ncodec/libs/automotive-bus/tests/test_can_fbs.c @@ -236,6 +236,9 @@ void test_can_fbs_readwrite(void** state) assert_int_equal(msg.len, strlen(greeting)); assert_non_null(msg.buffer); assert_memory_equal(msg.buffer, greeting, strlen(greeting)); + assert_int_equal(msg.sender.bus_id, 1); + assert_int_equal(msg.sender.node_id, 8); // Note this value was modified. + assert_int_equal(msg.sender.interface_id, 3); }