import re from pathlib import Path ROOT = Path(__file__).resolve().parents[1] NODE = ROOT / "firmware" / "xiao-esp32c6-sensor-node" def source(name): return (NODE / name).read_text() def test_wiring_matches_assembly(): config = source("sensor_node_config.h") expected = {"RS485_DE_PIN":"D2", "RS485_TX_PIN":"D4", "RS485_RX_PIN":"D5", "BNO086_SDA_PIN":"D7", "BNO086_SCL_PIN":"D8", "GPS_RX_PIN":"D9", "GPS_TX_PIN":"D10"} for name, pin in expected.items(): assert re.search(rf"#define\s+{name}\s+{pin}\b", config) def test_transport_contract(): text = source("rs485_transport.cpp") for token in ['doc["type"] = "sensor_status"', 'doc["schema_version"]', 'createNestedObject("imu")', 'createNestedObject("gps")', "serial.write('\\n')", "serial.flush()"]: assert token in text def test_loop_is_non_blocking(): loop = source("xiao-esp32c6-sensor-node.ino").split("void loop()", 1)[1] assert "updateGps" in loop and "updateImu" in loop and "TELEMETRY_INTERVAL_MS" in loop assert not re.search(r"delay\((?:[2-9]|[1-9]\d+)\)", loop) def test_node_does_not_take_cargo_or_ble_authority(): combined = "\n".join(p.read_text() for p in NODE.glob("*.*")) assert "NimBLE" not in combined and "JBD" not in combined and "server.on(" not in combined