Expand description
Rust-native HydraSDR RFOne driver built on nusb.
One-shot USB operations implement MaybeFuture: await them in async code,
or call MaybeFuture::wait on native targets. Devices remain available
while their independently owned receive stream retains a persistent USB
transfer queue.
The synchronous API uses nusb::MaybeFuture::wait for blocking operation.
Awaited operations are executor-agnostic at this crate layer. Bulk/control
transfers are natively async in nusb; async device discovery/open and
endpoint clear_halt follow the support exposed by nusb, so applications
that await those paths can enable exactly one of this crate’s tokio or
smol features for nusb IO thread integration. WebUSB does not need either
runtime feature. No async runtime is forced by default.
WebUSB builds must enable web_sys_unstable_apis as described in the
WebUSB section of the README.
Browsers only expose devices for which the page has WebUSB permission. Call
Device::request_permission from a browser-window user gesture;
Device::open can then discover and open the authorized device from
either the window or a Web Worker. Opening never prompts for permission.
MaybeFuture::wait is not available on wasm32; await device and stream
operations there.
§Synchronous API
Open and configure real hardware with the Device builder:
use hydrasdr_rs::{Complex32, Device, GainPreset, MaybeFuture, RfPort};
use std::time::Duration;
fn main() -> hydrasdr_rs::Result<()> {
let mut dev = Device::builder()
.frequency_hz(100_000_000)
.sample_rate_hz(10_000_000)
.rf_port(RfPort::Rx0)
.gain(GainPreset::Linearity(12))
.open()
.wait()?;
let mut rx = dev.rx_stream()?;
rx.start().wait()?;
dev.set_frequency_hz(101_000_000).wait()?;
let mut samples = [Complex32::default(); 1024];
let count = rx
.read(&mut samples, Some(Duration::from_secs(1)))
.wait()?;
let stats = rx.close().wait()?;
println!("{count} samples");
println!("{stats:?}");
dev.shutdown().wait()?;
Ok(())
}Structs§
- Config
- Reusable receiver configuration for sample mode
M. - Config
Builder - Builder for
Config, defaulting to theF32Iqsample mode. - Device
- Owned HydraSDR RFOne device handle.
- Device
Builder - Builder that selects, opens, and initially configures a
nusbdevice. - Device
Descriptor - Device information collected from
nusbwithout opening the interface. - Device
Info - Immutable device metadata reported while opening the device.
- F32Iq
- Converted complex
f32IQ sample mode. - RawAdc
- Raw ADC sample mode.
- RfPort
Info - RF port metadata returned in
DeviceInfo. - RxStream
- Owned receive stream for sample mode
M, defaulting toF32Iq. - Sample
Block - Borrowed view of one raw receive block.
- Streaming
Stats - Counters collected during a receive stream.
Enums§
- Decimation
Policy - Policy for selecting a firmware rate and host-side IQ decimation factor.
- Error
- Error returned by a HydraSDR operation.
- Error
Kind - Stable error category.
- Gain
Config - Complete gain configuration applied after sample/rate/RF-port setup.
- Gain
Preset - Preset gain plans for common RFOne operation.
- RfPort
- RF input port selector.
- Sample
Format - Runtime view of the sample format.
- Stage
Gain - Gain control for an LNA or mixer stage.
Constants§
- MAX_
F32_ IQ_ SAMPLES_ PER_ TRANSFER - Maximum number of unpacked complex
F32Iqsamples produced by one USB transfer.
Traits§
- Maybe
Future - IO that may be performed synchronously or asynchronously.
- Sample
Mode - Compile-time receiver sample mode.
Type Aliases§
- Complex32
- Alias for a
Complex<f32> - Result
- Crate result alias using
Error.