Merge pull request #473 from tisyang/master

timestamp formatting: always use 64-bit for timesstamp formatting.
pull/475/head
Marc Kleine-Budde 2023-11-28 08:47:45 +01:00 committed by GitHub
commit 2abf88cee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 58 additions and 42 deletions

View File

@ -73,7 +73,7 @@ void print_usage(char *prg)
void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, unsigned int max_dlen, char *extra_info) {
fprintf(file, "(%lu.%06lu) ", tv->tv_sec, tv->tv_usec);
fprintf(file, "(%llu.%06llu) ", (unsigned long long)tv->tv_sec, (unsigned long long)tv->tv_usec);
if (dev > 0)
fprintf(file, "can%d ", dev-1);
@ -141,11 +141,14 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
char dir[3]; /* 'Rx' or 'Tx' plus terminating zero */
char *extra_info;
int i, items;
unsigned long long sec, usec;
/* check for ErrorFrames */
if (sscanf(buf, "%lu.%lu %d %s",
&read_tv.tv_sec, &read_tv.tv_usec,
if (sscanf(buf, "%llu.%llu %d %s",
&sec, &usec,
&interface, tmp1) == 4) {
read_tv.tv_sec = sec;
read_tv.tv_usec = usec;
if (!strncmp(tmp1, "ErrorFrame", strlen("ErrorFrame"))) {
@ -165,18 +168,20 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
/* check for CAN frames with (hexa)decimal values */
if (base == 'h')
items = sscanf(buf, "%lu.%lu %d %s %2s %c %x %x %x %x %x %x %x %x %x",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
items = sscanf(buf, "%llu.%llu %d %s %2s %c %x %x %x %x %x %x %x %x %x",
&sec, &usec, &interface,
tmp1, dir, &rtr, &dlc,
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]);
else
items = sscanf(buf, "%lu.%lu %d %s %2s %c %x %d %d %d %d %d %d %d %d",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
items = sscanf(buf, "%llu.%llu %d %s %2s %c %x %d %d %d %d %d %d %d %d",
&sec, &usec, &interface,
tmp1, dir, &rtr, &dlc,
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]);
read_tv.tv_sec = sec;
read_tv.tv_usec = usec;
if (items < 7 ) /* make sure we've read the dlc */
return;
@ -246,6 +251,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
char *extra_info;
char *ptr;
int i;
unsigned long long sec, usec;
/* The CANFD format is mainly in hex representation but <DataLength>
and probably some content we skip anyway. Don't trust the docs! */
@ -255,19 +261,21 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
100000 214 223040 80000000 46500250 460a0250 20011736 20010205 */
/* check for valid line without symbolic name */
if (sscanf(buf, "%lu.%lu %*s %d %2s %s %hhx %hhx %x %d ",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
if (sscanf(buf, "%llu.%llu %*s %d %2s %s %hhx %hhx %x %d ",
&sec, &usec, &interface,
dir, tmp1, &brs, &esi, &dlc, &dlen) != 9) {
/* check for valid line with a symbolic name */
if (sscanf(buf, "%lu.%lu %*s %d %2s %s %*s %hhx %hhx %x %d ",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
if (sscanf(buf, "%llu.%llu %*s %d %2s %s %*s %hhx %hhx %x %d ",
&sec, &usec, &interface,
dir, tmp1, &brs, &esi, &dlc, &dlen) != 9) {
/* no valid CANFD format pattern */
return;
}
}
read_tv.tv_sec = sec;
read_tv.tv_usec = usec;
/* check for allowed (unsigned) value ranges */
if ((dlen > CANFD_MAX_DLEN) || (dlc > CANFD_MAX_DLC) ||
@ -427,12 +435,12 @@ int main(int argc, char **argv)
FILE *infile = stdin;
FILE *outfile = stdout;
static int verbose;
static struct timeval tmp_tv; /* tmp frame timestamp from ASC file */
static struct timeval date_tv; /* date of the ASC file */
static int dplace; /* decimal place 4, 5 or 6 or uninitialized */
static char base; /* 'd'ec or 'h'ex */
static char timestamps; /* 'a'bsolute or 'r'elative */
int opt;
unsigned long long sec, usec;
while ((opt = getopt(argc, argv, "I:O:v?")) != -1) {
switch (opt) {
@ -505,12 +513,12 @@ int main(int argc, char **argv)
gettimeofday(&date_tv, NULL);
}
if (verbose)
printf("date %lu => %s", date_tv.tv_sec, ctime(&date_tv.tv_sec));
printf("date %llu => %s", (unsigned long long)date_tv.tv_sec, ctime(&date_tv.tv_sec));
continue;
}
/* check for decimal places length in valid CAN frames */
if (sscanf(buf, "%lu.%s %s ", &tmp_tv.tv_sec, tmp2,
if (sscanf(buf, "%llu.%s %s ", &sec, tmp2,
tmp1) != 3)
continue; /* dplace remains zero until first found CAN frame */
@ -529,7 +537,7 @@ int main(int argc, char **argv)
/* so try to get CAN frames and ErrorFrames and convert them */
/* check classic CAN format or the CANFD tag which can take both types */
if (sscanf(buf, "%lu.%lu %s ", &tmp_tv.tv_sec, &tmp_tv.tv_usec, tmp1) == 3){
if (sscanf(buf, "%llu.%llu %s ", &sec, &usec, tmp1) == 3){
if (!strncmp(tmp1, "CANFD", 5))
eval_canfd(buf, &date_tv, timestamps, dplace, outfile);
else

View File

@ -226,7 +226,7 @@ static inline void sprint_timestamp(const char timestamp, const struct timeval *
{
switch (timestamp) {
case 'a': /* absolute with timestamp */
sprintf(ts_buffer, "(%010lu.%06lu) ", tv->tv_sec, tv->tv_usec);
sprintf(ts_buffer, "(%010llu.%06llu) ", (unsigned long long)tv->tv_sec, (unsigned long long)tv->tv_usec);
break;
case 'A': /* absolute with date */
@ -236,7 +236,7 @@ static inline void sprint_timestamp(const char timestamp, const struct timeval *
tm = *localtime(&tv->tv_sec);
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
sprintf(ts_buffer, "(%s.%06lu) ", timestring, tv->tv_usec);
sprintf(ts_buffer, "(%s.%06llu) ", timestring, (unsigned long long)tv->tv_usec);
}
break;
@ -253,7 +253,7 @@ static inline void sprint_timestamp(const char timestamp, const struct timeval *
diff.tv_sec--, diff.tv_usec += 1000000;
if (diff.tv_sec < 0)
diff.tv_sec = diff.tv_usec = 0;
sprintf(ts_buffer, "(%03lu.%06lu) ", diff.tv_sec, diff.tv_usec);
sprintf(ts_buffer, "(%03llu.%06llu) ", (unsigned long long)diff.tv_sec, (unsigned long long)diff.tv_usec);
if (timestamp == 'd')
*last_tv = *tv; /* update for delta calculation */

View File

@ -415,8 +415,8 @@ int main(int argc, char **argv)
idx = idx2dindex(addr.can_ifindex, s[i]);
sprintf(temp, "(%lu.%06lu) %*s ",
tv.tv_sec, tv.tv_usec, max_devname_len, devname[idx]);
sprintf(temp, "(%llu.%06llu) %*s ",
(unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec, max_devname_len, devname[idx]);
sprint_canframe(temp+strlen(temp), &frame, 0, maxdlen);
strcat(temp, "\n");

View File

@ -259,6 +259,7 @@ int main(int argc, char **argv)
int txidx; /* sendto() interface index */
int eof, txmtu, i, j;
char *fret;
unsigned long long sec, usec;
while ((opt = getopt(argc, argv, "I:l:tin:g:s:xv?")) != -1) {
switch (opt) {
@ -416,10 +417,12 @@ int main(int argc, char **argv)
eof = 0;
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec, device, ascframe) != 4) {
if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, ascframe) != 4) {
fprintf(stderr, "incorrect line format in logfile\n");
return 1;
}
log_tv.tv_sec = sec;
log_tv.tv_usec = usec;
/*
* ensure the fractions of seconds are 6 decimal places long to catch
@ -507,10 +510,12 @@ int main(int argc, char **argv)
break;
}
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec, device, ascframe) != 4) {
if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, ascframe) != 4) {
fprintf(stderr, "incorrect line format in logfile\n");
return 1;
}
log_tv.tv_sec = sec;
log_tv.tv_usec = usec;
/*
* ensure the fractions of seconds are 6 decimal places long to catch

View File

@ -361,7 +361,7 @@ int main(int argc, char **argv)
switch (timestamp) {
case 'a': /* absolute with timestamp */
printf("(%lu.%06lu) ", tv.tv_sec, tv.tv_usec);
printf("(%llu.%06llu) ", (unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec);
break;
case 'A': /* absolute with date */
@ -372,7 +372,7 @@ int main(int argc, char **argv)
tm = *localtime(&tv.tv_sec);
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S",
&tm);
printf("(%s.%06lu) ", timestring, tv.tv_usec);
printf("(%s.%06llu) ", timestring, (unsigned long long)tv.tv_usec);
} break;
case 'd': /* delta */
@ -388,8 +388,8 @@ int main(int argc, char **argv)
diff.tv_sec--, diff.tv_usec += 1000000;
if (diff.tv_sec < 0)
diff.tv_sec = diff.tv_usec = 0;
printf("(%lu.%06lu) ", diff.tv_sec,
diff.tv_usec);
printf("(%llu.%06llu) ", (unsigned long long)diff.tv_sec,
(unsigned long long)diff.tv_usec);
if (timestamp == 'd')
last_tv =

View File

@ -403,9 +403,9 @@ int main(int argc, char **argv)
/* check devisor to be not zero */
if (diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000){
printf("%lu.%06lus ", diff_tv.tv_sec, diff_tv.tv_usec);
printf("%llu.%06llus ", (unsigned long long)diff_tv.tv_sec, (unsigned long long)diff_tv.tv_usec);
printf("=> %lu byte/s", (fflen * 1000) /
(diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000));
(unsigned long)(diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000));
} else
printf("(no time available) ");

View File

@ -101,7 +101,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
switch (timestamp) {
case 'a': /* absolute with timestamp */
printf("(%lu.%06lu) ", tv->tv_sec, tv->tv_usec);
printf("(%llu.%06llu) ", (unsigned long long)tv->tv_sec, (unsigned long long)tv->tv_usec);
break;
case 'A': /* absolute with date */
@ -111,7 +111,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
tm = *localtime(&tv->tv_sec);
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
printf("(%s.%06lu) ", timestring, tv->tv_usec);
printf("(%s.%06llu) ", timestring, (unsigned long long)tv->tv_usec);
}
break;
@ -128,7 +128,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
diff.tv_sec--, diff.tv_usec += 1000000;
if (diff.tv_sec < 0)
diff.tv_sec = diff.tv_usec = 0;
printf("(%lu.%06lu) ", diff.tv_sec, diff.tv_usec);
printf("(%llu.%06llu) ", (unsigned long long)diff.tv_sec, (unsigned long long)diff.tv_usec);
if (timestamp == 'd')
*last_tv = *tv; /* update for delta calculation */

View File

@ -148,8 +148,8 @@ static void j1939cat_print_timestamp(struct j1939cat_priv *priv, const char *nam
if (!(cur->tv_sec | cur->tv_nsec))
return;
fprintf(stderr, " %s: %lu s %lu us (seq=%03u, send=%07u)",
name, cur->tv_sec, cur->tv_nsec / 1000,
fprintf(stderr, " %s: %llu s %llu us (seq=%03u, send=%07u)",
name, (unsigned long long)cur->tv_sec, (unsigned long long)cur->tv_nsec / 1000,
stats->tskey, stats->send);
fprintf(stderr, "\n");

View File

@ -259,14 +259,14 @@ int main(int argc, char **argv)
goto abs_time;
} else if ('a' == s.time) {
abs_time:
printf("(%lu.%04lu)", tdut.tv_sec, tdut.tv_usec / 100);
printf("(%llu.%04llu)", (unsigned long long)tdut.tv_sec, (unsigned long long)tdut.tv_usec / 100);
} else if ('A' == s.time) {
struct tm tm;
tm = *localtime(&tdut.tv_sec);
printf("(%04u%02u%02uT%02u%02u%02u.%04lu)",
printf("(%04u%02u%02uT%02u%02u%02u.%04llu)",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
tdut.tv_usec/100);
(unsigned long long)tdut.tv_usec/100);
}
}
printf(" %s ", libj1939_addr2str(&src));

View File

@ -191,6 +191,7 @@ int main(int argc, char **argv)
FILE *outfile = stdout;
static int maxdev, devno, i, crlf, fdfmt, nortrdlc, d4, opt, mtu;
int print_banner = 1;
unsigned long long sec, usec;
while ((opt = getopt(argc, argv, "I:O:4nfr?")) != -1) {
switch (opt) {
@ -260,18 +261,20 @@ int main(int argc, char **argv)
if (buf[0] != '(')
continue;
if (sscanf(buf, "(%lu.%lu) %s %s %s", &tv.tv_sec, &tv.tv_usec,
if (sscanf(buf, "(%llu.%llu) %s %s %s", &sec, &usec,
device, ascframe, extra_info) != 5) {
/* do not evaluate the extra info */
extra_info[0] = 0;
if (sscanf(buf, "(%lu.%lu) %s %s", &tv.tv_sec, &tv.tv_usec,
if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec,
device, ascframe) != 4) {
fprintf(stderr, "incorrect line format in logfile\n");
return 1;
}
}
tv.tv_sec = sec;
tv.tv_usec = usec;
if (print_banner) { /* print banner */
print_banner = 0;
@ -307,9 +310,9 @@ int main(int argc, char **argv)
tv.tv_sec = tv.tv_usec = 0;
if (d4)
fprintf(outfile, "%4lu.%04lu ", tv.tv_sec, tv.tv_usec/100);
fprintf(outfile, "%4llu.%04llu ", (unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec/100);
else
fprintf(outfile, "%4lu.%06lu ", tv.tv_sec, tv.tv_usec);
fprintf(outfile, "%4llu.%06llu ", (unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec);
if ((mtu == CAN_MTU) && (fdfmt == 0))
can_asc(&cf, devno, nortrdlc, extra_info, outfile);

View File

@ -363,8 +363,8 @@ int can2pty(int pty, int socket, int *tstamp)
if (ioctl(socket, SIOCGSTAMP, &tv) < 0)
perror("SIOCGSTAMP");
sprintf(&buf[ptr + 2*frame.can_dlc], "%04lX",
(tv.tv_sec%60)*1000 + tv.tv_usec/1000);
sprintf(&buf[ptr + 2*frame.can_dlc], "%04llX",
(unsigned long long)(tv.tv_sec%60)*1000 + tv.tv_usec/1000);
}
strcat(buf, "\r"); /* add terminating character */