asterix_parser 0.1.1

Playground do Protocolo ASTERIX
Documentation
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
/// This file is here only to document the content of the example message,
/// and is not intended for production use, just for tests
//
// DataRef.Item No.    Description	                                        System Units
// I048/010            Data Source Identifier 	                            N.A. 
// I048/020 	        Target Report Descriptor 	                        N.A. 
// I048/030 	        Warning/Error Conditions/Target Classification	    N.A. 
// I048/040 	        Measured Position in Slant Polar Co-ordinates	    RHO: 1/256 NM THETA: 360°/(216) 
// I048/042 	        Calculated Position in Cartesian Co-ordinates	    X, Y: 1/128 NM 
// I048/050 	        Mode-2 Code in Octal Representation 	            N.A. 
// I048/055 	        Mode-1 Code in Octal Representation 	            N.A. 
// I048/060 	        Mode-2 Code Confidence Indicator 	                N.A. 
// I048/065 	        Mode-1 Code Confidence Indicator 	                N.A. 
// I048/070 	        Mode-3/A Code in Octal Representation 	            N.A. 
// I048/080 	        Mode-3/A Code Confidence Indicator                  N.A. 
// I048/090 	        Flight Level in Binary Representation 	            1/4 FL 
// I048/100 	        Mode-C Code and Confidence Indicator 	            N.A. 
// I048/110 	        Height Measured by a 3D Radar 	                    25 ft 
// I048/120 	        Radial Doppler Speed 	                            N.A. 
// I048/130 	        Radar Plot Characteristics 	                        N.A. 
// I048/140 	        Time of Day 	                                    1/128 s 
// I048/161 	        Track/Plot Number 	                                N.A. 
// I048/170 	        Track Status 	                                    N.A. 
// I048/200 	        Calculated Track Velocity in Polar Representation 	Speed: (2-14) NM/s Heading:360°/(216) 
// I048/210 	        Track Quality 	                                    N.A. 
// I048/220 	        Aircraft Address 	                                N.A. 
// I048/230 	        Communications / ACAS Capability and FlightStatus 	N.A. 
// I048/240 	        Aircraft Identification 	                        N.A. 
// I048/250 	        Mode S MB Data 	                                    N.A. 
// I048/260 	        ACAS Resolution Advisory Report 	                N.A. 
// 
// Message bytes: 
//     message_bytes.append(&mut vec![0x30, 0x00, 0x30, 0xFD, 
//                                     0xF7, 0x02, 0x19, 0xC9,
//                                     0x35, 0x6D, 0x4D, 0xA0, 
//                                     0xC5, 0xAF, 0xF1, 0xE0, 
//                                     0x02, 0x00, 0x05, 0x28, 
//                                     0x3C, 0x66, 0x0C, 0x10, 
//                                     0xC2, 0x36, 0xD4, 0x18, 
//                                     0x20, 0x01, 0xC0, 0x78, 
//                                     0x00, 0x31, 0xBC, 0x00, 
//                                     0x00, 0x40, 0x0D, 0xEB, 
//                                     0x07, 0xB9, 0x58, 0x2E, 
//                                     0x41, 0x00, 0x20, 0xF5]); 
pub fn get_example_message() -> Vec<u8> {
    let mut message_bytes = Vec::<u8>::new();

    // Composed with 1 DataBlock, containing 1 DataRecord
    
    // Add CAT code
    message_bytes.push(0x30);

    // Add LEN 
    message_bytes.append(&mut vec![0x00, 0x30]);

    // Add FSPEC 
    // 1st FSPEC octet
    message_bytes.push(get_1st_fspec(0xFD as u8));

    // 2nd FSPEC octet
    message_bytes.push(get_2nd_fspec(0xF7 as u8));

    // 3rd FSPEC octet
    message_bytes.push(get_3rd_fspec(0x02 as u8));

    message_bytes.append(&mut get_i048_010(0x19, 0xC9));

    message_bytes.append(&mut get_i048_140(0x35, 0x6D, 0x4D));
    
    /* Here we have a variable length octets field, see the comments inside method */
    message_bytes.append(&mut get_i048_020(vec![0xA0]));

    message_bytes.append(&mut get_i048_040(0xC5, 0xAF, 0xF1, 0xE0));

    message_bytes.append(&mut get_i048_070(0x02, 0x00));

    message_bytes.append(&mut get_i048_090(0x05, 0x28));

    /* No method get_i048_130, since it is absent according to 1st FSPEC */
    
    message_bytes.append(&mut get_i048_220(0x3C, 0x66, 0x0C));

    message_bytes.append(&mut get_i048_240(0x10, 0xC2, 0x36, 0xD4, 0x18, 0x20));
    
    message_bytes.append(&mut get_i048_250(0x01, 0xC0, 0x78, 
                                           0x00, 0x31, 0xBC, 
                                           0x00, 0x00, 0x40));

    message_bytes.append(&mut get_i048_161(0x0D, 0xEB));
        
    /* No method get_i048_042, since it is absent according to 2nd FSPEC */

    message_bytes.append(&mut get_i048_200(0x07, 0xB9, 0x58, 0x2E));

    message_bytes.append(&mut get_i048_170(0x41, 0x00));

    /* No method get_i048_210, since it is absent according to 3rd FSPEC */
    /* No method get_i048_030, since it is absent according to 3rd FSPEC */
    /* No method get_i048_080, since it is absent according to 3rd FSPEC */
    /* No method get_i048_100, since it is absent according to 3rd FSPEC */
    /* No method get_i048_110, since it is absent according to 3rd FSPEC */
    /* No method get_i048_120, since it is absent according to 3rd FSPEC */

    message_bytes.append(&mut get_i048_230(0x20, 0xF5));

    /* No more data items since FX is not set at 3rd FSPEC */
    
    message_bytes
}

