Skip to main content

Crate hydrasdr_rs

Crate hydrasdr_rs 

Source
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.
ConfigBuilder
Builder for Config, defaulting to the F32Iq sample mode.
Device
Owned HydraSDR RFOne device handle.
DeviceBuilder
Builder that selects, opens, and initially configures a nusb device.
DeviceDescriptor
Device information collected from nusb without opening the interface.
DeviceInfo
Immutable device metadata reported while opening the device.
F32Iq
Converted complex f32 IQ sample mode.
RawAdc
Raw ADC sample mode.
RfPortInfo
RF port metadata returned in DeviceInfo.
RxStream
Owned receive stream for sample mode M, defaulting to F32Iq.
SampleBlock
Borrowed view of one raw receive block.
StreamingStats
Counters collected during a receive stream.

Enums§

DecimationPolicy
Policy for selecting a firmware rate and host-side IQ decimation factor.
Error
Error returned by a HydraSDR operation.
ErrorKind
Stable error category.
GainConfig
Complete gain configuration applied after sample/rate/RF-port setup.
GainPreset
Preset gain plans for common RFOne operation.
RfPort
RF input port selector.
SampleFormat
Runtime view of the sample format.
StageGain
Gain control for an LNA or mixer stage.

Constants§

MAX_F32_IQ_SAMPLES_PER_TRANSFER
Maximum number of unpacked complex F32Iq samples produced by one USB transfer.

Traits§

MaybeFuture
IO that may be performed synchronously or asynchronously.
SampleMode
Compile-time receiver sample mode.

Type Aliases§

Complex32
Alias for a Complex<f32>
Result
Crate result alias using Error.