From e618e70b123e3e32bd343a785d99ec653b5b9db5 Mon Sep 17 00:00:00 2001 From: Bastian Bloessl Date: Mon, 26 Aug 2019 13:20:54 +0200 Subject: [PATCH 01/10] cmake: adapt versioning to gr 3.8 --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd68d60..980fc8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,10 +41,10 @@ set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "") list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/Modules) # Set the version information here -set(VERSION_INFO_MAJOR_VERSION 3) -set(VERSION_INFO_API_COMPAT 8) -set(VERSION_INFO_MINOR_VERSION git) -set(VERSION_INFO_MAINT_VERSION 0) +set(VERSION_MAJOR 1) +set(VERSION_API 1) +set(VERSION_ABI 0) +set(VERSION_PATCH git) cmake_policy(SET CMP0011 NEW) From e3ada6d33e57d38cd30a3e1d158e9d3b04afcb75 Mon Sep 17 00:00:00 2001 From: Cyancali Date: Sat, 12 Oct 2019 12:10:49 +0200 Subject: [PATCH 02/10] Added new block: Pad Tagged Stream --- grc/CMakeLists.txt | 2 +- grc/foo_pad_tagged_stream.block.yml | 45 +++++++++++++++ include/foo/CMakeLists.txt | 2 +- include/foo/pad_tagged_stream.h | 55 ++++++++++++++++++ lib/CMakeLists.txt | 1 + lib/pad_tagged_stream_impl.cc | 86 +++++++++++++++++++++++++++++ lib/pad_tagged_stream_impl.h | 52 +++++++++++++++++ python/CMakeLists.txt | 1 + python/qa_pad_tagged_stream.py | 41 ++++++++++++++ swig/foo_swig.i | 3 + 10 files changed, 286 insertions(+), 2 deletions(-) create mode 100644 grc/foo_pad_tagged_stream.block.yml create mode 100644 include/foo/pad_tagged_stream.h create mode 100644 lib/pad_tagged_stream_impl.cc create mode 100644 lib/pad_tagged_stream_impl.h create mode 100755 python/qa_pad_tagged_stream.py diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index fd6f8e7..bb9028d 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -29,5 +29,5 @@ install(FILES foo_packet_dropper.block.yml foo_periodic_msg_source.block.yml foo_selector.block.yml - DESTINATION share/gnuradio/grc/blocks + foo_pad_tagged_stream.block.yml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/foo_pad_tagged_stream.block.yml b/grc/foo_pad_tagged_stream.block.yml new file mode 100644 index 0000000..8012887 --- /dev/null +++ b/grc/foo_pad_tagged_stream.block.yml @@ -0,0 +1,45 @@ +id: foo_pad_tagged_stream +label: Pad Tagged Stream +category: '[Foo]' + +templates: + imports: import foo + make: foo.pad_tagged_stream(${buffer_size}, ${len_tag_name}) + +# Make one 'parameters' list entry for every parameter you want settable from the GUI. +# Keys include: +# * id (makes the value accessible as \$keyname, e.g. in the make entry) +# * label (label shown in the GUI) +# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...) +parameters: +- id: buffer_size + label: Buffer Size + dtype: int +- id: len_tag_name + label: Length Tag Key + dtype: string + +# Make one 'inputs' list entry per input and one 'outputs' list entry per output. +# Keys include: +# * label (an identifier for the GUI) +# * domain (optional - stream or message. Default is stream) +# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...) +# * vlen (optional - data stream vector length. Default is 1) +# * optional (optional - set to 1 for optional inputs. Default is 0) +inputs: +- label: in + domain: stream + dtype: complex + vlen: 1 + optional: 0 + +outputs: +- label: out + domain: stream + dtype: complex + vlen: 1 + optional: 0 + +# 'file_format' specifies the version of the GRC yml format used in the file +# and should usually not be changed. +file_format: 1 diff --git a/include/foo/CMakeLists.txt b/include/foo/CMakeLists.txt index 4258fd4..b797ff3 100644 --- a/include/foo/CMakeLists.txt +++ b/include/foo/CMakeLists.txt @@ -31,5 +31,5 @@ install(FILES random_periodic_msg_source.h rtt_measure.h wireshark_connector.h - DESTINATION include/foo + pad_tagged_stream.h DESTINATION include/foo ) diff --git a/include/foo/pad_tagged_stream.h b/include/foo/pad_tagged_stream.h new file mode 100644 index 0000000..ac59c30 --- /dev/null +++ b/include/foo/pad_tagged_stream.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 "Cyancali". + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_FOO_PAD_TAGGED_STREAM_H +#define INCLUDED_FOO_PAD_TAGGED_STREAM_H + +#include +#include + +namespace gr { + namespace foo { + + /*! + * \brief <+description of block+> + * \ingroup foo + * + */ + class FOO_API pad_tagged_stream : virtual public gr::tagged_stream_block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * \brief Return a shared_ptr to a new instance of foo::pad_tagged_stream. + * + * To avoid accidental use of raw pointers, foo::pad_tagged_stream's + * constructor is in a private implementation + * class. foo::pad_tagged_stream::make is the public interface for + * creating new instances. + */ + static sptr make(int buffer_size, const std::string len_tag_name); + }; + + } // namespace foo +} // namespace gr + +#endif /* INCLUDED_FOO_PAD_TAGGED_STREAM_H */ + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 400517d..77edca2 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -39,6 +39,7 @@ list(APPEND foo_sources random_periodic_msg_source_impl.cc rtt_measure_impl.cc wireshark_connector_impl.cc + pad_tagged_stream_impl.cc ) set(foo_sources "${foo_sources}" PARENT_SCOPE) diff --git a/lib/pad_tagged_stream_impl.cc b/lib/pad_tagged_stream_impl.cc new file mode 100644 index 0000000..bcca35a --- /dev/null +++ b/lib/pad_tagged_stream_impl.cc @@ -0,0 +1,86 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 "Cyancali". + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "pad_tagged_stream_impl.h" + +namespace gr { + namespace foo { + + pad_tagged_stream::sptr + pad_tagged_stream::make(int buffer_size, const std::string len_tag_name) + { + return gnuradio::get_initial_sptr + (new pad_tagged_stream_impl(buffer_size, len_tag_name)); + } + + + /* + * The private constructor + */ + pad_tagged_stream_impl::pad_tagged_stream_impl(int buffer_size, const std::string len_tag_name) + : gr::tagged_stream_block("pad_tagged_stream", + gr::io_signature::make(1, 1, sizeof(gr_complex)), + gr::io_signature::make(1, 1, sizeof(gr_complex)), + len_tag_name), + d_buf_len(buffer_size), + d_len_tag(len_tag_name) + { + set_tag_propagation_policy(TPP_DONT); + } + + /* + * Our virtual destructor. + */ + pad_tagged_stream_impl::~pad_tagged_stream_impl() + { + } + + int + pad_tagged_stream_impl::calculate_output_stream_length(const gr_vector_int &ninput_items) + { + return d_buf_len; + } + + int + pad_tagged_stream_impl::work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *in = (const gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + + noutput_items = d_buf_len; + + memcpy((void*)out, (const void*)in, ninput_items[0]); + if (ninput_items[0] < noutput_items) memset((void*) (out+ninput_items[0]), 0, noutput_items-ninput_items[0]); + + return noutput_items; + + } + + } /* namespace foo */ +} /* namespace gr */ + diff --git a/lib/pad_tagged_stream_impl.h b/lib/pad_tagged_stream_impl.h new file mode 100644 index 0000000..9635704 --- /dev/null +++ b/lib/pad_tagged_stream_impl.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2019 "Cyancali". + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_FOO_PAD_TAGGED_STREAM_IMPL_H +#define INCLUDED_FOO_PAD_TAGGED_STREAM_IMPL_H + +#include + +namespace gr { + namespace foo { + + class pad_tagged_stream_impl : public pad_tagged_stream + { + private: + int d_buf_len; + std::string d_len_tag; + + public: + pad_tagged_stream_impl(int buffer_size, const std::string len_tag_name); + ~pad_tagged_stream_impl(); + + int calculate_output_stream_length(const gr_vector_int &ninput_items); + + // Where all the action really happens + int work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } // namespace foo +} // namespace gr + +#endif /* INCLUDED_FOO_PAD_TAGGED_STREAM_IMPL_H */ + diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 8ea97a3..70d961f 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -42,3 +42,4 @@ include(GrTest) set(GR_TEST_TARGET_DEPS gnuradio-foo) set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig) +GR_ADD_TEST(qa_pad_tagged_stream ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_pad_tagged_stream.py) diff --git a/python/qa_pad_tagged_stream.py b/python/qa_pad_tagged_stream.py new file mode 100755 index 0000000..cbc2996 --- /dev/null +++ b/python/qa_pad_tagged_stream.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2019 "Cyancali". +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +from gnuradio import blocks +import foo_swig as foo + +class qa_pad_tagged_stream(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001_t(self): + # set up fg + self.tb.run() + # check data + + +if __name__ == '__main__': + gr_unittest.run(qa_pad_tagged_stream) diff --git a/swig/foo_swig.i b/swig/foo_swig.i index e1845d3..ac9ff79 100644 --- a/swig/foo_swig.i +++ b/swig/foo_swig.i @@ -17,6 +17,7 @@ #include "foo/random_periodic_msg_source.h" #include "foo/rtt_measure.h" #include "foo/wireshark_connector.h" +#include "foo/pad_tagged_stream.h" %} @@ -39,3 +40,5 @@ GR_SWIG_BLOCK_MAGIC2(foo, periodic_msg_source); GR_SWIG_BLOCK_MAGIC2(foo, random_periodic_msg_source); GR_SWIG_BLOCK_MAGIC2(foo, rtt_measure); GR_SWIG_BLOCK_MAGIC2(foo, wireshark_connector); +%include "foo/pad_tagged_stream.h" +GR_SWIG_BLOCK_MAGIC2(foo, pad_tagged_stream); From c81c8dfa199f1d461bd78cbe056701780dfc5363 Mon Sep 17 00:00:00 2001 From: Cyancali Date: Sat, 12 Oct 2019 12:22:12 +0200 Subject: [PATCH 03/10] lib/pad_tagged_stream_impl.cc: Added minimum output buffer size to not need to set it in the advanced tab --- lib/pad_tagged_stream_impl.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pad_tagged_stream_impl.cc b/lib/pad_tagged_stream_impl.cc index bcca35a..8b70690 100644 --- a/lib/pad_tagged_stream_impl.cc +++ b/lib/pad_tagged_stream_impl.cc @@ -47,6 +47,7 @@ namespace gr { d_buf_len(buffer_size), d_len_tag(len_tag_name) { + set_min_output_buffer(buffer_size*2); set_tag_propagation_policy(TPP_DONT); } From e980b54f19858ff8ae83d70232b2dcd589a2d3c9 Mon Sep 17 00:00:00 2001 From: Cyancali Date: Sat, 12 Oct 2019 13:11:58 +0200 Subject: [PATCH 04/10] README.md: added documentation about the Pad Tagged Stream block --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 7fef886..0041f61 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,17 @@ I used this block for automated performance tests with no-GUI flow graphs. +### Pad Tagged Stream + +Pads an incoming tagged stream with 0s to the set buffer size. +Padding is applied to the tail of the tagged stream. + +This is useful when transmitting packetized data by using a Pluto as SDR. +The Pluto does currently not support a partial buffer flush triggered by an incoming tagged stream. +Therefore this block pads incoming tagged stream to fill the Pluto buffer to enforce an immediate transmission. + + + ### Installation ``` From 82b479c3e056979e218fcd676a64b2d4db3adb1b Mon Sep 17 00:00:00 2001 From: Cyancali Date: Tue, 15 Oct 2019 07:59:54 +0200 Subject: [PATCH 05/10] grc/foo_pad_tagged_stream.block: Added default value for buffer size to match default Pluto buffer size --- grc/foo_pad_tagged_stream.block.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/grc/foo_pad_tagged_stream.block.yml b/grc/foo_pad_tagged_stream.block.yml index 8012887..9226f67 100644 --- a/grc/foo_pad_tagged_stream.block.yml +++ b/grc/foo_pad_tagged_stream.block.yml @@ -15,6 +15,7 @@ parameters: - id: buffer_size label: Buffer Size dtype: int + default: '0x8000' - id: len_tag_name label: Length Tag Key dtype: string From 2ab199f87ab0b60fd9669c93b7bbbfca9fab0874 Mon Sep 17 00:00:00 2001 From: Cyancali Date: Tue, 15 Oct 2019 08:19:47 +0200 Subject: [PATCH 06/10] lib/pad_tagged_stream_impl.cc: Added a warning if tagged stream is longer than buffer size --- lib/pad_tagged_stream_impl.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/pad_tagged_stream_impl.cc b/lib/pad_tagged_stream_impl.cc index 8b70690..74c36dd 100644 --- a/lib/pad_tagged_stream_impl.cc +++ b/lib/pad_tagged_stream_impl.cc @@ -75,11 +75,19 @@ namespace gr { noutput_items = d_buf_len; + memcpy((void*)out, (const void*)in, ninput_items[0]); - if (ninput_items[0] < noutput_items) memset((void*) (out+ninput_items[0]), 0, noutput_items-ninput_items[0]); + + if (ninput_items[0] <= noutput_items) + { + memset((void*) (out+ninput_items[0]), 0, noutput_items-ninput_items[0]); + } + else // ninput_items[0] > noutput_items + { + std::cout << "PadTaggedStream: Warning - Tagged stream is longer than buffer" << std::endl; + } return noutput_items; - } } /* namespace foo */ From 84b4e9500723c55743e1076f5f44feeac637eb9a Mon Sep 17 00:00:00 2001 From: Cyancali Date: Tue, 15 Oct 2019 08:30:40 +0200 Subject: [PATCH 07/10] lib/pad_tagged_stream_impl.cc: Apply min call to avoid copying too much input --- lib/pad_tagged_stream_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pad_tagged_stream_impl.cc b/lib/pad_tagged_stream_impl.cc index 74c36dd..be41bc9 100644 --- a/lib/pad_tagged_stream_impl.cc +++ b/lib/pad_tagged_stream_impl.cc @@ -76,7 +76,7 @@ namespace gr { noutput_items = d_buf_len; - memcpy((void*)out, (const void*)in, ninput_items[0]); + memcpy((void*)out, (const void*)in, std::min(d_buf_len, ninput_items[0])); if (ninput_items[0] <= noutput_items) { From 65421a6755104c9de164f8777105760ee49ee980 Mon Sep 17 00:00:00 2001 From: aewag Date: Sun, 20 Oct 2019 12:56:21 +0200 Subject: [PATCH 08/10] lib/pad_tagged_stream_impl: Added element size to memcpy/memset call as the tagged stream is without it not completely copied --- lib/pad_tagged_stream_impl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pad_tagged_stream_impl.cc b/lib/pad_tagged_stream_impl.cc index be41bc9..9d61920 100644 --- a/lib/pad_tagged_stream_impl.cc +++ b/lib/pad_tagged_stream_impl.cc @@ -76,11 +76,11 @@ namespace gr { noutput_items = d_buf_len; - memcpy((void*)out, (const void*)in, std::min(d_buf_len, ninput_items[0])); + memcpy(out, in, sizeof(gr_complex) * std::min(d_buf_len, ninput_items[0])); if (ninput_items[0] <= noutput_items) { - memset((void*) (out+ninput_items[0]), 0, noutput_items-ninput_items[0]); + memset((out+ninput_items[0]), 0, sizeof(gr_complex) * noutput_items-ninput_items[0]); } else // ninput_items[0] > noutput_items { From 13fac53de827ece4f2a5a367ed8cb3900238b3f6 Mon Sep 17 00:00:00 2001 From: Bastian Bloessl Date: Tue, 17 Dec 2019 11:12:14 +0100 Subject: [PATCH 09/10] GR API was messed up through merging dev branch --- lib/periodic_msg_source_impl.cc | 2 +- lib/random_periodic_msg_source_impl.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/periodic_msg_source_impl.cc b/lib/periodic_msg_source_impl.cc index 8dbd9dd..d97b5f3 100644 --- a/lib/periodic_msg_source_impl.cc +++ b/lib/periodic_msg_source_impl.cc @@ -65,7 +65,7 @@ periodic_msg_source_impl::run(periodic_msg_source_impl *instance) { d_finished = true; if(d_quit) { boost::this_thread::sleep(boost::posix_time::milliseconds(500)); - post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::PMT_T)); + post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::from_long(1))); } break; } diff --git a/lib/random_periodic_msg_source_impl.cc b/lib/random_periodic_msg_source_impl.cc index 1bf370d..32a6d6b 100644 --- a/lib/random_periodic_msg_source_impl.cc +++ b/lib/random_periodic_msg_source_impl.cc @@ -70,7 +70,7 @@ random_periodic_msg_source_impl::run(random_periodic_msg_source_impl *instance) d_finished = true; if(d_quit) { boost::this_thread::sleep(boost::posix_time::milliseconds(500)); - post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::PMT_T)); + post(pmt::mp("system"), pmt::cons(pmt::mp("done"), pmt::from_long(1))); } break; } From e17edbd4ad0f4f5fd613f589bc83ff9700be5ba2 Mon Sep 17 00:00:00 2001 From: Bastian Bloessl Date: Wed, 12 Aug 2020 11:46:12 +0200 Subject: [PATCH 10/10] boost 1.73 fix --- lib/packet_dropper_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/packet_dropper_impl.cc b/lib/packet_dropper_impl.cc index 53212f2..c5f2499 100644 --- a/lib/packet_dropper_impl.cc +++ b/lib/packet_dropper_impl.cc @@ -32,7 +32,7 @@ packet_dropper_impl::packet_dropper_impl(double drop_rate, unsigned long seed) throw std::out_of_range("drop rate has to be < 1"); } message_port_register_in(pmt::mp("in")); - set_msg_handler(pmt::mp("in"), boost::bind(&packet_dropper_impl::msg_handler, this, _1)); + set_msg_handler(pmt::mp("in"), boost::bind(&packet_dropper_impl::msg_handler, this, boost::placeholders::_1)); message_port_register_out(pmt::mp("out")); }