Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check decode in C++ wrappers and handle multiple frame starts #65

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions canard.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ int16_t canardHandleRxFrame(CanardInstance* ins, const CanardCANFrame* frame, ui

// take off the crc and store the payload
rx_state->timestamp_usec = timestamp_usec;
rx_state->payload_len = 0;
const int16_t ret = bufferBlockPushBytes(&ins->allocator, rx_state, frame->data + 2,
(uint8_t) (frame->data_len - 3));
if (ret < 0)
Expand Down
5 changes: 4 additions & 1 deletion canard/service_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class Client : public HandlerList, public Sender {
/// @param transfer transfer object of the request
void handle_message(const CanardRxTransfer& transfer) override {
rsptype msg {};
rsptype::cxx_iface::rsp_decode(&transfer, &msg);
if (rsptype::cxx_iface::rsp_decode(&transfer, &msg)) {
// invalid decode
return;
}

// scan through the list of entries for corresponding server node id and transfer id
Client<rsptype>* entry = branch_head[index];
Expand Down
5 changes: 4 additions & 1 deletion canard/service_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class Server : public HandlerList {
/// @param transfer transfer object of the request
void handle_message(const CanardRxTransfer& transfer) override {
reqtype msg {};
reqtype::cxx_iface::req_decode(&transfer, &msg);
if (reqtype::cxx_iface::req_decode(&transfer, &msg)) {
// invalid decode
return;
}
transfer_id = transfer.transfer_id;
// call the registered callback
cb(transfer, msg);
Expand Down
5 changes: 4 additions & 1 deletion canard/subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ class Subscriber : public HandlerList {
/// @param transfer transfer object
void handle_message(const CanardRxTransfer& transfer) override {
msgtype msg {};
msgtype::cxx_iface::decode(&transfer, &msg);
if (msgtype::cxx_iface::decode(&transfer, &msg)) {
// invalid decode
return;
}
// call all registered callbacks in one go
Subscriber<msgtype>* entry = branch_head[index];
while (entry != nullptr) {
Expand Down
Loading