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::tpdu::tags;
13use dvb_ci_runtime::{Action, CiStack, Event, HostRequest, StackBounds, TransportBounds};
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 stack_bounds() -> StackBounds {
27    StackBounds {
28        transport: TransportBounds {
29            poll_interval: Duration::from_millis(100),
30            reply_timeout: Duration::from_secs(1),
31            max_setup_attempts: 5,
32            max_reassembly_len: 2 * 1024 * 1024,
33            max_outbound_queue: 64,
34        },
35        max_sessions: 32,
36    }
37}
38
39fn main() {
40    let mut stack = CiStack::new(stack_bounds());
41
42    // Host brings the interface up: reset + query slot + open transport.
43    show("Init", &stack.handle(Event::Host(HostRequest::Init)));
44
45    // Module accepts the transport connection.
46    let reply = [tags::C_T_C_REPLY, 0x01, 0x01];
47    show(
48        "Readable(C_T_C_Reply)",
49        &stack.handle(Event::Readable(&reply)),
50    );
51
52    // A timer tick with no inbound data drives the poll cadence
53    // (an empty T_Data_Last down to the module).
54    show(
55        "Tick(100ms)",
56        &stack.handle(Event::Tick {
57            elapsed: Duration::from_millis(100),
58        }),
59    );
60}