From ca46b9c906440f57f7b3cbe20841cad4ba91ab6d Mon Sep 17 00:00:00 2001 From: kx1t Date: Sat, 18 May 2024 16:39:49 -0400 Subject: [PATCH] partial mlat-gps feature commit --- Dockerfile | 12 +++++ .../gpsd_mlat_restart/dependencies.d/startup | 0 .../s6-overlay/s6-rc.d/gpsd_mlat_restart/run | 2 + .../s6-overlay/s6-rc.d/gpsd_mlat_restart/type | 1 + .../s6-rc.d/user/contents.d/gpsd_mlat_restart | 0 .../etc/s6-overlay/scripts/gpsd_mlat_restart | 50 +++++++++++++++++++ rootfs/etc/s6-overlay/scripts/mlat-client | 12 ++--- 7 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/dependencies.d/startup create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/run create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/gpsd_mlat_restart create mode 100755 rootfs/etc/s6-overlay/scripts/gpsd_mlat_restart diff --git a/Dockerfile b/Dockerfile index e2802ef..c0413b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,14 @@ +FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base AS build + +RUN set -x && \ + apt-get update -y && \ + apt-get install -q -o Dpkg::Options::="--force-confnew" -y \ + git gcc && \ + cd / && \ + git clone --depth=1 --single-branch https://github.com/sdr-enthusiasts/docker-vesselalert.git && \ + cd /docker-vesselalert/src && \ + gcc -static distance.c -o distance -lm -Ofast + FROM ghcr.io/sdr-enthusiasts/docker-tar1090:latest LABEL org.opencontainers.image.source = "https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder" @@ -58,6 +69,7 @@ RUN TEMP_PACKAGES=() && \ echo "alias nano=\"nano -l\"" >> /root/.bashrc COPY rootfs/ / +COPY --from=build /docker-vesselalert/src/distance /usr/local/bin/distance # Add Container Version RUN set -x && \ diff --git a/rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/dependencies.d/startup b/rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/dependencies.d/startup new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/run b/rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/run new file mode 100755 index 0000000..8fefd29 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/gpsd_mlat_restart diff --git a/rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/type b/rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/gpsd_mlat_restart/type @@ -0,0 +1 @@ +longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/gpsd_mlat_restart b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/gpsd_mlat_restart new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/scripts/gpsd_mlat_restart b/rootfs/etc/s6-overlay/scripts/gpsd_mlat_restart new file mode 100755 index 0000000..787256e --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/gpsd_mlat_restart @@ -0,0 +1,50 @@ +#!/command/with-contenv bash +# shellcheck shell=bash disable=SC2015,SC2016,SC1091,SC2001,SC2154 + +#--------------------------------------------------------------------------------------------- +# Copyright (C) 2023-2024, Ramon F. Kolb (kx1t) and contributors +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . +#--------------------------------------------------------------------------------------------- + +source /scripts/common + +# Check if GPSD_IN has been enabled +if ! grep -qi "gpsd_in" <<< "$ULTRAFEEDER_CONFIG" && ! grep -qi "gpsd_in" <<< "$ULTRAFEEDER_NET_CONNECTOR"; then + "${s6wrap[@]}" echo "GPSD not enabled - no need to check receiver location" + exec sleep infinity +fi + +# Now wait a bit to allow GPS to establish itself +sleep "${GPSD_INITIAL_WAIT:-300}" + +# Make sure that receiver.json exists; if it doesn't we need to wait for it +while ! [[ -f /run/readsb/receiver.json ]]; do + sleep 1 & wait $! +done + +# Get initial lat/lon/alt +lat="$(jq -r .lat /run/readsb/receiver.json)" +lon="$(jq -r .lon /run/readsb/receiver.json)" + +while :; do + sleep "${GPSD_CHECK_INTERVAL:30}" & wait $! + new_lat="$(jq -r .lat /run/readsb/receiver.json)" + new_lon="$(jq -r .lon /run/readsb/receiver.json)" + new_alt="$(jq -r .alt_m_amsl /run/readsb/receiver.json)" + distance="$(nice -n 20 distance "$lat" "$lon" "$new_lat" "$new_lon")" + if (( ${distance%%.*} > ${GPSD_MIN_DISTANCE} )); then + "${s6wrap[@]}" echo "Receiver moved ${distance%%.*} meters - restarting all mlat-clients" + pkill -f "/usr/bin/python3 /usr/bin/mlat-client" >/dev/null 2>&1 + fi +done \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/scripts/mlat-client b/rootfs/etc/s6-overlay/scripts/mlat-client index 16ed88c..68075e5 100755 --- a/rootfs/etc/s6-overlay/scripts/mlat-client +++ b/rootfs/etc/s6-overlay/scripts/mlat-client @@ -51,17 +51,17 @@ then exec sleep infinity fi -if [[ -z "$LAT$READSB_LAT" ]]; then - "${s6wrap[@]}" --args echo "ERROR: READSB_LAT or LAT must be defined - MLAT will be disabled." +if [[ -z "$LAT$READSB_LAT" ]] && ! grep -qi "gpsd_in" <<< "$ULTRAFEEDER_CONFIG" && ! grep -qi "gpsd_in" <<< "$ULTRAFEEDER_NET_CONNECTOR"; then + "${s6wrap[@]}" --args echo "ERROR: READSB_LAT or LAT must be defined or GPSD must be enabled - MLAT will be disabled." exec sleep infinity fi -if [[ -z "$LONG$READSB_LON" ]]; then - "${s6wrap[@]}" --args echo "ERROR: READSB_LON or LONG must be defined - MLAT will be disabled." +if [[ -z "$LONG$READSB_LON" ]] && ! grep -qi "gpsd_in" <<< "$ULTRAFEEDER_CONFIG" && ! grep -qi "gpsd_in" <<< "$ULTRAFEEDER_NET_CONNECTOR"; then + "${s6wrap[@]}" --args echo "ERROR: READSB_LON or LONG must be defined or GPSD must be enabled - MLAT will be disabled." exec sleep infinity fi -if [[ -z "$ALT$READSB_ALT" ]]; then - "${s6wrap[@]}" --args echo "ERROR: READSB_ALT or ALT must be defined - MLAT will be disabled." +if [[ -z "$ALT$READSB_ALT" ]] && ! grep -qi "gpsd_in" <<< "$ULTRAFEEDER_CONFIG" && ! grep -qi "gpsd_in" <<< "$ULTRAFEEDER_NET_CONNECTOR"; then + "${s6wrap[@]}" --args echo "ERROR: READSB_ALT or ALT must be defined or GPSD must be enabled - MLAT will be disabled." exec sleep infinity fi