summaryrefslogtreecommitdiff
path: root/ADSBDecoderFramework/ADSBTypeCodeAirbonePositon.swift
blob: b6a302addd923986fa520230e732fc8991ef6ca0 (plain) (blame)
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
//
//  ADSBTypeCodeAirbonePositon.swift
//  ADSBDecoder
//
//  Created by Jacky Jack on 27/09/2026.
//

//DF17 message types codes  8 to 18
public class ADSBTypeCodeAirbonePositon:CustomStringConvertible {
    var TypeCode:Int = 11
    var SurveillanceStatus: Int = 0
    var SingleAntennaFlag: Int = 0
    public var Altitude: Int = 0
    var Time: Int = 0
    public var CPRFormat: Int = 0
    public var Latitude: Int = 0
    public var Longitude: Int = 0

    public init(_ bindata:ArraySlice<UInt8>) {
        let ss = (bindata[4]>>1)&(0x3)
        SurveillanceStatus = Int(ss)
        let saf = bindata[5]&0x1
        SingleAntennaFlag = Int(saf)
        let altitude = UInt16(bindata[5])<<4 + (UInt16(bindata[6])>>4)&0xf
        //print(altitude)
        Altitude = BarometricAltitudeFeat(altitude)
        let time = (bindata[6]>>3)&0x1
        Time = Int(time)
        let cpr = (bindata[6]>>2)&0x1
        CPRFormat = Int(cpr)
        let lat:UInt32 = UInt32(bindata[6]&0x3)<<15 + UInt32(bindata[7])<<7 + UInt32(bindata[8]>>1)
        Latitude = Int(lat)
        let lon:UInt32 = UInt32(bindata[8]&0x1)<<16 + UInt32(bindata[9])<<8 + UInt32(bindata[10])
        Longitude = Int(lon)
    }
    
    public var description: String {
        var description = "SS \(SurveillanceStatus) SAF \(SingleAntennaFlag) Altitude \(Altitude)ft \n"
        description += "Time \(Time) CPR \(CPRFormat)"
        if (CPRFormat == 0) {
            description += "even"
        } else {
            description += "odd"
        }
        description += "\n"
        description += "Lat \(Latitude) Long \(Longitude)"
        return description
    }
}