diff options
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 12 | ||||
-rw-r--r-- | gr-blocks/lib/pack_k_bits.cc | 59 | ||||
-rw-r--r-- | gr-blocks/lib/pack_k_bits_bb_impl.cc | 26 | ||||
-rw-r--r-- | gr-blocks/lib/pack_k_bits_bb_impl.h | 14 | ||||
-rw-r--r-- | gr-blocks/lib/unpack_k_bits.cc | 66 | ||||
-rw-r--r-- | gr-blocks/lib/unpack_k_bits_bb_impl.cc | 23 | ||||
-rw-r--r-- | gr-blocks/lib/unpack_k_bits_bb_impl.h | 5 |
7 files changed, 161 insertions, 44 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 0e7aab5e7c..416c2c5c2d 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -54,7 +54,7 @@ macro(expand_cc_h_impl root) list(APPEND expanded_files_h_impl ${CMAKE_CURRENT_BINARY_DIR}/${name}_impl.h) list(APPEND expanded_files_h ${CMAKE_CURRENT_BINARY_DIR}/../include/${name}.h) endforeach(sig) - + #create a command to generate the _impl.cc files add_custom_command( OUTPUT ${expanded_files_cc_impl} @@ -63,7 +63,7 @@ macro(expand_cc_h_impl root) ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py ${root} ${root}_impl.cc.t ${ARGN} ) - + #create a command to generate the _impl.h files add_custom_command( OUTPUT ${expanded_files_h_impl} @@ -72,19 +72,19 @@ macro(expand_cc_h_impl root) ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py ${root} ${root}_impl.h.t ${ARGN} ) - + #make _impl.cc source files depend on headers to force generation set_source_files_properties(${expanded_files_cc_impl} PROPERTIES OBJECT_DEPENDS "${expanded_files_h_impl}" ) - + #make _impl.h source files depend on headers to force generation set_source_files_properties(${expanded_files_h_impl} PROPERTIES OBJECT_DEPENDS "${expanded_files_h}" ) #install rules for the generated cc files - list(APPEND generated_sources ${expanded_files_cc_impl}) + list(APPEND generated_sources ${expanded_files_cc_impl}) endmacro(expand_cc_h_impl) ######################################################################## @@ -147,6 +147,8 @@ list(APPEND gr_blocks_sources control_loop.cc count_bits.cc file_sink_base.cc + pack_k_bits.cc + unpack_k_bits.cc wavfile.cc add_ff_impl.cc annotator_1to1_impl.cc diff --git a/gr-blocks/lib/pack_k_bits.cc b/gr-blocks/lib/pack_k_bits.cc new file mode 100644 index 0000000000..d0123f5a09 --- /dev/null +++ b/gr-blocks/lib/pack_k_bits.cc @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2014 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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gnuradio/blocks/pack_k_bits.h> +#include <stdexcept> +#include <iostream> + +namespace gr { + namespace blocks { + namespace kernel { + + pack_k_bits::pack_k_bits(unsigned k) + : d_k(k) + { + if(d_k == 0) + throw std::out_of_range("pack_k_bits: k must be > 0"); + } + + pack_k_bits::~pack_k_bits() + { + } + + void + pack_k_bits::pack(unsigned char *bytes, const unsigned char *bits, int nbytes) const + { + for(int i = 0; i < nbytes; i++) { + bytes[i] = 0x00; + for(unsigned int j = 0; j < d_k; j++) { + bytes[i] |= (0x01 & bits[i*d_k+j])<<(d_k-j-1); + } + } + } + + } /* namespace kernel */ + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/pack_k_bits_bb_impl.cc b/gr-blocks/lib/pack_k_bits_bb_impl.cc index 9009c89ab7..889e0d29f4 100644 --- a/gr-blocks/lib/pack_k_bits_bb_impl.cc +++ b/gr-blocks/lib/pack_k_bits_bb_impl.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* - * Copyright 2012-2013 Free Software Foundation, Inc. - * + * Copyright 2012-2014 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, @@ -43,15 +43,14 @@ namespace gr { : sync_decimator("pack_k_bits_bb", io_signature::make(1, 1, sizeof(unsigned char)), io_signature::make(1, 1, sizeof(unsigned char)), - k), - d_k(k) + k) { - if(d_k == 0) - throw std::out_of_range("interpolation must be > 0"); + d_pack = new kernel::pack_k_bits(k); } - + pack_k_bits_bb_impl::~pack_k_bits_bb_impl() { + delete d_pack; } int @@ -62,12 +61,7 @@ namespace gr { const unsigned char *in = (const unsigned char *)input_items[0]; unsigned char *out = (unsigned char *)output_items[0]; - for(int i = 0; i < noutput_items; i++) { - out[i] = 0x00; - for(unsigned int j = 0; j < d_k; j++) { - out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1); - } - } + d_pack->pack(out, in, noutput_items); return noutput_items; } diff --git a/gr-blocks/lib/pack_k_bits_bb_impl.h b/gr-blocks/lib/pack_k_bits_bb_impl.h index dfe859478c..38cf1e7517 100644 --- a/gr-blocks/lib/pack_k_bits_bb_impl.h +++ b/gr-blocks/lib/pack_k_bits_bb_impl.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* - * Copyright 2012-2013 Free Software Foundation, Inc. - * + * Copyright 2012-2014 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, @@ -24,6 +24,7 @@ #define INCLUDED_GR_PACK_K_BITS_BB_IMPL_H #include <gnuradio/blocks/pack_k_bits_bb.h> +#include <gnuradio/blocks/pack_k_bits.h> namespace gr { namespace blocks { @@ -32,7 +33,8 @@ namespace gr { { private: unsigned d_k; // number of relevent bits to pack from k input bytes - + kernel::pack_k_bits *d_pack; + public: pack_k_bits_bb_impl(unsigned k); ~pack_k_bits_bb_impl(); diff --git a/gr-blocks/lib/unpack_k_bits.cc b/gr-blocks/lib/unpack_k_bits.cc new file mode 100644 index 0000000000..f274cf5b60 --- /dev/null +++ b/gr-blocks/lib/unpack_k_bits.cc @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2014 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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gnuradio/blocks/unpack_k_bits.h> +#include <gnuradio/io_signature.h> +#include <stdexcept> +#include <iostream> + +namespace gr { + namespace blocks { + namespace kernel { + + unpack_k_bits::unpack_k_bits(unsigned k) + : d_k(k) + { + if(d_k == 0) + throw std::out_of_range("unpack_k_bits: k must be > 0"); + } + + unpack_k_bits::~unpack_k_bits() + { + } + + void + unpack_k_bits::unpack(unsigned char *bits, const unsigned char *bytes, int nbytes) const + { + int n = 0; + for(int i = 0; i < nbytes; i++) { + unsigned int t = bytes[i]; + for(int j = d_k - 1; j >= 0; j--) + bits[n++] = (t >> j) & 0x01; + } + } + + int + unpack_k_bits::k() const + { + return d_k; + } + + } /* namespace kernel */ + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/unpack_k_bits_bb_impl.cc b/gr-blocks/lib/unpack_k_bits_bb_impl.cc index 70055f9381..caf3d059d6 100644 --- a/gr-blocks/lib/unpack_k_bits_bb_impl.cc +++ b/gr-blocks/lib/unpack_k_bits_bb_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2010,2013 Free Software Foundation, Inc. + * Copyright 2005,2010,2013-2014 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -41,17 +41,16 @@ namespace gr { unpack_k_bits_bb_impl::unpack_k_bits_bb_impl(unsigned k) : sync_interpolator("unpack_k_bits_bb", - io_signature::make(1, 1, sizeof(unsigned char)), - io_signature::make(1, 1, sizeof(unsigned char)), - k), - d_k(k) + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(unsigned char)), + k) { - if(d_k == 0) - throw std::out_of_range("interpolation must be > 0"); + d_unpack = new kernel::unpack_k_bits(k); } unpack_k_bits_bb_impl::~unpack_k_bits_bb_impl() { + delete d_unpack; } int @@ -61,15 +60,9 @@ namespace gr { { const unsigned char *in = (const unsigned char *)input_items[0]; unsigned char *out = (unsigned char *)output_items[0]; - - int n = 0; - for(unsigned int i = 0; i < noutput_items/d_k; i++) { - unsigned int t = in[i]; - for(int j = d_k - 1; j >= 0; j--) - out[n++] = (t >> j) & 0x01; - } - assert(n == noutput_items); + d_unpack->unpack(out, in, noutput_items/d_unpack->k()); + return noutput_items; } diff --git a/gr-blocks/lib/unpack_k_bits_bb_impl.h b/gr-blocks/lib/unpack_k_bits_bb_impl.h index 7355d235c5..246c4ea724 100644 --- a/gr-blocks/lib/unpack_k_bits_bb_impl.h +++ b/gr-blocks/lib/unpack_k_bits_bb_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2013 Free Software Foundation, Inc. + * Copyright 2006,2013-2014 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,6 +24,7 @@ #define INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H #include <gnuradio/blocks/unpack_k_bits_bb.h> +#include <gnuradio/blocks/unpack_k_bits.h> namespace gr { namespace blocks { @@ -31,7 +32,7 @@ namespace gr { class unpack_k_bits_bb_impl : public unpack_k_bits_bb { private: - unsigned d_k; // number of relevent bits to unpack into k output bytes + kernel::unpack_k_bits *d_unpack; public: unpack_k_bits_bb_impl(unsigned k); |