// // ADSBDataQueue.swift // LearnMapKit // // Created by Jacky Jack on 05/08/2024. // import Foundation import Collections ///Tag for location struct ADSBLocation { let address: Int let lat: Double let long: Double //let alt: Int } /// Tag for Altitude struct ADSBAltitude { let address: Int let altitude: Int } /// Tag for ICAO name struct ADSBICAOname { let address: Int let ICAOname: String } /// Tag enum for data stream /// 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 = [] var icaoArray: Array = [] var altQueue: Deque = [] var locQueue: Deque = [] //var tagQueue: Deque<> = [] var tagArray: Array = [] ///get the last tag from a queue ///user handles what todo with this data func getNextTag() -> DataStreamType { if tagArray.count < 0 { return DataStreamType.EMPTY } return tagArray[tagArray.count-1] } func addIcaoName(_ address: Int, _ icaoname: String) { tagArray.append(DataStreamType.ADSB_ICAO) icaoArray.append(ADSBICAOname(address: address, ICAOname: icaoname)) } func addAltitude(_ address: Int, _ altitude: Int) { tagArray.append(DataStreamType.ADSB_ALTITUDE) altQueue.append(ADSBAltitude(address: address, altitude: altitude)) } func addLocation(_ address: Int, _ lat: Double, _ long: Double) { tagArray.append(DataStreamType.ADSB_LOCATION) locQueue.append(ADSBLocation(address: address, lat: lat, long: long)) } ///let read next tag in a queue, that is ICAO name ///user handles order in a queue for now func getIcaoName() -> ADSBICAOname { if tagArray.count < 1 { print("ADSB tag Queue is empty") return ADSBICAOname(address:0,ICAOname: "TEmpty") } let tag = tagArray[tagArray.count-1] if tag != DataStreamType.ADSB_ICAO { print("ADSB Queue empty") return ADSBICAOname(address:0,ICAOname: "QEmpty") } tagArray.removeLast() var ret_icao_name = ADSBICAOname(address:0, ICAOname: "Default") if let last_icao_name = icaoArray.popLast() { ret_icao_name = last_icao_name } return ret_icao_name } ///let read next tag in a queue, that is Altitude ///user handles order in a queue for now func getAltitude() -> ADSBAltitude { if tagArray.count < 1 { print("ADSB tag Queue is empty") return ADSBAltitude(address:0,altitude:0) } let tag = tagArray[tagArray.count-1] if tag != DataStreamType.ADSB_ALTITUDE { print("ADSB Queue empty") return ADSBAltitude(address:0,altitude:0) } tagArray.removeLast() return altQueue.popLast()! } ///let read next tag in a queue, that is the location ///user handles order in a queue for now func getLocation() -> ADSBLocation { if tagArray.count < 1 { print("ADSB tag Queue is empry") return ADSBLocation(address:0,lat:0.0,long:0.0) } let tag = tagArray[tagArray.count-1] if tag != DataStreamType.ADSB_LOCATION { print("ADSB Queue empty") return ADSBLocation(address:0,lat:0.0,long:0.0) } tagArray.removeLast() return locQueue.popLast()! } //check if there is more then specified number in queue func haveNum(_ num: Int) -> Bool { if (tagArray.count > num) { return true } return false } ///get number in the queue func getCount() -> Int { return tagArray.count } }