lr-shuttle 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of lr-shuttle might be problematic. Click here for more details.

@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.4
2
+ Name: lr-shuttle
3
+ Version: 0.1.0
4
+ Summary: CLI and Python client for host-side of json based serial communication with embedded device bridge.
5
+ Author-email: Jonas Estberger <jonas.estberger@lumenradio.com>
6
+ License: MIT
7
+ Keywords: CLI
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.11
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: rich>=13.7
14
+ Requires-Dist: pydantic>=2.8
15
+ Requires-Dist: typer>=0.12
16
+ Requires-Dist: pyserial>=3.5
17
+ Provides-Extra: dev
18
+ Requires-Dist: build>=1.2.1; extra == "dev"
19
+ Requires-Dist: twine>=5.1.1; extra == "dev"
20
+ Requires-Dist: wheel; extra == "dev"
21
+ Requires-Dist: pytest>=8.4.2; extra == "dev"
22
+ Requires-Dist: black>=25.9.0; extra == "dev"
23
+ Requires-Dist: pytest-html; extra == "dev"
24
+ Requires-Dist: pytest-cov; extra == "dev"
25
+
26
+ # Shuttle
27
+
28
+ `shuttle` is a Typer-based command-line interface & python library for interacting with the SPI-to-USB devboard over its NDJSON serial protocol. The tool is packaged as `lr-shuttle` for PyPI distribution and exposes high-level helpers for common workflows such as probing firmware info, querying protocol metadata, and issuing TiMo SPI sequences.
29
+
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ python3 -m pip install lr-shuttle
35
+ ```
36
+
37
+ The package supports Python 3.11 and later. When working from this repository you can install it in editable mode:
38
+
39
+ ```bash
40
+ make -C host dev
41
+ ```
42
+
43
+ ## Connecting to the Devboard
44
+
45
+ - The CLI talks to the board over a serial device supplied via `--port` or the `SHUTTLE_PORT` environment variable (e.g., `/dev/ttyUSB0`).
46
+ - Default baud rate is `921600` with a `2s` read timeout. Both can be overridden using `--baud` and `--timeout`.
47
+ - Use `--log SERIAL.log` to capture raw RX/TX NDJSON lines with UTC timestamps for later inspection.
48
+
49
+ ## Core Commands
50
+
51
+ | Command | Description |
52
+ | --- | --- |
53
+ | `shuttle ping` | Sends a `ping` command to fetch firmware/protocol metadata. |
54
+ | `shuttle get-info` | Calls `get.info` and pretty-prints the returned capability snapshot. |
55
+ | `shuttle spi-cfg [options]` | Queries or updates the devboard SPI defaults (wraps the `spi.cfg` protocol command). |
56
+ | `shuttle uart-cfg [options]` | Queries or updates the devboard UART defaults (wraps the `uart.cfg` protocol command). |
57
+ | `shuttle uart-tx [payload]` | Transmits bytes over the devboard UART (wraps the `uart.tx` protocol command). |
58
+
59
+
60
+ ### SPI Configuration Workflow
61
+
62
+ - Run `shuttle spi-cfg --port /dev/ttyUSB0` with no extra flags to fetch the current board-level SPI defaults (the response mirrors the firmware’s `spi` object).
63
+ - Provide overrides such as `--hz 1500000 --clock-phase trailing` to persist new defaults in the device’s NVS store. String arguments are case-insensitive; the CLI normalizes them to the lowercase values expected by the firmware.
64
+ - If you need to push a raw JSON document (e.g., the sample in [`src/spi.cfg`](../src/spi.cfg)), pipe it through a future send-file helper or `screen`/`cat` directly; `spi-cfg` itself focuses on structured flag input.
65
+
66
+
67
+ ### UART Configuration Workflow
68
+
69
+ - Use `shuttle uart-cfg --port /dev/ttyUSB0` with no overrides to dump the persisted UART defaults (`baudrate`, `stopbits`, `parity`).
70
+ - Supply `--baudrate`, `--stopbits`, or `--parity` (accepts `n/none`, `e/even`, `o/odd`) to persist new values. Arguments are validated client-side to match the firmware’s accepted ranges (baudrate 1.2 k–4 M, stopbits 1–2).
71
+ - Like the SPI helper, UART updates are persisted to the device’s NVS region, so you only need to run the command when changing settings.
72
+
73
+ ### UART Transmission
74
+
75
+ - `shuttle uart-tx [HEX] --port /dev/ttyUSB0` forwards a hex-encoded payload to the devboard using the `uart.tx` protocol command. The CLI trims whitespace/underscores and validates the string before sending.
76
+ - To avoid manual hex encoding, pass `--text "Hello"` (optionally with `--newline`) to send UTF-8 text, `--file payload.bin` to transmit the raw bytes of a file, or provide `-` as the argument to read from stdin. Exactly one payload source can be used per invocation.
77
+ - Use `--uart-port` if a future firmware exposes multiple UART instances; otherwise the option can be omitted and the default device UART is used.
78
+ - Responses echo the number of bytes accepted by the firmware, matching the `n` field returned by `uart.tx`.
79
+
80
+
81
+ ### Sequence Integrity Checks
82
+
83
+ Every device message carries a monotonically increasing `seq` counter. Shuttle enforces sequential integrity both within multi-transfer operations and across invocations when requested:
84
+
85
+ - During a command, any gap in response/event sequence numbers raises a `ShuttleSerialError`, helping you catch dropped frames immediately.
86
+ - Pass `--seq-meta /path/to/seq.meta` to persist the last observed sequence number. Subsequent Shuttle runs expect the very next `seq` value; if a gap is detected (for example because the device dropped messages while Shuttle was offline), the CLI exits with an error detailing the missing value.
87
+ - The metadata file stores a single integer. Delete it (or point `--seq-meta` to another location) if the device was power-cycled and its counter reset.
88
+
89
+
90
+ ### Logging and Diagnostics
91
+
92
+ - `--log FILE` appends every raw NDJSON line (RX and TX) along with an ISO-8601 timestamp. This is useful for post-run audits or attaching transcripts to bug reports.
93
+ - Combine `--log` with `--seq-meta` to maintain both a byte-perfect trace and an audit trail of sequence continuity.
94
+ - Rich panels highlight non-`ok` responses and include firmware error codes returned by the device, making it straightforward to spot invalid arguments or transport failures.
95
+
96
+ ### Environment Tips
97
+
98
+ - Export `SHUTTLE_PORT` in your shell profile to avoid typing `--port` for each command.
99
+ - For scripted flows, prefer `shuttle timo read-reg` and `shuttle timo nop` helpers instead of manually streaming raw JSON—they take care of command IDs, transfer framing, and error presentation.
100
+ - Use `make -C host test` to run the CLI unit tests and verify local changes before publishing to PyPI.
101
+
102
+
103
+
104
+ ## TiMo SPI Commands
105
+
106
+ Commands implementing the SPI protocol as described at [docs.lumenradio.io/timotwo/spi-interface](https://docs.lumenrad.io/timotwo/spi-interface/).
107
+
108
+ | Command | Description |
109
+ | --- | --- |
110
+ | `shuttle timo nop` | Issues a single-frame TiMo NOP SPI transfer through the devboard. |
111
+ | `shuttle timo read-reg --addr 0x05 --length 2` | Performs the two-phase TiMo register read sequence and decodes the resulting payload/IRQ flags. |
112
+ | `shuttle timo write-reg --addr 0x05 --data cafebabe` | Performs the two-phase TiMo register write sequence to write bytes to a register. |
113
+ | `shuttle timo read-dmx --length 12` | Reads the latest received DMX values from the TiMo device using a two-phase SPI sequence. |
114
+
115
+ All commands respect the global options declared on the root CLI (`--log`, `--seq-meta`, `--port`, etc.). Rich tables are used to render human-friendly summaries of responses and decoded payloads.
116
+
117
+
118
+ ### TiMo Register Read Example
119
+
120
+ To read bytes from a TiMo register, use the `read-reg` command. I.e. to read the device name:
121
+
122
+ ```bash
123
+ $ shuttle timo read-reg --addr 0x36 --length 12
124
+ TiMo read-reg
125
+ Status OK
126
+ Command spi.xfer (payload phase)
127
+ RX 00 48 65 6c 6c 6f 20 57 6f 72 6c 64 00
128
+ IRQ level {'level': 'low'}
129
+ TiMo read-reg
130
+ Address 0x36
131
+ Length 12
132
+ Data 48 65 6c 6c 6f 20 57 6f 72 6c 64 00
133
+ IRQ (command) 0x00
134
+ IRQ (payload) 0x00
135
+ Command RX 00
136
+ Payload RX 00 48 65 6c 6c 6f 20 57 6f 72 6c 64 00
137
+ ```
138
+
139
+
140
+ ### TiMo Register Write Example
141
+
142
+ To write bytes to a TiMo register, use the `write-reg` command. I.e. to set the device name to `Hello World`:
143
+
144
+ ```bash
145
+ shuttle timo write-reg --addr 0x36 --data 48656c6c6f20576f726c6400 --port /dev/ttyUSB0
146
+ ```
147
+
148
+ - `--addr` specifies the register address (decimal or 0x-prefixed, 0-63)
149
+ - `--data` is a hex string of bytes to write (1-32 bytes)
150
+ - `--port` is your serial device
151
+
152
+ The command will print a summary table with the address, data written, and IRQ flags for each phase. If bit 7 of the IRQ flags is set, the sequence should be retried per the TiMo protocol.
153
+
154
+
155
+ ### TiMo DMX Read Example
156
+
157
+ Read the latest received DMX values from the window set up by the DMX_WINDOW register:
158
+
159
+ ```bash
160
+ shuttle timo read-dmx --length 12 --port /dev/ttyUSB0
161
+ ```
162
+
163
+ This will print a summary table with the length, data bytes (hex), and IRQ flags for each phase. If bit 7 of the IRQ flags is set, the sequence should be retried per the TiMo protocol.
164
+
165
+ - `--length` specifies the number of DMX bytes to read (1 - max_transfer_bytes)
166
+ - `--port` is your serial device
167
+
168
+
169
+ ### Using the Library from Python
170
+
171
+ Use the transport helpers for HIL tests with explicit request→response pairing:
172
+
173
+ ```python
174
+ from shuttle.serial_client import NDJSONSerialClient
175
+ from shuttle import timo
176
+
177
+ with NDJSONSerialClient("/dev/ttyUSB0") as client:
178
+ # Fire a TiMo read-reg using the async API
179
+ commands = timo.read_reg_sequence(address=0x05, length=2)
180
+ responses = [client.send_command("spi.xfer", cmd).result(timeout=1.0) for cmd in commands]
181
+ print("Command RX:", responses[0]["rx"])
182
+ print("Payload RX:", responses[1]["rx"])
183
+ ```
184
+
185
+ Legacy helpers (`spi_xfer`, `ping`, etc.) remain for simple sequential calls; prefer `send_command` when you need explicit request→response control.
186
+
187
+ #### Parsing registers with `REGISTER_MAP`
188
+
189
+ `REGISTER_MAP` in `shuttle.timo` documents the bit layout of TiMo registers. Example: read the `VERSION` register (0x10) and decode firmware/hardware versions.
190
+
191
+ ```python
192
+ from shuttle.serial_client import NDJSONSerialClient
193
+ from shuttle import timo
194
+
195
+ def read_register(client, reg_meta):
196
+ addr = reg_meta["address"]
197
+ length = reg_meta.get("length", 1)
198
+ seq = timo.read_reg_sequence(addr, length)
199
+ responses = [client.send_command("spi.xfer", cmd).result(timeout=1.0) for cmd in seq]
200
+ # The payload frame is in the second response's RX field
201
+ rx_payload = bytes.fromhex(responses[1]["rx"])
202
+ return rx_payload[1:] # skip IRQ flags byte
203
+
204
+ with NDJSONSerialClient("/dev/ttyUSB0") as client:
205
+ reg_meta = timo.REGISTER_MAP["VERSION"]
206
+ version_bytes = read_register(client, reg_meta)
207
+ fw_version = timo.slice_bits(version_bytes, *reg_meta["fields"]["FW_VERSION"]["bits"])
208
+ hw_version = timo.slice_bits(version_bytes, *reg_meta["fields"]["HW_VERSION"]["bits"])
209
+ print(f"VERSION: FW={fw_version:#x} HW={hw_version:#x}")
210
+ ```
211
+
212
+ Use the field metadata in `timo.REGISTER_MAP` to interpret other registers (e.g., check `REGISTER_MAP[0x01]["fields"]` for status flags).
213
+
214
+ More examples can be found in the [examples directory](examples/).
215
+
216
+ ### Async-style Command and Event Handling
217
+
218
+ `NDJSONSerialClient` now dispatches in a background reader thread and exposes futures so you can fan out work without changing the client for new ops:
219
+
220
+ - `send_command(op, params)` returns a `Future` that resolves to the matching response or raises on timeout/sequence gap. You can issue multiple commands back-to-back and wait later.
221
+ - `register_event_listener("ev.name")` returns a subscription whose `.next(timeout=…)` yields each event payload; multiple listeners can subscribe to the same event (e.g., IRQ and DMX streams).
222
+
223
+ Example HIL sketch:
224
+
225
+ ```python
226
+ client = NDJSONSerialClient(port, baudrate=DEFAULT_BAUD, timeout=DEFAULT_TIMEOUT)
227
+ irq_sub = client.register_event_listener("spi.irq")
228
+ cmd_future = client.send_command("timo.read-reg", {"address": 0x05, "length": 1})
229
+
230
+ # Wait for either side as your test requires
231
+ reg_resp = cmd_future.result(timeout=1)
232
+ irq_event = irq_sub.next(timeout=1)
233
+ ```
234
+
235
+ Events continue to emit until you close the subscription or client, so you can assert on multiple DMX frames or IRQ edges without recreating listeners.
236
+
237
+
238
+ ## Production Test SPI Commands
239
+
240
+ | Command | Description |
241
+ | --- | --- |
242
+ | `shuttle prodtest reset` | |
243
+ | `shuttle prodtest ping` | |
244
+ | `shuttle prodtest io-self-test` | |
@@ -0,0 +1,10 @@
1
+ shuttle/cli.py,sha256=KKNThf4eG6oOmqR__tw6Yqx-Y62epztbKje3WfNWGy0,61201
2
+ shuttle/constants.py,sha256=GUlAg3iEuPxLQ2mDCvlv5gVXHnlawl_YeLtaUSqsnPM,757
3
+ shuttle/prodtest.py,sha256=V0wkbicAb-kqMPKsvvi7lQgcPvto7M8RbACU9pf7y8I,3595
4
+ shuttle/serial_client.py,sha256=YdZFM13KrOKHGjqW0R25jdfaf4i_O1OtaPDSzVWm5c8,16877
5
+ shuttle/timo.py,sha256=1K18y0QtDF2lw2Abeok9PgrpPUiCEbQdGQXOQik75Hw,16481
6
+ lr_shuttle-0.1.0.dist-info/METADATA,sha256=TvjPypziHRV3HhEwQXJOMRFgBr8fWm4C5FmDGYcSuC8,11999
7
+ lr_shuttle-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ lr_shuttle-0.1.0.dist-info/entry_points.txt,sha256=obqdFPgvQLB1_EWcnD9ch8HjQRlNVT_pdB_EidDRDco,44
9
+ lr_shuttle-0.1.0.dist-info/top_level.txt,sha256=PtNxNQQdya-Xs8DYublNTBTa8c1TrtfEpQ0lUd_OeZY,8
10
+ lr_shuttle-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ shuttle = shuttle.cli:app
@@ -0,0 +1 @@
1
+ shuttle