### Define Installation Directories Source: https://github.com/sdr/gr-osmosdr/blob/master/CMakeLists.txt Sets up standard installation paths for the project. ```cmake include(GrPlatform) #define LIB_SUFFIX if(NOT CMAKE_MODULES_DIR) set(CMAKE_MODULES_DIR lib${LIB_SUFFIX}/cmake) endif(NOT CMAKE_MODULES_DIR) set(GR_INCLUDE_DIR include) set(GR_CMAKE_DIR ${CMAKE_MODULES_DIR}/osmosdr) set(GR_PKG_DATA_DIR ${GR_DATA_DIR}/${CMAKE_PROJECT_NAME}) set(GR_PKG_DOC_DIR ${GR_DOC_DIR}/${CMAKE_PROJECT_NAME}) set(GR_PKG_CONF_DIR ${GR_CONF_DIR}/${CMAKE_PROJECT_NAME}/conf.d) set(GR_PKG_LIBEXEC_DIR ${GR_LIBEXEC_DIR}/${CMAKE_PROJECT_NAME}) ``` -------------------------------- ### Install Built Library Files Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/CMakeLists.txt Installs the built library files using a utility function. This ensures the library is correctly placed for use by other projects. ```cmake include(GrMiscUtils) GR_LIBRARY_FOO(gnuradio-osmosdr) ``` -------------------------------- ### Install gr-osmosdr Dependencies and Build Source: https://context7.com/sdr/gr-osmosdr/llms.txt Commands to install necessary dependencies on Debian/Ubuntu systems and then clone, configure, build, and install gr-osmosdr using CMake. ```bash # Install dependencies (Debian/Ubuntu) sudo apt-get install gnuradio gnuradio-dev cmake \ librtlsdr-dev libhackrf-dev libairspy-dev \ libbladerf-dev libuhd-dev libsoapysdr-dev # Clone and build gr-osmosdr git clone https://gitea.osmocom.org/sdr/gr-osmosdr cd gr-osmosdr/ # Configure with CMake cmake -S . -B build # Optional: Enable non-free components (SDRplay) # cmake -S . -B build -DENABLE_NONFREE=ON # Build cmake --build build --parallel # Install sudo cmake --install build sudo ldconfig # Verify installation python3 -c "import osmosdr; print('gr-osmosdr loaded successfully')" ``` -------------------------------- ### Setup Configuration File Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/CMakeLists.txt Configures the build system to use a configuration header file. This involves adding definitions and copying a template file to the build directory. ```cmake add_definitions(-DHAVE_CONFIG_H=1) include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) ``` -------------------------------- ### Build gr-osmosdr with CMake Source: https://github.com/sdr/gr-osmosdr/blob/master/README.md Instructions for cloning the repository, configuring the build with CMake, compiling, and installing the gr-osmosdr block. Ensure `make uninstall` is run before rebuilding. ```bash git clone https://gitea.osmocom.org/sdr/gr-osmosdr cd gr-osmosdr/ cmake -S . -B build cmake --build build --parallel sudo cmake --install build sudo ldconfig ``` -------------------------------- ### Install Executable Programs for gr-osmosdr Source: https://github.com/sdr/gr-osmosdr/blob/master/apps/CMakeLists.txt Installs executable programs into the gr-osmosdr runtime directory. This includes tools like osmocom_fft and osmocom_siggen_nogui. ```cmake GR_PYTHON_INSTALL( PROGRAMS osmocom_fft # osmocom_siggen osmocom_siggen_nogui # osmocom_spectrum_sense DESTINATION ${GR_RUNTIME_DIR} ) ``` -------------------------------- ### GNU Radio Companion Flowgraph Example Source: https://context7.com/sdr/gr-osmosdr/llms.txt A basic Python flowgraph template generated by GNU Radio Companion, intended for use with gr-osmosdr blocks. ```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- # GNU Radio Python Flow Graph ``` -------------------------------- ### Setup XTRX Component Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/CMakeLists.txt Registers the XTRX SDR component and conditionally adds its subdirectory if XTRX is enabled. Ensure the XTRX library is found before enabling. ```cmake GR_REGISTER_COMPONENT("XTRX SDR" ENABLE_XTRX LIBXTRX_FOUND) if(ENABLE_XTRX) add_subdirectory(xtrx) endif(ENABLE_XTRX) ``` -------------------------------- ### Install Python Sources for Osmosdr Source: https://github.com/sdr/gr-osmosdr/blob/master/python/CMakeLists.txt Installs Python source files for the osmosdr module to the specified destination. ```cmake GR_PYTHON_INSTALL( FILES __init__.py DESTINATION ${GR_PYTHON_DIR}/osmosdr ) ``` -------------------------------- ### Configure Apple RPath Settings Source: https://github.com/sdr/gr-osmosdr/blob/master/CMakeLists.txt Ensures correct library installation paths and RPath settings on macOS. ```cmake if(APPLE) if(NOT CMAKE_INSTALL_NAME_DIR) set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE PATH "Library Install Name Destination Directory" FORCE) endif(NOT CMAKE_INSTALL_NAME_DIR) if(NOT CMAKE_INSTALL_RPATH) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE PATH "Library Install RPath" FORCE) endif(NOT CMAKE_INSTALL_RPATH) if(NOT CMAKE_BUILD_WITH_INSTALL_RPATH) set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "Do Build Using Library Install RPath" FORCE) endif(NOT CMAKE_BUILD_WITH_INSTALL_RPATH) endif(APPLE) ``` -------------------------------- ### Append Library List Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/redpitaya/CMakeLists.txt Appends libraries to the build list. This example appends Gnuradio-blocks_LIBRARIES and ws2_32 for Windows. ```cmake APPEND_LIB_LIST( ${Gnuradio-blocks_LIBRARIES} ) ``` ```cmake if(WIN32) APPEND_LIB_LIST( ws2_32 ) endif() ``` -------------------------------- ### FM Receiver Flowgraph Source: https://context7.com/sdr/gr-osmosdr/llms.txt Example of a basic FM receiver flowgraph using gr-osmosdr. Demonstrates setting sample rate, center frequency, and gain. Runtime parameter updates are also shown. ```python from gnuradio import gr from gnuradio import blocks from gnuradio import qtgui import osmosdr import time class fm_receiver(gr.top_block): def __init__(self): gr.top_block.__init__(self, "FM Receiver") # Variables self.samp_rate = samp_rate = 2.4e6 self.freq = freq = 98.5e6 # osmocom Source block (as configured in GRC) self.osmosdr_source = osmosdr.source( args="numchan=1 rtl=0" ) self.osmosdr_source.set_time_unknown_pps(osmosdr.time_spec_t()) self.osmosdr_source.set_sample_rate(samp_rate) self.osmosdr_source.set_center_freq(freq, 0) self.osmosdr_source.set_freq_corr(0, 0) self.osmosdr_source.set_dc_offset_mode(0, 0) self.osmosdr_source.set_iq_balance_mode(0, 0) self.osmosdr_source.set_gain_mode(False, 0) self.osmosdr_source.set_gain(40, 0) self.osmosdr_source.set_if_gain(20, 0) self.osmosdr_source.set_bb_gain(20, 0) self.osmosdr_source.set_antenna('', 0) self.osmosdr_source.set_bandwidth(0, 0) # Additional processing blocks would connect here # self.connect((self.osmosdr_source, 0), (self.next_block, 0)) # Runtime parameter update methods (GRC callbacks) def set_freq(self, freq): self.freq = freq self.osmosdr_source.set_center_freq(self.freq, 0) def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate self.osmosdr_source.set_sample_rate(self.samp_rate) if __name__ == '__main__': tb = fm_receiver() tb.start() # Runtime frequency change tb.set_freq(101.1e6) input('Press Enter to quit') tb.stop() tb.wait() ``` -------------------------------- ### Install Python Files for gr-osmosdr Source: https://github.com/sdr/gr-osmosdr/blob/master/apps/CMakeLists.txt Installs Python files into the gr-osmosdr Python directory. Ensure GR_PYTHON_DIR is correctly set in your build environment. ```cmake GR_PYTHON_INSTALL( FILES osmocom_siggen_base.py DESTINATION ${GR_PYTHON_DIR}/osmosdr ) ``` -------------------------------- ### Configure RTL-SDR Device Arguments Source: https://context7.com/sdr/gr-osmosdr/llms.txt Example of passing device-specific arguments to osmosdr.source for an RTL-SDR device, including crystal frequencies and buffer settings. Consult the documentation for available options for your specific device. ```python import osmosdr # RTL-SDR device arguments rrtl_src = osmosdr.source(args="rtl=0,rtl_xtal=28.8e6,tuner_xtal=28.8e6,buffers=32") # Options: rtl=INDEX, rtl_xtal=FREQ, tuner_xtal=FREQ, buffers=N, buflen=N*512 # direct_samp=0|1|2, offset_tune=0|1, bias=0|1 ``` -------------------------------- ### Clock and Time Synchronization Source: https://context7.com/sdr/gr-osmosdr/llms.txt Provides precise timing control and synchronization for multi-device or GPS-disciplined setups. ```APIDOC ## Clock and Time Sync ### Description Configures clock sources, time sources, and synchronization methods. ### Methods - **set_clock_source(source, mboard)** - Sets the clock source (e.g., 'internal', 'external') - **set_time_now(time_spec, mboard)** - Sets the device time immediately - **set_time_next_pps(time_spec)** - Sets time on the next PPS edge - **get_time_now(mboard)** - Returns the current device time ``` -------------------------------- ### Get Supported Bandwidth Range Source: https://context7.com/sdr/gr-osmosdr/llms.txt Retrieves the supported analog bandwidth range for a given channel. This is useful for understanding the filter capabilities of the SDR device. ```python import osmosdr src = osmosdr.source(args="airspy=0") # AirSpy supports bandwidth control src.set_sample_rate(10e6) src.set_center_freq(100e6) # Get supported bandwidth range try: bw_range = src.get_bandwidth_range(chan=0) print(f"Bandwidth range: {bw_range.start()/1e6} - {bw_range.stop()/1e6} MHz") ``` -------------------------------- ### Configure Build Dependencies and Options Source: https://github.com/sdr/gr-osmosdr/blob/master/CMakeLists.txt Initializes build options and searches for required GNURadio and hardware driver packages. ```cmake include(GrComponent) set(ENABLE_NONFREE FALSE CACHE BOOL "Enable or disable nonfree components.") # GNURadio components & OOTs ############################## # Note this is not supposed to be lique that for GR components # but ATM GR's handling of components is broken message(STATUS "Searching for GNURadio-Blocks...") find_package(gnuradio-blocks PATHS ${Gnuradio_DIR}) message(STATUS " Found GNURadio-Blocks: ${gnuradio-blocks_FOUND}") message(STATUS "Searching for IQ Balance...") find_package(gnuradio-iqbalance PATHS ${Gnuradio_DIR}) message (STATUS " Found IQ Balance: ${gnuradio-iqbalance_FOUND}") message(STATUS "Searching for UHD Drivers...") find_package(UHD) message (STATUS " Found UHD Driver: ${UHD_FOUND}") message(STATUS "Searching for UHD Block...") find_package(gnuradio-uhd PATHS ${Gnuradio_DIR}) message (STATUS " Found UHD Block: ${gnuradio-uhd_FOUND}") message(STATUS "Searching for Volk...") find_package(Volk REQUIRED) message (STATUS " Found Volk: ${Volk_FOUND}") # Hardware drivers #################### find_package(LibRTLSDR) find_package(LibMiriSDR) if(ENABLE_NONFREE) find_package(LibSDRplay) endif(ENABLE_NONFREE) find_package(LibHackRF) find_package(LibAIRSPY) find_package(LibAIRSPYHF) find_package(LibbladeRF) find_package(GnuradioFuncube) find_package(SoapySDR NO_MODULE) find_package(LibFreeSRP) find_package(LibXTRX) find_package(Doxygen) ``` -------------------------------- ### Create and Configure an SDR Source Block in Python Source: https://context7.com/sdr/gr-osmosdr/llms.txt Demonstrates instantiating an osmosdr source block within a GNU Radio flowgraph and configuring parameters like frequency, gain, and sample rate. ```python #!/usr/bin/env python3 import osmosdr from gnuradio import gr # Create a GNU Radio top block class sdr_receiver(gr.top_block): def __init__(self): gr.top_block.__init__(self, "SDR Receiver") # Create osmosdr source with device arguments # Examples: # "" - use first available device # "rtl=0" - use first RTL-SDR dongle # "hackrf=0" - use HackRF device # "airspy=0,bias=1" - use AirSpy with bias-tee enabled # "bladerf=0" - use BladeRF device # "uhd,serial=12345" - use specific USRP by serial self.src = osmosdr.source(args="rtl=0") # Verify device was opened successfully try: rates = self.src.get_sample_rates() print(f"Sample rate range: {rates.start()} - {rates.stop()} Hz") except RuntimeError: print("Error: Could not open device") return # Configure the source self.src.set_sample_rate(2.4e6) # 2.4 MHz sample rate self.src.set_center_freq(100e6) # Tune to 100 MHz self.src.set_freq_corr(0) # 0 ppm frequency correction self.src.set_gain_mode(False) # Manual gain mode self.src.set_gain(40) # Set RF gain to 40 dB self.src.set_if_gain(20) # Set IF gain to 20 dB self.src.set_bb_gain(20) # Set baseband gain to 20 dB self.src.set_bandwidth(0) # Auto bandwidth # Print actual values (may differ from requested) print(f"Actual sample rate: {self.src.get_sample_rate()} Hz") print(f"Actual center freq: {self.src.get_center_freq()} Hz") print(f"Actual gain: {self.src.get_gain()} dB") if __name__ == '__main__': tb = sdr_receiver() tb.start() input('Press Enter to quit: ') tb.stop() tb.wait() ``` -------------------------------- ### Print Build Summary Source: https://github.com/sdr/gr-osmosdr/blob/master/CMakeLists.txt Displays the final build configuration summary and warnings for non-free components. ```cmake GR_PRINT_COMPONENT_SUMMARY() if(ENABLE_NONFREE) MESSAGE(STATUS "NONFREE components have been enabled. The resulting binaries cannot be distributed under GPL terms. ") endif(ENABLE_NONFREE) MESSAGE(STATUS "Building for version: ${VERSION} / ${LIBVER}") MESSAGE(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Configure Clock and Time Sources Source: https://context7.com/sdr/gr-osmosdr/llms.txt Sets the clock and time sources for precise timing control, supporting options like internal, external, MIMO, and GPSDO. Also demonstrates setting and retrieving clock rates. ```python import osmosdr import time src = osmosdr.source(args="uhd") # USRP supports timing features src.set_sample_rate(1e6) src.set_center_freq(100e6) # Clock source options: 'internal', 'external', 'mimo', 'gpsdo' available_clocks = src.get_clock_sources(mboard=0) print(f"Available clock sources: {available_clocks}") src.set_clock_source("external", mboard=0) print(f"Clock source: {src.get_clock_source(mboard=0)}") # Time source options: 'external', 'mimo', 'gpsdo' available_time = src.get_time_sources(mboard=0) print(f"Available time sources: {available_time}") src.set_time_source("external", mboard=0) print(f"Time source: {src.get_time_source(mboard=0)}") # Get/set master clock rate clock_rate = src.get_clock_rate(mboard=0) print(f"Master clock rate: {clock_rate/1e6} MHz") src.set_clock_rate(200e6, mboard=0) ``` -------------------------------- ### Configure CMake build targets and sources Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/airspy/CMakeLists.txt Sets up include directories, library dependencies, and source file lists for the gnuradio-osmosdr target. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBAIRSPY_INCLUDE_DIRS} ) APPEND_LIB_LIST( gnuradio::gnuradio-filter ${Gnuradio-blocks_LIBRARIES} ${LIBAIRSPY_LIBRARIES} ) list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/airspy_source_c.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Configure File Source Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configure an osmosdr.source to read from a file. Options include file path, sample rate, frequency, repeat, and throttle. ```python file_src = osmosdr.source(args="file='/path/to/recording.cfile',rate=2.4e6,freq=100e6,repeat=true,throttle=true") ``` -------------------------------- ### Record to File while Displaying with osmocom_fft Source: https://context7.com/sdr/gr-osmosdr/llms.txt Launches osmocom_fft for an RTL-SDR, records the capture to a file with a timestamped format, and displays the spectrum. ```bash osmocom_fft -a "rtl=0" -f 100e6 -s 2.4e6 -r "/tmp/capture-f%F-s%S-t%T.cfile" ``` -------------------------------- ### Basic osmocom_fft Usage Source: https://context7.com/sdr/gr-osmosdr/llms.txt Launches the osmocom_fft spectrum analyzer, automatically detecting the connected SDR device. ```bash osmocom_fft ``` -------------------------------- ### Configure FreeSRP Source Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configure an osmosdr.source for FreeSRP devices. Requires paths to FX3 firmware and FPGA bitstream. ```python freesrp_src = osmosdr.source(args="freesrp=0,fx3='path/to/fx3.img',fpga='path/to/fpga.bin'") ``` -------------------------------- ### Configure Multi-Device Source Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configure an osmosdr.source to use multiple devices simultaneously. Devices are space-separated. ```python multi_src = osmosdr.source(args="numchan=2 rtl=0 rtl=1") ``` -------------------------------- ### Basic usage of ReaderWriterQueue Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/freesrp/readerwriterqueue/README.md Demonstrates initializing the queue, performing non-blocking enqueue/dequeue operations, and using peek to inspect the front element. ```cpp using namespace moodycamel; ReaderWriterQueue q(100); // Reserve space for at least 100 elements up front q.enqueue(17); // Will allocate memory if the queue is full bool succeeded = q.try_enqueue(18); // Will only succeed if the queue has an empty slot (never allocates) assert(succeeded); int number; succeeded = q.try_dequeue(number); // Returns false if the queue was empty assert(succeeded && number == 17); // You can also peek at the front item of the queue (consumer only) int* front = q.peek(); assert(*front == 18); succeeded = q.try_dequeue(number); assert(succeeded && number == 18); front = q.peek(); assert(front == nullptr); // Returns nullptr if the queue was empty ``` -------------------------------- ### Synchronize Device Time Source: https://context7.com/sdr/gr-osmosdr/llms.txt Demonstrates various methods for synchronizing the device's time, including setting the time immediately, on the next PPS edge, or with an unknown PPS edge. Also shows how to retrieve the current device time and the time of the last PPS signal. ```python import osmosdr import time src = osmosdr.source(args="uhd") # USRP supports timing features src.set_sample_rate(1e6) src.set_center_freq(100e6) # Time synchronization methods # Set time immediately src.set_time_now(osmosdr.time_spec_t(time.time()), mboard=0) # Set time on next PPS edge (for GPS sync) src.set_time_next_pps(osmosdr.time_spec_t(0.0)) # Set time with unknown PPS (waits for edge) src.set_time_unknown_pps(osmosdr.time_spec_t()) # Read current device time current_time = src.get_time_now(mboard=0) print(f"Device time: {current_time.get_real_secs()} seconds") # Get time of last PPS pps_time = src.get_time_last_pps(mboard=0) print(f"Last PPS: {pps_time.get_real_secs()} seconds") ``` -------------------------------- ### Specify Device and Frequency with osmocom_fft Source: https://context7.com/sdr/gr-osmosdr/llms.txt Launches osmocom_fft, specifying the device arguments (e.g., 'rtl=0') and the center frequency. ```bash osmocom_fft -a "rtl=0" -f 100e6 -s 2.4e6 ``` -------------------------------- ### Configure Doxygen Documentation Source: https://github.com/sdr/gr-osmosdr/blob/master/CMakeLists.txt Checks for Doxygen availability and sets the build option accordingly. ```cmake find_package(Doxygen) if(DOXYGEN_FOUND) option(ENABLE_DOXYGEN "Build docs using Doxygen" ON) else(DOXYGEN_FOUND) option(ENABLE_DOXYGEN "Build docs using Doxygen" OFF) endif(DOXYGEN_FOUND) ``` -------------------------------- ### Handle Unit Tests for gr-osmosdr Source: https://github.com/sdr/gr-osmosdr/blob/master/python/CMakeLists.txt Includes macros for handling unit tests and sets up target dependencies for gnuradio-osmosdr. ```cmake include(GrTest) set(GR_TEST_TARGET_DEPS gnuradio-osmosdr) ``` -------------------------------- ### Configure CMake for gr-osmosdr Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/freesrp/CMakeLists.txt Sets up include directories, library dependencies, and source files for the gr-osmosdr build process. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBFREESRP_INCLUDE_DIRS} ) APPEND_LIB_LIST( ${LIBFREESRP_LIBRARIES} ) list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/freesrp_common.cc ${CMAKE_CURRENT_SOURCE_DIR}/freesrp_source_c.cc ${CMAKE_CURRENT_SOURCE_DIR}/freesrp_sink_c.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Enable Fosphor GPU Acceleration with osmocom_fft Source: https://context7.com/sdr/gr-osmosdr/llms.txt Launches osmocom_fft for an AirSpy device, enabling the fosphor GPU-accelerated display. ```bash osmocom_fft -a "airspy=0" -f 100e6 -s 10e6 -F ``` -------------------------------- ### Set Specific Bandwidth and Verify Source: https://context7.com/sdr/gr-osmosdr/llms.txt Sets a specific analog bandwidth for the SDR frontend and verifies the setting. A value of 0 attempts automatic selection based on the sample rate. This helps reduce aliasing and out-of-band interference. ```python import osmosdr src = osmosdr.source(args="airspy=0") # AirSpy supports bandwidth control src.set_sample_rate(10e6) src.set_center_freq(100e6) # Set specific bandwidth # Use 0 for automatic selection based on sample rate actual_bw = src.set_bandwidth(5e6, chan=0) print(f"Bandwidth set to: {actual_bw/1e6} MHz") # Read current bandwidth current_bw = src.get_bandwidth(chan=0) print(f"Current bandwidth: {current_bw/1e6} MHz") except RuntimeError: print("Bandwidth control not supported by this device") ``` -------------------------------- ### Configure BladeRF Source Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configure an osmosdr.source for BladeRF devices. Options include device index, tamer, SMB frequency, and sample format. ```python bladerf_src = osmosdr.source(args="bladerf=0,tamer=external,smb=25e6") ``` -------------------------------- ### Define Library Target and Include Directories Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/CMakeLists.txt Creates the shared library target and configures include paths and target properties. ```cmake add_library(gnuradio-osmosdr SHARED) APPEND_LIB_LIST(${Boost_LIBRARIES} gnuradio::gnuradio-runtime) target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${Boost_INCLUDE_DIRS} PUBLIC $ PUBLIC $ ) set_target_properties(gnuradio-osmosdr PROPERTIES DEFINE_SYMBOL "gnuradio_osmosdr_EXPORTS") if(APPLE) set_target_properties(gnuradio-osmosdr PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" ) endif(APPLE) ``` -------------------------------- ### Discover SDR Devices in C++ Source: https://context7.com/sdr/gr-osmosdr/llms.txt Uses the osmosdr::device::find function to list all connected SDR hardware and access device properties. ```cpp #include #include int main() { // Discover all available SDR devices on the system osmosdr::devices_t devices = osmosdr::device::find(); std::cout << "Found " << devices.size() << " device(s):" << std::endl; for (const auto& dev : devices) { // Print device information in human-readable format std::cout << dev.to_pp_string() << std::endl; // Access specific device properties if (dev.count("label")) { std::cout << "Label: " << dev.at("label") << std::endl; } } return 0; } ``` -------------------------------- ### Create Uninstall Target Source: https://github.com/sdr/gr-osmosdr/blob/master/CMakeLists.txt Configures the uninstall script and adds a custom target for project removal. ```cmake configure_file( ${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake @ONLY) add_custom_target(uninstall ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake ) ``` -------------------------------- ### Configure Source Files and Compiler Flags Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/CMakeLists.txt Defines the source files for the library and adds pthread support for GCC compilers. ```cmake list(APPEND gr_osmosdr_srcs source_impl.cc sink_impl.cc ranges.cc device.cc time_spec.cc ) #-pthread Adds support for multithreading with the pthreads library. #This option sets flags for both the preprocessor and linker. (man gcc) if(CMAKE_COMPILER_IS_GNUCXX) list(APPEND Boost_LIBRARIES -pthread) endif() ``` -------------------------------- ### Configure SDR Sample Rate Source: https://context7.com/sdr/gr-osmosdr/llms.txt Queries supported sample rates and sets the device sampling frequency. Note that hardware may constrain the actual rate applied. ```python import osmosdr src = osmosdr.source(args="rtl=0") # Get the range of supported sample rates rates = src.get_sample_rates() print(f"Supported sample rates: {rates.start()} - {rates.stop()} Hz") print(f"Step size: {rates.step()} Hz") # Set sample rate and get actual value requested_rate = 2.4e6 actual_rate = src.set_sample_rate(requested_rate) print(f"Requested: {requested_rate} Hz, Actual: {actual_rate} Hz") # Read back current sample rate current_rate = src.get_sample_rate() print(f"Current sample rate: {current_rate} Hz") ``` -------------------------------- ### Create an SDR Sink Block Source: https://context7.com/sdr/gr-osmosdr/llms.txt Initializes a transmit sink block for supported SDR hardware. Requires a valid device argument string. ```python #!/usr/bin/env python3 import osmosdr from gnuradio import gr, analog class sdr_transmitter(gr.top_block): def __init__(self): gr.top_block.__init__(self, "SDR Transmitter") # Create osmosdr sink for transmission # Supported transmit devices: HackRF, BladeRF, USRP, FreeSRP, XTRX self.sink = osmosdr.sink(args="hackrf=0") # Configure transmitter self.sink.set_sample_rate(2e6) # 2 MHz sample rate self.sink.set_center_freq(433e6) # Tune to 433 MHz self.sink.set_freq_corr(0) # 0 ppm frequency correction self.sink.set_gain(14) # Set TX gain self.sink.set_if_gain(40) # Set IF gain self.sink.set_bb_gain(20) # Set baseband gain self.sink.set_bandwidth(0) # Auto bandwidth self.sink.set_antenna("TX/RX") # Select antenna port # Create a simple sine wave source self.signal = analog.sig_source_c( 2e6, # Sample rate analog.GR_SIN_WAVE, # Waveform type 10e3, # 10 kHz offset frequency 0.3, # Amplitude (0.0 to 1.0) 0 # Phase offset ) # Connect signal source to transmitter self.connect(self.signal, self.sink) print(f"Transmitting on {self.sink.get_center_freq()/1e6} MHz") if __name__ == '__main__': tb = sdr_transmitter() tb.start() input('Press Enter to stop: ') tb.stop() tb.wait() ``` -------------------------------- ### Configure RTL-TCP Source Source: https://context7.com/sdr/gr-osmosdr/llms.txt Use this to configure an osmosdr.source for RTL-TCP network devices. Ensure the IP address and port are correct. ```python rtl_tcp_src = osmosdr.source(args="rtl_tcp=192.168.1.100:1234,psize=16384") ``` -------------------------------- ### Configure Python Support Source: https://github.com/sdr/gr-osmosdr/blob/master/CMakeLists.txt Detects Python libraries and registers the Python support component. ```cmake find_package(PythonLibs 3) find_package(pybind11) GR_REGISTER_COMPONENT("Python support" ENABLE_PYTHON PYTHONLIBS_FOUND pybind11_FOUND ) ``` -------------------------------- ### Configure CMake Build Targets Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/fcd/CMakeLists.txt Sets include directories, appends library dependencies, and updates the source file list for the project. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${GNURADIO_FUNCUBE_INCLUDE_DIRS} ) APPEND_LIB_LIST( ${GNURADIO_FUNCUBE_LIBRARIES} ) list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/fcd_source_c.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Configure XTRX Build Dependencies Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/xtrx/CMakeLists.txt Sets include directories and appends XTRX libraries to the build configuration. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBXTRX_INCLUDE_DIRS} ) APPEND_LIB_LIST( ${LIBXTRX_LIBRARIES} ) ``` -------------------------------- ### HackRF with Waterfall Display using osmocom_fft Source: https://context7.com/sdr/gr-osmosdr/llms.txt Launches osmocom_fft for a HackRF device, specifying frequency, sample rate, gain, and enabling the waterfall display. ```bash osmocom_fft -a "hackrf=0" -f 915e6 -s 20e6 -g 30 -W ``` -------------------------------- ### Configure USRP (UHD) Source Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configure an osmosdr.source for USRP devices using UHD. Options include serial number, LO offset, master clock rate, and number of channels. ```python uhd_src = osmosdr.source(args="uhd,serial=12345678,lo_offset=0,mcr=52e6,nchan=2") ``` -------------------------------- ### Configure HackRF Source Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configure an osmosdr.source for HackRF devices. Options include device index, buffer count, and bias tee settings. ```python hackrf_src = osmosdr.source(args="hackrf=0,buffers=32,bias=1") ``` -------------------------------- ### Set Include Directories for gnuradio-osmosdr Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/hackrf/CMakeLists.txt Configures private include directories for the gnuradio-osmosdr target. Ensure LIBHACKRF_INCLUDE_DIRS is defined. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBHACKRF_INCLUDE_DIRS} ) ``` -------------------------------- ### Configure CMake Build Targets Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/file/CMakeLists.txt Sets include directories and appends required libraries for the gnuradio-osmosdr target. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) APPEND_LIB_LIST( gnuradio::gnuradio-blocks ) message(STATUS ${gnuradio-blocks_LIBRARIES}) ``` -------------------------------- ### Basic Sine Wave Transmission with osmocom_siggen Source: https://context7.com/sdr/gr-osmosdr/llms.txt Generates a basic sine wave using osmocom_siggen for a HackRF device. Specify frequency, sample rate, and sine wave parameters. ```bash osmocom_siggen -a "hackrf=0" -f 433e6 -s 2e6 --sine -x 10e3 ``` -------------------------------- ### Configure CMake Build Targets Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/miri/CMakeLists.txt Sets include directories, library dependencies, and source files for the gnuradio-osmosdr target. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBMIRISDR_INCLUDE_DIRS} ) APPEND_LIB_LIST( ${LIBMIRISDR_LIBRARIES} ) list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/miri_source_c.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Configure CMake Build Targets Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/rtl/CMakeLists.txt Sets include directories and appends source files for the gnuradio-osmosdr target. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBRTLSDR_INCLUDE_DIRS} ) APPEND_LIB_LIST( ${LIBRTLSDR_LIBRARIES} ) list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/rtl_source_c.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Set Target Include Directories Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/rfspace/CMakeLists.txt Configures private include directories for the gnuradio-osmosdr target using CMake. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) ``` -------------------------------- ### Set Clock Source for USRP with osmocom_fft Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configures osmocom_fft for a USRP device and sets the external clock source. ```bash osmocom_fft -a "uhd" -f 100e6 --clock-source external ``` -------------------------------- ### Configure AirSpy Source Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configure an osmosdr.source for AirSpy devices. Options include device index, bias tee, and linearity settings. ```python airspy_src = osmosdr.source(args="airspy=0,bias=1,linearity") ``` -------------------------------- ### Oscilloscope Mode with osmocom_fft Source: https://context7.com/sdr/gr-osmosdr/llms.txt Launches osmocom_fft for an RTL-SDR in oscilloscope (time domain) mode. ```bash osmocom_fft -a "rtl=0" -f 100e6 -s 2.4e6 -S ``` -------------------------------- ### Set Include Directories with CMake Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/airspyhf/CMakeLists.txt Configures private include directories for the gnuradio-osmosdr target. Ensure LIBAIRSPYHF_INCLUDE_DIRS is defined. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBAIRSPYHF_INCLUDE_DIRS} ) ``` -------------------------------- ### Define gr-osmosdr Source Files Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/redpitaya/CMakeLists.txt Lists the source files for the gr-osmosdr library. These files are essential for the build process. ```cmake list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/redpitaya_source_c.cc ${CMAKE_CURRENT_SOURCE_DIR}/redpitaya_sink_c.cc ${CMAKE_CURRENT_SOURCE_DIR}/redpitaya_common.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Two-Tone Signal for IMD Testing with osmocom_siggen Source: https://context7.com/sdr/gr-osmosdr/llms.txt Generates a two-tone signal for Intermodulation Distortion testing using osmocom_siggen. Specify frequency, sample rate, and tone offsets. ```bash osmocom_siggen -a "hackrf=0" -f 433e6 -s 2e6 --2tone -x 10e3 -y -10e3 ``` -------------------------------- ### Configure CMake build targets for gr-osmosdr Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/soapy/CMakeLists.txt Sets include directories and appends source files to the build configuration. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${SoapySDR_INCLUDE_DIRS} ) APPEND_LIB_LIST( ${SoapySDR_LIBRARIES} ) list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/soapy_common.cc ${CMAKE_CURRENT_SOURCE_DIR}/soapy_source_c.cc ${CMAKE_CURRENT_SOURCE_DIR}/soapy_sink_c.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Add Subdirectories Source: https://github.com/sdr/gr-osmosdr/blob/master/CMakeLists.txt Includes project subdirectories based on enabled features. ```cmake add_subdirectory(include/osmosdr) add_subdirectory(lib) if(ENABLE_PYTHON) add_subdirectory(python) add_subdirectory(grc) add_subdirectory(apps) endif(ENABLE_PYTHON) add_subdirectory(docs) ``` -------------------------------- ### Define gr-osmosdr Source Files Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/uhd/CMakeLists.txt Lists the source files for the gr-osmosdr library. Includes UHD source files for sink and source components. ```cmake list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/uhd_sink_c.cc ${CMAKE_CURRENT_SOURCE_DIR}/uhd_source_c.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Configure CMake Build Targets Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/sdrplay/CMakeLists.txt Sets include directories and source files for the gnuradio-osmosdr target using CMake variables. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBSDRPLAY_INCLUDE_DIRS} ) APPEND_LIB_LIST( ${LIBSDRPLAY_LIBRARIES} ) list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/sdrplay_source_c.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Set Target Include Directories Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/bladerf/CMakeLists.txt Specifies private include directories for the gnuradio-osmosdr target. Includes current source directory and external library paths. ```cmake target_include_directories(gnuradio-osmosdr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBBLADERF_INCLUDE_DIRS} ${Volk_INCLUDE_DIRS} ) ``` -------------------------------- ### Set Specific Gain Stages with osmocom_fft Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configures osmocom_fft for an RTL-SDR and sets specific gain stages (LNA, VGA, IF) with their respective dB values. ```bash osmocom_fft -a "rtl=0" -f 100e6 -G "LNA:40,VGA:20,IF:30" ``` -------------------------------- ### RTL-SDR Configuration with osmocom_fft Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configures osmocom_fft for an RTL-SDR with specific center frequency, sample rate, gain, frequency correction, FFT size, and update rate. ```bash osmocom_fft -a "rtl=0" \ -f 433e6 \ -s 2.4e6 \ -g 40 \ -c 28.5 \ --fft-size 2048 \ --fft-rate 30 ``` -------------------------------- ### Define Source Files for gr-osmosdr Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/bladerf/CMakeLists.txt Lists the source files for the gr-osmosdr module. These files are used to build the library. ```cmake list(APPEND gr_osmosdr_srcs ${CMAKE_CURRENT_SOURCE_DIR}/bladerf_source_c.cc ${CMAKE_CURRENT_SOURCE_DIR}/bladerf_sink_c.cc ${CMAKE_CURRENT_SOURCE_DIR}/bladerf_common.cc ) set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE) ``` -------------------------------- ### Gain Control API Source: https://context7.com/sdr/gr-osmosdr/llms.txt Methods for setting and retrieving gain values for specific hardware gain stages. ```APIDOC ## set_gain / get_gain ### Description Sets or retrieves the gain for a specific named gain stage on the SDR device. ### Parameters - **gain** (float) - Required - Gain value in dB - **name** (string) - Required - Name of the gain stage - **chan** (int) - Required - Channel index ``` -------------------------------- ### Set Transmit Gain Stages with osmocom_siggen Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configures osmocom_siggen for a HackRF device and sets specific transmit gain stages (VGA, IF) with their respective dB values. ```bash osmocom_siggen -a "hackrf=0" -f 433e6 -g 14 -G "VGA:30,IF:40" ``` -------------------------------- ### Set Antenna Selection with osmocom_siggen Source: https://context7.com/sdr/gr-osmosdr/llms.txt Configures osmocom_siggen for a USRP device and selects the transmit/receive antenna. ```bash osmocom_siggen -a "uhd" -f 433e6 -A "TX/RX" ``` -------------------------------- ### DC Offset and IQ Balance Correction Source: https://context7.com/sdr/gr-osmosdr/llms.txt APIs to compensate for hardware imperfections like DC spikes and image signals. ```APIDOC ## DC Offset and IQ Balance Correction ### Description Configures DC offset and IQ balance correction modes and values to improve signal quality. ### Methods - **set_dc_offset_mode(mode, chan)** - Sets the DC offset correction mode (0: Off, 1: Manual, 2: Automatic) - **set_dc_offset(value, chan)** - Sets manual DC offset (complex value) - **set_iq_balance_mode(mode, chan)** - Sets IQ balance correction mode (0: Off, 1: Manual, 2: Automatic) - **set_iq_balance(value, chan)** - Sets manual IQ balance (complex value) ``` -------------------------------- ### Uniform Noise Transmission with osmocom_siggen Source: https://context7.com/sdr/gr-osmosdr/llms.txt Generates uniform noise using osmocom_siggen for a HackRF device. Specify frequency, sample rate, and amplitude. ```bash osmocom_siggen -a "hackrf=0" -f 433e6 -s 2e6 --uniform --amplitude 0.3 ``` -------------------------------- ### Detect High Resolution Timing Support Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/CMakeLists.txt Checks for platform-specific high-resolution timing APIs and sets the appropriate compile definitions. ```cmake set(CMAKE_REQUIRED_LIBRARIES -lrt) CHECK_CXX_SOURCE_COMPILES(" #include int main(){ timespec ts; return clock_gettime(CLOCK_MONOTONIC, &ts); } " HAVE_CLOCK_GETTIME ) unset(CMAKE_REQUIRED_LIBRARIES) include(CheckCXXSourceCompiles) CHECK_CXX_SOURCE_COMPILES(" #include int main(){ mach_timebase_info_data_t info; mach_timebase_info(&info); mach_absolute_time(); return 0; } " HAVE_MACH_ABSOLUTE_TIME ) CHECK_CXX_SOURCE_COMPILES(" #include int main(){ LARGE_INTEGER value; QueryPerformanceCounter(&value); QueryPerformanceFrequency(&value); return 0; } " HAVE_QUERY_PERFORMANCE_COUNTER ) if(HAVE_CLOCK_GETTIME) message(STATUS " High resolution timing supported through clock_gettime.") set(TIME_SPEC_DEFS HAVE_CLOCK_GETTIME) APPEND_LIB_LIST( "-lrt") elseif(HAVE_MACH_ABSOLUTE_TIME) message(STATUS " High resolution timing supported through mach_absolute_time.") set(TIME_SPEC_DEFS HAVE_MACH_ABSOLUTE_TIME) elseif(HAVE_QUERY_PERFORMANCE_COUNTER) message(STATUS " High resolution timing supported through QueryPerformanceCounter.") set(TIME_SPEC_DEFS HAVE_QUERY_PERFORMANCE_COUNTER) else() message(STATUS " High resolution timing supported through microsec_clock.") set(TIME_SPEC_DEFS HAVE_MICROSEC_CLOCK) endif() set_source_files_properties( time_spec.cc PROPERTIES COMPILE_DEFINITIONS "${TIME_SPEC_DEFS}" ) ``` -------------------------------- ### Gaussian Noise Transmission with osmocom_siggen Source: https://context7.com/sdr/gr-osmosdr/llms.txt Generates Gaussian noise using osmocom_siggen for a HackRF device. Specify frequency, sample rate, and amplitude. ```bash osmocom_siggen -a "hackrf=0" -f 433e6 -s 2e6 --gaussian --amplitude 0.3 ``` -------------------------------- ### Check for Python Module and Generate Bindings Source: https://github.com/sdr/gr-osmosdr/blob/master/python/bindings/CMakeLists.txt Verifies the presence of the pygccxml module and configures the build system to generate Python bindings for the osmosdr project. ```cmake GR_PYTHON_CHECK_MODULE_RAW( "pygccxml" "import pygccxml" PYGCCXML_FOUND ) ``` ```cmake list(APPEND osmosdr_python_files device_python.cc sink_python.cc source_python.cc ranges_python.cc time_spec_python.cc python_bindings.cc) GR_PYBIND_MAKE_OOT(osmosdr ../.. gr::osmosdr "${osmosdr_python_files}") ``` ```cmake install(TARGETS osmosdr_python DESTINATION ${GR_PYTHON_DIR}/osmosdr COMPONENT pythonapi) ``` -------------------------------- ### Frequency Sweep with osmocom_siggen Source: https://context7.com/sdr/gr-osmosdr/llms.txt Generates a frequency sweep signal using osmocom_siggen. Specify center frequency, sample rate, sweep width, and sweep rate. ```bash osmocom_siggen -a "hackrf=0" -f 433e6 -s 2e6 --sweep -x 1e6 -y 0.1 ``` -------------------------------- ### Append Libraries with CMake Source: https://github.com/sdr/gr-osmosdr/blob/master/lib/airspyhf/CMakeLists.txt Appends specified libraries to the build target. Requires Gnuradio-blocks_LIBRARIES and LIBAIRSPYHF_LIBRARIES to be defined. ```cmake APPEND_LIB_LIST( ${Gnuradio-blocks_LIBRARIES} ${LIBAIRSPYHF_LIBRARIES} ) ```