// Function present only for documentation purpose
fn get_1st_fspec(arg: u8) -> u8 {
    assert_eq!(0xFD, arg);
    // First FSPEC = 0b11111101 (0xFD)
    /*  Data Items
        0
        b
        1 present      1,I048/010 ,Data Source Identifier
        1 present      2,I048/140 ,Time-of-Day
        1 present      3,I048/020 ,Target Report Descriptor
        1 present      4,I048/040 ,Measured Position in Slant Polar Coordinates
        1 present      5,I048/070 ,Mode-3/A Code in Octal Representation
        1 present      6,I048/090 ,Flight Level in Binary Representation
        0 absent       7,I048/130 ,Radar Plot Characteristics 
        1 present      FX ,n.a.   ,Field Extension Indicator
    */
    let fspec0: u8 = arg;
    fspec0 
}

// Function present only for documentation purpose
fn get_2nd_fspec(arg: u8) -> u8 {
    assert_eq!(0xF7, arg);
    // Second FSPEC = 0b11110111 (0xF7)
    /*  Data Items
        0
        b
        1 present      8,I048/220  ,Aircraft Address
        1 present      9,I048/240  ,Aircraft Identification
        1 present      10,I048/250 ,Mode S MB Data
        1 present      11,I048/161 ,Track Number
        0 absent       12,I048/042 ,Calculated Position in Cartesian Coordinates
        1 present      13,I048/200 ,Calculated Track Velocity in Polar Representation
        1 present      14,I048/170 ,Track Status
        1 present      FX ,n.a.    ,Field Extension Indicator
    */
    let fspec1: u8 = arg;
    fspec1 
}

// Function present only for documentation purpose
fn get_3rd_fspec(arg: u8) -> u8 {
    assert_eq!(0x02, arg);
    // Third FSPEC = 0b00000010 (0x02)
    /*  Data Items
        0
        b
        0 absent       15,I048/210,Track Quality,4,N.A. 
        0 absent       16,I048/030,Warning/Error Conditions/Target Classification,1+,N.A. 
        0 absent       17,I048/080,Mode-3/A Code Confidence Indicator,2,N.A. 
        0 absent       18,I048/100,Mode-C Code and Confidence Indicator,4,N.A. 
        0 absent       19,I048/110,Height Measured by 3D Radar,2,25 ft 
        0 absent       20,I048/120,Radial Doppler Speed,1+,N.A. 
        1 present      21,I048/230,Communications / ACAS Capability and Flight Status,2,N.A. 
        0 absent       FX,n.a.,Field Extension Indicator,n.a.,
    */
    let fspec1: u8 = arg;
    fspec1 
}

fn get_i048_010(sac: u8, sic:u8 ) -> Vec<u8>  {
    assert_eq!(0x19, sac);
    assert_eq!(0xC9, sic);
    let i048_010 = vec![sac, sic];
    i048_010
}

fn get_i048_020(vec: Vec<u8>) -> Vec<u8> {
    assert_eq!(1, vec.len());
    assert_eq!(0xA0, vec[0]);
    /* Here we have a variable length octets field, the octets could have set FX (field extent indicator) 
       but this is not the case, since 0xA0 converts to 0b10100000 meaning:
        0
        b
        101,    bits 8-6 (TYP) 000 No detection
                               001 Single PSR detection
                               010 Single SSR detection
                               011 SSR + PSR detection
                               100 Single ModeS All-Call
                               101 Single ModeS Roll-Call
                               110 ModeS All-Call + PSR
                               111 ModeS Roll-Call +PSR	        
        0,      bit  5 (SIM) 0 Actual target report
                             1 Simulated target report 
        0,      bit  4 (RDP) 0 Report from RDP Chain 1 
                             1 Report from RDP Chain 2 
        0,      bit  3 (SPI) 0 Absence of SPI 
                             1 Special Position Identification 
        0,      bit  2 (RAB) 0 Report from aircraft transponder 
                             1 Report from field monitor (fixed transponder) 
        0,      bit  1 (FX)  0 End of Data Item 
                             1 Extension into first extent 
    */

    vec
}

