read-dev-usbmon: prepend time to message

This commit is contained in:
Peter Wu
2013-04-29 19:03:13 +02:00
parent 20ae5c63cf
commit 0c6200cd5f

View File

@@ -27,6 +27,8 @@
#include <stdint.h>
#include <stdlib.h> /* getenv */
#include <errno.h>
#include <sys/time.h> /* gettimeofday */
#include <time.h> /* localtime */
typedef uint16_t u16;
typedef int32_t s32;
@@ -78,6 +80,20 @@ struct mon_get_arg {
#include "hidraw.c"
#undef NO_MAIN
void print_time(void) {
struct timeval tval;
struct tm *tm;
if (gettimeofday(&tval, NULL)) {
perror("gettimeofday");
return;
}
tm = localtime(&tval.tv_sec);
printf("%02d:%02d:%02d.%03ld ",
tm->tm_hour, tm->tm_min, tm->tm_sec,
tval.tv_usec / 1000);
}
int main(int argc, char ** argv) {
unsigned char data[1024];
struct usbmon_packet hdr;
@@ -131,6 +147,7 @@ int main(int argc, char ** argv) {
continue;
}
#define COLOR(c, cstr) "\033[" c "m" cstr "\033[m"
print_time();
if (hdr.type == 'C') {
printf(COLOR("1;32", "Recv\t"));
} else if (hdr.type == 'S') {