Skip to content

Commit

Permalink
Update to the latest libcanard and libcyphal
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 committed Nov 21, 2024
1 parent 65e579e commit 5a32771
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libcyphal_demo/src/platform/linux/can/can_media.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class CanMedia final : public libcyphal::transport::can::IMedia
return cetl::nullopt;
}

return PopResult::Metadata{executor_.now(), canard_frame.extended_can_id, canard_frame.payload_size};
return PopResult::Metadata{executor_.now(), canard_frame.extended_can_id, canard_frame.payload.size};
}

CETL_NODISCARD libcyphal::IExecutor::Callback::Any registerPushCallback(
Expand Down
12 changes: 6 additions & 6 deletions shared/socketcan/socketcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ SocketCANFD socketcanOpen(const char* const iface_name, const bool can_fd)

int16_t socketcanPush(const SocketCANFD fd, const CanardFrame* const frame, const CanardMicrosecond timeout_usec)
{
if ((frame == NULL) || (frame->payload == NULL) || (frame->payload_size > UINT8_MAX))
if ((frame == NULL) || (frame->payload.data == NULL) || (frame->payload.size > UINT8_MAX))
{
return -EINVAL;
}
Expand All @@ -149,15 +149,15 @@ int16_t socketcanPush(const SocketCANFD fd, const CanardFrame* const frame, cons
struct canfd_frame cfd;
(void) memset(&cfd, 0, sizeof(cfd));
cfd.can_id = frame->extended_can_id | CAN_EFF_FLAG;
cfd.len = (uint8_t) frame->payload_size;
cfd.len = (uint8_t) frame->payload.size;
// We set the bit rate switch on the assumption that it will be ignored by non-CAN-FD-capable hardware.
cfd.flags = CANFD_BRS;
(void) memcpy(cfd.data, frame->payload, frame->payload_size);
(void) memcpy(cfd.data, frame->payload.data, frame->payload.size);

// If the payload is small, use the smaller MTU for compatibility with non-FD sockets.
// This way, if the user attempts to transmit a CAN FD frame without having the CAN FD socket option enabled,
// an error will be triggered here. This is convenient -- we can handle both FD and Classic CAN uniformly.
const size_t mtu = (frame->payload_size > CAN_MAX_DLEN) ? CANFD_MTU : CAN_MTU;
const size_t mtu = (frame->payload.size > CAN_MAX_DLEN) ? CANFD_MTU : CAN_MTU;
if (write(fd, &cfd, mtu) < 0)
{
return getNegatedErrno();
Expand Down Expand Up @@ -267,8 +267,8 @@ int16_t socketcanPop(const SocketCANFD fd,
*out_timestamp_usec = (CanardMicrosecond) (((uint64_t) tv.tv_sec * MEGA) + (uint64_t) tv.tv_usec);
}
out_frame->extended_can_id = sockcan_frame.can_id & CAN_EFF_MASK;
out_frame->payload_size = sockcan_frame.len;
out_frame->payload = payload_buffer;
out_frame->payload.size = sockcan_frame.len;
out_frame->payload.data = payload_buffer;
(void) memcpy(payload_buffer, &sockcan_frame.data[0], sockcan_frame.len);
}
return poll_result;
Expand Down
2 changes: 1 addition & 1 deletion submodules/libcanard

0 comments on commit 5a32771

Please sign in to comment.