Skip to content

Commit

Permalink
add option to send non position messages on SBS
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatel3001 committed Mar 2, 2024
1 parent 6c33bfd commit 94f500e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Under active development, everything is subject to change without notice.
| `LON` | Longitude of receiver. Only required if `MAX_DISTANCE` > 0 | Unset |
| `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 print a log entry for each non-position message. | Unset |

## Docker Compose

Expand Down
19 changes: 11 additions & 8 deletions rootfs/scripts/acars2pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ def thread_wrapper(func, *args):
if sbs is None:
continue

if not sbs.get("txt") and not sbs.get("lat"):
continue

if not sbs.get("reg"):
sbs["reg"] = icao2reg(sbs.get("icao", ""))

Expand All @@ -115,7 +112,7 @@ def thread_wrapper(func, *args):
elif sbs["type"] == "hfdl":
squawk = "3333"
else:
squawk = "0000"
squawk = "9999"

if sbs.get("lat"):
lat = sbs["lat"]
Expand All @@ -126,6 +123,16 @@ def thread_wrapper(func, *args):
logfile.write(f'{sbs["lat"]}, {sbs["lon"]}\n')
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},,,,'
if s == "log":
print(f"sending nonpos {out}")
for q in txqs:
q.put(out+"\r\n")

if not sbs.get("txt"):
continue

if getenv("LOG_FILE") and sbs.get("msgtype") and sbs.get("type") != "hfdl":
with open(f"/log/nopos.log", "a", 1) as logfile:
logfile.write(f'{sbs["type"]}\t{sbs.get("msgtype")}\thttps://globe.adsbexchange.com/?icao={sbs["icao"]}&showTrace={datetime.fromtimestamp(sbs["time"], tz=timezone.utc):%Y-%m-%d}&timestamp={sbs["time"]}\n')
Expand Down Expand Up @@ -206,13 +213,9 @@ def thread_wrapper(func, *args):
continue

print(f'{sbs["type"]} {sbs.get("msgtype")}', file=stderr)
# print(pos, 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},,,,'

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:
q.put(out+"\r\n")
except BaseException:
Expand Down
1 change: 1 addition & 0 deletions rootfs/scripts/acars_decode/Decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def decode(msg):
print(f"regex {i} matched message type {dat['msgtype']}")
print(pos)
raw = rgx.search(dat["txt"])
print(raw)
if i == 0:
dat["lat"] = float(raw[2]) * (-1 if raw[1] == "S" else 1)
dat["lon"] = float(raw[4]) * (-1 if raw[3] == "W" else 1)
Expand Down

0 comments on commit 94f500e

Please sign in to comment.