diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-06-26 08:29:38 +0100 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-06-26 08:29:38 +0100 |
commit | 58d9d561df35f88884b2959d2cf322f1ee69e3cd (patch) | |
tree | d90eb046a4e508bc64adcce558079048e364dd96 /ADSBDecoder/main.swift | |
parent | de4f742388002e5b8307903369727300dd3e6049 (diff) | |
download | ADSBDecoder-58d9d561df35f88884b2959d2cf322f1ee69e3cd.tar.gz ADSBDecoder-58d9d561df35f88884b2959d2cf322f1ee69e3cd.zip |
Decoding lat/lon seems to work
Diffstat (limited to 'ADSBDecoder/main.swift')
-rw-r--r-- | ADSBDecoder/main.swift | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/ADSBDecoder/main.swift b/ADSBDecoder/main.swift index a324a0f..a346fbb 100644 --- a/ADSBDecoder/main.swift +++ b/ADSBDecoder/main.swift @@ -8,6 +8,7 @@ import Foundation import ArgumentParser import RegexBuilder +import SQLite3 //return true if file excists func checkIfFileExists(_ fname: String) -> Bool { @@ -82,13 +83,18 @@ let matchADSBShort = Regex { //gather stats var q_df = QueryDF() var q_dftc = QueryDF17TC() +var q_decoded = QueryDecodedMessages() +var q_df17_decoded = QueryDF17TC_decoded() + +//track all airplanes +var tracker = AirPlaneTracker() //parse line by line -var cnt=0 +var count_messages=0 for line in adsb_source.components(separatedBy: .newlines) { var found=false //print("\(cnt) \(line)") - //cnt += 1 + count_messages += 1 if let tokenMatch = try matchADSBLong.prefixMatch(in: line) { //print("\(String(tokenMatch.output))") found = true @@ -100,9 +106,32 @@ for line in adsb_source.components(separatedBy: .newlines) { if let d17 = decoder.getDataFormat17() { //print(d17) q_dftc.addTC(d17.TypeCode) + q_decoded.addDecoded() + if (d17.TypeCode == 4) { + if let indentification = d17.messageIdentification { + tracker.addDF17Indentification(d17.AddressAnnounced, indentification.ICAOName) + } + q_df17_decoded.addDecoded(4) + } else if (d17.TypeCode >= 9 && d17.TypeCode <= 18) { + if let airbornposition = d17.messageAirbornPositon { + tracker.addDF17AirBornPosition( + d17.AddressAnnounced, + airbornposition.Latitude, + airbornposition.Longitude, + airbornposition.Altitude, + airbornposition.CPRFormat == 0 + ) + if let position = tracker.getPosition(d17.AddressAnnounced) { + print("position: \(position)") + } + } + q_df17_decoded.addDecoded(d17.TypeCode) + } else { + q_df17_decoded.addUndecode(d17.TypeCode) + } } } else { - + q_decoded.addUndecoded() } q_df.addDF(decoder.DataFormat) }; @@ -110,6 +139,8 @@ for line in adsb_source.components(separatedBy: .newlines) { if let tokenMatch = try matchADSBShort.prefixMatch(in: line) { print("\(tokenMatch.output)") found = true + + q_decoded.addUndecoded() }; if (found == false) { @@ -125,4 +156,9 @@ if args.show_stats { //q_df.showStat() print(q_df) print(q_dftc) + print(q_decoded) + print(q_df17_decoded) + tracker.printAllICAOnames() + + print("Total message:\(count_messages)") } |