rbtest: timed small messages, one 50 kB message, and MT checks

`rbtest` in the shell sample sends test messages with a 16-byte header
and a counting ramp, so every byte can be checked at the other end.
`rbtest small` sends a few 32-byte messages and logs how long each took,
`rbtest large` sends one of up to 50000 bytes and only with `confirm`,
and `rbtest mt` shows the last MT and checks it. `rb9704 pattern make`
and `check` in python/ make and check the same messages.

rb9704_send_fill writes a message straight into the module's buffer, so
a large generated one is not held twice. overlay-large.conf raises the
limit to 50000 bytes; on the M5Stamp-C3 that links on the USB console
and not beside WiFi, which overflows by 11 kB.

Run against the fake modem on native_sim only; not yet on a real modem.
This commit is contained in:
scottp committed 2026-10-27 11:07:53 +11:00
1 parent 9f68104ac6
commit 144efe683e
15 files changed
+798 -6

No files matched your search

+54
View File
@@ -12,6 +12,8 @@ rb9704 - drive a RockBLOCK 9704 from the host over its USB-C port.
rb9704 [-p PORT] listen [--out DIR] [--for S]
rb9704 [-p PORT] session (--text T | --hex H | --file F) [--quiet S] [--yes]
rb9704 cloud ping | things | mo | msg ID | mt ... | status ID
rb9704 pattern make [--size N] [--seq N] [--count N] [--out F]
rb9704 pattern check (--hex H | --b64 B | --file F)
The modem side uses Ground Control's rockblock9704 package, a binding of
the same C library this repository builds into Zephyr, so what works here
@@ -23,6 +25,10 @@ the provisioning when a message is sent, and asking that way is free.
question. Everything else on the modem side is local serial traffic and
costs nothing. `cloud mt` costs airtime too.
`pattern` makes and checks the test message the shell sample's `rbtest`
sends (rb9704tools/pattern.py): `check` takes the bytes Cloudloop shows,
in hex or Base64, and `make` gives a message to queue with `cloud mt`.
The port is -p, or $RB9704_PORT, or the one FTDI FT234XD attached (the
9704's USB-C bridge, 0403:6015). --log FILE appends every event as a JSON
line, for the bench log.
@@ -42,6 +48,8 @@ import urllib.error
import urllib.parse
import urllib.request
from rb9704tools import pattern
FTDI_VID, FT234X_PID = 0x0403, 0x6015
BAUD = 230400
RAW_TOPIC = 244
@@ -570,6 +578,38 @@ def cmd_cloud(a):
ev("cloud_mt", bytes=len(data), topic=a.topic, result=json.dumps(r))
# ---------------------------------------------------------------- pattern
def cmd_pattern(a):
if a.verb == "make":
data = pattern.make(a.size, seq=a.seq, count=a.count)
if a.out:
with open(a.out, "wb") as f:
f.write(data)
else:
print(data.hex())
return
if a.hex is not None:
data = bytes.fromhex(a.hex)
elif a.b64 is not None:
# Cloudloop leaves the padding off
data = base64.b64decode(a.b64 + "=" * (-len(a.b64) % 4))
else:
with open(a.file, "rb") as f:
data = f.read()
r = pattern.check(data)
if r is None:
die(f"{len(data)} bytes, not a test message: {data[:16].hex()}")
print(f"{r['kind']} {r['seq']}/{r['count']}, {r['got']} bytes, made at uptime "
f"{r['uptime_ms'] / 1000:.3f} s")
if r["ok"]:
print("every byte as expected")
elif r["bad_at"] == 8:
die(f"the header says {r['length']} bytes, {r['got']} arrived")
else:
die(f"wrong from byte {r['bad_at']}")
# ---------------------------------------------------------------- main
def add_payload(p, required=True):
@@ -660,6 +700,20 @@ def main():
add_payload(q)
p.set_defaults(fn=cmd_cloud)
p = sub.add_parser("pattern", help="make or check an `rbtest` test message (free)")
ps = p.add_subparsers(dest="verb", required=True)
q = ps.add_parser("make", help="one test message, as hex or to a file")
q.add_argument("--size", type=int, default=32)
q.add_argument("--seq", type=int, default=1)
q.add_argument("--count", type=int, default=1)
q.add_argument("--out", help="write the bytes here; default hex on stdout")
q = ps.add_parser("check", help="every byte of one, as Cloudloop shows it")
g = q.add_mutually_exclusive_group(required=True)
g.add_argument("--hex")
g.add_argument("--b64")
g.add_argument("--file")
p.set_defaults(fn=cmd_pattern)
a = ap.parse_args()
LOG = a.log
a.fn(a)
+52
View File
@@ -0,0 +1,52 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
"""
The test message `rbtest` in the shell sample sends, and checks when one
arrives as an MT (samples/shell/src/rbtest.c has the same description).
A 16-byte header:
0..2 b"RBT"
3 version, 1
4 kind: b"S" small, b"L" large, anything else for one made here
5 seq, from 1
6 count in the run
7 0
8..11 the whole message's length, big-endian
12..15 uptime in ms when it was made, big-endian
then from byte 16 to the end, byte k is k % 510 counted up 0..255 and back
down 254..1.
"""
import struct
HEADER = 16
MAGIC = b"RBT\x01"
def ramp(k):
v = k % 510
return v if v < 256 else 510 - v
def make(length, kind="M", seq=1, count=1, uptime_ms=0):
if length <= HEADER:
raise ValueError(f"a test message is more than {HEADER} bytes")
head = MAGIC + struct.pack(">cBBxII", kind.encode()[:1], seq, count, length, uptime_ms)
return head + bytes(ramp(k) for k in range(HEADER, length))
def check(data):
"""A dict describing data, with "ok" True when every byte is as made,
or None when it is not a test message at all."""
if len(data) < HEADER or not data.startswith(MAGIC):
return None
kind, seq, count, length, uptime_ms = struct.unpack(">cBBxII", data[4:HEADER])
r = {"kind": kind.decode("ascii", "replace"), "seq": seq, "count": count,
"length": length, "got": len(data), "uptime_ms": uptime_ms, "bad_at": None}
if length != len(data):
r["bad_at"] = 8
else:
r["bad_at"] = next((k for k in range(HEADER, len(data)) if data[k] != ramp(k)), None)
r["ok"] = r["bad_at"] is None
return r