Skip to content

Commit 2281ea5

Browse files
committed
Set the region on the simradio nodes so we can test setting presets other than LONG_FAST properly
1 parent 7950798 commit 2281ea5

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

meshtastic/tests/conftest.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
find_meshtasticd,
1616
is_compatible_host,
1717
)
18+
from .fw_helpers import set_region
1819

1920
# Use a different base port for the single-node fixture so it doesn't
2021
# conflict with the multi-node mesh fixture.
@@ -41,11 +42,14 @@ def firmware_node():
4142
tests be order-independent.
4243
4344
Yields the SimNode instance. The node is booted with a fresh erased
44-
config and listens on localhost at its TCP port.
45+
config and listens on localhost at its TCP port. Region is set to US
46+
so modem-preset tests work against firmware >= 2.8, which clamps
47+
presets to the legal set for the current region.
4548
"""
4649
_skip_firmware_if_unavailable()
4750
mesh = SimMesh(n_nodes=1, base_port=SINGLE_NODE_BASE_PORT)
4851
mesh.start()
52+
set_region(mesh.get_node(0).port, "US")
4953
yield mesh.get_node(0)
5054
mesh.stop()
5155

@@ -55,11 +59,24 @@ def firmware_mesh():
5559
"""A 3-node chain (A-B-C) meshtasticd sim mesh for smokemesh tests.
5660
5761
Yields the SimMesh instance. Nodes are connected and the SIMULATOR_APP
58-
packet bridge is running. Node DB convergence is awaited.
62+
packet bridge is running. Region is set to US for firmware >= 2.8
63+
compatibility, interfaces are reconnected after the region change, and
64+
node DB convergence is awaited.
5965
"""
6066
_skip_firmware_if_unavailable()
6167
mesh = SimMesh(n_nodes=3, topology=CHAIN_TOPOLOGY)
6268
mesh.start()
69+
for node in mesh.nodes:
70+
set_region(node.port, "US")
71+
# The region commit restarts each node's TCP listener, so reconnect the
72+
# harness interfaces before waiting for convergence.
73+
for node in mesh.nodes:
74+
if node.iface is not None:
75+
try:
76+
node.iface.close()
77+
except Exception: # pylint: disable=broad-except
78+
pass
79+
node.connect()
6380
mesh.wait_for_convergence(timeout=30)
6481
yield mesh
6582
mesh.stop()

meshtastic/tests/fw_helpers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
# simulator happy when many short-lived connections are happening.
3232
PAUSE_AFTER_CLI = 0.2
3333

34+
# Pause after changing the LoRa region. The firmware may restart the TCP
35+
# listener while committing the new radio config, so give it time to settle
36+
# before the next CLI call or harness reconnect.
37+
PAUSE_AFTER_REGION_CHANGE = 2.0
38+
3439

3540
# ---------------------------------------------------------------------------
3641
# CLI invocation
@@ -325,6 +330,19 @@ def subscribe_positions(iface: TCPInterface) -> PacketCollector:
325330
return _subscribe_topic(iface, "meshtastic.receive.position")
326331

327332

333+
def set_region(port: int, region: str = "US") -> None:
334+
"""Set the LoRa region on a sim node via the CLI.
335+
336+
The node briefly restarts its TCP listener while committing the radio
337+
config; ``run_cli()`` handles the reconnect retry, and we sleep long
338+
enough for the new region to take effect before callers continue.
339+
"""
340+
rc, out = run_cli(port, "--set", "lora.region", region)
341+
if rc != 0:
342+
raise RuntimeError(f"Failed to set lora.region={region}: {out}")
343+
time.sleep(PAUSE_AFTER_REGION_CHANGE)
344+
345+
328346
def unsubscribe_all(topic: str) -> None:
329347
"""Drop every handler currently registered on *topic*.
330348
@@ -339,12 +357,14 @@ def unsubscribe_all(topic: str) -> None:
339357

340358
__all__ = [
341359
"PAUSE_AFTER_CLI",
360+
"PAUSE_AFTER_REGION_CHANGE",
342361
"PacketCollector",
343362
"RECEIVE_TIMEOUT",
344363
"cli_then_verify",
345364
"connect_iface",
346365
"resolve_cli",
347366
"run_cli",
367+
"set_region",
348368
"subscribe_positions",
349369
"subscribe_telemetries",
350370
"subscribe_texts",

0 commit comments

Comments
 (0)