SDRDriverBase#

class SDRDriverBase[source]#

Bases: ABC

Contract every vendor SDR driver implements.

Abstract methods cover what every radio can do: open, tune, set a rate, and return samples. The rest raise NotImplementedError by default, and a driver overrides only those its hardware supports. A driver owns its own transport and holds no reference back to InstroSDR.

Configuration methods take keyword-only direction and channel, defaulting to the first receive path. Acquisition (read_iq, fetch_iq, get_backlog) is receive-only.

Example

A receive-only, single-channel driver over a vendor SDK:

class MyVendorSDR(SDRDriverBase):
    def __init__(self, device_index: int = 0):
        self._device_index = device_index
        self._device = None

    def open(self) -> None:
        from vendor_sdk import Radio  # keeps the SDK optional at import time

        self._device = Radio(self._device_index)

    def close(self) -> None:
        self._device.close()

    def set_center_freq(self, frequency_hz, *, direction=Direction.RX, channel="0"):
        self._device.center_freq = frequency_hz

    ...  # get_center_freq, set_sample_rate, get_sample_rate

    def read_iq(self, n_samples, *, channels=("0",)) -> IQCapture:
        samples = np.asarray(self._device.read_samples(n_samples), dtype=np.complex128)
        return IQCapture(
            samples=samples.reshape(1, -1),
            sample_period_ns=1e9 / self._device.sample_rate,
            channels=("0",),
            center_freq_hz=(self._device.center_freq,),
        )

Methods

close

Close the underlying transport or SDR handle.

fetch_iq

Return the next contiguous block from the receive stream, blocking until it is available.

get_antenna

Return the selected antenna port.

get_backlog

Return how many samples are waiting to be fetched from the receive stream.

get_bandwidth

Return the IF or filter bandwidth.

get_center_freq

Return the RF center frequency the radio is tuned to.

get_freq_correction

Return the reference oscillator correction.

get_frequency_range

Return the lowest and highest tunable center frequency.

get_gain

Return the overall gain.

get_gain_mode

Report whether automatic gain control is in control.

get_gain_range

Return the lowest and highest settable gain.

get_num_channels

Return the number of signal paths in a direction.

get_sample_rate

Return the IQ sample rate the radio accepted.

get_sample_rate_range

Return the lowest and highest settable sample rate.

list_antennas

List the selectable antenna ports.

open

Open the underlying transport or SDR handle.

read_iq

Read one time-aligned receive block, with the timebase it was taken on.

set_antenna

Select an antenna port.

set_bandwidth

Set the IF or filter bandwidth.

set_center_freq

Tune the RF center frequency.

set_freq_correction

Correct the reference oscillator's frequency error.

set_gain

Set the overall gain.

set_gain_mode

Hand gain to the radio's automatic gain control, or take manual control.

set_sample_rate

Set the IQ sample rate.

start

Begin continuous acquisition.

stop

End a direction's stream and release its buffers.