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:
Oliver Hartkopp
2012-11-14 19:47:21 +01:00
parent a2b13452c7
commit e7631bd7f9
10 changed files with 440 additions and 201 deletions
+21 -5
View File
@@ -52,17 +52,33 @@
#include "lib.h"
#define COMMENTSZ 200
#define BUFSZ (sizeof("(1345212884.318850)") + IFNAMSIZ + 4 + CL_CFSZ + COMMENTSZ) /* for one line in the logfile */
int main(int argc, char **argv)
{
char buf[100], timestamp[100], device[100], ascframe[100];
struct can_frame cf;
char buf[BUFSZ], timestamp[BUFSZ], device[BUFSZ], ascframe[BUFSZ];
struct canfd_frame cf;
int mtu, maxdlen;
while (fgets(buf, 99, stdin)) {
while (fgets(buf, BUFSZ-1, stdin)) {
if (sscanf(buf, "%s %s %s", timestamp, device, ascframe) != 3)
return 1;
if (parse_canframe(ascframe, &cf))
mtu = parse_canframe(ascframe, &cf);
if (mtu == CAN_MTU)
maxdlen = CAN_MAX_DLEN;
else if (mtu == CANFD_MTU)
maxdlen = CANFD_MAX_DLEN;
else {
fprintf(stderr, "read: incomplete CAN frame\n");
return 1;
sprint_long_canframe(ascframe, &cf, 1); /* with ASCII output */
}
sprint_long_canframe(ascframe, &cf,
CANLIB_VIEW_ASCII,
maxdlen); /* with ASCII output */
printf("%s %s %s\n", timestamp, device, ascframe);
}