summaryrefslogtreecommitdiff
path: root/ADSBDecoderFramework/DataFormat17.swift
diff options
context:
space:
mode:
Diffstat (limited to 'ADSBDecoderFramework/DataFormat17.swift')
-rw-r--r--ADSBDecoderFramework/DataFormat17.swift100
1 files changed, 100 insertions, 0 deletions
diff --git a/ADSBDecoderFramework/DataFormat17.swift b/ADSBDecoderFramework/DataFormat17.swift
new file mode 100644
index 0000000..e1ea428
--- /dev/null
+++ b/ADSBDecoderFramework/DataFormat17.swift
@@ -0,0 +1,100 @@
+//
+// DataFormat17.swift
+// ADSBDecoder
+//
+// Created by Jacky Jack on 27/09/2026.
+//
+
+import Foundation
+
+public class DataFormat17 {
+
+ let DataFormat=17 //0:5
+ var Capability=0 //5:7
+ public var AddressAnnounced=0 //8:31
+ public var TypeCode=0 //32:36
+ var MovementField=0//37:43
+ var HeadingBit=0//44
+ var HeadingField=0//45:51
+ //var CPROddEven=0//53
+ //var CPRlat=0//54:70
+ //var CPRlon=0//71:87
+ var ParityIntegrity=0//88-111
+
+ //all avaliable message types
+ public var messageIdentification:ADSBTypeCodeIndentification? = nil
+ public var messageAirbornPositon:ADSBTypeCodeAirbonePositon? = nil
+
+ public init(_ adsb_data: String) {
+ //print("Dataformat: 17!")
+ //print(adsb_data)
+
+ var bindata:[UInt8] = []
+
+ var startN = adsb_data.startIndex
+ var endN = adsb_data.index(startN, offsetBy: 1)
+ var count=0//start index value
+ while (count<adsb_data.count) {
+ let u8 = UInt8(adsb_data[startN...endN], radix: 16)!
+ //print(adsb_data[startN...endN])
+ bindata.append(u8)
+ count += 2
+ if (count<adsb_data.count) {
+ startN = adsb_data.index(startN, offsetBy: 2)
+ endN = adsb_data.index(startN, offsetBy: 1)
+ }
+ }
+ //print(bindata)
+
+ //Decode Capability
+ let cap = (bindata[0]>>1)&0x7
+ //print(String(format: "cap %02x", cap))
+ Capability = Int(cap)
+
+ //Decode Address Announcement
+ let address_ann = UInt32(bindata[1])<<16 + UInt32(bindata[2])<<8 + UInt32(bindata[3])
+ //print(String(format: "address %06x", address_ann))
+
+ AddressAnnounced = Int(address_ann)
+
+ //Decode Type Code
+ let tc_byte = bindata[4] >> 3
+ //print(String(format: "tc %02d", tc_byte))
+
+ TypeCode = Int(tc_byte)
+
+ //aircraft indentification and category
+ if (tc_byte == 4) {
+ let msg = ADSBTypeCodeIndentification(bindata[4...10])
+ if decoder_debug_mode {
+ print("=====ADSB MESSSGE 04 =======")
+ print(msg)
+ print("============================")
+ }
+
+ messageIdentification = msg
+ //airborn position
+ } else if ((tc_byte >= 8) && (tc_byte <= 18)) {
+ let msg = ADSBTypeCodeAirbonePositon(bindata[4...10])
+ if decoder_debug_mode {
+ print(String(format:"=====ADSB MESSSGE %02d ======= AA:%04d", tc_byte, AddressAnnounced))
+ print(msg)
+ print("============================")
+ }
+
+ messageAirbornPositon = msg
+ //airborn velocity
+ } else if (tc_byte == 19) {
+ if decoder_debug_mode {
+ print("=====ADSB MESSSGE 19 =======")
+ print("=====VELOCITY =======")
+ }
+ } else {
+ if decoder_debug_mode {
+ print("=====ADSB MESSSGE UNKNOWN =======")
+ }
+ }
+ }
+}
+
+