mirror of
https://github.com/linux-can/can-utils.git
synced 2026-09-22 16:09:52 +02:00
canfd: upgrade tools to support CAN FD for Linux 3.6
This is a major upgrade of the basic tools to handle CAN FD frames.
The library to parse and print CAN frames and logfiles has been extended.
In detail:
asc2log.c | 5 +
candump.c | 24 ++++---
cangen.c | 172 +++++++++++++++++++++++++++++++++------------------
canlogserver.c | 28 +++++---
canplayer.c | 25 ++++---
cansend.c | 55 ++++++++++++----
lib.c | 189 ++++++++++++++++++++++++++++++++++++++-------------------
lib.h | 109 ++++++++++++++++++++++++--------
log2asc.c | 8 +-
log2long.c | 26 ++++++-
10 files changed, 440 insertions(+), 201 deletions(-)
asc2log.c / log2asc.c
- updates for new lib functions
- still can only handle CAN2.0 frames (no new info about ASC file layout)
log2long.c / canlogserver.c / canplayer.c
- updates for new lib functions to handle CAN FD
lib.h / lib.c
- reworked lib functions to handle CAN FD
- parse_canframe() now returns CAN_MTU and CANFD_MTU on success, 0 at failure
- added can_dlc2len() and can_len2dlc() helpers
- moved hexstring2candata to hexstring2data to support simple byte buffers
- in the long CAN frame representation use %03X/%08X instead of %3X/%8X
- introduced unified buffer size definitions for ASCII CAN frames
- updated documentation
cangen.c
- support CAN FD frames (added -f option to create CAN FD frames)
- added -m option ('mix') to create random extended / RTR / CAN FD frames
- fixed the 'fixed data' option which was zero'ing the payload by the time
- updated help text
candump.c
- support CAN FD frames (print, bridge, log)
- distinguish frame types by length info: [0] = CAN2.0 [00] = CAN FD frame
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
+18
-10
@@ -74,6 +74,9 @@
|
||||
#define ANYDEV "any"
|
||||
#define ANL "\r\n" /* newline in ASC mode */
|
||||
|
||||
#define COMMENTSZ 200
|
||||
#define BUFSZ (sizeof("(1345212884.318850)") + IFNAMSIZ + 4 + CL_CFSZ + COMMENTSZ) /* for one line in the logfile */
|
||||
|
||||
#define DEFPORT 28700
|
||||
|
||||
static char devname[MAXDEV][IFNAMSIZ+1];
|
||||
@@ -183,15 +186,16 @@ int main(int argc, char **argv)
|
||||
int currmax = 1; /* we assume at least one can bus ;-) */
|
||||
struct sockaddr_can addr;
|
||||
struct can_filter rfilter;
|
||||
struct can_frame frame;
|
||||
int nbytes, i, j;
|
||||
struct canfd_frame frame;
|
||||
const int canfd_on = 1;
|
||||
int nbytes, i, j, maxdlen;
|
||||
struct ifreq ifr;
|
||||
struct timeval tv, last_tv;
|
||||
int port = DEFPORT;
|
||||
struct sockaddr_in inaddr;
|
||||
struct sockaddr_in clientaddr;
|
||||
socklen_t sin_size = sizeof(clientaddr);
|
||||
char temp[128];
|
||||
char temp[BUFSZ];
|
||||
|
||||
sigemptyset(&sigset);
|
||||
signalaction.sa_handler = &childdied;
|
||||
@@ -339,6 +343,9 @@ int main(int argc, char **argv)
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
|
||||
&err_mask[i], sizeof(err_mask[i]));
|
||||
|
||||
/* try to switch the socket into CAN FD mode */
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
|
||||
|
||||
j = strlen(argv[optind+i]);
|
||||
|
||||
if (!(j < IFNAMSIZ)) {
|
||||
@@ -387,14 +394,17 @@ int main(int argc, char **argv)
|
||||
socklen_t len = sizeof(addr);
|
||||
int idx;
|
||||
|
||||
if ((nbytes = recvfrom(s[i], &frame,
|
||||
sizeof(struct can_frame), 0,
|
||||
if ((nbytes = recvfrom(s[i], &frame, CANFD_MTU, 0,
|
||||
(struct sockaddr*)&addr, &len)) < 0) {
|
||||
perror("read");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (nbytes < sizeof(struct can_frame)) {
|
||||
if ((size_t)nbytes == CAN_MTU)
|
||||
maxdlen = CAN_MAX_DLEN;
|
||||
else if ((size_t)nbytes == CANFD_MTU)
|
||||
maxdlen = CANFD_MAX_DLEN;
|
||||
else {
|
||||
fprintf(stderr, "read: incomplete CAN frame\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -407,7 +417,7 @@ int main(int argc, char **argv)
|
||||
|
||||
sprintf(temp, "(%ld.%06ld) %*s ",
|
||||
tv.tv_sec, tv.tv_usec, max_devname_len, devname[idx]);
|
||||
sprint_canframe(temp+strlen(temp), &frame, 0);
|
||||
sprint_canframe(temp+strlen(temp), &frame, 0, maxdlen);
|
||||
strcat(temp, "\n");
|
||||
|
||||
if (write(accsocket, temp, strlen(temp)) < 0) {
|
||||
@@ -415,13 +425,11 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* printf("%s\n",temp2); */
|
||||
|
||||
#if 0
|
||||
/* print CAN frame in log file style to stdout */
|
||||
printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec);
|
||||
printf("%*s ", max_devname_len, devname[idx]);
|
||||
fprint_canframe(stdout, &frame, "\n", 0);
|
||||
fprint_canframe(stdout, &frame, "\n", 0, maxdlen);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user