diff --git a/README.md b/README.md index 022bf35..8214dfe 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Under active development, everything is subject to change without notice. | `MAX_DIST` | Set this to a nonzero value to reject parsed positions that are too far away. Only applies to positions parsed from message text. | `0` | | `DIST_UNIT` | The unit of the value in `MAX_DIST`. One of `km`, `m`, `mi`, `nmi`, `ft`, `in`. | `nmi` | | `SEND_ALL` | Set to any value to send SBS messages for messages without a position. Set to `log` to also print a log entry for each non-position message. | Unset | +| `ACARS_FREQ_AS_SQUAWK`, `VDLM2_FREQ_AS_SQUAWK`, `HFDL_FREQ_AS_SQUAWK` | Set to any value to send the received frequency as the squawk value, for each incoming message type. | Unset | ## Docker Compose diff --git a/rootfs/scripts/acars2pos.py b/rootfs/scripts/acars2pos.py index 43531b5..2278c89 100755 --- a/rootfs/scripts/acars2pos.py +++ b/rootfs/scripts/acars2pos.py @@ -122,11 +122,22 @@ def thread_wrapper(func, *args): continue if sbs["type"] == "acars": - squawk = "1111" + if getenv("ACARS_FREQ_AS_SQUAWK"): + squawk = f"{round(sbs['freq']/1000-100000):d}" + else: + squawk = "1111" elif sbs["type"] == "vdlm2": - squawk = "2222" + if getenv("VDLM2_FREQ_AS_SQUAWK"): + squawk = f"{round(sbs['freq']/1000-100000):d}" + elif sbs.get("xid"): + squawk = "2220" + else: + squawk = "2222" elif sbs["type"] == "hfdl": - squawk = "3333" + if getenv("HFDL_FREQ_AS_SQUAWK"): + squawk = f"{round(sbs['freq']/1000):d}" + else: + squawk = "3333" else: squawk = "9999" diff --git a/rootfs/scripts/acars_decode/Decoder.py b/rootfs/scripts/acars_decode/Decoder.py index 3711f9c..254c614 100644 --- a/rootfs/scripts/acars_decode/Decoder.py +++ b/rootfs/scripts/acars_decode/Decoder.py @@ -252,6 +252,7 @@ def decodeACARS(msg): dat["flight"] = msg.get("flight", "") dat["txt"] = msg["text"] dat["msgtype"] = msg["label"] + dat["freq"] = round(float(msg.get("freq", 0))*1000000) return dat def decodeVDLM2(msg): @@ -262,12 +263,14 @@ def decodeVDLM2(msg): dat = {} dat["type"] = "vdlm2" dat["time"] = int(msg["t"]["sec"]) + dat["freq"] = int(msg.get("freq", 0)) if msg["avlc"].get("acars"): dat["reg"] = msg["avlc"]["acars"].get("reg", "") dat["flight"] = msg["avlc"]["acars"].get("flight", "") dat["msgtype"] = msg["avlc"]["acars"].get("label", "") dat["txt"] = msg["avlc"]["acars"].get("msg_text", "") elif not (msg["avlc"].get("xid") is None or msg["avlc"]["xid"].get("vdl_params") is None): + dat["xid"] = True dat["icao"] = msg["avlc"]["src"]["addr"] for p in msg["avlc"]["xid"]["vdl_params"]: if p["name"] == "ac_location": @@ -292,6 +295,7 @@ def decodeHFDL(msg): dat["type"] = "hfdl" dat["time"] = int(msg["t"]["sec"]) dat["flight"] = msg["lpdu"].get("hfnpdu", {}).get("flight_id", "") + dat["freq"] = int(msg.get("freq", 0)) try: dat["lat"] = msg["lpdu"]["hfnpdu"]["pos"]["lat"] dat["lon"] = msg["lpdu"]["hfnpdu"]["pos"]["lon"]