summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-08-13 09:04:53 +0100
committerArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-08-13 09:04:53 +0100
commita474815bb7f4f395d3dfeafba85c3fa9e7d880c3 (patch)
tree1f781186af3a9de1e35c134e0cb58810b8e2ac62
parent30a23711626c5afe7f86ca34fbc489d7979b71d9 (diff)
downloadADSBDecoder-a474815bb7f4f395d3dfeafba85c3fa9e7d880c3.tar.gz
ADSBDecoder-a474815bb7f4f395d3dfeafba85c3fa9e7d880c3.zip
CommandLine arguments for net and file are working
-rw-r--r--ADSBDecoder.xcodeproj/project.pbxproj2
-rw-r--r--LearnMapKit/ContentView.swift28
-rw-r--r--LearnMapKit/FlighState.swift221
-rw-r--r--LearnMapKit/LearnMapKitApp.swift86
-rw-r--r--LearnMapKit/NetworkConfigure.swift12
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 = "<group>";
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..<data.getCount() {
- let nextTag = data.getNextTag()
- if nextTag == DataStreamType.ADSB_ALTITUDE {
- let _ = data.getAltitude()
-#warning("Implement this")
- } else if (nextTag == DataStreamType.ADSB_ICAO) {
- let icao = data.getIcaoName()
- print("Tag icao \(icao) count:\(data.icaoArray.count)")
- self.addIcaoName(icao.address, icao.ICAOname)
- } else if (nextTag == DataStreamType.ADSB_LOCATION) {
- print("tag location")
- let loc = data.getLocation()
- self.addLocation(loc.address, loc.lat, loc.long)
- }
- }
-
- } else {
- print("Data stream is empty")
- }
- }
- }
+ //if sourceFile {
+ // startSourceFile()
+ //}
+
+ //if sourceDump1090Server {
+ // startDump1090()
+ //}
+ }
+
+ init(filename: String) {
+ fileMode(filepath: filename)
+ startSourceFile()
+ }
+
+ init(hostname: String, port: Int) {
+ networkMode(hostname: hostname, port: port)
+ startDump1090()
+ }
+
+ func networkMode(hostname: String, port: Int) {
+ print("network mode")
+ self.dump1090address = hostname
+ self.dump1090port = port
+ self.sourceDump1090Server = true
+ self.sourceFile = false
+ }
+
+ func fileMode(filepath: String) {
+ print("file mode")
+ self.default_file_path = filepath
+ self.sourceFile = true
+ self.sourceDump1090Server = false
+ }
+
+ func defaultMode() {
+ print("default mode")
+ self.sourceDump1090Server = true
+ self.sourceFile = false
+ }
+
+ func startSourceFile() {
+ print("Start reading ADSB messages from \(self.default_file_path)")
+ let adsb_file = ADSBFileRunner(filename: self.default_file_path)
+ DispatchQueue.global(qos: .background).sync {
+ print("Open file")
+ adsb_file.openFile()
+ adsb_file.readFile()
}
- if sourceDump1090Server {
- //let ADSBClient = NetADSBDecoder(host: "192.168.4.201", port: 30002)
- let ADSBClient = ADSBNetRunner(address: "192.168.4.201", port: 30002)
- timer = Timer.scheduledTimer(
- withTimeInterval: 1,
- repeats: true
- ) { _ in
- //print("Timer drain queue")
- //print("\(ADSBClient.msgarray.message_array.count)")
- /*if ADSBClient.msgarray.message_array.count > 0 {
- print(ADSBClient.msgarray.message_array.count)
- for i in 0..<ADSBClient.msgarray.message_array.count {
- print(ADSBClient.msgarray.message_array.popLast()!,terminator: "")
- }
- }*/
- if ADSBClient.adsb_tag_stream.getCount() > 0 {
- print("Process onse a second")
- for idx in 0..<ADSBClient.adsb_tag_stream.getCount() {
- let nextTag = ADSBClient.adsb_tag_stream.getNextTag()
+ 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..<data.getCount() {
+ let nextTag = data.getNextTag()
if nextTag == DataStreamType.ADSB_ALTITUDE {
- let _ = ADSBClient.adsb_tag_stream.getAltitude()
+ let _ = data.getAltitude()
#warning("Implement this")
} else if (nextTag == DataStreamType.ADSB_ICAO) {
- let icao = ADSBClient.adsb_tag_stream.getIcaoName()
- print("Tag icao \(icao) count:\(ADSBClient.adsb_tag_stream.icaoArray.count)")
+ let icao = data.getIcaoName()
+ print("Tag icao \(icao) count:\(data.icaoArray.count)")
self.addIcaoName(icao.address, icao.ICAOname)
} else if (nextTag == DataStreamType.ADSB_LOCATION) {
print("tag location")
- let loc = ADSBClient.adsb_tag_stream.getLocation()
+ let loc = data.getLocation()
self.addLocation(loc.address, loc.lat, loc.long)
}
}
+
+ } else {
+ print("Data stream is empty")
}
}
- /*
- DispatchQueue.global(qos: .background).async {
- do {
- try ADSBClient.start()
- } catch let error {
- print("Error: \(error.localizedDescription)")
- ADSBClient.stop()
+ }
+ }
+
+ func startDump1090() {
+ print("Start reading ADSB messages from \(dump1090address):\(dump1090port)")
+ //let ADSBClient = NetADSBDecoder(host: "192.168.4.201", port: 30002)
+ //let ADSBClient = ADSBNetRunner(address: "192.168.4.201", port: 30002)
+ let ADSBClient = ADSBNetRunner(address: dump1090address, port: dump1090port)
+ timer = Timer.scheduledTimer(
+ withTimeInterval: 1,
+ repeats: true
+ ) { _ in
+ //print("Timer drain queue")
+ //print("\(ADSBClient.msgarray.message_array.count)")
+ /*if ADSBClient.msgarray.message_array.count > 0 {
+ print(ADSBClient.msgarray.message_array.count)
+ for i in 0..<ADSBClient.msgarray.message_array.count {
+ print(ADSBClient.msgarray.message_array.popLast()!,terminator: "")
}
}*/
+ if ADSBClient.adsb_tag_stream.getCount() > 0 {
+ print("Process onse a second")
+ for idx in 0..<ADSBClient.adsb_tag_stream.getCount() {
+ let nextTag = ADSBClient.adsb_tag_stream.getNextTag()
+ if nextTag == DataStreamType.ADSB_ALTITUDE {
+ let _ = ADSBClient.adsb_tag_stream.getAltitude()
+#warning("Implement this")
+ } else if (nextTag == DataStreamType.ADSB_ICAO) {
+ let icao = ADSBClient.adsb_tag_stream.getIcaoName()
+ print("Tag icao \(icao) count:\(ADSBClient.adsb_tag_stream.icaoArray.count)")
+ self.addIcaoName(icao.address, icao.ICAOname)
+ } else if (nextTag == DataStreamType.ADSB_LOCATION) {
+ print("tag location")
+ let loc = ADSBClient.adsb_tag_stream.getLocation()
+ self.addLocation(loc.address, loc.lat, loc.long)
+ }
+ }
+ }
+ }
+ /*
+ DispatchQueue.global(qos: .background).async {
do {
- print("Start")
try ADSBClient.start()
} catch let error {
print("Error: \(error.localizedDescription)")
ADSBClient.stop()
}
-
+ }*/
+ do {
+ print("Start")
+ try ADSBClient.start()
+ } catch let error {
+ print("Error: \(error.localizedDescription)")
+ ADSBClient.stop()
}
}
- init(filename: String) {
- #warning("not implemented at all")
+ func run() {
+ print("run")
+ if self.sourceFile {
+ startSourceFile()
+ } else if self.sourceDump1090Server {
+ startDump1090()
+ }
}
func addLocation(_ address: Int, _ lat: Double, _ long: Double) {
diff --git a/LearnMapKit/LearnMapKitApp.swift b/LearnMapKit/LearnMapKitApp.swift
index 62a902f..8132c92 100644
--- a/LearnMapKit/LearnMapKitApp.swift
+++ b/LearnMapKit/LearnMapKitApp.swift
@@ -11,26 +11,60 @@ import ArgumentParser
//https://www.hackingwithswift.com/quick-start/swiftui/how-to-run-code-when-your-app-launches
-
+struct CommandLineArgs: ParsableCommand {
+ @Option(name: .shortAndLong) var hostname: String? = nil
+ @Option(name: .shortAndLong) var port: Int? = nil
+ @Option(name: .shortAndLong) var inputfile: String? = nil
+ @Flag(name: .shortAndLong) var debug:Bool = false
+ @Flag(name: .shortAndLong) var version:Bool = false
+}
@main
struct LearnMapKitApp: App {
-
+ var network_mode = false
+ var file_mode = false
@State var queue: Deque<ADSBLocation> = []
@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
+ }
}