Skip to content

Commit

Permalink
try matching nonexact VFO names
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatel3001 committed Mar 30, 2024
1 parent 364d44b commit 32b4f78
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ docker logs -f satdump | grep -v "(D)" | grep -v "Table Broadcast" | grep -v "Re
| `LOG_OUT_JSON_FILT` | Set to any value to log the reformatted JSON output to stdout, after filtering out non-ACARS messages. | Unset |
| `OUTPUT_ACARS_ONLY` | Set to any value to prevent outputting JSON for non-ACARS messages to ease the load on your Acarshub instance a little. | Unset |
| `STATION_ID` | The station ID to set on output messages. | Unset |
| `SNR_UPDATE_SEC` | How often to poll the HTTP API to update the VFO signal levels to attach to messages. | `1` |

## Docker Compose

Expand Down
35 changes: 23 additions & 12 deletions rootfs/etc/scripts/reformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ def thread_wrapper(func, *args):
while True:
try:
raw = rxq.get()
# print(f"{raw}\n")

data = loads(raw)
if data and (getenv("LOG_IN_JSON") or (getenv("LOG_IN_JSON_FILT") and "ACARS" == data.get("msg_name"))):
pprint(data)
print()
if not data or (getenv("OUTPUT_ACARS_ONLY") and "ACARS" != data.get("msg_name")):
continue

try:
if time() - lastSnr > 1:
if time() - lastSnr > float(getenv("SNR_UPDATE_SEC", 1)):
lastSnr = time()
snrjs = {}
rawsnrjs = requests.get("http://localhost:5000/api").json()
Expand All @@ -138,17 +144,9 @@ def thread_wrapper(func, *args):
"snr": rawsnrjs[k]['sdpsk_demod']['snr']}
except KeyError:
pass
# pprint(snrjs)
except requests.exceptions.ConnectionError:
pass

data = loads(raw)
if data and (getenv("LOG_IN_JSON") or (getenv("LOG_IN_JSON_FILT") and "ACARS" == data.get("msg_name"))):
pprint(data)
print()
if not data or "ACARS" != data.get("msg_name"):
continue

out = deepcopy(data)

# convert station ID tag to frequency, remove tag
Expand All @@ -167,8 +165,21 @@ def thread_wrapper(func, *args):
print(traceback.format_exc())

try:
if sig := snrjs[data["source"]["station_id"]]["signal"]:
out["level"] = f"{float(sig):.2f}"
if id := data.get("source", {}).get("station_id"):
if sigjs := snrjs.get(id):
if level := sigjs.get("signal"):
out["level"] = f"{float(level):.2f}"
else:
idint = int(id)
bestk = None
bestdiff = 1e6
for k,v in snrjs.items():
kint = int(k)
if abs(idint-kint) < bestdiff:
bestdiff = abs(idint-kint)
bestk = k
print(f"best match for {id} is {bestk}")
out["level"] = f"{float(snrjs[k]['signal']):.2f}"
except:
print("Couldn't set level")
print(traceback.format_exc())
Expand Down

0 comments on commit 32b4f78

Please sign in to comment.