055fc76b87c4087fd3ac5a017d4ae83e48a02df6
Track mux usage with a static AtomicBool. Once a mux connection succeeds, all future connect() calls in the same process only try the mux. connect() blocks waiting for the socket to reappear; try_connect() returns an error so callers can retry with backoff.
DongLoRa Rust Client
Rust client library for talking to a DongLoRa device — either directly over USB or through a mux daemon.
Install
[dependencies]
donglora-client = "0.2"
Quick Start
use donglora_client::*;
let mut client = connect_default()?;
client.set_config(RadioConfig::default())?;
client.start_rx()?;
loop {
if let Some(Response::RxPacket { rssi, snr, payload }) = client.recv()? {
println!("RX rssi={rssi} snr={snr} len={}", payload.len());
}
}
All connect functions automatically validate the device by pinging it,
so you'll get a clear error immediately if the port isn't a real DongLoRa.
What's in Here
src/protocol.rs— wire protocol types (RadioConfig,Command,Response,ErrorCode)src/codec.rs— COBS framing, frame accumulatorsrc/discovery.rs— USB VID:PID device discoverysrc/transport.rs— serial and mux socket transportssrc/client.rs— high-levelClient<T>with send/recvsrc/connect.rs— auto-detection (mux socket, TCP, direct USB)
Connection Priority
[connect] and [try_connect] try these in order:
- TCP mux — via
DONGLORA_MUX_TCPenv var - Unix socket mux — checks
$XDG_RUNTIME_DIR/donglora/mux.sockor/tmp/donglora-mux.sock - Direct USB serial — auto-detects by VID:PID
try_connect returns an error immediately if no device is found.
connect blocks until a USB device appears.
Dependencies
ucobs— COBS framing (same implementation as the firmware)serialport— USB serial communicationanyhow— error handlingtracing— logging
Languages
Rust
99.3%
Just
0.7%