Skip to content

Commit

Permalink
Merge pull request #14 from ke5gdb/master
Browse files Browse the repository at this point in the history
Add Chasemapper / UDP Payload Summary emitter
  • Loading branch information
darksidelemm authored Sep 7, 2024
2 parents 81e5bb2 + 30e3f8f commit 9959be4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
7 changes: 6 additions & 1 deletion rx/start_rx_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ fi
: "${BIAS:=0}"
: "${BAUD_RATE:=115177}"
: "${OVERSAMPLING:=8}"
: "${UDP_PORT:=0}"

# Start up the SSDV Uploader script and push it into the background.
python3 ssdvuploader.py "$MYCALL" &
SSDV_UPLOAD_PID=$!

# Start the Web Interface Server
python3 wenetserver.py "$MYCALL" &
if [ "$UDP_PORT" = "0" ]; then
python3 wenetserver.py "$MYCALL" &
else
python3 wenetserver.py "$MYCALL" -u "$UDP_PORT" &
fi
WEB_VIEWER_PID=$!

# Calculate the SDR sample rate required.
Expand Down
67 changes: 64 additions & 3 deletions rx/wenetserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
# PySondeHub Uploader, instantiated later.
sondehub = None

# UDP port for Payload Summary emit
udp_emit_port = 0

# Latest Image
latest_image = None
latest_image_lock = Lock()
Expand Down Expand Up @@ -127,7 +130,7 @@ def handle_gps_telemetry(gps_data):
logging.debug("No GPS lock - discarding GPS telemetry.")
return


if sondehub:
# Add to the SondeHub-Amateur uploader!
sondehub.add_telemetry(
Expand All @@ -147,9 +150,63 @@ def handle_gps_telemetry(gps_data):
snr = round(current_modem_stats['snr'],1)
)

# TODO - Emit as a Horus UDP Payload Summary packet.

# Emit as a Horus UDP Payload Summary packet.
if udp_emit_port > 0:
try:
# Prepare heading & speed fields, if they are provided in the incoming telemetry blob.

# Generate 'short' time field.
_short_time = gps_data['timestamp'].split('T')[1] + 'Z'

packet = {
"type": "PAYLOAD_SUMMARY",
"station": my_callsign,
"callsign": current_callsign + "-Wenet",
"latitude": round(gps_data['latitude'],6),
"longitude": round(gps_data['longitude'],6),
"altitude": round(gps_data['altitude'],1),
"sats": gps_data['numSV'],
"speed": round(gps_data['ground_speed'],1),
"heading": round(gps_data['heading'],1),
"time": _short_time,
"frequency": round(current_modem_stats['fcentre']/1e6, 5),
"snr": round(current_modem_stats['snr'],1),
"comment": "Wenet",
}

# Set up our UDP socket
_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
_s.settimeout(1)
# Set up socket for broadcast, and allow re-use of the address
_s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# Under OSX we also need to set SO_REUSEPORT to 1
try:
_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
except:
pass

try:
_s.sendto(
json.dumps(packet).encode("ascii"),
("<broadcast>", udp_emit_port),
)
# Catch any socket errors, that may occur when attempting to send to a broadcast address
# when there is no network connected. In this case, re-try and send to localhost instead.
except socket.error as e:
logging.debug(
"Send to broadcast address failed, sending to localhost instead."
)
_s.sendto(
json.dumps(packet).encode("ascii"),
("127.0.0.1", udp_emit_port),
)

_s.close()

except Exception as e:
logging.error("Error sending Payload Summary: %s" % str(e))

def handle_telemetry(packet):
""" Handle GPS and Text message packets from the wenet receiver """
Expand Down Expand Up @@ -256,9 +313,10 @@ def udp_rx_thread():

parser = argparse.ArgumentParser()
parser.add_argument("callsign", help="SondeHub-Amateur Uploader Callsign")
parser.add_argument("-l", "--listen_port",default=5003,help="Port to run Web Server on. (Default: 5003)")
parser.add_argument("-l", "--listen_port", default=5003, help="Port to run Web Server on. (Default: 5003)")
parser.add_argument("-v", "--verbose", action='store_true', help="Enable debug output.")
parser.add_argument("--no_sondehub", action='store_true', help="Disable SondeHub-Amateur position upload.")
parser.add_argument("-u", "--udp_port", default=None, type=int, help="Port to emit Horus UDP packets on. (Default: 0 (disabled), Typical: 55673)")
args = parser.parse_args()


Expand All @@ -275,6 +333,9 @@ def udp_rx_thread():
if not args.no_sondehub:
sondehub = Uploader(my_callsign, software_name="pysondehub-wenet", software_version=WENET_VERSION)

if args.udp_port:
udp_emit_port = args.udp_port

logging.getLogger("werkzeug").setLevel(logging.ERROR)
logging.getLogger("socketio").setLevel(logging.ERROR)
logging.getLogger("engineio").setLevel(logging.ERROR)
Expand Down
8 changes: 8 additions & 0 deletions start_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ BAUD_RATE=115177
OVERSAMPLING=8


# UDP Payload Summary
# Default: 0 (disabled)
# Set this to a valid UDP port (55673 typically) to emit payload summary packets for use
# with Chasemapper
UDP_PORT=0


# Stop and remove any existing wenet instances
echo "Stopping/Removing any existing Wenet instances..."
docker stop wenet || true && docker rm wenet || true
Expand All @@ -57,6 +64,7 @@ docker run -d \
-e BAUD_RATE=$BAUD_RATE \
-e OVERSAMPLING=$OVERSAMPLING \
-e DEVICE=$DEVICE \
-e UDP_PORT=$UDP_PORT \
-v ~/wenet/rx_images/:/opt/wenet/rx_images/ \
--device /dev/bus/usb \
-p 5003:5003 \
Expand Down

0 comments on commit 9959be4

Please sign in to comment.