From 9b75c6020f955b1023d8e7d129c5f45a1789f4ae Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Sun, 10 May 2020 19:22:53 +0200 Subject: [PATCH] asc2log: support milliseconds resolution in date/time string While strptime() does not support fractions of seconds in the date/time string some new asc files support the milliseconds resolution. When detecting this new format the msecs are retrieved by a separate sscanf() invocation and added to the timeval's tv_usec element. Signed-off-by: Oliver Hartkopp --- asc2log.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/asc2log.c b/asc2log.c index 4935de0..de619c0 100644 --- a/asc2log.c +++ b/asc2log.c @@ -323,6 +323,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace int get_date(struct timeval *tv, char *date) { struct tm tms; + unsigned int msecs = 0; if (strcasestr(date, " pm ") != NULL) { /* assume EN/US date due to existing am/pm field */ @@ -338,6 +339,8 @@ int get_date(struct timeval *tv, char *date) { before parsing the real year value (hack) */ if (!strptime(date, "%B %d %I:%M:%S.%Y %p %Y", &tms)) return 1; + else + sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs); } } else { @@ -354,14 +357,17 @@ int get_date(struct timeval *tv, char *date) { before parsing the real year value (hack) */ if (!strptime(date, "%B %d %H:%M:%S.%Y %Y", &tms)) return 1; + else + sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs); } } - //printf("h %d m %d s %d d %d m %d y %d\n", - //tms.tm_hour, tms.tm_min, tms.tm_sec, + //printf("h %d m %d s %d ms %03d d %d m %d y %d\n", + //tms.tm_hour, tms.tm_min, tms.tm_sec, msecs, //tms.tm_mday, tms.tm_mon+1, tms.tm_year+1900); tv->tv_sec = mktime(&tms); + tv->tv_usec = msecs * 1000; if (tv->tv_sec < 0) return 1;