Skip to content

Commit

Permalink
Merge pull request #1 from wiedehopf/master
Browse files Browse the repository at this point in the history
make vrs happy, fix decoder error
  • Loading branch information
rpatel3001 authored Mar 7, 2024
2 parents ffbb1ef + c5d7115 commit ef75ea2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
20 changes: 18 additions & 2 deletions rootfs/scripts/acars2pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from sys import stderr
from threading import Thread, current_thread
from time import sleep
import math

import requests
from bs4 import BeautifulSoup
Expand Down Expand Up @@ -43,6 +44,21 @@ def tx_thread(host, txq):
msg = txq.get()
sock.sendall(msg.encode(enc))

def generateBasestation(sbs, squawk, lat, lon):
sbs_timestamp = f'{datetime.fromtimestamp(sbs["time"], tz=timezone.utc):%Y/%m/%d,%T}.{(math.modf(sbs["time"])[0] * 1000):03.0f}'
sbs_callsign = sbs.get("flight", "")
if sbs_callsign:
sbs_callsign = sbs_callsign.ljust(8, ' ')
if lat != None and lon != None:
latstr = f'{lat:.6f}'
lonstr = f'{lon:.6f}'
else:
latstr = ''
lonstr = ''
if not squawk:
squawk = ''
return f'MSG,3,1,1,{sbs["icao"].upper()},1,{sbs_timestamp},{sbs_timestamp},{sbs_callsign},,,,{latstr},{lonstr},,{squawk},,0,,'

# wrapper to catch exceptions and restart threads
def thread_wrapper(func, *args):
slp = 10
Expand Down Expand Up @@ -124,7 +140,7 @@ def thread_wrapper(func, *args):
logfile.write(f'{sbs["txt"]}\n\n')
else:
if s := getenv("SEND_ALL"):
out = f'MSG,3,1,1,{sbs["icao"].upper()},1,{datetime.fromtimestamp(sbs["time"], tz=timezone.utc):%Y/%m/%d,%T},{datetime.now(timezone.utc):%Y/%m/%d,%T},{sbs.get("flight", "")},,,,,,,{squawk},,,,'
out = generateBasestation(sbs=sbs, squawk=squawk, lat=None, lon=None)
if s == "log":
print(f"sending nonpos {out}")
for q in txqs:
Expand Down Expand Up @@ -213,7 +229,7 @@ def thread_wrapper(func, *args):
continue

print(f'{sbs["type"]} {sbs.get("msgtype")}', file=stderr)
out = f'MSG,3,1,1,{sbs["icao"].upper()},1,{datetime.fromtimestamp(sbs["time"], tz=timezone.utc):%Y/%m/%d,%T},{datetime.now(timezone.utc):%Y/%m/%d,%T},{sbs.get("flight", "")},,,,{lat:.3f},{lon:.3f},,{squawk},,,,'
out = generateBasestation(sbs=sbs, squawk=squawk, lat=lat, lon=lon)
print(f'https://globe.adsbexchange.com/?icao={sbs["icao"]}&showTrace={datetime.fromtimestamp(sbs["time"], tz=timezone.utc):%Y-%m-%d}&timestamp={sbs["time"]}')
print(f'{Fore.BLUE}{out}{Fore.RESET}\n', file=stderr)
for q in txqs:
Expand Down
66 changes: 28 additions & 38 deletions rootfs/scripts/acars_decode/Decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ def d3(n):
def d4(n):
return name(n, dig4)

def getLat(raw):
lat = float(raw.get("latdeg", 0))
lat += float(raw.get("latdeg100", 0))/100
lat += float(raw.get("latdeg1000", 0))/1000
lat += float(raw.get("latdeg10000", 0))/10000
lat += float(raw.get("latmin", 0))/60
lat += float(raw.get("latmin10", 0))/600
lat += float(raw.get("latmin100", 0))/6000
lat += float(raw.get("latsec", 0))/3600
lat *= -1 if raw.get("dlat") == "S" or raw.get("dlat") == "-" else 1
return lat

