From a474815bb7f4f395d3dfeafba85c3fa9e7d880c3 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Tue, 13 Aug 2024 09:04:53 +0100 Subject: CommandLine arguments for net and file are working --- ADSBDecoder.xcodeproj/project.pbxproj | 2 +- LearnMapKit/ContentView.swift | 28 ----- LearnMapKit/FlighState.swift | 221 +++++++++++++++++++++------------- LearnMapKit/LearnMapKitApp.swift | 86 ++++++++++--- LearnMapKit/NetworkConfigure.swift | 12 ++ 5 files changed, 219 insertions(+), 130 deletions(-) diff --git a/ADSBDecoder.xcodeproj/project.pbxproj b/ADSBDecoder.xcodeproj/project.pbxproj index 0e0c319..e185afa 100644 --- a/ADSBDecoder.xcodeproj/project.pbxproj +++ b/ADSBDecoder.xcodeproj/project.pbxproj @@ -303,12 +303,12 @@ 8D8480F02C60C79E007ACD95 /* ADSBDataQueue.swift */, 8DF756862C10556A008E8DFF /* ContentView.swift */, 8D93B6992C4A665B00C91865 /* NetConfigView.swift */, + 8D93B69B2C4A727300C91865 /* NetworkConfigure.swift */, 8DF756842C10556A008E8DFF /* LearnMapKitApp.swift */, 8DEC6F312C31530C00AC6209 /* FlighState.swift */, 8DF756882C10556C008E8DFF /* Assets.xcassets */, 8DF7568D2C10556C008E8DFF /* LearnMapKit.entitlements */, 8DF7568A2C10556C008E8DFF /* Preview Content */, - 8D93B69B2C4A727300C91865 /* NetworkConfigure.swift */, ); path = LearnMapKit; sourceTree = ""; diff --git a/LearnMapKit/ContentView.swift b/LearnMapKit/ContentView.swift index e85c3b2..9f18e30 100644 --- a/LearnMapKit/ContentView.swift +++ b/LearnMapKit/ContentView.swift @@ -62,34 +62,6 @@ struct ContentView: View { var body: some View { VStack { - HStack(alignment: .top) { - Button("1") { - print("Pressed 1") - } - Button("2") { - print("Pressed 2") - } - Button("3") { - print("Pressed 3") - } - Button("4") { - print("Pressed 4") - } - Button("5") { - print("Pressed 5") - } - Button("6") { - print("Pressed 6") - } - Button("7") { - print("Pressed 7") - //print(evilClass.update_postions.count) - } - } - .border(.blue) - //.frame(maxWidth:.infinity) - //.padding() - Map(initialPosition: initialPosition) { ForEach(self.evilClass.flight.sorted(by: { $0.key < $1.key} ), id:\.key) { k in Annotation("\(k.key)", coordinate: CLLocationCoordinate2D(latitude: self.evilClass.flight[k.key]!.lat, longitude:self.evilClass.flight[k.key]!.long)) { diff --git a/LearnMapKit/FlighState.swift b/LearnMapKit/FlighState.swift index 446b491..9f42369 100644 --- a/LearnMapKit/FlighState.swift +++ b/LearnMapKit/FlighState.swift @@ -28,126 +28,173 @@ 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 + var sourceFile = false + var default_file_path = "/Users/jackyjack/Downloads/2024_05_27_raw_adsb.txt" + var process_per_second = 120 - let sourceDump1090Server = true - let dump1090address = "192.168.4.201" - let dump1090port = 30002 + var sourceDump1090Server = true + var dump1090address = "192.168.4.201" + var dump1090port = 30002 init() { + print("Init") var count = 0 //let ADSBtask = ADSBFileRunner(filename: "") //let adsb_net = ADSBNetRunner(address: dump1090address, port: dump1090port) - 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.. 0 { - print(ADSBClient.msgarray.message_array.count) - for i in 0.. 0 { - print("Process onse a second") - 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.. = [] @State var netconfig: NetworkConfigure = NetworkConfigure() - @StateObject private var flightState = FlightState() + @StateObject private var flightState:FlightState = FlightState() + + var default_hostname = "192.168.4.201" + var default_port = 30002 + var default_input_file = "" init() { - print("Init app") - let ADSBClient = NetADSBDecoder(host: "192.168.4.201", port: 30002) - /*do { - try ADSBClient.start() - } catch let error { - print("Error: \(error.localizedDescription)") - ADSBClient.stop() - }*/ + //parse arguments + //let args = CommandLineArgs.parseOrExit() + //flightState.defaultMode() + let args = CommandLineArgs.parseOrExit() + print(args) + print(args.inputfile) + //exit(0) + //if (true)// + if let args = CommandLineArgs.parseNotExit() + { + if args.hostname != nil { + default_hostname = args.hostname! + network_mode = true + } + if args.port != nil { + default_port = args.port! + network_mode = true + } + + if args.inputfile != nil { + default_input_file = args.inputfile! + file_mode = true + } + print("Set this") + + } + + //flightState.run() + + + /*let ADSBClient = NetADSBDecoder(host: default_hostname, port: default_port) DispatchQueue.global(qos: .background).async { do { try ADSBClient.start() @@ -38,17 +72,41 @@ struct LearnMapKitApp: App { print("Error: \(error.localizedDescription)") ADSBClient.stop() } - } + }*/ } var body: some Scene { WindowGroup { - ContentView(pos_queue: $queue, net_config: $netconfig) + ContentView(pos_queue: $queue, net_config: $netconfig).onAppear(perform: { + if network_mode { + print("network mode") + flightState.networkMode(hostname: self.default_hostname, port: self.default_port) + } else if (file_mode){ + print("RUn file mode") + flightState.fileMode(filepath: self.default_input_file) + } else { + print("Run default mode") + flightState.defaultMode() + } + flightState.run() + }) }.environmentObject(flightState) WindowGroup("Network", id: "net-config") { NetConfigView(net_config: $netconfig) } } - +} + +extension ParsableArguments { + static func parseNotExit( + _ arguments: [String]? = nil + ) -> Self! { + do { + return try parse(arguments) + } catch { + print("Ignore error") + return nil + } + } } diff --git a/LearnMapKit/NetworkConfigure.swift b/LearnMapKit/NetworkConfigure.swift index a566f8b..2baf6ad 100644 --- a/LearnMapKit/NetworkConfigure.swift +++ b/LearnMapKit/NetworkConfigure.swift @@ -10,4 +10,16 @@ import Foundation class NetworkConfigure { var servername: String = "192.168.4.201" var serverport: Int = 30002 + + var default_values: Bool = true + + func setPort(_ port: Int) { + default_values = false + self.serverport = port + } + + func setHost(_ hostname: String) { + default_values = false + self.servername = hostname + } } -- cgit v1.2.3