diff options
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 3 | ||||
-rw-r--r-- | gr-blocks/lib/repack_bits_bb_impl.cc | 123 | ||||
-rw-r--r-- | gr-blocks/lib/repack_bits_bb_impl.h | 58 | ||||
-rw-r--r-- | gr-blocks/lib/tagged_stream_mux_impl.cc | 93 | ||||
-rw-r--r-- | gr-blocks/lib/tagged_stream_mux_impl.h | 54 |
5 files changed, 331 insertions, 0 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index d64287c749..ee4658ae34 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -194,6 +194,7 @@ list(APPEND gr_blocks_sources peak_detector2_fb_impl.cc probe_rate_impl.cc regenerate_bb_impl.cc + repack_bits_bb_impl.cc repeat_impl.cc rms_cf_impl.cc rms_ff_impl.cc @@ -214,6 +215,7 @@ list(APPEND gr_blocks_sources transcendental_impl.cc tcp_connection.cc tuntap_pdu_impl.cc + tagged_stream_mux_impl.cc uchar_array_to_float.cc uchar_to_float_impl.cc udp_sink_impl.cc @@ -245,6 +247,7 @@ list(APPEND blocks_libs volk ${Boost_LIBRARIES} ${BLOCKS_LIBRARIES} + ${LOG4CPP_LIBRARIES} ) add_library(gnuradio-blocks SHARED ${gr_blocks_sources}) diff --git a/gr-blocks/lib/repack_bits_bb_impl.cc b/gr-blocks/lib/repack_bits_bb_impl.cc new file mode 100644 index 0000000000..c7ed054c8a --- /dev/null +++ b/gr-blocks/lib/repack_bits_bb_impl.cc @@ -0,0 +1,123 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; 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 <gr_io_signature.h> +#include "repack_bits_bb_impl.h" + +namespace gr { + namespace blocks { + + repack_bits_bb::sptr + repack_bits_bb::make(int k, int l, const std::string &len_tag_key, bool align_output) + { + return gnuradio::get_initial_sptr (new repack_bits_bb_impl(k, l, len_tag_key, align_output)); + } + + repack_bits_bb_impl::repack_bits_bb_impl(int k, int l, const std::string &len_tag_key, bool align_output) + : gr_tagged_stream_block("repack_bits_bb", + gr_make_io_signature(1, 1, sizeof (char)), + gr_make_io_signature(1, 1, sizeof (char)), + len_tag_key), + d_k(k), d_l(l), + d_packet_mode(!len_tag_key.empty()), + d_in_index(0), d_out_index(0), + d_align_output(align_output) + { + if (d_k > 8 || d_k < 1 || d_l > 8 || d_l < 1) { + throw std::invalid_argument("k and l must be in [1, 8]"); + } + + set_relative_rate((double) d_k / d_l); + } + + repack_bits_bb_impl::~repack_bits_bb_impl() + { + } + + int + repack_bits_bb_impl::calculate_output_stream_length(const gr_vector_int &ninput_items) + { + int n_out_bytes_required = (ninput_items[0] * d_k) / d_l; + if ((ninput_items[0] * d_k) % d_l && (!d_packet_mode || (d_packet_mode && !d_align_output))) { + n_out_bytes_required++; + } + + return n_out_bytes_required; + } + + int + repack_bits_bb_impl::work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const unsigned char *in = (const unsigned char *) input_items[0]; + unsigned char *out = (unsigned char *) output_items[0]; + int bytes_to_write = noutput_items; + + if (d_packet_mode) { // noutput_items could be larger than necessary + int bytes_to_read = ninput_items[0]; + bytes_to_write = bytes_to_read * d_k / d_l; + if (!d_align_output && (((bytes_to_read * d_k) % d_l) != 0)) { + bytes_to_write++; + } + } + + int n_read = 0; + int n_written = 0; + while(n_written < bytes_to_write && n_read < ninput_items[0]) { + if (d_out_index == 0) { // Starting a fresh byte + out[n_written] = 0; + } + out[n_written] |= ((in[n_read] >> d_in_index) & 0x01) << d_out_index; + + d_in_index = (d_in_index + 1) % d_k; + d_out_index = (d_out_index + 1) % d_l; + if (d_in_index == 0) { + n_read++; + d_in_index = 0; + } + if (d_out_index == 0) { + n_written++; + d_out_index = 0; + } + } + + if (d_packet_mode) { + if (d_out_index) { + n_written++; + d_out_index = 0; + } + } else { + consume_each(n_read); + } + + return n_written; + } + + } /* namespace blocks */ +} /* namespace gr */ + diff --git a/gr-blocks/lib/repack_bits_bb_impl.h b/gr-blocks/lib/repack_bits_bb_impl.h new file mode 100644 index 0000000000..bf39f8cb0f --- /dev/null +++ b/gr-blocks/lib/repack_bits_bb_impl.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_BLOCKS_REPACK_BITS_BB_IMPL_H +#define INCLUDED_BLOCKS_REPACK_BITS_BB_IMPL_H + +#include <blocks/repack_bits_bb.h> + +namespace gr { + namespace blocks { + + class repack_bits_bb_impl : public repack_bits_bb + { + private: + const int d_k; //! Bits on input stream + const int d_l; //! Bits on output stream + const bool d_packet_mode; + int d_in_index; // Current bit of input byte + int d_out_index; // Current bit of output byte + bool d_align_output; //! true if the output shall be aligned, false if the input shall be aligned + + protected: + int calculate_output_stream_length(const gr_vector_int &ninput_items); + + public: + repack_bits_bb_impl(int k, int l, const std::string &len_tag_key, bool align_output); + ~repack_bits_bb_impl(); + + int work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } // namespace blocks +} // namespace gr + +#endif /* INCLUDED_BLOCKS_REPACK_BITS_BB_IMPL_H */ + diff --git a/gr-blocks/lib/tagged_stream_mux_impl.cc b/gr-blocks/lib/tagged_stream_mux_impl.cc new file mode 100644 index 0000000000..59e36fa07e --- /dev/null +++ b/gr-blocks/lib/tagged_stream_mux_impl.cc @@ -0,0 +1,93 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; 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 <gr_io_signature.h> +#include "tagged_stream_mux_impl.h" + +namespace gr { + namespace blocks { + + tagged_stream_mux::sptr + tagged_stream_mux::make(size_t itemsize, const std::string &lengthtagname) + { + return gnuradio::get_initial_sptr (new tagged_stream_mux_impl(itemsize, lengthtagname)); + } + + tagged_stream_mux_impl::tagged_stream_mux_impl(size_t itemsize, const std::string &lengthtagname) + : gr_tagged_stream_block("tagged_stream_mux", + gr_make_io_signature(1, -1, itemsize), + gr_make_io_signature(1, 1, itemsize), + lengthtagname), + d_itemsize(itemsize) + { + set_tag_propagation_policy(TPP_DONT); + } + + tagged_stream_mux_impl::~tagged_stream_mux_impl() + { + } + + int + tagged_stream_mux_impl::calculate_output_stream_length(const gr_vector_int &ninput_items) + { + int nout = 0; + for (unsigned i = 0; i < ninput_items.size(); i++) { + nout += ninput_items[i]; + } + return nout; + } + + int + tagged_stream_mux_impl::work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + unsigned char *out = (unsigned char *) output_items[0]; + int n_produced = 0; + + set_relative_rate(ninput_items.size()); + + for (unsigned int i = 0; i < input_items.size(); i++) { + const unsigned char *in = (const unsigned char *) input_items[i]; + + std::vector<gr_tag_t> tags; + get_tags_in_range(tags, i, nitems_read(i), nitems_read(i)+ninput_items[i]); + for (unsigned int j = 0; j < tags.size(); j++) { + const uint64_t offset = tags[j].offset - nitems_read(i) + nitems_written(0) + n_produced; + add_item_tag(0, offset, tags[j].key, tags[j].value); + } + memcpy((void *) out, (const void *) in, ninput_items[i] * d_itemsize); + out += ninput_items[i] * d_itemsize; + n_produced += ninput_items[i]; + } + + return n_produced; + } + + } /* namespace blocks */ +} /* namespace gr */ + diff --git a/gr-blocks/lib/tagged_stream_mux_impl.h b/gr-blocks/lib/tagged_stream_mux_impl.h new file mode 100644 index 0000000000..19862e6868 --- /dev/null +++ b/gr-blocks/lib/tagged_stream_mux_impl.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_TAGGED_STREAM_MUX_IMPL_H +#define INCLUDED_TAGGED_STREAM_MUX_IMPL_H + +#include <vector> +#include <blocks/tagged_stream_mux.h> + +namespace gr { + namespace blocks { + + class tagged_stream_mux_impl : public tagged_stream_mux + { + private: + size_t d_itemsize; + + protected: + int calculate_output_stream_length(const std::vector<int> &ninput_items); + + public: + tagged_stream_mux_impl(size_t itemsize, const std::string &lengthtagname); + ~tagged_stream_mux_impl(); + + int work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } // namespace blocks +} // namespace gr + +#endif + |