48 if (IS_CAN_FRAME_EFF(*frame))
51 uint32_t
id = GET_CAN_FRAME_ID_EFF(*frame);
52 for (
int i = 9; i >= 2; --i,
id >>= 4)
61 uint16_t
id = GET_CAN_FRAME_ID(*frame);
62 for (
int i = 4; i >= 2; --i,
id >>= 4)
70 if (IS_CAN_FRAME_RTR(*frame))
81 for (
int i = 0; i < frame->can_dlc; i++, index += 2)
105 struct can_frame *can_frame = (
struct can_frame*)data;
106 size_t remaining = len;
109 if ((len %
sizeof(
struct can_frame)) != 0)
116 unsigned char buf[56];
121 ssize_t size =
encode(can_frame, buf);
126 for (ssize_t i = (size - 1), j = ((size * 2) - 1);
132 buf[0] = buf[1] =
'!';
138 ssize_t result =
::write(fd, buf, size);
146 remaining -=
sizeof(
struct can_frame);
162 struct can_frame *can_frame = (
struct can_frame*)data;
163 size_t remaining = len;
165 const char SOF = doub ?
'!' :
':';
166 const int factor = doub ? 2 : 1;
169 if ((len %
sizeof(
struct can_frame)) != 0)
188 ssize_t result =
::read(fd, buf, factor);
193 }
while(buf[0] != SOF);
197 for (i = 1; i < 28; ++i)
199 ssize_t result =
::read(fd, buf + i, factor);
221 SET_CAN_FRAME_EFF(*can_frame);
227 SET_CAN_FRAME_ID_EFF(*can_frame,
id);
230 else if (buf[1] ==
'S')
232 CLR_CAN_FRAME_EFF(*can_frame);
236 SET_CAN_FRAME_ID(*can_frame,
id);
246 if (buf[index] ==
'N')
248 CLR_CAN_FRAME_RTR(*can_frame);
250 else if (buf[index] ==
'R')
252 SET_CAN_FRAME_RTR(*can_frame);
263 for (i = 0; buf[index] !=
';'; index += 2, i++)
267 can_frame->can_dlc = i;
269 CLR_CAN_FRAME_ERR(*can_frame);
272 remaining -=
sizeof(
struct can_frame);
static int ascii_pair_to_byte(const char *pair)
Take a pair of ASCII characters and convert them to a byte value.
static ssize_t write_generic(int fd, const void *data, size_t len, bool doub)
Write a CAN packet to Grid Connect interface in single or double format.
static char nibble_to_ascii(int nibble)
Builds an ASCII character representation of a nibble value.
static ssize_t write(int fd, const void *data, size_t len)
Write a CAN packet to Grid Connect interface in single format.
static ssize_t read(int fd, void *data, size_t len)
Read a CAN packet to Grid Connect interface in single format.
static ssize_t encode(struct can_frame *frame, unsigned char buf[])
static ssize_t read_generic(int fd, void *data, size_t len, bool doub)
Read a CAN packet to Grid Connect interface in single or double format.