Skip to content

Commit

Permalink
standardize SBS output
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Mar 7, 2024
1 parent ffbb1ef commit de5fd1f
Showing 1 changed file with 18 additions and 2 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

0 comments on commit de5fd1f

Please sign in to comment.