FreeCalypso > hg > freecalypso-sw
annotate rvinterf/lowlevel/rvifmain.c @ 908:ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 07 Sep 2015 10:55:01 +0000 |
parents | 4423039aeb4b |
children | 16ed75e266f2 |
rev | line source |
---|---|
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
176
7f727aaf5cd4
rvinterf: beginning of server implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
2 * This module contains the main() function for rvinterf |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/errno.h> |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
191
cf8583923dc4
rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
187
diff
changeset
|
8 #include <string.h> |
cf8583923dc4
rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
187
diff
changeset
|
9 #include <strings.h> |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdlib.h> |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <unistd.h> |
179
ebfa9657d03d
rvinterf: ignore SIGPIPE
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
12 #include <signal.h> |
134
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
13 #include <time.h> |
256
2f285f20d617
rvinterf: *.h moved into include subdir
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
195
diff
changeset
|
14 #include "../include/pktmux.h" |
2f285f20d617
rvinterf: *.h moved into include subdir
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
195
diff
changeset
|
15 #include "../include/localsock.h" |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
16 #include "client.h" |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
18 extern int target_fd, listener; |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 extern char *baudrate_name; |
908
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
20 extern char *extlcd_program; |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
22 extern u_char rxpkt[]; |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
23 extern size_t rxpkt_len; |
133
56b53c289785
rvtdump: some restructuring
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
127
diff
changeset
|
24 |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
25 struct client *client_head; |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
26 int socketpair_fd; |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
27 |
134
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
28 char *logfname; |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
29 FILE *logF; |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
30 time_t logtime; |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
31 int background, no_output; |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
32 int max_fd; |
134
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
33 |
187
f5f8776f7c66
rvinterf: added -s option for changing the local socket pathname
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
179
diff
changeset
|
34 char *socket_pathname = "/tmp/rvinterf_socket"; |
f5f8776f7c66
rvinterf: added -s option for changing the local socket pathname
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
179
diff
changeset
|
35 |
265
4c416868524a
rvinterf: set -w default to 7, can be disabled with -w0
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
256
diff
changeset
|
36 int wakeup_after_sec = 7; |
191
cf8583923dc4
rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
187
diff
changeset
|
37 |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 main(argc, argv) |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 char **argv; |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 { |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 extern char *optarg; |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 extern int optind; |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
43 int c; |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 fd_set fds; |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
45 struct client *cli, **clip; |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 |
908
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
47 while ((c = getopt(argc, argv, "bB:d:l:ns:S:w:X:")) != EOF) |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 switch (c) { |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 case 'b': |
169
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
50 background++; |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
51 /* FALL THRU */ |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
52 case 'n': |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
53 no_output++; |
169
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
54 continue; |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
55 case 'B': |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 baudrate_name = optarg; |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 continue; |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 case 'd': |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 target_fd = atoi(optarg); |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 continue; |
134
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
61 case 'l': |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
62 logfname = optarg; |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
63 continue; |
187
f5f8776f7c66
rvinterf: added -s option for changing the local socket pathname
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
179
diff
changeset
|
64 case 's': |
f5f8776f7c66
rvinterf: added -s option for changing the local socket pathname
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
179
diff
changeset
|
65 socket_pathname = optarg; |
f5f8776f7c66
rvinterf: added -s option for changing the local socket pathname
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
179
diff
changeset
|
66 continue; |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
67 case 'S': |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
68 socketpair_fd = atoi(optarg); |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
69 continue; |
191
cf8583923dc4
rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
187
diff
changeset
|
70 case 'w': |
cf8583923dc4
rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
187
diff
changeset
|
71 wakeup_after_sec = strtoul(optarg, 0, 0); |
cf8583923dc4
rvinterf: workaround for sleeping targets
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
187
diff
changeset
|
72 continue; |
908
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
73 case 'X': |
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
74 extlcd_program = optarg; |
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
75 continue; |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 case '?': |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 default: |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 usage: fprintf(stderr, |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
79 "usage: %s [options] ttyport\n", argv[0]); |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 exit(1); |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 } |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 if (target_fd <= 0) { |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 if (argc - optind != 1) |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 goto usage; |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 open_target_serial(argv[optind]); |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 } |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
87 max_fd = target_fd; |
908
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
88 if (extlcd_program) |
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
89 open_extlcd_pipe(); |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 set_serial_nonblock(0); |
127
f4f0c8738dcb
rvtdump: satisfactory handling of output from Pirelli's fw
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
126
diff
changeset
|
92 setlinebuf(stdout); |
134
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
93 if (logfname) { |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
94 logF = fopen(logfname, "w"); |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
95 if (!logF) { |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
96 perror(logfname); |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
97 exit(1); |
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
98 } |
330
1171c32a637b
rvinterf & rvtdump: do setlinebuf() on the log file before emitting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
265
diff
changeset
|
99 setlinebuf(logF); |
176
7f727aaf5cd4
rvinterf: beginning of server implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
100 fprintf(logF, "*** Log of rvinterf session ***\n"); |
134
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
101 } |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
102 if (socketpair_fd) |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
103 create_socketpair_client(); |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
104 else |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
105 create_listener_socket(); |
169
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
106 if (background) { |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
107 c = fork(); |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
108 if (c < 0) { |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
109 perror("fork"); |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
110 exit(1); |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
111 } |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
112 if (c) { |
176
7f727aaf5cd4
rvinterf: beginning of server implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
174
diff
changeset
|
113 printf("rvinterf forked into background (pid %d)\n", c); |
169
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
114 exit(0); |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
115 } |
e01e3a60c858
rvinterf: background mode implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
134
diff
changeset
|
116 } |
179
ebfa9657d03d
rvinterf: ignore SIGPIPE
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
178
diff
changeset
|
117 signal(SIGPIPE, SIG_IGN); |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 for (;;) { |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 FD_ZERO(&fds); |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 FD_SET(target_fd, &fds); |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
121 if (listener) |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
122 FD_SET(listener, &fds); |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
123 for (clip = &client_head; cli = *clip; ) { |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
124 if (cli->rx_state == 2) { |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
125 close(cli->fd); |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
126 *clip = cli->next; |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
127 free(cli); |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
128 continue; |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
129 } |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
130 FD_SET(cli->fd, &fds); |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
131 clip = &cli->next; |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
132 } |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
133 if (socketpair_fd && !client_head) |
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
134 exit(0); |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
135 c = select(max_fd+1, &fds, 0, 0, 0); |
134
e0d56e9be8a2
rvtdump: time-stamped logging implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
133
diff
changeset
|
136 time(&logtime); |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 if (c < 0) { |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 if (errno == EINTR) |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 continue; |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 perror("select"); |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 exit(1); |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 } |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 if (FD_ISSET(target_fd, &fds)) |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 process_serial_rx(); |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
145 if (listener && FD_ISSET(listener, &fds)) |
177
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
146 handle_listener_select(); |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
147 for (cli = client_head; cli; cli = cli->next) |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
148 if (FD_ISSET(cli->fd, &fds)) |
fef035264dd4
rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
176
diff
changeset
|
149 handle_client_select(cli); |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 } |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 } |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 handle_rx_packet() |
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 { |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
155 switch (rxpkt[0]) { |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
156 case RVT_RV_HEADER: |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
157 if (rxpkt_len < 6) |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
158 goto unknown; |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
159 if (!no_output || logF) |
178
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
160 print_rv_trace(); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
161 if (client_head) |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
162 forward_rv_trace(); |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
163 return; |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
164 case RVT_L1_HEADER: |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
165 if (!no_output || logF) |
178
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
166 print_l1_trace(); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
167 if (client_head) |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
168 forward_nonrvt_pkt(); |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
169 return; |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
170 case RVT_L23_HEADER: |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
171 if (!no_output || logF) |
178
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
172 print_g23_trace(); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
173 if (client_head) |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
174 forward_nonrvt_pkt(); |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
175 return; |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
176 case RVT_TM_HEADER: |
195
549e6cd1e77d
rvinterf: support for socketpair invokation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
191
diff
changeset
|
177 if (!no_output || logF) |
178
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
178 print_etm_output_raw(); |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
179 if (client_head) |
7ab6b29e76bb
rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
177
diff
changeset
|
180 forward_nonrvt_pkt(); |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
181 return; |
870
2682003dcba7
rvinterf: client programs can now register to receive AT and EXTUI packets
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
856
diff
changeset
|
182 case RVT_AT_HEADER: |
880
136fa1ccd591
rvtdump & rvinterf: print and log ATI responses in ASCII
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
870
diff
changeset
|
183 if (!no_output || logF) |
136fa1ccd591
rvtdump & rvinterf: print and log ATI responses in ASCII
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
870
diff
changeset
|
184 print_ati_output(); |
136fa1ccd591
rvtdump & rvinterf: print and log ATI responses in ASCII
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
870
diff
changeset
|
185 if (client_head) |
136fa1ccd591
rvtdump & rvinterf: print and log ATI responses in ASCII
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
870
diff
changeset
|
186 forward_nonrvt_pkt(); |
136fa1ccd591
rvtdump & rvinterf: print and log ATI responses in ASCII
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
870
diff
changeset
|
187 return; |
870
2682003dcba7
rvinterf: client programs can now register to receive AT and EXTUI packets
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
856
diff
changeset
|
188 case RVT_EXTUI_HEADER: |
902
4423039aeb4b
rvtdump: report ext LCD output packets sanely
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
880
diff
changeset
|
189 if (rxpkt_len < 5 || !(rxpkt_len & 1)) |
4423039aeb4b
rvtdump: report ext LCD output packets sanely
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
880
diff
changeset
|
190 goto unknown; |
908
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
191 if (extlcd_program) |
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
192 output_to_extlcd(); |
ed5dcc53e0b3
rvinterf: hook for fc-lcdemu implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
902
diff
changeset
|
193 else |
902
4423039aeb4b
rvtdump: report ext LCD output packets sanely
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
880
diff
changeset
|
194 report_extui_packet(); |
870
2682003dcba7
rvinterf: client programs can now register to receive AT and EXTUI packets
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
856
diff
changeset
|
195 return; |
856
d527ac304ad5
rvinterf & rvtdump: handle low level debug messages from FC firmwares
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
330
diff
changeset
|
196 case '*': |
d527ac304ad5
rvinterf & rvtdump: handle low level debug messages from FC firmwares
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
330
diff
changeset
|
197 print_fc_lld_msg(); |
d527ac304ad5
rvinterf & rvtdump: handle low level debug messages from FC firmwares
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
330
diff
changeset
|
198 return; |
174
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
199 default: |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
200 unknown: |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
201 print_unknown_packet(); |
3256dc6e84ae
rvinterf: refactored rvtdump compiles and works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
173
diff
changeset
|
202 } |
126
811b138f1bed
rvtdump utility written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 } |