summaryrefslogtreecommitdiff
path: root/ADSBDecoder
diff options
context:
space:
mode:
authorArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-07-02 10:07:49 +0100
committerArturs Artamonovs <arturs.artamonovs@protonmail.com>2024-07-02 10:07:49 +0100
commitcc5272cd4be2ab55fa8411790082be408b586be9 (patch)
tree8436c54cdeb94e6383607fe0028b09a19790e8d2 /ADSBDecoder
parent58d9d561df35f88884b2959d2cf322f1ee69e3cd (diff)
downloadADSBDecoder-cc5272cd4be2ab55fa8411790082be408b586be9.tar.gz
ADSBDecoder-cc5272cd4be2ab55fa8411790082be408b586be9.zip
Make ADSBDecoder more modular. Integrate into LearnMapKit
Diffstat (limited to 'ADSBDecoder')
-rw-r--r--ADSBDecoder/ADSBRegEx.swift35
-rw-r--r--ADSBDecoder/AirplaneTracker.swift31
-rw-r--r--ADSBDecoder/Utils.swift23
-rw-r--r--ADSBDecoder/main.swift40
4 files changed, 86 insertions, 43 deletions
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()