Debian Codegraph @

interactive.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 // Part of dump1090, a Mode S message decoder for RTLSDR devices.
2 //
3 // interactive.c: aircraft tracking and interactive display
4 //
5 // Copyright (c) 2014,2015 Oliver Jowett <[email protected]>
6 //
7 // This file is free software: you may copy, redistribute and/or modify it
8 // under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, either version 2 of the License, or (at your
10 // option) any later version.
11 //
12 // This file is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 // This file incorporates work covered by the following copyright and
21 // permission notice:
22 //
23 // Copyright (C) 2012 by Salvatore Sanfilippo <[email protected]>
24 //
25 // All rights reserved.
26 //
27 // Redistribution and use in source and binary forms, with or without
28 // modification, are permitted provided that the following conditions are
29 // met:
30 //
31 // * Redistributions of source code must retain the above copyright
32 // notice, this list of conditions and the following disclaimer.
33 //
34 // * Redistributions in binary form must reproduce the above copyright
35 // notice, this list of conditions and the following disclaimer in the
36 // documentation and/or other materials provided with the distribution.
37 //
38 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
42 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
50 #include "dump1090.h"
51
52 //
53 //========================= Interactive mode ===============================
54
55
56 static int convert_altitude(int ft)
57 {
58 if (Modes.metric)
59 return (ft * 0.3048);
60 else
61 return ft;
62 }
63
64 static int convert_speed(int kts)
65 {
66 if (Modes.metric)
67 return (kts * 1.852);
68 else
69 return kts;
70 }
71
72 //
73 //=========================================================================
74 //
75 // Show the currently captured interactive data on screen.
76 //
77 void interactiveShowData(void) {
78 struct aircraft *a = Modes.aircrafts;
79 static uint64_t next_update;
80 uint64_t now = mstime();
81 int count = 0;
82 char progress;
83 char spinner[4] = "|/-\\";
84
85 // Refresh screen every (MODES_INTERACTIVE_REFRESH_TIME) miliseconde
86 if (now < next_update)
87 return;
88
89 next_update = now + MODES_INTERACTIVE_REFRESH_TIME;
90
91 progress = spinner[(now/1000)%4];
92
93 #ifndef _WIN32
94 printf("\x1b[H\x1b[2J"); // Clear the screen
95 #else
96 cls();
97 #endif
98
99 if (Modes.interactive_rtl1090 == 0) {
100 printf (
101 " Hex Mode Sqwk Flight Alt Spd Hdg Lat Long RSSI Msgs Ti%c\n", progress);
102 } else {
103 printf (
104 " Hex Flight Alt V/S GS TT SSR G*456^ Msgs Seen %c\n", progress);
105 }
106 printf(
107 "-------------------------------------------------------------------------------\n");
108
109 while(a && (count < Modes.interactive_rows)) {
110
111 if ((now - a->seen) < Modes.interactive_display_ttl)
112 {
113 int msgs = a->messages;
114 int flags = a->modeACflags;
115
116 if ( (((flags & (MODEAC_MSG_FLAG )) == 0 ) && (msgs > 1 ) )
117 || (((flags & (MODEAC_MSG_MODES_HIT | MODEAC_MSG_MODEA_ONLY)) == MODEAC_MSG_MODEA_ONLY) && (msgs > 4 ) )
118 || (((flags & (MODEAC_MSG_MODES_HIT | MODEAC_MSG_MODEC_OLD )) == 0 ) && (msgs > 127) )
119 ) {
120 char strSquawk[5] = " ";
121 char strFl[7] = " ";
122 char strTt[5] = " ";
123 char strGs[5] = " ";
124
125 if (trackDataValid(&a->squawk_valid)) {
126 snprintf(strSquawk,5,"%04x", a->squawk);
127 }
128
129 if (trackDataValid(&a->speed_valid)) {
130 snprintf (strGs, 5,"%3d", convert_speed(a->speed));
131 }
132
133 if (trackDataValid(&a->heading_valid)) {
134 snprintf (strTt, 5,"%03d", a->heading);
135 }
136
137 if (msgs > 99999) {
138 msgs = 99999;
139 }
140
141 if (Modes.interactive_rtl1090) { // RTL1090 display mode
142 if (trackDataValid(&a->altitude_valid)) {
143 snprintf(strFl,6,"F%03d",((a->altitude+50)/100));
144 }
145 printf("%06x %-8s %-4s %-3s %-3s %4s %-6d %-2.0f\n",
146 a->addr, a->callsign, strFl, strGs, strTt, strSquawk, msgs, (now - a->seen)/1000.0);
147
148 } else { // Dump1090 display mode
149 char strMode[5] = " ";
150 char strLat[8] = " ";
151 char strLon[9] = " ";
152 double * pSig = a->signalLevel;
153 double signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
154 pSig[4] + pSig[5] + pSig[6] + pSig[7]) / 8.0;
155
156 if ((flags & MODEAC_MSG_FLAG) == 0) {
157 strMode[0] = 'S';
158 } else if (flags & MODEAC_MSG_MODEA_ONLY) {
159 strMode[0] = 'A';
160 }
161 if (flags & MODEAC_MSG_MODEA_HIT) {strMode[2] = 'a';}
162 if (flags & MODEAC_MSG_MODEC_HIT) {strMode[3] = 'c';}
163
164 if (trackDataValid(&a->position_valid)) {
165 snprintf(strLat, 8,"%7.03f", a->lat);
166 snprintf(strLon, 9,"%8.03f", a->lon);
167 }
168
169 if (trackDataValid(&a->airground_valid) && a->airground == AG_GROUND) {
170 snprintf(strFl, 7," grnd");
171 } else if (Modes.use_gnss && trackDataValid(&a->altitude_gnss_valid)) {
172 snprintf(strFl, 7, "%5dH", convert_altitude(a->altitude_gnss));
173 } else if (trackDataValid(&a->altitude_valid)) {
174 snprintf(strFl, 7, "%5d ", convert_altitude(a->altitude));
175 }
176
177 printf("%s%06X %-4s %-4s %-8s %6s %3s %3s %7s %8s %5.1f %5d %2.0f\n",
178 (a->addr & MODES_NON_ICAO_ADDRESS) ? "~" : " ", (a->addr & 0xffffff),
179 strMode, strSquawk, a->callsign, strFl, strGs, strTt,
180 strLat, strLon, 10 * log10(signalAverage), msgs, (now - a->seen)/1000.0);
181 }
182 count++;
183 }
184 }
185 a = a->next;
186 }
187 }
188
189 //
190 //=========================================================================
191 //