Files
mppt-testbench/code64/debug_console/widgets/status_bar.py
T
janikandClaude Opus 4.8 d2dfc73f9e tooling: sync bench + debug console to live STM32 protocol
The mppt-testbench Python tooling had drifted from the flashed firmware
(bundled fw e7a23a3 vs live 1b85532) and could no longer communicate:

- stm32_link.py: CRC8 -> CRC-16/CCITT-FALSE; telemetry 68B -> 78B
  (btemp, cmp_outer/inner, iout_slow, vfly_ofs_applied); add PTYPE_INT16
  and commands 0x12-0x18; replace PARAMS with the current 37-param map
  (single dt_normal, no dt brackets; test_corr/phase_ofs, phase PI,
  precharge PI, duty dither; vfly_active 0-3).
- tuner.py: retire per-bracket deadtime; sweep the single dt_normal.
- cli.py: update tune-deadtime, help/examples, btemp readout;
  default ports COM11 (load) / COM4 (stm32).
- debug console TUI: sync protocol.py/app.py/status_bar/telemetry_panel
  from live (new command keys, link RX/TX/loss stats, single dead-time,
  new telemetry fields, param-write auto-retry); add duty_fft.py.
- README: rewrite parameter table, deadtime section, ports, keybindings.

Verified: protocol round-trip self-tests + live `bench stm32-read`
reading all 37 params over COM4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 12:03:51 +07:00

36 lines
1.1 KiB
Python

"""Connection status bar."""
from textual.widgets import Static
class StatusBar(Static):
"""Bottom status bar showing connection info."""
DEFAULT_CSS = """
StatusBar {
dock: bottom;
height: 1;
background: $primary-background;
color: $text;
padding: 0 1;
}
"""
def __init__(self):
super().__init__("")
self.connected = False
self.pkt_count = 0
self.drop_count = 0
self.last_seq = 0
self.fps = 0.0 # telemetry frames RECEIVED per second
self.sent_fps = 0.0 # frames the MCU GENERATED per second (from seq advance)
self.loss_pct = 0.0 # 100 * (1 - received/generated)
def refresh_status(self):
conn = "[green]CONN:OK[/green]" if self.connected else "[red]CONN:LOST[/red]"
if self.loss_pct >= 5.0:
loss = f"[red]LOSS:{self.loss_pct:.0f}%[/red]"
else:
loss = f"LOSS:{self.loss_pct:.0f}%"
self.update(f" {conn} PKTS:{self.pkt_count} DROPS:{self.drop_count} SEQ:{self.last_seq}"
f" RX:{self.fps:.1f}Hz TX:{self.sent_fps:.1f}Hz {loss}")