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
115 changes: 64 additions & 51 deletions base_station_gui.py

Large diffs are not rendered by default.

1,900 changes: 1,900 additions & 0 deletions base_station_gui_old.py

Large diffs are not rendered by default.

467 changes: 178 additions & 289 deletions base_station_main.py

Large diffs are not rendered by default.

378 changes: 378 additions & 0 deletions base_station_main_old.py

Large diffs are not rendered by default.

588 changes: 285 additions & 303 deletions bue_main.py

Large diffs are not rendered by default.

29 changes: 8 additions & 21 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
"""Simple Dictionary to map Reyex names to bUE names"""
from enum import Enum, auto

bUEs = {
"10": "Doof",
"70": "Candace",
"30": "Major",
"40": "Buford",
"50": "Carl",
"60": "Perry",
}

bUEs_inverted = {
"Doof": "10",
"Candace": "70",
"Major": "30",
"Buford": "40",
"Carl": "50",
"Perry": "60",
}

""" Defines how many seconds pass until the base station/bUE consider themselves disconnected
TIMEOUT * 10 seconds must pass"""
TIMEOUT = 6
class State(Enum):
INIT = auto()
CONNECT_OTA = auto()
IDLE = auto()
WAIT_FOR_START = auto()
UTW_TEST = auto()
TEST_CLEANUP = auto()
49 changes: 34 additions & 15 deletions ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
import queue
import crc8

from constants import bUEs


class Ota:
def __init__(self, port, baudrate, stdout_history=None):

Expand All @@ -38,6 +35,9 @@ def __init__(self, port, baudrate, stdout_history=None):
# Received messages buffer
self.recv_msgs = queue.Queue()

# Internal Reyax messages buffer
self.internal_msgs = queue.Queue()

# Reading thread
self.thread = threading.Thread(target=self.read_from_port, daemon=True)
self.thread.start() # keeping the program from exiting
Expand All @@ -56,12 +56,19 @@ def read_from_port(self):
"""
while not self.exit_event.is_set():
try:
message_with_crc = self.ser.readline().decode("utf-8", errors="ignore").strip()
parts = message_with_crc.split(",")
message = self.ser.readline().decode("utf-8", errors="ignore").strip()

if message == "" or message == "OK":
continue

if message_with_crc == "" or message_with_crc == "OK":
if not message.startswith("+RCV="):
self.internal_msgs.put(message)
continue

# else, we have a RVC message, needs to do reverse crc
message_with_crc = message
parts = message_with_crc.split(",")

# print(f"Message with CRC: {message_with_crc}")

if len(parts) < 5:
Expand All @@ -77,7 +84,7 @@ def read_from_port(self):
if not valid_crc: # Bad checksum
self.send_ota_message(origin, "BAD")
if self.stdout_history:
self.stdout_history.append(f"Got a message with a bad checksum from {bUEs(str(origin))}")
self.stdout_history.append(f"Got a message with a bad checksum from {origin}")
continue

self.recv_msgs.put(f"{origin},{original_message}")
Expand Down Expand Up @@ -159,15 +166,27 @@ def fetch_id(self):
Fetch the device ID from the Reyax module.
"""
try:
self.ser.write(b'AT+ADDRESS=?\r\n')
addr_req = f'AT+ADDRESS=?\r\n'
self.ser.write(addr_req.encode("utf-8"))
time.sleep(0.1) # Wait for response
response = self.ser.readlines()
for line in response:
decoded_line = line.decode('utf-8').strip()
if decoded_line.startswith('+ADDRESS='):
addr = decoded_line.split('=')[1]
self.id = int(addr)
return self.id
try:
while True:
response = self.internal_msgs.get_nowait()
# response may be bytes or str; handle both and also handle multiple lines
if isinstance(response, bytes):
lines = [response.decode('utf-8', errors='ignore').strip()]
else:
lines = [ln.strip() for ln in str(response).splitlines() if ln.strip()]

for line in lines:
if line.startswith('+ADDRESS='):
addr = line.split('=', 1)[1]
self.id = int(addr)
return self.id
except queue.Empty:
# No more lines in the queue
pass

except Exception as e:
print(f"Failed to fetch ID: {e}")
return None
Expand Down
21 changes: 7 additions & 14 deletions setup/message_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PING:
Direction: bUE -> base
Meaning: The bUE periodically pings the base station
Body: None
Example: (bue_main.py) self.ota.send_ota_message(10, "PING")
Example: (bue_main.py) self.ota.send_ota_message(10, PING:<self.cur_st.value>,<lat>,<long>) NOTE: lat, long are '' if GPS isn't working
Response: The base station will respond with a PINGR. If too much time passes between PINGR's, the bUE knows it has become disconnected from the network.

PINGR:
Expand All @@ -51,8 +51,8 @@ PINGR:
TEST:
Direction: base -> bUE
Meaning: The base station sends a UTW test configuration, a file, a start time, and parameters.
Body: <configuration>.<role>.<starttime>
Example: (bue_main.py) self.ota.send_ota_message(5, TEST,<file>,<start_time>,<parameters>)
Body: <file>,<start_time>,<parameters>
Example: (bue_main.py) self.ota.send_ota_message(5, TEST:<file>,<start_time>,<parameters>)
Response: The bUE will respond with a TESTR, confirming that it has received the test

FAIL:
Expand All @@ -78,18 +78,11 @@ PREPR:
Example: (bue_main.py) self.ota.send_ota_message(10, "TESTR:1745004290")
Response: None

BEGIN:
TOUT:
Direction: bUE -> base
Meaning: The bUE lets the base station know that it has begun its UTW test
Body: None
Example: (bue_main.py) self.ota.send_ota_message(10, "BEGIN")
Response: None

UPD:
Direction: bUE -> base
Meaning: The bUE sends an update on the UTW test; TBD (could be any time a UTW message is received, or just a periodic update)
Body: TBD
Example: (bue_main.py) self.ota.send_ota_message(10, "UPD:<body>")
Meaning: The bUE sends stdout/stderr from its UTW test
Body: <stdout>
Example: (bue_main.py) self.ota.send_ota_message(10, "TOUT:<stdout>")
Response: None

DONE:
Expand Down
3 changes: 3 additions & 0 deletions setup/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ six==1.17.0
survey==5.4.2
tkintermapview==1.29
urllib3==2.5.0
qt6-applications==6.5.0.2.3
qt6-tools==6.5.0.1.3

Loading