summaryrefslogtreecommitdiff
path: root/ADSBDecoder/Decoder.swift
diff options
context:
space:
mode:
Diffstat (limited to 'ADSBDecoder/Decoder.swift')
-rw-r--r--ADSBDecoder/Decoder.swift91
1 files changed, 44 insertions, 47 deletions
diff --git a/ADSBDecoder/Decoder.swift b/ADSBDecoder/Decoder.swift
index 95f798b..65a9ddd 100644
--- a/ADSBDecoder/Decoder.swift
+++ b/ADSBDecoder/Decoder.swift
@@ -14,7 +14,7 @@ func BarometricAltitudeFeat(_ altitude: UInt16) -> Int {
let part1:UInt16 = altitude&0xf
let part2:UInt16 = (altitude>>1)&0x7ff0
let altitude25 = part1 + part2
- print("altitude2 \(altitude25) ")
+ //print("altitude2 \(altitude25) ")
return Int(altitude25)*25-1000
}
return Int(altitude)*100-1000
@@ -86,11 +86,15 @@ class DataFormat17 {
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 CPROddEven=0//53
+ //var CPRlat=0//54:70
+ //var CPRlon=0//71:87
var ParityIntegrity=0//88-111
+ //all avaliable message types
+ var messageIdentification:ADSBTypeCodeIndentification? = nil
+ var messageAirbornPositon:ADSBTypeCodeAirbonePositon? = nil
+
init(_ adsb_data: String) {
//print("Dataformat: 17!")
//print(adsb_data)
@@ -114,65 +118,48 @@ class DataFormat17 {
//Decode Capability
let cap = (bindata[0]>>1)&0x7
- print(String(format: "cap %02x", cap))
+ //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))
+ //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))
+ //print(String(format: "tc %02d", tc_byte))
TypeCode = Int(tc_byte)
-
+
+ //aircraft indentification and category
if (tc_byte == 4) {
- let msg = ADSBTypeCode4(bindata[4...10])
+ let msg = ADSBTypeCodeIndentification(bindata[4...10])
print("=====ADSB MESSSGE 04 =======")
print(msg)
print("============================")
- } else if (tc_byte == 11) {
- let msg = ADSBTypeCode11(bindata[4...10])
- print("=====ADSB MESSSGE 11 =======")
+
+ messageIdentification = msg
+ //airborn position
+ } else if ((tc_byte >= 8) && (tc_byte <= 18)) {
+ let msg = ADSBTypeCodeAirbonePositon(bindata[4...10])
+ print(String(format:"=====ADSB MESSSGE %02d ======= AA:%04d", tc_byte, AddressAnnounced))
print(msg)
print("============================")
+
+ messageAirbornPositon = msg
+ //airborn velocity
} else if (tc_byte == 19) {
- print("Byte 19")
+ print("=====ADSB MESSSGE 19 =======")
+ print("=====VELOCITY =======")
} else {
- print("Unknow TC byte")
- /*
- //Decode Movement Field
- let mov_byte = (bindata[4]&0x7) + (bindata[5]>>5)
- print(String(format: "mov %02x", mov_byte))
-
- //Heading Bit
- let heading_bit = (bindata[5]>>3)&0x1
- print(String(format: "heading %02x", heading_bit))
-
- //Heading direction
- let heading_direction = (bindata[5]&0xF)<<3+(bindata[6]>>4)&0xF
- print(String(format: "hdir %02x", heading_direction))
-
- //CPR Odd/Even
- let cpr_odd_even = (bindata[6]>>2)&0x1;
- print(String(format: "cpr %02x", cpr_odd_even))
-
- //CPR lat
- let cpr_lat = (bindata[6]&0x7)<<14 + (bindata[7]<<7) + (bindata[8]>>1)
- print(String(format: "cpr lat %06x", cpr_lat))
-
- //CPR lon
- let cpr_lon = ((bindata[8]&0x1)<<16) + (bindata[9]<<8) + (bindata[10])
- print(String(format: "cpr lon %06x", cpr_lon))
- */
+ print("=====ADSB MESSSGE UNKNOWN =======")
}
}
}
-class ADSBTypeCode4: CustomStringConvertible {
+class ADSBTypeCodeIndentification: CustomStringConvertible {
var TypeCode:Int = 4
var Category:Int = 0
var ICAOName:String
@@ -200,7 +187,8 @@ class ADSBTypeCode4: CustomStringConvertible {
}
}
-class ADSBTypeCode11:CustomStringConvertible {
+//DF17 message types codes 8 to 18
+class ADSBTypeCodeAirbonePositon:CustomStringConvertible {
var TypeCode:Int = 11
var SurveillanceStatus: Int = 0
var SingleAntennaFlag: Int = 0
@@ -216,7 +204,7 @@ class ADSBTypeCode11:CustomStringConvertible {
let saf = bindata[5]&0x1
SingleAntennaFlag = Int(saf)
let altitude = UInt16(bindata[5])<<4 + (UInt16(bindata[6])>>4)&0xf
- print(altitude)
+ //print(altitude)
Altitude = BarometricAltitudeFeat(altitude)
let time = (bindata[6]>>3)&0x1
Time = Int(time)
@@ -230,15 +218,24 @@ class ADSBTypeCode11:CustomStringConvertible {
var description: String {
var description = "SS \(SurveillanceStatus) SAF \(SingleAntennaFlag) Altitude \(Altitude)ft \n"
- description += "Time \(Time) CPR \(CPRFormat) \n"
+ description += "Time \(Time) CPR \(CPRFormat)"
+ if (CPRFormat == 0) {
+ description += "even"
+ } else {
+ description += "odd"
+ }
+ description += "\n"
description += "Lat \(Latitude) Long \(Longitude)"
return description
}
}
-class DataFormat18 {
- init(_ adsb_data: String) {
- print("Dataformat: 18")
- print(adsb_data)
+class DataFormat19:CustomStringConvertible {
+ init(_ bindata:ArraySlice<UInt8>) {
+ print("Dataformat: 19")
+ }
+
+ var description: String {
+ return ""
}
}