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 |
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 |
|
stats |
StreamStats
|
Samples delivered, dropped and missing, and stalls, since |
tx_stats |
{"written", "sent", "underruns", "pending", "async_errors"} samples counted since start_tx, for the first |
Source code in src/pysdrlib/base/native.py
stall_timeout
property
writable
¶
Seconds without samples before get_samples raises err.StreamStalled; None disables
stats
property
¶
Samples delivered, dropped and missing, and stalls, since start_rx
tx_stats
property
¶
{"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