]> rtime.felk.cvut.cz Git - sojka/can-utils.git/commitdiff
Add new format option when mixing EFF/SFF frame output
authorOliver Hartkopp <socketcan@hartkopp.net>
Wed, 14 Nov 2012 18:59:18 +0000 (19:59 +0100)
committerOliver Hartkopp <socketcan@hartkopp.net>
Wed, 14 Nov 2012 18:59:18 +0000 (19:59 +0100)
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>
candump.c
canplayer.c
lib.c
lib.h
log2long.c

index 11be0aeef1f3084357ec73996e568161a3055bea..d6c7c0172595684c331dfd15108931c51c948857 100644 (file)
--- a/candump.c
+++ b/candump.c
@@ -673,6 +673,10 @@ int main(int argc, char **argv)
 
                                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) {
                                        /* log CAN frame with absolute timestamp & device */
                                        fprintf(logfile, "(%ld.%06ld) ", tv.tv_sec, tv.tv_usec);
index 7952177293022a5099e03888543c2fe93da31251..626100c750fdb85d38801af3d56eea17252a20e5 100644 (file)
@@ -455,9 +455,9 @@ int main(int argc, char **argv)
                                                printf("%s (%s) ", get_txname(device), device);
 
                                                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
-                                                       fprint_long_canframe(stdout, &frame, "\n", 0, CANFD_MAX_DLEN);
+                                                       fprint_long_canframe(stdout, &frame, "\n", CANLIB_VIEW_INDENT_SFF, CANFD_MAX_DLEN);
                                        }
                                }
 
diff --git a/lib.c b/lib.c
index 927f064117533432c7b64bd72694ae0f7f34941d..c8aa84a5640322157258ab5cb1e7fd4f22e23b5d 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -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);
                offset = 10;
        } else {
-               sprintf(buf, "%03X  ", cf->can_id & CAN_SFF_MASK);
-               offset = 5;
+               if (view & CANLIB_VIEW_INDENT_SFF) {
+                       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) {
diff --git a/lib.h b/lib.h
index 695498b0ea86e4d2f7939449670ac08cc37aff67..435a2d01a9c4a6d75e823303e9598cdec53f952e 100644 (file)
--- a/lib.h
+++ b/lib.h
@@ -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_SWAP       0x4
 #define CANLIB_VIEW_ERROR      0x8
+#define CANLIB_VIEW_INDENT_SFF 0x10
 
 #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)
  * 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:
  *
  * // CAN FD frame with eol to STDOUT
index 297d43f13d7cd0fe6fea8e27958a6a53dc7d86db..04354e5e4d406ab869fc202bb85c5f3e5002323e 100644 (file)
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
                }
 
                sprint_long_canframe(ascframe, &cf,
-                                    CANLIB_VIEW_ASCII,
+                                    (CANLIB_VIEW_INDENT_SFF | CANLIB_VIEW_ASCII),
                                     maxdlen); /* with ASCII output */
 
                printf("%s  %s  %s\n", timestamp, device, ascframe);