From 6359b16135d3eb33f3a2ee63c80b9ff70a7a2f5a Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 29 Mar 2026 22:24:45 -0600 Subject: [PATCH] feat: decode Config response in donglora.py, add all_commands.py example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Config response (GetConfig) now returns decoded RadioConfig fields instead of raw hex. New all_commands.py exercises all 8 protocol commands in sequence — Ping, SetConfig, GetConfig, StartRx, StopRx, Transmit, DisplayOff, DisplayOn. --- all_commands.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ donglora.py | 5 +++++ 2 files changed, 56 insertions(+) create mode 100755 all_commands.py diff --git a/all_commands.py b/all_commands.py new file mode 100755 index 0000000..74e9cc3 --- /dev/null +++ b/all_commands.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +"""Exercise every DongLoRa command to verify the API works. + +Usage: + uv run examples/all_commands.py [PORT] +""" +# /// script +# requires-python = ">=3.10" +# dependencies = ["cobs", "pyserial"] +# /// + +import serial +import sys + +sys.path.insert(0, __import__("pathlib").Path(__file__).parent.as_posix()) +import donglora as dl # noqa: E402 + +try: + ser = dl.connect(sys.argv[1] if len(sys.argv) > 1 else None) + + print("── Ping ──") + print(dl.send(ser, "Ping")) + + print("\n── SetConfig ──") + print(dl.send(ser, "SetConfig", config=dl.DEFAULT_CONFIG)) + + print("\n── GetConfig ──") + print(dl.send(ser, "GetConfig")) + + print("\n── StartRx ──") + print(dl.send(ser, "StartRx")) + + print("\n── StopRx ──") + print(dl.send(ser, "StopRx")) + + print("\n── Transmit ──") + print(dl.send(ser, "Transmit", payload=b"Hello from all_commands.py!")) + + print("\n── DisplayOff ──") + print(dl.send(ser, "DisplayOff")) + + print("\n── DisplayOn ──") + print(dl.send(ser, "DisplayOn")) + + print("\nAll 8 commands exercised successfully.") + +except KeyboardInterrupt: + print("\nInterrupted.") +except serial.SerialException as e: + print(f"\nSerial error: {e}", file=sys.stderr) + sys.exit(1) diff --git a/donglora.py b/donglora.py index 8ca43d7..5645eee 100644 --- a/donglora.py +++ b/donglora.py @@ -125,6 +125,11 @@ def decode_response(data: bytes) -> dict: if tag == 0: return {"type": "Pong"} elif tag == 1: + if len(rest) >= 10: + freq_hz, bw, sf, cr, sync_word, pwr = struct.unpack_from("