50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
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
|
|
assert "USB_TELEMETRY_ENABLED" in text
|
|
assert "serializeJson(doc, Serial)" in text
|
|
assert 'createNestedObject("nmea")' in text
|
|
assert 'nmea["sentences_passed"]' 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_imu_does_not_redeclare_arduino_degrees_macro():
|
|
imu = source("imu.cpp")
|
|
assert "float degrees(" not in imu
|
|
assert "radiansToDegrees" in imu
|
|
|
|
def test_imu_scans_both_bno08x_i2c_addresses():
|
|
config = source("sensor_node_config.h")
|
|
imu = source("imu.cpp")
|
|
assert "BNO086_I2C_ADDRESS 0x4A" in config
|
|
assert "BNO086_I2C_ADDRESS_ALTERNATE 0x4B" in config
|
|
assert "findBnoAddress()" in imu
|
|
assert "Wire.endTransmission()" in imu
|
|
|
|
def test_gps_auto_detects_common_nmea_baud_rates():
|
|
gps = source("gps.cpp")
|
|
assert "baudHasValidNmea" in gps
|
|
assert "{9600, 38400, 115200, 4800}" in gps
|
|
assert "passedChecksum() > 0" in gps
|
|
|
|
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
|