Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ground_station/impish_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

DB_NAME = "impish"
HEALTH_TABLE_NAME = "health"
ADDR = ("10.42.0.1", 12002)
ADDR = ("", 12004)


def connect(
Expand Down
20 changes: 15 additions & 5 deletions ground_station/processes/health_listener
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and displayed by Grafana.
import socket
import time

from struct import unpack

from mysql.connector.pooling import PooledMySQLConnection
from mysql.connector.abstracts import MySQLConnectionAbstract

Expand All @@ -24,11 +26,11 @@ def unpack_power_byte(byte: int) -> dict[str, int]:
return bools


def unpack_missing_bytes(bytes: int) -> dict[str, int]:
def unpack_missing_bytes(mbytes: int) -> dict[str, int]:
"""Map the missing status bits."""
missing_cols: list[str] = [c for c in HEALTH_COLUMNS.keys() if c.startswith("missing_")]
missing_cols.remove("missing_fields")
bools: dict[str, int] = {c: int((bytes >> i) & 1) for i, c in enumerate(reversed(missing_cols))}
bools: dict[str, int] = {c: int((mbytes >> i) & 1) for i, c in enumerate(missing_cols)}
return bools


Expand All @@ -55,11 +57,19 @@ def insert_packet(
def main():
logging.log_info("Opening DB connection")
db = connect()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(ADDR)
sock.listen(1)
try:
while True:
data, _ = sock.recvfrom(1024)
connection, addr = sock.accept()
buff = connection.recv(8)
(length,) = unpack(">Q", buff)
data = b""
while len(data) < length:
to_read = length - len(data)
data += connection.recv(4096 if to_read > 4096 else to_read)
Comment thread
settwi marked this conversation as resolved.
assert length == len(data)
if len(data) > 0: # For some reason we sometimes get empty packets?
packet = HealthPacket.from_buffer_copy(data)
insert_packet(db, packet)
Expand All @@ -70,4 +80,4 @@ def main():


if __name__ == "__main__":
main()
main()
22 changes: 22 additions & 0 deletions relay/deployment/install_services
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# Install systemd services and associated process programs

# Install all processes
processes=$(ls ../processes)
for s in $processes; do
sudo cp "../processes/$s" "/usr/local/bin"
done

# Install all .service files and enable them
services=$(ls ../services/*.service)
for s in $services; do
echo $s
sudo cp "../services/$s" "/etc/systemd/system"
done
sudo cp "../services/relay-variables.env" "/usr/local/bin"
sudo cp "../../services/variables.env" "/usr/local/bin"

sudo systemctl daemon-reload
for s in $services; do
sudo systemctl restart "$(basename $s)"
done
8 changes: 8 additions & 0 deletions relay/deployment/oneshot_deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

scripts="wifi-through-ethernet install_services"
for s in $scripts; do
echo "executing $s"
./"$s"
echo "done $s"
done
4 changes: 4 additions & 0 deletions relay/deployment/wifi-through-ethernet
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# For a fresh install, Wired connection 1 is going to be what we want to share...

sudo nmcli con modify "Wired connection 1" ipv4.method shared
12 changes: 12 additions & 0 deletions relay/processes/relay_logger
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/python3

import os
import socket
import sys

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", int(os.getenv("LOGGER_PORT"))))

while True:
data = s.recv(8192)
print(f"Forwarded {len(data)}B to ground station", file=sys.stderr)
10 changes: 10 additions & 0 deletions relay/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# relay

NOTE: this is **not** to be installed on the IMPISH flight computer.

This defines some code that simply acts to forward packets from IMPISH to some destination (e.g. the ground station).
Currently, this is installed onto a Raspberry Pi 3 and has a direct ethernet connection to IMPISH.
The intent is to loosely mimic the gondola.
This code will definitely evolve as we receive more details about how the gondola will handle packets.

This will be particularly useful during vacuum testing, as we will be able to place the relay in the chamber with IMPISH and wirelessly forward packets out of the chamber.
20 changes: 20 additions & 0 deletions relay/services/relay-logger.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=Log the number of bytes per forwarded packet
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
WorkingDirectory=/usr/local/bin
EnvironmentFile=/home/relay/gs-ip.env
EnvironmentFile=/usr/local/bin/relay-variables.env
EnvironmentFile=/usr/local/bin/variables.env
ExecStart=relay_logger
StandardOutput=journal
StandardError=journal
Restart=on-failure
RestartSec=5
User=relay

[Install]
WantedBy=multi-user.target
2 changes: 2 additions & 0 deletions relay/services/relay-variables.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GROUNDSTATION_PORT=12100
LOGGER_PORT=12345
20 changes: 20 additions & 0 deletions relay/services/relay.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[Unit]
Description=Relay all packets from IMPISH to the ground station.
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
WorkingDirectory=/usr/local/bin
EnvironmentFile=/home/relay/gs-ip.env
EnvironmentFile=/usr/local/bin/relay-variables.env
EnvironmentFile=/usr/local/bin/variables.env
ExecStart=udpcapture --port ${ENDPOINT_PORT} -f "${GROUNDSTATION_IP}:${GROUNDSTATION_PORT}" -f "127.0.0.1:${LOGGER_PORT}"
StandardOutput=journal
StandardError=journal
Restart=on-failure
RestartSec=5
User=relay

[Install]
WantedBy=multi-user.target