Skip to content

Commit

Permalink
Use gr-network's UDP Sink in GNU Radio >= 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
argilo committed Apr 26, 2021
1 parent 706a72d commit 1b19970
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 11 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion src/interfaces/udp_sink_f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#if GNURADIO_VERSION < 0x030900
#include <gnuradio/blocks/udp_sink.h>
#else
#include <gnuradio/network/udp_header_types.h>
#include <gnuradio/network/udp_sink.h>
#endif

#include <gnuradio/hier_block2.h>
#include <gnuradio/blocks/float_to_short.h>
#include <gnuradio/blocks/udp_sink.h>
#include <gnuradio/io_signature.h>

#include <iostream>
Expand Down Expand Up @@ -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.
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -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
}


Expand All @@ -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
}
11 changes: 10 additions & 1 deletion src/interfaces/udp_sink_f.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
#ifndef UDP_SINK_F_H
#define UDP_SINK_F_H

#if GNURADIO_VERSION < 0x030900
#include <gnuradio/blocks/udp_sink.h>
#else
#include <gnuradio/network/udp_sink.h>
#endif

#include <gnuradio/hier_block2.h>
#include <gnuradio/blocks/float_to_short.h>
#include <gnuradio/blocks/udp_sink.h>
#include <gnuradio/blocks/interleave.h>
#include <gnuradio/blocks/null_sink.h>

Expand All @@ -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. */
Expand Down

1 comment on commit 1b19970

@ulrichloose
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried the changes, but I'm having problems ...

Version 3.9.1.0 of gnuradio is installed without homebrew and /usr/local/lib/cmake/gnuradio/gnuradio-networkConfig.cmake is available and is also found. Gqrx compiles without errors and is executable.

The only "application" that can test UDP streaming is a bit of (illegal) POCSAG1200 via netcat, sox, multimon-ng. With the identical gnuradio version, but the unpatched gqrx version via gnuradio / blocks / udp_sink.h, this works and you can read the messages.

However, this does not work with the new gnuradio / network change in gqrx. No messages...

Interesting thing: something is sure to be transferred via udp, because when exiting netcat ... the usual clipping error messages appear.

Has the data format possibly changed?

Please sign in to comment.