Skip to content

Commit

Permalink
WIP: Finish pre-work data rxtx log data structure change
Browse files Browse the repository at this point in the history
  • Loading branch information
DeflateAwning committed Oct 2, 2024
1 parent 578a0b1 commit e652bd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cts1_ground_support/terminal_app/app_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class AppStore:
firmware_repo_path: Path | None = None

uart_port_name: str = UART_PORT_NAME_DISCONNECTED

# `rxtx_log` is a dictionary, where keys are increasing ints by the order the messages were
# added/received. Elements are popped from the start, and added to the end.
rxtx_log: dict[int, RxTxLogEntry] = field(
default_factory=lambda: {0: RxTxLogEntry(b"Start of Log", "notice")}
)
Expand Down
9 changes: 5 additions & 4 deletions cts1_ground_support/terminal_app/serial_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ def uart_listener() -> None:
# Check for incoming data
if port.in_waiting > 0:
received_data: bytes = port.readline()
app_store.rxtx_log.append(RxTxLogEntry(received_data, "receive"))
app_store.append_to_rxtx_log(RxTxLogEntry(received_data, "receive"))
elif len(app_store.rxtx_log) > MAX_RX_TX_LOG_ENTRIES:
# Data's not coming in rapid-fire, so take a sec to purge the buffer.
app_store.rxtx_log = app_store.rxtx_log[-MAX_RX_TX_LOG_ENTRIES:]
# Remove the oldest entry.
app_store.rxtx_log.pop(next(iter(app_store.rxtx_log.keys())))

# Check for outgoing data
if len(app_store.tx_queue) > 0:
tx_data = app_store.tx_queue.pop(0)
port.write(tx_data)
app_store.rxtx_log.append(RxTxLogEntry(tx_data, "transmit"))
app_store.append_to_rxtx_log(RxTxLogEntry(tx_data, "transmit"))
app_store.last_tx_timestamp_sec = time.time()

time.sleep(0.01)
Expand All @@ -46,7 +47,7 @@ def uart_listener() -> None:
f"Serial port forcefully disconnected (SerialException: {e}): "
f"{app_store.uart_port_name}"
)
app_store.rxtx_log.append(RxTxLogEntry(msg.encode(), "error"))
app_store.append_to_rxtx_log(RxTxLogEntry(msg.encode(), "error"))
logger.warning(msg)
app_store.uart_port_name = UART_PORT_NAME_DISCONNECTED # propagate back to UI
time.sleep(0.5)
Expand Down

0 comments on commit e652bd2

Please sign in to comment.