New Protocol - V2#848
Conversation
Size Report
|
Deploying rmk-rs with
|
| Latest commit: |
93044c3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://4a74aac2.rmk-4a2.pages.dev |
| Branch Preview URL: | https://feat-rynk-protocol.rmk-4a2.pages.dev |
|
Iirc this is also used as the protocol between central and peripheral. I can count a sequence number and simply not start the update if a message went missing. Or we need flow control e.g. with a sliding window for rynk. For the latter I would say it's better to have that reusable in the protocols instead of my firmware update cooking up its own flow control. |
In the current design Rynk is not used between central and peripheral, but I hope it can be used in the future. Now it has only a |
What I mean with flow control is basically what I already did for the split protocol in #886. So mostly checking if the data is correct and resending a packet if it isn't. |
1 similar comment
What I mean with flow control is basically what I already did for the split protocol in #886. So mostly checking if the data is correct and resending a packet if it isn't. |
89bfd45 to
2b538e9
Compare
Adds new rynk/ protocol module (buffer, cmd, header, fingerprint, mod) with the new wire format. Migrates per-domain modules (combo, encoder, fork, keymap, macro_data, morse, status, system) from the previous rmk/ namespace, and removes the old endpoint/topic snapshot-based layout. Also drops unused derives/imports across rmk-types/src/*.rs. Signed-off-by: Haobo Gu <haobogu@outlook.com>
Signed-off-by: Haobo Gu <haobogu@outlook.com>
Adds GetWpm (0x0805), GetSleepState (0x0806), GetLedIndicator (0x0807) in the Status group. These let the host probe the latest value of the three pure event-stream topics whose state isn't otherwise queryable (layer/connection/battery/ble already have getters). The snapshot source-of-truth lives in pr2; handlers land in pr3.
Drops the `Header` struct + `Header::decode`/`encode_into` in favour of `Frame` (a type alias for `[u8]`) and the `FrameOps` trait that adds in-place wire-header accessors (`cmd`, `seq`, `payload_len`, `payload`, plus their setters). Callers stop parsing a `Header` value out of the bytes and re-encoding it back — they hand the buffer through and access fields via the trait. The trait re-uses `RynkError::InvalidParameter` for "short buffer" / "unknown CMD" instead of a separate `DecodeError`. Wire layout unchanged: `[CMD u16 LE | SEQ u8 | LEN u16 LE | payload]`. Used by pr2's dispatch refactor (single buffer in/out) and the handler signature update in pr3.
Aliases `Result<T, RynkError>` (with `T = ()` default) so handler modules can write `RynkResult` for empty-status responses without re-declaring the alias in every file. Used by pr3's handlers.
Introduces rmk/src/host/rynk/{mod, codec, topics} as the dispatcher
scaffold for the on-device rynk service. Wires it into host/context
and host/mod, exposes channel hooks in src/channel.rs, and updates
src/keymap.rs and src/lib.rs to expose the new entry points.
Handlers and transports land in subsequent PRs.
Signed-off-by: Haobo Gu <haobogu@outlook.com>
These statics are only consumed by the BLE transport added in pr4. Move them out of the service-core PR so pr2 stays free of transport concerns; they'll be re-introduced alongside the BLE transport.
Adds rmk/src/host/rynk/snapshot.rs: three static atomics latched by a small `run_topic_snapshot` task that subscribes to WpmUpdateEvent, SleepStateEvent, and LedIndicatorEvent. The matching GetWpm / GetSleepState / GetLedIndicator handlers (pr3) read these atomics so the host can probe the latest value without waiting for the next push. Wires the dispatch arms for the new variants and re-exports the snapshot task at the crate root (`rmk::host::run_topic_snapshot`). Bumps default `subs` for wpm_update, sleep_state, and led_indicator by 1 to reserve the snapshot subscriber's slot. Handlers land in pr3; user wiring (run_all!) lands in pr5.
Replaces `Header::decode`/`encode_into` plumbing with the new `Frame` + `FrameOps` surface from rmk-types: - `dispatch` now takes `&mut Frame` (one buffer), returns `Result<(), RynkError>`. The request bytes and the response bytes share the same buffer; cmd/seq stay in place, only LEN is patched. - The previous private `handle` function is folded into `dispatch`'s match — there's no second function to hop through. - `encode_topic` renamed to `write_topic`, writes header + payload into the caller's frame in place (no length returned; caller reads `frame.payload_len()`). Wire layout unchanged; only the firmware-side API moves.
Signed-off-by: Haobo Gu <haobogu@outlook.com>
Every header accessor on the `RynkMessage` trait now returns `Result<T, RynkError>`, checking `self.len() >= RYNK_HEADER_SIZE` like `cmd()` already did. There's no longer an implicit "caller must verify length first" precondition — passing a short buffer to `seq()`, `payload_len()`, `payload()`, etc. surfaces `Err(InvalidRequest)` instead of indexing past the end. Dispatcher and `write_topic` propagate the new Result with `?`; `TopicEvent::encode` does the same. Transports already always pass buffers sized to `RYNK_BUFFER_SIZE >= RYNK_MIN_BUFFER_SIZE >= RYNK_HEADER_SIZE`, so the new error path is dead in practice — but it's no longer a footgun for fresh callers (including loopback tests). Adds `every_accessor_rejects_short_buffer` to the message tests so this invariant doesn't regress silently. Signed-off-by: Haobo Gu <haobogu@outlook.com>
`dispatch` no longer encodes handler errors into the payload itself.
Each match arm uses `await?` so any `RynkError` (from `msg.cmd()`,
`payload_mut()`, the handler body, or the topic-CMD arms) propagates
out as the function's `Err`. The dispatcher stays a pure
"request bytes → response bytes or error" function with no buffer
mutation on the failure path.
Adds `write_error_response(msg, err)` next to `dispatch` and
`write_topic`. Transports call it on the dispatch `Err` arm to encode
`Err::<(), RynkError>(err)` into the same buffer's payload region and
patch LEN, then send the reply. The split keeps the wire contract
("every response is a `Result<T, RynkError>` envelope") while pulling
the error-encoding policy out of the protocol core.
`cmd` and `seq` in the header are not touched by `write_error_response`
— the host correlates the reply with its outgoing request by `seq`,
regardless of the protocol-level error.
Signed-off-by: Haobo Gu <haobogu@outlook.com>
Signed-off-by: Haobo Gu <haobogu@outlook.com>
Signed-off-by: Haobo Gu <haobogu@outlook.com>
Adds rmk/src/host/rynk/transport/{mod, usb, ble} carrying rynk frames
over USB HID and a dedicated BLE service. Updates rmk/src/ble/* and
rmk/src/usb/mod.rs to register the new endpoints, and adds
rmk/src/split/peripheral_state.rs so split peripherals expose their
state for host-side reads.
Signed-off-by: Haobo Gu <haobogu@outlook.com>
…d, clean code Signed-off-by: Haobo Gu <haobogu@outlook.com>
Signed-off-by: Haobo Gu <haobogu@outlook.com>
Signed-off-by: Haobo Gu <haobogu@outlook.com>
Signed-off-by: Haobo Gu <haobogu@outlook.com>
Add a runtime-free host client crate for the Rynk protocol, plus native serial and BLE transport crates. Extend firmware-side Rynk protocol handling for host clients and cover the wire format, loopback path, hardware validation example, and host CI checks. Signed-off-by: Haobo Gu <haobogu@outlook.com>
b9e0599 to
93044c3
Compare
Signed-off-by: Haobo Gu <haobogu@outlook.com>
9047ce5 to
8ea6723
Compare
The 2nd try of adding RMK's protocol. Different from previous tries(#750, #835), this time
postcard-rpcis dropped because it's kind of overkill and introduces long compile time.Instead, a simpler, header + payload like protocol is used, and the new protocol is called
rynkwhich meansrmk+link.Progress:
RynkMessagea wrapper type #863