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 -9
View File
@@ -71,7 +71,7 @@ void print_usage(char *prg)
fprintf(stderr, "\t-O <outfile>\t(default stdout)\n");
}
void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, unsigned int max_dlen, char *extra_info) {
void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, char *extra_info) {
fprintf(file, "(%llu.%06llu) ", (unsigned long long)tv->tv_sec, (unsigned long long)tv->tv_usec);
@@ -80,7 +80,7 @@ void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, un
else
fprintf(file, "canX ");
fprint_canframe(file, cf, extra_info, 0, max_dlen);
fprint_canframe(file, cf, extra_info, 0);
}
void get_can_id(struct canfd_frame *cf, char *idstring, int base) {
@@ -131,7 +131,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
int interface;
static struct timeval tv; /* current frame timestamp */
static struct timeval read_tv; /* frame timestamp from ASC file */
struct canfd_frame cf;
struct canfd_frame cf = { 0 };
struct can_frame *ccf = (struct can_frame *)&cf; /* for len8_dlc */
char rtr;
int dlc = 0;
@@ -152,13 +152,12 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
if (!strncmp(tmp1, "ErrorFrame", strlen("ErrorFrame"))) {
memset(&cf, 0, sizeof(cf));
/* do not know more than 'Error' */
cf.can_id = (CAN_ERR_FLAG | CAN_ERR_BUSERROR);
cf.len = CAN_ERR_DLC;
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN, "\n");
prframe(outfile, &tv, interface, &cf, "\n");
fflush(outfile);
return;
}
@@ -232,7 +231,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
cf.data[i] = data[i] & 0xFFU;
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, CAN_MAX_DLEN, extra_info);
prframe(outfile, &tv, interface, &cf, extra_info);
fflush(outfile);
}
}
@@ -343,14 +342,13 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
#define ASC_F_ESI 0x00004000
if (flags & ASC_F_FDF) {
dlen = CANFD_MAX_DLEN;
cf.flags = CANFD_FDF;
if (flags & ASC_F_BRS)
cf.flags |= CANFD_BRS;
if (flags & ASC_F_ESI)
cf.flags |= CANFD_ESI;
} else {
/* yes. The 'CANFD' format supports classic CAN content! */
dlen = CAN_MAX_DLEN;
if (flags & ASC_F_RTR) {
cf.can_id |= CAN_RTR_FLAG;
/* dlen is always 0 for classic CAN RTR frames
@@ -369,7 +367,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
}
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, dlen, extra_info);
prframe(outfile, &tv, interface, &cf, extra_info);
fflush(outfile);
/* No support for really strange CANFD ErrorFrames format m( */