From cc5272cd4be2ab55fa8411790082be408b586be9 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Tue, 2 Jul 2024 10:07:49 +0100 Subject: Make ADSBDecoder more modular. Integrate into LearnMapKit --- ADSBDecoder/ADSBRegEx.swift | 35 ++++++++++++++++++++++++++++++++++ ADSBDecoder/AirplaneTracker.swift | 31 +++++++++++++++++++++++++++--- ADSBDecoder/Utils.swift | 23 ++++++++++++++++++++++ ADSBDecoder/main.swift | 40 --------------------------------------- 4 files changed, 86 insertions(+), 43 deletions(-) create mode 100644 ADSBDecoder/ADSBRegEx.swift create mode 100644 ADSBDecoder/Utils.swift (limited to 'ADSBDecoder') diff --git a/ADSBDecoder/ADSBRegEx.swift b/ADSBDecoder/ADSBRegEx.swift new file mode 100644 index 0000000..e9ebe17 --- /dev/null +++ b/ADSBDecoder/ADSBRegEx.swift @@ -0,0 +1,35 @@ +// +// ADSBRegEx.swift +// ADSBDecoder +// +// Created by Jacky Jack on 30/06/2024. +// + +import Foundation +import RegexBuilder + +let matchADSBLong = Regex { + Anchor.startOfLine + "*" + + Repeat( + CharacterClass( + ("a"..."f"), + ("0"..."9") + ) + ,count:28) + + ";" +} + +let matchADSBShort = Regex { + Anchor.startOfLine + "*" + Repeat( + CharacterClass( + ("a"..."f"), + ("0"..."9") + ) + ,count:14) + ";" +} diff --git a/ADSBDecoder/AirplaneTracker.swift b/ADSBDecoder/AirplaneTracker.swift index 0ac8bfc..f346201 100644 --- a/ADSBDecoder/AirplaneTracker.swift +++ b/ADSBDecoder/AirplaneTracker.swift @@ -83,9 +83,34 @@ class AirPlaneTracker { return nil } - func getAltitude() { - - print("not implemented") + func getAltitude(_ address: Int) -> Int? { + if (airplanes[address] == nil) { + return nil + } + if let airplane = airplanes[address] { + if airplane.altitudeReady { + return airplane.altitude + } else { + return nil + } + } else { + return nil + } + } + + func getICAOname(_ address: Int) -> String? { + if (airplanes[address] == nil) { + return nil + } + if let airplane = airplanes[address] { + if airplane.ICAOready { + return airplane.ICAOname + } else { + return nil + } + } else { + return nil + } } func printAllICAOnames() { diff --git a/ADSBDecoder/Utils.swift b/ADSBDecoder/Utils.swift new file mode 100644 index 0000000..7a7f177 --- /dev/null +++ b/ADSBDecoder/Utils.swift @@ -0,0 +1,23 @@ +// +// Utils.swift +// ADSBDecoder +// +// Created by Jacky Jack on 30/06/2024. +// + +import Foundation + +//return true if file excists +func checkIfFileExists(_ fname: String) -> Bool { + let fm = FileManager.default + if fm.fileExists(atPath: fname) { + return true + } + return false +} + +//get current run directory +func getCurrentDirPath() -> String { + return Process().currentDirectoryPath +} + diff --git a/ADSBDecoder/main.swift b/ADSBDecoder/main.swift index a346fbb..3148a9d 100644 --- a/ADSBDecoder/main.swift +++ b/ADSBDecoder/main.swift @@ -10,19 +10,7 @@ import ArgumentParser import RegexBuilder import SQLite3 -//return true if file excists -func checkIfFileExists(_ fname: String) -> Bool { - let fm = FileManager.default - if fm.fileExists(atPath: fname) { - return true - } - return false -} -//get current run directory -func getCurrentDirPath() -> String { - return Process().currentDirectoryPath -} struct CommandLineArgs: ParsableCommand { @Option(name: .shortAndLong) var inputfile: String @@ -52,34 +40,6 @@ do { exit(1) } - - -let matchADSBLong = Regex { - Anchor.startOfLine - "*" - - Repeat( - CharacterClass( - ("a"..."f"), - ("0"..."9") - ) - ,count:28) - - ";" -} - -let matchADSBShort = Regex { - Anchor.startOfLine - "*" - Repeat( - CharacterClass( - ("a"..."f"), - ("0"..."9") - ) - ,count:14) - ";" -} - //gather stats var q_df = QueryDF() var q_dftc = QueryDF17TC() -- cgit v1.2.3