Skip to content

Commit

Permalink
Extend type NCodecCanMessage to include additional metadata.
Browse files Browse the repository at this point in the history
Signed-off-by: Rule Timothy (VM/EMT3) <[email protected]>
  • Loading branch information
timrulebosch committed Sep 12, 2024
1 parent d6b89ac commit d327a10
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/content/apis/ncodec/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```

Expand Down
18 changes: 18 additions & 0 deletions dse/ncodec/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
4 changes: 4 additions & 0 deletions dse/ncodec/libs/automotive-bus/frame_can_fbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions dse/ncodec/libs/automotive-bus/tests/test_can_fbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down

0 comments on commit d327a10

Please sign in to comment.