lib: add support for Classic CAN raw DLC values

ISO 11898-1 Chapter 8.4.2.3 defines a 4 bit data length code (DLC) table which
maps the DLC to the payload length of the CAN frame in bytes:

    DLC      ->  payload length
    0 .. 8   ->  0 .. 8
    9 .. 15  ->  8

To access the raw DLC values 9 .. 15 the len8_dlc element is introduced, which
is only valid when the payload length 'len' is 8 and the DLC is greater than 8.

The extension for len8_dlc has been implemented for the Classic CAN frame
representation in the log file format and for the standard output for
candump where the raw DLC value is printed in 'unusual' curly braces {}.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
Oliver Hartkopp
2020-11-22 18:59:53 +01:00
parent c398e56afb
commit b70d8c050f
2 changed files with 76 additions and 12 deletions
+13 -7
View File
@@ -99,10 +99,11 @@ int parse_canframe(char *cs, struct canfd_frame *cf);
/*
* Transfers a valid ASCII string describing a CAN frame into struct canfd_frame.
*
* CAN 2.0 frames
* - string layout <can_id>#{R{len}|data}
* CAN 2.0 frames (aka Classical CAN)
* - string layout <can_id>#{R{len}|data}{_len8_dlc}
* - {data} has 0 to 8 hex-values that can (optionally) be separated by '.'
* - {len} can take values from 0 to 8 and can be omitted if zero
* - {_len8_dlc} can take hex values from '_9' to '_F' when len is CAN_MAX_DLEN
* - return value on successful parsing: CAN_MTU
*
* CAN FD frames
@@ -124,10 +125,12 @@ int parse_canframe(char *cs, struct canfd_frame *cf);
* 123#R -> standard CAN-Id = 0x123, len = 0, RTR-frame
* 123#R0 -> standard CAN-Id = 0x123, len = 0, RTR-frame
* 123#R7 -> standard CAN-Id = 0x123, len = 7, RTR-frame
* 123#R8_9 -> standard CAN-Id = 0x123, len = 8, dlc = 9, RTR-frame
* 7A1#r -> standard CAN-Id = 0x7A1, len = 0, RTR-frame
*
* 123#00 -> standard CAN-Id = 0x123, len = 1, data[0] = 0x00
* 123#1122334455667788 -> standard CAN-Id = 0x123, len = 8
* 123#1122334455667788_E -> standard CAN-Id = 0x123, len = 8, dlc = 14
* 123#11.22.33.44.55.66.77.88 -> standard CAN-Id = 0x123, len = 8
* 123#11.2233.44556677.88 -> standard CAN-Id = 0x123, len = 8
* 32345678#112233 -> error frame with CAN_ERR_FLAG (0x2000000) set
@@ -155,10 +158,11 @@ void sprint_canframe(char *buf , struct canfd_frame *cf, int sep, int maxdlen);
* The CAN data[] is separated by '.' when sep != 0.
*
* The type of the CAN frame (CAN 2.0 / CAN FD) is specified by maxdlen:
* maxdlen = 8 -> CAN2.0 frame
* maxdlen = 8 -> CAN2.0 frame (aka Classical CAN)
* maxdlen = 64 -> CAN FD frame
*
* 12345678#112233 -> extended CAN-Id = 0x12345678, len = 3, data, sep = 0
* 123#1122334455667788_E -> standard CAN-Id = 0x123, len = 8, dlc = 14, data, sep = 0
* 12345678#R -> extended CAN-Id = 0x12345678, RTR, len = 0
* 12345678#R5 -> extended CAN-Id = 0x12345678, RTR, len = 5
* 123#11.22.33.44.55.66.77.88 -> standard CAN-Id = 0x123, dlc = 8, sep = 1
@@ -178,6 +182,7 @@ void sprint_canframe(char *buf , struct canfd_frame *cf, int sep, int maxdlen);
#define CANLIB_VIEW_SWAP 0x4
#define CANLIB_VIEW_ERROR 0x8
#define CANLIB_VIEW_INDENT_SFF 0x10
#define CANLIB_VIEW_LEN8_DLC 0x20
#define SWAP_DELIMITER '`'
@@ -187,14 +192,15 @@ void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxd
* Creates a CAN frame hexadecimal output in user readable format.
*
* The type of the CAN frame (CAN 2.0 / CAN FD) is specified by maxdlen:
* maxdlen = 8 -> CAN2.0 frame
* maxdlen = 8 -> CAN2.0 frame (aka Classical CAN)
* maxdlen = 64 -> CAN FD frame
*
* 12345678 [3] 11 22 33 -> extended CAN-Id = 0x12345678, dlc = 3, data
* 12345678 [3] 11 22 33 -> extended CAN-Id = 0x12345678, len = 3, data
* 12345678 [0] remote request -> extended CAN-Id = 0x12345678, RTR
* 14B0DC51 [8] 4A 94 E8 2A EC 58 55 62 'J..*.XUb' -> (with ASCII output)
* 321 {B} 11 22 33 44 55 66 77 88 -> Classical CAN with raw '{DLC}' value B
* 20001111 [7] C6 23 7B 32 69 98 3C ERRORFRAME -> (CAN_ERR_FLAG set)
* 12345678 [03] 11 22 33 -> CAN FD with extended CAN-Id = 0x12345678, dlc = 3
* 12345678 [03] 11 22 33 -> CAN FD with extended CAN-Id = 0x12345678, len = 3
*
* 123 [3] 11 22 33 -> CANLIB_VIEW_INDENT_SFF == 0
* 123 [3] 11 22 33 -> CANLIB_VIEW_INDENT_SFF == set
@@ -204,7 +210,7 @@ void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxd
* // CAN FD frame with eol to STDOUT
* fprint_long_canframe(stdout, &frame, "\n", 0, CANFD_MAX_DLEN);
*
* // CAN 2.0 frame without eol to STDERR
* // Classical CAN 2.0 frame without eol to STDERR
* fprint_long_canframe(stderr, &frame, NULL, 0, CAN_MAX_DLEN);
*
*/