Skip to content

Native

pysdrlib.base.native

NativeDevice: the base of every driver over a compiled extension.

The extension streams on its own thread, converting to complex64 and queueing in C++ without the GIL. This class adds the Python side: draining the queue, the stall watchdog, drop reporting (on_drop, stats) and transmit through the extension's queue. A driver subclasses it and implements only what is particular to its hardware: see pysdrlib.contributing.

Classes:

Name Description
NativeDevice

A Device driven by a compiled extension (pybind11, see _native/include/hardware_pybind.hpp).

NativeDevice

NativeDevice()

Bases: Device

A Device driven by a compiled extension (pybind11, see _native/include/hardware_pybind.hpp).

The extension's device object, self.device, streams on a thread of its own. That thread converts the raw samples to complex64 (with the device's sample format) and queues them, all in C++ and without the GIL, so a busy Python thread (a GUI redraw, say) cannot hold up the driver and overflow the hardware's buffers. get_samples drains the queue. A device only implements what is particular to its hardware: _open, tuning and gain.

class MyDevice(NativeDevice):
    SAMPLE_FORMAT = convert.INT8
    def _open(self): return lib.mydev.open()
    def _set_rx_freq(self, freq, channel=0): self.device.set_freq(int(freq))

Receiving is watched (see Watchdog), each time get_samples or read looks at the queue: - the device stops delivering for stall_timeout seconds: raises err.StreamStalled, once any samples still buffered have been returned - samples were dropped, by the device or because they were not read in time: what on_drop says ("warn": warn.Dropped, "raise": err.Dropped, "ignore", or a function called with the count and a message) stats has the counts; read(..., meta=True) says where in the stream they were lost.

Attributes:

Name Type Description
stall_timeout

Seconds without samples before get_samples raises err.StreamStalled; None disables

stats StreamStats

Samples delivered, dropped and missing, and stalls, since start_rx

tx_stats

{"written", "sent", "underruns", "pending", "async_errors"} samples counted since start_tx, for the first

Source code in src/pysdrlib/base/native.py
def __init__(self):
    super().__init__()
    self._watchdog = Watchdog(type(self).STALL_TIMEOUT)
    self._dropped_reported = 0
    self.on_drop = "warn"
    self._rx_base = 0          # stream index of the queue's sample 0 (the queue restarts when the rate changes)

stall_timeout property writable

stall_timeout

Seconds without samples before get_samples raises err.StreamStalled; None disables

stats property

stats: StreamStats

Samples delivered, dropped and missing, and stalls, since start_rx

tx_stats property

tx_stats

{"written", "sent", "underruns", "pending", "async_errors"} samples counted since start_tx, for the first transmit channel (get_tx_stats(channel) for others). underruns: samples of silence sent because write was not keeping up