Skip to main content

sans_io_core/
sans_io_core.rs

1//! Drive the pure sans-IO core directly: `CiStack::handle(Event) -> Vec<Action>`.
2//!
3//! No device, threads, or clock — you feed events and execute the returned
4//! actions yourself. This is what the `Driver` wraps; driving it by hand shows
5//! the protocol with nothing in the way (and is how the state machines are
6//! tested without hardware).
7//!
8//! Run: `cargo run -p dvb-ci-runtime --example sans_io_core`
9
10use std::time::Duration;
11
12use dvb_ci_runtime::dvb_ci::tpdu::tags;
13use dvb_ci_runtime::{Action, CiStack, Event, HostRequest};
14
15fn show(label: &str, actions: &[Action]) {
16    println!("{label} -> {} action(s)", actions.len());
17    for a in actions {
18        match a {
19            Action::Write(w) => println!("  Write {:02X?}", &w[..w.len().min(8)]),
20            Action::SetTimer { after } => println!("  SetTimer after={after:?}"),
21            other => println!("  {other:?}"),
22        }
23    }
24}
25
26fn main() {
27    let mut stack = CiStack::new();
28
29    // Host brings the interface up: reset + query slot + open transport.
30    show("Init", &stack.handle(Event::Host(HostRequest::Init)));
31
32    // Module accepts the transport connection.
33    let reply = [tags::C_T_C_REPLY, 0x01, 0x01];
34    show(
35        "Readable(C_T_C_Reply)",
36        &stack.handle(Event::Readable(&reply)),
37    );
38
39    // A timer tick with no inbound data drives the poll cadence
40    // (an empty T_Data_Last down to the module).
41    show(
42        "Tick(100ms)",
43        &stack.handle(Event::Tick {
44            elapsed: Duration::from_millis(100),
45        }),
46    );
47}