logfile: add new extra info field

This patch adds a fourth string field in the can logfile format.
This new field contains the rx/tx direction information R/T as the
first entry (only one character separated from the CAN frame by space).

To generate the logfile format with this extra field candump has to be
called with the '-x' option for extra message infos,
e.g. 'candump -x -l can0' or 'candump -x -L can0'

log2asc and asc2log are extended to support the direction information
but still support the previous format without direction information.

The format extension does not affect legacy tools, e.g. the existing
canplayer ignores this extra information and does not need to be changed.

Therefore the existing logfiles remain valid and usable.

The extra message infos will be colon separated when there's need for
additional content beyond the rx/tx direction information, e.g. R:xx:yyy

Suggested-by: Pallavi Revanna https://github.com/brpallu
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
Oliver Hartkopp
2020-08-18 13:29:36 +02:00
parent a4905ed7c8
commit 7cb3e760fe
3 changed files with 89 additions and 35 deletions
+14 -4
View File
@@ -628,6 +628,7 @@ int main(int argc, char **argv)
if (FD_ISSET(s[i], &rdfs)) {
int idx;
char *extra_info = "";
/* these settings may be modified by recvmsg() */
iov.iov_len = sizeof(frame);
@@ -701,14 +702,22 @@ int main(int argc, char **argv)
if (frame.can_id & CAN_EFF_FLAG)
view |= CANLIB_VIEW_INDENT_SFF;
if (extra_msg_info) {
if (msg.msg_flags & MSG_DONTROUTE)
extra_info = " T";
else
extra_info = " R";
}
if (log) {
char buf[CL_CFSZ]; /* max length */
/* log CAN frame with absolute timestamp & device */
sprint_canframe(buf, &frame, 0, maxdlen);
fprintf(logfile, "(%010lu.%06lu) %*s %s\n",
fprintf(logfile, "(%010lu.%06lu) %*s %s%s\n",
tv.tv_sec, tv.tv_usec,
max_devname_len, devname[idx], buf);
max_devname_len, devname[idx], buf,
extra_info);
}
if ((logfrmt) && (silent == SILENT_OFF)){
@@ -716,9 +725,10 @@ int main(int argc, char **argv)
/* print CAN frame in log file style to stdout */
sprint_canframe(buf, &frame, 0, maxdlen);
printf("(%010lu.%06lu) %*s %s\n",
printf("(%010lu.%06lu) %*s %s%s\n",
tv.tv_sec, tv.tv_usec,
max_devname_len, devname[idx], buf);
max_devname_len, devname[idx], buf,
extra_info);
goto out_fflush; /* no other output to stdout */
}