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