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
attatched 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.RtlSdrTcpServer(device_index=0, test_mode_enabled=False, serial_number=None, hostname='127.0.0.1', port=None)[source]¶ Bases:
rtlsdr.rtlsdr.RtlSdr,rtlsdr.rtlsdrtcp.base.RtlSdrTcpBaseServer that connects to a physical dongle to allow client connections.
-
open(device_index=0, test_mode_enabled=False, serial_number=None)[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.
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.Server(rtl_sdr)[source]¶ Bases:
socketserver.TCPServer-
REQUEST_RECV_SIZE= 1024¶
-
-
class
rtlsdr.rtlsdrtcp.server.ServerThread(rtl_sdr)[source]¶ Bases:
threading.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:
rtlsdr.rtlsdrtcp.base.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¶
-
property
rtlsdr.rtlsdrtcp.base¶
-
class
rtlsdr.rtlsdrtcp.base.AckMessage(**kwargs)[source]¶ Bases:
rtlsdr.rtlsdrtcp.base.MessageBaseSimple message type meant for ACKnolegemnt of message receipt
-
class
rtlsdr.rtlsdrtcp.base.ClientMessage(**kwargs)[source]¶
-
class
rtlsdr.rtlsdrtcp.base.MessageBase(**kwargs)[source]¶ Bases:
objectBase class for messages sent between clients and servers.
Hanldes 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.- Returns
- 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:
rtlsdr.rtlsdrtcp.base.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)
-
classmethod