fn get_i048_040(rho_octet1: u8, rho_octet2: u8, theta_octet1: u8, theta_octet2: u8) -> Vec<u8> {
    assert_eq!(0xC5, rho_octet1);
    assert_eq!(0xAF, rho_octet2);
    assert_eq!(0xF1, theta_octet1);
    assert_eq!(0xE0, theta_octet2);

    /* 
        bit-17 (LSB) =1/256 NM. Max. range = 256-(1/256) NM
        bit-1 (LSB) = 360°/ 2**16 = approx. 0.0055°
     */
    vec![rho_octet1, rho_octet2, theta_octet1, theta_octet2]
}

fn get_i048_070(octet1: u8, octet2: u8) -> Vec<u8> {
    assert_eq!(0x02, octet1);
    assert_eq!(0x00, octet2);
    /* 
    bit-16 (V)  = 0 Code validated
                = 1 Code not validated
    bit-15 (G)  = 0 Default
                = 1 Garbled code
    bit-14 (L)  = 0 Mode-3/A code derived from the reply of the transponder
                = 1 Mode-3/A code not extracted during the last scan
    bit-13      = Spare bit set to 0
    bits-12/1   = Mode-3/A reply in octal representation
    */
    vec![octet1, octet2]
}

fn get_i048_090(octet1: u8, octet2: u8) -> Vec<u8> {
    assert_eq!(0x05, octet1);
    assert_eq!(0x28, octet2);
    /* 
    bit-16 (V)  = 0 Code validated
                = 1 Code not validated
    bit-15 (G)  = 0 Default
                = 1 Garbled code
    bits-14/1   = Flight Level, LSB= 1/4 FL
    */
    vec![octet1, octet2]
}


fn get_i048_140(octet1: u8, octet2: u8, octet3: u8) -> Vec<u8> {
    assert_eq!(0x35, octet1);
    assert_eq!(0x6D, octet2);
    assert_eq!(0x4D, octet3);
    vec![octet1, octet2, octet3]
}
fn get_i048_161(octet1: u8, octet2: u8) -> Vec<u8> {
    assert_eq!(0x0D, octet1);
    assert_eq!(0xEB, octet2);
    /* bits-16/13      Spare bits
       bits 12-1       Track number*/
    vec![octet1, octet2]
}

fn get_i048_170(octet1: u8, octet2: u8) -> Vec<u8> {
    assert_eq!(0x41, octet1);
    assert_eq!(0x00, octet2);

    /* 1st Octet
    bit-8       (CNF)   Confirmed vs. Tentative Track 
                        =0 Confirmed Track 
                        =1 Tentative Track 
    bits-7/6    (RAD)   Type of Sensor(s) maintaining Track 
                        =00 Combined Track 
                        =01 PSR Track 
                        =10 SSR/Mode S Track 
                        =11 Invalid 
    bit-5       (DOU)   Signals level of confidence in plot to track association process 
                        =0 Normal confidence 
                        =1 Low confidence in plot to track association. 
    bit-4       (MAH)   Manoeuvre detection in Horizontal Sense 
                        =0 No horizontal man.sensed 
                        =1 Horizontal man. sensed 
    bits-3/2    (CDM)   Climbing / Descending Mode 
                        =00 Maintaining
                        =01 Climbing 
                        =10 Descending 
                        =11 Unknown 
    bit-1       (FX)    Field extent
                        =0 End of Data Item 
                        =1 Extension into first extent 

    2nd Octet (if present - see FX above)
    bit-8 	(TRE) 		Signal for End_of_Track 
		                =0 	Track still alive
                        =1 	End of track lifetime(last report for this track) 
    bit-7 	(GHO) 		Ghost vs. true target 
                        =0 	True target track. 
                        =1 	Ghost target track. 
    bit-6 	(SUP) 		Track maintained with track information from neighbouring Node B on the cluster, or network 
		                =0 	no 
                        =1 	yes 
    bit-5 	(TCC) 		Type of plot coordinate transformation mechanism: 
                 		=0 	Tracking performed in so-called 'Radar Plane', i.e. neither slant range correction 
                            nor stereographical projection was applied. 
		                =1 	Slant range correction and a suitable projection technique are used to track in a 
                            2D.reference plane, tangential to the earth model at the Radar Site co-ordinates. 
    bits-4/2 (spare)    Spare bits, set to 0 
    bit-1 	(FX) 	    Field extent
                        =0 	End of Data Item 
                        =1 	Extension into second extent 
    */
    vec![octet1, octet2]
}


