Skip to content

Commit

Permalink
add back some extra processing, should this go in acarshub?
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatel3001 committed Mar 25, 2024
1 parent 6d5c2db commit 4f6774e
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 1 deletion.
27 changes: 26 additions & 1 deletion rootfs/etc/scripts/reformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from threading import Thread, current_thread
from time import sleep

from util import geslookup

#from colorama import Fore

def rx_thread(port, rxq):
Expand Down Expand Up @@ -81,7 +83,7 @@ def thread_wrapper(func, *args):
fn1 = compile(r"\/FN(?P<fn>\w+)\/")
fn2 = compile(r"\/FMH(?P<fn>\w+),")

gs1 = compile(r"^\/(?P<gs>\w{7})\.")
gs1 = compile(r"[\s\/](?P<gs>\w{7})\.")

while True:
try:
Expand All @@ -94,13 +96,36 @@ def thread_wrapper(func, *args):

out = data

# convert station ID tag to frequency, remove tag
try:
station = data["source"]["station_id"]
out["source"]["station_id"] = station[:station.rindex("-")]
out["freq"] = 1545.0 if "6" in station else 1545.075 if "12" in station else 1546.0
except:
pass

# try to extract flight number
flight = ""
fl1 = fn1.search(data.get("message", ""))
if fl1:
flight = fl1.groupdict().get("fn")
if not flight:
fl2 = fn2.search(data.get("message", ""))
if fl2:
flight = fl2.groupdict().get("fn")

if flight and len(flight) <= 9:
out["flight"] = flight

# try to decode ground station
gsa = data.get("libacars", {}).get("arinc622", {}).get("gs_addr", "")
if not gsa:
ges1 = gs1.search(data.get("message", ""))
if ges1:
gsa = ges1.groupdict().get("gs")
if decoded := geslookup(gsa):
out["fromaddr_decoded"] = f"{gsa}/{geslookup(gsa)}"

