Struct DigiMeshDevice

Source
pub struct DigiMeshDevice {
    pub addr_64bit: Option<u64>,
    pub node_id: Option<String>,
    pub firmware_version: Option<u16>,
    pub hardware_version: Option<u16>,
    pub nodes: Option<Vec<RemoteDigiMeshDevice>>,
    /* private fields */
}

Fields§

§addr_64bit: Option<u64>§node_id: Option<String>§firmware_version: Option<u16>§hardware_version: Option<u16>§nodes: Option<Vec<RemoteDigiMeshDevice>>

Implementations§

Source§

impl DigiMeshDevice

Source

pub fn new<'a>(port: &'a str, baud: u32) -> Result<Self>

Examples found in repository?
examples/atcommand_query.rs (line 18)
16fn main() -> Result<(), Box<dyn error::Error>> {
17    // first create instance of device
18    let mut device = DigiMeshDevice::new(PORT, 9600)?;
19
20    // Construct At command to ask for node_id of device
21    let node_id_request = api::AtCommandFrame("NI", None);
22    // returns dyn trait RecieveApiFrame
23    let response = device.send_frame(node_id_request)?;
24    // We can downcast to original AtCommandResponse struct to access members
25    let atcommand_response = response.downcast_ref::<api::AtCommandResponse>();
26
27    if let Some(obj) = atcommand_response {
28        let cmd_data = &obj.command_data;
29        println!("{:?}", cmd_data);
30    }
31
32    Ok(())
33}
More examples
Hide additional examples
examples/atcommand_set.rs (line 20)
18fn main() -> Result<(), Box<dyn error::Error>> {
19    // first create instance of device
20    let mut device = DigiMeshDevice::new(PORT, 9600)?;
21
22    // Construct At command and set node_id of device by supplying valid [u8] but None
23    let _ = api::AtCommandFrame("NI", Some(NODE_ID.as_bytes()));
24
25    // Now query new node_id
26    let new_node_id = api::AtCommandFrame("NI", None);
27
28    // returns dyn trait RecieveApiFrame
29    let response = device.send_frame(new_node_id)?;
30
31    // We can downcast to original AtCommandResponse struct to access members
32    let atcommand_response = response.downcast_ref::<api::AtCommandResponse>();
33
34    if let Some(obj) = atcommand_response {
35        let cmd_data = &obj.command_data;
36        println!("{:?}", cmd_data); // Some(b"MY_NODE")
37    }
38
39    Ok(())
40}
examples/remote_atcommand_set.rs (line 19)
17fn main() -> Result<(), Box<dyn error::Error>> {
18    // first create instance of device
19    let mut device = DigiMeshDevice::new(PORT, 9600)?;
20
21    let set_all_id = api::RemoteAtCommandFrame {
22        dest_addr: api::BROADCAST_ADDR,
23        options: &api::RemoteCommandOptions {
24            apply_changes: true,
25        },
26        atcmd: "ID",
27        cmd_param: Some(b"\x7f\xff"), // change all devices on same ID to a new ID (0x7fff)
28    };
29
30    let _ = device.send_frame(set_all_id)?;
31
32    let get_all_id = api::RemoteAtCommandFrame {
33        dest_addr: DEST_ADDR,
34        options: &api::RemoteCommandOptions {
35            apply_changes: true,
36        },
37        atcmd: "ID",
38        cmd_param: None,
39    };
40
41    let response = device.send_frame(get_all_id)?;
42
43    if let Some(resp) = response.downcast_ref::<api::RemoteAtCommandResponse>() {
44        println!("{:?}", resp.command_data);
45    }
46
47    Ok(())
48}
examples/transmit_request.rs (line 22)
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}
Source

pub fn get_firmware_version(&mut self) -> Result<u16>

Source

pub fn get_hardware_version(&mut self) -> Result<u16>

Source

pub fn get_node_id(&mut self) -> Result<String>

Source

pub fn get_64bit_addr(&mut self) -> Result<u64>

Source

pub fn send<'a>(&mut self, data: &'a [u8]) -> Result<usize>

Source

pub fn discover_nodes(&mut self, timeout: Option<Duration>) -> Result<()>

Source

pub fn send_frame<T: TransmitApiFrame>( &mut self, frame: T, ) -> Result<Box<dyn RecieveApiFrame>>

Examples found in repository?
examples/atcommand_query.rs (line 23)
16fn main() -> Result<(), Box<dyn error::Error>> {
17    // first create instance of device
18    let mut device = DigiMeshDevice::new(PORT, 9600)?;
19
20    // Construct At command to ask for node_id of device
21    let node_id_request = api::AtCommandFrame("NI", None);
22    // returns dyn trait RecieveApiFrame
23    let response = device.send_frame(node_id_request)?;
24    // We can downcast to original AtCommandResponse struct to access members
25    let atcommand_response = response.downcast_ref::<api::AtCommandResponse>();
26
27    if let Some(obj) = atcommand_response {
28        let cmd_data = &obj.command_data;
29        println!("{:?}", cmd_data);
30    }
31
32    Ok(())
33}
More examples
Hide additional examples
examples/atcommand_set.rs (line 29)
18fn main() -> Result<(), Box<dyn error::Error>> {
19    // first create instance of device
20    let mut device = DigiMeshDevice::new(PORT, 9600)?;
21
22    // Construct At command and set node_id of device by supplying valid [u8] but None
23    let _ = api::AtCommandFrame("NI", Some(NODE_ID.as_bytes()));
24
25    // Now query new node_id
26    let new_node_id = api::AtCommandFrame("NI", None);
27
28    // returns dyn trait RecieveApiFrame
29    let response = device.send_frame(new_node_id)?;
30
31    // We can downcast to original AtCommandResponse struct to access members
32    let atcommand_response = response.downcast_ref::<api::AtCommandResponse>();
33
34    if let Some(obj) = atcommand_response {
35        let cmd_data = &obj.command_data;
36        println!("{:?}", cmd_data); // Some(b"MY_NODE")
37    }
38
39    Ok(())
40}
examples/remote_atcommand_set.rs (line 30)
17fn main() -> Result<(), Box<dyn error::Error>> {
18    // first create instance of device
19    let mut device = DigiMeshDevice::new(PORT, 9600)?;
20
21    let set_all_id = api::RemoteAtCommandFrame {
22        dest_addr: api::BROADCAST_ADDR,
23        options: &api::RemoteCommandOptions {
24            apply_changes: true,
25        },
26        atcmd: "ID",
27        cmd_param: Some(b"\x7f\xff"), // change all devices on same ID to a new ID (0x7fff)
28    };
29
30    let _ = device.send_frame(set_all_id)?;
31
32    let get_all_id = api::RemoteAtCommandFrame {
33        dest_addr: DEST_ADDR,
34        options: &api::RemoteCommandOptions {
35            apply_changes: true,
36        },
37        atcmd: "ID",
38        cmd_param: None,
39    };
40
41    let response = device.send_frame(get_all_id)?;
42
43    if let Some(resp) = response.downcast_ref::<api::RemoteAtCommandResponse>() {
44        println!("{:?}", resp.command_data);
45    }
46
47    Ok(())
48}
examples/transmit_request.rs (line 37)
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}
Source

pub fn atcmd<'a>(&mut self, atcmd: &'a AtCommand<'_>) -> Result<()>

send an AT command and returns the result

Source

pub fn command_mode(&mut self, mode: bool) -> Result<()>

Trait Implementations§

Source§

impl Debug for DigiMeshDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V