Commit Graph

46 Commits (af09afb73435587009aaeba32c19fb7c7e8475f1)

Author SHA1 Message Date
GZZ8 23648c8a31
Refactor the help/usage message for canplayer
Limit the error return value only to unknown options.
If the utility is invoked with the help option '-h',
display the usage message and exit successfully.

Co-authored-by: Filip Valgimigli <filip.valgimigli@unimore.it>
Signed-off-by: Filip Valgimigli <filip.valgimigli@unimore.it>
2024-05-14 19:19:35 +02:00
Oliver Hartkopp dd16f2603b can-utils: make local functions static
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-12 20:10:00 +01:00
Oliver Hartkopp 27030b3e54 lib: make sprint_canframe the buffer size aware snprintf_canframe
Make sure the library functions to convert CAN frames into ASCII
represenation do not exceed the given buffer size. This also applies
to the long CAN frame output library function.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-12 19:11:58 +01:00
Oliver Hartkopp 29290505f7 log: finalize unified buffer handling
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-29 08:41:21 +01:00
Oliver Hartkopp 1da219922d unify buffer size for ASCII CAN frame string representations
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-29 07:10:34 +01:00
Oliver Hartkopp 34a1cfad29 lib: make parse_canframe CAN XL aware
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-28 22:00:19 +01:00
Oliver Hartkopp 3644a54d5b candump/lib: make sprint_long_canframe CAN XL aware
The 'long' CAN frame representation does not really fit for CAN XL content.
Therefore just a cropped output is provided to be able to see the CAN XL
header information and up to 64 byte of data (without binary or swap
formating options). To get the full qualified CAN XL content use the log
file format.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 20:11:46 +01:00
Oliver Hartkopp 48e10c9c57 canplayer: remove fprint_long_canframe usage
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 11:04:42 +01:00
Oliver Hartkopp 2522ec127b 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>
2024-02-24 11:28:35 +01:00
TyK ceda93bd5c timestamp formatting: always use 64-bit for timesstamp formatting.
Using C99 `unsigned long long` to format `struct timeval`'s `tv_sec`
and `tv_usec`, fix incorrect print under some 32bit platform which
 using time64.
2023-11-28 08:30:27 +08:00
Michael Wagner ad850776c3 canplayer: Format code according to .clang-format 2023-09-05 10:51:30 +02:00
Oliver Hartkopp 79601bd1d4 canplayer: ensure 6 decimal places in timestamp for first frame
The check has only been applied after the first CAN frame has been read
and evaluated. This lead to an unintended sending of a single handcrafted
frame with a following (intended) failure at the second frame.

Apply the check also for the very first CAN frame that is processed.

Fixes: ee0233505b ("canplayer: ensure 6 decimal places in timestamp")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2023-08-10 10:31:26 +02:00
Oliver Hartkopp 0d84033fa4 canplayer: introduce option to limit the number of processed frames
Analogue to the '-n <count>' option to limit the number of processed CAN
frames in candump and cangen this option makes sense in canplayer too.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2021-10-30 13:02:42 +02:00
Oliver Hartkopp aaa7fd215f canplayer: add interactive single-step frame processing mode
Wait for ENTER key to process next CAN frame from the log file.

As the new line is printed each time this approach doesn't win a
design price. But this feature is very uncommon and setting the
terminal into some raw mode to get the raw keyboard hits would
introduce a big code overhead to handle e.g. CTRL-C signals which
is a vital functionality for canplayer.

Link: https://github.com/linux-can/can-utils/issues/280
Suggested-by: https://github.com/nico0481
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2021-04-17 13:01:29 +02:00
Oliver Hartkopp 553f0d282b canplayer: fix usec overflow handling
Commit 9c2de072a0 ("asc2log: Correct usec overflow handling") fixed the
usec overflow handling which is contained in a similar code snippet in
canplayer too.

