From 1b19970f6fdf8ea30fa82a118c938a3a3cb003e7 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sun, 25 Apr 2021 21:38:35 -0400 Subject: [PATCH] Use gr-network's UDP Sink in GNU Radio >= 3.9 --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 12 +++++++++++- src/interfaces/udp_sink_f.cpp | 20 +++++++++++++++++++- src/interfaces/udp_sink_f.h | 11 ++++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9584ff8dda..f3925d825c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,7 +122,7 @@ include(FindPkgConfig) find_package(Gnuradio-osmosdr REQUIRED) set(GR_REQUIRED_COMPONENTS RUNTIME ANALOG AUDIO BLOCKS DIGITAL FILTER FFT PMT) -find_package(Gnuradio REQUIRED COMPONENTS analog audio blocks digital filter fft) +find_package(Gnuradio REQUIRED COMPONENTS analog audio blocks digital filter fft network) if(Gnuradio_VERSION VERSION_LESS "3.8") find_package(Volk) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2adec26aff..5568c68ed1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,7 +73,17 @@ target_link_libraries(${PROJECT_NAME} ${VOLK_LIBRARIES} ) -if(NOT Gnuradio_VERSION VERSION_LESS "3.8") +if(NOT Gnuradio_VERSION VERSION_LESS "3.9") + target_link_libraries(${PROJECT_NAME} + gnuradio::gnuradio-analog + gnuradio::gnuradio-blocks + gnuradio::gnuradio-digital + gnuradio::gnuradio-filter + gnuradio::gnuradio-network + gnuradio::gnuradio-audio + Volk::volk + ) +elseif(NOT Gnuradio_VERSION VERSION_LESS "3.8") target_link_libraries(${PROJECT_NAME} gnuradio::gnuradio-analog gnuradio::gnuradio-blocks diff --git a/src/interfaces/udp_sink_f.cpp b/src/interfaces/udp_sink_f.cpp index 6b33418cc3..bb9e1771fc 100644 --- a/src/interfaces/udp_sink_f.cpp +++ b/src/interfaces/udp_sink_f.cpp @@ -20,9 +20,15 @@ * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ +#if GNURADIO_VERSION < 0x030900 +#include +#else +#include +#include +#endif + #include #include -#include #include #include @@ -52,6 +58,7 @@ udp_sink_f::udp_sink_f() { d_f2s = gr::blocks::float_to_short::make(1, 32767); +#if GNURADIO_VERSION < 0x030900 #ifdef GQRX_OS_MACX // There seems to be excessive packet loss (even to localhost) on OS X // unless the buffer size is limited. @@ -60,6 +67,7 @@ udp_sink_f::udp_sink_f() d_sink = gr::blocks::udp_sink::make(sizeof(short), "localhost", 7355); #endif d_sink->disconnect(); +#endif d_inter = gr::blocks::interleave::make(sizeof(float)); d_null0 = gr::blocks::null_sink::make(sizeof(float)); @@ -87,6 +95,10 @@ void udp_sink_f::start_streaming(const std::string host, int port, bool stereo) std::cout << ", Port: " << std::to_string(port) << ", "; std::cout << (stereo ? "Stereo" : "Mono") << std::endl; +#if GNURADIO_VERSION >= 0x030900 + d_sink = gr::network::udp_sink::make(sizeof(short), 1, host, port, HEADERTYPE_NONE, 1448, true); +#endif + if (stereo) { connect(self(), 0, d_inter, 0); @@ -102,7 +114,9 @@ void udp_sink_f::start_streaming(const std::string host, int port, bool stereo) } unlock(); +#if GNURADIO_VERSION < 0x030900 d_sink->connect(host, port); +#endif } @@ -116,5 +130,9 @@ void udp_sink_f::stop_streaming(void) std::cout << "Disconnected UDP streaming" << std::endl; +#if GNURADIO_VERSION < 0x030900 d_sink->disconnect(); +#else + d_sink = nullptr; +#endif } diff --git a/src/interfaces/udp_sink_f.h b/src/interfaces/udp_sink_f.h index 4e3c2c0f2a..0ff56bad59 100644 --- a/src/interfaces/udp_sink_f.h +++ b/src/interfaces/udp_sink_f.h @@ -23,9 +23,14 @@ #ifndef UDP_SINK_F_H #define UDP_SINK_F_H +#if GNURADIO_VERSION < 0x030900 +#include +#else +#include +#endif + #include #include -#include #include #include @@ -50,7 +55,11 @@ class udp_sink_f : public gr::hier_block2 void stop_streaming(void); private: +#if GNURADIO_VERSION < 0x030900 gr::blocks::udp_sink::sptr d_sink; /*!< The gnuradio UDP sink. */ +#else + gr::network::udp_sink::sptr d_sink; /*!< The gnuradio UDP sink. */ +#endif gr::blocks::float_to_short::sptr d_f2s; /*!< Converts float to short. */ gr::blocks::interleave::sptr d_inter; /*!< Stereo interleaver. */ gr::blocks::null_sink::sptr d_null0; /*!< Null sink for mono. */