Skip to main content

Client

Struct Client 

Source
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>

Source

pub fn new(transport: T) -> Self

Create a new client wrapping the given transport.

Source

pub fn send(&mut self, cmd: Command) -> Result<Response>

Send a command and wait for the solicited response.

Any unsolicited RxPacket frames encountered while waiting are buffered and retrievable via recv or drain_rx.

Source

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).

Source

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.

Source

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.

Source

pub fn ping(&mut self) -> Result<()>

Send a Ping and verify the Pong response.

Examples found in repository?
examples/ping.rs (line 12)
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}
Source

pub fn set_config(&mut self, config: RadioConfig) -> Result<()>

Set the radio configuration.

Examples found in repository?
examples/ping.rs (line 21)
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}
Source

pub fn start_rx(&mut self) -> Result<()>

Start receiving LoRa packets.

Source

pub fn stop_rx(&mut self) -> Result<()>

Stop receiving LoRa packets.

Source

pub fn transmit( &mut self, payload: &[u8], config: Option<RadioConfig>, ) -> Result<()>

Transmit a LoRa packet.

Source

pub fn get_mac(&mut self) -> Result<[u8; 6]>

Get the board’s MAC address.

Examples found in repository?
examples/ping.rs (line 15)
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}
Source

pub fn get_config(&mut self) -> Result<RadioConfig>

Get the current radio configuration from the device.

Examples found in repository?
examples/ping.rs (line 18)
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}
Source

pub fn display_on(&mut self) -> Result<()>

Turn on the display (if present).

Source

pub fn display_off(&mut self) -> Result<()>

Turn off the display (if present).

Source

pub fn into_inner(self) -> T

Consume the client and return the inner transport.

Source

pub fn transport(&self) -> &T

Get a reference to the inner transport.

Source

pub fn transport_mut(&mut self) -> &mut T

Get a mutable reference to the inner transport.

Auto Trait Implementations§

§

impl<T> Freeze for Client<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Client<T>
where T: RefUnwindSafe,

§

impl<T> Send for Client<T>

§

impl<T> Sync for Client<T>
where T: Sync,

§

impl<T> Unpin for Client<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Client<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Client<T>
where T: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more