summaryrefslogtreecommitdiff
path: root/LearnMapKit/FlighState.swift
diff options
context:
space:
mode:
Diffstat (limited to 'LearnMapKit/FlighState.swift')
-rw-r--r--LearnMapKit/FlighState.swift126
1 files changed, 94 insertions, 32 deletions
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..<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")
+ }
+ }
+ }
}
- //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 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()
if nextTag == DataStreamType.ADSB_ALTITUDE {
- let _ = data.getAltitude()
+ let _ = ADSBClient.adsb_tag_stream.getAltitude()
#warning("Implement this")
} else if (nextTag == DataStreamType.ADSB_ICAO) {
- let icao = data.getIcaoName()
- print("Tag icao \(icao) count:\(data.icaoArray.count)")
+ 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 = data.getLocation()
+ let loc = ADSBClient.adsb_tag_stream.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()
+ }
+ }*/
+ do {
+ print("Start")
+ try ADSBClient.start()
+ } catch let error {
+ print("Error: \(error.localizedDescription)")
+ ADSBClient.stop()
+ }
+
}
}