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 --- LearnMapKit/FlighState.swift | 138 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 122 insertions(+), 16 deletions(-) (limited to 'LearnMapKit/FlighState.swift') diff --git a/LearnMapKit/FlighState.swift b/LearnMapKit/FlighState.swift index f3895cb..cfb34f1 100644 --- a/LearnMapKit/FlighState.swift +++ b/LearnMapKit/FlighState.swift @@ -8,38 +8,144 @@ import Foundation import Collections +class FlightTracker { + var last_time_seen: Int = 0 + var ICAOName_avaliable = false + @Published var ICAOName = "" + var Position_avaliable = false + @Published var long:Double = 0.0 + @Published var lat:Double = 0.0 + var FromTo_avaliable = false + var flightFrom:String = "" + var flightTo:String = "" +} + class FlightState: ObservableObject { - @Published var name = "Some Name" - @Published var isEnabled = false var timer: Timer? - var update_postions: Deque = [] + //default location currently for testing var fromFile: Bool = false + @Published var flight:[Int:FlightTracker] = [:] + + //configuration options + let default_file_path = "/Users/jackyjack/Downloads/2024_05_27_raw_adsb.txt" + let process_per_second = 120 + init() { var count = 0 - let ADSBtask = ADSBFileRunner(filename: "") + //let ADSBtask = ADSBFileRunner(filename: "") + let adsb_file = ADSBFileRunner(filename: self.default_file_path) + + + DispatchQueue.global(qos: .background).sync { + print("Open file") + adsb_file.openFile() + adsb_file.readFile() + } + + DispatchQueue.global(qos: .background).async { + print("Start decoding data") + adsb_file.decode() + print("Stop decoding data") + } + + //once a second read some data from decoded queue timer = Timer.scheduledTimer( withTimeInterval: 1, repeats: true ) { _ in - - //queue.append(MapADSBData(lat: 0.0, long: 0.0, alt: 1)) - - //let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in - print("Evil object \(count)") - //ADSBtask.runFromFile() - self.update_postions.append(ADSBLocation(address: 0, lat: 0.0, long: 0.0)) - // print(update_postions.count) - count += 1 - //} + //get the 10 entries if there is + if adsb_file.jobDone() { + print("Decoding done let get some data \(adsb_file.getCount())") + //if adsb_file + if adsb_file.getCount() > self.process_per_second { + let data = adsb_file.getPlainData(self.process_per_second) + //print(data.getCount()) + for idx in 0..