fn get_i048_200(ground_speed_octet1: u8, ground_speed_octet2: u8, heading_octet1: u8, heading_octet2: u8) -> Vec<u8> {
    assert_eq!(0x07, ground_speed_octet1);
    assert_eq!(0xB9, ground_speed_octet2);
    assert_eq!(0x58, heading_octet1);
    assert_eq!(0x2E, heading_octet2);

    /*
        bits 32-17  (LSB)  =  (2**-14) NM/s = approx. 0.22 kt
        bits 16-1   (LSB)  =  360°/ 2**16  = approx. 0.0055°
     */
    vec![ground_speed_octet1, ground_speed_octet2, heading_octet1, heading_octet2]
}

fn get_i048_220(octet1: u8, octet2: u8, octet3: u8) -> Vec<u8> {
    assert_eq!(0x3C, octet1);
    assert_eq!(0x66, octet2);
    assert_eq!(0x0C, octet3);

    /* bits-24/1 24-bits Mode S address, A23 to A0 */
    vec![octet1, octet2, octet3]
}

fn get_i048_230(octet1: u8, octet2: u8) -> Vec<u8> {
    assert_eq!(0x20, octet1);
    assert_eq!(0xF5, octet2);
    /*
    bits-16/14	(COM)   Communications capability of the transponder 
		                = 0  No communications capability (surveillance only) 
		                = 1  Comm. A and Comm. B capability 
		                = 2  Comm. A, Comm. B and Uplink ELM 
                        = 3  Comm. A, Comm. B, Uplink ELM and Downlink ELM 
                		= 4  Level 5 Transponder capability 
		                5 to 7 Not assigned 
    bits-13/11	(STAT) 	Flight Status 
		                = 0  No alert, no SPI, aircraft airborne 
                        = 1  No alert, no SPI, aircraft on ground 
		                = 2  Alert, no SPI, aircraft airborne 
		                = 3  Alert, no SPI, aircraft on ground 
		                = 4  Alert, SPI, aircraft airborne or on ground 
		                = 5  No alert, SPI, aircraft airborne or on ground 
		                = 6  Not assigned 
		                = 7  Unknown 
    bit-10  	(SI) 	SI/II Transponder Capability 
		                = 0  SI-Code Capable 
                        = 1  II-Code Capable 
    bit-9  	    (spare)	spare bit set to zero 
    bit-8  	    (MSSC)  Mode-S Specific Service Capability 
                        = 0  No 
		                = 1  Yes 
    bit-7  	    (ARC)   Altitude reporting capability 
		                = 0  100 ft resolution 
		                = 1  25 ft resolution 
    bit-6  	    (AIC)   Aircraft identification capability 
		                = 0  No 
		                = 1  Yes 
    bit-5  	    (B1A)   BDS 1,0 bit 16 
    bits 4/1    (B1B) 	BDS 1,0 bits 37/40 
    */
    vec![octet1, octet2]
}


fn get_i048_240(octet1: u8, octet2: u8, octet3: u8, octet4: u8, octet5: u8, octet6: u8) -> Vec<u8> {
    assert_eq!(0x10, octet1);
    assert_eq!(0xC2, octet2);
    assert_eq!(0x36, octet3);
    assert_eq!(0xD4, octet4);
    assert_eq!(0x18, octet5);
    assert_eq!(0x20, octet6);
    /* bits-48/1 Characters 1-8 (coded on 6 bits each) defining
                 aircraft identification when flight plan is available or
                 the registration marking when no flight plan is
                 available. */
    vec![octet1, octet2, octet3, octet4, octet5, octet6]
}

fn get_i048_250(octet1: u8, octet2: u8, octet3: u8, 
                octet4: u8, octet5: u8, octet6: u8,
                octet7: u8, octet8: u8, octet9: u8) -> Vec<u8> {
        assert_eq!(0x01, octet1);
        assert_eq!(0xC0, octet2);
        assert_eq!(0x78, octet3);
        assert_eq!(0x00, octet4);
        assert_eq!(0x31, octet5);
        assert_eq!(0xBC, octet6);
        assert_eq!(0x00, octet7);
        assert_eq!(0x00, octet8);
        assert_eq!(0x40, octet9);
        /* bits-72/65 (REP)     Repetition factor
        bits-64/9  (BDSDATA) 56-bit message conveying BDS Register Data
        bits-8/5   (BDS1)    BDS Register Address 1
        bits-4/1   (BDS2)    BDS Register Address 2 */
        vec![octet1, octet2, octet3, octet4, octet5, octet6, octet7, octet8, octet9]
}