Compare commits
11
Commits
f97fcab74b
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77796702d6 | ||
|
|
acd4263a06 | ||
|
|
db6d584807 | ||
|
|
144efe683e | ||
|
|
9f68104ac6 | ||
|
|
010704fc40 | ||
|
|
83aa6ebd8f | ||
|
|
a70e933b71 | ||
|
|
0cda7335d6 | ||
|
|
4f5834a467 | ||
|
|
d08364ce58 |
No files matched your search
@@ -0,0 +1,4 @@
|
|||||||
|
# GitHub language statistics. The Python under python/ is host-side test
|
||||||
|
# and provisioning tooling; leave it out so the repo shows as C/Zephyr.
|
||||||
|
python/** linguist-detectable=false
|
||||||
|
*.sh linguist-detectable=false
|
||||||
+93
-1
@@ -1,7 +1,99 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased
|
## 0.4.0, 2026-11-26
|
||||||
|
|
||||||
|
- Builds on Zephyr v4.5.0 as well as v4.4.0. 4.5 made
|
||||||
|
`uart_irq_update()` return `void`, and the receive interrupt used it as
|
||||||
|
its loop condition, so 0.3.0 does not compile on 4.5 ("void value not
|
||||||
|
ignored"). It is now called at the top of each pass, as Zephyr's own
|
||||||
|
samples do.
|
||||||
|
- `CONFIG_RB9704` selects `CONFIG_RING_BUFFER` only before Zephyr 4.5.
|
||||||
|
From 4.5 the ring buffer is header-only, and that option brings back
|
||||||
|
the deprecated legacy implementation and a build warning. The check
|
||||||
|
compares `KERNELVERSION` in Kconfig. The rig bridge reads its ring with
|
||||||
|
`ring_buf_peek()` and `ring_buf_get()` in place of the claim API, which
|
||||||
|
is legacy from 4.5, and gates the option the same way.
|
||||||
|
- The standalone manifest pins Zephyr v4.5.0.
|
||||||
|
|
||||||
|
- `rbtest` in the shell sample: airtime tests with a payload that can be
|
||||||
|
checked at the other end. `rbtest small` sends a few 32-byte messages
|
||||||
|
one after another and logs how long each took, `rbtest large` sends one
|
||||||
|
message of up to 50000 bytes and sends nothing without `confirm`, and
|
||||||
|
`rbtest mt` shows the last MT and checks it if it is a test message.
|
||||||
|
`rb9704 pattern make` and `check` in `python/` make and check the same
|
||||||
|
messages. Not yet run against a real modem.
|
||||||
|
- `rb9704_send_fill`: as `rb9704_send`, with the message written straight
|
||||||
|
into the module's buffer, so a large generated message is not held
|
||||||
|
twice. `overlay-large.conf` raises the limit to 50000 bytes; on the
|
||||||
|
M5Stamp-C3 that fits on the USB console and not beside WiFi
|
||||||
|
(`docs/boards/stamp_c3.md`).
|
||||||
|
|
||||||
|
- Docs: the M5Stamp-C3 left out overnight on 0.3.0, P_EN wired and
|
||||||
|
active low: the modem up and answering for about 11 h 54 min with no
|
||||||
|
drop, and the Stamp did not reboot. P_EN driven the wrong way had
|
||||||
|
stopped it within 5 minutes every time.
|
||||||
|
|
||||||
|
## 0.3.0, 2026-10-25
|
||||||
|
|
||||||
|
- Provisioning and MO messages to Cloudloop work: the M5Stamp-C3 under
|
||||||
|
open sky, provisioned with topics 244 and 313 to 317, sent two
|
||||||
|
messages on topic 244 from its shell over WiFi, 16 and 17 bytes, and
|
||||||
|
both arrived in Cloudloop whole. The second ran on the reworked
|
||||||
|
control pins below, with P_EN wired and active low, and the modem
|
||||||
|
stayed up past every earlier drop. `docs/CLOUDLOOP.md`, "What has
|
||||||
|
run", records how Cloudloop shows a message.
|
||||||
|
|
||||||
|
- P_EN is active low. On the RockBLOCK it is the supercapacitor charge
|
||||||
|
enable ("Cap Charge Enable Signal (ACTIVE LOW)", header pin 6), and the
|
||||||
|
sample's overlays had it `GPIO_ACTIVE_HIGH`, so every `begin` switched
|
||||||
|
the charger off: the modem ran down and went silent 2 to 5 minutes
|
||||||
|
later, as it did on the M5Stamp-C3 indoors and out. The overlays, the
|
||||||
|
README and the binding now say `GPIO_ACTIVE_LOW`, and the module drives
|
||||||
|
P_EN only while the modem runs, releasing it to an input while it is
|
||||||
|
off, where the board's pull-down keeps the charger on.
|
||||||
|
- The control pins follow Ground Control's start-up and shutdown
|
||||||
|
sequence. I_EN starts and stops the modem, and is what makes the pins
|
||||||
|
present (`CONFIG_RB9704_POWER` follows `iridium-enable-gpios`); P_EN
|
||||||
|
and I_BTD are optional beside it. Shutdown drives I_EN low and waits
|
||||||
|
for I_BTD to go low before anything else, as start-up waits for it to
|
||||||
|
go high, so I_EN never moves back before I_BTD has followed, which the
|
||||||
|
page warns may damage the module. Before, `power off` dropped the pins
|
||||||
|
and returned at once.
|
||||||
|
|
||||||
|
- The modem's UART is listened to from boot, not only while the library
|
||||||
|
is open. With the power pins wired, `rb9704 power on` or a modem left
|
||||||
|
talking after `rb9704 end` sent its boot lines to nobody; they
|
||||||
|
overflowed the M5Stamp-C3's 128-byte UART FIFO, after which `begin`
|
||||||
|
heard only repeated fragments of old lines and failed with `-EIO` (1 in
|
||||||
|
6 after a power cycle, none at all after a pause), and a second `begin`
|
||||||
|
crashed the board in the library's line parser. Bytes heard while the
|
||||||
|
library is closed are now thrown away, and when it opens part-way
|
||||||
|
through a line the rest of that line is too. On the Stamp: 8 of 8 power
|
||||||
|
cycles, and 12 of 12 with 0 to 5 s between power on and `begin`.
|
||||||
|
- The fake modem's `raw` and `before` write any bytes, now or just ahead
|
||||||
|
of its next reply. `test_a_boot_burst_while_closed` sends a 680-byte
|
||||||
|
boot burst before `begin`: the overflow above on a board through the
|
||||||
|
rig, a check that it does no harm on native_sim.
|
||||||
|
|
||||||
|
## 0.2.0, 2026-10-25
|
||||||
|
|
||||||
|
- The shell sample over WiFi: `overlay-wifi.conf` puts the shell on
|
||||||
|
telnet on any ESP32, joining the network `wifi cred add` stored in
|
||||||
|
flash at boot and rejoining it after a drop.
|
||||||
|
- The shell sample on the M5Stamp-C3 (ESP32-C3, RISC-V): the modem on
|
||||||
|
`uart1`, GPIO4 and GPIO5. Its RGB LED shows the modem's state and its
|
||||||
|
button begins, asks for the signal and ends. `docs/boards/stamp_c3.md`
|
||||||
|
has its pins, the WiFi commands and the LED's colours.
|
||||||
|
- The sample's overlays for the M5Stamp-C3, ESP32-S3-DevKitC, ESP32
|
||||||
|
DevKitC and NUCLEO-U575ZI-Q wire P_EN, I_EN and I_BTD; the wiring table
|
||||||
|
is in `docs/TESTING.md`. `no-control-pins.overlay` takes them out at
|
||||||
|
build time, for a modem on TX and RX alone; the modem node is labelled
|
||||||
|
`rb9704` in every overlay so it can.
|
||||||
|
- A real 9704 on a microcontroller for the first time: the M5Stamp-C3,
|
||||||
|
on TX and RX, powered from the Stamp's 5 V. The 9704's USB-C and its
|
||||||
|
header share the modem's UART, and with USB-C plugged in a board on the
|
||||||
|
header cannot reach the modem; the README, `docs/CLOUDLOOP.md` and
|
||||||
|
`docs/boards/stamp_c3.md` say so.
|
||||||
- `rb9704_cancel()` and `rb9704 cancel`: ask the modem to abandon the
|
- `rb9704_cancel()` and `rb9704 cancel`: ask the modem to abandon the
|
||||||
message in flight; `mo_done` then reports `-ECANCELED`. The status
|
message in flight; `mo_done` then reports `-ECANCELED`. The status
|
||||||
snapshot carries the in-flight message's id and start time. The fake
|
snapshot carries the in-flight message's id and start time. The fake
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ menuconfig RB9704
|
|||||||
default y
|
default y
|
||||||
depends on DT_HAS_ROCK7_ROCKBLOCK_9704_ENABLED
|
depends on DT_HAS_ROCK7_ROCKBLOCK_9704_ENABLED
|
||||||
depends on SERIAL
|
depends on SERIAL
|
||||||
select RING_BUFFER
|
select RING_BUFFER if RB9704_ZEPHYR_BEFORE_4_5
|
||||||
select UART_INTERRUPT_DRIVEN
|
select UART_INTERRUPT_DRIVEN
|
||||||
help
|
help
|
||||||
Ground Control's RockBLOCK 9704 (Iridium Certus, IMT messages) on the
|
Ground Control's RockBLOCK 9704 (Iridium Certus, IMT messages) on the
|
||||||
@@ -16,6 +16,16 @@ menuconfig RB9704
|
|||||||
|
|
||||||
if RB9704
|
if RB9704
|
||||||
|
|
||||||
|
# Zephyr 4.5 made the ring buffer header-only, and CONFIG_RING_BUFFER there
|
||||||
|
# brings back the deprecated legacy implementation. Before 4.5 it is what
|
||||||
|
# builds the ring buffer at all. KERNELVERSION is 0xMMmmpp00.
|
||||||
|
config RB9704_KERNEL_VERSION
|
||||||
|
hex
|
||||||
|
default "$(KERNELVERSION)"
|
||||||
|
|
||||||
|
config RB9704_ZEPHYR_BEFORE_4_5
|
||||||
|
def_bool RB9704_KERNEL_VERSION < 0x4050000
|
||||||
|
|
||||||
config RB9704_MESSAGE_MAX
|
config RB9704_MESSAGE_MAX
|
||||||
int "Largest message in either direction (bytes)"
|
int "Largest message in either direction (bytes)"
|
||||||
default 2048
|
default 2048
|
||||||
@@ -30,12 +40,13 @@ DT_COMPAT_ROCK7_ROCKBLOCK_9704 := rock7,rockblock-9704
|
|||||||
|
|
||||||
config RB9704_POWER
|
config RB9704_POWER
|
||||||
bool "Drive the power pins from devicetree"
|
bool "Drive the power pins from devicetree"
|
||||||
default y if $(dt_compat_any_has_prop,$(DT_COMPAT_ROCK7_ROCKBLOCK_9704),power-gpios)
|
default y if $(dt_compat_any_has_prop,$(DT_COMPAT_ROCK7_ROCKBLOCK_9704),iridium-enable-gpios)
|
||||||
select GPIO
|
select GPIO
|
||||||
help
|
help
|
||||||
P_EN, I_EN and I_BTD as the devicetree node gives them. Without
|
I_EN, I_BTD and P_EN as the devicetree node gives them, in Ground
|
||||||
them the modem is taken to be powered, as the board is with the pins
|
Control's start-up and shutdown sequence. I_EN is the one that
|
||||||
left open.
|
switches the modem; without it the modem is taken to be powered, as
|
||||||
|
the board is with the pins left open.
|
||||||
|
|
||||||
config RB9704_WORKER_STACK_SIZE
|
config RB9704_WORKER_STACK_SIZE
|
||||||
int "Worker thread stack size"
|
int "Worker thread stack size"
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
The RockBLOCK 9704, Ground Control's Iridium Certus modem, on Zephyr: a
|
The RockBLOCK 9704, Ground Control's Iridium Certus modem, on Zephyr: a
|
||||||
module that builds Ground Control's own C library for any board with a
|
module that builds Ground Control's own C library for any board with a
|
||||||
UART, gives it the one thread it needs, and offers a small API, a shell
|
UART, gives it the one thread it needs, and offers a small API, a shell
|
||||||
command and a devicetree binding. With it come host tools in Python and a
|
command and a devicetree binding. It also includes host tools in Python
|
||||||
fake modem, so the same tests run against Ground Control's Python binding,
|
and a fake modem, so the same tests run against Ground Control's Python binding,
|
||||||
against Zephyr on `native_sim`, and against Zephyr on a board.
|
against Zephyr on `native_sim`, and against Zephyr on a board.
|
||||||
|
|
||||||
The 9704 sends and receives IMT messages of up to 100 kB through the
|
The 9704 sends and receives IMT messages of up to 100 kB through the
|
||||||
@@ -16,7 +16,25 @@ rockblock9704-zephyr is written and maintained by Scott Penrose
|
|||||||
projects that send data home by satellite:
|
projects that send data home by satellite:
|
||||||
[WII6](https://wii6.au/), a wave-measuring buoy, and
|
[WII6](https://wii6.au/), a wave-measuring buoy, and
|
||||||
[OGLAS](https://oglas.au/), a fleet of LoRa sensors, repeaters and hubs.
|
[OGLAS](https://oglas.au/), a fleet of LoRa sensors, repeaters and hubs.
|
||||||
Both run it, and neither is needed to use it.
|
Both projects run it. The module does not depend on either.
|
||||||
|
|
||||||
|
The source lives at
|
||||||
|
[gitea.sh3d.com.au/Sh3d/rockblock9704-zephyr](https://gitea.sh3d.com.au/Sh3d/rockblock9704-zephyr)
|
||||||
|
and is mirrored to
|
||||||
|
[github.com/SH3D/rockblock9704-zephyr](https://github.com/SH3D/rockblock9704-zephyr).
|
||||||
|
Open issues and pull requests on the GitHub mirror; the Gitea instance does
|
||||||
|
not allow public sign-ups.
|
||||||
|
|
||||||
|
## Zephyr versions
|
||||||
|
|
||||||
|
The module builds and its tests pass on Zephyr v4.4.0 and v4.5.0. Use
|
||||||
|
0.4.0 or later with Zephyr 4.5: 0.3.0 does not compile there, because
|
||||||
|
4.5 changed `uart_irq_update()` to return `void` and the module's
|
||||||
|
receive interrupt used its value. 0.4.0 calls it the way Zephyr's own 4.5
|
||||||
|
samples do. It also selects `CONFIG_RING_BUFFER` only before 4.5, since
|
||||||
|
the ring buffer needs no option from 4.5 on and that option there brings
|
||||||
|
back the deprecated implementation. `CHANGELOG.md` has the detail and
|
||||||
|
`docs/TESTING.md` what was run on each.
|
||||||
|
|
||||||
## Ground Control's library
|
## Ground Control's library
|
||||||
|
|
||||||
@@ -38,28 +56,41 @@ and `CMakeLists.txt` compiles its portable core. What each part does:
|
|||||||
The library's source shows several things a caller has to work around;
|
The library's source shows several things a caller has to work around;
|
||||||
`docs/JSPR.md`, section 8, lists them all. The ones this module handles:
|
`docs/JSPR.md`, section 8, lists them all. The ones this module handles:
|
||||||
|
|
||||||
- **Provisioning is asked once and kept for good**, a miss included. A
|
- **Provisioning cache.** The library asks the modem for its provisioning
|
||||||
modem provisioned after the first send would refuse every topic until
|
once and keeps the answer for the rest of the process, even when the
|
||||||
a reboot. Before a send whose topic is not in what the library kept,
|
topic it wanted was not in it. A modem provisioned after the first send
|
||||||
and after the modem refuses one, the module clears the library's cache
|
would be refused on every topic until a reboot. Before a send whose
|
||||||
so it asks again: one free JSPR round trip.
|
topic is not in what the library kept, and after the modem refuses one,
|
||||||
- **The blocking calls stop working once callbacks are registered.** The
|
the module clears the library's cache so it asks again: one free JSPR
|
||||||
module uses the async path only.
|
round trip.
|
||||||
- **A query during a send swallows the modem's segment requests**, since
|
- **Blocking calls.** They stop working once callbacks are registered, so
|
||||||
the reader discards lines it is not waiting for. Info and signal
|
the module uses the async path only.
|
||||||
requests are refused with `-EBUSY` while a message is moving.
|
- **Queries during a send.** The reader discards lines it is not waiting
|
||||||
- **No locking.** Every library call is on the worker thread.
|
for, so a query during a send swallows the modem's segment requests.
|
||||||
- **A send has no timeout, and the queue's count survives `rbEnd`.** The
|
Info and signal requests are refused with `-EBUSY` while a message is
|
||||||
async path only reacts to lines from the modem, so a modem that goes
|
moving.
|
||||||
quiet mid-send leaves the message in flight for good; `rb9704_cancel`
|
- **Locking.** The library has none, so every library call is on the
|
||||||
asks the modem to abandon it. `rbBegin` empties the queue but not the
|
worker thread.
|
||||||
count of it, which would make every send after a stuck one queue
|
- **Send timeout and queue count.** The async path only reacts to lines
|
||||||
without transmitting; `rb9704_begin` zeroes the count.
|
from the modem, so a modem that goes quiet mid-send leaves the message
|
||||||
|
in flight for good; `rb9704_cancel` asks the modem to abandon it.
|
||||||
|
`rbBegin` empties the queue but not the count of it, which would make
|
||||||
|
every send after a stuck one queue without transmitting; `rb9704_begin`
|
||||||
|
zeroes the count.
|
||||||
|
- **Lines without a status code.** One of those reads past the library's
|
||||||
|
buffer, and on a board it crashed. A modem sends lines before
|
||||||
|
`rb9704_begin` opens the library: its boot lines, once its power pins
|
||||||
|
bring it up. The module
|
||||||
|
listens on the UART from boot and throws those bytes away, so a small
|
||||||
|
hardware FIFO never overflows into fragments of old lines, and when the
|
||||||
|
library opens part-way through a line the rest of that line is thrown
|
||||||
|
away too.
|
||||||
|
|
||||||
Others are for upstream to fix, and are listed in `docs/JSPR.md` for that:
|
Others are for upstream to fix, and are listed in `docs/JSPR.md` for that:
|
||||||
`setState` waits for a misspelt target, a line with no status code reads
|
`setState` waits for a misspelt target, the overread of a line with no
|
||||||
past its buffer, MT segment data is cut at 1446 characters, and the
|
status code remains for any cause the module does not know of (section
|
||||||
Python binding never releases the GIL.
|
8.2), MT segment data is cut at 1446 characters, and the Python binding
|
||||||
|
never releases the GIL.
|
||||||
|
|
||||||
## Using it
|
## Using it
|
||||||
|
|
||||||
@@ -69,15 +100,17 @@ library, pinned, at the path the module looks in, and nothing else:
|
|||||||
```yaml
|
```yaml
|
||||||
- name: rockblock9704-zephyr
|
- name: rockblock9704-zephyr
|
||||||
url: https://github.com/SH3D/rockblock9704-zephyr
|
url: https://github.com/SH3D/rockblock9704-zephyr
|
||||||
revision: v0.1.0
|
revision: v0.4.0
|
||||||
path: modules/lib/rockblock9704-zephyr
|
path: modules/lib/rockblock9704-zephyr
|
||||||
import:
|
import:
|
||||||
name-allowlist:
|
name-allowlist:
|
||||||
- rockblock9704
|
- rockblock9704
|
||||||
```
|
```
|
||||||
|
|
||||||
In the board overlay, a node on the modem's UART. The pins are optional;
|
The board overlay needs a node on the modem's UART. The pins are optional;
|
||||||
without them the modem is taken to be powered:
|
without them the modem is taken to be powered. I_EN starts and stops the
|
||||||
|
modem; P_EN is the supercapacitor charge enable and is active low, so
|
||||||
|
`GPIO_ACTIVE_LOW`, and it can be left unconnected:
|
||||||
|
|
||||||
```dts
|
```dts
|
||||||
&usart3 {
|
&usart3 {
|
||||||
@@ -86,14 +119,24 @@ without them the modem is taken to be powered:
|
|||||||
|
|
||||||
rockblock {
|
rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
power-gpios = <&gpiob 0 GPIO_ACTIVE_HIGH>; /* P_EN */
|
power-gpios = <&gpiob 0 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||||
iridium-enable-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>; /* I_EN */
|
iridium-enable-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||||
booted-gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
booted-gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
`CONFIG_RB9704` follows the node. Then `<rb9704/rb9704.h>`:
|
The 9704's USB-C goes through an FTDI chip to the modem's UART, on the
|
||||||
|
same lines as the header's TX and RX, so the two are one serial port.
|
||||||
|
With the USB-C cable plugged in, that chip drives the modem's RX, and a
|
||||||
|
board on the header can receive from the modem but not send to it:
|
||||||
|
`rb9704_begin` fails with `-EIO`, and the computer on USB gets no answer
|
||||||
|
either. Unplug the USB-C and power the 9704 from the header; a board's
|
||||||
|
5 V pin will do, as the modem draws a few hundred mA
|
||||||
|
(`docs/boards/stamp_c3.md`).
|
||||||
|
|
||||||
|
`CONFIG_RB9704` is selected when the node is present. The API is in
|
||||||
|
`<rb9704/rb9704.h>`:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
static void mo_done(uint16_t topic, uint16_t id, int result, void *user)
|
static void mo_done(uint16_t topic, uint16_t id, int result, void *user)
|
||||||
@@ -113,12 +156,15 @@ rb9704_begin(K_SECONDS(30));
|
|||||||
rb9704_send(RB9704_TOPIC_RAW, buf, len, K_SECONDS(10)); /* costs airtime */
|
rb9704_send(RB9704_TOPIC_RAW, buf, len, K_SECONDS(10)); /* costs airtime */
|
||||||
rb9704_send(RB9704_TOPIC_RAW, buf, len, K_NO_WAIT); /* queues, never blocks */
|
rb9704_send(RB9704_TOPIC_RAW, buf, len, K_NO_WAIT); /* queues, never blocks */
|
||||||
rb9704_cancel(K_SECONDS(10)); /* the one in flight; -ECANCELED via mo_done */
|
rb9704_cancel(K_SECONDS(10)); /* the one in flight; -ECANCELED via mo_done */
|
||||||
|
rb9704_send_fill(RB9704_TOPIC_RAW, len, fill, user, K_SECONDS(10)); /* fill() writes it in place */
|
||||||
```
|
```
|
||||||
|
|
||||||
Every request takes a timeout and waits no longer; with `K_NO_WAIT` a send
|
Every request takes a timeout and waits no longer; with `K_NO_WAIT` a send
|
||||||
queues and returns `-EINPROGRESS`, and its outcome, a refusal included,
|
queues and returns `-EINPROGRESS`, and its outcome, a refusal included,
|
||||||
comes through `mo_done`. Callbacks run on the worker thread. One modem per
|
comes through `mo_done`. Callbacks run on the worker thread. One modem per
|
||||||
system: the library keeps global state.
|
system: the library keeps global state. `rb9704_send_fill` hands `fill`
|
||||||
|
the module's own buffer, so a large message the application makes up as
|
||||||
|
it goes does not have to be held twice.
|
||||||
|
|
||||||
| Kconfig | Default | |
|
| Kconfig | Default | |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
@@ -126,7 +172,7 @@ system: the library keeps global state.
|
|||||||
| `CONFIG_RB9704_WORKER_STACK_SIZE` | 8192 | measured: the library parks 1.5 kB on the stack in `rbPoll()` |
|
| `CONFIG_RB9704_WORKER_STACK_SIZE` | 8192 | measured: the library parks 1.5 kB on the stack in `rbPoll()` |
|
||||||
| `CONFIG_RB9704_WORKER_PRIORITY` | 8 | |
|
| `CONFIG_RB9704_WORKER_PRIORITY` | 8 | |
|
||||||
| `CONFIG_RB9704_RX_RING_SIZE` | 8192 | the library's longest JSPR line |
|
| `CONFIG_RB9704_RX_RING_SIZE` | 8192 | the library's longest JSPR line |
|
||||||
| `CONFIG_RB9704_POWER` | with `power-gpios` | drive the pins |
|
| `CONFIG_RB9704_POWER` | with `iridium-enable-gpios` | drive the pins |
|
||||||
| `CONFIG_RB9704_SHELL` | with `CONFIG_SHELL` | `rb9704` on the shell |
|
| `CONFIG_RB9704_SHELL` | with `CONFIG_SHELL` | `rb9704` on the shell |
|
||||||
| `CONFIG_RB9704_UPSTREAM_DIR` | empty | where Ground Control's library is, if not where `west.yml` puts it |
|
| `CONFIG_RB9704_UPSTREAM_DIR` | empty | where Ground Control's library is, if not where `west.yml` puts it |
|
||||||
|
|
||||||
@@ -142,7 +188,16 @@ rb9704 cancel abandon the message in flight
|
|||||||
rb9704 spy on|off every JSPR line, both ways
|
rb9704 spy on|off every JSPR line, both ways
|
||||||
```
|
```
|
||||||
|
|
||||||
`samples/shell` is the shell plus callbacks that print what arrives.
|
`samples/shell` is the shell plus callbacks that print what arrives, and
|
||||||
|
`rbtest`, airtime tests with a payload `rb9704 pattern check` can check at
|
||||||
|
the other end:
|
||||||
|
|
||||||
|
```
|
||||||
|
rbtest small <topic> [count=3] [gap_s=60] 32-byte messages one after another, each timed
|
||||||
|
rbtest large <topic> [bytes=50000] confirm one large message; without confirm, only the cost
|
||||||
|
rbtest status | stop the run so far, or no more after this one
|
||||||
|
rbtest mt the last MT, checked if it is a test message
|
||||||
|
```
|
||||||
|
|
||||||
## Host tools
|
## Host tools
|
||||||
|
|
||||||
@@ -169,10 +224,23 @@ real 9704 from Python and from `native_sim`.
|
|||||||
|
|
||||||
## Boards
|
## Boards
|
||||||
|
|
||||||
Any board with a free UART. The sample has overlays for `native_sim`,
|
The module runs on any board with a free UART, on any architecture
|
||||||
NUCLEO-U575ZI-Q, Seeed XIAO ESP32S3, ESP32-S3-DevKitC, ESP32 DevKitC and
|
Zephyr runs on. The library is portable C and the module has nothing tied
|
||||||
LilyGO T3-S3 (an out-of-tree board in OGLAST2: build with its
|
to one CPU. The sample has overlays for:
|
||||||
`-DBOARD_ROOT`). It has run on the first three; all six build.
|
|
||||||
|
| Board | CPU | Run on |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `native_sim` | the host (x86-64) | yes |
|
||||||
|
| NUCLEO-U575ZI-Q | STM32U5, Arm Cortex-M33 | yes |
|
||||||
|
| Seeed XIAO ESP32S3 | ESP32-S3, Xtensa | yes |
|
||||||
|
| M5Stamp-C3 | ESP32-C3, RISC-V | yes, a real 9704 under the sky: provisioned, a message sent to Cloudloop; `docs/boards/stamp_c3.md` |
|
||||||
|
| ESP32-S3-DevKitC | ESP32-S3, Xtensa | builds |
|
||||||
|
| ESP32 DevKitC | ESP32, Xtensa | builds |
|
||||||
|
| LilyGO T3-S3 | ESP32-S3, Xtensa | builds; an out-of-tree board in OGLAST2, with its `-DBOARD_ROOT` |
|
||||||
|
|
||||||
|
On an ESP32, `-DEXTRA_CONF_FILE=overlay-wifi.conf` puts the shell on
|
||||||
|
telnet as well, for a board out under the sky with no USB
|
||||||
|
(`docs/TESTING.md`).
|
||||||
|
|
||||||
## Layout
|
## Layout
|
||||||
|
|
||||||
@@ -187,7 +255,8 @@ python/ rb9704, rb9704-fake, the tests
|
|||||||
docs/JSPR.md the protocol as the library speaks it
|
docs/JSPR.md the protocol as the library speaks it
|
||||||
docs/CLOUDLOOP.md account to first message
|
docs/CLOUDLOOP.md account to first message
|
||||||
docs/TESTING.md the tests and how to run them
|
docs/TESTING.md the tests and how to run them
|
||||||
west.yml the pins
|
docs/boards/ notes for one board each: pins, setup
|
||||||
|
west.yml Ground Control's library, pinned
|
||||||
```
|
```
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|||||||
+43
-13
@@ -1,14 +1,17 @@
|
|||||||
# Cloudloop and a RockBLOCK 9704, from the box to a message
|
# Cloudloop and a RockBLOCK 9704, from the box to a message
|
||||||
|
|
||||||
How to get a RockBLOCK 9704 from its box to a message seen on the
|
A RockBLOCK 9704 comes out of the box with an activation card and no
|
||||||
internet, from a computer over its USB-C port: the account, the token,
|
Cloudloop account behind it. This is how to get from there to a message
|
||||||
topics, provisioning, and the order to test things in. `rb9704` is the
|
seen on the internet, from a computer over the modem's USB-C port.
|
||||||
command line in `python/` (`python/README.md` has every verb).
|
`rb9704` is the command line in `python/` (`python/README.md` has every
|
||||||
|
verb).
|
||||||
|
|
||||||
Written 2026-10-09 from Ground Control's and Cloudloop's documentation
|
Written 2026-10-09 from Ground Control's and Cloudloop's documentation
|
||||||
and the library's source. `rb9704 info` and the free JSPR verbs have run
|
and the library's source. `rb9704 info` and the free JSPR verbs have run
|
||||||
against a real 9704 since; the account, provisioning and airtime steps
|
against a real 9704 since. Provisioning and MO messages to Cloudloop work
|
||||||
have not been tried yet.
|
(2026-10-25), from the Zephyr module on an M5Stamp-C3 rather than from
|
||||||
|
this command line; "What has run" at the end says how. MT has not been
|
||||||
|
tried yet.
|
||||||
|
|
||||||
## What there is
|
## What there is
|
||||||
|
|
||||||
@@ -18,7 +21,11 @@ have not been tried yet.
|
|||||||
- **Its USB-C port.** An FTDI FT234XD (USB id `0403:6015`) bridges it to
|
- **Its USB-C port.** An FTDI FT234XD (USB id `0403:6015`) bridges it to
|
||||||
the modem's UART, and the port also powers the board. It needs a port
|
the modem's UART, and the port also powers the board. It needs a port
|
||||||
that supplies 500 mA at 4.0 to 5.3 V; an unpowered hub is not supported.
|
that supplies 500 mA at 4.0 to 5.3 V; an unpowered hub is not supported.
|
||||||
The supercapacitor takes about 40 s to charge from USB. LEDs: red PWR is
|
The supercapacitor takes about 40 s to charge from USB. The FTDI is on
|
||||||
|
the same UART lines as the 10-way header, so with USB-C plugged in a
|
||||||
|
microcontroller on the header can hear the modem but not reach it; a
|
||||||
|
board on the header powers the 9704 from the header, with USB-C
|
||||||
|
unplugged (`boards/stamp_c3.md`). LEDs: red PWR is
|
||||||
input voltage present, green RDY is the modem powered and booted, blue
|
input voltage present, green RDY is the modem powered and booted, blue
|
||||||
XMT is transmitting.
|
XMT is transmitting.
|
||||||
- **The library.** Ground Control's C library (MIT) is what this
|
- **The library.** Ground Control's C library (MIT) is what this
|
||||||
@@ -65,7 +72,8 @@ serves a project.
|
|||||||
### 3. The API token
|
### 3. The API token
|
||||||
|
|
||||||
The API is how the tool reads messages and sends MT, and how the shore
|
The API is how the tool reads messages and sends MT, and how the shore
|
||||||
side will. A token is asked for, not made:
|
side will. Ground Control issues the token; there is no page to generate
|
||||||
|
one:
|
||||||
|
|
||||||
1. Email <help@groundcontrol.com> for a Cloudloop **platform API token**
|
1. Email <help@groundcontrol.com> for a Cloudloop **platform API token**
|
||||||
for the account. Ask for one that can send MT: `DoSendImtMessage` needs
|
for the account. Ask for one that can send MT: `DoSendImtMessage` needs
|
||||||
@@ -133,9 +141,9 @@ rb9704 --log provision.jsonl provision
|
|||||||
```
|
```
|
||||||
|
|
||||||
This asks the modem for its signal and its provisioning every 30 s and
|
This asks the modem for its signal and its provisioning every 30 s and
|
||||||
stops when topics appear, printing them. It talks JSPR directly, because
|
stops when topics appear, printing them. It sends the JSPR requests itself,
|
||||||
the library only asks for provisioning when it is about to send, and
|
because the library only asks for provisioning when it is about to send,
|
||||||
asking this way costs nothing.
|
and asking this way costs nothing.
|
||||||
|
|
||||||
## The order to test in
|
## The order to test in
|
||||||
|
|
||||||
@@ -149,7 +157,7 @@ money; the tool asks before each one, and `--yes` skips the question.
|
|||||||
`rb9704 ports`. The 9704 is the FT234XD, listed first.
|
`rb9704 ports`. The 9704 is the FT234XD, listed first.
|
||||||
3. **Identity, indoors.** `rb9704 info` gives hardware and
|
3. **Identity, indoors.** `rb9704 info` gives hardware and
|
||||||
firmware versions, serial, IMEI, ICCID, whether the SIM is present and
|
firmware versions, serial, IMEI, ICCID, whether the SIM is present and
|
||||||
talking, and the board temperature. Record the IMEI and ICCID against
|
connected, and the board temperature. Record the IMEI and ICCID against
|
||||||
the Thing in Cloudloop.
|
the Thing in Cloudloop.
|
||||||
4. **Signal, outdoors.** `rb9704 signal --watch 600` reads
|
4. **Signal, outdoors.** `rb9704 signal --watch 600` reads
|
||||||
the bars (0 to 5) every 5 s for ten minutes and ends with how often
|
the bars (0 to 5) every 5 s for ten minutes and ends with how often
|
||||||
@@ -184,9 +192,31 @@ version, SIM, operational state). In order of likelihood:
|
|||||||
blocks it. The `--udev` rule stops the first.
|
blocks it. The `--udev` rule stops the first.
|
||||||
- **Not in `dialout`.** `install.sh` checks; `sudo usermod -aG dialout
|
- **Not in `dialout`.** `install.sh` checks; `sudo usermod -aG dialout
|
||||||
$USER` and log in again.
|
$USER` and log in again.
|
||||||
|
- **USB-C and the header at once.** A board on the header with the
|
||||||
|
USB-C cable plugged in: the FTDI drives the modem's RX, and neither side
|
||||||
|
gets an answer. Unplug one.
|
||||||
- **Not booted.** No green RDY: the port gives too little current (a hub,
|
- **Not booted.** No green RDY: the port gives too little current (a hub,
|
||||||
a front-panel port), or the supercapacitor is still charging.
|
a front-panel port), or the supercapacitor is still charging.
|
||||||
- **Something odd.** `rb9704 jspr --setup 'GET hwInfo {}'
|
- **Something odd.** `rb9704 jspr --setup 'GET hwInfo {}'
|
||||||
'GET simStatus {}'` shows the modem's own answers; a 4xx code names
|
'GET simStatus {}'` shows the modem's own answers; a 4xx code names
|
||||||
the problem (`409` unauthorized, `410` SIM not configured, `418` not
|
the problem (`409` unauthorised, `410` SIM not configured, `418` not
|
||||||
provisioned).
|
provisioned).
|
||||||
|
|
||||||
|
## What has run
|
||||||
|
|
||||||
|
On 2026-10-25 a RockBLOCK 9704 (firmware v1.5.14) on the header pins of
|
||||||
|
an M5Stamp-C3, running the shell sample under open sky, was found already
|
||||||
|
provisioned with topics 244 (RAW) and 313 to 317, the Cloudloop colours,
|
||||||
|
and sent two messages on topic 244 that arrived in Cloudloop whole. The
|
||||||
|
library only asks the modem for its provisioning when it is about to
|
||||||
|
send, so the first send is when the module, and `rb9704 status`, learn
|
||||||
|
the topics. The board, its pins and the overnight run are in
|
||||||
|
`boards/stamp_c3.md`.
|
||||||
|
|
||||||
|
Cloudloop shows a message's bytes twice: the message data in Base64
|
||||||
|
(`U3RhbXAtQzMgUF9FTiBsb3c`, the padding `=` left off) and the payload in
|
||||||
|
hex (`5374616D702D433320505F454E206C6F77`). The CRC the library adds on
|
||||||
|
the way out is checked and gone.
|
||||||
|
|
||||||
|
Not yet: MT, a session, and this command line's own `provision` and
|
||||||
|
`send` against a real modem.
|
||||||
+6
-2
@@ -328,7 +328,7 @@ Source: `src/jspr_command.c:269-281`, parse `src/jspr.c:934-1007`.
|
|||||||
- The `messageProvisioning` callback (Python: `set_message_provisioning_callback`)
|
- The `messageProvisioning` callback (Python: `set_message_provisioning_callback`)
|
||||||
fires only here, after the GET (`src/rockblock_9704.c:1181-1187`).
|
fires only here, after the GET (`src/rockblock_9704.c:1181-1187`).
|
||||||
|
|
||||||
### 2.12 PUT serviceConfig (resync), with its state dance
|
### 2.12 PUT serviceConfig (resync), and the state changes around it
|
||||||
|
|
||||||
`rbResyncServiceConfig()` (`src/rockblock_9704.c:1064-1120`):
|
`rbResyncServiceConfig()` (`src/rockblock_9704.c:1064-1120`):
|
||||||
|
|
||||||
@@ -721,8 +721,12 @@ Everything else is ignored.
|
|||||||
solicited `200` first, then `299`s.
|
solicited `200` first, then `299`s.
|
||||||
2. **A line with no 3-digit code in 200..500** makes the code scan run off
|
2. **A line with no 3-digit code in 200..500** makes the code scan run off
|
||||||
the end of the line through the zeroed buffer, then `memmove` with a
|
the end of the line through the zeroed buffer, then `memmove` with a
|
||||||
negative length cast to `size_t` (`src/jspr.c:89-113`). Expect a crash.
|
negative length cast to `size_t` (`src/jspr.c:89-113`). The result is a crash.
|
||||||
Never send banners, prompts or blank-ish lines of 9 bytes or more.
|
Never send banners, prompts or blank-ish lines of 9 bytes or more.
|
||||||
|
On an M5Stamp-C3 it did crash (2026-10-25), when the UART's FIFO had
|
||||||
|
overflowed and handed over fragments of old lines. rockblock9704-zephyr
|
||||||
|
now keeps the FIFO empty from boot and gives the library no line it
|
||||||
|
opened in the middle of (`src/rb9704_serial.c`).
|
||||||
3. **`resultCodeIndexStart` is not reset** after a line is discarded for the
|
3. **`resultCodeIndexStart` is not reset** after a line is discarded for the
|
||||||
wrong target (`src/jspr.c:48,133-136`): if that line had leading junk,
|
wrong target (`src/jspr.c:48,133-136`): if that line had leading junk,
|
||||||
the next line is read from the same offset. Do not send leading junk.
|
the next line is read from the same offset. Do not send leading junk.
|
||||||
|
|||||||
+98
-7
@@ -1,7 +1,7 @@
|
|||||||
# Testing
|
# Testing
|
||||||
|
|
||||||
One fake modem, three places to run the code against it, and a few free
|
The tests run one fake modem against the code in three places, and a few
|
||||||
checks against a real modem.
|
free checks against a real modem.
|
||||||
|
|
||||||
| Level | What runs | Against | Needs |
|
| Level | What runs | Against | Needs |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
@@ -55,11 +55,11 @@ Every option has an environment variable as well: `RB9704_ZEPHYR_EXE`,
|
|||||||
On native_sim the modem UART is a `zephyr,native-tty-uart` node
|
On native_sim the modem UART is a `zephyr,native-tty-uart` node
|
||||||
(`samples/shell/boards/native_sim.overlay`); the tests give it the fake's
|
(`samples/shell/boards/native_sim.overlay`); the tests give it the fake's
|
||||||
pty with `-modem_uart_port=`. The same option takes a real modem's
|
pty with `-modem_uart_port=`. The same option takes a real modem's
|
||||||
`/dev/ttyUSB0`, which is how host Zephyr talks to real hardware.
|
`/dev/ttyUSB0`, which is how host Zephyr reaches real hardware.
|
||||||
|
|
||||||
## The rig: two boards, one wire
|
## The rig: two boards, one wire
|
||||||
|
|
||||||
No USB-serial adapter to hand? Two boards with a UART wired between them
|
Without a USB-serial adapter, two boards with a UART wired between them
|
||||||
will do: one runs the sample, the other runs `tests/rig/bridge`, which
|
will do: one runs the sample, the other runs `tests/rig/bridge`, which
|
||||||
copies bytes between that UART and its own USB serial port, where the
|
copies bytes between that UART and its own USB serial port, where the
|
||||||
fake answers.
|
fake answers.
|
||||||
@@ -82,6 +82,77 @@ round:
|
|||||||
The ESP32-S3 sits in its ROM loader after `west flash` until it is reset;
|
The ESP32-S3 sits in its ROM loader after `west flash` until it is reset;
|
||||||
toggle RTS on its USB port, or press reset, before the tests.
|
toggle RTS on its USB port, or press reset, before the tests.
|
||||||
|
|
||||||
|
## Out of doors: the shell over WiFi
|
||||||
|
|
||||||
|
A real modem needs a view of the sky, which is usually further than a
|
||||||
|
USB cable goes. `samples/shell/overlay-wifi.conf` puts the same shell on telnet,
|
||||||
|
on any ESP32 board, so the board needs only power:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-wifi.conf
|
||||||
|
west flash
|
||||||
|
```
|
||||||
|
|
||||||
|
Once, on the USB console, store the network; it is kept in flash:
|
||||||
|
|
||||||
|
```
|
||||||
|
wifi cred add -s "<SSID>" -k 1 -p "<password>"
|
||||||
|
```
|
||||||
|
|
||||||
|
At every boot after, the board joins it, logs `address 192.168.1.50:
|
||||||
|
telnet 192.168.1.50`, and rejoins after a drop. A network added after boot
|
||||||
|
is joined within 30 s. `wifi cred list` and `wifi cred delete <SSID>` look
|
||||||
|
after the stored list; `net iface` shows the address again.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
telnet 192.168.1.50
|
||||||
|
rb9704 begin
|
||||||
|
rb9704 spy on
|
||||||
|
rb9704 info
|
||||||
|
```
|
||||||
|
|
||||||
|
Telnet has no password and no encryption, and `rb9704 send` costs
|
||||||
|
airtime: use it on a network you trust.
|
||||||
|
|
||||||
|
The Linux `telnet` client stays in line mode, where the up arrow and line
|
||||||
|
editing do nothing: `Ctrl-]` then `mode character` fixes it, or connect
|
||||||
|
with `socat -,rawer,escape=0x1d TCP:<address>:23`.
|
||||||
|
|
||||||
|
On the M5Stamp-C3 the board's RGB LED shows the modem's state and its
|
||||||
|
button begins and ends it; `boards/stamp_c3.md` has the table, the pins
|
||||||
|
and the WiFi commands.
|
||||||
|
|
||||||
|
### Wiring
|
||||||
|
|
||||||
|
The board overlays for the M5Stamp-C3, ESP32-S3-DevKitC, ESP32 DevKitC
|
||||||
|
and NUCLEO-U575ZI-Q wire all three control lines, so `rb9704 begin`
|
||||||
|
starts the modem through I_EN and waits for I_BTD to go high, and
|
||||||
|
`rb9704 power off` waits for I_BTD to go low.
|
||||||
|
|
||||||
|
| 9704 header | M5Stamp-C3 | ESP32-S3-DevKitC | ESP32 DevKitC | NUCLEO-U575ZI-Q |
|
||||||
|
| --- | --- | --- | --- | --- |
|
||||||
|
| 14, RXD (board TX) | GPIO4 | GPIO17 | GPIO17 | PD8 |
|
||||||
|
| 13, TXD (board RX) | GPIO5 | GPIO18 | GPIO16 | PD9 |
|
||||||
|
| 3, I_EN | GPIO6 | GPIO4 | GPIO25 | PF14 (D4) |
|
||||||
|
| 7, I_BTD | GPIO7 | GPIO5 | GPIO26 | PF13 (D7) |
|
||||||
|
| 6, P_EN, active low, optional | GPIO10 | GPIO6 | GPIO27 | PF15 (D2) |
|
||||||
|
| 1, 4 or 10, GND | GND | GND | GND | GND |
|
||||||
|
|
||||||
|
The modem's supply goes to V_IN+ and V_IN- (pins 15 and 16), 4.0 to
|
||||||
|
5.3 V at up to 500 mA, not the board's 3.3 V regulator; V_BATT (pin 12)
|
||||||
|
is for a lithium cell, never 5 V. P_EN is the supercapacitor charge
|
||||||
|
enable and is active low: driven high it switches the charger off, and
|
||||||
|
the modem runs down within minutes. Leaving it unconnected is fine.
|
||||||
|
|
||||||
|
A fake modem on a USB-serial adapter in place of the 9704 has no I_BTD:
|
||||||
|
build with `no-control-pins.overlay`, below, or with the rig overlays,
|
||||||
|
which have no control lines. Tying I_BTD to 3.3 V gets `begin` going, but
|
||||||
|
`power off` then waits 30 s for it to fall and fails.
|
||||||
|
|
||||||
|
For a modem on TX and RX alone, `samples/shell/no-control-pins.overlay`
|
||||||
|
takes the three lines out of any board's overlay at build time:
|
||||||
|
`-DEXTRA_DTC_OVERLAY_FILE=no-control-pins.overlay`.
|
||||||
|
|
||||||
## What has passed
|
## What has passed
|
||||||
|
|
||||||
On 2026-10-09, Zephyr v4.4.0, Ground Control's library v1.0.1, the
|
On 2026-10-09, Zephyr v4.4.0, Ground Control's library v1.0.1, the
|
||||||
@@ -95,6 +166,26 @@ binding 1.0.2:
|
|||||||
| NUCLEO-U575ZI-Q through the rig | 12 | all pass |
|
| NUCLEO-U575ZI-Q through the rig | 12 | all pass |
|
||||||
| a real 9704 (firmware v1.5.14), binding and native_sim, free checks | 2 | all pass |
|
| a real 9704 (firmware v1.5.14), binding and native_sim, free checks | 2 | all pass |
|
||||||
|
|
||||||
Not yet: a message through a real modem and satellite, which costs
|
On 2026-10-25, the M5Stamp-C3 (ESP32-C3, RISC-V) with the shell over
|
||||||
airtime and needs the sky (`CLOUDLOOP.md`, "The order to test in"), and
|
WiFi and a real 9704 on its header pins, under open sky: `begin`, `info`
|
||||||
the power pins on a board that has them wired.
|
and `signal` answer, the modem was provisioned, two messages on topic
|
||||||
|
244 were received in Cloudloop, and the modem stayed up overnight with
|
||||||
|
all three control lines wired. Those were the first messages through a
|
||||||
|
real modem and a satellite. `boards/stamp_c3.md` has the pins, the runs
|
||||||
|
and the P_EN fault found on the way.
|
||||||
|
|
||||||
|
On 2026-11-26, 0.4.0 on Zephyr v4.4.0 and v4.5.0, in the WII6
|
||||||
|
workspace, with the same Ground Control library:
|
||||||
|
|
||||||
|
| Level | v4.4.0 | v4.5.0 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Python: fake, command line, binding, and `native_sim/native/64` against the fake | 37 pass, 2 skip (no real modem) | 37 pass, 2 skip |
|
||||||
|
| The shell sample built for NUCLEO-U575ZI-Q, XIAO ESP32S3, ESP32-S3-DevKitC, ESP32 DevKitC and M5Stamp-C3 | all build | all build |
|
||||||
|
| The Stamp-C3 with `overlay-wifi.conf` and with `overlay-large.conf`, both rig overlays, the bridge on the Nucleo and on the XIAO | all build | all build |
|
||||||
|
|
||||||
|
`CONFIG_RING_BUFFER` is selected on 4.4.0 and not on 4.5.0, and no build
|
||||||
|
on either gave a warning. Nothing has run on a board under 4.5 yet: the
|
||||||
|
rig and real modem runs above were on v4.4.0. 0.3.0 does not build on
|
||||||
|
4.5.
|
||||||
|
|
||||||
|
Not yet: an MT message down to the board.
|
||||||
@@ -0,0 +1,316 @@
|
|||||||
|
# M5Stamp-C3
|
||||||
|
|
||||||
|
M5Stack's Stamp-C3: an ESP32-C3, a single RISC-V core with WiFi and
|
||||||
|
400 kB of RAM, on a small board with a USB-C serial bridge, an RGB LED
|
||||||
|
and a button. Zephyr's name for it is `stamp_c3`, and it is in Zephyr
|
||||||
|
upstream. It is the board for taking the modem outside: powered from a
|
||||||
|
battery or a supply, reached over WiFi, and showing on its LED how things
|
||||||
|
stand.
|
||||||
|
|
||||||
|
The overlay is `samples/shell/boards/stamp_c3.overlay`, with
|
||||||
|
`stamp_c3.conf` beside it for the LED and button.
|
||||||
|
|
||||||
|
## Pins
|
||||||
|
|
||||||
|
| Stamp-C3 | 9704 header | Notes |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| GPIO4, `uart1` TX | 14, RXD | 230400 8N1 |
|
||||||
|
| GPIO5, `uart1` RX | 13, TXD | |
|
||||||
|
| GPIO6 | 3, I_EN | starts and stops the modem |
|
||||||
|
| GPIO7 | 7, I_BTD | high once booted, low once shut down; waited on both ways |
|
||||||
|
| GPIO10 | 6, P_EN | the supercapacitor charge enable, **active low**; optional |
|
||||||
|
| GND | 1, 4 or 10, GND | signal ground |
|
||||||
|
| | 15, V_IN+ and 16, V_IN- | 4.0 to 5.3 V, 500 mA: see Power |
|
||||||
|
| GPIO2 | | the RGB LED, an SK6812, on the board |
|
||||||
|
| GPIO3 | the button | on the board |
|
||||||
|
| GPIO20, GPIO21 | `uart0`, the console | through the USB-C bridge |
|
||||||
|
|
||||||
|
Kept clear: GPIO8 and GPIO9 (strapping pins, and the board's I2C) and
|
||||||
|
GPIO18 and GPIO19 (USB).
|
||||||
|
|
||||||
|
## Power: V_IN+, and the 9704's USB-C unplugged
|
||||||
|
|
||||||
|
The 9704's header UART and its USB-C port are the same serial lines. With
|
||||||
|
USB-C plugged in, the 9704's FTDI chip is powered and drives the modem's
|
||||||
|
RX, and a board on the header cannot drive the line, so the modem gets
|
||||||
|
no request from either side, the computer on USB included. Its TX still
|
||||||
|
reaches the header, so a board can receive alongside USB, but not send.
|
||||||
|
|
||||||
|
So the 9704 is powered from the header with its USB-C unplugged, on
|
||||||
|
V_IN+ (pin 15) and V_IN- (pin 16): 4.0 to 5.3 V, and the board limits
|
||||||
|
itself to about 460 mA while its supercapacitor charges, about 40 s to
|
||||||
|
the green RDY LED. A USB supply of its own is best, with its ground
|
||||||
|
joined to the Stamp's; the Stamp's 5V pin works too, sharing the Stamp's
|
||||||
|
USB-C. V_BATT (pin 12) is for a single lithium cell, 3.6 to 4.5 V, with
|
||||||
|
no reverse-polarity protection and no charger on the board: never 5 V
|
||||||
|
there. Ground Control recommends one input, not both.
|
||||||
|
|
||||||
|
The control lines are optional. With fewer wired, take the matching lines
|
||||||
|
out of the overlay's `rockblock` node, or `rb9704 begin` waits on a pin
|
||||||
|
that is not there:
|
||||||
|
|
||||||
|
- None: four wires, and the modem is taken to be powered: I_EN has a
|
||||||
|
pull-up and P_EN a pull-down, so it boots and charges when power comes.
|
||||||
|
No edit needed: `-DEXTRA_DTC_OVERLAY_FILE=no-control-pins.overlay`
|
||||||
|
takes all three out at build time (below).
|
||||||
|
- I_EN: `rb9704 power off` and `begin` over telnet restart a modem that
|
||||||
|
has hung, with nobody walking out to it. It is the line most worth
|
||||||
|
wiring.
|
||||||
|
- I_BTD as well: start-up and shutdown wait for I_BTD to follow I_EN,
|
||||||
|
as Ground Control's page asks, not a fixed 4 s
|
||||||
|
(`boot-delay-ms`). Moving I_EN back before I_BTD has followed "may
|
||||||
|
result in damage to the 9704 module".
|
||||||
|
- P_EN adds nothing for a modem on V_IN+: left open, the board's
|
||||||
|
pull-down keeps the charger on. Wired, it must be `GPIO_ACTIVE_LOW`;
|
||||||
|
driven high it switches the charger off.
|
||||||
|
|
||||||
|
## Build and flash
|
||||||
|
|
||||||
|
From a west workspace that has this module:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-wifi.conf
|
||||||
|
west flash
|
||||||
|
```
|
||||||
|
|
||||||
|
Without `-DEXTRA_CONF_FILE=overlay-wifi.conf` the shell is on the USB
|
||||||
|
console only, and the LED and button work the same.
|
||||||
|
|
||||||
|
TX and RX only, no control lines:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-wifi.conf \
|
||||||
|
-DEXTRA_DTC_OVERLAY_FILE=no-control-pins.overlay
|
||||||
|
```
|
||||||
|
|
||||||
|
With no I_EN, the long press on the button ends without turning anything
|
||||||
|
off, and `rb9704 power` answers `-ENOTSUP`.
|
||||||
|
|
||||||
|
## WiFi
|
||||||
|
|
||||||
|
Once, on the USB console (115200), store the network. It is kept in flash
|
||||||
|
across reboots and reflashing:
|
||||||
|
|
||||||
|
```
|
||||||
|
wifi cred add -s "<SSID>" -k 1 -p "<password>"
|
||||||
|
```
|
||||||
|
|
||||||
|
`-k 1` is WPA2-PSK; `-k 0` is an open network. The board joins at every
|
||||||
|
boot after, tries again every 30 s while the network is away, and logs:
|
||||||
|
|
||||||
|
```
|
||||||
|
address 192.168.1.50: telnet 192.168.1.50
|
||||||
|
```
|
||||||
|
|
||||||
|
| Command | |
|
||||||
|
| --- | --- |
|
||||||
|
| `wifi cred list` | the stored networks |
|
||||||
|
| `wifi cred delete <SSID>` | forget one |
|
||||||
|
| `wifi cred auto_connect` | join a stored network now |
|
||||||
|
| `wifi status` | the network joined, the channel, the signal |
|
||||||
|
| `wifi scan` | the networks in range |
|
||||||
|
| `net iface` | the address, again |
|
||||||
|
|
||||||
|
## Telnet
|
||||||
|
|
||||||
|
```sh
|
||||||
|
telnet 192.168.1.50
|
||||||
|
```
|
||||||
|
|
||||||
|
Zephyr's telnet server does not offer character mode, so the client stays
|
||||||
|
in line mode, and the up arrow, Tab and line editing do nothing. Ask for
|
||||||
|
it: `Ctrl-]`, then `mode character`. For every session, `~/.telnetrc`:
|
||||||
|
|
||||||
|
```
|
||||||
|
192.168.1.50
|
||||||
|
mode character
|
||||||
|
```
|
||||||
|
|
||||||
|
Or raw, with every key going to the shell and `Ctrl-]` to leave:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
socat -,rawer,escape=0x1d TCP:192.168.1.50:23
|
||||||
|
```
|
||||||
|
|
||||||
|
Telnet has no password and no encryption, and `rb9704 send` costs
|
||||||
|
airtime: use it on a network you trust.
|
||||||
|
|
||||||
|
## The LED and button
|
||||||
|
|
||||||
|
`samples/shell/src/indicator.c`.
|
||||||
|
|
||||||
|
| LED | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| blue | not begun |
|
||||||
|
| red / yellow / green | begun: no signal or no satellite / 1-2 bars / 3-5 bars |
|
||||||
|
| magenta | a message is with the modem, on its way |
|
||||||
|
| green flash, 1 s | a message went |
|
||||||
|
| red flash, 2 s | a message, or a button action, failed |
|
||||||
|
| cyan flash, 2 s | a message arrived |
|
||||||
|
| white, fast blink | a button action is running |
|
||||||
|
| slow blink of any of the above | no WiFi: telnet will not reach it |
|
||||||
|
|
||||||
|
| Button | |
|
||||||
|
| --- | --- |
|
||||||
|
| short press | not begun: `rb9704 begin`. Begun: ask for the signal |
|
||||||
|
| 2 s or more | end, and the modem off when I_EN is wired |
|
||||||
|
|
||||||
|
Nothing on the button costs airtime. The LED runs at 24 of 255
|
||||||
|
(`LEVEL` in `indicator.c`).
|
||||||
|
|
||||||
|
## First power-up
|
||||||
|
|
||||||
|
1. Without the modem: the LED blinks blue until WiFi joins, then stays
|
||||||
|
blue. A short press runs `begin` with nothing there: white, then a red
|
||||||
|
flash.
|
||||||
|
2. With the modem wired: a short press goes white, then red, yellow or
|
||||||
|
green with the signal.
|
||||||
|
3. Over telnet: `rb9704 spy on`, `rb9704 info`, `rb9704 signal`. None
|
||||||
|
of the three costs airtime.
|
||||||
|
|
||||||
|
A fake modem (`rb9704-fake`) on a USB-serial adapter in the modem's place
|
||||||
|
has no I_BTD: tie GPIO7 to 3.3 V for those runs.
|
||||||
|
|
||||||
|
## Airtime tests: `rbtest`
|
||||||
|
|
||||||
|
`samples/shell/src/rbtest.c`. Every test message has a 16-byte header
|
||||||
|
(`RBT`, the kind, its number in the run, its length, the uptime it was
|
||||||
|
made at) and then a ramp, byte k being k % 510 counted up to 255 and back
|
||||||
|
down, so a lost or repeated segment shows in a hex dump. Cloudloop shows
|
||||||
|
each message in hex and in Base64; either goes to the command line in
|
||||||
|
`python/`, which checks every byte:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
rb9704 pattern check --b64 UkJUAVMBAwAAAAAgAAAXfBAREhMUFRYXGBkaGxwdHh8
|
||||||
|
S 1/3, 32 bytes, made at uptime 6.012 s
|
||||||
|
every byte as expected
|
||||||
|
```
|
||||||
|
|
||||||
|
A run is on a thread of its own, so the shell stays free, and each
|
||||||
|
message is logged when the modem accepts it and when it finishes:
|
||||||
|
|
||||||
|
```
|
||||||
|
rbtest small 244 # 3 messages of 32 bytes, 60 s apart
|
||||||
|
rbtest small 244 5 120 # 5 of them, 120 s apart
|
||||||
|
rbtest status # how long each took
|
||||||
|
rbtest stop # no more after the one in flight
|
||||||
|
```
|
||||||
|
|
||||||
|
The log lines, with the times left out:
|
||||||
|
|
||||||
|
```
|
||||||
|
<inf> rbtest: rbtest S 1/3: 32 bytes on topic 244, accepted in <ms> ms
|
||||||
|
<inf> rbtest: rbtest S 1/3: sent in <s.ms> s
|
||||||
|
...
|
||||||
|
<inf> rbtest: rbtest S: 3 of 3 sent
|
||||||
|
```
|
||||||
|
|
||||||
|
A message that has not finished after 10 minutes, 30 for a large one, is
|
||||||
|
cancelled and counted as failed.
|
||||||
|
|
||||||
|
### One large message
|
||||||
|
|
||||||
|
```
|
||||||
|
rbtest large 244 # says what it would send, and sends nothing
|
||||||
|
rbtest large 244 confirm # sends 50000 bytes
|
||||||
|
rbtest large 244 20000 confirm # or another size
|
||||||
|
```
|
||||||
|
|
||||||
|
The size is limited by `CONFIG_RB9704_MESSAGE_MAX`, 2048 bytes unless
|
||||||
|
raised. 50000 needs `overlay-large.conf`, and on the Stamp-C3 that does
|
||||||
|
not fit beside WiFi: the module keeps three buffers of that size, the
|
||||||
|
library's MO and MT buffers and its own copy for sends, and the link
|
||||||
|
overflows by about 11 kB. Trimming the network buffers and the receive
|
||||||
|
ring still left it 3 kB over. So the 50000-byte test runs on the USB
|
||||||
|
console, with a laptop beside the board:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-large.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
With WiFi, 40000 bytes links, using 96% of the RAM, which leaves little
|
||||||
|
for anything added later:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-wifi.conf \
|
||||||
|
-DCONFIG_RB9704_MESSAGE_MAX=40000
|
||||||
|
```
|
||||||
|
|
||||||
|
`rbtest large` writes its message straight into the module's buffer
|
||||||
|
(`rb9704_send_fill`), so the test itself adds no fourth buffer.
|
||||||
|
|
||||||
|
### Messages to the board (MT)
|
||||||
|
|
||||||
|
The module listens for MT whenever it is begun, not only around a send:
|
||||||
|
the modem sends `messageTerminate` lines unprompted, the board logs each
|
||||||
|
whole MT (`mt topic 244 id 3 len 32 crc ...`) and the LED flashes cyan.
|
||||||
|
What has not been seen yet is when the network delivers: straight away
|
||||||
|
to a modem sitting idle under the sky, or only after it next sends. The
|
||||||
|
test is set up to find out:
|
||||||
|
|
||||||
|
1. `rb9704 begin` under open sky, and wait for bars. Send nothing.
|
||||||
|
2. From any computer with the Cloudloop token, queue a 32-byte test
|
||||||
|
message, which costs airtime:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
rb9704 pattern make --size 32 --out mt.bin
|
||||||
|
rb9704 cloud mt --file mt.bin
|
||||||
|
```
|
||||||
|
|
||||||
|
or `rb9704 cloud mt --text "ping 1"`, or the Cloudloop web interface.
|
||||||
|
3. Watch the log, then `rbtest mt`:
|
||||||
|
|
||||||
|
```
|
||||||
|
mt 1 since boot, the last 12 s ago
|
||||||
|
topic 244 id 3, 32 bytes, crc c07a7327
|
||||||
|
52 42 54 01 4d 01 01 00 00 00 00 20 00 00 00 00 10 11 12 ...
|
||||||
|
RBT.M...... ....................
|
||||||
|
test message M 1/1, all 32 bytes as expected
|
||||||
|
```
|
||||||
|
|
||||||
|
4. If nothing has arrived after 10 minutes, `rbtest small 244 1` and see
|
||||||
|
whether the MT follows the send. `rb9704 cloud status <id>` says what
|
||||||
|
Cloudloop thinks happened to it.
|
||||||
|
|
||||||
|
An MT larger than `CONFIG_RB9704_MESSAGE_MAX` cannot be received; with
|
||||||
|
the 2048-byte default, keep test MTs small.
|
||||||
|
|
||||||
|
## What has run
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| WiFi, the stored network, telnet | works (2026-10-24) |
|
||||||
|
| a real 9704 on TX and RX, on V_IN+ from the Stamp's 5V: `begin`, `info`, `signal` | works (2026-10-25) |
|
||||||
|
| the same with the 9704's USB-C plugged in | fails: the FTDI holds the modem's RX |
|
||||||
|
| P_EN, I_EN, I_BTD: `begin` powers it up in about 2 s, `power off`, `begin` again | works (2026-10-25), 8 of 8 cycles, and 12 of 12 with up to 5 s between `power on` and `begin` |
|
||||||
|
| under open sky: the constellation visible and 3 to 5 bars within seconds of `begin` | works (2026-10-25) |
|
||||||
|
| staying up while active | failed with P_EN driven the wrong way: see below; with P_EN unconnected, up and answering throughout (2026-10-25) |
|
||||||
|
| provisioning, and a message sent | works (2026-10-25): provisioned with 244 and 313 to 317, and "Stamp-C3 says hi", 16 bytes on topic 244, sent in 10 s with 3 to 4 bars and received in Cloudloop |
|
||||||
|
| the reworked control pins outside: I_EN and I_BTD in Ground Control's sequence, P_EN wired and `GPIO_ACTIVE_LOW` | works (2026-10-25): "Stamp-C3 P_EN low", 17 bytes on topic 244, sent in 6 s and received in Cloudloop, and the modem up overnight; see below |
|
||||||
|
| an MT message down to the board | not yet: `rbtest mt`, above |
|
||||||
|
| `rbtest small`, three timed messages | not yet: works against the fake modem on native_sim |
|
||||||
|
| `rbtest large`, 50000 bytes | not yet: the USB-console build links; works against the fake on native_sim at 2000 bytes |
|
||||||
|
| the LED and button | the button's short press works; the busy colour reads orange, not white, at this brightness |
|
||||||
|
|
||||||
|
### The modem stopped answering after a few minutes: P_EN
|
||||||
|
|
||||||
|
On 2026-10-25 the modem stopped answering 2 to 5 minutes after each
|
||||||
|
`begin`, four times: once indoors, three times under open sky. Every
|
||||||
|
request then got `-EIO`, its signal reports stopped, and it stayed silent
|
||||||
|
until the control lines were cycled. Indoors the RDY LED went off.
|
||||||
|
|
||||||
|
The overlay had P_EN as `GPIO_ACTIVE_HIGH`. P_EN is active low (Ground
|
||||||
|
Control's hardware page, pin 6, "Cap Charge Enable Signal (ACTIVE LOW)"),
|
||||||
|
so every `begin` drove it high and switched the supercapacitor charger
|
||||||
|
off: the modem ran on what the supercapacitor held until it was flat.
|
||||||
|
The TX and RX test without control lines, where the pull-down keeps the
|
||||||
|
charger on, did not stop. With P_EN taken off the header, the same
|
||||||
|
firmware stayed up and sent its first message. The overlay now has
|
||||||
|
`GPIO_ACTIVE_LOW`, and the module releases P_EN while the modem is off;
|
||||||
|
with P_EN wired again on that firmware, the modem sent a second message
|
||||||
|
and stayed up through the night, about 11 h 54 min from 22:41 on
|
||||||
|
2026-10-25 to 10:35 the next morning, satellites seen throughout.
|
||||||
|
|
||||||
|
The module also now shuts down as the page sets out: I_EN low, then wait
|
||||||
|
for I_BTD to go low before anything else, and the same wait on the way
|
||||||
|
up. Before, `power off` dropped the pins and returned at once.
|
||||||
@@ -7,7 +7,10 @@ description: |
|
|||||||
no AT mode. One per system: the library underneath keeps global state.
|
no AT mode. One per system: the library underneath keeps global state.
|
||||||
|
|
||||||
The control pins are optional. With none, the modem is assumed powered and
|
The control pins are optional. With none, the modem is assumed powered and
|
||||||
enabled, which is how the board behaves with the pins left open.
|
enabled, which is how the board behaves with the pins left open: I_EN
|
||||||
|
has a pull-up and P_EN a pull-down. I_EN is what switches the modem, so
|
||||||
|
power control needs iridium-enable-gpios; booted-gpios and power-gpios
|
||||||
|
are each optional beside it.
|
||||||
|
|
||||||
compatible: "rock7,rockblock-9704"
|
compatible: "rock7,rockblock-9704"
|
||||||
|
|
||||||
@@ -18,25 +21,32 @@ properties:
|
|||||||
power-gpios:
|
power-gpios:
|
||||||
type: phandle-array
|
type: phandle-array
|
||||||
description: |
|
description: |
|
||||||
P_EN, the supply enable. Driven active to power the board.
|
P_EN, header pin 6: the supercapacitor charge enable. It is active
|
||||||
|
low on the board, so give GPIO_ACTIVE_LOW. Driven active (charging
|
||||||
|
on) while the modem runs, and released to an input while it is off,
|
||||||
|
where the board's pull-down keeps the charger on. Leaving it
|
||||||
|
unconnected is fine.
|
||||||
|
|
||||||
iridium-enable-gpios:
|
iridium-enable-gpios:
|
||||||
type: phandle-array
|
type: phandle-array
|
||||||
description: |
|
description: |
|
||||||
I_EN, the modem enable. Driven active once the supply is up.
|
I_EN, header pin 3: starts and stops the modem. Driven high to
|
||||||
|
start it and low to stop it, and never moved back until I_BTD has
|
||||||
|
followed.
|
||||||
|
|
||||||
booted-gpios:
|
booted-gpios:
|
||||||
type: phandle-array
|
type: phandle-array
|
||||||
description: |
|
description: |
|
||||||
I_BTD, the modem's booted signal. When present, power-up waits for it
|
I_BTD, header pin 7: high once the modem has booted, low once it has
|
||||||
instead of a fixed delay.
|
shut down. When present, start-up and shutdown wait for it instead
|
||||||
|
of a fixed delay.
|
||||||
|
|
||||||
boot-delay-ms:
|
boot-delay-ms:
|
||||||
type: int
|
type: int
|
||||||
default: 4000
|
default: 4000
|
||||||
description: |
|
description: |
|
||||||
How long to wait after enabling the modem before talking to it, when
|
How long to wait after moving I_EN, either way, when there is no
|
||||||
there is no booted-gpios to wait on.
|
booted-gpios to wait on.
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
- |
|
- |
|
||||||
@@ -46,7 +56,7 @@ examples:
|
|||||||
|
|
||||||
modem: rockblock {
|
modem: rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
power-gpios = <&gpiob 0 GPIO_ACTIVE_HIGH>;
|
power-gpios = <&gpiob 0 GPIO_ACTIVE_LOW>;
|
||||||
iridium-enable-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>;
|
iridium-enable-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>;
|
||||||
booted-gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>;
|
booted-gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>;
|
||||||
};
|
};
|
||||||
|
|||||||
+14
-3
@@ -117,9 +117,10 @@ struct rb9704_callbacks {
|
|||||||
/* Replace the application's callbacks; NULL clears them. */
|
/* Replace the application's callbacks; NULL clears them. */
|
||||||
void rb9704_set_callbacks(const struct rb9704_callbacks *cb);
|
void rb9704_set_callbacks(const struct rb9704_callbacks *cb);
|
||||||
|
|
||||||
/* Switch the board's supply and modem enable, when the devicetree gives the
|
/* Start or stop the modem through I_EN, when the devicetree gives it, in
|
||||||
* pins. Waits for the booted pin or boot-delay-ms on the way up. -ENOTSUP
|
* Ground Control's sequence: each way waits for I_BTD to follow, or
|
||||||
* with no power pin. rb9704_end first if it was begun. */
|
* boot-delay-ms without it. -ENOTSUP with no I_EN. rb9704_end first if it
|
||||||
|
* was begun. */
|
||||||
int rb9704_power(bool on);
|
int rb9704_power(bool on);
|
||||||
|
|
||||||
/* Open the serial port and bring the library up: API version, SIM
|
/* Open the serial port and bring the library up: API version, SIM
|
||||||
@@ -144,6 +145,16 @@ int rb9704_end(k_timeout_t timeout);
|
|||||||
*/
|
*/
|
||||||
int rb9704_send(uint16_t topic, const void *data, size_t len, k_timeout_t timeout);
|
int rb9704_send(uint16_t topic, const void *data, size_t len, k_timeout_t timeout);
|
||||||
|
|
||||||
|
/* Writes len bytes of a message into buf. */
|
||||||
|
typedef void (*rb9704_fill_t)(uint8_t *buf, size_t len, void *user);
|
||||||
|
|
||||||
|
/* As rb9704_send, with the message written straight into this module's
|
||||||
|
* buffer by fill, on the caller's thread, once the request slot is taken.
|
||||||
|
* A generated message near CONFIG_RB9704_MESSAGE_MAX then needs no buffer
|
||||||
|
* of the caller's as well: the library already keeps two of that size. */
|
||||||
|
int rb9704_send_fill(uint16_t topic, size_t len, rb9704_fill_t fill, void *user,
|
||||||
|
k_timeout_t timeout);
|
||||||
|
|
||||||
/* Ask the modem to abandon the message in flight. Returns 0 once the
|
/* Ask the modem to abandon the message in flight. Returns 0 once the
|
||||||
* request is on the wire; the outcome, -ECANCELED when the modem agrees,
|
* request is on the wire; the outcome, -ECANCELED when the modem agrees,
|
||||||
* comes through mo_done, and until then the message counts as in flight.
|
* comes through mo_done, and until then the message counts as in flight.
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ macOS, Windows). Without the `modem` extra, the fake modem, `jspr`,
|
|||||||
| `cloud msg ID` | | one message record and its Lingo form |
|
| `cloud msg ID` | | one message record and its Lingo form |
|
||||||
| `cloud mt --text/--hex/--file [--thing ID]` | airtime | queue an MT on `IMT_TOPIC_RAW` |
|
| `cloud mt --text/--hex/--file [--thing ID]` | airtime | queue an MT on `IMT_TOPIC_RAW` |
|
||||||
| `cloud status ID` | | an MT's delivery status |
|
| `cloud status ID` | | an MT's delivery status |
|
||||||
|
| `pattern make [--size N] [--out F]` | | an `rbtest` test message, as hex or a file, to queue with `cloud mt` |
|
||||||
|
| `pattern check --hex/--b64/--file` | | check every byte of one, as Cloudloop shows it |
|
||||||
|
|
||||||
The verbs that cost airtime print the size and ask; `--yes` skips the
|
The verbs that cost airtime print the size and ask; `--yes` skips the
|
||||||
question and is the only way to send from a script.
|
question and is the only way to send from a script.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "rockblock9704-tools"
|
name = "rockblock9704-tools"
|
||||||
version = "0.1.0"
|
version = "0.4.0"
|
||||||
description = "Host tools for the RockBLOCK 9704: a command line for the modem and Cloudloop, and a fake modem for testing"
|
description = "Host tools for the RockBLOCK 9704: a command line for the modem and Cloudloop, and a fake modem for testing"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
"""Host tools for the RockBLOCK 9704."""
|
"""Host tools for the RockBLOCK 9704."""
|
||||||
|
|
||||||
__version__ = "0.1.0"
|
__version__ = "0.4.0"
|
||||||
@@ -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] listen [--out DIR] [--for S]
|
||||||
rb9704 [-p PORT] session (--text T | --hex H | --file F) [--quiet S] [--yes]
|
rb9704 [-p PORT] session (--text T | --hex H | --file F) [--quiet S] [--yes]
|
||||||
rb9704 cloud ping | things | mo | msg ID | mt ... | status ID
|
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 modem side uses Ground Control's rockblock9704 package, a binding of
|
||||||
the same C library this repository builds into Zephyr, so what works here
|
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
|
question. Everything else on the modem side is local serial traffic and
|
||||||
costs nothing. `cloud mt` costs airtime too.
|
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
|
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
|
9704's USB-C bridge, 0403:6015). --log FILE appends every event as a JSON
|
||||||
line, for the bench log.
|
line, for the bench log.
|
||||||
@@ -42,6 +48,8 @@ import urllib.error
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
|
from rb9704tools import pattern
|
||||||
|
|
||||||
FTDI_VID, FT234X_PID = 0x0403, 0x6015
|
FTDI_VID, FT234X_PID = 0x0403, 0x6015
|
||||||
BAUD = 230400
|
BAUD = 230400
|
||||||
RAW_TOPIC = 244
|
RAW_TOPIC = 244
|
||||||
@@ -570,6 +578,38 @@ def cmd_cloud(a):
|
|||||||
ev("cloud_mt", bytes=len(data), topic=a.topic, result=json.dumps(r))
|
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
|
# ---------------------------------------------------------------- main
|
||||||
|
|
||||||
def add_payload(p, required=True):
|
def add_payload(p, required=True):
|
||||||
@@ -660,6 +700,20 @@ def main():
|
|||||||
add_payload(q)
|
add_payload(q)
|
||||||
p.set_defaults(fn=cmd_cloud)
|
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()
|
a = ap.parse_args()
|
||||||
LOG = a.log
|
LOG = a.log
|
||||||
a.fn(a)
|
a.fn(a)
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ Control is one command per line on stdin, events one per line on stdout:
|
|||||||
mo-release send the withheld final status
|
mo-release send the withheld final status
|
||||||
segment <n> ask for MO segments of n bytes (default 1446)
|
segment <n> ask for MO segments of n bytes (default 1446)
|
||||||
state <state> the operationalState from now on
|
state <state> the operationalState from now on
|
||||||
|
raw <text> write text as it is, \r for CR: a line's
|
||||||
|
tail, junk, a line cut short
|
||||||
|
before <text> write text just before the next reply
|
||||||
quit
|
quit
|
||||||
|
|
||||||
READY <port>
|
READY <port>
|
||||||
@@ -95,6 +98,7 @@ class FakeModem:
|
|||||||
self.mo_refuse = False
|
self.mo_refuse = False
|
||||||
self.mo_hold = False # the next MO's final status waits for mo-release
|
self.mo_hold = False # the next MO's final status waits for mo-release
|
||||||
self.held = None # (topic, id, status) withheld
|
self.held = None # (topic, id, status) withheld
|
||||||
|
self.before = b"" # written ahead of the next reply
|
||||||
self.imei = "300434030000000"
|
self.imei = "300434030000000"
|
||||||
self.serial = "123456"
|
self.serial = "123456"
|
||||||
self.iccid = "8988169712345678901"
|
self.iccid = "8988169712345678901"
|
||||||
@@ -123,6 +127,9 @@ class FakeModem:
|
|||||||
|
|
||||||
def request(self, line):
|
def request(self, line):
|
||||||
self.events("RX " + line)
|
self.events("RX " + line)
|
||||||
|
if self.before:
|
||||||
|
self.write(self.before)
|
||||||
|
self.before = b""
|
||||||
parts = line.split(" ", 2)
|
parts = line.split(" ", 2)
|
||||||
if len(parts) < 2:
|
if len(parts) < 2:
|
||||||
return
|
return
|
||||||
@@ -324,6 +331,15 @@ class FakeModem:
|
|||||||
self.segment = max(1, min(MO_SEGMENT_MAX, int(w[1])))
|
self.segment = max(1, min(MO_SEGMENT_MAX, int(w[1])))
|
||||||
elif cmd == "state":
|
elif cmd == "state":
|
||||||
self.state = w[1]
|
self.state = w[1]
|
||||||
|
elif cmd in ("raw", "before"):
|
||||||
|
text = line.split(" ", 1)[1] if " " in line else ""
|
||||||
|
data = text.encode().decode("unicode_escape").encode("latin-1")
|
||||||
|
with self.lock:
|
||||||
|
if cmd == "raw":
|
||||||
|
self.write(data)
|
||||||
|
else:
|
||||||
|
self.before = data
|
||||||
|
self.events("%s %s" % (cmd.upper(), text))
|
||||||
elif cmd == "quit":
|
elif cmd == "quit":
|
||||||
return False
|
return False
|
||||||
elif cmd:
|
elif cmd:
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -2,11 +2,14 @@
|
|||||||
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
"""The rb9704 command line against the fake modem."""
|
"""The rb9704 command line against the fake modem."""
|
||||||
|
|
||||||
|
import base64
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from rb9704tools import pattern
|
||||||
|
|
||||||
|
|
||||||
def run(*args, timeout=30):
|
def run(*args, timeout=30):
|
||||||
return subprocess.run([sys.executable, "-m", "rb9704tools.cli", *args], capture_output=True,
|
return subprocess.run([sys.executable, "-m", "rb9704tools.cli", *args], capture_output=True,
|
||||||
@@ -46,3 +49,29 @@ def test_send_with_yes(fake):
|
|||||||
assert r.returncode == 0, r.stdout + r.stderr
|
assert r.returncode == 0, r.stdout + r.stderr
|
||||||
m = fake.out.expect(r"^MO 244 \d+ (\w+)")
|
m = fake.out.expect(r"^MO 244 \d+ (\w+)")
|
||||||
assert bytes.fromhex(m.group(1)) == b"cli-hello"
|
assert bytes.fromhex(m.group(1)) == b"cli-hello"
|
||||||
|
|
||||||
|
|
||||||
|
def test_pattern_make_and_check():
|
||||||
|
r = run("pattern", "make", "--size", "1000", "--seq", "2", "--count", "3")
|
||||||
|
assert r.returncode == 0, r.stderr
|
||||||
|
hexed = r.stdout.strip()
|
||||||
|
data = bytes.fromhex(hexed)
|
||||||
|
assert len(data) == 1000 and data[:4] == b"RBT\x01"
|
||||||
|
# the ramp turns at 255 and comes back down
|
||||||
|
assert data[255] == 255 and data[256] == 254 and data[510] == 0
|
||||||
|
r = run("pattern", "check", "--hex", hexed)
|
||||||
|
assert r.returncode == 0, r.stdout + r.stderr
|
||||||
|
assert "M 2/3, 1000 bytes" in r.stdout and "every byte as expected" in r.stdout
|
||||||
|
b64 = base64.b64encode(data).decode().rstrip("=")
|
||||||
|
assert run("pattern", "check", "--b64", b64).returncode == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_pattern_check_finds_the_damage():
|
||||||
|
data = bytearray(pattern.make(100))
|
||||||
|
data[40] ^= 1
|
||||||
|
r = run("pattern", "check", "--hex", data.hex())
|
||||||
|
assert r.returncode != 0 and "byte 40" in r.stdout + r.stderr
|
||||||
|
r = run("pattern", "check", "--hex", pattern.make(100)[:90].hex())
|
||||||
|
assert r.returncode != 0 and "says 100 bytes, 90 arrived" in r.stdout + r.stderr
|
||||||
|
r = run("pattern", "check", "--hex", b"hello".hex())
|
||||||
|
assert r.returncode != 0 and "not a test message" in r.stdout + r.stderr
|
||||||
@@ -5,10 +5,13 @@ Zephyr, through the shell sample, against the fake modem: on native_sim
|
|||||||
with --zephyr-exe, on a board with --board-console and --board-modem.
|
with --zephyr-exe, on a board with --board-console and --board-modem.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from rb9704tools import pattern
|
||||||
|
|
||||||
|
|
||||||
def begin(z):
|
def begin(z):
|
||||||
c, f = z
|
c, f = z
|
||||||
@@ -102,6 +105,37 @@ def test_cancel_a_send_the_modem_sits_on(zephyr):
|
|||||||
c.out.expect(r"result 0")
|
c.out.expect(r"result 0")
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_boot_burst_while_closed(zephyr):
|
||||||
|
"""A modem powered up before begin talks to nobody: its boot lines,
|
||||||
|
over 600 bytes here, end part-way through one, finished just before
|
||||||
|
the first reply. On the M5Stamp-C3 such a burst overflowed the UART's
|
||||||
|
128-byte FIFO while the module was not listening, and begin then heard
|
||||||
|
only repeated fragments of old lines; given one, the library read past
|
||||||
|
its buffer and the board crashed (2026-10-25). The module now empties
|
||||||
|
the FIFO from boot and skips the rest of a line it opened in.
|
||||||
|
|
||||||
|
On a board through the rig this is that overflow. native_sim has no
|
||||||
|
FIFO to overflow: there it checks that the burst does no harm."""
|
||||||
|
c, f = zephyr
|
||||||
|
boot = ('\\x11\\x11299 bootInfo {"image_type":"production","version":{"major":1,'
|
||||||
|
'"minor":5,"patch":14,"build_info":"SX-250613-A3E9C3E3-P1-P3142-1194848-'
|
||||||
|
'12516979"},"boot_source":"primary"}\\r')
|
||||||
|
lines = (boot
|
||||||
|
+ '299 simStatus {"card_present":true,"sim_connected":true,'
|
||||||
|
'"iccid":"8988169712345678901"}\\r'
|
||||||
|
+ '299 operationalState {"state":"inactive","reason":0}\\r' * 4
|
||||||
|
+ '299 constellationState {"constellation_visible":false,"signal_bars":0}\\r' * 2
|
||||||
|
+ '299 bootInfo {"image_type":"prod')
|
||||||
|
f.cmd("raw " + lines)
|
||||||
|
f.out.expect(r"^RAW ")
|
||||||
|
time.sleep(0.5)
|
||||||
|
f.cmd('before uction"}\\r')
|
||||||
|
f.out.expect(r"^BEFORE ")
|
||||||
|
begin(zephyr)
|
||||||
|
c.sh("rb9704 info")
|
||||||
|
c.out.expect(r"imei\s+300434030000000")
|
||||||
|
|
||||||
|
|
||||||
def test_topic_below_64_is_refused_here(zephyr):
|
def test_topic_below_64_is_refused_here(zephyr):
|
||||||
c, f = zephyr
|
c, f = zephyr
|
||||||
begin(zephyr)
|
begin(zephyr)
|
||||||
@@ -149,3 +183,61 @@ def test_end(zephyr):
|
|||||||
c.out.expect(r"end: ok")
|
c.out.expect(r"end: ok")
|
||||||
c.sh("rb9704 send 244 after-end")
|
c.sh("rb9704 send 244 after-end")
|
||||||
c.out.expect(r"send: -\d+ ENOTCONN")
|
c.out.expect(r"send: -\d+ ENOTCONN")
|
||||||
|
|
||||||
|
|
||||||
|
def test_rbtest_small_sends_checkable_messages(zephyr):
|
||||||
|
"""`rbtest small`, two messages with no gap: each reaches the network
|
||||||
|
whole, numbered, and its time is logged."""
|
||||||
|
c, f = zephyr
|
||||||
|
begin(zephyr)
|
||||||
|
c.sh("rbtest small 244 2 0")
|
||||||
|
c.out.expect(r"2 messages of 32 bytes on topic 244")
|
||||||
|
for seq in (1, 2):
|
||||||
|
m = f.out.expect(r"^MO 244 \d+ (\w+)")
|
||||||
|
r = pattern.check(bytes.fromhex(m.group(1)))
|
||||||
|
assert r["ok"] and (r["kind"], r["seq"], r["count"], r["got"]) == ("S", seq, 2, 32)
|
||||||
|
c.out.expect(r"rbtest S %d/2: sent in \d+\.\d{3} s" % seq)
|
||||||
|
c.out.expect(r"rbtest S: 2 of 2 sent$")
|
||||||
|
c.sh("rbtest status")
|
||||||
|
c.out.expect(r"last run S: 2 of 2 done, 32 bytes each on topic 244")
|
||||||
|
c.out.expect(r"2: sent in \d+\.\d{3} s")
|
||||||
|
|
||||||
|
|
||||||
|
def test_rbtest_small_logs_a_failure(zephyr):
|
||||||
|
c, f = zephyr
|
||||||
|
begin(zephyr)
|
||||||
|
f.cmd("mo-fail network_error")
|
||||||
|
c.sh("rbtest small 244 1 0")
|
||||||
|
c.out.expect(r"rbtest S 1/1: failed after \d+ ms: -\d+")
|
||||||
|
c.out.expect(r"rbtest S: 0 of 1 sent$")
|
||||||
|
|
||||||
|
|
||||||
|
def test_rbtest_large_asks_first(zephyr):
|
||||||
|
"""Without confirm nothing goes; with it, one message of the size given
|
||||||
|
(the 50000 default needs CONFIG_RB9704_MESSAGE_MAX raised)."""
|
||||||
|
c, f = zephyr
|
||||||
|
begin(zephyr)
|
||||||
|
c.sh("rbtest large 244 2000")
|
||||||
|
c.out.expect(r"Nothing sent. To send it: rbtest large 244 2000 confirm")
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
f.out.expect(r"^MO ", timeout=2)
|
||||||
|
c.sh("rbtest large 244 confirm")
|
||||||
|
c.out.expect(r"50000 bytes: from 17 to \d+")
|
||||||
|
c.sh("rbtest large 244 2000 confirm")
|
||||||
|
m = f.out.expect(r"^MO 244 \d+ (\w+)")
|
||||||
|
r = pattern.check(bytes.fromhex(m.group(1)))
|
||||||
|
assert r["ok"] and (r["kind"], r["got"]) == ("L", 2000)
|
||||||
|
c.out.expect(r"rbtest L 1/1: sent in")
|
||||||
|
|
||||||
|
|
||||||
|
def test_rbtest_mt_checks_a_test_message(zephyr):
|
||||||
|
c, f = zephyr
|
||||||
|
begin(zephyr)
|
||||||
|
c.sh("rbtest mt")
|
||||||
|
c.out.expect(r"no MT since boot|mt\s+\d+ since boot")
|
||||||
|
f.cmd("mthex 244 " + pattern.make(1200, seq=4, count=5).hex())
|
||||||
|
c.out.expect(r"rbtest: MT is a test message, M 4/5, all 1200 bytes as expected")
|
||||||
|
c.sh("rbtest mt")
|
||||||
|
c.out.expect(r"topic 244 id \d+, 1200 bytes, crc %08x" % zlib.crc32(pattern.make(1200, seq=4, count=5)))
|
||||||
|
c.out.expect(r"52 42 54 01 4d 04 05 00 00 00 04 b0")
|
||||||
|
c.out.expect(r"test message M 4/5, all 1200 bytes as expected")
|
||||||
@@ -3,4 +3,8 @@
|
|||||||
cmake_minimum_required(VERSION 3.20.0)
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
project(rb9704_shell)
|
project(rb9704_shell)
|
||||||
target_sources(app PRIVATE src/main.c)
|
target_sources(app PRIVATE src/main.c src/rbtest.c)
|
||||||
|
target_sources_ifdef(CONFIG_WIFI app PRIVATE src/wifi.c)
|
||||||
|
# The RGB LED and button, on boards whose overlay gives a led-strip alias
|
||||||
|
# and an sw0 button (boards/stamp_c3.*).
|
||||||
|
target_sources_ifdef(CONFIG_LED_STRIP app PRIVATE src/indicator.c)
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
/* ESP32 DevKitC (the original ESP32): the modem on uart2, GPIO17 (TX) and
|
/* ESP32 DevKitC (the original ESP32): the modem on uart2, GPIO17 (TX) and
|
||||||
* GPIO16 (RX). The console stays on uart0 through the board's USB bridge.
|
* GPIO16 (RX), with its control lines on GPIO27 (P_EN), GPIO25 (I_EN) and
|
||||||
|
* GPIO26 (I_BTD). The console stays on uart0 through the board's USB bridge.
|
||||||
* On WROVER modules GPIO16 and GPIO17 belong to the PSRAM: use a WROOM
|
* On WROVER modules GPIO16 and GPIO17 belong to the PSRAM: use a WROOM
|
||||||
* module, or move uart2's pins here. */
|
* module, or move uart2's pins here. */
|
||||||
&uart2 {
|
&uart2 {
|
||||||
current-speed = <230400>;
|
current-speed = <230400>;
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
|
||||||
rockblock {
|
rb9704: rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
|
power-gpios = <&gpio0 27 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||||
|
iridium-enable-gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||||
|
booted-gpios = <&gpio0 26 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
/* ESP32-S3-DevKitC: the modem on uart1, GPIO17 (TX) and GPIO18 (RX). */
|
/* ESP32-S3-DevKitC: the modem on uart1, GPIO17 (TX) and GPIO18 (RX), with
|
||||||
|
* its control lines on GPIO6 (P_EN), GPIO4 (I_EN) and GPIO5 (I_BTD). */
|
||||||
&pinctrl {
|
&pinctrl {
|
||||||
uart1_rb9704: uart1_rb9704 {
|
uart1_rb9704: uart1_rb9704 {
|
||||||
group1 {
|
group1 {
|
||||||
@@ -18,7 +19,10 @@
|
|||||||
current-speed = <230400>;
|
current-speed = <230400>;
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
|
||||||
rockblock {
|
rb9704: rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
|
power-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||||
|
iridium-enable-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||||
|
booted-gpios = <&gpio0 5 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
current-speed = <230400>;
|
current-speed = <230400>;
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
|
||||||
rockblock {
|
rb9704: rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
current-speed = <230400>;
|
current-speed = <230400>;
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
|
||||||
rockblock {
|
rb9704: rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
current-speed = <230400>;
|
current-speed = <230400>;
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
|
||||||
rockblock {
|
rb9704: rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
/* NUCLEO-U575ZI-Q: the modem on USART3, PD8 (TX) and PD9 (RX).
|
/* NUCLEO-U575ZI-Q: the modem on USART3, PD8 (TX) and PD9 (RX), with its
|
||||||
|
* control lines on the Arduino header: D2, PF15 (P_EN); D4, PF14 (I_EN);
|
||||||
|
* D7, PF13 (I_BTD). PB0 would match the README's example, but the board
|
||||||
|
* gives it to adc4.
|
||||||
*
|
*
|
||||||
* On this board those pins share solder bridges with the ST-LINK's virtual
|
* On this board PD8 and PD9 share solder bridges with the ST-LINK's virtual
|
||||||
* COM port; check UM2861 before wiring. To test without a modem, the fake
|
* COM port; check UM2861 before wiring. To test without a modem, the fake
|
||||||
* modem (python/rb9704tools/fakemodem.py) on a 3.3 V USB-serial adapter
|
* modem (python/rb9704tools/fakemodem.py) on a 3.3 V USB-serial adapter
|
||||||
* wired to the same pins stands in for it. */
|
* wired to the same pins stands in for it. */
|
||||||
@@ -10,7 +13,10 @@
|
|||||||
current-speed = <230400>;
|
current-speed = <230400>;
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
|
||||||
rockblock {
|
rb9704: rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
|
power-gpios = <&gpiof 15 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||||
|
iridium-enable-gpios = <&gpiof 14 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||||
|
booted-gpios = <&gpiof 13 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# The RGB LED and the button (src/indicator.c).
|
||||||
|
CONFIG_SPI=y
|
||||||
|
CONFIG_LED_STRIP=y
|
||||||
|
CONFIG_INPUT=y
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/* M5Stamp-C3: the modem on uart1, GPIO4 (TX) and GPIO5 (RX), with its
|
||||||
|
* three control lines on GPIO10 (P_EN), GPIO6 (I_EN) and GPIO7 (I_BTD). The
|
||||||
|
* console stays on uart0 through the board's USB bridge; with
|
||||||
|
* overlay-wifi.conf the shell is on telnet as well, for a board with power
|
||||||
|
* and no USB.
|
||||||
|
*
|
||||||
|
* The board's RGB LED, an SK6812 on GPIO2, is driven by spi2 with MOSI
|
||||||
|
* alone on that pin (src/indicator.c); the board's own spi2 pins put SCLK
|
||||||
|
* on GPIO4, the modem's TX. The button on GPIO3 is the board's sw0.
|
||||||
|
*
|
||||||
|
* Kept clear: GPIO8 and 9 (strapping, and the I2C), GPIO18 and 19 (USB),
|
||||||
|
* GPIO20 and 21 (the console).
|
||||||
|
*
|
||||||
|
* docs/boards/stamp_c3.md has the wiring, the WiFi set-up and the LED. */
|
||||||
|
|
||||||
|
#include <zephyr/dt-bindings/led/led.h>
|
||||||
|
|
||||||
|
&pinctrl {
|
||||||
|
spim2_led: spim2_led {
|
||||||
|
group1 {
|
||||||
|
pinmux = <SPIM2_MOSI_GPIO2>;
|
||||||
|
output-low;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
uart1_rb9704: uart1_rb9704 {
|
||||||
|
group1 {
|
||||||
|
pinmux = <UART1_TX_GPIO4>;
|
||||||
|
output-high;
|
||||||
|
};
|
||||||
|
group2 {
|
||||||
|
pinmux = <UART1_RX_GPIO5>;
|
||||||
|
bias-pull-up;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/ {
|
||||||
|
aliases {
|
||||||
|
led-strip = &led_strip;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
&spi2 {
|
||||||
|
pinctrl-0 = <&spim2_led>;
|
||||||
|
pinctrl-names = "default";
|
||||||
|
/* The SK6812 reads a high idle line as data. */
|
||||||
|
line-idle-low;
|
||||||
|
|
||||||
|
led_strip: ws2812@0 {
|
||||||
|
compatible = "worldsemi,ws2812-spi";
|
||||||
|
reg = <0>;
|
||||||
|
spi-max-frequency = <6400000>;
|
||||||
|
chain-length = <1>;
|
||||||
|
spi-cpha;
|
||||||
|
spi-one-frame = <0xf0>; /* 625 ns high, 625 ns low */
|
||||||
|
spi-zero-frame = <0xc0>; /* 312.5 ns high, 937.5 ns low */
|
||||||
|
color-mapping = <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
&uart1 {
|
||||||
|
pinctrl-0 = <&uart1_rb9704>;
|
||||||
|
pinctrl-names = "default";
|
||||||
|
current-speed = <230400>;
|
||||||
|
status = "okay";
|
||||||
|
|
||||||
|
rb9704: rockblock {
|
||||||
|
compatible = "rock7,rockblock-9704";
|
||||||
|
power-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||||
|
iridium-enable-gpios = <&gpio0 6 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||||
|
booted-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
current-speed = <230400>;
|
current-speed = <230400>;
|
||||||
status = "okay";
|
status = "okay";
|
||||||
|
|
||||||
rockblock {
|
rb9704: rockblock {
|
||||||
compatible = "rock7,rockblock-9704";
|
compatible = "rock7,rockblock-9704";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
*
|
||||||
|
* The modem on TX and RX alone: P_EN, I_EN and I_BTD taken out of the
|
||||||
|
* board overlay's node, for a modem wired with four wires. The module
|
||||||
|
* then takes it to be powered, as the RockBLOCK is with the pins open.
|
||||||
|
*
|
||||||
|
* west build -b stamp_c3 samples/shell -- \
|
||||||
|
* -DEXTRA_DTC_OVERLAY_FILE=no-control-pins.overlay
|
||||||
|
*/
|
||||||
|
&rb9704 {
|
||||||
|
/delete-property/ power-gpios;
|
||||||
|
/delete-property/ iridium-enable-gpios;
|
||||||
|
/delete-property/ booted-gpios;
|
||||||
|
};
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
#
|
||||||
|
# Messages up to 50000 bytes, for `rbtest large`:
|
||||||
|
#
|
||||||
|
# west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-large.conf
|
||||||
|
#
|
||||||
|
# Three buffers of this size are kept: the library's MO and MT buffers and
|
||||||
|
# this module's copy for rb9704_send, about 150 kB in all. On the
|
||||||
|
# M5Stamp-C3 that fits on the USB console, and with overlay-wifi.conf as
|
||||||
|
# well it does not: the link overflows by 11 kB. With WiFi, 40000 bytes
|
||||||
|
# fits (docs/boards/stamp_c3.md).
|
||||||
|
CONFIG_RB9704_MESSAGE_MAX=50000
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
#
|
||||||
|
# The shell over WiFi, for a board out in the open with power and no USB:
|
||||||
|
#
|
||||||
|
# west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-wifi.conf
|
||||||
|
#
|
||||||
|
# Once, on the USB console:
|
||||||
|
#
|
||||||
|
# wifi cred add -s "<SSID>" -k 1 -p "<password>"
|
||||||
|
#
|
||||||
|
# The board joins that network at every boot after (src/wifi.c), logs its
|
||||||
|
# address, and `telnet <address>` gives the same shell as the console. There
|
||||||
|
# is no password on telnet and `rb9704 send` costs airtime: keep it on a
|
||||||
|
# network you trust.
|
||||||
|
|
||||||
|
# --- WiFi -------------------------------------------------------------------
|
||||||
|
CONFIG_WIFI=y
|
||||||
|
CONFIG_NET_L2_WIFI_MGMT=y
|
||||||
|
CONFIG_NET_L2_WIFI_SHELL=y
|
||||||
|
# The ESP32 driver reconnects by itself after the access point drops it.
|
||||||
|
CONFIG_ESP32_WIFI_STA_RECONNECT=y
|
||||||
|
|
||||||
|
CONFIG_NETWORKING=y
|
||||||
|
CONFIG_NET_IPV4=y
|
||||||
|
CONFIG_NET_IPV6=n
|
||||||
|
CONFIG_NET_DHCPV4=y
|
||||||
|
CONFIG_NET_TCP=y
|
||||||
|
CONFIG_NET_SOCKETS=y
|
||||||
|
CONFIG_NET_SHELL=y
|
||||||
|
CONFIG_NET_MGMT=y
|
||||||
|
CONFIG_NET_MGMT_EVENT=y
|
||||||
|
CONFIG_NET_MGMT_EVENT_INFO=y
|
||||||
|
|
||||||
|
# --- credentials, kept in flash --------------------------------------------
|
||||||
|
CONFIG_WIFI_CREDENTIALS=y
|
||||||
|
CONFIG_WIFI_CREDENTIALS_CONNECT_STORED=y
|
||||||
|
CONFIG_SETTINGS=y
|
||||||
|
CONFIG_SETTINGS_NVS=y
|
||||||
|
CONFIG_NVS=y
|
||||||
|
CONFIG_FLASH=y
|
||||||
|
CONFIG_FLASH_MAP=y
|
||||||
|
|
||||||
|
# --- the shell on telnet ----------------------------------------------------
|
||||||
|
CONFIG_SHELL_BACKEND_TELNET=y
|
||||||
|
# Character mode and echo negotiated with the client, so line editing and
|
||||||
|
# history work as on the console. Zephyr's own telnet sample sets it.
|
||||||
|
CONFIG_SHELL_TELNET_SUPPORT_COMMAND=y
|
||||||
|
CONFIG_SHELL_STACK_SIZE=4096
|
||||||
|
|
||||||
|
# --- memory -----------------------------------------------------------------
|
||||||
|
CONFIG_MAIN_STACK_SIZE=4096
|
||||||
|
CONFIG_NET_TX_STACK_SIZE=2048
|
||||||
|
CONFIG_NET_RX_STACK_SIZE=2048
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
*
|
||||||
|
* indicator.c - the board's RGB LED and button, for a board out in the open
|
||||||
|
* with nobody at its console. Built on boards whose devicetree has a
|
||||||
|
* led-strip alias (one LED is enough) and an sw0 button.
|
||||||
|
*
|
||||||
|
* The LED, by priority:
|
||||||
|
*
|
||||||
|
* white, fast blink a button action is running (begin, end)
|
||||||
|
* green flash a message went (1 s)
|
||||||
|
* red flash a message, or a button action, failed (2 s)
|
||||||
|
* cyan flash a message arrived (2 s)
|
||||||
|
* magenta a message is with the modem, on its way
|
||||||
|
* red/yellow/green begun: no signal or no satellite / 1-2 bars / 3-5
|
||||||
|
* blue not begun
|
||||||
|
*
|
||||||
|
* On a WiFi build the steady colours blink slowly while there is no WiFi:
|
||||||
|
* blinking means telnet will not reach it.
|
||||||
|
*
|
||||||
|
* The button, both free of airtime:
|
||||||
|
*
|
||||||
|
* short press not begun: rb9704_begin. Begun: ask for the signal.
|
||||||
|
* long press rb9704_end, and the supply off when there is a power pin.
|
||||||
|
*/
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/devicetree.h>
|
||||||
|
#include <zephyr/drivers/led_strip.h>
|
||||||
|
#include <zephyr/input/input.h>
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
|
||||||
|
#include <rb9704/rb9704.h>
|
||||||
|
|
||||||
|
#include "indicator.h"
|
||||||
|
#ifdef CONFIG_WIFI
|
||||||
|
#include "wifi.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LOG_MODULE_REGISTER(sample_indicator, LOG_LEVEL_INF);
|
||||||
|
|
||||||
|
#define TICK_MS 100
|
||||||
|
#define LONG_MS 2000
|
||||||
|
/* Out of 255: the SK6812 at full is too bright to look at. */
|
||||||
|
#define LEVEL 24
|
||||||
|
|
||||||
|
static const struct device *const strip = DEVICE_DT_GET(DT_ALIAS(led_strip));
|
||||||
|
|
||||||
|
enum flash { FLASH_NONE, FLASH_SENT, FLASH_FAILED, FLASH_MT };
|
||||||
|
|
||||||
|
static atomic_t flash;
|
||||||
|
static int64_t flash_until;
|
||||||
|
static atomic_t busy;
|
||||||
|
static uint32_t ticks;
|
||||||
|
|
||||||
|
static K_SEM_DEFINE(press_sem, 0, 1);
|
||||||
|
static bool press_long;
|
||||||
|
|
||||||
|
static struct led_rgb rgb(uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
return (struct led_rgb){.r = r, .g = g, .b = b};
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct led_rgb off = {0};
|
||||||
|
|
||||||
|
static bool wifi_up(void)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_WIFI
|
||||||
|
return sample_wifi_connected();
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void indicator_flash_mo(int result)
|
||||||
|
{
|
||||||
|
atomic_set(&flash, result == 0 ? FLASH_SENT : FLASH_FAILED);
|
||||||
|
flash_until = k_uptime_get() + (result == 0 ? 1000 : 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void indicator_flash_mt(void)
|
||||||
|
{
|
||||||
|
atomic_set(&flash, FLASH_MT);
|
||||||
|
flash_until = k_uptime_get() + 2000;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct led_rgb pick(void)
|
||||||
|
{
|
||||||
|
struct rb9704_status st;
|
||||||
|
struct led_rgb c;
|
||||||
|
|
||||||
|
ticks++;
|
||||||
|
if (atomic_get(&busy)) {
|
||||||
|
return (ticks & 1) ? rgb(LEVEL, LEVEL, LEVEL) : off;
|
||||||
|
}
|
||||||
|
if (atomic_get(&flash) != FLASH_NONE) {
|
||||||
|
if (k_uptime_get() < flash_until) {
|
||||||
|
switch (atomic_get(&flash)) {
|
||||||
|
case FLASH_SENT:
|
||||||
|
return rgb(0, LEVEL, 0);
|
||||||
|
case FLASH_FAILED:
|
||||||
|
return rgb(LEVEL, 0, 0);
|
||||||
|
default:
|
||||||
|
return rgb(0, LEVEL, LEVEL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
atomic_set(&flash, FLASH_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
rb9704_status(&st);
|
||||||
|
if (st.mo_in_flight) {
|
||||||
|
c = rgb(LEVEL, 0, LEVEL);
|
||||||
|
} else if (!st.begun) {
|
||||||
|
c = rgb(0, 0, LEVEL);
|
||||||
|
} else if (!st.signal_known || st.signal_bars == 0 ||
|
||||||
|
(st.visibility_known && !st.constellation_visible)) {
|
||||||
|
c = rgb(LEVEL, 0, 0);
|
||||||
|
} else if (st.signal_bars < 3) {
|
||||||
|
c = rgb(LEVEL, LEVEL, 0);
|
||||||
|
} else {
|
||||||
|
c = rgb(0, LEVEL, 0);
|
||||||
|
}
|
||||||
|
/* Half a second on, half off, while telnet cannot reach the board. */
|
||||||
|
if (!wifi_up() && (ticks / 5) % 2) {
|
||||||
|
return off;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tick(struct k_work *work)
|
||||||
|
{
|
||||||
|
struct led_rgb c = pick();
|
||||||
|
|
||||||
|
(void)led_strip_update_rgb(strip, &c, 1);
|
||||||
|
k_work_schedule(k_work_delayable_from_work(work), K_MSEC(TICK_MS));
|
||||||
|
}
|
||||||
|
|
||||||
|
static K_WORK_DELAYABLE_DEFINE(tick_work, tick);
|
||||||
|
|
||||||
|
/* The input thread must not wait on the modem: a press is handed to the
|
||||||
|
* button thread, and a press during an action is dropped. */
|
||||||
|
static void on_key(struct input_event *evt, void *user)
|
||||||
|
{
|
||||||
|
static int64_t down;
|
||||||
|
|
||||||
|
ARG_UNUSED(user);
|
||||||
|
if (evt->type != INPUT_EV_KEY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (evt->value) {
|
||||||
|
down = k_uptime_get();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (atomic_get(&busy)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
press_long = k_uptime_get() - down >= LONG_MS;
|
||||||
|
k_sem_give(&press_sem);
|
||||||
|
}
|
||||||
|
|
||||||
|
INPUT_CALLBACK_DEFINE(DEVICE_DT_GET(DT_PARENT(DT_ALIAS(sw0))), on_key, NULL);
|
||||||
|
|
||||||
|
static void button_thread(void *a, void *b, void *c)
|
||||||
|
{
|
||||||
|
struct rb9704_status st;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
ARG_UNUSED(a);
|
||||||
|
ARG_UNUSED(b);
|
||||||
|
ARG_UNUSED(c);
|
||||||
|
for (;;) {
|
||||||
|
k_sem_take(&press_sem, K_FOREVER);
|
||||||
|
rb9704_status(&st);
|
||||||
|
atomic_set(&busy, 1);
|
||||||
|
if (press_long) {
|
||||||
|
LOG_INF("button: end");
|
||||||
|
/* rb9704_power ends the library first. */
|
||||||
|
rc = rb9704_power(false);
|
||||||
|
if (rc == -ENOTSUP) {
|
||||||
|
rc = st.begun ? rb9704_end(K_SECONDS(10)) : 0;
|
||||||
|
}
|
||||||
|
} else if (!st.begun) {
|
||||||
|
LOG_INF("button: begin");
|
||||||
|
rc = rb9704_begin(K_SECONDS(60));
|
||||||
|
} else {
|
||||||
|
LOG_INF("button: signal");
|
||||||
|
rc = rb9704_signal(K_SECONDS(10));
|
||||||
|
}
|
||||||
|
atomic_set(&busy, 0);
|
||||||
|
if (rc < 0) {
|
||||||
|
LOG_WRN("button: failed (%d)", rc);
|
||||||
|
indicator_flash_mo(rc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
K_THREAD_DEFINE(button_tid, 2048, button_thread, NULL, NULL, NULL, 10, 0, 0);
|
||||||
|
|
||||||
|
void indicator_start(void)
|
||||||
|
{
|
||||||
|
if (!device_is_ready(strip)) {
|
||||||
|
LOG_ERR("LED not ready");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
k_work_schedule(&tick_work, K_NO_WAIT);
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
*/
|
||||||
|
#ifndef SAMPLE_INDICATOR_H
|
||||||
|
#define SAMPLE_INDICATOR_H
|
||||||
|
|
||||||
|
/* The RGB LED shows the modem's state; the button begins and ends it. */
|
||||||
|
void indicator_start(void);
|
||||||
|
/* A short flash for a finished send (result as mo_done gives it) and for
|
||||||
|
* a message arrived. */
|
||||||
|
void indicator_flash_mo(int result);
|
||||||
|
void indicator_flash_mt(void);
|
||||||
|
|
||||||
|
#endif /* SAMPLE_INDICATOR_H */
|
||||||
@@ -15,12 +15,25 @@
|
|||||||
|
|
||||||
#include <rb9704/rb9704.h>
|
#include <rb9704/rb9704.h>
|
||||||
|
|
||||||
|
#include "rbtest.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_WIFI
|
||||||
|
#include "wifi.h"
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_LED_STRIP
|
||||||
|
#include "indicator.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(sample, LOG_LEVEL_INF);
|
LOG_MODULE_REGISTER(sample, LOG_LEVEL_INF);
|
||||||
|
|
||||||
static void on_mo_done(uint16_t topic, uint16_t id, int result, void *user)
|
static void on_mo_done(uint16_t topic, uint16_t id, int result, void *user)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(user);
|
ARG_UNUSED(user);
|
||||||
LOG_INF("mo done topic %u id %u result %d", topic, id, result);
|
LOG_INF("mo done topic %u id %u result %d", topic, id, result);
|
||||||
|
rbtest_mo_done(topic, id, result);
|
||||||
|
#ifdef CONFIG_LED_STRIP
|
||||||
|
indicator_flash_mo(result);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_mt(const struct rb9704_mt *mt, void *user)
|
static void on_mt(const struct rb9704_mt *mt, void *user)
|
||||||
@@ -37,6 +50,10 @@ static void on_mt(const struct rb9704_mt *mt, void *user)
|
|||||||
text[n] = '\0';
|
text[n] = '\0';
|
||||||
LOG_INF("mt topic %u id %u len %u crc %08x: %s", mt->topic, mt->id, (unsigned int)mt->len,
|
LOG_INF("mt topic %u id %u len %u crc %08x: %s", mt->topic, mt->id, (unsigned int)mt->len,
|
||||||
crc32_ieee(mt->data, mt->len), text);
|
crc32_ieee(mt->data, mt->len), text);
|
||||||
|
rbtest_mt(mt);
|
||||||
|
#ifdef CONFIG_LED_STRIP
|
||||||
|
indicator_flash_mt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_signal(uint8_t bars, bool visible, void *user)
|
static void on_signal(uint8_t bars, bool visible, void *user)
|
||||||
@@ -61,6 +78,12 @@ static const struct rb9704_callbacks cb = {
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
rb9704_set_callbacks(&cb);
|
rb9704_set_callbacks(&cb);
|
||||||
|
#ifdef CONFIG_WIFI
|
||||||
|
sample_wifi_start();
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_LED_STRIP
|
||||||
|
indicator_start();
|
||||||
|
#endif
|
||||||
LOG_INF("rb9704 shell sample: `rb9704 begin`, then `rb9704 info`");
|
LOG_INF("rb9704 shell sample: `rb9704 begin`, then `rb9704 info`");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,409 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
*
|
||||||
|
* rbtest.c - `rbtest` on the shell: airtime tests with a payload that is
|
||||||
|
* easy to check at the other end, and a record of the last MT.
|
||||||
|
*
|
||||||
|
* rbtest small <topic> [count] [gap_s] count messages of 32 bytes, one
|
||||||
|
* at a time, gap_s apart
|
||||||
|
* rbtest large <topic> [bytes] [confirm] one message, 50000 bytes unless
|
||||||
|
* given; without confirm it only
|
||||||
|
* says what it would cost
|
||||||
|
* rbtest status the run, and how long each took
|
||||||
|
* rbtest stop no more messages after this one
|
||||||
|
* rbtest mt the last message from the network
|
||||||
|
*
|
||||||
|
* A run is on a thread of its own, so the shell stays free; each message
|
||||||
|
* is logged as it is accepted and as it finishes.
|
||||||
|
*
|
||||||
|
* Every test message, MO or MT, has the same shape. A 16-byte header:
|
||||||
|
*
|
||||||
|
* 0..2 "RBT"
|
||||||
|
* 3 version, 1
|
||||||
|
* 4 kind: 'S' small, 'L' large, anything else from the cloud side
|
||||||
|
* 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: a ramp that shows a missing or repeated segment at a
|
||||||
|
* glance in a hex dump. `rb9704 pattern check` in python/ checks one, and
|
||||||
|
* `rb9704 pattern make` makes one to queue as an MT.
|
||||||
|
*/
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
#include <zephyr/shell/shell.h>
|
||||||
|
#include <zephyr/sys/byteorder.h>
|
||||||
|
#include <zephyr/sys/crc.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <rb9704/rb9704.h>
|
||||||
|
|
||||||
|
#include "rbtest.h"
|
||||||
|
|
||||||
|
LOG_MODULE_REGISTER(rbtest, LOG_LEVEL_INF);
|
||||||
|
|
||||||
|
#define HEADER 16
|
||||||
|
#define SMALL_LEN 32
|
||||||
|
#define LARGE_LEN 50000
|
||||||
|
#define MAX_COUNT 20
|
||||||
|
/* How long one message may take before it is cancelled. The modem retries
|
||||||
|
* by itself while it waits for a satellite, so these are generous. */
|
||||||
|
#define SMALL_TIMEOUT K_SECONDS(600)
|
||||||
|
#define LARGE_TIMEOUT K_SECONDS(1800)
|
||||||
|
|
||||||
|
struct fill_ctx {
|
||||||
|
char kind;
|
||||||
|
uint8_t seq, count;
|
||||||
|
uint32_t uptime_ms;
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint8_t ramp(size_t k)
|
||||||
|
{
|
||||||
|
size_t v = k % 510;
|
||||||
|
|
||||||
|
return v < 256 ? v : 510 - v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fill(uint8_t *buf, size_t len, void *user)
|
||||||
|
{
|
||||||
|
const struct fill_ctx *c = user;
|
||||||
|
uint8_t h[HEADER] = { 'R', 'B', 'T', 1, c->kind, c->seq, c->count, 0 };
|
||||||
|
|
||||||
|
sys_put_be32(len, &h[8]);
|
||||||
|
sys_put_be32(c->uptime_ms, &h[12]);
|
||||||
|
for (size_t k = 0; k < len; k++) {
|
||||||
|
buf[k] = k < HEADER ? h[k] : ramp(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -1: not a test message. Otherwise the offset of the first byte that is
|
||||||
|
* not as expected, and len when every byte is. */
|
||||||
|
static long check(const uint8_t *d, size_t len)
|
||||||
|
{
|
||||||
|
if (len < HEADER || memcmp(d, "RBT\x01", 4) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (sys_get_be32(&d[8]) != len) {
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
for (size_t k = HEADER; k < len; k++) {
|
||||||
|
if (d[k] != ramp(k)) {
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- the run --------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
bool running;
|
||||||
|
bool stop;
|
||||||
|
char kind;
|
||||||
|
uint16_t topic;
|
||||||
|
uint8_t count;
|
||||||
|
uint32_t gap_s;
|
||||||
|
size_t len;
|
||||||
|
uint8_t done;
|
||||||
|
int32_t result[MAX_COUNT]; /* ms to send, or a negative errno */
|
||||||
|
int mo_result;
|
||||||
|
} run;
|
||||||
|
static K_MUTEX_DEFINE(run_lock);
|
||||||
|
static K_SEM_DEFINE(run_go, 0, 1);
|
||||||
|
static K_SEM_DEFINE(run_mo, 0, 1);
|
||||||
|
static K_SEM_DEFINE(run_stop, 0, 1);
|
||||||
|
static volatile bool mo_waiting;
|
||||||
|
|
||||||
|
void rbtest_mo_done(uint16_t topic, uint16_t id, int result)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(topic); ARG_UNUSED(id);
|
||||||
|
if (mo_waiting) {
|
||||||
|
run.mo_result = result;
|
||||||
|
k_sem_give(&run_mo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t one(uint8_t seq)
|
||||||
|
{
|
||||||
|
struct fill_ctx c = { run.kind, seq, run.count, 0 };
|
||||||
|
k_timeout_t timeout = run.kind == 'L' ? LARGE_TIMEOUT : SMALL_TIMEOUT;
|
||||||
|
int64_t t0 = k_uptime_get();
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
c.uptime_ms = (uint32_t)t0;
|
||||||
|
k_sem_reset(&run_mo);
|
||||||
|
mo_waiting = true;
|
||||||
|
rc = rb9704_send_fill(run.topic, run.len, fill, &c, K_SECONDS(30));
|
||||||
|
if (rc != 0 && rc != -EINPROGRESS) {
|
||||||
|
mo_waiting = false;
|
||||||
|
LOG_WRN("rbtest %c %u/%u: not accepted: %d", run.kind, seq, run.count, rc);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
LOG_INF("rbtest %c %u/%u: %u bytes on topic %u, accepted in %lld ms", run.kind, seq,
|
||||||
|
run.count, (unsigned int)run.len, run.topic, k_uptime_get() - t0);
|
||||||
|
if (k_sem_take(&run_mo, timeout) != 0) {
|
||||||
|
LOG_WRN("rbtest %c %u/%u: no result in %lld s, cancelling", run.kind, seq,
|
||||||
|
run.count, (k_uptime_get() - t0) / 1000);
|
||||||
|
(void)rb9704_cancel(K_SECONDS(5));
|
||||||
|
(void)k_sem_take(&run_mo, K_SECONDS(60));
|
||||||
|
mo_waiting = false;
|
||||||
|
return -ETIMEDOUT;
|
||||||
|
}
|
||||||
|
mo_waiting = false;
|
||||||
|
if (run.mo_result != 0) {
|
||||||
|
LOG_WRN("rbtest %c %u/%u: failed after %lld ms: %d", run.kind, seq, run.count,
|
||||||
|
k_uptime_get() - t0, run.mo_result);
|
||||||
|
return run.mo_result;
|
||||||
|
}
|
||||||
|
return (int32_t)(k_uptime_get() - t0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void runner(void *a, void *b, void *c)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(a); ARG_UNUSED(b); ARG_UNUSED(c);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
uint8_t ok = 0;
|
||||||
|
|
||||||
|
k_sem_take(&run_go, K_FOREVER);
|
||||||
|
for (uint8_t i = 0; i < run.count && !run.stop; i++) {
|
||||||
|
int32_t r = one(i + 1);
|
||||||
|
|
||||||
|
k_mutex_lock(&run_lock, K_FOREVER);
|
||||||
|
run.result[i] = r;
|
||||||
|
run.done = i + 1;
|
||||||
|
k_mutex_unlock(&run_lock);
|
||||||
|
if (r >= 0) {
|
||||||
|
ok++;
|
||||||
|
LOG_INF("rbtest %c %u/%u: sent in %d.%03d s", run.kind, i + 1,
|
||||||
|
run.count, r / 1000, r % 1000);
|
||||||
|
}
|
||||||
|
if (i + 1 < run.count && !run.stop &&
|
||||||
|
k_sem_take(&run_stop, K_SECONDS(run.gap_s)) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG_INF("rbtest %c: %u of %u sent%s", run.kind, ok, run.count,
|
||||||
|
run.done < run.count ? ", stopped" : "");
|
||||||
|
k_mutex_lock(&run_lock, K_FOREVER);
|
||||||
|
run.running = false;
|
||||||
|
k_mutex_unlock(&run_lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
K_THREAD_DEFINE(rbtest_tid, 2048, runner, NULL, NULL, NULL, 10, 0, 0);
|
||||||
|
|
||||||
|
static int start(const struct shell *sh, char kind, uint16_t topic, uint8_t count,
|
||||||
|
uint32_t gap_s, size_t len)
|
||||||
|
{
|
||||||
|
k_mutex_lock(&run_lock, K_FOREVER);
|
||||||
|
if (run.running) {
|
||||||
|
k_mutex_unlock(&run_lock);
|
||||||
|
shell_error(sh, "a run is going: `rbtest status`, `rbtest stop`");
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
|
run.running = true;
|
||||||
|
run.stop = false;
|
||||||
|
run.kind = kind;
|
||||||
|
run.topic = topic;
|
||||||
|
run.count = count;
|
||||||
|
run.gap_s = gap_s;
|
||||||
|
run.len = len;
|
||||||
|
run.done = 0;
|
||||||
|
k_mutex_unlock(&run_lock);
|
||||||
|
k_sem_reset(&run_stop);
|
||||||
|
k_sem_give(&run_go);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int parse_topic(const struct shell *sh, const char *s, uint16_t *topic)
|
||||||
|
{
|
||||||
|
unsigned long t = strtoul(s, NULL, 10);
|
||||||
|
|
||||||
|
if (t < RB9704_TOPIC_MIN || t > UINT16_MAX) {
|
||||||
|
shell_error(sh, "topic %s: from %u, 244 is raw", s, RB9704_TOPIC_MIN);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
*topic = (uint16_t)t;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_small(const struct shell *sh, size_t argc, char **argv)
|
||||||
|
{
|
||||||
|
uint16_t topic;
|
||||||
|
unsigned long count = argc > 2 ? strtoul(argv[2], NULL, 10) : 3;
|
||||||
|
unsigned long gap = argc > 3 ? strtoul(argv[3], NULL, 10) : 60;
|
||||||
|
|
||||||
|
if (parse_topic(sh, argv[1], &topic) != 0) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
if (count < 1 || count > MAX_COUNT) {
|
||||||
|
shell_error(sh, "count 1 to %d", MAX_COUNT);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
shell_print(sh, "%lu messages of %d bytes on topic %u, %lu s apart: this costs airtime",
|
||||||
|
count, SMALL_LEN, topic, gap);
|
||||||
|
return start(sh, 'S', topic, count, gap, SMALL_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_large(const struct shell *sh, size_t argc, char **argv)
|
||||||
|
{
|
||||||
|
uint16_t topic;
|
||||||
|
unsigned long len = LARGE_LEN;
|
||||||
|
bool confirmed = false;
|
||||||
|
|
||||||
|
if (parse_topic(sh, argv[1], &topic) != 0) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
for (size_t i = 2; i < argc; i++) {
|
||||||
|
if (strcmp(argv[i], "confirm") == 0) {
|
||||||
|
confirmed = true;
|
||||||
|
} else {
|
||||||
|
len = strtoul(argv[i], NULL, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (len <= HEADER || len > CONFIG_RB9704_MESSAGE_MAX) {
|
||||||
|
shell_error(sh, "%lu bytes: from %d to %d, CONFIG_RB9704_MESSAGE_MAX in this build",
|
||||||
|
len, HEADER + 1, CONFIG_RB9704_MESSAGE_MAX);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
if (!confirmed) {
|
||||||
|
shell_print(sh, "one message of %lu bytes on topic %u, %lu times the size of a",
|
||||||
|
len, topic, len / SMALL_LEN);
|
||||||
|
shell_print(sh, "small test message. It costs airtime for every byte.");
|
||||||
|
shell_print(sh, "Nothing sent. To send it: rbtest large %u %lu confirm", topic, len);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
shell_print(sh, "%lu bytes on topic %u: this costs airtime", len, topic);
|
||||||
|
return start(sh, 'L', topic, 1, 0, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_status(const struct shell *sh, size_t argc, char **argv)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(argc); ARG_UNUSED(argv);
|
||||||
|
k_mutex_lock(&run_lock, K_FOREVER);
|
||||||
|
if (run.count == 0) {
|
||||||
|
shell_print(sh, "no run since boot");
|
||||||
|
} else {
|
||||||
|
shell_print(sh, "%s %c: %u of %u done, %u bytes each on topic %u",
|
||||||
|
run.running ? "running" : "last run", run.kind, run.done, run.count,
|
||||||
|
(unsigned int)run.len, run.topic);
|
||||||
|
for (int i = 0; i < run.done; i++) {
|
||||||
|
int32_t r = run.result[i];
|
||||||
|
|
||||||
|
if (r >= 0) {
|
||||||
|
shell_print(sh, " %d: sent in %d.%03d s", i + 1, r / 1000,
|
||||||
|
r % 1000);
|
||||||
|
} else {
|
||||||
|
shell_print(sh, " %d: failed, %d", i + 1, r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
k_mutex_unlock(&run_lock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_stop(const struct shell *sh, size_t argc, char **argv)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(argc); ARG_UNUSED(argv);
|
||||||
|
if (!run.running) {
|
||||||
|
shell_print(sh, "nothing running");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
run.stop = true;
|
||||||
|
k_sem_give(&run_stop);
|
||||||
|
shell_print(sh, "stopping after the message in flight; `rb9704 cancel` abandons it");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- the last MT ------------------------------------------------------------ */
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
uint32_t count;
|
||||||
|
int64_t at_ms;
|
||||||
|
uint16_t topic, id;
|
||||||
|
size_t len;
|
||||||
|
uint32_t crc;
|
||||||
|
uint8_t head[32];
|
||||||
|
long check;
|
||||||
|
} mt_last;
|
||||||
|
static K_MUTEX_DEFINE(mt_lock);
|
||||||
|
|
||||||
|
void rbtest_mt(const struct rb9704_mt *mt)
|
||||||
|
{
|
||||||
|
long c = check(mt->data, mt->len);
|
||||||
|
|
||||||
|
k_mutex_lock(&mt_lock, K_FOREVER);
|
||||||
|
mt_last.count++;
|
||||||
|
mt_last.at_ms = k_uptime_get();
|
||||||
|
mt_last.topic = mt->topic;
|
||||||
|
mt_last.id = mt->id;
|
||||||
|
mt_last.len = mt->len;
|
||||||
|
mt_last.crc = crc32_ieee(mt->data, mt->len);
|
||||||
|
memcpy(mt_last.head, mt->data, MIN(mt->len, sizeof(mt_last.head)));
|
||||||
|
mt_last.check = c;
|
||||||
|
k_mutex_unlock(&mt_lock);
|
||||||
|
if (c == (long)mt->len) {
|
||||||
|
LOG_INF("rbtest: MT is a test message, %c %u/%u, all %u bytes as expected",
|
||||||
|
mt->data[4], mt->data[5], mt->data[6], (unsigned int)mt->len);
|
||||||
|
} else if (c >= 0) {
|
||||||
|
LOG_WRN("rbtest: MT is a test message, wrong from byte %ld of %u", c,
|
||||||
|
(unsigned int)mt->len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_mt(const struct shell *sh, size_t argc, char **argv)
|
||||||
|
{
|
||||||
|
char hex[3 * sizeof(mt_last.head) + 1];
|
||||||
|
char text[sizeof(mt_last.head) + 1];
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
ARG_UNUSED(argc); ARG_UNUSED(argv);
|
||||||
|
k_mutex_lock(&mt_lock, K_FOREVER);
|
||||||
|
if (mt_last.count == 0) {
|
||||||
|
k_mutex_unlock(&mt_lock);
|
||||||
|
shell_print(sh, "no MT since boot");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
n = MIN(mt_last.len, sizeof(mt_last.head));
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
snprintk(&hex[3 * i], 4, "%02x ", mt_last.head[i]);
|
||||||
|
text[i] = isprint(mt_last.head[i]) ? mt_last.head[i] : '.';
|
||||||
|
}
|
||||||
|
hex[n > 0 ? 3 * n - 1 : 0] = '\0';
|
||||||
|
text[n] = '\0';
|
||||||
|
shell_print(sh, "mt %u since boot, the last %lld s ago", mt_last.count,
|
||||||
|
(k_uptime_get() - mt_last.at_ms) / 1000);
|
||||||
|
shell_print(sh, " topic %u id %u, %u bytes, crc %08x", mt_last.topic, mt_last.id,
|
||||||
|
(unsigned int)mt_last.len, mt_last.crc);
|
||||||
|
shell_print(sh, " %s", hex);
|
||||||
|
shell_print(sh, " %s", text);
|
||||||
|
if (mt_last.check == (long)mt_last.len) {
|
||||||
|
shell_print(sh, " test message %c %u/%u, all %u bytes as expected",
|
||||||
|
mt_last.head[4], mt_last.head[5], mt_last.head[6],
|
||||||
|
(unsigned int)mt_last.len);
|
||||||
|
} else if (mt_last.check >= 0) {
|
||||||
|
shell_print(sh, " test message, wrong from byte %ld", mt_last.check);
|
||||||
|
}
|
||||||
|
k_mutex_unlock(&mt_lock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHELL_STATIC_SUBCMD_SET_CREATE(rbtest_cmds,
|
||||||
|
SHELL_CMD_ARG(small, NULL, "small <topic> [count=3] [gap_s=60]: costs airtime",
|
||||||
|
cmd_small, 2, 2),
|
||||||
|
SHELL_CMD_ARG(large, NULL, "large <topic> [bytes=50000] [confirm]: costs airtime",
|
||||||
|
cmd_large, 2, 2),
|
||||||
|
SHELL_CMD(status, NULL, "the run, and how long each message took", cmd_status),
|
||||||
|
SHELL_CMD(stop, NULL, "no more messages after the one in flight", cmd_stop),
|
||||||
|
SHELL_CMD(mt, NULL, "the last message from the network", cmd_mt),
|
||||||
|
SHELL_SUBCMD_SET_END);
|
||||||
|
|
||||||
|
SHELL_CMD_REGISTER(rbtest, &rbtest_cmds, "airtime tests with a checkable payload", NULL);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
*
|
||||||
|
* rbtest.h - the airtime tests, fed from the sample's callbacks.
|
||||||
|
*/
|
||||||
|
#ifndef RBTEST_H_
|
||||||
|
#define RBTEST_H_
|
||||||
|
|
||||||
|
#include <rb9704/rb9704.h>
|
||||||
|
|
||||||
|
void rbtest_mo_done(uint16_t topic, uint16_t id, int result);
|
||||||
|
void rbtest_mt(const struct rb9704_mt *mt);
|
||||||
|
|
||||||
|
#endif /* RBTEST_H_ */
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
*
|
||||||
|
* wifi.c - join the stored network at boot, and keep trying, so a board out
|
||||||
|
* in the open is reachable by telnet with nobody at its USB port. Built with
|
||||||
|
* overlay-wifi.conf only.
|
||||||
|
*
|
||||||
|
* The credentials are the ones `wifi cred add` kept in flash. The ESP32
|
||||||
|
* driver reconnects by itself after a drop (CONFIG_ESP32_WIFI_STA_RECONNECT);
|
||||||
|
* the retry here covers a network that was not there at boot.
|
||||||
|
*/
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
#include <zephyr/net/net_if.h>
|
||||||
|
#include <zephyr/net/net_mgmt.h>
|
||||||
|
#include <zephyr/net/wifi_mgmt.h>
|
||||||
|
#include <zephyr/net/wifi_credentials.h>
|
||||||
|
|
||||||
|
#include "wifi.h"
|
||||||
|
|
||||||
|
LOG_MODULE_REGISTER(sample_wifi, LOG_LEVEL_INF);
|
||||||
|
|
||||||
|
#define RETRY K_SECONDS(30)
|
||||||
|
|
||||||
|
static struct net_mgmt_event_callback wifi_cb;
|
||||||
|
static struct net_mgmt_event_callback ip_cb;
|
||||||
|
static struct k_work_delayable retry;
|
||||||
|
static bool connected;
|
||||||
|
|
||||||
|
static void try_connect(struct k_work *work)
|
||||||
|
{
|
||||||
|
static bool warned;
|
||||||
|
struct net_if *iface = net_if_get_wifi_sta();
|
||||||
|
|
||||||
|
ARG_UNUSED(work);
|
||||||
|
if (connected || iface == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (wifi_credentials_is_empty()) {
|
||||||
|
/* Checked again in 30 s, so a network added now is joined
|
||||||
|
* without a reboot. */
|
||||||
|
if (!warned) {
|
||||||
|
LOG_WRN("no network stored: wifi cred add -s \"<SSID>\" -k 1 -p \"<password>\"");
|
||||||
|
warned = true;
|
||||||
|
}
|
||||||
|
k_work_reschedule(&retry, RETRY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (net_mgmt(NET_REQUEST_WIFI_CONNECT_STORED, iface, NULL, 0) != 0) {
|
||||||
|
k_work_reschedule(&retry, RETRY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_wifi(struct net_mgmt_event_callback *cb, uint64_t event, struct net_if *iface)
|
||||||
|
{
|
||||||
|
const struct wifi_status *status = cb->info;
|
||||||
|
|
||||||
|
ARG_UNUSED(iface);
|
||||||
|
if (event == NET_EVENT_WIFI_CONNECT_RESULT) {
|
||||||
|
connected = status->status == 0;
|
||||||
|
if (connected) {
|
||||||
|
LOG_INF("wifi connected, waiting for an address");
|
||||||
|
} else {
|
||||||
|
LOG_WRN("wifi connect failed (%d), again in 30 s", status->status);
|
||||||
|
k_work_reschedule(&retry, RETRY);
|
||||||
|
}
|
||||||
|
} else if (event == NET_EVENT_WIFI_DISCONNECT_RESULT) {
|
||||||
|
connected = false;
|
||||||
|
LOG_WRN("wifi disconnected");
|
||||||
|
k_work_reschedule(&retry, RETRY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_ip(struct net_mgmt_event_callback *cb, uint64_t event, struct net_if *iface)
|
||||||
|
{
|
||||||
|
char addr[NET_IPV4_ADDR_LEN];
|
||||||
|
|
||||||
|
ARG_UNUSED(cb);
|
||||||
|
ARG_UNUSED(event);
|
||||||
|
ARRAY_FOR_EACH(iface->config.ip.ipv4->unicast, i) {
|
||||||
|
const struct net_if_addr *a = &iface->config.ip.ipv4->unicast[i].ipv4;
|
||||||
|
|
||||||
|
if (a->is_used && a->addr_type == NET_ADDR_DHCP) {
|
||||||
|
net_addr_ntop(AF_INET, &a->address.in_addr, addr, sizeof(addr));
|
||||||
|
LOG_INF("address %s: telnet %s", addr, addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sample_wifi_connected(void)
|
||||||
|
{
|
||||||
|
return connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sample_wifi_start(void)
|
||||||
|
{
|
||||||
|
k_work_init_delayable(&retry, try_connect);
|
||||||
|
net_mgmt_init_event_callback(&wifi_cb, on_wifi,
|
||||||
|
NET_EVENT_WIFI_CONNECT_RESULT |
|
||||||
|
NET_EVENT_WIFI_DISCONNECT_RESULT);
|
||||||
|
net_mgmt_add_event_callback(&wifi_cb);
|
||||||
|
net_mgmt_init_event_callback(&ip_cb, on_ip, NET_EVENT_IPV4_ADDR_ADD);
|
||||||
|
net_mgmt_add_event_callback(&ip_cb);
|
||||||
|
/* A moment for the driver to bring the interface up. */
|
||||||
|
k_work_reschedule(&retry, K_SECONDS(1));
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
*/
|
||||||
|
#ifndef SAMPLE_WIFI_H
|
||||||
|
#define SAMPLE_WIFI_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/* Join the network `wifi cred add` stored, and rejoin it after a drop. */
|
||||||
|
void sample_wifi_start(void);
|
||||||
|
bool sample_wifi_connected(void);
|
||||||
|
|
||||||
|
#endif /* SAMPLE_WIFI_H */
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
#define RB9704_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(rock7_rockblock_9704)
|
#define RB9704_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(rock7_rockblock_9704)
|
||||||
|
|
||||||
/* rb9704_serial.c */
|
/* rb9704_serial.c */
|
||||||
|
/* The receive interrupt, on from boot (rb9704_serial.c says why). */
|
||||||
|
int rb9704_serial_start(void);
|
||||||
int rb9704_serial_available(void);
|
int rb9704_serial_available(void);
|
||||||
uint32_t rb9704_serial_dropped(void);
|
uint32_t rb9704_serial_dropped(void);
|
||||||
void rb9704_serial_spy(bool on);
|
void rb9704_serial_spy(bool on);
|
||||||
|
|||||||
+82
-42
@@ -1,14 +1,31 @@
|
|||||||
/* SPDX-License-Identifier: MIT
|
/* SPDX-License-Identifier: MIT
|
||||||
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
*
|
*
|
||||||
* rb9704_power.c - the board's control pins, as the devicetree gives them.
|
* rb9704_power.c - the board's control pins, as the devicetree gives them,
|
||||||
|
* in the sequence Ground Control's hardware page sets out
|
||||||
|
* (docs.groundcontrol.com/iot/rockblock-9704/hardware):
|
||||||
*
|
*
|
||||||
* power-gpios P_EN, the supply
|
* iridium-enable-gpios I_EN, pin 3: starts and stops the modem
|
||||||
* iridium-enable-gpios I_EN, the modem, once the supply is up
|
* booted-gpios I_BTD, pin 7: high once booted, low once shut down
|
||||||
* booted-gpios I_BTD, the modem saying it has booted
|
* power-gpios P_EN, pin 6: the supercapacitor charge enable,
|
||||||
|
* active low on the board, so GPIO_ACTIVE_LOW
|
||||||
*
|
*
|
||||||
* Up: supply, a moment, enable, then the booted pin or boot-delay-ms.
|
* Up: charging on, I_EN high, then I_BTD high (or boot-delay-ms).
|
||||||
* Down: enable, then supply. Called on the worker thread only.
|
* Down: I_EN low, then I_BTD low (or boot-delay-ms), then P_EN released.
|
||||||
|
*
|
||||||
|
* Once I_EN has moved, it must not move back until I_BTD has followed; the
|
||||||
|
* page warns that doing so "may result in damage to the 9704 module". Both
|
||||||
|
* directions wait for I_BTD here, and a request to go the other way waits
|
||||||
|
* its turn on the worker thread. While I_BTD is low no input other than
|
||||||
|
* I_EN should be driven, so P_EN is an input while the modem is off; the
|
||||||
|
* board's pull-down on P_EN keeps the charger on then.
|
||||||
|
*
|
||||||
|
* P_EN was GPIO_ACTIVE_HIGH in this module's overlays until 2026-10-25,
|
||||||
|
* which switched the charger off at every begin: the modem ran on its
|
||||||
|
* supercapacitor and went silent 2 to 5 minutes later.
|
||||||
|
*
|
||||||
|
* I_EN is what switches the modem, so it alone makes the pins present;
|
||||||
|
* P_EN and I_BTD are each optional. Called on the worker thread only.
|
||||||
*/
|
*/
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/drivers/gpio.h>
|
#include <zephyr/drivers/gpio.h>
|
||||||
@@ -20,7 +37,7 @@
|
|||||||
|
|
||||||
LOG_MODULE_DECLARE(rb9704, CONFIG_RB9704_LOG_LEVEL);
|
LOG_MODULE_DECLARE(rb9704, CONFIG_RB9704_LOG_LEVEL);
|
||||||
|
|
||||||
#define BOOT_TIMEOUT_MS 30000
|
#define BTD_TIMEOUT_MS 30000
|
||||||
|
|
||||||
static const struct gpio_dt_spec pwr = GPIO_DT_SPEC_GET_OR(RB9704_NODE, power_gpios, {0});
|
static const struct gpio_dt_spec pwr = GPIO_DT_SPEC_GET_OR(RB9704_NODE, power_gpios, {0});
|
||||||
static const struct gpio_dt_spec en = GPIO_DT_SPEC_GET_OR(RB9704_NODE, iridium_enable_gpios, {0});
|
static const struct gpio_dt_spec en = GPIO_DT_SPEC_GET_OR(RB9704_NODE, iridium_enable_gpios, {0});
|
||||||
@@ -30,7 +47,7 @@ static bool on;
|
|||||||
|
|
||||||
bool rb9704_power_present(void)
|
bool rb9704_power_present(void)
|
||||||
{
|
{
|
||||||
return pwr.port != NULL;
|
return en.port != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rb9704_power_on(void)
|
bool rb9704_power_on(void)
|
||||||
@@ -38,62 +55,85 @@ bool rb9704_power_on(void)
|
|||||||
return on;
|
return on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* P_EN released: an input, so nothing drives the modem's pin. */
|
||||||
|
static void charge_release(void)
|
||||||
|
{
|
||||||
|
if (pwr.port != NULL) {
|
||||||
|
(void)gpio_pin_configure_dt(&pwr, GPIO_INPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for I_BTD to read `level`; without I_BTD, wait boot-delay-ms. */
|
||||||
|
static int wait_booted(int level)
|
||||||
|
{
|
||||||
|
if (btd.port == NULL) {
|
||||||
|
k_msleep(DT_PROP(RB9704_NODE, boot_delay_ms));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int64_t until = k_uptime_get() + BTD_TIMEOUT_MS;
|
||||||
|
|
||||||
|
while (gpio_pin_get_dt(&btd) != level) {
|
||||||
|
if (k_uptime_get() > until) {
|
||||||
|
return -ETIMEDOUT;
|
||||||
|
}
|
||||||
|
k_msleep(50);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int rb9704_power_init(void)
|
int rb9704_power_init(void)
|
||||||
{
|
{
|
||||||
if (pwr.port == NULL) {
|
if (en.port == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
if (!gpio_is_ready_dt(&pwr) || gpio_pin_configure_dt(&pwr, GPIO_OUTPUT_INACTIVE) != 0) {
|
/* Off at boot: I_EN low. The modem may have been running from before
|
||||||
return -EIO;
|
* a reset, so wait for it to finish shutting down. */
|
||||||
}
|
if (!gpio_is_ready_dt(&en) || gpio_pin_configure_dt(&en, GPIO_OUTPUT_INACTIVE) != 0) {
|
||||||
if (en.port != NULL &&
|
|
||||||
(!gpio_is_ready_dt(&en) || gpio_pin_configure_dt(&en, GPIO_OUTPUT_INACTIVE) != 0)) {
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
if (btd.port != NULL && (!gpio_is_ready_dt(&btd) || gpio_pin_configure_dt(&btd, GPIO_INPUT) != 0)) {
|
if (btd.port != NULL && (!gpio_is_ready_dt(&btd) || gpio_pin_configure_dt(&btd, GPIO_INPUT) != 0)) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
if (pwr.port != NULL && !gpio_is_ready_dt(&pwr)) {
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
if (wait_booted(0) != 0) {
|
||||||
|
LOG_WRN("modem still signals booted after I_EN went low");
|
||||||
|
}
|
||||||
|
charge_release();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rb9704_power_set(bool want)
|
int rb9704_power_set(bool want)
|
||||||
{
|
{
|
||||||
if (pwr.port == NULL) {
|
if (en.port == NULL) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
if (want == on) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (!want) {
|
if (!want) {
|
||||||
if (en.port != NULL) {
|
|
||||||
(void)gpio_pin_set_dt(&en, 0);
|
(void)gpio_pin_set_dt(&en, 0);
|
||||||
}
|
|
||||||
(void)gpio_pin_set_dt(&pwr, 0);
|
|
||||||
on = false;
|
on = false;
|
||||||
return 0;
|
if (wait_booted(0) != 0) {
|
||||||
}
|
LOG_ERR("modem did not signal shut down in %d ms", BTD_TIMEOUT_MS);
|
||||||
if (on) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
(void)gpio_pin_set_dt(&pwr, 1);
|
|
||||||
k_msleep(10);
|
|
||||||
if (en.port != NULL) {
|
|
||||||
(void)gpio_pin_set_dt(&en, 1);
|
|
||||||
}
|
|
||||||
if (btd.port != NULL) {
|
|
||||||
int64_t until = k_uptime_get() + BOOT_TIMEOUT_MS;
|
|
||||||
|
|
||||||
while (gpio_pin_get_dt(&btd) != 1) {
|
|
||||||
if (k_uptime_get() > until) {
|
|
||||||
LOG_ERR("modem did not signal booted in %d ms", BOOT_TIMEOUT_MS);
|
|
||||||
/* Back down, so the next attempt starts from off. */
|
|
||||||
if (en.port != NULL) {
|
|
||||||
(void)gpio_pin_set_dt(&en, 0);
|
|
||||||
}
|
|
||||||
(void)gpio_pin_set_dt(&pwr, 0);
|
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
k_msleep(50);
|
charge_release();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
if (pwr.port != NULL) {
|
||||||
k_msleep(DT_PROP(RB9704_NODE, boot_delay_ms));
|
(void)gpio_pin_configure_dt(&pwr, GPIO_OUTPUT_ACTIVE); /* charging on */
|
||||||
|
}
|
||||||
|
(void)gpio_pin_set_dt(&en, 1);
|
||||||
|
if (wait_booted(1) != 0) {
|
||||||
|
LOG_ERR("modem did not signal booted in %d ms", BTD_TIMEOUT_MS);
|
||||||
|
/* I_EN has to come down again for the next attempt to start
|
||||||
|
* from off, though I_BTD never followed it up. */
|
||||||
|
(void)gpio_pin_set_dt(&en, 0);
|
||||||
|
(void)wait_booted(0);
|
||||||
|
charge_release();
|
||||||
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
on = true;
|
on = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+69
-7
@@ -12,6 +12,17 @@
|
|||||||
* bytes one at a time from receiveJspr(). TX is polled: a worst-case 2 kB
|
* bytes one at a time from receiveJspr(). TX is polled: a worst-case 2 kB
|
||||||
* command is about 90 ms at 230400, and only the worker thread ever writes.
|
* command is about 90 ms at 230400, and only the worker thread ever writes.
|
||||||
*
|
*
|
||||||
|
* The receive interrupt is on from boot, not only while the library is
|
||||||
|
* open. A modem powered up by `rb9704 power on`, or left talking after
|
||||||
|
* rbEnd(), sends lines nobody is reading; with the interrupt off they
|
||||||
|
* overflowed the UART's hardware FIFO, 128 bytes on the ESP32-C3, and the
|
||||||
|
* UART then gave back repeated fragments of old lines and never the
|
||||||
|
* replies (2026-10-25, M5Stamp-C3). Now the ISR always empties the FIFO
|
||||||
|
* and throws the bytes away while the library is closed. When it opens
|
||||||
|
* part-way through a line, the rest of that line is thrown away too: a
|
||||||
|
* line with no status code at its front makes the library read past its
|
||||||
|
* buffer (docs/JSPR.md, section 8, item 2), and that crashed the board.
|
||||||
|
*
|
||||||
* The spy (rb9704_spy): JSPR is printable JSON lines, so the spy reassembles
|
* The spy (rb9704_spy): JSPR is printable JSON lines, so the spy reassembles
|
||||||
* the lines in each direction and printk()s them. Do not use the library's
|
* the lines in each direction and printk()s them. Do not use the library's
|
||||||
* own -DDEBUG for this: its TX debug path truncates the caller's buffer in
|
* own -DDEBUG for this: its TX debug path truncates the caller's buffer in
|
||||||
@@ -24,6 +35,8 @@
|
|||||||
#include <zephyr/sys/atomic.h>
|
#include <zephyr/sys/atomic.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "rb9704_glue.h"
|
#include "rb9704_glue.h"
|
||||||
#include "rb9704_internal.h"
|
#include "rb9704_internal.h"
|
||||||
#include "serial.h" /* the library's serialContext */
|
#include "serial.h" /* the library's serialContext */
|
||||||
@@ -38,6 +51,15 @@ static K_SEM_DEFINE(rb9704_rx_sem, 0, 1);
|
|||||||
static atomic_t rx_dropped;
|
static atomic_t rx_dropped;
|
||||||
static atomic_t spy_on;
|
static atomic_t spy_on;
|
||||||
|
|
||||||
|
/* Whether the library is open, so received bytes are for it. */
|
||||||
|
static atomic_t listening;
|
||||||
|
/* ISR only: the last byte heard ended a line, or there was none yet.
|
||||||
|
* Non-printable bytes do not count: the modem sends a few at boot, and the
|
||||||
|
* library already skips junk in front of a status code. */
|
||||||
|
static bool mid_line;
|
||||||
|
/* Set as the library opens mid-line: drop bytes up to the next CR. */
|
||||||
|
static atomic_t skip_to_cr;
|
||||||
|
|
||||||
/* Per-byte RX timeout. receiveJspr() treats a 0-return mid-line as
|
/* Per-byte RX timeout. receiveJspr() treats a 0-return mid-line as
|
||||||
* end-of-data and discards the partial line, so this must comfortably
|
* end-of-data and discards the partial line, so this must comfortably
|
||||||
* exceed any inter-byte gap the modem produces (gaps at 230400 are
|
* exceed any inter-byte gap the modem produces (gaps at 230400 are
|
||||||
@@ -96,17 +118,44 @@ static void modem_uart_isr(const struct device *dev, void *user_data)
|
|||||||
{
|
{
|
||||||
ARG_UNUSED(user_data);
|
ARG_UNUSED(user_data);
|
||||||
|
|
||||||
while (uart_irq_update(dev) && uart_irq_rx_ready(dev)) {
|
/* uart_irq_update() is void since Zephyr 4.5; the STM32, ESP32
|
||||||
|
* and native drivers returned 1 from it before that. */
|
||||||
|
while (true) {
|
||||||
|
uart_irq_update(dev);
|
||||||
|
if (uart_irq_rx_ready(dev) <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t tmp[64];
|
uint8_t tmp[64];
|
||||||
int n = uart_fifo_read(dev, tmp, sizeof(tmp));
|
int n = uart_fifo_read(dev, tmp, sizeof(tmp));
|
||||||
|
int keep = 0;
|
||||||
|
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint32_t put = ring_buf_put(&rb9704_rx_ring, tmp, n);
|
for (int i = 0; i < n; i++) {
|
||||||
|
uint8_t c = tmp[i];
|
||||||
|
bool skip = !atomic_get(&listening) || atomic_get(&skip_to_cr);
|
||||||
|
|
||||||
if (put < (uint32_t)n) {
|
if (c == '\r') {
|
||||||
atomic_add(&rx_dropped, n - put);
|
mid_line = false;
|
||||||
|
if (atomic_get(&skip_to_cr)) {
|
||||||
|
atomic_clear(&skip_to_cr);
|
||||||
|
}
|
||||||
|
} else if (c >= 0x20 && c < 0x7f) {
|
||||||
|
mid_line = true;
|
||||||
|
}
|
||||||
|
if (!skip) {
|
||||||
|
tmp[keep++] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keep == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
uint32_t put = ring_buf_put(&rb9704_rx_ring, tmp, keep);
|
||||||
|
|
||||||
|
if (put < (uint32_t)keep) {
|
||||||
|
atomic_add(&rx_dropped, keep - put);
|
||||||
}
|
}
|
||||||
k_sem_give(&rb9704_rx_sem);
|
k_sem_give(&rb9704_rx_sem);
|
||||||
rb9704_worker_rx();
|
rb9704_worker_rx();
|
||||||
@@ -121,16 +170,19 @@ static bool ser_init(void)
|
|||||||
printk("rb9704: UART %s not ready\n", modem_uart->name);
|
printk("rb9704: UART %s not ready\n", modem_uart->name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/* The ISR does not touch the ring while not listening, so the reset
|
||||||
|
* needs no lock. */
|
||||||
ring_buf_reset(&rb9704_rx_ring);
|
ring_buf_reset(&rb9704_rx_ring);
|
||||||
k_sem_reset(&rb9704_rx_sem);
|
k_sem_reset(&rb9704_rx_sem);
|
||||||
uart_irq_callback_user_data_set(modem_uart, modem_uart_isr, NULL);
|
atomic_set(&skip_to_cr, mid_line ? 1 : 0);
|
||||||
uart_irq_rx_enable(modem_uart);
|
atomic_set(&listening, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ser_deinit(void)
|
static bool ser_deinit(void)
|
||||||
{
|
{
|
||||||
uart_irq_rx_disable(modem_uart);
|
/* The interrupt stays on, emptying the FIFO into nothing. */
|
||||||
|
atomic_clear(&listening);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +227,16 @@ static int ser_peek(void)
|
|||||||
|
|
||||||
/* --- setup + worker-facing helpers -------------------------------------- */
|
/* --- setup + worker-facing helpers -------------------------------------- */
|
||||||
|
|
||||||
|
int rb9704_serial_start(void)
|
||||||
|
{
|
||||||
|
if (!device_is_ready(modem_uart)) {
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
uart_irq_callback_user_data_set(modem_uart, modem_uart_isr, NULL);
|
||||||
|
uart_irq_rx_enable(modem_uart);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool rb9704_serial_set_context(const char *port, uint32_t baud)
|
bool rb9704_serial_set_context(const char *port, uint32_t baud)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(port); /* the UART is the devicetree node's bus */
|
ARG_UNUSED(port); /* the UART is the devicetree node's bus */
|
||||||
|
|||||||
+1
-1
@@ -197,7 +197,7 @@ static int cmd_spy(const struct shell *sh, size_t argc, char **argv)
|
|||||||
SHELL_STATIC_SUBCMD_SET_CREATE(rb9704_cmds,
|
SHELL_STATIC_SUBCMD_SET_CREATE(rb9704_cmds,
|
||||||
SHELL_CMD(begin, NULL, "open the port and bring the library up", cmd_begin),
|
SHELL_CMD(begin, NULL, "open the port and bring the library up", cmd_begin),
|
||||||
SHELL_CMD(end, NULL, "close it down", cmd_end),
|
SHELL_CMD(end, NULL, "close it down", cmd_end),
|
||||||
SHELL_CMD_ARG(power, NULL, "power on|off: the board's supply, if wired", cmd_power, 2, 0),
|
SHELL_CMD_ARG(power, NULL, "power on|off: the modem, through I_EN, if wired", cmd_power, 2, 0),
|
||||||
SHELL_CMD(status, NULL, "what is known, without asking the modem", cmd_status),
|
SHELL_CMD(status, NULL, "what is known, without asking the modem", cmd_status),
|
||||||
SHELL_CMD(info, NULL, "IMEI, serial, versions, ICCID, SIM, temperature", cmd_info),
|
SHELL_CMD(info, NULL, "IMEI, serial, versions, ICCID, SIM, temperature", cmd_info),
|
||||||
SHELL_CMD(signal, NULL, "signal bars now", cmd_signal),
|
SHELL_CMD(signal, NULL, "signal bars now", cmd_signal),
|
||||||
|
|||||||
+20
-3
@@ -530,12 +530,26 @@ int rb9704_info(struct rb9704_info *out, k_timeout_t timeout)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fill_copy(uint8_t *buf, size_t len, void *user)
|
||||||
|
{
|
||||||
|
memcpy(buf, user, len);
|
||||||
|
}
|
||||||
|
|
||||||
int rb9704_send(uint16_t topic, const void *data, size_t len, k_timeout_t timeout)
|
int rb9704_send(uint16_t topic, const void *data, size_t len, k_timeout_t timeout)
|
||||||
|
{
|
||||||
|
if (data == NULL) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return rb9704_send_fill(topic, len, fill_copy, (void *)data, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rb9704_send_fill(uint16_t topic, size_t len, rb9704_fill_t fill, void *user,
|
||||||
|
k_timeout_t timeout)
|
||||||
{
|
{
|
||||||
bool abandoned;
|
bool abandoned;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (topic < RB9704_TOPIC_MIN || data == NULL || len == 0 || len > sizeof(mo_buf)) {
|
if (topic < RB9704_TOPIC_MIN || fill == NULL || len == 0 || len > sizeof(mo_buf)) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
rc = take_slot(timeout);
|
rc = take_slot(timeout);
|
||||||
@@ -545,7 +559,7 @@ int rb9704_send(uint16_t topic, const void *data, size_t len, k_timeout_t timeou
|
|||||||
req.op = OP_SEND;
|
req.op = OP_SEND;
|
||||||
req.topic = topic;
|
req.topic = topic;
|
||||||
req.len = len;
|
req.len = len;
|
||||||
memcpy(mo_buf, data, len);
|
fill(mo_buf, len, user);
|
||||||
rc = submit(timeout, &abandoned);
|
rc = submit(timeout, &abandoned);
|
||||||
if (abandoned) {
|
if (abandoned) {
|
||||||
return -EINPROGRESS;
|
return -EINPROGRESS;
|
||||||
@@ -603,12 +617,15 @@ static void worker(void *a, void *b, void *c)
|
|||||||
ARG_UNUSED(a); ARG_UNUSED(b); ARG_UNUSED(c);
|
ARG_UNUSED(a); ARG_UNUSED(b); ARG_UNUSED(c);
|
||||||
|
|
||||||
k_mutex_lock(&rb9704_st_lock, K_FOREVER);
|
k_mutex_lock(&rb9704_st_lock, K_FOREVER);
|
||||||
/* No pins: the board is powered whenever this runs. */
|
/* No I_EN: the board is powered whenever this runs. */
|
||||||
st.powered = !rb9704_power_present();
|
st.powered = !rb9704_power_present();
|
||||||
if (rb9704_power_present() && rb9704_power_init() != 0) {
|
if (rb9704_power_present() && rb9704_power_init() != 0) {
|
||||||
LOG_ERR("power pins not ready");
|
LOG_ERR("power pins not ready");
|
||||||
}
|
}
|
||||||
k_mutex_unlock(&rb9704_st_lock);
|
k_mutex_unlock(&rb9704_st_lock);
|
||||||
|
if (rb9704_serial_start() != 0) {
|
||||||
|
LOG_ERR("modem UART not ready");
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint32_t ev = k_event_wait(&rb9704_ev, EV_REQ | EV_RX, false, K_FOREVER);
|
uint32_t ev = k_event_wait(&rb9704_ev, EV_REQ | EV_RX, false, K_FOREVER);
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||||
|
|
||||||
|
source "Kconfig.zephyr"
|
||||||
|
|
||||||
|
# Before Zephyr 4.5 the ring buffer is built only with CONFIG_RING_BUFFER;
|
||||||
|
# from 4.5 it is header-only and that option is the deprecated legacy one.
|
||||||
|
# The module's Kconfig is not used here: the bridge has no modem node.
|
||||||
|
config BRIDGE_KERNEL_VERSION
|
||||||
|
hex
|
||||||
|
default "$(KERNELVERSION)"
|
||||||
|
|
||||||
|
config BRIDGE_RING_BUFFER
|
||||||
|
def_bool y
|
||||||
|
select RING_BUFFER if BRIDGE_KERNEL_VERSION < 0x4050000
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
CONFIG_SERIAL=y
|
CONFIG_SERIAL=y
|
||||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||||
CONFIG_RING_BUFFER=y
|
|
||||||
# Both UARTs carry the bridged bytes; nothing else may print on them.
|
# Both UARTs carry the bridged bytes; nothing else may print on them.
|
||||||
CONFIG_CONSOLE=n
|
CONFIG_CONSOLE=n
|
||||||
CONFIG_UART_CONSOLE=n
|
CONFIG_UART_CONSOLE=n
|
||||||
|
|||||||
@@ -24,7 +24,14 @@ static void isr(const struct device *dev, void *user)
|
|||||||
struct ring_buf *back = out == &to_target ? &to_host : &to_target;
|
struct ring_buf *back = out == &to_target ? &to_host : &to_target;
|
||||||
uint8_t b[64];
|
uint8_t b[64];
|
||||||
|
|
||||||
while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
|
/* uart_irq_update() is void since Zephyr 4.5; the STM32, ESP32
|
||||||
|
* and native drivers returned 1 from it before that. */
|
||||||
|
while (true) {
|
||||||
|
uart_irq_update(dev);
|
||||||
|
if (uart_irq_is_pending(dev) <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (uart_irq_rx_ready(dev)) {
|
if (uart_irq_rx_ready(dev)) {
|
||||||
int n = uart_fifo_read(dev, b, sizeof(b));
|
int n = uart_fifo_read(dev, b, sizeof(b));
|
||||||
|
|
||||||
@@ -34,8 +41,11 @@ static void isr(const struct device *dev, void *user)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uart_irq_tx_ready(dev)) {
|
if (uart_irq_tx_ready(dev)) {
|
||||||
uint8_t *p;
|
/* Peek, fill, then take what the FIFO took: the claim
|
||||||
uint32_t n = ring_buf_get_claim(back, &p, 64);
|
* API this used is legacy from Zephyr 4.5, and peek and
|
||||||
|
* get are in both. */
|
||||||
|
uint8_t t[64];
|
||||||
|
uint32_t n = ring_buf_peek(back, t, sizeof(t));
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
/* The other port's ISR may have put bytes in `back`
|
/* The other port's ISR may have put bytes in `back`
|
||||||
@@ -44,9 +54,11 @@ static void isr(const struct device *dev, void *user)
|
|||||||
* soon. Not worth a lock here. */
|
* soon. Not worth a lock here. */
|
||||||
uart_irq_tx_disable(dev);
|
uart_irq_tx_disable(dev);
|
||||||
} else {
|
} else {
|
||||||
int w = uart_fifo_fill(dev, p, n);
|
int w = uart_fifo_fill(dev, t, n);
|
||||||
|
|
||||||
ring_buf_get_finish(back, w > 0 ? w : 0);
|
if (w > 0) {
|
||||||
|
ring_buf_get(back, t, (uint32_t)w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ manifest:
|
|||||||
revision: ab37e8ac7711e1ba8061835a0685c25b6069e767
|
revision: ab37e8ac7711e1ba8061835a0685c25b6069e767
|
||||||
path: modules/lib/rockblock9704
|
path: modules/lib/rockblock9704
|
||||||
|
|
||||||
# Zephyr v4.4.0, for working on this module alone. Tested with it.
|
# Zephyr v4.5.0, for working on this module alone. The module is
|
||||||
|
# tested with v4.4.0 (684c9e8f32e4373a21098559f748f06915f950c9) too.
|
||||||
- name: zephyr
|
- name: zephyr
|
||||||
remote: zephyrproject
|
remote: zephyrproject
|
||||||
revision: 684c9e8f32e4373a21098559f748f06915f950c9
|
revision: 41d10b59730406bbab4ca9f1fbbe9e96aafb4966
|
||||||
import:
|
import:
|
||||||
name-allowlist:
|
name-allowlist:
|
||||||
- cmsis_6
|
- cmsis_6
|
||||||
|
|||||||
Reference in new issue
Block a user