From dc258b024147499b83f19748018c504811746609 Mon Sep 17 00:00:00 2001 From: Rajan Patel Date: Fri, 23 Feb 2024 14:39:38 +0000 Subject: [PATCH] start parsing a couple specific message types for fraction degrees vs fractional minutes --- rootfs/scripts/acars2pos.py | 2 +- rootfs/scripts/acars_decode/Decoder.py | 61 +++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/rootfs/scripts/acars2pos.py b/rootfs/scripts/acars2pos.py index 6f76a00..de1a607 100755 --- a/rootfs/scripts/acars2pos.py +++ b/rootfs/scripts/acars2pos.py @@ -174,7 +174,7 @@ def thread_wrapper(func, *args): else: continue - print(f'{sbs["type"]} {sbs["msgtype"]}', file=stderr) + print(f'{sbs["type"]} {sbs.get("msgtype")}', file=stderr) # print(pos, file=stderr) sbs["reg"] = sub(r'[^a-zA-Z0-9-]', '', sbs["reg"]).upper() diff --git a/rootfs/scripts/acars_decode/Decoder.py b/rootfs/scripts/acars_decode/Decoder.py index 7768d64..d21f518 100644 --- a/rootfs/scripts/acars_decode/Decoder.py +++ b/rootfs/scripts/acars_decode/Decoder.py @@ -1,3 +1,5 @@ +from re import search + def decode(msg): if msg.get("vdl2"): dat = decodeVDLM2(msg["vdl2"]) @@ -5,6 +7,45 @@ def decode(msg): dat = decodeHFDL(msg["hfdl"]) else: dat = decodeACARS(msg) + + if dat is None or dat.get("msgtype") is None: + return dat + + if dat["msgtype"] == "10": + if raw := search(r"([NS]) ?(\d{2}\.\d{3})[,\/]([WE]) ?(\d{2,3}\.\d{3})", dat["txt"]): + print("matched type 10") + print(dat["txt"]) + print() + dat["lat"] = float(raw.group(2)) * (-1 if raw.group(1) == "S" else 1) + dat["lon"] = float(raw.group(4)) * (-1 if raw.group(1) == "W" else 1) + elif dat["msgtype"] == "4N": + if raw := search(r"([NS])(\d{3})(\d{3}) ([WE])(\d{3})(\d{3})", dat["txt"]): + print("matched type 4N") + print(dat["txt"]) + print() + dat["lat"] = (int(raw.group(2)) + int(raw.group(3))/600) * (-1 if raw.group(1) == "S" else 1) + dat["lon"] = (int(raw.group(5)) + int(raw.group(6))/600) * (-1 if raw.group(4) == "W" else 1) + elif dat["msgtype"] == "4T": + if raw := search(r"(\d{2})(\d{2}\.\d{1})([NS])[ 0](\d{2})(\d{2}\.\d{1})([WE])", dat["txt"]): + print("matched type 4T") + print(dat["txt"]) + print() + dat["lat"] = (int(raw.group(1)) + float(raw.group(2))/60) * (-1 if raw.group(3) == "S" else 1) + dat["lon"] = (int(raw.group(4)) + float(raw.group(5))/60) * (-1 if raw.group(6) == "W" else 1) + elif dat["msgtype"] == "21": + if raw := search(r"([NS]) (\d{2}\.\d{3})([WE]) (\d{2}\.\d{3})", dat["txt"]): + print("matched type 21") + print(dat["txt"]) + print() + dat["lat"] = float(raw.group(2)) * (-1 if raw.group(1) == "S" else 1) + dat["lon"] = float(raw.group(4)) * (-1 if raw.group(3) == "W" else 1) + elif dat["msgtype"] == "80" or dat["msgtype"] == "83": + if raw := search(r"[NS](\d{2})(\d{2}\.\d{1})[WE](\d{3)(\d{2}}\.\d{1})", dat["txt"]): + print("matched type 80/83") + print(dat["txt"]) + print() + dat["lat"] = (int(raw.group(2)) + float(raw.group(3))/60) * (-1 if raw.group(1) == "S" else 1) + dat["lon"] = (int(raw.group(5)) + float(raw.group(6))/60) * (-1 if raw.group(4) == "W" else 1) return dat def decodeACARS(msg): @@ -20,15 +61,25 @@ def decodeACARS(msg): return dat def decodeVDLM2(msg): - if msg.get("avlc") is None or msg["avlc"].get("acars") is None or msg["avlc"]["acars"].get("msg_text") is None: + if msg.get("avlc") is None: + return None + elif (msg["avlc"].get("acars") is None or msg["avlc"]["acars"].get("msg_text") is None) and (msg["avlc"].get("xid") is None or msg["avlc"]["xid"].get("vdl_params") is None): return None dat = {} dat["type"] = "vdlm2" - dat["reg"] = msg["avlc"]["acars"]["reg"] dat["time"] = int(msg["t"]["sec"]) - dat["flight"] = msg["avlc"]["acars"]["flight"] - dat["txt"] = msg["avlc"]["acars"]["msg_text"] - dat["msgtype"] = msg["avlc"]["acars"]["label"] + if not (msg["avlc"].get("acars") is None or msg["avlc"]["acars"].get("msg_text") is None): + dat["reg"] = msg["avlc"]["acars"]["reg"] + dat["flight"] = msg["avlc"]["acars"]["flight"] + dat["msgtype"] = msg["avlc"]["acars"]["label"] + dat["txt"] = msg["avlc"]["acars"]["msg_text"] + elif not (msg["avlc"].get("xid") is None or msg["avlc"]["xid"].get("vdl_params") is None): + dat["icao"] = msg["avlc"]["src"]["addr"] + for p in msg["avlc"]["xid"]["vdl_params"]: + if p["name"] == "ac_location": + dat["lat"] = p["value"]["loc"]["lat"] + dat["lon"] = p["value"]["loc"]["lon"] + print("got VDLM2 with XID pos {dat['lat']} {dat['lon']}") return dat acdb = {}