Cc: Simon Tegelid <simon.tegelid@niradynamics.se>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2021-04-16 16:18:40 +02:00
Rosen Penev b153fe3f35
clang-tidy: sort includes alphabetically
Found with llvm-include-order

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:58 -07:00
Rosen Penev 3e85fc5422
clang-tidy: fix cmp function usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:58 -07:00
Oliver Hartkopp a4905ed7c8 fix timeval to ASCII unsigned value conversion
As reported by Oleksij Rempel here
https://github.com/linux-can/can-utils/issues/233#issuecomment-674818935
the representation of timeval timestamps are signed values which leads to
negative values on 32 bit machines addressing the year 2038 unix sec counter
overflow.

Fix the issue on 32 bit systems by converting the timeval values to unsigned
ASCII value representations.

Fixes: https://github.com/linux-can/can-utils/issues/234
Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-08-18 12:51:35 +02:00
Gary Bisson 46895a41c5 Fix comparison type mismatch warnings
Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
2020-05-28 20:54:37 +02:00
Oliver Hartkopp 853989bed2 canplayer: make help text fit into 80 colums again
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-04-28 19:01:45 +02:00
Alexander Gerasiov 3e2c1d3cbd canplayer.c: Reformat help/usage output to be compatible with help2man.
Signed-off-by: Alexander Gerasiov <gq@debian.org>

Gbp-Pq: Name 0009-canplayer.c-Reformat-help-usage-output-to-be-compati.patch
2020-04-27 08:20:08 +03:00
Yegor Yefremov 14ccc06eba Fix spelling in various files
codespell parameters:

codespell -q 3 --skip="*.in,*.sh,*.m4,config,configure,autom4te.cache"

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-11-11 14:21:49 +01:00
Yegor Yefremov 7b7331976a Add SPDX identifiers
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-06-19 12:24:24 +02:00
Oliver Hartkopp ee0233505b canplayer: ensure 6 decimal places in timestamp
Ensure the fractions of seconds are 6 decimal places long to catch
3rd party or handcrafted logfiles that treat the timestamp as float.

See: https://github.com/linux-can/can-utils/issues/60

Reported-by: https://github.com/hauptmech
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2017-12-13 20:12:32 +01:00
Yegor Yefremov 5846246ddd canplayer: convert skipgap to unsigned long
The result of (last_log_tv.tv_sec - log_tv.tv_sec) is
unsigned long, so use labs() in order not to trim the
value to int. Make skipgap to unsigned long for the same
reason.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
2015-04-10 21:20:58 +02:00
Oliver Hartkopp 836d3cc012 remove obsolete SVN ID tags
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-14 20:57:16 +01:00
Oliver Hartkopp fcbdf71f1a Add new format option when mixing EFF/SFF frame output
Added new view CANLIB_VIEW_INDENT_SFF flags to fix the sloppy output of
fprint_long_canframe() when mixing EFF & SFF CAN identifiers.

candump: Once an EFF frame is detected the indention is enabled.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-14 19:59:18 +01:00
Oliver Hartkopp e7631bd7f9 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>
2012-11-14 19:47:21 +01:00
Yegor Yefremov 4d3a002ec1 can-utils: cleanup headers
- add missing sys/socket.h: on some systems (like Android)
have SOCK_RAW definition directly in sys/socket.h

- use sys/wait.h instead if wait.h

