Skip to content

Commit

Permalink
add back 4N message type
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatel3001 committed Feb 26, 2024
1 parent 685b894 commit 263c808
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
6 changes: 3 additions & 3 deletions rootfs/scripts/acars2pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def thread_wrapper(func, *args):
pos2b = findall("LON", sbs["txt"])
if (len(pos1) == 1):
txt = sub(rgx1, Fore.RED + r'\1' + Fore.RESET, sbs["txt"])
print(f"old regex 1 matched message type {dat['msgtype']}")
print(f"old regex 1 matched message type {sbs['msgtype']}")
print(txt)

pos = pos1[0]
Expand Down Expand Up @@ -141,7 +141,7 @@ def thread_wrapper(func, *args):
continue
elif len(pos1b) == 1:
txt = sub(rgx2, Fore.RED + r'\1' + Fore.RESET, sbs["txt"])
print(f"old regex 2 matched message type {dat['msgtype']}")
print(f"old regex 2 matched message type {sbs['msgtype']}")
print(txt)

pos = pos1b[0]
Expand Down Expand Up @@ -171,7 +171,7 @@ def thread_wrapper(func, *args):
elif len(pos2a) and len(pos2b):
txt = sub(r'(LAT)', Fore.MAGENTA + r'\1' + Fore.RESET, sbs["txt"])
txt = sub(r'(LON)', Fore.MAGENTA + r'\1' + Fore.RESET, txt)
print(f"old regex 3 matched message type {dat['msgtype']}")
print(f"old regex 3 matched message type {sbs['msgtype']}")
print(txt)
continue
else:
Expand Down
43 changes: 28 additions & 15 deletions rootfs/scripts/acars_decode/Decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
compile(r"([NS])[ 0]{0,1}(\d{1,2})[ 0]{0,1}(\d{1,2}\.\d{1}).?([WE])[ 0]{0,2}(\d{1,3}?)[ 0]{0,1}(\d{1,2}\.\d{1})"),
compile(r"([NS])[ 0]{0,1}(\d{1,2})[ 0]{0,3}(\d{0,2}\.\d{2}).?([WE])[ 0]{0,2}(\d{1,3})[ 0]{0,1}(\d{1,2}\.\d{2})"),
compile(r"([NS])\s?(\d{2})(\d{2})(\d{2}).?([WE])\s?(\d{2,3})(\d{2})(\d{2})"),
compile(r"([NS])[ 0]{0,1}(\d{1,2})(\d{3}).?([WE])[ 0]{0,2}(\d{1,3})(\d{3})"),
compile(r"([NS])[ 0]?([ 0\d]\d)(\d{3}).?([WE])([ 0\d][ 0\d]\d)(\d{3})"),
compile(r"[0 ]{0,1}(\d{1,2})[0 ]{0,1}(\d{1,2}\.\d{1})([NS])[ 0]{0,2}(\d{1,3})[0 ]{0,1}(\d{1,2}\.\d{1})([WE])"),
compile(r"[ 0]{0,1}(\d{1,2})[ 0]{0,1}(\d{1,2})([NS])[ 0]{0,2}(\d{1,3})[ 0]{0,1}(\d{1,2})([WE])"),
compile(r"LAT ([NS]) [0 ]{0,1}(\d{1,2}):(\d{2}\.\d{1}) LONG [WE] [0 ]{0,1}(\d{1,2}):(\d{2}\.\d{1})")]
Expand All @@ -18,35 +18,48 @@ def decode(msg):
else:
dat = decodeACARS(msg)

if dat:
if dat and dat.get("msgtype") == "4N":
rgx = compile(r"([NS])(\d{3})(\d{3}) ([WE])(\d{3})(\d{3})")
raw = rgx.findall(dat["txt"])
if len(raw) == 1:
pos = dat["txt"]
for pat in raw[0]:
pos = sub(f"({pat})", Fore.GREEN + r"\1" + Fore.RESET, pos)
print(f"matched message type {dat['msgtype']}")
print(pos)
raw = rgx.search(dat["txt"])
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)

if dat and not dat.get("lat"):
dat["txt"] = dat.get("txt", "").upper().replace("\r", "").replace("\n", "")
for i,rgx in enumerate(rgxs):
raw = rgx.findall(dat["txt"])
if len(raw) == 1:
pos = dat["txt"]
for pat in raw:
for pat in raw[0]:
pos = sub(f"({pat})", Fore.RED + r"\1" + Fore.RESET, pos)
print(f"regex {i} matched message type {dat['msgtype']}")
print(pos)

raw = raw[0] #search(rgx, dat["txt"])
raw = rgx.search(dat["txt"])
if i == 0:
dat["lat"] = float(raw[1]) * (-1 if raw[0] == "S" else 1)
dat["lon"] = float(raw[3]) * (-1 if raw[2] == "W" else 1)
dat["lat"] = float(raw[2]) * (-1 if raw[1] == "S" else 1)
dat["lon"] = float(raw[4]) * (-1 if raw[3] == "W" else 1)
elif i == 1 or i == 2 or i == 7:
dat["lat"] = (int(raw[1]) + float(raw[2])/60) * (-1 if raw[0] == "S" else 1)
dat["lon"] = (int(raw[4]) + float(raw[5])/60) * (-1 if raw[3] == "W" else 1)
dat["lat"] = (int(raw[2]) + float(raw[3])/60) * (-1 if raw[1] == "S" else 1)
dat["lon"] = (int(raw[5]) + float(raw[6])/60) * (-1 if raw[4] == "W" else 1)
elif i == 3:
dat["lat"] = (int(raw[1]) + int(raw[2])/60 + int(raw[3])/3600) * (-1 if raw[0] == "S" else 1)
dat["lon"] = (int(raw[5]) + int(raw[6])/60 + int(raw[7])/3600) * (-1 if raw[4] == "W" else 1)
dat["lat"] = (int(raw[2]) + int(raw[3])/60 + int(raw[4])/3600) * (-1 if raw[1] == "S" else 1)
dat["lon"] = (int(raw[6]) + int(raw[7])/60 + int(raw[8])/3600) * (-1 if raw[5] == "W" else 1)
elif i == 4:
dat["lat"] = (int(raw[1]) + int(raw[2])/600) * (-1 if raw[0] == "S" else 1)
dat["lon"] = (int(raw[4]) + int(raw[5])/600) * (-1 if raw[3] == "W" else 1)
dat["lat"] = (int(raw[2]) + int(raw[3])/600) * (-1 if raw[1] == "S" else 1)
dat["lon"] = (int(raw[5]) + int(raw[6])/600) * (-1 if raw[4] == "W" else 1)
elif i == 5 or i == 6:
dat["lat"] = (int(raw[0]) + float(raw[1])/60) * (-1 if raw[2] == "S" else 1)
dat["lon"] = (int(raw[3]) + float(raw[4])/60) * (-1 if raw[5] == "W" else 1)
dat["lat"] = (int(raw[1]) + float(raw[2])/60) * (-1 if raw[3] == "S" else 1)
dat["lon"] = (int(raw[4]) + float(raw[5])/60) * (-1 if raw[6] == "W" else 1)

if dat.get("lat"):
if dat.get("lat") and abs(dat["lat"]) <= 90 and abs(dat["lon"]) <= 180 :
break

return dat
Expand Down

0 comments on commit 263c808

Please sign in to comment.