Skip to content

Commit

Permalink
add level data
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatel3001 committed Mar 30, 2024
1 parent 3aa620f commit 364d44b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM ghcr.io/sdr-enthusiasts/docker-baseimage:rtlsdr

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

COPY satdump.patch /tmp/satdump.patch

# hadolint ignore=DL3008,SC2086,DL4006,SC2039
RUN set -x && \
TEMP_PACKAGES=() && \
Expand All @@ -21,6 +23,7 @@ RUN set -x && \
"${TEMP_PACKAGES[@]}" && \
git clone https://github.com/altillimity/satdump.git /src/satdump && \
pushd /src/satdump && \
git apply /tmp/satdump.patch && \
sed -i '/zenity/d' packages.runner && \
xargs -a /src/satdump/packages.builder apt install --no-install-recommends -qy && \
xargs -a /src/satdump/packages.runner apt install -qy && \
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rpatel3001/docker-satdump/deploy.yml?branch=master)](https://github.com/rpatel3001/docker-satdump/actions/workflows/deploy.yml)
[![Discord](https://img.shields.io/discord/734090820684349521)](https://discord.gg/sTf9uYF)

A Docker image with satdump installed. Currently it runs an arbitrary command on startup, but that will change in the future.
A Docker image with satdump installed. Currently it runs an arbitrary command on startup, but that may change in the future.

There is a python script also run at startup which takes the satdump UDP JSON messages and reformats them as acarshub compatible JSON.
There is a python script also run at startup which enriches the satdump JSON with ground station names, frequency and level information, and more.

Under active development, everything is subject to change without notice.

Expand All @@ -29,12 +29,11 @@ docker logs -f satdump | grep -v "(D)" | grep -v "Table Broadcast" | grep -v "Re
| `LOG_OUT_JSON` | Set to any value to log the reformatted JSON output to stdout. | Unset |
| `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 |

## Docker Compose

```
version: "3"
services:
satdump:
container_name: satdump
Expand All @@ -48,8 +47,8 @@ services:
- ./vfo.json:/vfo.json
- ./Inmarsat.json:/usr/share/satdump/pipelines/Inmarsat.json
environment:
- RUN_CMD=satdump live inmarsat_aero_6 /tmp/satdump_out --source rtltcp --ip_address 10.0.0.114 --port 7373 --gain 49 --samplerate 1.536e6 --frequency 1545.6e6 --multi_vfo /vfo.json 2>&1 | grep -v "Invalid CRC!"
# - RUN_CMD=satdump live inmarsat_aero_6 /tmp/satdump_out --source rtlsdr --source_id 0 --gain 49 --samplerate 1.536e6 --frequency 1545.6e6 --multi_vfo /vfo.json 2>&1 | grep -v "Invalid CRC!"
- RUN_CMD=satdump live inmarsat_aero_6 /tmp/satdump_out --source rtltcp --ip_address 10.0.0.114 --port 7373 --gain 49 --samplerate 1.536e6 --frequency 1545.6e6 --multi_vfo /vfo.json --http_server 0.0.0.0:5000 2>&1 | grep -v "Invalid CRC!"
# - RUN_CMD=satdump live inmarsat_aero_6 /tmp/satdump_out --source rtlsdr --source_id 0 --gain 49 --samplerate 1.536e6 --frequency 1545.6e6 --multi_vfo /vfo.json --http_server 0.0.0.0:5000 2>&1 | grep -v "Invalid CRC!"
- STATION_ID=XX-YYY-IMSL-98W
acarshub:
Expand Down
59 changes: 53 additions & 6 deletions rootfs/etc/scripts/reformat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from re import compile
import locale
import socket
Expand All @@ -10,8 +11,9 @@
import prctl
from queue import SimpleQueue
from threading import Thread, current_thread
from time import sleep
from time import sleep, time
from csv import DictReader
import requests

from util import geslookup

Expand Down Expand Up @@ -104,27 +106,72 @@ def thread_wrapper(func, *args):

gs1 = compile(r"^(\/|- #\w{2}\/\w{2} )(?P<gs>\w{7})\.")

lastSnr = 0

while True:
try:
raw = rxq.get()
# print(f"{raw}\n")

try:
if time() - lastSnr > 1:
lastSnr = time()
snrjs = {}
rawsnrjs = requests.get("http://localhost:5000/api").json()
for k, v in rawsnrjs.items():
try:
snrjs[k] = {"ber": rawsnrjs[k]['inmarsat_aero_decoder']['viterbi_ber'],
"lock": rawsnrjs[k]['inmarsat_aero_decoder']['correlator_lock'],
"freq": rawsnrjs[k]['psk_demod']['freq'],
"signal": rawsnrjs[k]['psk_demod']['signal'],
"noise": rawsnrjs[k]['psk_demod']['noise'],
"peak_snr": rawsnrjs[k]['psk_demod']['peak_snr'],
"snr": rawsnrjs[k]['psk_demod']['snr']}
except KeyError:
try:
snrjs[k] = {"ber": rawsnrjs[k]['inmarsat_aero_decoder']['viterbi_ber'],
"lock": rawsnrjs[k]['inmarsat_aero_decoder']['correlator_lock'],
# "freq": rawsnrjs[k]['sdpsk_demod']['freq'],
"signal": rawsnrjs[k]['sdpsk_demod']['signal'],
"noise": rawsnrjs[k]['sdpsk_demod']['noise'],
"peak_snr": rawsnrjs[k]['sdpsk_demod']['peak_snr'],
"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 = data
out = deepcopy(data)

# convert station ID tag to frequency, remove tag
try:
out["freq"] = int(data["source"]["station_id"])/1e6
if freq := data["source"]["station_id"]:
out["freq"] = f"{int(freq)/1e6:.3f}"
except:
pass
print("Couldn't set freq")
print(traceback.format_exc())

out["source"]["station_id"] = getenv("STATION_ID")
try:
if id := getenv("STATION_ID"):
out["source"]["station_id"] = id
except:
print("Couldn't set station id")
print(traceback.format_exc())

try:
if sig := snrjs[data["source"]["station_id"]]["signal"]:
out["level"] = f"{float(sig):.2f}"
except:
print("Couldn't set level")
print(traceback.format_exc())

# try to extract flight number
flight = ""
Expand Down Expand Up @@ -160,7 +207,7 @@ def thread_wrapper(func, *args):
print(f"ground station {gsa} not found")
out["fromaddr_decoded"] = fromaddr

if not getenv("OUTPUT_ACARS_ONLY") or data["msg_name"] == "ACARS":
if not getenv("OUTPUT_ACARS_ONLY") or "ACARS" == out.get("msg_name"):
if (getenv("LOG_OUT_JSON")) or (getenv("LOG_OUT_JSON_FILT") and "ACARS" == out.get("msg_name")):
pprint(out)
print()
Expand Down
57 changes: 57 additions & 0 deletions satdump.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
diff --git a/src-core/modules/demod/module_demod_base.h b/src-core/modules/demod/module_demod_base.h
index cd88fdfb..3e11c863 100644
--- a/src-core/modules/demod/module_demod_base.h
+++ b/src-core/modules/demod/module_demod_base.h
@@ -72,7 +72,7 @@ namespace demod
std::atomic<uint64_t> progress;

M2M4SNREstimator snr_estimator;
- float snr, peak_snr;
+ float snr, peak_snr, signal, noise;

bool show_freq = false;
float display_freq = 0;
diff --git a/src-core/modules/demod/module_psk_demod.cpp b/src-core/modules/demod/module_psk_demod.cpp
index d26fb12e..d74c4dbc 100644
--- a/src-core/modules/demod/module_psk_demod.cpp
+++ b/src-core/modules/demod/module_psk_demod.cpp
@@ -184,6 +184,8 @@ namespace demod
// Estimate SNR
snr_estimator.update(rec->output_stream->readBuf, dat_size);
snr = snr_estimator.snr();
+ signal = snr_estimator.signal();
+ noise = snr_estimator.noise();

if (snr > peak_snr)
peak_snr = snr;
@@ -218,6 +220,8 @@ namespace demod
module_stats["snr"] = snr;
module_stats["peak_snr"] = peak_snr;
module_stats["freq"] = display_freq;
+ module_stats["signal"] = signal;
+ module_stats["noise"] = noise;

if (input_data_type == DATA_FILE)
progress = file_source->getPosition();
diff --git a/src-core/modules/demod/module_sdpsk_demod.cpp b/src-core/modules/demod/module_sdpsk_demod.cpp
index 52920f03..44df41e8 100644
--- a/src-core/modules/demod/module_sdpsk_demod.cpp
+++ b/src-core/modules/demod/module_sdpsk_demod.cpp
@@ -112,6 +112,8 @@ namespace demod
// Estimate SNR
snr_estimator.update((complex_t *)rec->output_stream->readBuf, dat_size / 2);
snr = snr_estimator.snr();
+ signal = snr_estimator.signal();
+ noise = snr_estimator.noise();

if (snr > peak_snr)
peak_snr = snr;
@@ -132,6 +134,8 @@ namespace demod
// Update module stats
module_stats["snr"] = snr;
module_stats["peak_snr"] = peak_snr;
+ module_stats["signal"] = signal;
+ module_stats["noise"] = noise;

if (time(NULL) % 10 == 0 && lastTime != time(NULL))
{

0 comments on commit 364d44b

Please sign in to comment.