tools/ public with a local config, private tools to .tth/tools/
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b7b397b9b1
commit
845a228209
27 files changed
+5312
-4
No files matched your search
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""TRACE po pevné cestě na zvoleném presetu přes USB companion — měření přímého hopu.
|
||||
|
||||
Companion přepne rádio na preset, pošle N× TRACE po cestě (2B hashe) a vypíše
|
||||
SNR, které na trase připsal každý hop, a SNR, se kterým odpověď slyšel on sám.
|
||||
Slouží k měření spoje mezi dvěma repeatery, které jsou mezitím přes `tempradio`
|
||||
na stejném presetu (sám je nepřelaďuje).
|
||||
|
||||
preset_trace.py /dev/serial/by-id/... 869.525 62.5 12 8 --path 025c,5f14,025c -n 8
|
||||
preset_trace.py /dev/serial/by-id/... 866.5 62.5 8 5 --tx 2 --restore # zpět, bez TRACE
|
||||
|
||||
Nastavení rádia companion ukládá do prefs — po měření ho vrať (--restore).
|
||||
Výstup: jedna JSON řádka na pokus (ok/timeout, hopy se SNR, rtt).
|
||||
"""
|
||||
import argparse
|
||||
import asyncio
|
||||
import json
|
||||
import random
|
||||
import time
|
||||
|
||||
|
||||
def parse():
|
||||
ap = argparse.ArgumentParser(description=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("port", help="sériový port companionu (/dev/serial/by-id/...)")
|
||||
ap.add_argument("freq", type=float, help="MHz")
|
||||
ap.add_argument("bw", type=float, help="kHz")
|
||||
ap.add_argument("sf", type=int)
|
||||
ap.add_argument("cr", type=int, help="5..8 (4/5..4/8)")
|
||||
ap.add_argument("--tx", type=int, default=22, help="TX výkon dBm (default 22)")
|
||||
ap.add_argument("--path", default="025c,5f14,025c", help="hopy TRACE, 2B hex, čárkou")
|
||||
ap.add_argument("-n", type=int, default=8, help="počet TRACE (default 8)")
|
||||
ap.add_argument("--gap", type=float, default=3.0, help="pauza mezi pokusy, s")
|
||||
ap.add_argument("--timeout", type=float, default=0,
|
||||
help="čekání na odpověď, s (0 = odhad firmwaru + 50 %%)")
|
||||
ap.add_argument("--restore", action="store_true", help="jen nastavit rádio, žádný TRACE")
|
||||
return ap.parse_args()
|
||||
|
||||
|
||||
async def main(a):
|
||||
from meshcore import EventType, MeshCore
|
||||
|
||||
mc = await MeshCore.create_serial(a.port, 115200)
|
||||
if mc is None:
|
||||
raise SystemExit("companion neodpovídá")
|
||||
r = await mc.commands.set_radio(a.freq, a.bw, a.sf, a.cr)
|
||||
if r.type == EventType.ERROR:
|
||||
raise SystemExit("set_radio: %s" % r.payload)
|
||||
r = await mc.commands.set_tx_power(a.tx)
|
||||
if r.type == EventType.ERROR: # build caps TX (MAX_LORA_TX_POWER): keep its current power
|
||||
print(json.dumps({"warn": "set_tx_power %d refused" % a.tx}), flush=True)
|
||||
await mc.commands.send_appstart()
|
||||
si = mc.self_info
|
||||
print(json.dumps({"radio": [si.get("radio_freq"), si.get("radio_bw"), si.get("radio_sf"),
|
||||
si.get("radio_cr")], "tx": si.get("tx_power")}), flush=True)
|
||||
if a.restore:
|
||||
await mc.disconnect()
|
||||
return
|
||||
|
||||
for i in range(a.n):
|
||||
tag = random.randint(1, 0xFFFFFFFF)
|
||||
t0 = time.monotonic()
|
||||
sent = await mc.commands.send_trace(auth_code=0, tag=tag, flags=1, path=a.path)
|
||||
if sent.type == EventType.ERROR:
|
||||
print(json.dumps({"i": i, "error": str(sent.payload)}), flush=True)
|
||||
await asyncio.sleep(a.gap)
|
||||
continue
|
||||
est = (sent.payload or {}).get("suggested_timeout", 0) / 1000
|
||||
wait = a.timeout or max(10.0, est * 1.5)
|
||||
ev = await mc.wait_for_event(EventType.TRACE_DATA, attribute_filters={"tag": tag},
|
||||
timeout=wait)
|
||||
rec = {"i": i, "t": time.strftime("%H:%M:%S"), "wait": round(wait, 1)}
|
||||
if ev is None:
|
||||
rec["ok"] = False
|
||||
else:
|
||||
rec.update(ok=True, rtt=round(time.monotonic() - t0, 1),
|
||||
hops=[[h.get("hash", "me"), h["snr"]] for h in ev.payload.get("path", [])])
|
||||
print(json.dumps(rec), flush=True)
|
||||
await asyncio.sleep(a.gap)
|
||||
await mc.disconnect()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main(parse()))
|
||||
Reference in new issue
Block a user