SoapySDR Documentation

repository·master·Indexed 23 days ago

https://github.com/pothosware/soapysdr

A vendor and platform-neutral support library for Software Defined Radio (SDR) that provides a common abstraction layer and unified API for hardware-agnostic development. Includes guides for creating device driver modules, C# bindings via SWIG, and Python utilities such as MeasureDelay.py for RF loopback delay measurement and SimpleSiggen.py for signal generation testing.

Tokens
1.5K
Snippets
1
Records
11
Agent score
80%

What's inside SoapySDR

  1. Overview of Soapy SDR

    master
    Soapy SDR is a vendor and platform-neutral support library for Software Defined Radio (SDR). It provides a common abstraction layer that allows SDR applications to interact with various hardware devices through a unified API, regardless of the specific vendor or underlying platform.
  2. Use C# bindings for SoapySDR

    master

    The C# bindings for SoapySDR are provided via a SWIG wrapper supplemented with hand-written C# code to ensure the API is idiomatic for traditional C# development.

    Platform and Compiler Requirements:

    • Compiler: Only supported with MSVC (Microsoft Visual C++).
    • Runtime: CMake currently only supports the .NET implementation for C#.
    • Note: The bindings include .NET dependencies that are stubbed out in Mono, so Mono is not supported.
  3. Create a new SoapySDR device driver module

    master

    To implement support for a new SDR device, you can use the ExampleDriver module as a template. You can either copy the entire directory to start a new CMake build project or integrate it into an existing driver build system as a subdirectory.

    To complete the implementation, you must:

    1. Customize CMakeLists.txt: Update the build configuration to include your specific driver dependencies.
    2. Customize MyDeviceSupport.cpp: Implement the logic required to make calls into your low-level device driver for device configuration and data streaming.
  4. Configure SoapySDR logging in SimpleSiggen.py

    master

    The SimpleSiggen.py application allows controlling the verbosity and error handling of the underlying SoapySDR logs using two specific CLI flags:

    • --debug: Sets the SoapySDR log level to SOAPY_SDR_DEBUG.
    • --abort-on-error: Configures the Python log handler to treat SOAPY_SDR_WARNING as an exception level, halting operations if the SDR logs an error.
  5. Configure Python log handlers for SoapySDR troubleshooting

    master

    To capture SoapySDR logs within a Python application and potentially treat specific log levels as exceptions, you can use the set_python_log_handler pattern. This replaces the default SoapySDR log handler with a custom Python function that redirects log text to sys.stderr.

    If an exception_level is provided, the handler will raise a SoapyException whenever a log message is received at that level or higher (where lower numerical values represent higher severity, e.g., SOAPY_SDR_ERROR is more severe than SOAPY_SDR_INFO).

  6. Use MeasureDelay.py to measure RF loopback delay

    master

    The MeasureDelay.py script is a CLI utility that uses SoapySDR Python bindings to measure the round-trip delay through an RF loopback or leakage. It works by transmitting a bandlimited sinc pulse and receiving it back, then calculating the time delta between the transmitted and received peaks.

    Requirements:

    • The SDR must support hardware-timed streaming (sdr.hasHardwareTime()).
    • The script uses numpy for signal processing.

    Key Features:

    • Configures sample rate, frequency, bandwidth, gain, and antennas for both TX and RX.
    • Supports dumping debug samples (normalized TX/RX pulses and raw I/Q data) to a directory for analysis.
    • Can be configured to halt if the SDR logs an error using --abort-on-error.
  7. Use SimpleSiggen.py for signal generation testing

    master

    The SimpleSiggen.py script is a CLI tool used to test SDR transmission capabilities. It continuously outputs a carrier with single-sideband sinusoid amplitude modulation. The application runs until interrupted by Ctrl+C.

    CLI Arguments

    ArgumentTypeDescription
    --argsstrDevice factor arguments (passed to SoapySDR.Device())
    --ratefloatTx and Rx sample rate (default: 1e6)
    --amplfloatTx digital amplitude rate (default: 0.7)
    --tx-antstrOptional Tx antenna
    --tx-gainfloatOptional Tx gain in dB
    --tx-chanintTransmitter channel (default: 0)
    --freqfloatOptional Tx and Rx frequency in Hz
    --tx-bwfloatOptional Tx filter bandwidth in Hz (default: 5e6)
    --wave-freqfloatBaseband waveform frequency in Hz
    --clock-ratefloatOptional clock rate in Hz
    --debugflagOutput debug messages
    --abort-on-errorflagHalts operations if the SDR logs an error

    Example Usage

    To run the generator with a specific frequency and sample rate:

    python SimpleSiggen.py --freq 2.4e9 --rate 2e6 --tx-ant "TX1"
  8. MeasureDelay.py CLI arguments

    master

    The MeasureDelay.py script accepts the following command-line arguments to configure the SDR and the measurement process:

    ArgumentTypeDescription
    --argsstrDevice factor arguments (passed to the SoapySDR device constructor). Default: ""
    --ratefloatTx and Rx sample rate. Default: 1e6
    --rx-antstrOptional Rx antenna name
    --tx-antstrOptional Tx antenna name
    --rx-gainfloatOptional Rx gain in dB
    --tx-gainfloatOptional Tx gain in dB
    --rx-bwfloatOptional Rx filter bandwidth in Hz
    --tx-bwfloatOptional Tx filter bandwidth in Hz
    --rx-chanintReceiver channel index. Default: 0
    --tx-chanintTransmitter channel index. Default: 0
    --freqfloatOptional Tx and Rx frequency in Hz
    --clock-ratefloatOptional master clock rate in Hz
    --dump-dirstrOptional directory to dump debug .npy samples
    --debugflagEnable debug logging
    --abort-on-errorflagHalts operations if the SDR logs an error
  9. Use SoapyException for error handling

    master

    When using a custom Python log handler via set_python_log_handler, the library can be configured to raise a SoapyException. This exception is raised if a log message's severity level is equal to or more severe than the specified exception_level.

    class SoapyException(Exception):
        """SoapySDR has logged an error message (or worse)."""
        pass