def getLon(raw):
lon = float(raw.get("londeg", 0))
lon += float(raw.get("londeg100", 0))/100
lon += float(raw.get("londeg1000", 0))/1000
lon += float(raw.get("londeg10000", 0))/10000
lon += float(raw.get("lonmin", 0))/60
lon += float(raw.get("lonmin10", 0))/600
lon += float(raw.get("lonmin100", 0))/6000
lon += float(raw.get("lonsec", 0))/3600
lon *= -1 if raw.get("dlon") == "W" or raw.get("dlon") == "-" else 1
return lon


rgxs = [
compile(dlat + r"[ 0]{0,2}(\d{1,2}\.\d{3}).?" + dlon + r"[ 0]{0,2}(\d{1,3}\.\d{3})"), # thousandths of degrees
Expand Down Expand Up @@ -153,25 +177,8 @@ def decode(msg):
print(pos)
raw = rgx.search(dat["txt"]).groupdict()
print(raw)
dat["lat"] = float(raw.get("latdeg", 0))
dat["lat"] += float(raw.get("latdeg100", 0))/100
dat["lat"] += float(raw.get("latdeg1000", 0))/1000
dat["lat"] += float(raw.get("latdeg10000", 0))/10000
dat["lat"] += float(raw.get("latmin", 0))/60
dat["lat"] += float(raw.get("latmin10", 0))/600
dat["lat"] += float(raw.get("latmin100", 0))/6000
dat["lat"] += float(raw.get("latsec", 0))/3600
dat["lat"] *= -1 if raw.get("dlat") == "S" or raw.get("dlat") == "-" else 1

dat["lon"] = float(raw.get("londeg", 0))
dat["lon"] += float(raw.get("londeg100", 0))/100
dat["lon"] += float(raw.get("londeg1000", 0))/1000
dat["lon"] += float(raw.get("londeg10000", 0))/10000
dat["lon"] += float(raw.get("lonmin", 0))/60
dat["lon"] += float(raw.get("lonmin10", 0))/600
dat["lon"] += float(raw.get("lonmin100", 0))/6000
dat["lon"] += float(raw.get("lonsec", 0))/3600
dat["lon"] *= -1 if raw.get("dlon") == "W" or raw.get("dlon") == "-" else 1
dat["lat"] = getLat(raw)
dat["lon"] = getLon(raw)

if dat.get("lat"):
if dat["type"] == "hfdl" or checkpos(dat["lat"], dat["lon"]):
Expand All @@ -190,25 +197,8 @@ def decode(msg):
print(pos)
raw = rgx.search(dat["txt"]).groupdict()
print(raw)
dat["lat"] = float(raw.get("latdeg", 0))
dat["lat"] += float(raw.get("lat100", 0))/100
dat["lat"] += float(raw.get("lat1000", 0))/1000
dat["lat"] += float(raw.get("lat10000", 0))/10000
dat["lat"] += float(raw.get("latmin", 0))/60
dat["lat"] += float(raw.get("latmin10", 0))/600
dat["lat"] += float(raw.get("latmin100", 0))/6000
dat["lat"] += float(raw.get("latsec", 0))/3600
dat["lat"] *= -1 if raw.get("dlat") == "S" or raw.get("dlat") == "-" else 1

dat["lon"] = float(raw.get("londeg", 0))
dat["lon"] += float(raw.get("lon100", 0))/100
dat["lon"] += float(raw.get("lon1000", 0))/1000
dat["lon"] += float(raw.get("lon10000", 0))/10000
dat["lon"] += float(raw.get("lonmin", 0))/60
dat["lon"] += float(raw.get("lonmin10", 0))/600
dat["lon"] += float(raw.get("lonmin100", 0))/6000
dat["lon"] += float(raw.get("lonsec", 0))/3600
dat["lon"] *= -1 if raw.get("dlon") == "W" or raw.get("dlon") == "-" else 1
dat["lat"] = getLat(raw)
dat["lon"] = getLon(raw)

if dat.get("lat"):
if dat["type"] == "hfdl" or checkpos(dat["lat"], dat["lon"]):
Expand Down

0 comments on commit ef75ea2

Please sign in to comment.