diff --git a/Dockerfile b/Dockerfile index 392b439..ee38401 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,8 @@ ENV DEVICE_INDEX="" \ SERIAL="" \ SOAPYSDR="" \ SERVER_PORT="5556" \ - VDLM_FILTER_ENABLE="TRUE" + VDLM_FILTER_ENABLE="TRUE" \ + MIN_MESSAGE_THESHOLD="5" SHELL ["/bin/bash", "-o", "pipefail", "-c"] diff --git a/README.md b/README.md index 95bc0d7..e0682f4 100644 --- a/README.md +++ b/README.md @@ -66,19 +66,20 @@ Keep in mind not every SDR is usable with HF decoding. If you have an SDR that i ## Configuration options -| Variable | Description | Required | Default | -| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------- | -| `TZ` | Your timezone | No | UTC | -| `SOAPYSDRDRIVER` | SoapySDR driver. Required! Should be in the format that you would use to pass in to soapysdr. See the compose example above. | Yes | `unset` | -| `GAIN_TYPE` | The type of gain to use. Can be `--gain` or `--gain-elements`. | Yes | `unset` | -| `GAIN` | The gain to use. If used with `GAIN_TYPE=--gain-elements` then this should be in the format your SDR expects. For Airspy style devices something like `IFGR=53,RFGR=2`. Otherwise, if used with `GAIN_TYPE=--gain` then it should be a single value representing a gain value your SDR supports. Example above in the compose section. | Yes | `unset` | -| `SOAPYSAMPLERATE` | The sample rate to use. The sample rate that your SDR would expect. | Yes | `unset` | -| `FEED_ID` | The feed ID to use. This is the ID that will be used to identify your feed on the ACARS Hub and any site, such as [airframes](airframes.io) that you feed. | Yes | `unset` | -| `ZMQ_MODE` | The ZMQ mode to use. Can be `server` or `client`. | Yes | `unset` | -| `ZMQ_ENDPOINT` | The ZMQ endpoint to use. If `ZMQ_MODE=server` then this should be the endpoint that `acars_router` and other consumers will connect to. If `ZMQ_MODE=client` then this should be the endpoint that a ZMQ server is listening on and expects data from. | Yes | `unset` | -| `SERVER` | If you want this container to forward JSON data, via TCP, to a consumer then set this to the IP address of a consumer | No | `unset` | -| `SERVER_PORT` | If you want this container to forward JSON data, via TCP, to a consumer then set this to the port of a consumer | No | `unset` | -| `TIMEOUT` | The number of seconds that the frequency selector will run each group of frequencies for to pick the optimal HFDL frequencies for monitoring. | No | `90` | +| Variable | Description | Required | Default | +| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------- | +| `TZ` | Your timezone | No | UTC | +| `SOAPYSDRDRIVER` | SoapySDR driver. Required! Should be in the format that you would use to pass in to soapysdr. See the compose example above. | Yes | `unset` | +| `GAIN_TYPE` | The type of gain to use. Can be `--gain` or `--gain-elements`. | Yes | `unset` | +| `GAIN` | The gain to use. If used with `GAIN_TYPE=--gain-elements` then this should be in the format your SDR expects. For Airspy style devices something like `IFGR=53,RFGR=2`. Otherwise, if used with `GAIN_TYPE=--gain` then it should be a single value representing a gain value your SDR supports. Example above in the compose section. | Yes | `unset` | +| `SOAPYSAMPLERATE` | The sample rate to use. The sample rate that your SDR would expect. | Yes | `unset` | +| `FEED_ID` | The feed ID to use. This is the ID that will be used to identify your feed on the ACARS Hub and any site, such as [airframes](airframes.io) that you feed. | Yes | `unset` | +| `ZMQ_MODE` | The ZMQ mode to use. Can be `server` or `client`. | Yes | `unset` | +| `ZMQ_ENDPOINT` | The ZMQ endpoint to use. If `ZMQ_MODE=server` then this should be the endpoint that `acars_router` and other consumers will connect to. If `ZMQ_MODE=client` then this should be the endpoint that a ZMQ server is listening on and expects data from. | Yes | `unset` | +| `SERVER` | If you want this container to forward JSON data, via TCP, to a consumer then set this to the IP address of a consumer | No | `unset` | +| `SERVER_PORT` | If you want this container to forward JSON data, via TCP, to a consumer then set this to the port of a consumer | No | `unset` | +| `TIMEOUT` | The number of seconds that the frequency selector will run each group of frequencies for to pick the optimal HFDL frequencies for monitoring. | No | `90` | +| `MIN_MESSAGE_THESHOLD` | The minimum number of messages that should be received, on average, during the rolling 30 minute time period. If the average is below this threshold the frequency selector will be re-run. | No | `5` | ## What this thing does under the hood, or why don't I specify frequencies? diff --git a/rootfs/etc/s6-overlay/scripts/hfdl_feeder b/rootfs/etc/s6-overlay/scripts/hfdl_feeder index c601a58..0b83eff 100755 --- a/rootfs/etc/s6-overlay/scripts/hfdl_feeder +++ b/rootfs/etc/s6-overlay/scripts/hfdl_feeder @@ -1,6 +1,8 @@ #!/command/with-contenv bash # shellcheck shell=bash +source /scripts/common + set -o pipefail if [[ -n ${SERVER} ]]; then diff --git a/rootfs/etc/s6-overlay/scripts/hfdl_server b/rootfs/etc/s6-overlay/scripts/hfdl_server index 61536b9..41e5185 100755 --- a/rootfs/etc/s6-overlay/scripts/hfdl_server +++ b/rootfs/etc/s6-overlay/scripts/hfdl_server @@ -1,11 +1,13 @@ #!/command/with-contenv bash #shellcheck shell=bash - set -o pipefail - set -e +source /scripts/common - # Listens for the output of dumphfdl (UDP), and makes it available for multiple processes at TCP port 15555 - # shellcheck disable=SC2016 - "${s6wrap[@]}" socat -u udp-listen:5556,fork stdout | ncat -4 --keep-open --listen 0.0.0.0 15556 +set -o pipefail +set -e - sleep 5 +# Listens for the output of dumphfdl (UDP), and makes it available for multiple processes at TCP port 15555 +# shellcheck disable=SC2016 +"${s6wrap[@]}" socat -u udp-listen:5556,fork stdout | ncat -4 --keep-open --listen 0.0.0.0 15556 + +sleep 5 diff --git a/rootfs/etc/s6-overlay/scripts/hfdl_stats b/rootfs/etc/s6-overlay/scripts/hfdl_stats index a7ec46c..31db265 100755 --- a/rootfs/etc/s6-overlay/scripts/hfdl_stats +++ b/rootfs/etc/s6-overlay/scripts/hfdl_stats @@ -1,6 +1,9 @@ #!/command/with-contenv bash #shellcheck shell=bash +#shellcheck disable=SC2154 +source /scripts/common + set -o pipefail # Require that hfdl_server is running @@ -38,11 +41,16 @@ while true; do # first, verify we have 30 minutes of data by verifying there are at least 6 files if [[ $(find /run/hfdl -type f -name 'hfdl.*.json' | wc -l) -gt 6 ]]; then # now check the last 6 files for messages - if [[ $(sed 's/}{/}\n{/g' /run/hfdl/hfdl.{0..5}.json | wc -l) -eq 0 ]]; then - "${s6wrap[@]}" echo " No messages received in last 30 minutes, killing dumphfdl to rerun the frequency optimizer" + average_message_count=$(sed 's/}{/}\n{/g' /run/hfdl/hfdl.{0..5}.json | wc -l) + average_message_count=$((average_message_count / 6)) + if [[ $average_message_count -lt $MIN_MESSAGE_THESHOLD ]]; then + "${s6wrap[@]}" echo "Average messages (${average_message_count}) received in last 30 minutes is less then the threshold (${MIN_MESSAGE_THRESHOLD})" + "${s6wrap[@]}" echo "Restarting dumphfdl to rerun the frequency optimizer" s6-svc -r /run/service/dumphfdl rm -f /run/hfdl/hfdl.*.json exit + else + "${s6wrap[@]}" echo "Average messages (${average_message_count}) received in last 30 minutes is greater then the threshold (${MIN_MESSAGE_THRESHOLD})" fi fi diff --git a/rootfs/reset-dumphfdl.sh b/rootfs/reset-dumphfdl.sh index e27d417..f9af0c6 100755 --- a/rootfs/reset-dumphfdl.sh +++ b/rootfs/reset-dumphfdl.sh @@ -1,5 +1,12 @@ #!/command/with-contenv bash #shellcheck shell=bash +#shellcheck disable=SC2154,SC1091 +source /scripts/common + + +"${s6wrap[@]}" echo "=============================================" +"${s6wrap[@]}" echo "Resetting dumphfdl" +"${s6wrap[@]}" echo "=============================================" s6-svc -r /run/service/dumphfdl || exit 1 rm -f /run/hfdl/hfdl.*.json || exit 1