Remote
pysdrlib.remote ¶
Radios hosted on one machine and used from another, over ZeroMQ (pip install pysdrlib[remote]).
A remote device is a normal pysdrlib.Device (RemoteDevice), so code written for a local radio works unchanged.
sdr.caps comes from the hosted device, and every control (set_rx_gain, set_rx_bandwidth, set_setting, a
driver's own setters such as set_rx_lna_gain...) is forwarded to it. Channels, transmit, read(meta=True) gaps and
stream() work as they do locally, and so do retunes: m.events marks a change inside a block, m.freq is the
frequency the block was received at, and set_rx_freq(f, flush=True) skips what came before (viewers see the
controller's changes the same way).
How to run a server, connect, find servers, share and relay a radio, and the pysdrlib server/relay/client/discover
command line: the Remote radios guide. This page is the reference for what those do.
Finding servers¶
A server can announce itself on the local network (mDNS / DNS-SD, as _pysdrlib._tcp, with --advertise), so clients
find it without being told its address: discover() lists the servers announcing themselves. connect with no address
asks every server it finds which of its radios fit, without opening any, and connects to the best:
- Radios are compared across servers as one server compares its own (see Saying who you are and what you need): what fits
need, nearestwant, the antenna best for the frequency, one attached before one a client left open. Of equals, a server on this machine wins (samples come through shared memory). - Every fitting radio of every server is put in one order, and
connectopens exactly the radio it ranked (the open names it,pick=): if someone took it in the meantime, the server saysBusyrather than opening its next best in its place, and the next radio in the order is tried, on whichever server it is. A radio that fails to open is passed over the same way;err.NoDevicesays why each was left out. discover_timeout=(default 2 s) is how long it listens for servers. A server too old to be asked is tried last, as is one that can open the device type asked for but has none attached (sim, say).- The announcement says only where a server is, its protocol and pysdrlib version, and whether it is a
serveror arelay(pysdrlib relay --advertise). What it has is asked of the server itself, so it is never out of date. - A server bound to every interface (
0.0.0.0) announces each of its addresses;addressis one on a network the client is on,addressesall of them. A server on127.0.0.1oripc://cannot be advertised (--advertisesays so). - Servers of another protocol version are left out (
--all-versions/all_versions=Trueshows them). - mDNS stays on the local network: a server across a router or a VPN still has to be given by address. Advertising is off
unless asked for; it makes a server easier to find, not easier to use (see Security).
avahi-browse -rt _pysdrlib._tcpsees the same announcements.
Controllers and viewers¶
A hosted device has at most one controller and any number of viewers.
| Controller | Viewer | |
|---|---|---|
| Receive samples | yes | yes |
get_* calls |
yes | yes |
| Change settings, start/stop, transmit | yes | no |
- Connecting to a device type (
pysdrlib.connect(addr, "hackrf")) starts a new device and makes you its controller.reuse=Truefirst takes over a hosted one nobody controls (a client that died without closing leaves its device open). - Connecting to a hosted device id (
pysdrlib.connect(addr, "hackrf-0")) attaches you as a viewer;claim=Truealso takes control if it is free. (pysdrlib.device("remote", addr, ...)is the same without choosing for you.)sdr.claim()takes control if nobody has it, andsdr.release()gives it back. pysdrlib server --open hackrfhosts a device at startup with no controller until a client claims it.- A controller must keep talking to the server (the client sends heartbeats itself). One that is silent for
--leaseseconds (default 15) loses control: receiving and transmitting stop, the device stays open and can be claimed again. Time the server spends on a request that holds it up (a radio slow to open) counts against nobody. - A client that finds it has lost control (a heartbeat or a call is refused) says so in its log and is a viewer from then
on:
is_controlleris False,writeraiseserr.NotController,claim()takes control again if it is free (err.Busyif not), andclose()/detach()just disconnect. - A new stream (
stop_rx,start_rx) reaches every client: viewers start over at index 0, with the channels, frequency and rate it starts at.start_rxwhile receiving changes nothing, as on a local device. A read of several channels that a restart lands in starts over on the new stream; a read of one may return the end of the old one and the start of the new in one block. - A
RemoteDeviceclosed and opened again connects as it was constructed to. Anopenthat fails after the server opened the radio closes it there.
Saying who you are and what you need¶
A program can tell the server its name and let the server pick the radio, instead of knowing which radios it has:
programis shown bypysdrlib client ADDRESS list(and in the server log) next to the radio you control, with theneed/wantyou gave, so someone who finds a radio busy can see who has it. A viewer's or claimant'sprogramis logged.serialandlabelpick a unit among the radios attached to the server (listshows them under "attached, not open" with their serials). With them, or withneed/want, the driver may be left out.needandwantare dicts offreq(Hz, or a(low, high)pair that must be tunable without a gap),rate,bandwidth(the analog filter, or the sample rate where there is none),channelsandtx. A limit a driver does not declare is taken as met.- Radios that do not meet
needare never used;err.NoDevicenames why each was left out. Of the rest, the one that meets most ofwantwins, and a radio nobody has open is preferred to taking over one a client left open and uncontrolled. Nothing is tuned for you:grantedreports what it can do, theninitializeas usual. - A radio that runs faster than a
rateyou need is usable (decimate it yourself) but never preferred: the radio nearest above wins, and a faster one is picked only when nothing runs as fast.granted["rate"]is the rate it will really run at, so check it. freqis always the frequency over the air. If the operator says (pysdrlib server --frontends FILE, JSON or TOML, seepysdrlib.remote.frontends) that an LNB, converter or antenna sits on a radio, the server maps it to the radio's own tuning,set_rx_freq/set_tx_freqtake andget_*_freqreturn the over-the-air frequency, andgrantedaddsif_freq,antennaandinverted(get_rx_inverted(): the spectrum comes mirrored). Among radios that do equally well, the one whose antenna (ANT500: a 20-88 cm 50 ohm whip, best 75 MHz to 1 GHz; add your own with akindsuch aslpdaordish, asizein metres and animpedance, all shown bylist) is best at the wantedfreqcomes first; outside its best band it is only less preferred, not refused.- Arguments to
open()(andinit_args/init_kwargs) go to the radio the server opens. A hosted radio that would be taken over is open already: withopen()arguments it is passed over, and constructor arguments are not used on it. Anopen()argument that names another unit than the one chosen (serial,index,addr) is refused. - Nothing stops a controller from tuning outside
need/want: they are for choosing and for show, not limits. - Command line:
rx --serial SN --program NAME, orrx --need rate=2e6 --freq 433.92e6 --rate 10e6(with no type).
Sample format on the wire¶
By default samples cross the network in the device's own layout (8-bit for a HackRF, ...), which is lossless and
several times smaller than complex64. The client always hands you complex64. Choose another format with
--wire / --rx-wire (server default or per rx), --tx-wire (for tx), or the wire= / tx_wire= arguments of
RemoteDevice:
native (default), complex64 (float32), int8, uint8, int12, int12p (packed), int16
A narrower format than the device's own loses precision; one wider only costs bandwidth.
Sharing a radio between programs on one machine¶
Run pysdrlib server next to the radio and let each program connect to it: one program controls the radio, any number of
others watch (see Controllers and viewers). A program on the server's machine takes the samples from shared memory
by default (transport="auto"), so the cost of serving one reader or five is almost the same:
- The server keeps one ring of
complex64samples per streaming channel (a quarter second at the device's top rate) in shared memory and tells readers when it has written. Each reader has its own place in it: a reader that falls behind loses the samples it was too slow for, and sees that inread(..., meta=True)(m.gaps,m.dropped) like any other loss. It never slows the radio, the server, or another reader. - A client starts on the position of the block it first hears of; the one that called
start_rx, and any attached when a stream starts, reads from its first sample. When the controller restarts the stream (stop_rx,start_rx) readers move to its new ring and indices start again from 0. - A client on another machine, or one that cannot attach the segment, takes blocks over the socket as before, with no
setting.
transport="zmq"forces that;transport="shm"insists on shared memory (err.NotSupportedif there is none).pysdrlib server --no-shm(orServer(shm=False)) doesn't offer it. - The server only does the work of a way somebody is using: it writes the ring while a client reads from it, and encodes and sends blocks while one takes them over the socket.
- Rings live in
/dev/shm(namedpsdr-...) and are removed when the stream is restarted, the device is closed or the server stops. If a very large ring would not fit in/dev/shmthe server makes a smaller one, or none (then clients use the socket). A server killed outright can leavepsdr-*files there; deleting them is safe when it is not running.
Measured with the simulated radio, with reader processes on the same stream (CPU as a share of one core):
| Stream | Readers | Socket (server + readers) | Shared memory (server + readers) |
|---|---|---|---|
| 20 MS/s | 1 | 25% | 21% |
| 20 MS/s | 4 | 66% | 48% |
| 61.44 MS/s | 1 | 35% | 29% |
| 61.44 MS/s | 4 | 94% | 62% |
The server's share is flat in the number of readers with shared memory (13% at 20 MS/s whether one reads or four) where
over the socket it grows. What each reader still costs is mostly the array read() allocates and fills; read_into with
your own buffer avoids the allocation.
Relaying a radio on another machine to programs here¶
Several programs on a machine that is not the radio's would each pull their own copy of the stream across the network, and a B210 at 61 MS/s in its native layout is already about 245 MB/s (2 Gb/s) for one. A relay is a server on this machine that hosts the far device: it takes the stream once, and the programs here share it through shared memory.
- It hosts the device under the far device's own id, and the programs use it like any other hosted device: the same API, the same controller and viewer rules (those of the relay, among the programs on this machine).
- Control passes through. When the far device is free the relay takes control of it and local control calls reach it. If
someone else controls it the relay only watches: programs here can receive but not change anything (
NotController).--control yesinsists (an error if it is taken),--control noalways only watches.--open TYPEopens a new far device instead, which closing the relay closes; otherwise closing it gives control back and the far device carries on. - A relay follows the far device: a stream someone else starts or stops there starts or stops here, and a restarted stream starts over for programs here too.
- The far samples travel in the far device's own layout (8-bit for a HackRF), as to any client, and are shared here as
complex64. Transmitting works when the relay has control. The relay adds a hop: its server publishes in batches of about 2 ms, so expect a few milliseconds more than a direct connection (not measured). - What goes wrong far away shows here: a device the far server reports stalled, lost or failing, and a far server that
has stopped answering (
lost), make a localreadraiseerr.StreamStalledorerr.Lost, as with a direct connection. - It does not reconnect: when the far server stops answering (about two timeouts)
pysdrlib relayexits with an error, so a supervisor can restart it. From Python,worker.lostis set andlistshowslost.Server.relay(address, device)does the same inside your own server.
What it saves is the network: the far server sends one stream however many programs listen here. On a machine with no network between them (measured with the simulated radio, the far server in its own process) the CPU is about even:
| Stream | Readers | Directly: far server / all | Through a relay: far server / relay / all |
|---|---|---|---|
| 20 MS/s | 4 | 15% / 49% | 12% / 9% / 48% |
| 61.44 MS/s | 1 | 20% / 34% | 21% / 16% / 47% |
| 61.44 MS/s | 4 | 31% / 100% | 22% / 18% / 86% |
So a relay costs a little for one program, and pays for itself from two or three, and mostly in bandwidth.
Monitoring¶
Each hosted device counts what passes through it. pysdrlib client ADDRESS stats shows it, and Client.metrics()
returns it (--json prints the same dict):
rx: samples published, blocks and bytes sent on the socket (in the wire format), shared-memory notices, and how many clients subscribe over the socket and over shared memory.device: the radio's own stream counts while it receives: samples delivered,dropped(the server fell behind),missing(the radio didn't deliver at its rate), stalls.tx: samples and blocks transmitted, blocksrefused(not from the controller, or not transmitting), and the device's transmit stats.control: calls answered and failed. A relay addsupstream.dropped_blocks: blocks lost between the far server and the relay.
So lost samples can be placed: dropped_blocks on a client (the network or a slow client), device.dropped (the
server's host), device.missing (the radio or its USB link). pysdrlib server and pysdrlib relay also log a line per
streaming device every --stats-interval seconds (default 60; 0 turns it off): the rate published, subscribers, and
what the device dropped or missed since the last line.
Security¶
There is no authentication or encryption. The controller token only stops two clients from stepping on each other;
anyone who can reach the server can list devices, receive samples, and claim any uncontrolled device. The server binds
to 127.0.0.1 unless told otherwise. Use --bind tcp://0.0.0.0:5555 only on a network you trust, or tunnel the ports
(SSH, a VPN).
What a stranger who reaches the sockets can do is still bounded:
- A client passes a driver a serial, an index, a UHD radio's
addrand a simulated radio's signal, and nothing else: the arguments that name a host (tcpiq'shost,listen), a file (file'spathandtx_path,shm'sdirectory) or a device string (UHD'sargs) are the operator's.--open TYPE:KEY=VALUEopens such a device at startup;--allow-arg TYPE:KEY,KEY(Server(client_args=...)) lets clients choose those keys, and then a client can make the server read, write and connect as it says: allow them only to clients you would give a shell. - A
serial,serial_numberoraddra client gives is text with no,,=or control character, and anindexa whole number: a driver may build a device string from them, which they must not be able to add to. - A server hosts at most
--max-devices(32) devices, refuses a request over 1 MiB (a block to transmit over 4 MiB), and answers a request of the wrong shape with an error. A message that is not a single request frame does not stop it. - Each read
find_gainmakes through a server (count,confirm,skip) is at most 4 Mi samples and waits at most 30 s, andpump,sweepandfindare not remote methods. - A subscription only counts when it is one of the device's own two topics, and an unsubscribe only when the last
subscriber of a topic has gone, so
socket_subscribersis "someone is subscribed", not an exact count. - Streams in shared memory: the manifest directory is private to the user (
0700) and one that another user owns, or anyone can write to, is not believed; a reader refuses a ring whose header the segment cannot hold.
What it cannot stop: anyone who can reach the sockets can still list devices, claim any free one, receive every stream
and consume the server's CPU and bandwidth. A slow open (a radio that takes seconds to come up) still holds the C2
thread while it opens.
Layout¶
| File | Contents |
|---|---|
remote/server.py |
Server (the C2 socket: lifecycle and ownership) and DeviceWorker (one hosted device's sockets) |
remote/client.py |
Client (discovery) and RemoteDevice (a Device backed by a server) |
remote/server.py also has |
RelayWorker, a device of another server hosted here (Server.relay) |
pysdrlib.shm |
ShmWriter (the server's ring in shared memory) and ShmReader (a client's view of it), in shm/ring.py; the ring is C++ in _native/include/hardware_shm.hpp |
remote/discovery.py |
Advertiser (a server's mDNS announcement) and discover |
remote/protocol.py |
Wire format: message framing, sample block headers, wire formats. The file documents the sockets |
remote/cli.py |
The pysdrlib command |
Per hosted device the server runs a control socket (ROUTER), an RX stream (PUB) and a TX stream (PUSH);
see remote/protocol.py for the details. Tests are in tests/test_remote.py.
Modules:
| Name | Description |
|---|---|
choose |
Choosing a radio by what a program needs, without knowing which radios a server has. |
cli |
Command line for the remote server, relay and client |
client |
pysdrlib client: use a device hosted by a pysdrlib server like a local one. |
discovery |
Finding servers on the local network with mDNS / DNS-SD (needs |
frontends |
What sits between each radio of a server and the air: LNBs, converters, antennas |
protocol |
pysdrlib remote protocol. |
server |
pysdrlib server: hosts hardware SDRs for remote clients. |
choose ¶
Choosing a radio by what a program needs, without knowing which radios a server has.
A client says what it needs (need: below this it is of no use) and what it would like (want):
pysdrlib.connect(addr, program="pyspecan", need={"freq": 433e6, "rate": 2e6}, want={"freq": 433.92e6, "rate": 10e6})
Both are dicts with any of these keys:
freq Hz over the air to tune to, or a (low, high) pair of Hz the radio has to be able to tune across without a gap
(through whatever LNB or converter the server says is on the radio: see `Chain`)
rate samples/s; a radio can run at it or faster (the client decimates), never slower
bandwidth Hz of spectrum seen (the analog filter where the radio has one, else its sample rate)
channels how many channels
tx True if it must be able to transmit
A radio is a candidate when it meets all of need. Of the candidates the one that misses the fewest keys of want, and
then comes nearest to it, wins; a radio whose capabilities are unknown comes after every one whose are known. A freq pair
means the radio can tune across the whole span (retuning between its ends), not that it sees all of it at once: that is
bandwidth. More rate or bandwidth than want asks for is no miss (only a small cost, growing with how much more, so
the radio nearest above wins); less is. Of radios that do equally well, the one whose antenna is best at the wanted frequency
comes first. What the radio can actually do nearest to want (and need) is reported back as granted: the rate it will really run at, and
for a radio behind a converter the frequency it tunes (if_freq), the antenna port and whether the spectrum is inverted.
This module is pure functions of pysdrlib.base.caps.Capabilities: no sockets, no hardware.
Functions:
| Name | Description |
|---|---|
normalize |
|
problems |
What of |
granted |
What the radio can do nearest to |
score |
(keys missed, shortfall) of the radio against |
shortfall |
How far the radio is from |
known |
Whether |
antenna_off |
How far the antenna(s) the radio would use for |
rank |
Sort key of a radio that meets |
met |
Whether the radio meets all of |
normalize ¶
spec as a clean dict (None -> {}); raises ValueError for a key or value that makes no sense
Source code in src/pysdrlib/remote/choose.py
problems ¶
What of spec the radio described by caps cannot do, as sentences (empty: it meets all of it).
A limit the radio does not declare is taken as met.
Source code in src/pysdrlib/remote/choose.py
granted ¶
What the radio can do nearest to spec: for each key the value it would give (a frequency pair is the span clipped
to what it tunes; a rate is the slowest it runs at that is not below the asked one, else its top; a key the radio puts no
limit on keeps the asked value). Through a converter the frequency is still over the air, with if_freq (what the radio
tunes), antenna and inverted beside it
Source code in src/pysdrlib/remote/choose.py
score ¶
(keys missed, shortfall) of the radio against spec: how many keys it cannot meet, and how far from them it is as
the share of each unmet key (so 1.0 is one key missed entirely), summed. (0, 0.0) meets all of spec. Rate above
what was wanted costs a little and is not a miss.
Source code in src/pysdrlib/remote/choose.py
shortfall ¶
How far the radio is from spec, 0.0 when it meets all of it (see score). Orders radios that all meet need.
known ¶
Whether caps says anything about what the radio tunes or samples. One that does not (a driver that declares nothing,
or a radio whose capabilities could not be read) meets every limit by default, so it is ranked after those that do.
Source code in src/pysdrlib/remote/choose.py
antenna_off ¶
How far the antenna(s) the radio would use for want are from their best at the wanted frequency: 0.0 when optimal there or
when nothing says (see Chain.optimal)
Source code in src/pysdrlib/remote/choose.py
rank ¶
Sort key of a radio that meets need, smallest best: unknown capabilities last, then fewest keys of want missed, then
nearest, then the antenna nearest its best at the wanted frequency
Source code in src/pysdrlib/remote/choose.py
cli ¶
Command line for the remote server, relay and client
pysdrlib server --bind tcp://0.0.0.0:5555 --port-range 6000-6100 --devices <driver1>,<driver2>
pysdrlib client tcp://host:5555 list
pysdrlib client tcp://host:5555 info <driver>-0
pysdrlib client tcp://host:5555 rx <driver> --freq 100e6 --rate 10e6 -o out.cfile -t 5
pysdrlib client tcp://host:5555 rx --serial <serial> --program myapp -o out.cfile -t 5
pysdrlib client tcp://host:5555 rx --need freq=433e6 --need rate=2e6 --freq 433.92e6 --rate 10e6 -o out.cfile -t 5
pysdrlib client tcp://host:5555 watch <driver>-0 -o out.cfile -t 5
pysdrlib client tcp://host:5555 rx <driver> --freq 433.92e6 --rate 2e6 -f ci8 -o capture.sigmf -t 10
pysdrlib client tcp://host:5555 tx <driver> -i out.cfile --freq 915e6 --rate 2e6 --tx-gain 0 --tx-wire int8
pysdrlib client tcp://host:5555 set <driver>-0 rx_freq=101e6 rx_lna_gain=16
pysdrlib relay tcp://host:5555 <driver>-0 --bind tcp://127.0.0.1:5556 # programs here share one connection to it
Recordings are raw complex64 (GNU Radio .cfile) by default; -f picks another format (ci16, ci8, cu8...), and an
output ending in .sigmf (or --sigmf) records SigMF, with the rate, frequency, retunes and lost samples in its
metadata. Transmit files are raw complex64.
--rx-wire / --tx-wire choose the format samples cross the network in (native = the device's own layout).
Functions:
| Name | Description |
|---|---|
add_parsers |
Add the |
build_parser |
A parser of just the remote commands, for |
run_server |
|
run_relay |
|
format_chain |
A chain as one line for |
print_list |
Print what the server |
run_discover |
|
print_stats |
|
run_client |
|
run |
Run the command |
main |
The remote commands on their own ( |
add_parsers ¶
Add the server, relay and client commands to the subparsers of the pysdrlib command
Source code in src/pysdrlib/remote/cli.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
build_parser ¶
A parser of just the remote commands, for main here
Source code in src/pysdrlib/remote/cli.py
run_server ¶
pysdrlib server: host devices until Ctrl+C or SIGTERM. Logs to stderr (the journal, under systemd)
Source code in src/pysdrlib/remote/cli.py
run_relay ¶
pysdrlib relay: host a far device here until Ctrl+C, or until the far server stops answering
Source code in src/pysdrlib/remote/cli.py
format_chain ¶
A chain as one line for list: its direction, port, the LO it has and the antenna on it
Source code in src/pysdrlib/remote/cli.py
print_list ¶
Print what the server c (a Client) allows, hosts and has attached, as client ADDRESS list does
Source code in src/pysdrlib/remote/cli.py
run_discover ¶
pysdrlib discover: the servers announcing themselves here, and with --list what each has
Source code in src/pysdrlib/remote/cli.py
print_stats ¶
client stats: one paragraph per hosted device
Source code in src/pysdrlib/remote/cli.py
run_client ¶
pysdrlib client: list, info, stats, rx, watch, set and tx
Source code in src/pysdrlib/remote/cli.py
run ¶
Run the command args names (server, relay or client); errors exit with a message instead of a traceback
Source code in src/pysdrlib/remote/cli.py
main ¶
client ¶
pysdrlib client: use a device hosted by a pysdrlib server like a local one.
sdr = pysdrlib.device("remote", "tcp://host:5555", "hackrf") # a device type: this client controls it
sdr.open()
sdr.initialize(cf=100e6, Fs=10e6)
sdr.start_rx()
samples = sdr.get_samples()
view = pysdrlib.device("remote", "tcp://host:5555", id="hackrf-0") # an already hosted device: a viewer
view.open() # can read samples and `get_*`; view.claim() to take control if it is free
RemoteDevice is a Device, so code written for a local device works unchanged. Any other public
method of the hosted device (e.g. its per-stage gain setters) is reachable by name too.
Classes:
| Name | Description |
|---|---|
Client |
Talks to a server's C2 socket: discovery. Use |
RemoteDevice |
|
Client ¶
Talks to a server's C2 socket: discovery. Use RemoteDevice to work with a device.
Methods:
| Name | Description |
|---|---|
types |
Device types the server can open |
list |
Devices the server currently hosts |
available |
Radios attached to the server's machine as of its last scan: dicts with |
metrics |
What the server's devices (or the one with id |
candidates |
The server's radios that fit the request, best first, without opening any (see |
close |
Close the connection |
Source code in src/pysdrlib/remote/client.py
types ¶
list ¶
available ¶
Radios attached to the server's machine as of its last scan: dicts with driver, label, serial, index and
hosted (the id of the device that has it open, or None)
Source code in src/pysdrlib/remote/client.py
metrics ¶
What the server's devices (or the one with id device) have passed since hosted: see Server.metrics
candidates ¶
The server's radios that fit the request, best first, without opening any (see Server.candidates); raises
err.NoDevice saying why when none do
Source code in src/pysdrlib/remote/client.py
RemoteDevice ¶
RemoteDevice(address: str, device=None, *, id=None, timeout=DEFAULT_TIMEOUT, init_args=(), init_kwargs=None, wire=None, tx_wire='native', transport='auto', program=None, serial=None, label=None, need=None, want=None, pick=None)
Bases: Device
address: server C2 endpoint, e.g. tcp://host:5555
device: device type to open on the server (this client becomes its controller)
id: id of an already hosted device to attach to (as a viewer) instead
program: the name of the program you are running: the server shows it in list and its log, so others can tell who
has a radio
serial, label: which unit to open: the serial number, or part of the label (pysdrlib client ADDRESS list shows both).
With these, device may be left out to take a unit of any driver.
need, want: what the program needs (a radio that cannot is not used) and would like: dicts with freq (Hz, or a
(low, high) pair), rate, bandwidth, channels, tx. The server opens the best radio that meets need
(or takes over a free hosted one); granted says what it can do nearest to want and need.
pick: the key of one of Client.candidates: open that radio and no other (err.Busy if it has been taken since).
init_args/init_kwargs: passed to the device type's constructor on the server
wire: RX wire format to request when opening a device type (default: the server's, normally the
device's native layout). See set_wire.
tx_wire: wire format the TX stream is sent in: "native" (the device's own layout, lossless: the device
quantises to it anyway, and it is several times smaller than complex64), "complex64", "int8", ...
See set_tx_wire.
transport: how samples reach this client. "auto": from shared memory when the server is on this machine and
offers it (any number of clients then read one copy, each at its own pace), else over the socket; "zmq":
always over the socket; "shm": shared memory, or err.NotSupported.
Methods:
| Name | Description |
|---|---|
open |
Connect to the server. For a device type: opens it on the server (args/kwargs go to the device's |
close |
Disconnect. The controller also closes the device on the server; a viewer just detaches. |
detach |
Disconnect without closing the hosted device ( |
claim |
Become the controller of an attached device (raises |
release |
Give up control (stops RX/TX on the server); stay attached as a viewer |
refresh |
Update |
set_wire |
Choose the RX stream's wire format for everyone watching: "native" (the device's own layout, |
set_tx_wire |
Choose the wire format of the TX stream this client sends (it is the controller's alone, so this is local): |
get_rx_context |
How the hosted radio receives on this channel ( |
get_chains |
The hosted radio's chains, from the server's frontends file ( |
set_chains |
A server's chains are the operator's: its frontends file ( |
get_samples |
All samples of the first streaming channel received since the last call. Waits up to |
Attributes:
| Name | Type | Description |
|---|---|---|
tx_wire_name |
Name of the format TX blocks are sent in right now (with "native" resolved to the device's layout) |
|
caps |
The hosted device's capabilities (fetched once per connection) |
|
stats |
StreamStats
|
What this client has received of the first channel since |
Source code in src/pysdrlib/remote/client.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
tx_wire_name
property
¶
Name of the format TX blocks are sent in right now (with "native" resolved to the device's layout)
stats
property
¶
What this client has received of the first channel since start_rx: samples, dropped (lost between the
server and here: blocks the socket dropped, or samples a slow reader was lapped for in shared memory) and age (since
the server last wrote). missing and stalls are counted by the server's own device, not here
open ¶
Connect to the server. For a device type: opens it on the server (args/kwargs go to the device's open)
Source code in src/pysdrlib/remote/client.py
close ¶
Disconnect. The controller also closes the device on the server; a viewer just detaches.
Source code in src/pysdrlib/remote/client.py
detach ¶
Disconnect without closing the hosted device (close closes it, if this client controls it). A controller
gives up control first, which stops what it had running, as release does
Source code in src/pysdrlib/remote/client.py
claim ¶
Become the controller of an attached device (raises err.Busy if it has one)
Source code in src/pysdrlib/remote/client.py
release ¶
Give up control (stops RX/TX on the server); stay attached as a viewer
Source code in src/pysdrlib/remote/client.py
refresh ¶
Update state, CF and Fs from the server (a viewer sees what the controller does)
Source code in src/pysdrlib/remote/client.py
set_wire ¶
Choose the RX stream's wire format for everyone watching: "native" (the device's own layout, lossless), "complex64", "int8", "int16", ... Narrower than the device's native is lossy. Controller only. Returns the format name.
Source code in src/pysdrlib/remote/client.py
set_tx_wire ¶
Choose the wire format of the TX stream this client sends (it is the controller's alone, so this is local): "native" (the device's own layout, lossless), "complex64", "int8", "int16", ... Narrower than the device's native is lossy. Returns the format name.
Source code in src/pysdrlib/remote/client.py
get_rx_context ¶
How the hosted radio receives on this channel (RxContext; see Device.get_rx_context). Raises
err.NotSupported from a server whose pysdrlib is older than 0.5.1
Source code in src/pysdrlib/remote/client.py
get_chains ¶
set_chains ¶
A server's chains are the operator's: its frontends file (pysdrlib server --frontends)
get_samples ¶
All samples of the first streaming channel received since the last call. Waits up to timeout seconds
for the first block. See read for exact counts, several channels and stream metadata
Source code in src/pysdrlib/remote/client.py
discovery ¶
Finding servers on the local network with mDNS / DNS-SD (needs zeroconf: pip install pysdrlib[remote])
A server started with advertise=True (pysdrlib server --advertise) announces itself as a _pysdrlib._tcp service;
discover() lists the ones that answer. The announcement only says where a server is (and its protocol version): ask it
what it has with Client(address).list() as usual. mDNS does not cross routers, so a server on another subnet or over a
VPN still has to be given by address.
Classes:
| Name | Description |
|---|---|
NotAdvertisable |
The server's endpoint is not one other machines could use (ipc://, loopback, or a host that does not resolve) |
Advertiser |
Announces a server's C2 endpoint on the local network until |
Functions:
| Name | Description |
|---|---|
discover |
Servers announcing themselves on the local network, after listening for |
rank |
Ask each of |
NotAdvertisable ¶
Bases: ValueError
The server's endpoint is not one other machines could use (ipc://, loopback, or a host that does not resolve)
Advertiser ¶
Announces a server's C2 endpoint on the local network until stop
endpoint: the bound C2 endpoint (Server.endpoint). name: the instance name shown by discover (default: the
host name, with " relay" for a relay; a name already taken gets a number added). kind: "server" or "relay".
Methods:
| Name | Description |
|---|---|
stop |
Withdraw the announcement (clients see the server go at once) and close |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
The instance name in use (it may differ from the one asked for when that was taken) |
Source code in src/pysdrlib/remote/discovery.py
discover ¶
Servers announcing themselves on the local network, after listening for timeout seconds.
Each is a dict: name, address (a C2 endpoint to give Client or pysdrlib.connect: one on a network this machine
is on, when there is one), addresses (every endpoint it announced, for a server on several networks), host, kind ("server" or "relay"), proto and version.
Servers speaking another protocol version than this pysdrlib are left out unless all_versions.
Source code in src/pysdrlib/remote/discovery.py
rank ¶
Ask each of servers (from discover) for its radios that fit the request, without opening any.
-> (choices, hosting, reasons): choices every radio that fits on any server, best first (by choose.rank, then one
attached before one a client left open, then one on this machine, which can share samples through shared memory), as
dicts of its server and the candidate (from Client.candidates: open it with its key as pick). A server too old
to be asked, or that has no device attached but can open one (as a plain connect(address, device) would), is there
once with candidate None, after the rest; hosting the
servers that host a device whose id is device; reasons why each other server was left out, as text.
Source code in src/pysdrlib/remote/discovery.py
frontends ¶
What sits between each radio of a server and the air: LNBs, converters, antennas
An operator describes it once, in a JSON file (TOML also works) given to pysdrlib server --frontends FILE, and clients
just ask for the over-the-air frequency they want (see choose, pysdrlib.base.caps.Chain):
{
"antenna": { // antenna standards of your own (ANT500 is built in); usable/optimal: [low, high] Hz
"MYLPDA": {"optimal": [[430e6, 440e6]],
"kind": "lpda", // whip, dipole, biconical, lpda, yagi, dish, horn, discone, patch, helical, loop, or any text
"size": [0.5, 0.9], // metres: what the kind measures (boom length for lpda, diameter for dish)
"impedance": 50} // ohms
},
"radio": [{ // picked by any of driver, serial and label (a part of it, case ignored); first match wins
"serial": "0123ABCD",
"chain": [{
"direction": "rx", // rx or tx
"port": "RX2", // the radio's antenna port it is behind (leave out: any port)
// "channel": 1, // the radio's channel it is on (leave out: any): ports of one name on two channels
// "polarization": "H", // what the feed takes in: H, V, RHCP or LHCP (leave out: not said)
"antenna": "ANT500",
"lo": 9.75e9, // external LO, Hz (leave out: none): the radio tunes RF - lo, as behind an LNB
// "lo_accuracy": 25e3, // how well lo is known, Hz (a standard error; a measured LO's)
"name": "universal LNB"
// "invert": true // the LO is above the signal instead: radio tunes lo - RF, spectrum mirrored
// "usable": [[10.7e9, 12.75e9]], "optimal": [[11e9, 12e9]] // override the antenna's
}]
}]
}
(Comments and e notation are for reading here: JSON proper has neither, so write 9750000000 and no comments.) The file is
read as JSON, unless its name ends in .toml; one that is not valid JSON is tried as TOML, with the same keys
([antenna.MYLPDA], [[radio]], [[radio.chain]]).
Classes:
| Name | Description |
|---|---|
Frontends |
The chains each radio has, by what picks the radio out. |
Functions:
| Name | Description |
|---|---|
parse |
A |
load |
Read a frontends file: JSON, or TOML when the name ends in |
Frontends ¶
The chains each radio has, by what picks the radio out. radios: [({driver/serial/label: text}, [Chain])]
Methods:
| Name | Description |
|---|---|
chains_for |
The chains of the first radio entry that matches this radio ([] when none does) |
apply |
|
Source code in src/pysdrlib/remote/frontends.py
chains_for ¶
The chains of the first radio entry that matches this radio ([] when none does)
Source code in src/pysdrlib/remote/frontends.py
apply ¶
caps with the chains this radio has (itself, if it has none)
Source code in src/pysdrlib/remote/frontends.py
parse ¶
A Frontends from what json or tomllib read (registers the antennas it defines). Raises ValueError saying what is wrong
Source code in src/pysdrlib/remote/frontends.py
load ¶
Read a frontends file: JSON, or TOML when the name ends in .toml or it is not valid JSON. Raises ValueError (with the
file's name) when it cannot be read or is wrong
Source code in src/pysdrlib/remote/frontends.py
protocol ¶
pysdrlib remote protocol.
Three kinds of socket, all ZeroMQ:
C2 (server -> ROUTER, client -> DEALER) lifecycle: list / open / attach / claim / release / close / ping
device control (ROUTER <-> DEALER) one per hosted device: capabilities, state, method calls
device RX stream (PUB -> SUB) one per hosted device: sample blocks, every channel the device streams
(or, for a client on the same host, notices of blocks in shared memory)
device TX stream (PUSH -> PULL) one per hosted device: sample blocks to transmit (controller only)
Requests and replies on the C2 and control sockets are single-frame JSON:
request {"id": int, "op": str, ...op specific}
reply {"id": int, "ok": true, "result": ...}
{"id": int, "ok": false, "error": {"type": str, "msg": str, "reason"?: str}} (reason: err.NoDevice's)
Sample blocks are 3 frames: [topic, header, payload]. topic is the device id (SUB prefix filter) on the RX stream
and the controller's token on the TX stream, header is HEADER (below) and payload is nsamples interleaved I/Q
samples in the layout the header describes: a convert.SampleFormat. The header also says which channel the block is
and the stream index of its first sample (samples since start_rx), so a client keeps channels apart and aligned, and
sees where samples were lost. By default that is the device's own native layout (8-bit for a
HackRF, ...), which is lossless and several times smaller than complex64; clients always hand the
caller complex64. The same goes for the TX stream: the controller sends blocks in the device's native layout
by default (or any other wire format) and the server decodes whatever the header says. The format may change
between blocks (the controller can switch it), so it is read from every header.
A client on the same machine as the server can take the samples from shared memory instead (pysdrlib.shm.ring): per streaming
channel the server keeps a ring of complex64 samples in a shared-memory segment that any number of clients read, each at
its own pace. They subscribe to the topic shm:<device id> rather than the device id, and get a notice for each
block published: 3 frames like a block, with FLAG_SHM in the header (channel, index of the first sample, count) and
the name of the segment as the payload (empty: the server could not make one, so use the other topic). The server
encodes and sends full blocks only while someone subscribes to the device id.
Changes to the stream (a retune, a new gain, a flush) go to both topics as events: FLAG_EVENT in the header and a
JSON payload {"seq": n, "events": [[index, kind, value, channel], ...], "discard": index, "gen": g}, published before any
sample from after the change. gen numbers the device's streams. A new stream (indices from 0) begins with an event
that also has "start": {"channels": [...], "freq": [[channel, Hz], ...], "rate": [[channel, S/s], ...]}, published
before its first sample and sent in the reply to the start_rx that made it: a client then drops what it knew of the
last stream, ignores changes of an earlier gen, and drops blocks and notices that were still on their way. gen and
start are additions to protocol 4: a 0.5.2 client ignores them, and from a 0.5.2 server, which sends neither, a
client tells a new stream by its indices going back. A call of start_rx says "keeps_stream": true if the client
keeps what it has received when the device is receiving already; for one that doesn't (0.5.2), the server then moves
the stream to new rings. The reply to the call that made the change carries it too ("stream"), so the caller
has it before its next read. A client applies each seq once, as a local device would, so read(meta=True) reports
retunes inside a block and set_rx_freq(..., flush=True) skips what came before. Blocks and notices are numbered
separately, each from 0.
Endpoints handed out by the server may contain {host}, which the client replaces with the host
it used to reach the C2 socket (so a server bound to 0.0.0.0 doesn't need to know its own address).
Functions:
| Name | Description |
|---|---|
mismatch |
Why this side (protocol |
jsonable |
json.dumps default: numpy scalars/arrays, a few containers, and objects with a |
pack |
JSON-encode a request or reply message |
unpack |
Decode a message. Raises |
ok |
A success reply to request |
fail |
An error reply to request |
raise_error |
Raise the exception described by a reply's |
wire_format |
Name -> SampleFormat, e.g. "int8". |
wire_name |
SampleFormat -> its wire name, or its description if it has none |
resolve_wire |
The format to publish |
pack_block |
complex64 samples -> (header bytes, payload buffer) in wire format |
pack_notice |
-> (header bytes, payload bytes): a block of |
unpack_notice |
-> (seq, timestamp, channel, index, count, segment name) of a notice; |
change |
A change to the receive stream (see the module docs): |
pack_event |
-> (header bytes, payload bytes): a |
is_event |
Whether a message on the RX stream is an event ( |
unpack_event |
The |
unpack_block |
-> (seq, timestamp, complex64 samples, channel, index of the first sample or None) |
is_readonly |
Methods a viewer (no controller token) may call |
mismatch ¶
Why this side (protocol version, pysdrlib package) and peer ("server" or "client", running protocol
peer_version and pysdrlib peer_package) can't talk, naming the one to update; None when they can
Source code in src/pysdrlib/remote/protocol.py
jsonable ¶
json.dumps default: numpy scalars/arrays, a few containers, and objects with a json()
Source code in src/pysdrlib/remote/protocol.py
pack ¶
unpack ¶
Decode a message. Raises err.ProtocolError if it isn't a JSON object
Source code in src/pysdrlib/remote/protocol.py
ok ¶
A success reply to request req_id. stream: the change the request made to the receive stream, if any (the
caller applies it before its next read, rather than wait for it on the stream)
Source code in src/pysdrlib/remote/protocol.py
fail ¶
An error reply to request req_id; the client re-raises it as the same pysdrlib error type
Source code in src/pysdrlib/remote/protocol.py
raise_error ¶
Raise the exception described by a reply's error
Source code in src/pysdrlib/remote/protocol.py
wire_format ¶
Name -> SampleFormat, e.g. "int8".
Source code in src/pysdrlib/remote/protocol.py
wire_name ¶
SampleFormat -> its wire name, or its description if it has none
resolve_wire ¶
The format to publish device's samples in: "native" is its own SAMPLE_FORMAT (complex64 if it has none)
Source code in src/pysdrlib/remote/protocol.py
pack_block ¶
pack_block(seq: int, timestamp: float, samples: ndarray, fmt: SampleFormat = convert.FLOAT32, channel=0, index=None)
complex64 samples -> (header bytes, payload buffer) in wire format fmt
Source code in src/pysdrlib/remote/protocol.py
pack_notice ¶
-> (header bytes, payload bytes): a block of count samples from stream index index is in the shared-memory
segment name (see the module docs)
Source code in src/pysdrlib/remote/protocol.py
unpack_notice ¶
-> (seq, timestamp, channel, index, count, segment name) of a notice; err.ProtocolError if it isn't one
Source code in src/pysdrlib/remote/protocol.py
change ¶
A change to the receive stream (see the module docs): events are (index, kind, value, channel) as Device
records them, discard the stream index before which samples are settling or flushed, seq numbers the changes of
a device (a client applies each once: it may get one both in a reply and on the stream). gen: the number of the stream
it changes; start: how that stream starts, in the first change of one (see the module docs)
Source code in src/pysdrlib/remote/protocol.py
pack_event ¶
-> (header bytes, payload bytes): a change on the RX stream. Sent on both topics, ahead of any sample published
after it
Source code in src/pysdrlib/remote/protocol.py
is_event ¶
Whether a message on the RX stream is an event (pack_event) rather than samples or a notice
unpack_event ¶
unpack_block ¶
-> (seq, timestamp, complex64 samples, channel, index of the first sample or None)
Source code in src/pysdrlib/remote/protocol.py
server ¶
pysdrlib server: hosts hardware SDRs for remote clients.
server = Server("tcp://0.0.0.0:5555", port_range=(6000, 6100))
server.serve_forever() # or server.start() ... server.stop()
The C2 socket (the address given to Server) manages lifecycle and ownership. Every hosted device
gets its own control socket and RX stream socket on separate ports, each served by its own
threads, so a slow call on one device never blocks another. See protocol for the wire format.
Ownership: a device has at most one controller (the holder of its token) and any number of viewers.
Viewers may subscribe to RX and call get_* methods. A controller that stops talking to the server
for lease seconds loses control (RX/TX are stopped, the device stays open and can be claimed).
Samples reach clients two ways. A client on another machine subscribes to the device's id and gets blocks of samples over
the socket. One on this machine can take them from shared memory instead (see shm), which costs the server one copy
of each block however many clients there are: it keeps a ring per streaming channel and tells subscribers when it has
written. The server only does the work of a way someone is using.
Classes:
| Name | Description |
|---|---|
DeviceWorker |
One hosted device: its control socket, RX stream socket, and ownership state |
RelayWorker |
A device hosted by another server, hosted here: a relay |
Server |
|
DeviceWorker ¶
DeviceWorker(server: Server, dev_id: str, dtype: str, device, wire='native', shm=True, shm_samples=None)
One hosted device: its control socket, RX stream socket, and ownership state
Methods:
| Name | Description |
|---|---|
claim |
Make a new controller token the owner. Raises |
is_controller |
Whether |
touch |
Note that the controller is still there (renews its lease) |
release |
Drop the controller; stop streaming since nobody is left to manage it. |
serial |
The serial number of the radio, when the driver or the scan told us it |
status |
What |
metrics |
What has passed through since the device was hosted: samples published (to how many subscribers, over the |
close |
Stop serving and close the hardware |
Source code in src/pysdrlib/remote/server.py
claim ¶
Make a new controller token the owner. Raises err.Busy if the device already has a controller
Source code in src/pysdrlib/remote/server.py
is_controller ¶
touch ¶
release ¶
Drop the controller; stop streaming since nobody is left to manage it. wait=False: stop it in the background, so a radio slow to stop holds up nobody (the C2 thread answers everyone). A controller that claims the radio before that happens keeps its stream.
Source code in src/pysdrlib/remote/server.py
serial ¶
The serial number of the radio, when the driver or the scan told us it
Source code in src/pysdrlib/remote/server.py
status ¶
What list shows clients: id, type, name, state, frequency, sample rate, wire format and whether it is controlled.
While a call into the device is under way (a slow stop_rx...), the last status seen, with busy set
Source code in src/pysdrlib/remote/server.py
metrics ¶
What has passed through since the device was hosted: samples published (to how many subscribers, over the socket and in shared memory), what the device itself dropped or missed, what was transmitted, control calls. For a dashboard, or to tell a network problem (dropped_blocks on a client) from a radio's (device.dropped)
Source code in src/pysdrlib/remote/server.py
close ¶
Stop serving and close the hardware
Source code in src/pysdrlib/remote/server.py
RelayWorker ¶
RelayWorker(server: Server, dev_id: str, upstream: RemoteDevice, owns: bool, shm=True, shm_samples=None)
Bases: DeviceWorker
A device hosted by another server, hosted here: a relay
Programs on this machine connect here instead of to the far server, and the far server sees one client however many
there are. The samples cross the network once and reach every local program through shared memory. Control passes
through to the far device when this relay controls it (Server.relay takes control if it is free).
The upstream is a RemoteDevice. A thread follows its state (a stream started by someone else upstream starts the
relay's too), and lost is set when the far server stops answering.
Methods:
| Name | Description |
|---|---|
serial |
The far radio's serial number (not asked of a far server that is lost: whoever asks must not wait for it) |
status |
The far device's state as this relay last heard it (every forwarded call, and the watcher, refresh it) |
Source code in src/pysdrlib/remote/server.py
serial ¶
The far radio's serial number (not asked of a far server that is lost: whoever asks must not wait for it)
status ¶
The far device's state as this relay last heard it (every forwarded call, and the watcher, refresh it)
Source code in src/pysdrlib/remote/server.py
Server ¶
Server(bind='tcp://127.0.0.1:5555', port_range=None, devices=None, lease=15.0, wire='native', shm=True, shm_samples=None, scan_interval=0.0, frontends=None, advertise=False, name=None, kind='server', stats_interval=0.0, max_devices=MAX_DEVICES, client_args=None)
bind: C2 endpoint, tcp://host:port (port 0 or * picks one; see endpoint) or ipc://path.
port_range: (low, high) for the per-device tcp ports; default lets the OS pick.
devices: device types clients may open (default: every vendor package).
lease: seconds a controller may be silent before it loses control (0 disables).
wire: default RX wire format: "native" (the device's own sample layout), "complex64", "int8", "int16", ...
shm: let clients on this machine take samples from shared memory (the socket still serves the rest).
shm_samples: samples a shared-memory ring holds (default: a quarter second at the device's top rate).
scan_interval: seconds between looks at which radios are attached, logging the ones that appear or vanish (0 = never).
frontends: what sits between each radio and the air (a frontends.Frontends, or the path of its TOML file).
advertise: announce the server on the local network while it serves, for discovery.discover (needs zeroconf, and a
bind other clients can reach such as tcp://0.0.0.0:5555). name: the name it announces (default: the host name).
kind: what it announces itself as, "server" or "relay".
stats_interval: seconds between log lines saying what each streaming device published, to how many subscribers,
and what it dropped (0 = never). metrics() (the "metrics" request, pysdrlib client ADDRESS stats) has it all.
max_devices: devices hosted at once; a client that asks for one more gets err.Busy.
client_args: what a client may pass a driver, {type: [argument names]} on top of CLIENT_ARGS (by default a serial, an
index, a UHD radio's addr, and a simulated radio's signal). Anything else is refused, since a driver's arguments name
hosts, files and device strings: open those with open_device (--open), or name them here
({"tcpiq": ["host", "port", "sample_format"]}) to let clients choose them.
Methods:
| Name | Description |
|---|---|
start |
Serve in a background thread |
serve_forever |
Serve in this thread until Ctrl+C or SIGTERM (a service being stopped), then |
stop |
Stop serving and close every hosted device |
metrics |
{"uptime", "devices": {id: DeviceWorker.metrics()}}: what every hosted device (or just |
scan |
Look for attached radios and log what appeared or vanished since the last scan (the first logs all of them). |
types |
Device types clients may open: the |
open_device |
Create and open a device of vendor package |
available |
The radios attached at the last scan, as dicts: driver, label, serial, index and |
choose |
The radios a client could use for this request, best first: |
candidates |
|
open_matching |
Open (or take over, if it is hosted and nobody controls it) the best radio for the request (see |
relay |
Host a device of another server here, so programs on this machine share one connection to it (see |
Attributes:
| Name | Type | Description |
|---|---|---|
advertised_name |
The name the server announces on the network (None when not advertising) |
Source code in src/pysdrlib/remote/server.py
advertised_name
property
¶
The name the server announces on the network (None when not advertising)
start ¶
Serve in a background thread
Source code in src/pysdrlib/remote/server.py
serve_forever ¶
Serve in this thread until Ctrl+C or SIGTERM (a service being stopped), then stop
Source code in src/pysdrlib/remote/server.py
stop ¶
Stop serving and close every hosted device
Source code in src/pysdrlib/remote/server.py
metrics ¶
{"uptime", "devices": {id: DeviceWorker.metrics()}}: what every hosted device (or just device) has passed
Source code in src/pysdrlib/remote/server.py
scan ¶
Look for attached radios and log what appeared or vanished since the last scan (the first logs all of them).
-> the list of DeviceInfo
Source code in src/pysdrlib/remote/server.py
types ¶
Device types clients may open: the devices given to the server, or every driver
open_device ¶
open_device(dtype, init_args=(), init_kwargs=None, args=(), kwargs=None, controlled=False, wire=None, program=None, need=None, want=None, unit=None, client=False)
Create and open a device of vendor package dtype and start hosting it.
program/need/want: what the controller said it runs and needs (shown by list; see choose). unit: the DeviceInfo
of the radio, when it was picked from the attached ones.
client: the arguments came from a client, and are held to what it may pass (client_args).
-> (worker, token) where token is None unless controlled
Source code in src/pysdrlib/remote/server.py
available ¶
The radios attached at the last scan, as dicts: driver, label, serial, index and hosted (the id of the worker
that has it open, or None)
Source code in src/pysdrlib/remote/server.py
choose ¶
The radios a client could use for this request, best first: [(kind, target, caps)] with kind "hosted" (a
DeviceWorker nobody controls) or "unit" (a DeviceInfo attached and not hosted). A radio meets the request when it
is of type dtype, its serial is serial and its label contains label (case ignored), and meets all of need; those
that meet most of want come first, attached ones before hosted ones (a free hosted radio is one a client left open). Raises err.NoDevice saying why when none do.
Source code in src/pysdrlib/remote/server.py
candidates ¶
choose for a client that has not decided which server to use: the radios that fit the request, best first, as
dicts of kind ("unit" attached, "hosted" open and uncontrolled), driver, label, serial, id (a hosted one's),
rank (choose.rank, comparable between servers), granted and key (give it to open_matching as pick to open
that radio and no other). Opens nothing; raises err.NoDevice like choose
Source code in src/pysdrlib/remote/server.py
open_matching ¶
open_matching(dtype=None, serial=None, label=None, need=None, want=None, program=None, init_args=(), init_kwargs=None, wire=None, pick=None, client=False, args=(), kwargs=None)
Open (or take over, if it is hosted and nobody controls it) the best radio for the request (see choose).
pick: the key of one of candidates: open that radio or none, err.Busy if it no longer fits the request or is
no longer free (a client that compared servers by candidates then tries its next best, which may be elsewhere).
init_args/init_kwargs, args/kwargs: for the driver's constructor and open of a radio this opens. One taken over is
open already: the constructor's are not used on it, and with arguments for open it is passed over.
-> (worker, token, granted) where granted is what the radio can do nearest to want (and need)
Source code in src/pysdrlib/remote/server.py
relay ¶
Host a device of another server here, so programs on this machine share one connection to it (see RelayWorker).
address: the far server's endpoint. device: the id of a device it hosts (e.g. "hackrf-0"); or open: a device type to
open there instead (the relay then controls it, and closing the relay closes it).
control: take control of the device if it is free ("auto"), insist on it (True: err.Busy if someone has it), or only
watch it (False: local programs can receive but not change anything).
name: the id it has here (default: the far device's). Returns the RelayWorker.