From 901397ffe83cbf1aed01e6a77e00db57e9440dac Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Thu, 25 Jul 2024 12:13:51 +0100 Subject: Receiving ADSB stream from dump1090 works in LearnMapKit --- LearnMapKit/ContentView.swift | 1 + LearnMapKit/LearnMapKit.entitlements | 2 ++ LearnMapKit/LearnMapKitApp.swift | 27 ++++++++++++++++++++------- LearnMapKit/NetConfigView.swift | 11 ++++++++--- LearnMapKit/NetworkConfigure.swift | 13 +++++++++++++ 5 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 LearnMapKit/NetworkConfigure.swift (limited to 'LearnMapKit') diff --git a/LearnMapKit/ContentView.swift b/LearnMapKit/ContentView.swift index 9f7fd29..e85c3b2 100644 --- a/LearnMapKit/ContentView.swift +++ b/LearnMapKit/ContentView.swift @@ -42,6 +42,7 @@ struct ContentView: View { @State private var isImporting = false @Binding var pos_queue: Deque + @Binding var net_config: NetworkConfigure @EnvironmentObject var evilClass: FlightState @Environment(\.openWindow) private var openWindow diff --git a/LearnMapKit/LearnMapKit.entitlements b/LearnMapKit/LearnMapKit.entitlements index 61b4b47..ca15375 100644 --- a/LearnMapKit/LearnMapKit.entitlements +++ b/LearnMapKit/LearnMapKit.entitlements @@ -8,5 +8,7 @@ com.apple.security.files.user-selected.read-only + com.apple.security.network.client + diff --git a/LearnMapKit/LearnMapKitApp.swift b/LearnMapKit/LearnMapKitApp.swift index 6c46f3b..62a902f 100644 --- a/LearnMapKit/LearnMapKitApp.swift +++ b/LearnMapKit/LearnMapKitApp.swift @@ -15,26 +15,39 @@ import ArgumentParser @main struct LearnMapKitApp: App { - - - + @State var queue: Deque = [] + @State var netconfig: NetworkConfigure = NetworkConfigure() @StateObject private var flightState = FlightState() 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() + }*/ + DispatchQueue.global(qos: .background).async { + do { + try ADSBClient.start() + } catch let error { + print("Error: \(error.localizedDescription)") + ADSBClient.stop() + } + } } - - var body: some Scene { WindowGroup { - ContentView(pos_queue: $queue) + ContentView(pos_queue: $queue, net_config: $netconfig) }.environmentObject(flightState) WindowGroup("Network", id: "net-config") { - NetConfigView() + NetConfigView(net_config: $netconfig) } } diff --git a/LearnMapKit/NetConfigView.swift b/LearnMapKit/NetConfigView.swift index 06fc5c2..0216f8a 100644 --- a/LearnMapKit/NetConfigView.swift +++ b/LearnMapKit/NetConfigView.swift @@ -12,6 +12,8 @@ struct NetConfigView: View { @State private var server_port: String = "" @Environment(\.dismissWindow) private var dismissWindow + @Binding var net_config: NetworkConfigure + var body: some View { VStack { HStack { @@ -31,6 +33,9 @@ struct NetConfigView: View { } Button(action: { print("Save config") + net_config.servername = server_name + // is there better way? + net_config.serverport = Int(server_port)! dismissWindow(id:"net-config") }) { Text("Save") @@ -40,6 +45,6 @@ struct NetConfigView: View { } } -#Preview { - NetConfigView() -} +//#Preview { + //NetConfigView(net_config: net_config) +//} diff --git a/LearnMapKit/NetworkConfigure.swift b/LearnMapKit/NetworkConfigure.swift new file mode 100644 index 0000000..a566f8b --- /dev/null +++ b/LearnMapKit/NetworkConfigure.swift @@ -0,0 +1,13 @@ +// +// File.swift +// LearnMapKit +// +// Created by Jacky Jack on 19/07/2024. +// + +import Foundation + +class NetworkConfigure { + var servername: String = "192.168.4.201" + var serverport: Int = 30002 +} -- cgit v1.2.3