diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2019-08-07 21:45:12 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2019-08-09 23:04:28 +0200 |
commit | f7bbf2c1d8d780294f3e016aff239ca35eb6516e (patch) | |
tree | e09ab6112e02b2215b2d59ac24d3d6ea2edac745 /gr-blocks/lib | |
parent | 78431dc6941e3acc67c858277dfe4a0ed583643c (diff) |
Tree: clang-format without the include sorting
Diffstat (limited to 'gr-blocks/lib')
319 files changed, 13407 insertions, 13798 deletions
diff --git a/gr-blocks/lib/abs_blk_impl.cc b/gr-blocks/lib/abs_blk_impl.cc index aab0c8552a..cc772aec81 100644 --- a/gr-blocks/lib/abs_blk_impl.cc +++ b/gr-blocks/lib/abs_blk_impl.cc @@ -29,42 +29,41 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename abs_blk<T>::sptr abs_blk<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new abs_blk_impl<T> (vlen)); - } +template <class T> +typename abs_blk<T>::sptr abs_blk<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new abs_blk_impl<T>(vlen)); +} - template <class T> - abs_blk_impl<T> ::abs_blk_impl (size_t vlen) - : sync_block("abs_blk", - io_signature::make (1, 1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), - d_vlen(vlen) - { - } +template <class T> +abs_blk_impl<T>::abs_blk_impl(size_t vlen) + : sync_block("abs_blk", + io_signature::make(1, 1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), + d_vlen(vlen) +{ +} - template <class T> - int - abs_blk_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T *) input_items[0]; - T *optr = (T *) output_items[0]; +template <class T> +int abs_blk_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; + T* optr = (T*)output_items[0]; - for(size_t i=0; i<noutput_items*d_vlen; i++) { + for (size_t i = 0; i < noutput_items * d_vlen; i++) { T val = iptr[i]; optr[i] = ((val < ((T)0)) ? -val : val); - } - - return noutput_items; } + return noutput_items; +} + template class abs_blk<std::int16_t>; template class abs_blk<std::int32_t>; template class abs_blk<float>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/abs_blk_impl.h b/gr-blocks/lib/abs_blk_impl.h index 787a056767..d9e54785f2 100644 --- a/gr-blocks/lib/abs_blk_impl.h +++ b/gr-blocks/lib/abs_blk_impl.h @@ -27,23 +27,23 @@ #include <gnuradio/blocks/abs_blk.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API abs_blk_impl : public abs_blk<T> - { - private: - size_t d_vlen; +template <class T> +class BLOCKS_API abs_blk_impl : public abs_blk<T> +{ +private: + size_t d_vlen; - public: - abs_blk_impl(size_t vlen); +public: + abs_blk_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ABS_BLK_IMPL_H */ diff --git a/gr-blocks/lib/add_blk_impl.cc b/gr-blocks/lib/add_blk_impl.cc index 9cda4d080e..2b6cdc0b0d 100644 --- a/gr-blocks/lib/add_blk_impl.cc +++ b/gr-blocks/lib/add_blk_impl.cc @@ -30,77 +30,73 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - template <class T> - typename add_blk<T>::sptr add_blk<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new add_blk_impl<T> (vlen)); - } +namespace blocks { +template <class T> +typename add_blk<T>::sptr add_blk<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new add_blk_impl<T>(vlen)); +} - template <> - add_blk_impl<float>::add_blk_impl(size_t vlen) - : sync_block("add_ff", - io_signature::make (1, -1, sizeof(float)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1, alignment_multiple)); - } - template <> - int - add_blk_impl<float>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float *out = (float *) output_items[0]; - int noi = d_vlen*noutput_items; - - memcpy(out, input_items[0], noi*sizeof(float)); - for(size_t i = 1; i < input_items.size(); i++) +template <> +add_blk_impl<float>::add_blk_impl(size_t vlen) + : sync_block("add_ff", + io_signature::make(1, -1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +template <> +int add_blk_impl<float>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float* out = (float*)output_items[0]; + int noi = d_vlen * noutput_items; + + memcpy(out, input_items[0], noi * sizeof(float)); + for (size_t i = 1; i < input_items.size(); i++) volk_32f_x2_add_32f(out, out, (const float*)input_items[i], noi); - return noutput_items; - } + return noutput_items; +} - - template <class T> - add_blk_impl<T> ::add_blk_impl (size_t vlen) - : sync_block ("add_blk", - io_signature::make (1, -1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), +template <class T> +add_blk_impl<T>::add_blk_impl(size_t vlen) + : sync_block("add_blk", + io_signature::make(1, -1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), d_vlen(vlen) - { - } +{ +} - template <class T> - int - add_blk_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *) output_items[0]; +template <class T> +int add_blk_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; - int ninputs = input_items.size (); + int ninputs = input_items.size(); - for (size_t i = 0; i < noutput_items*d_vlen; i++){ - T acc = ((T *) input_items[0])[i]; - for (int j = 1; j < ninputs; j++) - acc += ((T *) input_items[j])[i]; + for (size_t i = 0; i < noutput_items * d_vlen; i++) { + T acc = ((T*)input_items[0])[i]; + for (int j = 1; j < ninputs; j++) + acc += ((T*)input_items[j])[i]; - *optr++ = (T) acc; - } - - return noutput_items; + *optr++ = (T)acc; } + return noutput_items; +} + template class add_blk<std::int16_t>; template class add_blk<std::int32_t>; template class add_blk<gr_complex>; template class add_blk<float>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/add_blk_impl.h b/gr-blocks/lib/add_blk_impl.h index 74f3e1bac1..adc0bc5df7 100644 --- a/gr-blocks/lib/add_blk_impl.h +++ b/gr-blocks/lib/add_blk_impl.h @@ -27,23 +27,23 @@ #include <gnuradio/blocks/add_blk.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> -class BLOCKS_API add_blk_impl : public add_blk<T> - { - private: - size_t d_vlen; +template <class T> +class BLOCKS_API add_blk_impl : public add_blk<T> +{ +private: + size_t d_vlen; - public: - add_blk_impl (size_t vlen); +public: + add_blk_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ADD_BLK_IMPL_H */ diff --git a/gr-blocks/lib/add_const_bb_impl.cc b/gr-blocks/lib/add_const_bb_impl.cc index 8f225d6e68..1ac9aff4ba 100644 --- a/gr-blocks/lib/add_const_bb_impl.cc +++ b/gr-blocks/lib/add_const_bb_impl.cc @@ -28,80 +28,79 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - add_const_bb::sptr add_const_bb::make(unsigned char k) - { - return gnuradio::get_initial_sptr - (new add_const_bb_impl(k)); - } - - add_const_bb_impl::add_const_bb_impl(unsigned char k) - : sync_block("add_const_bb", - io_signature::make (1, 1, sizeof(unsigned char)), - io_signature::make (1, 1, sizeof(unsigned char))), - d_k(k) - { - } +add_const_bb::sptr add_const_bb::make(unsigned char k) +{ + return gnuradio::get_initial_sptr(new add_const_bb_impl(k)); +} - add_const_bb_impl::~add_const_bb_impl() - { - } +add_const_bb_impl::add_const_bb_impl(unsigned char k) + : sync_block("add_const_bb", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(unsigned char))), + d_k(k) +{ +} - int - add_const_bb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *iptr = (const unsigned char *) input_items[0]; - unsigned char *optr = (unsigned char *) output_items[0]; +add_const_bb_impl::~add_const_bb_impl() {} - int size = noutput_items; +int add_const_bb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* iptr = (const unsigned char*)input_items[0]; + unsigned char* optr = (unsigned char*)output_items[0]; - while(size >= 8) { - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - size -= 8; - } + int size = noutput_items; - while(size-- > 0) { - *optr++ = *iptr++ + d_k; - } + while (size >= 8) { + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + size -= 8; + } - return noutput_items; + while (size-- > 0) { + *optr++ = *iptr++ + d_k; } - void - add_const_bb_impl::setup_rpc() - { + return noutput_items; +} + +void add_const_bb_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_get<add_const_bb, unsigned char>( - alias(), "Constant", - &add_const_bb::k, - pmt::from_long(-128), - pmt::from_long(127), - pmt::from_long(0), - "", "Constant to add", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); + add_rpc_variable(rpcbasic_sptr(new rpcbasic_register_get<add_const_bb, unsigned char>( + alias(), + "Constant", + &add_const_bb::k, + pmt::from_long(-128), + pmt::from_long(127), + pmt::from_long(0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_set<add_const_bb, unsigned char>( - alias(), "Constant", - &add_const_bb::set_k, - pmt::from_long(-128), - pmt::from_long(127), - pmt::from_long(0), - "", "Constant to add", - RPC_PRIVLVL_MIN, DISPNULL))); + add_rpc_variable(rpcbasic_sptr( + new rpcbasic_register_set<add_const_bb, unsigned char>(alias(), + "Constant", + &add_const_bb::set_k, + pmt::from_long(-128), + pmt::from_long(127), + pmt::from_long(0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/add_const_bb_impl.h b/gr-blocks/lib/add_const_bb_impl.h index 677569c45c..99a44c4f6d 100644 --- a/gr-blocks/lib/add_const_bb_impl.h +++ b/gr-blocks/lib/add_const_bb_impl.h @@ -26,28 +26,28 @@ #include <gnuradio/blocks/add_const_bb.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API add_const_bb_impl : public add_const_bb - { - private: - unsigned char d_k; +class BLOCKS_API add_const_bb_impl : public add_const_bb +{ +private: + unsigned char d_k; - public: - add_const_bb_impl(unsigned char k); - ~add_const_bb_impl(); +public: + add_const_bb_impl(unsigned char k); + ~add_const_bb_impl(); - void setup_rpc(); + void setup_rpc(); - unsigned char k() const { return d_k; } - void set_k(unsigned char k) { d_k = k; } + unsigned char k() const { return d_k; } + void set_k(unsigned char k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ADD_CONST_BB_IMPL */ diff --git a/gr-blocks/lib/add_const_cc_impl.cc b/gr-blocks/lib/add_const_cc_impl.cc index 133d45dfc0..6c326f1e1f 100644 --- a/gr-blocks/lib/add_const_cc_impl.cc +++ b/gr-blocks/lib/add_const_cc_impl.cc @@ -28,76 +28,77 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - add_const_cc::sptr add_const_cc::make(gr_complex k) - { - return gnuradio::get_initial_sptr - (new add_const_cc_impl(k)); - } - - add_const_cc_impl::add_const_cc_impl(gr_complex k) - : sync_block("add_const_cc", - io_signature::make (1, 1, sizeof(gr_complex)), - io_signature::make (1, 1, sizeof(gr_complex))), - d_k(k) - { - } +add_const_cc::sptr add_const_cc::make(gr_complex k) +{ + return gnuradio::get_initial_sptr(new add_const_cc_impl(k)); +} - int - add_const_cc_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *iptr = (const gr_complex *) input_items[0]; - gr_complex *optr = (gr_complex *) output_items[0]; +add_const_cc_impl::add_const_cc_impl(gr_complex k) + : sync_block("add_const_cc", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))), + d_k(k) +{ +} - int size = noutput_items; +int add_const_cc_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* iptr = (const gr_complex*)input_items[0]; + gr_complex* optr = (gr_complex*)output_items[0]; - while(size >= 8) { - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - size -= 8; - } + int size = noutput_items; - while(size-- > 0) { - *optr++ = *iptr++ + d_k; - } + while (size >= 8) { + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + size -= 8; + } - return noutput_items; + while (size-- > 0) { + *optr++ = *iptr++ + d_k; } - void - add_const_cc_impl::setup_rpc() - { + return noutput_items; +} + +void add_const_cc_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_get<add_const_cc, gr_complex>( - alias(), "Constant", - &add_const_cc::k, - pmt::from_complex(-4.29e9, 0), - pmt::from_complex(4.29e9, 0), - pmt::from_complex(0, 0), - "", "Constant to add", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); + add_rpc_variable(rpcbasic_sptr(new rpcbasic_register_get<add_const_cc, gr_complex>( + alias(), + "Constant", + &add_const_cc::k, + pmt::from_complex(-4.29e9, 0), + pmt::from_complex(4.29e9, 0), + pmt::from_complex(0, 0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_set<add_const_cc, gr_complex>( - alias(), "Constant", - &add_const_cc::set_k, - pmt::from_complex(-4.29e9, 0), - pmt::from_complex(4.29e9, 0), - pmt::from_complex(0, 0), - "", "Constant to add", - RPC_PRIVLVL_MIN, DISPNULL))); + add_rpc_variable(rpcbasic_sptr( + new rpcbasic_register_set<add_const_cc, gr_complex>(alias(), + "Constant", + &add_const_cc::set_k, + pmt::from_complex(-4.29e9, 0), + pmt::from_complex(4.29e9, 0), + pmt::from_complex(0, 0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/add_const_cc_impl.h b/gr-blocks/lib/add_const_cc_impl.h index f1861da7b2..075328fc2a 100644 --- a/gr-blocks/lib/add_const_cc_impl.h +++ b/gr-blocks/lib/add_const_cc_impl.h @@ -26,27 +26,27 @@ #include <gnuradio/blocks/add_const_cc.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API add_const_cc_impl : public add_const_cc - { - private: - gr_complex d_k; +class BLOCKS_API add_const_cc_impl : public add_const_cc +{ +private: + gr_complex d_k; - public: - add_const_cc_impl(gr_complex k); +public: + add_const_cc_impl(gr_complex k); - void setup_rpc(); + void setup_rpc(); - gr_complex k() const { return d_k; } - void set_k(gr_complex k) { d_k = k; } + gr_complex k() const { return d_k; } + void set_k(gr_complex k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ADD_CONST_CC_IMPL */ diff --git a/gr-blocks/lib/add_const_ff_impl.cc b/gr-blocks/lib/add_const_ff_impl.cc index 6da622f08b..110c5450eb 100644 --- a/gr-blocks/lib/add_const_ff_impl.cc +++ b/gr-blocks/lib/add_const_ff_impl.cc @@ -28,76 +28,77 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - add_const_ff::sptr add_const_ff::make(float k) - { - return gnuradio::get_initial_sptr - (new add_const_ff_impl(k)); - } - - add_const_ff_impl::add_const_ff_impl(float k) - : sync_block("add_const_ff", - io_signature::make (1, 1, sizeof(float)), - io_signature::make (1, 1, sizeof(float))), - d_k(k) - { - } +add_const_ff::sptr add_const_ff::make(float k) +{ + return gnuradio::get_initial_sptr(new add_const_ff_impl(k)); +} - int - add_const_ff_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *iptr = (const float *) input_items[0]; - float *optr = (float *) output_items[0]; +add_const_ff_impl::add_const_ff_impl(float k) + : sync_block("add_const_ff", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(float))), + d_k(k) +{ +} - int size = noutput_items; +int add_const_ff_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* iptr = (const float*)input_items[0]; + float* optr = (float*)output_items[0]; - while(size >= 8) { - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - size -= 8; - } + int size = noutput_items; - while(size-- > 0) { - *optr++ = *iptr++ + d_k; - } + while (size >= 8) { + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + size -= 8; + } - return noutput_items; + while (size-- > 0) { + *optr++ = *iptr++ + d_k; } - void - add_const_ff_impl::setup_rpc() - { + return noutput_items; +} + +void add_const_ff_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_get<add_const_ff, float>( - alias(), "Constant", - &add_const_ff::k, - pmt::from_double(-4.29e9), - pmt::from_double(4.29e9), - pmt::from_double(0), - "", "Constant to add", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); + add_rpc_variable(rpcbasic_sptr(new rpcbasic_register_get<add_const_ff, float>( + alias(), + "Constant", + &add_const_ff::k, + pmt::from_double(-4.29e9), + pmt::from_double(4.29e9), + pmt::from_double(0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_set<add_const_ff, float>( - alias(), "Constant", - &add_const_ff::set_k, - pmt::from_double(-4.29e9), - pmt::from_double(4.29e9), - pmt::from_double(0), - "", "Constant to add", - RPC_PRIVLVL_MIN, DISPNULL))); + add_rpc_variable(rpcbasic_sptr( + new rpcbasic_register_set<add_const_ff, float>(alias(), + "Constant", + &add_const_ff::set_k, + pmt::from_double(-4.29e9), + pmt::from_double(4.29e9), + pmt::from_double(0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/add_const_ff_impl.h b/gr-blocks/lib/add_const_ff_impl.h index a3074b4b98..df07aab1c3 100644 --- a/gr-blocks/lib/add_const_ff_impl.h +++ b/gr-blocks/lib/add_const_ff_impl.h @@ -26,27 +26,27 @@ #include <gnuradio/blocks/add_const_ff.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API add_const_ff_impl : public add_const_ff - { - private: - float d_k; +class BLOCKS_API add_const_ff_impl : public add_const_ff +{ +private: + float d_k; - public: - add_const_ff_impl(float k); +public: + add_const_ff_impl(float k); - void setup_rpc(); + void setup_rpc(); - float k() const { return d_k; } - void set_k(float k) { d_k = k; } + float k() const { return d_k; } + void set_k(float k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ADD_CONST_FF_IMPL */ diff --git a/gr-blocks/lib/add_const_ii_impl.cc b/gr-blocks/lib/add_const_ii_impl.cc index de81af5b26..3fa36d27bf 100644 --- a/gr-blocks/lib/add_const_ii_impl.cc +++ b/gr-blocks/lib/add_const_ii_impl.cc @@ -28,76 +28,77 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - add_const_ii::sptr add_const_ii::make(int k) - { - return gnuradio::get_initial_sptr - (new add_const_ii_impl(k)); - } - - add_const_ii_impl::add_const_ii_impl(int k) - : sync_block("add_const_ii", - io_signature::make (1, 1, sizeof(int)), - io_signature::make (1, 1, sizeof(int))), - d_k(k) - { - } +add_const_ii::sptr add_const_ii::make(int k) +{ + return gnuradio::get_initial_sptr(new add_const_ii_impl(k)); +} - int - add_const_ii_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const int *iptr = (const int *) input_items[0]; - int *optr = (int *) output_items[0]; +add_const_ii_impl::add_const_ii_impl(int k) + : sync_block("add_const_ii", + io_signature::make(1, 1, sizeof(int)), + io_signature::make(1, 1, sizeof(int))), + d_k(k) +{ +} - int size = noutput_items; +int add_const_ii_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const int* iptr = (const int*)input_items[0]; + int* optr = (int*)output_items[0]; - while(size >= 8) { - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - size -= 8; - } + int size = noutput_items; - while(size-- > 0) { - *optr++ = *iptr++ + d_k; - } + while (size >= 8) { + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + size -= 8; + } - return noutput_items; + while (size-- > 0) { + *optr++ = *iptr++ + d_k; } - void - add_const_ii_impl::setup_rpc() - { + return noutput_items; +} + +void add_const_ii_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_get<add_const_ii, int>( - alias(), "Constant", - &add_const_ii::k, - pmt::from_long(-2147483648), - pmt::from_long(2147483647), - pmt::from_long(0), - "", "Constant to add", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); + add_rpc_variable(rpcbasic_sptr(new rpcbasic_register_get<add_const_ii, int>( + alias(), + "Constant", + &add_const_ii::k, + pmt::from_long(-2147483648), + pmt::from_long(2147483647), + pmt::from_long(0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_set<add_const_ii, int>( - alias(), "Constant", - &add_const_ii::set_k, - pmt::from_long(-2147483648), - pmt::from_long(2147483647), - pmt::from_long(0), - "", "Constant to add", - RPC_PRIVLVL_MIN, DISPNULL))); + add_rpc_variable(rpcbasic_sptr( + new rpcbasic_register_set<add_const_ii, int>(alias(), + "Constant", + &add_const_ii::set_k, + pmt::from_long(-2147483648), + pmt::from_long(2147483647), + pmt::from_long(0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/add_const_ii_impl.h b/gr-blocks/lib/add_const_ii_impl.h index 8ddc3adb51..2eb9053497 100644 --- a/gr-blocks/lib/add_const_ii_impl.h +++ b/gr-blocks/lib/add_const_ii_impl.h @@ -26,27 +26,27 @@ #include <gnuradio/blocks/add_const_ii.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API add_const_ii_impl : public add_const_ii - { - private: - int d_k; +class BLOCKS_API add_const_ii_impl : public add_const_ii +{ +private: + int d_k; - public: - add_const_ii_impl(int k); +public: + add_const_ii_impl(int k); - void setup_rpc(); + void setup_rpc(); - int k() const { return d_k; } - void set_k(int k) { d_k = k; } + int k() const { return d_k; } + void set_k(int k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ADD_CONST_II_IMPL */ diff --git a/gr-blocks/lib/add_const_ss_impl.cc b/gr-blocks/lib/add_const_ss_impl.cc index 2796b2fbdd..3ae814f13e 100644 --- a/gr-blocks/lib/add_const_ss_impl.cc +++ b/gr-blocks/lib/add_const_ss_impl.cc @@ -28,80 +28,79 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - add_const_ss::sptr add_const_ss::make(short k) - { - return gnuradio::get_initial_sptr - (new add_const_ss_impl(k)); - } - - add_const_ss_impl::add_const_ss_impl(short k) - : sync_block("add_const_ss", - io_signature::make (1, 1, sizeof(short)), - io_signature::make (1, 1, sizeof(short))), - d_k(k) - { - } +add_const_ss::sptr add_const_ss::make(short k) +{ + return gnuradio::get_initial_sptr(new add_const_ss_impl(k)); +} - add_const_ss_impl::~add_const_ss_impl() - { - } +add_const_ss_impl::add_const_ss_impl(short k) + : sync_block("add_const_ss", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(short))), + d_k(k) +{ +} - int - add_const_ss_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *iptr = (const short *) input_items[0]; - short *optr = (short *) output_items[0]; +add_const_ss_impl::~add_const_ss_impl() {} - int size = noutput_items; +int add_const_ss_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* iptr = (const short*)input_items[0]; + short* optr = (short*)output_items[0]; - while(size >= 8) { - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - *optr++ = *iptr++ + d_k; - size -= 8; - } + int size = noutput_items; - while(size-- > 0) { - *optr++ = *iptr++ + d_k; - } + while (size >= 8) { + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + *optr++ = *iptr++ + d_k; + size -= 8; + } - return noutput_items; + while (size-- > 0) { + *optr++ = *iptr++ + d_k; } - void - add_const_ss_impl::setup_rpc() - { + return noutput_items; +} + +void add_const_ss_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_get<add_const_ss, short>( - alias(), "Constant", - &add_const_ss::k, - pmt::from_long(-65536), - pmt::from_long(65535), - pmt::from_long(0), - "", "Constant to add", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); + add_rpc_variable(rpcbasic_sptr(new rpcbasic_register_get<add_const_ss, short>( + alias(), + "Constant", + &add_const_ss::k, + pmt::from_long(-65536), + pmt::from_long(65535), + pmt::from_long(0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_set<add_const_ss, short>( - alias(), "Constant", - &add_const_ss::set_k, - pmt::from_long(-65536), - pmt::from_long(65535), - pmt::from_long(0), - "", "Constant to add", - RPC_PRIVLVL_MIN, DISPNULL))); + add_rpc_variable(rpcbasic_sptr( + new rpcbasic_register_set<add_const_ss, short>(alias(), + "Constant", + &add_const_ss::set_k, + pmt::from_long(-65536), + pmt::from_long(65535), + pmt::from_long(0), + "", + "Constant to add", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/add_const_ss_impl.h b/gr-blocks/lib/add_const_ss_impl.h index 40bcfb9b45..169422612c 100644 --- a/gr-blocks/lib/add_const_ss_impl.h +++ b/gr-blocks/lib/add_const_ss_impl.h @@ -26,28 +26,28 @@ #include <gnuradio/blocks/add_const_ss.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API add_const_ss_impl : public add_const_ss - { - private: - short d_k; +class BLOCKS_API add_const_ss_impl : public add_const_ss +{ +private: + short d_k; - public: - add_const_ss_impl(short k); - ~add_const_ss_impl(); +public: + add_const_ss_impl(short k); + ~add_const_ss_impl(); - void setup_rpc(); + void setup_rpc(); - short k() const { return d_k; } - void set_k(short k) { d_k = k; } + short k() const { return d_k; } + void set_k(short k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ADD_CONST_SS_IMPL */ diff --git a/gr-blocks/lib/add_const_v_impl.cc b/gr-blocks/lib/add_const_v_impl.cc index 06b420f7f5..7494c16d56 100644 --- a/gr-blocks/lib/add_const_v_impl.cc +++ b/gr-blocks/lib/add_const_v_impl.cc @@ -28,45 +28,44 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename add_const_v<T>::sptr add_const_v<T>::make(std::vector<T> k) - { - return gnuradio::get_initial_sptr(new add_const_v_impl<T>(k)); - } +template <class T> +typename add_const_v<T>::sptr add_const_v<T>::make(std::vector<T> k) +{ + return gnuradio::get_initial_sptr(new add_const_v_impl<T>(k)); +} - template <class T> - add_const_v_impl<T>::add_const_v_impl(std::vector<T> k) - : sync_block ("add_const_v", - io_signature::make (1, 1, sizeof (T)*k.size()), - io_signature::make (1, 1, sizeof (T)*k.size())), +template <class T> +add_const_v_impl<T>::add_const_v_impl(std::vector<T> k) + : sync_block("add_const_v", + io_signature::make(1, 1, sizeof(T) * k.size()), + io_signature::make(1, 1, sizeof(T) * k.size())), d_k(k) - { - } +{ +} - template <class T> - int - add_const_v_impl<T>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T *)input_items[0]; - T *optr = (T *)output_items[0]; +template <class T> +int add_const_v_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; + T* optr = (T*)output_items[0]; - int nitems_per_block = this->output_signature()->sizeof_stream_item(0)/sizeof(T); + int nitems_per_block = this->output_signature()->sizeof_stream_item(0) / sizeof(T); - for (int i = 0; i < noutput_items; i++) - for (int j = 0; j < nitems_per_block; j++) - *optr++ = *iptr++ + d_k[j]; + for (int i = 0; i < noutput_items; i++) + for (int j = 0; j < nitems_per_block; j++) + *optr++ = *iptr++ + d_k[j]; - return noutput_items; - } + return noutput_items; +} - template class add_const_v<std::uint8_t>; - template class add_const_v<std::int16_t>; - template class add_const_v<std::int32_t>; - template class add_const_v<float>; - template class add_const_v<gr_complex>; - } /* namespace blocks */ +template class add_const_v<std::uint8_t>; +template class add_const_v<std::int16_t>; +template class add_const_v<std::int32_t>; +template class add_const_v<float>; +template class add_const_v<gr_complex>; +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/add_const_v_impl.h b/gr-blocks/lib/add_const_v_impl.h index 1257ec08a0..1834ff68fb 100644 --- a/gr-blocks/lib/add_const_v_impl.h +++ b/gr-blocks/lib/add_const_v_impl.h @@ -26,25 +26,25 @@ #include <gnuradio/blocks/add_const_v.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - class BLOCKS_API add_const_v_impl: public add_const_v<T> - { - std::vector<T> d_k; +template <class T> +class BLOCKS_API add_const_v_impl : public add_const_v<T> +{ + std::vector<T> d_k; - public: - add_const_v_impl(std::vector<T> k); +public: + add_const_v_impl(std::vector<T> k); - std::vector<T> k() const { return d_k; } - void set_k(std::vector<T> k) { d_k = k; } + std::vector<T> k() const { return d_k; } + void set_k(std::vector<T> k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ADD_CONST_V_IMPL_H */ diff --git a/gr-blocks/lib/and_blk_impl.cc b/gr-blocks/lib/and_blk_impl.cc index f0f329dae4..f84906664b 100644 --- a/gr-blocks/lib/and_blk_impl.cc +++ b/gr-blocks/lib/and_blk_impl.cc @@ -29,46 +29,45 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename and_blk<T>::sptr and_blk<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new and_blk_impl<T> (vlen)); - } +template <class T> +typename and_blk<T>::sptr and_blk<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new and_blk_impl<T>(vlen)); +} - template <class T> - and_blk_impl<T> ::and_blk_impl (size_t vlen) - : sync_block ("and_blk", - io_signature::make (1, -1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), +template <class T> +and_blk_impl<T>::and_blk_impl(size_t vlen) + : sync_block("and_blk", + io_signature::make(1, -1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), d_vlen(vlen) - { - } +{ +} - template <class T> - int - and_blk_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *) output_items[0]; +template <class T> +int and_blk_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; - int ninputs = input_items.size (); + int ninputs = input_items.size(); - for (size_t i = 0; i < noutput_items*d_vlen; i++){ - T acc = ((T *) input_items[0])[i]; - for (int j = 1; j < ninputs; j++) - acc &= ((T *) input_items[j])[i]; + for (size_t i = 0; i < noutput_items * d_vlen; i++) { + T acc = ((T*)input_items[0])[i]; + for (int j = 1; j < ninputs; j++) + acc &= ((T*)input_items[j])[i]; - *optr++ = (T) acc; - } - - return noutput_items; + *optr++ = (T)acc; } + return noutput_items; +} + template class and_blk<std::uint8_t>; template class and_blk<std::int16_t>; template class and_blk<std::int32_t>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/and_blk_impl.h b/gr-blocks/lib/and_blk_impl.h index 54d721111e..8ce00f797d 100644 --- a/gr-blocks/lib/and_blk_impl.h +++ b/gr-blocks/lib/and_blk_impl.h @@ -27,22 +27,22 @@ #include <gnuradio/blocks/and_blk.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API and_blk_impl : public and_blk<T> - { - size_t d_vlen; +template <class T> +class BLOCKS_API and_blk_impl : public and_blk<T> +{ + size_t d_vlen; - public: - and_blk_impl (size_t vlen); +public: + and_blk_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* AND_BLK_IMPL_H */ diff --git a/gr-blocks/lib/and_const_impl.cc b/gr-blocks/lib/and_const_impl.cc index 76b24956cf..ad464e0a1a 100644 --- a/gr-blocks/lib/and_const_impl.cc +++ b/gr-blocks/lib/and_const_impl.cc @@ -29,54 +29,53 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename and_const<T>::sptr and_const<T>::make(T k) - { - return gnuradio::get_initial_sptr(new and_const_impl<T> (k)); - } +template <class T> +typename and_const<T>::sptr and_const<T>::make(T k) +{ + return gnuradio::get_initial_sptr(new and_const_impl<T>(k)); +} - template <class T> - and_const_impl<T> ::and_const_impl (T k) - : sync_block ("and_const", - io_signature::make (1, 1, sizeof (T)), - io_signature::make (1, 1, sizeof (T))), +template <class T> +and_const_impl<T>::and_const_impl(T k) + : sync_block("and_const", + io_signature::make(1, 1, sizeof(T)), + io_signature::make(1, 1, sizeof(T))), d_k(k) - { - } +{ +} - template <class T> - int - and_const_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T *) input_items[0]; - T *optr = (T *) output_items[0]; +template <class T> +int and_const_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; + T* optr = (T*)output_items[0]; - int size = noutput_items; + int size = noutput_items; - while (size >= 8){ - *optr++ = *iptr++ & d_k; - *optr++ = *iptr++ & d_k; - *optr++ = *iptr++ & d_k; - *optr++ = *iptr++ & d_k; - *optr++ = *iptr++ & d_k; - *optr++ = *iptr++ & d_k; - *optr++ = *iptr++ & d_k; - *optr++ = *iptr++ & d_k; - size -= 8; - } + while (size >= 8) { + *optr++ = *iptr++ & d_k; + *optr++ = *iptr++ & d_k; + *optr++ = *iptr++ & d_k; + *optr++ = *iptr++ & d_k; + *optr++ = *iptr++ & d_k; + *optr++ = *iptr++ & d_k; + *optr++ = *iptr++ & d_k; + *optr++ = *iptr++ & d_k; + size -= 8; + } - while (size-- > 0) - *optr++ = *iptr++ & d_k; + while (size-- > 0) + *optr++ = *iptr++ & d_k; - return noutput_items; - } + return noutput_items; +} template class and_const<std::uint8_t>; template class and_const<std::int16_t>; template class and_const<std::int32_t>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/and_const_impl.h b/gr-blocks/lib/and_const_impl.h index 3af7651e22..ee8af0c2fa 100644 --- a/gr-blocks/lib/and_const_impl.h +++ b/gr-blocks/lib/and_const_impl.h @@ -27,25 +27,25 @@ #include <gnuradio/blocks/and_const.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API and_const_impl : public and_const<T> - { - T d_k; +template <class T> +class BLOCKS_API and_const_impl : public and_const<T> +{ + T d_k; - public: - and_const_impl (T k); +public: + and_const_impl(T k); - T k() const { return d_k; } - void set_k(T k) { d_k = k; } + T k() const { return d_k; } + void set_k(T k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* AND_CONST_IMPL_H */ diff --git a/gr-blocks/lib/annotator_1to1_impl.cc b/gr-blocks/lib/annotator_1to1_impl.cc index cf26728193..1b099cde74 100644 --- a/gr-blocks/lib/annotator_1to1_impl.cc +++ b/gr-blocks/lib/annotator_1to1_impl.cc @@ -31,83 +31,78 @@ #include <iomanip> namespace gr { - namespace blocks { - - annotator_1to1::sptr - annotator_1to1::make(int when, size_t sizeof_stream_item) - { - return gnuradio::get_initial_sptr - (new annotator_1to1_impl(when, sizeof_stream_item)); - } - - annotator_1to1_impl::annotator_1to1_impl(int when, size_t sizeof_stream_item) - : sync_block("annotator_1to1", - io_signature::make(1, -1, sizeof_stream_item), - io_signature::make(1, -1, sizeof_stream_item)), - d_when((uint64_t)when) - { - set_tag_propagation_policy(TPP_ONE_TO_ONE); - - d_tag_counter = 0; - set_relative_rate(1, 1); - } - - annotator_1to1_impl::~annotator_1to1_impl() - { - } - - int - annotator_1to1_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float*)input_items[0]; - float *out = (float*)output_items[0]; - - std::stringstream str; - str << name() << unique_id(); - - uint64_t abs_N = 0; - int ninputs = input_items.size(); - for(int i = 0; i < ninputs; i++) { +namespace blocks { + +annotator_1to1::sptr annotator_1to1::make(int when, size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr(new annotator_1to1_impl(when, sizeof_stream_item)); +} + +annotator_1to1_impl::annotator_1to1_impl(int when, size_t sizeof_stream_item) + : sync_block("annotator_1to1", + io_signature::make(1, -1, sizeof_stream_item), + io_signature::make(1, -1, sizeof_stream_item)), + d_when((uint64_t)when) +{ + set_tag_propagation_policy(TPP_ONE_TO_ONE); + + d_tag_counter = 0; + set_relative_rate(1, 1); +} + +annotator_1to1_impl::~annotator_1to1_impl() {} + +int annotator_1to1_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + float* out = (float*)output_items[0]; + + std::stringstream str; + str << name() << unique_id(); + + uint64_t abs_N = 0; + int ninputs = input_items.size(); + for (int i = 0; i < ninputs; i++) { abs_N = nitems_read(i); std::vector<tag_t> all_tags; get_tags_in_range(all_tags, i, abs_N, abs_N + noutput_items); std::vector<tag_t>::iterator itr; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_stored_tags.push_back(*itr); + for (itr = all_tags.begin(); itr != all_tags.end(); itr++) { + d_stored_tags.push_back(*itr); } - } + } - // Storing the current noutput_items as the value to the "noutput_items" key - pmt::pmt_t srcid = pmt::string_to_symbol(str.str()); - pmt::pmt_t key = pmt::string_to_symbol("seq"); + // Storing the current noutput_items as the value to the "noutput_items" key + pmt::pmt_t srcid = pmt::string_to_symbol(str.str()); + pmt::pmt_t key = pmt::string_to_symbol("seq"); - // Work does nothing to the data stream; just copy all inputs to outputs - // Adds a new tag when the number of items read is a multiple of d_when - abs_N = nitems_read(0); - int noutputs = output_items.size(); - for(int j = 0; j < noutput_items; j++) { + // Work does nothing to the data stream; just copy all inputs to outputs + // Adds a new tag when the number of items read is a multiple of d_when + abs_N = nitems_read(0); + int noutputs = output_items.size(); + for (int j = 0; j < noutput_items; j++) { // the min() is a hack to make sure this doesn't segfault if // there are a different number of ins and outs. This is // specifically designed to test the 1-to-1 propagation policy. - for(int i = 0; i < std::min(noutputs, ninputs); i++) { - if(abs_N % d_when == 0) { - pmt::pmt_t value = pmt::from_uint64(d_tag_counter++); - add_item_tag(i, abs_N, key, value, srcid); - } - - in = (const float*)input_items[i]; - out = (float*)output_items[i]; - out[j] = in[j]; + for (int i = 0; i < std::min(noutputs, ninputs); i++) { + if (abs_N % d_when == 0) { + pmt::pmt_t value = pmt::from_uint64(d_tag_counter++); + add_item_tag(i, abs_N, key, value, srcid); + } + + in = (const float*)input_items[i]; + out = (float*)output_items[i]; + out[j] = in[j]; } abs_N++; - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/annotator_1to1_impl.h b/gr-blocks/lib/annotator_1to1_impl.h index 206366ca17..eca1c7c11e 100644 --- a/gr-blocks/lib/annotator_1to1_impl.h +++ b/gr-blocks/lib/annotator_1to1_impl.h @@ -21,35 +21,32 @@ */ #ifndef INCLUDED_GR_ANNOTATOR_1TO1_IMPL_H -#define INCLUDED_GR_ANNOTATOR_1TO1_IMPL_H +#define INCLUDED_GR_ANNOTATOR_1TO1_IMPL_H #include <gnuradio/blocks/annotator_1to1.h> namespace gr { - namespace blocks { - - class annotator_1to1_impl : public annotator_1to1 - { - private: - uint64_t d_when; - uint64_t d_tag_counter; - std::vector<tag_t> d_stored_tags; - - public: - annotator_1to1_impl(int when, size_t sizeof_stream_item); - ~annotator_1to1_impl(); - - std::vector<tag_t> data() const - { - return d_stored_tags; - } - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class annotator_1to1_impl : public annotator_1to1 +{ +private: + uint64_t d_when; + uint64_t d_tag_counter; + std::vector<tag_t> d_stored_tags; + +public: + annotator_1to1_impl(int when, size_t sizeof_stream_item); + ~annotator_1to1_impl(); + + std::vector<tag_t> data() const { return d_stored_tags; } + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_ANNOTATOR_1TO1_IMPL_H */ diff --git a/gr-blocks/lib/annotator_alltoall_impl.cc b/gr-blocks/lib/annotator_alltoall_impl.cc index afc60d0acb..8eeb7625e0 100644 --- a/gr-blocks/lib/annotator_alltoall_impl.cc +++ b/gr-blocks/lib/annotator_alltoall_impl.cc @@ -31,45 +31,40 @@ #include <iomanip> namespace gr { - namespace blocks { - - annotator_alltoall::sptr - annotator_alltoall::make(int when, size_t sizeof_stream_item) - { - return gnuradio::get_initial_sptr - (new annotator_alltoall_impl(when, sizeof_stream_item)); - } - - annotator_alltoall_impl::annotator_alltoall_impl(int when, - size_t sizeof_stream_item) - : sync_block("annotator_alltoall", - io_signature::make(1, -1, sizeof_stream_item), - io_signature::make(1, -1, sizeof_stream_item)), - d_when((uint64_t)when) - { - set_tag_propagation_policy(TPP_ALL_TO_ALL); - - d_tag_counter = 0; - } - - annotator_alltoall_impl::~annotator_alltoall_impl() - { - } - - int - annotator_alltoall_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float*)input_items[0]; - float *out = (float*)output_items[0]; - - std::stringstream str; - str << name() << unique_id(); - - uint64_t abs_N = 0, end_N; - int ninputs = input_items.size(); - for(int i = 0; i < ninputs; i++) { +namespace blocks { + +annotator_alltoall::sptr annotator_alltoall::make(int when, size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr( + new annotator_alltoall_impl(when, sizeof_stream_item)); +} + +annotator_alltoall_impl::annotator_alltoall_impl(int when, size_t sizeof_stream_item) + : sync_block("annotator_alltoall", + io_signature::make(1, -1, sizeof_stream_item), + io_signature::make(1, -1, sizeof_stream_item)), + d_when((uint64_t)when) +{ + set_tag_propagation_policy(TPP_ALL_TO_ALL); + + d_tag_counter = 0; +} + +annotator_alltoall_impl::~annotator_alltoall_impl() {} + +int annotator_alltoall_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + float* out = (float*)output_items[0]; + + std::stringstream str; + str << name() << unique_id(); + + uint64_t abs_N = 0, end_N; + int ninputs = input_items.size(); + for (int i = 0; i < ninputs; i++) { abs_N = nitems_read(i); end_N = abs_N + (uint64_t)(noutput_items); @@ -77,41 +72,41 @@ namespace gr { get_tags_in_range(all_tags, i, abs_N, end_N); std::vector<tag_t>::iterator itr; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_stored_tags.push_back(*itr); + for (itr = all_tags.begin(); itr != all_tags.end(); itr++) { + d_stored_tags.push_back(*itr); } - } - - // Source ID and key for any tag that might get applied from this block - pmt::pmt_t srcid = pmt::string_to_symbol(str.str()); - pmt::pmt_t key = pmt::string_to_symbol("seq"); - - // Work does nothing to the data stream; just copy all inputs to - // outputs Adds a new tag when the number of items read is a - // multiple of d_when - abs_N = nitems_written(0); - int noutputs = output_items.size(); - - for(int j = 0; j < noutput_items; j++) { - for(int i = 0; i < noutputs; i++) { - if(abs_N % d_when == 0) { - pmt::pmt_t value = pmt::from_uint64(d_tag_counter++); - add_item_tag(i, abs_N, key, value, srcid); - } - - // Sum all of the inputs together for each output. Just 'cause. - out = (float*)output_items[i]; - out[j] = 0; - for(int ins = 0; ins < ninputs; ins++) { - in = (const float*)input_items[ins]; - out[j] += in[j]; - } + } + + // Source ID and key for any tag that might get applied from this block + pmt::pmt_t srcid = pmt::string_to_symbol(str.str()); + pmt::pmt_t key = pmt::string_to_symbol("seq"); + + // Work does nothing to the data stream; just copy all inputs to + // outputs Adds a new tag when the number of items read is a + // multiple of d_when + abs_N = nitems_written(0); + int noutputs = output_items.size(); + + for (int j = 0; j < noutput_items; j++) { + for (int i = 0; i < noutputs; i++) { + if (abs_N % d_when == 0) { + pmt::pmt_t value = pmt::from_uint64(d_tag_counter++); + add_item_tag(i, abs_N, key, value, srcid); + } + + // Sum all of the inputs together for each output. Just 'cause. + out = (float*)output_items[i]; + out[j] = 0; + for (int ins = 0; ins < ninputs; ins++) { + in = (const float*)input_items[ins]; + out[j] += in[j]; + } } abs_N++; - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/annotator_alltoall_impl.h b/gr-blocks/lib/annotator_alltoall_impl.h index cdd5c88e62..8aa12ba8e0 100644 --- a/gr-blocks/lib/annotator_alltoall_impl.h +++ b/gr-blocks/lib/annotator_alltoall_impl.h @@ -21,35 +21,32 @@ */ #ifndef INCLUDED_GR_ANNOTATOR_ALLTOALL_IMPL_H -#define INCLUDED_GR_ANNOTATOR_ALLTOALL_IMPL_H +#define INCLUDED_GR_ANNOTATOR_ALLTOALL_IMPL_H #include <gnuradio/blocks/annotator_alltoall.h> namespace gr { - namespace blocks { - - class annotator_alltoall_impl : public annotator_alltoall - { - private: - uint64_t d_when; - uint64_t d_tag_counter; - std::vector<tag_t> d_stored_tags; - - public: - annotator_alltoall_impl(int when, size_t sizeof_stream_item); - ~annotator_alltoall_impl(); - - std::vector<tag_t> data() const - { - return d_stored_tags; - } - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class annotator_alltoall_impl : public annotator_alltoall +{ +private: + uint64_t d_when; + uint64_t d_tag_counter; + std::vector<tag_t> d_stored_tags; + +public: + annotator_alltoall_impl(int when, size_t sizeof_stream_item); + ~annotator_alltoall_impl(); + + std::vector<tag_t> data() const { return d_stored_tags; } + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_ANNOTATOR_ALLTOALL_IMPL_H */ diff --git a/gr-blocks/lib/annotator_raw_impl.cc b/gr-blocks/lib/annotator_raw_impl.cc index ce15103822..4ca6f3fde5 100644 --- a/gr-blocks/lib/annotator_raw_impl.cc +++ b/gr-blocks/lib/annotator_raw_impl.cc @@ -34,80 +34,73 @@ using namespace pmt; namespace gr { - namespace blocks { - - annotator_raw::sptr - annotator_raw::make(size_t sizeof_stream_item) - { - return gnuradio::get_initial_sptr - (new annotator_raw_impl(sizeof_stream_item)); - } - - annotator_raw_impl::annotator_raw_impl(size_t sizeof_stream_item) - : sync_block("annotator_raw", - io_signature::make(1, 1, sizeof_stream_item), - io_signature::make(1, 1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item) - { - set_tag_propagation_policy(TPP_ONE_TO_ONE); - set_relative_rate(1, 1); +namespace blocks { + +annotator_raw::sptr annotator_raw::make(size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr(new annotator_raw_impl(sizeof_stream_item)); +} + +annotator_raw_impl::annotator_raw_impl(size_t sizeof_stream_item) + : sync_block("annotator_raw", + io_signature::make(1, 1, sizeof_stream_item), + io_signature::make(1, 1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item) +{ + set_tag_propagation_policy(TPP_ONE_TO_ONE); + set_relative_rate(1, 1); +} + +annotator_raw_impl::~annotator_raw_impl() {} + +void annotator_raw_impl::add_tag(uint64_t offset, pmt_t key, pmt_t val) +{ + gr::thread::scoped_lock l(d_mutex); + + tag_t tag; + tag.srcid = pmt::intern(name()); + tag.key = key; + tag.value = val; + tag.offset = offset; + + // add our new tag + d_queued_tags.push_back(tag); + // make sure our tags are in offset order + std::sort(d_queued_tags.begin(), d_queued_tags.end(), tag_t::offset_compare); + // make sure we are not adding an item in the past! + if (tag.offset > nitems_read(0)) { + throw std::runtime_error( + "annotator_raw::add_tag: item added too far in the past\n."); } - - annotator_raw_impl::~annotator_raw_impl() - { - } - - void - annotator_raw_impl::add_tag(uint64_t offset, pmt_t key, pmt_t val) - { - gr::thread::scoped_lock l(d_mutex); - - tag_t tag; - tag.srcid = pmt::intern(name()); - tag.key = key; - tag.value = val; - tag.offset = offset; - - // add our new tag - d_queued_tags.push_back(tag); - // make sure our tags are in offset order - std::sort(d_queued_tags.begin(), d_queued_tags.end(), - tag_t::offset_compare); - // make sure we are not adding an item in the past! - if(tag.offset > nitems_read(0)) { - throw std::runtime_error("annotator_raw::add_tag: item added too far in the past\n."); - } - } - - int - annotator_raw_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr::thread::scoped_lock l(d_mutex); - - const char *in = (const char*)input_items[0]; - char *out = (char*)output_items[0]; - - uint64_t start_N = nitems_read(0); - uint64_t end_N = start_N + (uint64_t)(noutput_items); - - // locate queued tags that fall in this range and insert them when appropriate - std::vector<tag_t>::iterator i = d_queued_tags.begin(); - while( i != d_queued_tags.end() ) { - if( (*i).offset >= start_N && (*i).offset < end_N) { - add_item_tag(0, (*i).offset,(*i).key, (*i).value, (*i).srcid); - i = d_queued_tags.erase(i); - } - else { - break; +} + +int annotator_raw_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr::thread::scoped_lock l(d_mutex); + + const char* in = (const char*)input_items[0]; + char* out = (char*)output_items[0]; + + uint64_t start_N = nitems_read(0); + uint64_t end_N = start_N + (uint64_t)(noutput_items); + + // locate queued tags that fall in this range and insert them when appropriate + std::vector<tag_t>::iterator i = d_queued_tags.begin(); + while (i != d_queued_tags.end()) { + if ((*i).offset >= start_N && (*i).offset < end_N) { + add_item_tag(0, (*i).offset, (*i).key, (*i).value, (*i).srcid); + i = d_queued_tags.erase(i); + } else { + break; } - } - - // copy data across - memcpy(out, in, noutput_items*d_itemsize); - return noutput_items; } - } /* namespace blocks */ + // copy data across + memcpy(out, in, noutput_items * d_itemsize); + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/annotator_raw_impl.h b/gr-blocks/lib/annotator_raw_impl.h index 54bed2ea25..9bf3f9eeb9 100644 --- a/gr-blocks/lib/annotator_raw_impl.h +++ b/gr-blocks/lib/annotator_raw_impl.h @@ -21,34 +21,34 @@ */ #ifndef INCLUDED_GR_ANNOTATOR_RAW_IMPL_H -#define INCLUDED_GR_ANNOTATOR_RAW_IMPL_H +#define INCLUDED_GR_ANNOTATOR_RAW_IMPL_H #include <gnuradio/blocks/annotator_raw.h> #include <gnuradio/thread/thread.h> namespace gr { - namespace blocks { +namespace blocks { - class annotator_raw_impl : public annotator_raw - { - private: - size_t d_itemsize; - std::vector<tag_t> d_queued_tags; - gr::thread::mutex d_mutex; +class annotator_raw_impl : public annotator_raw +{ +private: + size_t d_itemsize; + std::vector<tag_t> d_queued_tags; + gr::thread::mutex d_mutex; - public: - annotator_raw_impl(size_t sizeof_stream_item); - ~annotator_raw_impl(); +public: + annotator_raw_impl(size_t sizeof_stream_item); + ~annotator_raw_impl(); - // insert a tag to be added - void add_tag(uint64_t offset, pmt::pmt_t key, pmt::pmt_t val); + // insert a tag to be added + void add_tag(uint64_t offset, pmt::pmt_t key, pmt::pmt_t val); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_ANNOTATOR_RAW_IMPL_H */ diff --git a/gr-blocks/lib/argmax_impl.cc b/gr-blocks/lib/argmax_impl.cc index b3fd548aee..c3d7546c34 100644 --- a/gr-blocks/lib/argmax_impl.cc +++ b/gr-blocks/lib/argmax_impl.cc @@ -28,64 +28,61 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename argmax<T>::sptr - argmax<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr - (new argmax_impl<T>(vlen)); - } +template <class T> +typename argmax<T>::sptr argmax<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new argmax_impl<T>(vlen)); +} - template <class T> - argmax_impl<T>::argmax_impl(size_t vlen) +template <class T> +argmax_impl<T>::argmax_impl(size_t vlen) : sync_block("argmax", - io_signature::make(1, -1, vlen*sizeof(T)), - io_signature::make(2, 2, sizeof(std::int16_t))), + io_signature::make(1, -1, vlen * sizeof(T)), + io_signature::make(2, 2, sizeof(std::int16_t))), d_vlen(vlen) - { - } +{ +} - template <class T> - argmax_impl<T>::~argmax_impl() - { - } +template <class T> +argmax_impl<T>::~argmax_impl() +{ +} - template <class T> - int - argmax_impl<T>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - int ninputs = input_items.size (); +template <class T> +int argmax_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + int ninputs = input_items.size(); - std::int16_t *x_optr = (std::int16_t *)output_items[0]; - std::int16_t *y_optr = (std::int16_t *)output_items[1]; + std::int16_t* x_optr = (std::int16_t*)output_items[0]; + std::int16_t* y_optr = (std::int16_t*)output_items[1]; - for(int i = 0; i < noutput_items; i++) { - T max = ((T *)input_items[0])[i*d_vlen]; + for (int i = 0; i < noutput_items; i++) { + T max = ((T*)input_items[0])[i * d_vlen]; int x = 0; int y = 0; - for(int j = 0; j < (int)d_vlen; j++ ) { - for(int k = 0; k < ninputs; k++) { - if(((T *)input_items[k])[i*d_vlen + j] > max) { - max = ((T *)input_items[k])[i*d_vlen + j]; - x = j; - y = k; + for (int j = 0; j < (int)d_vlen; j++) { + for (int k = 0; k < ninputs; k++) { + if (((T*)input_items[k])[i * d_vlen + j] > max) { + max = ((T*)input_items[k])[i * d_vlen + j]; + x = j; + y = k; + } } - } } *x_optr++ = (std::int16_t)x; *y_optr++ = (std::int16_t)y; - } - return noutput_items; } - template class argmax<float>; - template class argmax<std::int32_t>; - template class argmax<std::int16_t>; + return noutput_items; +} +template class argmax<float>; +template class argmax<std::int32_t>; +template class argmax<std::int16_t>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/argmax_impl.h b/gr-blocks/lib/argmax_impl.h index e6609930dc..c4de0bd38a 100644 --- a/gr-blocks/lib/argmax_impl.h +++ b/gr-blocks/lib/argmax_impl.h @@ -26,24 +26,24 @@ #include <gnuradio/blocks/argmax.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - class argmax_impl : public argmax<T> - { - private: - size_t d_vlen; +template <class T> +class argmax_impl : public argmax<T> +{ +private: + size_t d_vlen; - public: - argmax_impl(size_t vlen); - ~argmax_impl(); +public: + argmax_impl(size_t vlen); + ~argmax_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* ARGMAX_IMPL_H */ diff --git a/gr-blocks/lib/bin_statistics_f_impl.cc b/gr-blocks/lib/bin_statistics_f_impl.cc index f91faea61d..0886a2a75a 100644 --- a/gr-blocks/lib/bin_statistics_f_impl.cc +++ b/gr-blocks/lib/bin_statistics_f_impl.cc @@ -29,148 +29,136 @@ #include <string.h> namespace gr { - namespace blocks { - - bin_statistics_f::sptr - bin_statistics_f::make(unsigned int vlen, - msg_queue::sptr msgq, - feval_dd *tune, - size_t tune_delay, - size_t dwell_delay) - { - return gnuradio::get_initial_sptr - (new bin_statistics_f_impl(vlen, msgq, tune, - tune_delay, dwell_delay)); - } - - bin_statistics_f_impl::bin_statistics_f_impl(unsigned int vlen, - msg_queue::sptr msgq, - feval_dd *tune, - size_t tune_delay, - size_t dwell_delay) - : sync_block("bin_statistics_f", - io_signature::make(1, 1, sizeof(float) * vlen), - io_signature::make(0, 0, 0)), - d_vlen(vlen), d_msgq(msgq), d_tune(tune), - d_tune_delay(tune_delay), d_dwell_delay(dwell_delay), - d_center_freq(0), d_delay(0), - d_max(vlen) - { - enter_init(); - } - - bin_statistics_f_impl::~bin_statistics_f_impl() - { - } - - void - bin_statistics_f_impl::enter_init() - { - d_state = ST_INIT; - d_delay = 0; - } - - void - bin_statistics_f_impl::enter_tune_delay() - { - d_state = ST_TUNE_DELAY; - d_delay = d_tune_delay; - d_center_freq = d_tune->calleval(0); - } - - void - bin_statistics_f_impl::enter_dwell_delay() - { - d_state = ST_DWELL_DELAY; - d_delay = d_dwell_delay; - reset_stats(); - } - - void - bin_statistics_f_impl::leave_dwell_delay() - { - send_stats(); - } - - int - bin_statistics_f_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *input = (const float*)input_items[0]; - size_t vlen = d_max.size(); - - int n = 0; - int t; - - while(n < noutput_items) { - switch(d_state) { - - case ST_INIT: +namespace blocks { + +bin_statistics_f::sptr bin_statistics_f::make(unsigned int vlen, + msg_queue::sptr msgq, + feval_dd* tune, + size_t tune_delay, + size_t dwell_delay) +{ + return gnuradio::get_initial_sptr( + new bin_statistics_f_impl(vlen, msgq, tune, tune_delay, dwell_delay)); +} + +bin_statistics_f_impl::bin_statistics_f_impl(unsigned int vlen, + msg_queue::sptr msgq, + feval_dd* tune, + size_t tune_delay, + size_t dwell_delay) + : sync_block("bin_statistics_f", + io_signature::make(1, 1, sizeof(float) * vlen), + io_signature::make(0, 0, 0)), + d_vlen(vlen), + d_msgq(msgq), + d_tune(tune), + d_tune_delay(tune_delay), + d_dwell_delay(dwell_delay), + d_center_freq(0), + d_delay(0), + d_max(vlen) +{ + enter_init(); +} + +bin_statistics_f_impl::~bin_statistics_f_impl() {} + +void bin_statistics_f_impl::enter_init() +{ + d_state = ST_INIT; + d_delay = 0; +} + +void bin_statistics_f_impl::enter_tune_delay() +{ + d_state = ST_TUNE_DELAY; + d_delay = d_tune_delay; + d_center_freq = d_tune->calleval(0); +} + +void bin_statistics_f_impl::enter_dwell_delay() +{ + d_state = ST_DWELL_DELAY; + d_delay = d_dwell_delay; + reset_stats(); +} + +void bin_statistics_f_impl::leave_dwell_delay() { send_stats(); } + +int bin_statistics_f_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* input = (const float*)input_items[0]; + size_t vlen = d_max.size(); + + int n = 0; + int t; + + while (n < noutput_items) { + switch (d_state) { + + case ST_INIT: enter_tune_delay(); break; - case ST_TUNE_DELAY: + case ST_TUNE_DELAY: t = std::min(noutput_items - n, int(d_delay)); n += t; d_delay -= t; - if(d_delay == 0) - enter_dwell_delay(); + if (d_delay == 0) + enter_dwell_delay(); break; - case ST_DWELL_DELAY: + case ST_DWELL_DELAY: t = std::min(noutput_items - n, int(d_delay)); - for(int i = 0; i < t; i++) { - accrue_stats(&input[n * vlen]); - n++; + for (int i = 0; i < t; i++) { + accrue_stats(&input[n * vlen]); + n++; } d_delay -= t; - if(d_delay == 0) { - leave_dwell_delay(); - enter_tune_delay(); + if (d_delay == 0) { + leave_dwell_delay(); + enter_tune_delay(); } break; - default: + default: assert(0); - } - } - - return noutput_items; + } } - ////////////////////////////////////////////////////////////////////////// - // virtual methods for gathering stats - ////////////////////////////////////////////////////////////////////////// + return noutput_items; +} + +////////////////////////////////////////////////////////////////////////// +// virtual methods for gathering stats +////////////////////////////////////////////////////////////////////////// - void - bin_statistics_f_impl::reset_stats() - { - for (size_t i = 0; i < vlen(); i++){ +void bin_statistics_f_impl::reset_stats() +{ + for (size_t i = 0; i < vlen(); i++) { d_max[i] = 0; - } } +} - void - bin_statistics_f_impl::accrue_stats(const float *input) - { - for(size_t i = 0; i < vlen(); i++) { - d_max[i] = std::max(d_max[i], input[i]); // compute per bin maxima - } +void bin_statistics_f_impl::accrue_stats(const float* input) +{ + for (size_t i = 0; i < vlen(); i++) { + d_max[i] = std::max(d_max[i], input[i]); // compute per bin maxima } +} - void - bin_statistics_f_impl::send_stats() - { - if(msgq()->full_p()) // if the queue is full, don't block, drop the data... +void bin_statistics_f_impl::send_stats() +{ + if (msgq()->full_p()) // if the queue is full, don't block, drop the data... return; - // build & send a message - message::sptr msg = message::make(0, center_freq(), vlen(), vlen() * sizeof(float)); - memcpy(msg->msg(), &d_max[0], vlen() * sizeof(float)); - msgq()->insert_tail(msg); - } + // build & send a message + message::sptr msg = message::make(0, center_freq(), vlen(), vlen() * sizeof(float)); + memcpy(msg->msg(), &d_max[0], vlen() * sizeof(float)); + msgq()->insert_tail(msg); +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ - diff --git a/gr-blocks/lib/bin_statistics_f_impl.h b/gr-blocks/lib/bin_statistics_f_impl.h index 1d8da6b348..09686d04f1 100644 --- a/gr-blocks/lib/bin_statistics_f_impl.h +++ b/gr-blocks/lib/bin_statistics_f_impl.h @@ -29,54 +29,53 @@ #include <gnuradio/msg_queue.h> namespace gr { - namespace blocks { +namespace blocks { - class bin_statistics_f_impl : public bin_statistics_f - { - private: - enum state_t { ST_INIT, ST_TUNE_DELAY, ST_DWELL_DELAY }; +class bin_statistics_f_impl : public bin_statistics_f +{ +private: + enum state_t { ST_INIT, ST_TUNE_DELAY, ST_DWELL_DELAY }; - size_t d_vlen; - msg_queue::sptr d_msgq; - feval_dd *d_tune; - size_t d_tune_delay; - size_t d_dwell_delay; - double d_center_freq; + size_t d_vlen; + msg_queue::sptr d_msgq; + feval_dd* d_tune; + size_t d_tune_delay; + size_t d_dwell_delay; + double d_center_freq; - state_t d_state; - size_t d_delay; // nsamples remaining to state transition + state_t d_state; + size_t d_delay; // nsamples remaining to state transition - void enter_init(); - void enter_tune_delay(); - void enter_dwell_delay(); - void leave_dwell_delay(); + void enter_init(); + void enter_tune_delay(); + void enter_dwell_delay(); + void leave_dwell_delay(); - protected: - std::vector<float> d_max; // per bin maxima +protected: + std::vector<float> d_max; // per bin maxima - size_t vlen() const { return d_vlen; } - double center_freq() const { return d_center_freq; } - msg_queue::sptr msgq() const { return d_msgq; } + size_t vlen() const { return d_vlen; } + double center_freq() const { return d_center_freq; } + msg_queue::sptr msgq() const { return d_msgq; } - virtual void reset_stats(); - virtual void accrue_stats(const float *input); - virtual void send_stats(); + virtual void reset_stats(); + virtual void accrue_stats(const float* input); + virtual void send_stats(); - public: - bin_statistics_f_impl(unsigned int vlen, - msg_queue::sptr msgq, - feval_dd *tune, - size_t tune_delay, - size_t dwell_delay); - ~bin_statistics_f_impl(); +public: + bin_statistics_f_impl(unsigned int vlen, + msg_queue::sptr msgq, + feval_dd* tune, + size_t tune_delay, + size_t dwell_delay); + ~bin_statistics_f_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - }; - - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_BIN_STATISTICS_F_IMPL_H */ diff --git a/gr-blocks/lib/burst_tagger_impl.cc b/gr-blocks/lib/burst_tagger_impl.cc index da69a0ea48..a2a8c87c0f 100644 --- a/gr-blocks/lib/burst_tagger_impl.cc +++ b/gr-blocks/lib/burst_tagger_impl.cc @@ -29,88 +29,79 @@ #include <string.h> namespace gr { - namespace blocks { +namespace blocks { - burst_tagger::sptr - burst_tagger::make(size_t itemsize) - { - return gnuradio::get_initial_sptr - (new burst_tagger_impl(itemsize)); - } +burst_tagger::sptr burst_tagger::make(size_t itemsize) +{ + return gnuradio::get_initial_sptr(new burst_tagger_impl(itemsize)); +} - burst_tagger_impl::burst_tagger_impl(size_t itemsize) - : sync_block("burst_tagger", - io_signature::make2(2, 2, itemsize, sizeof(short)), - io_signature::make(1, 1, itemsize)), - d_itemsize(itemsize), d_state(false) - { - std::stringstream str; - str << name() << unique_id(); +burst_tagger_impl::burst_tagger_impl(size_t itemsize) + : sync_block("burst_tagger", + io_signature::make2(2, 2, itemsize, sizeof(short)), + io_signature::make(1, 1, itemsize)), + d_itemsize(itemsize), + d_state(false) +{ + std::stringstream str; + str << name() << unique_id(); - d_true_key = pmt::string_to_symbol("burst"); - d_true_value = pmt::PMT_T; + d_true_key = pmt::string_to_symbol("burst"); + d_true_value = pmt::PMT_T; - d_false_key = pmt::string_to_symbol("burst"); - d_false_value = pmt::PMT_F; + d_false_key = pmt::string_to_symbol("burst"); + d_false_value = pmt::PMT_F; - d_id = pmt::string_to_symbol(str.str()); - } + d_id = pmt::string_to_symbol(str.str()); +} - burst_tagger_impl::~burst_tagger_impl() - { - } +burst_tagger_impl::~burst_tagger_impl() {} - void - burst_tagger_impl::set_true_tag(const std::string &key, bool value) - { - d_true_key = pmt::string_to_symbol(key); - if(value == true) { +void burst_tagger_impl::set_true_tag(const std::string& key, bool value) +{ + d_true_key = pmt::string_to_symbol(key); + if (value == true) { d_true_value = pmt::PMT_T; - } - else { + } else { d_true_value = pmt::PMT_F; - } } +} - void - burst_tagger_impl::set_false_tag (const std::string &key, bool value) - { - d_false_key = pmt::string_to_symbol(key); - if(value == true) { +void burst_tagger_impl::set_false_tag(const std::string& key, bool value) +{ + d_false_key = pmt::string_to_symbol(key); + if (value == true) { d_false_value = pmt::PMT_T; - } - else { + } else { d_false_value = pmt::PMT_F; - } } +} - int - burst_tagger_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *signal = (const char*)input_items[0]; - const short *trigger = (const short*)input_items[1]; - char *out = (char*)output_items[0]; +int burst_tagger_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* signal = (const char*)input_items[0]; + const short* trigger = (const short*)input_items[1]; + char* out = (char*)output_items[0]; - memcpy(out, signal, noutput_items * d_itemsize); + memcpy(out, signal, noutput_items * d_itemsize); - for(int i = 0; i < noutput_items; i++) { - if(trigger[i] > 0) { - if(d_state == false) { - d_state = true; - add_item_tag(0, nitems_written(0)+i, d_true_key, d_true_value, d_id); - } - } - else { - if(d_state == true) { - d_state = false; - add_item_tag(0, nitems_written(0)+i, d_false_key, d_false_value, d_id); - } + for (int i = 0; i < noutput_items; i++) { + if (trigger[i] > 0) { + if (d_state == false) { + d_state = true; + add_item_tag(0, nitems_written(0) + i, d_true_key, d_true_value, d_id); + } + } else { + if (d_state == true) { + d_state = false; + add_item_tag(0, nitems_written(0) + i, d_false_key, d_false_value, d_id); + } } - } - return noutput_items; } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/burst_tagger_impl.h b/gr-blocks/lib/burst_tagger_impl.h index 65ad58f8b3..412e9cc695 100644 --- a/gr-blocks/lib/burst_tagger_impl.h +++ b/gr-blocks/lib/burst_tagger_impl.h @@ -26,34 +26,34 @@ #include <gnuradio/blocks/burst_tagger.h> namespace gr { - namespace blocks { +namespace blocks { - class burst_tagger_impl : public burst_tagger - { - private: - size_t d_itemsize; - bool d_state; - pmt::pmt_t d_true_key; - pmt::pmt_t d_true_value; +class burst_tagger_impl : public burst_tagger +{ +private: + size_t d_itemsize; + bool d_state; + pmt::pmt_t d_true_key; + pmt::pmt_t d_true_value; - pmt::pmt_t d_false_key; - pmt::pmt_t d_false_value; + pmt::pmt_t d_false_key; + pmt::pmt_t d_false_value; - pmt::pmt_t d_id; + pmt::pmt_t d_id; - public: - burst_tagger_impl(size_t itemsize); - ~burst_tagger_impl(); +public: + burst_tagger_impl(size_t itemsize); + ~burst_tagger_impl(); - void set_true_tag(const std::string &key, bool value); - void set_false_tag(const std::string &key, bool value); + void set_true_tag(const std::string& key, bool value); + void set_false_tag(const std::string& key, bool value); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_BURST_TAGGER_IMPL_H */ diff --git a/gr-blocks/lib/char_to_float_impl.cc b/gr-blocks/lib/char_to_float_impl.cc index f6fb990981..3c550412ef 100644 --- a/gr-blocks/lib/char_to_float_impl.cc +++ b/gr-blocks/lib/char_to_float_impl.cc @@ -29,37 +29,36 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - char_to_float::sptr char_to_float::make(size_t vlen, float scale) - { - return gnuradio::get_initial_sptr(new char_to_float_impl(vlen, scale)); - } +char_to_float::sptr char_to_float::make(size_t vlen, float scale) +{ + return gnuradio::get_initial_sptr(new char_to_float_impl(vlen, scale)); +} - char_to_float_impl::char_to_float_impl(size_t vlen, float scale) - : sync_block("char_to_float", - io_signature::make (1, -1, sizeof(char)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen), d_scale(scale) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1, alignment_multiple)); - } +char_to_float_impl::char_to_float_impl(size_t vlen, float scale) + : sync_block("char_to_float", + io_signature::make(1, -1, sizeof(char) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen), + d_scale(scale) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} - int - char_to_float_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const int8_t *in = (const int8_t *) input_items[0]; - float *out = (float *) output_items[0]; +int char_to_float_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const int8_t* in = (const int8_t*)input_items[0]; + float* out = (float*)output_items[0]; - // Note: the unaligned benchmarked much faster than the aligned - volk_8i_s32f_convert_32f_u(out, in, d_scale, d_vlen*noutput_items); + // Note: the unaligned benchmarked much faster than the aligned + volk_8i_s32f_convert_32f_u(out, in, d_scale, d_vlen * noutput_items); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/char_to_float_impl.h b/gr-blocks/lib/char_to_float_impl.h index 4d056850b0..1d73335eed 100644 --- a/gr-blocks/lib/char_to_float_impl.h +++ b/gr-blocks/lib/char_to_float_impl.h @@ -26,25 +26,25 @@ #include <gnuradio/blocks/char_to_float.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API char_to_float_impl : public char_to_float - { - size_t d_vlen; - float d_scale; +class BLOCKS_API char_to_float_impl : public char_to_float +{ + size_t d_vlen; + float d_scale; - public: - char_to_float_impl(size_t vlen, float scale); +public: + char_to_float_impl(size_t vlen, float scale); - virtual float scale() const { return d_scale; } - virtual void set_scale(float scale) { d_scale = scale; } + virtual float scale() const { return d_scale; } + virtual void set_scale(float scale) { d_scale = scale; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/char_to_short_impl.cc b/gr-blocks/lib/char_to_short_impl.cc index fa8d55fbd0..f75e5b7c84 100644 --- a/gr-blocks/lib/char_to_short_impl.cc +++ b/gr-blocks/lib/char_to_short_impl.cc @@ -29,36 +29,34 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - char_to_short::sptr char_to_short::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new char_to_short_impl(vlen)); - } - - char_to_short_impl::char_to_short_impl(size_t vlen) - : sync_block("char_to_short", - io_signature::make(1, 1, sizeof(char)*vlen), - io_signature::make(1, 1, sizeof(short)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(short); - set_alignment(std::max(1, alignment_multiple)); - } - - int - char_to_short_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const int8_t *in = (const int8_t *)input_items[0]; - int16_t *out = (int16_t *)output_items[0]; - - volk_8i_convert_16i(out, in, d_vlen*noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +char_to_short::sptr char_to_short::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new char_to_short_impl(vlen)); +} + +char_to_short_impl::char_to_short_impl(size_t vlen) + : sync_block("char_to_short", + io_signature::make(1, 1, sizeof(char) * vlen), + io_signature::make(1, 1, sizeof(short) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(short); + set_alignment(std::max(1, alignment_multiple)); +} + +int char_to_short_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const int8_t* in = (const int8_t*)input_items[0]; + int16_t* out = (int16_t*)output_items[0]; + + volk_8i_convert_16i(out, in, d_vlen * noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/char_to_short_impl.h b/gr-blocks/lib/char_to_short_impl.h index ad13fd1918..e49c204ec5 100644 --- a/gr-blocks/lib/char_to_short_impl.h +++ b/gr-blocks/lib/char_to_short_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/char_to_short.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API char_to_short_impl : public char_to_short - { - size_t d_vlen; +class BLOCKS_API char_to_short_impl : public char_to_short +{ + size_t d_vlen; - public: - char_to_short_impl(size_t vlen); +public: + char_to_short_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/check_lfsr_32k_s_impl.cc b/gr-blocks/lib/check_lfsr_32k_s_impl.cc index fac30223f7..a3826d5a6e 100644 --- a/gr-blocks/lib/check_lfsr_32k_s_impl.cc +++ b/gr-blocks/lib/check_lfsr_32k_s_impl.cc @@ -30,150 +30,144 @@ #include <stdio.h> namespace gr { - namespace blocks { - - check_lfsr_32k_s::sptr - check_lfsr_32k_s::make() - { - return gnuradio::get_initial_sptr - (new check_lfsr_32k_s_impl()); - } - - check_lfsr_32k_s_impl::check_lfsr_32k_s_impl() - : sync_block("check_lfsr_32k", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(0, 0, 0)), - d_state(SEARCHING), d_history(0), d_ntotal(0), d_nright(0), - d_runlength(0), d_index(0) - { - lfsr_32k lfsr; - - for(int i = 0; i < BUFSIZE; i++) +namespace blocks { + +check_lfsr_32k_s::sptr check_lfsr_32k_s::make() +{ + return gnuradio::get_initial_sptr(new check_lfsr_32k_s_impl()); +} + +check_lfsr_32k_s_impl::check_lfsr_32k_s_impl() + : sync_block("check_lfsr_32k", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(0, 0, 0)), + d_state(SEARCHING), + d_history(0), + d_ntotal(0), + d_nright(0), + d_runlength(0), + d_index(0) +{ + lfsr_32k lfsr; + + for (int i = 0; i < BUFSIZE; i++) d_buffer[i] = lfsr.next_short(); - enter_SEARCHING(); - } + enter_SEARCHING(); +} - check_lfsr_32k_s_impl::~check_lfsr_32k_s_impl() - { - } +check_lfsr_32k_s_impl::~check_lfsr_32k_s_impl() {} - int - check_lfsr_32k_s_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - unsigned short *in = (unsigned short*)input_items[0]; +int check_lfsr_32k_s_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + unsigned short* in = (unsigned short*)input_items[0]; - for(int i = 0; i < noutput_items; i++) { + for (int i = 0; i < noutput_items; i++) { unsigned short x = in[i]; unsigned short expected; - switch(d_state) { + switch (d_state) { case MATCH0: - if(x == d_buffer[0]) - enter_MATCH1(); - break; + if (x == d_buffer[0]) + enter_MATCH1(); + break; case MATCH1: - if(x == d_buffer[1]) - enter_MATCH2(); - else - enter_MATCH0(); - break; + if (x == d_buffer[1]) + enter_MATCH2(); + else + enter_MATCH0(); + break; case MATCH2: - if(x == d_buffer[2]) - enter_LOCKED(); - else - enter_MATCH0(); - break; + if (x == d_buffer[2]) + enter_LOCKED(); + else + enter_MATCH0(); + break; case LOCKED: - expected = d_buffer[d_index]; - d_index = d_index + 1; - if(d_index >= BUFSIZE) - d_index = 0; - - if(x == expected) - right(); - else { - wrong(); - log_error(expected, x); - if(wrong_three_times()) - enter_SEARCHING(); - } - break; + expected = d_buffer[d_index]; + d_index = d_index + 1; + if (d_index >= BUFSIZE) + d_index = 0; + + if (x == expected) + right(); + else { + wrong(); + log_error(expected, x); + if (wrong_three_times()) + enter_SEARCHING(); + } + break; default: - abort(); + abort(); } d_ntotal++; - } - - return noutput_items; } - void - check_lfsr_32k_s_impl::enter_SEARCHING() - { - d_state = SEARCHING; - wrong(); // reset history - wrong(); - wrong(); + return noutput_items; +} - d_runlength = 0; - d_index = 0; // reset LFSR to beginning +void check_lfsr_32k_s_impl::enter_SEARCHING() +{ + d_state = SEARCHING; + wrong(); // reset history + wrong(); + wrong(); - if(0) - fprintf(stdout, "check_lfsr_32k: enter_SEARCHING at offset %8ld (0x%08lx)\n", - d_ntotal, d_ntotal); + d_runlength = 0; + d_index = 0; // reset LFSR to beginning - enter_MATCH0(); - } + if (0) + fprintf(stdout, + "check_lfsr_32k: enter_SEARCHING at offset %8ld (0x%08lx)\n", + d_ntotal, + d_ntotal); - void - check_lfsr_32k_s_impl::enter_MATCH0() - { - d_state = MATCH0; - } + enter_MATCH0(); +} - void - check_lfsr_32k_s_impl::enter_MATCH1() - { - d_state = MATCH1; - } +void check_lfsr_32k_s_impl::enter_MATCH0() { d_state = MATCH0; } - void - check_lfsr_32k_s_impl::enter_MATCH2() - { - d_state = MATCH2; - } +void check_lfsr_32k_s_impl::enter_MATCH1() { d_state = MATCH1; } - void - check_lfsr_32k_s_impl::enter_LOCKED() - { - d_state = LOCKED; - right(); // setup history - right(); - right(); +void check_lfsr_32k_s_impl::enter_MATCH2() { d_state = MATCH2; } - d_index = 3; // already matched first 3 items +void check_lfsr_32k_s_impl::enter_LOCKED() +{ + d_state = LOCKED; + right(); // setup history + right(); + right(); - if(0) - fprintf(stdout, "check_lfsr_32k: enter_LOCKED at offset %8ld (0x%08lx)\n", - d_ntotal, d_ntotal); - } + d_index = 3; // already matched first 3 items - void - check_lfsr_32k_s_impl::log_error(unsigned short expected, unsigned short actual) - { - if(0) + if (0) fprintf(stdout, - "check_lfsr_32k: expected %5d (0x%04x) got %5d (0x%04x) offset %8ld (0x%08lx)\n", - expected, expected, actual, actual, d_ntotal, d_ntotal); - } - - } /* namespace blocks */ + "check_lfsr_32k: enter_LOCKED at offset %8ld (0x%08lx)\n", + d_ntotal, + d_ntotal); +} + +void check_lfsr_32k_s_impl::log_error(unsigned short expected, unsigned short actual) +{ + if (0) + fprintf(stdout, + "check_lfsr_32k: expected %5d (0x%04x) got %5d (0x%04x) offset %8ld " + "(0x%08lx)\n", + expected, + expected, + actual, + actual, + d_ntotal, + d_ntotal); +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/check_lfsr_32k_s_impl.h b/gr-blocks/lib/check_lfsr_32k_s_impl.h index 2d0da21fcf..3830c0b814 100644 --- a/gr-blocks/lib/check_lfsr_32k_s_impl.h +++ b/gr-blocks/lib/check_lfsr_32k_s_impl.h @@ -27,68 +27,68 @@ #include <gnuradio/blocks/lfsr_32k.h> namespace gr { - namespace blocks { +namespace blocks { - class check_lfsr_32k_s_impl : public check_lfsr_32k_s - { - private: - enum state { - SEARCHING, // searching for synchronization +class check_lfsr_32k_s_impl : public check_lfsr_32k_s +{ +private: + enum state { + SEARCHING, // searching for synchronization MATCH0, MATCH1, MATCH2, - LOCKED // is locked - }; + LOCKED // is locked + }; - state d_state; - unsigned int d_history; // bitmask of decisions + state d_state; + unsigned int d_history; // bitmask of decisions - long d_ntotal; // total number of shorts - long d_nright; // # of correct shorts - long d_runlength; // # of correct shorts in a row + long d_ntotal; // total number of shorts + long d_nright; // # of correct shorts + long d_runlength; // # of correct shorts in a row - static const int BUFSIZE = 2048 - 1; // ensure pattern isn't packet aligned - int d_index; - unsigned short d_buffer[BUFSIZE]; + static const int BUFSIZE = 2048 - 1; // ensure pattern isn't packet aligned + int d_index; + unsigned short d_buffer[BUFSIZE]; - void enter_SEARCHING(); - void enter_MATCH0(); - void enter_MATCH1(); - void enter_MATCH2(); - void enter_LOCKED(); + void enter_SEARCHING(); + void enter_MATCH0(); + void enter_MATCH1(); + void enter_MATCH2(); + void enter_LOCKED(); - void right() - { + void right() + { d_history = (d_history << 1) | 0x1; d_nright++; d_runlength++; - } + } - void wrong() - { + void wrong() + { d_history = (d_history << 1) | 0x0; d_runlength = 0; - } + } - bool right_three_times() { return (d_history & 0x7) == 0x7; } - bool wrong_three_times() { return (d_history & 0x7) == 0x0; } + bool right_three_times() { return (d_history & 0x7) == 0x7; } + bool wrong_three_times() { return (d_history & 0x7) == 0x0; } - void log_error(unsigned short expected, unsigned short actual); + void log_error(unsigned short expected, unsigned short actual); - public: - check_lfsr_32k_s_impl(); - ~check_lfsr_32k_s_impl(); +public: + check_lfsr_32k_s_impl(); + ~check_lfsr_32k_s_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - long ntotal() const { return d_ntotal; } - long nright() const { return d_nright; } - long runlength() const { return d_runlength; } - }; + long ntotal() const { return d_ntotal; } + long nright() const { return d_nright; } + long runlength() const { return d_runlength; } +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_CHECK_LFSR_32K_S_IMPL_H */ diff --git a/gr-blocks/lib/complex_to_arg_impl.cc b/gr-blocks/lib/complex_to_arg_impl.cc index ab92c08b3b..8f5bf61c81 100644 --- a/gr-blocks/lib/complex_to_arg_impl.cc +++ b/gr-blocks/lib/complex_to_arg_impl.cc @@ -30,41 +30,39 @@ #include <gnuradio/math.h> namespace gr { - namespace blocks { +namespace blocks { - complex_to_arg::sptr complex_to_arg::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new complex_to_arg_impl(vlen)); - } - - complex_to_arg_impl::complex_to_arg_impl(size_t vlen) - : sync_block("complex_to_arg", - io_signature::make (1, 1, sizeof(gr_complex)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } +complex_to_arg::sptr complex_to_arg::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new complex_to_arg_impl(vlen)); +} - int - complex_to_arg_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - float *out = (float *) output_items[0]; - int noi = noutput_items * d_vlen; +complex_to_arg_impl::complex_to_arg_impl(size_t vlen) + : sync_block("complex_to_arg", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} - // The fast_atan2f is faster than Volk - for (int i = 0; i < noi; i++){ - // out[i] = std::arg (in[i]); - out[i] = gr::fast_atan2f(in[i]); - } +int complex_to_arg_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + float* out = (float*)output_items[0]; + int noi = noutput_items * d_vlen; - return noutput_items; + // The fast_atan2f is faster than Volk + for (int i = 0; i < noi; i++) { + // out[i] = std::arg (in[i]); + out[i] = gr::fast_atan2f(in[i]); } - } /* namespace blocks */ -}/* namespace gr */ + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_arg_impl.h b/gr-blocks/lib/complex_to_arg_impl.h index 923ef4ba8e..60e08bf387 100644 --- a/gr-blocks/lib/complex_to_arg_impl.h +++ b/gr-blocks/lib/complex_to_arg_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/complex_to_arg.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_arg_impl : public complex_to_arg - { - size_t d_vlen; +class BLOCKS_API complex_to_arg_impl : public complex_to_arg +{ + size_t d_vlen; - public: - complex_to_arg_impl(size_t vlen); +public: + complex_to_arg_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_float_impl.cc b/gr-blocks/lib/complex_to_float_impl.cc index bfa75bd35d..3fc42fafaf 100644 --- a/gr-blocks/lib/complex_to_float_impl.cc +++ b/gr-blocks/lib/complex_to_float_impl.cc @@ -29,51 +29,48 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - complex_to_float::sptr complex_to_float::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new complex_to_float_impl(vlen)); - } +complex_to_float::sptr complex_to_float::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new complex_to_float_impl(vlen)); +} - complex_to_float_impl::complex_to_float_impl(size_t vlen) - : sync_block("complex_to_float", - io_signature::make (1, 1, sizeof(gr_complex)*vlen), - io_signature::make (1, 2, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } +complex_to_float_impl::complex_to_float_impl(size_t vlen) + : sync_block("complex_to_float", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(1, 2, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} - int - complex_to_float_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - float *out0 = (float *) output_items[0]; - float* out1; - int noi = noutput_items * d_vlen; +int complex_to_float_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + float* out0 = (float*)output_items[0]; + float* out1; + int noi = noutput_items * d_vlen; - switch (output_items.size ()){ - case 1: + switch (output_items.size()) { + case 1: volk_32fc_deinterleave_real_32f(out0, in, noi); - break; + break; - case 2: - out1 = (float *) output_items[1]; + case 2: + out1 = (float*)output_items[1]; volk_32fc_deinterleave_32f_x2(out0, out1, in, noi); - break; - - default: - abort (); + break; - } - - return noutput_items; + default: + abort(); } - } /* namespace blocks */ -}/* namespace gr */ + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_float_impl.h b/gr-blocks/lib/complex_to_float_impl.h index 81ac801e71..2bcfb04ff7 100644 --- a/gr-blocks/lib/complex_to_float_impl.h +++ b/gr-blocks/lib/complex_to_float_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/complex_to_float.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_float_impl : public complex_to_float - { - size_t d_vlen; +class BLOCKS_API complex_to_float_impl : public complex_to_float +{ + size_t d_vlen; - public: - complex_to_float_impl(size_t vlen); +public: + complex_to_float_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_imag_impl.cc b/gr-blocks/lib/complex_to_imag_impl.cc index 8e47201694..4620d1d1ac 100644 --- a/gr-blocks/lib/complex_to_imag_impl.cc +++ b/gr-blocks/lib/complex_to_imag_impl.cc @@ -29,37 +29,35 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - complex_to_imag::sptr complex_to_imag::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new complex_to_imag_impl(vlen)); - } - - complex_to_imag_impl::complex_to_imag_impl(size_t vlen) - : sync_block("complex_to_imag", - io_signature::make (1, 1, sizeof(gr_complex)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } - - int - complex_to_imag_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - float *out = (float *) output_items[0]; - int noi = noutput_items * d_vlen; - - volk_32fc_deinterleave_imag_32f(out, in, noi); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +complex_to_imag::sptr complex_to_imag::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new complex_to_imag_impl(vlen)); +} + +complex_to_imag_impl::complex_to_imag_impl(size_t vlen) + : sync_block("complex_to_imag", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +int complex_to_imag_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + float* out = (float*)output_items[0]; + int noi = noutput_items * d_vlen; + + volk_32fc_deinterleave_imag_32f(out, in, noi); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_imag_impl.h b/gr-blocks/lib/complex_to_imag_impl.h index f624c97d82..0ee01b03ae 100644 --- a/gr-blocks/lib/complex_to_imag_impl.h +++ b/gr-blocks/lib/complex_to_imag_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/complex_to_imag.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_imag_impl : public complex_to_imag - { - size_t d_vlen; +class BLOCKS_API complex_to_imag_impl : public complex_to_imag +{ + size_t d_vlen; - public: - complex_to_imag_impl(size_t vlen); +public: + complex_to_imag_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_interleaved_char_impl.cc b/gr-blocks/lib/complex_to_interleaved_char_impl.cc index f25378e64e..066b48f0ba 100644 --- a/gr-blocks/lib/complex_to_interleaved_char_impl.cc +++ b/gr-blocks/lib/complex_to_interleaved_char_impl.cc @@ -17,7 +17,7 @@ * 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. + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H @@ -28,38 +28,38 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - complex_to_interleaved_char::sptr complex_to_interleaved_char::make(bool vector) - { - return gnuradio::get_initial_sptr(new complex_to_interleaved_char_impl(vector)); - } - - complex_to_interleaved_char_impl::complex_to_interleaved_char_impl(bool vector) - : sync_interpolator("complex_to_interleaved_char", - io_signature::make (1, 1, sizeof(gr_complex)), - io_signature::make (1, 1, vector?2*sizeof(char):sizeof(char)), - vector?1:2), - d_vector(vector) - { - } +complex_to_interleaved_char::sptr complex_to_interleaved_char::make(bool vector) +{ + return gnuradio::get_initial_sptr(new complex_to_interleaved_char_impl(vector)); +} - int - complex_to_interleaved_char_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - char *out = (char *) output_items[0]; +complex_to_interleaved_char_impl::complex_to_interleaved_char_impl(bool vector) + : sync_interpolator( + "complex_to_interleaved_char", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, vector ? 2 * sizeof(char) : sizeof(char)), + vector ? 1 : 2), + d_vector(vector) +{ +} - int npairs = (d_vector?noutput_items:noutput_items/2); - for (int i = 0; i < npairs; i++){ - *out++ = (char) lrintf(in[i].real()); // FIXME saturate? - *out++ = (char) lrintf(in[i].imag()); - } +int complex_to_interleaved_char_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + char* out = (char*)output_items[0]; - return noutput_items; + int npairs = (d_vector ? noutput_items : noutput_items / 2); + for (int i = 0; i < npairs; i++) { + *out++ = (char)lrintf(in[i].real()); // FIXME saturate? + *out++ = (char)lrintf(in[i].imag()); } - } /* namespace blocks */ -}/* namespace gr */ + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_interleaved_char_impl.h b/gr-blocks/lib/complex_to_interleaved_char_impl.h index 95ca7ea6a4..74bdbd1a3e 100644 --- a/gr-blocks/lib/complex_to_interleaved_char_impl.h +++ b/gr-blocks/lib/complex_to_interleaved_char_impl.h @@ -26,21 +26,22 @@ #include <gnuradio/blocks/complex_to_interleaved_char.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_interleaved_char_impl : public complex_to_interleaved_char - { - private: - bool d_vector; - public: - complex_to_interleaved_char_impl(bool vector); +class BLOCKS_API complex_to_interleaved_char_impl : public complex_to_interleaved_char +{ +private: + bool d_vector; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; +public: + complex_to_interleaved_char_impl(bool vector); - } /* namespace blocks */ + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_interleaved_short_impl.cc b/gr-blocks/lib/complex_to_interleaved_short_impl.cc index 1bc79989a9..411929905e 100644 --- a/gr-blocks/lib/complex_to_interleaved_short_impl.cc +++ b/gr-blocks/lib/complex_to_interleaved_short_impl.cc @@ -28,38 +28,38 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - complex_to_interleaved_short::sptr complex_to_interleaved_short::make(bool vector) - { - return gnuradio::get_initial_sptr(new complex_to_interleaved_short_impl(vector)); - } - - complex_to_interleaved_short_impl::complex_to_interleaved_short_impl(bool vector) - : sync_interpolator("complex_to_interleaved_short", - io_signature::make (1, 1, sizeof(gr_complex)), - io_signature::make (1, 1, vector?2*sizeof(short):sizeof(short)), - vector?1:2), - d_vector(vector) - { - } +complex_to_interleaved_short::sptr complex_to_interleaved_short::make(bool vector) +{ + return gnuradio::get_initial_sptr(new complex_to_interleaved_short_impl(vector)); +} - int - complex_to_interleaved_short_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - short *out = (short *) output_items[0]; +complex_to_interleaved_short_impl::complex_to_interleaved_short_impl(bool vector) + : sync_interpolator( + "complex_to_interleaved_short", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, vector ? 2 * sizeof(short) : sizeof(short)), + vector ? 1 : 2), + d_vector(vector) +{ +} - int npairs = (d_vector?noutput_items:noutput_items/2); - for (int i = 0; i < npairs; i++){ - *out++ = (short) lrintf(in[i].real()); // FIXME saturate? - *out++ = (short) lrintf(in[i].imag()); - } +int complex_to_interleaved_short_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + short* out = (short*)output_items[0]; - return noutput_items; + int npairs = (d_vector ? noutput_items : noutput_items / 2); + for (int i = 0; i < npairs; i++) { + *out++ = (short)lrintf(in[i].real()); // FIXME saturate? + *out++ = (short)lrintf(in[i].imag()); } - } /* namespace blocks */ -}/* namespace gr */ + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_interleaved_short_impl.h b/gr-blocks/lib/complex_to_interleaved_short_impl.h index 64835f0eec..f14efe0cbd 100644 --- a/gr-blocks/lib/complex_to_interleaved_short_impl.h +++ b/gr-blocks/lib/complex_to_interleaved_short_impl.h @@ -26,21 +26,22 @@ #include <gnuradio/blocks/complex_to_interleaved_short.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_interleaved_short_impl : public complex_to_interleaved_short - { - private: - bool d_vector; - public: - complex_to_interleaved_short_impl(bool vector); +class BLOCKS_API complex_to_interleaved_short_impl : public complex_to_interleaved_short +{ +private: + bool d_vector; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; +public: + complex_to_interleaved_short_impl(bool vector); - } /* namespace blocks */ + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_mag_impl.cc b/gr-blocks/lib/complex_to_mag_impl.cc index b9574a92ce..b520f45d57 100644 --- a/gr-blocks/lib/complex_to_mag_impl.cc +++ b/gr-blocks/lib/complex_to_mag_impl.cc @@ -29,38 +29,36 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - complex_to_mag::sptr complex_to_mag::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new complex_to_mag_impl(vlen)); - } +complex_to_mag::sptr complex_to_mag::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new complex_to_mag_impl(vlen)); +} - complex_to_mag_impl::complex_to_mag_impl(size_t vlen) - : sync_block("complex_to_mag", - io_signature::make (1, 1, sizeof(gr_complex)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } +complex_to_mag_impl::complex_to_mag_impl(size_t vlen) + : sync_block("complex_to_mag", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} - int - complex_to_mag_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - float *out = (float *) output_items[0]; - int noi = noutput_items * d_vlen; +int complex_to_mag_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + float* out = (float*)output_items[0]; + int noi = noutput_items * d_vlen; - // turned out to be faster than aligned/unaligned switching - volk_32fc_magnitude_32f_u(out, in, noi); + // turned out to be faster than aligned/unaligned switching + volk_32fc_magnitude_32f_u(out, in, noi); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_mag_impl.h b/gr-blocks/lib/complex_to_mag_impl.h index 88f6f2843a..5778bd91ca 100644 --- a/gr-blocks/lib/complex_to_mag_impl.h +++ b/gr-blocks/lib/complex_to_mag_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/complex_to_mag.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_mag_impl : public complex_to_mag - { - size_t d_vlen; +class BLOCKS_API complex_to_mag_impl : public complex_to_mag +{ + size_t d_vlen; - public: - complex_to_mag_impl(size_t vlen); +public: + complex_to_mag_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_mag_squared_impl.cc b/gr-blocks/lib/complex_to_mag_squared_impl.cc index 0e41ae0d4c..070d04e8cc 100644 --- a/gr-blocks/lib/complex_to_mag_squared_impl.cc +++ b/gr-blocks/lib/complex_to_mag_squared_impl.cc @@ -29,37 +29,35 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - complex_to_mag_squared::sptr complex_to_mag_squared::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new complex_to_mag_squared_impl(vlen)); - } - - complex_to_mag_squared_impl::complex_to_mag_squared_impl(size_t vlen) - : sync_block("complex_to_mag_squared", - io_signature::make (1, 1, sizeof(gr_complex)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } - - int - complex_to_mag_squared_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - float *out = (float *) output_items[0]; - int noi = noutput_items * d_vlen; - - volk_32fc_magnitude_squared_32f(out, in, noi); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +complex_to_mag_squared::sptr complex_to_mag_squared::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new complex_to_mag_squared_impl(vlen)); +} + +complex_to_mag_squared_impl::complex_to_mag_squared_impl(size_t vlen) + : sync_block("complex_to_mag_squared", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +int complex_to_mag_squared_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + float* out = (float*)output_items[0]; + int noi = noutput_items * d_vlen; + + volk_32fc_magnitude_squared_32f(out, in, noi); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_mag_squared_impl.h b/gr-blocks/lib/complex_to_mag_squared_impl.h index 2413b3bbdf..e03e59aabb 100644 --- a/gr-blocks/lib/complex_to_mag_squared_impl.h +++ b/gr-blocks/lib/complex_to_mag_squared_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/complex_to_mag_squared.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_mag_squared_impl : public complex_to_mag_squared - { - size_t d_vlen; +class BLOCKS_API complex_to_mag_squared_impl : public complex_to_mag_squared +{ + size_t d_vlen; - public: - complex_to_mag_squared_impl(size_t vlen); +public: + complex_to_mag_squared_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_magphase_impl.cc b/gr-blocks/lib/complex_to_magphase_impl.cc index 8c914f756b..dd72c8e9c8 100644 --- a/gr-blocks/lib/complex_to_magphase_impl.cc +++ b/gr-blocks/lib/complex_to_magphase_impl.cc @@ -30,44 +30,42 @@ #include <gnuradio/math.h> namespace gr { - namespace blocks { +namespace blocks { - complex_to_magphase::sptr complex_to_magphase::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new complex_to_magphase_impl(vlen)); - } - - complex_to_magphase_impl::complex_to_magphase_impl(size_t vlen) - : sync_block("complex_to_magphase", - io_signature::make (1, 1, sizeof(gr_complex)*vlen), - io_signature::make (2, 2, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } +complex_to_magphase::sptr complex_to_magphase::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new complex_to_magphase_impl(vlen)); +} - int - complex_to_magphase_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - float *out0 = (float *) output_items[0]; - float* out1 = (float *) output_items[1]; - int noi = noutput_items * d_vlen; +complex_to_magphase_impl::complex_to_magphase_impl(size_t vlen) + : sync_block("complex_to_magphase", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(2, 2, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} - volk_32fc_magnitude_32f_u(out0, in, noi); +int complex_to_magphase_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + float* out0 = (float*)output_items[0]; + float* out1 = (float*)output_items[1]; + int noi = noutput_items * d_vlen; - // The fast_atan2f is faster than Volk - for (int i = 0; i < noi; i++){ - // out[i] = std::arg (in[i]); - out1[i] = gr::fast_atan2f(in[i]); - } + volk_32fc_magnitude_32f_u(out0, in, noi); - return noutput_items; + // The fast_atan2f is faster than Volk + for (int i = 0; i < noi; i++) { + // out[i] = std::arg (in[i]); + out1[i] = gr::fast_atan2f(in[i]); } - } /* namespace blocks */ -}/* namespace gr */ + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_magphase_impl.h b/gr-blocks/lib/complex_to_magphase_impl.h index 4673d8ab2a..a6c1be0049 100644 --- a/gr-blocks/lib/complex_to_magphase_impl.h +++ b/gr-blocks/lib/complex_to_magphase_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/complex_to_magphase.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_magphase_impl : public complex_to_magphase - { - size_t d_vlen; +class BLOCKS_API complex_to_magphase_impl : public complex_to_magphase +{ + size_t d_vlen; - public: - complex_to_magphase_impl(size_t vlen); +public: + complex_to_magphase_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_real_impl.cc b/gr-blocks/lib/complex_to_real_impl.cc index bab139e79c..ab4119969f 100644 --- a/gr-blocks/lib/complex_to_real_impl.cc +++ b/gr-blocks/lib/complex_to_real_impl.cc @@ -29,37 +29,35 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - complex_to_real::sptr complex_to_real::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new complex_to_real_impl(vlen)); - } - - complex_to_real_impl::complex_to_real_impl(size_t vlen) - : sync_block("complex_to_real", - io_signature::make (1, 1, sizeof(gr_complex)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } - - int - complex_to_real_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *) input_items[0]; - float *out = (float *) output_items[0]; - int noi = noutput_items * d_vlen; - - volk_32fc_deinterleave_real_32f(out, in, noi); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +complex_to_real::sptr complex_to_real::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new complex_to_real_impl(vlen)); +} + +complex_to_real_impl::complex_to_real_impl(size_t vlen) + : sync_block("complex_to_real", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +int complex_to_real_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + float* out = (float*)output_items[0]; + int noi = noutput_items * d_vlen; + + volk_32fc_deinterleave_real_32f(out, in, noi); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/complex_to_real_impl.h b/gr-blocks/lib/complex_to_real_impl.h index e3c4dbaa19..27af7f766b 100644 --- a/gr-blocks/lib/complex_to_real_impl.h +++ b/gr-blocks/lib/complex_to_real_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/complex_to_real.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API complex_to_real_impl : public complex_to_real - { - size_t d_vlen; +class BLOCKS_API complex_to_real_impl : public complex_to_real +{ + size_t d_vlen; - public: - complex_to_real_impl(size_t vlen); +public: + complex_to_real_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/conjugate_cc_impl.cc b/gr-blocks/lib/conjugate_cc_impl.cc index d16f9eb421..a8c9d79b77 100644 --- a/gr-blocks/lib/conjugate_cc_impl.cc +++ b/gr-blocks/lib/conjugate_cc_impl.cc @@ -29,35 +29,33 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - conjugate_cc::sptr conjugate_cc::make() - { - return gnuradio::get_initial_sptr(new conjugate_cc_impl()); - } - - conjugate_cc_impl::conjugate_cc_impl() - : sync_block("conjugate_cc", - io_signature::make (1, 1, sizeof(gr_complex)), - io_signature::make (1, 1, sizeof(gr_complex))) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(std::max(1, alignment_multiple)); - } - - int - conjugate_cc_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr_complex *iptr = (gr_complex *) input_items[0]; - gr_complex *optr = (gr_complex *) output_items[0]; - - volk_32fc_conjugate_32fc(optr, iptr, noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +conjugate_cc::sptr conjugate_cc::make() +{ + return gnuradio::get_initial_sptr(new conjugate_cc_impl()); +} + +conjugate_cc_impl::conjugate_cc_impl() + : sync_block("conjugate_cc", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); +} + +int conjugate_cc_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr_complex* iptr = (gr_complex*)input_items[0]; + gr_complex* optr = (gr_complex*)output_items[0]; + + volk_32fc_conjugate_32fc(optr, iptr, noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/conjugate_cc_impl.h b/gr-blocks/lib/conjugate_cc_impl.h index d3d0f9a0b7..4d35a22e69 100644 --- a/gr-blocks/lib/conjugate_cc_impl.h +++ b/gr-blocks/lib/conjugate_cc_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/conjugate_cc.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API conjugate_cc_impl : public conjugate_cc - { - public: - conjugate_cc_impl(); +class BLOCKS_API conjugate_cc_impl : public conjugate_cc +{ +public: + conjugate_cc_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_CONJUGATE_CC_IMPL_H */ diff --git a/gr-blocks/lib/control_loop.cc b/gr-blocks/lib/control_loop.cc index 30260b5646..c8bca8ef12 100644 --- a/gr-blocks/lib/control_loop.cc +++ b/gr-blocks/lib/control_loop.cc @@ -29,186 +29,133 @@ #include <stdexcept> namespace gr { - namespace blocks { - -#define M_TWOPI (2.0f*GR_M_PI) - - control_loop::control_loop(float loop_bw, - float max_freq, float min_freq) - : d_phase(0), d_freq(0), d_max_freq(max_freq), d_min_freq(min_freq) - { - // Set the damping factor for a critically damped system - d_damping = sqrtf(2.0f)/2.0f; - - // Set the bandwidth, which will then call update_gains() - set_loop_bandwidth(loop_bw); - } - - control_loop::~control_loop() - { - } - - void - control_loop::update_gains() - { - float denom = (1.0 + 2.0*d_damping*d_loop_bw + d_loop_bw*d_loop_bw); - d_alpha = (4*d_damping*d_loop_bw) / denom; - d_beta = (4*d_loop_bw*d_loop_bw) / denom; - } - - void - control_loop::advance_loop(float error) - { - d_freq = d_freq + d_beta * error; - d_phase = d_phase + d_freq + d_alpha * error; - } - - void - control_loop::phase_wrap() - { - while(d_phase>M_TWOPI) +namespace blocks { + +#define M_TWOPI (2.0f * GR_M_PI) + +control_loop::control_loop(float loop_bw, float max_freq, float min_freq) + : d_phase(0), d_freq(0), d_max_freq(max_freq), d_min_freq(min_freq) +{ + // Set the damping factor for a critically damped system + d_damping = sqrtf(2.0f) / 2.0f; + + // Set the bandwidth, which will then call update_gains() + set_loop_bandwidth(loop_bw); +} + +control_loop::~control_loop() {} + +void control_loop::update_gains() +{ + float denom = (1.0 + 2.0 * d_damping * d_loop_bw + d_loop_bw * d_loop_bw); + d_alpha = (4 * d_damping * d_loop_bw) / denom; + d_beta = (4 * d_loop_bw * d_loop_bw) / denom; +} + +void control_loop::advance_loop(float error) +{ + d_freq = d_freq + d_beta * error; + d_phase = d_phase + d_freq + d_alpha * error; +} + +void control_loop::phase_wrap() +{ + while (d_phase > M_TWOPI) d_phase -= M_TWOPI; - while(d_phase<-M_TWOPI) + while (d_phase < -M_TWOPI) d_phase += M_TWOPI; - } +} - void - control_loop::frequency_limit() - { - if(d_freq > d_max_freq) +void control_loop::frequency_limit() +{ + if (d_freq > d_max_freq) d_freq = d_max_freq; - else if(d_freq < d_min_freq) + else if (d_freq < d_min_freq) d_freq = d_min_freq; - } - - /******************************************************************* - * SET FUNCTIONS - *******************************************************************/ +} - void - control_loop::set_loop_bandwidth(float bw) - { - if(bw < 0) { - throw std::out_of_range ("control_loop: invalid bandwidth. Must be >= 0."); - } +/******************************************************************* + * SET FUNCTIONS + *******************************************************************/ - d_loop_bw = bw; - update_gains(); +void control_loop::set_loop_bandwidth(float bw) +{ + if (bw < 0) { + throw std::out_of_range("control_loop: invalid bandwidth. Must be >= 0."); } - void - control_loop::set_damping_factor(float df) - { - if(df <= 0) { - throw std::out_of_range ("control_loop: invalid damping factor. Must be > 0."); - } + d_loop_bw = bw; + update_gains(); +} - d_damping = df; - update_gains(); +void control_loop::set_damping_factor(float df) +{ + if (df <= 0) { + throw std::out_of_range("control_loop: invalid damping factor. Must be > 0."); } - void - control_loop::set_alpha(float alpha) - { - if(alpha < 0 || alpha > 1.0) { - throw std::out_of_range ("control_loop: invalid alpha. Must be in [0,1]."); - } - d_alpha = alpha; + d_damping = df; + update_gains(); +} + +void control_loop::set_alpha(float alpha) +{ + if (alpha < 0 || alpha > 1.0) { + throw std::out_of_range("control_loop: invalid alpha. Must be in [0,1]."); } + d_alpha = alpha; +} - void - control_loop::set_beta(float beta) - { - if(beta < 0 || beta > 1.0) { - throw std::out_of_range ("control_loop: invalid beta. Must be in [0,1]."); - } - d_beta = beta; +void control_loop::set_beta(float beta) +{ + if (beta < 0 || beta > 1.0) { + throw std::out_of_range("control_loop: invalid beta. Must be in [0,1]."); } + d_beta = beta; +} - void - control_loop::set_frequency(float freq) - { - if(freq > d_max_freq) +void control_loop::set_frequency(float freq) +{ + if (freq > d_max_freq) d_freq = d_min_freq; - else if(freq < d_min_freq) + else if (freq < d_min_freq) d_freq = d_max_freq; - else + else d_freq = freq; - } +} - void - control_loop::set_phase(float phase) - { - d_phase = phase; - while(d_phase>M_TWOPI) +void control_loop::set_phase(float phase) +{ + d_phase = phase; + while (d_phase > M_TWOPI) d_phase -= M_TWOPI; - while(d_phase<-M_TWOPI) + while (d_phase < -M_TWOPI) d_phase += M_TWOPI; - } +} - void - control_loop::set_max_freq(float freq) - { - d_max_freq = freq; - } +void control_loop::set_max_freq(float freq) { d_max_freq = freq; } - void - control_loop::set_min_freq(float freq) - { - d_min_freq = freq; - } +void control_loop::set_min_freq(float freq) { d_min_freq = freq; } - /******************************************************************* - * GET FUNCTIONS - *******************************************************************/ +/******************************************************************* + * GET FUNCTIONS + *******************************************************************/ - float - control_loop::get_loop_bandwidth() const - { - return d_loop_bw; - } +float control_loop::get_loop_bandwidth() const { return d_loop_bw; } - float - control_loop::get_damping_factor() const - { - return d_damping; - } +float control_loop::get_damping_factor() const { return d_damping; } - float - control_loop::get_alpha() const - { - return d_alpha; - } +float control_loop::get_alpha() const { return d_alpha; } - float - control_loop::get_beta() const - { - return d_beta; - } +float control_loop::get_beta() const { return d_beta; } - float - control_loop::get_frequency() const - { - return d_freq; - } +float control_loop::get_frequency() const { return d_freq; } - float - control_loop::get_phase() const - { - return d_phase; - } +float control_loop::get_phase() const { return d_phase; } - float - control_loop::get_max_freq() const - { - return d_max_freq; - } +float control_loop::get_max_freq() const { return d_max_freq; } - float - control_loop::get_min_freq() const - { - return d_min_freq; - } +float control_loop::get_min_freq() const { return d_min_freq; } - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/copy_impl.cc b/gr-blocks/lib/copy_impl.cc index acac576075..c377e57b1e 100644 --- a/gr-blocks/lib/copy_impl.cc +++ b/gr-blocks/lib/copy_impl.cc @@ -29,88 +29,72 @@ #include <string.h> namespace gr { - namespace blocks { +namespace blocks { - copy::sptr - copy::make(size_t itemsize) - { - return gnuradio::get_initial_sptr - (new copy_impl(itemsize)); - } +copy::sptr copy::make(size_t itemsize) +{ + return gnuradio::get_initial_sptr(new copy_impl(itemsize)); +} - copy_impl::copy_impl(size_t itemsize) - : block("copy", - io_signature::make(1, -1, itemsize), - io_signature::make(1, -1, itemsize)), - d_itemsize(itemsize), - d_enabled(true) - { - message_port_register_in(pmt::mp("en")); - set_msg_handler(pmt::mp("en"), - boost::bind(©_impl::handle_enable, this, _1)); - } +copy_impl::copy_impl(size_t itemsize) + : block("copy", + io_signature::make(1, -1, itemsize), + io_signature::make(1, -1, itemsize)), + d_itemsize(itemsize), + d_enabled(true) +{ + message_port_register_in(pmt::mp("en")); + set_msg_handler(pmt::mp("en"), boost::bind(©_impl::handle_enable, this, _1)); +} - copy_impl::~copy_impl() - { - } +copy_impl::~copy_impl() {} - void - copy_impl::handle_enable(pmt::pmt_t msg) - { - if(pmt::is_bool(msg)) { +void copy_impl::handle_enable(pmt::pmt_t msg) +{ + if (pmt::is_bool(msg)) { bool en = pmt::to_bool(msg); d_enabled = en; - } } +} - void - copy_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required) - { - unsigned ninputs = ninput_items_required.size(); - for (unsigned i = 0; i < ninputs; i++) - ninput_items_required[i] = noutput_items; - } +void copy_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required) +{ + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = noutput_items; +} - bool - copy_impl::check_topology(int ninputs, int noutputs) - { - return ninputs == noutputs; - } +bool copy_impl::check_topology(int ninputs, int noutputs) { return ninputs == noutputs; } - int - copy_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const uint8_t **in = (const uint8_t**)&input_items[0]; - uint8_t **out = (uint8_t**)&output_items[0]; +int copy_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const uint8_t** in = (const uint8_t**)&input_items[0]; + uint8_t** out = (uint8_t**)&output_items[0]; - int n = 0; - if(d_enabled) { + int n = 0; + if (d_enabled) { int ninputs = input_items.size(); - for(int i = 0; i < ninputs; i++) { - memcpy(out[i], in[i], noutput_items*d_itemsize); + for (int i = 0; i < ninputs; i++) { + memcpy(out[i], in[i], noutput_items * d_itemsize); } n = noutput_items; - } - - consume_each(noutput_items); - return n; } + consume_each(noutput_items); + return n; +} - void - copy_impl::setup_rpc() - { + +void copy_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_handler<copy>( - alias(), "en", - "", "Enable", - RPC_PRIVLVL_MIN, DISPNULL))); + add_rpc_variable(rpcbasic_sptr(new rpcbasic_register_handler<copy>( + alias(), "en", "", "Enable", RPC_PRIVLVL_MIN, DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/copy_impl.h b/gr-blocks/lib/copy_impl.h index ac7126749b..d49dd128f5 100644 --- a/gr-blocks/lib/copy_impl.h +++ b/gr-blocks/lib/copy_impl.h @@ -26,35 +26,35 @@ #include <gnuradio/blocks/copy.h> namespace gr { - namespace blocks { +namespace blocks { - class copy_impl : public copy - { - private: - size_t d_itemsize; - bool d_enabled; +class copy_impl : public copy +{ +private: + size_t d_itemsize; + bool d_enabled; - public: - copy_impl(size_t itemsize); - ~copy_impl(); +public: + copy_impl(size_t itemsize); + ~copy_impl(); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); - bool check_topology(int ninputs, int noutputs); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); + bool check_topology(int ninputs, int noutputs); - void handle_enable(pmt::pmt_t msg); + void handle_enable(pmt::pmt_t msg); - void setup_rpc(); + void setup_rpc(); - void set_enabled(bool enable) { d_enabled = enable; } - bool enabled() const { return d_enabled;} + void set_enabled(bool enable) { d_enabled = enable; } + bool enabled() const { return d_enabled; } - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int general_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 blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_COPY_IMPL_H */ diff --git a/gr-blocks/lib/count_bits.cc b/gr-blocks/lib/count_bits.cc index c65dc94894..aaab97b66a 100644 --- a/gr-blocks/lib/count_bits.cc +++ b/gr-blocks/lib/count_bits.cc @@ -29,50 +29,45 @@ */ namespace gr { - namespace blocks { +namespace blocks { - unsigned int - count_bits8(unsigned int x) - { - int count = 0; +unsigned int count_bits8(unsigned int x) +{ + int count = 0; - for(int i = 0; i < 8; i++) { - if(x & (1 << i)) - count++; - } - - return count; + for (int i = 0; i < 8; i++) { + if (x & (1 << i)) + count++; } - unsigned int - count_bits16(unsigned int x) - { - int count = 0; + return count; +} - for(int i = 0; i < 16; i++) { - if(x & (1 << i)) - count++; - } +unsigned int count_bits16(unsigned int x) +{ + int count = 0; - return count; + for (int i = 0; i < 16; i++) { + if (x & (1 << i)) + count++; } - unsigned int - count_bits32(unsigned int x) - { - unsigned res = (x & 0x55555555) + ((x >> 1) & 0x55555555); - res = (res & 0x33333333) + ((res >> 2) & 0x33333333); - res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F); - res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF); - return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF); - } + return count; +} - unsigned int - count_bits64(unsigned long long x) - { - return count_bits32((x >> 32) & 0xffffffff) + \ - count_bits32(x & 0xffffffff); - } +unsigned int count_bits32(unsigned int x) +{ + unsigned res = (x & 0x55555555) + ((x >> 1) & 0x55555555); + res = (res & 0x33333333) + ((res >> 2) & 0x33333333); + res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F); + res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF); + return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF); +} + +unsigned int count_bits64(unsigned long long x) +{ + return count_bits32((x >> 32) & 0xffffffff) + count_bits32(x & 0xffffffff); +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/ctrlport_probe2_b_impl.cc b/gr-blocks/lib/ctrlport_probe2_b_impl.cc index 996e997d96..b5c9532658 100644 --- a/gr-blocks/lib/ctrlport_probe2_b_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_b_impl.cc @@ -28,122 +28,132 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - ctrlport_probe2_b::sptr - ctrlport_probe2_b::make(const std::string &id, const std::string &desc, - int len, unsigned int disp_mask) - { - return gnuradio::get_initial_sptr - (new ctrlport_probe2_b_impl(id, desc, len, disp_mask)); - } - - ctrlport_probe2_b_impl::ctrlport_probe2_b_impl(const std::string &id, - const std::string &desc, - int len, unsigned int disp_mask) +namespace blocks { + +ctrlport_probe2_b::sptr ctrlport_probe2_b::make(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask) +{ + return gnuradio::get_initial_sptr( + new ctrlport_probe2_b_impl(id, desc, len, disp_mask)); +} + +ctrlport_probe2_b_impl::ctrlport_probe2_b_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask) : sync_block("probe2_b", io_signature::make(1, 1, sizeof(char)), io_signature::make(0, 0, 0)), - d_id(id), d_desc(desc), d_len(len), d_disp_mask(disp_mask) - { - set_length(len); - } - - ctrlport_probe2_b_impl::~ctrlport_probe2_b_impl() - { - } - - void - ctrlport_probe2_b_impl::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - // make sure all inputs have noutput_items available - unsigned ninputs = ninput_items_required.size(); - for(unsigned i = 0; i < ninputs; i++) + d_id(id), + d_desc(desc), + d_len(len), + d_disp_mask(disp_mask) +{ + set_length(len); +} + +ctrlport_probe2_b_impl::~ctrlport_probe2_b_impl() {} + +void ctrlport_probe2_b_impl::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{ + // make sure all inputs have noutput_items available + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) ninput_items_required[i] = d_len; - } +} - std::vector<signed char> - ctrlport_probe2_b_impl::get() - { - return buffered_get.get(); - } +std::vector<signed char> ctrlport_probe2_b_impl::get() { return buffered_get.get(); } - void - ctrlport_probe2_b_impl::set_length(int len) - { - gr::thread::scoped_lock guard(d_setlock); +void ctrlport_probe2_b_impl::set_length(int len) +{ + gr::thread::scoped_lock guard(d_setlock); - if(len > 8191) { + if (len > 8191) { GR_LOG_WARN(d_logger, boost::format("probe2_b: length %1% exceeds maximum" - " buffer size of 8191") % len); + " buffer size of 8191") % + len); len = 8191; - } - - d_len = len; - d_buffer.resize(d_len); - d_index = 0; } - int - ctrlport_probe2_b_impl::length() const - { - return (int)d_len; - } + d_len = len; + d_buffer.resize(d_len); + d_index = 0; +} - int - ctrlport_probe2_b_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *in = (const char*)input_items[0]; +int ctrlport_probe2_b_impl::length() const { return (int)d_len; } - gr::thread::scoped_lock guard(d_setlock); +int ctrlport_probe2_b_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* in = (const char*)input_items[0]; - // copy samples to get buffer if we need samples - if(d_index < d_len) { + gr::thread::scoped_lock guard(d_setlock); + + // copy samples to get buffer if we need samples + if (d_index < d_len) { // copy smaller of remaining buffer space and num inputs to work() - int num_copy = std::min( (int)(d_len - d_index), noutput_items ); + int num_copy = std::min((int)(d_len - d_index), noutput_items); - memcpy(&d_buffer[d_index], in, num_copy*sizeof(char)); + memcpy(&d_buffer[d_index], in, num_copy * sizeof(char)); d_index += num_copy; - } + } - // notify the waiting get() if we fill up the buffer - if(d_index == d_len) { + // notify the waiting get() if we fill up the buffer + if (d_index == d_len) { buffered_get.offer_data(d_buffer); d_index = 0; - } - - return noutput_items; } - void - ctrlport_probe2_b_impl::setup_rpc() - { + return noutput_items; +} + +void ctrlport_probe2_b_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - int len = static_cast<int>(d_len); - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_b, std::vector<signed char> >( - alias(), d_id.c_str(), &ctrlport_probe2_b::get, - pmt::mp(-128), pmt::mp(127), pmt::mp(0), - "volts", d_desc.c_str(), RPC_PRIVLVL_MIN, - d_disp_mask))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_b, int>( - alias(), "length", &ctrlport_probe2_b::length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "get vector length", RPC_PRIVLVL_MIN, DISPNULL))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_set<ctrlport_probe2_b, int>( - alias(), "length", &ctrlport_probe2_b::set_length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "set vector length", RPC_PRIVLVL_MIN, DISPNULL))); + int len = static_cast<int>(d_len); + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<ctrlport_probe2_b, std::vector<signed char>>( + alias(), + d_id.c_str(), + &ctrlport_probe2_b::get, + pmt::mp(-128), + pmt::mp(127), + pmt::mp(0), + "volts", + d_desc.c_str(), + RPC_PRIVLVL_MIN, + d_disp_mask))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<ctrlport_probe2_b, int>(alias(), + "length", + &ctrlport_probe2_b::length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "get vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_set<ctrlport_probe2_b, int>(alias(), + "length", + &ctrlport_probe2_b::set_length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "set vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/ctrlport_probe2_b_impl.h b/gr-blocks/lib/ctrlport_probe2_b_impl.h index 165f0d33db..8a5f7952c8 100644 --- a/gr-blocks/lib/ctrlport_probe2_b_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_b_impl.h @@ -28,40 +28,42 @@ #include <gnuradio/rpcbufferedget.h> namespace gr { - namespace blocks { +namespace blocks { - class ctrlport_probe2_b_impl : public ctrlport_probe2_b - { - private: - std::string d_id; - std::string d_desc; - size_t d_len; - unsigned int d_disp_mask; +class ctrlport_probe2_b_impl : public ctrlport_probe2_b +{ +private: + std::string d_id; + std::string d_desc; + size_t d_len; + unsigned int d_disp_mask; - size_t d_index; - std::vector<signed char> d_buffer; - rpcbufferedget< std::vector<signed char> > buffered_get; + size_t d_index; + std::vector<signed char> d_buffer; + rpcbufferedget<std::vector<signed char>> buffered_get; - public: - ctrlport_probe2_b_impl(const std::string &id, const std::string &desc, - int len, unsigned int disp_mask); - ~ctrlport_probe2_b_impl(); +public: + ctrlport_probe2_b_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask); + ~ctrlport_probe2_b_impl(); - void setup_rpc(); + void setup_rpc(); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - std::vector<signed char> get(); + std::vector<signed char> get(); - void set_length(int len); - int length() const; + void set_length(int len); + int length() const; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_C_IMPL_H */ diff --git a/gr-blocks/lib/ctrlport_probe2_c_impl.cc b/gr-blocks/lib/ctrlport_probe2_c_impl.cc index b8ed0af444..b1b8233f2d 100644 --- a/gr-blocks/lib/ctrlport_probe2_c_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_c_impl.cc @@ -28,123 +28,132 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - ctrlport_probe2_c::sptr - ctrlport_probe2_c::make(const std::string &id, - const std::string &desc, - int len, unsigned int disp_mask) - { - return gnuradio::get_initial_sptr - (new ctrlport_probe2_c_impl(id, desc, len, disp_mask)); - } - - ctrlport_probe2_c_impl::ctrlport_probe2_c_impl(const std::string &id, - const std::string &desc, - int len, unsigned int disp_mask) - : sync_block("probe2_c", - io_signature::make(1, 1, sizeof(gr_complex)), - io_signature::make(0, 0, 0)), - d_id(id), d_desc(desc), d_len(len), d_disp_mask(disp_mask) - { - set_length(len); - } - - ctrlport_probe2_c_impl::~ctrlport_probe2_c_impl() - { - } - - void - ctrlport_probe2_c_impl::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - // make sure all inputs have noutput_items available - unsigned ninputs = ninput_items_required.size(); - for(unsigned i = 0; i < ninputs; i++) +namespace blocks { + +ctrlport_probe2_c::sptr ctrlport_probe2_c::make(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask) +{ + return gnuradio::get_initial_sptr( + new ctrlport_probe2_c_impl(id, desc, len, disp_mask)); +} + +ctrlport_probe2_c_impl::ctrlport_probe2_c_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask) + : sync_block("probe2_c", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(0, 0, 0)), + d_id(id), + d_desc(desc), + d_len(len), + d_disp_mask(disp_mask) +{ + set_length(len); +} + +ctrlport_probe2_c_impl::~ctrlport_probe2_c_impl() {} + +void ctrlport_probe2_c_impl::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{ + // make sure all inputs have noutput_items available + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) ninput_items_required[i] = d_len; - } +} - std::vector<gr_complex> - ctrlport_probe2_c_impl::get() - { - return buffered_get.get(); - } +std::vector<gr_complex> ctrlport_probe2_c_impl::get() { return buffered_get.get(); } - void - ctrlport_probe2_c_impl::set_length(int len) - { - gr::thread::scoped_lock guard(d_setlock); +void ctrlport_probe2_c_impl::set_length(int len) +{ + gr::thread::scoped_lock guard(d_setlock); - if(len > 8191) { + if (len > 8191) { GR_LOG_WARN(d_logger, boost::format("probe2_c: length %1% exceeds maximum" - " buffer size of 8191") % len); + " buffer size of 8191") % + len); len = 8191; - } - - d_len = len; - d_buffer.resize(d_len); - d_index = 0; } - int - ctrlport_probe2_c_impl::length() const - { - return (int)d_len; - } + d_len = len; + d_buffer.resize(d_len); + d_index = 0; +} - int - ctrlport_probe2_c_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex*)input_items[0]; +int ctrlport_probe2_c_impl::length() const { return (int)d_len; } - gr::thread::scoped_lock guard(d_setlock); +int ctrlport_probe2_c_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; - // copy samples to get buffer if we need samples - if(d_index < d_len) { + gr::thread::scoped_lock guard(d_setlock); + + // copy samples to get buffer if we need samples + if (d_index < d_len) { // copy smaller of remaining buffer space and num inputs to work() - int num_copy = std::min( (int)(d_len - d_index), noutput_items ); + int num_copy = std::min((int)(d_len - d_index), noutput_items); - memcpy(&d_buffer[d_index], in, num_copy*sizeof(gr_complex)); + memcpy(&d_buffer[d_index], in, num_copy * sizeof(gr_complex)); d_index += num_copy; - } + } - // notify the waiting get() if we fill up the buffer - if(d_index == d_len) { + // notify the waiting get() if we fill up the buffer + if (d_index == d_len) { buffered_get.offer_data(d_buffer); d_index = 0; - } - - return noutput_items; } - void - ctrlport_probe2_c_impl::setup_rpc() - { + return noutput_items; +} + +void ctrlport_probe2_c_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - int len = static_cast<int>(d_len); - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_c, std::vector<std::complex<float> > >( - alias(), d_id.c_str(), &ctrlport_probe2_c::get, - pmt::mp(-2), pmt::mp(2), pmt::mp(0), - "volts", d_desc.c_str(), RPC_PRIVLVL_MIN, - d_disp_mask | DISPOPTCPLX))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_c, int>( - alias(), "length", &ctrlport_probe2_c::length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "get vector length", RPC_PRIVLVL_MIN, DISPNULL))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_set<ctrlport_probe2_c, int>( - alias(), "length", &ctrlport_probe2_c::set_length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "set vector length", RPC_PRIVLVL_MIN, DISPNULL))); + int len = static_cast<int>(d_len); + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<ctrlport_probe2_c, std::vector<std::complex<float>>>( + alias(), + d_id.c_str(), + &ctrlport_probe2_c::get, + pmt::mp(-2), + pmt::mp(2), + pmt::mp(0), + "volts", + d_desc.c_str(), + RPC_PRIVLVL_MIN, + d_disp_mask | DISPOPTCPLX))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<ctrlport_probe2_c, int>(alias(), + "length", + &ctrlport_probe2_c::length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "get vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_set<ctrlport_probe2_c, int>(alias(), + "length", + &ctrlport_probe2_c::set_length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "set vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/ctrlport_probe2_c_impl.h b/gr-blocks/lib/ctrlport_probe2_c_impl.h index 119738a481..63d7629e26 100644 --- a/gr-blocks/lib/ctrlport_probe2_c_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_c_impl.h @@ -28,40 +28,42 @@ #include <gnuradio/rpcbufferedget.h> namespace gr { - namespace blocks { +namespace blocks { - class ctrlport_probe2_c_impl : public ctrlport_probe2_c - { - private: - std::string d_id; - std::string d_desc; - size_t d_len; - unsigned int d_disp_mask; +class ctrlport_probe2_c_impl : public ctrlport_probe2_c +{ +private: + std::string d_id; + std::string d_desc; + size_t d_len; + unsigned int d_disp_mask; - size_t d_index; - std::vector<gr_complex> d_buffer; - rpcbufferedget< std::vector<gr_complex> > buffered_get; + size_t d_index; + std::vector<gr_complex> d_buffer; + rpcbufferedget<std::vector<gr_complex>> buffered_get; - public: - ctrlport_probe2_c_impl(const std::string &id, const std::string &desc, - int len, unsigned int disp_mask); - ~ctrlport_probe2_c_impl(); +public: + ctrlport_probe2_c_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask); + ~ctrlport_probe2_c_impl(); - void setup_rpc(); + void setup_rpc(); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - std::vector<gr_complex> get(); + std::vector<gr_complex> get(); - void set_length(int len); - int length() const; + void set_length(int len); + int length() const; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_C_IMPL_H */ diff --git a/gr-blocks/lib/ctrlport_probe2_f_impl.cc b/gr-blocks/lib/ctrlport_probe2_f_impl.cc index ff37401e88..d373c23770 100644 --- a/gr-blocks/lib/ctrlport_probe2_f_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_f_impl.cc @@ -28,124 +28,135 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - ctrlport_probe2_f::sptr - ctrlport_probe2_f::make(const std::string &id, const std::string &desc, - int len, unsigned int disp_mask) - { - return gnuradio::get_initial_sptr - (new ctrlport_probe2_f_impl(id, desc, len, disp_mask)); - } - - ctrlport_probe2_f_impl::ctrlport_probe2_f_impl(const std::string &id, const std::string &desc, - int len, unsigned int disp_mask) +namespace blocks { + +ctrlport_probe2_f::sptr ctrlport_probe2_f::make(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask) +{ + return gnuradio::get_initial_sptr( + new ctrlport_probe2_f_impl(id, desc, len, disp_mask)); +} + +ctrlport_probe2_f_impl::ctrlport_probe2_f_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask) : sync_block("probe2_f", io_signature::make(1, 1, sizeof(float)), io_signature::make(0, 0, 0)), - d_id(id), d_desc(desc), d_len(len), d_disp_mask(disp_mask) - { - set_length(len); - } - - ctrlport_probe2_f_impl::~ctrlport_probe2_f_impl() - { - } - - void - ctrlport_probe2_f_impl::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - // make sure all inputs have noutput_items available - unsigned ninputs = ninput_items_required.size(); - for(unsigned i = 0; i < ninputs; i++) + d_id(id), + d_desc(desc), + d_len(len), + d_disp_mask(disp_mask) +{ + set_length(len); +} + +ctrlport_probe2_f_impl::~ctrlport_probe2_f_impl() {} + +void ctrlport_probe2_f_impl::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{ + // make sure all inputs have noutput_items available + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) ninput_items_required[i] = d_len; - } +} - std::vector<float> - ctrlport_probe2_f_impl::get() - { - return buffered_get.get(); - } +std::vector<float> ctrlport_probe2_f_impl::get() { return buffered_get.get(); } - void - ctrlport_probe2_f_impl::set_length(int len) - { - gr::thread::scoped_lock guard(d_setlock); +void ctrlport_probe2_f_impl::set_length(int len) +{ + gr::thread::scoped_lock guard(d_setlock); - if(len > 8191) { + if (len > 8191) { GR_LOG_WARN(d_logger, boost::format("probe2_f: length %1% exceeds maximum" - " buffer size of 8191") % len); + " buffer size of 8191") % + len); len = 8191; - } - - d_len = len; - d_buffer.resize(d_len); - d_index = 0; } - int - ctrlport_probe2_f_impl::length() const - { - return (int)d_len; - } + d_len = len; + d_buffer.resize(d_len); + d_index = 0; +} - int - ctrlport_probe2_f_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float*)input_items[0]; +int ctrlport_probe2_f_impl::length() const { return (int)d_len; } - gr::thread::scoped_lock guard(d_setlock); +int ctrlport_probe2_f_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; - // copy samples to get buffer if we need samples - if(d_index < d_len) { + gr::thread::scoped_lock guard(d_setlock); + + // copy samples to get buffer if we need samples + if (d_index < d_len) { // copy smaller of remaining buffer space and num inputs to work() - int num_copy = std::min( (int)(d_len - d_index), noutput_items ); + int num_copy = std::min((int)(d_len - d_index), noutput_items); - memcpy(&d_buffer[d_index], in, num_copy*sizeof(float)); + memcpy(&d_buffer[d_index], in, num_copy * sizeof(float)); d_index += num_copy; - } + } - // notify the waiting get() if we fill up the buffer - if(d_index == d_len) { + // notify the waiting get() if we fill up the buffer + if (d_index == d_len) { buffered_get.offer_data(d_buffer); d_index = 0; - } - - return noutput_items; } - void - ctrlport_probe2_f_impl::setup_rpc() - { + return noutput_items; +} + +void ctrlport_probe2_f_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - int len = static_cast<int>(d_len); - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_f, std::vector<float> >( - alias(), d_id.c_str(), &ctrlport_probe2_f::get, - pmt::mp(-2.0f), pmt::mp(2.0f), pmt::mp(0.0f), -// pmt::make_f32vector(1,-2), -// pmt::make_f32vector(1,2), -// pmt::make_f32vector(1,0), - "volts", d_desc.c_str(), RPC_PRIVLVL_MIN, - d_disp_mask))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_f, int>( - alias(), "length", &ctrlport_probe2_f::length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "get vector length", RPC_PRIVLVL_MIN, DISPNULL))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_set<ctrlport_probe2_f, int>( - alias(), "length", &ctrlport_probe2_f::set_length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "set vector length", RPC_PRIVLVL_MIN, DISPNULL))); + int len = static_cast<int>(d_len); + d_rpc_vars.push_back( + rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_f, std::vector<float>>( + alias(), + d_id.c_str(), + &ctrlport_probe2_f::get, + pmt::mp(-2.0f), + pmt::mp(2.0f), + pmt::mp(0.0f), + // pmt::make_f32vector(1,-2), + // pmt::make_f32vector(1,2), + // pmt::make_f32vector(1,0), + "volts", + d_desc.c_str(), + RPC_PRIVLVL_MIN, + d_disp_mask))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<ctrlport_probe2_f, int>(alias(), + "length", + &ctrlport_probe2_f::length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "get vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_set<ctrlport_probe2_f, int>(alias(), + "length", + &ctrlport_probe2_f::set_length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "set vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/ctrlport_probe2_f_impl.h b/gr-blocks/lib/ctrlport_probe2_f_impl.h index 6aec0789f4..81c79e4d36 100644 --- a/gr-blocks/lib/ctrlport_probe2_f_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_f_impl.h @@ -28,40 +28,42 @@ #include <gnuradio/rpcbufferedget.h> namespace gr { - namespace blocks { +namespace blocks { - class ctrlport_probe2_f_impl : public ctrlport_probe2_f - { - private: - std::string d_id; - std::string d_desc; - size_t d_len; - unsigned int d_disp_mask; +class ctrlport_probe2_f_impl : public ctrlport_probe2_f +{ +private: + std::string d_id; + std::string d_desc; + size_t d_len; + unsigned int d_disp_mask; - size_t d_index; - std::vector<float> d_buffer; - rpcbufferedget< std::vector<float> > buffered_get; + size_t d_index; + std::vector<float> d_buffer; + rpcbufferedget<std::vector<float>> buffered_get; - public: - ctrlport_probe2_f_impl(const std::string &id, const std::string &desc, - int len, unsigned int disp_mask); - ~ctrlport_probe2_f_impl(); +public: + ctrlport_probe2_f_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask); + ~ctrlport_probe2_f_impl(); - void setup_rpc(); + void setup_rpc(); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - std::vector<float> get(); + std::vector<float> get(); - void set_length(int len); - int length() const; + void set_length(int len); + int length() const; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_F_IMPL_H */ diff --git a/gr-blocks/lib/ctrlport_probe2_i_impl.cc b/gr-blocks/lib/ctrlport_probe2_i_impl.cc index 7e17d8e8fe..d52f1762b0 100644 --- a/gr-blocks/lib/ctrlport_probe2_i_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_i_impl.cc @@ -28,123 +28,131 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - ctrlport_probe2_i::sptr - ctrlport_probe2_i::make(const std::string &id, - const std::string &desc, - int len, unsigned int disp_mask) - { - return gnuradio::get_initial_sptr - (new ctrlport_probe2_i_impl(id, desc, len, disp_mask)); - } - - ctrlport_probe2_i_impl::ctrlport_probe2_i_impl(const std::string &id, - const std::string &desc, - int len, unsigned int disp_mask) - : sync_block("probe2_i", - io_signature::make(1, 1, sizeof(int)), - io_signature::make(0, 0, 0)), - d_id(id), d_desc(desc), d_len(len), d_disp_mask(disp_mask) - { - set_length(len); - } - - ctrlport_probe2_i_impl::~ctrlport_probe2_i_impl() - { - } - - void - ctrlport_probe2_i_impl::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - // make sure all inputs have noutput_items available - unsigned ninputs = ninput_items_required.size(); - for(unsigned i = 0; i < ninputs; i++) +namespace blocks { + +ctrlport_probe2_i::sptr ctrlport_probe2_i::make(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask) +{ + return gnuradio::get_initial_sptr( + new ctrlport_probe2_i_impl(id, desc, len, disp_mask)); +} + +ctrlport_probe2_i_impl::ctrlport_probe2_i_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask) + : sync_block( + "probe2_i", io_signature::make(1, 1, sizeof(int)), io_signature::make(0, 0, 0)), + d_id(id), + d_desc(desc), + d_len(len), + d_disp_mask(disp_mask) +{ + set_length(len); +} + +ctrlport_probe2_i_impl::~ctrlport_probe2_i_impl() {} + +void ctrlport_probe2_i_impl::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{ + // make sure all inputs have noutput_items available + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) ninput_items_required[i] = d_len; - } +} - std::vector<int> - ctrlport_probe2_i_impl::get() - { - return buffered_get.get(); - } +std::vector<int> ctrlport_probe2_i_impl::get() { return buffered_get.get(); } - void - ctrlport_probe2_i_impl::set_length(int len) - { - gr::thread::scoped_lock guard(d_setlock); +void ctrlport_probe2_i_impl::set_length(int len) +{ + gr::thread::scoped_lock guard(d_setlock); - if(len > 8191) { + if (len > 8191) { GR_LOG_WARN(d_logger, boost::format("probe2_i: length %1% exceeds maximum" - " buffer size of 8191") % len); + " buffer size of 8191") % + len); len = 8191; - } - - d_len = len; - d_buffer.resize(d_len); - d_index = 0; } - int - ctrlport_probe2_i_impl::length() const - { - return (int)d_len; - } + d_len = len; + d_buffer.resize(d_len); + d_index = 0; +} - int - ctrlport_probe2_i_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const int *in = (const int*)input_items[0]; +int ctrlport_probe2_i_impl::length() const { return (int)d_len; } - gr::thread::scoped_lock guard(d_setlock); +int ctrlport_probe2_i_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const int* in = (const int*)input_items[0]; - // copy samples to get buffer if we need samples - if(d_index < d_len) { + gr::thread::scoped_lock guard(d_setlock); + + // copy samples to get buffer if we need samples + if (d_index < d_len) { // copy smaller of remaining buffer space and num inputs to work() - int num_copy = std::min( (int)(d_len - d_index), noutput_items ); + int num_copy = std::min((int)(d_len - d_index), noutput_items); - memcpy(&d_buffer[d_index], in, num_copy*sizeof(int)); + memcpy(&d_buffer[d_index], in, num_copy * sizeof(int)); d_index += num_copy; - } + } - // notify the waiting get() if we fill up the buffer - if(d_index == d_len) { + // notify the waiting get() if we fill up the buffer + if (d_index == d_len) { buffered_get.offer_data(d_buffer); d_index = 0; - } - - return noutput_items; } - void - ctrlport_probe2_i_impl::setup_rpc() - { + return noutput_items; +} + +void ctrlport_probe2_i_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - int len = static_cast<int>(d_len); - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_i, std::vector<int> >( - alias(), d_id.c_str(), &ctrlport_probe2_i::get, - pmt::mp(-32768), pmt::mp(32767), pmt::mp(0), - "volts", d_desc.c_str(), RPC_PRIVLVL_MIN, - d_disp_mask))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_i, int>( - alias(), "length", &ctrlport_probe2_i::length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "get vector length", RPC_PRIVLVL_MIN, DISPNULL))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_set<ctrlport_probe2_i, int>( - alias(), "length", &ctrlport_probe2_i::set_length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "set vector length", RPC_PRIVLVL_MIN, DISPNULL))); + int len = static_cast<int>(d_len); + d_rpc_vars.push_back( + rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_i, std::vector<int>>( + alias(), + d_id.c_str(), + &ctrlport_probe2_i::get, + pmt::mp(-32768), + pmt::mp(32767), + pmt::mp(0), + "volts", + d_desc.c_str(), + RPC_PRIVLVL_MIN, + d_disp_mask))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<ctrlport_probe2_i, int>(alias(), + "length", + &ctrlport_probe2_i::length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "get vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_set<ctrlport_probe2_i, int>(alias(), + "length", + &ctrlport_probe2_i::set_length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "set vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/ctrlport_probe2_i_impl.h b/gr-blocks/lib/ctrlport_probe2_i_impl.h index 2832af07ec..ed59801160 100644 --- a/gr-blocks/lib/ctrlport_probe2_i_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_i_impl.h @@ -28,40 +28,42 @@ #include <gnuradio/rpcbufferedget.h> namespace gr { - namespace blocks { +namespace blocks { - class ctrlport_probe2_i_impl : public ctrlport_probe2_i - { - private: - std::string d_id; - std::string d_desc; - size_t d_len; - unsigned int d_disp_mask; +class ctrlport_probe2_i_impl : public ctrlport_probe2_i +{ +private: + std::string d_id; + std::string d_desc; + size_t d_len; + unsigned int d_disp_mask; - size_t d_index; - std::vector<int> d_buffer; - rpcbufferedget< std::vector<int> > buffered_get; + size_t d_index; + std::vector<int> d_buffer; + rpcbufferedget<std::vector<int>> buffered_get; - public: - ctrlport_probe2_i_impl(const std::string &id, const std::string &desc, - int len, unsigned int disp_mask); - ~ctrlport_probe2_i_impl(); +public: + ctrlport_probe2_i_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask); + ~ctrlport_probe2_i_impl(); - void setup_rpc(); + void setup_rpc(); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - std::vector<int> get(); + std::vector<int> get(); - void set_length(int len); - int length() const; + void set_length(int len); + int length() const; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_I_IMPL_H */ diff --git a/gr-blocks/lib/ctrlport_probe2_s_impl.cc b/gr-blocks/lib/ctrlport_probe2_s_impl.cc index 9924243db0..45ae21a839 100644 --- a/gr-blocks/lib/ctrlport_probe2_s_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_s_impl.cc @@ -28,122 +28,131 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - ctrlport_probe2_s::sptr - ctrlport_probe2_s::make(const std::string &id, - const std::string &desc, - int len, unsigned disp_mask) - { - return gnuradio::get_initial_sptr - (new ctrlport_probe2_s_impl(id, desc, len, disp_mask)); - } - - ctrlport_probe2_s_impl::ctrlport_probe2_s_impl(const std::string &id, - const std::string &desc, - int len, unsigned disp_mask) +namespace blocks { + +ctrlport_probe2_s::sptr ctrlport_probe2_s::make(const std::string& id, + const std::string& desc, + int len, + unsigned disp_mask) +{ + return gnuradio::get_initial_sptr( + new ctrlport_probe2_s_impl(id, desc, len, disp_mask)); +} + +ctrlport_probe2_s_impl::ctrlport_probe2_s_impl(const std::string& id, + const std::string& desc, + int len, + unsigned disp_mask) : sync_block("probe2_s", io_signature::make(1, 1, sizeof(short)), io_signature::make(0, 0, 0)), - d_id(id), d_desc(desc), d_len(len), d_disp_mask(disp_mask) - { - set_length(len); - } - - ctrlport_probe2_s_impl::~ctrlport_probe2_s_impl() - { - } - - void - ctrlport_probe2_s_impl::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - // make sure all inputs have noutput_items available - unsigned ninputs = ninput_items_required.size(); - for(unsigned i = 0; i < ninputs; i++) + d_id(id), + d_desc(desc), + d_len(len), + d_disp_mask(disp_mask) +{ + set_length(len); +} + +ctrlport_probe2_s_impl::~ctrlport_probe2_s_impl() {} + +void ctrlport_probe2_s_impl::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{ + // make sure all inputs have noutput_items available + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) ninput_items_required[i] = d_len; - } +} - std::vector<short> - ctrlport_probe2_s_impl::get() - { - return buffered_get.get(); - } +std::vector<short> ctrlport_probe2_s_impl::get() { return buffered_get.get(); } - void - ctrlport_probe2_s_impl::set_length(int len) - { - gr::thread::scoped_lock guard(d_setlock); +void ctrlport_probe2_s_impl::set_length(int len) +{ + gr::thread::scoped_lock guard(d_setlock); - if(len > 8191) { + if (len > 8191) { GR_LOG_WARN(d_logger, boost::format("probe2_s: length %1% exceeds maximum" - " buffer size of 8191") % len); + " buffer size of 8191") % + len); len = 8191; - } - - d_len = len; - d_buffer.resize(d_len); - d_index = 0; } - int - ctrlport_probe2_s_impl::length() const - { - return (int)d_len; - } + d_len = len; + d_buffer.resize(d_len); + d_index = 0; +} - int - ctrlport_probe2_s_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; +int ctrlport_probe2_s_impl::length() const { return (int)d_len; } - gr::thread::scoped_lock guard(d_setlock); +int ctrlport_probe2_s_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; - // copy samples to get buffer if we need samples - if(d_index < d_len) { + gr::thread::scoped_lock guard(d_setlock); + + // copy samples to get buffer if we need samples + if (d_index < d_len) { // copy smaller of remaining buffer space and num inputs to work() - int num_copy = std::min( (int)(d_len - d_index), noutput_items ); + int num_copy = std::min((int)(d_len - d_index), noutput_items); - memcpy(&d_buffer[d_index], in, num_copy*sizeof(short)); + memcpy(&d_buffer[d_index], in, num_copy * sizeof(short)); d_index += num_copy; - } - - // notify the waiting get() if we fill up the buffer - if(d_index == d_len) { - buffered_get.offer_data(d_buffer); - } + } - return noutput_items; + // notify the waiting get() if we fill up the buffer + if (d_index == d_len) { + buffered_get.offer_data(d_buffer); } - void - ctrlport_probe2_s_impl::setup_rpc() - { + return noutput_items; +} + +void ctrlport_probe2_s_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - int len = static_cast<int>(d_len); - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_s, std::vector<short> >( - alias(), d_id.c_str(), &ctrlport_probe2_s::get, - pmt::mp(-32768), pmt::mp(32767), pmt::mp(0), - "volts", d_desc.c_str(), RPC_PRIVLVL_MIN, - d_disp_mask))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_s, int>( - alias(), "length", &ctrlport_probe2_s::length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "get vector length", RPC_PRIVLVL_MIN, DISPNULL))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_set<ctrlport_probe2_s, int>( - alias(), "length", &ctrlport_probe2_s::set_length, - pmt::mp(1), pmt::mp(10*len), pmt::mp(len), - "samples", "set vector length", RPC_PRIVLVL_MIN, DISPNULL))); + int len = static_cast<int>(d_len); + d_rpc_vars.push_back( + rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe2_s, std::vector<short>>( + alias(), + d_id.c_str(), + &ctrlport_probe2_s::get, + pmt::mp(-32768), + pmt::mp(32767), + pmt::mp(0), + "volts", + d_desc.c_str(), + RPC_PRIVLVL_MIN, + d_disp_mask))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<ctrlport_probe2_s, int>(alias(), + "length", + &ctrlport_probe2_s::length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "get vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_set<ctrlport_probe2_s, int>(alias(), + "length", + &ctrlport_probe2_s::set_length, + pmt::mp(1), + pmt::mp(10 * len), + pmt::mp(len), + "samples", + "set vector length", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/ctrlport_probe2_s_impl.h b/gr-blocks/lib/ctrlport_probe2_s_impl.h index a608a7898c..6b3677a4f3 100644 --- a/gr-blocks/lib/ctrlport_probe2_s_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_s_impl.h @@ -28,40 +28,42 @@ #include <gnuradio/rpcbufferedget.h> namespace gr { - namespace blocks { +namespace blocks { - class ctrlport_probe2_s_impl : public ctrlport_probe2_s - { - private: - std::string d_id; - std::string d_desc; - size_t d_len; - unsigned int d_disp_mask; +class ctrlport_probe2_s_impl : public ctrlport_probe2_s +{ +private: + std::string d_id; + std::string d_desc; + size_t d_len; + unsigned int d_disp_mask; - size_t d_index; - std::vector<short> d_buffer; - rpcbufferedget< std::vector<short> > buffered_get; + size_t d_index; + std::vector<short> d_buffer; + rpcbufferedget<std::vector<short>> buffered_get; - public: - ctrlport_probe2_s_impl(const std::string &id, const std::string &desc, - int len, unsigned int disp_mask); - ~ctrlport_probe2_s_impl(); +public: + ctrlport_probe2_s_impl(const std::string& id, + const std::string& desc, + int len, + unsigned int disp_mask); + ~ctrlport_probe2_s_impl(); - void setup_rpc(); + void setup_rpc(); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - std::vector<short> get(); + std::vector<short> get(); - void set_length(int len); - int length() const; + void set_length(int len); + int length() const; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_S_IMPL_H */ diff --git a/gr-blocks/lib/ctrlport_probe_c_impl.cc b/gr-blocks/lib/ctrlport_probe_c_impl.cc index 8141b2a2d1..a899917c98 100644 --- a/gr-blocks/lib/ctrlport_probe_c_impl.cc +++ b/gr-blocks/lib/ctrlport_probe_c_impl.cc @@ -28,74 +28,73 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - ctrlport_probe_c::sptr - ctrlport_probe_c::make(const std::string &id, - const std::string &desc) - { - return gnuradio::get_initial_sptr - (new ctrlport_probe_c_impl(id, desc)); - } +ctrlport_probe_c::sptr ctrlport_probe_c::make(const std::string& id, + const std::string& desc) +{ + return gnuradio::get_initial_sptr(new ctrlport_probe_c_impl(id, desc)); +} - ctrlport_probe_c_impl::ctrlport_probe_c_impl(const std::string &id, - const std::string &desc) - : sync_block("probe_c", - io_signature::make(1, 1, sizeof(gr_complex)), - io_signature::make(0, 0, 0)), - d_id(id), d_desc(desc), d_ptr(NULL), d_ptrLen(0) - { - } +ctrlport_probe_c_impl::ctrlport_probe_c_impl(const std::string& id, + const std::string& desc) + : sync_block("probe_c", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(0, 0, 0)), + d_id(id), + d_desc(desc), + d_ptr(NULL), + d_ptrLen(0) +{ +} - ctrlport_probe_c_impl::~ctrlport_probe_c_impl() - { - } +ctrlport_probe_c_impl::~ctrlport_probe_c_impl() {} - std::vector<gr_complex> - ctrlport_probe_c_impl::get() - { - if(d_ptr != NULL && d_ptrLen > 0) { +std::vector<gr_complex> ctrlport_probe_c_impl::get() +{ + if (d_ptr != NULL && d_ptrLen > 0) { ptrlock.lock(); - std::vector<gr_complex> vec(d_ptr, d_ptr+d_ptrLen); + std::vector<gr_complex> vec(d_ptr, d_ptr + d_ptrLen); ptrlock.unlock(); return vec; - } - else { + } else { std::vector<gr_complex> vec; return vec; - } } +} - int - ctrlport_probe_c_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex*)input_items[0]; +int ctrlport_probe_c_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; - // keep reference to symbols - ptrlock.lock(); - d_ptr = in; - d_ptrLen = noutput_items; - ptrlock.unlock(); + // keep reference to symbols + ptrlock.lock(); + d_ptr = in; + d_ptrLen = noutput_items; + ptrlock.unlock(); - return noutput_items; - } + return noutput_items; +} - void - ctrlport_probe_c_impl::setup_rpc() - { +void ctrlport_probe_c_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe_c, std::vector<std::complex<float> > >( - alias(), d_id.c_str(), &ctrlport_probe_c::get, - pmt::make_c32vector(0,-2), - pmt::make_c32vector(0,2), - pmt::make_c32vector(0,0), - "volts", d_desc.c_str(), RPC_PRIVLVL_MIN, - DISPXY | DISPOPTSCATTER))); + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<ctrlport_probe_c, std::vector<std::complex<float>>>( + alias(), + d_id.c_str(), + &ctrlport_probe_c::get, + pmt::make_c32vector(0, -2), + pmt::make_c32vector(0, 2), + pmt::make_c32vector(0, 0), + "volts", + d_desc.c_str(), + RPC_PRIVLVL_MIN, + DISPXY | DISPOPTSCATTER))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/ctrlport_probe_c_impl.h b/gr-blocks/lib/ctrlport_probe_c_impl.h index 59e9497a82..4170e24929 100644 --- a/gr-blocks/lib/ctrlport_probe_c_impl.h +++ b/gr-blocks/lib/ctrlport_probe_c_impl.h @@ -28,33 +28,32 @@ #include <boost/thread/shared_mutex.hpp> namespace gr { - namespace blocks { +namespace blocks { - class ctrlport_probe_c_impl : public ctrlport_probe_c - { - private: - boost::shared_mutex ptrlock; +class ctrlport_probe_c_impl : public ctrlport_probe_c +{ +private: + boost::shared_mutex ptrlock; - std::string d_id; - std::string d_desc; - const gr_complex* d_ptr; - size_t d_ptrLen; + std::string d_id; + std::string d_desc; + const gr_complex* d_ptr; + size_t d_ptrLen; - public: - ctrlport_probe_c_impl(const std::string &id, const std::string &desc); - ~ctrlport_probe_c_impl(); +public: + ctrlport_probe_c_impl(const std::string& id, const std::string& desc); + ~ctrlport_probe_c_impl(); - void setup_rpc(); + void setup_rpc(); - std::vector<gr_complex> get(); + std::vector<gr_complex> get(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_GR_CTRLPORT_PROBE_C_IMPL_H */ - diff --git a/gr-blocks/lib/deinterleave_impl.cc b/gr-blocks/lib/deinterleave_impl.cc index d7fdbb8f8f..e6f36dae9a 100644 --- a/gr-blocks/lib/deinterleave_impl.cc +++ b/gr-blocks/lib/deinterleave_impl.cc @@ -28,51 +28,50 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - deinterleave::sptr deinterleave::make(size_t itemsize, unsigned int blocksize) - { - return gnuradio::get_initial_sptr(new deinterleave_impl(itemsize, blocksize)); - } +deinterleave::sptr deinterleave::make(size_t itemsize, unsigned int blocksize) +{ + return gnuradio::get_initial_sptr(new deinterleave_impl(itemsize, blocksize)); +} - deinterleave_impl::deinterleave_impl(size_t itemsize, unsigned int blocksize) - : block("deinterleave", - io_signature::make (1, 1, itemsize), - io_signature::make (1, io_signature::IO_INFINITE, itemsize)), - d_itemsize(itemsize), d_blocksize(blocksize), d_current_output(0) - { - d_size_bytes = d_itemsize * d_blocksize; - set_output_multiple(blocksize); - } +deinterleave_impl::deinterleave_impl(size_t itemsize, unsigned int blocksize) + : block("deinterleave", + io_signature::make(1, 1, itemsize), + io_signature::make(1, io_signature::IO_INFINITE, itemsize)), + d_itemsize(itemsize), + d_blocksize(blocksize), + d_current_output(0) +{ + d_size_bytes = d_itemsize * d_blocksize; + set_output_multiple(blocksize); +} - void - deinterleave_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required) - { - ninput_items_required[0] = noutput_items * d_noutputs; - } +void deinterleave_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required) +{ + ninput_items_required[0] = noutput_items * d_noutputs; +} - bool - deinterleave_impl::check_topology(int ninputs, int noutputs) - { - set_relative_rate(1, (uint64_t)noutputs); - d_noutputs = noutputs; - return true; - } +bool deinterleave_impl::check_topology(int ninputs, int noutputs) +{ + set_relative_rate(1, (uint64_t)noutputs); + d_noutputs = noutputs; + return true; +} - int - deinterleave_impl::general_work(int noutput_items, +int deinterleave_impl::general_work(int noutput_items, gr_vector_int& ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *in = (const char*)input_items[0]; - char **out = (char**)&output_items[0]; + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* in = (const char*)input_items[0]; + char** out = (char**)&output_items[0]; - int count = 0, totalcount = noutput_items*d_noutputs; - unsigned int skip = 0; - unsigned int acc = 0; - while(count < totalcount) { - memcpy(out[d_current_output]+skip*d_size_bytes, in, d_size_bytes); + int count = 0, totalcount = noutput_items * d_noutputs; + unsigned int skip = 0; + unsigned int acc = 0; + while (count < totalcount) { + memcpy(out[d_current_output] + skip * d_size_bytes, in, d_size_bytes); in += d_size_bytes; produce(d_current_output, d_blocksize); d_current_output = (d_current_output + 1) % d_noutputs; @@ -82,18 +81,18 @@ namespace gr { // This is separate than d_current_output since we could be in // the middle of a loop when we exit. acc++; - if(acc >= d_noutputs) { - skip++; - acc = 0; + if (acc >= d_noutputs) { + skip++; + acc = 0; } // Keep track of our loop counter - count+=d_blocksize; - } - consume_each(totalcount); - return WORK_CALLED_PRODUCE; + count += d_blocksize; } + consume_each(totalcount); + return WORK_CALLED_PRODUCE; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/deinterleave_impl.h b/gr-blocks/lib/deinterleave_impl.h index 71a551a69c..951e66b526 100644 --- a/gr-blocks/lib/deinterleave_impl.h +++ b/gr-blocks/lib/deinterleave_impl.h @@ -26,31 +26,30 @@ #include <gnuradio/blocks/deinterleave.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API deinterleave_impl : public deinterleave - { +class BLOCKS_API deinterleave_impl : public deinterleave +{ - size_t d_itemsize; - unsigned int d_blocksize; - unsigned int d_current_output; - unsigned int d_noutputs; - unsigned int d_size_bytes; // block size in bytes + size_t d_itemsize; + unsigned int d_blocksize; + unsigned int d_current_output; + unsigned int d_noutputs; + unsigned int d_size_bytes; // block size in bytes - public: - deinterleave_impl(size_t itemsize, unsigned int blocksize); +public: + deinterleave_impl(size_t itemsize, unsigned int blocksize); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); - bool check_topology(int ninputs, int noutputs); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); + bool check_topology(int ninputs, int noutputs); - int general_work(int noutput_items, - gr_vector_int& ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_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 blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/delay_impl.cc b/gr-blocks/lib/delay_impl.cc index 0ebe124b09..d064ccf86d 100644 --- a/gr-blocks/lib/delay_impl.cc +++ b/gr-blocks/lib/delay_impl.cc @@ -29,117 +29,109 @@ #include <string.h> namespace gr { - namespace blocks { +namespace blocks { - delay::sptr - delay::make(size_t itemsize, int delay) - { - return gnuradio::get_initial_sptr - (new delay_impl(itemsize, delay)); - } +delay::sptr delay::make(size_t itemsize, int delay) +{ + return gnuradio::get_initial_sptr(new delay_impl(itemsize, delay)); +} - delay_impl::delay_impl(size_t itemsize, int delay) - : block("delay", - io_signature::make(1, -1, itemsize), - io_signature::make(1, -1, itemsize)), - d_itemsize(itemsize) - { - if(delay < 0) { +delay_impl::delay_impl(size_t itemsize, int delay) + : block("delay", + io_signature::make(1, -1, itemsize), + io_signature::make(1, -1, itemsize)), + d_itemsize(itemsize) +{ + if (delay < 0) { throw std::runtime_error("delay: Cannot initialize block with a delay < 0."); - } - set_dly(delay); - d_delta = 0; } + set_dly(delay); + d_delta = 0; +} - delay_impl::~delay_impl() - { - } +delay_impl::~delay_impl() {} - void - delay_impl::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - // make sure all inputs have noutput_items available - unsigned ninputs = ninput_items_required.size(); - for(unsigned i = 0; i < ninputs; i++) +void delay_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required) +{ + // make sure all inputs have noutput_items available + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) ninput_items_required[i] = noutput_items; - } +} - void - delay_impl::set_dly(int d) - { - // only set a new delta if there is a change in the delay; this - // protects from quickly-repeated calls to this function that - // would end with d_delta=0. - if(d != dly()) { +void delay_impl::set_dly(int d) +{ + // only set a new delta if there is a change in the delay; this + // protects from quickly-repeated calls to this function that + // would end with d_delta=0. + if (d != dly()) { gr::thread::scoped_lock l(d_mutex_delay); int old = dly(); - set_history(d+1); - declare_sample_delay(history()-1); + set_history(d + 1); + declare_sample_delay(history() - 1); d_delta += dly() - old; - } } +} - int - delay_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr::thread::scoped_lock l(d_mutex_delay); - assert(input_items.size() == output_items.size()); +int delay_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr::thread::scoped_lock l(d_mutex_delay); + assert(input_items.size() == output_items.size()); - const char *iptr; - char *optr; - int cons, ret; + const char* iptr; + char* optr; + int cons, ret; - // No change in delay; just memcpy ins to outs - if(d_delta == 0) { - for(size_t i = 0; i < input_items.size(); i++) { - iptr = (const char *)input_items[i]; - optr = (char *)output_items[i]; - std::memcpy(optr, iptr, noutput_items*d_itemsize); + // No change in delay; just memcpy ins to outs + if (d_delta == 0) { + for (size_t i = 0; i < input_items.size(); i++) { + iptr = (const char*)input_items[i]; + optr = (char*)output_items[i]; + std::memcpy(optr, iptr, noutput_items * d_itemsize); } cons = noutput_items; ret = noutput_items; - } + } - // Skip over d_delta items on the input - else if(d_delta < 0) { + // Skip over d_delta items on the input + else if (d_delta < 0) { int n_to_copy, n_adj; int delta = -d_delta; - n_to_copy = std::max(0, noutput_items-delta); + n_to_copy = std::max(0, noutput_items - delta); n_adj = std::min(delta, noutput_items); - for(size_t i = 0; i < input_items.size(); i++) { - iptr = (const char *) input_items[i]; - optr = (char *) output_items[i]; - std::memcpy(optr, iptr+delta*d_itemsize, n_to_copy*d_itemsize); + for (size_t i = 0; i < input_items.size(); i++) { + iptr = (const char*)input_items[i]; + optr = (char*)output_items[i]; + std::memcpy(optr, iptr + delta * d_itemsize, n_to_copy * d_itemsize); } cons = noutput_items; ret = n_to_copy; delta -= n_adj; d_delta = -delta; - } + } - //produce but not consume (inserts zeros) - else { // d_delta > 0 + // produce but not consume (inserts zeros) + else { // d_delta > 0 int n_from_input, n_padding; - n_from_input = std::max(0, noutput_items-d_delta); + n_from_input = std::max(0, noutput_items - d_delta); n_padding = std::min(d_delta, noutput_items); - for(size_t i = 0; i < input_items.size(); i++) { - iptr = (const char *) input_items[i]; - optr = (char *) output_items[i]; - std::memset(optr, 0, n_padding*d_itemsize); - std::memcpy(optr, iptr, n_from_input*d_itemsize); + for (size_t i = 0; i < input_items.size(); i++) { + iptr = (const char*)input_items[i]; + optr = (char*)output_items[i]; + std::memset(optr, 0, n_padding * d_itemsize); + std::memcpy(optr, iptr, n_from_input * d_itemsize); } cons = n_from_input; ret = noutput_items; d_delta -= n_padding; - } - - consume_each(cons); - return ret; } - } /* namespace blocks */ + consume_each(cons); + return ret; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/delay_impl.h b/gr-blocks/lib/delay_impl.h index ad07e6aa78..434fb03a15 100644 --- a/gr-blocks/lib/delay_impl.h +++ b/gr-blocks/lib/delay_impl.h @@ -27,32 +27,31 @@ #include <gnuradio/thread/thread.h> namespace gr { - namespace blocks { +namespace blocks { - class delay_impl : public delay - { - private: - void forecast(int noutput_items, - gr_vector_int &ninput_items_required); +class delay_impl : public delay +{ +private: + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - size_t d_itemsize; - int d_delta; - gr::thread::mutex d_mutex_delay; + size_t d_itemsize; + int d_delta; + gr::thread::mutex d_mutex_delay; - public: - delay_impl(size_t itemsize, int delay); - ~delay_impl(); +public: + delay_impl(size_t itemsize, int delay); + ~delay_impl(); - int dly() const { return history()-1; } - void set_dly(int d); + int dly() const { return history() - 1; } + void set_dly(int d); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int general_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 blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_DELAY_IMPL_H */ diff --git a/gr-blocks/lib/divide_impl.cc b/gr-blocks/lib/divide_impl.cc index 5fe08f95d1..2c7258dd32 100644 --- a/gr-blocks/lib/divide_impl.cc +++ b/gr-blocks/lib/divide_impl.cc @@ -30,101 +30,98 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - template <class T> - typename divide<T>::sptr divide<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new divide_impl<T> (vlen)); - } - - template <> - divide_impl<float>::divide_impl(size_t vlen) - : sync_block ("divide", - io_signature::make (2, -1, sizeof (float)*vlen), - io_signature::make (1, 1, sizeof (float)*vlen)), - d_vlen(vlen) - { +namespace blocks { + +template <class T> +typename divide<T>::sptr divide<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new divide_impl<T>(vlen)); +} + +template <> +divide_impl<float>::divide_impl(size_t vlen) + : sync_block("divide", + io_signature::make(2, -1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen) +{ +} + +template <> +int divide_impl<float>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float* optr = (float*)output_items[0]; + size_t ninputs = input_items.size(); + float* numerator = (float*)input_items[0]; + for (size_t inp = 1; inp < ninputs; ++inp) { + volk_32f_x2_divide_32f( + optr, numerator, (float*)input_items[inp], noutput_items * d_vlen); + numerator = optr; } - template <> - int - divide_impl<float>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float *optr = (float *) output_items[0]; - size_t ninputs = input_items.size (); - float *numerator = (float *) input_items[0]; - for(size_t inp = 1; inp < ninputs; ++inp) - { - volk_32f_x2_divide_32f(optr, numerator, (float*) input_items[inp], noutput_items * d_vlen); - numerator = optr; - } - - return noutput_items; - } + return noutput_items; +} - template <> - divide_impl<gr_complex>::divide_impl(size_t vlen) - : sync_block ("divide_cc", - io_signature::make (2, -1, sizeof (gr_complex)*vlen), - io_signature::make (1, 1, sizeof (gr_complex)*vlen)), - d_vlen(vlen) - { +template <> +divide_impl<gr_complex>::divide_impl(size_t vlen) + : sync_block("divide_cc", + io_signature::make(2, -1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(gr_complex) * vlen)), + d_vlen(vlen) +{ +} + +template <> +int divide_impl<gr_complex>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr_complex* optr = (gr_complex*)output_items[0]; + size_t ninputs = input_items.size(); + gr_complex* numerator = (gr_complex*)input_items[0]; + for (size_t inp = 1; inp < ninputs; ++inp) { + volk_32fc_x2_divide_32fc( + optr, numerator, (gr_complex*)input_items[inp], noutput_items * d_vlen); + numerator = optr; } - template <> - int - divide_impl<gr_complex>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr_complex *optr = (gr_complex *) output_items[0]; - size_t ninputs = input_items.size (); - gr_complex *numerator = (gr_complex *) input_items[0]; - for(size_t inp = 1; inp < ninputs; ++inp) - { - volk_32fc_x2_divide_32fc(optr, numerator, (gr_complex*) input_items[inp], noutput_items * d_vlen); - numerator = optr; - } - - return noutput_items; - } + return noutput_items; +} - template <class T> - divide_impl<T> ::divide_impl (size_t vlen) - : sync_block ("divide", - io_signature::make (1, -1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), +template <class T> +divide_impl<T>::divide_impl(size_t vlen) + : sync_block("divide", + io_signature::make(1, -1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), d_vlen(vlen) - { - } +{ +} - template <class T> - int - divide_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *) output_items[0]; +template <class T> +int divide_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; - int ninputs = input_items.size (); + int ninputs = input_items.size(); - for (size_t i = 0; i < noutput_items*d_vlen; i++){ - T acc = ((T *) input_items[0])[i]; - for (int j = 1; j < ninputs; j++) - acc /= ((T *) input_items[j])[i]; + for (size_t i = 0; i < noutput_items * d_vlen; i++) { + T acc = ((T*)input_items[0])[i]; + for (int j = 1; j < ninputs; j++) + acc /= ((T*)input_items[j])[i]; - *optr++ = (T) acc; - } - - return noutput_items; + *optr++ = (T)acc; } + return noutput_items; +} + template class divide<std::int16_t>; template class divide<std::int32_t>; - template class divide<float>; - template class divide<gr_complex>; - } /* namespace blocks */ +template class divide<float>; +template class divide<gr_complex>; +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/divide_impl.h b/gr-blocks/lib/divide_impl.h index cc9045c711..35f1bb0f2e 100644 --- a/gr-blocks/lib/divide_impl.h +++ b/gr-blocks/lib/divide_impl.h @@ -27,22 +27,22 @@ #include <gnuradio/blocks/divide.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API divide_impl : public divide<T> - { - size_t d_vlen; +template <class T> +class BLOCKS_API divide_impl : public divide<T> +{ + size_t d_vlen; - public: - divide_impl (size_t vlen); +public: + divide_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* DIVIDE_IMPL_H */ diff --git a/gr-blocks/lib/endian_swap_impl.cc b/gr-blocks/lib/endian_swap_impl.cc index 604e8b9ad8..e4db818b1e 100644 --- a/gr-blocks/lib/endian_swap_impl.cc +++ b/gr-blocks/lib/endian_swap_impl.cc @@ -29,59 +29,54 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - endian_swap::sptr - endian_swap::make(size_t item_size_bytes) - { - return gnuradio::get_initial_sptr - (new endian_swap_impl(item_size_bytes)); - } +endian_swap::sptr endian_swap::make(size_t item_size_bytes) +{ + return gnuradio::get_initial_sptr(new endian_swap_impl(item_size_bytes)); +} - endian_swap_impl::endian_swap_impl (size_t item_size_bytes) - : sync_block("endian_swap_impl", - io_signature::make(1, 1, item_size_bytes), - io_signature::make(1, 1, item_size_bytes)) - { - const int alignment_multiple = volk_get_alignment(); - set_alignment(std::max(1, alignment_multiple)); - } +endian_swap_impl::endian_swap_impl(size_t item_size_bytes) + : sync_block("endian_swap_impl", + io_signature::make(1, 1, item_size_bytes), + io_signature::make(1, 1, item_size_bytes)) +{ + const int alignment_multiple = volk_get_alignment(); + set_alignment(std::max(1, alignment_multiple)); +} - endian_swap_impl::~endian_swap_impl() - { - } +endian_swap_impl::~endian_swap_impl() {} - int - endian_swap_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *in = (const char*)input_items[0]; - char *out = (char*)output_items[0]; +int endian_swap_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* in = (const char*)input_items[0]; + char* out = (char*)output_items[0]; - int nbytes(output_signature()->sizeof_stream_item(0)); - switch(nbytes){ - case 1: - memcpy(out,in,noutput_items); + int nbytes(output_signature()->sizeof_stream_item(0)); + switch (nbytes) { + case 1: + memcpy(out, in, noutput_items); break; - case 2: - memcpy(out,in,2*noutput_items); - volk_16u_byteswap((uint16_t*)out,noutput_items); + case 2: + memcpy(out, in, 2 * noutput_items); + volk_16u_byteswap((uint16_t*)out, noutput_items); break; - case 4: - memcpy(out,in,4*noutput_items); - volk_32u_byteswap((uint32_t*)out,noutput_items); + case 4: + memcpy(out, in, 4 * noutput_items); + volk_32u_byteswap((uint32_t*)out, noutput_items); break; - case 8: - memcpy(out,in,8*noutput_items); - volk_64u_byteswap((uint64_t*)out,noutput_items); + case 8: + memcpy(out, in, 8 * noutput_items); + volk_64u_byteswap((uint64_t*)out, noutput_items); break; - default: + default: throw std::runtime_error("itemsize is not valid for endian_swap!"); - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/endian_swap_impl.h b/gr-blocks/lib/endian_swap_impl.h index de56c52725..975e178327 100644 --- a/gr-blocks/lib/endian_swap_impl.h +++ b/gr-blocks/lib/endian_swap_impl.h @@ -26,22 +26,21 @@ #include <gnuradio/blocks/endian_swap.h> namespace gr { - namespace blocks { +namespace blocks { - class endian_swap_impl : public endian_swap - { - private: +class endian_swap_impl : public endian_swap +{ +private: +public: + endian_swap_impl(size_t item_size_bytes); + ~endian_swap_impl(); - public: - endian_swap_impl(size_t item_size_bytes); - ~endian_swap_impl(); + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_ENDIAN_SWAP_IMPL_H */ diff --git a/gr-blocks/lib/exponentiate_const_cci_impl.cc b/gr-blocks/lib/exponentiate_const_cci_impl.cc index c46930febb..cd9a287ae5 100644 --- a/gr-blocks/lib/exponentiate_const_cci_impl.cc +++ b/gr-blocks/lib/exponentiate_const_cci_impl.cc @@ -29,74 +29,66 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - exponentiate_const_cci::sptr - exponentiate_const_cci::make(int exponent, size_t vlen) - { - return gnuradio::get_initial_sptr - (new exponentiate_const_cci_impl(exponent, vlen)); - } +exponentiate_const_cci::sptr exponentiate_const_cci::make(int exponent, size_t vlen) +{ + return gnuradio::get_initial_sptr(new exponentiate_const_cci_impl(exponent, vlen)); +} - /* - * The private constructor - */ - exponentiate_const_cci_impl::exponentiate_const_cci_impl(int exponent, size_t vlen) - : gr::sync_block("exponentiate_const_cci", - gr::io_signature::make(1, -1, sizeof(gr_complex)*vlen), - gr::io_signature::make(1, -1, sizeof(gr_complex)*vlen)), - d_exponent(exponent), - d_vlen(vlen) - { - const int alignment_multiple = volk_get_alignment()/sizeof(gr_complex); - set_alignment(std::max(1, alignment_multiple)); - } +/* + * The private constructor + */ +exponentiate_const_cci_impl::exponentiate_const_cci_impl(int exponent, size_t vlen) + : gr::sync_block("exponentiate_const_cci", + gr::io_signature::make(1, -1, sizeof(gr_complex) * vlen), + gr::io_signature::make(1, -1, sizeof(gr_complex) * vlen)), + d_exponent(exponent), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); +} - /* - * Our virtual destructor. - */ - exponentiate_const_cci_impl::~exponentiate_const_cci_impl() - { - } +/* + * Our virtual destructor. + */ +exponentiate_const_cci_impl::~exponentiate_const_cci_impl() {} - bool - exponentiate_const_cci_impl::check_topology(int ninputs, int noutputs) - { - return ninputs == noutputs; - } +bool exponentiate_const_cci_impl::check_topology(int ninputs, int noutputs) +{ + return ninputs == noutputs; +} - void - exponentiate_const_cci_impl::set_exponent(int exponent) { - gr::thread::scoped_lock guard(d_setlock); - d_exponent = exponent; - } +void exponentiate_const_cci_impl::set_exponent(int exponent) +{ + gr::thread::scoped_lock guard(d_setlock); + d_exponent = exponent; +} - int - exponentiate_const_cci_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr::thread::scoped_lock guard(d_setlock); +int exponentiate_const_cci_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr::thread::scoped_lock guard(d_setlock); - for(unsigned int i = 0; i < input_items.size(); i++) { - const gr_complex *in = (const gr_complex *) input_items[i]; - gr_complex *out = (gr_complex *) output_items[i]; - - if(d_exponent > 1) { - volk_32fc_x2_multiply_32fc(out, in, in, noutput_items*d_vlen); - for(int j = 2; j < d_exponent; j++) { - volk_32fc_x2_multiply_32fc(out, out, in, noutput_items*d_vlen); - } - } - else { - memcpy(out, in, sizeof(gr_complex)*noutput_items*d_vlen); - } - } + for (unsigned int i = 0; i < input_items.size(); i++) { + const gr_complex* in = (const gr_complex*)input_items[i]; + gr_complex* out = (gr_complex*)output_items[i]; - // Tell runtime system how many output items we produced. - return noutput_items; + if (d_exponent > 1) { + volk_32fc_x2_multiply_32fc(out, in, in, noutput_items * d_vlen); + for (int j = 2; j < d_exponent; j++) { + volk_32fc_x2_multiply_32fc(out, out, in, noutput_items * d_vlen); + } + } else { + memcpy(out, in, sizeof(gr_complex) * noutput_items * d_vlen); + } } - } /* namespace blocks */ -} /* namespace gr */ + // Tell runtime system how many output items we produced. + return noutput_items; +} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/exponentiate_const_cci_impl.h b/gr-blocks/lib/exponentiate_const_cci_impl.h index c89fe57646..35aea10e9d 100644 --- a/gr-blocks/lib/exponentiate_const_cci_impl.h +++ b/gr-blocks/lib/exponentiate_const_cci_impl.h @@ -26,28 +26,27 @@ #include <gnuradio/blocks/exponentiate_const_cci.h> namespace gr { - namespace blocks { - - class exponentiate_const_cci_impl : public exponentiate_const_cci - { - private: - int d_exponent; - int d_vlen; - - public: - exponentiate_const_cci_impl(int exponent, size_t vlen); - ~exponentiate_const_cci_impl(); - bool check_topology(int ninputs, int noutputs); - void set_exponent(int exponent); - - // Where all the action really happens - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } // namespace blocks +namespace blocks { + +class exponentiate_const_cci_impl : public exponentiate_const_cci +{ +private: + int d_exponent; + int d_vlen; + +public: + exponentiate_const_cci_impl(int exponent, size_t vlen); + ~exponentiate_const_cci_impl(); + bool check_topology(int ninputs, int noutputs); + void set_exponent(int exponent); + + // Where all the action really happens + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} // namespace blocks } // namespace gr #endif /* INCLUDED_BLOCKS_EXPONENTIATE_CONST_CCI_IMPL_H */ - diff --git a/gr-blocks/lib/file_descriptor_sink_impl.cc b/gr-blocks/lib/file_descriptor_sink_impl.cc index 975c60c63d..cb16129bcc 100644 --- a/gr-blocks/lib/file_descriptor_sink_impl.cc +++ b/gr-blocks/lib/file_descriptor_sink_impl.cc @@ -39,56 +39,50 @@ #endif namespace gr { - namespace blocks { +namespace blocks { - file_descriptor_sink::sptr - file_descriptor_sink::make(size_t itemsize, int fd) - { - return gnuradio::get_initial_sptr - (new file_descriptor_sink_impl(itemsize, fd)); - } +file_descriptor_sink::sptr file_descriptor_sink::make(size_t itemsize, int fd) +{ + return gnuradio::get_initial_sptr(new file_descriptor_sink_impl(itemsize, fd)); +} - file_descriptor_sink_impl::file_descriptor_sink_impl(size_t itemsize, int fd) - : sync_block("file_descriptor_sink", - io_signature::make(1, 1, itemsize), - io_signature::make(0, 0, 0)), - d_itemsize(itemsize), d_fd(fd) - { - } +file_descriptor_sink_impl::file_descriptor_sink_impl(size_t itemsize, int fd) + : sync_block("file_descriptor_sink", + io_signature::make(1, 1, itemsize), + io_signature::make(0, 0, 0)), + d_itemsize(itemsize), + d_fd(fd) +{ +} - file_descriptor_sink_impl::~file_descriptor_sink_impl() - { - close(d_fd); - } +file_descriptor_sink_impl::~file_descriptor_sink_impl() { close(d_fd); } - int - file_descriptor_sink_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - char *inbuf = (char*)input_items[0]; - unsigned long byte_size = noutput_items * d_itemsize; +int file_descriptor_sink_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + char* inbuf = (char*)input_items[0]; + unsigned long byte_size = noutput_items * d_itemsize; - while(byte_size > 0) { + while (byte_size > 0) { ssize_t r; r = write(d_fd, inbuf, byte_size); - if(r == -1) { - if(errno == EINTR) - continue; - else { - perror("file_descriptor_sink"); - return -1; // indicate we're done - } + if (r == -1) { + if (errno == EINTR) + continue; + else { + perror("file_descriptor_sink"); + return -1; // indicate we're done + } + } else { + byte_size -= r; + inbuf += r; } - else { - byte_size -= r; - inbuf += r; - } - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/file_descriptor_sink_impl.h b/gr-blocks/lib/file_descriptor_sink_impl.h index 0b455879a4..16df63333e 100644 --- a/gr-blocks/lib/file_descriptor_sink_impl.h +++ b/gr-blocks/lib/file_descriptor_sink_impl.h @@ -26,24 +26,24 @@ #include <gnuradio/blocks/file_descriptor_sink.h> namespace gr { - namespace blocks { +namespace blocks { - class file_descriptor_sink_impl : public file_descriptor_sink - { - private: - size_t d_itemsize; - int d_fd; +class file_descriptor_sink_impl : public file_descriptor_sink +{ +private: + size_t d_itemsize; + int d_fd; - public: - file_descriptor_sink_impl(size_t itemsize, int fd); - ~file_descriptor_sink_impl(); +public: + file_descriptor_sink_impl(size_t itemsize, int fd); + ~file_descriptor_sink_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_FILE_DESCRIPTOR_SINK_IMPL_H */ diff --git a/gr-blocks/lib/file_descriptor_source_impl.cc b/gr-blocks/lib/file_descriptor_source_impl.cc index 575681ba9b..de47bb85a3 100644 --- a/gr-blocks/lib/file_descriptor_source_impl.cc +++ b/gr-blocks/lib/file_descriptor_source_impl.cc @@ -40,117 +40,114 @@ #endif namespace gr { - namespace blocks { - - file_descriptor_source::sptr - file_descriptor_source::make(size_t itemsize, int fd, bool repeat) - { - return gnuradio::get_initial_sptr - (new file_descriptor_source_impl(itemsize, fd, repeat)); - } - - file_descriptor_source_impl::file_descriptor_source_impl(size_t itemsize, - int fd, - bool repeat) - : sync_block("file_descriptor_source", - io_signature::make(0, 0, 0), - io_signature::make(1, 1, itemsize)), - d_itemsize(itemsize), d_fd(fd), d_repeat(repeat), - d_residue(new unsigned char[itemsize]), d_residue_len (0) - { - } - - file_descriptor_source_impl::~file_descriptor_source_impl() - { - close(d_fd); - delete [] d_residue; - } - - int - file_descriptor_source_impl::read_items(char *buf, int nitems) - { - assert(nitems > 0); - assert(d_residue_len < d_itemsize); - - int nbytes_read = 0; - - if(d_residue_len > 0) { +namespace blocks { + +file_descriptor_source::sptr +file_descriptor_source::make(size_t itemsize, int fd, bool repeat) +{ + return gnuradio::get_initial_sptr( + new file_descriptor_source_impl(itemsize, fd, repeat)); +} + +file_descriptor_source_impl::file_descriptor_source_impl(size_t itemsize, + int fd, + bool repeat) + : sync_block("file_descriptor_source", + io_signature::make(0, 0, 0), + io_signature::make(1, 1, itemsize)), + d_itemsize(itemsize), + d_fd(fd), + d_repeat(repeat), + d_residue(new unsigned char[itemsize]), + d_residue_len(0) +{ +} + +file_descriptor_source_impl::~file_descriptor_source_impl() +{ + close(d_fd); + delete[] d_residue; +} + +int file_descriptor_source_impl::read_items(char* buf, int nitems) +{ + assert(nitems > 0); + assert(d_residue_len < d_itemsize); + + int nbytes_read = 0; + + if (d_residue_len > 0) { memcpy(buf, d_residue, d_residue_len); nbytes_read = d_residue_len; d_residue_len = 0; - } + } - int r = read(d_fd, buf + nbytes_read, - nitems * d_itemsize - nbytes_read); - if(r <= 0) { + int r = read(d_fd, buf + nbytes_read, nitems * d_itemsize - nbytes_read); + if (r <= 0) { handle_residue(buf, nbytes_read); return r; - } + } - r = handle_residue(buf, r + nbytes_read); + r = handle_residue(buf, r + nbytes_read); - if(r == 0) // block until we get something + if (r == 0) // block until we get something return read_items(buf, nitems); - return r; - } + return r; +} - int - file_descriptor_source_impl::handle_residue(char *buf, int nbytes_read) - { - assert(nbytes_read >= 0); - int nitems_read = nbytes_read / d_itemsize; - d_residue_len = nbytes_read % d_itemsize; - if(d_residue_len > 0) { +int file_descriptor_source_impl::handle_residue(char* buf, int nbytes_read) +{ + assert(nbytes_read >= 0); + int nitems_read = nbytes_read / d_itemsize; + d_residue_len = nbytes_read % d_itemsize; + if (d_residue_len > 0) { // fprintf (stderr, "handle_residue: %d\n", d_residue_len); memcpy(d_residue, buf + nbytes_read - d_residue_len, d_residue_len); - } - return nitems_read; } + return nitems_read; +} - int - file_descriptor_source_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - assert(noutput_items > 0); +int file_descriptor_source_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + assert(noutput_items > 0); - char *o = (char*)output_items[0]; - int nread = 0; + char* o = (char*)output_items[0]; + int nread = 0; - while(1) { + while (1) { int r = read_items(o, noutput_items - nread); - if(r == -1) { - if(errno == EINTR) - continue; - else { - perror("file_descriptor_source[read]"); - return -1; - } - } - else if(r == 0) { // end of file - if(!d_repeat) - break; - else { - flush_residue(); - if(lseek(d_fd, 0, SEEK_SET) == -1) { - perror("file_descriptor_source[lseek]"); - return -1; + if (r == -1) { + if (errno == EINTR) + continue; + else { + perror("file_descriptor_source[read]"); + return -1; } - } - } - else { - o += r * d_itemsize; - nread += r; - break; + } else if (r == 0) { // end of file + if (!d_repeat) + break; + else { + flush_residue(); + if (lseek(d_fd, 0, SEEK_SET) == -1) { + perror("file_descriptor_source[lseek]"); + return -1; + } + } + } else { + o += r * d_itemsize; + nread += r; + break; } - } + } - if(nread == 0) // EOF + if (nread == 0) // EOF return -1; - return nread; - } + return nread; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/file_descriptor_source_impl.h b/gr-blocks/lib/file_descriptor_source_impl.h index 6bdfa03614..e0f49bfd9d 100644 --- a/gr-blocks/lib/file_descriptor_source_impl.h +++ b/gr-blocks/lib/file_descriptor_source_impl.h @@ -26,33 +26,33 @@ #include <gnuradio/blocks/file_descriptor_source.h> namespace gr { - namespace blocks { +namespace blocks { - class file_descriptor_source_impl : public file_descriptor_source - { - private: - size_t d_itemsize; - int d_fd; - bool d_repeat; +class file_descriptor_source_impl : public file_descriptor_source +{ +private: + size_t d_itemsize; + int d_fd; + bool d_repeat; - unsigned char *d_residue; - unsigned long d_residue_len; + unsigned char* d_residue; + unsigned long d_residue_len; - protected: - int read_items(char *buf, int nitems); - int handle_residue(char *buf, int nbytes_read); - void flush_residue() { d_residue_len = 0; } +protected: + int read_items(char* buf, int nitems); + int handle_residue(char* buf, int nbytes_read); + void flush_residue() { d_residue_len = 0; } - public: - file_descriptor_source_impl(size_t itemsize, int fd, bool repeat); - ~file_descriptor_source_impl(); +public: + file_descriptor_source_impl(size_t itemsize, int fd, bool repeat); + ~file_descriptor_source_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_FILE_DESCRIPTOR_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/file_meta_sink_impl.cc b/gr-blocks/lib/file_meta_sink_impl.cc index fed28c7352..342ee4573c 100644 --- a/gr-blocks/lib/file_meta_sink_impl.cc +++ b/gr-blocks/lib/file_meta_sink_impl.cc @@ -38,433 +38,420 @@ #include <io.h> #endif #ifdef O_BINARY -#define OUR_O_BINARY O_BINARY +#define OUR_O_BINARY O_BINARY #else -#define OUR_O_BINARY 0 +#define OUR_O_BINARY 0 #endif // should be handled via configure #ifdef O_LARGEFILE -#define OUR_O_LARGEFILE O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE #else -#define OUR_O_LARGEFILE 0 +#define OUR_O_LARGEFILE 0 #endif namespace gr { - namespace blocks { - - - file_meta_sink::sptr - file_meta_sink::make(size_t itemsize, - const std::string &filename, - double samp_rate, - double relative_rate, - gr_file_types type, - bool complex, - size_t max_segment_size, - pmt::pmt_t extra_dict, - bool detached_header) - { - return gnuradio::get_initial_sptr - (new file_meta_sink_impl(itemsize, filename, - samp_rate, relative_rate, - type, complex, - max_segment_size, - extra_dict, - detached_header)); +namespace blocks { + + +file_meta_sink::sptr file_meta_sink::make(size_t itemsize, + const std::string& filename, + double samp_rate, + double relative_rate, + gr_file_types type, + bool complex, + size_t max_segment_size, + pmt::pmt_t extra_dict, + bool detached_header) +{ + return gnuradio::get_initial_sptr(new file_meta_sink_impl(itemsize, + filename, + samp_rate, + relative_rate, + type, + complex, + max_segment_size, + extra_dict, + detached_header)); +} + +file_meta_sink_impl::file_meta_sink_impl(size_t itemsize, + const std::string& filename, + double samp_rate, + double relative_rate, + gr_file_types type, + bool complex, + size_t max_segment_size, + pmt::pmt_t extra_dict, + bool detached_header) + : sync_block("file_meta_sink", + io_signature::make(1, 1, itemsize), + io_signature::make(0, 0, 0)), + d_itemsize(itemsize), + d_samp_rate(samp_rate), + d_relative_rate(relative_rate), + d_max_seg_size(max_segment_size), + d_total_seg_size(0), + d_updated(false), + d_unbuffered(false) +{ + d_fp = 0; + d_new_fp = 0; + d_hdr_fp = 0; + d_new_hdr_fp = 0; + + if (detached_header == true) + d_state = STATE_DETACHED; + else + d_state = STATE_INLINE; + + if (!open(filename)) + throw std::runtime_error("file_meta_sink: can't open file\n"); + + pmt::pmt_t timestamp = pmt::make_tuple(pmt::from_uint64(0), pmt::from_double(0)); + + // handle extra dictionary + d_extra = pmt::make_dict(); + pmt::pmt_t keys = pmt::dict_keys(extra_dict); + pmt::pmt_t vals = pmt::dict_values(extra_dict); + size_t nitems = pmt::length(keys); + for (size_t i = 0; i < nitems; i++) { + d_extra = pmt::dict_add(d_extra, pmt::nth(i, keys), pmt::nth(i, vals)); } - file_meta_sink_impl::file_meta_sink_impl(size_t itemsize, - const std::string &filename, - double samp_rate, double relative_rate, - gr_file_types type, bool complex, - size_t max_segment_size, - pmt::pmt_t extra_dict, - bool detached_header) - : sync_block("file_meta_sink", - io_signature::make(1, 1, itemsize), - io_signature::make(0, 0, 0)), - d_itemsize(itemsize), - d_samp_rate(samp_rate), d_relative_rate(relative_rate), - d_max_seg_size(max_segment_size), d_total_seg_size(0), - d_updated(false), d_unbuffered(false) - { - d_fp = 0; - d_new_fp = 0; - d_hdr_fp = 0; - d_new_hdr_fp = 0; - - if(detached_header == true) - d_state = STATE_DETACHED; - else - d_state = STATE_INLINE; - - if(!open(filename)) - throw std::runtime_error("file_meta_sink: can't open file\n"); - - pmt::pmt_t timestamp = pmt::make_tuple(pmt::from_uint64(0), - pmt::from_double(0)); - - // handle extra dictionary - d_extra = pmt::make_dict(); - pmt::pmt_t keys = pmt::dict_keys(extra_dict); - pmt::pmt_t vals = pmt::dict_values(extra_dict); - size_t nitems = pmt::length(keys); - for(size_t i = 0; i < nitems; i++) { - d_extra = pmt::dict_add(d_extra, - pmt::nth(i, keys), - pmt::nth(i, vals)); - } - - d_extra_size = pmt::serialize_str(d_extra).size(); - - d_header = pmt::make_dict(); - d_header = pmt::dict_add(d_header, pmt::mp("version"), pmt::mp(METADATA_VERSION)); - d_header = pmt::dict_add(d_header, pmt::mp("rx_rate"), pmt::mp(samp_rate)); - d_header = pmt::dict_add(d_header, pmt::mp("rx_time"), timestamp); - d_header = pmt::dict_add(d_header, pmt::mp("size"), pmt::from_long(d_itemsize)); - d_header = pmt::dict_add(d_header, pmt::mp("type"), pmt::from_long(type)); - d_header = pmt::dict_add(d_header, pmt::mp("cplx"), complex ? pmt::PMT_T : pmt::PMT_F); - d_header = pmt::dict_add(d_header, pmt::mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE+d_extra_size)); - d_header = pmt::dict_add(d_header, mp("bytes"), pmt::from_uint64(0)); - - do_update(); - - if(d_state == STATE_DETACHED) - write_header(d_hdr_fp, d_header, d_extra); - else - write_header(d_fp, d_header, d_extra); + d_extra_size = pmt::serialize_str(d_extra).size(); + + d_header = pmt::make_dict(); + d_header = pmt::dict_add(d_header, pmt::mp("version"), pmt::mp(METADATA_VERSION)); + d_header = pmt::dict_add(d_header, pmt::mp("rx_rate"), pmt::mp(samp_rate)); + d_header = pmt::dict_add(d_header, pmt::mp("rx_time"), timestamp); + d_header = pmt::dict_add(d_header, pmt::mp("size"), pmt::from_long(d_itemsize)); + d_header = pmt::dict_add(d_header, pmt::mp("type"), pmt::from_long(type)); + d_header = + pmt::dict_add(d_header, pmt::mp("cplx"), complex ? pmt::PMT_T : pmt::PMT_F); + d_header = pmt::dict_add( + d_header, pmt::mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE + d_extra_size)); + d_header = pmt::dict_add(d_header, mp("bytes"), pmt::from_uint64(0)); + + do_update(); + + if (d_state == STATE_DETACHED) + write_header(d_hdr_fp, d_header, d_extra); + else + write_header(d_fp, d_header, d_extra); +} + +file_meta_sink_impl::~file_meta_sink_impl() { close(); } + +bool file_meta_sink_impl::open(const std::string& filename) +{ + bool ret = true; + if (d_state == STATE_DETACHED) { + std::string s = filename + ".hdr"; + ret = _open(&d_new_hdr_fp, s.c_str()); } - file_meta_sink_impl::~file_meta_sink_impl() - { - close(); + ret = ret && _open(&d_new_fp, filename.c_str()); + d_updated = true; + return ret; +} +bool file_meta_sink_impl::_open(FILE** fp, const char* filename) +{ + gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this function - } + bool ret = true; + int fd; - bool - file_meta_sink_impl::open(const std::string &filename) - { - bool ret = true; - if(d_state == STATE_DETACHED) { - std::string s = filename + ".hdr"; - ret = _open(&d_new_hdr_fp, s.c_str()); - } - - ret = ret && _open(&d_new_fp, filename.c_str()); - d_updated = true; - return ret; + if ((fd = ::open(filename, + O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE | OUR_O_BINARY, + 0664)) < 0) { + perror(filename); + return false; } - bool - file_meta_sink_impl::_open(FILE **fp, const char *filename) - { - gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this function + if (*fp) { // if we've already got a new one open, close it + fclose(*fp); + fp = 0; + } - bool ret = true; - int fd; + if ((*fp = fdopen(fd, "wb")) == NULL) { + perror(filename); + ::close(fd); // don't leak file descriptor if fdopen fails. + } - if((fd = ::open(filename, - O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, - 0664)) < 0){ - perror(filename); - return false; - } + ret = fp != 0; - if(*fp) { // if we've already got a new one open, close it - fclose(*fp); - fp = 0; - } + return ret; +} - if((*fp = fdopen(fd, "wb")) == NULL) { - perror(filename); - ::close(fd); // don't leak file descriptor if fdopen fails. - } +void file_meta_sink_impl::close() +{ + gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this function + update_last_header(); - ret = fp != 0; + if (d_state == STATE_DETACHED) { + if (d_new_hdr_fp) { + fclose(d_new_hdr_fp); + d_new_hdr_fp = 0; + } + } - return ret; + if (d_new_fp) { + fclose(d_new_fp); + d_new_fp = 0; } + d_updated = true; - void - file_meta_sink_impl::close() - { - gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this function - update_last_header(); - - if(d_state == STATE_DETACHED) { - if(d_new_hdr_fp) { - fclose(d_new_hdr_fp); - d_new_hdr_fp = 0; - } - } - - if(d_new_fp) { - fclose(d_new_fp); - d_new_fp = 0; - } - d_updated = true; - - if (d_fp) { + if (d_fp) { fclose(d_fp); d_fp = 0; - } + } - if (d_state == STATE_DETACHED) { + if (d_state == STATE_DETACHED) { if (d_hdr_fp) { - fclose(d_hdr_fp); - d_hdr_fp = 0; + fclose(d_hdr_fp); + d_hdr_fp = 0; } - } } +} + +void file_meta_sink_impl::do_update() +{ + if (d_updated) { + gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this block + if (d_state == STATE_DETACHED) { + if (d_hdr_fp) + fclose(d_hdr_fp); + d_hdr_fp = d_new_hdr_fp; // install new file pointer + d_new_hdr_fp = 0; + } - void - file_meta_sink_impl::do_update() - { - if(d_updated) { - gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this block - if(d_state == STATE_DETACHED) { - if(d_hdr_fp) - fclose(d_hdr_fp); - d_hdr_fp = d_new_hdr_fp; // install new file pointer - d_new_hdr_fp = 0; - } - - if(d_fp) - fclose(d_fp); - d_fp = d_new_fp; // install new file pointer - d_new_fp = 0; - - d_updated = false; - } - } + if (d_fp) + fclose(d_fp); + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; - void - file_meta_sink_impl::write_header(FILE *fp, pmt::pmt_t header, pmt::pmt_t extra) - { - std::string header_str = pmt::serialize_str(header); - std::string extra_str = pmt::serialize_str(extra); - - if((header_str.size() != METADATA_HEADER_SIZE) && (extra_str.size() != d_extra_size)) - throw std::runtime_error("file_meta_sink: header or extra_dict is wrong size.\n"); - - size_t nwritten = 0; - while(nwritten < header_str.size()) { - std::string sub = header_str.substr(nwritten); - int count = fwrite(sub.c_str(), sizeof(char), sub.size(), fp); - nwritten += count; - if((count == 0) && (ferror(fp))) { - fclose(fp); - throw std::runtime_error("file_meta_sink: error writing header to file.\n"); - } - } - - nwritten = 0; - while(nwritten < extra_str.size()) { - std::string sub = extra_str.substr(nwritten); - int count = fwrite(sub.c_str(), sizeof(char), sub.size(), fp); - nwritten += count; - if((count == 0) && (ferror(fp))) { - fclose(fp); - throw std::runtime_error("file_meta_sink: error writing extra to file.\n"); - } - } - - fflush(fp); + d_updated = false; } - - void - file_meta_sink_impl::update_header(pmt::pmt_t key, pmt::pmt_t value) - { - // Special handling caveat to transform rate from radio source into - // the rate at this sink. - if(pmt::eq(key, mp("rx_rate"))) { - d_samp_rate = pmt::to_double(value); - value = pmt::from_double(d_samp_rate*d_relative_rate); - } - - // If the tag is not part of the standard header, we put it into the - // extra data, which either updates the current dictionary or adds a - // new item. - if(pmt::dict_has_key(d_header, key)) { - d_header = pmt::dict_add(d_header, key, value); - } - else { - d_extra = pmt::dict_add(d_extra, key, value); - d_extra_size = pmt::serialize_str(d_extra).size(); - } +} + +void file_meta_sink_impl::write_header(FILE* fp, pmt::pmt_t header, pmt::pmt_t extra) +{ + std::string header_str = pmt::serialize_str(header); + std::string extra_str = pmt::serialize_str(extra); + + if ((header_str.size() != METADATA_HEADER_SIZE) && (extra_str.size() != d_extra_size)) + throw std::runtime_error("file_meta_sink: header or extra_dict is wrong size.\n"); + + size_t nwritten = 0; + while (nwritten < header_str.size()) { + std::string sub = header_str.substr(nwritten); + int count = fwrite(sub.c_str(), sizeof(char), sub.size(), fp); + nwritten += count; + if ((count == 0) && (ferror(fp))) { + fclose(fp); + throw std::runtime_error("file_meta_sink: error writing header to file.\n"); + } } - void - file_meta_sink_impl::update_last_header() - { - if(d_state == STATE_DETACHED) { - if (d_hdr_fp) update_last_header_detached(); - } else { - if(d_fp) update_last_header_inline(); - } + nwritten = 0; + while (nwritten < extra_str.size()) { + std::string sub = extra_str.substr(nwritten); + int count = fwrite(sub.c_str(), sizeof(char), sub.size(), fp); + nwritten += count; + if ((count == 0) && (ferror(fp))) { + fclose(fp); + throw std::runtime_error("file_meta_sink: error writing extra to file.\n"); + } } - void - file_meta_sink_impl::update_last_header_inline() - { - // Update the last header info with the number of samples this - // block represents. - - size_t hdrlen = pmt::to_uint64(pmt::dict_ref(d_header, mp("strt"), pmt::PMT_NIL)); - size_t seg_size = d_itemsize*d_total_seg_size; - pmt::pmt_t s = pmt::from_uint64(seg_size); - update_header(mp("bytes"), s); - update_header(mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE+d_extra_size)); - fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); - write_header(d_fp, d_header, d_extra); - fseek(d_fp, seg_size, SEEK_CUR); - } + fflush(fp); +} - void - file_meta_sink_impl::update_last_header_detached() - { - // Update the last header info with the number of samples this - // block represents. - size_t hdrlen = pmt::to_uint64(pmt::dict_ref(d_header, mp("strt"), pmt::PMT_NIL)); - size_t seg_size = d_itemsize*d_total_seg_size; - pmt::pmt_t s = pmt::from_uint64(seg_size); - update_header(mp("bytes"), s); - update_header(mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE+d_extra_size)); - fseek(d_hdr_fp, -hdrlen, SEEK_CUR); - write_header(d_hdr_fp, d_header, d_extra); +void file_meta_sink_impl::update_header(pmt::pmt_t key, pmt::pmt_t value) +{ + // Special handling caveat to transform rate from radio source into + // the rate at this sink. + if (pmt::eq(key, mp("rx_rate"))) { + d_samp_rate = pmt::to_double(value); + value = pmt::from_double(d_samp_rate * d_relative_rate); } - void - file_meta_sink_impl::write_and_update() - { - // New header, so set current size of chunk to 0 and start of chunk - // based on current index + header size. - //uint64_t loc = get_last_header_loc(); - pmt::pmt_t s = pmt::from_uint64(0); - update_header(mp("bytes"), s); - - // If we have multiple tags on the same offset, this makes - // sure we just overwrite the same header each time instead - // of creating a new header per tag. - s = pmt::from_uint64(METADATA_HEADER_SIZE + d_extra_size); - update_header(mp("strt"), s); - - if(d_state == STATE_DETACHED) - write_header(d_hdr_fp, d_header, d_extra); - else - write_header(d_fp, d_header, d_extra); + // If the tag is not part of the standard header, we put it into the + // extra data, which either updates the current dictionary or adds a + // new item. + if (pmt::dict_has_key(d_header, key)) { + d_header = pmt::dict_add(d_header, key, value); + } else { + d_extra = pmt::dict_add(d_extra, key, value); + d_extra_size = pmt::serialize_str(d_extra).size(); } +} + +void file_meta_sink_impl::update_last_header() +{ + if (d_state == STATE_DETACHED) { + if (d_hdr_fp) + update_last_header_detached(); + } else { + if (d_fp) + update_last_header_inline(); + } +} + +void file_meta_sink_impl::update_last_header_inline() +{ + // Update the last header info with the number of samples this + // block represents. + + size_t hdrlen = pmt::to_uint64(pmt::dict_ref(d_header, mp("strt"), pmt::PMT_NIL)); + size_t seg_size = d_itemsize * d_total_seg_size; + pmt::pmt_t s = pmt::from_uint64(seg_size); + update_header(mp("bytes"), s); + update_header(mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE + d_extra_size)); + fseek(d_fp, -seg_size - hdrlen, SEEK_CUR); + write_header(d_fp, d_header, d_extra); + fseek(d_fp, seg_size, SEEK_CUR); +} + +void file_meta_sink_impl::update_last_header_detached() +{ + // Update the last header info with the number of samples this + // block represents. + size_t hdrlen = pmt::to_uint64(pmt::dict_ref(d_header, mp("strt"), pmt::PMT_NIL)); + size_t seg_size = d_itemsize * d_total_seg_size; + pmt::pmt_t s = pmt::from_uint64(seg_size); + update_header(mp("bytes"), s); + update_header(mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE + d_extra_size)); + fseek(d_hdr_fp, -hdrlen, SEEK_CUR); + write_header(d_hdr_fp, d_header, d_extra); +} + +void file_meta_sink_impl::write_and_update() +{ + // New header, so set current size of chunk to 0 and start of chunk + // based on current index + header size. + // uint64_t loc = get_last_header_loc(); + pmt::pmt_t s = pmt::from_uint64(0); + update_header(mp("bytes"), s); + + // If we have multiple tags on the same offset, this makes + // sure we just overwrite the same header each time instead + // of creating a new header per tag. + s = pmt::from_uint64(METADATA_HEADER_SIZE + d_extra_size); + update_header(mp("strt"), s); + + if (d_state == STATE_DETACHED) + write_header(d_hdr_fp, d_header, d_extra); + else + write_header(d_fp, d_header, d_extra); +} + +void file_meta_sink_impl::update_rx_time() +{ + pmt::pmt_t rx_time = pmt::string_to_symbol("rx_time"); + pmt::pmt_t r = pmt::dict_ref(d_header, rx_time, pmt::PMT_NIL); + uint64_t secs = pmt::to_uint64(pmt::tuple_ref(r, 0)); + double fracs = pmt::to_double(pmt::tuple_ref(r, 1)); + double diff = d_total_seg_size / (d_samp_rate * d_relative_rate); + + // std::cerr << "old secs: " << secs << std::endl; + // std::cerr << "old fracs: " << fracs << std::endl; + // std::cerr << "seg size: " << d_total_seg_size << std::endl; + // std::cerr << "diff: " << diff << std::endl; + + fracs += diff; + uint64_t new_secs = static_cast<uint64_t>(fracs); + secs += new_secs; + fracs -= new_secs; + + // std::cerr << "new secs: " << secs << std::endl; + // std::cerr << "new fracs: " << fracs << std::endl << std::endl; + + r = pmt::make_tuple(pmt::from_uint64(secs), pmt::from_double(fracs)); + d_header = pmt::dict_add(d_header, rx_time, r); +} + +int file_meta_sink_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + char* inbuf = (char*)input_items[0]; + int nwritten = 0; + + do_update(); // update d_fp is reqd + + if (!d_fp) + return noutput_items; // drop output on the floor + + uint64_t abs_N = nitems_read(0); + uint64_t end_N = abs_N + (uint64_t)(noutput_items); + std::vector<tag_t> all_tags; + get_tags_in_range(all_tags, 0, abs_N, end_N); + + std::vector<tag_t>::iterator itr; + for (itr = all_tags.begin(); itr != all_tags.end(); itr++) { + int item_offset = (int)(itr->offset - abs_N); + + // Write date to file up to the next tag location + while (nwritten < item_offset) { + size_t towrite = std::min(d_max_seg_size - d_total_seg_size, + (size_t)(item_offset - nwritten)); + int count = fwrite(inbuf, d_itemsize, towrite, d_fp); + if (count == 0) // FIXME add error handling + break; + nwritten += count; + inbuf += count * d_itemsize; + + d_total_seg_size += count; + + // Only add a new header if we are not at the position of the + // next tag + if ((d_total_seg_size == d_max_seg_size) && (nwritten < item_offset)) { + update_last_header(); + update_rx_time(); + write_and_update(); + d_total_seg_size = 0; + } + } - void - file_meta_sink_impl::update_rx_time() - { - pmt::pmt_t rx_time = pmt::string_to_symbol("rx_time"); - pmt::pmt_t r = pmt::dict_ref(d_header, rx_time, pmt::PMT_NIL); - uint64_t secs = pmt::to_uint64(pmt::tuple_ref(r, 0)); - double fracs = pmt::to_double(pmt::tuple_ref(r, 1)); - double diff = d_total_seg_size / (d_samp_rate*d_relative_rate); - - //std::cerr << "old secs: " << secs << std::endl; - //std::cerr << "old fracs: " << fracs << std::endl; - //std::cerr << "seg size: " << d_total_seg_size << std::endl; - //std::cerr << "diff: " << diff << std::endl; - - fracs += diff; - uint64_t new_secs = static_cast<uint64_t>(fracs); - secs += new_secs; - fracs -= new_secs; - - //std::cerr << "new secs: " << secs << std::endl; - //std::cerr << "new fracs: " << fracs << std::endl << std::endl; - - r = pmt::make_tuple(pmt::from_uint64(secs), pmt::from_double(fracs)); - d_header = pmt::dict_add(d_header, rx_time, r); + if (d_total_seg_size > 0) { + update_last_header(); + update_header(itr->key, itr->value); + write_and_update(); + d_total_seg_size = 0; + } else { + update_header(itr->key, itr->value); + update_last_header(); + } } - int - file_meta_sink_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - char *inbuf = (char*)input_items[0]; - int nwritten = 0; - - do_update(); // update d_fp is reqd - - if(!d_fp) - return noutput_items; // drop output on the floor - - uint64_t abs_N = nitems_read(0); - uint64_t end_N = abs_N + (uint64_t)(noutput_items); - std::vector<tag_t> all_tags; - get_tags_in_range(all_tags, 0, abs_N, end_N); - - std::vector<tag_t>::iterator itr; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - int item_offset = (int)(itr->offset - abs_N); - - // Write date to file up to the next tag location - while(nwritten < item_offset) { - size_t towrite = std::min(d_max_seg_size - d_total_seg_size, - (size_t)(item_offset - nwritten)); - int count = fwrite(inbuf, d_itemsize, towrite, d_fp); - if(count == 0) // FIXME add error handling - break; - nwritten += count; - inbuf += count * d_itemsize; - - d_total_seg_size += count; - - // Only add a new header if we are not at the position of the - // next tag - if((d_total_seg_size == d_max_seg_size) && - (nwritten < item_offset)) { - update_last_header(); - update_rx_time(); - write_and_update(); - d_total_seg_size = 0; - } - } - - if(d_total_seg_size > 0) { - update_last_header(); - update_header(itr->key, itr->value); - write_and_update(); - d_total_seg_size = 0; - } - else { - update_header(itr->key, itr->value); - update_last_header(); - } - } - - // Finish up the rest of the data after tags - while(nwritten < noutput_items) { - size_t towrite = std::min(d_max_seg_size - d_total_seg_size, - (size_t)(noutput_items - nwritten)); - int count = fwrite(inbuf, d_itemsize, towrite, d_fp); - if(count == 0) // FIXME add error handling - break; - nwritten += count; - inbuf += count * d_itemsize; - - d_total_seg_size += count; - if(d_total_seg_size == d_max_seg_size) { - update_last_header(); - update_rx_time(); - write_and_update(); - d_total_seg_size = 0; - } - } - - if(d_unbuffered) - fflush(d_fp); - - return nwritten; + // Finish up the rest of the data after tags + while (nwritten < noutput_items) { + size_t towrite = std::min(d_max_seg_size - d_total_seg_size, + (size_t)(noutput_items - nwritten)); + int count = fwrite(inbuf, d_itemsize, towrite, d_fp); + if (count == 0) // FIXME add error handling + break; + nwritten += count; + inbuf += count * d_itemsize; + + d_total_seg_size += count; + if (d_total_seg_size == d_max_seg_size) { + update_last_header(); + update_rx_time(); + write_and_update(); + d_total_seg_size = 0; + } } - } /* namespace blocks */ + if (d_unbuffered) + fflush(d_fp); + + return nwritten; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/file_meta_sink_impl.h b/gr-blocks/lib/file_meta_sink_impl.h index b274b3e8ed..80ce1f8306 100644 --- a/gr-blocks/lib/file_meta_sink_impl.h +++ b/gr-blocks/lib/file_meta_sink_impl.h @@ -29,68 +29,63 @@ using namespace pmt; namespace gr { - namespace blocks { +namespace blocks { - class file_meta_sink_impl : public file_meta_sink - { - private: - enum meta_state_t { - STATE_INLINE=0, - STATE_DETACHED - }; +class file_meta_sink_impl : public file_meta_sink +{ +private: + enum meta_state_t { STATE_INLINE = 0, STATE_DETACHED }; - size_t d_itemsize; - double d_samp_rate; - double d_relative_rate; - size_t d_max_seg_size; - size_t d_total_seg_size; - pmt_t d_header; - pmt_t d_extra; - size_t d_extra_size; - bool d_updated; - bool d_unbuffered; + size_t d_itemsize; + double d_samp_rate; + double d_relative_rate; + size_t d_max_seg_size; + size_t d_total_seg_size; + pmt_t d_header; + pmt_t d_extra; + size_t d_extra_size; + bool d_updated; + bool d_unbuffered; - FILE *d_new_fp, *d_new_hdr_fp; - FILE *d_fp, *d_hdr_fp; - meta_state_t d_state; + FILE *d_new_fp, *d_new_hdr_fp; + FILE *d_fp, *d_hdr_fp; + meta_state_t d_state; - protected: - void write_header(FILE *fp, pmt_t header, pmt_t extra); - void update_header(pmt_t key, pmt_t value); - void update_last_header(); - void update_last_header_inline(); - void update_last_header_detached(); - void write_and_update(); - void update_rx_time(); +protected: + void write_header(FILE* fp, pmt_t header, pmt_t extra); + void update_header(pmt_t key, pmt_t value); + void update_last_header(); + void update_last_header_inline(); + void update_last_header_detached(); + void write_and_update(); + void update_rx_time(); - bool _open(FILE **fp, const char *filename); + bool _open(FILE** fp, const char* filename); - public: - file_meta_sink_impl(size_t itemsize, const std::string &filename, - double samp_rate=1, - double relative_rate=1, - gr_file_types type=GR_FILE_FLOAT, - bool complex=true, - size_t max_segment_size=1000000, - pmt::pmt_t extra_dict=pmt::make_dict(), - bool detached_header=false); - ~file_meta_sink_impl(); +public: + file_meta_sink_impl(size_t itemsize, + const std::string& filename, + double samp_rate = 1, + double relative_rate = 1, + gr_file_types type = GR_FILE_FLOAT, + bool complex = true, + size_t max_segment_size = 1000000, + pmt::pmt_t extra_dict = pmt::make_dict(), + bool detached_header = false); + ~file_meta_sink_impl(); - bool open(const std::string &filename); - void close(); - void do_update(); + bool open(const std::string& filename); + void close(); + void do_update(); - void set_unbuffered(bool unbuffered) - { - d_unbuffered = unbuffered; - } + void set_unbuffered(bool unbuffered) { d_unbuffered = unbuffered; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_FILE_META_SINK_IMPL_H */ diff --git a/gr-blocks/lib/file_meta_source_impl.cc b/gr-blocks/lib/file_meta_source_impl.cc index 3c72e2a003..fcf8228de5 100644 --- a/gr-blocks/lib/file_meta_source_impl.cc +++ b/gr-blocks/lib/file_meta_source_impl.cc @@ -38,409 +38,391 @@ #include <io.h> #endif #ifdef O_BINARY -#define OUR_O_BINARY O_BINARY +#define OUR_O_BINARY O_BINARY #else -#define OUR_O_BINARY 0 +#define OUR_O_BINARY 0 #endif // should be handled via configure #ifdef O_LARGEFILE -#define OUR_O_LARGEFILE O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE #else -#define OUR_O_LARGEFILE 0 +#define OUR_O_LARGEFILE 0 #endif namespace gr { - namespace blocks { - - - file_meta_source::sptr - file_meta_source::make(const std::string &filename, - bool repeat, - bool detached_header, - const std::string &hdr_filename) - { - return gnuradio::get_initial_sptr - (new file_meta_source_impl(filename, - repeat, - detached_header, - hdr_filename)); +namespace blocks { + + +file_meta_source::sptr file_meta_source::make(const std::string& filename, + bool repeat, + bool detached_header, + const std::string& hdr_filename) +{ + return gnuradio::get_initial_sptr( + new file_meta_source_impl(filename, repeat, detached_header, hdr_filename)); +} + +file_meta_source_impl::file_meta_source_impl(const std::string& filename, + bool repeat, + bool detached_header, + const std::string& hdr_filename) + : sync_block( + "file_meta_source", io_signature::make(0, 0, 0), io_signature::make(1, 1, 1)), + d_itemsize(0), + d_samp_rate(0), + d_seg_size(0), + d_updated(false), + d_repeat(repeat) +{ + d_fp = 0; + d_new_fp = 0; + d_hdr_fp = 0; + d_new_hdr_fp = 0; + + if (detached_header == true) { + d_state = STATE_DETACHED; + } else + d_state = STATE_INLINE; + + if (!open(filename, hdr_filename)) + throw std::runtime_error("file_meta_source: can't open file\n"); + + do_update(); + + pmt::pmt_t hdr = pmt::PMT_NIL, extras = pmt::PMT_NIL; + if (read_header(hdr, extras)) { + parse_header(hdr, 0, d_tags); + parse_extras(extras, 0, d_tags); + } else + throw std::runtime_error("file_meta_source: could not read header.\n"); + + // Set output signature based on itemsize info in header + set_output_signature(io_signature::make(1, 1, d_itemsize)); +} + +file_meta_source_impl::~file_meta_source_impl() { close(); } + +bool file_meta_source_impl::read_header(pmt::pmt_t& hdr, pmt::pmt_t& extras) +{ + // Select which file handle to read from. + FILE* fp; + if (d_state == STATE_DETACHED) + fp = d_hdr_fp; + else + fp = d_fp; + + size_t ret; + size_t size = 0; + std::string str; + char* hdr_buffer = new char[METADATA_HEADER_SIZE]; + while (size < METADATA_HEADER_SIZE) { + ret = fread(&hdr_buffer[size], sizeof(char), METADATA_HEADER_SIZE - size, fp); + if (ret == 0) { + delete[] hdr_buffer; + if (feof(fp)) + return false; + else { + std::stringstream s; + s << "file_meta_source: error occurred extracting header: " + << strerror(errno) << std::endl; + throw std::runtime_error(s.str()); + } + } + size += ret; } - file_meta_source_impl::file_meta_source_impl(const std::string &filename, - bool repeat, - bool detached_header, - const std::string &hdr_filename) - : sync_block("file_meta_source", - io_signature::make(0, 0, 0), - io_signature::make(1, 1, 1)), - d_itemsize(0), d_samp_rate(0), - d_seg_size(0), - d_updated(false), d_repeat(repeat) - { - d_fp = 0; - d_new_fp = 0; - d_hdr_fp = 0; - d_new_hdr_fp = 0; - - if(detached_header == true) { - d_state = STATE_DETACHED; - } - else - d_state = STATE_INLINE; - - if(!open(filename, hdr_filename)) - throw std::runtime_error("file_meta_source: can't open file\n"); - - do_update(); - - pmt::pmt_t hdr = pmt::PMT_NIL, extras = pmt::PMT_NIL; - if(read_header(hdr, extras)) { - parse_header(hdr, 0, d_tags); - parse_extras(extras, 0, d_tags); - } - else - throw std::runtime_error("file_meta_source: could not read header.\n"); - - // Set output signature based on itemsize info in header - set_output_signature(io_signature::make(1, 1, d_itemsize)); + // Convert to string or the char array gets confused by the \0 + str.insert(0, hdr_buffer, METADATA_HEADER_SIZE); + hdr = pmt::deserialize_str(str); + delete[] hdr_buffer; + + uint64_t seg_start, extra_len = 0; + pmt::pmt_t r, dump; + if (pmt::dict_has_key(hdr, pmt::string_to_symbol("strt"))) { + r = pmt::dict_ref(hdr, pmt::string_to_symbol("strt"), dump); + seg_start = pmt::to_uint64(r); + extra_len = seg_start - METADATA_HEADER_SIZE; } - file_meta_source_impl::~file_meta_source_impl() - { - close(); - + if (extra_len > 0) { + size = 0; + hdr_buffer = new char[extra_len]; + while (size < extra_len) { + ret = fread(&hdr_buffer[size], sizeof(char), extra_len - size, fp); + if (ret == 0) { + delete[] hdr_buffer; + if (feof(fp)) + return false; + else { + std::stringstream s; + s << "file_meta_source: error occurred extracting extras: " + << strerror(errno) << std::endl; + throw std::runtime_error(s.str()); + } + } + size += ret; + } + str.clear(); + str.insert(0, hdr_buffer, extra_len); + extras = pmt::deserialize_str(str); + delete[] hdr_buffer; } - bool - file_meta_source_impl::read_header(pmt::pmt_t &hdr, pmt::pmt_t &extras) - { - // Select which file handle to read from. - FILE *fp; - if(d_state == STATE_DETACHED) - fp = d_hdr_fp; - else - fp = d_fp; - - size_t ret; - size_t size = 0; - std::string str; - char *hdr_buffer = new char[METADATA_HEADER_SIZE]; - while(size < METADATA_HEADER_SIZE) { - ret = fread(&hdr_buffer[size], sizeof(char), METADATA_HEADER_SIZE-size, fp); - if(ret == 0) { - delete [] hdr_buffer; - if(feof(fp)) - return false; - else { - std::stringstream s; - s << "file_meta_source: error occurred extracting header: " - << strerror(errno) << std::endl; - throw std::runtime_error(s.str()); - } - } - size += ret; - } - - // Convert to string or the char array gets confused by the \0 - str.insert(0, hdr_buffer, METADATA_HEADER_SIZE); - hdr = pmt::deserialize_str(str); - delete [] hdr_buffer; - - uint64_t seg_start, extra_len = 0; - pmt::pmt_t r, dump; - if(pmt::dict_has_key(hdr, pmt::string_to_symbol("strt"))) { - r = pmt::dict_ref(hdr, pmt::string_to_symbol("strt"), dump); - seg_start = pmt::to_uint64(r); - extra_len = seg_start - METADATA_HEADER_SIZE; - } - - if(extra_len > 0) { - size = 0; - hdr_buffer = new char[extra_len]; - while(size < extra_len) { - ret = fread(&hdr_buffer[size], sizeof(char), extra_len-size, fp); - if(ret == 0) { - delete [] hdr_buffer; - if(feof(fp)) - return false; - else { - std::stringstream s; - s << "file_meta_source: error occurred extracting extras: " - << strerror(errno) << std::endl; - throw std::runtime_error(s.str()); - } - } - size += ret; - } - - str.clear(); - str.insert(0, hdr_buffer, extra_len); - extras = pmt::deserialize_str(str); - delete [] hdr_buffer; - } - - return true; + return true; +} + +void file_meta_source_impl::parse_header(pmt::pmt_t hdr, + uint64_t offset, + std::vector<tag_t>& tags) +{ + pmt::pmt_t r, key; + + // GET SAMPLE RATE + key = pmt::string_to_symbol("rx_rate"); + if (pmt::dict_has_key(hdr, key)) { + r = pmt::dict_ref(hdr, key, pmt::PMT_NIL); + d_samp_rate = pmt::to_double(r); + + tag_t t; + t.offset = offset; + t.key = key; + t.value = r; + t.srcid = alias_pmt(); + tags.push_back(t); + } else { + throw std::runtime_error("file_meta_source: Could not extract sample rate.\n"); } - void - file_meta_source_impl::parse_header(pmt::pmt_t hdr, uint64_t offset, - std::vector<tag_t> &tags) - { - pmt::pmt_t r, key; - - // GET SAMPLE RATE - key = pmt::string_to_symbol("rx_rate"); - if(pmt::dict_has_key(hdr, key)) { - r = pmt::dict_ref(hdr, key, pmt::PMT_NIL); - d_samp_rate = pmt::to_double(r); - - tag_t t; - t.offset = offset; - t.key = key; - t.value = r; - t.srcid = alias_pmt(); - tags.push_back(t); - } - else { - throw std::runtime_error("file_meta_source: Could not extract sample rate.\n"); - } - - // GET TIME STAMP - key = pmt::string_to_symbol("rx_time"); - if(pmt::dict_has_key(hdr, key)) { - d_time_stamp = pmt::dict_ref(hdr, key, pmt::PMT_NIL); - - tag_t t; - t.offset = offset; - t.key = key; - t.value = d_time_stamp; - t.srcid = alias_pmt(); - tags.push_back(t); - } - else { - throw std::runtime_error("file_meta_source: Could not extract time stamp.\n"); - } - - // GET ITEM SIZE OF DATA - if(pmt::dict_has_key(hdr, pmt::string_to_symbol("size"))) { - d_itemsize = pmt::to_long(pmt::dict_ref(hdr, pmt::string_to_symbol("size"), pmt::PMT_NIL)); - } - else { - throw std::runtime_error("file_meta_source: Could not extract item size.\n"); - } - - // GET SEGMENT SIZE - if(pmt::dict_has_key(hdr, pmt::string_to_symbol("bytes"))) { - d_seg_size = pmt::to_uint64(pmt::dict_ref(hdr, pmt::string_to_symbol("bytes"), pmt::PMT_NIL)); - - // Convert from bytes to items - d_seg_size /= d_itemsize; - } - else { - throw std::runtime_error("file_meta_source: Could not extract segment size.\n"); - } + // GET TIME STAMP + key = pmt::string_to_symbol("rx_time"); + if (pmt::dict_has_key(hdr, key)) { + d_time_stamp = pmt::dict_ref(hdr, key, pmt::PMT_NIL); + + tag_t t; + t.offset = offset; + t.key = key; + t.value = d_time_stamp; + t.srcid = alias_pmt(); + tags.push_back(t); + } else { + throw std::runtime_error("file_meta_source: Could not extract time stamp.\n"); } - void - file_meta_source_impl::parse_extras(pmt::pmt_t extras, uint64_t offset, - std::vector<tag_t> &tags) - { - pmt::pmt_t item, key, val; - - size_t nitems = pmt::length(extras); - for(size_t i = 0; i < nitems; i++) { - item = pmt::nth(i, extras); - key = pmt::car(item); - val = pmt::cdr(item); - - tag_t t; - t.offset = offset; - t.key = key; - t.value = val; - t.srcid = alias_pmt(); - tags.push_back(t); - } + // GET ITEM SIZE OF DATA + if (pmt::dict_has_key(hdr, pmt::string_to_symbol("size"))) { + d_itemsize = + pmt::to_long(pmt::dict_ref(hdr, pmt::string_to_symbol("size"), pmt::PMT_NIL)); + } else { + throw std::runtime_error("file_meta_source: Could not extract item size.\n"); } - bool - file_meta_source_impl::open(const std::string &filename, - const std::string &hdr_filename) - { - bool ret = true; - if(d_state == STATE_DETACHED) { - std::string s; - if(hdr_filename == "") - s = filename + ".hdr"; - else - s = hdr_filename; - ret = _open(&d_new_hdr_fp, s.c_str()); - } - - ret = ret && _open(&d_new_fp, filename.c_str()); - d_updated = true; - return ret; + // GET SEGMENT SIZE + if (pmt::dict_has_key(hdr, pmt::string_to_symbol("bytes"))) { + d_seg_size = pmt::to_uint64( + pmt::dict_ref(hdr, pmt::string_to_symbol("bytes"), pmt::PMT_NIL)); + + // Convert from bytes to items + d_seg_size /= d_itemsize; + } else { + throw std::runtime_error("file_meta_source: Could not extract segment size.\n"); + } +} + +void file_meta_source_impl::parse_extras(pmt::pmt_t extras, + uint64_t offset, + std::vector<tag_t>& tags) +{ + pmt::pmt_t item, key, val; + + size_t nitems = pmt::length(extras); + for (size_t i = 0; i < nitems; i++) { + item = pmt::nth(i, extras); + key = pmt::car(item); + val = pmt::cdr(item); + + tag_t t; + t.offset = offset; + t.key = key; + t.value = val; + t.srcid = alias_pmt(); + tags.push_back(t); + } +} + +bool file_meta_source_impl::open(const std::string& filename, + const std::string& hdr_filename) +{ + bool ret = true; + if (d_state == STATE_DETACHED) { + std::string s; + if (hdr_filename == "") + s = filename + ".hdr"; + else + s = hdr_filename; + ret = _open(&d_new_hdr_fp, s.c_str()); } - bool - file_meta_source_impl::_open(FILE **fp, const char *filename) - { - gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this function + ret = ret && _open(&d_new_fp, filename.c_str()); + d_updated = true; + return ret; +} - bool ret = true; - int fd; +bool file_meta_source_impl::_open(FILE** fp, const char* filename) +{ + gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this function - if((fd = ::open(filename, - O_RDONLY|OUR_O_LARGEFILE|OUR_O_BINARY)) < 0) { - perror(filename); - return false; - } + bool ret = true; + int fd; - if(*fp) { // if we've already got a new one open, close it - fclose(*fp); - fp = 0; - } + if ((fd = ::open(filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { + perror(filename); + return false; + } - if((*fp = fdopen(fd, "rb")) == NULL) { - perror(filename); - ::close(fd); // don't leak file descriptor if fdopen fails. - } + if (*fp) { // if we've already got a new one open, close it + fclose(*fp); + fp = 0; + } - ret = fp != 0; + if ((*fp = fdopen(fd, "rb")) == NULL) { + perror(filename); + ::close(fd); // don't leak file descriptor if fdopen fails. + } + + ret = fp != 0; + + return ret; +} - return ret; +void file_meta_source_impl::close() +{ + gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this function + if (d_state == STATE_DETACHED) { + if (d_new_hdr_fp) { + fclose(d_new_hdr_fp); + d_new_hdr_fp = 0; + } } - void - file_meta_source_impl::close() - { - gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this function - if(d_state == STATE_DETACHED) { - if(d_new_hdr_fp) { - fclose(d_new_hdr_fp); - d_new_hdr_fp = 0; - } - } - - if(d_new_fp) { - fclose(d_new_fp); - d_new_fp = 0; - } - d_updated = true; - - if (d_fp) { + if (d_new_fp) { + fclose(d_new_fp); + d_new_fp = 0; + } + d_updated = true; + + if (d_fp) { fclose(d_fp); d_fp = 0; - } + } - if (d_state == STATE_DETACHED) { + if (d_state == STATE_DETACHED) { if (d_hdr_fp) { - fclose(d_hdr_fp); - d_hdr_fp = 0; + fclose(d_hdr_fp); + d_hdr_fp = 0; } - } } +} + +void file_meta_source_impl::do_update() +{ + if (d_updated) { + gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this block + if (d_state == STATE_DETACHED) { + if (d_hdr_fp) + fclose(d_hdr_fp); + d_hdr_fp = d_new_hdr_fp; // install new file pointer + d_new_hdr_fp = 0; + } + + if (d_fp) + fclose(d_fp); + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; - void - file_meta_source_impl::do_update() - { - if(d_updated) { - gr::thread::scoped_lock guard(d_setlock); // hold mutex for duration of this block - if(d_state == STATE_DETACHED) { - if(d_hdr_fp) - fclose(d_hdr_fp); - d_hdr_fp = d_new_hdr_fp; // install new file pointer - d_new_hdr_fp = 0; - } - - if(d_fp) - fclose(d_fp); - d_fp = d_new_fp; // install new file pointer - d_new_fp = 0; - - d_updated = false; - } + d_updated = false; } +} + +int file_meta_source_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + // We've reached the end of a segment; parse the next header and get + // the new tags to send and set the next segment size. + if (d_seg_size == 0) { + pmt::pmt_t hdr = pmt::PMT_NIL, extras = pmt::PMT_NIL; + if (read_header(hdr, extras)) { + parse_header(hdr, nitems_written(0), d_tags); + parse_extras(extras, nitems_written(0), d_tags); + } else { + if (!d_repeat) + return -1; + else { + if (fseek(d_fp, 0, SEEK_SET) == -1) { + std::stringstream s; + s << "[" << __FILE__ << "]" + << " fseek failed" << std::endl; + throw std::runtime_error(s.str()); + } + } + } + } + + char* out = (char*)output_items[0]; + int i; + int seg_size = std::min(noutput_items, (int)d_seg_size); + int size = seg_size; + + do_update(); // update d_fp is reqd + if (d_fp == NULL) + throw std::runtime_error("work with file not open"); + + // Push all tags onto the stream and remove them from the vector + while (!d_tags.empty()) { + add_item_tag(0, d_tags.back()); + d_tags.pop_back(); + } + + gr::thread::scoped_lock lock(d_setlock); // hold for the rest of this function + while (size) { + i = fread(out, d_itemsize, size, d_fp); + + size -= i; + d_seg_size -= i; + out += i * d_itemsize; - int - file_meta_source_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - // We've reached the end of a segment; parse the next header and get - // the new tags to send and set the next segment size. - if(d_seg_size == 0) { - pmt::pmt_t hdr=pmt::PMT_NIL, extras=pmt::PMT_NIL; - if(read_header(hdr, extras)) { - parse_header(hdr, nitems_written(0), d_tags); - parse_extras(extras, nitems_written(0), d_tags); - } - else { - if(!d_repeat) + if (size == 0) // done + break; + + if (i > 0) // short read, try again + continue; + + // We got a zero from fread. This is either EOF or error. In + // any event, if we're in repeat mode, seek back to the beginning + // of the file and try again, else break + + if (!d_repeat) + break; + + if (fseek(d_fp, 0, SEEK_SET) == -1) { + std::stringstream s; + s << "[" << __FILE__ << "]" + << " fseek failed" << std::endl; + throw std::runtime_error(s.str()); + } + } + + if (size > 0) { // EOF or error + if (size == seg_size) // we didn't read anything; say we're done return -1; - else { - if(fseek(d_fp, 0, SEEK_SET) == -1) { - std::stringstream s; - s << "[" << __FILE__ << "]" << " fseek failed" << std::endl; - throw std::runtime_error(s.str()); - } - } - } - } - - char *out = (char*)output_items[0]; - int i; - int seg_size = std::min(noutput_items, (int)d_seg_size); - int size = seg_size; - - do_update(); // update d_fp is reqd - if(d_fp == NULL) - throw std::runtime_error("work with file not open"); - - // Push all tags onto the stream and remove them from the vector - while(!d_tags.empty()) { - add_item_tag(0, d_tags.back()); - d_tags.pop_back(); - } - - gr::thread::scoped_lock lock(d_setlock); // hold for the rest of this function - while(size) { - i = fread(out, d_itemsize, size, d_fp); - - size -= i; - d_seg_size -= i; - out += i * d_itemsize; - - if(size == 0) // done - break; - - if(i > 0) // short read, try again - continue; - - // We got a zero from fread. This is either EOF or error. In - // any event, if we're in repeat mode, seek back to the beginning - // of the file and try again, else break - - if(!d_repeat) - break; - - if(fseek(d_fp, 0, SEEK_SET) == -1) { - std::stringstream s; - s << "[" << __FILE__ << "]" << " fseek failed" << std::endl; - throw std::runtime_error(s.str()); - } - } - - if(size > 0) { // EOF or error - if(size == seg_size) // we didn't read anything; say we're done - return -1; - return seg_size - size; // else return partial result - } - - return seg_size; + return seg_size - size; // else return partial result } - } /* namespace blocks */ + return seg_size; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/file_meta_source_impl.h b/gr-blocks/lib/file_meta_source_impl.h index bd7d3c1209..242edce56a 100644 --- a/gr-blocks/lib/file_meta_source_impl.h +++ b/gr-blocks/lib/file_meta_source_impl.h @@ -33,56 +33,50 @@ using namespace pmt; namespace gr { - namespace blocks { - - class file_meta_source_impl : public file_meta_source - { - private: - enum meta_state_t { - STATE_INLINE=0, - STATE_DETACHED - }; - - size_t d_itemsize; - double d_samp_rate; - pmt_t d_time_stamp; - size_t d_seg_size; - bool d_updated; - bool d_repeat; - - FILE *d_new_fp, *d_new_hdr_fp; - FILE *d_fp, *d_hdr_fp; - meta_state_t d_state; - - std::vector<tag_t> d_tags; - - protected: - bool _open(FILE **fp, const char *filename); - bool read_header(pmt_t &hdr, pmt_t &extras); - void parse_header(pmt_t hdr, uint64_t offset, - std::vector<tag_t> &tags); - void parse_extras(pmt_t extras, uint64_t offset, - std::vector<tag_t> &tags); - - public: - file_meta_source_impl(const std::string &filename, - bool repeat=false, - bool detached_header=false, - const std::string &hdr_filename=""); - - ~file_meta_source_impl(); - - bool open(const std::string &filename, - const std::string &hdr_filename=""); - void close(); - void do_update(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class file_meta_source_impl : public file_meta_source +{ +private: + enum meta_state_t { STATE_INLINE = 0, STATE_DETACHED }; + + size_t d_itemsize; + double d_samp_rate; + pmt_t d_time_stamp; + size_t d_seg_size; + bool d_updated; + bool d_repeat; + + FILE *d_new_fp, *d_new_hdr_fp; + FILE *d_fp, *d_hdr_fp; + meta_state_t d_state; + + std::vector<tag_t> d_tags; + +protected: + bool _open(FILE** fp, const char* filename); + bool read_header(pmt_t& hdr, pmt_t& extras); + void parse_header(pmt_t hdr, uint64_t offset, std::vector<tag_t>& tags); + void parse_extras(pmt_t extras, uint64_t offset, std::vector<tag_t>& tags); + +public: + file_meta_source_impl(const std::string& filename, + bool repeat = false, + bool detached_header = false, + const std::string& hdr_filename = ""); + + ~file_meta_source_impl(); + + bool open(const std::string& filename, const std::string& hdr_filename = ""); + void close(); + void do_update(); + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_FILE_META_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/file_sink_base.cc b/gr-blocks/lib/file_sink_base.cc index 81bc94f351..2b10ba93e5 100644 --- a/gr-blocks/lib/file_sink_base.cc +++ b/gr-blocks/lib/file_sink_base.cc @@ -38,98 +38,91 @@ #include <io.h> #endif #ifdef O_BINARY -#define OUR_O_BINARY O_BINARY +#define OUR_O_BINARY O_BINARY #else -#define OUR_O_BINARY 0 +#define OUR_O_BINARY 0 #endif // should be handled via configure #ifdef O_LARGEFILE -#define OUR_O_LARGEFILE O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE #else -#define OUR_O_LARGEFILE 0 +#define OUR_O_LARGEFILE 0 #endif namespace gr { - namespace blocks { - - file_sink_base::file_sink_base(const char *filename, bool is_binary, bool append) - : d_fp(0), d_new_fp(0), d_updated(false), d_is_binary(is_binary), d_append(append) - { - if (!open(filename)) - throw std::runtime_error ("can't open file"); - } - - file_sink_base::~file_sink_base() - { - close(); - if(d_fp) { +namespace blocks { + +file_sink_base::file_sink_base(const char* filename, bool is_binary, bool append) + : d_fp(0), d_new_fp(0), d_updated(false), d_is_binary(is_binary), d_append(append) +{ + if (!open(filename)) + throw std::runtime_error("can't open file"); +} + +file_sink_base::~file_sink_base() +{ + close(); + if (d_fp) { fclose(d_fp); d_fp = 0; - } } - - bool - file_sink_base::open(const char *filename) - { - gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this function - - // we use the open system call to get access to the O_LARGEFILE flag. - int fd; - int flags; - if(d_append) { - flags = O_WRONLY|O_CREAT|O_APPEND|OUR_O_LARGEFILE|OUR_O_BINARY; - } else { - flags = O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY; - } - if((fd = ::open(filename, flags, 0664)) < 0){ +} + +bool file_sink_base::open(const char* filename) +{ + gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this function + + // we use the open system call to get access to the O_LARGEFILE flag. + int fd; + int flags; + if (d_append) { + flags = O_WRONLY | O_CREAT | O_APPEND | OUR_O_LARGEFILE | OUR_O_BINARY; + } else { + flags = O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE | OUR_O_BINARY; + } + if ((fd = ::open(filename, flags, 0664)) < 0) { perror(filename); return false; - } - if(d_new_fp) { // if we've already got a new one open, close it + } + if (d_new_fp) { // if we've already got a new one open, close it fclose(d_new_fp); d_new_fp = 0; - } - - if((d_new_fp = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL) { - perror (filename); - ::close(fd); // don't leak file descriptor if fdopen fails. - } + } - d_updated = true; - return d_new_fp != 0; + if ((d_new_fp = fdopen(fd, d_is_binary ? "wb" : "w")) == NULL) { + perror(filename); + ::close(fd); // don't leak file descriptor if fdopen fails. } - void - file_sink_base::close() - { - gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this function + d_updated = true; + return d_new_fp != 0; +} - if(d_new_fp) { +void file_sink_base::close() +{ + gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this function + + if (d_new_fp) { fclose(d_new_fp); d_new_fp = 0; - } - d_updated = true; } - - void - file_sink_base::do_update() - { - if(d_updated) { - gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this block - if(d_fp) - fclose(d_fp); - d_fp = d_new_fp; // install new file pointer + d_updated = true; +} + +void file_sink_base::do_update() +{ + if (d_updated) { + gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this block + if (d_fp) + fclose(d_fp); + d_fp = d_new_fp; // install new file pointer d_new_fp = 0; d_updated = false; - } } +} - void - file_sink_base::set_unbuffered(bool unbuffered) - { - d_unbuffered = unbuffered; - } +void file_sink_base::set_unbuffered(bool unbuffered) { d_unbuffered = unbuffered; } - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/file_sink_impl.cc b/gr-blocks/lib/file_sink_impl.cc index ab36dcd4e6..0f49138359 100644 --- a/gr-blocks/lib/file_sink_impl.cc +++ b/gr-blocks/lib/file_sink_impl.cc @@ -29,62 +29,55 @@ #include <stdexcept> namespace gr { - namespace blocks { +namespace blocks { - file_sink::sptr - file_sink::make(size_t itemsize, const char *filename, bool append) - { - return gnuradio::get_initial_sptr - (new file_sink_impl(itemsize, filename, append)); - } +file_sink::sptr file_sink::make(size_t itemsize, const char* filename, bool append) +{ + return gnuradio::get_initial_sptr(new file_sink_impl(itemsize, filename, append)); +} - file_sink_impl::file_sink_impl(size_t itemsize, const char *filename, bool append) - : sync_block("file_sink", - io_signature::make(1, 1, itemsize), - io_signature::make(0, 0, 0)), - file_sink_base(filename, true, append), - d_itemsize(itemsize) - { - } +file_sink_impl::file_sink_impl(size_t itemsize, const char* filename, bool append) + : sync_block( + "file_sink", io_signature::make(1, 1, itemsize), io_signature::make(0, 0, 0)), + file_sink_base(filename, true, append), + d_itemsize(itemsize) +{ +} - file_sink_impl::~file_sink_impl() - { - } +file_sink_impl::~file_sink_impl() {} - int - file_sink_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - char *inbuf = (char*)input_items[0]; - int nwritten = 0; +int file_sink_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + char* inbuf = (char*)input_items[0]; + int nwritten = 0; - do_update(); // update d_fp is reqd + do_update(); // update d_fp is reqd - if(!d_fp) - return noutput_items; // drop output on the floor + if (!d_fp) + return noutput_items; // drop output on the floor - while(nwritten < noutput_items) { + while (nwritten < noutput_items) { int count = fwrite(inbuf, d_itemsize, noutput_items - nwritten, d_fp); - if(count == 0) { - if(ferror(d_fp)) { - std::stringstream s; - s << "file_sink write failed with error " << fileno(d_fp) << std::endl; - throw std::runtime_error(s.str()); - } - else { // is EOF - break; - } + if (count == 0) { + if (ferror(d_fp)) { + std::stringstream s; + s << "file_sink write failed with error " << fileno(d_fp) << std::endl; + throw std::runtime_error(s.str()); + } else { // is EOF + break; + } } nwritten += count; inbuf += count * d_itemsize; - } + } - if(d_unbuffered) - fflush (d_fp); + if (d_unbuffered) + fflush(d_fp); - return nwritten; - } + return nwritten; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/file_sink_impl.h b/gr-blocks/lib/file_sink_impl.h index 9e0c81569b..3671aab540 100644 --- a/gr-blocks/lib/file_sink_impl.h +++ b/gr-blocks/lib/file_sink_impl.h @@ -26,23 +26,23 @@ #include <gnuradio/blocks/file_sink.h> namespace gr { - namespace blocks { +namespace blocks { - class file_sink_impl : public file_sink - { - private: - size_t d_itemsize; +class file_sink_impl : public file_sink +{ +private: + size_t d_itemsize; - public: - file_sink_impl(size_t itemsize, const char *filename, bool append=false); - ~file_sink_impl(); +public: + file_sink_impl(size_t itemsize, const char* filename, bool append = false); + ~file_sink_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_FILE_SINK_IMPL_H */ diff --git a/gr-blocks/lib/file_source_impl.cc b/gr-blocks/lib/file_source_impl.cc index e9ef6a2145..b025f449af 100644 --- a/gr-blocks/lib/file_source_impl.cc +++ b/gr-blocks/lib/file_source_impl.cc @@ -40,7 +40,7 @@ #define GR_FSTAT _fstat #define GR_FILENO _fileno #define GR_STAT _stat -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) #else #define GR_FSEEK fseeko #define GR_FTELL ftello @@ -50,223 +50,227 @@ #endif namespace gr { - namespace blocks { - - file_source::sptr file_source::make(size_t itemsize, const char *filename, bool repeat, - uint64_t start_offset_items, uint64_t length_items) - { - return gnuradio::get_initial_sptr - (new file_source_impl(itemsize, filename, repeat, start_offset_items, length_items)); - } - - file_source_impl::file_source_impl(size_t itemsize, const char *filename, bool repeat, - uint64_t start_offset_items, uint64_t length_items) - : sync_block("file_source", - io_signature::make(0, 0, 0), - io_signature::make(1, 1, itemsize)), - d_itemsize(itemsize), - d_start_offset_items(start_offset_items), d_length_items(length_items), - d_fp(0), d_new_fp(0), d_repeat(repeat), d_updated(false), - d_file_begin(true), d_repeat_cnt(0), d_add_begin_tag(pmt::PMT_NIL) - { - open(filename, repeat, start_offset_items, length_items); - do_update(); - - std::stringstream str; - str << name() << unique_id(); - _id = pmt::string_to_symbol(str.str()); - } - - file_source_impl::~file_source_impl() - { - if(d_fp) - fclose ((FILE*)d_fp); - if(d_new_fp) - fclose ((FILE*)d_new_fp); - } - - bool - file_source_impl::seek(int64_t seek_point, int whence) - { - if (d_seekable) { +namespace blocks { + +file_source::sptr file_source::make(size_t itemsize, + const char* filename, + bool repeat, + uint64_t start_offset_items, + uint64_t length_items) +{ + return gnuradio::get_initial_sptr(new file_source_impl( + itemsize, filename, repeat, start_offset_items, length_items)); +} + +file_source_impl::file_source_impl(size_t itemsize, + const char* filename, + bool repeat, + uint64_t start_offset_items, + uint64_t length_items) + : sync_block( + "file_source", io_signature::make(0, 0, 0), io_signature::make(1, 1, itemsize)), + d_itemsize(itemsize), + d_start_offset_items(start_offset_items), + d_length_items(length_items), + d_fp(0), + d_new_fp(0), + d_repeat(repeat), + d_updated(false), + d_file_begin(true), + d_repeat_cnt(0), + d_add_begin_tag(pmt::PMT_NIL) +{ + open(filename, repeat, start_offset_items, length_items); + do_update(); + + std::stringstream str; + str << name() << unique_id(); + _id = pmt::string_to_symbol(str.str()); +} + +file_source_impl::~file_source_impl() +{ + if (d_fp) + fclose((FILE*)d_fp); + if (d_new_fp) + fclose((FILE*)d_new_fp); +} + +bool file_source_impl::seek(int64_t seek_point, int whence) +{ + if (d_seekable) { seek_point += d_start_offset_items; - switch(whence) { + switch (whence) { case SEEK_SET: - break; + break; case SEEK_CUR: - seek_point += (d_length_items - d_items_remaining); - break; + seek_point += (d_length_items - d_items_remaining); + break; case SEEK_END: - seek_point = d_length_items - seek_point; - break; + seek_point = d_length_items - seek_point; + break; default: - GR_LOG_WARN(d_logger, "bad seek mode"); - return 0; + GR_LOG_WARN(d_logger, "bad seek mode"); + return 0; } - if ((seek_point < (int64_t)d_start_offset_items) - || (seek_point > (int64_t)(d_start_offset_items+d_length_items-1))) { - GR_LOG_WARN(d_logger, "bad seek point"); - return 0; + if ((seek_point < (int64_t)d_start_offset_items) || + (seek_point > (int64_t)(d_start_offset_items + d_length_items - 1))) { + GR_LOG_WARN(d_logger, "bad seek point"); + return 0; } return GR_FSEEK((FILE*)d_fp, seek_point * d_itemsize, SEEK_SET) == 0; - } - else { + } else { GR_LOG_WARN(d_logger, "file not seekable"); return 0; - } } +} - void - file_source_impl::open(const char *filename, bool repeat, - uint64_t start_offset_items, uint64_t length_items) - { - // obtain exclusive access for duration of this function - gr::thread::scoped_lock lock(fp_mutex); +void file_source_impl::open(const char* filename, + bool repeat, + uint64_t start_offset_items, + uint64_t length_items) +{ + // obtain exclusive access for duration of this function + gr::thread::scoped_lock lock(fp_mutex); - if(d_new_fp) { + if (d_new_fp) { fclose(d_new_fp); d_new_fp = 0; - } + } - if((d_new_fp = fopen (filename, "rb")) == NULL) { + if ((d_new_fp = fopen(filename, "rb")) == NULL) { GR_LOG_ERROR(d_logger, boost::format("%s: %s") % filename % strerror(errno)); throw std::runtime_error("can't open file"); - } + } - struct GR_STAT st; + struct GR_STAT st; - if(GR_FSTAT(GR_FILENO(d_new_fp), &st)) { + if (GR_FSTAT(GR_FILENO(d_new_fp), &st)) { GR_LOG_ERROR(d_logger, boost::format("%s: %s") % filename % strerror(errno)); throw std::runtime_error("can't fstat file"); - } - if(S_ISREG(st.st_mode)) { + } + if (S_ISREG(st.st_mode)) { d_seekable = true; - } - else { + } else { d_seekable = false; - } + } - uint64_t file_size; + uint64_t file_size; - if (d_seekable) { - //Check to ensure the file will be consumed according to item size + if (d_seekable) { + // Check to ensure the file will be consumed according to item size GR_FSEEK(d_new_fp, 0, SEEK_END); file_size = GR_FTELL(d_new_fp); // Make sure there will be at least one item available - if ((file_size / d_itemsize) < (start_offset_items+1)) { - if (start_offset_items) { - GR_LOG_WARN(d_logger, "file is too small for start offset"); - } - else { - GR_LOG_WARN(d_logger, "file is too small"); - } - fclose(d_new_fp); - throw std::runtime_error("file is too small"); + if ((file_size / d_itemsize) < (start_offset_items + 1)) { + if (start_offset_items) { + GR_LOG_WARN(d_logger, "file is too small for start offset"); + } else { + GR_LOG_WARN(d_logger, "file is too small"); + } + fclose(d_new_fp); + throw std::runtime_error("file is too small"); } - } - else { + } else { file_size = INT64_MAX; - } + } - uint64_t items_available = (file_size / d_itemsize - start_offset_items); + uint64_t items_available = (file_size / d_itemsize - start_offset_items); - // If length is not specified, use the remainder of the file. Check alignment at end. - if (length_items == 0) { + // If length is not specified, use the remainder of the file. Check alignment at end. + if (length_items == 0) { length_items = items_available; - if (file_size % d_itemsize){ - GR_LOG_WARN(d_logger, "file size is not a multiple of item size"); + if (file_size % d_itemsize) { + GR_LOG_WARN(d_logger, "file size is not a multiple of item size"); } - } + } - // Check specified length. Warn and use available items instead of throwing an exception. - if (length_items > items_available) { + // Check specified length. Warn and use available items instead of throwing an + // exception. + if (length_items > items_available) { length_items = items_available; GR_LOG_WARN(d_logger, "file too short, will read fewer than requested items"); - } + } - // Rewind to start offset - if (d_seekable) { + // Rewind to start offset + if (d_seekable) { GR_FSEEK(d_new_fp, start_offset_items * d_itemsize, SEEK_SET); - } - - d_updated = true; - d_repeat = repeat; - d_start_offset_items = start_offset_items; - d_length_items = length_items; - d_items_remaining = length_items; } - void - file_source_impl::close() - { - // obtain exclusive access for duration of this function - gr::thread::scoped_lock lock(fp_mutex); + d_updated = true; + d_repeat = repeat; + d_start_offset_items = start_offset_items; + d_length_items = length_items; + d_items_remaining = length_items; +} - if(d_new_fp != NULL) { +void file_source_impl::close() +{ + // obtain exclusive access for duration of this function + gr::thread::scoped_lock lock(fp_mutex); + + if (d_new_fp != NULL) { fclose(d_new_fp); d_new_fp = NULL; - } - d_updated = true; } + d_updated = true; +} - void - file_source_impl::do_update() - { - if(d_updated) { +void file_source_impl::do_update() +{ + if (d_updated) { gr::thread::scoped_lock lock(fp_mutex); // hold while in scope - if(d_fp) - fclose(d_fp); + if (d_fp) + fclose(d_fp); - d_fp = d_new_fp; // install new file pointer + d_fp = d_new_fp; // install new file pointer d_new_fp = 0; d_updated = false; d_file_begin = true; - } } +} - void - file_source_impl::set_begin_tag(pmt::pmt_t val) - { - d_add_begin_tag = val; - } +void file_source_impl::set_begin_tag(pmt::pmt_t val) { d_add_begin_tag = val; } - int - file_source_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - char *o = (char*)output_items[0]; - uint64_t size = noutput_items; +int file_source_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + char* o = (char*)output_items[0]; + uint64_t size = noutput_items; - do_update(); // update d_fp is reqd - if(d_fp == NULL) + do_update(); // update d_fp is reqd + if (d_fp == NULL) throw std::runtime_error("work with file not open"); - gr::thread::scoped_lock lock(fp_mutex); // hold for the rest of this function + gr::thread::scoped_lock lock(fp_mutex); // hold for the rest of this function - // No items remaining - all done - if (d_items_remaining == 0) + // No items remaining - all done + if (d_items_remaining == 0) return WORK_DONE; - while(size) { + while (size) { // Add stream tag whenever the file starts again if (d_file_begin && d_add_begin_tag != pmt::PMT_NIL) { - add_item_tag(0, nitems_written(0) + noutput_items - size, - d_add_begin_tag, pmt::from_long(d_repeat_cnt), _id); - d_file_begin = false; + add_item_tag(0, + nitems_written(0) + noutput_items - size, + d_add_begin_tag, + pmt::from_long(d_repeat_cnt), + _id); + d_file_begin = false; } uint64_t nitems_to_read = std::min(size, d_items_remaining); // Since the bounds of the file are known, unexpected nitems is an error if (nitems_to_read != fread(o, d_itemsize, nitems_to_read, (FILE*)d_fp)) - throw std::runtime_error("fread error"); + throw std::runtime_error("fread error"); size -= nitems_to_read; d_items_remaining -= nitems_to_read; @@ -275,25 +279,25 @@ namespace gr { // Ran out of items ("EOF") if (d_items_remaining == 0) { - // Repeat: rewind and request tag - if (d_repeat && d_seekable) { - GR_FSEEK(d_fp, d_start_offset_items * d_itemsize, SEEK_SET); - d_items_remaining = d_length_items; - if (d_add_begin_tag != pmt::PMT_NIL) { - d_file_begin = true; - d_repeat_cnt++; + // Repeat: rewind and request tag + if (d_repeat && d_seekable) { + GR_FSEEK(d_fp, d_start_offset_items * d_itemsize, SEEK_SET); + d_items_remaining = d_length_items; + if (d_add_begin_tag != pmt::PMT_NIL) { + d_file_begin = true; + d_repeat_cnt++; + } } - } - // No repeat: return - else { - break; - } + // No repeat: return + else { + break; + } } - } - - return (noutput_items - size); } - } /* namespace blocks */ + return (noutput_items - size); +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/file_source_impl.h b/gr-blocks/lib/file_source_impl.h index 6ce87cf7c7..bec21ea8ab 100644 --- a/gr-blocks/lib/file_source_impl.h +++ b/gr-blocks/lib/file_source_impl.h @@ -27,46 +27,49 @@ #include <boost/thread/mutex.hpp> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API file_source_impl : public file_source - { - private: - size_t d_itemsize; - uint64_t d_start_offset_items; - uint64_t d_length_items; - uint64_t d_items_remaining; - FILE *d_fp; - FILE *d_new_fp; - bool d_repeat; - bool d_updated; - bool d_file_begin; - bool d_seekable; - long d_repeat_cnt; - pmt::pmt_t d_add_begin_tag; +class BLOCKS_API file_source_impl : public file_source +{ +private: + size_t d_itemsize; + uint64_t d_start_offset_items; + uint64_t d_length_items; + uint64_t d_items_remaining; + FILE* d_fp; + FILE* d_new_fp; + bool d_repeat; + bool d_updated; + bool d_file_begin; + bool d_seekable; + long d_repeat_cnt; + pmt::pmt_t d_add_begin_tag; - boost::mutex fp_mutex; - pmt::pmt_t _id; + boost::mutex fp_mutex; + pmt::pmt_t _id; - void do_update(); + void do_update(); - public: - file_source_impl(size_t itemsize, const char *filename, bool repeat, - uint64_t offset, uint64_t len); - ~file_source_impl(); +public: + file_source_impl(size_t itemsize, + const char* filename, + bool repeat, + uint64_t offset, + uint64_t len); + ~file_source_impl(); - bool seek(int64_t seek_point, int whence); - void open(const char *filename, bool repeat, uint64_t offset, uint64_t len); - void close(); + bool seek(int64_t seek_point, int whence); + void open(const char* filename, bool repeat, uint64_t offset, uint64_t len); + void close(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - void set_begin_tag(pmt::pmt_t val); - }; + void set_begin_tag(pmt::pmt_t val); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_FILE_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/float_array_to_int.cc b/gr-blocks/lib/float_array_to_int.cc index 66cae4b2d2..dbdae45201 100644 --- a/gr-blocks/lib/float_array_to_int.cc +++ b/gr-blocks/lib/float_array_to_int.cc @@ -34,18 +34,17 @@ using std::int64_t; #include <stdint.h> #endif -static const int64_t MAX_INT = INT32_MAX; -static const int64_t MIN_INT = INT32_MIN; +static const int64_t MAX_INT = INT32_MAX; +static const int64_t MIN_INT = INT32_MIN; -void -float_array_to_int(const float *in, int *out, float scale, int nsamples) +void float_array_to_int(const float* in, int* out, float scale, int nsamples) { - for (int i = 0; i < nsamples; i++){ - int64_t r = llrintf(scale * in[i]); - if (r < MIN_INT) - r = MIN_INT; - else if (r > MAX_INT) - r = MAX_INT; - out[i] = static_cast<int>(r); - } + for (int i = 0; i < nsamples; i++) { + int64_t r = llrintf(scale * in[i]); + if (r < MIN_INT) + r = MIN_INT; + else if (r > MAX_INT) + r = MAX_INT; + out[i] = static_cast<int>(r); + } } diff --git a/gr-blocks/lib/float_array_to_int.h b/gr-blocks/lib/float_array_to_int.h index 6a528d797a..717dc1d143 100644 --- a/gr-blocks/lib/float_array_to_int.h +++ b/gr-blocks/lib/float_array_to_int.h @@ -28,6 +28,6 @@ /*! * convert array of floats to int with rounding and saturation. */ -BLOCKS_API void float_array_to_int (const float *in, int *out, float scale, int nsamples); +BLOCKS_API void float_array_to_int(const float* in, int* out, float scale, int nsamples); #endif /* INCLUDED_BLOCKS_FLOAT_ARRAY_TO_INT_H */ diff --git a/gr-blocks/lib/float_array_to_uchar.cc b/gr-blocks/lib/float_array_to_uchar.cc index 54a66f60e1..4aaa2630dd 100644 --- a/gr-blocks/lib/float_array_to_uchar.cc +++ b/gr-blocks/lib/float_array_to_uchar.cc @@ -29,17 +29,16 @@ #include <math.h> static const int MIN_UCHAR = 0; -static const int MAX_UCHAR = 255; +static const int MAX_UCHAR = 255; -void -float_array_to_uchar(const float *in, unsigned char *out, int nsamples) +void float_array_to_uchar(const float* in, unsigned char* out, int nsamples) { - for (int i = 0; i < nsamples; i++){ - long int r = (long int) rint (in[i]); - if (r < MIN_UCHAR) - r = MIN_UCHAR; - else if (r > MAX_UCHAR) - r = MAX_UCHAR; - out[i] = r; - } + for (int i = 0; i < nsamples; i++) { + long int r = (long int)rint(in[i]); + if (r < MIN_UCHAR) + r = MIN_UCHAR; + else if (r > MAX_UCHAR) + r = MAX_UCHAR; + out[i] = r; + } } diff --git a/gr-blocks/lib/float_array_to_uchar.h b/gr-blocks/lib/float_array_to_uchar.h index 2cc3993d50..97e2412d84 100644 --- a/gr-blocks/lib/float_array_to_uchar.h +++ b/gr-blocks/lib/float_array_to_uchar.h @@ -28,6 +28,6 @@ /*! * convert array of floats to unsigned chars with rounding and saturation. */ -BLOCKS_API void float_array_to_uchar (const float *in, unsigned char *out, int nsamples); +BLOCKS_API void float_array_to_uchar(const float* in, unsigned char* out, int nsamples); #endif /* INCLUDED_FLOAT_ARRAY_TO_UCHAR_H */ diff --git a/gr-blocks/lib/float_to_char_impl.cc b/gr-blocks/lib/float_to_char_impl.cc index 342187d3ee..c54c023c6e 100644 --- a/gr-blocks/lib/float_to_char_impl.cc +++ b/gr-blocks/lib/float_to_char_impl.cc @@ -29,36 +29,35 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - float_to_char::sptr float_to_char::make(size_t vlen, float scale) - { - return gnuradio::get_initial_sptr(new float_to_char_impl(vlen, scale)); - } - - float_to_char_impl::float_to_char_impl(size_t vlen, float scale) - : sync_block("float_to_char", - io_signature::make (1, 1, sizeof(float)*vlen), - io_signature::make (1, 1, sizeof(char)*vlen)), - d_vlen(vlen), d_scale(scale) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(char); - set_alignment(std::max(1, alignment_multiple)); - } - - int - float_to_char_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float *) input_items[0]; - int8_t *out = (int8_t *) output_items[0]; - - volk_32f_s32f_convert_8i(out, in, d_scale, d_vlen*noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +float_to_char::sptr float_to_char::make(size_t vlen, float scale) +{ + return gnuradio::get_initial_sptr(new float_to_char_impl(vlen, scale)); +} + +float_to_char_impl::float_to_char_impl(size_t vlen, float scale) + : sync_block("float_to_char", + io_signature::make(1, 1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(char) * vlen)), + d_vlen(vlen), + d_scale(scale) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(char); + set_alignment(std::max(1, alignment_multiple)); +} + +int float_to_char_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + int8_t* out = (int8_t*)output_items[0]; + + volk_32f_s32f_convert_8i(out, in, d_scale, d_vlen * noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/float_to_char_impl.h b/gr-blocks/lib/float_to_char_impl.h index 99376990c5..d7b7c3b1d6 100644 --- a/gr-blocks/lib/float_to_char_impl.h +++ b/gr-blocks/lib/float_to_char_impl.h @@ -26,25 +26,25 @@ #include <gnuradio/blocks/float_to_char.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API float_to_char_impl : public float_to_char - { - size_t d_vlen; - float d_scale; +class BLOCKS_API float_to_char_impl : public float_to_char +{ + size_t d_vlen; + float d_scale; - public: - float_to_char_impl(size_t vlen, float scale); +public: + float_to_char_impl(size_t vlen, float scale); - virtual float scale() const { return d_scale; } - virtual void set_scale(float scale) { d_scale = scale; } + virtual float scale() const { return d_scale; } + virtual void set_scale(float scale) { d_scale = scale; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/float_to_complex_impl.cc b/gr-blocks/lib/float_to_complex_impl.cc index d66d05a327..dc2a8d3491 100644 --- a/gr-blocks/lib/float_to_complex_impl.cc +++ b/gr-blocks/lib/float_to_complex_impl.cc @@ -29,55 +29,50 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - float_to_complex::sptr - float_to_complex::make(size_t vlen) - { - return gnuradio::get_initial_sptr - (new float_to_complex_impl(vlen)); - } - - float_to_complex_impl::float_to_complex_impl(size_t vlen) - : sync_block("float_to_complex", - io_signature::make(1, 2, sizeof(float)*vlen), - io_signature::make(1, 1, sizeof(gr_complex)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } +float_to_complex::sptr float_to_complex::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new float_to_complex_impl(vlen)); +} - int - float_to_complex_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float *r = (float *) input_items[0]; - gr_complex *out = (gr_complex *) output_items[0]; +float_to_complex_impl::float_to_complex_impl(size_t vlen) + : sync_block("float_to_complex", + io_signature::make(1, 2, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(gr_complex) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} - switch (input_items.size ()){ - case 1: - for (size_t j = 0; j < noutput_items*d_vlen; j++) - out[j] = gr_complex (r[j], 0); - break; +int float_to_complex_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float* r = (float*)input_items[0]; + gr_complex* out = (gr_complex*)output_items[0]; - case 2: - { - //for (size_t j = 0; j < noutput_items*d_vlen; j++) - // out[j] = gr_complex (r[j], i[j]); - float *i = (float *) input_items[1]; - volk_32f_x2_interleave_32fc(out, r, i, noutput_items*d_vlen); - break; - } + switch (input_items.size()) { + case 1: + for (size_t j = 0; j < noutput_items * d_vlen; j++) + out[j] = gr_complex(r[j], 0); + break; - default: - assert (0); - } + case 2: { + // for (size_t j = 0; j < noutput_items*d_vlen; j++) + // out[j] = gr_complex (r[j], i[j]); + float* i = (float*)input_items[1]; + volk_32f_x2_interleave_32fc(out, r, i, noutput_items * d_vlen); + break; + } - return noutput_items; + default: + assert(0); } - } /* namespace blocks */ -}/* namespace gr */ + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/float_to_complex_impl.h b/gr-blocks/lib/float_to_complex_impl.h index 6e14aba4e5..9219fa1516 100644 --- a/gr-blocks/lib/float_to_complex_impl.h +++ b/gr-blocks/lib/float_to_complex_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/float_to_complex.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API float_to_complex_impl : public float_to_complex - { - size_t d_vlen; +class BLOCKS_API float_to_complex_impl : public float_to_complex +{ + size_t d_vlen; - public: - float_to_complex_impl(size_t vlen); +public: + float_to_complex_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/float_to_int_impl.cc b/gr-blocks/lib/float_to_int_impl.cc index 0dbef975bb..4c8ae689d8 100644 --- a/gr-blocks/lib/float_to_int_impl.cc +++ b/gr-blocks/lib/float_to_int_impl.cc @@ -30,49 +30,48 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - float_to_int::sptr float_to_int::make(size_t vlen, float scale) - { - return gnuradio::get_initial_sptr(new float_to_int_impl(vlen, scale)); - } +float_to_int::sptr float_to_int::make(size_t vlen, float scale) +{ + return gnuradio::get_initial_sptr(new float_to_int_impl(vlen, scale)); +} - float_to_int_impl::float_to_int_impl(size_t vlen, float scale) - : sync_block("float_to_int", - io_signature::make (1, 1, sizeof(float)*vlen), - io_signature::make (1, 1, sizeof(int)*vlen)), - d_vlen(vlen), d_scale(scale) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(int); - set_alignment(std::max(1, alignment_multiple)); - } +float_to_int_impl::float_to_int_impl(size_t vlen, float scale) + : sync_block("float_to_int", + io_signature::make(1, 1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(int) * vlen)), + d_vlen(vlen), + d_scale(scale) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(int); + set_alignment(std::max(1, alignment_multiple)); +} - int - float_to_int_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - // Disable the Volk for now. There is a problem for large 32-bit ints that - // are not properly represented by the precisions of a single float, which - // can cause wrapping from large, positive numbers to negative. - // In gri_float_to_int, the value is first promoted to a 64-bit - // value, clipped, then converted to a float. +int float_to_int_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + // Disable the Volk for now. There is a problem for large 32-bit ints that + // are not properly represented by the precisions of a single float, which + // can cause wrapping from large, positive numbers to negative. + // In gri_float_to_int, the value is first promoted to a 64-bit + // value, clipped, then converted to a float. #if 0 const float *in = (const float *) input_items[0]; int32_t *out = (int32_t *) output_items[0]; volk_32f_s32f_convert_32i(out, in, d_scale, d_vlen*noutput_items); #else - const float *in = (const float *) input_items[0]; - int *out = (int *) output_items[0]; + const float* in = (const float*)input_items[0]; + int* out = (int*)output_items[0]; - float_array_to_int (in, out, d_scale, d_vlen*noutput_items); + float_array_to_int(in, out, d_scale, d_vlen * noutput_items); #endif - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/float_to_int_impl.h b/gr-blocks/lib/float_to_int_impl.h index 7062672738..4bc237313c 100644 --- a/gr-blocks/lib/float_to_int_impl.h +++ b/gr-blocks/lib/float_to_int_impl.h @@ -26,25 +26,25 @@ #include <gnuradio/blocks/float_to_int.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API float_to_int_impl : public float_to_int - { - size_t d_vlen; - float d_scale; +class BLOCKS_API float_to_int_impl : public float_to_int +{ + size_t d_vlen; + float d_scale; - public: - float_to_int_impl(size_t vlen, float scale); +public: + float_to_int_impl(size_t vlen, float scale); - virtual float scale() const { return d_scale; } - virtual void set_scale(float scale) { d_scale = scale; } + virtual float scale() const { return d_scale; } + virtual void set_scale(float scale) { d_scale = scale; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/float_to_short_impl.cc b/gr-blocks/lib/float_to_short_impl.cc index 791519002f..a9eef40292 100644 --- a/gr-blocks/lib/float_to_short_impl.cc +++ b/gr-blocks/lib/float_to_short_impl.cc @@ -29,36 +29,35 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - float_to_short::sptr float_to_short::make(size_t vlen, float scale) - { - return gnuradio::get_initial_sptr(new float_to_short_impl(vlen, scale)); - } - - float_to_short_impl::float_to_short_impl(size_t vlen, float scale) - : sync_block("float_to_short", - io_signature::make (1, 1, sizeof(float)*vlen), - io_signature::make (1, 1, sizeof(short)*vlen)), - d_vlen(vlen), d_scale(scale) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(short); - set_alignment(std::max(1, alignment_multiple)); - } - - int - float_to_short_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float *) input_items[0]; - short *out = (short *) output_items[0]; - - volk_32f_s32f_convert_16i(out, in, d_scale, d_vlen*noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +float_to_short::sptr float_to_short::make(size_t vlen, float scale) +{ + return gnuradio::get_initial_sptr(new float_to_short_impl(vlen, scale)); +} + +float_to_short_impl::float_to_short_impl(size_t vlen, float scale) + : sync_block("float_to_short", + io_signature::make(1, 1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(short) * vlen)), + d_vlen(vlen), + d_scale(scale) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(short); + set_alignment(std::max(1, alignment_multiple)); +} + +int float_to_short_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + short* out = (short*)output_items[0]; + + volk_32f_s32f_convert_16i(out, in, d_scale, d_vlen * noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/float_to_short_impl.h b/gr-blocks/lib/float_to_short_impl.h index fb88092937..c6dbc0a8fb 100644 --- a/gr-blocks/lib/float_to_short_impl.h +++ b/gr-blocks/lib/float_to_short_impl.h @@ -26,25 +26,25 @@ #include <gnuradio/blocks/float_to_short.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API float_to_short_impl : public float_to_short - { - size_t d_vlen; - float d_scale; +class BLOCKS_API float_to_short_impl : public float_to_short +{ + size_t d_vlen; + float d_scale; - public: - float_to_short_impl(size_t vlen, float scale); +public: + float_to_short_impl(size_t vlen, float scale); - virtual float scale() const { return d_scale; } - virtual void set_scale(float scale) { d_scale = scale; } + virtual float scale() const { return d_scale; } + virtual void set_scale(float scale) { d_scale = scale; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/float_to_uchar_impl.cc b/gr-blocks/lib/float_to_uchar_impl.cc index eccd36da78..ad75df9eff 100644 --- a/gr-blocks/lib/float_to_uchar_impl.cc +++ b/gr-blocks/lib/float_to_uchar_impl.cc @@ -29,32 +29,31 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - float_to_uchar::sptr float_to_uchar::make() - { - return gnuradio::get_initial_sptr(new float_to_uchar_impl()); - } - - float_to_uchar_impl::float_to_uchar_impl() - : sync_block("float_to_uchar", - io_signature::make (1, 1, sizeof(float)), - io_signature::make (1, 1, sizeof(unsigned char))) - { - } - - int - float_to_uchar_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float *)input_items[0]; - unsigned char *out = (unsigned char *)output_items[0]; - - float_array_to_uchar(in, out, noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +float_to_uchar::sptr float_to_uchar::make() +{ + return gnuradio::get_initial_sptr(new float_to_uchar_impl()); +} + +float_to_uchar_impl::float_to_uchar_impl() + : sync_block("float_to_uchar", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(unsigned char))) +{ +} + +int float_to_uchar_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; + + float_array_to_uchar(in, out, noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/float_to_uchar_impl.h b/gr-blocks/lib/float_to_uchar_impl.h index 1e60ae8ebd..f555a6b8be 100644 --- a/gr-blocks/lib/float_to_uchar_impl.h +++ b/gr-blocks/lib/float_to_uchar_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/float_to_uchar.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API float_to_uchar_impl : public float_to_uchar - { - public: - float_to_uchar_impl(); +class BLOCKS_API float_to_uchar_impl : public float_to_uchar +{ +public: + float_to_uchar_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/head_impl.cc b/gr-blocks/lib/head_impl.cc index 4c33f9f08e..83dc855f55 100644 --- a/gr-blocks/lib/head_impl.cc +++ b/gr-blocks/lib/head_impl.cc @@ -29,47 +29,41 @@ #include <string.h> namespace gr { - namespace blocks { +namespace blocks { - head::sptr - head::make(size_t sizeof_stream_item, uint64_t nitems) - { - return gnuradio::get_initial_sptr - (new head_impl(sizeof_stream_item, nitems)); - } +head::sptr head::make(size_t sizeof_stream_item, uint64_t nitems) +{ + return gnuradio::get_initial_sptr(new head_impl(sizeof_stream_item, nitems)); +} - head_impl::head_impl(size_t sizeof_stream_item, uint64_t nitems) - : sync_block("head", - io_signature::make(1, 1, sizeof_stream_item), - io_signature::make(1, 1, sizeof_stream_item)), - d_nitems(nitems), d_ncopied_items(0) - { - } +head_impl::head_impl(size_t sizeof_stream_item, uint64_t nitems) + : sync_block("head", + io_signature::make(1, 1, sizeof_stream_item), + io_signature::make(1, 1, sizeof_stream_item)), + d_nitems(nitems), + d_ncopied_items(0) +{ +} - head_impl::~head_impl() - { - } +head_impl::~head_impl() {} - int - head_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - if(d_ncopied_items >= d_nitems) - return -1; // Done! +int head_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + if (d_ncopied_items >= d_nitems) + return -1; // Done! - unsigned n = std::min(d_nitems - d_ncopied_items, - (uint64_t)noutput_items); + unsigned n = std::min(d_nitems - d_ncopied_items, (uint64_t)noutput_items); - if(n == 0) + if (n == 0) return 0; - memcpy(output_items[0], input_items[0], - n * input_signature()->sizeof_stream_item (0)); - d_ncopied_items += n; + memcpy(output_items[0], input_items[0], n * input_signature()->sizeof_stream_item(0)); + d_ncopied_items += n; - return n; - } + return n; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/head_impl.h b/gr-blocks/lib/head_impl.h index 4a2c33864b..0925bbdd26 100644 --- a/gr-blocks/lib/head_impl.h +++ b/gr-blocks/lib/head_impl.h @@ -26,27 +26,27 @@ #include <gnuradio/blocks/head.h> namespace gr { - namespace blocks { +namespace blocks { - class head_impl : public head - { - private: - uint64_t d_nitems; - uint64_t d_ncopied_items; +class head_impl : public head +{ +private: + uint64_t d_nitems; + uint64_t d_ncopied_items; - public: - head_impl(size_t sizeof_stream_item, uint64_t nitems); - ~head_impl(); +public: + head_impl(size_t sizeof_stream_item, uint64_t nitems); + ~head_impl(); - void reset() { d_ncopied_items = 0; } - void set_length(uint64_t nitems) { d_nitems = nitems; } + void reset() { d_ncopied_items = 0; } + void set_length(uint64_t nitems) { d_nitems = nitems; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_HEAD_IMPL_H */ diff --git a/gr-blocks/lib/int_to_float_impl.cc b/gr-blocks/lib/int_to_float_impl.cc index 33b59e9f4b..64338ce1e5 100644 --- a/gr-blocks/lib/int_to_float_impl.cc +++ b/gr-blocks/lib/int_to_float_impl.cc @@ -29,35 +29,34 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - int_to_float::sptr int_to_float::make(size_t vlen, float scale) - { - return gnuradio::get_initial_sptr(new int_to_float_impl(vlen, scale)); - } - - int_to_float_impl::int_to_float_impl(size_t vlen, float scale) - : sync_block("int_to_float", - io_signature::make (1, 1, sizeof(int32_t)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen), d_scale(scale) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1, alignment_multiple)); - } - - int - int_to_float_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const int32_t *in = (const int32_t *) input_items[0]; - float *out = (float *) output_items[0]; - - volk_32i_s32f_convert_32f(out, in, d_scale, d_vlen*noutput_items); - - return noutput_items; - } - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +int_to_float::sptr int_to_float::make(size_t vlen, float scale) +{ + return gnuradio::get_initial_sptr(new int_to_float_impl(vlen, scale)); +} + +int_to_float_impl::int_to_float_impl(size_t vlen, float scale) + : sync_block("int_to_float", + io_signature::make(1, 1, sizeof(int32_t) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen), + d_scale(scale) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +int int_to_float_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const int32_t* in = (const int32_t*)input_items[0]; + float* out = (float*)output_items[0]; + + volk_32i_s32f_convert_32f(out, in, d_scale, d_vlen * noutput_items); + + return noutput_items; +} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/int_to_float_impl.h b/gr-blocks/lib/int_to_float_impl.h index 53942b1488..6e09585329 100644 --- a/gr-blocks/lib/int_to_float_impl.h +++ b/gr-blocks/lib/int_to_float_impl.h @@ -26,25 +26,25 @@ #include <gnuradio/blocks/int_to_float.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API int_to_float_impl : public int_to_float - { - size_t d_vlen; - float d_scale; +class BLOCKS_API int_to_float_impl : public int_to_float +{ + size_t d_vlen; + float d_scale; - public: - int_to_float_impl(size_t vlen, float scale); +public: + int_to_float_impl(size_t vlen, float scale); - virtual float scale() const { return d_scale; } - virtual void set_scale(float scale) { d_scale = scale; } + virtual float scale() const { return d_scale; } + virtual void set_scale(float scale) { d_scale = scale; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/integrate_impl.cc b/gr-blocks/lib/integrate_impl.cc index 3fe3a376c6..499a854b11 100644 --- a/gr-blocks/lib/integrate_impl.cc +++ b/gr-blocks/lib/integrate_impl.cc @@ -29,51 +29,50 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename integrate<T>::sptr integrate<T>::make(int decim, unsigned int vlen) - { - return gnuradio::get_initial_sptr(new integrate_impl<T> (decim, vlen)); - } +template <class T> +typename integrate<T>::sptr integrate<T>::make(int decim, unsigned int vlen) +{ + return gnuradio::get_initial_sptr(new integrate_impl<T>(decim, vlen)); +} - template <class T> - integrate_impl<T> ::integrate_impl(int decim, unsigned int vlen) - : sync_decimator("integrate", - io_signature::make(1, 1, sizeof (T) * vlen), - io_signature::make(1, 1, sizeof (T) * vlen), - decim), +template <class T> +integrate_impl<T>::integrate_impl(int decim, unsigned int vlen) + : sync_decimator("integrate", + io_signature::make(1, 1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen), + decim), d_decim(decim), d_vlen(vlen) - { - } +{ +} - template <class T> - int - integrate_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const T *in = (const T *)input_items[0]; - T *out = (T *)output_items[0]; +template <class T> +int integrate_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const T* in = (const T*)input_items[0]; + T* out = (T*)output_items[0]; - for (int i = 0; i < noutput_items; i++) { + for (int i = 0; i < noutput_items; i++) { for (unsigned int j = 0; j < d_vlen; ++j) { - out[i*d_vlen + j] = (T)0; + out[i * d_vlen + j] = (T)0; } for (int j = 0; j < d_decim; j++) { - for (unsigned int k = 0; k < d_vlen; ++k) { - out[i*d_vlen + k] += in[i*d_decim*d_vlen + j*d_vlen + k]; - } + for (unsigned int k = 0; k < d_vlen; ++k) { + out[i * d_vlen + k] += in[i * d_decim * d_vlen + j * d_vlen + k]; + } } - } - - return noutput_items; } + return noutput_items; +} + template class integrate<std::int16_t>; template class integrate<std::int32_t>; template class integrate<float>; template class integrate<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/integrate_impl.h b/gr-blocks/lib/integrate_impl.h index 30c2142f42..ae0ee841f7 100644 --- a/gr-blocks/lib/integrate_impl.h +++ b/gr-blocks/lib/integrate_impl.h @@ -27,23 +27,23 @@ #include <gnuradio/blocks/integrate.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> -class BLOCKS_API integrate_impl : public integrate<T> - { - int d_decim; - unsigned int d_vlen; +template <class T> +class BLOCKS_API integrate_impl : public integrate<T> +{ + int d_decim; + unsigned int d_vlen; - public: - integrate_impl (int decim, unsigned int vlen); +public: + integrate_impl(int decim, unsigned int vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INTEGRATE_IMPL_H */ diff --git a/gr-blocks/lib/interleave_impl.cc b/gr-blocks/lib/interleave_impl.cc index be0b1c6f73..fac81feeca 100644 --- a/gr-blocks/lib/interleave_impl.cc +++ b/gr-blocks/lib/interleave_impl.cc @@ -28,77 +28,70 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - interleave::sptr interleave::make(size_t itemsize, unsigned int blocksize) - { - return gnuradio::get_initial_sptr(new interleave_impl(itemsize, blocksize)); - } - - interleave_impl::interleave_impl(size_t itemsize, unsigned int blocksize) - : block("interleave", - io_signature::make (1, io_signature::IO_INFINITE, itemsize), - io_signature::make (1, 1, itemsize)), - d_itemsize(itemsize), d_blocksize(blocksize) - { - set_fixed_rate(true); - set_output_multiple(d_blocksize); - } - - bool - interleave_impl::check_topology(int ninputs, int noutputs) - { - set_relative_rate((uint64_t)ninputs, 1); - d_ninputs = ninputs; - set_output_multiple(d_blocksize * d_ninputs); - return true; - } - - - int - interleave_impl::fixed_rate_ninput_to_noutput(int ninput) - { - return ninput * d_ninputs; - } - - int - interleave_impl::fixed_rate_noutput_to_ninput(int noutput) - { - return (noutput / d_ninputs); - } - - void - interleave_impl::forecast(int noutput_items, - gr_vector_int& ninput_items_required) - { - for(unsigned int i = 0; i < ninput_items_required.size(); ++i) { +namespace blocks { + +interleave::sptr interleave::make(size_t itemsize, unsigned int blocksize) +{ + return gnuradio::get_initial_sptr(new interleave_impl(itemsize, blocksize)); +} + +interleave_impl::interleave_impl(size_t itemsize, unsigned int blocksize) + : block("interleave", + io_signature::make(1, io_signature::IO_INFINITE, itemsize), + io_signature::make(1, 1, itemsize)), + d_itemsize(itemsize), + d_blocksize(blocksize) +{ + set_fixed_rate(true); + set_output_multiple(d_blocksize); +} + +bool interleave_impl::check_topology(int ninputs, int noutputs) +{ + set_relative_rate((uint64_t)ninputs, 1); + d_ninputs = ninputs; + set_output_multiple(d_blocksize * d_ninputs); + return true; +} + + +int interleave_impl::fixed_rate_ninput_to_noutput(int ninput) +{ + return ninput * d_ninputs; +} + +int interleave_impl::fixed_rate_noutput_to_ninput(int noutput) +{ + return (noutput / d_ninputs); +} + +void interleave_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required) +{ + for (unsigned int i = 0; i < ninput_items_required.size(); ++i) { ninput_items_required[i] = noutput_items / ninput_items_required.size(); - } } +} - int - interleave_impl::general_work(int noutput_items, +int interleave_impl::general_work(int noutput_items, gr_vector_int& ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - size_t noutput_blocks = (size_t) (noutput_items/d_blocksize); - const char **in = (const char**)&input_items[0]; - char *out = (char*)output_items[0]; - - for (unsigned int i = 0; i < noutput_blocks; i += d_ninputs) { - for (unsigned int n = 0; n < d_ninputs; n++){ - memcpy(out, in[n], d_itemsize * d_blocksize); - out += d_itemsize * d_blocksize; - in[n] += d_itemsize * d_blocksize; + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + size_t noutput_blocks = (size_t)(noutput_items / d_blocksize); + const char** in = (const char**)&input_items[0]; + char* out = (char*)output_items[0]; + + for (unsigned int i = 0; i < noutput_blocks; i += d_ninputs) { + for (unsigned int n = 0; n < d_ninputs; n++) { + memcpy(out, in[n], d_itemsize * d_blocksize); + out += d_itemsize * d_blocksize; + in[n] += d_itemsize * d_blocksize; } - } - consume_each(noutput_items/d_ninputs); - return noutput_items; } + consume_each(noutput_items / d_ninputs); + return noutput_items; +} - - - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/interleave_impl.h b/gr-blocks/lib/interleave_impl.h index 7675259c8e..ad010fef36 100644 --- a/gr-blocks/lib/interleave_impl.h +++ b/gr-blocks/lib/interleave_impl.h @@ -26,37 +26,36 @@ #include <gnuradio/blocks/interleave.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API interleave_impl : public interleave - { - size_t d_itemsize; - unsigned int d_blocksize; - unsigned int d_ninputs; +class BLOCKS_API interleave_impl : public interleave +{ + size_t d_itemsize; + unsigned int d_blocksize; + unsigned int d_ninputs; - public: - interleave_impl(size_t itemsize, unsigned int blocksize); +public: + interleave_impl(size_t itemsize, unsigned int blocksize); - bool check_topology(int ninputs, int noutputs); + bool check_topology(int ninputs, int noutputs); - int fixed_rate_ninput_to_noutput(int ninput); + int fixed_rate_ninput_to_noutput(int ninput); - int fixed_rate_noutput_to_ninput(int noutput); + int fixed_rate_noutput_to_ninput(int noutput); - void forecast(int noutput_items, - gr_vector_int& ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - int general_work(int noutput_items, - gr_vector_int& ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/interleaved_char_to_complex_impl.cc b/gr-blocks/lib/interleaved_char_to_complex_impl.cc index ab6364a6d4..ad11b883fa 100644 --- a/gr-blocks/lib/interleaved_char_to_complex_impl.cc +++ b/gr-blocks/lib/interleaved_char_to_complex_impl.cc @@ -29,36 +29,34 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - interleaved_char_to_complex::sptr interleaved_char_to_complex::make(bool vector_input) - { - return gnuradio::get_initial_sptr(new interleaved_char_to_complex_impl(vector_input)); - } - - interleaved_char_to_complex_impl::interleaved_char_to_complex_impl(bool vector_input) - : sync_decimator("interleaved_char_to_complex", - gr::io_signature::make (1, 1, (vector_input?2:1)*sizeof(char)), - gr::io_signature::make (1, 1, sizeof(gr_complex)), - vector_input?1:2) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(std::max(1, alignment_multiple)); - } - - int - interleaved_char_to_complex_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const int8_t *in = (const int8_t *) input_items[0]; - float *out = (float *) output_items[0]; - - volk_8i_s32f_convert_32f_u(out, in, 1.0, 2*noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +interleaved_char_to_complex::sptr interleaved_char_to_complex::make(bool vector_input) +{ + return gnuradio::get_initial_sptr(new interleaved_char_to_complex_impl(vector_input)); +} + +interleaved_char_to_complex_impl::interleaved_char_to_complex_impl(bool vector_input) + : sync_decimator("interleaved_char_to_complex", + gr::io_signature::make(1, 1, (vector_input ? 2 : 1) * sizeof(char)), + gr::io_signature::make(1, 1, sizeof(gr_complex)), + vector_input ? 1 : 2) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); +} + +int interleaved_char_to_complex_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const int8_t* in = (const int8_t*)input_items[0]; + float* out = (float*)output_items[0]; + + volk_8i_s32f_convert_32f_u(out, in, 1.0, 2 * noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/interleaved_char_to_complex_impl.h b/gr-blocks/lib/interleaved_char_to_complex_impl.h index f07805788c..979e24be3d 100644 --- a/gr-blocks/lib/interleaved_char_to_complex_impl.h +++ b/gr-blocks/lib/interleaved_char_to_complex_impl.h @@ -26,20 +26,20 @@ #include <gnuradio/blocks/interleaved_char_to_complex.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API interleaved_char_to_complex_impl : public interleaved_char_to_complex - { - private: - public: - interleaved_char_to_complex_impl(bool vector_input=false); +class BLOCKS_API interleaved_char_to_complex_impl : public interleaved_char_to_complex +{ +private: +public: + interleaved_char_to_complex_impl(bool vector_input = false); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/interleaved_short_array_to_complex.cc b/gr-blocks/lib/interleaved_short_array_to_complex.cc index 4aac6208a1..78653c76c2 100644 --- a/gr-blocks/lib/interleaved_short_array_to_complex.cc +++ b/gr-blocks/lib/interleaved_short_array_to_complex.cc @@ -28,10 +28,8 @@ #include <assert.h> #include <volk/volk.h> -void -interleaved_short_array_to_complex (const short *in, - gr_complex *out, int nsamples) +void interleaved_short_array_to_complex(const short* in, gr_complex* out, int nsamples) { - assert (nsamples % 2 == 0); - volk_16i_s32f_convert_32f_u( (float*)out, (const int16_t*) in, 1, nsamples ); + assert(nsamples % 2 == 0); + volk_16i_s32f_convert_32f_u((float*)out, (const int16_t*)in, 1, nsamples); } diff --git a/gr-blocks/lib/interleaved_short_array_to_complex.h b/gr-blocks/lib/interleaved_short_array_to_complex.h index 33f70ccdfa..04a1f785d9 100644 --- a/gr-blocks/lib/interleaved_short_array_to_complex.h +++ b/gr-blocks/lib/interleaved_short_array_to_complex.h @@ -31,6 +31,7 @@ * the shorts contains real, imaginary, real, imaginary... * nsamples is the number of shorts; it must be even. */ -BLOCKS_API void interleaved_short_array_to_complex (const short *in, gr_complex *out, int nsamples); +BLOCKS_API void +interleaved_short_array_to_complex(const short* in, gr_complex* out, int nsamples); #endif /* INCLUDED_INTERLEAVED_SHORT_ARRAY_TO_COMPLEX_H */ diff --git a/gr-blocks/lib/interleaved_short_to_complex_impl.cc b/gr-blocks/lib/interleaved_short_to_complex_impl.cc index ca0dfc9064..ada88cd34a 100644 --- a/gr-blocks/lib/interleaved_short_to_complex_impl.cc +++ b/gr-blocks/lib/interleaved_short_to_complex_impl.cc @@ -29,48 +29,47 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - interleaved_short_to_complex::sptr interleaved_short_to_complex::make(bool vector_input, bool swap) - { - return gnuradio::get_initial_sptr(new interleaved_short_to_complex_impl(vector_input, swap)); - } +interleaved_short_to_complex::sptr interleaved_short_to_complex::make(bool vector_input, + bool swap) +{ + return gnuradio::get_initial_sptr( + new interleaved_short_to_complex_impl(vector_input, swap)); +} - interleaved_short_to_complex_impl::interleaved_short_to_complex_impl(bool vector_input, bool swap) - : sync_decimator("interleaved_short_to_complex", - gr::io_signature::make (1, 1, (vector_input?2:1)*sizeof(short)), - gr::io_signature::make (1, 1, sizeof(gr_complex)), - vector_input?1:2), - d_swap(swap) - { - } +interleaved_short_to_complex_impl::interleaved_short_to_complex_impl(bool vector_input, + bool swap) + : sync_decimator("interleaved_short_to_complex", + gr::io_signature::make(1, 1, (vector_input ? 2 : 1) * sizeof(short)), + gr::io_signature::make(1, 1, sizeof(gr_complex)), + vector_input ? 1 : 2), + d_swap(swap) +{ +} - void interleaved_short_to_complex_impl::set_swap(bool swap) - { - d_swap = swap; - } +void interleaved_short_to_complex_impl::set_swap(bool swap) { d_swap = swap; } - int - interleaved_short_to_complex_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short *) input_items[0]; - gr_complex *out = (gr_complex *) output_items[0]; +int interleaved_short_to_complex_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + gr_complex* out = (gr_complex*)output_items[0]; - interleaved_short_array_to_complex (in, out, 2 * noutput_items); + interleaved_short_array_to_complex(in, out, 2 * noutput_items); - if (d_swap) { + if (d_swap) { float* p = (float*)output_items[0]; for (int i = 0; i < noutput_items; ++i) { - float f = p[2*i+1]; - p[2*i+1] = p[2*i+0]; - p[2*i+0] = f; + float f = p[2 * i + 1]; + p[2 * i + 1] = p[2 * i + 0]; + p[2 * i + 0] = f; } - } - - return noutput_items; } - } /* namespace blocks */ -}/* namespace gr */ + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/interleaved_short_to_complex_impl.h b/gr-blocks/lib/interleaved_short_to_complex_impl.h index 7a3ca419c9..2dea401c58 100644 --- a/gr-blocks/lib/interleaved_short_to_complex_impl.h +++ b/gr-blocks/lib/interleaved_short_to_complex_impl.h @@ -26,23 +26,24 @@ #include <gnuradio/blocks/interleaved_short_to_complex.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API interleaved_short_to_complex_impl : public interleaved_short_to_complex - { - private: - bool d_swap; - public: - interleaved_short_to_complex_impl(bool vector_input=false, bool swap=false); +class BLOCKS_API interleaved_short_to_complex_impl : public interleaved_short_to_complex +{ +private: + bool d_swap; - void set_swap(bool swap); +public: + interleaved_short_to_complex_impl(bool vector_input = false, bool swap = false); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + void set_swap(bool swap); - } /* namespace blocks */ + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/keep_m_in_n_impl.cc b/gr-blocks/lib/keep_m_in_n_impl.cc index 2c67af9c34..d502fcebe8 100644 --- a/gr-blocks/lib/keep_m_in_n_impl.cc +++ b/gr-blocks/lib/keep_m_in_n_impl.cc @@ -28,108 +28,101 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - keep_m_in_n::sptr - keep_m_in_n::make(size_t itemsize, int m, int n, int offset) - { - return gnuradio::get_initial_sptr - (new keep_m_in_n_impl(itemsize, m, n, offset)); - } +keep_m_in_n::sptr keep_m_in_n::make(size_t itemsize, int m, int n, int offset) +{ + return gnuradio::get_initial_sptr(new keep_m_in_n_impl(itemsize, m, n, offset)); +} - keep_m_in_n_impl::keep_m_in_n_impl(size_t itemsize, int m, int n, int offset) - : block("keep_m_in_n", - io_signature::make (1, 1, itemsize), - io_signature::make (1, 1, itemsize)), - d_m(m), - d_n(n), - d_offset(offset), - d_itemsize(itemsize) - { - // sanity checking - if(d_m <= 0) { - std::string s = boost::str(boost::format("keep_m_in_n: m=%1% but must be > 0") % d_m); +keep_m_in_n_impl::keep_m_in_n_impl(size_t itemsize, int m, int n, int offset) + : block("keep_m_in_n", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize)), + d_m(m), + d_n(n), + d_offset(offset), + d_itemsize(itemsize) +{ + // sanity checking + if (d_m <= 0) { + std::string s = + boost::str(boost::format("keep_m_in_n: m=%1% but must be > 0") % d_m); throw std::runtime_error(s); - } - if(d_n <= 0) { - std::string s = boost::str(boost::format("keep_m_in_n: n=%1% but must be > 0") % d_n); + } + if (d_n <= 0) { + std::string s = + boost::str(boost::format("keep_m_in_n: n=%1% but must be > 0") % d_n); throw std::runtime_error(s); - } - if(d_m > d_n) { - std::string s = boost::str(boost::format("keep_m_in_n: m (%1%) <= n %2%") % d_m % d_n); + } + if (d_m > d_n) { + std::string s = + boost::str(boost::format("keep_m_in_n: m (%1%) <= n %2%") % d_m % d_n); throw std::runtime_error(s); - } - if(d_offset < 0) { - std::string s = boost::str(boost::format("keep_m_in_n: offset (%1%) must be >= 0") \ - % d_offset); + } + if (d_offset < 0) { + std::string s = boost::str( + boost::format("keep_m_in_n: offset (%1%) must be >= 0") % d_offset); throw std::runtime_error(s); - } - if(d_offset >= d_n) { - std::string s = boost::str(boost::format("keep_m_in_n: offset (%1%) < n (%2%)") \ - % d_offset % d_n); + } + if (d_offset >= d_n) { + std::string s = boost::str(boost::format("keep_m_in_n: offset (%1%) < n (%2%)") % + d_offset % d_n); throw std::runtime_error(s); - } - - set_output_multiple(m); - set_relative_rate(static_cast<uint64_t>(d_m), static_cast<uint64_t>(d_n)); } - void - keep_m_in_n_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required) - { - ninput_items_required[0] = d_n*(noutput_items/d_m); - } + set_output_multiple(m); + set_relative_rate(static_cast<uint64_t>(d_m), static_cast<uint64_t>(d_n)); +} - void - keep_m_in_n_impl::set_m(int m) - { - d_m = m; - set_output_multiple(m); - set_relative_rate(static_cast<uint64_t>(d_m), static_cast<uint64_t>(d_n)); - } +void keep_m_in_n_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required) +{ + ninput_items_required[0] = d_n * (noutput_items / d_m); +} - void - keep_m_in_n_impl::set_n(int n) - { - d_n = n; - set_relative_rate(static_cast<uint64_t>(d_m), static_cast<uint64_t>(d_n)); - } +void keep_m_in_n_impl::set_m(int m) +{ + d_m = m; + set_output_multiple(m); + set_relative_rate(static_cast<uint64_t>(d_m), static_cast<uint64_t>(d_n)); +} - void - keep_m_in_n_impl::set_offset(int offset) - { - d_offset = offset; - } +void keep_m_in_n_impl::set_n(int n) +{ + d_n = n; + set_relative_rate(static_cast<uint64_t>(d_m), static_cast<uint64_t>(d_n)); +} - int - keep_m_in_n_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - uint8_t* out = (uint8_t*)output_items[0]; - const uint8_t* in = (const uint8_t*)input_items[0]; +void keep_m_in_n_impl::set_offset(int offset) { d_offset = offset; } - // iterate over data blocks of size {n, input : m, output} - int blks = std::min(noutput_items/d_m, ninput_items[0]/d_n); - int excess = (d_offset + d_m - d_n) * d_itemsize; +int keep_m_in_n_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + uint8_t* out = (uint8_t*)output_items[0]; + const uint8_t* in = (const uint8_t*)input_items[0]; - for(int i=0; i<blks; i++) { + // iterate over data blocks of size {n, input : m, output} + int blks = std::min(noutput_items / d_m, ninput_items[0] / d_n); + int excess = (d_offset + d_m - d_n) * d_itemsize; + + for (int i = 0; i < blks; i++) { // set up copy pointers - const uint8_t* iptr = &in[(i*d_n + d_offset)*d_itemsize]; - uint8_t* optr = &out[i*d_m*d_itemsize]; + const uint8_t* iptr = &in[(i * d_n + d_offset) * d_itemsize]; + uint8_t* optr = &out[i * d_m * d_itemsize]; // perform copy - if(excess <= 0) { - memcpy( optr, iptr, d_m*d_itemsize ); + if (excess <= 0) { + memcpy(optr, iptr, d_m * d_itemsize); } else { - memcpy( optr, &in[i*d_n*d_itemsize], excess); - memcpy( optr + excess, iptr, d_m*d_itemsize - excess); + memcpy(optr, &in[i * d_n * d_itemsize], excess); + memcpy(optr + excess, iptr, d_m * d_itemsize - excess); } - } - - consume_each(blks*d_n); - return blks*d_m; } - } /* namespace blocks */ + consume_each(blks * d_n); + return blks * d_m; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/keep_m_in_n_impl.h b/gr-blocks/lib/keep_m_in_n_impl.h index 4a54b4c336..9f96272a1e 100644 --- a/gr-blocks/lib/keep_m_in_n_impl.h +++ b/gr-blocks/lib/keep_m_in_n_impl.h @@ -26,31 +26,31 @@ #include <gnuradio/blocks/keep_m_in_n.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API keep_m_in_n_impl : public keep_m_in_n - { - int d_m; - int d_n; - int d_offset; - int d_itemsize; +class BLOCKS_API keep_m_in_n_impl : public keep_m_in_n +{ + int d_m; + int d_n; + int d_offset; + int d_itemsize; - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - public: - keep_m_in_n_impl(size_t itemsize, int m, int n, int offset); +public: + keep_m_in_n_impl(size_t itemsize, int m, int n, int offset); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - void set_m(int m); - void set_n(int n); - void set_offset(int offset); - }; + void set_m(int m); + void set_n(int n); + void set_offset(int offset); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/keep_one_in_n_impl.cc b/gr-blocks/lib/keep_one_in_n_impl.cc index 91c77da829..5c7e4b3a12 100644 --- a/gr-blocks/lib/keep_one_in_n_impl.cc +++ b/gr-blocks/lib/keep_one_in_n_impl.cc @@ -28,83 +28,81 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - keep_one_in_n::sptr keep_one_in_n::make(size_t itemsize, int n) - { - return gnuradio::get_initial_sptr(new keep_one_in_n_impl(itemsize, n)); - } +keep_one_in_n::sptr keep_one_in_n::make(size_t itemsize, int n) +{ + return gnuradio::get_initial_sptr(new keep_one_in_n_impl(itemsize, n)); +} - keep_one_in_n_impl::keep_one_in_n_impl(size_t itemsize, int n) - : block("keep_one_in_n", - io_signature::make (1, 1, itemsize), - io_signature::make (1, 1, itemsize)), - d_count(n) - { - // To avoid bad behavior with using set_relative_rate in this block with - // VERY large values of n, we will keep track of things ourselves. Using - // this to turn off automatic tag propagation, which will be handled - // locally in general_work(). - set_tag_propagation_policy(TPP_DONT); +keep_one_in_n_impl::keep_one_in_n_impl(size_t itemsize, int n) + : block("keep_one_in_n", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize)), + d_count(n) +{ + // To avoid bad behavior with using set_relative_rate in this block with + // VERY large values of n, we will keep track of things ourselves. Using + // this to turn off automatic tag propagation, which will be handled + // locally in general_work(). + set_tag_propagation_policy(TPP_DONT); - set_n(n); - } + set_n(n); +} - void - keep_one_in_n_impl::set_n(int n) - { - if (n < 1) { +void keep_one_in_n_impl::set_n(int n) +{ + if (n < 1) { throw std::invalid_argument("N must be at least 1."); - } + } - d_n = n; - d_count = n; + d_n = n; + d_count = n; - // keep our internal understanding of the relative rate of this block - // don't set the relative rate, though, and we will handle our own - // tag propagation. - d_decim_rate = 1.0/(float)d_n; - } + // keep our internal understanding of the relative rate of this block + // don't set the relative rate, though, and we will handle our own + // tag propagation. + d_decim_rate = 1.0 / (float)d_n; +} - int - keep_one_in_n_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *in = (const char *) input_items[0]; - char *out = (char *) output_items[0]; +int keep_one_in_n_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* in = (const char*)input_items[0]; + char* out = (char*)output_items[0]; - size_t item_size = input_signature ()->sizeof_stream_item (0); - int ni = 0; - int no = 0; + size_t item_size = input_signature()->sizeof_stream_item(0); + int ni = 0; + int no = 0; - while (ni < ninput_items[0] && no < noutput_items){ + while (ni < ninput_items[0] && no < noutput_items) { d_count--; - if (d_count <= 0){ - memcpy (out, in, item_size); // copy 1 item - out += item_size; - no++; - d_count = d_n; + if (d_count <= 0) { + memcpy(out, in, item_size); // copy 1 item + out += item_size; + no++; + d_count = d_n; } in += item_size; ni++; - } + } - // Because we have set TPP_DONT, we have to propagate the tags here manually. - // Adjustment of the tag sample value is done using the float d_decim_rate. - std::vector<tag_t> tags; - std::vector<tag_t>::iterator t; - get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0)+ni); - for(t = tags.begin(); t != tags.end(); t++) { + // Because we have set TPP_DONT, we have to propagate the tags here manually. + // Adjustment of the tag sample value is done using the float d_decim_rate. + std::vector<tag_t> tags; + std::vector<tag_t>::iterator t; + get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0) + ni); + for (t = tags.begin(); t != tags.end(); t++) { tag_t new_tag = *t; new_tag.offset *= d_decim_rate; add_item_tag(0, new_tag); - } - - consume_each (ni); - return no; } - } /* namespace blocks */ + consume_each(ni); + return no; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/keep_one_in_n_impl.h b/gr-blocks/lib/keep_one_in_n_impl.h index f60bf1a02b..e2882e74bc 100644 --- a/gr-blocks/lib/keep_one_in_n_impl.h +++ b/gr-blocks/lib/keep_one_in_n_impl.h @@ -27,26 +27,26 @@ #include <gnuradio/blocks/keep_one_in_n.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API keep_one_in_n_impl : public keep_one_in_n - { - int d_n; - int d_count; - float d_decim_rate; +class BLOCKS_API keep_one_in_n_impl : public keep_one_in_n +{ + int d_n; + int d_count; + float d_decim_rate; - public: - keep_one_in_n_impl(size_t itemsize,int n); +public: + keep_one_in_n_impl(size_t itemsize, int n); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - void set_n(int n); - }; + void set_n(int n); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/lfsr_32k_source_s_impl.cc b/gr-blocks/lib/lfsr_32k_source_s_impl.cc index 58b0ad7def..fe9f227cd6 100644 --- a/gr-blocks/lib/lfsr_32k_source_s_impl.cc +++ b/gr-blocks/lib/lfsr_32k_source_s_impl.cc @@ -29,51 +29,46 @@ #include <stdexcept> namespace gr { - namespace blocks { +namespace blocks { - lfsr_32k_source_s::sptr - lfsr_32k_source_s::make() - { - return gnuradio::get_initial_sptr - (new lfsr_32k_source_s_impl()); - } +lfsr_32k_source_s::sptr lfsr_32k_source_s::make() +{ + return gnuradio::get_initial_sptr(new lfsr_32k_source_s_impl()); +} - lfsr_32k_source_s_impl::lfsr_32k_source_s_impl() - : sync_block("lfsr_32k_source_s", - io_signature::make(0, 0, 0), - io_signature::make(1, 1, sizeof(short))), - d_index(0) - { - lfsr_32k lfsr; +lfsr_32k_source_s_impl::lfsr_32k_source_s_impl() + : sync_block("lfsr_32k_source_s", + io_signature::make(0, 0, 0), + io_signature::make(1, 1, sizeof(short))), + d_index(0) +{ + lfsr_32k lfsr; - for(int i = 0; i < BUFSIZE; i++) + for (int i = 0; i < BUFSIZE; i++) d_buffer[i] = lfsr.next_short(); - } +} - lfsr_32k_source_s_impl::~lfsr_32k_source_s_impl() - { - } +lfsr_32k_source_s_impl::~lfsr_32k_source_s_impl() {} - int - lfsr_32k_source_s_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - short *out = (short*)output_items[0]; - short *buf = d_buffer; - int index = d_index; +int lfsr_32k_source_s_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + short* out = (short*)output_items[0]; + short* buf = d_buffer; + int index = d_index; - for(int i = 0; i < noutput_items; i++) { + for (int i = 0; i < noutput_items; i++) { out[i] = buf[index]; // index = (index + 1) & (BUFSIZE - 1); index = index + 1; - if(index >= BUFSIZE) - index = 0; - } - - d_index = index; - return noutput_items; + if (index >= BUFSIZE) + index = 0; } - } /* namespace blocks */ + d_index = index; + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/lfsr_32k_source_s_impl.h b/gr-blocks/lib/lfsr_32k_source_s_impl.h index 40fc6b6d84..7705c9f02f 100644 --- a/gr-blocks/lib/lfsr_32k_source_s_impl.h +++ b/gr-blocks/lib/lfsr_32k_source_s_impl.h @@ -28,25 +28,25 @@ #include <gnuradio/sync_block.h> namespace gr { - namespace blocks { +namespace blocks { - class lfsr_32k_source_s_impl : public lfsr_32k_source_s - { - private: - static const int BUFSIZE = 2048 - 1; // ensure pattern isn't packet aligned - int d_index; - short d_buffer[BUFSIZE]; +class lfsr_32k_source_s_impl : public lfsr_32k_source_s +{ +private: + static const int BUFSIZE = 2048 - 1; // ensure pattern isn't packet aligned + int d_index; + short d_buffer[BUFSIZE]; - public: - lfsr_32k_source_s_impl(); - ~lfsr_32k_source_s_impl(); +public: + lfsr_32k_source_s_impl(); + ~lfsr_32k_source_s_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_LFSR_32K_SOURCE_S_IMPL_H */ diff --git a/gr-blocks/lib/magphase_to_complex_impl.cc b/gr-blocks/lib/magphase_to_complex_impl.cc index db6240d939..bc8f727e34 100644 --- a/gr-blocks/lib/magphase_to_complex_impl.cc +++ b/gr-blocks/lib/magphase_to_complex_impl.cc @@ -29,40 +29,36 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - magphase_to_complex::sptr - magphase_to_complex::make(size_t vlen) - { - return gnuradio::get_initial_sptr - (new magphase_to_complex_impl(vlen)); - } +magphase_to_complex::sptr magphase_to_complex::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new magphase_to_complex_impl(vlen)); +} - magphase_to_complex_impl::magphase_to_complex_impl(size_t vlen) - : sync_block("magphase_to_complex", - io_signature::make(2, 2, sizeof(float)*vlen), - io_signature::make(1, 1, sizeof(gr_complex)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } +magphase_to_complex_impl::magphase_to_complex_impl(size_t vlen) + : sync_block("magphase_to_complex", + io_signature::make(2, 2, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(gr_complex) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} - int - magphase_to_complex_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float *mag = (float *)input_items[0]; - float *phase = (float *)input_items[1]; - gr_complex *out = (gr_complex *) output_items[0]; +int magphase_to_complex_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float* mag = (float*)input_items[0]; + float* phase = (float*)input_items[1]; + gr_complex* out = (gr_complex*)output_items[0]; - for (size_t j = 0; j < noutput_items*d_vlen; j++) - out[j] = gr_complex (mag[j]*cos(phase[j]),mag[j]*sin(phase[j])); - - return noutput_items; - } + for (size_t j = 0; j < noutput_items * d_vlen; j++) + out[j] = gr_complex(mag[j] * cos(phase[j]), mag[j] * sin(phase[j])); - } /* namespace blocks */ -}/* namespace gr */ + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/magphase_to_complex_impl.h b/gr-blocks/lib/magphase_to_complex_impl.h index 114e15321d..d8a1181ec6 100644 --- a/gr-blocks/lib/magphase_to_complex_impl.h +++ b/gr-blocks/lib/magphase_to_complex_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/magphase_to_complex.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API magphase_to_complex_impl : public magphase_to_complex - { - size_t d_vlen; +class BLOCKS_API magphase_to_complex_impl : public magphase_to_complex +{ + size_t d_vlen; - public: - magphase_to_complex_impl(size_t vlen); +public: + magphase_to_complex_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/max_blk_impl.cc b/gr-blocks/lib/max_blk_impl.cc index 82caccf75f..9f2dcaf5a0 100644 --- a/gr-blocks/lib/max_blk_impl.cc +++ b/gr-blocks/lib/max_blk_impl.cc @@ -29,74 +29,72 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - template <class T> - typename max_blk<T>::sptr - max_blk<T>::make(size_t vlen, size_t vlen_out) - { - return gnuradio::get_initial_sptr - (new max_blk_impl<T> (vlen,vlen_out)); - } - - template <class T> - max_blk_impl<T> ::max_blk_impl(size_t vlen, size_t vlen_out) +namespace blocks { + +template <class T> +typename max_blk<T>::sptr max_blk<T>::make(size_t vlen, size_t vlen_out) +{ + return gnuradio::get_initial_sptr(new max_blk_impl<T>(vlen, vlen_out)); +} + +template <class T> +max_blk_impl<T>::max_blk_impl(size_t vlen, size_t vlen_out) : sync_block("max_blk", - io_signature::make(1, -1, vlen*sizeof(T)), - io_signature::make(1, 1, vlen_out*sizeof(T))), - d_vlen(vlen), d_vlen_out(vlen_out) - { - assert((vlen_out == vlen) || (vlen_out == 1)); - } - - template <class T> - max_blk_impl<T> ::~max_blk_impl() - { - } - - template <class T> - int - max_blk_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *)output_items[0]; - - int ninputs = input_items.size(); - - if(d_vlen_out == 1) - for(int i = 0; i < noutput_items; i++) { - T max = ((T *)input_items[0])[i*d_vlen]; - - for(int j = 0; j < (int)d_vlen; j++ ) { - for(int k = 0; k < ninputs; k++) { - if(((T *)input_items[k])[i*d_vlen + j] > max) { - max = ((T*)input_items[k])[i*d_vlen + j]; - } - } - } - - *optr++ = (T)max; - } - - else // vector mode output - for(size_t i = 0; i < (size_t)noutput_items * d_vlen_out; i++) { - T max = ((T *)input_items[0])[i]; - - for(int k = 1; k < ninputs; k++) { - if(((T *)input_items[k])[i] > max) { - max = ((T*)input_items[k])[i]; - } - } - - *optr++ = (T)max; - } - - return noutput_items; - } + io_signature::make(1, -1, vlen * sizeof(T)), + io_signature::make(1, 1, vlen_out * sizeof(T))), + d_vlen(vlen), + d_vlen_out(vlen_out) +{ + assert((vlen_out == vlen) || (vlen_out == 1)); +} + +template <class T> +max_blk_impl<T>::~max_blk_impl() +{ +} + +template <class T> +int max_blk_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; + + int ninputs = input_items.size(); + + if (d_vlen_out == 1) + for (int i = 0; i < noutput_items; i++) { + T max = ((T*)input_items[0])[i * d_vlen]; + + for (int j = 0; j < (int)d_vlen; j++) { + for (int k = 0; k < ninputs; k++) { + if (((T*)input_items[k])[i * d_vlen + j] > max) { + max = ((T*)input_items[k])[i * d_vlen + j]; + } + } + } + + *optr++ = (T)max; + } + + else // vector mode output + for (size_t i = 0; i < (size_t)noutput_items * d_vlen_out; i++) { + T max = ((T*)input_items[0])[i]; + + for (int k = 1; k < ninputs; k++) { + if (((T*)input_items[k])[i] > max) { + max = ((T*)input_items[k])[i]; + } + } + + *optr++ = (T)max; + } + + return noutput_items; +} template class max_blk<std::int16_t>; template class max_blk<std::int32_t>; template class max_blk<float>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/max_blk_impl.h b/gr-blocks/lib/max_blk_impl.h index af62d9f4a8..5d4718aec7 100644 --- a/gr-blocks/lib/max_blk_impl.h +++ b/gr-blocks/lib/max_blk_impl.h @@ -27,24 +27,24 @@ #include <gnuradio/blocks/max_blk.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class max_blk_impl : public max_blk<T> - { - private: - size_t d_vlen, d_vlen_out; +template <class T> +class max_blk_impl : public max_blk<T> +{ +private: + size_t d_vlen, d_vlen_out; - public: - max_blk_impl (size_t vlen, size_t vlen_out); - ~max_blk_impl (); +public: + max_blk_impl(size_t vlen, size_t vlen_out); + ~max_blk_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* MAX_BLK_IMPL_H */ diff --git a/gr-blocks/lib/message_debug_impl.cc b/gr-blocks/lib/message_debug_impl.cc index 8bab788261..a8c84aa509 100644 --- a/gr-blocks/lib/message_debug_impl.cc +++ b/gr-blocks/lib/message_debug_impl.cc @@ -30,91 +30,77 @@ #include <iostream> namespace gr { - namespace blocks { - - message_debug::sptr - message_debug::make() - { - return gnuradio::get_initial_sptr - (new message_debug_impl()); - } - - void - message_debug_impl::print(pmt::pmt_t msg) - { - std::cout << "******* MESSAGE DEBUG PRINT ********\n"; - pmt::print(msg); - std::cout << "************************************\n"; - } - - void - message_debug_impl::store(pmt::pmt_t msg) - { - gr::thread::scoped_lock guard(d_mutex); - d_messages.push_back(msg); - } - - void - message_debug_impl::print_pdu(pmt::pmt_t pdu) - { - pmt::pmt_t meta = pmt::car(pdu); - pmt::pmt_t vector = pmt::cdr(pdu); - std::cout << "* MESSAGE DEBUG PRINT PDU VERBOSE *\n"; - pmt::print(meta); - size_t len = pmt::blob_length(vector); - std::cout << "pdu_length = " << len << std::endl; - std::cout << "contents = " << std::endl; - size_t offset(0); - const uint8_t* d = (const uint8_t*) pmt::uniform_vector_elements(vector, offset); - for(size_t i=0; i<len; i+=16){ +namespace blocks { + +message_debug::sptr message_debug::make() +{ + return gnuradio::get_initial_sptr(new message_debug_impl()); +} + +void message_debug_impl::print(pmt::pmt_t msg) +{ + std::cout << "******* MESSAGE DEBUG PRINT ********\n"; + pmt::print(msg); + std::cout << "************************************\n"; +} + +void message_debug_impl::store(pmt::pmt_t msg) +{ + gr::thread::scoped_lock guard(d_mutex); + d_messages.push_back(msg); +} + +void message_debug_impl::print_pdu(pmt::pmt_t pdu) +{ + pmt::pmt_t meta = pmt::car(pdu); + pmt::pmt_t vector = pmt::cdr(pdu); + std::cout << "* MESSAGE DEBUG PRINT PDU VERBOSE *\n"; + pmt::print(meta); + size_t len = pmt::blob_length(vector); + std::cout << "pdu_length = " << len << std::endl; + std::cout << "contents = " << std::endl; + size_t offset(0); + const uint8_t* d = (const uint8_t*)pmt::uniform_vector_elements(vector, offset); + for (size_t i = 0; i < len; i += 16) { printf("%04x: ", ((unsigned int)i)); - for(size_t j=i; j<std::min(i+16,len); j++){ - printf("%02x ",d[j] ); + for (size_t j = i; j < std::min(i + 16, len); j++) { + printf("%02x ", d[j]); } std::cout << std::endl; - } - - std::cout << "***********************************\n"; } - int - message_debug_impl::num_messages() - { - return (int)d_messages.size(); - } + std::cout << "***********************************\n"; +} - pmt::pmt_t - message_debug_impl::get_message(int i) - { - gr::thread::scoped_lock guard(d_mutex); +int message_debug_impl::num_messages() { return (int)d_messages.size(); } - if((size_t)i >= d_messages.size()) { - throw std::runtime_error("message_debug: index for message out of bounds.\n"); - } +pmt::pmt_t message_debug_impl::get_message(int i) +{ + gr::thread::scoped_lock guard(d_mutex); - return d_messages[i]; + if ((size_t)i >= d_messages.size()) { + throw std::runtime_error("message_debug: index for message out of bounds.\n"); } - message_debug_impl::message_debug_impl() - : block("message_debug", - io_signature::make(0, 0, 0), - io_signature::make(0, 0, 0)) - { - message_port_register_in(pmt::mp("print")); - set_msg_handler(pmt::mp("print"), boost::bind(&message_debug_impl::print, this, _1)); + return d_messages[i]; +} - message_port_register_in(pmt::mp("store")); - set_msg_handler(pmt::mp("store"), boost::bind(&message_debug_impl::store, this, _1)); +message_debug_impl::message_debug_impl() + : block("message_debug", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)) +{ + message_port_register_in(pmt::mp("print")); + set_msg_handler(pmt::mp("print"), boost::bind(&message_debug_impl::print, this, _1)); - message_port_register_in(pmt::mp("print_pdu")); - set_msg_handler(pmt::mp("print_pdu"), boost::bind(&message_debug_impl::print_pdu, this, _1)); - } + message_port_register_in(pmt::mp("store")); + set_msg_handler(pmt::mp("store"), boost::bind(&message_debug_impl::store, this, _1)); - message_debug_impl::~message_debug_impl() - { - } + message_port_register_in(pmt::mp("print_pdu")); + set_msg_handler(pmt::mp("print_pdu"), + boost::bind(&message_debug_impl::print_pdu, this, _1)); +} - } /* namespace blocks */ -} /* namespace gr */ +message_debug_impl::~message_debug_impl() {} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/message_debug_impl.h b/gr-blocks/lib/message_debug_impl.h index 5a6e2e4acb..2faa42a0d0 100644 --- a/gr-blocks/lib/message_debug_impl.h +++ b/gr-blocks/lib/message_debug_impl.h @@ -29,61 +29,60 @@ #include <pmt/pmt.h> namespace gr { - namespace blocks { +namespace blocks { - class message_debug_impl : public message_debug - { - private: +class message_debug_impl : public message_debug +{ +private: + /*! + * \brief Messages received in this port are printed to stdout. + * + * This port receives messages from the scheduler's message + * handling mechanism and prints it to stdout. This message + * handler function is only meant to be used by the scheduler to + * handle messages posted to port 'print'. + * + * \param msg A pmt message passed from the scheduler's message handling. + */ + void print(pmt::pmt_t msg); - /*! - * \brief Messages received in this port are printed to stdout. - * - * This port receives messages from the scheduler's message - * handling mechanism and prints it to stdout. This message - * handler function is only meant to be used by the scheduler to - * handle messages posted to port 'print'. - * - * \param msg A pmt message passed from the scheduler's message handling. - */ - void print(pmt::pmt_t msg); + /*! + * \brief PDU formatted messages received in this port are printed to stdout. + * + * This port receives messages from the scheduler's message + * handling mechanism and prints it to stdout. This message + * handler function is only meant to be used by the scheduler to + * handle messages posted to port 'print'. + * + * \param pdu A PDU message passed from the scheduler's message handling. + */ + void print_pdu(pmt::pmt_t pdu); - /*! - * \brief PDU formatted messages received in this port are printed to stdout. - * - * This port receives messages from the scheduler's message - * handling mechanism and prints it to stdout. This message - * handler function is only meant to be used by the scheduler to - * handle messages posted to port 'print'. - * - * \param pdu A PDU message passed from the scheduler's message handling. - */ - void print_pdu(pmt::pmt_t pdu); + /*! + * \brief Messages received in this port are stored in a vector. + * + * This port receives messages from the scheduler's message + * handling mechanism and stores it in a vector. Messages can be + * retrieved later using the 'get_message' function. This + * message handler function is only meant to be used by the + * scheduler to handle messages posted to port 'store'. + * + * \param msg A pmt message passed from the scheduler's message handling. + */ + void store(pmt::pmt_t msg); - /*! - * \brief Messages received in this port are stored in a vector. - * - * This port receives messages from the scheduler's message - * handling mechanism and stores it in a vector. Messages can be - * retrieved later using the 'get_message' function. This - * message handler function is only meant to be used by the - * scheduler to handle messages posted to port 'store'. - * - * \param msg A pmt message passed from the scheduler's message handling. - */ - void store(pmt::pmt_t msg); + gr::thread::mutex d_mutex; + std::vector<pmt::pmt_t> d_messages; - gr::thread::mutex d_mutex; - std::vector<pmt::pmt_t> d_messages; +public: + message_debug_impl(); + ~message_debug_impl(); - public: - message_debug_impl(); - ~message_debug_impl(); + int num_messages(); + pmt::pmt_t get_message(int i); +}; - int num_messages(); - pmt::pmt_t get_message(int i); - }; - - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_MESSAGE_DEBUG_IMPL_H */ diff --git a/gr-blocks/lib/message_strobe_impl.cc b/gr-blocks/lib/message_strobe_impl.cc index bedec78a57..cf06448ecb 100644 --- a/gr-blocks/lib/message_strobe_impl.cc +++ b/gr-blocks/lib/message_strobe_impl.cc @@ -36,69 +36,62 @@ #include <iostream> namespace gr { - namespace blocks { +namespace blocks { - message_strobe::sptr - message_strobe::make(pmt::pmt_t msg, long period_ms) - { - return gnuradio::get_initial_sptr - (new message_strobe_impl(msg, period_ms)); - } +message_strobe::sptr message_strobe::make(pmt::pmt_t msg, long period_ms) +{ + return gnuradio::get_initial_sptr(new message_strobe_impl(msg, period_ms)); +} - message_strobe_impl::message_strobe_impl(pmt::pmt_t msg, long period_ms) - : block("message_strobe", - io_signature::make(0, 0, 0), - io_signature::make(0, 0, 0)), - d_finished(false), - d_period_ms(period_ms), - d_msg(msg), - d_port(pmt::mp("strobe")) - { - message_port_register_out(d_port); +message_strobe_impl::message_strobe_impl(pmt::pmt_t msg, long period_ms) + : block("message_strobe", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)), + d_finished(false), + d_period_ms(period_ms), + d_msg(msg), + d_port(pmt::mp("strobe")) +{ + message_port_register_out(d_port); - message_port_register_in(pmt::mp("set_msg")); - set_msg_handler(pmt::mp("set_msg"), - boost::bind(&message_strobe_impl::set_msg, this, _1)); - } + message_port_register_in(pmt::mp("set_msg")); + set_msg_handler(pmt::mp("set_msg"), + boost::bind(&message_strobe_impl::set_msg, this, _1)); +} - message_strobe_impl::~message_strobe_impl() - { - } +message_strobe_impl::~message_strobe_impl() {} - bool - message_strobe_impl::start() - { - // NOTE: d_finished should be something explicitly thread safe. But since - // nothing breaks on concurrent access, I'll just leave it as bool. - d_finished = false; - d_thread = boost::shared_ptr<gr::thread::thread> - (new gr::thread::thread(boost::bind(&message_strobe_impl::run, this))); +bool message_strobe_impl::start() +{ + // NOTE: d_finished should be something explicitly thread safe. But since + // nothing breaks on concurrent access, I'll just leave it as bool. + d_finished = false; + d_thread = boost::shared_ptr<gr::thread::thread>( + new gr::thread::thread(boost::bind(&message_strobe_impl::run, this))); - return block::start(); - } + return block::start(); +} - bool - message_strobe_impl::stop() - { - // Shut down the thread - d_finished = true; - d_thread->interrupt(); - d_thread->join(); +bool message_strobe_impl::stop() +{ + // Shut down the thread + d_finished = true; + d_thread->interrupt(); + d_thread->join(); - return block::stop(); - } + return block::stop(); +} - void message_strobe_impl::run() - { - while(!d_finished) { - boost::this_thread::sleep(boost::posix_time::milliseconds(static_cast<long>(d_period_ms))); - if(d_finished) { - return; +void message_strobe_impl::run() +{ + while (!d_finished) { + boost::this_thread::sleep( + boost::posix_time::milliseconds(static_cast<long>(d_period_ms))); + if (d_finished) { + return; } message_port_pub(d_port, d_msg); - } } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/message_strobe_impl.h b/gr-blocks/lib/message_strobe_impl.h index 0ee1cf1f3d..956b57da7a 100644 --- a/gr-blocks/lib/message_strobe_impl.h +++ b/gr-blocks/lib/message_strobe_impl.h @@ -26,35 +26,35 @@ #include <gnuradio/blocks/message_strobe.h> namespace gr { - namespace blocks { - - class BLOCKS_API message_strobe_impl : public message_strobe - { - private: - boost::shared_ptr<gr::thread::thread> d_thread; - bool d_finished; - long d_period_ms; - pmt::pmt_t d_msg; - const pmt::pmt_t d_port; - - void run(); - - public: - message_strobe_impl(pmt::pmt_t msg, long period_ms); - ~message_strobe_impl(); - - void set_msg(pmt::pmt_t msg) { d_msg = msg; } - pmt::pmt_t msg() const { return d_msg; } - void set_period(long period_ms) { d_period_ms = period_ms; } - long period() const { return d_period_ms; } - - // Overloading these to start and stop the internal thread that - // periodically produces the message. - bool start(); - bool stop(); - }; - - } /* namespace blocks */ +namespace blocks { + +class BLOCKS_API message_strobe_impl : public message_strobe +{ +private: + boost::shared_ptr<gr::thread::thread> d_thread; + bool d_finished; + long d_period_ms; + pmt::pmt_t d_msg; + const pmt::pmt_t d_port; + + void run(); + +public: + message_strobe_impl(pmt::pmt_t msg, long period_ms); + ~message_strobe_impl(); + + void set_msg(pmt::pmt_t msg) { d_msg = msg; } + pmt::pmt_t msg() const { return d_msg; } + void set_period(long period_ms) { d_period_ms = period_ms; } + long period() const { return d_period_ms; } + + // Overloading these to start and stop the internal thread that + // periodically produces the message. + bool start(); + bool stop(); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_MESSAGE_STROBE_IMPL_H */ diff --git a/gr-blocks/lib/message_strobe_random_impl.cc b/gr-blocks/lib/message_strobe_random_impl.cc index 5c2055ddbd..0a36b6d380 100644 --- a/gr-blocks/lib/message_strobe_random_impl.cc +++ b/gr-blocks/lib/message_strobe_random_impl.cc @@ -36,88 +36,104 @@ #include <iostream> namespace gr { - namespace blocks { - - message_strobe_random::sptr - message_strobe_random::make(pmt::pmt_t msg, message_strobe_random_distribution_t dist, float mean_ms, float std_ms) - { - return gnuradio::get_initial_sptr - (new message_strobe_random_impl(msg, dist, mean_ms, std_ms)); - } - - - message_strobe_random_impl::message_strobe_random_impl(pmt::pmt_t msg, message_strobe_random_distribution_t dist, float mean_ms, float std_ms) - : block("message_strobe_random", - io_signature::make(0, 0, 0), - io_signature::make(0, 0, 0)), - d_finished(false), - d_mean_ms(mean_ms), - d_std_ms(std_ms), - d_dist(dist), - d_msg(msg), - d_rng(), - d_port(pmt::mp("strobe")) - { - // allocate RNGs - update_dist(); - - // set up ports - message_port_register_out(d_port); - d_thread = boost::shared_ptr<gr::thread::thread> - (new gr::thread::thread(boost::bind(&message_strobe_random_impl::run, this))); - - message_port_register_in(pmt::mp("set_msg")); - set_msg_handler(pmt::mp("set_msg"), - boost::bind(&message_strobe_random_impl::set_msg, this, _1)); +namespace blocks { + +message_strobe_random::sptr +message_strobe_random::make(pmt::pmt_t msg, + message_strobe_random_distribution_t dist, + float mean_ms, + float std_ms) +{ + return gnuradio::get_initial_sptr( + new message_strobe_random_impl(msg, dist, mean_ms, std_ms)); +} + + +message_strobe_random_impl::message_strobe_random_impl( + pmt::pmt_t msg, + message_strobe_random_distribution_t dist, + float mean_ms, + float std_ms) + : block("message_strobe_random", + io_signature::make(0, 0, 0), + io_signature::make(0, 0, 0)), + d_finished(false), + d_mean_ms(mean_ms), + d_std_ms(std_ms), + d_dist(dist), + d_msg(msg), + d_rng(), + d_port(pmt::mp("strobe")) +{ + // allocate RNGs + update_dist(); + + // set up ports + message_port_register_out(d_port); + d_thread = boost::shared_ptr<gr::thread::thread>( + new gr::thread::thread(boost::bind(&message_strobe_random_impl::run, this))); + + message_port_register_in(pmt::mp("set_msg")); + set_msg_handler(pmt::mp("set_msg"), + boost::bind(&message_strobe_random_impl::set_msg, this, _1)); +} + +long message_strobe_random_impl::next_delay() +{ + switch (d_dist) { + case STROBE_POISSON: + // return d_variate_poisson->operator()(); + return static_cast<long>(d_variate_poisson->operator()()); + case STROBE_GAUSSIAN: + return static_cast<long>(d_variate_normal->operator()()); + case STROBE_UNIFORM: + return static_cast<long>(d_variate_uniform->operator()()); + default: + throw std::runtime_error( + "message_strobe_random_impl::d_distribution is very unhappy with you"); } - - long message_strobe_random_impl::next_delay(){ - switch(d_dist){ - case STROBE_POISSON: - //return d_variate_poisson->operator()(); - return static_cast<long>(d_variate_poisson->operator()()); - case STROBE_GAUSSIAN: - return static_cast<long>(d_variate_normal->operator()()); - case STROBE_UNIFORM: - return static_cast<long>(d_variate_uniform->operator()()); - default: - throw std::runtime_error("message_strobe_random_impl::d_distribution is very unhappy with you"); - } - } - - void message_strobe_random_impl::update_dist(){ - boost::poisson_distribution<> pd(d_mean_ms); - d_variate_poisson = boost::shared_ptr< boost::variate_generator<boost::mt19937, boost::poisson_distribution<> > > ( - new boost::variate_generator <boost::mt19937, boost::poisson_distribution<> >(d_rng,pd) ); - - boost::normal_distribution<> nd(d_mean_ms, d_std_ms); - d_variate_normal = boost::shared_ptr< boost::variate_generator<boost::mt19937, boost::normal_distribution<> > > ( - new boost::variate_generator <boost::mt19937, boost::normal_distribution<> >(d_rng,nd) ); - - boost::uniform_real<> ud(d_mean_ms-d_std_ms, d_mean_ms+d_std_ms); - d_variate_uniform = boost::shared_ptr< boost::variate_generator<boost::mt19937, boost::uniform_real<> > > ( - new boost::variate_generator <boost::mt19937, boost::uniform_real<> >(d_rng,ud) ); - } - - - message_strobe_random_impl::~message_strobe_random_impl() - { - d_finished = true; - d_thread->interrupt(); - d_thread->join(); - } - - void message_strobe_random_impl::run() - { - while(!d_finished) { - boost::this_thread::sleep(boost::posix_time::milliseconds(std::max(0L, next_delay()))); - if(d_finished) { - return; +} + +void message_strobe_random_impl::update_dist() +{ + boost::poisson_distribution<> pd(d_mean_ms); + d_variate_poisson = boost::shared_ptr< + boost::variate_generator<boost::mt19937, boost::poisson_distribution<>>>( + new boost::variate_generator<boost::mt19937, boost::poisson_distribution<>>(d_rng, + pd)); + + boost::normal_distribution<> nd(d_mean_ms, d_std_ms); + d_variate_normal = boost::shared_ptr< + boost::variate_generator<boost::mt19937, boost::normal_distribution<>>>( + new boost::variate_generator<boost::mt19937, boost::normal_distribution<>>(d_rng, + nd)); + + boost::uniform_real<> ud(d_mean_ms - d_std_ms, d_mean_ms + d_std_ms); + d_variate_uniform = boost::shared_ptr< + boost::variate_generator<boost::mt19937, boost::uniform_real<>>>( + new boost::variate_generator<boost::mt19937, boost::uniform_real<>>(d_rng, ud)); +} + + +message_strobe_random_impl::~message_strobe_random_impl() +{ + d_finished = true; + d_thread->interrupt(); + d_thread->join(); +} + +void message_strobe_random_impl::run() +{ + while (!d_finished) { + boost::this_thread::sleep( + boost::posix_time::milliseconds(std::max(0L, next_delay()))); + if (d_finished) { + return; } message_port_pub(d_port, d_msg); - } } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/message_strobe_random_impl.h b/gr-blocks/lib/message_strobe_random_impl.h index 08f966921c..de70c28419 100644 --- a/gr-blocks/lib/message_strobe_random_impl.h +++ b/gr-blocks/lib/message_strobe_random_impl.h @@ -31,45 +31,60 @@ #include <boost/random/uniform_real.hpp> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API message_strobe_random_impl : public message_strobe_random - { - private: - boost::shared_ptr<gr::thread::thread> d_thread; - bool d_finished; - float d_mean_ms; - float d_std_ms; - message_strobe_random_distribution_t d_dist; - pmt::pmt_t d_msg; - void run(); - long next_delay(); - - boost::mt19937 d_rng; - boost::shared_ptr< boost::variate_generator <boost::mt19937, boost::poisson_distribution<> > > d_variate_poisson; - boost::shared_ptr< boost::variate_generator <boost::mt19937, boost::normal_distribution<> > > d_variate_normal; - boost::shared_ptr< boost::variate_generator <boost::mt19937, boost::uniform_real<> > > d_variate_uniform; +class BLOCKS_API message_strobe_random_impl : public message_strobe_random +{ +private: + boost::shared_ptr<gr::thread::thread> d_thread; + bool d_finished; + float d_mean_ms; + float d_std_ms; + message_strobe_random_distribution_t d_dist; + pmt::pmt_t d_msg; + void run(); + long next_delay(); - const pmt::pmt_t d_port; + boost::mt19937 d_rng; + boost::shared_ptr< + boost::variate_generator<boost::mt19937, boost::poisson_distribution<>>> + d_variate_poisson; + boost::shared_ptr< + boost::variate_generator<boost::mt19937, boost::normal_distribution<>>> + d_variate_normal; + boost::shared_ptr<boost::variate_generator<boost::mt19937, boost::uniform_real<>>> + d_variate_uniform; - void update_dist(); + const pmt::pmt_t d_port; - public: - message_strobe_random_impl(pmt::pmt_t msg, message_strobe_random_distribution_t dist, float mean_ms, float std_ms); - ~message_strobe_random_impl(); + void update_dist(); - void set_msg(pmt::pmt_t msg) { d_msg = msg; } - pmt::pmt_t msg() const { return d_msg; } - void set_mean(float mean_ms) { d_mean_ms = mean_ms; update_dist(); } - float mean() const { return d_mean_ms; } - void set_std(float std_ms) { d_std_ms = std_ms; update_dist(); } - float std() const { return d_std_ms; } - void set_dist(message_strobe_random_distribution_t dist){ d_dist = dist; } - message_strobe_random_distribution_t dist() const { return d_dist; } +public: + message_strobe_random_impl(pmt::pmt_t msg, + message_strobe_random_distribution_t dist, + float mean_ms, + float std_ms); + ~message_strobe_random_impl(); - }; + void set_msg(pmt::pmt_t msg) { d_msg = msg; } + pmt::pmt_t msg() const { return d_msg; } + void set_mean(float mean_ms) + { + d_mean_ms = mean_ms; + update_dist(); + } + float mean() const { return d_mean_ms; } + void set_std(float std_ms) + { + d_std_ms = std_ms; + update_dist(); + } + float std() const { return d_std_ms; } + void set_dist(message_strobe_random_distribution_t dist) { d_dist = dist; } + message_strobe_random_distribution_t dist() const { return d_dist; } +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_MESSAGE_STROBE_RANDOM_IMPL_H */ diff --git a/gr-blocks/lib/min_blk_impl.cc b/gr-blocks/lib/min_blk_impl.cc index 540d1717f1..6ed9635e26 100644 --- a/gr-blocks/lib/min_blk_impl.cc +++ b/gr-blocks/lib/min_blk_impl.cc @@ -29,69 +29,67 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename min_blk<T>::sptr - min_blk<T>::make(size_t vlen, size_t vlen_out) - { - return gnuradio::get_initial_sptr - (new min_blk_impl<T> (vlen,vlen_out)); - } +template <class T> +typename min_blk<T>::sptr min_blk<T>::make(size_t vlen, size_t vlen_out) +{ + return gnuradio::get_initial_sptr(new min_blk_impl<T>(vlen, vlen_out)); +} - template <class T> - min_blk_impl<T> ::min_blk_impl(size_t vlen, size_t vlen_out) +template <class T> +min_blk_impl<T>::min_blk_impl(size_t vlen, size_t vlen_out) : sync_block("min", - io_signature::make(1, -1, vlen*sizeof(T)), - io_signature::make(1, 1, vlen_out*sizeof(T))), - d_vlen(vlen), d_vlen_out(vlen_out) - { - assert((vlen_out == vlen) || (vlen_out == 1)); - } + io_signature::make(1, -1, vlen * sizeof(T)), + io_signature::make(1, 1, vlen_out * sizeof(T))), + d_vlen(vlen), + d_vlen_out(vlen_out) +{ + assert((vlen_out == vlen) || (vlen_out == 1)); +} - template <class T> - min_blk_impl<T> ::~min_blk_impl() - { - } +template <class T> +min_blk_impl<T>::~min_blk_impl() +{ +} - template <class T> - int - min_blk_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *)output_items[0]; +template <class T> +int min_blk_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; - int ninputs = input_items.size(); + int ninputs = input_items.size(); - if(d_vlen_out == 1) - for(int i = 0; i < noutput_items; i++) { - T min = ((T *)input_items[0])[i*d_vlen]; - for(int j = 0; j < (int)d_vlen; j++ ) { - for(int k = 0; k < ninputs; k++) { - if(((T *)input_items[k])[i*d_vlen + j] < min) { - min = ((T*)input_items[k])[i*d_vlen + j]; - } - } - } - *optr++ = (T)min; - } + if (d_vlen_out == 1) + for (int i = 0; i < noutput_items; i++) { + T min = ((T*)input_items[0])[i * d_vlen]; + for (int j = 0; j < (int)d_vlen; j++) { + for (int k = 0; k < ninputs; k++) { + if (((T*)input_items[k])[i * d_vlen + j] < min) { + min = ((T*)input_items[k])[i * d_vlen + j]; + } + } + } + *optr++ = (T)min; + } - else // vector mode output - for(size_t i = 0; i < noutput_items * d_vlen_out; i++) { - T min = ((T *)input_items[0])[i]; - for(int k = 1; k < ninputs; k++) { - if(((T *)input_items[k])[i] < min) { - min = ((T*)input_items[k])[i]; - } - } - *optr++ = (T)min; - } - return noutput_items; - } + else // vector mode output + for (size_t i = 0; i < noutput_items * d_vlen_out; i++) { + T min = ((T*)input_items[0])[i]; + for (int k = 1; k < ninputs; k++) { + if (((T*)input_items[k])[i] < min) { + min = ((T*)input_items[k])[i]; + } + } + *optr++ = (T)min; + } + return noutput_items; +} template class min_blk<std::int16_t>; template class min_blk<std::int32_t>; template class min_blk<float>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/min_blk_impl.h b/gr-blocks/lib/min_blk_impl.h index 151b97b391..36e7506679 100644 --- a/gr-blocks/lib/min_blk_impl.h +++ b/gr-blocks/lib/min_blk_impl.h @@ -27,24 +27,24 @@ #include <gnuradio/blocks/min_blk.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class min_blk_impl : public min_blk<T> - { - private: - size_t d_vlen, d_vlen_out; +template <class T> +class min_blk_impl : public min_blk<T> +{ +private: + size_t d_vlen, d_vlen_out; - public: - min_blk_impl (size_t vlen, size_t vlen_out); - ~min_blk_impl (); +public: + min_blk_impl(size_t vlen, size_t vlen_out); + ~min_blk_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* MIN_BLK_IMPL_H */ diff --git a/gr-blocks/lib/moving_average_impl.cc b/gr-blocks/lib/moving_average_impl.cc index b77a70a440..3342e2c937 100644 --- a/gr-blocks/lib/moving_average_impl.cc +++ b/gr-blocks/lib/moving_average_impl.cc @@ -29,21 +29,24 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - template <class T> - typename moving_average<T>::sptr - moving_average<T>::make(int length, T scale, int max_iter, unsigned int vlen) - { - return gnuradio::get_initial_sptr - (new moving_average_impl<T> (length, scale, max_iter, vlen)); - } - - template <class T> - moving_average_impl<T>::moving_average_impl(int length, T scale, int max_iter, unsigned int vlen) +namespace blocks { + +template <class T> +typename moving_average<T>::sptr +moving_average<T>::make(int length, T scale, int max_iter, unsigned int vlen) +{ + return gnuradio::get_initial_sptr( + new moving_average_impl<T>(length, scale, max_iter, vlen)); +} + +template <class T> +moving_average_impl<T>::moving_average_impl(int length, + T scale, + int max_iter, + unsigned int vlen) : sync_block("moving_average", - io_signature::make(1, 1, sizeof(T)*vlen), - io_signature::make(1, 1, sizeof(T)*vlen)), + io_signature::make(1, 1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), d_length(length), d_scale(scale), d_max_iter(max_iter), @@ -51,101 +54,99 @@ namespace gr { d_new_length(length), d_new_scale(scale), d_updated(false) - { - this->set_history(length); - //we don't have C++11's <array>, so initialize the stored vector instead - //we store this vector so that work() doesn't spend its time allocating and freeing vector storage - if(d_vlen > 1) { +{ + this->set_history(length); + // we don't have C++11's <array>, so initialize the stored vector instead + // we store this vector so that work() doesn't spend its time allocating and freeing + // vector storage + if (d_vlen > 1) { d_sum = std::vector<T>(d_vlen); - } - } - - template <class T> - moving_average_impl<T> ::~moving_average_impl() - { - } - - template <class T> - void - moving_average_impl<T> ::set_length_and_scale(int length, T scale) - { - d_new_length = length; - d_new_scale = scale; - d_updated = true; } - - template <class T> - void - moving_average_impl<T> ::set_length(int length) - { - d_new_length = length; - d_updated = true; - } - - template <class T> - void - moving_average_impl<T> ::set_scale(T scale) - { - d_new_scale = scale; - d_updated = true; - } - - template <class T> - int - moving_average_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - if(d_updated) { +} + +template <class T> +moving_average_impl<T>::~moving_average_impl() +{ +} + +template <class T> +void moving_average_impl<T>::set_length_and_scale(int length, T scale) +{ + d_new_length = length; + d_new_scale = scale; + d_updated = true; +} + +template <class T> +void moving_average_impl<T>::set_length(int length) +{ + d_new_length = length; + d_updated = true; +} + +template <class T> +void moving_average_impl<T>::set_scale(T scale) +{ + d_new_scale = scale; + d_updated = true; +} + +template <class T> +int moving_average_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + if (d_updated) { d_length = d_new_length; d_scale = d_new_scale; this->set_history(d_length); d_updated = false; return 0; // history requirements might have changed - } + } - const T *in = (const T *)input_items[0]; - T *out = (T *)output_items[0]; + const T* in = (const T*)input_items[0]; + T* out = (T*)output_items[0]; - unsigned int num_iter = (unsigned int)((noutput_items>d_max_iter) ? d_max_iter : noutput_items); - if(d_vlen == 1) { + unsigned int num_iter = + (unsigned int)((noutput_items > d_max_iter) ? d_max_iter : noutput_items); + if (d_vlen == 1) { T sum = in[0]; - for(int i = 1; i < d_length-1; i++) { - sum += in[i]; + for (int i = 1; i < d_length - 1; i++) { + sum += in[i]; } - for(unsigned int i = 0; i < num_iter; i++) { - sum += in[i+d_length-1]; - out[i] = sum * d_scale; - sum -= in[i]; + for (unsigned int i = 0; i < num_iter; i++) { + sum += in[i + d_length - 1]; + out[i] = sum * d_scale; + sum -= in[i]; } - } else { // d_vlen > 1 - //gets automatically optimized well - for(unsigned int elem = 0; elem < d_vlen; elem++) { - d_sum[elem] = in[elem]; + } else { // d_vlen > 1 + // gets automatically optimized well + for (unsigned int elem = 0; elem < d_vlen; elem++) { + d_sum[elem] = in[elem]; } - for(int i = 1; i < d_length - 1; i++) { - for(unsigned int elem = 0; elem < d_vlen; elem++) { - d_sum[elem] += in[i*d_vlen + elem]; - } + for (int i = 1; i < d_length - 1; i++) { + for (unsigned int elem = 0; elem < d_vlen; elem++) { + d_sum[elem] += in[i * d_vlen + elem]; + } } - for(unsigned int i = 0; i < num_iter; i++) { - for(unsigned int elem = 0; elem < d_vlen; elem++) { - d_sum[elem] += in[(i+d_length-1)*d_vlen + elem]; - out[i*d_vlen + elem] = d_sum[elem] * d_scale; - d_sum[elem] -= in[i*d_vlen + elem]; - } + for (unsigned int i = 0; i < num_iter; i++) { + for (unsigned int elem = 0; elem < d_vlen; elem++) { + d_sum[elem] += in[(i + d_length - 1) * d_vlen + elem]; + out[i * d_vlen + elem] = d_sum[elem] * d_scale; + d_sum[elem] -= in[i * d_vlen + elem]; + } } - } - return num_iter; } + return num_iter; +} template class moving_average<std::int16_t>; template class moving_average<std::int32_t>; template class moving_average<float>; template class moving_average<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/moving_average_impl.h b/gr-blocks/lib/moving_average_impl.h index a4e248d05d..bb29e26d23 100644 --- a/gr-blocks/lib/moving_average_impl.h +++ b/gr-blocks/lib/moving_average_impl.h @@ -29,44 +29,41 @@ #include <algorithm> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class moving_average_impl : public moving_average<T> - { - private: - int d_length; - T d_scale; - int d_max_iter; - unsigned int d_vlen; - std::vector<T> d_sum; +template <class T> +class moving_average_impl : public moving_average<T> +{ +private: + int d_length; + T d_scale; + int d_max_iter; + unsigned int d_vlen; + std::vector<T> d_sum; - int d_new_length; - T d_new_scale; - bool d_updated; + int d_new_length; + T d_new_scale; + bool d_updated; - public: - moving_average_impl (int length, T scale, - int max_iter = 4096, - unsigned int vlen = 1); - ~moving_average_impl (); +public: + moving_average_impl(int length, T scale, int max_iter = 4096, unsigned int vlen = 1); + ~moving_average_impl(); - int length() const { return d_new_length; } - T scale() const { return d_new_scale; } - unsigned int vlen() const { return d_vlen; } + int length() const { return d_new_length; } + T scale() const { return d_new_scale; } + unsigned int vlen() const { return d_vlen; } - void set_length_and_scale(int length, T scale); - void set_length(int length); - void set_scale(T scale); + void set_length_and_scale(int length, T scale); + void set_length(int length); + void set_scale(T scale); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - }; - - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* MOVING_AVERAGE_IMPL_H */ diff --git a/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc b/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc index 01b6a548c6..9907106bc5 100644 --- a/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc +++ b/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc @@ -29,100 +29,91 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - multiply_by_tag_value_cc::sptr - multiply_by_tag_value_cc::make(const std::string& tag_name, - size_t vlen) - { - return gnuradio::get_initial_sptr - (new multiply_by_tag_value_cc_impl(tag_name, vlen)); - } - - multiply_by_tag_value_cc_impl::multiply_by_tag_value_cc_impl(const std::string& tag_name, - size_t vlen) - : sync_block("multiply_by_tag_value_cc", - io_signature::make (1, 1, sizeof (gr_complex)*vlen), - io_signature::make (1, 1, sizeof (gr_complex)*vlen)), - d_vlen(vlen), d_k(gr_complex(1,0)) - { - d_tag_key = pmt::intern(tag_name); - - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(std::max(1,alignment_multiple)); - } - - multiply_by_tag_value_cc_impl::~multiply_by_tag_value_cc_impl() - { - } - - gr_complex - multiply_by_tag_value_cc_impl::k() const - { - return d_k; - } - - int - multiply_by_tag_value_cc_impl::work(int noutput_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]; - - std::vector<tag_t> tags; - get_tags_in_window(tags, 0, 0, noutput_items, d_tag_key); - - std::vector<tag_t>::iterator itag = tags.begin(); - - int start = 0, end; - while(itag != tags.end()) { +namespace blocks { + +multiply_by_tag_value_cc::sptr multiply_by_tag_value_cc::make(const std::string& tag_name, + size_t vlen) +{ + return gnuradio::get_initial_sptr(new multiply_by_tag_value_cc_impl(tag_name, vlen)); +} + +multiply_by_tag_value_cc_impl::multiply_by_tag_value_cc_impl(const std::string& tag_name, + size_t vlen) + : sync_block("multiply_by_tag_value_cc", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(gr_complex) * vlen)), + d_vlen(vlen), + d_k(gr_complex(1, 0)) +{ + d_tag_key = pmt::intern(tag_name); + + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); +} + +multiply_by_tag_value_cc_impl::~multiply_by_tag_value_cc_impl() {} + +gr_complex multiply_by_tag_value_cc_impl::k() const { return d_k; } + +int multiply_by_tag_value_cc_impl::work(int noutput_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]; + + std::vector<tag_t> tags; + get_tags_in_window(tags, 0, 0, noutput_items, d_tag_key); + + std::vector<tag_t>::iterator itag = tags.begin(); + + int start = 0, end; + while (itag != tags.end()) { end = itag->offset - nitems_read(0); end *= d_vlen; // Multiply based on the current value of k from 'start' to 'end' - volk_32fc_s32fc_multiply_32fc(&out[start], &in[start], d_k, (end-start)); + volk_32fc_s32fc_multiply_32fc(&out[start], &in[start], d_k, (end - start)); start = end; // Extract new value of k pmt::pmt_t k = itag->value; - if(pmt::is_complex(k)) { - d_k = pmt::to_complex(k); - } - else if(pmt::is_number(k)) { - d_k = gr_complex(pmt::to_double(k), 0); - } - else { - GR_LOG_WARN(d_logger, - boost::format("Got key '%1%' with incompatible value of '%2%'") \ - % pmt::write_string(d_tag_key) % pmt::write_string(k)); + if (pmt::is_complex(k)) { + d_k = pmt::to_complex(k); + } else if (pmt::is_number(k)) { + d_k = gr_complex(pmt::to_double(k), 0); + } else { + GR_LOG_WARN(d_logger, + boost::format("Got key '%1%' with incompatible value of '%2%'") % + pmt::write_string(d_tag_key) % pmt::write_string(k)); } itag++; - } + } - volk_32fc_s32fc_multiply_32fc(&out[start], &in[start], d_k, - (d_vlen*noutput_items-start)); + volk_32fc_s32fc_multiply_32fc( + &out[start], &in[start], d_k, (d_vlen * noutput_items - start)); - return noutput_items; - } + return noutput_items; +} - void - multiply_by_tag_value_cc_impl::setup_rpc() - { +void multiply_by_tag_value_cc_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( + add_rpc_variable( rpcbasic_sptr(new rpcbasic_register_get<multiply_by_tag_value_cc, gr_complex>( - alias(), "Constant", - &multiply_by_tag_value_cc::k, - pmt::from_complex(-1024.0f, 0.0f), - pmt::from_complex(1024.0f, 0.0f), - pmt::from_complex(0.0f, 0.0f), - "", "Constant to multiply", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); + alias(), + "Constant", + &multiply_by_tag_value_cc::k, + pmt::from_complex(-1024.0f, 0.0f), + pmt::from_complex(1024.0f, 0.0f), + pmt::from_complex(0.0f, 0.0f), + "", + "Constant to multiply", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/multiply_by_tag_value_cc_impl.h b/gr-blocks/lib/multiply_by_tag_value_cc_impl.h index 23adcc9aab..ff45ee3c6c 100644 --- a/gr-blocks/lib/multiply_by_tag_value_cc_impl.h +++ b/gr-blocks/lib/multiply_by_tag_value_cc_impl.h @@ -26,31 +26,29 @@ #include <gnuradio/blocks/multiply_by_tag_value_cc.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API multiply_by_tag_value_cc_impl - : public multiply_by_tag_value_cc - { - private: - size_t d_vlen; - pmt::pmt_t d_tag_key; - gr_complex d_k; +class BLOCKS_API multiply_by_tag_value_cc_impl : public multiply_by_tag_value_cc +{ +private: + size_t d_vlen; + pmt::pmt_t d_tag_key; + gr_complex d_k; - public: - multiply_by_tag_value_cc_impl(const std::string& tag_name, - size_t vlen); - ~multiply_by_tag_value_cc_impl(); +public: + multiply_by_tag_value_cc_impl(const std::string& tag_name, size_t vlen); + ~multiply_by_tag_value_cc_impl(); - gr_complex k() const; + gr_complex k() const; - void setup_rpc(); + void setup_rpc(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_IMPL_H */ diff --git a/gr-blocks/lib/multiply_conjugate_cc_impl.cc b/gr-blocks/lib/multiply_conjugate_cc_impl.cc index a6d47cb070..7bb57f8792 100644 --- a/gr-blocks/lib/multiply_conjugate_cc_impl.cc +++ b/gr-blocks/lib/multiply_conjugate_cc_impl.cc @@ -29,38 +29,36 @@ #include <volk/volk.h> namespace gr { - namespace blocks { +namespace blocks { - multiply_conjugate_cc::sptr multiply_conjugate_cc::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new multiply_conjugate_cc_impl(vlen)); - } +multiply_conjugate_cc::sptr multiply_conjugate_cc::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new multiply_conjugate_cc_impl(vlen)); +} - multiply_conjugate_cc_impl::multiply_conjugate_cc_impl(size_t vlen) - : sync_block("multiply_conjugate_cc", - io_signature::make (2, 2, sizeof(gr_complex)*vlen), - io_signature::make (1, 1, sizeof(gr_complex)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(std::max(1, alignment_multiple)); - } +multiply_conjugate_cc_impl::multiply_conjugate_cc_impl(size_t vlen) + : sync_block("multiply_conjugate_cc", + io_signature::make(2, 2, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(gr_complex) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); +} - int - multiply_conjugate_cc_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr_complex *in0 = (gr_complex *) input_items[0]; - gr_complex *in1 = (gr_complex *) input_items[1]; - gr_complex *out = (gr_complex *) output_items[0]; - int noi = d_vlen*noutput_items; +int multiply_conjugate_cc_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr_complex* in0 = (gr_complex*)input_items[0]; + gr_complex* in1 = (gr_complex*)input_items[1]; + gr_complex* out = (gr_complex*)output_items[0]; + int noi = d_vlen * noutput_items; - volk_32fc_x2_multiply_conjugate_32fc(out, in0, in1, noi); + volk_32fc_x2_multiply_conjugate_32fc(out, in0, in1, noi); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/multiply_conjugate_cc_impl.h b/gr-blocks/lib/multiply_conjugate_cc_impl.h index ef4d73bb32..1f7f31091d 100644 --- a/gr-blocks/lib/multiply_conjugate_cc_impl.h +++ b/gr-blocks/lib/multiply_conjugate_cc_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/multiply_conjugate_cc.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API multiply_conjugate_cc_impl : public multiply_conjugate_cc - { - size_t d_vlen; +class BLOCKS_API multiply_conjugate_cc_impl : public multiply_conjugate_cc +{ + size_t d_vlen; - public: - multiply_conjugate_cc_impl(size_t vlen); +public: + multiply_conjugate_cc_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/multiply_const_impl.cc b/gr-blocks/lib/multiply_const_impl.cc index 03ac054a0e..bd6f442fc2 100644 --- a/gr-blocks/lib/multiply_const_impl.cc +++ b/gr-blocks/lib/multiply_const_impl.cc @@ -30,110 +30,108 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - template <class T> - typename multiply_const<T>::sptr multiply_const<T>::make(T k, size_t vlen) - { - return gnuradio::get_initial_sptr(new multiply_const_impl<T> (k, vlen)); - } - - template <> - multiply_const_impl<float>::multiply_const_impl(float k, size_t vlen) - : sync_block ("multiply_const_ff", - io_signature::make (1, 1, sizeof (float)*vlen), - io_signature::make (1, 1, sizeof (float)*vlen)), - d_k(k), d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } - - template<> - int - multiply_const_impl<float>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float *) input_items[0]; - float *out = (float *) output_items[0]; - int noi = noutput_items * d_vlen; - - volk_32f_s32f_multiply_32f(out, in, d_k, noi); - - return noutput_items; - } - - template <> - multiply_const_impl<gr_complex>::multiply_const_impl(gr_complex k, size_t vlen) - : sync_block ("multiply_const_cc", - io_signature::make (1, 1, sizeof (gr_complex)*vlen), - io_signature::make (1, 1, sizeof (gr_complex)*vlen)), - d_k(k), d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(std::max(1,alignment_multiple)); - } - - template <> - int - multiply_const_impl<gr_complex>::work(int noutput_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]; - int noi = noutput_items * d_vlen; - - volk_32fc_s32fc_multiply_32fc(out, in, d_k, noi); - - return noutput_items; +namespace blocks { + +template <class T> +typename multiply_const<T>::sptr multiply_const<T>::make(T k, size_t vlen) +{ + return gnuradio::get_initial_sptr(new multiply_const_impl<T>(k, vlen)); +} + +template <> +multiply_const_impl<float>::multiply_const_impl(float k, size_t vlen) + : sync_block("multiply_const_ff", + io_signature::make(1, 1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_k(k), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +template <> +int multiply_const_impl<float>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + float* out = (float*)output_items[0]; + int noi = noutput_items * d_vlen; + + volk_32f_s32f_multiply_32f(out, in, d_k, noi); + + return noutput_items; +} + +template <> +multiply_const_impl<gr_complex>::multiply_const_impl(gr_complex k, size_t vlen) + : sync_block("multiply_const_cc", + io_signature::make(1, 1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(gr_complex) * vlen)), + d_k(k), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); +} + +template <> +int multiply_const_impl<gr_complex>::work(int noutput_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]; + int noi = noutput_items * d_vlen; + + volk_32fc_s32fc_multiply_32fc(out, in, d_k, noi); + + return noutput_items; +} + + +template <class T> +multiply_const_impl<T>::multiply_const_impl(T k, size_t vlen) + : sync_block("multiply_const", + io_signature::make(1, 1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), + d_k(k), + d_vlen(vlen) +{ +} + +template <class T> +int multiply_const_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; + T* optr = (T*)output_items[0]; + + int size = noutput_items * d_vlen; + + while (size >= 8) { + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + *optr++ = *iptr++ * d_k; + size -= 8; } + while (size-- > 0) + *optr++ = *iptr++ * d_k; - template <class T> - multiply_const_impl<T> ::multiply_const_impl(T k, size_t vlen) - : sync_block ("multiply_const", - io_signature::make (1, 1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), - d_k(k), d_vlen(vlen) - { - } - - template <class T> - int - multiply_const_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T *) input_items[0]; - T *optr = (T *) output_items[0]; - - int size = noutput_items * d_vlen; - - while (size >= 8){ - *optr++ = *iptr++ * d_k; - *optr++ = *iptr++ * d_k; - *optr++ = *iptr++ * d_k; - *optr++ = *iptr++ * d_k; - *optr++ = *iptr++ * d_k; - *optr++ = *iptr++ * d_k; - *optr++ = *iptr++ * d_k; - *optr++ = *iptr++ * d_k; - size -= 8; - } - - while (size-- > 0) - *optr++ = *iptr++ * d_k; - - return noutput_items; - } + return noutput_items; +} template class multiply_const<std::int16_t>; template class multiply_const<std::int32_t>; template class multiply_const<float>; template class multiply_const<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/multiply_const_impl.h b/gr-blocks/lib/multiply_const_impl.h index 674fc66609..19501efd80 100644 --- a/gr-blocks/lib/multiply_const_impl.h +++ b/gr-blocks/lib/multiply_const_impl.h @@ -27,26 +27,26 @@ #include <gnuradio/blocks/multiply_const.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API multiply_const_impl : public multiply_const<T> - { - T d_k; - size_t d_vlen; +template <class T> +class BLOCKS_API multiply_const_impl : public multiply_const<T> +{ + T d_k; + size_t d_vlen; - public: - multiply_const_impl (T k, size_t vlen); +public: + multiply_const_impl(T k, size_t vlen); - T k() const { return d_k; } - void set_k(T k) { d_k = k; } + T k() const { return d_k; } + void set_k(T k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* MULTIPLY_CONST_IMPL_H */ diff --git a/gr-blocks/lib/multiply_const_v_impl.cc b/gr-blocks/lib/multiply_const_v_impl.cc index cab920d90c..172d327d52 100644 --- a/gr-blocks/lib/multiply_const_v_impl.cc +++ b/gr-blocks/lib/multiply_const_v_impl.cc @@ -29,110 +29,106 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - template <class T> - typename multiply_const_v<T>::sptr multiply_const_v<T>::make(std::vector<T> k) - { - return gnuradio::get_initial_sptr(new multiply_const_v_impl<T>(k)); - } - - template <> - multiply_const_v_impl<float>::multiply_const_v_impl(std::vector<float> k) - : sync_block("multiply_const_vff", - io_signature::make(1, 1, sizeof(float)*k.size()), - io_signature::make(1, 1, sizeof(float)*k.size())), - d_k(k) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } - - template <> - int - multiply_const_v_impl<float>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float *iptr = (float*)input_items[0]; - float *optr = (float*)output_items[0]; - - int nitems_per_block = this->output_signature()->sizeof_stream_item(0)/sizeof(float); - - for(int i = 0; i < noutput_items; i++) { - for(int j = 0; j < nitems_per_block; j++) { - *optr++ = *iptr++ * d_k[j]; +namespace blocks { + +template <class T> +typename multiply_const_v<T>::sptr multiply_const_v<T>::make(std::vector<T> k) +{ + return gnuradio::get_initial_sptr(new multiply_const_v_impl<T>(k)); +} + +template <> +multiply_const_v_impl<float>::multiply_const_v_impl(std::vector<float> k) + : sync_block("multiply_const_vff", + io_signature::make(1, 1, sizeof(float) * k.size()), + io_signature::make(1, 1, sizeof(float) * k.size())), + d_k(k) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +template <> +int multiply_const_v_impl<float>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float* iptr = (float*)input_items[0]; + float* optr = (float*)output_items[0]; + + int nitems_per_block = + this->output_signature()->sizeof_stream_item(0) / sizeof(float); + + for (int i = 0; i < noutput_items; i++) { + for (int j = 0; j < nitems_per_block; j++) { + *optr++ = *iptr++ * d_k[j]; } - } - - return noutput_items; - } - - template <> - multiply_const_v_impl<gr_complex>::multiply_const_v_impl(std::vector<gr_complex> k) - : sync_block("multiply_const_vcc", - io_signature::make(1, 1, sizeof(gr_complex)*k.size()), - io_signature::make(1, 1, sizeof(gr_complex)*k.size())), - d_k(k) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(std::max(1,alignment_multiple)); } - template <> - int - multiply_const_v_impl<gr_complex>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr_complex *iptr = (gr_complex*)input_items[0]; - gr_complex *optr = (gr_complex*)output_items[0]; + return noutput_items; +} - int nitems_per_block = this->output_signature()->sizeof_stream_item(0)/sizeof(gr_complex); - - for(int i = 0; i < noutput_items; i++) { - for(int j = 0; j < nitems_per_block; j++) { - *optr++ = *iptr++ * d_k[j]; +template <> +multiply_const_v_impl<gr_complex>::multiply_const_v_impl(std::vector<gr_complex> k) + : sync_block("multiply_const_vcc", + io_signature::make(1, 1, sizeof(gr_complex) * k.size()), + io_signature::make(1, 1, sizeof(gr_complex) * k.size())), + d_k(k) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); +} + +template <> +int multiply_const_v_impl<gr_complex>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr_complex* iptr = (gr_complex*)input_items[0]; + gr_complex* optr = (gr_complex*)output_items[0]; + + int nitems_per_block = + this->output_signature()->sizeof_stream_item(0) / sizeof(gr_complex); + + for (int i = 0; i < noutput_items; i++) { + for (int j = 0; j < nitems_per_block; j++) { + *optr++ = *iptr++ * d_k[j]; } - } - - return noutput_items; } + return noutput_items; +} - template <class T> - multiply_const_v_impl<T>::multiply_const_v_impl(std::vector<T> k) - : sync_block ("multiply_const_v<T>", - io_signature::make (1, 1, sizeof (T)*k.size()), - io_signature::make (1, 1, sizeof (T)*k.size())), +template <class T> +multiply_const_v_impl<T>::multiply_const_v_impl(std::vector<T> k) + : sync_block("multiply_const_v<T>", + io_signature::make(1, 1, sizeof(T) * k.size()), + io_signature::make(1, 1, sizeof(T) * k.size())), d_k(k) - { - } - - template <class T> - int - multiply_const_v_impl<T>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T *)input_items[0]; - T *optr = (T *)output_items[0]; - - int nitems_per_block = this->output_signature()->sizeof_stream_item(0)/sizeof(T); - - for (int i = 0; i < noutput_items; i++) - for (int j = 0; j < nitems_per_block; j++) - *optr++ = *iptr++ * d_k[j]; - - return noutput_items; - } - - template class multiply_const_v<std::int16_t>; - template class multiply_const_v<std::int32_t>; - template class multiply_const_v<float>; - template class multiply_const_v<gr_complex>; - } /* namespace blocks */ +{ +} + +template <class T> +int multiply_const_v_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; + T* optr = (T*)output_items[0]; + + int nitems_per_block = this->output_signature()->sizeof_stream_item(0) / sizeof(T); + + for (int i = 0; i < noutput_items; i++) + for (int j = 0; j < nitems_per_block; j++) + *optr++ = *iptr++ * d_k[j]; + + return noutput_items; +} + +template class multiply_const_v<std::int16_t>; +template class multiply_const_v<std::int32_t>; +template class multiply_const_v<float>; +template class multiply_const_v<gr_complex>; +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/multiply_const_v_impl.h b/gr-blocks/lib/multiply_const_v_impl.h index a329c12dd3..70bae818ac 100644 --- a/gr-blocks/lib/multiply_const_v_impl.h +++ b/gr-blocks/lib/multiply_const_v_impl.h @@ -26,25 +26,25 @@ #include <gnuradio/blocks/multiply_const_v.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - class BLOCKS_API multiply_const_v_impl : public multiply_const_v<T> - { - std::vector<T> d_k; +template <class T> +class BLOCKS_API multiply_const_v_impl : public multiply_const_v<T> +{ + std::vector<T> d_k; - public: - multiply_const_v_impl(std::vector<T> k); +public: + multiply_const_v_impl(std::vector<T> k); - std::vector<T> k() const { return d_k; } - void set_k(std::vector<T> k) { d_k = k; } + std::vector<T> k() const { return d_k; } + void set_k(std::vector<T> k) { d_k = k; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* MULTIPLY_CONST_V_IMPL_H */ diff --git a/gr-blocks/lib/multiply_impl.cc b/gr-blocks/lib/multiply_impl.cc index 22845251fb..5778f17ba7 100644 --- a/gr-blocks/lib/multiply_impl.cc +++ b/gr-blocks/lib/multiply_impl.cc @@ -30,103 +30,98 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - template <class T> - typename multiply<T>::sptr multiply<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new multiply_impl<T> (vlen)); - } - - template <> - multiply_impl<float>::multiply_impl(size_t vlen) - : sync_block("multiply_ff", - io_signature::make (1, -1, sizeof(float)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1, alignment_multiple)); - } - - template<> - int - multiply_impl<float>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float *out = (float *) output_items[0]; - int noi = d_vlen*noutput_items; - - memcpy(out, input_items[0], noi*sizeof(float)); - for(size_t i = 1; i < input_items.size(); i++) +namespace blocks { + +template <class T> +typename multiply<T>::sptr multiply<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new multiply_impl<T>(vlen)); +} + +template <> +multiply_impl<float>::multiply_impl(size_t vlen) + : sync_block("multiply_ff", + io_signature::make(1, -1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +template <> +int multiply_impl<float>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float* out = (float*)output_items[0]; + int noi = d_vlen * noutput_items; + + memcpy(out, input_items[0], noi * sizeof(float)); + for (size_t i = 1; i < input_items.size(); i++) volk_32f_x2_multiply_32f(out, out, (float*)input_items[i], noi); - return noutput_items; - } - - template <> - multiply_impl<gr_complex>::multiply_impl(size_t vlen) - : sync_block("multiply_cc", - io_signature::make (1, -1, sizeof(gr_complex)*vlen), - io_signature::make (1, 1, sizeof(gr_complex)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(gr_complex); - set_alignment(std::max(1, alignment_multiple)); - } + return noutput_items; +} - template <> - int - multiply_impl<gr_complex>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr_complex *out = (gr_complex *) output_items[0]; - int noi = d_vlen*noutput_items; - - memcpy(out, input_items[0], noi*sizeof(gr_complex)); - for(size_t i = 1; i < input_items.size(); i++) +template <> +multiply_impl<gr_complex>::multiply_impl(size_t vlen) + : sync_block("multiply_cc", + io_signature::make(1, -1, sizeof(gr_complex) * vlen), + io_signature::make(1, 1, sizeof(gr_complex) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); +} + +template <> +int multiply_impl<gr_complex>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr_complex* out = (gr_complex*)output_items[0]; + int noi = d_vlen * noutput_items; + + memcpy(out, input_items[0], noi * sizeof(gr_complex)); + for (size_t i = 1; i < input_items.size(); i++) volk_32fc_x2_multiply_32fc(out, out, (gr_complex*)input_items[i], noi); - return noutput_items; - } + return noutput_items; +} - template <class T> - multiply_impl<T> ::multiply_impl(size_t vlen) - : sync_block ("multiply", - io_signature::make (1, -1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), +template <class T> +multiply_impl<T>::multiply_impl(size_t vlen) + : sync_block("multiply", + io_signature::make(1, -1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), d_vlen(vlen) - { - } - - template <class T> - int - multiply_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *) output_items[0]; +{ +} - int ninputs = input_items.size (); +template <class T> +int multiply_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; - for (size_t i = 0; i < noutput_items*d_vlen; i++){ - T acc = ((T *) input_items[0])[i]; - for (int j = 1; j < ninputs; j++) - acc *= ((T *) input_items[j])[i]; + int ninputs = input_items.size(); - *optr++ = (T) acc; - } + for (size_t i = 0; i < noutput_items * d_vlen; i++) { + T acc = ((T*)input_items[0])[i]; + for (int j = 1; j < ninputs; j++) + acc *= ((T*)input_items[j])[i]; - return noutput_items; + *optr++ = (T)acc; } + return noutput_items; +} + template class multiply<std::int16_t>; template class multiply<std::int32_t>; template class multiply<gr_complex>; template class multiply<float>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/multiply_impl.h b/gr-blocks/lib/multiply_impl.h index 7f75f85f9f..4c8d4d3ccb 100644 --- a/gr-blocks/lib/multiply_impl.h +++ b/gr-blocks/lib/multiply_impl.h @@ -27,21 +27,21 @@ #include <gnuradio/blocks/multiply.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API multiply_impl : public multiply<T> - { - size_t d_vlen; +template <class T> +class BLOCKS_API multiply_impl : public multiply<T> +{ + size_t d_vlen; - public: - multiply_impl (size_t vlen); +public: + multiply_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - } /* namespace blocks */ + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; +} /* namespace blocks */ } /* namespace gr */ #endif /* MULTIPLY_IMPL_H */ diff --git a/gr-blocks/lib/multiply_matrix_impl.cc b/gr-blocks/lib/multiply_matrix_impl.cc index 60053e7f56..eb0a77409d 100644 --- a/gr-blocks/lib/multiply_matrix_impl.cc +++ b/gr-blocks/lib/multiply_matrix_impl.cc @@ -29,299 +29,296 @@ #include "multiply_matrix_impl.h" namespace gr { - namespace blocks { +namespace blocks { - // Copy tags from input k to output l if A[l][k] is not zero - template <> - void - multiply_matrix_impl<gr_complex>::propagate_tags_by_A(int noutput_items, size_t ninput_ports, size_t noutput_ports) - { - std::vector<gr::tag_t> tags; - for (size_t in_idx = 0; in_idx < ninput_ports; in_idx++) { - this->get_tags_in_window( - tags, - in_idx, - 0, - noutput_items - ); +// Copy tags from input k to output l if A[l][k] is not zero +template <> +void multiply_matrix_impl<gr_complex>::propagate_tags_by_A(int noutput_items, + size_t ninput_ports, + size_t noutput_ports) +{ + std::vector<gr::tag_t> tags; + for (size_t in_idx = 0; in_idx < ninput_ports; in_idx++) { + this->get_tags_in_window(tags, in_idx, 0, noutput_items); for (size_t out_idx = 0; out_idx < noutput_ports; out_idx++) { - if (d_A[out_idx][in_idx] == std::complex<float>(0, 0)) { - continue; - } - for (size_t i = 0; i < tags.size(); i++) { - this->add_item_tag(out_idx, tags[i]); - } + if (d_A[out_idx][in_idx] == std::complex<float>(0, 0)) { + continue; + } + for (size_t i = 0; i < tags.size(); i++) { + this->add_item_tag(out_idx, tags[i]); + } } - } } +} - // Check dimensions before copying - template <> - bool - multiply_matrix_impl<gr_complex>::set_A(const std::vector<std::vector<gr_complex> > &new_A) - { - if (d_A.size() != new_A.size()) { +// Check dimensions before copying +template <> +bool multiply_matrix_impl<gr_complex>::set_A( + const std::vector<std::vector<gr_complex>>& new_A) +{ + if (d_A.size() != new_A.size()) { GR_LOG_ALERT(d_logger, "Attempted to set matrix with invalid dimensions."); return false; - } - for (size_t i = 0; i < d_A.size(); i++) { + } + for (size_t i = 0; i < d_A.size(); i++) { if (d_A[i].size() != new_A[i].size()) { - GR_LOG_ALERT(d_logger, "Attempted to set matrix with invalid dimensions."); - return false; + GR_LOG_ALERT(d_logger, "Attempted to set matrix with invalid dimensions."); + return false; } - } - d_A = new_A; - return true; } + d_A = new_A; + return true; +} - template <> - void - multiply_matrix_impl<gr_complex>::msg_handler_A(pmt::pmt_t A) - { - if (!pmt::is_vector(A) && !pmt::is_tuple(A)) { - GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong type)."); - return; - } - if (pmt::length(A) != d_A.size()) { - GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong size)."); - return; - } +template <> +void multiply_matrix_impl<gr_complex>::msg_handler_A(pmt::pmt_t A) +{ + if (!pmt::is_vector(A) && !pmt::is_tuple(A)) { + GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong type)."); + return; + } + if (pmt::length(A) != d_A.size()) { + GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong size)."); + return; + } - std::vector<std::vector<gr_complex> > new_A(d_A); - for (size_t i = 0; i < pmt::length(A); i++) { + std::vector<std::vector<gr_complex>> new_A(d_A); + for (size_t i = 0; i < pmt::length(A); i++) { pmt::pmt_t row; if (pmt::is_vector(A)) { - row = pmt::vector_ref(A, i); + row = pmt::vector_ref(A, i); } else if (pmt::is_tuple(A)) { - row = pmt::tuple_ref(A, i); + row = pmt::tuple_ref(A, i); } if (pmt::is_vector(row) || pmt::is_tuple(row)) { - if (pmt::length(row) != d_A[0].size()) { - GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong number of columns)."); - return; - } - for (size_t k = 0; k < pmt::length(row); k++) { - new_A[i][k] = pmt::to_complex(pmt::is_vector(row) ? pmt::vector_ref(row, k) : pmt::tuple_ref(row, k)); - } + if (pmt::length(row) != d_A[0].size()) { + GR_LOG_ALERT(d_logger, + "Invalid message to set A (wrong number of columns)."); + return; + } + for (size_t k = 0; k < pmt::length(row); k++) { + new_A[i][k] = + pmt::to_complex(pmt::is_vector(row) ? pmt::vector_ref(row, k) + : pmt::tuple_ref(row, k)); + } } else if (pmt::is_c32vector(row)) { - size_t row_len = 0; - const gr_complex *elements = pmt::c32vector_elements(row, row_len); - if (row_len != d_A[0].size()) { - GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong number of columns)."); - return; - } - new_A[i].assign(elements, elements + row_len); + size_t row_len = 0; + const gr_complex* elements = pmt::c32vector_elements(row, row_len); + if (row_len != d_A[0].size()) { + GR_LOG_ALERT(d_logger, + "Invalid message to set A (wrong number of columns)."); + return; + } + new_A[i].assign(elements, elements + row_len); } - } + } - if (!set_A(new_A)) { - GR_LOG_ALERT(d_logger, "Invalid message to set A."); - } + if (!set_A(new_A)) { + GR_LOG_ALERT(d_logger, "Invalid message to set A."); } +} - // Copy tags from input k to output l if A[l][k] is not zero - template <> - void - multiply_matrix_impl<float>::propagate_tags_by_A(int noutput_items, size_t ninput_ports, size_t noutput_ports) - { - std::vector<gr::tag_t> tags; - for (size_t in_idx = 0; in_idx < ninput_ports; in_idx++) { - get_tags_in_window( - tags, - in_idx, - 0, - noutput_items - ); +// Copy tags from input k to output l if A[l][k] is not zero +template <> +void multiply_matrix_impl<float>::propagate_tags_by_A(int noutput_items, + size_t ninput_ports, + size_t noutput_ports) +{ + std::vector<gr::tag_t> tags; + for (size_t in_idx = 0; in_idx < ninput_ports; in_idx++) { + get_tags_in_window(tags, in_idx, 0, noutput_items); for (size_t out_idx = 0; out_idx < noutput_ports; out_idx++) { - if (d_A[out_idx][in_idx] == 0) { - continue; - } - for (size_t i = 0; i < tags.size(); i++) { - add_item_tag(out_idx, tags[i]); - } + if (d_A[out_idx][in_idx] == 0) { + continue; + } + for (size_t i = 0; i < tags.size(); i++) { + add_item_tag(out_idx, tags[i]); + } } - } } +} - // Check dimensions before copying - template <> - bool - multiply_matrix_impl<float>::set_A(const std::vector<std::vector<float> > &new_A) - { - if (d_A.size() != new_A.size()) { +// Check dimensions before copying +template <> +bool multiply_matrix_impl<float>::set_A(const std::vector<std::vector<float>>& new_A) +{ + if (d_A.size() != new_A.size()) { GR_LOG_ALERT(d_logger, "Attempted to set matrix with invalid dimensions."); return false; - } - for (size_t i = 0; i < d_A.size(); i++) { + } + for (size_t i = 0; i < d_A.size(); i++) { if (d_A[i].size() != new_A[i].size()) { - GR_LOG_ALERT(d_logger, "Attempted to set matrix with invalid dimensions."); - return false; + GR_LOG_ALERT(d_logger, "Attempted to set matrix with invalid dimensions."); + return false; } - } - d_A = new_A; - return true; } + d_A = new_A; + return true; +} - template <> - void - multiply_matrix_impl<float>::msg_handler_A(pmt::pmt_t A) - { - if (!pmt::is_vector(A) && !pmt::is_tuple(A)) { - GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong type)."); - return; - } - if (pmt::length(A) != d_A.size()) { - GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong size)."); - return; - } +template <> +void multiply_matrix_impl<float>::msg_handler_A(pmt::pmt_t A) +{ + if (!pmt::is_vector(A) && !pmt::is_tuple(A)) { + GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong type)."); + return; + } + if (pmt::length(A) != d_A.size()) { + GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong size)."); + return; + } - std::vector<std::vector<float> > new_A(d_A); - for (size_t i = 0; i < pmt::length(A); i++) { + std::vector<std::vector<float>> new_A(d_A); + for (size_t i = 0; i < pmt::length(A); i++) { pmt::pmt_t row; if (pmt::is_vector(A)) { - row = pmt::vector_ref(A, i); + row = pmt::vector_ref(A, i); } else if (pmt::is_tuple(A)) { - row = pmt::tuple_ref(A, i); + row = pmt::tuple_ref(A, i); } if (pmt::is_vector(row) || pmt::is_tuple(row)) { - if (pmt::length(row) != d_A[0].size()) { - GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong number of columns)."); - return; - } - for (size_t k = 0; k < pmt::length(row); k++) { - new_A[i][k] = pmt::to_double(pmt::is_vector(row) ? pmt::vector_ref(row, k) : pmt::tuple_ref(row, k)); - } + if (pmt::length(row) != d_A[0].size()) { + GR_LOG_ALERT(d_logger, + "Invalid message to set A (wrong number of columns)."); + return; + } + for (size_t k = 0; k < pmt::length(row); k++) { + new_A[i][k] = + pmt::to_double(pmt::is_vector(row) ? pmt::vector_ref(row, k) + : pmt::tuple_ref(row, k)); + } } else if (pmt::is_f32vector(row)) { - size_t row_len = 0; - const float *elements = pmt::f32vector_elements(row, row_len); - if (row_len != d_A[0].size()) { - GR_LOG_ALERT(d_logger, "Invalid message to set A (wrong number of columns)."); - return; - } - new_A[i].assign(elements, elements + row_len); + size_t row_len = 0; + const float* elements = pmt::f32vector_elements(row, row_len); + if (row_len != d_A[0].size()) { + GR_LOG_ALERT(d_logger, + "Invalid message to set A (wrong number of columns)."); + return; + } + new_A[i].assign(elements, elements + row_len); } - } - - if (!set_A(new_A)) { - GR_LOG_ALERT(d_logger, "Invalid message to set A."); - } } + if (!set_A(new_A)) { + GR_LOG_ALERT(d_logger, "Invalid message to set A."); + } +} - template <class T> - typename multiply_matrix<T>::sptr - multiply_matrix<T>::make(std::vector<std::vector<T> > A, gr::block::tag_propagation_policy_t tag_propagation_policy) - { - if (A.empty() || A[0].size() == 0) { +template <class T> +typename multiply_matrix<T>::sptr +multiply_matrix<T>::make(std::vector<std::vector<T>> A, + gr::block::tag_propagation_policy_t tag_propagation_policy) +{ + if (A.empty() || A[0].size() == 0) { throw std::invalid_argument("matrix A has invalid dimensions."); - } - return gnuradio::get_initial_sptr - (new multiply_matrix_impl<T>(A, tag_propagation_policy)); } + return gnuradio::get_initial_sptr( + new multiply_matrix_impl<T>(A, tag_propagation_policy)); +} - template <> - multiply_matrix_impl<gr_complex>::multiply_matrix_impl(std::vector<std::vector<gr_complex> > A, gr::block::tag_propagation_policy_t tag_propagation_policy) - : gr::sync_block("multiply_matrix_cc", - gr::io_signature::make(A[0].size(), A[0].size(), sizeof(gr_complex)), - gr::io_signature::make(A.size(), A.size(), sizeof(gr_complex))), - d_A(A) - { this->MSG_PORT_NAME_SET_A = "set_A"; - this->set_tag_propagation_policy(tag_propagation_policy); - const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); - set_alignment(std::max(1, alignment_multiple)); +template <> +multiply_matrix_impl<gr_complex>::multiply_matrix_impl( + std::vector<std::vector<gr_complex>> A, + gr::block::tag_propagation_policy_t tag_propagation_policy) + : gr::sync_block("multiply_matrix_cc", + gr::io_signature::make(A[0].size(), A[0].size(), sizeof(gr_complex)), + gr::io_signature::make(A.size(), A.size(), sizeof(gr_complex))), + d_A(A) +{ + this->MSG_PORT_NAME_SET_A = "set_A"; + this->set_tag_propagation_policy(tag_propagation_policy); + const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); - pmt::pmt_t port_name = pmt::string_to_symbol("set_A"); - message_port_register_in(port_name); - set_msg_handler( - port_name, - boost::bind(&multiply_matrix_impl<gr_complex>::msg_handler_A, this, _1) - ); - } + pmt::pmt_t port_name = pmt::string_to_symbol("set_A"); + message_port_register_in(port_name); + set_msg_handler( + port_name, + boost::bind(&multiply_matrix_impl<gr_complex>::msg_handler_A, this, _1)); +} - template <> - multiply_matrix_impl<float>::multiply_matrix_impl(std::vector<std::vector<float> > A, gr::block::tag_propagation_policy_t tag_propagation_policy) - : gr::sync_block("multiply_matrix_ff", - gr::io_signature::make(A[0].size(), A[0].size(), sizeof(float)), - gr::io_signature::make(A.size(), A.size(), sizeof(float))), - d_A(A) - { this->MSG_PORT_NAME_SET_A = "set_A"; - this->set_tag_propagation_policy(tag_propagation_policy); - const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(std::max(1, alignment_multiple)); +template <> +multiply_matrix_impl<float>::multiply_matrix_impl( + std::vector<std::vector<float>> A, + gr::block::tag_propagation_policy_t tag_propagation_policy) + : gr::sync_block("multiply_matrix_ff", + gr::io_signature::make(A[0].size(), A[0].size(), sizeof(float)), + gr::io_signature::make(A.size(), A.size(), sizeof(float))), + d_A(A) +{ + this->MSG_PORT_NAME_SET_A = "set_A"; + this->set_tag_propagation_policy(tag_propagation_policy); + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); - pmt::pmt_t port_name = pmt::string_to_symbol("set_A"); - message_port_register_in(port_name); - set_msg_handler( - port_name, - boost::bind(&multiply_matrix_impl<float>::msg_handler_A, this, _1) - ); - } + pmt::pmt_t port_name = pmt::string_to_symbol("set_A"); + message_port_register_in(port_name); + set_msg_handler(port_name, + boost::bind(&multiply_matrix_impl<float>::msg_handler_A, this, _1)); +} +template <class T> +multiply_matrix_impl<T>::~multiply_matrix_impl() +{ +} - template <class T> - multiply_matrix_impl<T>::~multiply_matrix_impl() - { - } - - template <> - int - multiply_matrix_impl<gr_complex>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - for (size_t out_idx = 0; out_idx < output_items.size(); out_idx++) { - gr_complex *out = reinterpret_cast<gr_complex *>(output_items[out_idx]); +template <> +int multiply_matrix_impl<gr_complex>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + for (size_t out_idx = 0; out_idx < output_items.size(); out_idx++) { + gr_complex* out = reinterpret_cast<gr_complex*>(output_items[out_idx]); // Do input 0 first, this saves a memset - const gr_complex *in = reinterpret_cast<const gr_complex *>(input_items[0]); + const gr_complex* in = reinterpret_cast<const gr_complex*>(input_items[0]); volk_32fc_s32fc_multiply_32fc(out, in, d_A[out_idx][0], noutput_items); // Then do inputs 1 through N for (size_t in_idx = 1; in_idx < input_items.size(); in_idx++) { - in = reinterpret_cast<const gr_complex *>(input_items[in_idx]); - // Yeah, this needs VOLK-ifying (TODO) - for (int i = 0; i < noutput_items; i++) { - out[i] += in[i] * d_A[out_idx][in_idx]; - } + in = reinterpret_cast<const gr_complex*>(input_items[in_idx]); + // Yeah, this needs VOLK-ifying (TODO) + for (int i = 0; i < noutput_items; i++) { + out[i] += in[i] * d_A[out_idx][in_idx]; + } } - } - if (tag_propagation_policy() == TPP_CUSTOM) { + } + if (tag_propagation_policy() == TPP_CUSTOM) { propagate_tags_by_A(noutput_items, input_items.size(), output_items.size()); - } - return noutput_items; } + return noutput_items; +} - template <> - int - multiply_matrix_impl<float>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - for (size_t out_idx = 0; out_idx < output_items.size(); out_idx++) { - float *out = reinterpret_cast<float *>(output_items[out_idx]); +template <> +int multiply_matrix_impl<float>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + for (size_t out_idx = 0; out_idx < output_items.size(); out_idx++) { + float* out = reinterpret_cast<float*>(output_items[out_idx]); // Do input 0 first, this saves a memset - const float *in = reinterpret_cast<const float *>(input_items[0]); + const float* in = reinterpret_cast<const float*>(input_items[0]); volk_32f_s32f_multiply_32f(out, in, d_A[out_idx][0], noutput_items); // Then do inputs 1 through N for (size_t in_idx = 1; in_idx < input_items.size(); in_idx++) { - in = reinterpret_cast<const float *>(input_items[in_idx]); - // Yeah, this needs VOLK-ifying (TODO) - for (int i = 0; i < noutput_items; i++) { - out[i] += in[i] * d_A[out_idx][in_idx]; - } + in = reinterpret_cast<const float*>(input_items[in_idx]); + // Yeah, this needs VOLK-ifying (TODO) + for (int i = 0; i < noutput_items; i++) { + out[i] += in[i] * d_A[out_idx][in_idx]; + } } - } - if (tag_propagation_policy() == TPP_CUSTOM) { + } + if (tag_propagation_policy() == TPP_CUSTOM) { propagate_tags_by_A(noutput_items, input_items.size(), output_items.size()); - } - return noutput_items; } + return noutput_items; +} - template class multiply_matrix<float>; - template class multiply_matrix<gr_complex>; +template class multiply_matrix<float>; +template class multiply_matrix<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/multiply_matrix_impl.h b/gr-blocks/lib/multiply_matrix_impl.h index bb5477e805..6cbac7d5a6 100644 --- a/gr-blocks/lib/multiply_matrix_impl.h +++ b/gr-blocks/lib/multiply_matrix_impl.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ -/* +/* * Copyright 2014,2017-2018 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, @@ -26,31 +26,33 @@ #include <gnuradio/blocks/multiply_matrix.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - class multiply_matrix_impl : public multiply_matrix<T> - { - private: - std::vector<std::vector<T> > d_A; +template <class T> +class multiply_matrix_impl : public multiply_matrix<T> +{ +private: + std::vector<std::vector<T>> d_A; - void propagate_tags_by_A(int noutput_items, size_t ninput_ports, size_t noutput_ports); + void + propagate_tags_by_A(int noutput_items, size_t ninput_ports, size_t noutput_ports); - void msg_handler_A(pmt::pmt_t A); + void msg_handler_A(pmt::pmt_t A); - public: - multiply_matrix_impl(std::vector<std::vector<T> > A, gr::block::tag_propagation_policy_t tag_propagation_policy); - ~multiply_matrix_impl(); +public: + multiply_matrix_impl(std::vector<std::vector<T>> A, + gr::block::tag_propagation_policy_t tag_propagation_policy); + ~multiply_matrix_impl(); - const std::vector<std::vector<T> >& get_A() const { return d_A; }; - bool set_A(const std::vector<std::vector<T> > &new_A); + const std::vector<std::vector<T>>& get_A() const { return d_A; }; + bool set_A(const std::vector<std::vector<T>>& new_A); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } // namespace blocks +} // namespace blocks } // namespace gr #endif /* INCLUDED_BLOCKS_MULTIPLY_MATRIX_IMPL_H */ diff --git a/gr-blocks/lib/mute_impl.cc b/gr-blocks/lib/mute_impl.cc index 081dd81b35..34c0d4094e 100644 --- a/gr-blocks/lib/mute_impl.cc +++ b/gr-blocks/lib/mute_impl.cc @@ -30,70 +30,66 @@ #include <string.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename mute_blk<T>::sptr - mute_blk<T>::make(bool mute) - { - return gnuradio::get_initial_sptr - (new mute_impl<T> (mute)); - } +template <class T> +typename mute_blk<T>::sptr mute_blk<T>::make(bool mute) +{ + return gnuradio::get_initial_sptr(new mute_impl<T>(mute)); +} - template <class T> - mute_impl<T> ::mute_impl(bool mute) +template <class T> +mute_impl<T>::mute_impl(bool mute) : sync_block("mute", - io_signature::make(1, 1, sizeof(T)), - io_signature::make(1, 1, sizeof(T))), + io_signature::make(1, 1, sizeof(T)), + io_signature::make(1, 1, sizeof(T))), d_mute(mute) - { - this->message_port_register_in(pmt::intern("set_mute")); - this->set_msg_handler(pmt::intern("set_mute"), - boost::bind(&mute_impl<T> ::set_mute_pmt, this, _1)); - } +{ + this->message_port_register_in(pmt::intern("set_mute")); + this->set_msg_handler(pmt::intern("set_mute"), + boost::bind(&mute_impl<T>::set_mute_pmt, this, _1)); +} - template <class T> - mute_impl<T> ::~mute_impl() - { - } +template <class T> +mute_impl<T>::~mute_impl() +{ +} - template <class T> - int - mute_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T *)input_items[0]; - T *optr = (T *)output_items[0]; +template <class T> +int mute_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; + T* optr = (T*)output_items[0]; - int size = noutput_items; + int size = noutput_items; - if(d_mute) { + if (d_mute) { memset(optr, 0, noutput_items * sizeof(T)); - } - else { - while(size >= 8) { - *optr++ = *iptr++; - *optr++ = *iptr++; - *optr++ = *iptr++; - *optr++ = *iptr++; - *optr++ = *iptr++; - *optr++ = *iptr++; - *optr++ = *iptr++; - *optr++ = *iptr++; - size -= 8; + } else { + while (size >= 8) { + *optr++ = *iptr++; + *optr++ = *iptr++; + *optr++ = *iptr++; + *optr++ = *iptr++; + *optr++ = *iptr++; + *optr++ = *iptr++; + *optr++ = *iptr++; + *optr++ = *iptr++; + size -= 8; } - while(size-- > 0) - *optr++ = *iptr++; - } - - return noutput_items; + while (size-- > 0) + *optr++ = *iptr++; } + return noutput_items; +} + template class mute_blk<std::int16_t>; template class mute_blk<std::int32_t>; template class mute_blk<float>; template class mute_blk<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/mute_impl.h b/gr-blocks/lib/mute_impl.h index 6943e22739..5d54a0c940 100644 --- a/gr-blocks/lib/mute_impl.h +++ b/gr-blocks/lib/mute_impl.h @@ -27,28 +27,28 @@ #include <gnuradio/blocks/mute.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class mute_impl : public mute_blk<T> - { - private: - bool d_mute; +template <class T> +class mute_impl : public mute_blk<T> +{ +private: + bool d_mute; - public: - mute_impl (bool mute); - ~mute_impl (); +public: + mute_impl(bool mute); + ~mute_impl(); - bool mute() const { return d_mute; } - void set_mute(bool mute) { d_mute = mute; } - void set_mute_pmt(pmt::pmt_t msg) { set_mute(pmt::to_bool(msg)); } + bool mute() const { return d_mute; } + void set_mute(bool mute) { d_mute = mute; } + void set_mute_pmt(pmt::pmt_t msg) { set_mute(pmt::to_bool(msg)); } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* MUTE_IMPL_H */ diff --git a/gr-blocks/lib/nlog10_ff_impl.cc b/gr-blocks/lib/nlog10_ff_impl.cc index beabed66c9..16c0cfc86b 100644 --- a/gr-blocks/lib/nlog10_ff_impl.cc +++ b/gr-blocks/lib/nlog10_ff_impl.cc @@ -30,47 +30,47 @@ #include <limits> namespace gr { - namespace blocks { +namespace blocks { - nlog10_ff::sptr nlog10_ff::make(float n, size_t vlen, float k) - { - return gnuradio::get_initial_sptr(new nlog10_ff_impl(n, vlen, k)); - } - - nlog10_ff_impl::nlog10_ff_impl(float n, size_t vlen, float k) - : sync_block("nlog10_ff", - io_signature::make (1, 1, sizeof(float)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_n_log2_10(n/log2f(10.0f)), d_10_k_n(std::pow(10.0f, k/n)), d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1,alignment_multiple)); - } +nlog10_ff::sptr nlog10_ff::make(float n, size_t vlen, float k) +{ + return gnuradio::get_initial_sptr(new nlog10_ff_impl(n, vlen, k)); +} - int - nlog10_ff_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float *) input_items[0]; - float *out = (float *) output_items[0]; - int noi = noutput_items * d_vlen; +nlog10_ff_impl::nlog10_ff_impl(float n, size_t vlen, float k) + : sync_block("nlog10_ff", + io_signature::make(1, 1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_n_log2_10(n / log2f(10.0f)), + d_10_k_n(std::pow(10.0f, k / n)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} - constexpr float float_min = std::numeric_limits<float>::min(); +int nlog10_ff_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + float* out = (float*)output_items[0]; + int noi = noutput_items * d_vlen; - for (int i = 0; i < noi; i++) { - out[i] = std::max(in[i], float_min); - } + constexpr float float_min = std::numeric_limits<float>::min(); - if (d_10_k_n != 1.0f) { - volk_32f_s32f_multiply_32f(out, out, d_10_k_n, noi); - } - volk_32f_log2_32f(out, out, noi); - volk_32f_s32f_multiply_32f(out, out, d_n_log2_10, noi); + for (int i = 0; i < noi; i++) { + out[i] = std::max(in[i], float_min); + } - return noutput_items; + if (d_10_k_n != 1.0f) { + volk_32f_s32f_multiply_32f(out, out, d_10_k_n, noi); } + volk_32f_log2_32f(out, out, noi); + volk_32f_s32f_multiply_32f(out, out, d_n_log2_10, noi); + + return noutput_items; +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/nlog10_ff_impl.h b/gr-blocks/lib/nlog10_ff_impl.h index cac3754679..b59492aff3 100644 --- a/gr-blocks/lib/nlog10_ff_impl.h +++ b/gr-blocks/lib/nlog10_ff_impl.h @@ -26,23 +26,23 @@ #include <gnuradio/blocks/nlog10_ff.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API nlog10_ff_impl : public nlog10_ff - { - float d_n_log2_10; - float d_10_k_n; - size_t d_vlen; +class BLOCKS_API nlog10_ff_impl : public nlog10_ff +{ + float d_n_log2_10; + float d_10_k_n; + size_t d_vlen; - public: - nlog10_ff_impl(float n, size_t vlen, float k); +public: + nlog10_ff_impl(float n, size_t vlen, float k); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/nop_impl.cc b/gr-blocks/lib/nop_impl.cc index da1398e51a..f079886e03 100644 --- a/gr-blocks/lib/nop_impl.cc +++ b/gr-blocks/lib/nop_impl.cc @@ -29,72 +29,71 @@ #include <boost/bind.hpp> namespace gr { - namespace blocks { +namespace blocks { - nop::sptr - nop::make(size_t sizeof_stream_item) - { - return gnuradio::get_initial_sptr - (new nop_impl(sizeof_stream_item)); - } +nop::sptr nop::make(size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr(new nop_impl(sizeof_stream_item)); +} - nop_impl::nop_impl (size_t sizeof_stream_item) - : block("nop", - io_signature::make(0, -1, sizeof_stream_item), - io_signature::make(0, -1, sizeof_stream_item)), - d_nmsgs_recvd(0) - { - // Arrange to have count_received_msgs called when messages are received. - message_port_register_in(pmt::mp("port")); - set_msg_handler(pmt::mp("port"), boost::bind(&nop_impl::count_received_msgs, this, _1)); - } +nop_impl::nop_impl(size_t sizeof_stream_item) + : block("nop", + io_signature::make(0, -1, sizeof_stream_item), + io_signature::make(0, -1, sizeof_stream_item)), + d_nmsgs_recvd(0) +{ + // Arrange to have count_received_msgs called when messages are received. + message_port_register_in(pmt::mp("port")); + set_msg_handler(pmt::mp("port"), + boost::bind(&nop_impl::count_received_msgs, this, _1)); +} - nop_impl::~nop_impl() - { - } +nop_impl::~nop_impl() {} - // Trivial message handler that just counts them. - // (N.B., This feature is used in qa_set_msg_handler) - void - nop_impl::count_received_msgs(pmt::pmt_t msg) - { - d_nmsgs_recvd++; - } +// Trivial message handler that just counts them. +// (N.B., This feature is used in qa_set_msg_handler) +void nop_impl::count_received_msgs(pmt::pmt_t msg) { d_nmsgs_recvd++; } - int - nop_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - // eat any input that's available - for(unsigned i = 0; i < ninput_items.size (); i++) +int nop_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + // eat any input that's available + for (unsigned i = 0; i < ninput_items.size(); i++) consume(i, ninput_items[i]); - return noutput_items; - } + return noutput_items; +} - void - nop_impl::setup_rpc() - { +void nop_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<nop, int>( - alias(), "test", - &nop::ctrlport_test, - pmt::mp(-256), pmt::mp(255), pmt::mp(0), - "", "Simple testing variable", - RPC_PRIVLVL_MIN, DISPNULL))); + d_rpc_vars.push_back( + rpcbasic_sptr(new rpcbasic_register_get<nop, int>(alias(), + "test", + &nop::ctrlport_test, + pmt::mp(-256), + pmt::mp(255), + pmt::mp(0), + "", + "Simple testing variable", + RPC_PRIVLVL_MIN, + DISPNULL))); - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_set<nop, int>( - alias(), "test", - &nop::set_ctrlport_test, - pmt::mp(-256), pmt::mp(255), pmt::mp(0), - "", "Simple testing variable", - RPC_PRIVLVL_MIN, DISPNULL))); + d_rpc_vars.push_back( + rpcbasic_sptr(new rpcbasic_register_set<nop, int>(alias(), + "test", + &nop::set_ctrlport_test, + pmt::mp(-256), + pmt::mp(255), + pmt::mp(0), + "", + "Simple testing variable", + RPC_PRIVLVL_MIN, + DISPNULL))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/nop_impl.h b/gr-blocks/lib/nop_impl.h index a76b2a3288..d2e13a1c45 100644 --- a/gr-blocks/lib/nop_impl.h +++ b/gr-blocks/lib/nop_impl.h @@ -26,35 +26,35 @@ #include <gnuradio/blocks/nop.h> namespace gr { - namespace blocks { +namespace blocks { - class nop_impl : public nop - { - protected: - int d_nmsgs_recvd; - int d_ctrlport_test; +class nop_impl : public nop +{ +protected: + int d_nmsgs_recvd; + int d_ctrlport_test; - // Method that just counts any received messages. - void count_received_msgs(pmt::pmt_t msg); + // Method that just counts any received messages. + void count_received_msgs(pmt::pmt_t msg); - public: - nop_impl(size_t sizeof_stream_item); - ~nop_impl(); +public: + nop_impl(size_t sizeof_stream_item); + ~nop_impl(); - void setup_rpc(); + void setup_rpc(); - int nmsgs_received() const { return d_nmsgs_recvd; } + int nmsgs_received() const { return d_nmsgs_recvd; } - int ctrlport_test() const { return d_ctrlport_test; } - void set_ctrlport_test(int x) { d_ctrlport_test = x; } + int ctrlport_test() const { return d_ctrlport_test; } + void set_ctrlport_test(int x) { d_ctrlport_test = x; } - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int general_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 blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_NOP_IMPL_H */ diff --git a/gr-blocks/lib/not_blk_impl.cc b/gr-blocks/lib/not_blk_impl.cc index 3c3dea5a15..366671353d 100644 --- a/gr-blocks/lib/not_blk_impl.cc +++ b/gr-blocks/lib/not_blk_impl.cc @@ -29,42 +29,41 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename not_blk<T>::sptr not_blk<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new not_blk_impl<T> (vlen)); - } +template <class T> +typename not_blk<T>::sptr not_blk<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new not_blk_impl<T>(vlen)); +} - template <class T> - not_blk_impl<T> ::not_blk_impl(size_t vlen) - : sync_block ("not_blk", - io_signature::make (1, 1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), +template <class T> +not_blk_impl<T>::not_blk_impl(size_t vlen) + : sync_block("not_blk", + io_signature::make(1, 1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), d_vlen(vlen) - { - } +{ +} - template <class T> - int - not_blk_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *) output_items[0]; - const T *inptr = (const T *) input_items[0]; +template <class T> +int not_blk_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; + const T* inptr = (const T*)input_items[0]; - int noi = noutput_items*d_vlen; + int noi = noutput_items * d_vlen; - for (int i = 0; i < noi; i++) - *optr++ = ~(inptr[i]); + for (int i = 0; i < noi; i++) + *optr++ = ~(inptr[i]); - return noutput_items; - } + return noutput_items; +} template class not_blk<std::uint8_t>; template class not_blk<std::int16_t>; template class not_blk<std::int32_t>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/not_blk_impl.h b/gr-blocks/lib/not_blk_impl.h index 77050adee2..432ffbbdd1 100644 --- a/gr-blocks/lib/not_blk_impl.h +++ b/gr-blocks/lib/not_blk_impl.h @@ -27,22 +27,22 @@ #include <gnuradio/blocks/not_blk.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API not_blk_impl : public not_blk<T> - { - size_t d_vlen; +template <class T> +class BLOCKS_API not_blk_impl : public not_blk<T> +{ + size_t d_vlen; - public: - not_blk_impl (size_t vlen); +public: + not_blk_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* NOT_BLK_IMPL_H */ diff --git a/gr-blocks/lib/null_sink_impl.cc b/gr-blocks/lib/null_sink_impl.cc index 14dd5eff24..12a32819f5 100644 --- a/gr-blocks/lib/null_sink_impl.cc +++ b/gr-blocks/lib/null_sink_impl.cc @@ -28,33 +28,28 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - null_sink::sptr - null_sink::make(size_t sizeof_stream_item) - { - return gnuradio::get_initial_sptr - (new null_sink_impl(sizeof_stream_item)); - } - - null_sink_impl::null_sink_impl(size_t sizeof_stream_item) - : sync_block("null_sink", - io_signature::make(1, -1, sizeof_stream_item), - io_signature::make(0, 0, 0)) - { - } - - null_sink_impl::~null_sink_impl() - { - } - - int - null_sink_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - return noutput_items; - } - - } /* namespace blocks */ +namespace blocks { + +null_sink::sptr null_sink::make(size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr(new null_sink_impl(sizeof_stream_item)); +} + +null_sink_impl::null_sink_impl(size_t sizeof_stream_item) + : sync_block("null_sink", + io_signature::make(1, -1, sizeof_stream_item), + io_signature::make(0, 0, 0)) +{ +} + +null_sink_impl::~null_sink_impl() {} + +int null_sink_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/null_sink_impl.h b/gr-blocks/lib/null_sink_impl.h index 948bc19de6..6d307a16c4 100644 --- a/gr-blocks/lib/null_sink_impl.h +++ b/gr-blocks/lib/null_sink_impl.h @@ -26,20 +26,20 @@ #include <gnuradio/blocks/null_sink.h> namespace gr { - namespace blocks { +namespace blocks { - class null_sink_impl : public null_sink - { - public: - null_sink_impl(size_t sizeof_stream_item); - ~null_sink_impl(); +class null_sink_impl : public null_sink +{ +public: + null_sink_impl(size_t sizeof_stream_item); + ~null_sink_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_NULL_SINK_IMPL_H */ diff --git a/gr-blocks/lib/null_source_impl.cc b/gr-blocks/lib/null_source_impl.cc index 9550dd6bce..9c4b3c610b 100644 --- a/gr-blocks/lib/null_source_impl.cc +++ b/gr-blocks/lib/null_source_impl.cc @@ -29,38 +29,33 @@ #include <string.h> namespace gr { - namespace blocks { - - null_source::sptr - null_source::make(size_t sizeof_stream_item) - { - return gnuradio::get_initial_sptr - (new null_source_impl(sizeof_stream_item)); - } - - null_source_impl::null_source_impl (size_t sizeof_stream_item) - : sync_block("null_source", - io_signature::make(0, 0, 0), - io_signature::make(1, -1, sizeof_stream_item)) - { - } - - null_source_impl::~null_source_impl() - { - } - - int - null_source_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - void *optr; - for(size_t n = 0; n < input_items.size(); n++) { +namespace blocks { + +null_source::sptr null_source::make(size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr(new null_source_impl(sizeof_stream_item)); +} + +null_source_impl::null_source_impl(size_t sizeof_stream_item) + : sync_block("null_source", + io_signature::make(0, 0, 0), + io_signature::make(1, -1, sizeof_stream_item)) +{ +} + +null_source_impl::~null_source_impl() {} + +int null_source_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + void* optr; + for (size_t n = 0; n < input_items.size(); n++) { optr = (void*)output_items[n]; memset(optr, 0, noutput_items * output_signature()->sizeof_stream_item(n)); - } - return noutput_items; } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/null_source_impl.h b/gr-blocks/lib/null_source_impl.h index 887c77d424..c514e92ead 100644 --- a/gr-blocks/lib/null_source_impl.h +++ b/gr-blocks/lib/null_source_impl.h @@ -26,20 +26,20 @@ #include <gnuradio/blocks/null_source.h> namespace gr { - namespace blocks { +namespace blocks { - class null_source_impl : public null_source - { - public: - null_source_impl(size_t sizeof_stream_item); - ~null_source_impl(); +class null_source_impl : public null_source +{ +public: + null_source_impl(size_t sizeof_stream_item); + ~null_source_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_NULL_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/or_blk_impl.cc b/gr-blocks/lib/or_blk_impl.cc index ca04e8e4fa..f47849b4ba 100644 --- a/gr-blocks/lib/or_blk_impl.cc +++ b/gr-blocks/lib/or_blk_impl.cc @@ -30,28 +30,34 @@ namespace gr { namespace blocks { -template <class T> typename or_blk<T>::sptr or_blk<T>::make(size_t vlen) { +template <class T> +typename or_blk<T>::sptr or_blk<T>::make(size_t vlen) +{ return gnuradio::get_initial_sptr(new or_blk_impl<T>(vlen)); } template <class T> or_blk_impl<T>::or_blk_impl(size_t vlen) - : sync_block("or_blk", io_signature::make(1, -1, sizeof(T) * vlen), + : sync_block("or_blk", + io_signature::make(1, -1, sizeof(T) * vlen), io_signature::make(1, 1, sizeof(T) * vlen)), - d_vlen(vlen) {} + d_vlen(vlen) +{ +} template <class T> int or_blk_impl<T>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) { - T *optr = (T *)output_items[0]; + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; int ninputs = input_items.size(); for (size_t i = 0; i < noutput_items * d_vlen; i++) { - T acc = ((T *)input_items[0])[i]; + T acc = ((T*)input_items[0])[i]; for (int j = 1; j < ninputs; j++) - acc |= ((T *)input_items[j])[i]; + acc |= ((T*)input_items[j])[i]; *optr++ = (T)acc; } diff --git a/gr-blocks/lib/or_blk_impl.h b/gr-blocks/lib/or_blk_impl.h index fbff19a24d..b4c97c7694 100644 --- a/gr-blocks/lib/or_blk_impl.h +++ b/gr-blocks/lib/or_blk_impl.h @@ -26,22 +26,22 @@ #include <gnuradio/blocks/or_blk.h> namespace gr { - namespace blocks { +namespace blocks { - template<class T> - class BLOCKS_API or_blk_impl : public or_blk<T> - { - size_t d_vlen; +template <class T> +class BLOCKS_API or_blk_impl : public or_blk<T> +{ + size_t d_vlen; - public: - or_blk_impl(size_t vlen); +public: + or_blk_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* OR_BLK_IMPL_H */ diff --git a/gr-blocks/lib/pack_k_bits.cc b/gr-blocks/lib/pack_k_bits.cc index ad6e78ae18..8ff5f638ff 100644 --- a/gr-blocks/lib/pack_k_bits.cc +++ b/gr-blocks/lib/pack_k_bits.cc @@ -29,42 +29,39 @@ #include <iostream> namespace gr { - namespace blocks { - namespace kernel { +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(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() - { - } +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); - } +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); } - } + } +} - void - pack_k_bits::pack_rev(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])<<j; - } +void pack_k_bits::pack_rev(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]) << j; } - } + } +} - } /* namespace kernel */ - } /* namespace blocks */ +} /* 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 889e0d29f4..06c422b923 100644 --- a/gr-blocks/lib/pack_k_bits_bb_impl.cc +++ b/gr-blocks/lib/pack_k_bits_bb_impl.cc @@ -30,41 +30,35 @@ #include <iostream> namespace gr { - namespace blocks { +namespace blocks { - pack_k_bits_bb::sptr - pack_k_bits_bb::make(unsigned k) - { - return gnuradio::get_initial_sptr - (new pack_k_bits_bb_impl(k)); - } +pack_k_bits_bb::sptr pack_k_bits_bb::make(unsigned k) +{ + return gnuradio::get_initial_sptr(new pack_k_bits_bb_impl(k)); +} - pack_k_bits_bb_impl::pack_k_bits_bb_impl(unsigned k) - : sync_decimator("pack_k_bits_bb", - io_signature::make(1, 1, sizeof(unsigned char)), - io_signature::make(1, 1, sizeof(unsigned char)), - k) - { - d_pack = new kernel::pack_k_bits(k); - } +pack_k_bits_bb_impl::pack_k_bits_bb_impl(unsigned k) + : sync_decimator("pack_k_bits_bb", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(unsigned char)), + k) +{ + d_pack = new kernel::pack_k_bits(k); +} - pack_k_bits_bb_impl::~pack_k_bits_bb_impl() - { - delete d_pack; - } +pack_k_bits_bb_impl::~pack_k_bits_bb_impl() { delete d_pack; } - int - pack_k_bits_bb_impl::work(int noutput_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 pack_k_bits_bb_impl::work(int noutput_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]; - d_pack->pack(out, in, noutput_items); + d_pack->pack(out, in, noutput_items); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/pack_k_bits_bb_impl.h b/gr-blocks/lib/pack_k_bits_bb_impl.h index 2cf4f28fc3..6459a1e811 100644 --- a/gr-blocks/lib/pack_k_bits_bb_impl.h +++ b/gr-blocks/lib/pack_k_bits_bb_impl.h @@ -21,29 +21,29 @@ */ #ifndef INCLUDED_GR_PACK_K_BITS_BB_IMPL_H -#define INCLUDED_GR_PACK_K_BITS_BB_IMPL_H +#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 { +namespace blocks { - class pack_k_bits_bb_impl : public pack_k_bits_bb - { - private: - kernel::pack_k_bits *d_pack; +class pack_k_bits_bb_impl : public pack_k_bits_bb +{ +private: + kernel::pack_k_bits* d_pack; - public: - pack_k_bits_bb_impl(unsigned k); - ~pack_k_bits_bb_impl(); +public: + pack_k_bits_bb_impl(unsigned k); + ~pack_k_bits_bb_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_PACK_K_BITS_BB_IMPL_H */ diff --git a/gr-blocks/lib/packed_to_unpacked_impl.cc b/gr-blocks/lib/packed_to_unpacked_impl.cc index 8b13371e58..f63e040b2a 100644 --- a/gr-blocks/lib/packed_to_unpacked_impl.cc +++ b/gr-blocks/lib/packed_to_unpacked_impl.cc @@ -30,123 +30,125 @@ #include <assert.h> namespace gr { - namespace blocks { - - template <class T> - typename packed_to_unpacked<T>::sptr - packed_to_unpacked<T>::make(unsigned int bits_per_chunk, - endianness_t endianness) - { - return gnuradio::get_initial_sptr - (new packed_to_unpacked_impl<T> (bits_per_chunk, endianness)); - } - - template <class T> - packed_to_unpacked_impl<T> ::packed_to_unpacked_impl(unsigned int bits_per_chunk, - endianness_t endianness) +namespace blocks { + +template <class T> +typename packed_to_unpacked<T>::sptr +packed_to_unpacked<T>::make(unsigned int bits_per_chunk, endianness_t endianness) +{ + return gnuradio::get_initial_sptr( + new packed_to_unpacked_impl<T>(bits_per_chunk, endianness)); +} + +template <class T> +packed_to_unpacked_impl<T>::packed_to_unpacked_impl(unsigned int bits_per_chunk, + endianness_t endianness) : block("packed_to_unpacked", - io_signature::make(1, -1, sizeof(T)), - io_signature::make(1, -1, sizeof(T))), - d_bits_per_chunk(bits_per_chunk), d_endianness(endianness), d_index(0) - { - assert(bits_per_chunk <= this->d_bits_per_type); - assert(bits_per_chunk > 0); - - this->set_relative_rate((uint64_t)this->d_bits_per_type, (uint64_t)bits_per_chunk); - } - - template <class T> - packed_to_unpacked_impl<T> ::~packed_to_unpacked_impl() - { - } - - template <class T> - void - packed_to_unpacked_impl<T> ::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - int input_required = (int)ceil((d_index + noutput_items * d_bits_per_chunk) - / (1.0 * this->d_bits_per_type)); - unsigned ninputs = ninput_items_required.size(); - for(unsigned int i = 0; i < ninputs; i++) { + io_signature::make(1, -1, sizeof(T)), + io_signature::make(1, -1, sizeof(T))), + d_bits_per_chunk(bits_per_chunk), + d_endianness(endianness), + d_index(0) +{ + assert(bits_per_chunk <= this->d_bits_per_type); + assert(bits_per_chunk > 0); + + this->set_relative_rate((uint64_t)this->d_bits_per_type, (uint64_t)bits_per_chunk); +} + +template <class T> +packed_to_unpacked_impl<T>::~packed_to_unpacked_impl() +{ +} + +template <class T> +void packed_to_unpacked_impl<T>::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{ + int input_required = (int)ceil((d_index + noutput_items * d_bits_per_chunk) / + (1.0 * this->d_bits_per_type)); + unsigned ninputs = ninput_items_required.size(); + for (unsigned int i = 0; i < ninputs; i++) { ninput_items_required[i] = input_required; - //printf("Forecast wants %d needs %d\n",noutput_items,ninput_items_required[i]); - } + // printf("Forecast wants %d needs %d\n",noutput_items,ninput_items_required[i]); } - - template <class T> - unsigned int - packed_to_unpacked_impl<T>::get_bit_le(const T *in_vector, unsigned int bit_addr) - { - T x = in_vector[bit_addr >> this->d_log2_l_type]; - return (x >> (bit_addr & (this->d_bits_per_type-1))) & 1; - } - - template <class T> - unsigned int - packed_to_unpacked_impl<T>::get_bit_be(const T *in_vector, unsigned int bit_addr) - { - T x = in_vector[bit_addr >> this->d_log2_l_type]; - return (x >> ((this->d_bits_per_type-1) - (bit_addr & (this->d_bits_per_type-1)))) & 1; - } - - template <class T> - int - packed_to_unpacked_impl<T> ::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - unsigned int index_tmp = d_index; - - assert(input_items.size() == output_items.size()); - int nstreams = input_items.size(); - - for (int m=0; m < nstreams; m++){ - const T *in = (T *)input_items[m]; - T *out = (T *)output_items[m]; +} + +template <class T> +unsigned int packed_to_unpacked_impl<T>::get_bit_le(const T* in_vector, + unsigned int bit_addr) +{ + T x = in_vector[bit_addr >> this->d_log2_l_type]; + return (x >> (bit_addr & (this->d_bits_per_type - 1))) & 1; +} + +template <class T> +unsigned int packed_to_unpacked_impl<T>::get_bit_be(const T* in_vector, + unsigned int bit_addr) +{ + T x = in_vector[bit_addr >> this->d_log2_l_type]; + return (x >> + ((this->d_bits_per_type - 1) - (bit_addr & (this->d_bits_per_type - 1)))) & + 1; +} + +template <class T> +int packed_to_unpacked_impl<T>::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + unsigned int index_tmp = d_index; + + assert(input_items.size() == output_items.size()); + int nstreams = input_items.size(); + + for (int m = 0; m < nstreams; m++) { + const T* in = (T*)input_items[m]; + T* out = (T*)output_items[m]; index_tmp = d_index; // per stream processing - switch(d_endianness) { + switch (d_endianness) { case GR_MSB_FIRST: - for(int i = 0; i < noutput_items; i++) { - //printf("here msb %d\n",i); - T x = 0; - for(unsigned int j = 0; j < d_bits_per_chunk; j++, index_tmp++) - x = (x<<1) | get_bit_be(in, index_tmp); - out[i] = x; - } - break; + for (int i = 0; i < noutput_items; i++) { + // printf("here msb %d\n",i); + T x = 0; + for (unsigned int j = 0; j < d_bits_per_chunk; j++, index_tmp++) + x = (x << 1) | get_bit_be(in, index_tmp); + out[i] = x; + } + break; case GR_LSB_FIRST: - for(int i = 0; i < noutput_items; i++) { - //printf("here lsb %d\n",i); - T x = 0; - for(unsigned int j = 0; j < d_bits_per_chunk; j++, index_tmp++) - x = (x<<1) | get_bit_le(in, index_tmp); - out[i] = x; - } - break; + for (int i = 0; i < noutput_items; i++) { + // printf("here lsb %d\n",i); + T x = 0; + for (unsigned int j = 0; j < d_bits_per_chunk; j++, index_tmp++) + x = (x << 1) | get_bit_le(in, index_tmp); + out[i] = x; + } + break; default: - assert(0); + assert(0); } - //printf("almost got to end\n"); - assert(ninput_items[m] >= (int)((d_index+(this->d_bits_per_type-1)) >> this->d_log2_l_type)); - } - - d_index = index_tmp; - this->consume_each(d_index >> this->d_log2_l_type); - d_index = d_index & (this->d_bits_per_type-1); - //printf("got to end\n"); - return noutput_items; + // printf("almost got to end\n"); + assert(ninput_items[m] >= + (int)((d_index + (this->d_bits_per_type - 1)) >> this->d_log2_l_type)); } + d_index = index_tmp; + this->consume_each(d_index >> this->d_log2_l_type); + d_index = d_index & (this->d_bits_per_type - 1); + // printf("got to end\n"); + return noutput_items; +} + template class packed_to_unpacked<std::uint8_t>; template class packed_to_unpacked<std::int16_t>; template class packed_to_unpacked<std::int32_t>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/packed_to_unpacked_impl.h b/gr-blocks/lib/packed_to_unpacked_impl.h index fd65242478..1ef8b17c48 100644 --- a/gr-blocks/lib/packed_to_unpacked_impl.h +++ b/gr-blocks/lib/packed_to_unpacked_impl.h @@ -28,37 +28,34 @@ #include <gnuradio/blocks/log2_const.h> namespace gr { - namespace blocks { - -template<class T> - class packed_to_unpacked_impl : public packed_to_unpacked<T> - { - private: - unsigned int d_bits_per_chunk; - endianness_t d_endianness; - unsigned int d_index; - const unsigned int d_bits_per_type = sizeof(T) * 8; - const unsigned int d_log2_l_type = log2_const<sizeof(T) * 8>(); - unsigned int get_bit_le(const T *in_vector, unsigned int bit_addr); - unsigned int get_bit_be(const T *in_vector, unsigned int bit_addr); - - public: - packed_to_unpacked_impl (unsigned int bits_per_chunk, - endianness_t endianness); - ~packed_to_unpacked_impl (); - - void forecast(int noutput_items, - gr_vector_int &ninput_items_required); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - bool check_topology(int ninputs, int noutputs) - { return ninputs == noutputs; } - }; - - } /* namespace blocks */ +namespace blocks { + +template <class T> +class packed_to_unpacked_impl : public packed_to_unpacked<T> +{ +private: + unsigned int d_bits_per_chunk; + endianness_t d_endianness; + unsigned int d_index; + const unsigned int d_bits_per_type = sizeof(T) * 8; + const unsigned int d_log2_l_type = log2_const<sizeof(T) * 8>(); + unsigned int get_bit_le(const T* in_vector, unsigned int bit_addr); + unsigned int get_bit_be(const T* in_vector, unsigned int bit_addr); + +public: + packed_to_unpacked_impl(unsigned int bits_per_chunk, endianness_t endianness); + ~packed_to_unpacked_impl(); + + void forecast(int noutput_items, gr_vector_int& ninput_items_required); + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); + + bool check_topology(int ninputs, int noutputs) { return ninputs == noutputs; } +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* PACKED_TO_UNPACKED_IMPL_H */ diff --git a/gr-blocks/lib/patterned_interleaver_impl.cc b/gr-blocks/lib/patterned_interleaver_impl.cc index 9ed45abb85..26b56c89a3 100644 --- a/gr-blocks/lib/patterned_interleaver_impl.cc +++ b/gr-blocks/lib/patterned_interleaver_impl.cc @@ -28,60 +28,66 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - patterned_interleaver::sptr patterned_interleaver::make(size_t itemsize, std::vector<int> pattern) - { - return gnuradio::get_initial_sptr(new patterned_interleaver_impl(itemsize, pattern)); - } +patterned_interleaver::sptr patterned_interleaver::make(size_t itemsize, + std::vector<int> pattern) +{ + return gnuradio::get_initial_sptr(new patterned_interleaver_impl(itemsize, pattern)); +} - patterned_interleaver_impl::patterned_interleaver_impl(size_t itemsize, std::vector<int> pattern) - : block ("patterned_interleaver", - io_signature::make (pattern_max(pattern)+1, pattern_max(pattern)+1, itemsize), - io_signature::make (1, 1, itemsize)), - d_pattern(pattern), d_counts( pattern_max(pattern)+1, 0), d_itemsize(itemsize) - { - BOOST_FOREACH( int i, d_pattern) - { d_counts[i]++; } - set_output_multiple(d_pattern.size()); +patterned_interleaver_impl::patterned_interleaver_impl(size_t itemsize, + std::vector<int> pattern) + : block("patterned_interleaver", + io_signature::make( + pattern_max(pattern) + 1, pattern_max(pattern) + 1, itemsize), + io_signature::make(1, 1, itemsize)), + d_pattern(pattern), + d_counts(pattern_max(pattern) + 1, 0), + d_itemsize(itemsize) +{ + BOOST_FOREACH (int i, d_pattern) { + d_counts[i]++; } + set_output_multiple(d_pattern.size()); +} - int - patterned_interleaver_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - size_t nblks = noutput_items/d_pattern.size(); +int patterned_interleaver_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + size_t nblks = noutput_items / d_pattern.size(); - std::vector<const char*> ii; - for(size_t i=0; i<input_items.size(); i++){ + std::vector<const char*> ii; + for (size_t i = 0; i < input_items.size(); i++) { ii.push_back((const char*)input_items[i]); - } + } - char *oo = (char *) output_items[0]; + char* oo = (char*)output_items[0]; - for(size_t i=0; i<nblks; i++){ - for(size_t j=0; j<d_pattern.size(); j++){ - memcpy(oo, ii[d_pattern[j]], d_itemsize); - oo += d_itemsize; - ii[d_pattern[j]] += d_itemsize; - } + for (size_t i = 0; i < nblks; i++) { + for (size_t j = 0; j < d_pattern.size(); j++) { + memcpy(oo, ii[d_pattern[j]], d_itemsize); + oo += d_itemsize; + ii[d_pattern[j]] += d_itemsize; } + } - for(size_t i=0; i<d_counts.size(); i++){ - consume(i, d_counts[i]*nblks ); - } - return nblks*d_pattern.size(); + for (size_t i = 0; i < d_counts.size(); i++) { + consume(i, d_counts[i] * nblks); } + return nblks * d_pattern.size(); +} - void patterned_interleaver_impl::forecast (int noutput_items, - gr_vector_int &ninput_items_required){ - int nblks = noutput_items / d_pattern.size(); - for(size_t i=0; i<ninput_items_required.size(); i++){ - ninput_items_required[i] = d_counts[i] * nblks; - } - } +void patterned_interleaver_impl::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{ + int nblks = noutput_items / d_pattern.size(); + for (size_t i = 0; i < ninput_items_required.size(); i++) { + ninput_items_required[i] = d_counts[i] * nblks; + } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/patterned_interleaver_impl.h b/gr-blocks/lib/patterned_interleaver_impl.h index 4b78b65e0b..7daedfb224 100644 --- a/gr-blocks/lib/patterned_interleaver_impl.h +++ b/gr-blocks/lib/patterned_interleaver_impl.h @@ -27,35 +27,35 @@ #include <boost/foreach.hpp> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API patterned_interleaver_impl : public patterned_interleaver - { - public: - patterned_interleaver_impl(size_t itemsize, std::vector<int> pattern); +class BLOCKS_API patterned_interleaver_impl : public patterned_interleaver +{ +public: + patterned_interleaver_impl(size_t itemsize, std::vector<int> pattern); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - int pattern_max(std::vector<int> pattern){ + int pattern_max(std::vector<int> pattern) + { int mval(0); - BOOST_FOREACH( int i, pattern) - { mval = std::max(mval, i); } - return mval; + BOOST_FOREACH (int i, pattern) { + mval = std::max(mval, i); } + return mval; + } - void forecast (int noutput_items, - gr_vector_int &ninput_items_required); - - std::vector<int> d_pattern; - std::vector<int> d_counts; - size_t d_itemsize; + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - }; + std::vector<int> d_pattern; + std::vector<int> d_counts; + size_t d_itemsize; +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif diff --git a/gr-blocks/lib/pdu.cc b/gr-blocks/lib/pdu.cc index f0e610209f..3d0db4d5b2 100644 --- a/gr-blocks/lib/pdu.cc +++ b/gr-blocks/lib/pdu.cc @@ -27,72 +27,68 @@ #include <gnuradio/blocks/pdu.h> namespace gr { - namespace blocks { - namespace pdu { +namespace blocks { +namespace pdu { - const - pmt::pmt_t pdu_port_id(){ - static const pmt::pmt_t pdu_port_id = pmt::mp("pdus"); - return pdu_port_id; - } +const pmt::pmt_t pdu_port_id() +{ + static const pmt::pmt_t pdu_port_id = pmt::mp("pdus"); + return pdu_port_id; +} - size_t - itemsize(vector_type type) - { - switch(type) { - case byte_t: - return sizeof(char); - case float_t: - return sizeof(float); - case complex_t: - return sizeof(gr_complex); - default: - throw std::runtime_error("bad PDU type"); - } - } +size_t itemsize(vector_type type) +{ + switch (type) { + case byte_t: + return sizeof(char); + case float_t: + return sizeof(float); + case complex_t: + return sizeof(gr_complex); + default: + throw std::runtime_error("bad PDU type"); + } +} - bool - type_matches(vector_type type, pmt::pmt_t v) - { - switch(type) { - case byte_t: - return pmt::is_u8vector(v); - case float_t: - return pmt::is_f32vector(v); - case complex_t: - return pmt::is_c32vector(v); - default: - throw std::runtime_error("bad PDU type"); - } - } +bool type_matches(vector_type type, pmt::pmt_t v) +{ + switch (type) { + case byte_t: + return pmt::is_u8vector(v); + case float_t: + return pmt::is_f32vector(v); + case complex_t: + return pmt::is_c32vector(v); + default: + throw std::runtime_error("bad PDU type"); + } +} - pmt::pmt_t - make_pdu_vector(vector_type type, const uint8_t *buf, size_t items) - { - switch(type) { - case byte_t: - return pmt::init_u8vector(items, buf); - case float_t: - return pmt::init_f32vector(items, (const float *)buf); - case complex_t: - return pmt::init_c32vector(items, (const gr_complex *)buf); - default: - throw std::runtime_error("bad PDU type"); - } - } +pmt::pmt_t make_pdu_vector(vector_type type, const uint8_t* buf, size_t items) +{ + switch (type) { + case byte_t: + return pmt::init_u8vector(items, buf); + case float_t: + return pmt::init_f32vector(items, (const float*)buf); + case complex_t: + return pmt::init_c32vector(items, (const gr_complex*)buf); + default: + throw std::runtime_error("bad PDU type"); + } +} - vector_type - type_from_pmt(pmt::pmt_t vector) - { - if(pmt::is_u8vector(vector)) - return byte_t; - if(pmt::is_f32vector(vector)) - return float_t; - if(pmt::is_c32vector(vector)) - return complex_t; - throw std::runtime_error("bad PDU type"); - } +vector_type type_from_pmt(pmt::pmt_t vector) +{ + if (pmt::is_u8vector(vector)) + return byte_t; + if (pmt::is_f32vector(vector)) + return float_t; + if (pmt::is_c32vector(vector)) + return complex_t; + throw std::runtime_error("bad PDU type"); +} - } /* namespace pdu */ - } /* namespace blocks */ +} /* namespace pdu */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/pdu_filter_impl.cc b/gr-blocks/lib/pdu_filter_impl.cc index 31c737af53..10423ae05d 100644 --- a/gr-blocks/lib/pdu_filter_impl.cc +++ b/gr-blocks/lib/pdu_filter_impl.cc @@ -29,43 +29,43 @@ #include <gnuradio/blocks/pdu.h> namespace gr { - namespace blocks { +namespace blocks { - pdu_filter::sptr - pdu_filter::make(pmt::pmt_t k, pmt::pmt_t v, bool invert) - { - return gnuradio::get_initial_sptr(new pdu_filter_impl(k,v,invert)); - } +pdu_filter::sptr pdu_filter::make(pmt::pmt_t k, pmt::pmt_t v, bool invert) +{ + return gnuradio::get_initial_sptr(new pdu_filter_impl(k, v, invert)); +} - pdu_filter_impl::pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v, bool invert) - : block("pdu_filter", - io_signature::make (0, 0, 0), - io_signature::make (0, 0, 0)), - d_k(k), d_v(v), d_invert(invert) - { - message_port_register_out(pdu::pdu_port_id()); - message_port_register_in(pdu::pdu_port_id()); - set_msg_handler(pdu::pdu_port_id(), boost::bind(&pdu_filter_impl::handle_msg, this, _1)); - } +pdu_filter_impl::pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v, bool invert) + : block("pdu_filter", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)), + d_k(k), + d_v(v), + d_invert(invert) +{ + message_port_register_out(pdu::pdu_port_id()); + message_port_register_in(pdu::pdu_port_id()); + set_msg_handler(pdu::pdu_port_id(), + boost::bind(&pdu_filter_impl::handle_msg, this, _1)); +} - void - pdu_filter_impl::handle_msg(pmt::pmt_t pdu) - { - pmt::pmt_t meta = pmt::car(pdu); - bool output = d_invert; +void pdu_filter_impl::handle_msg(pmt::pmt_t pdu) +{ + pmt::pmt_t meta = pmt::car(pdu); + bool output = d_invert; - // check base type - // key exists - // value matches - if(pmt::is_dict(meta) && dict_has_key(meta, d_k) && pmt::eqv(pmt::dict_ref(meta,d_k,pmt::PMT_NIL), d_v)){ + // check base type + // key exists + // value matches + if (pmt::is_dict(meta) && dict_has_key(meta, d_k) && + pmt::eqv(pmt::dict_ref(meta, d_k, pmt::PMT_NIL), d_v)) { output = !d_invert; - } + } - // if all tests pass, propagate the pdu - if(output){ + // if all tests pass, propagate the pdu + if (output) { message_port_pub(pdu::pdu_port_id(), pdu); - } } +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/pdu_filter_impl.h b/gr-blocks/lib/pdu_filter_impl.h index e54b50427c..33d18d29dc 100644 --- a/gr-blocks/lib/pdu_filter_impl.h +++ b/gr-blocks/lib/pdu_filter_impl.h @@ -26,24 +26,24 @@ #include <gnuradio/blocks/pdu_filter.h> namespace gr { - namespace blocks { +namespace blocks { - class pdu_filter_impl : public pdu_filter - { - private: - pmt::pmt_t d_k; - pmt::pmt_t d_v; - bool d_invert; +class pdu_filter_impl : public pdu_filter +{ +private: + pmt::pmt_t d_k; + pmt::pmt_t d_v; + bool d_invert; - public: - pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v, bool invert); - void handle_msg(pmt::pmt_t msg); - void set_key(pmt::pmt_t key) { d_k = key; }; - void set_val(pmt::pmt_t val) { d_v = val; }; - void set_inversion(bool invert) { d_invert = invert; }; - }; +public: + pdu_filter_impl(pmt::pmt_t k, pmt::pmt_t v, bool invert); + void handle_msg(pmt::pmt_t msg); + void set_key(pmt::pmt_t key) { d_k = key; }; + void set_val(pmt::pmt_t val) { d_v = val; }; + void set_inversion(bool invert) { d_invert = invert; }; +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_PDU_FILTER_IMPL_H */ diff --git a/gr-blocks/lib/pdu_remove_impl.cc b/gr-blocks/lib/pdu_remove_impl.cc index ab6dd4a4e7..09c73c5875 100644 --- a/gr-blocks/lib/pdu_remove_impl.cc +++ b/gr-blocks/lib/pdu_remove_impl.cc @@ -29,38 +29,35 @@ #include <gnuradio/blocks/pdu.h> namespace gr { - namespace blocks { +namespace blocks { - pdu_remove::sptr - pdu_remove::make(pmt::pmt_t k) - { - return gnuradio::get_initial_sptr(new pdu_remove_impl(k)); - } +pdu_remove::sptr pdu_remove::make(pmt::pmt_t k) +{ + return gnuradio::get_initial_sptr(new pdu_remove_impl(k)); +} - pdu_remove_impl::pdu_remove_impl(pmt::pmt_t k) - : block("pdu_remove", - io_signature::make (0, 0, 0), - io_signature::make (0, 0, 0)), - d_k(k) - { - message_port_register_out(pdu::pdu_port_id()); - message_port_register_in(pdu::pdu_port_id()); - set_msg_handler(pdu::pdu_port_id(), boost::bind(&pdu_remove_impl::handle_msg, this, _1)); - } +pdu_remove_impl::pdu_remove_impl(pmt::pmt_t k) + : block("pdu_remove", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)), + d_k(k) +{ + message_port_register_out(pdu::pdu_port_id()); + message_port_register_in(pdu::pdu_port_id()); + set_msg_handler(pdu::pdu_port_id(), + boost::bind(&pdu_remove_impl::handle_msg, this, _1)); +} - void - pdu_remove_impl::handle_msg(pmt::pmt_t pdu) - { - // add the field and publish - pmt::pmt_t meta = pmt::car(pdu); - if(pmt::is_null(meta)){ +void pdu_remove_impl::handle_msg(pmt::pmt_t pdu) +{ + // add the field and publish + pmt::pmt_t meta = pmt::car(pdu); + if (pmt::is_null(meta)) { meta = pmt::make_dict(); - } else if(!pmt::is_dict(meta)){ + } else if (!pmt::is_dict(meta)) { throw std::runtime_error("pdu_remove received non PDU input"); - } - meta = pmt::dict_delete(meta, d_k); - message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu))); } + meta = pmt::dict_delete(meta, d_k); + message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu))); +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/pdu_remove_impl.h b/gr-blocks/lib/pdu_remove_impl.h index 6f1a7f1b90..e17e1e6ea8 100644 --- a/gr-blocks/lib/pdu_remove_impl.h +++ b/gr-blocks/lib/pdu_remove_impl.h @@ -26,20 +26,20 @@ #include <gnuradio/blocks/pdu_remove.h> namespace gr { - namespace blocks { +namespace blocks { - class pdu_remove_impl : public pdu_remove - { - private: - pmt::pmt_t d_k; +class pdu_remove_impl : public pdu_remove +{ +private: + pmt::pmt_t d_k; - public: - pdu_remove_impl(pmt::pmt_t k); - void handle_msg(pmt::pmt_t msg); - void set_key(pmt::pmt_t key) { d_k = key; }; - }; +public: + pdu_remove_impl(pmt::pmt_t k); + void handle_msg(pmt::pmt_t msg); + void set_key(pmt::pmt_t key) { d_k = key; }; +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_PDU_REMOVE_IMPL_H */ diff --git a/gr-blocks/lib/pdu_set_impl.cc b/gr-blocks/lib/pdu_set_impl.cc index df09e2e9f9..6ef46f370f 100644 --- a/gr-blocks/lib/pdu_set_impl.cc +++ b/gr-blocks/lib/pdu_set_impl.cc @@ -29,38 +29,35 @@ #include <gnuradio/blocks/pdu.h> namespace gr { - namespace blocks { +namespace blocks { - pdu_set::sptr - pdu_set::make(pmt::pmt_t k, pmt::pmt_t v) - { - return gnuradio::get_initial_sptr(new pdu_set_impl(k,v)); - } +pdu_set::sptr pdu_set::make(pmt::pmt_t k, pmt::pmt_t v) +{ + return gnuradio::get_initial_sptr(new pdu_set_impl(k, v)); +} - pdu_set_impl::pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v) - : block("pdu_set", - io_signature::make (0, 0, 0), - io_signature::make (0, 0, 0)), - d_k(k), d_v(v) - { - message_port_register_out(pdu::pdu_port_id()); - message_port_register_in(pdu::pdu_port_id()); - set_msg_handler(pdu::pdu_port_id(), boost::bind(&pdu_set_impl::handle_msg, this, _1)); - } +pdu_set_impl::pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v) + : block("pdu_set", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)), + d_k(k), + d_v(v) +{ + message_port_register_out(pdu::pdu_port_id()); + message_port_register_in(pdu::pdu_port_id()); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&pdu_set_impl::handle_msg, this, _1)); +} - void - pdu_set_impl::handle_msg(pmt::pmt_t pdu) - { - // add the field and publish - pmt::pmt_t meta = pmt::car(pdu); - if(pmt::is_null(meta)){ +void pdu_set_impl::handle_msg(pmt::pmt_t pdu) +{ + // add the field and publish + pmt::pmt_t meta = pmt::car(pdu); + if (pmt::is_null(meta)) { meta = pmt::make_dict(); - } else if(!pmt::is_dict(meta)){ + } else if (!pmt::is_dict(meta)) { throw std::runtime_error("pdu_set received non PDU input"); - } - meta = pmt::dict_add(meta, d_k, d_v); - message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu))); } + meta = pmt::dict_add(meta, d_k, d_v); + message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu))); +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/pdu_set_impl.h b/gr-blocks/lib/pdu_set_impl.h index 3529195aaf..581e177e94 100644 --- a/gr-blocks/lib/pdu_set_impl.h +++ b/gr-blocks/lib/pdu_set_impl.h @@ -26,22 +26,22 @@ #include <gnuradio/blocks/pdu_set.h> namespace gr { - namespace blocks { +namespace blocks { - class pdu_set_impl : public pdu_set - { - private: - pmt::pmt_t d_k; - pmt::pmt_t d_v; +class pdu_set_impl : public pdu_set +{ +private: + pmt::pmt_t d_k; + pmt::pmt_t d_v; - public: - pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v); - void handle_msg(pmt::pmt_t msg); - void set_key(pmt::pmt_t key) { d_k = key; }; - void set_val(pmt::pmt_t val) { d_v = val; }; - }; +public: + pdu_set_impl(pmt::pmt_t k, pmt::pmt_t v); + void handle_msg(pmt::pmt_t msg); + void set_key(pmt::pmt_t key) { d_k = key; }; + void set_val(pmt::pmt_t val) { d_v = val; }; +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_PDU_SET_IMPL_H */ diff --git a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc index 2169d1c33d..556f01eaad 100644 --- a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc +++ b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc @@ -29,82 +29,82 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - pdu_to_tagged_stream::sptr - pdu_to_tagged_stream::make(pdu::vector_type type, const std::string& tsb_tag_key) - { - return gnuradio::get_initial_sptr(new pdu_to_tagged_stream_impl(type, tsb_tag_key)); - } - - pdu_to_tagged_stream_impl::pdu_to_tagged_stream_impl(pdu::vector_type type, const std::string& tsb_tag_key) - : tagged_stream_block("pdu_to_tagged_stream", - io_signature::make(0, 0, 0), - io_signature::make(1, 1, pdu::itemsize(type)), - tsb_tag_key), - d_itemsize(pdu::itemsize(type)), - d_curr_len(0) - { - message_port_register_in(pdu::pdu_port_id()); - } - - int pdu_to_tagged_stream_impl::calculate_output_stream_length(const gr_vector_int &) - { - if (d_curr_len == 0) { +namespace blocks { + +pdu_to_tagged_stream::sptr pdu_to_tagged_stream::make(pdu::vector_type type, + const std::string& tsb_tag_key) +{ + return gnuradio::get_initial_sptr(new pdu_to_tagged_stream_impl(type, tsb_tag_key)); +} + +pdu_to_tagged_stream_impl::pdu_to_tagged_stream_impl(pdu::vector_type type, + const std::string& tsb_tag_key) + : tagged_stream_block("pdu_to_tagged_stream", + io_signature::make(0, 0, 0), + io_signature::make(1, 1, pdu::itemsize(type)), + tsb_tag_key), + d_itemsize(pdu::itemsize(type)), + d_curr_len(0) +{ + message_port_register_in(pdu::pdu_port_id()); +} + +int pdu_to_tagged_stream_impl::calculate_output_stream_length(const gr_vector_int&) +{ + if (d_curr_len == 0) { pmt::pmt_t msg(delete_head_nowait(pdu::pdu_port_id())); if (msg.get() == NULL) { - return 0; + return 0; } if (!pmt::is_pair(msg)) - throw std::runtime_error("received a malformed pdu message"); + throw std::runtime_error("received a malformed pdu message"); d_curr_meta = pmt::car(msg); d_curr_vect = pmt::cdr(msg); // do not assume the length of PMT is in items (e.g.: from socket_pdu) - d_curr_len = pmt::blob_length(d_curr_vect)/d_itemsize; - } - - return d_curr_len; + d_curr_len = pmt::blob_length(d_curr_vect) / d_itemsize; } - int - pdu_to_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) - { - uint8_t *out = (uint8_t*) output_items[0]; + return d_curr_len; +} + +int pdu_to_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) +{ + uint8_t* out = (uint8_t*)output_items[0]; - if (d_curr_len == 0) { + if (d_curr_len == 0) { return 0; - } + } - // work() should only be called if the current PDU fits entirely - // into the output buffer. - assert(noutput_items >= 0 && (unsigned int) noutput_items >= d_curr_len); + // work() should only be called if the current PDU fits entirely + // into the output buffer. + assert(noutput_items >= 0 && (unsigned int)noutput_items >= d_curr_len); - // Copy vector output - size_t nout = d_curr_len; - size_t io(0); - const uint8_t* ptr = (const uint8_t*) uniform_vector_elements(d_curr_vect, io); - memcpy(out, ptr, d_curr_len*d_itemsize); + // Copy vector output + size_t nout = d_curr_len; + size_t io(0); + const uint8_t* ptr = (const uint8_t*)uniform_vector_elements(d_curr_vect, io); + memcpy(out, ptr, d_curr_len * d_itemsize); - // Copy tags - if (!pmt::eq(d_curr_meta, pmt::PMT_NIL) ) { + // Copy tags + if (!pmt::eq(d_curr_meta, pmt::PMT_NIL)) { pmt::pmt_t klist(pmt::dict_keys(d_curr_meta)); for (size_t i = 0; i < pmt::length(klist); i++) { - pmt::pmt_t k(pmt::nth(i, klist)); - pmt::pmt_t v(pmt::dict_ref(d_curr_meta, k, pmt::PMT_NIL)); - add_item_tag(0, nitems_written(0), k, v, alias_pmt()); + pmt::pmt_t k(pmt::nth(i, klist)); + pmt::pmt_t v(pmt::dict_ref(d_curr_meta, k, pmt::PMT_NIL)); + add_item_tag(0, nitems_written(0), k, v, alias_pmt()); } - } + } - // Reset state - d_curr_len = 0; + // Reset state + d_curr_len = 0; - return nout; - } /* work() */ + return nout; +} /* work() */ - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/pdu_to_tagged_stream_impl.h b/gr-blocks/lib/pdu_to_tagged_stream_impl.h index bce8122b13..76e968ae0e 100644 --- a/gr-blocks/lib/pdu_to_tagged_stream_impl.h +++ b/gr-blocks/lib/pdu_to_tagged_stream_impl.h @@ -26,28 +26,28 @@ #include <gnuradio/blocks/pdu_to_tagged_stream.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API pdu_to_tagged_stream_impl : public pdu_to_tagged_stream - { - size_t d_itemsize; - pmt::pmt_t d_curr_meta; - pmt::pmt_t d_curr_vect; - size_t d_curr_len; +class BLOCKS_API pdu_to_tagged_stream_impl : public pdu_to_tagged_stream +{ + size_t d_itemsize; + pmt::pmt_t d_curr_meta; + pmt::pmt_t d_curr_vect; + size_t d_curr_len; - public: - pdu_to_tagged_stream_impl(pdu::vector_type type, const std::string& lengthtagname="packet_len"); +public: + pdu_to_tagged_stream_impl(pdu::vector_type type, + const std::string& lengthtagname = "packet_len"); - int calculate_output_stream_length(const gr_vector_int &ninput_items); + int calculate_output_stream_length(const gr_vector_int& ninput_items); - int work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items - ); - }; + 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 blocks */ } /* namespace gr */ #endif /* INCLUDED_PDU_TO_TAGGED_STREAM_IMPL_H */ diff --git a/gr-blocks/lib/peak_detector2_fb_impl.cc b/gr-blocks/lib/peak_detector2_fb_impl.cc index f361ea18bb..bf1e648cd5 100644 --- a/gr-blocks/lib/peak_detector2_fb_impl.cc +++ b/gr-blocks/lib/peak_detector2_fb_impl.cc @@ -30,117 +30,107 @@ #include <limits> namespace gr { - namespace blocks { - - peak_detector2_fb::sptr - peak_detector2_fb::make(float threshold_factor_rise, - int look_ahead, float alpha) - { - return gnuradio::get_initial_sptr - (new peak_detector2_fb_impl(threshold_factor_rise, - look_ahead, alpha)); - } - - peak_detector2_fb_impl::peak_detector2_fb_impl(float threshold_factor_rise, - int look_ahead, float alpha) - : sync_block("peak_detector2_fb", - io_signature::make(1, 1, sizeof(float)), - io_signature::make2(1, 2, sizeof(char), sizeof(float))), - d_avg(0.0f), d_found(false) - { - set_threshold_factor_rise(threshold_factor_rise); - set_look_ahead(look_ahead); - set_alpha(alpha); - } - - peak_detector2_fb_impl::~peak_detector2_fb_impl() - { - } - - void - peak_detector2_fb_impl::set_threshold_factor_rise(float thr) - { - gr::thread::scoped_lock lock(d_setlock); - d_threshold_factor_rise = thr; - invalidate(); - } - - void - peak_detector2_fb_impl::set_look_ahead(int look) - { - gr::thread::scoped_lock lock(d_setlock); - d_look_ahead = look; - invalidate(); - } - - void - peak_detector2_fb_impl::set_alpha(float alpha) - { - d_alpha = alpha; - } - - void - peak_detector2_fb_impl::invalidate() - { - d_found = false; - set_output_multiple(1); - } - - int - peak_detector2_fb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float *iptr = (float *)input_items[0]; - char *optr = (char *)output_items[0]; - float *sigout; - - if(output_items.size() == 2) - sigout = (float *)output_items[1]; - - memset(optr, 0, noutput_items*sizeof(char)); - - gr::thread::scoped_lock lock(d_setlock); - - // have not crossed threshold yet - if(d_found==false) { - for(int i = 0; i < noutput_items; i++) { - d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg; - if(output_items.size() == 2) - sigout[i]=d_avg; - if(iptr[i] > d_avg * (1.0f + d_threshold_factor_rise)) { - d_found = true; - d_peak_val = std::numeric_limits<float>::min(); - set_output_multiple(d_look_ahead); - return i; - } +namespace blocks { + +peak_detector2_fb::sptr +peak_detector2_fb::make(float threshold_factor_rise, int look_ahead, float alpha) +{ + return gnuradio::get_initial_sptr( + new peak_detector2_fb_impl(threshold_factor_rise, look_ahead, alpha)); +} + +peak_detector2_fb_impl::peak_detector2_fb_impl(float threshold_factor_rise, + int look_ahead, + float alpha) + : sync_block("peak_detector2_fb", + io_signature::make(1, 1, sizeof(float)), + io_signature::make2(1, 2, sizeof(char), sizeof(float))), + d_avg(0.0f), + d_found(false) +{ + set_threshold_factor_rise(threshold_factor_rise); + set_look_ahead(look_ahead); + set_alpha(alpha); +} + +peak_detector2_fb_impl::~peak_detector2_fb_impl() {} + +void peak_detector2_fb_impl::set_threshold_factor_rise(float thr) +{ + gr::thread::scoped_lock lock(d_setlock); + d_threshold_factor_rise = thr; + invalidate(); +} + +void peak_detector2_fb_impl::set_look_ahead(int look) +{ + gr::thread::scoped_lock lock(d_setlock); + d_look_ahead = look; + invalidate(); +} + +void peak_detector2_fb_impl::set_alpha(float alpha) { d_alpha = alpha; } + +void peak_detector2_fb_impl::invalidate() +{ + d_found = false; + set_output_multiple(1); +} + +int peak_detector2_fb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float* iptr = (float*)input_items[0]; + char* optr = (char*)output_items[0]; + float* sigout; + + if (output_items.size() == 2) + sigout = (float*)output_items[1]; + + memset(optr, 0, noutput_items * sizeof(char)); + + gr::thread::scoped_lock lock(d_setlock); + + // have not crossed threshold yet + if (d_found == false) { + for (int i = 0; i < noutput_items; i++) { + d_avg = d_alpha * iptr[i] + (1.0f - d_alpha) * d_avg; + if (output_items.size() == 2) + sigout[i] = d_avg; + if (iptr[i] > d_avg * (1.0f + d_threshold_factor_rise)) { + d_found = true; + d_peak_val = std::numeric_limits<float>::min(); + set_output_multiple(d_look_ahead); + return i; + } } return noutput_items; - } // end d_found==false - - // can complete in this call - else if(noutput_items >= d_look_ahead) { - for(int i = 0; i < d_look_ahead; i++) { - d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg; - if(output_items.size() == 2) - sigout[i]=d_avg; - if(iptr[i] > d_peak_val) { - d_peak_val = iptr[i]; - d_peak_ind =i; - } + } // end d_found==false + + // can complete in this call + else if (noutput_items >= d_look_ahead) { + for (int i = 0; i < d_look_ahead; i++) { + d_avg = d_alpha * iptr[i] + (1.0f - d_alpha) * d_avg; + if (output_items.size() == 2) + sigout[i] = d_avg; + if (iptr[i] > d_peak_val) { + d_peak_val = iptr[i]; + d_peak_ind = i; + } } optr[d_peak_ind] = 1; // restart the search invalidate(); return d_look_ahead; - } // end can complete in this call + } // end can complete in this call - // cannot complete in this call - else { + // cannot complete in this call + else { return 0; // ask for more - } } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/peak_detector2_fb_impl.h b/gr-blocks/lib/peak_detector2_fb_impl.h index 929e302d68..713577a19a 100644 --- a/gr-blocks/lib/peak_detector2_fb_impl.h +++ b/gr-blocks/lib/peak_detector2_fb_impl.h @@ -26,40 +26,39 @@ #include <gnuradio/blocks/peak_detector2_fb.h> namespace gr { - namespace blocks { +namespace blocks { - class peak_detector2_fb_impl : public peak_detector2_fb - { - private: - float d_threshold_factor_rise; - int d_look_ahead; - int d_peak_ind; - float d_peak_val; - float d_alpha; - float d_avg; - bool d_found; +class peak_detector2_fb_impl : public peak_detector2_fb +{ +private: + float d_threshold_factor_rise; + int d_look_ahead; + int d_peak_ind; + float d_peak_val; + float d_alpha; + float d_avg; + bool d_found; - void invalidate(); + void invalidate(); - public: - peak_detector2_fb_impl(float threshold_factor_rise, - int look_ahead, float alpha); - ~peak_detector2_fb_impl(); +public: + peak_detector2_fb_impl(float threshold_factor_rise, int look_ahead, float alpha); + ~peak_detector2_fb_impl(); - void set_threshold_factor_rise(float thr); - void set_look_ahead(int look); - void set_alpha(float alpha); + void set_threshold_factor_rise(float thr); + void set_look_ahead(int look); + void set_alpha(float alpha); - float threshold_factor_rise() { return d_threshold_factor_rise; } - int look_ahead() { return d_look_ahead; } - float alpha() { return d_alpha; } + float threshold_factor_rise() { return d_threshold_factor_rise; } + int look_ahead() { return d_look_ahead; } + float alpha() { return d_alpha; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_PEAK_DETECTOR2_FB_IMPL_H */ diff --git a/gr-blocks/lib/peak_detector_impl.cc b/gr-blocks/lib/peak_detector_impl.cc index cda1f6007b..236db4a7aa 100644 --- a/gr-blocks/lib/peak_detector_impl.cc +++ b/gr-blocks/lib/peak_detector_impl.cc @@ -30,99 +30,95 @@ #include <limits> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename peak_detector<T>::sptr - peak_detector<T>::make(float threshold_factor_rise, - float threshold_factor_fall, - int look_ahead, float alpha) - { - return gnuradio::get_initial_sptr - (new peak_detector_impl<T>(threshold_factor_rise, - threshold_factor_fall, - look_ahead, alpha)); - } +template <class T> +typename peak_detector<T>::sptr peak_detector<T>::make(float threshold_factor_rise, + float threshold_factor_fall, + int look_ahead, + float alpha) +{ + return gnuradio::get_initial_sptr(new peak_detector_impl<T>( + threshold_factor_rise, threshold_factor_fall, look_ahead, alpha)); +} - template <class T> - peak_detector_impl<T>::peak_detector_impl(float threshold_factor_rise, - float threshold_factor_fall, - int look_ahead, float alpha) +template <class T> +peak_detector_impl<T>::peak_detector_impl(float threshold_factor_rise, + float threshold_factor_fall, + int look_ahead, + float alpha) : sync_block("peak_detector", - io_signature::make(1, 1, sizeof(T)), - io_signature::make(1, 1, sizeof(char))), + io_signature::make(1, 1, sizeof(T)), + io_signature::make(1, 1, sizeof(char))), d_threshold_factor_rise(threshold_factor_rise), d_threshold_factor_fall(threshold_factor_fall), - d_look_ahead(look_ahead), d_avg_alpha(alpha), d_avg(0) - { - } + d_look_ahead(look_ahead), + d_avg_alpha(alpha), + d_avg(0) +{ +} - template <class T> - peak_detector_impl<T>::~peak_detector_impl() - { - } +template <class T> +peak_detector_impl<T>::~peak_detector_impl() +{ +} - template <class T> - int - peak_detector_impl<T>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T*)input_items[0]; - char *optr = (char*)output_items[0]; +template <class T> +int peak_detector_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; + char* optr = (char*)output_items[0]; - memset(optr, 0, noutput_items*sizeof(char)); + memset(optr, 0, noutput_items * sizeof(char)); - T peak_val = std::numeric_limits<T>::min(); - int peak_ind = 0; - unsigned char state = 0; - int i = 0; + T peak_val = std::numeric_limits<T>::min(); + int peak_ind = 0; + unsigned char state = 0; + int i = 0; - //printf("noutput_items %d\n",noutput_items); - while(i < noutput_items) { - if(state == 0) { // below threshold - if(iptr[i] > d_avg*d_threshold_factor_rise) { - state = 1; - } - else { - d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg; - i++; - } + // printf("noutput_items %d\n",noutput_items); + while (i < noutput_items) { + if (state == 0) { // below threshold + if (iptr[i] > d_avg * d_threshold_factor_rise) { + state = 1; + } else { + d_avg = (d_avg_alpha)*iptr[i] + (1 - d_avg_alpha) * d_avg; + i++; + } + } else if (state == 1) { // above threshold, have not found peak + // printf("Entered State 1: %f i: %d noutput_items: %d\n", iptr[i], i, + // noutput_items); + if (iptr[i] > peak_val) { + peak_val = iptr[i]; + peak_ind = i; + d_avg = (d_avg_alpha)*iptr[i] + (1 - d_avg_alpha) * d_avg; + i++; + } else if (iptr[i] > d_avg * d_threshold_factor_fall) { + d_avg = (d_avg_alpha)*iptr[i] + (1 - d_avg_alpha) * d_avg; + i++; + } else { + optr[peak_ind] = 1; + state = 0; + peak_val = -(T)INFINITY; + // printf("Leaving State 1: Peak: %f Peak Ind: %d i: %d noutput_items: + // %d\n", peak_val, peak_ind, i, noutput_items); + } } - else if(state == 1) { // above threshold, have not found peak - //printf("Entered State 1: %f i: %d noutput_items: %d\n", iptr[i], i, noutput_items); - if(iptr[i] > peak_val) { - peak_val = iptr[i]; - peak_ind = i; - d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg; - i++; - } - else if(iptr[i] > d_avg*d_threshold_factor_fall) { - d_avg = (d_avg_alpha)*iptr[i] + (1-d_avg_alpha)*d_avg; - i++; - } - else { - optr[peak_ind] = 1; - state = 0; - peak_val = -(T)INFINITY; - //printf("Leaving State 1: Peak: %f Peak Ind: %d i: %d noutput_items: %d\n", - //peak_val, peak_ind, i, noutput_items); - } - } - } + } - if(state == 0) { - //printf("Leave in State 0, produced %d\n",noutput_items); + if (state == 0) { + // printf("Leave in State 0, produced %d\n",noutput_items); return noutput_items; - } - else { // only return up to passing the threshold - //printf("Leave in State 1, only produced %d of %d\n",peak_ind,noutput_items); - return peak_ind+1; - } + } else { // only return up to passing the threshold + // printf("Leave in State 1, only produced %d of %d\n",peak_ind,noutput_items); + return peak_ind + 1; } +} - template class peak_detector<float>; - template class peak_detector<std::int16_t>; - template class peak_detector<std::int32_t>; - } /* namespace blocks */ +template class peak_detector<float>; +template class peak_detector<std::int16_t>; +template class peak_detector<std::int32_t>; +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/peak_detector_impl.h b/gr-blocks/lib/peak_detector_impl.h index 5a70c1b060..934d712a9f 100644 --- a/gr-blocks/lib/peak_detector_impl.h +++ b/gr-blocks/lib/peak_detector_impl.h @@ -26,39 +26,40 @@ #include <gnuradio/blocks/peak_detector.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - class peak_detector_impl : public peak_detector<T> - { - private: - float d_threshold_factor_rise; - float d_threshold_factor_fall; - int d_look_ahead; - float d_avg_alpha; - float d_avg; +template <class T> +class peak_detector_impl : public peak_detector<T> +{ +private: + float d_threshold_factor_rise; + float d_threshold_factor_fall; + int d_look_ahead; + float d_avg_alpha; + float d_avg; - public: - peak_detector_impl(float threshold_factor_rise, - float threshold_factor_fall, - int look_ahead, float alpha); - ~peak_detector_impl(); +public: + peak_detector_impl(float threshold_factor_rise, + float threshold_factor_fall, + int look_ahead, + float alpha); + ~peak_detector_impl(); - void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; } - void set_threshold_factor_fall(float thr) { d_threshold_factor_fall = thr; } - void set_look_ahead(int look) { d_look_ahead = look; } - void set_alpha(float alpha) { d_avg_alpha = alpha; } - float threshold_factor_rise() { return d_threshold_factor_rise; } - float threshold_factor_fall() { return d_threshold_factor_fall; } - int look_ahead() { return d_look_ahead; } - float alpha() { return d_avg_alpha; } + void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; } + void set_threshold_factor_fall(float thr) { d_threshold_factor_fall = thr; } + void set_look_ahead(int look) { d_look_ahead = look; } + void set_alpha(float alpha) { d_avg_alpha = alpha; } + float threshold_factor_rise() { return d_threshold_factor_rise; } + float threshold_factor_fall() { return d_threshold_factor_fall; } + int look_ahead() { return d_look_ahead; } + float alpha() { return d_avg_alpha; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* PEAK_DETECTOR_IMPL_H */ diff --git a/gr-blocks/lib/plateau_detector_fb_impl.cc b/gr-blocks/lib/plateau_detector_fb_impl.cc index 375c1a3070..6f75702c84 100644 --- a/gr-blocks/lib/plateau_detector_fb_impl.cc +++ b/gr-blocks/lib/plateau_detector_fb_impl.cc @@ -28,79 +28,71 @@ #include "plateau_detector_fb_impl.h" namespace gr { - namespace blocks { +namespace blocks { - plateau_detector_fb::sptr - plateau_detector_fb::make(int max_len, float threshold) - { - return gnuradio::get_initial_sptr - (new plateau_detector_fb_impl(max_len, threshold)); - } +plateau_detector_fb::sptr plateau_detector_fb::make(int max_len, float threshold) +{ + return gnuradio::get_initial_sptr(new plateau_detector_fb_impl(max_len, threshold)); +} - plateau_detector_fb_impl::plateau_detector_fb_impl(int max_len, float threshold) - : block("plateau_detector_fb", - io_signature::make(1, 1, sizeof(float)), - io_signature::make(1, 1, sizeof(char))), - d_max_len(max_len), - d_threshold(threshold) - {} +plateau_detector_fb_impl::plateau_detector_fb_impl(int max_len, float threshold) + : block("plateau_detector_fb", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(char))), + d_max_len(max_len), + d_threshold(threshold) +{ +} - plateau_detector_fb_impl::~plateau_detector_fb_impl() - { - } +plateau_detector_fb_impl::~plateau_detector_fb_impl() {} - void - plateau_detector_fb_impl::forecast(int, gr_vector_int &ninput_items_required) - { - ninput_items_required[0] = 2*d_max_len; - } +void plateau_detector_fb_impl::forecast(int, gr_vector_int& ninput_items_required) +{ + ninput_items_required[0] = 2 * d_max_len; +} - int - plateau_detector_fb_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - // thread-safe protection from ::set_threshold - gr::thread::scoped_lock l (d_setlock); +int plateau_detector_fb_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + // thread-safe protection from ::set_threshold + gr::thread::scoped_lock l(d_setlock); - const float *in = (const float *) input_items[0]; - unsigned char *out = (unsigned char *) output_items[0]; - int flank_start; - noutput_items = std::min(noutput_items, ninput_items[0]); - memset((void *) out, 0x00, noutput_items); - int i; - for(i = 0; i < noutput_items; i++) { - if(in[i] >= d_threshold) { - if(noutput_items-i < 2*d_max_len) { // If we can't finish, come back later - break; - } - flank_start = i; - while(i < noutput_items && in[i] >= d_threshold) - i++; - if((i - flank_start) > 1) { // 1 Sample is not a plateau - out[flank_start + (i-flank_start)/2] = 1; - i = std::min(i+d_max_len, noutput_items-1); - } + const float* in = (const float*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; + int flank_start; + noutput_items = std::min(noutput_items, ninput_items[0]); + memset((void*)out, 0x00, noutput_items); + int i; + for (i = 0; i < noutput_items; i++) { + if (in[i] >= d_threshold) { + if (noutput_items - i < + 2 * d_max_len) { // If we can't finish, come back later + break; + } + flank_start = i; + while (i < noutput_items && in[i] >= d_threshold) + i++; + if ((i - flank_start) > 1) { // 1 Sample is not a plateau + out[flank_start + (i - flank_start) / 2] = 1; + i = std::min(i + d_max_len, noutput_items - 1); + } } - } - - this->consume_each(i); - return i; } - void plateau_detector_fb_impl::set_threshold(float threshold) - { - // thread-safe protection from ::set_threshold - gr::thread::scoped_lock l (d_setlock); - d_threshold = threshold; - } + this->consume_each(i); + return i; +} - float plateau_detector_fb_impl::threshold() const - { - return d_threshold; - } +void plateau_detector_fb_impl::set_threshold(float threshold) +{ + // thread-safe protection from ::set_threshold + gr::thread::scoped_lock l(d_setlock); + d_threshold = threshold; +} - } /* namespace blocks */ -} /* namespace gr */ +float plateau_detector_fb_impl::threshold() const { return d_threshold; } +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/plateau_detector_fb_impl.h b/gr-blocks/lib/plateau_detector_fb_impl.h index 1a99745104..198f4083d3 100644 --- a/gr-blocks/lib/plateau_detector_fb_impl.h +++ b/gr-blocks/lib/plateau_detector_fb_impl.h @@ -26,31 +26,30 @@ #include <gnuradio/blocks/plateau_detector_fb.h> namespace gr { - namespace blocks { +namespace blocks { class plateau_detector_fb_impl : public plateau_detector_fb { - private: - int d_max_len; - float d_threshold; +private: + int d_max_len; + float d_threshold; - public: - plateau_detector_fb_impl(int max_len, float threshold); - ~plateau_detector_fb_impl(); +public: + plateau_detector_fb_impl(int max_len, float threshold); + ~plateau_detector_fb_impl(); - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - virtual void set_threshold(float threshold); - virtual float threshold() const; + virtual void set_threshold(float threshold); + virtual float threshold() const; }; - } // namespace blocks +} // namespace blocks } // namespace gr #endif /* INCLUDED_BLOCKS_PLATEAU_DETECTOR_FB_IMPL_H */ - diff --git a/gr-blocks/lib/probe_rate_impl.cc b/gr-blocks/lib/probe_rate_impl.cc index 24a736db4d..577959dff2 100644 --- a/gr-blocks/lib/probe_rate_impl.cc +++ b/gr-blocks/lib/probe_rate_impl.cc @@ -28,99 +28,106 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - probe_rate::sptr - probe_rate::make(size_t itemsize, double update_rate_ms, double alpha) - { - return gnuradio::get_initial_sptr - (new probe_rate_impl(itemsize,update_rate_ms,alpha)); - } - - probe_rate_impl::probe_rate_impl(size_t itemsize, double update_rate_ms, double alpha) : - sync_block("probe_rate", - io_signature::make(1,1,itemsize), - io_signature::make(0,0,itemsize)), - d_alpha(alpha), - d_beta(1.0-alpha), - d_avg(0), - d_min_update_time(update_rate_ms), - d_lastthru(0), - d_port(pmt::mp("rate")), - d_dict_avg(pmt::mp("rate_avg")), - d_dict_now(pmt::mp("rate_now")) - { - message_port_register_out(d_port); - } - - probe_rate_impl::~probe_rate_impl(){} - - int probe_rate_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items){ - d_lastthru += noutput_items; - boost::posix_time::ptime now(boost::posix_time::microsec_clock::local_time()); - boost::posix_time::time_duration diff = now - d_last_update; - double diff_ms = diff.total_milliseconds(); - if(diff_ms >= d_min_update_time){ - double rate_this_update = d_lastthru *1e3 / diff_ms; - d_lastthru = 0; - d_last_update = now; - if(d_avg == 0){ - d_avg = rate_this_update; - } else { - d_avg = rate_this_update*d_alpha + d_avg*d_beta; - } - pmt::pmt_t d = pmt::make_dict(); - d = pmt::dict_add(d, d_dict_avg, pmt::mp(d_avg)); - d = pmt::dict_add(d, d_dict_now, pmt::mp(rate_this_update)); - message_port_pub(d_port, pmt::cons(d, pmt::PMT_NIL)); +namespace blocks { + +probe_rate::sptr probe_rate::make(size_t itemsize, double update_rate_ms, double alpha) +{ + return gnuradio::get_initial_sptr( + new probe_rate_impl(itemsize, update_rate_ms, alpha)); +} + +probe_rate_impl::probe_rate_impl(size_t itemsize, double update_rate_ms, double alpha) + : sync_block("probe_rate", + io_signature::make(1, 1, itemsize), + io_signature::make(0, 0, itemsize)), + d_alpha(alpha), + d_beta(1.0 - alpha), + d_avg(0), + d_min_update_time(update_rate_ms), + d_lastthru(0), + d_port(pmt::mp("rate")), + d_dict_avg(pmt::mp("rate_avg")), + d_dict_now(pmt::mp("rate_now")) +{ + message_port_register_out(d_port); +} + +probe_rate_impl::~probe_rate_impl() {} + +int probe_rate_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + d_lastthru += noutput_items; + boost::posix_time::ptime now(boost::posix_time::microsec_clock::local_time()); + boost::posix_time::time_duration diff = now - d_last_update; + double diff_ms = diff.total_milliseconds(); + if (diff_ms >= d_min_update_time) { + double rate_this_update = d_lastthru * 1e3 / diff_ms; + d_lastthru = 0; + d_last_update = now; + if (d_avg == 0) { + d_avg = rate_this_update; + } else { + d_avg = rate_this_update * d_alpha + d_avg * d_beta; } - return noutput_items; - } + pmt::pmt_t d = pmt::make_dict(); + d = pmt::dict_add(d, d_dict_avg, pmt::mp(d_avg)); + d = pmt::dict_add(d, d_dict_now, pmt::mp(rate_this_update)); + message_port_pub(d_port, pmt::cons(d, pmt::PMT_NIL)); + } + return noutput_items; +} - void probe_rate_impl::setup_rpc(){ +void probe_rate_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_get<probe_rate_impl, double >( - alias(), "rate_items", - &probe_rate_impl::rate, - pmt::mp(0), pmt::mp(1e6), pmt::mp(1), - "items/sec", "Item rate", - RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_get<probe_rate_impl, double >( - alias(), "timesincelast", - &probe_rate_impl::timesincelast, - pmt::mp(0), pmt::mp(d_min_update_time*2), pmt::mp(0), - "ms", "Time since last update", - RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); + add_rpc_variable(rpcbasic_sptr( + new rpcbasic_register_get<probe_rate_impl, double>(alias(), + "rate_items", + &probe_rate_impl::rate, + pmt::mp(0), + pmt::mp(1e6), + pmt::mp(1), + "items/sec", + "Item rate", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); + add_rpc_variable(rpcbasic_sptr(new rpcbasic_register_get<probe_rate_impl, double>( + alias(), + "timesincelast", + &probe_rate_impl::timesincelast, + pmt::mp(0), + pmt::mp(d_min_update_time * 2), + pmt::mp(0), + "ms", + "Time since last update", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); #endif - } +} - void probe_rate_impl::set_alpha(double alpha){ d_alpha = alpha; } +void probe_rate_impl::set_alpha(double alpha) { d_alpha = alpha; } - double probe_rate_impl::rate(){ return d_avg; } +double probe_rate_impl::rate() { return d_avg; } - double probe_rate_impl::timesincelast(){ - boost::posix_time::ptime now(boost::posix_time::microsec_clock::local_time()); - boost::posix_time::time_duration diff = now - d_last_update; - return diff.total_milliseconds(); - } +double probe_rate_impl::timesincelast() +{ + boost::posix_time::ptime now(boost::posix_time::microsec_clock::local_time()); + boost::posix_time::time_duration diff = now - d_last_update; + return diff.total_milliseconds(); +} - bool probe_rate_impl::start(){ - d_avg = 0; - d_lastthru = 0; - d_last_update = boost::posix_time::microsec_clock::local_time(); - return true; - } - - bool probe_rate_impl::stop(){ - return true; - } +bool probe_rate_impl::start() +{ + d_avg = 0; + d_lastthru = 0; + d_last_update = boost::posix_time::microsec_clock::local_time(); + return true; +} +bool probe_rate_impl::stop() { return true; } - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ - diff --git a/gr-blocks/lib/probe_rate_impl.h b/gr-blocks/lib/probe_rate_impl.h index 42c3b13fe2..7128981b55 100644 --- a/gr-blocks/lib/probe_rate_impl.h +++ b/gr-blocks/lib/probe_rate_impl.h @@ -26,36 +26,36 @@ #include <gnuradio/blocks/probe_rate.h> namespace gr { - namespace blocks { - - class probe_rate_impl : public probe_rate - { - private: - double d_alpha, d_beta, d_avg; - double d_min_update_time; - boost::posix_time::ptime d_last_update; - uint64_t d_lastthru; - void setup_rpc(); - - const pmt::pmt_t d_port; - const pmt::pmt_t d_dict_avg, d_dict_now; - - public: - probe_rate_impl(size_t itemsize, double update_rate_ms, double alpha = 0.0001); - ~probe_rate_impl(); - void set_alpha(double alpha); - double rate(); - double timesincelast(); - bool start(); - bool stop(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - }; // end class - - } /* namespace blocks */ +namespace blocks { + +class probe_rate_impl : public probe_rate +{ +private: + double d_alpha, d_beta, d_avg; + double d_min_update_time; + boost::posix_time::ptime d_last_update; + uint64_t d_lastthru; + void setup_rpc(); + + const pmt::pmt_t d_port; + const pmt::pmt_t d_dict_avg, d_dict_now; + +public: + probe_rate_impl(size_t itemsize, double update_rate_ms, double alpha = 0.0001); + ~probe_rate_impl(); + void set_alpha(double alpha); + double rate(); + double timesincelast(); + bool start(); + bool stop(); + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); + +}; // end class + +} /* namespace blocks */ } /* namespace gr */ #endif diff --git a/gr-blocks/lib/probe_signal_impl.cc b/gr-blocks/lib/probe_signal_impl.cc index 1766464fc6..256df2036e 100644 --- a/gr-blocks/lib/probe_signal_impl.cc +++ b/gr-blocks/lib/probe_signal_impl.cc @@ -29,48 +29,45 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename probe_signal<T>::sptr - probe_signal<T>::make() - { - return gnuradio::get_initial_sptr - (new probe_signal_impl<T> ()); - } +template <class T> +typename probe_signal<T>::sptr probe_signal<T>::make() +{ + return gnuradio::get_initial_sptr(new probe_signal_impl<T>()); +} - template <class T> - probe_signal_impl<T> ::probe_signal_impl() +template <class T> +probe_signal_impl<T>::probe_signal_impl() : sync_block("probe_signal", - io_signature::make(1, 1, sizeof(T)), - io_signature::make(0, 0, 0)), + io_signature::make(1, 1, sizeof(T)), + io_signature::make(0, 0, 0)), d_level(0) - { - } +{ +} - template <class T> - probe_signal_impl<T> ::~probe_signal_impl() - { - } +template <class T> +probe_signal_impl<T>::~probe_signal_impl() +{ +} - template <class T> - int - probe_signal_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const T *in = (const T *)input_items[0]; +template <class T> +int probe_signal_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const T* in = (const T*)input_items[0]; - if(noutput_items > 0) - d_level = in[noutput_items-1]; + if (noutput_items > 0) + d_level = in[noutput_items - 1]; - return noutput_items; - } + return noutput_items; +} template class probe_signal<std::uint8_t>; template class probe_signal<std::int16_t>; template class probe_signal<std::int32_t>; template class probe_signal<float>; template class probe_signal<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/probe_signal_impl.h b/gr-blocks/lib/probe_signal_impl.h index d86f6e6d75..bf0822ff91 100644 --- a/gr-blocks/lib/probe_signal_impl.h +++ b/gr-blocks/lib/probe_signal_impl.h @@ -27,26 +27,26 @@ #include <gnuradio/blocks/probe_signal.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class probe_signal_impl : public probe_signal<T> - { - private: - T d_level; +template <class T> +class probe_signal_impl : public probe_signal<T> +{ +private: + T d_level; - public: - probe_signal_impl (); - ~probe_signal_impl (); +public: + probe_signal_impl(); + ~probe_signal_impl(); - T level() const { return d_level; } + T level() const { return d_level; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* PROBE_SIGNAL_IMPL_H */ diff --git a/gr-blocks/lib/probe_signal_v_impl.cc b/gr-blocks/lib/probe_signal_v_impl.cc index 3b2b942bf5..fb716831f0 100644 --- a/gr-blocks/lib/probe_signal_v_impl.cc +++ b/gr-blocks/lib/probe_signal_v_impl.cc @@ -29,48 +29,46 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename probe_signal_v<T>::sptr - probe_signal_v<T>::make(size_t size) - { - return gnuradio::get_initial_sptr - (new probe_signal_v_impl<T>(size)); - } +template <class T> +typename probe_signal_v<T>::sptr probe_signal_v<T>::make(size_t size) +{ + return gnuradio::get_initial_sptr(new probe_signal_v_impl<T>(size)); +} - template <class T> - probe_signal_v_impl<T>::probe_signal_v_impl(size_t size) +template <class T> +probe_signal_v_impl<T>::probe_signal_v_impl(size_t size) : sync_block("probe_signal_v", - io_signature::make(1, 1, size*sizeof(T)), - io_signature::make(0, 0, 0)), - d_level(size, 0), d_size(size) - { - } + io_signature::make(1, 1, size * sizeof(T)), + io_signature::make(0, 0, 0)), + d_level(size, 0), + d_size(size) +{ +} - template <class T> - probe_signal_v_impl<T>::~probe_signal_v_impl() - { - } +template <class T> +probe_signal_v_impl<T>::~probe_signal_v_impl() +{ +} - template <class T> - int - probe_signal_v_impl<T>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const T *in = (const T *)input_items[0]; +template <class T> +int probe_signal_v_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const T* in = (const T*)input_items[0]; - for(size_t i=0; i<d_size; i++) - d_level[i] = in[(noutput_items-1)*d_size+i]; + for (size_t i = 0; i < d_size; i++) + d_level[i] = in[(noutput_items - 1) * d_size + i]; - return noutput_items; - } - template class probe_signal_v<std::uint8_t>; - template class probe_signal_v<std::int16_t>; - template class probe_signal_v<std::int32_t>; - template class probe_signal_v<float>; - template class probe_signal_v<gr_complex>; + return noutput_items; +} +template class probe_signal_v<std::uint8_t>; +template class probe_signal_v<std::int16_t>; +template class probe_signal_v<std::int32_t>; +template class probe_signal_v<float>; +template class probe_signal_v<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/probe_signal_v_impl.h b/gr-blocks/lib/probe_signal_v_impl.h index dd36ebf741..17d8e348db 100644 --- a/gr-blocks/lib/probe_signal_v_impl.h +++ b/gr-blocks/lib/probe_signal_v_impl.h @@ -27,27 +27,27 @@ #include <gnuradio/blocks/probe_signal_v.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - class probe_signal_v_impl : public probe_signal_v<T> - { - private: - std::vector<T> d_level; - size_t d_size; +template <class T> +class probe_signal_v_impl : public probe_signal_v<T> +{ +private: + std::vector<T> d_level; + size_t d_size; - public: - probe_signal_v_impl(size_t size); - ~probe_signal_v_impl(); +public: + probe_signal_v_impl(size_t size); + ~probe_signal_v_impl(); - std::vector<T> level() const { return d_level; } + std::vector<T> level() const { return d_level; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* PROBE_SIGNAL_V_IMPL_H */ diff --git a/gr-blocks/lib/qa_block_tags.cc b/gr-blocks/lib/qa_block_tags.cc index fc61065e95..2c45551e37 100644 --- a/gr-blocks/lib/qa_block_tags.cc +++ b/gr-blocks/lib/qa_block_tags.cc @@ -46,408 +46,435 @@ // particular order. #define QA_TAGS_DEBUG 0 -gr::tag_t make_tag(uint64_t offset, pmt::pmt_t key, pmt::pmt_t value, pmt::pmt_t srcid) { - gr::tag_t result; - result.offset = offset; - result.key = key; - result.value = value; - result.srcid = srcid; - return result; +gr::tag_t make_tag(uint64_t offset, pmt::pmt_t key, pmt::pmt_t value, pmt::pmt_t srcid) +{ + gr::tag_t result; + result.offset = offset; + result.key = key; + result.value = value; + result.srcid = srcid; + return result; } -std::ostream& -operator << (std::ostream& os, const gr::tag_t &t) { - return os; -} +std::ostream& operator<<(std::ostream& os, const gr::tag_t& t) { return os; } BOOST_AUTO_TEST_CASE(t0) { - unsigned int N = 1000; - gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src (gr::blocks::null_source::make(sizeof(int))); - gr::block_sptr head (gr::blocks::head::make(sizeof(int), N)); - gr::block_sptr snk (gr::blocks::null_sink::make(sizeof(int))); + unsigned int N = 1000; + gr::top_block_sptr tb = gr::make_top_block("top"); + gr::block_sptr src(gr::blocks::null_source::make(sizeof(int))); + gr::block_sptr head(gr::blocks::head::make(sizeof(int), N)); + gr::block_sptr snk(gr::blocks::null_sink::make(sizeof(int))); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, snk, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, snk, 0); - BOOST_REQUIRE_EQUAL(src->nitems_read(0), (uint64_t)0); - BOOST_REQUIRE_EQUAL(src->nitems_written(0), (uint64_t)0); + BOOST_REQUIRE_EQUAL(src->nitems_read(0), (uint64_t)0); + BOOST_REQUIRE_EQUAL(src->nitems_written(0), (uint64_t)0); - tb->run(); + tb->run(); - BOOST_REQUIRE_THROW(src->nitems_read(0), std::invalid_argument); - BOOST_REQUIRE(src->nitems_written(0) >= N); - BOOST_REQUIRE_EQUAL(snk->nitems_read(0), (uint64_t)1000); - BOOST_REQUIRE_THROW(snk->nitems_written(0), std::invalid_argument); + BOOST_REQUIRE_THROW(src->nitems_read(0), std::invalid_argument); + BOOST_REQUIRE(src->nitems_written(0) >= N); + BOOST_REQUIRE_EQUAL(snk->nitems_read(0), (uint64_t)1000); + BOOST_REQUIRE_THROW(snk->nitems_written(0), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t1) { - int N = 40000; - gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src (gr::blocks::null_source::make(sizeof(int))); - gr::block_sptr head (gr::blocks::head::make(sizeof(int), N)); - gr::blocks::annotator_alltoall::sptr ann0(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann1(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann2(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann3(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann4(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::block_sptr snk0 (gr::blocks::null_sink::make(sizeof(int))); - gr::block_sptr snk1 (gr::blocks::null_sink::make(sizeof(int))); - - tb->connect(src, 0, head, 0); - tb->connect(head, 0, ann0, 0); - - tb->connect(ann0, 0, ann1, 0); - tb->connect(ann0, 1, ann2, 0); - tb->connect(ann1, 0, ann3, 0); - tb->connect(ann2, 0, ann4, 0); - - tb->connect(ann3, 0, snk0, 0); - tb->connect(ann4, 0, snk1, 0); - - tb->run(); - - std::vector<gr::tag_t> tags0 = ann0->data(); - std::vector<gr::tag_t> tags3 = ann3->data(); - std::vector<gr::tag_t> tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - BOOST_REQUIRE_EQUAL(tags0.size(), (size_t)0); - BOOST_REQUIRE_EQUAL(tags3.size(), (size_t)8); - BOOST_REQUIRE_EQUAL(tags4.size(), (size_t)8); + int N = 40000; + gr::top_block_sptr tb = gr::make_top_block("top"); + gr::block_sptr src(gr::blocks::null_source::make(sizeof(int))); + gr::block_sptr head(gr::blocks::head::make(sizeof(int), N)); + gr::blocks::annotator_alltoall::sptr ann0( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann1( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann2( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann3( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann4( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::block_sptr snk0(gr::blocks::null_sink::make(sizeof(int))); + gr::block_sptr snk1(gr::blocks::null_sink::make(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, ann3, 0); + tb->connect(ann2, 0, ann4, 0); + + tb->connect(ann3, 0, snk0, 0); + tb->connect(ann4, 0, snk1, 0); + + tb->run(); + + std::vector<gr::tag_t> tags0 = ann0->data(); + std::vector<gr::tag_t> tags3 = ann3->data(); + std::vector<gr::tag_t> tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + BOOST_REQUIRE_EQUAL(tags0.size(), (size_t)0); + BOOST_REQUIRE_EQUAL(tags3.size(), (size_t)8); + BOOST_REQUIRE_EQUAL(tags4.size(), (size_t)8); #if QA_TAGS_DEBUG - // Kludge together the tags that we know should result from the above graph - std::stringstream str0, str1, str2; - str0 << ann0->name() << ann0->unique_id(); - str1 << ann1->name() << ann1->unique_id(); - str2 << ann2->name() << ann2->unique_id(); - - gr::tag_t expected_tags3[8]; - expected_tags3[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags3[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags3[2] = make_tag(10000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags3[3] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags3[4] = make_tag(20000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags3[5] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); - expected_tags3[6] = make_tag(30000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags3[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6)); - - gr::tag_t expected_tags4[8]; - expected_tags4[0] = make_tag(0, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags4[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags4[2] = make_tag(10000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags4[3] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags4[4] = make_tag(20000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags4[5] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(5)); - expected_tags4[6] = make_tag(30000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags4[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7)); - - std::cout << std::endl << "qa_block_tags::t1" << std::endl; - - // For annotator 3, we know it gets tags from ann0 and ann1, test this - for(size_t i = 0; i < tags3.size(); i++) { - std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - BOOST_REQUIRE_EQUAL(tags3[i], expected_tags3[i]); - } - - // For annotator 4, we know it gets tags from ann0 and ann2, test this - std::cout << std::endl; - for(size_t i = 0; i < tags4.size(); i++) { - std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; - BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]); - } + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + gr::tag_t expected_tags3[8]; + expected_tags3[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags3[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags3[2] = make_tag(10000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags3[3] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags3[4] = make_tag(20000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags3[5] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); + expected_tags3[6] = make_tag(30000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags3[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6)); + + gr::tag_t expected_tags4[8]; + expected_tags4[0] = make_tag(0, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags4[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags4[2] = make_tag(10000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags4[3] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags4[4] = make_tag(20000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags4[5] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(5)); + expected_tags4[6] = make_tag(30000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags4[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7)); + + std::cout << std::endl << "qa_block_tags::t1" << std::endl; + + // For annotator 3, we know it gets tags from ann0 and ann1, test this + for (size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] + << std::endl; + BOOST_REQUIRE_EQUAL(tags3[i], expected_tags3[i]); + } + + // For annotator 4, we know it gets tags from ann0 and ann2, test this + std::cout << std::endl; + for (size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] + << std::endl; + BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]); + } #endif } BOOST_AUTO_TEST_CASE(t2) { - int N = 40000; - gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src (gr::blocks::null_source::make(sizeof(int))); - gr::block_sptr head (gr::blocks::head::make(sizeof(int), N)); - gr::blocks::annotator_alltoall::sptr ann0(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann1(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann2(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann3(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann4(gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::block_sptr snk0 (gr::blocks::null_sink::make(sizeof(int))); - gr::block_sptr snk1 (gr::blocks::null_sink::make(sizeof(int))); - gr::block_sptr snk2 (gr::blocks::null_sink::make(sizeof(int))); - - tb->connect(src, 0, head, 0); - tb->connect(head, 0, ann0, 0); - - tb->connect(ann0, 0, ann1, 0); - tb->connect(ann0, 1, ann1, 1); - tb->connect(ann1, 0, ann2, 0); - tb->connect(ann1, 1, ann3, 0); - tb->connect(ann1, 2, ann4, 0); - - tb->connect(ann2, 0, snk0, 0); - tb->connect(ann3, 0, snk1, 0); - tb->connect(ann4, 0, snk2, 0); - - tb->run(); - - std::vector<gr::tag_t> tags0 = ann0->data(); - std::vector<gr::tag_t> tags1 = ann1->data(); - std::vector<gr::tag_t> tags2 = ann2->data(); - std::vector<gr::tag_t> tags3 = ann4->data(); - std::vector<gr::tag_t> tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - BOOST_REQUIRE_EQUAL(tags0.size(), (size_t)0); - BOOST_REQUIRE_EQUAL(tags1.size(), (size_t)8); - - // Make sure the rest all have 12 tags - BOOST_REQUIRE_EQUAL(tags2.size(), (size_t)12); - BOOST_REQUIRE_EQUAL(tags3.size(), (size_t)12); - BOOST_REQUIRE_EQUAL(tags4.size(), (size_t)12); + int N = 40000; + gr::top_block_sptr tb = gr::make_top_block("top"); + gr::block_sptr src(gr::blocks::null_source::make(sizeof(int))); + gr::block_sptr head(gr::blocks::head::make(sizeof(int), N)); + gr::blocks::annotator_alltoall::sptr ann0( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann1( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann2( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann3( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann4( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::block_sptr snk0(gr::blocks::null_sink::make(sizeof(int))); + gr::block_sptr snk1(gr::blocks::null_sink::make(sizeof(int))); + gr::block_sptr snk2(gr::blocks::null_sink::make(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann1, 1); + tb->connect(ann1, 0, ann2, 0); + tb->connect(ann1, 1, ann3, 0); + tb->connect(ann1, 2, ann4, 0); + + tb->connect(ann2, 0, snk0, 0); + tb->connect(ann3, 0, snk1, 0); + tb->connect(ann4, 0, snk2, 0); + + tb->run(); + + std::vector<gr::tag_t> tags0 = ann0->data(); + std::vector<gr::tag_t> tags1 = ann1->data(); + std::vector<gr::tag_t> tags2 = ann2->data(); + std::vector<gr::tag_t> tags3 = ann4->data(); + std::vector<gr::tag_t> tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + BOOST_REQUIRE_EQUAL(tags0.size(), (size_t)0); + BOOST_REQUIRE_EQUAL(tags1.size(), (size_t)8); + + // Make sure the rest all have 12 tags + BOOST_REQUIRE_EQUAL(tags2.size(), (size_t)12); + BOOST_REQUIRE_EQUAL(tags3.size(), (size_t)12); + BOOST_REQUIRE_EQUAL(tags4.size(), (size_t)12); #if QA_TAGS_DEBUG - // Kludge together the tags that we know should result from the above graph - std::stringstream str0, str1; - str0 << ann0->name() << ann0->unique_id(); - str1 << ann1->name() << ann1->unique_id(); - - gr::tag_t expected_tags2[12]; - expected_tags2[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags2[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags2[2] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags2[3] = make_tag(10000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags2[4] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags2[5] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags2[6] = make_tag(20000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(6)); - expected_tags2[7] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); - expected_tags2[8] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(5)); - expected_tags2[9] = make_tag(30000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(9)); - expected_tags2[10] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6)); - expected_tags2[11] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7)); - - gr::tag_t expected_tags4[12]; - expected_tags4[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags4[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags4[2] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags4[3] = make_tag(10000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(5)); - expected_tags4[4] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags4[5] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags4[6] = make_tag(20000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(8)); - expected_tags4[7] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); - expected_tags4[8] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(5)); - expected_tags4[9] = make_tag(30000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(11)); - expected_tags4[10] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6)); - expected_tags4[11] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7)); - - std::cout << std::endl << "qa_block_tags::t2" << std::endl; - - // For annotator[2-4], we know it gets tags from ann0 and ann1 - // but the tags from the different outputs of ann1 are different for each. - // Just testing ann2 and ann4; if they are correct it would be - // inconceivable for ann3 to have it wrong. - for(size_t i = 0; i < tags2.size(); i++) { - std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; - BOOST_REQUIRE_EQUAL(tags2[i], expected_tags2[i]); - } - - std::cout << std::endl; - for(size_t i = 0; i < tags4.size(); i++) { - std::cout << "tags2[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; - BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]); - } + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + + gr::tag_t expected_tags2[12]; + expected_tags2[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags2[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags2[2] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags2[3] = make_tag(10000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags2[4] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags2[5] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags2[6] = make_tag(20000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(6)); + expected_tags2[7] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); + expected_tags2[8] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(5)); + expected_tags2[9] = make_tag(30000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(9)); + expected_tags2[10] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6)); + expected_tags2[11] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7)); + + gr::tag_t expected_tags4[12]; + expected_tags4[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags4[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags4[2] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags4[3] = make_tag(10000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(5)); + expected_tags4[4] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags4[5] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags4[6] = make_tag(20000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(8)); + expected_tags4[7] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); + expected_tags4[8] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(5)); + expected_tags4[9] = make_tag(30000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(11)); + expected_tags4[10] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6)); + expected_tags4[11] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7)); + + std::cout << std::endl << "qa_block_tags::t2" << std::endl; + + // For annotator[2-4], we know it gets tags from ann0 and ann1 + // but the tags from the different outputs of ann1 are different for each. + // Just testing ann2 and ann4; if they are correct it would be + // inconceivable for ann3 to have it wrong. + for (size_t i = 0; i < tags2.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] + << std::endl; + BOOST_REQUIRE_EQUAL(tags2[i], expected_tags2[i]); + } + + std::cout << std::endl; + for (size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] + << std::endl; + BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]); + } #endif } BOOST_AUTO_TEST_CASE(t3) { - int N = 40000; - gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src (gr::blocks::null_source::make(sizeof(int))); - gr::block_sptr head (gr::blocks::head::make(sizeof(int), N)); - gr::blocks::annotator_1to1::sptr ann0 (gr::blocks::annotator_1to1::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann1 (gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_alltoall::sptr ann2 (gr::blocks::annotator_alltoall::make(10000, sizeof(int))); - gr::blocks::annotator_1to1::sptr ann3 (gr::blocks::annotator_1to1::make(10000, sizeof(int))); - gr::blocks::annotator_1to1::sptr ann4 (gr::blocks::annotator_1to1::make(10000, sizeof(int))); - gr::block_sptr snk0 (gr::blocks::null_sink::make(sizeof(int))); - gr::block_sptr snk1 (gr::blocks::null_sink::make(sizeof(int))); - - tb->connect(src, 0, head, 0); - tb->connect(head, 0, ann0, 0); - tb->connect(head, 0, ann0, 1); - - tb->connect(ann0, 0, ann1, 0); - tb->connect(ann0, 1, ann2, 0); - tb->connect(ann1, 0, ann3, 0); - tb->connect(ann2, 0, ann4, 0); - - tb->connect(ann3, 0, snk0, 0); - tb->connect(ann4, 0, snk1, 0); - - tb->run(); - - - std::vector<gr::tag_t> tags0 = ann0->data(); - std::vector<gr::tag_t> tags3 = ann3->data(); - std::vector<gr::tag_t> tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - BOOST_REQUIRE_EQUAL(tags0.size(), (size_t)0); - BOOST_REQUIRE_EQUAL(tags3.size(), (size_t)8); - BOOST_REQUIRE_EQUAL(tags4.size(), (size_t)8); + int N = 40000; + gr::top_block_sptr tb = gr::make_top_block("top"); + gr::block_sptr src(gr::blocks::null_source::make(sizeof(int))); + gr::block_sptr head(gr::blocks::head::make(sizeof(int), N)); + gr::blocks::annotator_1to1::sptr ann0( + gr::blocks::annotator_1to1::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann1( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_alltoall::sptr ann2( + gr::blocks::annotator_alltoall::make(10000, sizeof(int))); + gr::blocks::annotator_1to1::sptr ann3( + gr::blocks::annotator_1to1::make(10000, sizeof(int))); + gr::blocks::annotator_1to1::sptr ann4( + gr::blocks::annotator_1to1::make(10000, sizeof(int))); + gr::block_sptr snk0(gr::blocks::null_sink::make(sizeof(int))); + gr::block_sptr snk1(gr::blocks::null_sink::make(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(head, 0, ann0, 1); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, ann3, 0); + tb->connect(ann2, 0, ann4, 0); + + tb->connect(ann3, 0, snk0, 0); + tb->connect(ann4, 0, snk1, 0); + + tb->run(); + + + std::vector<gr::tag_t> tags0 = ann0->data(); + std::vector<gr::tag_t> tags3 = ann3->data(); + std::vector<gr::tag_t> tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + BOOST_REQUIRE_EQUAL(tags0.size(), (size_t)0); + BOOST_REQUIRE_EQUAL(tags3.size(), (size_t)8); + BOOST_REQUIRE_EQUAL(tags4.size(), (size_t)8); #if QA_TAGS_DEBUG - // Kludge together the tags that we know should result from the above graph - std::stringstream str0, str1, str2; - str0 << ann0->name() << ann0->unique_id(); - str1 << ann1->name() << ann1->unique_id(); - str2 << ann2->name() << ann2->unique_id(); - - gr::tag_t expected_tags3[8]; - expected_tags3[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags3[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags3[2] = make_tag(10000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags3[3] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags3[4] = make_tag(20000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags3[5] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); - expected_tags3[6] = make_tag(30000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags3[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6)); - - gr::tag_t expected_tags4[8]; - expected_tags4[0] = make_tag(0, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags4[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags4[2] = make_tag(10000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags4[3] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags4[4] = make_tag(20000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags4[5] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(5)); - expected_tags4[6] = make_tag(30000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags4[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7)); - - std::cout << std::endl << "qa_block_tags::t3" << std::endl; - - // For annotator 3, we know it gets tags from ann0 and ann1, test this - for(size_t i = 0; i < tags3.size(); i++) { - std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - BOOST_REQUIRE_EQUAL(tags3[i], expected_tags3[i]); - } - - // For annotator 4, we know it gets tags from ann0 and ann2, test this - std::cout << std::endl; - for(size_t i = 0; i < tags4.size(); i++) { - std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; - BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]); - } + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + gr::tag_t expected_tags3[8]; + expected_tags3[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags3[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags3[2] = make_tag(10000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags3[3] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags3[4] = make_tag(20000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags3[5] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); + expected_tags3[6] = make_tag(30000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags3[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(6)); + + gr::tag_t expected_tags4[8]; + expected_tags4[0] = make_tag(0, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags4[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags4[2] = make_tag(10000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags4[3] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags4[4] = make_tag(20000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags4[5] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(5)); + expected_tags4[6] = make_tag(30000, pmt::mp(str2.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags4[7] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(7)); + + std::cout << std::endl << "qa_block_tags::t3" << std::endl; + + // For annotator 3, we know it gets tags from ann0 and ann1, test this + for (size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] + << std::endl; + BOOST_REQUIRE_EQUAL(tags3[i], expected_tags3[i]); + } + + // For annotator 4, we know it gets tags from ann0 and ann2, test this + std::cout << std::endl; + for (size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] + << std::endl; + BOOST_REQUIRE_EQUAL(tags4[i], expected_tags4[i]); + } #endif } BOOST_AUTO_TEST_CASE(t4) { - int N = 40000; - gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src (gr::blocks::null_source::make(sizeof(int))); - gr::block_sptr head (gr::blocks::head::make(sizeof(int), N)); - gr::blocks::annotator_1to1::sptr ann0(gr::blocks::annotator_1to1::make(10000, sizeof(int))); - gr::blocks::annotator_1to1::sptr ann1(gr::blocks::annotator_1to1::make(10000, sizeof(int))); - gr::blocks::annotator_1to1::sptr ann2(gr::blocks::annotator_1to1::make(10000, sizeof(int))); - gr::block_sptr snk0 (gr::blocks::null_sink::make(sizeof(int))); - gr::block_sptr snk1 (gr::blocks::null_sink::make(sizeof(int))); - - // using 1-to-1 tag propagation without having equal number of - // ins and outs. Make sure this works; will just exit run early. - tb->connect(src, 0, head, 0); - tb->connect(head, 0, ann0, 0); - tb->connect(ann0, 0, ann1, 0); - tb->connect(ann0, 1, ann2, 0); - tb->connect(ann1, 0, snk0, 0); - tb->connect(ann2, 0, snk1, 0); - - std::cerr << std::endl - << "NOTE: This is supposed to produce an error from block_executor" - << std::endl; - tb->run(); + int N = 40000; + gr::top_block_sptr tb = gr::make_top_block("top"); + gr::block_sptr src(gr::blocks::null_source::make(sizeof(int))); + gr::block_sptr head(gr::blocks::head::make(sizeof(int), N)); + gr::blocks::annotator_1to1::sptr ann0( + gr::blocks::annotator_1to1::make(10000, sizeof(int))); + gr::blocks::annotator_1to1::sptr ann1( + gr::blocks::annotator_1to1::make(10000, sizeof(int))); + gr::blocks::annotator_1to1::sptr ann2( + gr::blocks::annotator_1to1::make(10000, sizeof(int))); + gr::block_sptr snk0(gr::blocks::null_sink::make(sizeof(int))); + gr::block_sptr snk1(gr::blocks::null_sink::make(sizeof(int))); + + // using 1-to-1 tag propagation without having equal number of + // ins and outs. Make sure this works; will just exit run early. + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, snk0, 0); + tb->connect(ann2, 0, snk1, 0); + + std::cerr << std::endl + << "NOTE: This is supposed to produce an error from block_executor" + << std::endl; + tb->run(); } BOOST_AUTO_TEST_CASE(t5) { - int N = 40000; - gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src (gr::blocks::null_source::make(sizeof(float))); - gr::block_sptr head (gr::blocks::head::make(sizeof(float), N)); - gr::blocks::annotator_alltoall::sptr ann0(gr::blocks::annotator_alltoall::make(10000, sizeof(float))); - gr::blocks::annotator_alltoall::sptr ann1(gr::blocks::annotator_alltoall::make(10000, sizeof(float))); - gr::blocks::annotator_alltoall::sptr ann2(gr::blocks::annotator_alltoall::make(1000, sizeof(float))); - gr::block_sptr snk0 (gr::blocks::null_sink::make(sizeof(float))); - - // Rate change blocks - gr::blocks::keep_one_in_n::sptr dec10(gr::blocks::keep_one_in_n::make(sizeof(float), 10)); - - tb->connect(src, 0, head, 0); - tb->connect(head, 0, ann0, 0); - tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, dec10, 0); - tb->connect(dec10, 0, ann2, 0); - tb->connect(ann2, 0, snk0, 0); - - tb->run(); - - std::vector<gr::tag_t> tags0 = ann0->data(); - std::vector<gr::tag_t> tags1 = ann1->data(); - std::vector<gr::tag_t> tags2 = ann2->data(); - - // The first annotator does not receive any tags from the null sink upstream - BOOST_REQUIRE_EQUAL(tags0.size(), (size_t)0); - BOOST_REQUIRE_EQUAL(tags1.size(), (size_t)4); - BOOST_REQUIRE_EQUAL(tags2.size(), (size_t)8); + int N = 40000; + gr::top_block_sptr tb = gr::make_top_block("top"); + gr::block_sptr src(gr::blocks::null_source::make(sizeof(float))); + gr::block_sptr head(gr::blocks::head::make(sizeof(float), N)); + gr::blocks::annotator_alltoall::sptr ann0( + gr::blocks::annotator_alltoall::make(10000, sizeof(float))); + gr::blocks::annotator_alltoall::sptr ann1( + gr::blocks::annotator_alltoall::make(10000, sizeof(float))); + gr::blocks::annotator_alltoall::sptr ann2( + gr::blocks::annotator_alltoall::make(1000, sizeof(float))); + gr::block_sptr snk0(gr::blocks::null_sink::make(sizeof(float))); + + // Rate change blocks + gr::blocks::keep_one_in_n::sptr dec10( + gr::blocks::keep_one_in_n::make(sizeof(float), 10)); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann1, 0, dec10, 0); + tb->connect(dec10, 0, ann2, 0); + tb->connect(ann2, 0, snk0, 0); + + tb->run(); + + std::vector<gr::tag_t> tags0 = ann0->data(); + std::vector<gr::tag_t> tags1 = ann1->data(); + std::vector<gr::tag_t> tags2 = ann2->data(); + + // The first annotator does not receive any tags from the null sink upstream + BOOST_REQUIRE_EQUAL(tags0.size(), (size_t)0); + BOOST_REQUIRE_EQUAL(tags1.size(), (size_t)4); + BOOST_REQUIRE_EQUAL(tags2.size(), (size_t)8); #if QA_TAGS_DEBUG - // Kludge together the tags that we know should result from the above graph - std::stringstream str0, str1, str2; - str0 << ann0->name() << ann0->unique_id(); - str1 << ann1->name() << ann1->unique_id(); - str2 << ann2->name() << ann2->unique_id(); - - gr::tag_t expected_tags1[5]; - expected_tags1[0] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags1[1] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags1[2] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags1[3] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); - - gr::tag_t expected_tags2[10]; - expected_tags2[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags2[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); - expected_tags2[2] = make_tag(1000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags2[3] = make_tag(1000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); - expected_tags2[4] = make_tag(2000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags2[5] = make_tag(2000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); - expected_tags2[6] = make_tag(3000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags2[7] = make_tag(3000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); - expected_tags2[8] = make_tag(4000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(4)); - expected_tags2[9] = make_tag(4000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); - - std::cout << std::endl << "qa_block_tags::t5" << std::endl; - - // annotator 1 gets tags from annotator 0 - std::cout << "tags1.size(): " << tags1.size() << std::endl; - for(size_t i = 0; i < tags1.size(); i++) { - std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] << std::endl; - BOOST_REQUIRE_EQUAL(tags1[i], expected_tags1[i]); - } - - // annotator 2 gets tags from annotators 0 and 1 - std::cout << std::endl; - std::cout << "tags2.size(): " << tags2.size() << std::endl; - for(size_t i = 0; i < tags2.size(); i++) { - std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; - BOOST_REQUIRE_EQUAL(tags2[i], expected_tags2[i]); - } + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + gr::tag_t expected_tags1[5]; + expected_tags1[0] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags1[1] = make_tag(10000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags1[2] = make_tag(20000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags1[3] = make_tag(30000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); + + gr::tag_t expected_tags2[10]; + expected_tags2[0] = make_tag(0, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags2[1] = make_tag(0, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(0)); + expected_tags2[2] = make_tag(1000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags2[3] = make_tag(1000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(1)); + expected_tags2[4] = make_tag(2000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags2[5] = make_tag(2000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(2)); + expected_tags2[6] = make_tag(3000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags2[7] = make_tag(3000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(3)); + expected_tags2[8] = make_tag(4000, pmt::mp(str1.str()), pmt::mp("seq"), pmt::mp(4)); + expected_tags2[9] = make_tag(4000, pmt::mp(str0.str()), pmt::mp("seq"), pmt::mp(4)); + + std::cout << std::endl << "qa_block_tags::t5" << std::endl; + + // annotator 1 gets tags from annotator 0 + std::cout << "tags1.size(): " << tags1.size() << std::endl; + for (size_t i = 0; i < tags1.size(); i++) { + std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] + << std::endl; + BOOST_REQUIRE_EQUAL(tags1[i], expected_tags1[i]); + } + + // annotator 2 gets tags from annotators 0 and 1 + std::cout << std::endl; + std::cout << "tags2.size(): " << tags2.size() << std::endl; + for (size_t i = 0; i < tags2.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] + << std::endl; + BOOST_REQUIRE_EQUAL(tags2[i], expected_tags2[i]); + } #endif } - diff --git a/gr-blocks/lib/qa_gr_block.cc b/gr-blocks/lib/qa_gr_block.cc index 46079165b0..b40a63cd2a 100644 --- a/gr-blocks/lib/qa_gr_block.cc +++ b/gr-blocks/lib/qa_gr_block.cc @@ -31,44 +31,43 @@ BOOST_AUTO_TEST_CASE(t0) { - // test creation of sources - gr::block_sptr src1(gr::blocks::null_source::make(sizeof (int))); - BOOST_REQUIRE_EQUAL(std::string("null_source"), src1->name ()); - BOOST_REQUIRE_EQUAL(0, src1->input_signature()->max_streams ()); - BOOST_REQUIRE_EQUAL(1, src1->output_signature()->min_streams ()); - BOOST_REQUIRE_EQUAL(-1, src1->output_signature()->max_streams ()); - BOOST_REQUIRE_EQUAL((int) sizeof(int), - src1->output_signature()->sizeof_stream_item (0)); + // test creation of sources + gr::block_sptr src1(gr::blocks::null_source::make(sizeof(int))); + BOOST_REQUIRE_EQUAL(std::string("null_source"), src1->name()); + BOOST_REQUIRE_EQUAL(0, src1->input_signature()->max_streams()); + BOOST_REQUIRE_EQUAL(1, src1->output_signature()->min_streams()); + BOOST_REQUIRE_EQUAL(-1, src1->output_signature()->max_streams()); + BOOST_REQUIRE_EQUAL((int)sizeof(int), + src1->output_signature()->sizeof_stream_item(0)); - gr::block_sptr src2(gr::blocks::null_source::make(sizeof(short))); - BOOST_REQUIRE_EQUAL(std::string ("null_source"), src2->name ()); - BOOST_REQUIRE_EQUAL(0, src2->input_signature()->max_streams ()); - BOOST_REQUIRE_EQUAL(1, src2->output_signature()->min_streams ()); - BOOST_REQUIRE_EQUAL(-1, src2->output_signature()->max_streams ()); - BOOST_REQUIRE_EQUAL((int)sizeof (short), - src2->output_signature()->sizeof_stream_item (0)); + gr::block_sptr src2(gr::blocks::null_source::make(sizeof(short))); + BOOST_REQUIRE_EQUAL(std::string("null_source"), src2->name()); + BOOST_REQUIRE_EQUAL(0, src2->input_signature()->max_streams()); + BOOST_REQUIRE_EQUAL(1, src2->output_signature()->min_streams()); + BOOST_REQUIRE_EQUAL(-1, src2->output_signature()->max_streams()); + BOOST_REQUIRE_EQUAL((int)sizeof(short), + src2->output_signature()->sizeof_stream_item(0)); } BOOST_AUTO_TEST_CASE(t1) { - // test creation of sinks - gr::block_sptr dst1 (gr::blocks::null_sink::make (sizeof (int))); - BOOST_REQUIRE_EQUAL (std::string ("null_sink"), dst1->name ()); - BOOST_REQUIRE_EQUAL (1, dst1->input_signature()->min_streams ()); - BOOST_REQUIRE_EQUAL (-1, dst1->input_signature()->max_streams ()); - BOOST_REQUIRE_EQUAL ((int) sizeof (int), - dst1->input_signature()->sizeof_stream_item (0)); + // test creation of sinks + gr::block_sptr dst1(gr::blocks::null_sink::make(sizeof(int))); + BOOST_REQUIRE_EQUAL(std::string("null_sink"), dst1->name()); + BOOST_REQUIRE_EQUAL(1, dst1->input_signature()->min_streams()); + BOOST_REQUIRE_EQUAL(-1, dst1->input_signature()->max_streams()); + BOOST_REQUIRE_EQUAL((int)sizeof(int), dst1->input_signature()->sizeof_stream_item(0)); - BOOST_REQUIRE_EQUAL (0, dst1->output_signature()->max_streams ()); + BOOST_REQUIRE_EQUAL(0, dst1->output_signature()->max_streams()); - gr::block_sptr dst2 (gr::blocks::null_sink::make (sizeof (short))); - BOOST_REQUIRE_EQUAL (std::string ("null_sink"), dst2->name ()); - BOOST_REQUIRE_EQUAL (1, dst2->input_signature()->min_streams ()); - BOOST_REQUIRE_EQUAL (-1, dst2->input_signature()->max_streams ()); - BOOST_REQUIRE_EQUAL ((int) sizeof (short), - dst2->input_signature()->sizeof_stream_item (0)); - BOOST_REQUIRE_EQUAL (0, dst2->output_signature()->max_streams ()); + gr::block_sptr dst2(gr::blocks::null_sink::make(sizeof(short))); + BOOST_REQUIRE_EQUAL(std::string("null_sink"), dst2->name()); + BOOST_REQUIRE_EQUAL(1, dst2->input_signature()->min_streams()); + BOOST_REQUIRE_EQUAL(-1, dst2->input_signature()->max_streams()); + BOOST_REQUIRE_EQUAL((int)sizeof(short), + dst2->input_signature()->sizeof_stream_item(0)); + BOOST_REQUIRE_EQUAL(0, dst2->output_signature()->max_streams()); } #include <gnuradio/top_block.h> @@ -78,26 +77,25 @@ BOOST_AUTO_TEST_CASE(t1) BOOST_AUTO_TEST_CASE(t2) { - gr::block_sptr src1(gr::blocks::null_source::make(sizeof (int))); - gr::block_sptr nop(gr::blocks::nop::make(sizeof (int))); - gr::block_sptr dst1 (gr::blocks::null_sink::make (sizeof (int))); + gr::block_sptr src1(gr::blocks::null_source::make(sizeof(int))); + gr::block_sptr nop(gr::blocks::nop::make(sizeof(int))); + gr::block_sptr dst1(gr::blocks::null_sink::make(sizeof(int))); - gr::top_block_sptr tb(gr::make_top_block("t2")); - tb->connect(src1, 0, nop, 0); - tb->connect(nop, 0, dst1, 0); - tb->start(); + gr::top_block_sptr tb(gr::make_top_block("t2")); + tb->connect(src1, 0, nop, 0); + tb->connect(nop, 0, dst1, 0); + tb->start(); - const char *obuf = nop->detail()->output(0)->base(); - int obsize = nop->detail()->output(0)->bufsize(); - const char *ibuf = nop->detail()->input(0)->buffer()->base(); - int ibsize = nop->detail()->input(0)->buffer()->bufsize(); + const char* obuf = nop->detail()->output(0)->base(); + int obsize = nop->detail()->output(0)->bufsize(); + const char* ibuf = nop->detail()->input(0)->buffer()->base(); + int ibsize = nop->detail()->input(0)->buffer()->bufsize(); - BOOST_REQUIRE(obuf != NULL); - BOOST_REQUIRE(ibuf != NULL); - BOOST_REQUIRE(obsize > 0); - BOOST_REQUIRE(ibsize > 0); + BOOST_REQUIRE(obuf != NULL); + BOOST_REQUIRE(ibuf != NULL); + BOOST_REQUIRE(obsize > 0); + BOOST_REQUIRE(ibsize > 0); - tb->stop(); - tb->wait(); + tb->stop(); + tb->wait(); } - diff --git a/gr-blocks/lib/qa_gr_flowgraph.cc b/gr-blocks/lib/qa_gr_flowgraph.cc index 2626b9bbda..524c43755e 100644 --- a/gr-blocks/lib/qa_gr_flowgraph.cc +++ b/gr-blocks/lib/qa_gr_flowgraph.cc @@ -31,263 +31,280 @@ #include <boost/test/unit_test.hpp> namespace gr { - namespace blocks { - class null_qa_source : virtual public sync_block { - public: - typedef boost::shared_ptr<null_qa_source> sptr; - static sptr make(size_t sizeof_stream_item); - }; - class null_source_qa_impl : public null_qa_source +namespace blocks { +class null_qa_source : virtual public sync_block +{ +public: + typedef boost::shared_ptr<null_qa_source> sptr; + static sptr make(size_t sizeof_stream_item); +}; +class null_source_qa_impl : public null_qa_source +{ +public: + null_source_qa_impl(size_t sizeof_stream_item) + : sync_block("null_source", + io_signature::make(0, 0, 0), + io_signature::make(1, 1, sizeof_stream_item)) + { + } + ~null_source_qa_impl() {} + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) { - public: - null_source_qa_impl(size_t sizeof_stream_item) - : sync_block("null_source", io_signature::make(0, 0, 0), io_signature::make(1, 1, sizeof_stream_item)) {} - ~null_source_qa_impl(){} - - int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - void *optr; - for(size_t n = 0; n < input_items.size(); n++) { - optr = (void*)output_items[n]; - memset(optr, 0, noutput_items * output_signature()->sizeof_stream_item(n)); + void* optr; + for (size_t n = 0; n < input_items.size(); n++) { + optr = (void*)output_items[n]; + memset(optr, 0, noutput_items * output_signature()->sizeof_stream_item(n)); } return noutput_items; - } - }; - null_qa_source::sptr null_qa_source::make(size_t sizeof_stream_item) + } +}; +null_qa_source::sptr null_qa_source::make(size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr(new null_source_qa_impl(sizeof_stream_item)); +} +class null_qa_sink : virtual public sync_block +{ +public: + typedef boost::shared_ptr<null_qa_sink> sptr; + static sptr make(size_t sizeof_stream_item); +}; +class null_sink_qa_impl : public null_qa_sink +{ +public: + null_sink_qa_impl(size_t sizeof_stream_item) + : sync_block("null_qa_sink", + io_signature::make(1, 1, sizeof_stream_item), + io_signature::make(0, 0, 0)) { - return gnuradio::get_initial_sptr(new null_source_qa_impl(sizeof_stream_item)); } - class null_qa_sink : virtual public sync_block + ~null_sink_qa_impl() {} + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) { - public: - typedef boost::shared_ptr<null_qa_sink> sptr; - static sptr make(size_t sizeof_stream_item); - }; - class null_sink_qa_impl : public null_qa_sink { - public: - null_sink_qa_impl(size_t sizeof_stream_item) - : sync_block("null_qa_sink", io_signature::make(1, 1, sizeof_stream_item), io_signature::make(0, 0, 0)) {} - ~null_sink_qa_impl() {} - int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { return noutput_items; - } - }; - null_qa_sink::sptr null_qa_sink::make(size_t sizeof_stream_item) { - return gnuradio::get_initial_sptr(new null_sink_qa_impl(sizeof_stream_item)); } - } /* namespace blocks */ +}; +null_qa_sink::sptr null_qa_sink::make(size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr(new null_sink_qa_impl(sizeof_stream_item)); +} +} /* namespace blocks */ } /* namespace gr */ BOOST_AUTO_TEST_CASE(t0) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - BOOST_REQUIRE(fg); + BOOST_REQUIRE(fg); } BOOST_AUTO_TEST_CASE(t1_connect) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - fg->connect(nop1, 0, nop2, 0); + fg->connect(nop1, 0, nop2, 0); } BOOST_AUTO_TEST_CASE(t2_connect_invalid_src_port_neg) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - BOOST_REQUIRE_THROW(fg->connect(nop1, -1, nop2, 0), std::invalid_argument); + BOOST_REQUIRE_THROW(fg->connect(nop1, -1, nop2, 0), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t3_connect_src_port_exceeds) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr src = gr::blocks::null_qa_source::make(sizeof(int)); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_qa_source::make(sizeof(int)); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - BOOST_REQUIRE_THROW(fg->connect(src, 1, dst, 0), std::invalid_argument); + BOOST_REQUIRE_THROW(fg->connect(src, 1, dst, 0), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t4_connect_invalid_dst_port_neg) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - BOOST_REQUIRE_THROW(fg->connect(nop1, 0, nop2, -1), std::invalid_argument); + BOOST_REQUIRE_THROW(fg->connect(nop1, 0, nop2, -1), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t5_connect_dst_port_exceeds) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr dst = gr::blocks::null_qa_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr dst = gr::blocks::null_qa_sink::make(sizeof(int)); - BOOST_REQUIRE_THROW(fg->connect(src, 0, dst, 1), std::invalid_argument); + BOOST_REQUIRE_THROW(fg->connect(src, 0, dst, 1), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t6_connect_dst_in_use) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr src1 = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr src2 = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src1 = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr src2 = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - fg->connect(src1, 0, dst, 0); - BOOST_REQUIRE_THROW(fg->connect(src2, 0, dst, 0), std::invalid_argument); + fg->connect(src1, 0, dst, 0); + BOOST_REQUIRE_THROW(fg->connect(src2, 0, dst, 0), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t7_connect_one_src_two_dst) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr dst1 = gr::blocks::null_sink::make(sizeof(int)); - gr::block_sptr dst2 = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr dst1 = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr dst2 = gr::blocks::null_sink::make(sizeof(int)); - fg->connect(src, 0, dst1, 0); - fg->connect(src, 0, dst2, 0); + fg->connect(src, 0, dst1, 0); + fg->connect(src, 0, dst2, 0); } BOOST_AUTO_TEST_CASE(t8_connect_type_mismatch) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(char)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(char)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - BOOST_REQUIRE_THROW(fg->connect(nop1, 0, nop2, 0), std::invalid_argument); + BOOST_REQUIRE_THROW(fg->connect(nop1, 0, nop2, 0), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t9_disconnect) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - fg->connect(nop1, 0, nop2, 0); - fg->disconnect(nop1, 0, nop2, 0); + fg->connect(nop1, 0, nop2, 0); + fg->disconnect(nop1, 0, nop2, 0); } BOOST_AUTO_TEST_CASE(t10_disconnect_unconnected_block) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop3 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop3 = gr::blocks::nop::make(sizeof(int)); - fg->connect(nop1, 0, nop2, 0); - BOOST_REQUIRE_THROW(fg->disconnect(nop1, 0, nop3, 0), std::invalid_argument); + fg->connect(nop1, 0, nop2, 0); + BOOST_REQUIRE_THROW(fg->disconnect(nop1, 0, nop3, 0), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t11_disconnect_unconnected_port) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - fg->connect(nop1, 0, nop2, 0); - BOOST_REQUIRE_THROW(fg->disconnect(nop1, 0, nop2, 1), std::invalid_argument); + fg->connect(nop1, 0, nop2, 0); + BOOST_REQUIRE_THROW(fg->disconnect(nop1, 0, nop2, 1), std::invalid_argument); } BOOST_AUTO_TEST_CASE(t12_validate) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - fg->connect(nop1, 0, nop2, 0); - fg->validate(); + fg->connect(nop1, 0, nop2, 0); + fg->validate(); } BOOST_AUTO_TEST_CASE(t13_validate_missing_input_assignment) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - fg->connect(nop1, 0, nop2, 0); - fg->connect(nop1, 0, nop2, 2); - BOOST_REQUIRE_THROW(fg->validate(), std::runtime_error); + fg->connect(nop1, 0, nop2, 0); + fg->connect(nop1, 0, nop2, 2); + BOOST_REQUIRE_THROW(fg->validate(), std::runtime_error); } BOOST_AUTO_TEST_CASE(t14_validate_missing_output_assignment) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - fg->connect(nop1, 0, nop2, 0); - fg->connect(nop1, 2, nop2, 1); - BOOST_REQUIRE_THROW(fg->validate(), std::runtime_error); + fg->connect(nop1, 0, nop2, 0); + fg->connect(nop1, 2, nop2, 1); + BOOST_REQUIRE_THROW(fg->validate(), std::runtime_error); } BOOST_AUTO_TEST_CASE(t15_clear) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop1 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop2 = gr::blocks::nop::make(sizeof(int)); - fg->connect(nop1, 0, nop2, 0); + fg->connect(nop1, 0, nop2, 0); - BOOST_REQUIRE(fg->edges().size() == 1); - BOOST_REQUIRE(fg->calc_used_blocks().size() == 2); + BOOST_REQUIRE(fg->edges().size() == 1); + BOOST_REQUIRE(fg->calc_used_blocks().size() == 2); - fg->clear(); + fg->clear(); - BOOST_REQUIRE(fg->edges().size() == 0); - BOOST_REQUIRE(fg->calc_used_blocks().size() == 0); + BOOST_REQUIRE(fg->edges().size() == 0); + BOOST_REQUIRE(fg->calc_used_blocks().size() == 0); } BOOST_AUTO_TEST_CASE(t16_partition) { - gr::flowgraph_sptr fg = gr::make_flowgraph(); + gr::flowgraph_sptr fg = gr::make_flowgraph(); - gr::block_sptr nop11 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop12 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop13 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop14 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop11 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop12 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop13 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop14 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop21 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop22 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop23 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop21 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop22 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop23 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop31 = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr nop32 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop31 = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr nop32 = gr::blocks::nop::make(sizeof(int)); - // Build disjoint graph #1 - fg->connect(nop11, 0, nop12, 0); - fg->connect(nop12, 0, nop13, 0); - fg->connect(nop13, 0, nop14, 0); + // Build disjoint graph #1 + fg->connect(nop11, 0, nop12, 0); + fg->connect(nop12, 0, nop13, 0); + fg->connect(nop13, 0, nop14, 0); - // Build disjoint graph #2 - fg->connect(nop21, 0, nop22, 0); - fg->connect(nop22, 0, nop23, 0); + // Build disjoint graph #2 + fg->connect(nop21, 0, nop22, 0); + fg->connect(nop22, 0, nop23, 0); - // Build disjoint graph #3 - fg->connect(nop31, 0, nop32, 0); + // Build disjoint graph #3 + fg->connect(nop31, 0, nop32, 0); - std::vector<gr::basic_block_vector_t> graphs = fg->partition(); + std::vector<gr::basic_block_vector_t> graphs = fg->partition(); - BOOST_REQUIRE(graphs.size() == 3); - BOOST_REQUIRE(graphs[0].size() == 4); - BOOST_REQUIRE(graphs[1].size() == 3); - BOOST_REQUIRE(graphs[2].size() == 2); + BOOST_REQUIRE(graphs.size() == 3); + BOOST_REQUIRE(graphs[0].size() == 4); + BOOST_REQUIRE(graphs[1].size() == 3); + BOOST_REQUIRE(graphs[2].size() == 2); } diff --git a/gr-blocks/lib/qa_gr_hier_block2.cc b/gr-blocks/lib/qa_gr_hier_block2.cc index fcc9e6fdc9..6a95c2c1bd 100644 --- a/gr-blocks/lib/qa_gr_hier_block2.cc +++ b/gr-blocks/lib/qa_gr_hier_block2.cc @@ -30,24 +30,24 @@ BOOST_AUTO_TEST_CASE(test_make) { - gr::hier_block2_sptr src1(gr::make_hier_block2("test", - gr::io_signature::make(1, 1, 1 * sizeof(int)), - gr::io_signature::make(1, 1, 1 * sizeof(int)))); + gr::hier_block2_sptr src1( + gr::make_hier_block2("test", + gr::io_signature::make(1, 1, 1 * sizeof(int)), + gr::io_signature::make(1, 1, 1 * sizeof(int)))); BOOST_REQUIRE(src1); BOOST_REQUIRE_EQUAL(std::string("test"), src1->name()); - BOOST_REQUIRE_EQUAL(1 * (int) sizeof(int), - src1->input_signature()->sizeof_stream_item(0)); + BOOST_REQUIRE_EQUAL(1 * (int)sizeof(int), + src1->input_signature()->sizeof_stream_item(0)); BOOST_REQUIRE_EQUAL(1, src1->input_signature()->min_streams()); BOOST_REQUIRE_EQUAL(1, src1->input_signature()->max_streams()); - BOOST_REQUIRE_EQUAL(1 * (int) sizeof(int), - src1->output_signature()->sizeof_stream_item(0)); + BOOST_REQUIRE_EQUAL(1 * (int)sizeof(int), + src1->output_signature()->sizeof_stream_item(0)); BOOST_REQUIRE_EQUAL(1, src1->output_signature()->min_streams()); BOOST_REQUIRE_EQUAL(1, src1->output_signature()->max_streams()); } - diff --git a/gr-blocks/lib/qa_gr_hier_block2_derived.cc b/gr-blocks/lib/qa_gr_hier_block2_derived.cc index 519a23d97e..9b22568a4c 100644 --- a/gr-blocks/lib/qa_gr_hier_block2_derived.cc +++ b/gr-blocks/lib/qa_gr_hier_block2_derived.cc @@ -41,47 +41,44 @@ gr_derived_block_sptr gr_make_derived_block(); class gr_derived_block : public gr::hier_block2 { private: - friend gr_derived_block_sptr gr_make_derived_block(); - gr_derived_block(); + friend gr_derived_block_sptr gr_make_derived_block(); + gr_derived_block(); public: - ~gr_derived_block(); + ~gr_derived_block(); }; -gr_derived_block_sptr -gr_make_derived_block() +gr_derived_block_sptr gr_make_derived_block() { - return gnuradio::get_initial_sptr(new gr_derived_block()); + return gnuradio::get_initial_sptr(new gr_derived_block()); } gr_derived_block::gr_derived_block() - : gr::hier_block2("gr_derived_block", - gr::io_signature::make(1, 1, sizeof(int)), // Input signature - gr::io_signature::make(1, 1, sizeof(int))) // Output signature + : gr::hier_block2("gr_derived_block", + gr::io_signature::make(1, 1, sizeof(int)), // Input signature + gr::io_signature::make(1, 1, sizeof(int))) // Output signature { - gr::block_sptr copy(gr::blocks::copy::make(sizeof(int))); + gr::block_sptr copy(gr::blocks::copy::make(sizeof(int))); - connect(self(), 0, copy, 0); - connect(copy, 0, self(), 0); + connect(self(), 0, copy, 0); + connect(copy, 0, self(), 0); } -gr_derived_block::~gr_derived_block() -{ -} +gr_derived_block::~gr_derived_block() {} BOOST_AUTO_TEST_CASE(test_1) { - gr::top_block_sptr tb(gr::make_top_block("test")); + gr::top_block_sptr tb(gr::make_top_block("test")); - gr::block_sptr src(gr::blocks::null_source::make(sizeof(int))); - gr::block_sptr head(gr::blocks::head::make(sizeof(int), 1000)); - gr_derived_block_sptr blk(gr_make_derived_block()); - gr::block_sptr dst(gr::blocks::null_sink::make(sizeof(int))); + gr::block_sptr src(gr::blocks::null_source::make(sizeof(int))); + gr::block_sptr head(gr::blocks::head::make(sizeof(int), 1000)); + gr_derived_block_sptr blk(gr_make_derived_block()); + gr::block_sptr dst(gr::blocks::null_sink::make(sizeof(int))); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, blk, 0); - tb->connect(blk, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, blk, 0); + tb->connect(blk, 0, dst, 0); - tb->run(); + tb->run(); } diff --git a/gr-blocks/lib/qa_gr_top_block.cc b/gr-blocks/lib/qa_gr_top_block.cc index 7c456e312a..04e4379e97 100644 --- a/gr-blocks/lib/qa_gr_top_block.cc +++ b/gr-blocks/lib/qa_gr_top_block.cc @@ -36,259 +36,261 @@ BOOST_AUTO_TEST_CASE(t0) { - if (VERBOSE) std::cout << "qa_top_block::t0()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t0()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - BOOST_REQUIRE(tb); + BOOST_REQUIRE(tb); } BOOST_AUTO_TEST_CASE(t1_run) { - if (VERBOSE) std::cout << "qa_top_block::t1()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t1()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); - tb->run(); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->run(); } BOOST_AUTO_TEST_CASE(t2_start_stop_wait) { - if(VERBOSE) - std::cout << "qa_top_block::t2()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t2()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); - tb->start(); - tb->stop(); - tb->wait(); + tb->start(); + tb->stop(); + tb->wait(); } BOOST_AUTO_TEST_CASE(t3_lock_unlock) { - if(VERBOSE) - std::cout << "qa_top_block::t3()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t3()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - tb->connect(src, 0, dst, 0); + tb->connect(src, 0, dst, 0); - tb->start(); + tb->start(); - tb->lock(); - tb->unlock(); + tb->lock(); + tb->unlock(); - tb->stop(); - tb->wait(); + tb->stop(); + tb->wait(); } BOOST_AUTO_TEST_CASE(t4_reconfigure) { - if(VERBOSE) - std::cout << "qa_top_block::t4()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t4()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - // Start infinite flowgraph - tb->connect(src, 0, dst, 0); - tb->start(); + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(); - // Reconfigure with gr_head in the middle - tb->lock(); - tb->disconnect(src, 0, dst, 0); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); - tb->unlock(); + // Reconfigure with gr_head in the middle + tb->lock(); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->unlock(); - // Wait for flowgraph to end on its own - tb->wait(); + // Wait for flowgraph to end on its own + tb->wait(); } BOOST_AUTO_TEST_CASE(t5_max_noutputs) { - if(VERBOSE) - std::cout << "qa_top_block::t5()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t5()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - // Start infinite flowgraph - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); - tb->start(100); - tb->wait(); + // Start infinite flowgraph + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->start(100); + tb->wait(); } BOOST_AUTO_TEST_CASE(t6_reconfig_max_noutputs) { - if(VERBOSE) - std::cout << "qa_top_block::t6()\n"; - - gr::top_block_sptr tb = gr::make_top_block("top"); - - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - - // Start infinite flowgraph - tb->connect(src, 0, dst, 0); - tb->start(100); - - // Reconfigure with gr_head in the middle - tb->lock(); - tb->disconnect(src, 0, dst, 0); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); - tb->set_max_noutput_items(1000); - head->set_max_noutput_items(500); - tb->unlock(); - - // Wait for flowgraph to end on its own - tb->wait(); + if (VERBOSE) + std::cout << "qa_top_block::t6()\n"; + + gr::top_block_sptr tb = gr::make_top_block("top"); + + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(100); + + // Reconfigure with gr_head in the middle + tb->lock(); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->set_max_noutput_items(1000); + head->set_max_noutput_items(500); + tb->unlock(); + + // Wait for flowgraph to end on its own + tb->wait(); } BOOST_AUTO_TEST_CASE(t7_max_noutputs_per_block) { - if(VERBOSE) - std::cout << "qa_top_block::t7()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t7()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - head->set_max_noutput_items(100); + head->set_max_noutput_items(100); - // Start infinite flowgraph - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); - tb->start(); - tb->wait(); + // Start infinite flowgraph + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->start(); + tb->wait(); } BOOST_AUTO_TEST_CASE(t8_reconfig_max_noutputs_per_block) { - if(VERBOSE) - std::cout << "qa_top_block::t8()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t8()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - head->set_max_noutput_items(99); + head->set_max_noutput_items(99); - // Start infinite flowgraph - tb->connect(src, 0, dst, 0); - tb->start(201); + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(201); - // Reconfigure with gr_head in the middle - tb->lock(); - tb->disconnect(src, 0, dst, 0); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); - tb->set_max_noutput_items(1023); - head->set_max_noutput_items(513); - tb->unlock(); + // Reconfigure with gr_head in the middle + tb->lock(); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->set_max_noutput_items(1023); + head->set_max_noutput_items(513); + tb->unlock(); - // Wait for flowgraph to end on its own - tb->wait(); + // Wait for flowgraph to end on its own + tb->wait(); } BOOST_AUTO_TEST_CASE(t9_max_output_buffer) { - if(VERBOSE) - std::cout << "qa_top_block::t9()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t9()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - head->set_max_output_buffer(1024); + head->set_max_output_buffer(1024); - // Start infinite flowgraph - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); - tb->start(); - tb->wait(); + // Start infinite flowgraph + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->start(); + tb->wait(); } BOOST_AUTO_TEST_CASE(t10_reconfig_max_output_buffer) { - if(VERBOSE) - std::cout << "qa_top_block::t10()\n"; + if (VERBOSE) + std::cout << "qa_top_block::t10()\n"; - gr::top_block_sptr tb = gr::make_top_block("top"); + gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::block_sptr head = gr::blocks::head::make(sizeof(int), 100000); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - head->set_max_output_buffer(1000); + head->set_max_output_buffer(1000); - // Start infinite flowgraph - tb->connect(src, 0, dst, 0); - tb->start(201); + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(201); - // Reconfigure with gr_head in the middle - tb->lock(); - gr::block_sptr nop = gr::blocks::nop::make(sizeof(int)); - nop->set_max_output_buffer(4000); - tb->disconnect(src, 0, dst, 0); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, nop, 0); - tb->connect(nop, 0, dst, 0); - tb->unlock(); + // Reconfigure with gr_head in the middle + tb->lock(); + gr::block_sptr nop = gr::blocks::nop::make(sizeof(int)); + nop->set_max_output_buffer(4000); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, nop, 0); + tb->connect(nop, 0, dst, 0); + tb->unlock(); - // Wait for flowgraph to end on its own - tb->wait(); + // Wait for flowgraph to end on its own + tb->wait(); } BOOST_AUTO_TEST_CASE(t11_set_block_affinity) { - gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src (gr::blocks::null_source::make(sizeof(float))); - gr::block_sptr snk (gr::blocks::null_sink::make(sizeof(float))); + gr::top_block_sptr tb = gr::make_top_block("top"); + gr::block_sptr src(gr::blocks::null_source::make(sizeof(float))); + gr::block_sptr snk(gr::blocks::null_sink::make(sizeof(float))); - std::vector<int> set(1, 0), ret; - src->set_processor_affinity(set); + std::vector<int> set(1, 0), ret; + src->set_processor_affinity(set); - tb->connect(src, 0, snk, 0); - tb->start(); - tb->stop(); - tb->wait(); + tb->connect(src, 0, snk, 0); + tb->start(); + tb->stop(); + tb->wait(); - ret = src->processor_affinity(); + ret = src->processor_affinity(); - // We only set the core affinity to 0 because we always know at - // least one thread core exists to use. - BOOST_CHECK_EQUAL(set[0], ret[0]); + // We only set the core affinity to 0 because we always know at + // least one thread core exists to use. + BOOST_CHECK_EQUAL(set[0], ret[0]); } diff --git a/gr-blocks/lib/qa_rotator.cc b/gr-blocks/lib/qa_rotator.cc index a39a2bd0fa..7a1426b4b9 100644 --- a/gr-blocks/lib/qa_rotator.cc +++ b/gr-blocks/lib/qa_rotator.cc @@ -33,73 +33,72 @@ #include <cmath> // error vector magnitude -__GR_ATTR_UNUSED static float -error_vector_mag(gr_complex a, gr_complex b) +__GR_ATTR_UNUSED static float error_vector_mag(gr_complex a, gr_complex b) { - return abs(a-b); + return abs(a - b); } BOOST_AUTO_TEST_CASE(t1) { - static const unsigned int N = 100000; + static const unsigned int N = 100000; - gr::blocks::rotator r; + gr::blocks::rotator r; - double phase_incr = 2*GR_M_PI / 1003; - double phase = 0; + double phase_incr = 2 * GR_M_PI / 1003; + double phase = 0; - // Old code: We increment then return the rotated value, thus we - // need to start one tick back r.set_phase(gr_complex(1,0) * - // conj(gr_expj(phase_incr))); + // Old code: We increment then return the rotated value, thus we + // need to start one tick back r.set_phase(gr_complex(1,0) * + // conj(gr_expj(phase_incr))); - r.set_phase(gr_complex(1,0)); - r.set_phase_incr(gr_expj(phase_incr)); + r.set_phase(gr_complex(1, 0)); + r.set_phase_incr(gr_expj(phase_incr)); - for(unsigned i = 0; i < N; i++) { - gr_complex expected = gr_expj(phase); - gr_complex actual = r.rotate(gr_complex(1, 0)); + for (unsigned i = 0; i < N; i++) { + gr_complex expected = gr_expj(phase); + gr_complex actual = r.rotate(gr_complex(1, 0)); - BOOST_CHECK(std::abs(expected - actual) <= 0.0001); + BOOST_CHECK(std::abs(expected - actual) <= 0.0001); - phase += phase_incr; - if(phase >= 2*GR_M_PI) - phase -= 2*GR_M_PI; - } + phase += phase_incr; + if (phase >= 2 * GR_M_PI) + phase -= 2 * GR_M_PI; + } } BOOST_AUTO_TEST_CASE(t2) { - static const unsigned int N = 100000; + static const unsigned int N = 100000; - gr::blocks::rotator r; - gr_complex *input = new gr_complex[N]; - gr_complex *output = new gr_complex[N]; + gr::blocks::rotator r; + gr_complex* input = new gr_complex[N]; + gr_complex* output = new gr_complex[N]; - double phase_incr = 2*GR_M_PI / 1003; - double phase = 0; + double phase_incr = 2 * GR_M_PI / 1003; + double phase = 0; - r.set_phase(gr_complex(1,0)); - r.set_phase_incr(gr_expj(phase_incr)); + r.set_phase(gr_complex(1, 0)); + r.set_phase_incr(gr_expj(phase_incr)); - // Generate a unity sequence - for(unsigned i = 0; i < N; i++) - input[i] = gr_complex(1.0f, 0.0f); + // Generate a unity sequence + for (unsigned i = 0; i < N; i++) + input[i] = gr_complex(1.0f, 0.0f); - // Rotate it - r.rotateN(output, input, N); + // Rotate it + r.rotateN(output, input, N); - // Compare with expected result - for(unsigned i = 0; i < N; i++) { - gr_complex expected = gr_expj(phase); - gr_complex actual = output[i]; + // Compare with expected result + for (unsigned i = 0; i < N; i++) { + gr_complex expected = gr_expj(phase); + gr_complex actual = output[i]; - BOOST_CHECK(std::abs(expected - actual) <= 0.0001); + BOOST_CHECK(std::abs(expected - actual) <= 0.0001); - phase += phase_incr; - if(phase >= 2*GR_M_PI) - phase -= 2*GR_M_PI; - } + phase += phase_incr; + if (phase >= 2 * GR_M_PI) + phase -= 2 * GR_M_PI; + } - delete[] output; - delete[] input; + delete[] output; + delete[] input; } diff --git a/gr-blocks/lib/qa_set_msg_handler.cc b/gr-blocks/lib/qa_set_msg_handler.cc index 94bd6e4249..368643bfa7 100644 --- a/gr-blocks/lib/qa_set_msg_handler.cc +++ b/gr-blocks/lib/qa_set_msg_handler.cc @@ -41,31 +41,31 @@ */ BOOST_AUTO_TEST_CASE(t0) { - static const int NMSGS = 10; + static const int NMSGS = 10; - gr::top_block_sptr tb = gr::make_top_block("top"); - gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); - gr::blocks::nop::sptr nop = gr::blocks::nop::make(sizeof(int)); - gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); + gr::top_block_sptr tb = gr::make_top_block("top"); + gr::block_sptr src = gr::blocks::null_source::make(sizeof(int)); + gr::blocks::nop::sptr nop = gr::blocks::nop::make(sizeof(int)); + gr::block_sptr dst = gr::blocks::null_sink::make(sizeof(int)); - tb->connect(src, 0, nop, 0); - tb->connect(nop, 0, dst, 0); + tb->connect(src, 0, nop, 0); + tb->connect(nop, 0, dst, 0); - // Must start graph before sending messages - tb->start(); + // Must start graph before sending messages + tb->start(); - // Send them... - pmt::pmt_t port(pmt::intern("port")); - for (int i = 0; i < NMSGS; i++){ - send(nop, port, pmt::mp(pmt::mp("example-msg"), pmt::mp(i))); - } + // Send them... + pmt::pmt_t port(pmt::intern("port")); + for (int i = 0; i < NMSGS; i++) { + send(nop, port, pmt::mp(pmt::mp("example-msg"), pmt::mp(i))); + } - // Give the messages a chance to be processed - boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + // Give the messages a chance to be processed + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); - tb->stop(); - tb->wait(); + tb->stop(); + tb->wait(); - // Confirm that the nop block received the right number of messages. - BOOST_CHECK_EQUAL(NMSGS, nop->nmsgs_received()); + // Confirm that the nop block received the right number of messages. + BOOST_CHECK_EQUAL(NMSGS, nop->nmsgs_received()); } diff --git a/gr-blocks/lib/random_pdu_impl.cc b/gr-blocks/lib/random_pdu_impl.cc index 07e729810a..08078cc75b 100644 --- a/gr-blocks/lib/random_pdu_impl.cc +++ b/gr-blocks/lib/random_pdu_impl.cc @@ -29,59 +29,60 @@ #include <gnuradio/blocks/pdu.h> namespace gr { - namespace blocks { +namespace blocks { - random_pdu::sptr - random_pdu::make(int min_items, int max_items, unsigned char byte_mask, int length_modulo) - { - return gnuradio::get_initial_sptr(new random_pdu_impl(min_items, max_items, byte_mask, length_modulo)); - } +random_pdu::sptr +random_pdu::make(int min_items, int max_items, unsigned char byte_mask, int length_modulo) +{ + return gnuradio::get_initial_sptr( + new random_pdu_impl(min_items, max_items, byte_mask, length_modulo)); +} - random_pdu_impl::random_pdu_impl(int min_items, int max_items, unsigned char byte_mask, int length_modulo) - : block("random_pdu", - io_signature::make (0, 0, 0), - io_signature::make (0, 0, 0)), - d_urange(min_items, max_items), - d_brange(0, 255), - d_rvar(d_rng, d_urange), - d_bvar(d_rng, d_brange), - d_mask(byte_mask), - d_length_modulo(length_modulo) - { - message_port_register_out(pdu::pdu_port_id()); - message_port_register_in(pmt::mp("generate")); - set_msg_handler(pmt::mp("generate"), boost::bind(&random_pdu_impl::generate_pdu, this, _1)); - if(length_modulo < 1) +random_pdu_impl::random_pdu_impl(int min_items, + int max_items, + unsigned char byte_mask, + int length_modulo) + : block("random_pdu", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)), + d_urange(min_items, max_items), + d_brange(0, 255), + d_rvar(d_rng, d_urange), + d_bvar(d_rng, d_brange), + d_mask(byte_mask), + d_length_modulo(length_modulo) +{ + message_port_register_out(pdu::pdu_port_id()); + message_port_register_in(pmt::mp("generate")); + set_msg_handler(pmt::mp("generate"), + boost::bind(&random_pdu_impl::generate_pdu, this, _1)); + if (length_modulo < 1) throw std::runtime_error("length_module must be >= 1"); - if(max_items < length_modulo) + if (max_items < length_modulo) throw std::runtime_error("max_items must be >= to length_modulo"); - } +} - bool - random_pdu_impl::start() - { - output_random(); - return true; - } +bool random_pdu_impl::start() +{ + output_random(); + return true; +} - void - random_pdu_impl::output_random() - { - // pick a random vector length - int len = d_rvar(); - len = std::max(d_length_modulo, len - len%d_length_modulo); +void random_pdu_impl::output_random() +{ + // pick a random vector length + int len = d_rvar(); + len = std::max(d_length_modulo, len - len % d_length_modulo); - // fill it with random bytes - std::vector<unsigned char> vec(len); - for (int i=0; i<len; i++) - vec[i] = ((unsigned char) d_bvar()) & d_mask; + // fill it with random bytes + std::vector<unsigned char> vec(len); + for (int i = 0; i < len; i++) + vec[i] = ((unsigned char)d_bvar()) & d_mask; - // send the vector - pmt::pmt_t vecpmt(pmt::make_blob(&vec[0], len)); - pmt::pmt_t pdu(pmt::cons(pmt::PMT_NIL, vecpmt)); + // send the vector + pmt::pmt_t vecpmt(pmt::make_blob(&vec[0], len)); + pmt::pmt_t pdu(pmt::cons(pmt::PMT_NIL, vecpmt)); - message_port_pub(pdu::pdu_port_id(), pdu); - } + message_port_pub(pdu::pdu_port_id(), pdu); +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/random_pdu_impl.h b/gr-blocks/lib/random_pdu_impl.h index b5438cb3cd..ecb8ec770d 100644 --- a/gr-blocks/lib/random_pdu_impl.h +++ b/gr-blocks/lib/random_pdu_impl.h @@ -28,29 +28,32 @@ #include <boost/generator_iterator.hpp> namespace gr { - namespace blocks { - - class random_pdu_impl : public random_pdu - { - private: - boost::mt19937 d_rng; - boost::uniform_int<> d_urange; - boost::uniform_int<> d_brange; - boost::variate_generator< boost::mt19937, boost::uniform_int<> > d_rvar; // pdu length - boost::variate_generator< boost::mt19937, boost::uniform_int<> > d_bvar; // pdu contents - unsigned char d_mask; - int d_length_modulo; - - public: - random_pdu_impl(int min_items, int max_items, unsigned char byte_mask, int length_modulo); - - bool start(); - void output_random(); - void generate_pdu(pmt::pmt_t msg) { output_random(); } - void generate_pdu() { output_random(); } - }; - - } /* namespace blocks */ +namespace blocks { + +class random_pdu_impl : public random_pdu +{ +private: + boost::mt19937 d_rng; + boost::uniform_int<> d_urange; + boost::uniform_int<> d_brange; + boost::variate_generator<boost::mt19937, boost::uniform_int<>> d_rvar; // pdu length + boost::variate_generator<boost::mt19937, boost::uniform_int<>> d_bvar; // pdu contents + unsigned char d_mask; + int d_length_modulo; + +public: + random_pdu_impl(int min_items, + int max_items, + unsigned char byte_mask, + int length_modulo); + + bool start(); + void output_random(); + void generate_pdu(pmt::pmt_t msg) { output_random(); } + void generate_pdu() { output_random(); } +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_RANDOM_PDU_IMPL_H */ diff --git a/gr-blocks/lib/regenerate_bb_impl.cc b/gr-blocks/lib/regenerate_bb_impl.cc index 1e2427d4ad..51806471da 100644 --- a/gr-blocks/lib/regenerate_bb_impl.cc +++ b/gr-blocks/lib/regenerate_bb_impl.cc @@ -28,76 +28,68 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - regenerate_bb::sptr - regenerate_bb::make(int period, unsigned int max_regen) - { - return gnuradio::get_initial_sptr - (new regenerate_bb_impl(period, max_regen)); - } +regenerate_bb::sptr regenerate_bb::make(int period, unsigned int max_regen) +{ + return gnuradio::get_initial_sptr(new regenerate_bb_impl(period, max_regen)); +} - regenerate_bb_impl::regenerate_bb_impl(int period, unsigned int max_regen) - : sync_block("regenerate_bb", - io_signature::make(1, 1, sizeof(char)), - io_signature::make(1, 1, sizeof(char))), - d_period(period), - d_countdown(0), - d_max_regen(max_regen), - d_regen_count(max_regen) - { - } +regenerate_bb_impl::regenerate_bb_impl(int period, unsigned int max_regen) + : sync_block("regenerate_bb", + io_signature::make(1, 1, sizeof(char)), + io_signature::make(1, 1, sizeof(char))), + d_period(period), + d_countdown(0), + d_max_regen(max_regen), + d_regen_count(max_regen) +{ +} - regenerate_bb_impl::~regenerate_bb_impl() - { - } +regenerate_bb_impl::~regenerate_bb_impl() {} - void - regenerate_bb_impl::set_max_regen(unsigned int regen) - { - d_max_regen = regen; - d_countdown = 0; - d_regen_count = d_max_regen; - } +void regenerate_bb_impl::set_max_regen(unsigned int regen) +{ + d_max_regen = regen; + d_countdown = 0; + d_regen_count = d_max_regen; +} - void - regenerate_bb_impl::set_period(int period) - { - d_period = period; - d_countdown = 0; - d_regen_count = d_max_regen; - } +void regenerate_bb_impl::set_period(int period) +{ + d_period = period; + d_countdown = 0; + d_regen_count = d_max_regen; +} - int - regenerate_bb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *iptr = (const char *)input_items[0]; - char *optr = (char *)output_items[0]; +int regenerate_bb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* iptr = (const char*)input_items[0]; + char* optr = (char*)output_items[0]; - for(int i = 0; i < noutput_items; i++) { + for (int i = 0; i < noutput_items; i++) { optr[i] = 0; - if(d_regen_count < d_max_regen) { - d_countdown--; + if (d_regen_count < d_max_regen) { + d_countdown--; - if(d_countdown == 0) { - optr[i] = 1; - d_countdown = d_period; - d_regen_count++; - } + if (d_countdown == 0) { + optr[i] = 1; + d_countdown = d_period; + d_regen_count++; + } } - if(iptr[i] == 1) { - d_countdown = d_period; - optr[i] = 1; - d_regen_count = 0; + if (iptr[i] == 1) { + d_countdown = d_period; + optr[i] = 1; + d_regen_count = 0; } - - } - return noutput_items; } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/regenerate_bb_impl.h b/gr-blocks/lib/regenerate_bb_impl.h index 5cb7f573e7..84b8b78f78 100644 --- a/gr-blocks/lib/regenerate_bb_impl.h +++ b/gr-blocks/lib/regenerate_bb_impl.h @@ -26,32 +26,32 @@ #include <gnuradio/blocks/regenerate_bb.h> namespace gr { - namespace blocks { +namespace blocks { - class regenerate_bb_impl : public regenerate_bb - { - private: - int d_period; - int d_countdown; - unsigned int d_max_regen; - unsigned int d_regen_count; +class regenerate_bb_impl : public regenerate_bb +{ +private: + int d_period; + int d_countdown; + unsigned int d_max_regen; + unsigned int d_regen_count; - public: - regenerate_bb_impl(int period, unsigned int max_regen=500); - ~regenerate_bb_impl(); +public: + regenerate_bb_impl(int period, unsigned int max_regen = 500); + ~regenerate_bb_impl(); - void set_max_regen(unsigned int regen); - void set_period(int period); + void set_max_regen(unsigned int regen); + void set_period(int period); - unsigned int max_regen() const { return d_max_regen; }; - int period() const { return d_period; }; + unsigned int max_regen() const { return d_max_regen; }; + int period() const { return d_period; }; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_REGENERATE_BB_IMPL_H */ diff --git a/gr-blocks/lib/repack_bits_bb_impl.cc b/gr-blocks/lib/repack_bits_bb_impl.cc index a8185a95dc..240cac4a1f 100644 --- a/gr-blocks/lib/repack_bits_bb_impl.cc +++ b/gr-blocks/lib/repack_bits_bb_impl.cc @@ -28,149 +28,150 @@ #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, endianness_t endianness) - { - return gnuradio::get_initial_sptr - (new repack_bits_bb_impl(k, l, len_tag_key, - align_output, endianness)); +namespace blocks { + +repack_bits_bb::sptr repack_bits_bb::make(int k, + int l, + const std::string& len_tag_key, + bool align_output, + endianness_t endianness) +{ + return gnuradio::get_initial_sptr( + new repack_bits_bb_impl(k, l, len_tag_key, align_output, endianness)); +} + +repack_bits_bb_impl::repack_bits_bb_impl(int k, + int l, + const std::string& len_tag_key, + bool align_output, + endianness_t endianness) + : tagged_stream_block("repack_bits_bb", + io_signature::make(1, 1, sizeof(char)), + io_signature::make(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), + d_endianness(endianness) +{ + 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]"); } - repack_bits_bb_impl::repack_bits_bb_impl(int k, int l, const std::string &len_tag_key, - bool align_output, endianness_t endianness) - : tagged_stream_block("repack_bits_bb", - io_signature::make(1, 1, sizeof(char)), - io_signature::make(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), - d_endianness(endianness) - { - 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((uint64_t) d_k, (uint64_t) d_l); + set_relative_rate((uint64_t)d_k, (uint64_t)d_l); +} + +void repack_bits_bb_impl::set_k_and_l(int k, int l) +{ + gr::thread::scoped_lock guard(d_setlock); + d_k = k; + d_l = l; + set_relative_rate((uint64_t)d_k, (uint64_t)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++; } - void - repack_bits_bb_impl::set_k_and_l(int k, int l) - { - gr::thread::scoped_lock guard(d_setlock); - d_k = k; - d_l = l; - set_relative_rate((uint64_t) d_k, (uint64_t) 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; + 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) +{ + gr::thread::scoped_lock guard(d_setlock); + 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 - 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) - { - gr::thread::scoped_lock guard(d_setlock); - 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; - switch(d_endianness) { - case GR_LSB_FIRST: - 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; - } + int n_read = 0; + int n_written = 0; + switch (d_endianness) { + case GR_LSB_FIRST: + 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); + if (d_packet_mode) { + if (d_out_index) { + n_written++; + d_out_index = 0; + } + } else { + consume_each(n_read); } break; - case GR_MSB_FIRST: - 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_k - 1 - d_in_index)) & 0x01) << (d_l - 1 - 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; - } + case GR_MSB_FIRST: + 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_k - 1 - d_in_index)) & 0x01) + << (d_l - 1 - 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); + if (d_packet_mode) { + if (d_out_index) { + n_written++; + d_out_index = 0; + } + } else { + consume_each(n_read); } break; - default: + default: throw std::runtime_error("repack_bits_bb: unrecognized endianness value."); - } - - return n_written; } - } /* namespace blocks */ + 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 index 8dfb0600a6..39d0c06897 100644 --- a/gr-blocks/lib/repack_bits_bb_impl.h +++ b/gr-blocks/lib/repack_bits_bb_impl.h @@ -26,34 +26,40 @@ #include <gnuradio/blocks/repack_bits_bb.h> namespace gr { - namespace blocks { - - class repack_bits_bb_impl : public repack_bits_bb - { - private: - int d_k; //! Bits on input stream - 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 - endianness_t d_endianness; - - 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, endianness_t endianness=GR_LSB_FIRST); - ~repack_bits_bb_impl(); - void set_k_and_l(int k, int l);//callback function for bits per input byte k and bits per output byte l - 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 blocks { + +class repack_bits_bb_impl : public repack_bits_bb +{ +private: + int d_k; //! Bits on input stream + 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 + endianness_t d_endianness; + +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, + endianness_t endianness = GR_LSB_FIRST); + ~repack_bits_bb_impl(); + void set_k_and_l( + int k, + int l); // callback function for bits per input byte k and bits per output byte l + 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/repeat_impl.cc b/gr-blocks/lib/repeat_impl.cc index fb62265134..189fbc8948 100644 --- a/gr-blocks/lib/repeat_impl.cc +++ b/gr-blocks/lib/repeat_impl.cc @@ -28,62 +28,59 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - repeat::sptr repeat::make(size_t itemsize, int interp) - { - return gnuradio::get_initial_sptr(new repeat_impl(itemsize, interp)); - } - - repeat_impl::repeat_impl(size_t itemsize, int interp) - : sync_interpolator("repeat", - io_signature::make (1, 1, itemsize), - io_signature::make (1, 1, itemsize), - interp), - d_itemsize(itemsize), - d_interp(interp) - { - message_port_register_in(pmt::mp("interpolation")); - set_msg_handler(pmt::mp("interpolation"), - boost::bind(&repeat_impl::msg_set_interpolation, this, _1)); - } +repeat::sptr repeat::make(size_t itemsize, int interp) +{ + return gnuradio::get_initial_sptr(new repeat_impl(itemsize, interp)); +} - void - repeat_impl::msg_set_interpolation(pmt::pmt_t msg) - { - // Dynamization by Kevin McQuiggin: - d_interp = pmt::to_long(pmt::cdr(msg)); - sync_interpolator::set_interpolation(d_interp); - } - void - repeat_impl::set_interpolation(int interp) - { - // This ensures that interpolation is only changed between calls to work - // (and not in the middle of an ongoing work) - _post( pmt::mp("interpolation"), /* port */ - pmt::cons(pmt::mp("interpolation"), pmt::from_long(interp)) /* pair */ - ); - } +repeat_impl::repeat_impl(size_t itemsize, int interp) + : sync_interpolator("repeat", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize), + interp), + d_itemsize(itemsize), + d_interp(interp) +{ + message_port_register_in(pmt::mp("interpolation")); + set_msg_handler(pmt::mp("interpolation"), + boost::bind(&repeat_impl::msg_set_interpolation, this, _1)); +} - int - repeat_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *in = (const char *) input_items[0]; - char *out = (char *)output_items[0]; +void repeat_impl::msg_set_interpolation(pmt::pmt_t msg) +{ + // Dynamization by Kevin McQuiggin: + d_interp = pmt::to_long(pmt::cdr(msg)); + sync_interpolator::set_interpolation(d_interp); +} +void repeat_impl::set_interpolation(int interp) +{ + // This ensures that interpolation is only changed between calls to work + // (and not in the middle of an ongoing work) + _post(pmt::mp("interpolation"), /* port */ + pmt::cons(pmt::mp("interpolation"), pmt::from_long(interp)) /* pair */ + ); +} - for (int i = 0; i < noutput_items/d_interp; i++) { - for (int j = 0; j < d_interp; j++) { - memcpy(out, in, d_itemsize); - out += d_itemsize; - } +int repeat_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* in = (const char*)input_items[0]; + char* out = (char*)output_items[0]; - in += d_itemsize; - } + for (int i = 0; i < noutput_items / d_interp; i++) { + for (int j = 0; j < d_interp; j++) { + memcpy(out, in, d_itemsize); + out += d_itemsize; + } - return noutput_items; + in += d_itemsize; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/repeat_impl.h b/gr-blocks/lib/repeat_impl.h index 486a47a1ad..871b963e46 100644 --- a/gr-blocks/lib/repeat_impl.h +++ b/gr-blocks/lib/repeat_impl.h @@ -26,28 +26,29 @@ #include <gnuradio/blocks/repeat.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API repeat_impl : public repeat - { - size_t d_itemsize; - int d_interp; +class BLOCKS_API repeat_impl : public repeat +{ + size_t d_itemsize; + int d_interp; - public: - repeat_impl(size_t itemsize, int d_interp); +public: + repeat_impl(size_t itemsize, int d_interp); - int interpolation() const { return d_interp; } - void set_interpolation(int interp); + int interpolation() const { return d_interp; } + void set_interpolation(int interp); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - private: - void msg_set_interpolation(pmt::pmt_t msg); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - } /* namespace blocks */ +private: + void msg_set_interpolation(pmt::pmt_t msg); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_REPEAT_IMPL_H */ diff --git a/gr-blocks/lib/rms_cf_impl.cc b/gr-blocks/lib/rms_cf_impl.cc index 9ef243beba..11586a4ae2 100644 --- a/gr-blocks/lib/rms_cf_impl.cc +++ b/gr-blocks/lib/rms_cf_impl.cc @@ -29,51 +29,45 @@ #include <cmath> namespace gr { - namespace blocks { +namespace blocks { - rms_cf::sptr - rms_cf::make(double alpha) - { - return gnuradio::get_initial_sptr - (new rms_cf_impl(alpha)); - } +rms_cf::sptr rms_cf::make(double alpha) +{ + return gnuradio::get_initial_sptr(new rms_cf_impl(alpha)); +} - rms_cf_impl::rms_cf_impl(double alpha) - : sync_block("rms_cf", - io_signature::make(1, 1, sizeof(gr_complex)), - io_signature::make(1, 1, sizeof(float))) - { - set_alpha(alpha); - } +rms_cf_impl::rms_cf_impl(double alpha) + : sync_block("rms_cf", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(float))) +{ + set_alpha(alpha); +} - rms_cf_impl::~rms_cf_impl() - { - } +rms_cf_impl::~rms_cf_impl() {} - void - rms_cf_impl::set_alpha(double alpha) - { - d_alpha = alpha; - d_beta = 1 - d_alpha; - d_avg = 0; - } +void rms_cf_impl::set_alpha(double alpha) +{ + d_alpha = alpha; + d_beta = 1 - d_alpha; + d_avg = 0; +} - int - rms_cf_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const gr_complex *in = (const gr_complex *)input_items[0]; - float *out = (float *)output_items[0]; +int rms_cf_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const gr_complex* in = (const gr_complex*)input_items[0]; + float* out = (float*)output_items[0]; - for(int i = 0; i < noutput_items; i++) { - double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag(); - d_avg = d_beta*d_avg + d_alpha*mag_sqrd; + for (int i = 0; i < noutput_items; i++) { + double mag_sqrd = in[i].real() * in[i].real() + in[i].imag() * in[i].imag(); + d_avg = d_beta * d_avg + d_alpha * mag_sqrd; out[i] = sqrt(d_avg); - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/rms_cf_impl.h b/gr-blocks/lib/rms_cf_impl.h index 75bc8f3524..84663cb121 100644 --- a/gr-blocks/lib/rms_cf_impl.h +++ b/gr-blocks/lib/rms_cf_impl.h @@ -26,30 +26,29 @@ #include <gnuradio/blocks/rms_cf.h> namespace gr { - namespace blocks { +namespace blocks { - /*! - * \brief RMS average power - * \ingroup math_blk - */ - class rms_cf_impl : public rms_cf - { - private: - double d_alpha, d_beta, d_avg; - - public: - rms_cf_impl(double alpha = 0.0001); - ~rms_cf_impl(); +/*! + * \brief RMS average power + * \ingroup math_blk + */ +class rms_cf_impl : public rms_cf +{ +private: + double d_alpha, d_beta, d_avg; - void set_alpha(double alpha); +public: + rms_cf_impl(double alpha = 0.0001); + ~rms_cf_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + void set_alpha(double alpha); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_RMS_CF_IMPL_H */ diff --git a/gr-blocks/lib/rms_ff_impl.cc b/gr-blocks/lib/rms_ff_impl.cc index c84193c9f3..ae758b2449 100644 --- a/gr-blocks/lib/rms_ff_impl.cc +++ b/gr-blocks/lib/rms_ff_impl.cc @@ -29,51 +29,45 @@ #include <cmath> namespace gr { - namespace blocks { +namespace blocks { - rms_ff::sptr - rms_ff::make(double alpha) - { - return gnuradio::get_initial_sptr - (new rms_ff_impl(alpha)); - } +rms_ff::sptr rms_ff::make(double alpha) +{ + return gnuradio::get_initial_sptr(new rms_ff_impl(alpha)); +} - rms_ff_impl::rms_ff_impl(double alpha) - : sync_block("rms_ff", - io_signature::make(1, 1, sizeof(float)), - io_signature::make(1, 1, sizeof(float))) - { - set_alpha(alpha); - } +rms_ff_impl::rms_ff_impl(double alpha) + : sync_block("rms_ff", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(float))) +{ + set_alpha(alpha); +} - rms_ff_impl::~rms_ff_impl() - { - } +rms_ff_impl::~rms_ff_impl() {} - void - rms_ff_impl::set_alpha(double alpha) - { - d_alpha = alpha; - d_beta = 1 - d_alpha; - d_avg = 0; - } +void rms_ff_impl::set_alpha(double alpha) +{ + d_alpha = alpha; + d_beta = 1 - d_alpha; + d_avg = 0; +} - int - rms_ff_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float *)input_items[0]; - float *out = (float *)output_items[0]; +int rms_ff_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + float* out = (float*)output_items[0]; - for(int i = 0; i < noutput_items; i++) { - double mag_sqrd = in[i]*in[i]; - d_avg = d_beta*d_avg + d_alpha*mag_sqrd; + for (int i = 0; i < noutput_items; i++) { + double mag_sqrd = in[i] * in[i]; + d_avg = d_beta * d_avg + d_alpha * mag_sqrd; out[i] = sqrt(d_avg); - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/rms_ff_impl.h b/gr-blocks/lib/rms_ff_impl.h index 49ef1e07b3..a25fff6ecb 100644 --- a/gr-blocks/lib/rms_ff_impl.h +++ b/gr-blocks/lib/rms_ff_impl.h @@ -26,29 +26,29 @@ #include <gnuradio/blocks/rms_ff.h> namespace gr { - namespace blocks { +namespace blocks { - /*! - * \brief RMS average power - * \ingroup math_blk - */ - class rms_ff_impl : public rms_ff - { - private: - double d_alpha, d_beta, d_avg; +/*! + * \brief RMS average power + * \ingroup math_blk + */ +class rms_ff_impl : public rms_ff +{ +private: + double d_alpha, d_beta, d_avg; - public: - rms_ff_impl(double alpha = 0.0001); - ~rms_ff_impl(); +public: + rms_ff_impl(double alpha = 0.0001); + ~rms_ff_impl(); - void set_alpha(double alpha); + void set_alpha(double alpha); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_RMS_FF_IMPL_H */ diff --git a/gr-blocks/lib/rotator_cc_impl.cc b/gr-blocks/lib/rotator_cc_impl.cc index 3760d09c2e..a58040ef11 100644 --- a/gr-blocks/lib/rotator_cc_impl.cc +++ b/gr-blocks/lib/rotator_cc_impl.cc @@ -30,50 +30,44 @@ #include <cmath> namespace gr { - namespace blocks { +namespace blocks { - rotator_cc::sptr - rotator_cc::make(double phase_inc) - { - return gnuradio::get_initial_sptr - (new rotator_cc_impl(phase_inc)); - } +rotator_cc::sptr rotator_cc::make(double phase_inc) +{ + return gnuradio::get_initial_sptr(new rotator_cc_impl(phase_inc)); +} - rotator_cc_impl::rotator_cc_impl(double phase_inc) - : sync_block("rotator_cc", - io_signature::make(1, 1, sizeof(gr_complex)), - io_signature::make(1, 1, sizeof(gr_complex))) - { - set_phase_inc(phase_inc); - } +rotator_cc_impl::rotator_cc_impl(double phase_inc) + : sync_block("rotator_cc", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))) +{ + set_phase_inc(phase_inc); +} - rotator_cc_impl::~rotator_cc_impl() - { - } +rotator_cc_impl::~rotator_cc_impl() {} - void - rotator_cc_impl::set_phase_inc(double phase_inc) - { - d_r.set_phase_incr( exp(gr_complex(0, phase_inc)) ); - } +void rotator_cc_impl::set_phase_inc(double phase_inc) +{ + d_r.set_phase_incr(exp(gr_complex(0, phase_inc))); +} - int - rotator_cc_impl::work(int noutput_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]; +int rotator_cc_impl::work(int noutput_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]; #if 0 for (int i=0; i<noutput_items; i++) out[i] = d_r.rotate(in[i]); #else - d_r.rotateN(out, in, noutput_items); + d_r.rotateN(out, in, noutput_items); #endif - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/rotator_cc_impl.h b/gr-blocks/lib/rotator_cc_impl.h index 105fd1c534..415b49cd49 100644 --- a/gr-blocks/lib/rotator_cc_impl.h +++ b/gr-blocks/lib/rotator_cc_impl.h @@ -27,30 +27,29 @@ #include <gnuradio/blocks/rotator.h> namespace gr { - namespace blocks { +namespace blocks { - /*! - * \brief Complex rotator - * \ingroup math_blk - */ - class rotator_cc_impl : public rotator_cc - { - private: - rotator d_r; - - public: - rotator_cc_impl(double phase_inc = 0.0); - ~rotator_cc_impl(); +/*! + * \brief Complex rotator + * \ingroup math_blk + */ +class rotator_cc_impl : public rotator_cc +{ +private: + rotator d_r; - void set_phase_inc(double phase_inc); +public: + rotator_cc_impl(double phase_inc = 0.0); + ~rotator_cc_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + void set_phase_inc(double phase_inc); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_ROTATOR_CC_IMPL_H */ diff --git a/gr-blocks/lib/sample_and_hold_impl.cc b/gr-blocks/lib/sample_and_hold_impl.cc index c5e25bca6c..1520593500 100644 --- a/gr-blocks/lib/sample_and_hold_impl.cc +++ b/gr-blocks/lib/sample_and_hold_impl.cc @@ -29,52 +29,49 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename sample_and_hold<T>::sptr - sample_and_hold<T>::make() - { - return gnuradio::get_initial_sptr - (new sample_and_hold_impl<T> ()); - } +template <class T> +typename sample_and_hold<T>::sptr sample_and_hold<T>::make() +{ + return gnuradio::get_initial_sptr(new sample_and_hold_impl<T>()); +} - template <class T> - sample_and_hold_impl<T> ::sample_and_hold_impl() +template <class T> +sample_and_hold_impl<T>::sample_and_hold_impl() : sync_block("sample_and_hold", - io_signature::make2(2, 2, sizeof(T), sizeof(char)), - io_signature::make(1, 1, sizeof(T))), + io_signature::make2(2, 2, sizeof(T), sizeof(char)), + io_signature::make(1, 1, sizeof(T))), d_data(0) - { - } +{ +} - template <class T> - sample_and_hold_impl<T> ::~sample_and_hold_impl() - { - } +template <class T> +sample_and_hold_impl<T>::~sample_and_hold_impl() +{ +} - template <class T> - int - sample_and_hold_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T *)input_items[0]; - const char *ctrl = (const char *)input_items[1]; - T *optr = (T *)output_items[0]; +template <class T> +int sample_and_hold_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; + const char* ctrl = (const char*)input_items[1]; + T* optr = (T*)output_items[0]; - for(int i = 0; i < noutput_items; i++) { - if(ctrl[i]) { - d_data = iptr[i]; + for (int i = 0; i < noutput_items; i++) { + if (ctrl[i]) { + d_data = iptr[i]; } optr[i] = d_data; - } - return noutput_items; } + return noutput_items; +} template class sample_and_hold<std::uint8_t>; template class sample_and_hold<std::int16_t>; template class sample_and_hold<std::int32_t>; template class sample_and_hold<float>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/sample_and_hold_impl.h b/gr-blocks/lib/sample_and_hold_impl.h index f2ba032073..a264663422 100644 --- a/gr-blocks/lib/sample_and_hold_impl.h +++ b/gr-blocks/lib/sample_and_hold_impl.h @@ -27,24 +27,24 @@ #include <gnuradio/blocks/sample_and_hold.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class sample_and_hold_impl : public sample_and_hold<T> - { - private: - T d_data; +template <class T> +class sample_and_hold_impl : public sample_and_hold<T> +{ +private: + T d_data; - public: - sample_and_hold_impl (); - ~sample_and_hold_impl (); +public: + sample_and_hold_impl(); + ~sample_and_hold_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* SAMPLE_AND_HOLD_IMPL_H */ diff --git a/gr-blocks/lib/short_to_char_impl.cc b/gr-blocks/lib/short_to_char_impl.cc index 5ef6f203d5..ffde32fd3a 100644 --- a/gr-blocks/lib/short_to_char_impl.cc +++ b/gr-blocks/lib/short_to_char_impl.cc @@ -29,36 +29,34 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - short_to_char::sptr short_to_char::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new short_to_char_impl(vlen)); - } - - short_to_char_impl::short_to_char_impl(size_t vlen) - : sync_block("short_to_char", - io_signature::make (1, 1, sizeof(short)*vlen), - io_signature::make (1, 1, sizeof(char)*vlen)), - d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(char); - set_alignment(std::max(1, alignment_multiple)); - } - - int - short_to_char_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const int16_t *in = (const int16_t *) input_items[0]; - int8_t *out = (int8_t *) output_items[0]; - - volk_16i_convert_8i(out, in, d_vlen*noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +short_to_char::sptr short_to_char::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new short_to_char_impl(vlen)); +} + +short_to_char_impl::short_to_char_impl(size_t vlen) + : sync_block("short_to_char", + io_signature::make(1, 1, sizeof(short) * vlen), + io_signature::make(1, 1, sizeof(char) * vlen)), + d_vlen(vlen) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(char); + set_alignment(std::max(1, alignment_multiple)); +} + +int short_to_char_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const int16_t* in = (const int16_t*)input_items[0]; + int8_t* out = (int8_t*)output_items[0]; + + volk_16i_convert_8i(out, in, d_vlen * noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/short_to_char_impl.h b/gr-blocks/lib/short_to_char_impl.h index 387b5b4cb3..9f5702006f 100644 --- a/gr-blocks/lib/short_to_char_impl.h +++ b/gr-blocks/lib/short_to_char_impl.h @@ -26,21 +26,21 @@ #include <gnuradio/blocks/short_to_char.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API short_to_char_impl : public short_to_char - { - size_t d_vlen; +class BLOCKS_API short_to_char_impl : public short_to_char +{ + size_t d_vlen; - public: - short_to_char_impl(size_t vlen); +public: + short_to_char_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/short_to_float_impl.cc b/gr-blocks/lib/short_to_float_impl.cc index 609cc7fdb6..7bce7ef907 100644 --- a/gr-blocks/lib/short_to_float_impl.cc +++ b/gr-blocks/lib/short_to_float_impl.cc @@ -29,36 +29,35 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - short_to_float::sptr short_to_float::make(size_t vlen, float scale) - { - return gnuradio::get_initial_sptr(new short_to_float_impl(vlen, scale)); - } - - short_to_float_impl::short_to_float_impl(size_t vlen, float scale) - : sync_block("short_to_float", - io_signature::make (1, 1, sizeof(short)*vlen), - io_signature::make (1, 1, sizeof(float)*vlen)), - d_vlen(vlen), d_scale(scale) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1, alignment_multiple)); - } - - int - short_to_float_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short *) input_items[0]; - float *out = (float *) output_items[0]; - - volk_16i_s32f_convert_32f(out, in, d_scale, d_vlen*noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +short_to_float::sptr short_to_float::make(size_t vlen, float scale) +{ + return gnuradio::get_initial_sptr(new short_to_float_impl(vlen, scale)); +} + +short_to_float_impl::short_to_float_impl(size_t vlen, float scale) + : sync_block("short_to_float", + io_signature::make(1, 1, sizeof(short) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), + d_vlen(vlen), + d_scale(scale) +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +int short_to_float_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + float* out = (float*)output_items[0]; + + volk_16i_s32f_convert_32f(out, in, d_scale, d_vlen * noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/short_to_float_impl.h b/gr-blocks/lib/short_to_float_impl.h index 7976b58a09..0ded27bc1d 100644 --- a/gr-blocks/lib/short_to_float_impl.h +++ b/gr-blocks/lib/short_to_float_impl.h @@ -26,25 +26,25 @@ #include <gnuradio/blocks/short_to_float.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API short_to_float_impl : public short_to_float - { - size_t d_vlen; - float d_scale; +class BLOCKS_API short_to_float_impl : public short_to_float +{ + size_t d_vlen; + float d_scale; - public: - short_to_float_impl(size_t vlen, float scale); +public: + short_to_float_impl(size_t vlen, float scale); - virtual float scale() const { return d_scale; } - virtual void set_scale(float scale) { d_scale = scale; } + virtual float scale() const { return d_scale; } + virtual void set_scale(float scale) { d_scale = scale; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/skiphead_impl.cc b/gr-blocks/lib/skiphead_impl.cc index 0a1685b732..ed6082c2d3 100644 --- a/gr-blocks/lib/skiphead_impl.cc +++ b/gr-blocks/lib/skiphead_impl.cc @@ -29,77 +29,74 @@ #include <string.h> namespace gr { - namespace blocks { +namespace blocks { - skiphead::sptr - skiphead::make(size_t itemsize, uint64_t nitems_to_skip) - { - return gnuradio::get_initial_sptr - (new skiphead_impl(itemsize, nitems_to_skip)); - } +skiphead::sptr skiphead::make(size_t itemsize, uint64_t nitems_to_skip) +{ + return gnuradio::get_initial_sptr(new skiphead_impl(itemsize, nitems_to_skip)); +} - skiphead_impl::skiphead_impl(size_t itemsize, uint64_t nitems_to_skip) - : block("skiphead", - io_signature::make(1, 1, itemsize), - io_signature::make(1, 1, itemsize)), - d_nitems_to_skip(nitems_to_skip), d_nitems(0) - { - // Reserve space for a few tags to avoid constant re-allocation - // in the call to get_tags_in_window - d_tags.reserve(8); +skiphead_impl::skiphead_impl(size_t itemsize, uint64_t nitems_to_skip) + : block("skiphead", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize)), + d_nitems_to_skip(nitems_to_skip), + d_nitems(0) +{ + // Reserve space for a few tags to avoid constant re-allocation + // in the call to get_tags_in_window + d_tags.reserve(8); - // We'll handle propagating tags our selves to handle shifting offsets of tags - set_tag_propagation_policy(TPP_DONT); - } + // We'll handle propagating tags our selves to handle shifting offsets of tags + set_tag_propagation_policy(TPP_DONT); +} - skiphead_impl::~skiphead_impl() - { - } +skiphead_impl::~skiphead_impl() {} - int - skiphead_impl::general_work(int noutput_items, - gr_vector_int &ninput_items_, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *in = (const char*)input_items[0]; - char *out = (char*)output_items[0]; +int skiphead_impl::general_work(int noutput_items, + gr_vector_int& ninput_items_, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* in = (const char*)input_items[0]; + char* out = (char*)output_items[0]; - int ninput_items = std::min(ninput_items_[0], noutput_items); - int ii = 0; // input index + int ninput_items = std::min(ninput_items_[0], noutput_items); + int ii = 0; // input index - while (ii < ninput_items) { - uint64_t ni_total = ii + d_nitems; // total items processed so far - if(ni_total < d_nitems_to_skip) { // need to skip some more + while (ii < ninput_items) { + uint64_t ni_total = ii + d_nitems; // total items processed so far + if (ni_total < d_nitems_to_skip) { // need to skip some more - int n_to_skip = (int)std::min(d_nitems_to_skip - ni_total, - (uint64_t)(ninput_items - ii)); - ii += n_to_skip; + int n_to_skip = + (int)std::min(d_nitems_to_skip - ni_total, (uint64_t)(ninput_items - ii)); + ii += n_to_skip; } else { // nothing left to skip. copy away - // Grab all tags in the window and shift their offsets appropriately - get_tags_in_window(d_tags, 0, ii, ninput_items); - for(std::vector<tag_t>::iterator it = d_tags.begin(); it != d_tags.end(); it++) { - (*it).offset -= d_nitems_to_skip; - add_item_tag(0, *it); - } - int n_to_copy = ninput_items - ii; - if(n_to_copy > 0) { - size_t itemsize = output_signature()->sizeof_stream_item(0); - memcpy(out, in + (ii*itemsize), n_to_copy*itemsize); - } + // Grab all tags in the window and shift their offsets appropriately + get_tags_in_window(d_tags, 0, ii, ninput_items); + for (std::vector<tag_t>::iterator it = d_tags.begin(); it != d_tags.end(); + it++) { + (*it).offset -= d_nitems_to_skip; + add_item_tag(0, *it); + } + int n_to_copy = ninput_items - ii; + if (n_to_copy > 0) { + size_t itemsize = output_signature()->sizeof_stream_item(0); + memcpy(out, in + (ii * itemsize), n_to_copy * itemsize); + } - d_nitems += ninput_items; - consume_each(ninput_items); - return n_to_copy; + d_nitems += ninput_items; + consume_each(ninput_items); + return n_to_copy; } - } - - d_nitems += ninput_items; - consume_each(ninput_items); - return 0; } - } /* namespace blocks */ + d_nitems += ninput_items; + consume_each(ninput_items); + return 0; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/skiphead_impl.h b/gr-blocks/lib/skiphead_impl.h index 738fa86a61..e85873289a 100644 --- a/gr-blocks/lib/skiphead_impl.h +++ b/gr-blocks/lib/skiphead_impl.h @@ -26,26 +26,26 @@ #include <gnuradio/blocks/skiphead.h> namespace gr { - namespace blocks { - - class skiphead_impl : public skiphead - { - private: - uint64_t d_nitems_to_skip; - uint64_t d_nitems; // total items seen - std::vector<tag_t> d_tags; - - public: - skiphead_impl(size_t itemsize, uint64_t nitems_to_skip); - ~skiphead_impl(); - - int general_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 blocks { + +class skiphead_impl : public skiphead +{ +private: + uint64_t d_nitems_to_skip; + uint64_t d_nitems; // total items seen + std::vector<tag_t> d_tags; + +public: + skiphead_impl(size_t itemsize, uint64_t nitems_to_skip); + ~skiphead_impl(); + + int general_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_GR_SKIPHEAD_IMPL_H */ diff --git a/gr-blocks/lib/socket_pdu_impl.cc b/gr-blocks/lib/socket_pdu_impl.cc index 168d74ebb2..b3a96d350a 100644 --- a/gr-blocks/lib/socket_pdu_impl.cc +++ b/gr-blocks/lib/socket_pdu_impl.cc @@ -30,65 +30,79 @@ #include <gnuradio/blocks/pdu.h> namespace gr { - namespace blocks { - - socket_pdu::sptr - socket_pdu::make(std::string type, std::string addr, std::string port, int MTU/*= 10000*/, bool tcp_no_delay/*= false*/) - { - return gnuradio::get_initial_sptr(new socket_pdu_impl(type, addr, port, MTU, tcp_no_delay)); - } - - socket_pdu_impl::socket_pdu_impl(std::string type, std::string addr, std::string port, int MTU/*= 10000*/, bool tcp_no_delay/*= false*/) - : block("socket_pdu", - io_signature::make (0, 0, 0), - io_signature::make (0, 0, 0)), +namespace blocks { + +socket_pdu::sptr socket_pdu::make(std::string type, + std::string addr, + std::string port, + int MTU /*= 10000*/, + bool tcp_no_delay /*= false*/) +{ + return gnuradio::get_initial_sptr( + new socket_pdu_impl(type, addr, port, MTU, tcp_no_delay)); +} + +socket_pdu_impl::socket_pdu_impl(std::string type, + std::string addr, + std::string port, + int MTU /*= 10000*/, + bool tcp_no_delay /*= false*/) + : block("socket_pdu", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)), d_tcp_no_delay(tcp_no_delay) - { - d_rxbuf.resize(MTU); +{ + d_rxbuf.resize(MTU); - message_port_register_in(pdu::pdu_port_id()); - message_port_register_out(pdu::pdu_port_id()); + message_port_register_in(pdu::pdu_port_id()); + message_port_register_out(pdu::pdu_port_id()); - if ((type == "TCP_SERVER") && ((addr.empty()) || (addr == "0.0.0.0"))) { // Bind on all interfaces + if ((type == "TCP_SERVER") && + ((addr.empty()) || (addr == "0.0.0.0"))) { // Bind on all interfaces int port_num = atoi(port.c_str()); if (port_num == 0) - throw std::invalid_argument("gr::blocks:socket_pdu: invalid port for TCP_SERVER"); - d_tcp_endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port_num); - } - else if ((type == "TCP_SERVER") || (type == "TCP_CLIENT")) { + throw std::invalid_argument( + "gr::blocks:socket_pdu: invalid port for TCP_SERVER"); + d_tcp_endpoint = + boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port_num); + } else if ((type == "TCP_SERVER") || (type == "TCP_CLIENT")) { boost::asio::ip::tcp::resolver resolver(d_io_service); - boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), - addr, port, - boost::asio::ip::resolver_query_base::passive); + boost::asio::ip::tcp::resolver::query query( + boost::asio::ip::tcp::v4(), + addr, + port, + boost::asio::ip::resolver_query_base::passive); d_tcp_endpoint = *resolver.resolve(query); - } - else if ((type == "UDP_SERVER") && ((addr.empty()) || (addr == "0.0.0.0"))) { // Bind on all interfaces + } else if ((type == "UDP_SERVER") && + ((addr.empty()) || (addr == "0.0.0.0"))) { // Bind on all interfaces int port_num = atoi(port.c_str()); if (port_num == 0) - throw std::invalid_argument("gr::blocks:socket_pdu: invalid port for UDP_SERVER"); - d_udp_endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port_num); - } - else if ((type == "UDP_SERVER") || (type == "UDP_CLIENT")) { + throw std::invalid_argument( + "gr::blocks:socket_pdu: invalid port for UDP_SERVER"); + d_udp_endpoint = + boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port_num); + } else if ((type == "UDP_SERVER") || (type == "UDP_CLIENT")) { boost::asio::ip::udp::resolver resolver(d_io_service); - boost::asio::ip::udp::resolver::query query(boost::asio::ip::udp::v4(), - addr, port, - boost::asio::ip::resolver_query_base::passive); + boost::asio::ip::udp::resolver::query query( + boost::asio::ip::udp::v4(), + addr, + port, + boost::asio::ip::resolver_query_base::passive); if (type == "UDP_SERVER") - d_udp_endpoint = *resolver.resolve(query); + d_udp_endpoint = *resolver.resolve(query); else - d_udp_endpoint_other = *resolver.resolve(query); - } + d_udp_endpoint_other = *resolver.resolve(query); + } - if (type == "TCP_SERVER") { - d_acceptor_tcp.reset(new boost::asio::ip::tcp::acceptor(d_io_service, d_tcp_endpoint)); + if (type == "TCP_SERVER") { + d_acceptor_tcp.reset( + new boost::asio::ip::tcp::acceptor(d_io_service, d_tcp_endpoint)); d_acceptor_tcp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); start_tcp_accept(); - set_msg_handler(pdu::pdu_port_id(), boost::bind(&socket_pdu_impl::tcp_server_send, this, _1)); - } - else if (type =="TCP_CLIENT") { + set_msg_handler(pdu::pdu_port_id(), + boost::bind(&socket_pdu_impl::tcp_server_send, this, _1)); + } else if (type == "TCP_CLIENT") { boost::system::error_code error = boost::asio::error::host_not_found; d_tcp_socket.reset(new boost::asio::ip::tcp::socket(d_io_service)); d_tcp_socket->connect(d_tcp_endpoint, error); @@ -96,163 +110,174 @@ namespace gr { throw boost::system::system_error(error); d_tcp_socket->set_option(boost::asio::ip::tcp::no_delay(d_tcp_no_delay)); - set_msg_handler(pdu::pdu_port_id(), boost::bind(&socket_pdu_impl::tcp_client_send, this, _1)); - - d_tcp_socket->async_read_some(boost::asio::buffer(d_rxbuf), - boost::bind(&socket_pdu_impl::handle_tcp_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } - else if (type =="UDP_SERVER") { - d_udp_socket.reset(new boost::asio::ip::udp::socket(d_io_service, d_udp_endpoint)); - d_udp_socket->async_receive_from(boost::asio::buffer(d_rxbuf), d_udp_endpoint_other, - boost::bind(&socket_pdu_impl::handle_udp_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - - set_msg_handler(pdu::pdu_port_id(), boost::bind(&socket_pdu_impl::udp_send, this, _1)); - } - else if (type =="UDP_CLIENT") { - d_udp_socket.reset(new boost::asio::ip::udp::socket(d_io_service, d_udp_endpoint)); - d_udp_socket->async_receive_from(boost::asio::buffer(d_rxbuf), d_udp_endpoint_other, - boost::bind(&socket_pdu_impl::handle_udp_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - - set_msg_handler(pdu::pdu_port_id(), boost::bind(&socket_pdu_impl::udp_send, this, _1)); - } - else + set_msg_handler(pdu::pdu_port_id(), + boost::bind(&socket_pdu_impl::tcp_client_send, this, _1)); + + d_tcp_socket->async_read_some( + boost::asio::buffer(d_rxbuf), + boost::bind(&socket_pdu_impl::handle_tcp_read, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + } else if (type == "UDP_SERVER") { + d_udp_socket.reset( + new boost::asio::ip::udp::socket(d_io_service, d_udp_endpoint)); + d_udp_socket->async_receive_from( + boost::asio::buffer(d_rxbuf), + d_udp_endpoint_other, + boost::bind(&socket_pdu_impl::handle_udp_read, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + + set_msg_handler(pdu::pdu_port_id(), + boost::bind(&socket_pdu_impl::udp_send, this, _1)); + } else if (type == "UDP_CLIENT") { + d_udp_socket.reset( + new boost::asio::ip::udp::socket(d_io_service, d_udp_endpoint)); + d_udp_socket->async_receive_from( + boost::asio::buffer(d_rxbuf), + d_udp_endpoint_other, + boost::bind(&socket_pdu_impl::handle_udp_read, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + + set_msg_handler(pdu::pdu_port_id(), + boost::bind(&socket_pdu_impl::udp_send, this, _1)); + } else throw std::runtime_error("gr::blocks:socket_pdu: unknown socket type"); - d_thread = gr::thread::thread(boost::bind(&socket_pdu_impl::run_io_service, this)); - d_started = true; - } + d_thread = gr::thread::thread(boost::bind(&socket_pdu_impl::run_io_service, this)); + d_started = true; +} - socket_pdu_impl::~socket_pdu_impl() - { - stop(); - } +socket_pdu_impl::~socket_pdu_impl() { stop(); } - bool - socket_pdu_impl::stop() - { - if (d_started) { +bool socket_pdu_impl::stop() +{ + if (d_started) { d_io_service.stop(); d_thread.interrupt(); d_thread.join(); - } - d_started = false; - return true; } - - void - socket_pdu_impl::handle_tcp_read(const boost::system::error_code& error, size_t bytes_transferred) - { - if (!error) { - pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t *)&d_rxbuf[0]); + d_started = false; + return true; +} + +void socket_pdu_impl::handle_tcp_read(const boost::system::error_code& error, + size_t bytes_transferred) +{ + if (!error) { + pmt::pmt_t vector = + pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]); pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); message_port_pub(pdu::pdu_port_id(), pdu); - d_tcp_socket->async_read_some(boost::asio::buffer(d_rxbuf), - boost::bind(&socket_pdu_impl::handle_tcp_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } - else + d_tcp_socket->async_read_some( + boost::asio::buffer(d_rxbuf), + boost::bind(&socket_pdu_impl::handle_tcp_read, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + } else throw boost::system::system_error(error); - } +} - void - socket_pdu_impl::start_tcp_accept() - { +void socket_pdu_impl::start_tcp_accept() +{ #if (BOOST_VERSION >= 107000) - tcp_connection::sptr new_connection = tcp_connection::make(d_io_service, d_rxbuf.size(), d_tcp_no_delay); + tcp_connection::sptr new_connection = + tcp_connection::make(d_io_service, d_rxbuf.size(), d_tcp_no_delay); #else - tcp_connection::sptr new_connection = tcp_connection::make(d_acceptor_tcp->get_io_service(), d_rxbuf.size(), d_tcp_no_delay); + tcp_connection::sptr new_connection = tcp_connection::make( + d_acceptor_tcp->get_io_service(), d_rxbuf.size(), d_tcp_no_delay); #endif - d_acceptor_tcp->async_accept(new_connection->socket(), - boost::bind(&socket_pdu_impl::handle_tcp_accept, this, - new_connection, boost::asio::placeholders::error)); - } - - void - socket_pdu_impl::tcp_server_send(pmt::pmt_t msg) - { - pmt::pmt_t vector = pmt::cdr(msg); - for(size_t i = 0; i < d_tcp_connections.size(); i++) + d_acceptor_tcp->async_accept(new_connection->socket(), + boost::bind(&socket_pdu_impl::handle_tcp_accept, + this, + new_connection, + boost::asio::placeholders::error)); +} + +void socket_pdu_impl::tcp_server_send(pmt::pmt_t msg) +{ + pmt::pmt_t vector = pmt::cdr(msg); + for (size_t i = 0; i < d_tcp_connections.size(); i++) d_tcp_connections[i]->send(vector); - } +} - void - socket_pdu_impl::handle_tcp_accept(tcp_connection::sptr new_connection, const boost::system::error_code& error) - { - if (!error) { +void socket_pdu_impl::handle_tcp_accept(tcp_connection::sptr new_connection, + const boost::system::error_code& error) +{ + if (!error) { // Garbage collect closed sockets std::vector<tcp_connection::sptr>::iterator it = d_tcp_connections.begin(); - while(it != d_tcp_connections.end()) { - if (! (**it).socket().is_open()) - it = d_tcp_connections.erase(it); - else - ++it; + while (it != d_tcp_connections.end()) { + if (!(**it).socket().is_open()) + it = d_tcp_connections.erase(it); + else + ++it; } new_connection->start(this); d_tcp_connections.push_back(new_connection); start_tcp_accept(); - } - else + } else std::cout << error << std::endl; - } - - void - socket_pdu_impl::tcp_client_send(pmt::pmt_t msg) - { - pmt::pmt_t vector = pmt::cdr(msg); - size_t len = pmt::blob_length(vector); - size_t offset = 0; - std::vector<char> txbuf(std::min(len, d_rxbuf.size())); - while (offset < len) { +} + +void socket_pdu_impl::tcp_client_send(pmt::pmt_t msg) +{ + pmt::pmt_t vector = pmt::cdr(msg); + size_t len = pmt::blob_length(vector); + size_t offset = 0; + std::vector<char> txbuf(std::min(len, d_rxbuf.size())); + while (offset < len) { size_t send_len = std::min((len - offset), txbuf.size()); memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), send_len); offset += send_len; d_tcp_socket->send(boost::asio::buffer(txbuf, send_len)); - } } +} - void - socket_pdu_impl::udp_send(pmt::pmt_t msg) - { - if (d_udp_endpoint_other.address().to_string() == "0.0.0.0") +void socket_pdu_impl::udp_send(pmt::pmt_t msg) +{ + if (d_udp_endpoint_other.address().to_string() == "0.0.0.0") return; - pmt::pmt_t vector = pmt::cdr(msg); - size_t len = pmt::blob_length(vector); - size_t offset = 0; - std::vector<char> txbuf(std::min(len, d_rxbuf.size())); - while (offset < len) { + pmt::pmt_t vector = pmt::cdr(msg); + size_t len = pmt::blob_length(vector); + size_t offset = 0; + std::vector<char> txbuf(std::min(len, d_rxbuf.size())); + while (offset < len) { size_t send_len = std::min((len - offset), txbuf.size()); memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), send_len); offset += send_len; d_udp_socket->send_to(boost::asio::buffer(txbuf, send_len), d_udp_endpoint_other); - } } - - void - socket_pdu_impl::handle_udp_read(const boost::system::error_code& error, size_t bytes_transferred) - { - if (!error) { - pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]); +} + +void socket_pdu_impl::handle_udp_read(const boost::system::error_code& error, + size_t bytes_transferred) +{ + if (!error) { + pmt::pmt_t vector = + pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]); pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); message_port_pub(pdu::pdu_port_id(), pdu); - d_udp_socket->async_receive_from(boost::asio::buffer(d_rxbuf), d_udp_endpoint_other, - boost::bind(&socket_pdu_impl::handle_udp_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } + d_udp_socket->async_receive_from( + boost::asio::buffer(d_rxbuf), + d_udp_endpoint_other, + boost::bind(&socket_pdu_impl::handle_udp_read, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); } +} - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/socket_pdu_impl.h b/gr-blocks/lib/socket_pdu_impl.h index ad42996cd1..c05ef7bbc9 100644 --- a/gr-blocks/lib/socket_pdu_impl.h +++ b/gr-blocks/lib/socket_pdu_impl.h @@ -27,47 +27,54 @@ #include "tcp_connection.h" namespace gr { - namespace blocks { +namespace blocks { - class socket_pdu_impl : public socket_pdu - { - private: - boost::asio::io_service d_io_service; - std::vector<char> d_rxbuf; - void run_io_service() { d_io_service.run(); } - gr::thread::thread d_thread; - bool d_started; +class socket_pdu_impl : public socket_pdu +{ +private: + boost::asio::io_service d_io_service; + std::vector<char> d_rxbuf; + void run_io_service() { d_io_service.run(); } + gr::thread::thread d_thread; + bool d_started; - // TCP specific - boost::asio::ip::tcp::endpoint d_tcp_endpoint; - std::vector<tcp_connection::sptr> d_tcp_connections; - void handle_tcp_read(const boost::system::error_code& error, size_t bytes_transferred); - bool d_tcp_no_delay; + // TCP specific + boost::asio::ip::tcp::endpoint d_tcp_endpoint; + std::vector<tcp_connection::sptr> d_tcp_connections; + void handle_tcp_read(const boost::system::error_code& error, + size_t bytes_transferred); + bool d_tcp_no_delay; - // TCP server specific - boost::shared_ptr<boost::asio::ip::tcp::acceptor> d_acceptor_tcp; - void start_tcp_accept(); - void tcp_server_send(pmt::pmt_t msg); - void handle_tcp_accept(tcp_connection::sptr new_connection, const boost::system::error_code& error); + // TCP server specific + boost::shared_ptr<boost::asio::ip::tcp::acceptor> d_acceptor_tcp; + void start_tcp_accept(); + void tcp_server_send(pmt::pmt_t msg); + void handle_tcp_accept(tcp_connection::sptr new_connection, + const boost::system::error_code& error); - // TCP client specific - boost::shared_ptr<boost::asio::ip::tcp::socket> d_tcp_socket; - void tcp_client_send(pmt::pmt_t msg); + // TCP client specific + boost::shared_ptr<boost::asio::ip::tcp::socket> d_tcp_socket; + void tcp_client_send(pmt::pmt_t msg); - // UDP specific - boost::asio::ip::udp::endpoint d_udp_endpoint; - boost::asio::ip::udp::endpoint d_udp_endpoint_other; - boost::shared_ptr<boost::asio::ip::udp::socket> d_udp_socket; - void handle_udp_read(const boost::system::error_code& error, size_t bytes_transferred); - void udp_send(pmt::pmt_t msg); + // UDP specific + boost::asio::ip::udp::endpoint d_udp_endpoint; + boost::asio::ip::udp::endpoint d_udp_endpoint_other; + boost::shared_ptr<boost::asio::ip::udp::socket> d_udp_socket; + void handle_udp_read(const boost::system::error_code& error, + size_t bytes_transferred); + void udp_send(pmt::pmt_t msg); - public: - socket_pdu_impl(std::string type, std::string addr, std::string port, int MTU = 10000, bool tcp_no_delay = false); - ~socket_pdu_impl(); - bool stop(); - }; +public: + socket_pdu_impl(std::string type, + std::string addr, + std::string port, + int MTU = 10000, + bool tcp_no_delay = false); + ~socket_pdu_impl(); + bool stop(); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_SOCKET_PDU_IMPL_H */ diff --git a/gr-blocks/lib/stream_mux_impl.cc b/gr-blocks/lib/stream_mux_impl.cc index 4d5e71baca..000caf5454 100644 --- a/gr-blocks/lib/stream_mux_impl.cc +++ b/gr-blocks/lib/stream_mux_impl.cc @@ -30,94 +30,93 @@ #include <cstring> namespace gr { - namespace blocks { +namespace blocks { - stream_mux::sptr stream_mux::make(size_t itemsize, const std::vector<int> &lengths) - { - return gnuradio::get_initial_sptr(new stream_mux_impl(itemsize, lengths)); - } +stream_mux::sptr stream_mux::make(size_t itemsize, const std::vector<int>& lengths) +{ + return gnuradio::get_initial_sptr(new stream_mux_impl(itemsize, lengths)); +} - stream_mux_impl::stream_mux_impl(size_t itemsize, const std::vector<int> &lengths) - : block("stream_mux", - io_signature::make (1, -1, itemsize), - io_signature::make (1, 1, itemsize)), - d_itemsize(itemsize), - d_stream(0), - d_residual(0), - d_lengths(lengths) - { - while (d_lengths[d_stream] == 0) { +stream_mux_impl::stream_mux_impl(size_t itemsize, const std::vector<int>& lengths) + : block("stream_mux", + io_signature::make(1, -1, itemsize), + io_signature::make(1, 1, itemsize)), + d_itemsize(itemsize), + d_stream(0), + d_residual(0), + d_lengths(lengths) +{ + while (d_lengths[d_stream] == 0) { d_stream++; if (d_stream == d_lengths.size()) { - throw std::invalid_argument("At least one size must be non-zero."); + throw std::invalid_argument("At least one size must be non-zero."); } - } - d_residual = d_lengths[d_stream]; - set_tag_propagation_policy(TPP_DONT); } + d_residual = d_lengths[d_stream]; + set_tag_propagation_policy(TPP_DONT); +} - void - stream_mux_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required) - { - unsigned ninputs = ninput_items_required.size (); - for (unsigned i = 0; i < ninputs; i++) { - // Only active inputs *need* items, for the rest, it would just be nice - ninput_items_required[i] = (d_stream == i ? 1 : 0); - } +void stream_mux_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required) +{ + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) { + // Only active inputs *need* items, for the rest, it would just be nice + ninput_items_required[i] = (d_stream == i ? 1 : 0); } +} - int - stream_mux_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items - ){ - char *out = (char *) output_items[0]; - const char *in; - int out_index = 0; // Items written - gr_vector_int input_index(d_lengths.size(), 0); // Items read - std::vector<gr::tag_t> stream_t; +int stream_mux_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + char* out = (char*)output_items[0]; + const char* in; + int out_index = 0; // Items written + gr_vector_int input_index(d_lengths.size(), 0); // Items read + std::vector<gr::tag_t> stream_t; - while (out_index < noutput_items) { + while (out_index < noutput_items) { if (ninput_items[d_stream] <= input_index[d_stream]) { - break; + break; } int space_left_in_buffers = std::min( - noutput_items - out_index, // Space left in output buffer - ninput_items[d_stream] - input_index[d_stream] // Space left in input buffer - ); - int items_to_copy = std::min( - space_left_in_buffers, - d_residual + noutput_items - out_index, // Space left in output buffer + ninput_items[d_stream] - input_index[d_stream] // Space left in input buffer ); - in = (const char *) input_items[d_stream] + input_index[d_stream]*d_itemsize; - memcpy(&out[out_index*d_itemsize], in, items_to_copy*d_itemsize); - get_tags_in_window(stream_t, d_stream,input_index[d_stream],input_index[d_stream] + items_to_copy); - BOOST_FOREACH(gr::tag_t t, stream_t){ - t.offset = t.offset - nitems_read(d_stream) - input_index[d_stream] + nitems_written(0) + out_index; - add_item_tag(0, t); + int items_to_copy = std::min(space_left_in_buffers, d_residual); + in = (const char*)input_items[d_stream] + input_index[d_stream] * d_itemsize; + memcpy(&out[out_index * d_itemsize], in, items_to_copy * d_itemsize); + get_tags_in_window(stream_t, + d_stream, + input_index[d_stream], + input_index[d_stream] + items_to_copy); + BOOST_FOREACH (gr::tag_t t, stream_t) { + t.offset = t.offset - nitems_read(d_stream) - input_index[d_stream] + + nitems_written(0) + out_index; + add_item_tag(0, t); } - + out_index += items_to_copy; input_index[d_stream] += items_to_copy; d_residual -= items_to_copy; if (d_residual == 0) { - do { // Skip all those inputs with zero length - d_stream = (d_stream+1) % d_lengths.size(); - } while (d_lengths[d_stream] == 0); - d_residual = d_lengths[d_stream]; + do { // Skip all those inputs with zero length + d_stream = (d_stream + 1) % d_lengths.size(); + } while (d_lengths[d_stream] == 0); + d_residual = d_lengths[d_stream]; } else { - break; + break; } - } // while + } // while - for (size_t i = 0; i < input_index.size(); i++) { - consume((int) i, input_index[i]); - } + for (size_t i = 0; i < input_index.size(); i++) { + consume((int)i, input_index[i]); + } - return out_index; - } /* work */ + return out_index; +} /* work */ - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/stream_mux_impl.h b/gr-blocks/lib/stream_mux_impl.h index 67be9381af..3805790373 100644 --- a/gr-blocks/lib/stream_mux_impl.h +++ b/gr-blocks/lib/stream_mux_impl.h @@ -26,28 +26,28 @@ #include <gnuradio/blocks/stream_mux.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API stream_mux_impl : public stream_mux - { - private: - size_t d_itemsize; - unsigned int d_stream; // index of currently selected stream - int d_residual; // number if items left to put into current stream - gr_vector_int d_lengths; // number if items to pack per stream +class BLOCKS_API stream_mux_impl : public stream_mux +{ +private: + size_t d_itemsize; + unsigned int d_stream; // index of currently selected stream + int d_residual; // number if items left to put into current stream + gr_vector_int d_lengths; // number if items to pack per stream - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - public: - stream_mux_impl(size_t itemsize, const std::vector<int> &lengths); +public: + stream_mux_impl(size_t itemsize, const std::vector<int>& lengths); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int general_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 blocks */ } /* namespace gr */ #endif /* INCLUDED_STREAM_MUX_IMPL_H */ diff --git a/gr-blocks/lib/stream_pdu_base.cc b/gr-blocks/lib/stream_pdu_base.cc index a698f85d55..1cbcb0485c 100644 --- a/gr-blocks/lib/stream_pdu_base.cc +++ b/gr-blocks/lib/stream_pdu_base.cc @@ -37,94 +37,85 @@ #include "stream_pdu_base.h" #include <boost/format.hpp> -static const long timeout_us = 100*1000; //100ms +static const long timeout_us = 100 * 1000; // 100ms namespace gr { - namespace blocks { - - stream_pdu_base::stream_pdu_base(int MTU) - : d_fd(-1), - d_started(false), - d_finished(false) - { - // reserve space for rx buffer - d_rxbuf.resize(MTU,0); - } +namespace blocks { - stream_pdu_base::~stream_pdu_base() - { - stop_rxthread(); - } +stream_pdu_base::stream_pdu_base(int MTU) : d_fd(-1), d_started(false), d_finished(false) +{ + // reserve space for rx buffer + d_rxbuf.resize(MTU, 0); +} - void - stream_pdu_base::start_rxthread(basic_block *blk, pmt::pmt_t port) - { - d_blk = blk; - d_port = port; - d_thread = gr::thread::thread(boost::bind(&stream_pdu_base::run, this)); - d_started = true; - } +stream_pdu_base::~stream_pdu_base() { stop_rxthread(); } + +void stream_pdu_base::start_rxthread(basic_block* blk, pmt::pmt_t port) +{ + d_blk = blk; + d_port = port; + d_thread = gr::thread::thread(boost::bind(&stream_pdu_base::run, this)); + d_started = true; +} - void - stream_pdu_base::stop_rxthread() - { - d_finished = true; +void stream_pdu_base::stop_rxthread() +{ + d_finished = true; - if (d_started) { + if (d_started) { d_thread.interrupt(); d_thread.join(); - } } +} - void - stream_pdu_base::run() - { - while(!d_finished) { +void stream_pdu_base::run() +{ + while (!d_finished) { if (!wait_ready()) - continue; + continue; const int result = read(d_fd, &d_rxbuf[0], d_rxbuf.size()); if (result <= 0) - throw std::runtime_error("stream_pdu_base, bad socket read!"); + throw std::runtime_error("stream_pdu_base, bad socket read!"); pmt::pmt_t vector = pmt::init_u8vector(result, &d_rxbuf[0]); pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); d_blk->message_port_pub(d_port, pdu); - } } - - bool - stream_pdu_base::wait_ready() - { - //setup timeval for timeout - timeval tv; - tv.tv_sec = 0; - tv.tv_usec = timeout_us; - - //setup rset for timeout - fd_set rset; - FD_ZERO(&rset); - FD_SET(d_fd, &rset); - - //call select with timeout on receive socket - return ::select(d_fd+1, &rset, NULL, NULL, &tv) > 0; - } - - void - stream_pdu_base::send(pmt::pmt_t msg) - { - pmt::pmt_t vector = pmt::cdr(msg); - size_t offset(0); - size_t itemsize(pdu::itemsize(pdu::type_from_pmt(vector))); - int len(pmt::length(vector)*itemsize); - - const int rv = write(d_fd, pmt::uniform_vector_elements(vector, offset), len); - if (rv != len) { - std::cerr << boost::format("WARNING: stream_pdu_base::send(pdu) write failed! (d_fd=%d, len=%d, rv=%d)") - % d_fd % len % rv << std::endl; - } +} + +bool stream_pdu_base::wait_ready() +{ + // setup timeval for timeout + timeval tv; + tv.tv_sec = 0; + tv.tv_usec = timeout_us; + + // setup rset for timeout + fd_set rset; + FD_ZERO(&rset); + FD_SET(d_fd, &rset); + + // call select with timeout on receive socket + return ::select(d_fd + 1, &rset, NULL, NULL, &tv) > 0; +} + +void stream_pdu_base::send(pmt::pmt_t msg) +{ + pmt::pmt_t vector = pmt::cdr(msg); + size_t offset(0); + size_t itemsize(pdu::itemsize(pdu::type_from_pmt(vector))); + int len(pmt::length(vector) * itemsize); + + const int rv = write(d_fd, pmt::uniform_vector_elements(vector, offset), len); + if (rv != len) { + std::cerr << boost::format("WARNING: stream_pdu_base::send(pdu) write failed! " + "(d_fd=%d, len=%d, rv=%d)") % + d_fd % len % rv + << std::endl; } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/stream_pdu_base.h b/gr-blocks/lib/stream_pdu_base.h index e15aec1787..cc3394d6f0 100644 --- a/gr-blocks/lib/stream_pdu_base.h +++ b/gr-blocks/lib/stream_pdu_base.h @@ -30,32 +30,32 @@ class basic_block; namespace gr { - namespace blocks { - - class stream_pdu_base - { - public: - stream_pdu_base(int MTU=10000); - ~stream_pdu_base(); - - protected: - int d_fd; - bool d_started; - bool d_finished; - std::vector<uint8_t> d_rxbuf; - gr::thread::thread d_thread; - - pmt::pmt_t d_port; - basic_block *d_blk; - - void run(); - void send(pmt::pmt_t msg); - bool wait_ready(); - void start_rxthread(basic_block *blk, pmt::pmt_t rxport); - void stop_rxthread(); - }; - - } /* namespace blocks */ +namespace blocks { + +class stream_pdu_base +{ +public: + stream_pdu_base(int MTU = 10000); + ~stream_pdu_base(); + +protected: + int d_fd; + bool d_started; + bool d_finished; + std::vector<uint8_t> d_rxbuf; + gr::thread::thread d_thread; + + pmt::pmt_t d_port; + basic_block* d_blk; + + void run(); + void send(pmt::pmt_t msg); + bool wait_ready(); + void start_rxthread(basic_block* blk, pmt::pmt_t rxport); + void stop_rxthread(); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_STREAM_PDU_BASE_H */ diff --git a/gr-blocks/lib/stream_to_streams_impl.cc b/gr-blocks/lib/stream_to_streams_impl.cc index 2832a21563..a25786b5b3 100644 --- a/gr-blocks/lib/stream_to_streams_impl.cc +++ b/gr-blocks/lib/stream_to_streams_impl.cc @@ -29,44 +29,41 @@ #include <string.h> namespace gr { - namespace blocks { +namespace blocks { - stream_to_streams::sptr - stream_to_streams::make(size_t itemsize, size_t nstreams) - { - return gnuradio::get_initial_sptr - (new stream_to_streams_impl(itemsize, nstreams)); - } - - stream_to_streams_impl::stream_to_streams_impl(size_t itemsize, size_t nstreams) - : sync_decimator("stream_to_streams", - io_signature::make(1, 1, itemsize), - io_signature::make(nstreams, nstreams, itemsize), - nstreams) - { - } +stream_to_streams::sptr stream_to_streams::make(size_t itemsize, size_t nstreams) +{ + return gnuradio::get_initial_sptr(new stream_to_streams_impl(itemsize, nstreams)); +} - int - stream_to_streams_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - size_t item_size = output_signature()->sizeof_stream_item(0); +stream_to_streams_impl::stream_to_streams_impl(size_t itemsize, size_t nstreams) + : sync_decimator("stream_to_streams", + io_signature::make(1, 1, itemsize), + io_signature::make(nstreams, nstreams, itemsize), + nstreams) +{ +} - const char *in = (const char *)input_items[0]; - char **outv = (char **)&output_items[0]; - int nstreams = output_items.size(); +int stream_to_streams_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + size_t item_size = output_signature()->sizeof_stream_item(0); - for (int i = 0; i < noutput_items; i++) { - for (int j = 0; j < nstreams; j++) { - memcpy(outv[j], in, item_size); - outv[j] += item_size; - in += item_size; - } - } + const char* in = (const char*)input_items[0]; + char** outv = (char**)&output_items[0]; + int nstreams = output_items.size(); - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + for (int j = 0; j < nstreams; j++) { + memcpy(outv[j], in, item_size); + outv[j] += item_size; + in += item_size; + } } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/stream_to_streams_impl.h b/gr-blocks/lib/stream_to_streams_impl.h index bd3763572b..09057e18de 100644 --- a/gr-blocks/lib/stream_to_streams_impl.h +++ b/gr-blocks/lib/stream_to_streams_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/stream_to_streams.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API stream_to_streams_impl : public stream_to_streams - { - public: - stream_to_streams_impl(size_t itemsize, size_t nstreams); +class BLOCKS_API stream_to_streams_impl : public stream_to_streams +{ +public: + stream_to_streams_impl(size_t itemsize, size_t nstreams); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_STREAM_TO_STREAMS_IMPL_H */ diff --git a/gr-blocks/lib/stream_to_tagged_stream_impl.cc b/gr-blocks/lib/stream_to_tagged_stream_impl.cc index c38f09abaa..2873e98042 100644 --- a/gr-blocks/lib/stream_to_tagged_stream_impl.cc +++ b/gr-blocks/lib/stream_to_tagged_stream_impl.cc @@ -29,68 +29,68 @@ #include "stream_to_tagged_stream_impl.h" namespace gr { - namespace blocks { +namespace blocks { - stream_to_tagged_stream::sptr - stream_to_tagged_stream::make(size_t itemsize, unsigned int vlen, unsigned packet_len, const std::string &len_tag_key) - { - return gnuradio::get_initial_sptr - (new stream_to_tagged_stream_impl(itemsize, vlen, packet_len, len_tag_key)); - } +stream_to_tagged_stream::sptr +stream_to_tagged_stream::make(size_t itemsize, + unsigned int vlen, + unsigned packet_len, + const std::string& len_tag_key) +{ + return gnuradio::get_initial_sptr( + new stream_to_tagged_stream_impl(itemsize, vlen, packet_len, len_tag_key)); +} - stream_to_tagged_stream_impl::stream_to_tagged_stream_impl(size_t itemsize, unsigned int vlen, unsigned packet_len, const std::string &len_tag_key) - : gr::sync_block("stream_to_tagged_stream", - gr::io_signature::make(1, 1, itemsize * vlen), - gr::io_signature::make(1, 1, itemsize * vlen)), +stream_to_tagged_stream_impl::stream_to_tagged_stream_impl(size_t itemsize, + unsigned int vlen, + unsigned packet_len, + const std::string& len_tag_key) + : gr::sync_block("stream_to_tagged_stream", + gr::io_signature::make(1, 1, itemsize * vlen), + gr::io_signature::make(1, 1, itemsize * vlen)), d_itemsize(itemsize * vlen), d_packet_len(packet_len), d_packet_len_pmt(pmt::from_long(packet_len)), d_len_tag_key(pmt::string_to_symbol(len_tag_key)), d_next_tag_pos(0) - {} - - stream_to_tagged_stream_impl::~stream_to_tagged_stream_impl() - { - } +{ +} - void - stream_to_tagged_stream_impl::set_packet_len(unsigned packet_len) - { - gr::thread::scoped_lock guard(d_setlock); - d_packet_len = packet_len; - } - void - stream_to_tagged_stream_impl::set_packet_len_pmt(unsigned packet_len) - { - gr::thread::scoped_lock guard(d_setlock); - d_packet_len_pmt=pmt::from_long(packet_len); - } - int - stream_to_tagged_stream_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr::thread::scoped_lock guard(d_setlock); - const unsigned char *in = (const unsigned char *) input_items[0]; - unsigned char *out = (unsigned char *) output_items[0]; - // Copy data - memcpy(out, in, noutput_items * d_itemsize); - // Add tags every d_packet_len - while(d_next_tag_pos < nitems_written(0) + noutput_items) { - add_item_tag(0, d_next_tag_pos, d_len_tag_key, d_packet_len_pmt); - d_next_tag_pos += d_packet_len; - } +stream_to_tagged_stream_impl::~stream_to_tagged_stream_impl() {} - return noutput_items; +void stream_to_tagged_stream_impl::set_packet_len(unsigned packet_len) +{ + gr::thread::scoped_lock guard(d_setlock); + d_packet_len = packet_len; +} +void stream_to_tagged_stream_impl::set_packet_len_pmt(unsigned packet_len) +{ + gr::thread::scoped_lock guard(d_setlock); + d_packet_len_pmt = pmt::from_long(packet_len); +} +int stream_to_tagged_stream_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr::thread::scoped_lock guard(d_setlock); + const unsigned char* in = (const unsigned char*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; + // Copy data + memcpy(out, in, noutput_items * d_itemsize); + // Add tags every d_packet_len + while (d_next_tag_pos < nitems_written(0) + noutput_items) { + add_item_tag(0, d_next_tag_pos, d_len_tag_key, d_packet_len_pmt); + d_next_tag_pos += d_packet_len; } - bool - stream_to_tagged_stream_impl::start() - { - d_next_tag_pos = 0; - return true; - } + return noutput_items; +} - } /* namespace blocks */ -} /* namespace gr */ +bool stream_to_tagged_stream_impl::start() +{ + d_next_tag_pos = 0; + return true; +} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/stream_to_tagged_stream_impl.h b/gr-blocks/lib/stream_to_tagged_stream_impl.h index 82c920296f..111b8df601 100644 --- a/gr-blocks/lib/stream_to_tagged_stream_impl.h +++ b/gr-blocks/lib/stream_to_tagged_stream_impl.h @@ -26,32 +26,34 @@ #include <gnuradio/blocks/stream_to_tagged_stream.h> namespace gr { - namespace blocks { - - class stream_to_tagged_stream_impl : public stream_to_tagged_stream - { - private: - size_t d_itemsize; - unsigned d_packet_len; - pmt::pmt_t d_packet_len_pmt; - pmt::pmt_t d_len_tag_key; - uint64_t d_next_tag_pos; - - public: - stream_to_tagged_stream_impl(size_t itemsize, unsigned int vlen, unsigned packet_len, const std::string &tag_len_key); - ~stream_to_tagged_stream_impl(); - void set_packet_len(unsigned packet_len); - void set_packet_len_pmt(unsigned packet_len); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - bool start(); - }; - - } // namespace blocks +namespace blocks { + +class stream_to_tagged_stream_impl : public stream_to_tagged_stream +{ +private: + size_t d_itemsize; + unsigned d_packet_len; + pmt::pmt_t d_packet_len_pmt; + pmt::pmt_t d_len_tag_key; + uint64_t d_next_tag_pos; + +public: + stream_to_tagged_stream_impl(size_t itemsize, + unsigned int vlen, + unsigned packet_len, + const std::string& tag_len_key); + ~stream_to_tagged_stream_impl(); + void set_packet_len(unsigned packet_len); + void set_packet_len_pmt(unsigned packet_len); + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); + + bool start(); +}; + +} // namespace blocks } // namespace gr #endif /* INCLUDED_BLOCKS_STREAM_TO_TAGGED_STREAM_IMPL_H */ - diff --git a/gr-blocks/lib/stream_to_vector_impl.cc b/gr-blocks/lib/stream_to_vector_impl.cc index 60b330c246..bd518312a1 100644 --- a/gr-blocks/lib/stream_to_vector_impl.cc +++ b/gr-blocks/lib/stream_to_vector_impl.cc @@ -28,35 +28,35 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - stream_to_vector::sptr stream_to_vector::make(size_t itemsize, size_t nitems_per_block) - { - return gnuradio::get_initial_sptr(new stream_to_vector_impl(itemsize, nitems_per_block)); - } +stream_to_vector::sptr stream_to_vector::make(size_t itemsize, size_t nitems_per_block) +{ + return gnuradio::get_initial_sptr( + new stream_to_vector_impl(itemsize, nitems_per_block)); +} - stream_to_vector_impl::stream_to_vector_impl(size_t itemsize, size_t nitems_per_block) - : sync_decimator ("stream_to_vector", - io_signature::make (1, 1, itemsize), - io_signature::make (1, 1, itemsize * nitems_per_block), - nitems_per_block) - { - } +stream_to_vector_impl::stream_to_vector_impl(size_t itemsize, size_t nitems_per_block) + : sync_decimator("stream_to_vector", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize * nitems_per_block), + nitems_per_block) +{ +} - int - stream_to_vector_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - size_t block_size = output_signature()->sizeof_stream_item (0); +int stream_to_vector_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + size_t block_size = output_signature()->sizeof_stream_item(0); - const char *in = (const char *) input_items[0]; - char *out = (char *) output_items[0]; + const char* in = (const char*)input_items[0]; + char* out = (char*)output_items[0]; - memcpy (out, in, noutput_items * block_size); + memcpy(out, in, noutput_items * block_size); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/stream_to_vector_impl.h b/gr-blocks/lib/stream_to_vector_impl.h index 3484d397ed..ca79d2d0e3 100644 --- a/gr-blocks/lib/stream_to_vector_impl.h +++ b/gr-blocks/lib/stream_to_vector_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/stream_to_vector.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API stream_to_vector_impl : public stream_to_vector - { - public: - stream_to_vector_impl(size_t itemsize, size_t nitems_per_block); +class BLOCKS_API stream_to_vector_impl : public stream_to_vector +{ +public: + stream_to_vector_impl(size_t itemsize, size_t nitems_per_block); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_STREAM_TO_VECTOR_IMPL_H */ diff --git a/gr-blocks/lib/streams_to_stream_impl.cc b/gr-blocks/lib/streams_to_stream_impl.cc index cbd31c4b72..146c456f3e 100644 --- a/gr-blocks/lib/streams_to_stream_impl.cc +++ b/gr-blocks/lib/streams_to_stream_impl.cc @@ -28,45 +28,44 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - streams_to_stream::sptr streams_to_stream::make(size_t itemsize, size_t nstreams) - { - return gnuradio::get_initial_sptr(new streams_to_stream_impl(itemsize, nstreams)); - } - - streams_to_stream_impl::streams_to_stream_impl(size_t itemsize, size_t nstreams) - : sync_interpolator ("streams_to_stream", - io_signature::make (nstreams, nstreams, itemsize), - io_signature::make (1, 1, itemsize), - nstreams) - { - } +streams_to_stream::sptr streams_to_stream::make(size_t itemsize, size_t nstreams) +{ + return gnuradio::get_initial_sptr(new streams_to_stream_impl(itemsize, nstreams)); +} - int - streams_to_stream_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - size_t itemsize = output_signature()->sizeof_stream_item (0); +streams_to_stream_impl::streams_to_stream_impl(size_t itemsize, size_t nstreams) + : sync_interpolator("streams_to_stream", + io_signature::make(nstreams, nstreams, itemsize), + io_signature::make(1, 1, itemsize), + nstreams) +{ +} - const char **inv = (const char **) &input_items[0]; - char *out = (char *) output_items[0]; - int nstreams = input_items.size(); +int streams_to_stream_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + size_t itemsize = output_signature()->sizeof_stream_item(0); - assert (noutput_items % nstreams == 0); - int ni = noutput_items / nstreams; + const char** inv = (const char**)&input_items[0]; + char* out = (char*)output_items[0]; + int nstreams = input_items.size(); - for (int i = 0; i < ni; i++){ - for (int j = 0; j < nstreams; j++){ - memcpy(out, inv[j], itemsize); - out += itemsize; - inv[j] += itemsize; - } - } + assert(noutput_items % nstreams == 0); + int ni = noutput_items / nstreams; - return noutput_items; + for (int i = 0; i < ni; i++) { + for (int j = 0; j < nstreams; j++) { + memcpy(out, inv[j], itemsize); + out += itemsize; + inv[j] += itemsize; + } } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/streams_to_stream_impl.h b/gr-blocks/lib/streams_to_stream_impl.h index e3ffde504c..3dec237c14 100644 --- a/gr-blocks/lib/streams_to_stream_impl.h +++ b/gr-blocks/lib/streams_to_stream_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/streams_to_stream.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API streams_to_stream_impl : public streams_to_stream - { - public: - streams_to_stream_impl(size_t itemsize, size_t nstreams); +class BLOCKS_API streams_to_stream_impl : public streams_to_stream +{ +public: + streams_to_stream_impl(size_t itemsize, size_t nstreams); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_STREAMS_TO_STREAM_IMPL_H */ diff --git a/gr-blocks/lib/streams_to_vector_impl.cc b/gr-blocks/lib/streams_to_vector_impl.cc index fc6c5c44a9..6c8eb2ac6f 100644 --- a/gr-blocks/lib/streams_to_vector_impl.cc +++ b/gr-blocks/lib/streams_to_vector_impl.cc @@ -28,41 +28,40 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - streams_to_vector::sptr streams_to_vector::make(size_t itemsize, size_t nstreams) - { - return gnuradio::get_initial_sptr(new streams_to_vector_impl(itemsize, nstreams)); - } - - streams_to_vector_impl::streams_to_vector_impl(size_t itemsize, size_t nstreams) - : sync_block ("streams_to_vector", - io_signature::make (nstreams, nstreams, itemsize), - io_signature::make (1, 1, nstreams * itemsize)) - { - } +streams_to_vector::sptr streams_to_vector::make(size_t itemsize, size_t nstreams) +{ + return gnuradio::get_initial_sptr(new streams_to_vector_impl(itemsize, nstreams)); +} - int - streams_to_vector_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - size_t itemsize = input_signature()->sizeof_stream_item(0); - int nstreams = input_items.size(); +streams_to_vector_impl::streams_to_vector_impl(size_t itemsize, size_t nstreams) + : sync_block("streams_to_vector", + io_signature::make(nstreams, nstreams, itemsize), + io_signature::make(1, 1, nstreams * itemsize)) +{ +} - const char **inv = (const char **) &input_items[0]; - char *out = (char *) output_items[0]; +int streams_to_vector_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + size_t itemsize = input_signature()->sizeof_stream_item(0); + int nstreams = input_items.size(); - for (int i = 0; i < noutput_items; i++){ - for (int j = 0; j < nstreams; j++){ - memcpy(out, inv[j], itemsize); - inv[j] += itemsize; - out += itemsize; - } - } + const char** inv = (const char**)&input_items[0]; + char* out = (char*)output_items[0]; - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + for (int j = 0; j < nstreams; j++) { + memcpy(out, inv[j], itemsize); + inv[j] += itemsize; + out += itemsize; + } } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/streams_to_vector_impl.h b/gr-blocks/lib/streams_to_vector_impl.h index 5590e416b2..841b8acd71 100644 --- a/gr-blocks/lib/streams_to_vector_impl.h +++ b/gr-blocks/lib/streams_to_vector_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/streams_to_vector.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API streams_to_vector_impl : public streams_to_vector - { - public: - streams_to_vector_impl(size_t itemsize, size_t nstreams); +class BLOCKS_API streams_to_vector_impl : public streams_to_vector +{ +public: + streams_to_vector_impl(size_t itemsize, size_t nstreams); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_STREAMS_TO_VECTOR_IMPL_H */ diff --git a/gr-blocks/lib/stretch_ff_impl.cc b/gr-blocks/lib/stretch_ff_impl.cc index 4d43d13d68..2d788c9461 100644 --- a/gr-blocks/lib/stretch_ff_impl.cc +++ b/gr-blocks/lib/stretch_ff_impl.cc @@ -28,57 +28,53 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - stretch_ff::sptr - stretch_ff::make(float lo, size_t vlen) - { - return gnuradio::get_initial_sptr - (new stretch_ff_impl(lo, vlen)); - } +stretch_ff::sptr stretch_ff::make(float lo, size_t vlen) +{ + return gnuradio::get_initial_sptr(new stretch_ff_impl(lo, vlen)); +} - stretch_ff_impl::stretch_ff_impl(float lo, size_t vlen) - : sync_block("stretch_ff", - io_signature::make(1, 1, vlen * sizeof(float)), - io_signature::make(1, 1, vlen * sizeof(float))), - d_lo(lo), d_vlen(vlen) - { - } +stretch_ff_impl::stretch_ff_impl(float lo, size_t vlen) + : sync_block("stretch_ff", + io_signature::make(1, 1, vlen * sizeof(float)), + io_signature::make(1, 1, vlen * sizeof(float))), + d_lo(lo), + d_vlen(vlen) +{ +} - stretch_ff_impl::~stretch_ff_impl() - { - } +stretch_ff_impl::~stretch_ff_impl() {} - int - stretch_ff_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float *)input_items[0]; - float *out = (float *)output_items[0]; +int stretch_ff_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + float* out = (float*)output_items[0]; - for(int count = 0; count < noutput_items; count++) { + for (int count = 0; count < noutput_items; count++) { float vmax = in[0] - d_lo; - for(unsigned int i = 1; i < d_vlen; i++) { - float vtmp = in[i] - d_lo; - if(vtmp > vmax) - vmax = vtmp; + for (unsigned int i = 1; i < d_vlen; i++) { + float vtmp = in[i] - d_lo; + if (vtmp > vmax) + vmax = vtmp; } - if(vmax != 0.0) - for(unsigned int i = 0; i < d_vlen; i++) - out[i] = d_lo * (1.0 - (in[i] - d_lo) / vmax); + if (vmax != 0.0) + for (unsigned int i = 0; i < d_vlen; i++) + out[i] = d_lo * (1.0 - (in[i] - d_lo) / vmax); else - for(unsigned int i = 0; i < d_vlen; i++) - out[i] = in[i]; + for (unsigned int i = 0; i < d_vlen; i++) + out[i] = in[i]; - in += d_vlen; + in += d_vlen; out += d_vlen; - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/stretch_ff_impl.h b/gr-blocks/lib/stretch_ff_impl.h index 69cf95ac73..c2228c93a6 100644 --- a/gr-blocks/lib/stretch_ff_impl.h +++ b/gr-blocks/lib/stretch_ff_impl.h @@ -26,28 +26,28 @@ #include <gnuradio/blocks/stretch_ff.h> namespace gr { - namespace blocks { +namespace blocks { - class stretch_ff_impl : public stretch_ff - { - private: - float d_lo; // the constant - size_t d_vlen; +class stretch_ff_impl : public stretch_ff +{ +private: + float d_lo; // the constant + size_t d_vlen; - public: - stretch_ff_impl(float lo, size_t vlen); - ~stretch_ff_impl(); +public: + stretch_ff_impl(float lo, size_t vlen); + ~stretch_ff_impl(); - float lo() const { return d_lo; } - void set_lo(float lo) { d_lo = lo; } - size_t vlen() const { return d_vlen; } + float lo() const { return d_lo; } + void set_lo(float lo) { d_lo = lo; } + size_t vlen() const { return d_vlen; } - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_STRETCH_FF_IMPL_H */ diff --git a/gr-blocks/lib/sub_impl.cc b/gr-blocks/lib/sub_impl.cc index 5d618d3467..67ca84ec36 100644 --- a/gr-blocks/lib/sub_impl.cc +++ b/gr-blocks/lib/sub_impl.cc @@ -30,80 +30,77 @@ #include <volk/volk.h> namespace gr { - namespace blocks { - - template <class T> - typename sub<T>::sptr sub<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new sub_impl<T> (vlen)); - } - - template <> - sub_impl<float>::sub_impl(size_t vlen) - : sync_block("sub_ff", - io_signature::make(1, -1, sizeof(float)*vlen), - io_signature::make(1, 1, sizeof(float)*vlen)), +namespace blocks { + +template <class T> +typename sub<T>::sptr sub<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new sub_impl<T>(vlen)); +} + +template <> +sub_impl<float>::sub_impl(size_t vlen) + : sync_block("sub_ff", + io_signature::make(1, -1, sizeof(float) * vlen), + io_signature::make(1, 1, sizeof(float) * vlen)), d_vlen(vlen) - { - const int alignment_multiple = - volk_get_alignment() / sizeof(float); - set_alignment(std::max(1, alignment_multiple)); - } - - template <> - int - sub_impl<float>::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float *out = (float*)output_items[0]; - - int ninputs = input_items.size(); - int noi = noutput_items*d_vlen; - - const float *in = (const float*)input_items[0]; - memcpy(out, in, noi*sizeof(float)); - for(int i = 1; i < ninputs; i++) { +{ + const int alignment_multiple = volk_get_alignment() / sizeof(float); + set_alignment(std::max(1, alignment_multiple)); +} + +template <> +int sub_impl<float>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float* out = (float*)output_items[0]; + + int ninputs = input_items.size(); + int noi = noutput_items * d_vlen; + + const float* in = (const float*)input_items[0]; + memcpy(out, in, noi * sizeof(float)); + for (int i = 1; i < ninputs; i++) { in = (const float*)input_items[i]; volk_32f_x2_subtract_32f(out, out, in, noi); - } - - return noutput_items; } - template <class T> - sub_impl<T> ::sub_impl(size_t vlen) - : sync_block ("sub", - io_signature::make (1, -1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), - d_vlen(vlen) - { - } + return noutput_items; +} - template <class T> - int - sub_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *) output_items[0]; +template <class T> +sub_impl<T>::sub_impl(size_t vlen) + : sync_block("sub", + io_signature::make(1, -1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), + d_vlen(vlen) +{ +} - int ninputs = input_items.size (); +template <class T> +int sub_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; - for (size_t i = 0; i < noutput_items*d_vlen; i++){ - T acc = ((T *) input_items[0])[i]; - for (int j = 1; j < ninputs; j++) - acc -= ((T *) input_items[j])[i]; + int ninputs = input_items.size(); - *optr++ = (T) acc; - } + for (size_t i = 0; i < noutput_items * d_vlen; i++) { + T acc = ((T*)input_items[0])[i]; + for (int j = 1; j < ninputs; j++) + acc -= ((T*)input_items[j])[i]; - return noutput_items; + *optr++ = (T)acc; } + return noutput_items; +} + template class sub<std::int16_t>; template class sub<std::int32_t>; template class sub<gr_complex>; template class sub<float>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/sub_impl.h b/gr-blocks/lib/sub_impl.h index 66e46995fd..97f4cf5156 100644 --- a/gr-blocks/lib/sub_impl.h +++ b/gr-blocks/lib/sub_impl.h @@ -27,22 +27,22 @@ #include <gnuradio/blocks/sub.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API sub_impl : public sub<T> - { - size_t d_vlen; +template <class T> +class BLOCKS_API sub_impl : public sub<T> +{ + size_t d_vlen; - public: - sub_impl (size_t vlen); +public: + sub_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* SUB_IMPL_H */ diff --git a/gr-blocks/lib/tag_debug_impl.cc b/gr-blocks/lib/tag_debug_impl.cc index a4c4c694b8..450e5f87fe 100644 --- a/gr-blocks/lib/tag_debug_impl.cc +++ b/gr-blocks/lib/tag_debug_impl.cc @@ -30,137 +30,128 @@ #include <iomanip> namespace gr { - namespace blocks { - - tag_debug::sptr - tag_debug::make(size_t sizeof_stream_item, - const std::string &name, - const std::string &key_filter) - { - return gnuradio::get_initial_sptr - (new tag_debug_impl(sizeof_stream_item, name, key_filter)); - } - - tag_debug_impl::tag_debug_impl(size_t sizeof_stream_item, - const std::string &name, - const std::string &key_filter) - : sync_block("tag_debug", - io_signature::make(1, -1, sizeof_stream_item), - io_signature::make(0, 0, 0)), - d_name(name), d_display(true) - { - set_key_filter(key_filter); - } - - tag_debug_impl::~tag_debug_impl() - { - } - - std::vector<tag_t> - tag_debug_impl::current_tags() - { - gr::thread::scoped_lock l(d_mutex); - return d_tags; - } - - int - tag_debug_impl::num_tags() - { - std::vector<tag_t> t; - get_tags_in_range(t, 0, 0, nitems_read(0)); - return static_cast<int>(t.size()); - } - - void - tag_debug_impl::set_display(bool d) - { - d_display = d; - } - - void - tag_debug_impl::set_key_filter(const std::string &key_filter) - { - if(key_filter == "") +namespace blocks { + +tag_debug::sptr tag_debug::make(size_t sizeof_stream_item, + const std::string& name, + const std::string& key_filter) +{ + return gnuradio::get_initial_sptr( + new tag_debug_impl(sizeof_stream_item, name, key_filter)); +} + +tag_debug_impl::tag_debug_impl(size_t sizeof_stream_item, + const std::string& name, + const std::string& key_filter) + : sync_block("tag_debug", + io_signature::make(1, -1, sizeof_stream_item), + io_signature::make(0, 0, 0)), + d_name(name), + d_display(true) +{ + set_key_filter(key_filter); +} + +tag_debug_impl::~tag_debug_impl() {} + +std::vector<tag_t> tag_debug_impl::current_tags() +{ + gr::thread::scoped_lock l(d_mutex); + return d_tags; +} + +int tag_debug_impl::num_tags() +{ + std::vector<tag_t> t; + get_tags_in_range(t, 0, 0, nitems_read(0)); + return static_cast<int>(t.size()); +} + +void tag_debug_impl::set_display(bool d) { d_display = d; } + +void tag_debug_impl::set_key_filter(const std::string& key_filter) +{ + if (key_filter == "") d_filter = pmt::PMT_NIL; - else + else d_filter = pmt::intern(key_filter); - } +} - std::string - tag_debug_impl::key_filter() const - { - return pmt::symbol_to_string(d_filter); - } +std::string tag_debug_impl::key_filter() const { return pmt::symbol_to_string(d_filter); } - int - tag_debug_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr::thread::scoped_lock l(d_mutex); - bool toprint = false; +int tag_debug_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr::thread::scoped_lock l(d_mutex); + bool toprint = false; - std::stringstream sout; - if(d_display) { + std::stringstream sout; + if (d_display) { sout << std::endl << "----------------------------------------------------------------------"; sout << std::endl << "Tag Debug: " << d_name << std::endl; - } + } - uint64_t abs_N, end_N; - for(size_t i = 0; i < input_items.size(); i++) { + uint64_t abs_N, end_N; + for (size_t i = 0; i < input_items.size(); i++) { abs_N = nitems_read(i); end_N = abs_N + (uint64_t)(noutput_items); d_tags.clear(); - if(pmt::is_null(d_filter)) - get_tags_in_range(d_tags, i, abs_N, end_N); + if (pmt::is_null(d_filter)) + get_tags_in_range(d_tags, i, abs_N, end_N); else - get_tags_in_range(d_tags, i, abs_N, end_N, d_filter); + get_tags_in_range(d_tags, i, abs_N, end_N, d_filter); - if(d_tags.size() > 0) { - toprint = true; + if (d_tags.size() > 0) { + toprint = true; } - if(d_display) { - sout << "Input Stream: " << std::setw(2) << std::setfill('0') - << i << std::setfill(' ') << std::endl; - for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) { - sout << std::setw(10) << "Offset: " << d_tags_itr->offset - << std::setw(10) << "Source: " - << (pmt::is_symbol(d_tags_itr->srcid) ? pmt::symbol_to_string(d_tags_itr->srcid) : "n/a") - << std::setw(10) << "Key: " << pmt::symbol_to_string(d_tags_itr->key) - << std::setw(10) << "Value: "; - sout << d_tags_itr->value << std::endl; - } + if (d_display) { + sout << "Input Stream: " << std::setw(2) << std::setfill('0') << i + << std::setfill(' ') << std::endl; + for (d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) { + sout << std::setw(10) << "Offset: " << d_tags_itr->offset << std::setw(10) + << "Source: " + << (pmt::is_symbol(d_tags_itr->srcid) + ? pmt::symbol_to_string(d_tags_itr->srcid) + : "n/a") + << std::setw(10) << "Key: " << pmt::symbol_to_string(d_tags_itr->key) + << std::setw(10) << "Value: "; + sout << d_tags_itr->value << std::endl; + } } - } + } - if(d_display) { + if (d_display) { sout << "----------------------------------------------------------------------"; sout << std::endl; - if(toprint) { - std::cout << sout.str(); + if (toprint) { + std::cout << sout.str(); } - } - - return noutput_items; } - void - tag_debug_impl::setup_rpc() - { + return noutput_items; +} + +void tag_debug_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - add_rpc_variable( - rpcbasic_sptr(new rpcbasic_register_get<tag_debug, int>( - alias(), "num. tags", - &tag_debug::num_tags, - pmt::from_long(0), pmt::from_long(10000), pmt::from_long(0), - "", "Number of Tags", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTSTRIP))); + add_rpc_variable(rpcbasic_sptr( + new rpcbasic_register_get<tag_debug, int>(alias(), + "num. tags", + &tag_debug::num_tags, + pmt::from_long(0), + pmt::from_long(10000), + pmt::from_long(0), + "", + "Number of Tags", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/tag_debug_impl.h b/gr-blocks/lib/tag_debug_impl.h index 1d28f123d3..6fad5761c8 100644 --- a/gr-blocks/lib/tag_debug_impl.h +++ b/gr-blocks/lib/tag_debug_impl.h @@ -28,39 +28,40 @@ #include <stddef.h> namespace gr { - namespace blocks { +namespace blocks { - class tag_debug_impl : public tag_debug - { - private: - std::string d_name; - std::vector<tag_t> d_tags; - std::vector<tag_t>::iterator d_tags_itr; - bool d_display; - pmt::pmt_t d_filter; - gr::thread::mutex d_mutex; +class tag_debug_impl : public tag_debug +{ +private: + std::string d_name; + std::vector<tag_t> d_tags; + std::vector<tag_t>::iterator d_tags_itr; + bool d_display; + pmt::pmt_t d_filter; + gr::thread::mutex d_mutex; - public: - tag_debug_impl(size_t sizeof_stream_item, const std::string &name, - const std::string &key_filter=""); - ~tag_debug_impl(); +public: + tag_debug_impl(size_t sizeof_stream_item, + const std::string& name, + const std::string& key_filter = ""); + ~tag_debug_impl(); - void setup_rpc(); + void setup_rpc(); - std::vector<tag_t> current_tags(); - int num_tags(); + std::vector<tag_t> current_tags(); + int num_tags(); - void set_display(bool d); + void set_display(bool d); - void set_key_filter(const std::string &key_filter); - std::string key_filter() const; + void set_key_filter(const std::string& key_filter); + std::string key_filter() const; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_TAG_DEBUG_IMPL_H */ diff --git a/gr-blocks/lib/tag_gate_impl.cc b/gr-blocks/lib/tag_gate_impl.cc index ad55c8af9a..08390beca2 100644 --- a/gr-blocks/lib/tag_gate_impl.cc +++ b/gr-blocks/lib/tag_gate_impl.cc @@ -28,87 +28,81 @@ #include "tag_gate_impl.h" namespace gr { - namespace blocks { +namespace blocks { - tag_gate::sptr - tag_gate::make(size_t item_size, bool propagate_tags) - { - return gnuradio::get_initial_sptr (new tag_gate_impl(item_size, propagate_tags)); - } +tag_gate::sptr tag_gate::make(size_t item_size, bool propagate_tags) +{ + return gnuradio::get_initial_sptr(new tag_gate_impl(item_size, propagate_tags)); +} - tag_gate_impl::tag_gate_impl(size_t item_size, bool propagate_tags) - : gr::sync_block("tag_gate", - gr::io_signature::make(1, 1, item_size), - gr::io_signature::make(1, 1, item_size)), +tag_gate_impl::tag_gate_impl(size_t item_size, bool propagate_tags) + : gr::sync_block("tag_gate", + gr::io_signature::make(1, 1, item_size), + gr::io_signature::make(1, 1, item_size)), d_item_size(item_size), d_propagate_tags(propagate_tags), d_single_key_set(false) - { - if (!d_propagate_tags) { - set_tag_propagation_policy(TPP_DONT); - } - d_single_key = pmt::PMT_NIL; +{ + if (!d_propagate_tags) { + set_tag_propagation_policy(TPP_DONT); } + d_single_key = pmt::PMT_NIL; +} - tag_gate_impl::~tag_gate_impl() - { - } +tag_gate_impl::~tag_gate_impl() {} - void tag_gate_impl::set_propagation(bool propagate_tags) - { - d_propagate_tags = propagate_tags; +void tag_gate_impl::set_propagation(bool propagate_tags) +{ + d_propagate_tags = propagate_tags; - if (propagate_tags) { + if (propagate_tags) { set_tag_propagation_policy(TPP_ALL_TO_ALL); - } else { + } else { set_tag_propagation_policy(TPP_DONT); - } } +} - void tag_gate_impl::set_single_key(const std::string &single_key) - { - if(single_key == "") { +void tag_gate_impl::set_single_key(const std::string& single_key) +{ + if (single_key == "") { d_single_key = pmt::PMT_NIL; d_single_key_set = false; - } - else { + } else { d_single_key = pmt::intern(single_key); d_single_key_set = true; - } } +} - std::string tag_gate_impl::single_key() const - { - if(pmt::equal(d_single_key, pmt::PMT_NIL)) { +std::string tag_gate_impl::single_key() const +{ + if (pmt::equal(d_single_key, pmt::PMT_NIL)) { return ""; - } - else { + } else { return pmt::symbol_to_string(d_single_key); - } } +} - int - tag_gate_impl::work(int noutput_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]; - std::vector<tag_t> tags; +int tag_gate_impl::work(int noutput_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]; + std::vector<tag_t> tags; - memcpy((void *) out, (void *) in, d_item_size * noutput_items); + memcpy((void*)out, (void*)in, d_item_size * noutput_items); - if (d_single_key_set && (!d_propagate_tags)) { + if (d_single_key_set && (!d_propagate_tags)) { get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0) + noutput_items); - for (unsigned int i=0; i < tags.size(); i++) { - if (!pmt::equal(tags[i].key, d_single_key)) - add_item_tag(0, tags[i].offset, tags[i].key, tags[i].value, tags[i].srcid); + for (unsigned int i = 0; i < tags.size(); i++) { + if (!pmt::equal(tags[i].key, d_single_key)) + add_item_tag( + 0, tags[i].offset, tags[i].key, tags[i].value, tags[i].srcid); } - } - - return noutput_items; } - } /* namespace blocks */ -} /* namespace gr */ + return noutput_items; +} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/tag_gate_impl.h b/gr-blocks/lib/tag_gate_impl.h index 129fb78cb8..62dbc9a251 100644 --- a/gr-blocks/lib/tag_gate_impl.h +++ b/gr-blocks/lib/tag_gate_impl.h @@ -26,33 +26,32 @@ #include <gnuradio/blocks/tag_gate.h> namespace gr { - namespace blocks { +namespace blocks { - class tag_gate_impl : public tag_gate - { - private: - size_t d_item_size; - bool d_propagate_tags; - bool d_single_key_set; +class tag_gate_impl : public tag_gate +{ +private: + size_t d_item_size; + bool d_propagate_tags; + bool d_single_key_set; - pmt::pmt_t d_single_key; + pmt::pmt_t d_single_key; - public: - tag_gate_impl(size_t item_size, bool propagate_tags); - ~tag_gate_impl(); +public: + tag_gate_impl(size_t item_size, bool propagate_tags); + ~tag_gate_impl(); - void set_propagation(bool propagate_tags); + void set_propagation(bool propagate_tags); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - void set_single_key(const std::string &single_key); - std::string single_key() const; - }; + void set_single_key(const std::string& single_key); + std::string single_key() const; +}; - } // namespace blocks +} // namespace blocks } // namespace gr #endif /* INCLUDED_BLOCKS_TAG_GATE_IMPL_H */ - diff --git a/gr-blocks/lib/tag_share_impl.cc b/gr-blocks/lib/tag_share_impl.cc index 26a54dbf8c..f8a1129704 100644 --- a/gr-blocks/lib/tag_share_impl.cc +++ b/gr-blocks/lib/tag_share_impl.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ -/* +/* * Copyright 2017 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, @@ -28,52 +28,51 @@ #include "tag_share_impl.h" namespace gr { - namespace blocks { +namespace blocks { - tag_share::sptr - tag_share::make(size_t sizeof_io_item, size_t sizeof_share_item, size_t vlen) - { - return gnuradio::get_initial_sptr - (new tag_share_impl(sizeof_io_item, sizeof_share_item, vlen)); - } +tag_share::sptr +tag_share::make(size_t sizeof_io_item, size_t sizeof_share_item, size_t vlen) +{ + return gnuradio::get_initial_sptr( + new tag_share_impl(sizeof_io_item, sizeof_share_item, vlen)); +} - /* - * The private constructor - */ - tag_share_impl::tag_share_impl(size_t sizeof_io_item, size_t sizeof_share_item, size_t vlen) - : gr::sync_block("tag_share", - gr::io_signature::make2(2, 2, sizeof_io_item*vlen, sizeof_share_item*vlen), - gr::io_signature::make(1, 1, sizeof_io_item*vlen)), - d_sizeof_io_item(sizeof_io_item), - d_vlen(vlen) - { - // This is the entire premise of the block -- to have the GNU Radio runtime - // propagate all the tags from Input 0 and Input 1 to Output 0. - set_tag_propagation_policy(TPP_ALL_TO_ALL); - } +/* + * The private constructor + */ +tag_share_impl::tag_share_impl(size_t sizeof_io_item, + size_t sizeof_share_item, + size_t vlen) + : gr::sync_block( + "tag_share", + gr::io_signature::make2(2, 2, sizeof_io_item * vlen, sizeof_share_item * vlen), + gr::io_signature::make(1, 1, sizeof_io_item * vlen)), + d_sizeof_io_item(sizeof_io_item), + d_vlen(vlen) +{ + // This is the entire premise of the block -- to have the GNU Radio runtime + // propagate all the tags from Input 0 and Input 1 to Output 0. + set_tag_propagation_policy(TPP_ALL_TO_ALL); +} - /* - * Our virtual destructor. - */ - tag_share_impl::~tag_share_impl() - { - } +/* + * Our virtual destructor. + */ +tag_share_impl::~tag_share_impl() {} - int - tag_share_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const void *in = (const void *) input_items[0]; - void *out = (void *) output_items[0]; +int tag_share_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const void* in = (const void*)input_items[0]; + void* out = (void*)output_items[0]; - // Input 0 passes through to Output 0 - memcpy(out, in, d_sizeof_io_item*d_vlen*noutput_items); + // Input 0 passes through to Output 0 + memcpy(out, in, d_sizeof_io_item * d_vlen * noutput_items); - // Tell runtime system how many output items we produced. - return noutput_items; - } + // Tell runtime system how many output items we produced. + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ - diff --git a/gr-blocks/lib/tag_share_impl.h b/gr-blocks/lib/tag_share_impl.h index e5df8e3a0c..f91b0de61f 100644 --- a/gr-blocks/lib/tag_share_impl.h +++ b/gr-blocks/lib/tag_share_impl.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ -/* +/* * Copyright 2017 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, @@ -26,26 +26,25 @@ #include <gnuradio/blocks/tag_share.h> namespace gr { - namespace blocks { - - class tag_share_impl : public tag_share - { - private: - size_t d_sizeof_io_item; - size_t d_vlen; - - public: - tag_share_impl(size_t sizeof_io_item, size_t sizeof_share_item, size_t vlen); - ~tag_share_impl(); - - // Where all the action really happens - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } // namespace blocks +namespace blocks { + +class tag_share_impl : public tag_share +{ +private: + size_t d_sizeof_io_item; + size_t d_vlen; + +public: + tag_share_impl(size_t sizeof_io_item, size_t sizeof_share_item, size_t vlen); + ~tag_share_impl(); + + // Where all the action really happens + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} // namespace blocks } // namespace gr #endif /* INCLUDED_BLOCKS_TAG_SHARE_IMPL_H */ - diff --git a/gr-blocks/lib/tagged_file_sink_impl.cc b/gr-blocks/lib/tagged_file_sink_impl.cc index e81209ab6e..83b0432253 100644 --- a/gr-blocks/lib/tagged_file_sink_impl.cc +++ b/gr-blocks/lib/tagged_file_sink_impl.cc @@ -38,198 +38,193 @@ #endif #ifdef O_BINARY -#define OUR_O_BINARY O_BINARY +#define OUR_O_BINARY O_BINARY #else -#define OUR_O_BINARY 0 +#define OUR_O_BINARY 0 #endif // should be handled via configure #ifdef O_LARGEFILE -#define OUR_O_LARGEFILE O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE #else -#define OUR_O_LARGEFILE 0 +#define OUR_O_LARGEFILE 0 #endif namespace gr { - namespace blocks { - - tagged_file_sink::sptr - tagged_file_sink::make(size_t itemsize, double samp_rate) - { - return gnuradio::get_initial_sptr - (new tagged_file_sink_impl(itemsize, samp_rate)); - } - - tagged_file_sink_impl::tagged_file_sink_impl(size_t itemsize, double samp_rate) - : sync_block("tagged_file_sink", - io_signature::make(1, 1, itemsize), - io_signature::make(0, 0, 0)), - d_itemsize (itemsize), d_n(0), d_sample_rate(samp_rate) - { - d_state = NOT_IN_BURST; - d_last_N = 0; - d_timeval = 0; +namespace blocks { + +tagged_file_sink::sptr tagged_file_sink::make(size_t itemsize, double samp_rate) +{ + return gnuradio::get_initial_sptr(new tagged_file_sink_impl(itemsize, samp_rate)); +} + +tagged_file_sink_impl::tagged_file_sink_impl(size_t itemsize, double samp_rate) + : sync_block("tagged_file_sink", + io_signature::make(1, 1, itemsize), + io_signature::make(0, 0, 0)), + d_itemsize(itemsize), + d_n(0), + d_sample_rate(samp_rate) +{ + d_state = NOT_IN_BURST; + d_last_N = 0; + d_timeval = 0; +} + +tagged_file_sink_impl::~tagged_file_sink_impl() {} + +int tagged_file_sink_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + char* inbuf = (char*)input_items[0]; + + uint64_t start_N = nitems_read(0); + uint64_t end_N = start_N + (uint64_t)(noutput_items); + pmt::pmt_t bkey = pmt::string_to_symbol("burst"); + pmt::pmt_t tkey = pmt::string_to_symbol("rx_time"); // use gr_tags::key_time + + std::vector<tag_t> all_tags; + get_tags_in_range(all_tags, 0, start_N, end_N); + + std::sort(all_tags.begin(), all_tags.end(), tag_t::offset_compare); + + std::vector<tag_t>::iterator vitr = all_tags.begin(); + + // Look for a time tag and initialize d_timeval. + std::vector<tag_t> time_tags_outer; + get_tags_in_range(time_tags_outer, 0, start_N, end_N, tkey); + if (time_tags_outer.size() > 0) { + const tag_t tag = time_tags_outer[0]; + uint64_t offset = tag.offset; + pmt::pmt_t time = tag.value; + uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); + double tfrac = pmt::to_double(pmt::tuple_ref(time, 1)); + double delta = (double)offset / d_sample_rate; + d_timeval = (double)tsecs + tfrac + delta; + d_last_N = offset; } - tagged_file_sink_impl::~tagged_file_sink_impl() - { + int idx = 0, idx_stop = 0; + while (idx < noutput_items) { + if (d_state == NOT_IN_BURST) { + while (vitr != all_tags.end()) { + if ((pmt::eqv((*vitr).key, bkey)) && pmt::is_true((*vitr).value)) { + + uint64_t N = (*vitr).offset; + idx = (int)(N - start_N); + + // std::cout << std::endl << "Found start of burst: " + // << idx << ", " << N << std::endl; + + // Find time burst occurred by getting latest time tag and + // extrapolating to new time based on sample rate of this block. + std::vector<tag_t> time_tags; + // get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); + get_tags_in_range(time_tags, 0, d_last_N, N, tkey); + if (time_tags.size() > 0) { + const tag_t tag = time_tags[time_tags.size() - 1]; + + uint64_t time_nitems = tag.offset; + + // Get time based on last time tag from USRP + pmt::pmt_t time = tag.value; + uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); + double tfrac = pmt::to_double(pmt::tuple_ref(time, 1)); + + // Get new time from last time tag + difference in time to when + // burst tag occurred based on the sample rate + double delta = (double)(N - time_nitems) / d_sample_rate; + d_timeval = (double)tsecs + tfrac + delta; + + // std::cout.setf(std::ios::fixed, std::ios::floatfield); + // std::cout.precision(8); + // std::cout << "Time found: " << (double)tsecs + tfrac << + // std::endl; std::cout << " time: " << d_timeval << std::endl; + // std::cout << " time at N = " << time_nitems << " burst N = " + // << N << std::endl; + } else { + // if no time tag, use last seen tag and update time based on + // sample rate of the block + d_timeval += (double)(N - d_last_N) / d_sample_rate; + // std::cout << "Time not found" << std::endl; + // std::cout << " time: " << d_timeval << std::endl; + } + d_last_N = N; + + std::stringstream filename; + filename.setf(std::ios::fixed, std::ios::floatfield); + filename.precision(8); + filename << "file" << unique_id() << "_" << d_n << "_" << d_timeval + << ".dat"; + d_n++; + + int fd; + if ((fd = ::open(filename.str().c_str(), + O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE | + OUR_O_BINARY, + 0664)) < 0) { + perror(filename.str().c_str()); + return -1; + } + + // FIXME: + // if((d_handle = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL) { + if ((d_handle = fdopen(fd, "wb")) == NULL) { + perror(filename.str().c_str()); + ::close(fd); // don't leak file descriptor if fdopen fails. + } + + // std::cout << "Created new file: " << filename.str() << std::endl; + + d_state = IN_BURST; + break; + } + + vitr++; + } + if (d_state == NOT_IN_BURST) + return noutput_items; + } else { // In burst + while (vitr != all_tags.end()) { + if ((pmt::eqv((*vitr).key, bkey)) && pmt::is_false((*vitr).value)) { + uint64_t N = (*vitr).offset; + idx_stop = (int)N - start_N; + + // std::cout << "Found end of burst: " + // << idx_stop << ", " << N << std::endl; + + int count = fwrite( + &inbuf[d_itemsize * idx], d_itemsize, idx_stop - idx, d_handle); + if (count == 0) { + if (ferror(d_handle)) { + perror("tagged_file_sink: error writing file"); + } + } + idx = idx_stop; + d_state = NOT_IN_BURST; + vitr++; + fclose(d_handle); + break; + } else { + vitr++; + } + } + if (d_state == IN_BURST) { + int count = fwrite( + &inbuf[d_itemsize * idx], d_itemsize, noutput_items - idx, d_handle); + if (count == 0) { + if (ferror(d_handle)) { + perror("tagged_file_sink: error writing file"); + } + } + idx = noutput_items; + } + } } - int - tagged_file_sink_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - char *inbuf = (char*)input_items[0]; - - uint64_t start_N = nitems_read(0); - uint64_t end_N = start_N + (uint64_t)(noutput_items); - pmt::pmt_t bkey = pmt::string_to_symbol("burst"); - pmt::pmt_t tkey = pmt::string_to_symbol("rx_time"); // use gr_tags::key_time - - std::vector<tag_t> all_tags; - get_tags_in_range(all_tags, 0, start_N, end_N); - - std::sort(all_tags.begin(), all_tags.end(), tag_t::offset_compare); - - std::vector<tag_t>::iterator vitr = all_tags.begin(); - - // Look for a time tag and initialize d_timeval. - std::vector<tag_t> time_tags_outer; - get_tags_in_range(time_tags_outer, 0, start_N, end_N, tkey); - if(time_tags_outer.size() > 0) { - const tag_t tag = time_tags_outer[0]; - uint64_t offset = tag.offset; - pmt::pmt_t time = tag.value; - uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); - double tfrac = pmt::to_double(pmt::tuple_ref(time, 1)); - double delta = (double)offset / d_sample_rate; - d_timeval = (double)tsecs + tfrac + delta; - d_last_N = offset; - } - - int idx = 0, idx_stop = 0; - while(idx < noutput_items) { - if(d_state == NOT_IN_BURST) { - while(vitr != all_tags.end()) { - if((pmt::eqv((*vitr).key, bkey)) && - pmt::is_true((*vitr).value)) { - - uint64_t N = (*vitr).offset; - idx = (int)(N - start_N); - - //std::cout << std::endl << "Found start of burst: " - // << idx << ", " << N << std::endl; - - // Find time burst occurred by getting latest time tag and extrapolating - // to new time based on sample rate of this block. - std::vector<tag_t> time_tags; - //get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); - get_tags_in_range(time_tags, 0, d_last_N, N, tkey); - if(time_tags.size() > 0) { - const tag_t tag = time_tags[time_tags.size()-1]; - - uint64_t time_nitems = tag.offset; - - // Get time based on last time tag from USRP - pmt::pmt_t time = tag.value; - uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); - double tfrac = pmt::to_double(pmt::tuple_ref(time, 1)); - - // Get new time from last time tag + difference in time to when - // burst tag occurred based on the sample rate - double delta = (double)(N - time_nitems) / d_sample_rate; - d_timeval = (double)tsecs + tfrac + delta; - - //std::cout.setf(std::ios::fixed, std::ios::floatfield); - //std::cout.precision(8); - //std::cout << "Time found: " << (double)tsecs + tfrac << std::endl; - //std::cout << " time: " << d_timeval << std::endl; - //std::cout << " time at N = " << time_nitems << " burst N = " << N << std::endl; - } - else { - // if no time tag, use last seen tag and update time based on - // sample rate of the block - d_timeval += (double)(N - d_last_N) / d_sample_rate; - //std::cout << "Time not found" << std::endl; - //std::cout << " time: " << d_timeval << std::endl; - } - d_last_N = N; - - std::stringstream filename; - filename.setf(std::ios::fixed, std::ios::floatfield); - filename.precision(8); - filename << "file" << unique_id() << "_" << d_n << "_" << d_timeval << ".dat"; - d_n++; - - int fd; - if((fd = ::open(filename.str().c_str(), - O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, - 0664)) < 0){ - perror(filename.str().c_str()); - return -1; - } - - // FIXME: - //if((d_handle = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL) { - if((d_handle = fdopen (fd, "wb")) == NULL) { - perror(filename.str().c_str()); - ::close(fd); // don't leak file descriptor if fdopen fails. - } - - //std::cout << "Created new file: " << filename.str() << std::endl; - - d_state = IN_BURST; - break; - } - - vitr++; - } - if(d_state == NOT_IN_BURST) - return noutput_items; - } - else { // In burst - while(vitr != all_tags.end()) { - if((pmt::eqv((*vitr).key, bkey)) && - pmt::is_false((*vitr).value)) { - uint64_t N = (*vitr).offset; - idx_stop = (int)N - start_N; - - //std::cout << "Found end of burst: " - // << idx_stop << ", " << N << std::endl; - - int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, - idx_stop-idx, d_handle); - if(count == 0) { - if(ferror(d_handle)) { - perror("tagged_file_sink: error writing file"); - } - } - idx = idx_stop; - d_state = NOT_IN_BURST; - vitr++; - fclose(d_handle); - break; - } - else { - vitr++; - } - } - if(d_state == IN_BURST) { - int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, - noutput_items-idx, d_handle); - if (count == 0) { - if(ferror(d_handle)) { - perror("tagged_file_sink: error writing file"); - } - } - idx = noutput_items; - } - } - } - - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/tagged_file_sink_impl.h b/gr-blocks/lib/tagged_file_sink_impl.h index 7b1d43e641..836f46dbca 100644 --- a/gr-blocks/lib/tagged_file_sink_impl.h +++ b/gr-blocks/lib/tagged_file_sink_impl.h @@ -24,37 +24,34 @@ #define INCLUDED_GR_TAGGED_FILE_SINK_IMPL_H #include <gnuradio/blocks/tagged_file_sink.h> -#include <cstdio> // for FILE +#include <cstdio> // for FILE namespace gr { - namespace blocks { - - class tagged_file_sink_impl : public tagged_file_sink - { - private: - enum { - NOT_IN_BURST = 0, - IN_BURST - }; - - size_t d_itemsize; - int d_state; - FILE *d_handle; - int d_n; - double d_sample_rate; - uint64_t d_last_N; - double d_timeval; - - public: - tagged_file_sink_impl(size_t itemsize, double samp_rate); - ~tagged_file_sink_impl(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class tagged_file_sink_impl : public tagged_file_sink +{ +private: + enum { NOT_IN_BURST = 0, IN_BURST }; + + size_t d_itemsize; + int d_state; + FILE* d_handle; + int d_n; + double d_sample_rate; + uint64_t d_last_N; + double d_timeval; + +public: + tagged_file_sink_impl(size_t itemsize, double samp_rate); + ~tagged_file_sink_impl(); + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/tagged_stream_align_impl.cc b/gr-blocks/lib/tagged_stream_align_impl.cc index 80b5286278..c2050e1556 100644 --- a/gr-blocks/lib/tagged_stream_align_impl.cc +++ b/gr-blocks/lib/tagged_stream_align_impl.cc @@ -28,60 +28,59 @@ #include "tagged_stream_align_impl.h" namespace gr { - namespace blocks { +namespace blocks { - tagged_stream_align::sptr - tagged_stream_align::make(size_t itemsize, const std::string &lengthtagname) - { - return gnuradio::get_initial_sptr (new tagged_stream_align_impl(itemsize, lengthtagname)); - } +tagged_stream_align::sptr tagged_stream_align::make(size_t itemsize, + const std::string& lengthtagname) +{ + return gnuradio::get_initial_sptr( + new tagged_stream_align_impl(itemsize, lengthtagname)); +} - tagged_stream_align_impl::tagged_stream_align_impl(size_t itemsize, const std::string &lengthtagname) - : block("tagged_stream_align", - io_signature::make(1, 1, itemsize), - io_signature::make(1, 1, itemsize)), - d_itemsize(itemsize), - d_lengthtag(pmt::mp(lengthtagname)), - d_have_sync(false) - { - set_tag_propagation_policy(TPP_DONT); - } +tagged_stream_align_impl::tagged_stream_align_impl(size_t itemsize, + const std::string& lengthtagname) + : block("tagged_stream_align", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize)), + d_itemsize(itemsize), + d_lengthtag(pmt::mp(lengthtagname)), + d_have_sync(false) +{ + set_tag_propagation_policy(TPP_DONT); +} - tagged_stream_align_impl::~tagged_stream_align_impl() - { - } +tagged_stream_align_impl::~tagged_stream_align_impl() {} - int - tagged_stream_align_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - std::vector<tag_t> tags; - if(d_have_sync){ +int tagged_stream_align_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + std::vector<tag_t> tags; + if (d_have_sync) { int ncp = std::min(noutput_items, ninput_items[0]); get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0) + noutput_items); - for(size_t i=0; i<tags.size(); i++){ + for (size_t i = 0; i < tags.size(); i++) { gr::tag_t t = tags[i]; int offset = (nitems_read(0) - nitems_written(0)); t.offset -= offset; - add_item_tag(0,t); - } - memcpy(output_items[0], input_items[0], ncp*d_itemsize); + add_item_tag(0, t); + } + memcpy(output_items[0], input_items[0], ncp * d_itemsize); consume_each(ncp); return ncp; - } else { - get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0) + ninput_items[0], d_lengthtag); - if(tags.size() > 0){ + } else { + get_tags_in_range( + tags, 0, nitems_read(0), nitems_read(0) + ninput_items[0], d_lengthtag); + if (tags.size() > 0) { d_have_sync = true; - consume_each( tags[0].offset - nitems_read(0) ); + consume_each(tags[0].offset - nitems_read(0)); } else { consume_each(ninput_items[0]); } return 0; - } } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ - diff --git a/gr-blocks/lib/tagged_stream_align_impl.h b/gr-blocks/lib/tagged_stream_align_impl.h index 0481f88d5c..8b203115c2 100644 --- a/gr-blocks/lib/tagged_stream_align_impl.h +++ b/gr-blocks/lib/tagged_stream_align_impl.h @@ -27,27 +27,26 @@ #include <gnuradio/blocks/tagged_stream_align.h> namespace gr { - namespace blocks { - - class tagged_stream_align_impl : public tagged_stream_align - { - private: - size_t d_itemsize; - pmt::pmt_t d_lengthtag; - bool d_have_sync; - - public: - tagged_stream_align_impl(size_t itemsize, const std::string &lengthtagname); - ~tagged_stream_align_impl(); - - int general_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 blocks { + +class tagged_stream_align_impl : public tagged_stream_align +{ +private: + size_t d_itemsize; + pmt::pmt_t d_lengthtag; + bool d_have_sync; + +public: + tagged_stream_align_impl(size_t itemsize, const std::string& lengthtagname); + ~tagged_stream_align_impl(); + + int general_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 - diff --git a/gr-blocks/lib/tagged_stream_multiply_length_impl.cc b/gr-blocks/lib/tagged_stream_multiply_length_impl.cc index 266b967e69..96d77401ae 100644 --- a/gr-blocks/lib/tagged_stream_multiply_length_impl.cc +++ b/gr-blocks/lib/tagged_stream_multiply_length_impl.cc @@ -28,62 +28,66 @@ #include "tagged_stream_multiply_length_impl.h" namespace gr { - namespace blocks { +namespace blocks { - tagged_stream_multiply_length::sptr - tagged_stream_multiply_length::make(size_t itemsize, const std::string &lengthtagname, double scalar) - { - return gnuradio::get_initial_sptr (new tagged_stream_multiply_length_impl(itemsize, lengthtagname, scalar)); - } +tagged_stream_multiply_length::sptr tagged_stream_multiply_length::make( + size_t itemsize, const std::string& lengthtagname, double scalar) +{ + return gnuradio::get_initial_sptr( + new tagged_stream_multiply_length_impl(itemsize, lengthtagname, scalar)); +} - tagged_stream_multiply_length_impl::tagged_stream_multiply_length_impl(size_t itemsize, const std::string &lengthtagname, double scalar) - : block("tagged_stream_multiply_length", - io_signature::make(1, 1, itemsize), - io_signature::make(1, 1, itemsize)), - d_lengthtag(pmt::mp(lengthtagname)), - d_scalar(scalar), - d_itemsize(itemsize) - { - set_tag_propagation_policy(TPP_DONT); - set_relative_rate(1, 1); - message_port_register_in(pmt::intern("set_scalar")); - set_msg_handler(pmt::intern("set_scalar"), +tagged_stream_multiply_length_impl::tagged_stream_multiply_length_impl( + size_t itemsize, const std::string& lengthtagname, double scalar) + : block("tagged_stream_multiply_length", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize)), + d_lengthtag(pmt::mp(lengthtagname)), + d_scalar(scalar), + d_itemsize(itemsize) +{ + set_tag_propagation_policy(TPP_DONT); + set_relative_rate(1, 1); + message_port_register_in(pmt::intern("set_scalar")); + set_msg_handler( + pmt::intern("set_scalar"), boost::bind(&tagged_stream_multiply_length_impl::set_scalar_pmt, this, _1)); - } +} - tagged_stream_multiply_length_impl::~tagged_stream_multiply_length_impl() - { - } +tagged_stream_multiply_length_impl::~tagged_stream_multiply_length_impl() {} - int - tagged_stream_multiply_length_impl::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const void* in = input_items[0]; - void* out = output_items[0]; +int tagged_stream_multiply_length_impl::general_work( + int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const void* in = input_items[0]; + void* out = output_items[0]; - // move data across ( wasteful memcopy :< ) - memcpy(out, in, noutput_items*d_itemsize); + // move data across ( wasteful memcopy :< ) + memcpy(out, in, noutput_items * d_itemsize); - // move and update tags - std::vector<tag_t> tags; - get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0)+noutput_items); - for(size_t i=0; i<tags.size(); i++){ - if(pmt::eqv( tags[i].key , d_lengthtag)){ - // propagate with value update (scaled) - add_item_tag(0, tags[i].offset, tags[i].key, pmt::from_long(pmt::to_long(tags[i].value) * d_scalar), tags[i].srcid ); - } else { - // propagate unmodified - add_item_tag(0, tags[i].offset, tags[i].key, tags[i].value, tags[i].srcid ); - } + // move and update tags + std::vector<tag_t> tags; + get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0) + noutput_items); + for (size_t i = 0; i < tags.size(); i++) { + if (pmt::eqv(tags[i].key, d_lengthtag)) { + // propagate with value update (scaled) + add_item_tag(0, + tags[i].offset, + tags[i].key, + pmt::from_long(pmt::to_long(tags[i].value) * d_scalar), + tags[i].srcid); + } else { + // propagate unmodified + add_item_tag(0, tags[i].offset, tags[i].key, tags[i].value, tags[i].srcid); } - - consume_each(noutput_items); - return noutput_items; } - } /* namespace blocks */ -} /* namespace gr */ + consume_each(noutput_items); + return noutput_items; +} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/tagged_stream_multiply_length_impl.h b/gr-blocks/lib/tagged_stream_multiply_length_impl.h index 5d61650369..f54c71b3c7 100644 --- a/gr-blocks/lib/tagged_stream_multiply_length_impl.h +++ b/gr-blocks/lib/tagged_stream_multiply_length_impl.h @@ -27,36 +27,32 @@ #include <gnuradio/blocks/tagged_stream_multiply_length.h> namespace gr { - namespace blocks { +namespace blocks { - class tagged_stream_multiply_length_impl : public tagged_stream_multiply_length - { - private: - pmt::pmt_t d_lengthtag; - double d_scalar; - size_t d_itemsize; +class tagged_stream_multiply_length_impl : public tagged_stream_multiply_length +{ +private: + pmt::pmt_t d_lengthtag; + double d_scalar; + size_t d_itemsize; - public: - tagged_stream_multiply_length_impl(size_t itemsize, const std::string &lengthtagname, double scalar); - ~tagged_stream_multiply_length_impl(); +public: + tagged_stream_multiply_length_impl(size_t itemsize, + const std::string& lengthtagname, + double scalar); + ~tagged_stream_multiply_length_impl(); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); - void set_scalar(double scalar){ - d_scalar = scalar; - } + void set_scalar(double scalar) { d_scalar = scalar; } - void set_scalar_pmt(pmt::pmt_t msg){ - set_scalar(pmt::to_double(msg)); - } + void set_scalar_pmt(pmt::pmt_t msg) { set_scalar(pmt::to_double(msg)); } +}; - }; - - } // namespace blocks +} // namespace blocks } // namespace gr #endif - diff --git a/gr-blocks/lib/tagged_stream_mux_impl.cc b/gr-blocks/lib/tagged_stream_mux_impl.cc index 90587639ce..1742340d89 100644 --- a/gr-blocks/lib/tagged_stream_mux_impl.cc +++ b/gr-blocks/lib/tagged_stream_mux_impl.cc @@ -28,73 +28,71 @@ #include "tagged_stream_mux_impl.h" namespace gr { - namespace blocks { +namespace blocks { - tagged_stream_mux::sptr - tagged_stream_mux::make(size_t itemsize, const std::string &lengthtagname, - unsigned int tag_preserve_head_pos) - { - return gnuradio::get_initial_sptr - (new tagged_stream_mux_impl(itemsize, lengthtagname, - tag_preserve_head_pos)); - } +tagged_stream_mux::sptr tagged_stream_mux::make(size_t itemsize, + const std::string& lengthtagname, + unsigned int tag_preserve_head_pos) +{ + return gnuradio::get_initial_sptr( + new tagged_stream_mux_impl(itemsize, lengthtagname, tag_preserve_head_pos)); +} - tagged_stream_mux_impl::tagged_stream_mux_impl(size_t itemsize, const std::string &lengthtagname, - unsigned int tag_preserve_head_pos) - : tagged_stream_block("tagged_stream_mux", - io_signature::make(1, -1, itemsize), - io_signature::make(1, 1, itemsize), - lengthtagname), - d_itemsize(itemsize), - d_tag_preserve_head_pos(tag_preserve_head_pos) - { - set_tag_propagation_policy(TPP_DONT); - } +tagged_stream_mux_impl::tagged_stream_mux_impl(size_t itemsize, + const std::string& lengthtagname, + unsigned int tag_preserve_head_pos) + : tagged_stream_block("tagged_stream_mux", + io_signature::make(1, -1, itemsize), + io_signature::make(1, 1, itemsize), + lengthtagname), + d_itemsize(itemsize), + d_tag_preserve_head_pos(tag_preserve_head_pos) +{ + set_tag_propagation_policy(TPP_DONT); +} - tagged_stream_mux_impl::~tagged_stream_mux_impl() - { - } +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::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; +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((uint64_t)ninput_items.size(), 1); + set_relative_rate((uint64_t)ninput_items.size(), 1); - for (unsigned int i = 0; i < input_items.size(); i++) { - const unsigned char *in = (const unsigned char *) input_items[i]; + for (unsigned int i = 0; i < input_items.size(); i++) { + const unsigned char* in = (const unsigned char*)input_items[i]; - std::vector<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++) { - uint64_t offset = tags[j].offset - nitems_read(i) + nitems_written(0) + n_produced; - if (i == d_tag_preserve_head_pos && tags[j].offset == nitems_read(i)) { - offset -= 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; + std::vector<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++) { + uint64_t offset = + tags[j].offset - nitems_read(i) + nitems_written(0) + n_produced; + if (i == d_tag_preserve_head_pos && tags[j].offset == nitems_read(i)) { + offset -= 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]; } - } /* namespace blocks */ + 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 index 3a61956a07..03804a6253 100644 --- a/gr-blocks/lib/tagged_stream_mux_impl.h +++ b/gr-blocks/lib/tagged_stream_mux_impl.h @@ -27,29 +27,30 @@ #include <gnuradio/blocks/tagged_stream_mux.h> namespace gr { - namespace blocks { - - class tagged_stream_mux_impl : public tagged_stream_mux - { - private: - size_t d_itemsize; - unsigned int d_tag_preserve_head_pos; - - protected: - int calculate_output_stream_length(const gr_vector_int &ninput_items); - - public: - tagged_stream_mux_impl(size_t itemsize, const std::string &lengthtagname, unsigned int d_tag_preserve_head_pos); - ~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 blocks { + +class tagged_stream_mux_impl : public tagged_stream_mux +{ +private: + size_t d_itemsize; + unsigned int d_tag_preserve_head_pos; + +protected: + int calculate_output_stream_length(const gr_vector_int& ninput_items); + +public: + tagged_stream_mux_impl(size_t itemsize, + const std::string& lengthtagname, + unsigned int d_tag_preserve_head_pos); + ~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 - diff --git a/gr-blocks/lib/tagged_stream_to_pdu_impl.cc b/gr-blocks/lib/tagged_stream_to_pdu_impl.cc index feada488c7..6411ad0c41 100644 --- a/gr-blocks/lib/tagged_stream_to_pdu_impl.cc +++ b/gr-blocks/lib/tagged_stream_to_pdu_impl.cc @@ -29,52 +29,50 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - tagged_stream_to_pdu::sptr - tagged_stream_to_pdu::make(pdu::vector_type type, const std::string& lengthtagname) - { - return gnuradio::get_initial_sptr(new tagged_stream_to_pdu_impl(type, lengthtagname)); - } +tagged_stream_to_pdu::sptr tagged_stream_to_pdu::make(pdu::vector_type type, + const std::string& lengthtagname) +{ + return gnuradio::get_initial_sptr(new tagged_stream_to_pdu_impl(type, lengthtagname)); +} - tagged_stream_to_pdu_impl::tagged_stream_to_pdu_impl(pdu::vector_type type, const std::string& lengthtagname) - : tagged_stream_block("tagged_stream_to_pdu", - io_signature::make(1, 1, pdu::itemsize(type)), - io_signature::make(0, 0, 0), lengthtagname), - d_type(type), - d_pdu_meta(pmt::PMT_NIL), - d_pdu_vector(pmt::PMT_NIL) - { - message_port_register_out(pdu::pdu_port_id()); - } +tagged_stream_to_pdu_impl::tagged_stream_to_pdu_impl(pdu::vector_type type, + const std::string& lengthtagname) + : tagged_stream_block("tagged_stream_to_pdu", + io_signature::make(1, 1, pdu::itemsize(type)), + io_signature::make(0, 0, 0), + lengthtagname), + d_type(type), + d_pdu_meta(pmt::PMT_NIL), + d_pdu_vector(pmt::PMT_NIL) +{ + message_port_register_out(pdu::pdu_port_id()); +} - int - tagged_stream_to_pdu_impl::work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const uint8_t *in = (const uint8_t*) input_items[0]; +int tagged_stream_to_pdu_impl::work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const uint8_t* in = (const uint8_t*)input_items[0]; - // Grab tags, throw them into dict - get_tags_in_range(d_tags, 0, - nitems_read(0), - nitems_read(0) + ninput_items[0] - ); - d_pdu_meta = pmt::make_dict(); - for (d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) { - d_pdu_meta = dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value); - } + // Grab tags, throw them into dict + get_tags_in_range(d_tags, 0, nitems_read(0), nitems_read(0) + ninput_items[0]); + d_pdu_meta = pmt::make_dict(); + for (d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) { + d_pdu_meta = dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value); + } - // Grab data, throw into vector - d_pdu_vector = pdu::make_pdu_vector(d_type, in, ninput_items[0]); + // Grab data, throw into vector + d_pdu_vector = pdu::make_pdu_vector(d_type, in, ninput_items[0]); - // Send msg - pmt::pmt_t msg = pmt::cons(d_pdu_meta, d_pdu_vector); - message_port_pub(pdu::pdu_port_id(), msg); + // Send msg + pmt::pmt_t msg = pmt::cons(d_pdu_meta, d_pdu_vector); + message_port_pub(pdu::pdu_port_id(), msg); - return ninput_items[0]; - } + return ninput_items[0]; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/tagged_stream_to_pdu_impl.h b/gr-blocks/lib/tagged_stream_to_pdu_impl.h index 2c3a7ca44a..1894aad7c3 100644 --- a/gr-blocks/lib/tagged_stream_to_pdu_impl.h +++ b/gr-blocks/lib/tagged_stream_to_pdu_impl.h @@ -26,27 +26,26 @@ #include <gnuradio/blocks/tagged_stream_to_pdu.h> namespace gr { - namespace blocks { - - class BLOCKS_API tagged_stream_to_pdu_impl : public tagged_stream_to_pdu - { - pdu::vector_type d_type; - pmt::pmt_t d_pdu_meta; - pmt::pmt_t d_pdu_vector; - std::vector<tag_t>::iterator d_tags_itr; - std::vector<tag_t> d_tags; - - public: - tagged_stream_to_pdu_impl(pdu::vector_type type, const std::string& lengthtagname); - - 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 blocks { + +class BLOCKS_API tagged_stream_to_pdu_impl : public tagged_stream_to_pdu +{ + pdu::vector_type d_type; + pmt::pmt_t d_pdu_meta; + pmt::pmt_t d_pdu_vector; + std::vector<tag_t>::iterator d_tags_itr; + std::vector<tag_t> d_tags; + +public: + tagged_stream_to_pdu_impl(pdu::vector_type type, const std::string& lengthtagname); + + 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 diff --git a/gr-blocks/lib/tags_strobe_impl.cc b/gr-blocks/lib/tags_strobe_impl.cc index f821cefccd..51391fb082 100644 --- a/gr-blocks/lib/tags_strobe_impl.cc +++ b/gr-blocks/lib/tags_strobe_impl.cc @@ -36,72 +36,59 @@ #include <iostream> namespace gr { - namespace blocks { +namespace blocks { - tags_strobe::sptr - tags_strobe::make(size_t sizeof_stream_item, - pmt::pmt_t value, uint64_t nsamps, pmt::pmt_t key) - { - return gnuradio::get_initial_sptr - (new tags_strobe_impl(sizeof_stream_item, value, nsamps, key)); - } +tags_strobe::sptr tags_strobe::make(size_t sizeof_stream_item, + pmt::pmt_t value, + uint64_t nsamps, + pmt::pmt_t key) +{ + return gnuradio::get_initial_sptr( + new tags_strobe_impl(sizeof_stream_item, value, nsamps, key)); +} - tags_strobe_impl::tags_strobe_impl(size_t sizeof_stream_item, - pmt::pmt_t value, uint64_t nsamps, - pmt::pmt_t key) - : sync_block("tags_strobe", - io_signature::make(0, 0, 0), - io_signature::make(1, 1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item) - { - d_tag.offset = 0; - d_tag.key = pmt::intern("strobe"); - d_tag.srcid = alias_pmt(); - set_value(value); - set_key(key); - set_nsamps(nsamps); - d_offset = 0; - } +tags_strobe_impl::tags_strobe_impl(size_t sizeof_stream_item, + pmt::pmt_t value, + uint64_t nsamps, + pmt::pmt_t key) + : sync_block("tags_strobe", + io_signature::make(0, 0, 0), + io_signature::make(1, 1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item) +{ + d_tag.offset = 0; + d_tag.key = pmt::intern("strobe"); + d_tag.srcid = alias_pmt(); + set_value(value); + set_key(key); + set_nsamps(nsamps); + d_offset = 0; +} - tags_strobe_impl::~tags_strobe_impl() - { - } +tags_strobe_impl::~tags_strobe_impl() {} - void - tags_strobe_impl::set_value(pmt::pmt_t value) - { - d_tag.value = value; - } +void tags_strobe_impl::set_value(pmt::pmt_t value) { d_tag.value = value; } - void - tags_strobe_impl::set_key(pmt::pmt_t key) - { - d_tag.key = key; - } +void tags_strobe_impl::set_key(pmt::pmt_t key) { d_tag.key = key; } - void - tags_strobe_impl::set_nsamps(uint64_t nsamps) - { - d_nsamps = nsamps; - } +void tags_strobe_impl::set_nsamps(uint64_t nsamps) { d_nsamps = nsamps; } - int - tags_strobe_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - void *optr = (void*)output_items[0]; - memset(optr, 0, noutput_items * d_itemsize); +int tags_strobe_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + void* optr = (void*)output_items[0]; + memset(optr, 0, noutput_items * d_itemsize); - uint64_t nitems = static_cast<uint64_t>(noutput_items) + nitems_written(0); - while((nitems - d_offset) > d_nsamps) { + uint64_t nitems = static_cast<uint64_t>(noutput_items) + nitems_written(0); + while ((nitems - d_offset) > d_nsamps) { d_offset += d_nsamps; d_tag.offset = d_offset; add_item_tag(0, d_tag); - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/tags_strobe_impl.h b/gr-blocks/lib/tags_strobe_impl.h index e99d3e1b44..2d0537de26 100644 --- a/gr-blocks/lib/tags_strobe_impl.h +++ b/gr-blocks/lib/tags_strobe_impl.h @@ -26,37 +26,38 @@ #include <gnuradio/blocks/tags_strobe.h> namespace gr { - namespace blocks { - - class BLOCKS_API tags_strobe_impl : public tags_strobe - { - private: - size_t d_itemsize; - uint64_t d_nsamps; - tag_t d_tag; - uint64_t d_offset; - - void run(); - - public: - tags_strobe_impl(size_t sizeof_stream_item, - pmt::pmt_t value, uint64_t nsamps, - pmt::pmt_t key); - ~tags_strobe_impl(); - - void set_value(pmt::pmt_t value); - void set_key(pmt::pmt_t key); - pmt::pmt_t value() const { return d_tag.value; } - pmt::pmt_t key() const { return d_tag.key; } - void set_nsamps(uint64_t nsamps); - uint64_t nsamps() const { return d_nsamps; } - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class BLOCKS_API tags_strobe_impl : public tags_strobe +{ +private: + size_t d_itemsize; + uint64_t d_nsamps; + tag_t d_tag; + uint64_t d_offset; + + void run(); + +public: + tags_strobe_impl(size_t sizeof_stream_item, + pmt::pmt_t value, + uint64_t nsamps, + pmt::pmt_t key); + ~tags_strobe_impl(); + + void set_value(pmt::pmt_t value); + void set_key(pmt::pmt_t key); + pmt::pmt_t value() const { return d_tag.value; } + pmt::pmt_t key() const { return d_tag.key; } + void set_nsamps(uint64_t nsamps); + uint64_t nsamps() const { return d_nsamps; } + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_TAGS_STROBE_IMPL_H */ diff --git a/gr-blocks/lib/tcp_connection.cc b/gr-blocks/lib/tcp_connection.cc index 4c0dfc27ac..bef89fb523 100644 --- a/gr-blocks/lib/tcp_connection.cc +++ b/gr-blocks/lib/tcp_connection.cc @@ -29,83 +29,90 @@ #include <gnuradio/blocks/pdu.h> namespace gr { - namespace blocks { +namespace blocks { - tcp_connection::sptr tcp_connection::make(boost::asio::io_service& io_service, int MTU/*= 10000*/, bool no_delay/*=false*/) - { - return sptr(new tcp_connection(io_service, MTU, no_delay)); - } +tcp_connection::sptr tcp_connection::make(boost::asio::io_service& io_service, + int MTU /*= 10000*/, + bool no_delay /*=false*/) +{ + return sptr(new tcp_connection(io_service, MTU, no_delay)); +} - tcp_connection::tcp_connection(boost::asio::io_service& io_service, int MTU/*= 10000*/, bool no_delay/*=false*/) - : d_socket(io_service) - , d_block(NULL) - , d_no_delay(no_delay) - { - d_buf.resize(MTU); - try { +tcp_connection::tcp_connection(boost::asio::io_service& io_service, + int MTU /*= 10000*/, + bool no_delay /*=false*/) + : d_socket(io_service), d_block(NULL), d_no_delay(no_delay) +{ + d_buf.resize(MTU); + try { d_socket.set_option(boost::asio::ip::tcp::no_delay(no_delay)); - } - catch (...) { - // Silently ignore failure (socket might be current in accept stage) and try again in 'start' - } + } catch (...) { + // Silently ignore failure (socket might be current in accept stage) and try again + // in 'start' } +} - void - tcp_connection::send(pmt::pmt_t vector) - { - size_t len = pmt::blob_length(vector); +void tcp_connection::send(pmt::pmt_t vector) +{ + size_t len = pmt::blob_length(vector); - // Asio async_write() requires the buffer to remain valid until the handler is called. - boost::shared_ptr<char[]> txbuf(new char[len]); + // Asio async_write() requires the buffer to remain valid until the handler is called. + boost::shared_ptr<char[]> txbuf(new char[len]); - size_t temp = 0; - memcpy(txbuf.get(), pmt::uniform_vector_elements(vector, temp), len); + size_t temp = 0; + memcpy(txbuf.get(), pmt::uniform_vector_elements(vector, temp), len); - size_t offset = 0; - while (offset < len) { + size_t offset = 0; + while (offset < len) { // Limit the size of each write() to the MTU. - // FIXME: Note that this has the effect of breaking a large PDU into several smaller PDUs, each - // containing <= MTU bytes. Is this the desired behavior? + // FIXME: Note that this has the effect of breaking a large PDU into several + // smaller PDUs, each containing <= MTU bytes. Is this the desired behavior? size_t send_len = std::min((len - offset), d_buf.size()); - boost::asio::async_write(d_socket, boost::asio::buffer(txbuf.get() + offset, send_len), - boost::bind(&tcp_connection::handle_write, this, txbuf, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); + boost::asio::async_write( + d_socket, + boost::asio::buffer(txbuf.get() + offset, send_len), + boost::bind(&tcp_connection::handle_write, + this, + txbuf, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); offset += send_len; - } } +} - void - tcp_connection::start(gr::basic_block *block) - { - d_block = block; - d_socket.set_option(boost::asio::ip::tcp::no_delay(d_no_delay)); - d_socket.async_read_some(boost::asio::buffer(d_buf), - boost::bind(&tcp_connection::handle_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } +void tcp_connection::start(gr::basic_block* block) +{ + d_block = block; + d_socket.set_option(boost::asio::ip::tcp::no_delay(d_no_delay)); + d_socket.async_read_some(boost::asio::buffer(d_buf), + boost::bind(&tcp_connection::handle_read, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); +} - void - tcp_connection::handle_read(const boost::system::error_code& error, size_t bytes_transferred) - { - if (!error) { +void tcp_connection::handle_read(const boost::system::error_code& error, + size_t bytes_transferred) +{ + if (!error) { if (d_block) { - pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_buf[0]); - pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); + pmt::pmt_t vector = + pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_buf[0]); + pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); - d_block->message_port_pub(pdu::pdu_port_id(), pdu); + d_block->message_port_pub(pdu::pdu_port_id(), pdu); } - d_socket.async_read_some(boost::asio::buffer(d_buf), - boost::bind(&tcp_connection::handle_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } - else { + d_socket.async_read_some( + boost::asio::buffer(d_buf), + boost::bind(&tcp_connection::handle_read, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + } else { d_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both); d_socket.close(); - } } - } /* namespace blocks */ -}/* namespace gr */ +} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/tcp_connection.h b/gr-blocks/lib/tcp_connection.h index eb4c0df285..4c5a67c54b 100644 --- a/gr-blocks/lib/tcp_connection.h +++ b/gr-blocks/lib/tcp_connection.h @@ -30,35 +30,41 @@ namespace gr { - class basic_block; +class basic_block; - namespace blocks { +namespace blocks { - class tcp_connection - { - private: - boost::asio::ip::tcp::socket d_socket; - std::vector<char> d_buf; - basic_block *d_block; - bool d_no_delay; +class tcp_connection +{ +private: + boost::asio::ip::tcp::socket d_socket; + std::vector<char> d_buf; + basic_block* d_block; + bool d_no_delay; - tcp_connection(boost::asio::io_service& io_service, int MTU=10000, bool no_delay=false); + tcp_connection(boost::asio::io_service& io_service, + int MTU = 10000, + bool no_delay = false); - public: - typedef boost::shared_ptr<tcp_connection> sptr; +public: + typedef boost::shared_ptr<tcp_connection> sptr; - static sptr make(boost::asio::io_service& io_service, int MTU=10000, bool no_delay=false); + static sptr + make(boost::asio::io_service& io_service, int MTU = 10000, bool no_delay = false); - boost::asio::ip::tcp::socket& socket() { return d_socket; }; + boost::asio::ip::tcp::socket& socket() { return d_socket; }; - void start(gr::basic_block *block); - void send(pmt::pmt_t vector); - void handle_read(const boost::system::error_code& error, size_t bytes_transferred); - void handle_write(boost::shared_ptr<char[]> txbuf, const boost::system::error_code& error, - size_t bytes_transferred) { } - }; + void start(gr::basic_block* block); + void send(pmt::pmt_t vector); + void handle_read(const boost::system::error_code& error, size_t bytes_transferred); + void handle_write(boost::shared_ptr<char[]> txbuf, + const boost::system::error_code& error, + size_t bytes_transferred) + { + } +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_TCP_CONNECTION_H */ diff --git a/gr-blocks/lib/tcp_server_sink_impl.cc b/gr-blocks/lib/tcp_server_sink_impl.cc index 44f0765cb2..dd6a9d2e44 100644 --- a/gr-blocks/lib/tcp_server_sink_impl.cc +++ b/gr-blocks/lib/tcp_server_sink_impl.cc @@ -36,126 +36,130 @@ #include <string.h> namespace gr { - namespace blocks { - - tcp_server_sink::sptr - tcp_server_sink::make(size_t itemsize, - const std::string &host, int port, - bool noblock) - { - return gnuradio::get_initial_sptr - (new tcp_server_sink_impl(itemsize, host, port, noblock)); - } - - tcp_server_sink_impl::tcp_server_sink_impl(size_t itemsize, - const std::string &host, int port, - bool noblock) - : sync_block("tcp_server_sink", - io_signature::make(1, 1, itemsize), - io_signature::make(0, 0, 0)), +namespace blocks { + +tcp_server_sink::sptr +tcp_server_sink::make(size_t itemsize, const std::string& host, int port, bool noblock) +{ + return gnuradio::get_initial_sptr( + new tcp_server_sink_impl(itemsize, host, port, noblock)); +} + +tcp_server_sink_impl::tcp_server_sink_impl(size_t itemsize, + const std::string& host, + int port, + bool noblock) + : sync_block("tcp_server_sink", + io_signature::make(1, 1, itemsize), + io_signature::make(0, 0, 0)), d_itemsize(itemsize), d_acceptor(d_io_service), d_buf(new uint8_t[BUF_SIZE]), d_writing(0) - { - std::string s__port = (boost::format("%d") % port).str(); - std::string s__host = host.empty() ? std::string("localhost") : host; - boost::asio::ip::tcp::resolver resolver(d_io_service); - boost::asio::ip::tcp::resolver::query query(s__host, s__port, - boost::asio::ip::resolver_query_base::passive); - d_endpoint = *resolver.resolve(query); - - d_acceptor.open(d_endpoint.protocol()); - d_acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); - d_acceptor.bind(d_endpoint); - d_acceptor.listen(); - - if (!noblock) { - d_socket.reset(new boost::asio::ip::tcp::socket(d_io_service)); - d_acceptor.accept(*d_socket, d_endpoint); - d_sockets.insert(d_socket.release()); - } - +{ + std::string s__port = (boost::format("%d") % port).str(); + std::string s__host = host.empty() ? std::string("localhost") : host; + boost::asio::ip::tcp::resolver resolver(d_io_service); + boost::asio::ip::tcp::resolver::query query( + s__host, s__port, boost::asio::ip::resolver_query_base::passive); + d_endpoint = *resolver.resolve(query); + + d_acceptor.open(d_endpoint.protocol()); + d_acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); + d_acceptor.bind(d_endpoint); + d_acceptor.listen(); + + if (!noblock) { d_socket.reset(new boost::asio::ip::tcp::socket(d_io_service)); - d_acceptor.async_accept(*d_socket, boost::bind(&tcp_server_sink_impl::do_accept, - this, boost::asio::placeholders::error)); - d_io_serv_thread = boost::thread( - boost::bind(&boost::asio::io_service::run, &d_io_service)); - } - - void - tcp_server_sink_impl::do_accept(const boost::system::error_code& error) - { - if (!error) { + d_acceptor.accept(*d_socket, d_endpoint); + d_sockets.insert(d_socket.release()); + } + + d_socket.reset(new boost::asio::ip::tcp::socket(d_io_service)); + d_acceptor.async_accept(*d_socket, + boost::bind(&tcp_server_sink_impl::do_accept, + this, + boost::asio::placeholders::error)); + d_io_serv_thread = + boost::thread(boost::bind(&boost::asio::io_service::run, &d_io_service)); +} + +void tcp_server_sink_impl::do_accept(const boost::system::error_code& error) +{ + if (!error) { gr::thread::scoped_lock guard(d_writing_mut); d_sockets.insert(d_socket.release()); d_socket.reset(new boost::asio::ip::tcp::socket(d_io_service)); - d_acceptor.async_accept(*d_socket, boost::bind(&tcp_server_sink_impl::do_accept, - this, boost::asio::placeholders::error)); - } + d_acceptor.async_accept(*d_socket, + boost::bind(&tcp_server_sink_impl::do_accept, + this, + boost::asio::placeholders::error)); } +} - void - tcp_server_sink_impl::do_write(const boost::system::error_code& error, - size_t len, std::set<boost::asio::ip::tcp::socket *>::iterator i) +void tcp_server_sink_impl::do_write(const boost::system::error_code& error, + size_t len, + std::set<boost::asio::ip::tcp::socket*>::iterator i) +{ { - { gr::thread::scoped_lock guard(d_writing_mut); --d_writing; if (error) { - delete *i; - d_sockets.erase(i); + delete *i; + d_sockets.erase(i); } - } - d_writing_cond.notify_one(); } + d_writing_cond.notify_one(); +} - tcp_server_sink_impl::~tcp_server_sink_impl() - { - gr::thread::scoped_lock guard(d_writing_mut); - while (d_writing) { +tcp_server_sink_impl::~tcp_server_sink_impl() +{ + gr::thread::scoped_lock guard(d_writing_mut); + while (d_writing) { d_writing_cond.wait(guard); - } + } - for (std::set<boost::asio::ip::tcp::socket *>::iterator i = d_sockets.begin(); - i != d_sockets.end(); ++i ) { + for (std::set<boost::asio::ip::tcp::socket*>::iterator i = d_sockets.begin(); + i != d_sockets.end(); + ++i) { delete *i; - } - d_sockets.clear(); - - d_io_service.reset(); - d_io_service.stop(); - d_io_serv_thread.join(); } + d_sockets.clear(); - int - tcp_server_sink_impl::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *in = (const char *) input_items[0]; + d_io_service.reset(); + d_io_service.stop(); + d_io_serv_thread.join(); +} - gr::thread::scoped_lock guard(d_writing_mut); - while (d_writing) { +int tcp_server_sink_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* in = (const char*)input_items[0]; + + gr::thread::scoped_lock guard(d_writing_mut); + while (d_writing) { d_writing_cond.wait(guard); - } - - size_t data_len = std::min(size_t(BUF_SIZE), noutput_items * d_itemsize); - data_len -= data_len % d_itemsize; - memcpy(d_buf.get(), in, data_len); - for (std::set<boost::asio::ip::tcp::socket *>::iterator i = d_sockets.begin(); - i != d_sockets.end(); ++i ) { - boost::asio::async_write(**i, boost::asio::buffer(d_buf.get(), data_len), - boost::bind(&tcp_server_sink_impl::do_write, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred, - i)); - } - d_writing = d_sockets.size(); - - return data_len / d_itemsize; } - } /* namespace blocks */ -} /* namespace gr */ + size_t data_len = std::min(size_t(BUF_SIZE), noutput_items * d_itemsize); + data_len -= data_len % d_itemsize; + memcpy(d_buf.get(), in, data_len); + for (std::set<boost::asio::ip::tcp::socket*>::iterator i = d_sockets.begin(); + i != d_sockets.end(); + ++i) { + boost::asio::async_write(**i, + boost::asio::buffer(d_buf.get(), data_len), + boost::bind(&tcp_server_sink_impl::do_write, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred, + i)); + } + d_writing = d_sockets.size(); + + return data_len / d_itemsize; +} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/tcp_server_sink_impl.h b/gr-blocks/lib/tcp_server_sink_impl.h index db26b705fe..6c4b0f938f 100644 --- a/gr-blocks/lib/tcp_server_sink_impl.h +++ b/gr-blocks/lib/tcp_server_sink_impl.h @@ -29,45 +29,47 @@ #include <boost/ptr_container/ptr_vector.hpp> namespace gr { - namespace blocks { +namespace blocks { - class tcp_server_sink_impl : public tcp_server_sink - { - private: - size_t d_itemsize; +class tcp_server_sink_impl : public tcp_server_sink +{ +private: + size_t d_itemsize; - boost::asio::io_service d_io_service; - gr::thread::thread d_io_serv_thread; - boost::asio::ip::tcp::endpoint d_endpoint; - std::unique_ptr<boost::asio::ip::tcp::socket> d_socket; - std::set<boost::asio::ip::tcp::socket *> d_sockets; - boost::asio::ip::tcp::acceptor d_acceptor; + boost::asio::io_service d_io_service; + gr::thread::thread d_io_serv_thread; + boost::asio::ip::tcp::endpoint d_endpoint; + std::unique_ptr<boost::asio::ip::tcp::socket> d_socket; + std::set<boost::asio::ip::tcp::socket*> d_sockets; + boost::asio::ip::tcp::acceptor d_acceptor; - boost::shared_ptr<uint8_t[]> d_buf; - enum { - BUF_SIZE = 256 * 1024, - }; + boost::shared_ptr<uint8_t[]> d_buf; + enum { + BUF_SIZE = 256 * 1024, + }; - int d_writing; - boost::condition_variable d_writing_cond; - boost::mutex d_writing_mut; + int d_writing; + boost::condition_variable d_writing_cond; + boost::mutex d_writing_mut; - void do_accept(const boost::system::error_code& error); - void do_write(const boost::system::error_code& error, std::size_t len, - std::set<boost::asio::ip::tcp::socket *>::iterator); + void do_accept(const boost::system::error_code& error); + void do_write(const boost::system::error_code& error, + std::size_t len, + std::set<boost::asio::ip::tcp::socket*>::iterator); - public: - tcp_server_sink_impl(size_t itemsize, - const std::string &host, int port, - bool noblock); - ~tcp_server_sink_impl(); +public: + tcp_server_sink_impl(size_t itemsize, + const std::string& host, + int port, + bool noblock); + ~tcp_server_sink_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_TCP_SERVER_SINK_IMPL_H */ diff --git a/gr-blocks/lib/test_tag_variable_rate_ff_impl.cc b/gr-blocks/lib/test_tag_variable_rate_ff_impl.cc index cc9e1eeab9..5a825710e6 100644 --- a/gr-blocks/lib/test_tag_variable_rate_ff_impl.cc +++ b/gr-blocks/lib/test_tag_variable_rate_ff_impl.cc @@ -36,106 +36,103 @@ using namespace pmt; namespace gr { - namespace blocks { - - test_tag_variable_rate_ff::sptr - test_tag_variable_rate_ff::make(bool update_once, double update_step) - { - return gnuradio::get_initial_sptr - (new test_tag_variable_rate_ff_impl(update_once, update_step)); - } - - test_tag_variable_rate_ff_impl::test_tag_variable_rate_ff_impl(bool update_once, double update_step) - : block("test_tag_variable_rate_ff", - io_signature::make(1, 1, sizeof(float)), - io_signature::make(1, 1, sizeof(float))), - d_update_once(update_once), d_update_step(update_step) - { - set_tag_propagation_policy(TPP_DONT); - set_relative_rate(1, 2); - d_accum = 0; - d_rrate = 0.5; - d_old_in = 0; - d_new_in = 0; - d_last_out = 0; - - xoroshiro128p_seed(d_rng_state, 4 /* chosen by fair dice roll */); - } - - test_tag_variable_rate_ff_impl::~test_tag_variable_rate_ff_impl() - { - } - - int - test_tag_variable_rate_ff_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float*)input_items[0]; - float *out = (float*)output_items[0]; - - GR_LOG_DEBUG(d_logger, "\n"); - GR_LOG_DEBUG(d_logger, boost::format("ninput_items: %1%") % ninput_items[0]); - GR_LOG_DEBUG(d_logger, boost::format("noutput_items: %1%") % noutput_items); - - if(d_update_once) { - if (xoroshiro128p_next(d_rng_state) > (UINT64_MAX / 2)){ - d_rrate += d_update_step; - } - else { - d_rrate -= d_update_step; - if(d_rrate < d_update_step) - d_rrate = d_update_step; +namespace blocks { + +test_tag_variable_rate_ff::sptr test_tag_variable_rate_ff::make(bool update_once, + double update_step) +{ + return gnuradio::get_initial_sptr( + new test_tag_variable_rate_ff_impl(update_once, update_step)); +} + +test_tag_variable_rate_ff_impl::test_tag_variable_rate_ff_impl(bool update_once, + double update_step) + : block("test_tag_variable_rate_ff", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(float))), + d_update_once(update_once), + d_update_step(update_step) +{ + set_tag_propagation_policy(TPP_DONT); + set_relative_rate(1, 2); + d_accum = 0; + d_rrate = 0.5; + d_old_in = 0; + d_new_in = 0; + d_last_out = 0; + + xoroshiro128p_seed(d_rng_state, 4 /* chosen by fair dice roll */); +} + +test_tag_variable_rate_ff_impl::~test_tag_variable_rate_ff_impl() {} + +int test_tag_variable_rate_ff_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + float* out = (float*)output_items[0]; + + GR_LOG_DEBUG(d_logger, "\n"); + GR_LOG_DEBUG(d_logger, boost::format("ninput_items: %1%") % ninput_items[0]); + GR_LOG_DEBUG(d_logger, boost::format("noutput_items: %1%") % noutput_items); + + if (d_update_once) { + if (xoroshiro128p_next(d_rng_state) > (UINT64_MAX / 2)) { + d_rrate += d_update_step; + } else { + d_rrate -= d_update_step; + if (d_rrate < d_update_step) + d_rrate = d_update_step; } - } + } - std::vector<tag_t> tags; - std::vector<tag_t>::iterator itags; + std::vector<tag_t> tags; + std::vector<tag_t>::iterator itags; - int i = 0, j = 0; - while(i < ninput_items[0]) { + int i = 0, j = 0; + while (i < ninput_items[0]) { - if(!d_update_once) { - if (xoroshiro128p_next(d_rng_state) > (UINT64_MAX / 2)){ - d_rrate += d_update_step; - } - else { - d_rrate -= d_update_step; - if(d_rrate < d_update_step) - d_rrate = d_update_step; - } + if (!d_update_once) { + if (xoroshiro128p_next(d_rng_state) > (UINT64_MAX / 2)) { + d_rrate += d_update_step; + } else { + d_rrate -= d_update_step; + if (d_rrate < d_update_step) + d_rrate = d_update_step; + } } d_accum += d_rrate; - if(d_accum >= 1.0) { - out[j] = in[i]; - - // Manage Tags - d_new_in = nitems_read(0) + i; - get_tags_in_range(tags, 0, d_old_in, d_new_in); - for(itags = tags.begin(); itags != tags.end(); itags++) { - tag_t new_tag = *itags; - new_tag.offset = d_last_out; - add_item_tag(0, new_tag); - } - d_old_in = d_new_in; - d_last_out = nitems_written(0) + j; - - // Book keeping - j++; - d_accum -= 1.0; + if (d_accum >= 1.0) { + out[j] = in[i]; + + // Manage Tags + d_new_in = nitems_read(0) + i; + get_tags_in_range(tags, 0, d_old_in, d_new_in); + for (itags = tags.begin(); itags != tags.end(); itags++) { + tag_t new_tag = *itags; + new_tag.offset = d_last_out; + add_item_tag(0, new_tag); + } + d_old_in = d_new_in; + d_last_out = nitems_written(0) + j; + + // Book keeping + j++; + d_accum -= 1.0; } i++; - } + } - GR_LOG_DEBUG(d_logger, boost::format("consuming: %1%") % i); - GR_LOG_DEBUG(d_logger, boost::format("producing: %1%") % j); - GR_LOG_DEBUG(d_logger, boost::format("block's rel rate: %1%") % d_rrate); + GR_LOG_DEBUG(d_logger, boost::format("consuming: %1%") % i); + GR_LOG_DEBUG(d_logger, boost::format("producing: %1%") % j); + GR_LOG_DEBUG(d_logger, boost::format("block's rel rate: %1%") % d_rrate); - consume_each(i); - return j; - } + consume_each(i); + return j; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/test_tag_variable_rate_ff_impl.h b/gr-blocks/lib/test_tag_variable_rate_ff_impl.h index a02bce1ccf..9bd6468c0a 100644 --- a/gr-blocks/lib/test_tag_variable_rate_ff_impl.h +++ b/gr-blocks/lib/test_tag_variable_rate_ff_impl.h @@ -26,32 +26,31 @@ #include <gnuradio/blocks/test_tag_variable_rate_ff.h> namespace gr { - namespace blocks { - - class test_tag_variable_rate_ff_impl : public test_tag_variable_rate_ff - { - protected: - bool d_update_once; - double d_update_step; - double d_accum; - double d_rrate; - uint64_t d_old_in, d_new_in, d_last_out; - uint64_t d_rng_state[2]; - - public: - test_tag_variable_rate_ff_impl(bool update_once=false, - double update_step=0.001); - ~test_tag_variable_rate_ff_impl(); - - //void setup_rpc(); - - int general_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 blocks { + +class test_tag_variable_rate_ff_impl : public test_tag_variable_rate_ff +{ +protected: + bool d_update_once; + double d_update_step; + double d_accum; + double d_rrate; + uint64_t d_old_in, d_new_in, d_last_out; + uint64_t d_rng_state[2]; + +public: + test_tag_variable_rate_ff_impl(bool update_once = false, double update_step = 0.001); + ~test_tag_variable_rate_ff_impl(); + + // void setup_rpc(); + + int general_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_GR_TEST_TAG_VARIABLE_RATE_FF_IMPL_H */ diff --git a/gr-blocks/lib/threshold_ff_impl.cc b/gr-blocks/lib/threshold_ff_impl.cc index 86432de113..3dcaccd44c 100644 --- a/gr-blocks/lib/threshold_ff_impl.cc +++ b/gr-blocks/lib/threshold_ff_impl.cc @@ -28,51 +28,45 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - threshold_ff::sptr - threshold_ff::make(float lo, float hi, float initial_state) - { - return gnuradio::get_initial_sptr - (new threshold_ff_impl(lo, hi, initial_state)); - } +threshold_ff::sptr threshold_ff::make(float lo, float hi, float initial_state) +{ + return gnuradio::get_initial_sptr(new threshold_ff_impl(lo, hi, initial_state)); +} - threshold_ff_impl::threshold_ff_impl(float lo, float hi, - float initial_state) - : sync_block("threshold_ff", - io_signature::make(1, 1, sizeof(float)), - io_signature::make(1, 1, sizeof(float))), - d_lo(lo), d_hi(hi), d_last_state(initial_state) - { - } +threshold_ff_impl::threshold_ff_impl(float lo, float hi, float initial_state) + : sync_block("threshold_ff", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(float))), + d_lo(lo), + d_hi(hi), + d_last_state(initial_state) +{ +} - threshold_ff_impl::~threshold_ff_impl() - { - } +threshold_ff_impl::~threshold_ff_impl() {} - int - threshold_ff_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *in = (const float *)input_items[0]; - float *out = (float *)output_items[0]; +int threshold_ff_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* in = (const float*)input_items[0]; + float* out = (float*)output_items[0]; - for(int i = 0; i < noutput_items; i++) { - if(in[i] > d_hi) { - out[i] = 1.0; - d_last_state = 1.0; - } - else if(in[i] < d_lo) { - out[i] = 0.0; - d_last_state = 0.0; - } - else - out[i] = d_last_state; - } - - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + if (in[i] > d_hi) { + out[i] = 1.0; + d_last_state = 1.0; + } else if (in[i] < d_lo) { + out[i] = 0.0; + d_last_state = 0.0; + } else + out[i] = d_last_state; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/threshold_ff_impl.h b/gr-blocks/lib/threshold_ff_impl.h index 13d71c433f..541ba291f4 100644 --- a/gr-blocks/lib/threshold_ff_impl.h +++ b/gr-blocks/lib/threshold_ff_impl.h @@ -26,32 +26,31 @@ #include <gnuradio/blocks/threshold_ff.h> namespace gr { - namespace blocks { - - class threshold_ff_impl : public threshold_ff - { - private: - float d_lo, d_hi; // the constant - float d_last_state; - - public: - threshold_ff_impl(float lo, float hi, - float initial_state=0); - ~threshold_ff_impl(); - - float lo() const { return d_lo; } - void set_lo(float lo) { d_lo = lo; } - float hi() const { return d_hi; } - void set_hi(float hi) { d_hi = hi; } - float last_state() const { return d_last_state; } - void set_last_state(float last_state) { d_last_state = last_state; } - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class threshold_ff_impl : public threshold_ff +{ +private: + float d_lo, d_hi; // the constant + float d_last_state; + +public: + threshold_ff_impl(float lo, float hi, float initial_state = 0); + ~threshold_ff_impl(); + + float lo() const { return d_lo; } + void set_lo(float lo) { d_lo = lo; } + float hi() const { return d_hi; } + void set_hi(float hi) { d_hi = hi; } + float last_state() const { return d_last_state; } + void set_last_state(float last_state) { d_last_state = last_state; } + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_THRESHOLD_FF_IMPL_H */ diff --git a/gr-blocks/lib/throttle_impl.cc b/gr-blocks/lib/throttle_impl.cc index d818ce192b..d5614c5676 100644 --- a/gr-blocks/lib/throttle_impl.cc +++ b/gr-blocks/lib/throttle_impl.cc @@ -33,117 +33,114 @@ pmt::pmt_t throttle_rx_rate_pmt(pmt::intern("rx_rate")); namespace gr { - namespace blocks { - - throttle::sptr - throttle::make(size_t itemsize, double samples_per_sec, bool ignore_tags) - { - return gnuradio::get_initial_sptr - (new throttle_impl(itemsize, samples_per_sec, ignore_tags)); - } - - throttle_impl::throttle_impl(size_t itemsize, - double samples_per_second, - bool ignore_tags) - : sync_block("throttle", - io_signature::make(1, 1, itemsize), - io_signature::make(1, 1, itemsize)), - d_itemsize(itemsize), - d_ignore_tags(ignore_tags) - { - set_sample_rate(samples_per_second); - } - - throttle_impl::~throttle_impl() - { - } - - bool - throttle_impl::start() - { - d_start = boost::get_system_time(); - d_total_samples = 0; - return block::start(); - } - - void - throttle_impl::set_sample_rate(double rate) - { - //changing the sample rate performs a reset of state params - d_start = boost::get_system_time(); - d_total_samples = 0; - d_samps_per_tick = rate/boost::posix_time::time_duration::ticks_per_second(); - d_samps_per_us = rate/1e6; - } - - double - throttle_impl::sample_rate() const - { - return d_samps_per_us * 1e6; - } - - int - throttle_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - // check for updated rx_rate tag - if(!d_ignore_tags){ +namespace blocks { + +throttle::sptr throttle::make(size_t itemsize, double samples_per_sec, bool ignore_tags) +{ + return gnuradio::get_initial_sptr( + new throttle_impl(itemsize, samples_per_sec, ignore_tags)); +} + +throttle_impl::throttle_impl(size_t itemsize, double samples_per_second, bool ignore_tags) + : sync_block("throttle", + io_signature::make(1, 1, itemsize), + io_signature::make(1, 1, itemsize)), + d_itemsize(itemsize), + d_ignore_tags(ignore_tags) +{ + set_sample_rate(samples_per_second); +} + +throttle_impl::~throttle_impl() {} + +bool throttle_impl::start() +{ + d_start = boost::get_system_time(); + d_total_samples = 0; + return block::start(); +} + +void throttle_impl::set_sample_rate(double rate) +{ + // changing the sample rate performs a reset of state params + d_start = boost::get_system_time(); + d_total_samples = 0; + d_samps_per_tick = rate / boost::posix_time::time_duration::ticks_per_second(); + d_samps_per_us = rate / 1e6; +} + +double throttle_impl::sample_rate() const { return d_samps_per_us * 1e6; } + +int throttle_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + // check for updated rx_rate tag + if (!d_ignore_tags) { uint64_t abs_N = nitems_read(0); std::vector<tag_t> all_tags; get_tags_in_range(all_tags, 0, abs_N, abs_N + noutput_items); std::vector<tag_t>::iterator itr; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - if(pmt::eq( (*itr).key, throttle_rx_rate_pmt)){ - double new_rate = pmt::to_double( (*itr).value ); - set_sample_rate(new_rate); + for (itr = all_tags.begin(); itr != all_tags.end(); itr++) { + if (pmt::eq((*itr).key, throttle_rx_rate_pmt)) { + double new_rate = pmt::to_double((*itr).value); + set_sample_rate(new_rate); } - } } + } - //calculate the expected number of samples to have passed through - boost::system_time now = boost::get_system_time(); - boost::int64_t ticks = (now - d_start).ticks(); - uint64_t expected_samps = uint64_t(d_samps_per_tick*ticks); + // calculate the expected number of samples to have passed through + boost::system_time now = boost::get_system_time(); + boost::int64_t ticks = (now - d_start).ticks(); + uint64_t expected_samps = uint64_t(d_samps_per_tick * ticks); - //if the expected samples was less, we need to throttle back - if(d_total_samples > expected_samps) { - double sleep_time = (d_total_samples - expected_samps)/d_samps_per_us; + // if the expected samples was less, we need to throttle back + if (d_total_samples > expected_samps) { + double sleep_time = (d_total_samples - expected_samps) / d_samps_per_us; if (std::numeric_limits<long>::max() < sleep_time) { - GR_LOG_ALERT(d_logger, "WARNING: Throttle sleep time overflow! You " - "are probably using a very low sample rate."); + GR_LOG_ALERT(d_logger, + "WARNING: Throttle sleep time overflow! You " + "are probably using a very low sample rate."); } - boost::this_thread::sleep(boost::posix_time::microseconds - (long(sleep_time))); - } - - //copy all samples output[i] <= input[i] - const char *in = (const char *)input_items[0]; - char *out = (char *)output_items[0]; - std::memcpy(out, in, noutput_items * d_itemsize); - d_total_samples += noutput_items; - return noutput_items; + boost::this_thread::sleep(boost::posix_time::microseconds(long(sleep_time))); } - void - throttle_impl::setup_rpc() - { + // copy all samples output[i] <= input[i] + const char* in = (const char*)input_items[0]; + char* out = (char*)output_items[0]; + std::memcpy(out, in, noutput_items * d_itemsize); + d_total_samples += noutput_items; + return noutput_items; +} + +void throttle_impl::setup_rpc() +{ #ifdef GR_CTRLPORT - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_get<throttle, double>( - alias(), "sample_rate", &throttle::sample_rate, - pmt::mp(0.0), pmt::mp(100.0e6), pmt::mp(0.0), - "Hz", "Sample Rate", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTSTRIP))); - - d_rpc_vars.push_back( - rpcbasic_sptr(new rpcbasic_register_set<throttle, double>( - alias(), "sample_rate", &throttle::set_sample_rate, - pmt::mp(0.0), pmt::mp(100.0e6), pmt::mp(0.0), - "Hz", "Sample Rate", RPC_PRIVLVL_MIN, - DISPTIME | DISPOPTSTRIP))); + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_get<throttle, double>(alias(), + "sample_rate", + &throttle::sample_rate, + pmt::mp(0.0), + pmt::mp(100.0e6), + pmt::mp(0.0), + "Hz", + "Sample Rate", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); + + d_rpc_vars.push_back(rpcbasic_sptr( + new rpcbasic_register_set<throttle, double>(alias(), + "sample_rate", + &throttle::set_sample_rate, + pmt::mp(0.0), + pmt::mp(100.0e6), + pmt::mp(0.0), + "Hz", + "Sample Rate", + RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); #endif /* GR_CTRLPORT */ - } +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/throttle_impl.h b/gr-blocks/lib/throttle_impl.h index 6afacbba5d..9fbff3664f 100644 --- a/gr-blocks/lib/throttle_impl.h +++ b/gr-blocks/lib/throttle_impl.h @@ -26,35 +26,35 @@ #include <gnuradio/blocks/throttle.h> namespace gr { - namespace blocks { +namespace blocks { - class throttle_impl : public throttle - { - private: - boost::system_time d_start; - size_t d_itemsize; - uint64_t d_total_samples; - double d_samps_per_tick, d_samps_per_us; - bool d_ignore_tags; +class throttle_impl : public throttle +{ +private: + boost::system_time d_start; + size_t d_itemsize; + uint64_t d_total_samples; + double d_samps_per_tick, d_samps_per_us; + bool d_ignore_tags; - public: - throttle_impl(size_t itemsize, double samples_per_sec, bool ignore_tags=true); - ~throttle_impl(); +public: + throttle_impl(size_t itemsize, double samples_per_sec, bool ignore_tags = true); + ~throttle_impl(); - // Overloading gr::block::start to reset timer - bool start(); + // Overloading gr::block::start to reset timer + bool start(); - void setup_rpc(); + void setup_rpc(); - void set_sample_rate(double rate); - double sample_rate() const; + void set_sample_rate(double rate); + double sample_rate() const; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_THROTTLE_IMPL_H */ diff --git a/gr-blocks/lib/transcendental_impl.cc b/gr-blocks/lib/transcendental_impl.cc index d9a635fdc2..a29a1e75da 100644 --- a/gr-blocks/lib/transcendental_impl.cc +++ b/gr-blocks/lib/transcendental_impl.cc @@ -24,127 +24,120 @@ #include <gnuradio/io_signature.h> #include <stdexcept> #include <complex> //complex math -#include <cmath> //real math +#include <cmath> //real math #include <map> namespace gr { - namespace blocks { - - /*********************************************************************** - * work function creation and registration - **********************************************************************/ - struct map_val_type - { - work_fcn_type work_fcn; - size_t io_size; - }; - typedef std::map<std::string, map_val_type> map_type; - - //construct map on first use idiom - static map_type & - get_map(void) - { - static map_type map; - return map; - } - - //static initialization of this object registers a function - struct transcendental_registrant +namespace blocks { + +/*********************************************************************** + * work function creation and registration + **********************************************************************/ +struct map_val_type { + work_fcn_type work_fcn; + size_t io_size; +}; +typedef std::map<std::string, map_val_type> map_type; + +// construct map on first use idiom +static map_type& get_map(void) +{ + static map_type map; + return map; +} + +// static initialization of this object registers a function +struct transcendental_registrant { + transcendental_registrant(const std::string& key, + const work_fcn_type& work_fcn, + const size_t io_size) { - transcendental_registrant(const std::string &key, - const work_fcn_type &work_fcn, - const size_t io_size) - { map_val_type val; val.work_fcn = work_fcn; val.io_size = io_size; get_map()[key] = val; - } - }; - - //macro to create a work function and register it -#define REGISTER_FUNCTION(__fcn__, __type__, __key__) \ - static int __key__ ## _work( \ - int noutput_items, \ - gr_vector_const_void_star &input_items, \ - gr_vector_void_star &output_items) \ - { \ - const __type__ *in = (const __type__ *) input_items[0]; \ - __type__ *out = (__type__ *) output_items[0]; \ - for (size_t i = 0; i < size_t(noutput_items); i++){ \ - out[i] = std::__fcn__(in[i]); \ - } \ - return noutput_items; \ - } \ - transcendental_registrant __key__ ## _registrant(#__key__, &__key__ ## _work, sizeof(__type__)); - - //register work functions for real types -#define REGISTER_REAL_FUNCTIONS(__fcn__) \ - REGISTER_FUNCTION(__fcn__, float, __fcn__ ## _float) \ - REGISTER_FUNCTION(__fcn__, double, __fcn__ ## _double) - - //register work functions for complex types -#define REGISTER_COMPLEX_FUNCTIONS(__fcn__) \ - REGISTER_FUNCTION(__fcn__, std::complex<float>, __fcn__ ## _complex_float) \ - REGISTER_FUNCTION(__fcn__, std::complex<double>, __fcn__ ## _complex_double) - - //register both complex and real + } +}; + +// macro to create a work function and register it +#define REGISTER_FUNCTION(__fcn__, __type__, __key__) \ + static int __key__##_work(int noutput_items, \ + gr_vector_const_void_star& input_items, \ + gr_vector_void_star& output_items) \ + { \ + const __type__* in = (const __type__*)input_items[0]; \ + __type__* out = (__type__*)output_items[0]; \ + for (size_t i = 0; i < size_t(noutput_items); i++) { \ + out[i] = std::__fcn__(in[i]); \ + } \ + return noutput_items; \ + } \ + transcendental_registrant __key__##_registrant( \ + #__key__, &__key__##_work, sizeof(__type__)); + +// register work functions for real types +#define REGISTER_REAL_FUNCTIONS(__fcn__) \ + REGISTER_FUNCTION(__fcn__, float, __fcn__##_float) \ + REGISTER_FUNCTION(__fcn__, double, __fcn__##_double) + +// register work functions for complex types +#define REGISTER_COMPLEX_FUNCTIONS(__fcn__) \ + REGISTER_FUNCTION(__fcn__, std::complex<float>, __fcn__##_complex_float) \ + REGISTER_FUNCTION(__fcn__, std::complex<double>, __fcn__##_complex_double) + +// register both complex and real #define REGISTER_FUNCTIONS(__fcn__) \ - REGISTER_REAL_FUNCTIONS(__fcn__) \ + REGISTER_REAL_FUNCTIONS(__fcn__) \ REGISTER_COMPLEX_FUNCTIONS(__fcn__) - //create and register transcendental work functions - REGISTER_FUNCTIONS(cos) - REGISTER_FUNCTIONS(sin) - REGISTER_FUNCTIONS(tan) - REGISTER_REAL_FUNCTIONS(acos) - REGISTER_REAL_FUNCTIONS(asin) - REGISTER_REAL_FUNCTIONS(atan) - REGISTER_FUNCTIONS(cosh) - REGISTER_FUNCTIONS(sinh) - REGISTER_FUNCTIONS(tanh) - REGISTER_FUNCTIONS(exp) - REGISTER_FUNCTIONS(log) - REGISTER_FUNCTIONS(log10) - REGISTER_FUNCTIONS(sqrt) - - - transcendental::sptr - transcendental::make(const std::string &name, - const std::string &type) - { - //search for an entry in the map - const std::string key = name + "_" + type; - const bool has_key = get_map().count(key) != 0; - if(!has_key) +// create and register transcendental work functions +REGISTER_FUNCTIONS(cos) +REGISTER_FUNCTIONS(sin) +REGISTER_FUNCTIONS(tan) +REGISTER_REAL_FUNCTIONS(acos) +REGISTER_REAL_FUNCTIONS(asin) +REGISTER_REAL_FUNCTIONS(atan) +REGISTER_FUNCTIONS(cosh) +REGISTER_FUNCTIONS(sinh) +REGISTER_FUNCTIONS(tanh) +REGISTER_FUNCTIONS(exp) +REGISTER_FUNCTIONS(log) +REGISTER_FUNCTIONS(log10) +REGISTER_FUNCTIONS(sqrt) + + +transcendental::sptr transcendental::make(const std::string& name, + const std::string& type) +{ + // search for an entry in the map + const std::string key = name + "_" + type; + const bool has_key = get_map().count(key) != 0; + if (!has_key) throw std::runtime_error("could not find transcendental function for " + key); - //make a new block with found work function - return gnuradio::get_initial_sptr - (new transcendental_impl(get_map()[key].work_fcn, get_map()[key].io_size)); - } - - transcendental_impl::transcendental_impl(const work_fcn_type &work_fcn, - const size_t io_size) - : sync_block("transcendental", - io_signature::make(1, 1, io_size), - io_signature::make(1, 1, io_size)), - _work_fcn(work_fcn) - { - // NOP - } - - transcendental_impl::~transcendental_impl() - { - } - - int - transcendental_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - return _work_fcn(noutput_items, input_items, output_items); - } - - } /* namespace blocks */ + // make a new block with found work function + return gnuradio::get_initial_sptr( + new transcendental_impl(get_map()[key].work_fcn, get_map()[key].io_size)); +} + +transcendental_impl::transcendental_impl(const work_fcn_type& work_fcn, + const size_t io_size) + : sync_block("transcendental", + io_signature::make(1, 1, io_size), + io_signature::make(1, 1, io_size)), + _work_fcn(work_fcn) +{ + // NOP +} + +transcendental_impl::~transcendental_impl() {} + +int transcendental_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + return _work_fcn(noutput_items, input_items, output_items); +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/transcendental_impl.h b/gr-blocks/lib/transcendental_impl.h index bb82b23b66..359e6bcf6a 100644 --- a/gr-blocks/lib/transcendental_impl.h +++ b/gr-blocks/lib/transcendental_impl.h @@ -26,26 +26,25 @@ #include <gnuradio/blocks/transcendental.h> namespace gr { - namespace blocks { +namespace blocks { - typedef int(*work_fcn_type)(int, gr_vector_const_void_star &, gr_vector_void_star &); +typedef int (*work_fcn_type)(int, gr_vector_const_void_star&, gr_vector_void_star&); - class transcendental_impl : public transcendental - { - private: - const work_fcn_type &_work_fcn; +class transcendental_impl : public transcendental +{ +private: + const work_fcn_type& _work_fcn; - public: - transcendental_impl(const work_fcn_type &work_fcn, - const size_t io_size); - ~transcendental_impl(); +public: + transcendental_impl(const work_fcn_type& work_fcn, const size_t io_size); + ~transcendental_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_TRANSCENDENTAL_IMPL_H */ diff --git a/gr-blocks/lib/tsb_vector_sink_impl.cc b/gr-blocks/lib/tsb_vector_sink_impl.cc index 79c1fe7c73..676af1b705 100644 --- a/gr-blocks/lib/tsb_vector_sink_impl.cc +++ b/gr-blocks/lib/tsb_vector_sink_impl.cc @@ -29,67 +29,65 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename tsb_vector_sink<T>::sptr - tsb_vector_sink<T>::make(unsigned int vlen, const std::string &tsb_key) - { - return gnuradio::get_initial_sptr - (new tsb_vector_sink_impl<T> (vlen, tsb_key)); - } +template <class T> +typename tsb_vector_sink<T>::sptr tsb_vector_sink<T>::make(unsigned int vlen, + const std::string& tsb_key) +{ + return gnuradio::get_initial_sptr(new tsb_vector_sink_impl<T>(vlen, tsb_key)); +} - template <class T> - tsb_vector_sink_impl<T> ::tsb_vector_sink_impl(unsigned int vlen, const std::string &tsb_key) - : gr::tagged_stream_block("tsb_vector_sink", - gr::io_signature::make(1, 1, vlen * sizeof(T)), - gr::io_signature::make(0, 0, 0), tsb_key), +template <class T> +tsb_vector_sink_impl<T>::tsb_vector_sink_impl(unsigned int vlen, + const std::string& tsb_key) + : gr::tagged_stream_block("tsb_vector_sink", + gr::io_signature::make(1, 1, vlen * sizeof(T)), + gr::io_signature::make(0, 0, 0), + tsb_key), d_vlen(vlen) - {} +{ +} - template <class T> - tsb_vector_sink_impl<T> ::~tsb_vector_sink_impl() - { - } +template <class T> +tsb_vector_sink_impl<T>::~tsb_vector_sink_impl() +{ +} - template <class T> - std::vector<std::vector<T> > - tsb_vector_sink_impl<T> ::data() const - { - return d_data; - } +template <class T> +std::vector<std::vector<T>> tsb_vector_sink_impl<T>::data() const +{ + return d_data; +} - template <class T> - std::vector<tag_t> - tsb_vector_sink_impl<T> ::tags() const - { - return d_tags; - } +template <class T> +std::vector<tag_t> tsb_vector_sink_impl<T>::tags() const +{ + return d_tags; +} - template <class T> - int - tsb_vector_sink_impl<T> ::work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const T *in = (const T *) input_items[0]; +template <class T> +int tsb_vector_sink_impl<T>::work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const T* in = (const T*)input_items[0]; - std::vector<T> new_data(in, in + (ninput_items[0] * d_vlen)); - d_data.push_back(new_data); + std::vector<T> new_data(in, in + (ninput_items[0] * d_vlen)); + d_data.push_back(new_data); - std::vector<tag_t> tags; - this->get_tags_in_window(tags, 0, 0, ninput_items[0]); - d_tags.insert(d_tags.end(), tags.begin(), tags.end()); + std::vector<tag_t> tags; + this->get_tags_in_window(tags, 0, 0, ninput_items[0]); + d_tags.insert(d_tags.end(), tags.begin(), tags.end()); - return ninput_items[0]; - } + return ninput_items[0]; +} template class tsb_vector_sink<std::uint8_t>; template class tsb_vector_sink<std::int16_t>; template class tsb_vector_sink<std::int32_t>; template class tsb_vector_sink<float>; template class tsb_vector_sink<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ - diff --git a/gr-blocks/lib/tsb_vector_sink_impl.h b/gr-blocks/lib/tsb_vector_sink_impl.h index 6da7e2de6e..0a703ec865 100644 --- a/gr-blocks/lib/tsb_vector_sink_impl.h +++ b/gr-blocks/lib/tsb_vector_sink_impl.h @@ -27,32 +27,31 @@ #include <gnuradio/blocks/tsb_vector_sink.h> namespace gr { - namespace blocks { - -template<class T> - class tsb_vector_sink_impl : public tsb_vector_sink<T> - { - private: - std::vector<std::vector<T> > d_data; - std::vector<tag_t> d_tags; - unsigned int d_vlen; - - public: - tsb_vector_sink_impl (unsigned int vlen, const std::string &tsb_key); - ~tsb_vector_sink_impl (); - - void reset() { d_data.clear(); } - std::vector<std::vector<T> > data() const; - std::vector<tag_t> tags() const; - - 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 blocks { + +template <class T> +class tsb_vector_sink_impl : public tsb_vector_sink<T> +{ +private: + std::vector<std::vector<T>> d_data; + std::vector<tag_t> d_tags; + unsigned int d_vlen; + +public: + tsb_vector_sink_impl(unsigned int vlen, const std::string& tsb_key); + ~tsb_vector_sink_impl(); + + void reset() { d_data.clear(); } + std::vector<std::vector<T>> data() const; + std::vector<tag_t> tags() const; + + 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 /* TSB_VECTOR_SINK_IMPL_H */ - diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc index 64eeb02255..fa16683510 100644 --- a/gr-blocks/lib/tuntap_pdu_impl.cc +++ b/gr-blocks/lib/tuntap_pdu_impl.cc @@ -40,143 +40,140 @@ #endif namespace gr { - namespace blocks { +namespace blocks { - tuntap_pdu::sptr - tuntap_pdu::make(std::string dev, int MTU, bool istunflag) - { +tuntap_pdu::sptr tuntap_pdu::make(std::string dev, int MTU, bool istunflag) +{ #if (defined(linux) || defined(__linux) || defined(__linux__)) - return gnuradio::get_initial_sptr(new tuntap_pdu_impl(dev, MTU, istunflag)); + return gnuradio::get_initial_sptr(new tuntap_pdu_impl(dev, MTU, istunflag)); #else - throw std::runtime_error("tuntap_pdu not implemented on this platform"); + throw std::runtime_error("tuntap_pdu not implemented on this platform"); #endif - } +} #if (defined(linux) || defined(__linux) || defined(__linux__)) - tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU, bool istunflag) - : block("tuntap_pdu", - io_signature::make (0, 0, 0), - io_signature::make (0, 0, 0)), - stream_pdu_base(istunflag ? MTU : MTU + 14), - d_dev(dev), - d_istunflag(istunflag) - { - // make the tuntap - char dev_cstr[1024]; - memset(dev_cstr, 0x00, 1024); - strncpy(dev_cstr, dev.c_str(), std::min(sizeof(dev_cstr), dev.size())); - - bool istun = d_istunflag; - if(istun){ - d_fd = tun_alloc(dev_cstr, (IFF_TUN | IFF_NO_PI)); - } else { - d_fd = tun_alloc(dev_cstr, (IFF_TAP | IFF_NO_PI)); - } - - if (d_fd <= 0) - throw std::runtime_error("gr::tuntap_pdu::make: tun_alloc failed (are you running as root?)"); - - int err = set_mtu(dev_cstr, MTU); - if(err < 0) - std::cerr << boost::format( - "gr::tuntap_pdu: failed to set MTU to %d.\n" - "You should use ifconfig to set the MTU. E.g.,\n" - " $ sudo ifconfig %s mtu %d\n" - ) % MTU % dev % MTU << std::endl; - - std::cout << boost::format( - "Allocated virtual ethernet interface: %s\n" - "You must now use ifconfig to set its IP address. E.g.,\n" - " $ sudo ifconfig %s 192.168.200.1\n" - "Be sure to use a different address in the same subnet for each machine.\n" - ) % dev % dev << std::endl; - - // set up output message port - message_port_register_out(pdu::pdu_port_id()); - start_rxthread(this, pdu::pdu_port_id()); - - // set up input message port - message_port_register_in(pdu::pdu_port_id()); - set_msg_handler(pdu::pdu_port_id(), boost::bind(&tuntap_pdu_impl::send, this, _1)); +tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU, bool istunflag) + : block("tuntap_pdu", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)), + stream_pdu_base(istunflag ? MTU : MTU + 14), + d_dev(dev), + d_istunflag(istunflag) +{ + // make the tuntap + char dev_cstr[1024]; + memset(dev_cstr, 0x00, 1024); + strncpy(dev_cstr, dev.c_str(), std::min(sizeof(dev_cstr), dev.size())); + + bool istun = d_istunflag; + if (istun) { + d_fd = tun_alloc(dev_cstr, (IFF_TUN | IFF_NO_PI)); + } else { + d_fd = tun_alloc(dev_cstr, (IFF_TAP | IFF_NO_PI)); } - int - tuntap_pdu_impl::tun_alloc(char *dev, int flags) - { - struct ifreq ifr; - int fd, err; - const char *clonedev = "/dev/net/tun"; - - /* Arguments taken by the function: - * - * char *dev: the name of an interface (or '\0'). MUST have enough - * space to hold the interface name if '\0' is passed - * int flags: interface flags (eg, IFF_TUN etc.) - */ - - /* open the clone device */ - if ((fd = open(clonedev, O_RDWR)) < 0) + if (d_fd <= 0) + throw std::runtime_error( + "gr::tuntap_pdu::make: tun_alloc failed (are you running as root?)"); + + int err = set_mtu(dev_cstr, MTU); + if (err < 0) + std::cerr << boost::format("gr::tuntap_pdu: failed to set MTU to %d.\n" + "You should use ifconfig to set the MTU. E.g.,\n" + " $ sudo ifconfig %s mtu %d\n") % + MTU % dev % MTU + << std::endl; + + std::cout << boost::format("Allocated virtual ethernet interface: %s\n" + "You must now use ifconfig to set its IP address. E.g.,\n" + " $ sudo ifconfig %s 192.168.200.1\n" + "Be sure to use a different address in the same subnet " + "for each machine.\n") % + dev % dev + << std::endl; + + // set up output message port + message_port_register_out(pdu::pdu_port_id()); + start_rxthread(this, pdu::pdu_port_id()); + + // set up input message port + message_port_register_in(pdu::pdu_port_id()); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&tuntap_pdu_impl::send, this, _1)); +} + +int tuntap_pdu_impl::tun_alloc(char* dev, int flags) +{ + struct ifreq ifr; + int fd, err; + const char* clonedev = "/dev/net/tun"; + + /* Arguments taken by the function: + * + * char *dev: the name of an interface (or '\0'). MUST have enough + * space to hold the interface name if '\0' is passed + * int flags: interface flags (eg, IFF_TUN etc.) + */ + + /* open the clone device */ + if ((fd = open(clonedev, O_RDWR)) < 0) return fd; - /* preparation of the struct ifr, of type "struct ifreq" */ - memset(&ifr, 0, sizeof(ifr)); + /* preparation of the struct ifr, of type "struct ifreq" */ + memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_flags = flags; /* IFF_TUN or IFF_TAP, plus maybe IFF_NO_PI */ + ifr.ifr_flags = flags; /* IFF_TUN or IFF_TAP, plus maybe IFF_NO_PI */ - /* if a device name was specified, put it in the structure; otherwise, - * the kernel will try to allocate the "next" device of the - * specified type - */ - if (*dev) + /* if a device name was specified, put it in the structure; otherwise, + * the kernel will try to allocate the "next" device of the + * specified type + */ + if (*dev) strncpy(ifr.ifr_name, dev, IFNAMSIZ - 1); - /* try to create the device */ - if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0) { + /* try to create the device */ + if ((err = ioctl(fd, TUNSETIFF, (void*)&ifr)) < 0) { close(fd); return err; - } - - /* if the operation was successful, write back the name of the - * interface to the variable "dev", so the caller can know - * it. Note that the caller MUST reserve space in *dev (see calling - * code below) - */ - strcpy(dev, ifr.ifr_name); - - /* this is the special file descriptor that the caller will use to talk - * with the virtual interface - */ - return fd; } - int - tuntap_pdu_impl::set_mtu(const char *dev, int MTU) - { - struct ifreq ifr; - int sfd, err; - - /* MTU must be set by passing a socket fd to ioctl; - * create an arbitrary socket for this purpose - */ - if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - return sfd; - - /* preparation of the struct ifr, of type "struct ifreq" */ - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, dev, IFNAMSIZ); - ifr.ifr_addr.sa_family = AF_INET; /* address family */ - ifr.ifr_mtu = MTU; - - /* try to set MTU */ - if ((err = ioctl(sfd, SIOCSIFMTU, (void *) &ifr)) < 0) { - close(sfd); - return err; - } - - close(sfd); - return MTU; + /* if the operation was successful, write back the name of the + * interface to the variable "dev", so the caller can know + * it. Note that the caller MUST reserve space in *dev (see calling + * code below) + */ + strcpy(dev, ifr.ifr_name); + + /* this is the special file descriptor that the caller will use to talk + * with the virtual interface + */ + return fd; +} + +int tuntap_pdu_impl::set_mtu(const char* dev, int MTU) +{ + struct ifreq ifr; + int sfd, err; + + /* MTU must be set by passing a socket fd to ioctl; + * create an arbitrary socket for this purpose + */ + if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + return sfd; + + /* preparation of the struct ifr, of type "struct ifreq" */ + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); + ifr.ifr_addr.sa_family = AF_INET; /* address family */ + ifr.ifr_mtu = MTU; + + /* try to set MTU */ + if ((err = ioctl(sfd, SIOCSIFMTU, (void*)&ifr)) < 0) { + close(sfd); + return err; } + + close(sfd); + return MTU; +} #endif - } /* namespace blocks */ -}/* namespace gr */ +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/tuntap_pdu_impl.h b/gr-blocks/lib/tuntap_pdu_impl.h index 3a53e3acb5..31afc445e7 100644 --- a/gr-blocks/lib/tuntap_pdu_impl.h +++ b/gr-blocks/lib/tuntap_pdu_impl.h @@ -31,23 +31,23 @@ #endif namespace gr { - namespace blocks { +namespace blocks { - class tuntap_pdu_impl : public tuntap_pdu, public stream_pdu_base - { +class tuntap_pdu_impl : public tuntap_pdu, public stream_pdu_base +{ #if (defined(linux) || defined(__linux) || defined(__linux__)) - private: - std::string d_dev; - bool d_istunflag; - int tun_alloc(char *dev, int flags); - int set_mtu(const char *dev, int MTU); - - public: - tuntap_pdu_impl(std::string dev, int MTU, bool istunflag); +private: + std::string d_dev; + bool d_istunflag; + int tun_alloc(char* dev, int flags); + int set_mtu(const char* dev, int MTU); + +public: + tuntap_pdu_impl(std::string dev, int MTU, bool istunflag); #endif - }; +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_BLOCKS_TUNTAP_PDU_IMPL_H */ diff --git a/gr-blocks/lib/uchar_array_to_float.cc b/gr-blocks/lib/uchar_array_to_float.cc index c3e2c3f369..4a2efe8da5 100644 --- a/gr-blocks/lib/uchar_array_to_float.cc +++ b/gr-blocks/lib/uchar_array_to_float.cc @@ -22,19 +22,18 @@ #include "uchar_array_to_float.h" -void -uchar_array_to_float (const unsigned char *in, float *out, int nsamples) +void uchar_array_to_float(const unsigned char* in, float* out, int nsamples) { - while (nsamples >= 4){ - out[0] = in[0]; - out[1] = in[1]; - out[2] = in[2]; - out[3] = in[3]; - out += 4; - in += 4; - nsamples -= 4; - } + while (nsamples >= 4) { + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[2]; + out[3] = in[3]; + out += 4; + in += 4; + nsamples -= 4; + } - while (nsamples-- > 0) - *out++ = *in++; + while (nsamples-- > 0) + *out++ = *in++; } diff --git a/gr-blocks/lib/uchar_array_to_float.h b/gr-blocks/lib/uchar_array_to_float.h index 9b499760aa..93ba88d9f7 100644 --- a/gr-blocks/lib/uchar_array_to_float.h +++ b/gr-blocks/lib/uchar_array_to_float.h @@ -28,7 +28,7 @@ /* * convert array of unsigned chars to floats */ -BLOCKS_API void uchar_array_to_float (const unsigned char *in, float *out, int nsamples); +BLOCKS_API void uchar_array_to_float(const unsigned char* in, float* out, int nsamples); #endif /* INCLUDED_UCHAR_ARRAY_TO_FLOAT_H */ diff --git a/gr-blocks/lib/uchar_to_float_impl.cc b/gr-blocks/lib/uchar_to_float_impl.cc index 0068094861..ec666da349 100644 --- a/gr-blocks/lib/uchar_to_float_impl.cc +++ b/gr-blocks/lib/uchar_to_float_impl.cc @@ -29,32 +29,31 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - - uchar_to_float::sptr uchar_to_float::make() - { - return gnuradio::get_initial_sptr(new uchar_to_float_impl()); - } - - uchar_to_float_impl::uchar_to_float_impl() - : sync_block("uchar_to_float", - io_signature::make (1, 1, sizeof(unsigned char)), - io_signature::make (1, 1, sizeof(float))) - { - } - - int - uchar_to_float_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char *) input_items[0]; - float *out = (float *) output_items[0]; - - uchar_array_to_float (in, out, noutput_items); - - return noutput_items; - } - - } /* namespace blocks */ -}/* namespace gr */ +namespace blocks { + +uchar_to_float::sptr uchar_to_float::make() +{ + return gnuradio::get_initial_sptr(new uchar_to_float_impl()); +} + +uchar_to_float_impl::uchar_to_float_impl() + : sync_block("uchar_to_float", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(float))) +{ +} + +int uchar_to_float_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + float* out = (float*)output_items[0]; + + uchar_array_to_float(in, out, noutput_items); + + return noutput_items; +} + +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/uchar_to_float_impl.h b/gr-blocks/lib/uchar_to_float_impl.h index 602662c54f..d22a72cde2 100644 --- a/gr-blocks/lib/uchar_to_float_impl.h +++ b/gr-blocks/lib/uchar_to_float_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/uchar_to_float.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API uchar_to_float_impl : public uchar_to_float - { - public: - uchar_to_float_impl(); +class BLOCKS_API uchar_to_float_impl : public uchar_to_float +{ +public: + uchar_to_float_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/udp_sink_impl.cc b/gr-blocks/lib/udp_sink_impl.cc index b540a7da19..cb44ba0b6f 100644 --- a/gr-blocks/lib/udp_sink_impl.cc +++ b/gr-blocks/lib/udp_sink_impl.cc @@ -35,49 +35,45 @@ #include <string.h> namespace gr { - namespace blocks { - - udp_sink::sptr - udp_sink::make(size_t itemsize, - const std::string &host, int port, - int payload_size, bool eof) - { - return gnuradio::get_initial_sptr - (new udp_sink_impl(itemsize, host, port, - payload_size, eof)); - } - - udp_sink_impl::udp_sink_impl(size_t itemsize, - const std::string &host, int port, - int payload_size, bool eof) - : sync_block("udp_sink", - io_signature::make(1, 1, itemsize), - io_signature::make(0, 0, 0)), - d_itemsize(itemsize), d_payload_size(payload_size), d_eof(eof), - d_connected(false) - { - // Get the destination address - connect(host, port); - } - - // public constructor that returns a shared_ptr - udp_sink_impl::~udp_sink_impl() - { - if(d_connected) +namespace blocks { + +udp_sink::sptr udp_sink::make( + size_t itemsize, const std::string& host, int port, int payload_size, bool eof) +{ + return gnuradio::get_initial_sptr( + new udp_sink_impl(itemsize, host, port, payload_size, eof)); +} + +udp_sink_impl::udp_sink_impl( + size_t itemsize, const std::string& host, int port, int payload_size, bool eof) + : sync_block( + "udp_sink", io_signature::make(1, 1, itemsize), io_signature::make(0, 0, 0)), + d_itemsize(itemsize), + d_payload_size(payload_size), + d_eof(eof), + d_connected(false) +{ + // Get the destination address + connect(host, port); +} + +// public constructor that returns a shared_ptr +udp_sink_impl::~udp_sink_impl() +{ + if (d_connected) disconnect(); - } +} - void - udp_sink_impl::connect(const std::string &host, int port) - { - if(d_connected) +void udp_sink_impl::connect(const std::string& host, int port) +{ + if (d_connected) disconnect(); - std::string s_port = (boost::format("%d")%port).str(); - if(host.size() > 0) { + std::string s_port = (boost::format("%d") % port).str(); + if (host.size() > 0) { boost::asio::ip::udp::resolver resolver(d_io_service); - boost::asio::ip::udp::resolver::query query(host, s_port, - boost::asio::ip::resolver_query_base::passive); + boost::asio::ip::udp::resolver::query query( + host, s_port, boost::asio::ip::resolver_query_base::passive); d_endpoint = *resolver.resolve(query); d_socket = new boost::asio::ip::udp::socket(d_io_service); @@ -87,63 +83,59 @@ namespace gr { d_socket->set_option(roption); d_connected = true; - } } +} - void - udp_sink_impl::disconnect() - { - if(!d_connected) +void udp_sink_impl::disconnect() +{ + if (!d_connected) return; - gr::thread::scoped_lock guard(d_mutex); // protect d_socket from work() + gr::thread::scoped_lock guard(d_mutex); // protect d_socket from work() - // Send a few zero-length packets to signal receiver we are done - boost::array<char, 0> send_buf; - if(d_eof) { + // Send a few zero-length packets to signal receiver we are done + boost::array<char, 0> send_buf; + if (d_eof) { int i; - for(i = 0; i < 3; i++) - d_socket->send_to(boost::asio::buffer(send_buf), d_endpoint); - } - - d_socket->close(); - delete d_socket; - - d_connected = false; + for (i = 0; i < 3; i++) + d_socket->send_to(boost::asio::buffer(send_buf), d_endpoint); } - int - udp_sink_impl::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char *in = (const char *) input_items[0]; - ssize_t r=0, bytes_sent=0, bytes_to_send=0; - ssize_t total_size = noutput_items*d_itemsize; - - gr::thread::scoped_lock guard(d_mutex); // protect d_socket - - while(bytes_sent < total_size) { - bytes_to_send = std::min((ssize_t)d_payload_size, (total_size-bytes_sent)); - - if(d_connected) { - try { - r = d_socket->send_to(boost::asio::buffer((void*)(in+bytes_sent), bytes_to_send), - d_endpoint); - } - catch(std::exception& e) { - GR_LOG_ERROR(d_logger, boost::format("send error: %s") % e.what()); - return -1; - } - } - else - r = bytes_to_send; // discarded for lack of connection + d_socket->close(); + delete d_socket; + + d_connected = false; +} + +int udp_sink_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char* in = (const char*)input_items[0]; + ssize_t r = 0, bytes_sent = 0, bytes_to_send = 0; + ssize_t total_size = noutput_items * d_itemsize; + + gr::thread::scoped_lock guard(d_mutex); // protect d_socket + + while (bytes_sent < total_size) { + bytes_to_send = std::min((ssize_t)d_payload_size, (total_size - bytes_sent)); + + if (d_connected) { + try { + r = d_socket->send_to( + boost::asio::buffer((void*)(in + bytes_sent), bytes_to_send), + d_endpoint); + } catch (std::exception& e) { + GR_LOG_ERROR(d_logger, boost::format("send error: %s") % e.what()); + return -1; + } + } else + r = bytes_to_send; // discarded for lack of connection bytes_sent += r; - } - - return noutput_items; } - } /* namespace blocks */ -} /* namespace gr */ + return noutput_items; +} +} /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/udp_sink_impl.h b/gr-blocks/lib/udp_sink_impl.h index c593e6e809..5b3a2bd015 100644 --- a/gr-blocks/lib/udp_sink_impl.h +++ b/gr-blocks/lib/udp_sink_impl.h @@ -27,39 +27,38 @@ #include <boost/asio.hpp> namespace gr { - namespace blocks { +namespace blocks { - class udp_sink_impl : public udp_sink - { - private: - size_t d_itemsize; +class udp_sink_impl : public udp_sink +{ +private: + size_t d_itemsize; - int d_payload_size; // maximum transmission unit (packet length) - bool d_eof; // send zero-length packet on disconnect - bool d_connected; // are we connected? - gr::thread::mutex d_mutex; // protects d_socket and d_connected + int d_payload_size; // maximum transmission unit (packet length) + bool d_eof; // send zero-length packet on disconnect + bool d_connected; // are we connected? + gr::thread::mutex d_mutex; // protects d_socket and d_connected - boost::asio::ip::udp::socket *d_socket; // handle to socket - boost::asio::ip::udp::endpoint d_endpoint; - boost::asio::io_service d_io_service; + boost::asio::ip::udp::socket* d_socket; // handle to socket + boost::asio::ip::udp::endpoint d_endpoint; + boost::asio::io_service d_io_service; - public: - udp_sink_impl(size_t itemsize, - const std::string &host, int port, - int payload_size, bool eof); - ~udp_sink_impl(); +public: + udp_sink_impl( + size_t itemsize, const std::string& host, int port, int payload_size, bool eof); + ~udp_sink_impl(); - int payload_size() { return d_payload_size; } + int payload_size() { return d_payload_size; } - void connect(const std::string &host, int port); - void disconnect(); + void connect(const std::string& host, int port); + void disconnect(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_UDP_SINK_IMPL_H */ diff --git a/gr-blocks/lib/udp_source_impl.cc b/gr-blocks/lib/udp_source_impl.cc index 66fb68741a..c948410c02 100644 --- a/gr-blocks/lib/udp_source_impl.cc +++ b/gr-blocks/lib/udp_source_impl.cc @@ -34,62 +34,60 @@ #include <string.h> namespace gr { - namespace blocks { - - const int udp_source_impl::BUF_SIZE_PAYLOADS = - gr::prefs::singleton()->get_long("udp_blocks", "buf_size_payloads", 50); - - udp_source::sptr - udp_source::make(size_t itemsize, - const std::string &ipaddr, int port, - int payload_size, bool eof) - { - return gnuradio::get_initial_sptr - (new udp_source_impl(itemsize, ipaddr, port, - payload_size, eof)); - } - - udp_source_impl::udp_source_impl(size_t itemsize, - const std::string &host, int port, - int payload_size, bool eof) - : sync_block("udp_source", - io_signature::make(0, 0, 0), - io_signature::make(1, 1, itemsize)), - d_itemsize(itemsize), d_payload_size(payload_size), - d_eof(eof), d_connected(false), d_residual(0), d_sent(0) - { - // Give us some more room to play. - d_rxbuf = new char[4*d_payload_size]; - d_residbuf = new char[BUF_SIZE_PAYLOADS*d_payload_size]; - - connect(host, port); - } - - udp_source_impl::~udp_source_impl() - { - if(d_connected) +namespace blocks { + +const int udp_source_impl::BUF_SIZE_PAYLOADS = + gr::prefs::singleton()->get_long("udp_blocks", "buf_size_payloads", 50); + +udp_source::sptr udp_source::make( + size_t itemsize, const std::string& ipaddr, int port, int payload_size, bool eof) +{ + return gnuradio::get_initial_sptr( + new udp_source_impl(itemsize, ipaddr, port, payload_size, eof)); +} + +udp_source_impl::udp_source_impl( + size_t itemsize, const std::string& host, int port, int payload_size, bool eof) + : sync_block( + "udp_source", io_signature::make(0, 0, 0), io_signature::make(1, 1, itemsize)), + d_itemsize(itemsize), + d_payload_size(payload_size), + d_eof(eof), + d_connected(false), + d_residual(0), + d_sent(0) +{ + // Give us some more room to play. + d_rxbuf = new char[4 * d_payload_size]; + d_residbuf = new char[BUF_SIZE_PAYLOADS * d_payload_size]; + + connect(host, port); +} + +udp_source_impl::~udp_source_impl() +{ + if (d_connected) disconnect(); - delete [] d_rxbuf; - delete [] d_residbuf; - } + delete[] d_rxbuf; + delete[] d_residbuf; +} - void - udp_source_impl::connect(const std::string &host, int port) - { - if(d_connected) +void udp_source_impl::connect(const std::string& host, int port) +{ + if (d_connected) disconnect(); - d_host = host; - d_port = static_cast<unsigned short>(port); + d_host = host; + d_port = static_cast<unsigned short>(port); - std::string s_port; - s_port = (boost::format("%d")%d_port).str(); + std::string s_port; + s_port = (boost::format("%d") % d_port).str(); - if(host.size() > 0) { + if (host.size() > 0) { boost::asio::ip::udp::resolver resolver(d_io_service); - boost::asio::ip::udp::resolver::query query(d_host, s_port, - boost::asio::ip::resolver_query_base::passive); + boost::asio::ip::udp::resolver::query query( + d_host, s_port, boost::asio::ip::resolver_query_base::passive); d_endpoint = *resolver.resolve(query); d_socket = new boost::asio::ip::udp::socket(d_io_service); @@ -101,121 +99,118 @@ namespace gr { d_socket->bind(d_endpoint); start_receive(); - d_udp_thread = gr::thread::thread(boost::bind(&udp_source_impl::run_io_service, this)); + d_udp_thread = + gr::thread::thread(boost::bind(&udp_source_impl::run_io_service, this)); d_connected = true; - } } +} - void - udp_source_impl::disconnect() - { - gr::thread::scoped_lock lock(d_setlock); +void udp_source_impl::disconnect() +{ + gr::thread::scoped_lock lock(d_setlock); - if(!d_connected) + if (!d_connected) return; - d_io_service.reset(); - d_io_service.stop(); - d_udp_thread.join(); - - d_socket->close(); - delete d_socket; - - d_connected = false; - } - - // Return port number of d_socket - int - udp_source_impl::get_port(void) - { - //return d_endpoint.port(); - return d_socket->local_endpoint().port(); - } - - void - udp_source_impl::start_receive() - { - d_socket->async_receive_from(boost::asio::buffer((void*)d_rxbuf, d_payload_size), d_endpoint_rcvd, - boost::bind(&udp_source_impl::handle_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } - - void - udp_source_impl::handle_read(const boost::system::error_code& error, - size_t bytes_transferred) - { - if(!error) { + d_io_service.reset(); + d_io_service.stop(); + d_udp_thread.join(); + + d_socket->close(); + delete d_socket; + + d_connected = false; +} + +// Return port number of d_socket +int udp_source_impl::get_port(void) +{ + // return d_endpoint.port(); + return d_socket->local_endpoint().port(); +} + +void udp_source_impl::start_receive() +{ + d_socket->async_receive_from( + boost::asio::buffer((void*)d_rxbuf, d_payload_size), + d_endpoint_rcvd, + boost::bind(&udp_source_impl::handle_read, + this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); +} + +void udp_source_impl::handle_read(const boost::system::error_code& error, + size_t bytes_transferred) +{ + if (!error) { { - boost::lock_guard<gr::thread::mutex> lock(d_udp_mutex); - if(d_eof && (bytes_transferred == 0)) { - // If we are using EOF notification, test for it and don't - // add anything to the output. - d_residual = WORK_DONE; - d_cond_wait.notify_one(); - return; - } - else { - // Make sure we never go beyond the boundary of the - // residual buffer. This will just drop the last bit of - // data in the buffer if we've run out of room. - if((int)(d_residual + bytes_transferred) >= (BUF_SIZE_PAYLOADS*d_payload_size)) { - GR_LOG_WARN(d_logger, "Too much data; dropping packet."); - } - else { - // otherwise, copy received data into local buffer for - // copying later. - memcpy(d_residbuf+d_residual, d_rxbuf, bytes_transferred); - d_residual += bytes_transferred; + boost::lock_guard<gr::thread::mutex> lock(d_udp_mutex); + if (d_eof && (bytes_transferred == 0)) { + // If we are using EOF notification, test for it and don't + // add anything to the output. + d_residual = WORK_DONE; + d_cond_wait.notify_one(); + return; + } else { + // Make sure we never go beyond the boundary of the + // residual buffer. This will just drop the last bit of + // data in the buffer if we've run out of room. + if ((int)(d_residual + bytes_transferred) >= + (BUF_SIZE_PAYLOADS * d_payload_size)) { + GR_LOG_WARN(d_logger, "Too much data; dropping packet."); + } else { + // otherwise, copy received data into local buffer for + // copying later. + memcpy(d_residbuf + d_residual, d_rxbuf, bytes_transferred); + d_residual += bytes_transferred; + } } - } - d_cond_wait.notify_one(); + d_cond_wait.notify_one(); } - } - start_receive(); } + start_receive(); +} - int - udp_source_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - gr::thread::scoped_lock l(d_setlock); +int udp_source_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + gr::thread::scoped_lock l(d_setlock); - char *out = (char*)output_items[0]; + char* out = (char*)output_items[0]; - // Use async receive_from to get data from UDP buffer and wait - // on a conditional signal before proceeding. We use this - // because the conditional wait is interruptible while a - // synchronous receive_from is not. - boost::unique_lock<boost::mutex> lock(d_udp_mutex); + // Use async receive_from to get data from UDP buffer and wait + // on a conditional signal before proceeding. We use this + // because the conditional wait is interruptible while a + // synchronous receive_from is not. + boost::unique_lock<boost::mutex> lock(d_udp_mutex); - //use timed_wait to avoid permanent blocking in the work function - d_cond_wait.timed_wait(lock, boost::posix_time::milliseconds(10)); + // use timed_wait to avoid permanent blocking in the work function + d_cond_wait.timed_wait(lock, boost::posix_time::milliseconds(10)); - if (d_residual < 0) { + if (d_residual < 0) { return d_residual; - } + } - int bytes_left_in_buffer = (int)(d_residual - d_sent); - int bytes_to_send = std::min<int>(d_itemsize * noutput_items, bytes_left_in_buffer); + int bytes_left_in_buffer = (int)(d_residual - d_sent); + int bytes_to_send = std::min<int>(d_itemsize * noutput_items, bytes_left_in_buffer); - // Copy the received data in the residual buffer to the output stream - memcpy(out, d_residbuf+d_sent, bytes_to_send); - int nitems = bytes_to_send/d_itemsize; + // Copy the received data in the residual buffer to the output stream + memcpy(out, d_residbuf + d_sent, bytes_to_send); + int nitems = bytes_to_send / d_itemsize; - // Keep track of where we are if we don't have enough output - // space to send all the data in the residbuf. - if (bytes_to_send == bytes_left_in_buffer) { + // Keep track of where we are if we don't have enough output + // space to send all the data in the residbuf. + if (bytes_to_send == bytes_left_in_buffer) { d_residual = 0; d_sent = 0; - } - else { + } else { d_sent += bytes_to_send; - } - - return nitems; } - } /* namespace blocks */ + return nitems; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/udp_source_impl.h b/gr-blocks/lib/udp_source_impl.h index 5b4b6996ab..a1f0b3b06d 100644 --- a/gr-blocks/lib/udp_source_impl.h +++ b/gr-blocks/lib/udp_source_impl.h @@ -29,57 +29,56 @@ #include <gnuradio/thread/thread.h> namespace gr { - namespace blocks { +namespace blocks { - class udp_source_impl : public udp_source - { - private: - size_t d_itemsize; - int d_payload_size; // maximum transmission unit (packet length) - bool d_eof; // look for an EOF signal - bool d_connected; // are we connected? - char *d_rxbuf; // get UDP buffer items - char *d_residbuf; // hold buffer between calls - ssize_t d_residual; // hold information about number of bytes stored in residbuf - ssize_t d_sent; // track how much of d_residbuf we've outputted +class udp_source_impl : public udp_source +{ +private: + size_t d_itemsize; + int d_payload_size; // maximum transmission unit (packet length) + bool d_eof; // look for an EOF signal + bool d_connected; // are we connected? + char* d_rxbuf; // get UDP buffer items + char* d_residbuf; // hold buffer between calls + ssize_t d_residual; // hold information about number of bytes stored in residbuf + ssize_t d_sent; // track how much of d_residbuf we've outputted - static const int BUF_SIZE_PAYLOADS; //!< The d_residbuf size in multiples of d_payload_size + static const int + BUF_SIZE_PAYLOADS; //!< The d_residbuf size in multiples of d_payload_size - std::string d_host; - unsigned short d_port; + std::string d_host; + unsigned short d_port; - boost::asio::ip::udp::socket *d_socket; - boost::asio::ip::udp::endpoint d_endpoint; - boost::asio::ip::udp::endpoint d_endpoint_rcvd; - boost::asio::io_service d_io_service; + boost::asio::ip::udp::socket* d_socket; + boost::asio::ip::udp::endpoint d_endpoint; + boost::asio::ip::udp::endpoint d_endpoint_rcvd; + boost::asio::io_service d_io_service; - gr::thread::condition_variable d_cond_wait; - gr::thread::mutex d_udp_mutex; - gr::thread::thread d_udp_thread; + gr::thread::condition_variable d_cond_wait; + gr::thread::mutex d_udp_mutex; + gr::thread::thread d_udp_thread; - void start_receive(); - void handle_read(const boost::system::error_code& error, - size_t bytes_transferred); - void run_io_service() { d_io_service.run(); } + void start_receive(); + void handle_read(const boost::system::error_code& error, size_t bytes_transferred); + void run_io_service() { d_io_service.run(); } - public: - udp_source_impl(size_t itemsize, - const std::string &host, int port, - int payload_size, bool eof); - ~udp_source_impl(); +public: + udp_source_impl( + size_t itemsize, const std::string& host, int port, int payload_size, bool eof); + ~udp_source_impl(); - void connect(const std::string &host, int port); - void disconnect(); + void connect(const std::string& host, int port); + void disconnect(); - int payload_size() { return d_payload_size; } - int get_port(); + int payload_size() { return d_payload_size; } + int get_port(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_UDP_SOURCE_H */ diff --git a/gr-blocks/lib/unpack_k_bits.cc b/gr-blocks/lib/unpack_k_bits.cc index 967d7e17d9..0865121d02 100644 --- a/gr-blocks/lib/unpack_k_bits.cc +++ b/gr-blocks/lib/unpack_k_bits.cc @@ -30,48 +30,43 @@ #include <iostream> namespace gr { - namespace blocks { - namespace kernel { +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(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() - { - } +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--) +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; - } - } + } +} - void - unpack_k_bits::unpack_rev(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(unsigned int j = 0; j < d_k; j++) +void unpack_k_bits::unpack_rev(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 (unsigned int j = 0; j < d_k; j++) bits[n++] = (t >> j) & 0x01; - } - } + } +} - int - unpack_k_bits::k() const - { - return d_k; - } +int unpack_k_bits::k() const { return d_k; } - } /* namespace kernel */ - } /* namespace blocks */ +} /* 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 caf3d059d6..49849e9285 100644 --- a/gr-blocks/lib/unpack_k_bits_bb_impl.cc +++ b/gr-blocks/lib/unpack_k_bits_bb_impl.cc @@ -30,41 +30,35 @@ #include <iostream> namespace gr { - namespace blocks { +namespace blocks { - unpack_k_bits_bb::sptr - unpack_k_bits_bb::make(unsigned k) - { - return gnuradio::get_initial_sptr - (new unpack_k_bits_bb_impl(k)); - } +unpack_k_bits_bb::sptr unpack_k_bits_bb::make(unsigned k) +{ + return gnuradio::get_initial_sptr(new unpack_k_bits_bb_impl(k)); +} - 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_unpack = new kernel::unpack_k_bits(k); - } +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_unpack = new kernel::unpack_k_bits(k); +} - unpack_k_bits_bb_impl::~unpack_k_bits_bb_impl() - { - delete d_unpack; - } +unpack_k_bits_bb_impl::~unpack_k_bits_bb_impl() { delete d_unpack; } - int - unpack_k_bits_bb_impl::work(int noutput_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 unpack_k_bits_bb_impl::work(int noutput_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]; - d_unpack->unpack(out, in, noutput_items/d_unpack->k()); + d_unpack->unpack(out, in, noutput_items / d_unpack->k()); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/unpack_k_bits_bb_impl.h b/gr-blocks/lib/unpack_k_bits_bb_impl.h index 246c4ea724..b677de81e1 100644 --- a/gr-blocks/lib/unpack_k_bits_bb_impl.h +++ b/gr-blocks/lib/unpack_k_bits_bb_impl.h @@ -21,29 +21,29 @@ */ #ifndef INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H -#define INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H +#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 { +namespace blocks { - class unpack_k_bits_bb_impl : public unpack_k_bits_bb - { - private: - kernel::unpack_k_bits *d_unpack; +class unpack_k_bits_bb_impl : public unpack_k_bits_bb +{ +private: + kernel::unpack_k_bits* d_unpack; - public: - unpack_k_bits_bb_impl(unsigned k); - ~unpack_k_bits_bb_impl(); +public: + unpack_k_bits_bb_impl(unsigned k); + ~unpack_k_bits_bb_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H */ diff --git a/gr-blocks/lib/unpacked_to_packed_impl.cc b/gr-blocks/lib/unpacked_to_packed_impl.cc index ff0fac1050..cdca25dd7e 100644 --- a/gr-blocks/lib/unpacked_to_packed_impl.cc +++ b/gr-blocks/lib/unpacked_to_packed_impl.cc @@ -30,121 +30,123 @@ #include <assert.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename unpacked_to_packed<T>::sptr - unpacked_to_packed<T>::make(unsigned int bits_per_chunk, - endianness_t endianness) - { - return gnuradio::get_initial_sptr - (new unpacked_to_packed_impl<T> (bits_per_chunk, endianness)); - } +template <class T> +typename unpacked_to_packed<T>::sptr +unpacked_to_packed<T>::make(unsigned int bits_per_chunk, endianness_t endianness) +{ + return gnuradio::get_initial_sptr( + new unpacked_to_packed_impl<T>(bits_per_chunk, endianness)); +} - template <class T> - unpacked_to_packed_impl<T> ::unpacked_to_packed_impl(unsigned int bits_per_chunk, - endianness_t endianness) +template <class T> +unpacked_to_packed_impl<T>::unpacked_to_packed_impl(unsigned int bits_per_chunk, + endianness_t endianness) : block("unpacked_to_packed", - io_signature::make(1, -1, sizeof(T)), - io_signature::make(1, -1, sizeof(T))), - d_bits_per_chunk(bits_per_chunk), d_endianness(endianness), d_index(0) - { - assert(bits_per_chunk <= d_bits_per_type); - assert(bits_per_chunk > 0); - - this->set_relative_rate((uint64_t)bits_per_chunk, (uint64_t)this->d_bits_per_type); - } - - template <class T> - unpacked_to_packed_impl<T> ::~unpacked_to_packed_impl() - { - } - - template <class T> - void - unpacked_to_packed_impl<T> ::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - int input_required = (int)ceil((d_index+noutput_items * 1.0 * d_bits_per_type) - / d_bits_per_chunk); - unsigned ninputs = ninput_items_required.size(); - for(unsigned int i = 0; i < ninputs; i++) { + io_signature::make(1, -1, sizeof(T)), + io_signature::make(1, -1, sizeof(T))), + d_bits_per_chunk(bits_per_chunk), + d_endianness(endianness), + d_index(0) +{ + assert(bits_per_chunk <= d_bits_per_type); + assert(bits_per_chunk > 0); + + this->set_relative_rate((uint64_t)bits_per_chunk, (uint64_t)this->d_bits_per_type); +} + +template <class T> +unpacked_to_packed_impl<T>::~unpacked_to_packed_impl() +{ +} + +template <class T> +void unpacked_to_packed_impl<T>::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{ + int input_required = + (int)ceil((d_index + noutput_items * 1.0 * d_bits_per_type) / d_bits_per_chunk); + unsigned ninputs = ninput_items_required.size(); + for (unsigned int i = 0; i < ninputs; i++) { ninput_items_required[i] = input_required; - } - } - - template <class T> - unsigned int - unpacked_to_packed_impl<T>::get_bit_be1(const T *in_vector, unsigned int bit_addr, - unsigned int bits_per_chunk) - { - unsigned int byte_addr = (int)bit_addr/bits_per_chunk; - T x = in_vector[byte_addr]; - unsigned int residue = bit_addr - byte_addr * bits_per_chunk; - //printf("Bit addr %d byte addr %d residue %d val %d\n",bit_addr,byte_addr,residue,(x>>(bits_per_chunk-1-residue))&1); - return (x >> (bits_per_chunk-1-residue)) & 1; } - - template <class T> - int - unpacked_to_packed_impl<T> ::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - unsigned int index_tmp = d_index; - - assert(input_items.size() == output_items.size()); - int nstreams = input_items.size(); - - for(int m=0; m< nstreams; m++) { - const T *in = (T *)input_items[m]; - T *out = (T *)output_items[m]; - index_tmp=d_index; +} + +template <class T> +unsigned int unpacked_to_packed_impl<T>::get_bit_be1(const T* in_vector, + unsigned int bit_addr, + unsigned int bits_per_chunk) +{ + unsigned int byte_addr = (int)bit_addr / bits_per_chunk; + T x = in_vector[byte_addr]; + unsigned int residue = bit_addr - byte_addr * bits_per_chunk; + // printf("Bit addr %d byte addr %d residue %d val + // %d\n",bit_addr,byte_addr,residue,(x>>(bits_per_chunk-1-residue))&1); + return (x >> (bits_per_chunk - 1 - residue)) & 1; +} + +template <class T> +int unpacked_to_packed_impl<T>::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + unsigned int index_tmp = d_index; + + assert(input_items.size() == output_items.size()); + int nstreams = input_items.size(); + + for (int m = 0; m < nstreams; m++) { + const T* in = (T*)input_items[m]; + T* out = (T*)output_items[m]; + index_tmp = d_index; // per stream processing - //assert((ninput_items[m]-d_index)*d_bits_per_chunk >= noutput_items*d_bits_per_type); + // assert((ninput_items[m]-d_index)*d_bits_per_chunk >= + // noutput_items*d_bits_per_type); - switch(d_endianness) { + switch (d_endianness) { case GR_MSB_FIRST: - for(int i = 0; i < noutput_items; i++) { - T tmp=0; - for(unsigned int j = 0; j < d_bits_per_type; j++) { - tmp = (tmp<<1) | get_bit_be1(in, index_tmp, d_bits_per_chunk); - index_tmp++; + for (int i = 0; i < noutput_items; i++) { + T tmp = 0; + for (unsigned int j = 0; j < d_bits_per_type; j++) { + tmp = (tmp << 1) | get_bit_be1(in, index_tmp, d_bits_per_chunk); + index_tmp++; + } + out[i] = tmp; } - out[i] = tmp; - } - break; + break; case GR_LSB_FIRST: - for(int i = 0; i < noutput_items; i++) { - unsigned long tmp=0; - for(unsigned int j = 0; j < d_bits_per_type; j++) { - tmp = (tmp>>1) | (get_bit_be1(in, index_tmp, d_bits_per_chunk) << (d_bits_per_type-1)); - index_tmp++; + for (int i = 0; i < noutput_items; i++) { + unsigned long tmp = 0; + for (unsigned int j = 0; j < d_bits_per_type; j++) { + tmp = (tmp >> 1) | (get_bit_be1(in, index_tmp, d_bits_per_chunk) + << (d_bits_per_type - 1)); + index_tmp++; + } + out[i] = tmp; } - out[i] = tmp; - } - break; + break; default: - assert(0); + assert(0); } - } + } - d_index = index_tmp; - this->consume_each((int)(d_index/d_bits_per_chunk)); - d_index = d_index%d_bits_per_chunk; + d_index = index_tmp; + this->consume_each((int)(d_index / d_bits_per_chunk)); + d_index = d_index % d_bits_per_chunk; - return noutput_items; - } + return noutput_items; +} template class unpacked_to_packed<std::uint8_t>; template class unpacked_to_packed<std::int16_t>; template class unpacked_to_packed<std::int32_t>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/unpacked_to_packed_impl.h b/gr-blocks/lib/unpacked_to_packed_impl.h index 78b39b0f2d..daa2ba6949 100644 --- a/gr-blocks/lib/unpacked_to_packed_impl.h +++ b/gr-blocks/lib/unpacked_to_packed_impl.h @@ -27,35 +27,33 @@ #include <gnuradio/blocks/unpacked_to_packed.h> namespace gr { - namespace blocks { - -template<class T> - class unpacked_to_packed_impl : public unpacked_to_packed<T> - { - private: - unsigned int d_bits_per_chunk; - endianness_t d_endianness; - unsigned int d_index; - const unsigned int d_bits_per_type = sizeof(T) * 8; - unsigned int get_bit_be1(const T *in_vector, unsigned int bit_addr, unsigned int bits_per_chunk); - - public: - unpacked_to_packed_impl (unsigned int bits_per_chunk, - endianness_t endianness); - ~unpacked_to_packed_impl (); - - void forecast(int noutput_items, - gr_vector_int &ninput_items_required); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - bool check_topology(int ninputs, int noutputs) - { return ninputs == noutputs; } - }; - - } /* namespace blocks */ +namespace blocks { + +template <class T> +class unpacked_to_packed_impl : public unpacked_to_packed<T> +{ +private: + unsigned int d_bits_per_chunk; + endianness_t d_endianness; + unsigned int d_index; + const unsigned int d_bits_per_type = sizeof(T) * 8; + unsigned int + get_bit_be1(const T* in_vector, unsigned int bit_addr, unsigned int bits_per_chunk); + +public: + unpacked_to_packed_impl(unsigned int bits_per_chunk, endianness_t endianness); + ~unpacked_to_packed_impl(); + + void forecast(int noutput_items, gr_vector_int& ninput_items_required); + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); + + bool check_topology(int ninputs, int noutputs) { return ninputs == noutputs; } +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* UNPACKED_TO_PACKED_IMPL_H */ diff --git a/gr-blocks/lib/vco_c_impl.cc b/gr-blocks/lib/vco_c_impl.cc index 5103ce1851..c83818475e 100644 --- a/gr-blocks/lib/vco_c_impl.cc +++ b/gr-blocks/lib/vco_c_impl.cc @@ -29,40 +29,38 @@ #include <math.h> namespace gr { - namespace blocks { +namespace blocks { - vco_c::sptr - vco_c::make(double sampling_rate, double sensitivity, double amplitude) - { - return gnuradio::get_initial_sptr - (new vco_c_impl(sampling_rate, sensitivity, amplitude)); - } +vco_c::sptr vco_c::make(double sampling_rate, double sensitivity, double amplitude) +{ + return gnuradio::get_initial_sptr( + new vco_c_impl(sampling_rate, sensitivity, amplitude)); +} - vco_c_impl::vco_c_impl(double sampling_rate, double sensitivity, double amplitude) - : sync_block("vco_c", - io_signature::make(1, 1, sizeof(float)), - io_signature::make(1, 1, sizeof(gr_complex))), - d_sampling_rate(sampling_rate), d_sensitivity(sensitivity), - d_amplitude(amplitude), d_k(d_sensitivity/d_sampling_rate) - { - } +vco_c_impl::vco_c_impl(double sampling_rate, double sensitivity, double amplitude) + : sync_block("vco_c", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(gr_complex))), + d_sampling_rate(sampling_rate), + d_sensitivity(sensitivity), + d_amplitude(amplitude), + d_k(d_sensitivity / d_sampling_rate) +{ +} - vco_c_impl::~vco_c_impl() - { - } +vco_c_impl::~vco_c_impl() {} - int - vco_c_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *input = (const float*)input_items[0]; - gr_complex *output = (gr_complex*)output_items[0]; +int vco_c_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* input = (const float*)input_items[0]; + gr_complex* output = (gr_complex*)output_items[0]; - d_vco.sincos(output, input, noutput_items, d_k, d_amplitude); + d_vco.sincos(output, input, noutput_items, d_k, d_amplitude); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/vco_c_impl.h b/gr-blocks/lib/vco_c_impl.h index 53def4f1da..70b1f81e39 100644 --- a/gr-blocks/lib/vco_c_impl.h +++ b/gr-blocks/lib/vco_c_impl.h @@ -27,27 +27,27 @@ #include <gnuradio/fxpt_vco.h> namespace gr { - namespace blocks { - - class vco_c_impl : public vco_c - { - private: - double d_sampling_rate; - double d_sensitivity; - double d_amplitude; - double d_k; - gr::fxpt_vco d_vco; - - public: - vco_c_impl(double sampling_rate, double sensitivity, double amplitude); - ~vco_c_impl(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class vco_c_impl : public vco_c +{ +private: + double d_sampling_rate; + double d_sensitivity; + double d_amplitude; + double d_k; + gr::fxpt_vco d_vco; + +public: + vco_c_impl(double sampling_rate, double sensitivity, double amplitude); + ~vco_c_impl(); + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_VCO_C_H */ diff --git a/gr-blocks/lib/vco_f_impl.cc b/gr-blocks/lib/vco_f_impl.cc index 42be98ad4e..16119f3431 100644 --- a/gr-blocks/lib/vco_f_impl.cc +++ b/gr-blocks/lib/vco_f_impl.cc @@ -29,40 +29,38 @@ #include <math.h> namespace gr { - namespace blocks { +namespace blocks { - vco_f::sptr - vco_f::make(double sampling_rate, double sensitivity, double amplitude) - { - return gnuradio::get_initial_sptr - (new vco_f_impl(sampling_rate, sensitivity, amplitude)); - } +vco_f::sptr vco_f::make(double sampling_rate, double sensitivity, double amplitude) +{ + return gnuradio::get_initial_sptr( + new vco_f_impl(sampling_rate, sensitivity, amplitude)); +} - vco_f_impl::vco_f_impl(double sampling_rate, double sensitivity, double amplitude) - : sync_block("vco_f", - io_signature::make(1, 1, sizeof(float)), - io_signature::make(1, 1, sizeof(float))), - d_sampling_rate(sampling_rate), d_sensitivity(sensitivity), - d_amplitude(amplitude), d_k(d_sensitivity/d_sampling_rate) - { - } +vco_f_impl::vco_f_impl(double sampling_rate, double sensitivity, double amplitude) + : sync_block("vco_f", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(float))), + d_sampling_rate(sampling_rate), + d_sensitivity(sensitivity), + d_amplitude(amplitude), + d_k(d_sensitivity / d_sampling_rate) +{ +} - vco_f_impl::~vco_f_impl() - { - } +vco_f_impl::~vco_f_impl() {} - int - vco_f_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const float *input = (const float*)input_items[0]; - float *output = (float*)output_items[0]; +int vco_f_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const float* input = (const float*)input_items[0]; + float* output = (float*)output_items[0]; - d_vco.cos(output, input, noutput_items, d_k, d_amplitude); + d_vco.cos(output, input, noutput_items, d_k, d_amplitude); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/vco_f_impl.h b/gr-blocks/lib/vco_f_impl.h index 6e7a6dd7b6..049d595111 100644 --- a/gr-blocks/lib/vco_f_impl.h +++ b/gr-blocks/lib/vco_f_impl.h @@ -27,27 +27,27 @@ #include <gnuradio/fxpt_vco.h> namespace gr { - namespace blocks { - - class vco_f_impl : public vco_f - { - private: - double d_sampling_rate; - double d_sensitivity; - double d_amplitude; - double d_k; - gr::fxpt_vco d_vco; - - public: - vco_f_impl(double sampling_rate, double sensitivity, double amplitude); - ~vco_f_impl(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class vco_f_impl : public vco_f +{ +private: + double d_sampling_rate; + double d_sensitivity; + double d_amplitude; + double d_k; + gr::fxpt_vco d_vco; + +public: + vco_f_impl(double sampling_rate, double sensitivity, double amplitude); + ~vco_f_impl(); + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_VCO_F_H */ diff --git a/gr-blocks/lib/vector_insert_impl.cc b/gr-blocks/lib/vector_insert_impl.cc index a39b0779ac..8f13dfa421 100644 --- a/gr-blocks/lib/vector_insert_impl.cc +++ b/gr-blocks/lib/vector_insert_impl.cc @@ -33,93 +33,100 @@ #include <stdio.h> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename vector_insert<T>::sptr - vector_insert<T>::make(const std::vector<T> &data, int periodicity, int offset) - { - return gnuradio::get_initial_sptr - (new vector_insert_impl<T> (data, periodicity, offset)); - } +template <class T> +typename vector_insert<T>::sptr +vector_insert<T>::make(const std::vector<T>& data, int periodicity, int offset) +{ + return gnuradio::get_initial_sptr( + new vector_insert_impl<T>(data, periodicity, offset)); +} - template <class T> - vector_insert_impl<T>::vector_insert_impl(const std::vector<T> &data, - int periodicity, int offset) +template <class T> +vector_insert_impl<T>::vector_insert_impl(const std::vector<T>& data, + int periodicity, + int offset) : block("vector_insert", - io_signature::make(1, 1, sizeof(T)), - io_signature::make(1, 1, sizeof(T))), + io_signature::make(1, 1, sizeof(T)), + io_signature::make(1, 1, sizeof(T))), d_data(data), d_offset(offset), d_periodicity(periodicity) - { - this->set_tag_propagation_policy(gr::block::TPP_DONT); // handle tags manually - // some sanity checks - assert(offset < periodicity); - assert(offset >= 0); - assert((size_t)periodicity > data.size()); - } +{ + this->set_tag_propagation_policy(gr::block::TPP_DONT); // handle tags manually + // some sanity checks + assert(offset < periodicity); + assert(offset >= 0); + assert((size_t)periodicity > data.size()); +} - template <class T> - vector_insert_impl<T>::~vector_insert_impl() - {} +template <class T> +vector_insert_impl<T>::~vector_insert_impl() +{ +} - template <class T> - int - vector_insert_impl<T> ::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *out = (T *)output_items[0]; - const T *in = (const T *)input_items[0]; +template <class T> +int vector_insert_impl<T>::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* out = (T*)output_items[0]; + const T* in = (const T*)input_items[0]; - int ii(0), oo(0); + int ii(0), oo(0); - while((oo < noutput_items) && (ii < ninput_items[0])) { - //printf("oo = %d, ii = %d, d_offset = %d, noutput_items = %d, ninput_items[0] = %d", oo, ii, d_offset, noutput_items, ninput_items[0]); - //printf(", d_periodicity = %d\n", d_periodicity); + while ((oo < noutput_items) && (ii < ninput_items[0])) { + // printf("oo = %d, ii = %d, d_offset = %d, noutput_items = %d, ninput_items[0] = + // %d", oo, ii, d_offset, noutput_items, ninput_items[0]); printf(", d_periodicity + // = %d\n", d_periodicity); - if(d_offset >= ((int)d_data.size())) { // if we are in the copy region - int max_copy = std::min(std::min(noutput_items - oo, ninput_items[0] - ii), - d_periodicity - d_offset); - std::vector<tag_t> tags; - this->get_tags_in_range(tags, 0, this->nitems_read(0) + ii, this->nitems_read(0) + max_copy + ii); - for(unsigned i = 0; i < tags.size(); i++) - { - //printf("copy tag from in@%d to out@%d\n", int(tags[i].offset), int(nitems_written(0) + oo + (tags[i].offset-nitems_read(0)-ii))); - this->add_item_tag(0, this->nitems_written(0) + oo + (tags[i].offset-this->nitems_read(0)-ii), tags[i].key, tags[i].value, tags[i].srcid); - } - //printf("copy %d from input\n", max_copy); - memcpy( &out[oo], &in[ii], sizeof(T)*max_copy ); - //printf(" * memcpy returned.\n"); - ii += max_copy; - oo += max_copy; - d_offset = (d_offset + max_copy)%d_periodicity; - } - else { // if we are in the insertion region - int max_copy = std::min(noutput_items - oo, ((int)d_data.size()) - d_offset); - //printf("copy %d from d_data[%d] to out[%d]\n", max_copy, d_offset, oo); - memcpy(&out[oo], &d_data[d_offset], sizeof(T)*max_copy); - //printf(" * memcpy returned.\n"); - oo += max_copy; - d_offset = (d_offset + max_copy)%d_periodicity; - //printf(" ## (inelse) oo = %d, d_offset = %d\n", oo, d_offset); + if (d_offset >= ((int)d_data.size())) { // if we are in the copy region + int max_copy = std::min(std::min(noutput_items - oo, ninput_items[0] - ii), + d_periodicity - d_offset); + std::vector<tag_t> tags; + this->get_tags_in_range( + tags, 0, this->nitems_read(0) + ii, this->nitems_read(0) + max_copy + ii); + for (unsigned i = 0; i < tags.size(); i++) { + // printf("copy tag from in@%d to out@%d\n", int(tags[i].offset), + // int(nitems_written(0) + oo + (tags[i].offset-nitems_read(0)-ii))); + this->add_item_tag(0, + this->nitems_written(0) + oo + + (tags[i].offset - this->nitems_read(0) - ii), + tags[i].key, + tags[i].value, + tags[i].srcid); + } + // printf("copy %d from input\n", max_copy); + memcpy(&out[oo], &in[ii], sizeof(T) * max_copy); + // printf(" * memcpy returned.\n"); + ii += max_copy; + oo += max_copy; + d_offset = (d_offset + max_copy) % d_periodicity; + } else { // if we are in the insertion region + int max_copy = std::min(noutput_items - oo, ((int)d_data.size()) - d_offset); + // printf("copy %d from d_data[%d] to out[%d]\n", max_copy, d_offset, oo); + memcpy(&out[oo], &d_data[d_offset], sizeof(T) * max_copy); + // printf(" * memcpy returned.\n"); + oo += max_copy; + d_offset = (d_offset + max_copy) % d_periodicity; + // printf(" ## (inelse) oo = %d, d_offset = %d\n", oo, d_offset); } - //printf(" # exit else, on to next loop.\n"); - } - //printf(" # got out of loop\n"); - - //printf("consume = %d, produce = %d\n", ii, oo); - this->consume_each(ii); - return oo; + // printf(" # exit else, on to next loop.\n"); } + // printf(" # got out of loop\n"); + + // printf("consume = %d, produce = %d\n", ii, oo); + this->consume_each(ii); + return oo; +} template class vector_insert<std::uint8_t>; template class vector_insert<std::int16_t>; template class vector_insert<std::int32_t>; template class vector_insert<float>; template class vector_insert<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/vector_insert_impl.h b/gr-blocks/lib/vector_insert_impl.h index a24fe4fc43..79ebd86e8a 100644 --- a/gr-blocks/lib/vector_insert_impl.h +++ b/gr-blocks/lib/vector_insert_impl.h @@ -27,32 +27,34 @@ #include <gnuradio/blocks/vector_insert.h> namespace gr { - namespace blocks { - -template<class T> - class vector_insert_impl : public vector_insert<T> +namespace blocks { + +template <class T> +class vector_insert_impl : public vector_insert<T> +{ +private: + std::vector<T> d_data; + int d_offset; + int d_periodicity; + +public: + vector_insert_impl(const std::vector<T>& data, int periodicity, int offset); + ~vector_insert_impl(); + + void rewind() { d_offset = 0; } + void set_data(const std::vector<T>& data) { - private: - std::vector<T> d_data; - int d_offset; - int d_periodicity; - - public: - vector_insert_impl (const std::vector<T> &data, - int periodicity, int offset); - ~vector_insert_impl (); - - void rewind() { d_offset=0; } - void set_data(const std::vector<T> &data) { - d_data = data; rewind(); } - - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ + d_data = data; + rewind(); + } + + int general_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 /* VECTOR_INSERT_IMPL_H */ diff --git a/gr-blocks/lib/vector_map_impl.cc b/gr-blocks/lib/vector_map_impl.cc index 883d6a3195..def5b51544 100644 --- a/gr-blocks/lib/vector_map_impl.cc +++ b/gr-blocks/lib/vector_map_impl.cc @@ -29,99 +29,102 @@ #include <string.h> namespace gr { - namespace blocks { +namespace blocks { - std::vector<int> - get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) - { - std::vector<int> in_sizeofs; - for(unsigned int i = 0; i < in_vlens.size(); i++) { - in_sizeofs.push_back(in_vlens[i]*item_size); - } - return in_sizeofs; +std::vector<int> get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) +{ + std::vector<int> in_sizeofs; + for (unsigned int i = 0; i < in_vlens.size(); i++) { + in_sizeofs.push_back(in_vlens[i] * item_size); } + return in_sizeofs; +} - std::vector<int> - get_out_sizeofs(size_t item_size, - std::vector< std::vector< std::vector<size_t> > > mapping) - { - std::vector<int> out_sizeofs; - for(unsigned int i = 0; i < mapping.size(); i++) { - out_sizeofs.push_back(mapping[i].size()*item_size); - } - return out_sizeofs; +std::vector<int> get_out_sizeofs(size_t item_size, + std::vector<std::vector<std::vector<size_t>>> mapping) +{ + std::vector<int> out_sizeofs; + for (unsigned int i = 0; i < mapping.size(); i++) { + out_sizeofs.push_back(mapping[i].size() * item_size); } + return out_sizeofs; +} - vector_map::sptr - vector_map::make(size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping) - { - return gnuradio::get_initial_sptr - (new vector_map_impl(item_size, in_vlens, mapping)); - } +vector_map::sptr vector_map::make(size_t item_size, + std::vector<size_t> in_vlens, + std::vector<std::vector<std::vector<size_t>>> mapping) +{ + return gnuradio::get_initial_sptr(new vector_map_impl(item_size, in_vlens, mapping)); +} - vector_map_impl::vector_map_impl(size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping) - : sync_block("vector_map", - io_signature::makev(in_vlens.size(), in_vlens.size(), - get_in_sizeofs(item_size, in_vlens)), - io_signature::makev(mapping.size(), mapping.size(), - get_out_sizeofs(item_size, mapping))), - d_item_size(item_size), d_in_vlens(in_vlens) - { - set_mapping(mapping); - } +vector_map_impl::vector_map_impl(size_t item_size, + std::vector<size_t> in_vlens, + std::vector<std::vector<std::vector<size_t>>> mapping) + : sync_block( + "vector_map", + io_signature::makev( + in_vlens.size(), in_vlens.size(), get_in_sizeofs(item_size, in_vlens)), + io_signature::makev( + mapping.size(), mapping.size(), get_out_sizeofs(item_size, mapping))), + d_item_size(item_size), + d_in_vlens(in_vlens) +{ + set_mapping(mapping); +} - vector_map_impl::~vector_map_impl() - { - } +vector_map_impl::~vector_map_impl() {} - void - vector_map_impl::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) - { - // Make sure the contents of the mapping vectors are possible. - for(unsigned int i=0; i<mapping.size(); i++) { - for(unsigned int j=0; j<mapping[i].size(); j++) { - if(mapping[i][j].size() != 2) { - throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items."); - } - unsigned int s = mapping[i][j][0]; - unsigned int index = mapping[i][j][1]; - if(s >= d_in_vlens.size()) { - throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); - } - if(index >= d_in_vlens[s]) { - throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths."); - } +void vector_map_impl::set_mapping(std::vector<std::vector<std::vector<size_t>>> mapping) +{ + // Make sure the contents of the mapping vectors are possible. + for (unsigned int i = 0; i < mapping.size(); i++) { + for (unsigned int j = 0; j < mapping[i].size(); j++) { + if (mapping[i][j].size() != 2) { + throw std::runtime_error( + "Mapping must be of the form (out_mapping_stream1, " + "out_mapping_stream2, ...), where out_mapping_stream1 is of the form " + "(mapping_element1, mapping_element2, ...), where mapping_element1 " + "is of the form (input_stream, input_element). This error is raised " + "because a mapping_element vector does not contain exactly 2 items."); + } + unsigned int s = mapping[i][j][0]; + unsigned int index = mapping[i][j][1]; + if (s >= d_in_vlens.size()) { + throw std::runtime_error("Stream numbers in mapping must be less than " + "the number of input streams."); + } + if (index >= d_in_vlens[s]) { + throw std::runtime_error("Indices in mapping must be greater than 0 and " + "less than the input vector lengths."); + } } - } - gr::thread::scoped_lock guard(d_mutex); - d_mapping = mapping; } + gr::thread::scoped_lock guard(d_mutex); + d_mapping = mapping; +} - int - vector_map_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const char **inv = (const char**)&input_items[0]; - char **outv = (char**)&output_items[0]; +int vector_map_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const char** inv = (const char**)&input_items[0]; + char** outv = (char**)&output_items[0]; - for(unsigned int n = 0; n < (unsigned int)(noutput_items); n++) { - for(unsigned int i = 0; i < d_mapping.size(); i++) { - unsigned int out_vlen = d_mapping[i].size(); - for(unsigned int j = 0; j < out_vlen; j++) { - unsigned int s = d_mapping[i][j][0]; - unsigned int k = d_mapping[i][j][1]; - memcpy(outv[i] + out_vlen*d_item_size*n + - d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + - k*d_item_size, d_item_size); - } + for (unsigned int n = 0; n < (unsigned int)(noutput_items); n++) { + for (unsigned int i = 0; i < d_mapping.size(); i++) { + unsigned int out_vlen = d_mapping[i].size(); + for (unsigned int j = 0; j < out_vlen; j++) { + unsigned int s = d_mapping[i][j][0]; + unsigned int k = d_mapping[i][j][1]; + memcpy(outv[i] + out_vlen * d_item_size * n + d_item_size * j, + inv[s] + d_in_vlens[s] * d_item_size * n + k * d_item_size, + d_item_size); + } } - } - - return noutput_items; } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/vector_map_impl.h b/gr-blocks/lib/vector_map_impl.h index 64f5e091e6..c6d9abda40 100644 --- a/gr-blocks/lib/vector_map_impl.h +++ b/gr-blocks/lib/vector_map_impl.h @@ -27,29 +27,30 @@ #include <gnuradio/thread/thread.h> namespace gr { - namespace blocks { - - class vector_map_impl : public vector_map - { - private: - size_t d_item_size; - std::vector<size_t> d_in_vlens; - std::vector< std::vector< std::vector<size_t> > > d_mapping; - gr::thread::mutex d_mutex; // mutex to protect set/work access - - public: - vector_map_impl(size_t item_size, std::vector<size_t> in_vlens, - std::vector< std::vector< std::vector<size_t> > > mapping); - ~vector_map_impl(); - - void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class vector_map_impl : public vector_map +{ +private: + size_t d_item_size; + std::vector<size_t> d_in_vlens; + std::vector<std::vector<std::vector<size_t>>> d_mapping; + gr::thread::mutex d_mutex; // mutex to protect set/work access + +public: + vector_map_impl(size_t item_size, + std::vector<size_t> in_vlens, + std::vector<std::vector<std::vector<size_t>>> mapping); + ~vector_map_impl(); + + void set_mapping(std::vector<std::vector<std::vector<size_t>>> mapping); + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_VECTOR_MAP_IMPL_H */ diff --git a/gr-blocks/lib/vector_sink_impl.cc b/gr-blocks/lib/vector_sink_impl.cc index b09c8e81b7..ec5c05f2b0 100644 --- a/gr-blocks/lib/vector_sink_impl.cc +++ b/gr-blocks/lib/vector_sink_impl.cc @@ -32,80 +32,77 @@ #include <iostream> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename vector_sink<T>::sptr - vector_sink<T>::make(unsigned int vlen, const int reserve_items) - { - return gnuradio::get_initial_sptr - (new vector_sink_impl<T> (vlen, reserve_items)); - } +template <class T> +typename vector_sink<T>::sptr vector_sink<T>::make(unsigned int vlen, + const int reserve_items) +{ + return gnuradio::get_initial_sptr(new vector_sink_impl<T>(vlen, reserve_items)); +} - template <class T> - vector_sink_impl<T> ::vector_sink_impl(unsigned int vlen, const int reserve_items) +template <class T> +vector_sink_impl<T>::vector_sink_impl(unsigned int vlen, const int reserve_items) : sync_block("vector_sink", - io_signature::make(1, 1, sizeof(T) * vlen), - io_signature::make(0, 0, 0)), - d_vlen(vlen) - { - gr::thread::scoped_lock guard(d_data_mutex); - d_data.reserve(d_vlen * reserve_items); - } + io_signature::make(1, 1, sizeof(T) * vlen), + io_signature::make(0, 0, 0)), + d_vlen(vlen) +{ + gr::thread::scoped_lock guard(d_data_mutex); + d_data.reserve(d_vlen * reserve_items); +} - template <class T> - vector_sink_impl<T> ::~vector_sink_impl() - {} +template <class T> +vector_sink_impl<T>::~vector_sink_impl() +{ +} - template <class T> - std::vector<T> - vector_sink_impl<T> ::data() const - { - gr::thread::scoped_lock guard(d_data_mutex); - return d_data; - } +template <class T> +std::vector<T> vector_sink_impl<T>::data() const +{ + gr::thread::scoped_lock guard(d_data_mutex); + return d_data; +} - template <class T> - std::vector<tag_t> - vector_sink_impl<T> ::tags() const - { - gr::thread::scoped_lock guard(d_data_mutex); - return d_tags; - } +template <class T> +std::vector<tag_t> vector_sink_impl<T>::tags() const +{ + gr::thread::scoped_lock guard(d_data_mutex); + return d_tags; +} - template <class T> - void - vector_sink_impl<T> ::reset() - { - gr::thread::scoped_lock guard(d_data_mutex); - d_tags.clear(); - d_data.clear(); - } +template <class T> +void vector_sink_impl<T>::reset() +{ + gr::thread::scoped_lock guard(d_data_mutex); + d_tags.clear(); + d_data.clear(); +} - template <class T> - int - vector_sink_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *iptr = (T*)input_items[0]; +template <class T> +int vector_sink_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* iptr = (T*)input_items[0]; - // can't touch this (as long as work() is working, the accessors shall not - // read the data - gr::thread::scoped_lock guard(d_data_mutex); - for(unsigned int i = 0; i < noutput_items * d_vlen; i++) - d_data.push_back (iptr[i]); - std::vector<tag_t> tags; - this->get_tags_in_range(tags, 0, this->nitems_read(0), this->nitems_read(0) + noutput_items); - d_tags.insert(d_tags.end(), tags.begin(), tags.end()); - return noutput_items; - } + // can't touch this (as long as work() is working, the accessors shall not + // read the data + gr::thread::scoped_lock guard(d_data_mutex); + for (unsigned int i = 0; i < noutput_items * d_vlen; i++) + d_data.push_back(iptr[i]); + std::vector<tag_t> tags; + this->get_tags_in_range( + tags, 0, this->nitems_read(0), this->nitems_read(0) + noutput_items); + d_tags.insert(d_tags.end(), tags.begin(), tags.end()); + return noutput_items; +} template class vector_sink<std::uint8_t>; template class vector_sink<std::int16_t>; template class vector_sink<std::int32_t>; template class vector_sink<float>; template class vector_sink<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/vector_sink_impl.h b/gr-blocks/lib/vector_sink_impl.h index 6e18e0b006..fd1263957b 100644 --- a/gr-blocks/lib/vector_sink_impl.h +++ b/gr-blocks/lib/vector_sink_impl.h @@ -28,31 +28,31 @@ #include <gnuradio/thread/thread.h> namespace gr { - namespace blocks { - -template<class T> - class vector_sink_impl : public vector_sink<T> - { - private: - std::vector<T> d_data; - std::vector<tag_t> d_tags; - mutable gr::thread::mutex d_data_mutex; // protects internal data access. - unsigned int d_vlen; - - public: - vector_sink_impl (unsigned int vlen, const int reserve_items); - ~vector_sink_impl (); - - void reset(); - std::vector<T> data() const; - std::vector<tag_t> tags() const; - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +template <class T> +class vector_sink_impl : public vector_sink<T> +{ +private: + std::vector<T> d_data; + std::vector<tag_t> d_tags; + mutable gr::thread::mutex d_data_mutex; // protects internal data access. + unsigned int d_vlen; + +public: + vector_sink_impl(unsigned int vlen, const int reserve_items); + ~vector_sink_impl(); + + void reset(); + std::vector<T> data() const; + std::vector<tag_t> tags() const; + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* VECTOR_SINK_IMPL_H */ diff --git a/gr-blocks/lib/vector_source_impl.cc b/gr-blocks/lib/vector_source_impl.cc index 24a21854f2..b7f9409631 100644 --- a/gr-blocks/lib/vector_source_impl.cc +++ b/gr-blocks/lib/vector_source_impl.cc @@ -31,123 +31,122 @@ #include <stdexcept> namespace gr { - namespace blocks { +namespace blocks { - template <class T> - typename vector_source<T>::sptr - vector_source<T>::make(const std::vector<T> &data, - bool repeat, unsigned int vlen, - const std::vector<tag_t> &tags) - { - return gnuradio::get_initial_sptr - (new vector_source_impl<T> (data, repeat, vlen, tags)); - } +template <class T> +typename vector_source<T>::sptr vector_source<T>::make(const std::vector<T>& data, + bool repeat, + unsigned int vlen, + const std::vector<tag_t>& tags) +{ + return gnuradio::get_initial_sptr( + new vector_source_impl<T>(data, repeat, vlen, tags)); +} - template <class T> - vector_source_impl<T> ::vector_source_impl(const std::vector<T> &data, - bool repeat, unsigned int vlen, - const std::vector<tag_t> &tags) +template <class T> +vector_source_impl<T>::vector_source_impl(const std::vector<T>& data, + bool repeat, + unsigned int vlen, + const std::vector<tag_t>& tags) : sync_block("vector_source", - io_signature::make(0, 0, 0), - io_signature::make(1, 1, sizeof(T) * vlen)), + io_signature::make(0, 0, 0), + io_signature::make(1, 1, sizeof(T) * vlen)), d_data(data), d_repeat(repeat), d_offset(0), d_vlen(vlen), d_tags(tags) - { - if(tags.size() == 0) { +{ + if (tags.size() == 0) { d_settags = 0; - } - else { + } else { d_settags = 1; this->set_output_multiple(data.size() / vlen); - } - if((data.size() % vlen) != 0) - throw std::invalid_argument("data length must be a multiple of vlen"); } + if ((data.size() % vlen) != 0) + throw std::invalid_argument("data length must be a multiple of vlen"); +} - template <class T> - vector_source_impl<T> ::~vector_source_impl() - {} +template <class T> +vector_source_impl<T>::~vector_source_impl() +{ +} - template <class T> - void - vector_source_impl<T> ::set_data (const std::vector<T> &data, - const std::vector<tag_t> &tags) - { - d_data = data; - d_tags = tags; - rewind(); - if(tags.size() == 0) { +template <class T> +void vector_source_impl<T>::set_data(const std::vector<T>& data, + const std::vector<tag_t>& tags) +{ + d_data = data; + d_tags = tags; + rewind(); + if (tags.size() == 0) { d_settags = false; - } - else { + } else { d_settags = true; - } } +} - template <class T> - int - vector_source_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *) output_items[0]; +template <class T> +int vector_source_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; - if(d_repeat) { - unsigned int size = d_data.size (); + if (d_repeat) { + unsigned int size = d_data.size(); unsigned int offset = d_offset; - if(size == 0) - return -1; + if (size == 0) + return -1; - if(d_settags) { - int n_outputitems_per_vector = d_data.size() / d_vlen; - for(int i = 0; i < noutput_items; i += n_outputitems_per_vector) { - // FIXME do proper vector copy - memcpy((void *) optr, (const void*)&d_data[0], size*sizeof (T)); - optr += size; - for(unsigned t = 0; t < d_tags.size(); t++) { - this->add_item_tag(0, this->nitems_written(0)+i+d_tags[t].offset, - d_tags[t].key, d_tags[t].value, d_tags[t].srcid); + if (d_settags) { + int n_outputitems_per_vector = d_data.size() / d_vlen; + for (int i = 0; i < noutput_items; i += n_outputitems_per_vector) { + // FIXME do proper vector copy + memcpy((void*)optr, (const void*)&d_data[0], size * sizeof(T)); + optr += size; + for (unsigned t = 0; t < d_tags.size(); t++) { + this->add_item_tag(0, + this->nitems_written(0) + i + d_tags[t].offset, + d_tags[t].key, + d_tags[t].value, + d_tags[t].srcid); + } } - } - } - else { - for(int i = 0; i < static_cast<int>(noutput_items*d_vlen); i++) { - optr[i] = d_data[offset++]; - if(offset >= size) { - offset = 0; + } else { + for (int i = 0; i < static_cast<int>(noutput_items * d_vlen); i++) { + optr[i] = d_data[offset++]; + if (offset >= size) { + offset = 0; + } } - } } d_offset = offset; return noutput_items; - } - else { - if(d_offset >= d_data.size ()) - return -1; // Done! + } else { + if (d_offset >= d_data.size()) + return -1; // Done! unsigned n = std::min((unsigned)d_data.size() - d_offset, - (unsigned)noutput_items*d_vlen); - for(unsigned i = 0; i < n; i++) { - optr[i] = d_data[d_offset + i]; + (unsigned)noutput_items * d_vlen); + for (unsigned i = 0; i < n; i++) { + optr[i] = d_data[d_offset + i]; } - for(unsigned t = 0; t < d_tags.size(); t++) { - if((d_tags[t].offset >= d_offset) && (d_tags[t].offset < d_offset+n)) - this->add_item_tag(0, d_tags[t].offset, d_tags[t].key, d_tags[t].value, - d_tags[t].srcid); + for (unsigned t = 0; t < d_tags.size(); t++) { + if ((d_tags[t].offset >= d_offset) && (d_tags[t].offset < d_offset + n)) + this->add_item_tag( + 0, d_tags[t].offset, d_tags[t].key, d_tags[t].value, d_tags[t].srcid); } d_offset += n; - return n/d_vlen; - } + return n / d_vlen; } +} template class vector_source<std::uint8_t>; template class vector_source<std::int16_t>; template class vector_source<std::int32_t>; template class vector_source<float>; template class vector_source<gr_complex>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/vector_source_impl.h b/gr-blocks/lib/vector_source_impl.h index 19966d01e8..eaa8a0b6b0 100644 --- a/gr-blocks/lib/vector_source_impl.h +++ b/gr-blocks/lib/vector_source_impl.h @@ -27,36 +27,36 @@ #include <gnuradio/blocks/vector_source.h> namespace gr { - namespace blocks { - -template<class T> - class vector_source_impl : public vector_source<T> - { - private: - std::vector<T> d_data; - bool d_repeat; - unsigned int d_offset; - unsigned int d_vlen; - bool d_settags; - std::vector<tag_t> d_tags; - - public: - vector_source_impl (const std::vector<T> &data, - bool repeat, unsigned int vlen, - const std::vector<tag_t> &tags); - ~vector_source_impl (); - - void rewind() { d_offset=0; } - void set_data(const std::vector<T> &data, - const std::vector<tag_t> &tags); - void set_repeat(bool repeat) { d_repeat=repeat; }; - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +template <class T> +class vector_source_impl : public vector_source<T> +{ +private: + std::vector<T> d_data; + bool d_repeat; + unsigned int d_offset; + unsigned int d_vlen; + bool d_settags; + std::vector<tag_t> d_tags; + +public: + vector_source_impl(const std::vector<T>& data, + bool repeat, + unsigned int vlen, + const std::vector<tag_t>& tags); + ~vector_source_impl(); + + void rewind() { d_offset = 0; } + void set_data(const std::vector<T>& data, const std::vector<tag_t>& tags); + void set_repeat(bool repeat) { d_repeat = repeat; }; + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* VECTOR_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/vector_to_stream_impl.cc b/gr-blocks/lib/vector_to_stream_impl.cc index 941a1f1752..2769dc13ae 100644 --- a/gr-blocks/lib/vector_to_stream_impl.cc +++ b/gr-blocks/lib/vector_to_stream_impl.cc @@ -28,35 +28,35 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - vector_to_stream::sptr vector_to_stream::make(size_t itemsize, size_t nitems_per_block) - { - return gnuradio::get_initial_sptr(new vector_to_stream_impl(itemsize, nitems_per_block)); - } +vector_to_stream::sptr vector_to_stream::make(size_t itemsize, size_t nitems_per_block) +{ + return gnuradio::get_initial_sptr( + new vector_to_stream_impl(itemsize, nitems_per_block)); +} - vector_to_stream_impl::vector_to_stream_impl(size_t itemsize, size_t nitems_per_block) - : sync_interpolator ("vector_to_stream", - io_signature::make (1, 1, itemsize * nitems_per_block), - io_signature::make (1, 1, itemsize), - nitems_per_block) - { - } +vector_to_stream_impl::vector_to_stream_impl(size_t itemsize, size_t nitems_per_block) + : sync_interpolator("vector_to_stream", + io_signature::make(1, 1, itemsize * nitems_per_block), + io_signature::make(1, 1, itemsize), + nitems_per_block) +{ +} - int - vector_to_stream_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - size_t block_size = output_signature()->sizeof_stream_item (0); +int vector_to_stream_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + size_t block_size = output_signature()->sizeof_stream_item(0); - const char *in = (const char *) input_items[0]; - char *out = (char *) output_items[0]; + const char* in = (const char*)input_items[0]; + char* out = (char*)output_items[0]; - memcpy (out, in, noutput_items * block_size); + memcpy(out, in, noutput_items * block_size); - return noutput_items; - } + return noutput_items; +} - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/vector_to_stream_impl.h b/gr-blocks/lib/vector_to_stream_impl.h index d2f4759cd9..6bb48390d5 100644 --- a/gr-blocks/lib/vector_to_stream_impl.h +++ b/gr-blocks/lib/vector_to_stream_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/vector_to_stream.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API vector_to_stream_impl : public vector_to_stream - { - public: - vector_to_stream_impl(size_t itemsize, size_t nitems_per_block); +class BLOCKS_API vector_to_stream_impl : public vector_to_stream +{ +public: + vector_to_stream_impl(size_t itemsize, size_t nitems_per_block); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_VECTOR_TO_STREAM_IMPL_H */ diff --git a/gr-blocks/lib/vector_to_streams_impl.cc b/gr-blocks/lib/vector_to_streams_impl.cc index 87f3e8e23c..66fc217eff 100644 --- a/gr-blocks/lib/vector_to_streams_impl.cc +++ b/gr-blocks/lib/vector_to_streams_impl.cc @@ -28,41 +28,40 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { +namespace blocks { - vector_to_streams::sptr vector_to_streams::make(size_t itemsize, size_t nstreams) - { - return gnuradio::get_initial_sptr(new vector_to_streams_impl(itemsize, nstreams)); - } - - vector_to_streams_impl::vector_to_streams_impl(size_t itemsize, size_t nstreams) - : sync_block ("vector_to_streams", - io_signature::make (1, 1, nstreams * itemsize), - io_signature::make (nstreams, nstreams, itemsize)) +vector_to_streams::sptr vector_to_streams::make(size_t itemsize, size_t nstreams) +{ + return gnuradio::get_initial_sptr(new vector_to_streams_impl(itemsize, nstreams)); +} - { - } +vector_to_streams_impl::vector_to_streams_impl(size_t itemsize, size_t nstreams) + : sync_block("vector_to_streams", + io_signature::make(1, 1, nstreams * itemsize), + io_signature::make(nstreams, nstreams, itemsize)) - int - vector_to_streams_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - size_t itemsize = output_signature()->sizeof_stream_item(0); - int nstreams = output_items.size(); +{ +} - const char *in = (const char *) input_items[0]; - char **outv = (char **) &output_items[0]; +int vector_to_streams_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + size_t itemsize = output_signature()->sizeof_stream_item(0); + int nstreams = output_items.size(); - for (int i = 0; i < noutput_items; i++){ - for (int j = 0; j < nstreams; j++){ - memcpy(outv[j], in, itemsize); - outv[j] += itemsize; - in += itemsize; - } - } + const char* in = (const char*)input_items[0]; + char** outv = (char**)&output_items[0]; - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + for (int j = 0; j < nstreams; j++) { + memcpy(outv[j], in, itemsize); + outv[j] += itemsize; + in += itemsize; + } } - } /* namespace blocks */ + + return noutput_items; +} +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/vector_to_streams_impl.h b/gr-blocks/lib/vector_to_streams_impl.h index b5393729eb..eb336bdbfb 100644 --- a/gr-blocks/lib/vector_to_streams_impl.h +++ b/gr-blocks/lib/vector_to_streams_impl.h @@ -26,19 +26,19 @@ #include <gnuradio/blocks/vector_to_streams.h> namespace gr { - namespace blocks { +namespace blocks { - class BLOCKS_API vector_to_streams_impl : public vector_to_streams - { - public: - vector_to_streams_impl(size_t itemsize, size_t nstreams); +class BLOCKS_API vector_to_streams_impl : public vector_to_streams +{ +public: + vector_to_streams_impl(size_t itemsize, size_t nstreams); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_VECTOR_TO_STREAMS_IMPL_H */ diff --git a/gr-blocks/lib/wavfile.cc b/gr-blocks/lib/wavfile.cc index e191f763c2..72cec7d8bc 100644 --- a/gr-blocks/lib/wavfile.cc +++ b/gr-blocks/lib/wavfile.cc @@ -30,250 +30,239 @@ #include <boost/detail/endian.hpp> //BOOST_BIG_ENDIAN namespace gr { - namespace blocks { +namespace blocks { #define VALID_COMPRESSION_TYPE 0x0001 - // Basically, this is the opposite of htonx() and ntohx() - // Define host to/from worknet (little endian) short and long +// Basically, this is the opposite of htonx() and ntohx() +// Define host to/from worknet (little endian) short and long #ifdef BOOST_BIG_ENDIAN - static inline uint16_t __gri_wav_bs16(uint16_t x) - { - return (x>>8) | (x<<8); - } +static inline uint16_t __gri_wav_bs16(uint16_t x) { return (x >> 8) | (x << 8); } - static inline uint32_t __gri_wav_bs32(uint32_t x) - { - return (uint32_t(__gri_wav_bs16(uint16_t(x&0xfffful)))<<16) | (__gri_wav_bs16(uint16_t(x>>16))); - } +static inline uint32_t __gri_wav_bs32(uint32_t x) +{ + return (uint32_t(__gri_wav_bs16(uint16_t(x & 0xfffful))) << 16) | + (__gri_wav_bs16(uint16_t(x >> 16))); +} - #define htowl(x) __gri_wav_bs32(x) - #define wtohl(x) __gri_wav_bs32(x) - #define htows(x) __gri_wav_bs16(x) - #define wtohs(x) __gri_wav_bs16(x) +#define htowl(x) __gri_wav_bs32(x) +#define wtohl(x) __gri_wav_bs32(x) +#define htows(x) __gri_wav_bs16(x) +#define wtohs(x) __gri_wav_bs16(x) #else - #define htowl(x) uint32_t(x) - #define wtohl(x) uint32_t(x) - #define htows(x) uint16_t(x) - #define wtohs(x) uint16_t(x) +#define htowl(x) uint32_t(x) +#define wtohl(x) uint32_t(x) +#define htows(x) uint16_t(x) +#define wtohs(x) uint16_t(x) #endif // BOOST_BIG_ENDIAN - // WAV files are always little-endian, so we need some byte switching macros - static inline uint32_t host_to_wav(uint32_t x) { return htowl(x); } - static inline uint16_t host_to_wav(uint16_t x) { return htows(x); } - static inline int16_t host_to_wav(int16_t x) { return htows(x); } - static inline uint32_t wav_to_host(uint32_t x) { return wtohl(x); } - static inline uint16_t wav_to_host(uint16_t x) { return wtohs(x); } - static inline int16_t wav_to_host(int16_t x) { return wtohs(x); } - - bool - wavheader_parse(FILE *fp, - unsigned int &sample_rate_o, - int &nchans_o, - int &bytes_per_sample_o, - int &first_sample_pos_o, - unsigned int &samples_per_chan_o) - { - // _o variables take return values - char str_buf[8] = {0}; - - uint32_t file_size; - uint32_t fmt_hdr_skip; - uint16_t compression_type; - uint16_t nchans; - uint32_t sample_rate; - uint32_t avg_bytes_per_sec; - uint16_t block_align; - uint16_t bits_per_sample; - uint32_t chunk_size; - - size_t fresult; - - fresult = fread(str_buf, 1, 4, fp); - if(fresult != 4 || strncmp(str_buf, "RIFF", 4) || feof(fp)) { - return false; - } - - fresult = fread(&file_size, 1, 4, fp); - - fresult = fread(str_buf, 1, 8, fp); - if(fresult != 8 || strncmp(str_buf, "WAVEfmt ", 8) || feof(fp)) { - return false; - } - - fresult = fread(&fmt_hdr_skip, 1, 4, fp); - - fresult = fread(&compression_type, 1, 2, fp); - if(wav_to_host(compression_type) != VALID_COMPRESSION_TYPE) { - return false; - } - - fresult = fread(&nchans, 1, 2, fp); - fresult = fread(&sample_rate, 1, 4, fp); - fresult = fread(&avg_bytes_per_sec, 1, 4, fp); - fresult = fread(&block_align, 1, 2, fp); - fresult = fread(&bits_per_sample, 1, 2, fp); - - if(ferror(fp)) { - return false; - } - - fmt_hdr_skip = wav_to_host(fmt_hdr_skip); - nchans = wav_to_host(nchans); - sample_rate = wav_to_host(sample_rate); - bits_per_sample = wav_to_host(bits_per_sample); - - if(bits_per_sample != 8 && bits_per_sample != 16) { - return false; - } - - fmt_hdr_skip -= 16; - if(fmt_hdr_skip) { - if (fseek(fp, fmt_hdr_skip, SEEK_CUR) != 0) { - return false; - } - } - - // find data chunk - fresult = fread(str_buf, 1, 4, fp); - // keep parsing chunk until we hit the data chunk - while(fresult != 4 || strncmp(str_buf, "data", 4)) - { - // all good? - if(fresult != 4 || ferror(fp) || feof(fp)) { - return false; - } - // get chunk body size and skip - fresult = fread(&chunk_size, 1, 4, fp); - if(fresult != 4 || ferror(fp) || feof(fp)) { - return false; +// WAV files are always little-endian, so we need some byte switching macros +static inline uint32_t host_to_wav(uint32_t x) { return htowl(x); } +static inline uint16_t host_to_wav(uint16_t x) { return htows(x); } +static inline int16_t host_to_wav(int16_t x) { return htows(x); } +static inline uint32_t wav_to_host(uint32_t x) { return wtohl(x); } +static inline uint16_t wav_to_host(uint16_t x) { return wtohs(x); } +static inline int16_t wav_to_host(int16_t x) { return wtohs(x); } + +bool wavheader_parse(FILE* fp, + unsigned int& sample_rate_o, + int& nchans_o, + int& bytes_per_sample_o, + int& first_sample_pos_o, + unsigned int& samples_per_chan_o) +{ + // _o variables take return values + char str_buf[8] = { 0 }; + + uint32_t file_size; + uint32_t fmt_hdr_skip; + uint16_t compression_type; + uint16_t nchans; + uint32_t sample_rate; + uint32_t avg_bytes_per_sec; + uint16_t block_align; + uint16_t bits_per_sample; + uint32_t chunk_size; + + size_t fresult; + + fresult = fread(str_buf, 1, 4, fp); + if (fresult != 4 || strncmp(str_buf, "RIFF", 4) || feof(fp)) { + return false; + } + + fresult = fread(&file_size, 1, 4, fp); + + fresult = fread(str_buf, 1, 8, fp); + if (fresult != 8 || strncmp(str_buf, "WAVEfmt ", 8) || feof(fp)) { + return false; + } + + fresult = fread(&fmt_hdr_skip, 1, 4, fp); + + fresult = fread(&compression_type, 1, 2, fp); + if (wav_to_host(compression_type) != VALID_COMPRESSION_TYPE) { + return false; + } + + fresult = fread(&nchans, 1, 2, fp); + fresult = fread(&sample_rate, 1, 4, fp); + fresult = fread(&avg_bytes_per_sec, 1, 4, fp); + fresult = fread(&block_align, 1, 2, fp); + fresult = fread(&bits_per_sample, 1, 2, fp); + + if (ferror(fp)) { + return false; + } + + fmt_hdr_skip = wav_to_host(fmt_hdr_skip); + nchans = wav_to_host(nchans); + sample_rate = wav_to_host(sample_rate); + bits_per_sample = wav_to_host(bits_per_sample); + + if (bits_per_sample != 8 && bits_per_sample != 16) { + return false; + } + + fmt_hdr_skip -= 16; + if (fmt_hdr_skip) { + if (fseek(fp, fmt_hdr_skip, SEEK_CUR) != 0) { + return false; + } + } + + // find data chunk + fresult = fread(str_buf, 1, 4, fp); + // keep parsing chunk until we hit the data chunk + while (fresult != 4 || strncmp(str_buf, "data", 4)) { + // all good? + if (fresult != 4 || ferror(fp) || feof(fp)) { + return false; + } + // get chunk body size and skip + fresult = fread(&chunk_size, 1, 4, fp); + if (fresult != 4 || ferror(fp) || feof(fp)) { + return false; + } + chunk_size = wav_to_host(chunk_size); + if (fseek(fp, chunk_size, SEEK_CUR) != 0) { + return false; } - chunk_size = wav_to_host(chunk_size); - if(fseek(fp, chunk_size, SEEK_CUR) != 0) { - return false; - } // read next chunk type fresult = fread(str_buf, 1, 4, fp); - } - - fresult = fread(&chunk_size, 1, 4, fp); - if(ferror(fp)) { - return false; - } - - // More byte swapping - chunk_size = wav_to_host(chunk_size); - - // Output values - sample_rate_o = (unsigned)sample_rate; - nchans_o = (int)nchans; - bytes_per_sample_o = (int)(bits_per_sample / 8); - first_sample_pos_o = (int)ftell(fp); - samples_per_chan_o = (unsigned)(chunk_size / (bytes_per_sample_o * nchans)); - return true; } + fresult = fread(&chunk_size, 1, 4, fp); + if (ferror(fp)) { + return false; + } + + // More byte swapping + chunk_size = wav_to_host(chunk_size); - short int - wav_read_sample(FILE *fp, int bytes_per_sample) - { - int16_t buf_16bit = 0; + // Output values + sample_rate_o = (unsigned)sample_rate; + nchans_o = (int)nchans; + bytes_per_sample_o = (int)(bits_per_sample / 8); + first_sample_pos_o = (int)ftell(fp); + samples_per_chan_o = (unsigned)(chunk_size / (bytes_per_sample_o * nchans)); + return true; +} - if(fread(&buf_16bit, bytes_per_sample, 1, fp) != 1) { - return 0; - } - if(bytes_per_sample == 1) { - return (short)buf_16bit; - } - return (short)wav_to_host(buf_16bit); - } +short int wav_read_sample(FILE* fp, int bytes_per_sample) +{ + int16_t buf_16bit = 0; - bool - wavheader_write(FILE *fp, - unsigned int sample_rate, - int nchans, - int bytes_per_sample) - { - const int header_len = 44; - char wav_hdr[header_len] = "RIFF\0\0\0\0WAVEfmt \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0data\0\0\0"; - uint16_t nchans_f = (uint16_t) nchans; - uint32_t sample_rate_f = (uint32_t) sample_rate; - uint16_t block_align = bytes_per_sample * nchans; - uint32_t avg_bytes = sample_rate * block_align; - uint16_t bits_per_sample = bytes_per_sample * 8; - - nchans_f = host_to_wav(nchans_f); - sample_rate_f = host_to_wav(sample_rate_f); - block_align = host_to_wav(block_align); - avg_bytes = host_to_wav(avg_bytes); - bits_per_sample = host_to_wav(bits_per_sample); - - wav_hdr[16] = 0x10; // no extra bytes - wav_hdr[20] = 0x01; // no compression - memcpy((void*)(wav_hdr + 22), (void*)&nchans_f, 2); - memcpy((void*)(wav_hdr + 24), (void*)&sample_rate_f, 4); - memcpy((void*)(wav_hdr + 28), (void*)&avg_bytes, 4); - memcpy((void*)(wav_hdr + 32), (void*)&block_align, 2); - memcpy((void*)(wav_hdr + 34), (void*)&bits_per_sample, 2); - - fwrite(&wav_hdr, 1, header_len, fp); - if(ferror(fp)) { - return false; - } - - return true; + if (fread(&buf_16bit, bytes_per_sample, 1, fp) != 1) { + return 0; + } + if (bytes_per_sample == 1) { + return (short)buf_16bit; + } + return (short)wav_to_host(buf_16bit); +} + + +bool wavheader_write(FILE* fp, unsigned int sample_rate, int nchans, int bytes_per_sample) +{ + const int header_len = 44; + char wav_hdr[header_len] = + "RIFF\0\0\0\0WAVEfmt \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0data\0\0\0"; + uint16_t nchans_f = (uint16_t)nchans; + uint32_t sample_rate_f = (uint32_t)sample_rate; + uint16_t block_align = bytes_per_sample * nchans; + uint32_t avg_bytes = sample_rate * block_align; + uint16_t bits_per_sample = bytes_per_sample * 8; + + nchans_f = host_to_wav(nchans_f); + sample_rate_f = host_to_wav(sample_rate_f); + block_align = host_to_wav(block_align); + avg_bytes = host_to_wav(avg_bytes); + bits_per_sample = host_to_wav(bits_per_sample); + + wav_hdr[16] = 0x10; // no extra bytes + wav_hdr[20] = 0x01; // no compression + memcpy((void*)(wav_hdr + 22), (void*)&nchans_f, 2); + memcpy((void*)(wav_hdr + 24), (void*)&sample_rate_f, 4); + memcpy((void*)(wav_hdr + 28), (void*)&avg_bytes, 4); + memcpy((void*)(wav_hdr + 32), (void*)&block_align, 2); + memcpy((void*)(wav_hdr + 34), (void*)&bits_per_sample, 2); + + fwrite(&wav_hdr, 1, header_len, fp); + if (ferror(fp)) { + return false; } + return true; +} - void - wav_write_sample(FILE *fp, short int sample, int bytes_per_sample) - { - void *data_ptr; - unsigned char buf_8bit; - int16_t buf_16bit; - if(bytes_per_sample == 1) { - buf_8bit = (unsigned char)sample; - data_ptr = (void*)&buf_8bit; - } - else { - buf_16bit = host_to_wav((int16_t) sample); - data_ptr = (void *) &buf_16bit; - } +void wav_write_sample(FILE* fp, short int sample, int bytes_per_sample) +{ + void* data_ptr; + unsigned char buf_8bit; + int16_t buf_16bit; - fwrite(data_ptr, 1, bytes_per_sample, fp); + if (bytes_per_sample == 1) { + buf_8bit = (unsigned char)sample; + data_ptr = (void*)&buf_8bit; + } else { + buf_16bit = host_to_wav((int16_t)sample); + data_ptr = (void*)&buf_16bit; } + fwrite(data_ptr, 1, bytes_per_sample, fp); +} - bool - wavheader_complete(FILE *fp, unsigned int byte_count) - { - uint32_t chunk_size = (uint32_t)byte_count; - chunk_size = host_to_wav(chunk_size); - if (fseek(fp, 40, SEEK_SET) != 0) { - return false; - } - fwrite(&chunk_size, 1, 4, fp); +bool wavheader_complete(FILE* fp, unsigned int byte_count) +{ + uint32_t chunk_size = (uint32_t)byte_count; + chunk_size = host_to_wav(chunk_size); - chunk_size = (uint32_t)byte_count + 36; // fmt chunk and data header - chunk_size = host_to_wav(chunk_size); - if (fseek(fp, 4, SEEK_SET) != 0) { - return false; - } + if (fseek(fp, 40, SEEK_SET) != 0) { + return false; + } + fwrite(&chunk_size, 1, 4, fp); - fwrite(&chunk_size, 1, 4, fp); + chunk_size = (uint32_t)byte_count + 36; // fmt chunk and data header + chunk_size = host_to_wav(chunk_size); + if (fseek(fp, 4, SEEK_SET) != 0) { + return false; + } - if(ferror(fp)) { - return false; - } + fwrite(&chunk_size, 1, 4, fp); - return true; + if (ferror(fp)) { + return false; } - } /* namespace blocks */ + return true; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/wavfile_sink_impl.cc b/gr-blocks/lib/wavfile_sink_impl.cc index dfa5ce425a..8ce5d94b96 100644 --- a/gr-blocks/lib/wavfile_sink_impl.cc +++ b/gr-blocks/lib/wavfile_sink_impl.cc @@ -53,246 +53,220 @@ #endif namespace gr { - namespace blocks { - - wavfile_sink::sptr - wavfile_sink::make(const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample) - { - return gnuradio::get_initial_sptr - (new wavfile_sink_impl(filename, n_channels, - sample_rate, bits_per_sample)); +namespace blocks { + +wavfile_sink::sptr wavfile_sink::make(const char* filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample) +{ + return gnuradio::get_initial_sptr( + new wavfile_sink_impl(filename, n_channels, sample_rate, bits_per_sample)); +} + +wavfile_sink_impl::wavfile_sink_impl(const char* filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample) + : sync_block("wavfile_sink", + io_signature::make(1, n_channels, sizeof(float)), + io_signature::make(0, 0, 0)), + d_sample_rate(sample_rate), + d_nchans(n_channels), + d_fp(0), + d_new_fp(0), + d_updated(false) +{ + if (bits_per_sample != 8 && bits_per_sample != 16) { + throw std::runtime_error("Invalid bits per sample (supports 8 and 16)"); } + d_bytes_per_sample = bits_per_sample / 8; + d_bytes_per_sample_new = d_bytes_per_sample; - wavfile_sink_impl::wavfile_sink_impl(const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample) - : sync_block("wavfile_sink", - io_signature::make(1, n_channels, sizeof(float)), - io_signature::make(0, 0, 0)), - d_sample_rate(sample_rate), d_nchans(n_channels), - d_fp(0), d_new_fp(0), d_updated(false) - { - if(bits_per_sample != 8 && bits_per_sample != 16) { - throw std::runtime_error("Invalid bits per sample (supports 8 and 16)"); - } - d_bytes_per_sample = bits_per_sample / 8; - d_bytes_per_sample_new = d_bytes_per_sample; - - if(!open(filename)) { - throw std::runtime_error("can't open file"); - } - - if(bits_per_sample == 8) { - d_max_sample_val = 0xFF; - d_min_sample_val = 0; - d_normalize_fac = d_max_sample_val/2; - d_normalize_shift = 1; - } - else { - d_max_sample_val = 0x7FFF; - d_min_sample_val = -0x7FFF; - d_normalize_fac = d_max_sample_val; - d_normalize_shift = 0; - } + if (!open(filename)) { + throw std::runtime_error("can't open file"); } - bool - wavfile_sink_impl::open(const char* filename) - { - gr::thread::scoped_lock guard(d_mutex); - - // we use the open system call to get access to the O_LARGEFILE flag. - int fd; - if((fd = ::open(filename, - O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, - 0664)) < 0) { - perror(filename); - return false; - } - - if(d_new_fp) { // if we've already got a new one open, close it - fclose(d_new_fp); - d_new_fp = 0; - } - - if((d_new_fp = fdopen (fd, "wb")) == NULL) { - perror(filename); - ::close(fd); // don't leak file descriptor if fdopen fails. - return false; - } - d_updated = true; - - if(!wavheader_write(d_new_fp, - d_sample_rate, - d_nchans, - d_bytes_per_sample_new)) { - fprintf(stderr, "[%s] could not write to WAV file\n", __FILE__); - exit(-1); - } - - return true; + if (bits_per_sample == 8) { + d_max_sample_val = 0xFF; + d_min_sample_val = 0; + d_normalize_fac = d_max_sample_val / 2; + d_normalize_shift = 1; + } else { + d_max_sample_val = 0x7FFF; + d_min_sample_val = -0x7FFF; + d_normalize_fac = d_max_sample_val; + d_normalize_shift = 0; + } +} + +bool wavfile_sink_impl::open(const char* filename) +{ + gr::thread::scoped_lock guard(d_mutex); + + // we use the open system call to get access to the O_LARGEFILE flag. + int fd; + if ((fd = ::open(filename, + O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE | OUR_O_BINARY, + 0664)) < 0) { + perror(filename); + return false; } - void - wavfile_sink_impl::close() - { - gr::thread::scoped_lock guard(d_mutex); + if (d_new_fp) { // if we've already got a new one open, close it + fclose(d_new_fp); + d_new_fp = 0; + } - if(!d_fp) - return; + if ((d_new_fp = fdopen(fd, "wb")) == NULL) { + perror(filename); + ::close(fd); // don't leak file descriptor if fdopen fails. + return false; + } + d_updated = true; - close_wav(); + if (!wavheader_write(d_new_fp, d_sample_rate, d_nchans, d_bytes_per_sample_new)) { + fprintf(stderr, "[%s] could not write to WAV file\n", __FILE__); + exit(-1); } - void - wavfile_sink_impl::close_wav() - { - unsigned int byte_count = d_sample_count * d_bytes_per_sample; + return true; +} - wavheader_complete(d_fp, byte_count); +void wavfile_sink_impl::close() +{ + gr::thread::scoped_lock guard(d_mutex); - fclose(d_fp); - d_fp = NULL; - } + if (!d_fp) + return; - wavfile_sink_impl::~wavfile_sink_impl() - { - stop(); - } + close_wav(); +} - bool wavfile_sink_impl::stop() - { - if(d_new_fp) { - fclose(d_new_fp); - d_new_fp = NULL; - } +void wavfile_sink_impl::close_wav() +{ + unsigned int byte_count = d_sample_count * d_bytes_per_sample; - close(); + wavheader_complete(d_fp, byte_count); - return true; - } + fclose(d_fp); + d_fp = NULL; +} - int - wavfile_sink_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float **in = (float**)&input_items[0]; - int n_in_chans = input_items.size(); - - short int sample_buf_s; - - int nwritten; - - gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this block - do_update(); // update: d_fp is reqd - if(!d_fp) // drop output on the floor - return noutput_items; - - for(nwritten = 0; nwritten < noutput_items; nwritten++) { - for(int chan = 0; chan < d_nchans; chan++) { - // Write zeros to channels which are in the WAV file - // but don't have any inputs here - if(chan < n_in_chans) { - sample_buf_s = - convert_to_short(in[chan][nwritten]); - } - else { - sample_buf_s = 0; - } - - wav_write_sample(d_fp, sample_buf_s, d_bytes_per_sample); - - if(feof(d_fp) || ferror(d_fp)) { - fprintf(stderr, "[%s] file i/o error\n", __FILE__); - close(); - exit(-1); - } - d_sample_count++; - } - } - - return nwritten; +wavfile_sink_impl::~wavfile_sink_impl() { stop(); } + +bool wavfile_sink_impl::stop() +{ + if (d_new_fp) { + fclose(d_new_fp); + d_new_fp = NULL; } - short int - wavfile_sink_impl::convert_to_short(float sample) - { - sample += d_normalize_shift; - sample *= d_normalize_fac; - if(sample > d_max_sample_val) { - sample = d_max_sample_val; - } - else if(sample < d_min_sample_val) { - sample = d_min_sample_val; - } - - return (short int)boost::math::iround(sample); + close(); + + return true; +} + +int wavfile_sink_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float** in = (float**)&input_items[0]; + int n_in_chans = input_items.size(); + + short int sample_buf_s; + + int nwritten; + + gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this block + do_update(); // update: d_fp is reqd + if (!d_fp) // drop output on the floor + return noutput_items; + + for (nwritten = 0; nwritten < noutput_items; nwritten++) { + for (int chan = 0; chan < d_nchans; chan++) { + // Write zeros to channels which are in the WAV file + // but don't have any inputs here + if (chan < n_in_chans) { + sample_buf_s = convert_to_short(in[chan][nwritten]); + } else { + sample_buf_s = 0; + } + + wav_write_sample(d_fp, sample_buf_s, d_bytes_per_sample); + + if (feof(d_fp) || ferror(d_fp)) { + fprintf(stderr, "[%s] file i/o error\n", __FILE__); + close(); + exit(-1); + } + d_sample_count++; + } } - void - wavfile_sink_impl::set_bits_per_sample(int bits_per_sample) - { - gr::thread::scoped_lock guard(d_mutex); - if(bits_per_sample == 8 || bits_per_sample == 16) { - d_bytes_per_sample_new = bits_per_sample / 8; - } + return nwritten; +} + +short int wavfile_sink_impl::convert_to_short(float sample) +{ + sample += d_normalize_shift; + sample *= d_normalize_fac; + if (sample > d_max_sample_val) { + sample = d_max_sample_val; + } else if (sample < d_min_sample_val) { + sample = d_min_sample_val; } - void - wavfile_sink_impl::set_sample_rate(unsigned int sample_rate) - { - gr::thread::scoped_lock guard(d_mutex); - d_sample_rate = sample_rate; + return (short int)boost::math::iround(sample); +} + +void wavfile_sink_impl::set_bits_per_sample(int bits_per_sample) +{ + gr::thread::scoped_lock guard(d_mutex); + if (bits_per_sample == 8 || bits_per_sample == 16) { + d_bytes_per_sample_new = bits_per_sample / 8; } +} - int - wavfile_sink_impl::bits_per_sample() - { - return d_bytes_per_sample_new; +void wavfile_sink_impl::set_sample_rate(unsigned int sample_rate) +{ + gr::thread::scoped_lock guard(d_mutex); + d_sample_rate = sample_rate; +} + +int wavfile_sink_impl::bits_per_sample() { return d_bytes_per_sample_new; } + +unsigned int wavfile_sink_impl::sample_rate() { return d_sample_rate; } + +void wavfile_sink_impl::do_update() +{ + if (!d_updated) { + return; } - unsigned int - wavfile_sink_impl::sample_rate() - { - return d_sample_rate; + if (d_fp) { + close_wav(); } - void - wavfile_sink_impl::do_update() - { - if(!d_updated) { - return; - } - - if(d_fp) { - close_wav(); - } - - d_fp = d_new_fp; // install new file pointer - d_new_fp = 0; - d_sample_count = 0; - d_bytes_per_sample = d_bytes_per_sample_new; - - if(d_bytes_per_sample == 1) { - d_max_sample_val = UCHAR_MAX; - d_min_sample_val = 0; - d_normalize_fac = d_max_sample_val/2; - d_normalize_shift = 1; - } - else if(d_bytes_per_sample == 2) { - d_max_sample_val = SHRT_MAX; - d_min_sample_val = SHRT_MIN; - d_normalize_fac = d_max_sample_val; - d_normalize_shift = 0; - } - - d_updated = false; + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; + d_sample_count = 0; + d_bytes_per_sample = d_bytes_per_sample_new; + + if (d_bytes_per_sample == 1) { + d_max_sample_val = UCHAR_MAX; + d_min_sample_val = 0; + d_normalize_fac = d_max_sample_val / 2; + d_normalize_shift = 1; + } else if (d_bytes_per_sample == 2) { + d_max_sample_val = SHRT_MAX; + d_min_sample_val = SHRT_MIN; + d_normalize_fac = d_max_sample_val; + d_normalize_shift = 0; } - } /* namespace blocks */ + d_updated = false; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/wavfile_sink_impl.h b/gr-blocks/lib/wavfile_sink_impl.h index 0e77f9799e..38a757704b 100644 --- a/gr-blocks/lib/wavfile_sink_impl.h +++ b/gr-blocks/lib/wavfile_sink_impl.h @@ -26,72 +26,72 @@ #include <gnuradio/blocks/wavfile_sink.h> namespace gr { - namespace blocks { - - class wavfile_sink_impl : public wavfile_sink - { - private: - unsigned d_sample_rate; - int d_nchans; - unsigned d_sample_count; - int d_bytes_per_sample; - int d_bytes_per_sample_new; - int d_max_sample_val; - int d_min_sample_val; - int d_normalize_shift; - int d_normalize_fac; - - FILE *d_fp; - FILE *d_new_fp; - bool d_updated; - boost::mutex d_mutex; - - /*! - * \brief Convert a sample value within [-1;+1] to a corresponding - * short integer value - */ - short convert_to_short(float sample); - - /*! - * \brief If any file changes have occurred, update now. This is called - * internally by work() and thus doesn't usually need to be called by - * hand. - */ - void do_update(); - - /*! - * \brief Writes information to the WAV header which is not available - * a-priori (chunk size etc.) and closes the file. Not thread-safe and - * assumes d_fp is a valid file pointer, should thus only be called by - * other methods. - */ - void close_wav(); - - protected: - bool stop(); - - public: - wavfile_sink_impl(const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample); - ~wavfile_sink_impl(); - - bool open(const char* filename); - void close(); - - void set_sample_rate(unsigned int sample_rate); - void set_bits_per_sample(int bits_per_sample); - - int bits_per_sample(); - unsigned int sample_rate(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; - - } /* namespace blocks */ +namespace blocks { + +class wavfile_sink_impl : public wavfile_sink +{ +private: + unsigned d_sample_rate; + int d_nchans; + unsigned d_sample_count; + int d_bytes_per_sample; + int d_bytes_per_sample_new; + int d_max_sample_val; + int d_min_sample_val; + int d_normalize_shift; + int d_normalize_fac; + + FILE* d_fp; + FILE* d_new_fp; + bool d_updated; + boost::mutex d_mutex; + + /*! + * \brief Convert a sample value within [-1;+1] to a corresponding + * short integer value + */ + short convert_to_short(float sample); + + /*! + * \brief If any file changes have occurred, update now. This is called + * internally by work() and thus doesn't usually need to be called by + * hand. + */ + void do_update(); + + /*! + * \brief Writes information to the WAV header which is not available + * a-priori (chunk size etc.) and closes the file. Not thread-safe and + * assumes d_fp is a valid file pointer, should thus only be called by + * other methods. + */ + void close_wav(); + +protected: + bool stop(); + +public: + wavfile_sink_impl(const char* filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample); + ~wavfile_sink_impl(); + + bool open(const char* filename); + void close(); + + void set_sample_rate(unsigned int sample_rate); + void set_bits_per_sample(int bits_per_sample); + + int bits_per_sample(); + unsigned int sample_rate(); + + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_WAVFILE_SINK_IMPL_H */ diff --git a/gr-blocks/lib/wavfile_source_impl.cc b/gr-blocks/lib/wavfile_source_impl.cc index 7538792d1c..b1950f2deb 100644 --- a/gr-blocks/lib/wavfile_source_impl.cc +++ b/gr-blocks/lib/wavfile_source_impl.cc @@ -36,139 +36,138 @@ #include <io.h> #endif #ifdef O_BINARY -#define OUR_O_BINARY O_BINARY +#define OUR_O_BINARY O_BINARY #else -#define OUR_O_BINARY 0 +#define OUR_O_BINARY 0 #endif // should be handled via configure #ifdef O_LARGEFILE -#define OUR_O_LARGEFILE O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE #else -#define OUR_O_LARGEFILE 0 +#define OUR_O_LARGEFILE 0 #endif namespace gr { - namespace blocks { +namespace blocks { + +wavfile_source::sptr wavfile_source::make(const char* filename, bool repeat) +{ + return gnuradio::get_initial_sptr(new wavfile_source_impl(filename, repeat)); +} + +wavfile_source_impl::wavfile_source_impl(const char* filename, bool repeat) + : sync_block("wavfile_source", + io_signature::make(0, 0, 0), + io_signature::make(1, 2, sizeof(float))), + d_fp(NULL), + d_repeat(repeat), + d_sample_rate(1), + d_nchans(1), + d_bytes_per_sample(2), + d_first_sample_pos(0), + d_samples_per_chan(0), + d_sample_idx(0) +{ + // we use "open" to use to the O_LARGEFILE flag + + int fd; + if ((fd = open(filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { + perror(filename); + throw std::runtime_error("can't open file"); + } - wavfile_source::sptr - wavfile_source::make(const char *filename, bool repeat) - { - return gnuradio::get_initial_sptr - (new wavfile_source_impl(filename, repeat)); + if ((d_fp = fdopen(fd, "rb")) == NULL) { + perror(filename); + throw std::runtime_error("can't open file"); } - wavfile_source_impl::wavfile_source_impl (const char *filename, bool repeat) - : sync_block("wavfile_source", - io_signature::make(0, 0, 0), - io_signature::make(1, 2, sizeof(float))), - d_fp(NULL), d_repeat(repeat), - d_sample_rate(1), d_nchans(1), d_bytes_per_sample(2), d_first_sample_pos(0), - d_samples_per_chan(0), d_sample_idx(0) - { - // we use "open" to use to the O_LARGEFILE flag - - int fd; - if((fd = open (filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { - perror(filename); - throw std::runtime_error("can't open file"); - } - - if((d_fp = fdopen(fd, "rb")) == NULL) { - perror(filename); - throw std::runtime_error("can't open file"); - } - - // Scan headers, check file validity - if(!wavheader_parse(d_fp, - d_sample_rate, - d_nchans, - d_bytes_per_sample, - d_first_sample_pos, - d_samples_per_chan)) { - throw std::runtime_error("is not a valid wav file"); - } - - if(d_samples_per_chan == 0) { - throw std::runtime_error("WAV file does not contain any samples"); - } - - if(d_bytes_per_sample == 1) { - d_normalize_fac = 128; - d_normalize_shift = 1; - } - else { - d_normalize_fac = 0x7FFF; - d_normalize_shift = 0; - } - - // Re-set the output signature - set_output_signature(io_signature::make(1, d_nchans, sizeof(float))); + // Scan headers, check file validity + if (!wavheader_parse(d_fp, + d_sample_rate, + d_nchans, + d_bytes_per_sample, + d_first_sample_pos, + d_samples_per_chan)) { + throw std::runtime_error("is not a valid wav file"); } - wavfile_source_impl::~wavfile_source_impl () - { - fclose(d_fp); + if (d_samples_per_chan == 0) { + throw std::runtime_error("WAV file does not contain any samples"); } - float - wavfile_source_impl::convert_to_float(short int sample) - { - float sample_out = (float)sample; - sample_out /= d_normalize_fac; - sample_out -= d_normalize_shift; - return sample_out; + if (d_bytes_per_sample == 1) { + d_normalize_fac = 128; + d_normalize_shift = 1; + } else { + d_normalize_fac = 0x7FFF; + d_normalize_shift = 0; } - int - wavfile_source_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - float **out = (float**)&output_items[0]; - int n_out_chans = output_items.size(); - - int i; - short sample; - - for(i = 0; i < noutput_items; i++) { - if(d_sample_idx >= d_samples_per_chan) { - if(!d_repeat) { - // if nothing was read at all, say we're done. - return i ? i : -1; - } - - if(fseek (d_fp, d_first_sample_pos, SEEK_SET) == -1) { - fprintf(stderr, "[%s] fseek failed\n", __FILE__); - exit(-1); - } - - d_sample_idx = 0; - } - - for(int chan = 0; chan < d_nchans; chan++) { - sample = wav_read_sample(d_fp, d_bytes_per_sample); - - if(chan < n_out_chans) { - out[chan][i] = convert_to_float(sample); - } - } - - d_sample_idx++; - - // OK, EOF is not necessarily an error. But we're not going to - // deal with handling corrupt wav files, so if they give us any - // trouble they won't be processed. Serves them bloody right. - if(feof(d_fp) || ferror(d_fp)) { - if(i == 0) { - fprintf(stderr, "[%s] WAV file has corrupted header or i/o error\n", __FILE__); - return -1; - } - return i; - } - } - - return noutput_items; + // Re-set the output signature + set_output_signature(io_signature::make(1, d_nchans, sizeof(float))); +} + +wavfile_source_impl::~wavfile_source_impl() { fclose(d_fp); } + +float wavfile_source_impl::convert_to_float(short int sample) +{ + float sample_out = (float)sample; + sample_out /= d_normalize_fac; + sample_out -= d_normalize_shift; + return sample_out; +} + +int wavfile_source_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + float** out = (float**)&output_items[0]; + int n_out_chans = output_items.size(); + + int i; + short sample; + + for (i = 0; i < noutput_items; i++) { + if (d_sample_idx >= d_samples_per_chan) { + if (!d_repeat) { + // if nothing was read at all, say we're done. + return i ? i : -1; + } + + if (fseek(d_fp, d_first_sample_pos, SEEK_SET) == -1) { + fprintf(stderr, "[%s] fseek failed\n", __FILE__); + exit(-1); + } + + d_sample_idx = 0; + } + + for (int chan = 0; chan < d_nchans; chan++) { + sample = wav_read_sample(d_fp, d_bytes_per_sample); + + if (chan < n_out_chans) { + out[chan][i] = convert_to_float(sample); + } + } + + d_sample_idx++; + + // OK, EOF is not necessarily an error. But we're not going to + // deal with handling corrupt wav files, so if they give us any + // trouble they won't be processed. Serves them bloody right. + if (feof(d_fp) || ferror(d_fp)) { + if (i == 0) { + fprintf(stderr, + "[%s] WAV file has corrupted header or i/o error\n", + __FILE__); + return -1; + } + return i; + } } - } /* namespace blocks */ + return noutput_items; +} + +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/wavfile_source_impl.h b/gr-blocks/lib/wavfile_source_impl.h index 3996cb0606..677c95562b 100644 --- a/gr-blocks/lib/wavfile_source_impl.h +++ b/gr-blocks/lib/wavfile_source_impl.h @@ -24,47 +24,47 @@ #define INCLUDED_GR_WAVFILE_SOURCE_IMPL_H #include <gnuradio/blocks/wavfile_source.h> -#include <cstdio> // for FILE +#include <cstdio> // for FILE namespace gr { - namespace blocks { +namespace blocks { - class wavfile_source_impl : public wavfile_source - { - private: - FILE *d_fp; - bool d_repeat; +class wavfile_source_impl : public wavfile_source +{ +private: + FILE* d_fp; + bool d_repeat; - unsigned d_sample_rate; - int d_nchans; - int d_bytes_per_sample; - int d_first_sample_pos; - unsigned d_samples_per_chan; - unsigned d_sample_idx; - int d_normalize_shift; - int d_normalize_fac; + unsigned d_sample_rate; + int d_nchans; + int d_bytes_per_sample; + int d_first_sample_pos; + unsigned d_samples_per_chan; + unsigned d_sample_idx; + int d_normalize_shift; + int d_normalize_fac; - /*! - * \brief Convert an integer sample value to a float value within [-1;1] - */ - float convert_to_float(short int sample); + /*! + * \brief Convert an integer sample value to a float value within [-1;1] + */ + float convert_to_float(short int sample); - public: - wavfile_source_impl(const char *filename, bool repeat); - ~wavfile_source_impl(); +public: + wavfile_source_impl(const char* filename, bool repeat); + ~wavfile_source_impl(); - unsigned int sample_rate() const { return d_sample_rate; }; + unsigned int sample_rate() const { return d_sample_rate; }; - int bits_per_sample() const { return d_bytes_per_sample * 8; }; + int bits_per_sample() const { return d_bytes_per_sample * 8; }; - int channels() const { return d_nchans; }; + int channels() const { return d_nchans; }; - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* INCLUDED_GR_WAVFILE_SOURCE_IMPL_H */ diff --git a/gr-blocks/lib/xor_blk_impl.cc b/gr-blocks/lib/xor_blk_impl.cc index 5180e6a600..ca8c623a65 100644 --- a/gr-blocks/lib/xor_blk_impl.cc +++ b/gr-blocks/lib/xor_blk_impl.cc @@ -29,45 +29,44 @@ #include <gnuradio/io_signature.h> namespace gr { - namespace blocks { - template <class T> - typename xor_blk<T>::sptr xor_blk<T>::make(size_t vlen) - { - return gnuradio::get_initial_sptr(new xor_blk_impl<T> (vlen)); - } +namespace blocks { +template <class T> +typename xor_blk<T>::sptr xor_blk<T>::make(size_t vlen) +{ + return gnuradio::get_initial_sptr(new xor_blk_impl<T>(vlen)); +} - template <class T> - xor_blk_impl<T> ::xor_blk_impl(size_t vlen) - : sync_block ("xor_blk", - io_signature::make (1, -1, sizeof (T)*vlen), - io_signature::make (1, 1, sizeof (T)*vlen)), +template <class T> +xor_blk_impl<T>::xor_blk_impl(size_t vlen) + : sync_block("xor_blk", + io_signature::make(1, -1, sizeof(T) * vlen), + io_signature::make(1, 1, sizeof(T) * vlen)), d_vlen(vlen) - { - } +{ +} - template <class T> - int - xor_blk_impl<T> ::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - T *optr = (T *) output_items[0]; +template <class T> +int xor_blk_impl<T>::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + T* optr = (T*)output_items[0]; - int ninputs = input_items.size (); + int ninputs = input_items.size(); - for (size_t i = 0; i < noutput_items*d_vlen; i++){ - T acc = ((T *) input_items[0])[i]; - for (int j = 1; j < ninputs; j++) - acc ^= ((T *) input_items[j])[i]; + for (size_t i = 0; i < noutput_items * d_vlen; i++) { + T acc = ((T*)input_items[0])[i]; + for (int j = 1; j < ninputs; j++) + acc ^= ((T*)input_items[j])[i]; - *optr++ = (T) acc; - } - - return noutput_items; + *optr++ = (T)acc; } + return noutput_items; +} + template class xor_blk<std::uint8_t>; template class xor_blk<std::int16_t>; template class xor_blk<std::int32_t>; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/xor_blk_impl.h b/gr-blocks/lib/xor_blk_impl.h index 72caa0a799..73ebe486d1 100644 --- a/gr-blocks/lib/xor_blk_impl.h +++ b/gr-blocks/lib/xor_blk_impl.h @@ -27,22 +27,22 @@ #include <gnuradio/blocks/xor_blk.h> namespace gr { - namespace blocks { +namespace blocks { -template<class T> - class BLOCKS_API xor_blk_impl : public xor_blk<T> - { - size_t d_vlen; +template <class T> +class BLOCKS_API xor_blk_impl : public xor_blk<T> +{ + size_t d_vlen; - public: - xor_blk_impl (size_t vlen); +public: + xor_blk_impl(size_t vlen); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace blocks */ +} /* namespace blocks */ } /* namespace gr */ #endif /* XOR_BLK_IMPL_H */ |