- Add ping-on-connect handshake: all connect functions validate the device within 200ms, rejecting non-DongLoRa serial devices immediately - Add try_connect() — non-blocking connect that errors instead of blocking forever when no USB device is present - Add payload size validation in transmit() (max 256 bytes) - Add ErrorCode: impl std::error::Error - Fix drain_rx error handling (no longer swallows original error) - Fix repository URL to github.com/donglora/client-rs - Remove wire-level tag constants from top-level re-exports - Add rust-version (MSRV 1.85), homepage, exclude fields to Cargo.toml - Add examples/ping.rs - Allow clippy unwrap/expect in test modules
26 lines
689 B
Rust
26 lines
689 B
Rust
//! Connect to a DongLoRa device, ping it, and print the MAC address.
|
|
//!
|
|
//! Run with: cargo run --example ping
|
|
|
|
use donglora_client::{RadioConfig, try_connect};
|
|
use std::time::Duration;
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
let mut client = try_connect(Duration::from_secs(2))?;
|
|
println!("connected!");
|
|
|
|
client.ping()?;
|
|
println!("ping ok");
|
|
|
|
let mac = client.get_mac()?;
|
|
println!("MAC: {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
|
|
let config = client.get_config()?;
|
|
println!("current config: {config:?}");
|
|
|
|
client.set_config(RadioConfig::default())?;
|
|
println!("config set to defaults");
|
|
|
|
Ok(())
|
|
}
|