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 <socketcan@hartkopp.net>pull/204/head
parent
41c8ead6c0
commit
9b75c6020f
10
asc2log.c
10
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue