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>
pull/7/head
Oliver Hartkopp 2012-11-14 19:59:18 +01:00
parent e7631bd7f9
commit fcbdf71f1a
5 changed files with 18 additions and 5 deletions

View File

@ -673,6 +673,10 @@ int main(int argc, char **argv)
idx = idx2dindex(addr.can_ifindex, s[i]); idx = idx2dindex(addr.can_ifindex, s[i]);
/* once we detected a EFF frame indent SFF frames accordingly */
if (frame.can_id & CAN_EFF_FLAG)
view |= CANLIB_VIEW_INDENT_SFF;
if (log) { if (log) {
/* log CAN frame with absolute timestamp & device */ /* log CAN frame with absolute timestamp & device */
fprintf(logfile, "(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); fprintf(logfile, "(%ld.%06ld) ", tv.tv_sec, tv.tv_usec);

View File

@ -455,9 +455,9 @@ int main(int argc, char **argv)
printf("%s (%s) ", get_txname(device), device); printf("%s (%s) ", get_txname(device), device);
if (txmtu == CAN_MTU) if (txmtu == CAN_MTU)
fprint_long_canframe(stdout, &frame, "\n", 0, CAN_MAX_DLEN); fprint_long_canframe(stdout, &frame, "\n", CANLIB_VIEW_INDENT_SFF, CAN_MAX_DLEN);
else else
fprint_long_canframe(stdout, &frame, "\n", 0, CANFD_MAX_DLEN); fprint_long_canframe(stdout, &frame, "\n", CANLIB_VIEW_INDENT_SFF, CANFD_MAX_DLEN);
} }
} }

9
lib.c
View File

@ -288,8 +288,13 @@ void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxd
sprintf(buf, "%08X ", cf->can_id & CAN_EFF_MASK); sprintf(buf, "%08X ", cf->can_id & CAN_EFF_MASK);
offset = 10; offset = 10;
} else { } else {
sprintf(buf, "%03X ", cf->can_id & CAN_SFF_MASK); if (view & CANLIB_VIEW_INDENT_SFF) {
offset = 5; sprintf(buf, " %03X ", cf->can_id & CAN_SFF_MASK);
offset = 10;
} else {
sprintf(buf, "%03X ", cf->can_id & CAN_SFF_MASK);
offset = 5;
}
} }
if (maxdlen == CAN_MAX_DLEN) { if (maxdlen == CAN_MAX_DLEN) {

4
lib.h
View File

@ -171,6 +171,7 @@ void sprint_canframe(char *buf , struct canfd_frame *cf, int sep, int maxdlen);
#define CANLIB_VIEW_BINARY 0x2 #define CANLIB_VIEW_BINARY 0x2
#define CANLIB_VIEW_SWAP 0x4 #define CANLIB_VIEW_SWAP 0x4
#define CANLIB_VIEW_ERROR 0x8 #define CANLIB_VIEW_ERROR 0x8
#define CANLIB_VIEW_INDENT_SFF 0x10
#define SWAP_DELIMITER '`' #define SWAP_DELIMITER '`'
@ -189,6 +190,9 @@ void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxd
* 20001111 [7] C6 23 7B 32 69 98 3C ERRORFRAME -> (CAN_ERR_FLAG set) * 20001111 [7] C6 23 7B 32 69 98 3C ERRORFRAME -> (CAN_ERR_FLAG set)
* 12345678 [03] 11 22 33 -> CAN FD with exended CAN-Id = 0x12345678, dlc = 3 * 12345678 [03] 11 22 33 -> CAN FD with exended CAN-Id = 0x12345678, dlc = 3
* *
* 123 [3] 11 22 33 -> CANLIB_VIEW_INDENT_SFF == 0
* 123 [3] 11 22 33 -> CANLIB_VIEW_INDENT_SFF == set
*
* Examples: * Examples:
* *
* // CAN FD frame with eol to STDOUT * // CAN FD frame with eol to STDOUT

View File

@ -76,7 +76,7 @@ int main(int argc, char **argv)
} }
sprint_long_canframe(ascframe, &cf, sprint_long_canframe(ascframe, &cf,
CANLIB_VIEW_ASCII, (CANLIB_VIEW_INDENT_SFF | CANLIB_VIEW_ASCII),
maxdlen); /* with ASCII output */ maxdlen); /* with ASCII output */
printf("%s %s %s\n", timestamp, device, ascframe); printf("%s %s %s\n", timestamp, device, ascframe);