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:
1 parent
9f68104ac6
commit
144efe683e
15 files changed
+798
-6
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user