Tcpiq
pysdrlib.tcpiq ¶
Raw interleaved I/Q over TCP, at either end of the connection. pysdrlib can be the client of a server that sends
samples (an rtl_tcp-style source, a GNU Radio TCP sink in server mode, a radio on another machine that pysdrlib has no
driver for). It can also be the server that a sender connects to (a GNU Radio TCP sink in client mode, nc, a script).
It is receive-only.
# client: connect to a server that sends samples
sdr = pysdrlib.open("tcpiq", host="10.0.0.5", port=1234)
# server: listen for a client that sends samples (every interface by default)
sdr = pysdrlib.open("tcpiq", listen=True, port=1234)
sdr.initialize(cf=100e6, Fs=2e6) # says what the stream is; a stream can't be retuned from here
sdr.start_rx()
samples = sdr.read(65536, timeout=1.0)
Receiving¶
The socket is read on a thread of the extension's own, in C++ and without the GIL, like the radios' streaming threads.
That thread converts the samples to complex64 and queues them. It reads as fast as the network delivers, so a busy
Python process never slows the sender down. If Python doesn't read in time, the queue (0.5 s of the declared rate, at
most 2^24 samples) drops the oldest samples, and this is reported like any native device's drops (on_drop, default:
the Dropped warning). There is no stall watchdog, because the sender decides when to send.
Server¶
listen=Truebinds tohost(default0.0.0.0, every interface; passhost="127.0.0.1"to keep it local) andport(0: any free port, seesdr.port). A port that is in use raiseserr.NoDevice.- It listens from
opentocloseand serves one client at a time. When the client disconnects it waits for it to reconnect (or for another), and the stream goes on:start_rxholds, and areadwaits through the gap (give it atimeoutto bound that).reconnect_timeout(default 10 s; None: no limit) is how long it waits: after that a read with nothing queued raiseserr.Lost, until a client connects again (it keeps listening). Before the first client, reads wait as long as it takes. A client that connects while one is connected takes over, as a sender reconnecting after its connection died does before this end has noticed; TCP keepalive notices a client that vanished without closing within about 5 s.sdr.reconnectscounts the takeovers. - Samples that arrive while not receiving (before
start_rx, afterstop_rx) are read and discarded, so a sender is never blocked. sdr.peeris the connected client ("host:port", or None: waiting for one), andsdr.connectionscounts the clients accepted.
Specs¶
- Frequency and sample rate: whatever the source sends.
cfandFsare what you declare it to be. - Measured rate:
sdr.measured_rateis how many samples per second are arriving, measured over windows of about a second, whether receiving or not. It is None until the first window is complete (the first 0.25 s of a stream are skipped, because what the sender and the kernel buffered arrives as a burst), when nothing has arrived for 2 s, and after a client leaves. A window restarts after a pause longer than 0.5 s. If it is more than 10% off the declaredFsfor 3 windows in a row,readwarns once per client (warn.RateMismatch).Fsis never taken from it: only a sender paced in real time (a radio,rtl_tcp) arrives at its sample rate. A file replayed withnc, or a GNU Radio flowgraph without a Throttle, arrives as fast as the network allows. - Samples:
open(..., sample_format=...)with a SigMF-style name ("cf32", the default: float32 I, Q, GNU Radio'scomplex64;"ci16","ci8","cu8"forrtl_tcp-style unsigned bytes,"cu16","ci32","cf64","cf16"(IEEE half),"ci4"(I and Q nibbles in one byte, I high), optionally with_be;pysdrlib.tcpiq.FORMATSlists them) or anypysdrlib.base.convert.SampleFormat. The stream is little-endian unless the format says otherwise. A sample split across two reads is put back together. rtl_tcp: its stream starts with 12 bytes of dongle info ("RTL0", tuner type, gain count). They are recognized and skipped, not read as samples, andsdr.rtl_tcphas them ({"tuner": "R820T", "tuner_type": 5, "gain_count": 29}). Nothing is sent back: set the frequency, rate and gain on the rtl_tcp side.- Gain: none (
rx_gain_stages()is empty).
Notes¶
- It is not listed by
pysdrlib.find(): there is nothing to enumerate. - Client: a stream that ends (the server closed it) stops the receive thread, and
readthen times out.sdr.eofsays so. - The extension uses only the operating system's sockets, so there is no vendor library to build.
Modules:
| Name | Description |
|---|---|
tcpiq |
A TCP stream of raw I/Q samples (receive only), as the client or the server: see |
tcpiq ¶
A TCP stream of raw I/Q samples (receive only), as the client or the server: see pysdrlib.tcpiq
Classes:
| Name | Description |
|---|---|
TcpIq |
Samples over TCP, raw interleaved I/Q. Connect to a server that sends them ( |
TcpIq ¶
Bases: NativeDevice
Samples over TCP, raw interleaved I/Q. Connect to a server that sends them (host, port), or listen for a
client that does (listen=True). cf and Fs say what the stream is (nothing is sent back).
The socket is read on a thread of the extension's own, without the GIL, as fast as the network delivers: a sender is
never held up by Python. Samples not read within BUFFER_SECONDS are dropped (oldest first) and reported like any
native device's (on_drop, warn.Dropped).
Attributes:
| Name | Type | Description |
|---|---|---|
eof |
The server closed the stream (connected only: a listening device accepts the next client) |
|
peer |
"host:port" of the other end, or None when nothing is connected |
|
connections |
Clients accepted since |
|
reconnects |
Clients that connected while one was (listening): each took over, as a sender reconnecting after its |
|
port |
The local port (the one chosen, after listening on port 0) |
|
measured_rate |
Samples per second arriving, over the latest second or so (receiving or not), or None when not known yet |
|
rate_mismatch |
Whether |
|
rtl_tcp |
What the rtl_tcp server said about its dongle, when the stream began with rtl_tcp's 12-byte header (which |
Source code in src/pysdrlib/base/native.py
eof
property
¶
The server closed the stream (connected only: a listening device accepts the next client)
reconnects
property
¶
Clients that connected while one was (listening): each took over, as a sender reconnecting after its connection died does
measured_rate
property
¶
Samples per second arriving, over the latest second or so (receiving or not), or None when not known yet
(or nothing is arriving). Only a sender paced in real time arrives at its sample rate: this checks the declared
Fs (a warning when they disagree), it never sets it
rate_mismatch
property
¶
Whether measured_rate is more than RATE_TOLERANCE (relatively) from the declared Fs, or None while it
isn't known. The latest measurement alone: read warns (warn.RateMismatch) only after RATE_WINDOWS in a row
rtl_tcp
property
¶
What the rtl_tcp server said about its dongle, when the stream began with rtl_tcp's 12-byte header (which is skipped, not read as samples): {"tuner": name, "tuner_type": n, "gain_count": n}; None otherwise (or not yet)