if (getenv("LOG_IN_JSON")) or (getenv("LOG_IN_JSON_FILT") and "ACARS" == data.get("msg_name")):
pprint(data)
print()
Expand Down
127 changes: 127 additions & 0 deletions rootfs/etc/scripts/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
gesLoc = {
"ABJCAYA": "Abidjan (Ivory Coast)",
"ACCFAYA": "Accra (Ghana)",
"AKLCDYA": "Auckland Oceanic (NZ)",
"ALGCAYA": "Alger (Algeria)",
"ANCATYA": "Anchorage Oceanic (USA)",
"ANCXFXA": "Anchorage Domestic (USA)",
"AUHABYA": "",
"AUHCAYA": "",
"BAHCEYA": "",
"BDOCAYA": "Bodo Oceanic (Norway)",
"BJSATYA": "",
"BJSGWYA": "Beijing (China)",
"BKKCAYA": "Thailand",
"BKKGWXA": "Bangkok (Thailand)",
"BNECAYA": "Brisbane (AUS)",
"BOMCAYA": "Mumbai (India)",
"BOMCDYA": "",
"BZVCAYA": "Brazzaville (Congo)",
"CAICAYA": "Egypt",
"CAICDYA": "Cairo (Egypt)",
"CANGWYA": "Guangzhou (China)",
"CAYCAYA": "Cayenne (French Guiana)",
"CCUCAYA": "Kolkata (India)",
"CCUCBYA": "Kolkata (India)",
"CDGATYA": "Paris (France)",
"CMBCAYA": "Colombo (Sri Lanka)",
"CMBCBYA": "Colombo (Sri Lanka)",
"CTUGWYA": "Chengdu (China)",
"DATSAXS": "",
"DDLCVXA": "Bodo (Norway)",
"DELCAYA": "Delhi (India)",
"DKRCAYA": "Dakar Oceanic (Senegal)",
"DOHATYA": "Doha (Qatar)",
"DXBEGEK": "",
"FIHCAYA": "Congo",
"FUKJJYA": "Fukuoka (Japan)",
"GDXE1XA": "Magadan (Russia)",
"GDXGWXA": "Magadan (Russia)",
"GVACBYA": "",
"GVSCAYA": "Sal Oceanic (Cape Verde)",
"GYDCDYA": "",
"HDQOILX": "",
"HKGCCYA": "Hong Kong",
"HRBGWYA": "Harbin (China)",
"JAKGWXA": "Jakarta (Indonesia)",
"JEDAAYA": "",
"JEDATYA": "",
"JNBCAYA": "Johannesburg Oceanic (SA)",
"KANCAYA": "Kano (Nigeria)",
"KMGGWYA": "Kunming (China)",
"KRTCAYA": "Khartoum (Sudan)",
"KRTCDYA": "Sudan",
"KULCAYA": "Kuala Lumpur (Malaysia)",
"LADCAYA": "Angola (Luanda)",
"LHWGWYA": "Lanzhou (China)",
"LISACYA": "Lisboa (Portugal)",
"LPAFAYA": "Canarias (Spain)",
"LXAGWYA": "Lhasa (China)",
"MAACAYA": "Chennai (India)",
"MADAAYA": "",
"MADCDYA": "",
"MCTASWY": "Muscat (Oman)",
"MELCAYA": "Melbourne (AUS)",
"MEXCAYA": "Mexico",
"MGQCAYA": "Ethiopia",
"MLECAYA": "Male (Maldives)",
"MNLCBYA": "Manila (Philippines)",
"MRUCAYA": "Mauritius (Mauritius)",
"MSTEC7X": "Maastricht (NL)",
"NANCDYA": "Nadi (Fiji)",
"NBOCAYA": "Kenya (Niarobi)",
"NDJCAYA": "N'Djamena (Chad)",
"NIMCAYA": "Niamey (Niger)",
"NKCCAYA": "Dakar Domestic (Senegal)",
"NYCODYA": "New York Oceanic (USA)",
"OAKODYA": "Oakland Oceanic (USA)",
"PAREUYA": "France",
"PIKCAYA": "Scottish (UK)",
"PIKCLXS": "Prestwick Domestic (UK)",
"PIKCLYA": "Prestwick Oceanic (UK)",
"PIKCPYA": "Shanwick (UK)",
"POMCAYA": "Port Moresby (PG)",
"POSCLYA": "Piarco (Trinidad)",
"PPTCDYA": "Tahiti (French Polynesia)",
"RECOEYA": "Atlantico (Brazil)",
"REKCAYA": "Reykjavik (Iceland)",
"RGNCAYA": "Yangon (Myanmar)",
"RIOCDYA": "",
"RPHIAYA": "Manila (Philippines)",
"RUHAAYA": "",
"SCLCAYA": "Antofagasta (Chile)",
"SELCAXH": "Seoul (Korea)",
"SEZCAYA": "Seychelles",
"SGNGWXA": "Ho Chi Minh (Vietnam)",
"SHAGWYA": "Shanghai (China)",
"SINCDYA": "Singapore",
"SINCXYA": "Singapore",
"SMACAYA": "Santa Maria (Portugal)",
"SNNCPXA": "Shannon (Ireland)",
"SOUCAYA": "London (UK)",
"SPLATYA": "Amsterdam Schipol (NL)",
"TASCAXH": "Tashkent (Uzbekistan)",
"TGUACAY": "Honduras (Cenamer)",
"TGUACYA": "Cenamar (Honduras)",
"TNRCAYA": "Antananarivo (Madagascar)",
"ULNGWXA": "Ulan Bataar (Mongolia)",
"UPGCAYA": "Makassar (Indonesia)",
"URCE1YA": "Urumqi (China)",
"URCGWYA": "Urum-Qi (China)",
"USADCXA": "USA Domestic (USA)",
"YEGCDYA": "Edmonton (Canada)",
"YEGE2YA": "Edmonton (Canada)",
"YQME2YA": "Moncton (Canada)",
"YQXD2YA": "Gander Domestic (Canada)",
"YQXE2YA": "Gander Oceanic (Canada)",
"YULE2YA": "Montreal (Canada)",
"YVRE2YA": "Vancouver (Canada)",
"YWGE2YA": "Winnipeg (Canada)",
"YYZE2YA": "Toronto (Canada)"
}

def geslookup(gsa):
txt = gesLoc.get(gsa)
if not txt:
pass
return txt

0 comments on commit 4f6774e

Please sign in to comment.