forked from TLeconte/acarsdec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
label.c
427 lines (411 loc) · 9.74 KB
/
label.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "acarsdec.h"
static char *lblfilter[1024];
void build_label_filter(char *arg)
{
int i=0;
char *aptr;
lblfilter[0]=NULL;
if(arg==NULL) return;
aptr=strtok(strdup(arg),":");
while(aptr) {
lblfilter[i]=aptr; i++;
aptr=strtok(NULL,":");
}
lblfilter[i]=NULL;
}
int label_filter(char *lbl)
{
int i;
if(lblfilter[0]==NULL) return 1;
i=0;
while(lblfilter[i]) {
if(strcmp(lbl,lblfilter[i])==0) return 1;
i++;
}
return 0;
}
static int label_q1(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->gout,&(txt[4]),4);
memcpy(oooi->woff,&(txt[8]),4);
memcpy(oooi->won,&(txt[12]),4);
memcpy(oooi->gin,&(txt[16]),4);
memcpy(oooi->da,&(txt[24]),4);
return 1;
}
static int label_q2(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->eta,&(txt[4]),4);
return 1;
}
static int label_qa(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->gout,&(txt[4]),4);
return 1;
}
static int label_qb(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->woff,&(txt[4]),4);
return 1;
}
static int label_qc(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->won,&(txt[4]),4);
return 1;
}
static int label_qd(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->gin,&(txt[4]),4);
return 1;
}
static int label_qe(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->gout,&(txt[4]),4);
memcpy(oooi->da,&(txt[8]),4);
return 1;
}
static int label_qf(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->woff,&(txt[4]),4);
memcpy(oooi->da,&(txt[8]),4);
return 1;
}
static int label_qg(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->gout,&(txt[4]),4);
memcpy(oooi->gin,&(txt[8]),4);
return 1;
}
static int label_qh(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->gout,&(txt[4]),4);
return 1;
}
static int label_qk(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->won,&(txt[4]),4);
memcpy(oooi->da,&(txt[8]),4);
return 1;
}
static int label_ql(char *txt,oooi_t *oooi)
{
memcpy(oooi->da,txt,4);
memcpy(oooi->gin,&(txt[8]),4);
memcpy(oooi->sa,&(txt[13]),4);
return 1;
}
static int label_qm(char *txt,oooi_t *oooi)
{
memcpy(oooi->da,txt,4);
memcpy(oooi->sa,&(txt[8]),4);
return 1;
}
static int label_qn(char *txt,oooi_t *oooi)
{
memcpy(oooi->da,&(txt[4]),4);
memcpy(oooi->eta,&(txt[8]),4);
return 1;
}
static int label_qp(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->da,&(txt[4]),4);
memcpy(oooi->gout,&(txt[8]),4);
return 1;
}
static int label_qq(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->da,&(txt[4]),4);
memcpy(oooi->woff,&(txt[8]),4);
return 1;
}
static int label_qr(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->da,&(txt[4]),4);
memcpy(oooi->won,&(txt[8]),4);
return 1;
}
static int label_qs(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->da,&(txt[4]),4);
memcpy(oooi->gin,&(txt[8]),4);
return 1;
}
static int label_qt(char *txt,oooi_t *oooi)
{
memcpy(oooi->sa,txt,4);
memcpy(oooi->da,&(txt[4]),4);
memcpy(oooi->gout,&(txt[8]),4);
memcpy(oooi->gin,&(txt[12]),4);
return 1;
}
static int label_20(char *txt,oooi_t *oooi)
{
if(memcmp(txt,"RST",3)) return 0;
memcpy(oooi->sa,&(txt[22]),4);
memcpy(oooi->da,&(txt[26]),4);
return 1;
}
static int label_21(char *txt,oooi_t *oooi)
{
if(txt[6]!=',') return 0;
memcpy(oooi->sa,&(txt[7]),4);
if(txt[11]!=',') return 0;
memcpy(oooi->da,&(txt[12]),4);
return 1;
}
static int label_26(char *txt,oooi_t *oooi)
{
char *p;
if(memcmp(txt,"VER/077",7)) return 0;
p=strchr(txt,'\n'); if(p==NULL) return 0;
p++;
if(memcmp(p,"SCH/",4)) return 0;
p=strchr(p+4,'/'); if(p==NULL) return 0;
memcpy(oooi->sa,p+1,4);
memcpy(oooi->da,p+6,4);
p=strchr(p,'\n'); if(p==NULL) return 1;
p++;
if(memcmp(p,"ETA/",4)) return 0;
memcpy(oooi->eta,p+4,4);
return 1;
}
static int label_2N(char *txt,oooi_t *oooi)
{
if(memcmp(txt,"TKO01",5)) return 0;
if(txt[11]!='/') return 0;
memcpy(oooi->sa,&(txt[20]),4);
memcpy(oooi->da,&(txt[24]),4);
return 1;
}
static int label_2Z(char *txt,oooi_t *oooi)
{
memcpy(oooi->da,txt,4);
return 1;
}
static int label_33(char *txt,oooi_t *oooi)
{
if(txt[0]!=',') return 0;
if(txt[20]!=',') return 0;
memcpy(oooi->sa,&(txt[21]),4);
if(txt[25]!=',') return 0;
memcpy(oooi->da,&(txt[26]),4);
return 1;
}
static int label_39(char *txt,oooi_t *oooi)
{
if(memcmp(txt,"GTA01",5)) return 0;
if(txt[15]!='/') return 0;
memcpy(oooi->sa,&(txt[24]),4);
memcpy(oooi->da,&(txt[28]),4);
return 1;
}
static int label_44(char *txt,oooi_t *oooi)
{
if(txt[0]=='0') {
if(txt[1]!='0') return 0;
txt+=2;
}
if(memcmp(txt,"POS0",4) && memcmp(txt,"ETA0",4)) return 0;
if(txt[4]!='2' && txt[4]!='3') return 0;
if(txt[23]!=',') return 0;
memcpy(oooi->da,&(txt[24]),4);
if(txt[28]!=',') return 0;
memcpy(oooi->eta,&(txt[29]),4);
if(txt[33]!=',') return 0;
if(txt[38]!=',') return 0;
if(txt[43]!=',') return 0;
memcpy(oooi->eta,&(txt[44]),4);
return 1;
}
static int label_45(char *txt,oooi_t *oooi)
{
if(txt[0]!='A') return 0;
memcpy(oooi->da,&(txt[1]),4);
return 1;
}
static int label_10(char *txt,oooi_t *oooi)
{
if(memcmp(txt,"ARR01",5)) return 0;
memcpy(oooi->da,&(txt[12]),4);
memcpy(oooi->eta,&(txt[16]),4);
return 1;
}
static int label_11(char *txt,oooi_t *oooi)
{
if(memcmp(&(txt[13]),"/DS ",4)) return 0;
memcpy(oooi->da,&(txt[17]),4);
if(memcmp(&(txt[21]),"/ETA ",5)) return 0;
memcpy(oooi->eta,&(txt[26]),4);
return 1;
}
static int label_12(char *txt,oooi_t *oooi)
{
if(txt[4]!=',') return 0;
memcpy(oooi->sa,txt,4);
memcpy(oooi->da,&(txt[5]),4);
return 1;
}
static int label_15(char *txt,oooi_t *oooi)
{
if(memcmp(txt,"FST01",5)) return 0;
memcpy(oooi->sa,&(txt[5]),4);
memcpy(oooi->da,&(txt[9]),4);
return 1;
}
static int label_17(char *txt,oooi_t *oooi)
{
if(memcmp(txt,"ETA ",4)) return 0;
memcpy(oooi->eta,&(txt[4]),4);
if(txt[8]!=',') return 0;
memcpy(oooi->sa,&(txt[9]),4);
if(txt[13]!=',') return 0;
memcpy(oooi->da,&(txt[14]),4);
return 1;
}
static int label_1G(char *txt,oooi_t *oooi)
{
if(txt[4]!=',') return 0;
memcpy(oooi->sa,txt,4);
memcpy(oooi->da,&(txt[5]),4);
return 1;
}
static int label_80(char *txt,oooi_t *oooi)
{
if(memcmp(&(txt[6]),"/DEST/",5)) return 0;
memcpy(oooi->da,&(txt[12]),4);
return 1;
}
static int label_83(char *txt,oooi_t *oooi)
{
if(txt[4]!=',') return 0;
memcpy(oooi->sa,txt,4);
memcpy(oooi->da,&(txt[5]),4);
return 1;
}
static int label_8D(char *txt,oooi_t *oooi)
{
if(txt[4]!=',') return 0;
if(txt[35]!=',') return 0;
memcpy(oooi->sa,&(txt[36]),4);
if(txt[40]!=',') return 0;
memcpy(oooi->da,&(txt[41]),4);
return 1;
}
static int label_8e(char *txt,oooi_t *oooi)
{
if(txt[4]!=',') return 0;
memcpy(oooi->da,txt,4);
memcpy(oooi->eta,&(txt[5]),4);
return 1;
}
static int label_8s(char *txt,oooi_t *oooi)
{
if(txt[4]!=',') return 0;
memcpy(oooi->da,txt,4);
memcpy(oooi->eta,&(txt[5]),4);
return 1;
}
int DecodeLabel(acarsmsg_t *msg,oooi_t *oooi)
{
int ov=0;
memset(oooi,0,sizeof(oooi_t));
switch(msg->label[0]) {
case '1' :
if(msg->label[1]=='0')
ov=label_10(msg->txt,oooi);
if(msg->label[1]=='1')
ov=label_11(msg->txt,oooi);
if(msg->label[1]=='2')
ov=label_12(msg->txt,oooi);
if(msg->label[1]=='5')
ov=label_15(msg->txt,oooi);
if(msg->label[1]=='7')
ov=label_17(msg->txt,oooi);
if(msg->label[1]=='G')
ov=label_1G(msg->txt,oooi);
break;
case '2' :
if(msg->label[1]=='0')
ov=label_20(msg->txt,oooi);
if(msg->label[1]=='1')
ov=label_21(msg->txt,oooi);
if(msg->label[1]=='6')
ov=label_26(msg->txt,oooi);
if(msg->label[1]=='N')
ov=label_2N(msg->txt,oooi);
if(msg->label[1]=='Z')
ov=label_2Z(msg->txt,oooi);
break;
case '3' :
if(msg->label[1]=='3')
ov=label_33(msg->txt,oooi);
if(msg->label[1]=='9')
ov=label_39(msg->txt,oooi);
break;
case '4' :
if(msg->label[1]=='4')
ov=label_44(msg->txt,oooi);
if(msg->label[1]=='5')
ov=label_45(msg->txt,oooi);
break;
case '8' :
if(msg->label[1]=='0')
ov=label_80(msg->txt,oooi);
if(msg->label[1]=='3')
ov=label_83(msg->txt,oooi);
if(msg->label[1]=='D')
ov=label_8D(msg->txt,oooi);
if(msg->label[1]=='E')
ov=label_8e(msg->txt,oooi);
if(msg->label[1]=='S')
ov=label_8s(msg->txt,oooi);
break;
case 'R' :
if(msg->label[1]=='B')
ov=label_26(msg->txt,oooi);
break;
case 'Q' :
switch(msg->label[1]) {
case '1':ov=label_q1(msg->txt,oooi);break;
case '2':ov=label_q2(msg->txt,oooi);break;
case 'A':ov=label_qa(msg->txt,oooi);break;
case 'B':ov=label_qb(msg->txt,oooi);break;
case 'C':ov=label_qc(msg->txt,oooi);break;
case 'D':ov=label_qd(msg->txt,oooi);break;
case 'E':ov=label_qe(msg->txt,oooi);break;
case 'F':ov=label_qf(msg->txt,oooi);break;
case 'G':ov=label_qg(msg->txt,oooi);break;
case 'H':ov=label_qh(msg->txt,oooi);break;
case 'K':ov=label_qk(msg->txt,oooi);break;
case 'L':ov=label_ql(msg->txt,oooi);break;
case 'M':ov=label_qm(msg->txt,oooi);break;
case 'N':ov=label_qn(msg->txt,oooi);break;
case 'P':ov=label_qp(msg->txt,oooi);break;
case 'Q':ov=label_qq(msg->txt,oooi);break;
case 'R':ov=label_qr(msg->txt,oooi);break;
case 'S':ov=label_qs(msg->txt,oooi);break;
case 'T':ov=label_qt(msg->txt,oooi);break;
}
break;
}
return ov;
}