SDRDriverBase#
- class SDRDriverBase[source]#
Bases:
ABCContract every vendor SDR driver implements.
Abstract methods cover what every radio can do: open, tune, set a rate, and return samples. The rest raise
NotImplementedErrorby default, and a driver overrides only those its hardware supports. A driver owns its own transport and holds no reference back toInstroSDR.Configuration methods take keyword-only
directionandchannel, 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 the underlying transport or SDR handle.
Return the next contiguous block from the receive stream, blocking until it is available.
Return the selected antenna port.
Return how many samples are waiting to be fetched from the receive stream.
Return the IF or filter bandwidth.
Return the RF center frequency the radio is tuned to.
Return the reference oscillator correction.
Return the lowest and highest tunable center frequency.
Return the overall gain.
Report whether automatic gain control is in control.
Return the lowest and highest settable gain.
Return the number of signal paths in a direction.
Return the IQ sample rate the radio accepted.
Return the lowest and highest settable sample rate.
List the selectable antenna ports.
Open the underlying transport or SDR handle.
Read one time-aligned receive block, with the timebase it was taken on.
Select an antenna port.
Set the IF or filter bandwidth.
Tune the RF center frequency.
Correct the reference oscillator's frequency error.
Set the overall gain.
Hand gain to the radio's automatic gain control, or take manual control.
Set the IQ sample rate.
Begin continuous acquisition.
End a direction's stream and release its buffers.
- abstractmethod get_center_freq( ) float[source]#
Return the RF center frequency the radio is tuned to.
- abstractmethod read_iq( ) IQCapture[source]#
Read one time-aligned receive block, with the timebase it was taken on.
sample_period_nson the result must describe the block returned, not the rate last requested:InstroSDRderives every IQ timestamp from it.
- set_gain( ) None[source]#
Set the overall gain.
Override where the radio exposes a single gain figure.
- Parameters:
- Raises:
NotImplementedError – If the driver does not support gain control.
- get_gain( ) float[source]#
Return the overall gain.
- Parameters:
- Returns:
float – Gain in dB.
- Raises:
NotImplementedError – If the driver does not support gain control.
- set_gain_mode( ) None[source]#
Hand gain to the radio’s automatic gain control, or take manual control.
- Parameters:
- Raises:
NotImplementedError – If the driver does not support a gain mode.
- get_gain_mode( ) bool[source]#
Report whether automatic gain control is in control.
Many radios cannot read this back.
- Parameters:
- Returns:
bool –
Truewhen AGC is in control.- Raises:
NotImplementedError – If the driver does not support gain mode readback.
- get_gain_range( ) tuple[float, float][source]#
Return the lowest and highest settable gain.
- Parameters:
- Returns:
tuple[float, float] –
(low, high)in dB.- Raises:
NotImplementedError – If the driver does not support reporting a gain range.
- set_bandwidth( ) None[source]#
Set the IF or filter bandwidth.
Some radios tie this to the sample rate.
- Parameters:
- Raises:
NotImplementedError – If the driver does not support bandwidth control.
- get_bandwidth( ) float[source]#
Return the IF or filter bandwidth.
- Parameters:
- Returns:
float – Bandwidth in Hz.
- Raises:
NotImplementedError – If the driver does not support bandwidth control.
- set_freq_correction( ) None[source]#
Correct the reference oscillator’s frequency error.
- Parameters:
- Raises:
NotImplementedError – If the driver does not support frequency correction.
- get_freq_correction( ) float[source]#
Return the reference oscillator correction.
- Parameters:
- Returns:
float – Correction in parts per million.
- Raises:
NotImplementedError – If the driver does not support frequency correction.
- list_antennas( ) list[str][source]#
List the selectable antenna ports.
- Parameters:
- Returns:
list[str] – Antenna port names.
- Raises:
NotImplementedError – If the driver does not support antenna selection.
- set_antenna( ) None[source]#
Select an antenna port.
- Parameters:
antenna (str)
Port name, one of
list_antennas.direction (Direction)
Signal path,
Direction.RXorDirection.TX.channel (str)
Channel on that path, e.g.
"0".
- Raises:
NotImplementedError – If the driver does not support antenna selection.
- get_antenna( ) str[source]#
Return the selected antenna port.
- Parameters:
- Returns:
str – Port name.
- Raises:
NotImplementedError – If the driver does not support antenna selection.
- start( ) None[source]#
Begin continuous acquisition.
One stream covers one direction and its whole channel set, chosen here.
- Parameters:
- Raises:
NotImplementedError – If the driver does not support streaming.
- stop(
- *,
- direction: Direction = Direction.RX,
End a direction’s stream and release its buffers.
- Parameters:
direction (Direction)
Stream to end.
- Raises:
NotImplementedError – If the driver does not support streaming.
- fetch_iq(
- n_samples: int,
Return the next contiguous block from the receive stream, blocking until it is available.
- Parameters:
n_samples (int)
Samples to return per channel.
- Returns:
IQCapture – One row per channel the stream covers.
- Raises:
ValueError – If
n_samplesexceeds what the stream can buffer.NotImplementedError – If the driver does not support streaming.
- get_backlog() int[source]#
Return how many samples are waiting to be fetched from the receive stream.
- Returns:
int – Samples per channel.
- Raises:
NotImplementedError – If the driver does not support streaming.
- get_num_channels(
- *,
- direction: Direction = Direction.RX,
Return the number of signal paths in a direction.
- Parameters:
direction (Direction)
Direction to count.
- Returns:
int – Signal paths.
0means the radio cannot use that direction at all.- Raises:
NotImplementedError – If the driver does not support reporting channel counts.
- get_frequency_range( ) tuple[float, float][source]#
Return the lowest and highest tunable center frequency.
- Parameters:
- Returns:
tuple[float, float] –
(low, high)in Hz.- Raises:
NotImplementedError – If the driver does not support reporting a frequency range.