transmit_request/
transmit_request.rs

1//! Transmit Request Example
2//!
3//! This example shows how to send two transmit request packets. One that will
4//! broadcast through all connected frames within same network ID and the other to
5//! a specific addr
6//!
7//!
8
9use rustbee::{api, device::DigiMeshDevice};
10use std::error;
11
12#[cfg(target_os = "linux")]
13static PORT: &'static str = "/dev/ttyUSB0";
14
15#[cfg(target_os = "windows")]
16static PORT: &'static str = "COM1";
17
18static DEST_ADDR: u64 = 0xabcdef0101020304;
19
20fn main() -> Result<(), Box<dyn error::Error>> {
21    // first create instance of device
22    let mut device = DigiMeshDevice::new(PORT, 9600)?;
23
24    let broadcast = api::TransmitRequestFrame {
25        dest_addr: api::BROADCAST_ADDR,
26        broadcast_radius: 0,
27        options: Some(&api::TransmitRequestOptions {
28            disable_ack: false,
29            disable_route_discovery: false,
30            enable_unicast_nack: false,
31            enable_unicast_trace_route: false,
32            mode: api::MessagingMode::DigiMesh,
33        }),
34        payload: b"HELLO FROM RUST!!",
35    };
36    // all devices with same Network ID will have the payload broadcasted too.
37    let _transmit_status = device.send_frame(broadcast)?;
38
39    let unicast_msg = api::TransmitRequestFrame {
40        dest_addr: DEST_ADDR,
41        broadcast_radius: 0,
42        options: Some(&api::TransmitRequestOptions {
43            disable_ack: false,
44            disable_route_discovery: false,
45            enable_unicast_nack: false,
46            enable_unicast_trace_route: false,
47            mode: api::MessagingMode::DigiMesh,
48        }),
49
50        payload: b"Hello individual device!",
51    };
52
53    // will send payload to DEST_ADDR if it is found on the same network ID
54    let transmit_status = device.send_frame(unicast_msg)?;
55    println!("{:?}", transmit_status); // review the status of the transmit
56    Ok(())
57}