pub struct Client<T: Transport> { /* private fields */ }Expand description
High-level DongLoRa client, generic over transport.
Works with any Transport: direct USB serial, Unix socket mux, or TCP mux.
Implementations§
Source§impl<T: Transport> Client<T>
impl<T: Transport> Client<T>
Sourcepub fn recv(&mut self) -> Result<Option<Response>>
pub fn recv(&mut self) -> Result<Option<Response>>
Return the next RxPacket from the buffer or the wire.
Returns Ok(None) on timeout (no packet available).
Sourcepub fn drain_rx(&mut self) -> Result<Vec<Response>>
pub fn drain_rx(&mut self) -> Result<Vec<Response>>
Drain all buffered and pending RxPacket frames.
Temporarily reduces the read timeout to quickly drain any frames still in flight, then restores the original timeout.
Sourcepub fn validate(&mut self) -> Result<()>
pub fn validate(&mut self) -> Result<()>
Validate the connection by pinging the device.
Uses a short timeout to fail fast on non-DongLoRa devices (e.g. USB-UART
bridges that happen to match known VID:PIDs). Called automatically by the
connect family of functions.
Sourcepub fn ping(&mut self) -> Result<()>
pub fn ping(&mut self) -> Result<()>
Send a Ping and verify the Pong response.
Examples found in repository?
8fn main() -> anyhow::Result<()> {
9 let mut client = try_connect(Duration::from_secs(2))?;
10 println!("connected!");
11
12 client.ping()?;
13 println!("ping ok");
14
15 let mac = client.get_mac()?;
16 println!("MAC: {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
17
18 let config = client.get_config()?;
19 println!("current config: {config:?}");
20
21 client.set_config(RadioConfig::default())?;
22 println!("config set to defaults");
23
24 Ok(())
25}Sourcepub fn set_config(&mut self, config: RadioConfig) -> Result<()>
pub fn set_config(&mut self, config: RadioConfig) -> Result<()>
Set the radio configuration.
Examples found in repository?
8fn main() -> anyhow::Result<()> {
9 let mut client = try_connect(Duration::from_secs(2))?;
10 println!("connected!");
11
12 client.ping()?;
13 println!("ping ok");
14
15 let mac = client.get_mac()?;
16 println!("MAC: {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
17
18 let config = client.get_config()?;
19 println!("current config: {config:?}");
20
21 client.set_config(RadioConfig::default())?;
22 println!("config set to defaults");
23
24 Ok(())
25}Sourcepub fn transmit(
&mut self,
payload: &[u8],
config: Option<RadioConfig>,
) -> Result<()>
pub fn transmit( &mut self, payload: &[u8], config: Option<RadioConfig>, ) -> Result<()>
Transmit a LoRa packet.
Sourcepub fn get_mac(&mut self) -> Result<[u8; 6]>
pub fn get_mac(&mut self) -> Result<[u8; 6]>
Get the board’s MAC address.
Examples found in repository?
8fn main() -> anyhow::Result<()> {
9 let mut client = try_connect(Duration::from_secs(2))?;
10 println!("connected!");
11
12 client.ping()?;
13 println!("ping ok");
14
15 let mac = client.get_mac()?;
16 println!("MAC: {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
17
18 let config = client.get_config()?;
19 println!("current config: {config:?}");
20
21 client.set_config(RadioConfig::default())?;
22 println!("config set to defaults");
23
24 Ok(())
25}Sourcepub fn get_config(&mut self) -> Result<RadioConfig>
pub fn get_config(&mut self) -> Result<RadioConfig>
Get the current radio configuration from the device.
Examples found in repository?
8fn main() -> anyhow::Result<()> {
9 let mut client = try_connect(Duration::from_secs(2))?;
10 println!("connected!");
11
12 client.ping()?;
13 println!("ping ok");
14
15 let mac = client.get_mac()?;
16 println!("MAC: {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
17
18 let config = client.get_config()?;
19 println!("current config: {config:?}");
20
21 client.set_config(RadioConfig::default())?;
22 println!("config set to defaults");
23
24 Ok(())
25}Sourcepub fn display_on(&mut self) -> Result<()>
pub fn display_on(&mut self) -> Result<()>
Turn on the display (if present).
Sourcepub fn display_off(&mut self) -> Result<()>
pub fn display_off(&mut self) -> Result<()>
Turn off the display (if present).
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the client and return the inner transport.
Sourcepub fn transport_mut(&mut self) -> &mut T
pub fn transport_mut(&mut self) -> &mut T
Get a mutable reference to the inner transport.