From 1b8c84f2dd4189f14186b93fdd0fe65a93262f80 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Fri, 24 Jul 2026 22:07:25 -0400 Subject: [PATCH] Bridge: accept modern MeshCore ACKs with extra bytes after the CRC Newer MeshCore firmware sends discrete ACK payloads longer than 4 bytes (4-byte CRC first, then extras). pymc_core's AckHandler requires exactly 4 bytes and silently drops them, so DMs sent through the SPI bridge never show delivery confirmation. Patch process_discrete_ack at bridge startup to take the leading 4 bytes as the CRC, matching pymc_core's own path-bundled ACK parsing. Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/meshterm-spi-bridge | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/scripts/meshterm-spi-bridge b/scripts/meshterm-spi-bridge index d8b3762..00bb743 100755 --- a/scripts/meshterm-spi-bridge +++ b/scripts/meshterm-spi-bridge @@ -562,6 +562,38 @@ def menu() -> int: # --------------------------------------------------------------------------- # +def _patch_pymc_ack_compat(log) -> None: + """Accept modern MeshCore ACKs that carry extra bytes after the CRC. + + Newer firmware sends discrete ACK payloads longer than 4 bytes (the 4-byte + CRC first, then extras). pymc_core's AckHandler requires exactly 4 bytes + and drops the rest, so delivery confirmations never reach MeshTerm. + Override it to take the leading 4 bytes as the CRC — the same tolerant + parse pymc_core already uses for path-bundled ACKs. + """ + try: + from pymc_core.node.handlers.ack import AckHandler + except Exception as exc: # package layout changed — leave it alone + log.warning("ack compat shim not applied (%s)", exc) + return + + async def process_discrete_ack(self, packet): + payload = packet.payload + self.log(f"Processing discrete ACK: payload_len={len(payload)}") + self.log(f"ACK payload (hex): {payload.hex().upper()}") + if len(payload) < 4: + self.log(f"Invalid ACK length: {len(payload)} bytes (expected >= 4)") + return None + crc = int.from_bytes(payload[:4], "little") + if len(payload) > 4: + self.log(f"ACK carries {len(payload) - 4} extra byte(s): {payload[4:].hex().upper()}") + self.log(f"Discrete ACK received: CRC={crc:08X}") + return crc + + AckHandler.process_discrete_ack = process_discrete_ack + log.info("compat: AckHandler patched to accept >4-byte ACK payloads") + + def run_bridge(host: str, port: int, node_name: str) -> int: import asyncio import logging @@ -580,6 +612,8 @@ def run_bridge(host: str, port: int, node_name: str) -> int: ) return 2 + _patch_pymc_ack_compat(log) + from pymc_core.companion import CompanionFrameServer, CompanionRadio # Prefer the hackergadgets meshcore_console helpers (correct board pins +