diff options
Diffstat (limited to 'LearnMapKit')
-rw-r--r-- | LearnMapKit/ADSBRunner.swift | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/LearnMapKit/ADSBRunner.swift b/LearnMapKit/ADSBRunner.swift index 0f09759..6d2bbc5 100644 --- a/LearnMapKit/ADSBRunner.swift +++ b/LearnMapKit/ADSBRunner.swift @@ -6,6 +6,7 @@ // import Foundation +import Collections struct ADSBLocation { let address: Int @@ -24,12 +25,99 @@ struct ADSBICAOname { let ICAOname: String } +enum DataStreamType { + case EMPTY + case ADSB_ICAO + case ADSB_LOCATION + case ADSB_ALTITUDE +} + +//get stream of decoded data, to tagged stream so all can be processed in sequence +class ADSBDataQueue { + var icaoQueue: Deque<ADSBICAOname> = [] + var altQueue: Deque<ADSBAltitude> = [] + var locQueue: Deque<ADSBLocation> = [] + var tagQueue: Deque<DataStreamType> = [] + + func getNextTag() -> DataStreamType { + if tagQueue.count < 0 { + return DataStreamType.EMPTY + } + return tagQueue[tagQueue.count-1] + } + + func addIcaoName(_ address: Int, _ icaoname: String) { + tagQueue.append(DataStreamType.ADSB_ICAO) + icaoQueue.append(ADSBICAOname(address: address, ICAOname: icaoname)) + } + + func addAltitude(_ address: Int, _ altitude: Int) { + tagQueue.append(DataStreamType.ADSB_ALTITUDE) + altQueue.append(ADSBAltitude(address: address, altitude: altitude)) + } + + func addLocation(_ address: Int, _ lat: Double, _ long: Double) { + tagQueue.append(DataStreamType.ADSB_LOCATION) + locQueue.append(ADSBLocation(address: address, lat: lat, long: long)) + } + + func getIcaoName() -> ADSBICAOname { + if tagQueue.count < 1 { + print("ADSB tag Queue is empry") + return ADSBICAOname(address:0,ICAOname: "") + } + let tag = tagQueue[tagQueue.count-1] + if tag != DataStreamType.ADSB_ICAO { + print("ADSB Queue empty") + return ADSBICAOname(address:0,ICAOname: "") + } + tagQueue.removeLast() + return icaoQueue.popLast()! + } + + func getAltitude() -> ADSBAltitude { + if tagQueue.count < 1 { + print("ADSB tag Queue is empry") + return ADSBAltitude(address:0,altitude:0) + } + let tag = tagQueue[tagQueue.count-1] + if tag != DataStreamType.ADSB_ALTITUDE { + print("ADSB Queue empty") + return ADSBAltitude(address:0,altitude:0) + } + tagQueue.removeLast() + return altQueue.popLast()! + } + + func getLocation() -> ADSBLocation { + if tagQueue.count < 1 { + print("ADSB tag Queue is empry") + return ADSBLocation(address:0,lat:0.0,long:0.0) + } + let tag = tagQueue[tagQueue.count-1] + if tag != DataStreamType.ADSB_LOCATION { + print("ADSB Queue empty") + return ADSBLocation(address:0,lat:0.0,long:0.0) + } + tagQueue.removeLast() + return locQueue.popLast()! + } + + func haveNum(_ num: Int) -> Bool { + if (tagQueue.count > num) { + return true + } + return false + } +} + class ADSBFileRunner { var filename: URL //track all airplanes var tracker = AirPlaneTracker() var adsb_source: String = "" + var adsb_tag_stream = ADSBDataQueue() init(filename:String) { self.filename = URL(fileURLWithPath:filename) @@ -73,6 +161,7 @@ class ADSBFileRunner { if (d17.TypeCode == 4) { if let indentification = d17.messageIdentification { tracker.addDF17Indentification(d17.AddressAnnounced, indentification.ICAOName) + adsb_tag_stream.addIcaoName(d17.AddressAnnounced, tracker.getICAOname(d17.AddressAnnounced)!) } } else if (d17.TypeCode >= 9 && d17.TypeCode <= 18) { if let airbornposition = d17.messageAirbornPositon { @@ -85,6 +174,10 @@ class ADSBFileRunner { ) if let position = tracker.getPosition(d17.AddressAnnounced) { print("position: \(position)") + adsb_tag_stream.addAltitude(d17.AddressAnnounced, tracker.getAltitude(d17.AddressAnnounced)!) + let location = tracker.getPosition(d17.AddressAnnounced)! + adsb_tag_stream.addLocation(d17.AddressAnnounced, location.0, location.1) + } } } |