FreeCalypso > hg > freecalypso-sw
comparison rvinterf/rvtdump.c @ 134:e0d56e9be8a2
rvtdump: time-stamped logging implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 02 Nov 2013 23:15:42 +0000 |
parents | 56b53c289785 |
children | e01e3a60c858 |
comparison
equal
deleted
inserted
replaced
133:56b53c289785 | 134:e0d56e9be8a2 |
---|---|
6 #include <sys/types.h> | 6 #include <sys/types.h> |
7 #include <sys/errno.h> | 7 #include <sys/errno.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
11 #include <time.h> | |
11 | 12 |
12 extern int target_fd; | 13 extern int target_fd; |
13 extern char *baudrate_name; | 14 extern char *baudrate_name; |
14 | 15 |
15 extern char pr_item[]; | 16 extern char pr_item[]; |
17 | |
18 char *logfname; | |
19 FILE *logF; | |
20 time_t logtime; | |
16 | 21 |
17 main(argc, argv) | 22 main(argc, argv) |
18 char **argv; | 23 char **argv; |
19 { | 24 { |
20 extern char *optarg; | 25 extern char *optarg; |
21 extern int optind; | 26 extern int optind; |
22 int c; | 27 int c; |
23 fd_set fds; | 28 fd_set fds; |
24 | 29 |
25 while ((c = getopt(argc, argv, "b:d:")) != EOF) | 30 while ((c = getopt(argc, argv, "b:d:l:")) != EOF) |
26 switch (c) { | 31 switch (c) { |
27 case 'b': | 32 case 'b': |
28 baudrate_name = optarg; | 33 baudrate_name = optarg; |
29 continue; | 34 continue; |
30 case 'd': | 35 case 'd': |
31 target_fd = atoi(optarg); | 36 target_fd = atoi(optarg); |
37 continue; | |
38 case 'l': | |
39 logfname = optarg; | |
32 continue; | 40 continue; |
33 case '?': | 41 case '?': |
34 default: | 42 default: |
35 usage: fprintf(stderr, | 43 usage: fprintf(stderr, |
36 "usage: %s [-b baudrate] ttyport\n", argv[0]); | 44 "usage: %s [-b baudrate] ttyport\n", argv[0]); |
42 open_target_serial(argv[optind]); | 50 open_target_serial(argv[optind]); |
43 } | 51 } |
44 | 52 |
45 set_serial_nonblock(0); | 53 set_serial_nonblock(0); |
46 setlinebuf(stdout); | 54 setlinebuf(stdout); |
55 if (logfname) { | |
56 logF = fopen(logfname, "w"); | |
57 if (!logF) { | |
58 perror(logfname); | |
59 exit(1); | |
60 } | |
61 fprintf(logF, "*** Log of decoded RVT output ***\n"); | |
62 setlinebuf(logF); | |
63 } | |
47 for (;;) { | 64 for (;;) { |
48 FD_ZERO(&fds); | 65 FD_ZERO(&fds); |
49 FD_SET(target_fd, &fds); | 66 FD_SET(target_fd, &fds); |
50 c = select(target_fd+1, &fds, 0, 0, 0); | 67 c = select(target_fd+1, &fds, 0, 0, 0); |
68 time(&logtime); | |
51 if (c < 0) { | 69 if (c < 0) { |
52 if (errno == EINTR) | 70 if (errno == EINTR) |
53 continue; | 71 continue; |
54 perror("select"); | 72 perror("select"); |
55 exit(1); | 73 exit(1); |
65 } | 83 } |
66 | 84 |
67 print_item() | 85 print_item() |
68 { | 86 { |
69 printf("%s\n", pr_item); | 87 printf("%s\n", pr_item); |
88 if (logF) | |
89 log_item(); | |
70 } | 90 } |