Skip to main content

std_managed_node/
std_managed_node.rs

1use std::{thread, time::Duration};
2
3use rns_embedded_core::transport::LinkState;
4use rns_embedded_runtime::{
5    BleNodeBackendConfig, EmbeddedNode, NodeBackendConfig, NodeConfig, NodeEventKind,
6    NodeTransportMode, PollResult, RuntimeConfig, SendOptions,
7};
8
9fn main() {
10    let node = EmbeddedNode::new();
11    let subscription = node.subscribe_events().expect("subscribe");
12
13    let config = NodeConfig {
14        runtime: RuntimeConfig {
15            store_identity: [0x11; 32],
16            lxmf_address: [0x22; 16],
17            node_mode: NodeTransportMode::BleOnly,
18            announce_interval_ms: 1_000,
19            max_outbound_queue: 8,
20            max_events: 16,
21            capture_defaults: Default::default(),
22        },
23        backend: NodeBackendConfig::Ble(BleNodeBackendConfig::default()),
24    };
25
26    node.start(config).expect("start");
27    node.set_link_state(LinkState::Up).expect("link up");
28    node.send([0x42; 16], b"hello from managed std", SendOptions).expect("send");
29
30    thread::sleep(Duration::from_millis(75));
31
32    loop {
33        match subscription.next(0).expect("poll") {
34            PollResult::Event(event) => {
35                if let NodeEventKind::PacketSent { sequence, .. } = event.kind {
36                    println!("packet sent with sequence {sequence}");
37                    break;
38                }
39            }
40            PollResult::Timeout => break,
41            other => println!("poll result: {other:?}"),
42        }
43    }
44
45    node.stop().expect("stop");
46}