lib: integrate CAN FD indicator into dual-use struct canfd_frame

Replace maxdlen parameter and use CANFD_FDF flags instead.

Since the CANFD_FDF flag has been introduced in can.h the struct canfd_frame
can be used for CAN CC and CAN FD frames as a dual-use data structure.

Remove the extra maxdlen parameter in library calls and only use the
CANFD_FDF flag to differentiate the two CAN CC/FD frames.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
Oliver Hartkopp
2024-02-24 11:28:35 +01:00
parent c6f4cbcaa7
commit 2522ec127b
8 changed files with 78 additions and 60 deletions
+7 -5
View File
@@ -56,25 +56,27 @@ int main(void)
{
char buf[BUFSZ], timestamp[BUFSZ], device[BUFSZ], ascframe[BUFSZ];
struct canfd_frame cf;
int mtu, maxdlen;
int mtu;
while (fgets(buf, BUFSZ-1, stdin)) {
if (sscanf(buf, "%s %s %s", timestamp, device, ascframe) != 3)
return 1;
mtu = parse_canframe(ascframe, &cf);
/* mark dual-use struct canfd_frame */
if (mtu == CAN_MTU)
maxdlen = CAN_MAX_DLEN;
cf.flags = 0;
else if (mtu == CANFD_MTU)
maxdlen = CANFD_MAX_DLEN;
cf.flags |= CANFD_FDF;
else {
fprintf(stderr, "read: incomplete CAN frame\n");
return 1;
}
/* with ASCII output */
sprint_long_canframe(ascframe, &cf,
(CANLIB_VIEW_INDENT_SFF | CANLIB_VIEW_ASCII),
maxdlen); /* with ASCII output */
(CANLIB_VIEW_INDENT_SFF | CANLIB_VIEW_ASCII));
printf("%s %s %s\n", timestamp, device, ascframe);
}