/
explain.c
311 lines (293 loc) · 10.1 KB
/
explain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
* Explain the various ACARS label types.
* Sources:
* http://www.cosmic.com.au/acarsanalyser/v3/DataRes/MsgLabels.htm
* http://www.universal-radio.com/catalog/decoders/acars.pdf
*
* Copyright (c) 2015 David Barts
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
struct kv {
char *key, *value;
};
char GeneralLab[] = "General response, demand mode; no information to transmit";
char AirlineLab[] = "Airline defined message";
struct kv explanations[] = {
{ "_", GeneralLab },
{ "_d", GeneralLab },
{ "_\x7f", GeneralLab },
{ "_j", "No info to transmit; polled mode" },
{ "00", "Emergency situation report" },
{ "2S", "Weather request" },
{ "2U", "Weather" },
{ "4M", "Cargo information" },
{ "51", "Ground GMT request/response" },
{ "52", "Ground UTC request/response" },
{ "54", "Aircrew initiated voice contact request" },
{ "57", "Alternate aircrew initiated position report" },
{ "5D", "ATIS request" },
{ "5P", "Temporary suspension of ACARS" },
{ "5R", "Aircraft initiated position report" },
{ "5U", "Weather request" },
{ "5Y", "Revision to previous ETA" },
{ "5Z", "Airline designated downlink" },
{ "7A", "Aircraft initiated engine data" },
{ "7B", "Aircraft initiated miscellaneous message" },
{ "80", "Aircraft addressed downlink 0" },
{ "81", "Aircraft addressed downlink 1" },
{ "82", "Aircraft addressed downlink 2" },
{ "83", "Aircraft addressed downlink 3" },
{ "84", "Aircraft addressed downlink 4" },
{ "85", "Aircraft addressed downlink 5" },
{ "86", "Aircraft addressed downlink 6" },
{ "87", "Aircraft addressed downlink 7" },
{ "88", "Aircraft addressed downlink 8" },
{ "89", "Aircraft addressed downlink 9" },
{ "8~", "Aircraft addressed downlink 10" },
{ "A1", "Deliver oceanic clearance" },
{ "A2", "Deliver departure clearance" },
{ "A4", "Acknowledge PDC" },
{ "A5", "Request position report" },
{ "A6", "Request ADS report" },
{ "A7", "Forward free text to aircraft" },
{ "A8", "Deliver departure slot" },
{ "A9", "Deliver ATIS information" },
{ "A0", "ATIS Facilities notification" },
{ "AA", "ATC Communications" },
{ "AB", "Terminal Weather Information for Pilots (TWIP)" },
{ "AC", "Pushback clearance" },
{ "AD", "Expected taxi clearance" },
{ "AE", "Unassigned" },
{ "AF", "CPC Command Response" },
{ "AG", "Unassigned" },
{ "B1", "Request oceanic clearance" },
{ "B2", "Request oceanic readback" },
{ "B3", "Request departure clearance" },
{ "B4", "Acknowledge departure clearance" },
{ "B5", "Provide position report" },
{ "B6", "Provide ADS report" },
{ "B7", "Forward free text to ATS" },
{ "B8", "Request departure slot" },
{ "B9", "Request ATIS information" },
{ "B0", "ATS Facility Notification (AFN)" },
{ "BA", "ATC communications" },
{ "BB", "Terminal Weather Information for Pilots (TWIP)" },
{ "BC", "Pushback clearance request" },
{ "BD", "Expected taxi clearance request" },
{ "BE", "CPC log-on/log-off request" },
{ "BF", "CPC WILCO/unassigned BLE response" },
{ "BG", "Unassigned" },
{ "C0", "Uplink message to all cockpit printers" },
{ "C1", "Uplink message to printer #1" },
{ "C2", "Uplink message to printer #2" },
{ "C3", "Uplink message to printer #3" },
{ "C4", "Uplink message to printer #4" },
{ "C5", "Uplink message to printer #5" },
{ "C6", "Uplink message to printer #6" },
{ "C7", "Uplink message to printer #7" },
{ "C8", "Uplink message to printer #8" },
{ "C9", "Uplink message to printer #9" },
{ "CA", "Printer status = error" },
{ "CB", "Printer status = busy" },
{ "CC", "Printer status = local" },
{ "CD", "Printer status = no paper" },
{ "CE", "Printer status = buffer overrun" },
{ "CF", "Printer status = reserved" },
{ "EI", "Internet e-mail message" },
{ "F3", "Dedicated transceiver advisory" },
{ "H1", "Message to/from terminal" },
{ "H2", "Meteorological report" },
{ "H3", "Icing report" },
{ "HX", "Undelivered uplink report" },
{ "M1", "IATA Departure message" },
{ "M2", "IATA Arrival message" },
{ "M3", "IATA Return to ramp message" },
{ "M4", "IATA Return from airborne message" },
{ "Q0", "ACARS link test" },
{ "Q1", "ETA Departure/arrival reports" },
{ "Q2", "ETA reports" },
{ "Q3", "Clock update" },
{ "Q4", "Voice circuit busy (response to 54)" },
{ "Q5", "Unable to process uplinked messages" },
{ "Q6", "Voice-to-ACARS change-over" },
{ "Q7", "Delay message" },
{ "QA", "Out/fuel report" },
{ "QB", "Off report" },
{ "QC", "On report" },
{ "QD", "In/fuel report" },
{ "QE", "Out/fuel destination report" },
{ "QF", "Off/destination report" },
{ "QG", "Out/return in report" },
{ "QH", "Out report" },
{ "QK", "Landing report" },
{ "QL", "Arrival report" },
{ "QM", "Arrival information report" },
{ "QN", "Diversion report" },
{ "QP", "OUT report" },
{ "QQ", "OFF report" },
{ "QR", "ON report" },
{ "QS", "IN report" },
{ "QT", "OUT/return IN report" },
{ "QX", "Intercept" },
{ "S1", "Network statistics request/response" },
{ "S2", "VHF performance report request" },
{ "S3", "LRU configuration request/response" },
{ "SA", "Media advisory" },
{ "SQ", "Squitter message" },
{ "X1", "Service provider defined DSP" },
{ "RA", "Command aircraft term. to transmit data" },
{ "RB", "Response of aircraft terminal to RA message" },
{ ":;", "Command aircraft xcvr to change frequency" },
{ "10", AirlineLab },
{ "11", AirlineLab },
{ "12", AirlineLab },
{ "13", AirlineLab },
{ "14", AirlineLab },
{ "15", AirlineLab },
{ "16", AirlineLab },
{ "17", AirlineLab },
{ "18", AirlineLab },
{ "19", AirlineLab },
{ "20", AirlineLab },
{ "21", AirlineLab },
{ "22", AirlineLab },
{ "23", AirlineLab },
{ "24", AirlineLab },
{ "25", AirlineLab },
{ "26", AirlineLab },
{ "27", AirlineLab },
{ "28", AirlineLab },
{ "29", AirlineLab },
{ "30", AirlineLab },
{ "31", AirlineLab },
{ "32", AirlineLab },
{ "33", AirlineLab },
{ "34", AirlineLab },
{ "35", AirlineLab },
{ "36", AirlineLab },
{ "37", AirlineLab },
{ "38", AirlineLab },
{ "39", AirlineLab },
{ "40", AirlineLab },
{ "41", AirlineLab },
{ "42", AirlineLab },
{ "43", AirlineLab },
{ "44", AirlineLab },
{ "45", AirlineLab },
{ "46", AirlineLab },
{ "47", AirlineLab },
{ "48", AirlineLab },
{ "49", AirlineLab },
{ "4~", AirlineLab }
};
int _lcompare(const struct kv *l1, const struct kv *l2)
{
return strcmp(l1->key, l2->key);
}
void explain(FILE *fp, char *lstr)
{
struct kv key, *expl;
static bool unsorted = true;
if (unsorted) {
mergesort(
&explanations[0],
sizeof(explanations) / sizeof(explanations[0]),
sizeof(explanations[0]),
(int (*)(const void *, const void *)) _lcompare);
unsorted = false;
}
key.key = lstr;
expl = bsearch(
&key,
&explanations[0],
sizeof(explanations) / sizeof(key),
sizeof(key),
(int (*)(const void *, const void *)) _lcompare);
fputs(expl == NULL ? "Unknown" : expl->value, fp);
}
char UnknownH1[] = "Unknown";
char AirlineH1[] = "Airline defined";
char TerminalH1[] = "Cabin terminal";
struct kv h1_expl[] = {
{ "CF", "Central fault data indicator" },
{ "DF", "Flight data recorder" },
{ "EC", "Engine display system" },
{ "EI", "Engine report" },
{ "H1", "HF data radio #1" },
{ "H2", "HF data radio #2" },
{ "HD", "HF data radio" },
{ "M1", "Flight management computer #1" },
{ "M2", "Flight management computer #2" },
{ "M3", "Flight management computer #3" },
{ "MD", "Flight management computer" },
{ "PS", "Keyboard/display unit" },
{ "S1", "Satellite data unit #1" },
{ "S2", "Satellite data unit #2" },
{ "SD", "Satellite data unit" },
{ "T0", TerminalH1 },
{ "T1", TerminalH1 },
{ "T2", TerminalH1 },
{ "T3", TerminalH1 },
{ "T4", TerminalH1 },
{ "T5", TerminalH1 },
{ "T6", TerminalH1 },
{ "T7", TerminalH1 },
{ "T8", TerminalH1 },
{ "WO", "Weather observation" }
};
void explain_h1(FILE *fp, char *mbody)
{
struct kv key, *expl;
static bool unsorted = true;
char keybuf[3];
char *rret, *mstart;
int skipped;
if (unsorted) {
mergesort(
&h1_expl[0],
sizeof(h1_expl) / sizeof(h1_expl[0]),
sizeof(h1_expl[0]),
(int (*)(const void *, const void *)) _lcompare);
unsorted = false;
}
for (mstart=mbody, skipped=0; *mstart && skipped < 4; mstart++, skipped++) {
if (*mstart == '#')
break;
}
if (strlen(mstart) < 3 || mstart[0] != '#') {
fputs(UnknownH1, fp);
return;
}
keybuf[0] = mstart[1];
keybuf[1] = mstart[2];
keybuf[2] = '\0';
key.key = keybuf;
if (keybuf[0] >= '0' && keybuf[0] <= '9') {
fprintf(fp, "%s (%s)", keybuf, AirlineH1);
return;
}
expl = bsearch(
&key,
&h1_expl[0],
sizeof(h1_expl) / sizeof(key),
sizeof(key),
(int (*)(const void *, const void *)) _lcompare);
rret = expl == NULL ? UnknownH1 : expl->value;
fprintf(fp, "%s (%s)", keybuf, rret);
}