1+ /*
2+ Copyright(c) 2021-2025 jvde.github@gmail.com
3+
4+ This program is free software: you can redistribute it and/or modify
5+ it under the terms of the GNU General Public License as published by
6+ the Free Software Foundation, either version 3 of the License, or
7+ (at your option) any later version.
8+
9+ This program is distributed in the hope that it will be useful,
10+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ GNU General Public License for more details.
13+
14+ You should have received a copy of the GNU General Public License
15+ along with this program. If not, see <https://www.gnu.org/licenses/>.
16+ */
17+
18+ #include " ADSB.h"
19+
20+ namespace Plane
21+ {
22+
23+ void ADSB::Callsign ()
24+ {
25+ static const char *cs_table = " #ABCDEFGHIJKLMNOPQRSTUVWXYZ##### ###############0123456789######" ;
26+ char temp[9 ] = {0 };
27+ int len = 0 ;
28+
29+ for (int i = 0 ; i < 8 ; i++)
30+ {
31+ uint32_t c = getBits ( 40 + (i * 6 ), 6 );
32+ if (cs_table[c] != ' #' )
33+ {
34+ temp[len++] = cs_table[c];
35+ }
36+ }
37+
38+ if (len > 0 )
39+ {
40+ std::strncpy (callsign, temp, sizeof (callsign) - 1 );
41+ callsign[sizeof (callsign) - 1 ] = ' \0 ' ;
42+ }
43+ }
44+
45+ void ADSB::Decode ()
46+ {
47+ if (msgtype == ' 1' ) return ;
48+
49+ df = getBits (0 , 5 );
50+
51+ switch (df)
52+ {
53+ case 0 : // Short Air-Air Surveillance
54+ case 4 : // Surveillance, Altitude Reply
55+ case 20 : // Comm-B, Altitude Reply
56+ {
57+ // unsigned ac = getBits( 19, 13);
58+ // if (ac)
59+ // altitude = decodeESAlt(ac);
60+ }
61+ break ;
62+
63+ case 11 : // All-Call Reply
64+ hexident = getBits (8 , 24 );
65+ break ;
66+
67+ case 17 : // Extended Squitter
68+ case 18 : // Extended Squitter/Supplementary
69+ {
70+ hexident = getBits ( 8 , 24 );
71+ msgtype = getBits ( 32 , 5 );
72+
73+ switch (msgtype)
74+ {
75+ case 1 :
76+ case 2 :
77+ case 3 :
78+ case 4 : // Aircraft Identification
79+ Callsign ();
80+ break ;
81+
82+ case 19 : // Airborne Velocity
83+ // decodeVelocity();
84+ break ;
85+
86+ case 5 :
87+ case 6 :
88+ case 7 :
89+ case 8 : // Surface Position
90+ case 9 :
91+ case 10 :
92+ case 11 :
93+ case 12 : // Airborne Position
94+ case 13 :
95+ case 14 :
96+ case 15 :
97+ case 16 :
98+ case 17 :
99+ case 18 :
100+ if (msgtype >= 9 )
101+ {
102+ // unsigned ac = getBits( 37, 12);
103+ // if (ac)
104+ // altitude = decodeESAlt(ac);
105+ }
106+ // Position( getBits(msgData, 54, 1));
107+ break ;
108+ }
109+ }
110+ break ;
111+ }
112+
113+ }
114+ }
0 commit comments