6#include "dawn/porting/can.hxx"
14#include "dawn/debug.hxx"
15#include "dawn/porting/config.hxx"
33int can_open(
const char *path)
35 return open(path, O_RDWR);
61 unsigned int msgalign = 0;
69 ret = ioctl(fd, CANIOC_SET_MSGALIGN, &msgalign);
72 DAWNERR(
"CANIOC_SET_MSGALIGN failed %d\n", -errno);
89 struct can_msg_s frame;
94 ret = read(fd, &frame,
sizeof(
struct can_msg_s));
99 DAWNERR(
"read failed %d\n", -errno);
107 msg->id = frame.cm_hdr.ch_id;
108 msg->len = can_dlc2bytes(frame.cm_hdr.ch_dlc);
109 msg->rtr = frame.cm_hdr.ch_rtr;
112#ifdef CONFIG_CAN_EXTID
113 msg->extid = frame.cm_hdr.ch_extid;
117#ifdef CONFIG_CAN_ERRORS
118 msg->error = frame.cm_hdr.ch_error;
121 std::memcpy(msg->data, frame.cm_data, CAN_DATA_MAX);
123 return static_cast<int>(ret);
136 struct can_msg_s frame;
141 frame.cm_hdr.ch_id = msg->id;
142 frame.cm_hdr.ch_rtr = msg->rtr;
143 frame.cm_hdr.ch_dlc = can_bytes2dlc(msg->len);
144#ifdef CONFIG_CAN_ERRORS
145 frame.cm_hdr.ch_error = 0;
147#ifdef CONFIG_CAN_EXTID
148 frame.cm_hdr.ch_extid = msg->extid;
150 frame.cm_hdr.ch_tcf = 0;
151 std::memcpy(frame.cm_data, msg->data, CAN_DATA_MAX);
155 ret = write(fd, &frame, CAN_MSGLEN(msg->len));
158 DAWNERR(
"write failed %d\n", -errno);
162 return static_cast<int>(ret);
Common CAN message format for chardev and socketCAN.