refactor: companion FrameServer and related (substantive only, no Black)

Reapply refactor from ce8381a (replace monolithic FrameServer with thin
pymc_core subclass, re-export constants, SQLite persistence hooks) while
preserving pre-refactor whitespace where patch applied cleanly. Remaining
files match refactor commit exactly. Diff vs ce8381a is whitespace-only.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
agessaman
2026-02-21 15:35:47 -08:00
parent 22e337a707
commit c2f8a2e3cd
57 changed files with 4385 additions and 4922 deletions
+44 -25
View File
@@ -10,12 +10,12 @@ import struct
import time
from pymc_core.node.handlers.protocol_request import (
ProtocolRequestHandler,
REQ_TYPE_GET_STATUS,
REQ_TYPE_GET_TELEMETRY_DATA,
REQ_TYPE_GET_ACCESS_LIST,
REQ_TYPE_GET_NEIGHBOURS,
SERVER_RESPONSE_DELAY_MS
REQ_TYPE_GET_STATUS,
REQ_TYPE_GET_TELEMETRY_DATA,
SERVER_RESPONSE_DELAY_MS,
ProtocolRequestHandler,
)
logger = logging.getLogger("ProtocolRequestHelper")
@@ -23,8 +23,16 @@ logger = logging.getLogger("ProtocolRequestHelper")
class ProtocolRequestHelper:
"""Provides repeater-specific protocol request handlers."""
def __init__(self, identity_manager, packet_injector=None, acl_dict=None, radio=None, engine=None, neighbor_tracker=None):
def __init__(
self,
identity_manager,
packet_injector=None,
acl_dict=None,
radio=None,
engine=None,
neighbor_tracker=None,
):
self.identity_manager = identity_manager
self.packet_injector = packet_injector
@@ -71,9 +79,10 @@ class ProtocolRequestHelper:
}
logger.info(f"Registered protocol request handler for '{name}': hash=0x{hash_byte:02X}")
def _create_acl_contacts_wrapper(self, acl):
"""Create contacts wrapper from ACL."""
class ACLContactsWrapper:
def __init__(self, identity_acl):
self._acl = identity_acl
@@ -138,22 +147,32 @@ class ProtocolRequestHelper:
# uint32_t n_direct_dups;
# uint32_t n_flood_dups;
# uint32_t total_rx_air_time_secs;
# Get stats from radio/engine
noise_floor = int(self.radio.get_noise_floor() * 1.0) if self.radio else -120
last_rssi = int(self.radio.last_rssi) if self.radio and hasattr(self.radio, 'last_rssi') else -120
last_snr = int((self.radio.last_snr * 4.0) if self.radio and hasattr(self.radio, 'last_snr') else 0)
last_rssi = (
int(self.radio.last_rssi) if self.radio and hasattr(self.radio, "last_rssi") else -120
)
last_snr = int(
(self.radio.last_snr * 4.0) if self.radio and hasattr(self.radio, "last_snr") else 0
)
# Get packet counts
n_packets_recv = self.radio.packets_received if self.radio and hasattr(self.radio, 'packets_received') else 0
n_packets_sent = self.radio.packets_sent if self.radio and hasattr(self.radio, 'packets_sent') else 0
n_packets_recv = (
self.radio.packets_received
if self.radio and hasattr(self.radio, "packets_received")
else 0
)
n_packets_sent = (
self.radio.packets_sent if self.radio and hasattr(self.radio, "packets_sent") else 0
)
# Get airtime stats
total_air_time_secs = 0
total_rx_air_time_secs = 0
if self.engine and hasattr(self.engine, 'airtime_manager'):
if self.engine and hasattr(self.engine, "airtime_manager"):
total_air_time_secs = int(self.engine.airtime_manager.total_tx_airtime_ms / 1000)
# Get routing stats
n_sent_flood = 0
n_sent_direct = 0
@@ -161,18 +180,18 @@ class ProtocolRequestHelper:
n_recv_direct = 0
n_direct_dups = 0
n_flood_dups = 0
if self.engine:
n_sent_flood = getattr(self.engine, 'sent_flood_count', 0)
n_sent_direct = getattr(self.engine, 'sent_direct_count', 0)
n_recv_flood = getattr(self.engine, 'recv_flood_count', 0)
n_recv_direct = getattr(self.engine, 'recv_direct_count', 0)
n_direct_dups = getattr(self.engine, 'direct_dup_count', 0)
n_flood_dups = getattr(self.engine, 'flood_dup_count', 0)
n_sent_flood = getattr(self.engine, "sent_flood_count", 0)
n_sent_direct = getattr(self.engine, "sent_direct_count", 0)
n_recv_flood = getattr(self.engine, "recv_flood_count", 0)
n_recv_direct = getattr(self.engine, "recv_direct_count", 0)
n_direct_dups = getattr(self.engine, "direct_dup_count", 0)
n_flood_dups = getattr(self.engine, "flood_dup_count", 0)
# Pack struct (little-endian)
stats = struct.pack(
'<HHhhIIIIIIIIIhIII',
"<HHhhIIIIIIIIIhIII",
0, # batt_milli_volts (not available on Pi)
0, # curr_tx_queue_len (TODO)
noise_floor,