rtlsdr.rtlsdrtcp
This module allows client/server communication.
The RtlSdrTcpServer class is meant to be
connected physically to an SDR dongle and communicate with an instance of
RtlSdrTcpClient.
The client is intended to function as closely as possible to the base
RtlSdr class (as if it had a physical dongle
attached to it).
Both of these classes have the same arguments as the base
RtlSdr class with the addition of hostname and port.
Examples
server = RtlSdrTcpServer(hostname='192.168.1.100', port=12345)
server.run_forever()
# Will listen for clients until Ctrl-C is pressed
# On another machine (typically)
client = RtlSdrTcpClient(hostname='192.168.1.100', port=12345)
client.center_freq = 2e6
data = client.read_samples()
Note
On platforms where the librtlsdr library cannot be installed/compiled,
it is possible to import RtlSdrTcpClient only by
setting the environment variable "RTLSDR_CLIENT_MODE" to "true".
If this is set, no other modules will be available.
Feature added in v0.2.4
rtlsdr.rtlsdrtcp.server
- class rtlsdr.rtlsdrtcp.server.RequestHandler(request, client_address, server)[source]
Bases:
BaseRequestHandler
- class rtlsdr.rtlsdrtcp.server.RtlSdrTcpServer(device_index=0, test_mode_enabled=False, serial_number=None, hostname='127.0.0.1', port=None, dithering_enabled=True)[source]
Bases:
RtlSdrAio,RtlSdrTcpBaseServer that connects to a physical dongle to allow client connections.
- open(device_index=0, test_mode_enabled=False, serial_number=None, dithering_enabled=True)[source]
Connect to the device through the underlying wrapper library
Initializes communication with the device and retrieves information from it with a call to
init_device_values().- Parameters:
device_index (
int, optional) – The device index to use if there are multiple dongles attached. If only one is being used, the default value (0) will be used.test_mode_enabled (
bool, optional) – If True, enables a special test mode, which will return the value of an internal RTL2832 8-bit counter with calls toread_bytes().serial_number (
str, optional) – If not None, the device will be searched for by the given serial_number byget_device_index_by_serial()and thedevice_indexreturned will be used automatically.dithering_enabled (
bool, optional) – If False, disables PLL dithering to prevent it destroying phase coherence in CLK-synchronized dongles.
Notes
The arguments used here are passed directly from object initialization.
- Raises:
IOError – If communication with the device could not be established.
- read_samples(num_samples=1024)[source]
This overrides the base implementation so that the raw data is sent. It will be unpacked to I/Q samples on the client side.
- class rtlsdr.rtlsdrtcp.server.ServerThread(rtl_sdr)[source]
Bases:
Thread- run()[source]
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
rtlsdr.rtlsdrtcp.client
- class rtlsdr.rtlsdrtcp.client.RtlSdrTcpClient(device_index=0, test_mode_enabled=False, hostname='127.0.0.1', port=None)[source]
Bases:
RtlSdrTcpBaseClient object that connects to a remote server.
Exposes most of the methods and descriptors that are available in the RtlSdr class in a transparent manner allowing an interface that is nearly identical to the core API.
- property bandwidth
- property center_freq
- property fc
- property freq_correction
- property gain
- property rs
- property sample_rate
rtlsdr.rtlsdrtcp.base
- class rtlsdr.rtlsdrtcp.base.AckMessage(**kwargs)[source]
Bases:
MessageBaseSimple message type meant for ACKnolegemnt of message receipt
- class rtlsdr.rtlsdrtcp.base.ClientMessage(**kwargs)[source]
Bases:
MessageBase
- class rtlsdr.rtlsdrtcp.base.MessageBase(**kwargs)[source]
Bases:
objectBase class for messages sent between clients and servers.
Handles serialization/deserialization and communication with socket type objects.
- timestamp
Timestamp given from
time.time()- Type:
- data
The payload containing either the request or response data
- classmethod from_remote(sock)[source]
Reads data from the socket and parses an instance of
MessageBase- Parameters:
sock – The
socketobject to read from
- get_header(**kwargs)[source]
Builds the header data for the message
The
timestampis added to the header if not already present.- Return type:
- get_response(sock)[source]
Waits for a specific response message
The message class returned from
get_response_class()is used to parse the message (called fromfrom_remote())- Parameters:
sock – The
socketobject to read from
- class rtlsdr.rtlsdrtcp.base.RtlSdrTcpBase(device_index=0, test_mode_enabled=False, hostname='127.0.0.1', port=None)[source]
Bases:
objectBase class for all
rtlsdrtcpfunctionality- Parameters:
- DEFAULT_PORT = 1235
- class rtlsdr.rtlsdrtcp.base.ServerMessage(**kwargs)[source]
Bases:
MessageBase- classmethod from_remote(sock)[source]
Reads data for the socket buffer and reconstructs the appropriate message that was sent by the other end.
This method is used by clients to reconstruct ServerMessage objects and if necessary, use multiple read calls to get the entire message (if the message size is greater than the buffer length)