From b32ecfab276fb8e1dff0e1d72ed819b548323328 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Tue, 16 Jul 2024 06:45:43 +0100 Subject: Working implementation of ADSB loaded from file. Net1090 can read from dump1090 socket --- ADSBDecoder/AirplaneTracker.swift | 1 - ADSBDecoder/Configs.swift | 10 ++++++++++ ADSBDecoder/Decoder.swift | 34 +++++++++++++++++++++------------- ADSBDecoder/PositionDecoder.swift | 2 +- ADSBDecoder/main.swift | 3 --- 5 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 ADSBDecoder/Configs.swift (limited to 'ADSBDecoder') diff --git a/ADSBDecoder/AirplaneTracker.swift b/ADSBDecoder/AirplaneTracker.swift index f346201..96c4d5f 100644 --- a/ADSBDecoder/AirplaneTracker.swift +++ b/ADSBDecoder/AirplaneTracker.swift @@ -67,7 +67,6 @@ class AirPlaneTracker { } } - func getPosition(_ address: Int) -> (Double,Double)? { if (airplanes[address] == nil) { diff --git a/ADSBDecoder/Configs.swift b/ADSBDecoder/Configs.swift new file mode 100644 index 0000000..97ab31c --- /dev/null +++ b/ADSBDecoder/Configs.swift @@ -0,0 +1,10 @@ +// +// Configs.swift +// ADSBDecoder +// +// Created by Jacky Jack on 09/07/2024. +// + +import Foundation + +var decoder_debug_mode = true diff --git a/ADSBDecoder/Decoder.swift b/ADSBDecoder/Decoder.swift index 65a9ddd..a9724b6 100644 --- a/ADSBDecoder/Decoder.swift +++ b/ADSBDecoder/Decoder.swift @@ -25,7 +25,7 @@ class Decoder { var DataFormat: UInt32 = 0; init (_ adsb_data: String) { - print(adsb_data) + //print(adsb_data) self.adsb_data = adsb_data //get the first 8 bits as integer let startI = adsb_data.startIndex @@ -38,7 +38,7 @@ class Decoder { DataFormat = CM_DataFormat //let CM_TranspoderCapability = ControlMsg&(0x7) } - print("Data Format \(DataFormat)") + //print("Data Format \(DataFormat)") } func getDataFormat17() -> DataFormat17? { @@ -114,7 +114,7 @@ class DataFormat17 { endN = adsb_data.index(startN, offsetBy: 1) } } - print(bindata) + //print(bindata) //Decode Capability let cap = (bindata[0]>>1)&0x7 @@ -136,25 +136,33 @@ class DataFormat17 { //aircraft indentification and category if (tc_byte == 4) { let msg = ADSBTypeCodeIndentification(bindata[4...10]) - print("=====ADSB MESSSGE 04 =======") - print(msg) - print("============================") + 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]) - print(String(format:"=====ADSB MESSSGE %02d ======= AA:%04d", tc_byte, AddressAnnounced)) - print(msg) - print("============================") + 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) { - print("=====ADSB MESSSGE 19 =======") - print("=====VELOCITY =======") + if decoder_debug_mode { + print("=====ADSB MESSSGE 19 =======") + print("=====VELOCITY =======") + } } else { - print("=====ADSB MESSSGE UNKNOWN =======") + if decoder_debug_mode { + print("=====ADSB MESSSGE UNKNOWN =======") + } } } } @@ -176,7 +184,7 @@ class ADSBTypeCodeIndentification: CustomStringConvertible { 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) + //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)") } diff --git a/ADSBDecoder/PositionDecoder.swift b/ADSBDecoder/PositionDecoder.swift index 7d77221..85b9d49 100644 --- a/ADSBDecoder/PositionDecoder.swift +++ b/ADSBDecoder/PositionDecoder.swift @@ -162,7 +162,7 @@ class PositionDecoder { let cpr_even = el1.even ? el1 : el2 let cpr_odd = (!el1.even) ? el1 : el2 - print("Position queue is ready to calculate location \(cpr_even) \(cpr_odd)") + //print("Position queue is ready to calculate location \(cpr_even) \(cpr_odd)") // from here https://github.com/antirez/dump1090/blob/master/dump1090.c#L1718 let AirDlat0:Double = 360.0/60.0 let AirDlat1:Double = 360.0/59.0 diff --git a/ADSBDecoder/main.swift b/ADSBDecoder/main.swift index 3148a9d..f75cdfb 100644 --- a/ADSBDecoder/main.swift +++ b/ADSBDecoder/main.swift @@ -81,9 +81,6 @@ for line in adsb_source.components(separatedBy: .newlines) { airbornposition.Altitude, airbornposition.CPRFormat == 0 ) - if let position = tracker.getPosition(d17.AddressAnnounced) { - print("position: \(position)") - } } q_df17_decoded.addDecoded(d17.TypeCode) } else { -- cgit v1.2.3