From 30a23711626c5afe7f86ca34fbc489d7979b71d9 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Thu, 8 Aug 2024 12:25:55 +0100 Subject: Live data works --- LearnMapKit/FlighState.swift | 126 ++++++++++++++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 32 deletions(-) (limited to 'LearnMapKit/FlighState.swift') diff --git a/LearnMapKit/FlighState.swift b/LearnMapKit/FlighState.swift index cfb34f1..446b491 100644 --- a/LearnMapKit/FlighState.swift +++ b/LearnMapKit/FlighState.swift @@ -8,6 +8,7 @@ import Foundation import Collections + class FlightTracker { var last_time_seen: Int = 0 var ICAOName_avaliable = false @@ -27,60 +28,121 @@ class FlightState: ObservableObject { @Published var flight:[Int:FlightTracker] = [:] //configuration options + let sourceFile = false let default_file_path = "/Users/jackyjack/Downloads/2024_05_27_raw_adsb.txt" let process_per_second = 120 + let sourceDump1090Server = true + let dump1090address = "192.168.4.201" + let dump1090port = 30002 + init() { var count = 0 //let ADSBtask = ADSBFileRunner(filename: "") - let adsb_file = ADSBFileRunner(filename: self.default_file_path) + //let adsb_net = ADSBNetRunner(address: dump1090address, port: dump1090port) - 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") + if sourceFile { + 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.decodeFromFile() + print("Stop decoding data") + } + + //once a second read some data from decoded queue + timer = Timer.scheduledTimer( + withTimeInterval: 1, + repeats: true + ) { _ in + //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.. self.process_per_second { - let data = adsb_file.getPlainData(self.process_per_second) - //print(data.getCount()) - for idx in 0.. 0 { + print(ADSBClient.msgarray.message_array.count) + for i in 0.. 0 { + print("Process onse a second") + for idx in 0..