FreeCalypso > hg > freecalypso-sw
comparison rvinterf/rvtdump.c @ 169:e01e3a60c858
rvinterf: background mode implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Wed, 20 Nov 2013 02:58:35 +0000 |
parents | e0d56e9be8a2 |
children | 4d8e4c58df71 |
comparison
equal
deleted
inserted
replaced
168:60afcd233b04 | 169:e01e3a60c858 |
---|---|
16 extern char pr_item[]; | 16 extern char pr_item[]; |
17 | 17 |
18 char *logfname; | 18 char *logfname; |
19 FILE *logF; | 19 FILE *logF; |
20 time_t logtime; | 20 time_t logtime; |
21 int background; | |
21 | 22 |
22 main(argc, argv) | 23 main(argc, argv) |
23 char **argv; | 24 char **argv; |
24 { | 25 { |
25 extern char *optarg; | 26 extern char *optarg; |
26 extern int optind; | 27 extern int optind; |
27 int c; | 28 int c; |
28 fd_set fds; | 29 fd_set fds; |
29 | 30 |
30 while ((c = getopt(argc, argv, "b:d:l:")) != EOF) | 31 while ((c = getopt(argc, argv, "bB:d:l:")) != EOF) |
31 switch (c) { | 32 switch (c) { |
32 case 'b': | 33 case 'b': |
34 background++; | |
35 continue; | |
36 case 'B': | |
33 baudrate_name = optarg; | 37 baudrate_name = optarg; |
34 continue; | 38 continue; |
35 case 'd': | 39 case 'd': |
36 target_fd = atoi(optarg); | 40 target_fd = atoi(optarg); |
37 continue; | 41 continue; |
39 logfname = optarg; | 43 logfname = optarg; |
40 continue; | 44 continue; |
41 case '?': | 45 case '?': |
42 default: | 46 default: |
43 usage: fprintf(stderr, | 47 usage: fprintf(stderr, |
44 "usage: %s [-b baudrate] ttyport\n", argv[0]); | 48 "usage: %s [options] ttyport\n", argv[0]); |
45 exit(1); | 49 exit(1); |
46 } | 50 } |
51 if (background && !logfname) { | |
52 fprintf(stderr, "%s: -b is meaningless without -l\n", argv[0]); | |
53 exit(1); | |
54 } | |
47 if (target_fd <= 0) { | 55 if (target_fd <= 0) { |
48 if (argc - optind != 1) | 56 if (argc - optind != 1) |
49 goto usage; | 57 goto usage; |
50 open_target_serial(argv[optind]); | 58 open_target_serial(argv[optind]); |
51 } | 59 } |
58 perror(logfname); | 66 perror(logfname); |
59 exit(1); | 67 exit(1); |
60 } | 68 } |
61 fprintf(logF, "*** Log of decoded RVT output ***\n"); | 69 fprintf(logF, "*** Log of decoded RVT output ***\n"); |
62 setlinebuf(logF); | 70 setlinebuf(logF); |
71 } | |
72 if (background) { | |
73 c = fork(); | |
74 if (c < 0) { | |
75 perror("fork"); | |
76 exit(1); | |
77 } | |
78 if (c) { | |
79 printf("rvtdump forked into background (pid %d)\n", c); | |
80 exit(0); | |
81 } | |
63 } | 82 } |
64 for (;;) { | 83 for (;;) { |
65 FD_ZERO(&fds); | 84 FD_ZERO(&fds); |
66 FD_SET(target_fd, &fds); | 85 FD_SET(target_fd, &fds); |
67 c = select(target_fd+1, &fds, 0, 0, 0); | 86 c = select(target_fd+1, &fds, 0, 0, 0); |
82 print_rx_packet(); | 101 print_rx_packet(); |
83 } | 102 } |
84 | 103 |
85 print_item() | 104 print_item() |
86 { | 105 { |
87 printf("%s\n", pr_item); | 106 if (!background) |
107 printf("%s\n", pr_item); | |
88 if (logF) | 108 if (logF) |
89 log_item(); | 109 log_item(); |
90 } | 110 } |