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
impl DigiMeshDevice
Sourcepub fn new<'a>(port: &'a str, baud: u32) -> Result<Self>
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
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}
pub fn get_firmware_version(&mut self) -> Result<u16>
pub fn get_hardware_version(&mut self) -> Result<u16>
pub fn get_node_id(&mut self) -> Result<String>
pub fn get_64bit_addr(&mut self) -> Result<u64>
pub fn send<'a>(&mut self, data: &'a [u8]) -> Result<usize>
pub fn discover_nodes(&mut self, timeout: Option<Duration>) -> Result<()>
Sourcepub fn send_frame<T: TransmitApiFrame>(
&mut self,
frame: T,
) -> Result<Box<dyn RecieveApiFrame>>
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
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}
Sourcepub fn atcmd<'a>(&mut self, atcmd: &'a AtCommand<'_>) -> Result<()>
pub fn atcmd<'a>(&mut self, atcmd: &'a AtCommand<'_>) -> Result<()>
send an AT command and returns the result
pub fn command_mode(&mut self, mode: bool) -> Result<()>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DigiMeshDevice
impl !RefUnwindSafe for DigiMeshDevice
impl Send for DigiMeshDevice
impl !Sync for DigiMeshDevice
impl Unpin for DigiMeshDevice
impl !UnwindSafe for DigiMeshDevice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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.