- include termios.h explicitly (Android)

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2012-03-20 11:16:43 +01:00
Marc Kleine-Budde 722a09116d treewide: replace berlios contact email by linux-can@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2012-01-11 12:14:15 +01:00
Oliver Hartkopp 5655d53acb Remove compiler warning :
warning: suggest explicit braces to avoid ambiguous ‘else’
2010-05-14 12:50:17 +00:00
Oliver Hartkopp c11220e9c9 fflush the new configurable stdout output to allow proper pipe/netcat setups. 2009-11-25 18:51:31 +00:00
Oliver Hartkopp 0b4d143113 Added hook to print selected logfile lines on stdout for further processing. 2009-11-06 08:07:45 +00:00
Oliver Hartkopp 4369ac1c55 Consistencely allow '-?' to get a help text. 2009-01-13 09:32:45 +00:00
Oliver Hartkopp 6c0ca36ab2 Create an informative error message when detecting a wrong line format. 2008-07-25 06:32:20 +00:00
Oliver Hartkopp 15ce202e60 Changed comment line recognition:
Everything without a '(' at the beginning of an input line is treated as comment.
Changed buffer size to allow long comment lines & added overflow handling.
2008-07-24 19:12:19 +00:00
Oliver Hartkopp ba037dcffa Support for comment lines in the logfile:
'#' at the beginning of a line marks comment lines.
2008-07-24 13:03:18 +00:00
Oliver Hartkopp 34703ac659 Fixed condition pointed out by Uwe Bonnes:
https://lists.berlios.de/pipermail/socketcan-core/2008-June/001625.html
2008-06-26 14:35:46 +00:00
Oliver Hartkopp adbe6f9bee Whitespace fixes. Indented the code following Linux styleguide to fix
the mess between tabs and spaces.
2008-06-03 08:46:57 +00:00
Oliver Hartkopp d72681c442 Reverted most of the changes since r500 except the changes in
drivers/net/can/* after discussion with Urs.
TODO: Documentation & new Version.
2007-10-01 05:48:50 +00:00
Oliver Hartkopp 6689e9600d Changed loopback to echo in CAN RAW sockets. The binary interface does
not change through this renaming of CAN_RAW_LOOPBACK to CAN_RAW_ECHO.
2007-09-30 13:00:42 +00:00
Oliver Hartkopp d0b24ffc10 Fixed contradiction in Sourcecode discalimer.
See details at
http://marc.info/?l=linux-netdev&m=119074747913703&w=2
2007-09-27 12:29:32 +00:00
Oliver Hartkopp 592c916948 Updated the canplayer to accept logfile timestamps in the future (which
is very nice when you don't have a RTC and your systemtime is somewhere 
in the 1970's :)
Added a new commandline option to skip timestamp jumps greater than x 
seconds to allow to concatenate different logfiles that replay 
constantly and not waiting for the absolute timestamp offsets.
2007-09-07 11:15:22 +00:00
Oliver Hartkopp 404bf3b1bd Added option '-x' to disable local loopback for sent CAN frames. 2007-06-22 08:33:18 +00:00
Oliver Hartkopp aca93c6867 Added Option -l ('l'oop) to make the canplayer replay a given file more than
one time. To replay a given file infinitely say '-l i'. Of course it is not
possible/reasonable to define '-l' when reading from stdin ...
2007-02-12 08:36:38 +00:00
Oliver Hartkopp 4d129ea348 Minor fix and cosmetics in color handling in candump.c .
Added new tool 'canplayer' to replay logfiles generated by candump -l .

Features of canplayer:

- Input from stdin or file.
- throttling of the replay to get nearly original timestamps / message gaps
- mapping and selection of CAN interfaces (assignment)
  e.g. canplay -I logfile vcan2=can2 vcan0=can1 can2=can3
  means: send frames received on can1 in the logfile to vcan0 and so on ...
- if no assignment is made the original interfaces are used for replay
- handling of multiple CAN interfaces simultaneously (if in logfile)
- option: throttle disable (do not look on timestamps => very FAST replay!)
- option: change the 'sleep time' in milli seconds

Remarks:
canplayer uses nanosleep() for throttling which means that the resolution of
the canplayer is about 1ms (Kernel HZ = 1000) or 10ms (Kernel HZ = 100).
After each nanosleep() all the CAN frames are send that had to be transmitted
until the timestamp at the current time. Giving e.g. the option '-g 500' for
500ms let's you see the behaviour. Using nanosleep() makes canplay a very
performant tool with minimum CPU load.

To transfer CAN frames over a TCP/IP network you may now say something like:
candump -> netcat -> netcat -> canplayer
2007-01-06 15:43:12 +00:00