diff options
| author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2026-09-27 10:24:48 +0100 |
|---|---|---|
| committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2026-09-27 10:24:48 +0100 |
| commit | fa8b756462fec42b23acbf253313c9292e43afed (patch) | |
| tree | 81b153638b18226feb254f44d0e8a7efababe69a /ADSBDecoderFramework | |
| parent | 40038b02ce651958ae703c8ecfe5f5578e1f7f09 (diff) | |
| download | ADSBDecoder-fa8b756462fec42b23acbf253313c9292e43afed.tar.gz ADSBDecoder-fa8b756462fec42b23acbf253313c9292e43afed.zip | |
remove from files multiple clases and put them in separate filesmain
Diffstat (limited to 'ADSBDecoderFramework')
| -rw-r--r-- | ADSBDecoderFramework/ADSBDecoderFramework.docc/ADSBDecoderFramework.md | 4 | ||||
| -rw-r--r-- | ADSBDecoderFramework/ADSBTypeCodeAirbonePositon.swift | 49 | ||||
| -rw-r--r-- | ADSBDecoderFramework/ADSBTypeCodeIndentification.swift | 34 | ||||
| -rw-r--r-- | ADSBDecoderFramework/AirplaneTracker.swift | 1 | ||||
| -rw-r--r-- | ADSBDecoderFramework/DataFormat17.swift | 100 | ||||
| -rw-r--r-- | ADSBDecoderFramework/Decoder.swift | 159 |
6 files changed, 185 insertions, 162 deletions
diff --git a/ADSBDecoderFramework/ADSBDecoderFramework.docc/ADSBDecoderFramework.md b/ADSBDecoderFramework/ADSBDecoderFramework.docc/ADSBDecoderFramework.md index 588e73d..6a75e2c 100644 --- a/ADSBDecoderFramework/ADSBDecoderFramework.docc/ADSBDecoderFramework.md +++ b/ADSBDecoderFramework/ADSBDecoderFramework.docc/ADSBDecoderFramework.md @@ -1,6 +1,6 @@ # ``ADSBDecoderFramework`` -<!--@START_MENU_TOKEN@-->Summary<!--@END_MENU_TOKEN@--> +List of functions to decode ADSB ASCII hex messages. ## Overview @@ -10,4 +10,4 @@ ### <!--@START_MENU_TOKEN@-->Group<!--@END_MENU_TOKEN@--> -- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@-->
\ No newline at end of file +- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@--> diff --git a/ADSBDecoderFramework/ADSBTypeCodeAirbonePositon.swift b/ADSBDecoderFramework/ADSBTypeCodeAirbonePositon.swift new file mode 100644 index 0000000..b6a302a --- /dev/null +++ b/ADSBDecoderFramework/ADSBTypeCodeAirbonePositon.swift @@ -0,0 +1,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 + } +} diff --git a/ADSBDecoderFramework/ADSBTypeCodeIndentification.swift b/ADSBDecoderFramework/ADSBTypeCodeIndentification.swift new file mode 100644 index 0000000..ad66378 --- /dev/null +++ b/ADSBDecoderFramework/ADSBTypeCodeIndentification.swift @@ -0,0 +1,34 @@ +// +// ADSBTypeCodeIndentification.swift +// ADSBDecoder +// +// Created by Jacky Jack on 27/09/2026. +// + +public class ADSBTypeCodeIndentification: CustomStringConvertible { + var TypeCode:Int = 4 + var Category:Int = 0 + public var ICAOName:String + + public init(_ bindata:ArraySlice<UInt8>) { + let cat = bindata[4]&0x7 + Category = Int(cat) + let char_0 = bindata[5]>>2 + let char_1 = (bindata[5]&0x3)<<4 + bindata[6]>>4 + let char_2 = (bindata[6]&0xf)<<2 + (bindata[7]>>6)&0x3 + let char_3 = (bindata[7])&0x3f + let char_4 = bindata[8]>>2 + let char_5 = (bindata[8]&0x3)<<4 + bindata[9]>>4 + let char_6 = (bindata[9]&0xf)<<2 + (bindata[10]>>6) + let char_7 = bindata[10]&0x3f + + //print(char_0, char_1, char_2,char_3,char_4,char_5,char_6,char_7) + ICAOName = ICAO2String(char_0, char_1, char_2, char_3, char_4, char_5, char_6, char_7) + //print("ICAO name \(ICAOName)") + } + + public var description: String { + let description = "TypeCode \(TypeCode) Cat \(Category) Flight name \(ICAOName)" + return description + } +} diff --git a/ADSBDecoderFramework/AirplaneTracker.swift b/ADSBDecoderFramework/AirplaneTracker.swift index 6c09953..d32e33c 100644 --- a/ADSBDecoderFramework/AirplaneTracker.swift +++ b/ADSBDecoderFramework/AirplaneTracker.swift @@ -116,5 +116,4 @@ public class AirPlaneTracker { } } } - } 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 =======") + } + } + } +} + + diff --git a/ADSBDecoderFramework/Decoder.swift b/ADSBDecoderFramework/Decoder.swift index 17fce52..1296b40 100644 --- a/ADSBDecoderFramework/Decoder.swift +++ b/ADSBDecoderFramework/Decoder.swift @@ -50,9 +50,6 @@ public class Decoder { //let endI = adsb_data.index(adsb_data.endIndex, offsetBy: -1) //let adsbData = adsb_data[startI...endI] let ret:DataFormat17 = DataFormat17(adsb_data) - - - return ret; } @@ -77,166 +74,10 @@ func ICAO2String(_ b1: UInt8, _ b2: UInt8, _ b3: UInt8, _ b4: UInt8, _ b5: UInt8 return ICAOAlphabet(b1)+ICAOAlphabet(b2)+ICAOAlphabet(b3)+ICAOAlphabet(b4)+ICAOAlphabet(b5)+ICAOAlphabet(b6)+ICAOAlphabet(b7)+ICAOAlphabet(b8) } -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 =======") - } - } - } -} - -public class ADSBTypeCodeIndentification: CustomStringConvertible { - var TypeCode:Int = 4 - var Category:Int = 0 - public var ICAOName:String - - public init(_ bindata:ArraySlice<UInt8>) { - let cat = bindata[4]&0x7 - Category = Int(cat) - let char_0 = bindata[5]>>2 - let char_1 = (bindata[5]&0x3)<<4 + bindata[6]>>4 - let char_2 = (bindata[6]&0xf)<<2 + (bindata[7]>>6)&0x3 - let char_3 = (bindata[7])&0x3f - let char_4 = bindata[8]>>2 - let char_5 = (bindata[8]&0x3)<<4 + bindata[9]>>4 - let char_6 = (bindata[9]&0xf)<<2 + (bindata[10]>>6) - let char_7 = bindata[10]&0x3f - - //print(char_0, char_1, char_2,char_3,char_4,char_5,char_6,char_7) - ICAOName = ICAO2String(char_0, char_1, char_2, char_3, char_4, char_5, char_6, char_7) - //print("ICAO name \(ICAOName)") - } - - public var description: String { - let description = "TypeCode \(TypeCode) Cat \(Category) Flight name \(ICAOName)" - return description - } -} -//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 - } -} class DataFormat19:CustomStringConvertible { init(_ bindata:ArraySlice<UInt8>) { |
