diff options
author | Tom Rondeau <tom@trondeau.com> | 2014-05-16 10:19:07 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2014-05-17 17:45:16 -0400 |
commit | 03b3b0eb63232507a4837be38d0398a655284f69 (patch) | |
tree | 46177f6253752306394f5db74fa0619694af7c47 /gr-fec | |
parent | 372c53a1d57f052015dc1247896e6e49944b54fb (diff) |
fec: wip: fixing formatting.
Diffstat (limited to 'gr-fec')
-rw-r--r-- | gr-fec/grc/fec_async_decoder.xml | 124 | ||||
-rw-r--r-- | gr-fec/grc/fec_async_encoder.xml | 60 | ||||
-rw-r--r-- | gr-fec/grc/variable_repetition_decoder_def_list.xml | 1 | ||||
-rw-r--r-- | gr-fec/include/gnuradio/fec/async_decoder.h | 138 | ||||
-rw-r--r-- | gr-fec/include/gnuradio/fec/async_encoder.h | 130 | ||||
-rw-r--r-- | gr-fec/lib/async_decoder_impl.cc | 222 | ||||
-rw-r--r-- | gr-fec/lib/async_decoder_impl.h | 110 | ||||
-rw-r--r-- | gr-fec/lib/async_encoder_impl.cc | 243 | ||||
-rw-r--r-- | gr-fec/lib/async_encoder_impl.h | 109 |
9 files changed, 574 insertions, 563 deletions
diff --git a/gr-fec/grc/fec_async_decoder.xml b/gr-fec/grc/fec_async_decoder.xml index 4cc7be7650..1f9ff99690 100644 --- a/gr-fec/grc/fec_async_decoder.xml +++ b/gr-fec/grc/fec_async_decoder.xml @@ -1,62 +1,62 @@ -<?xml version="1.0"?>
-<block>
- <name>FEC Async Decoder</name>
- <key>fec_async_decoder</key>
- <import>from gnuradio import fec</import>
- <make>fec.async_decoder($decoder, $itype.size, $otype.size)</make>
-
- <param>
- <name>Constituent Decoder</name>
- <key>decoder</key>
- <value>decoder_variable</value>
- <type>raw</type>
- </param>
-
- <param>
- <name>Input Type</name>
- <key>itype</key>
- <type>enum</type>
- <option>
- <name>Byte</name>
- <key>byte</key>
- <opt>size:gr.sizeof_char</opt>
- </option>
- <option>
- <name>Float</name>
- <key>float</key>
- <opt>size:gr.sizeof_float</opt>
- </option>
- </param>
-
- <param>
- <name>Output Type</name>
- <key>otype</key>
- <type>enum</type>
- <option>
- <name>Byte</name>
- <key>byte</key>
- <opt>size:gr.sizeof_char</opt>
- </option>
- <option>
- <name>Float</name>
- <key>float</key>
- <opt>size:gr.sizeof_float</opt>
- </option>
- </param>
-
- <sink>
- <name>pdus</name>
- <type>message</type>
- <optional>1</optional>
- </sink>
-
- <source>
- <name>pdus</name>
- <type>message</type>
- <optional>1</optional>
- </source>
-
- <doc>
- </doc>
-
-</block>
+<?xml version="1.0"?> +<block> + <name>FEC Async Decoder</name> + <key>fec_async_decoder</key> + <import>from gnuradio import fec</import> + <make>fec.async_decoder($decoder, $itype.size, $otype.size)</make> + + <param> + <name>Constituent Decoder</name> + <key>decoder</key> + <value>decoder_variable</value> + <type>raw</type> + </param> + + <param> + <name>Input Type</name> + <key>itype</key> + <type>enum</type> + <option> + <name>Byte</name> + <key>byte</key> + <opt>size:gr.sizeof_char</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>size:gr.sizeof_float</opt> + </option> + </param> + + <param> + <name>Output Type</name> + <key>otype</key> + <type>enum</type> + <option> + <name>Byte</name> + <key>byte</key> + <opt>size:gr.sizeof_char</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>size:gr.sizeof_float</opt> + </option> + </param> + + <sink> + <name>in</name> + <type>message</type> + <optional>1</optional> + </sink> + + <source> + <name>out</name> + <type>message</type> + <optional>1</optional> + </source> + + <doc> + </doc> + +</block> diff --git a/gr-fec/grc/fec_async_encoder.xml b/gr-fec/grc/fec_async_encoder.xml index 5b58c645ed..d552210523 100644 --- a/gr-fec/grc/fec_async_encoder.xml +++ b/gr-fec/grc/fec_async_encoder.xml @@ -1,30 +1,30 @@ -<?xml version="1.0"?>
-<block>
- <name>FEC Async Encoder</name>
- <key>fec_async_encoder</key>
- <import>from gnuradio import fec</import>
- <make>fec.async_encoder($encoder)</make>
-
- <param>
- <name>Constituent Encoder</name>
- <key>encoder</key>
- <value>encoder_variable</value>
- <type>raw</type>
- </param>
-
- <sink>
- <name>pdus</name>
- <type>message</type>
- <optional>1</optional>
- </sink>
-
- <source>
- <name>pdus</name>
- <type>message</type>
- <optional>1</optional>
- </source>
-
- <doc>
- </doc>
-
-</block>
+<?xml version="1.0"?> +<block> + <name>FEC Async Encoder</name> + <key>fec_async_encoder</key> + <import>from gnuradio import fec</import> + <make>fec.async_encoder($encoder)</make> + + <param> + <name>Constituent Encoder</name> + <key>encoder</key> + <value>encoder_variable</value> + <type>raw</type> + </param> + + <sink> + <name>in</name> + <type>message</type> + <optional>1</optional> + </sink> + + <source> + <name>out</name> + <type>message</type> + <optional>1</optional> + </source> + + <doc> + </doc> + +</block> diff --git a/gr-fec/grc/variable_repetition_decoder_def_list.xml b/gr-fec/grc/variable_repetition_decoder_def_list.xml index c3ab1dcc99..eba43f9b06 100644 --- a/gr-fec/grc/variable_repetition_decoder_def_list.xml +++ b/gr-fec/grc/variable_repetition_decoder_def_list.xml @@ -11,6 +11,7 @@ <var_make> #if int($ndim())==0 # self.$(id) = $(id) = fec.repetition_decoder.make($framebits, $rep, $prob) +#else if int($ndim())==1 # self.$(id) = $(id) = map( (lambda a: fec.repetition_decoder.make($framebits, $rep, $prob)), range(0,$dim1) ) #slurp #else self.$(id) = $(id) = map( (lambda b: map( ( lambda a: fec.repetition_decoder.make($framebits, $rep, $prob)), range(0,$dim2) ) ), range(0,$dim1)) #slurp diff --git a/gr-fec/include/gnuradio/fec/async_decoder.h b/gr-fec/include/gnuradio/fec/async_decoder.h index 2053d6494f..b68bd7157a 100644 --- a/gr-fec/include/gnuradio/fec/async_decoder.h +++ b/gr-fec/include/gnuradio/fec/async_decoder.h @@ -1,69 +1,69 @@ -/* -*- c++ -*- */
-/*
- * Copyright 2014 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef INCLUDED_FEC_ASYNC_DECODER_H
-#define INCLUDED_FEC_ASYNC_DECODER_H
-
-#include <gnuradio/fec/api.h>
-#include <gnuradio/fec/generic_decoder.h>
-#include <gnuradio/block.h>
-#include <boost/shared_ptr.hpp>
-
-namespace gr {
- namespace fec {
-
- /*!
- * \brief Creates the decoder block for use in GNU Radio
- * flowgraphs from a given FECAPI object derived from the
- * generic_decoder class.
- * \ingroup error_coding_blk
- *
- * \details
- *
- * Decodes frames received as a PDU over a message port.
- */
- class FEC_API async_decoder : virtual public block
- {
- public:
- typedef boost::shared_ptr<async_decoder> sptr;
-
- /*!
- * Build the PDU-based FEC decoder block from an FECAPI decoder object.
- *
- * \param my_decoder An FECAPI decoder object child of the generic_decoder class.
- * \param input_item_size size of a block of data for the decoder.
- * \param output_item_size size of a block of data the decoder will produce.
- */
- static sptr make(generic_decoder::sptr my_decoder,
- size_t input_item_size,
- size_t output_item_size);
-
- virtual int general_work(int noutput_items,
- gr_vector_int& ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items) = 0;
- };
-
- } /* namespace fec */
-} /* namespace gr */
-
-#endif /* INCLUDED_FEC_ASYNC_DECODER_H */
+/* -*- c++ -*- */ +/* + * Copyright 2014 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_FEC_ASYNC_DECODER_H +#define INCLUDED_FEC_ASYNC_DECODER_H + +#include <gnuradio/fec/api.h> +#include <gnuradio/fec/generic_decoder.h> +#include <gnuradio/block.h> +#include <boost/shared_ptr.hpp> + +namespace gr { + namespace fec { + + /*! + * \brief Creates the decoder block for use in GNU Radio + * flowgraphs from a given FECAPI object derived from the + * generic_decoder class. + * \ingroup error_coding_blk + * + * \details + * + * Decodes frames received as a PDU over a message port. + */ + class FEC_API async_decoder : virtual public block + { + public: + typedef boost::shared_ptr<async_decoder> sptr; + + /*! + * Build the PDU-based FEC decoder block from an FECAPI decoder object. + * + * \param my_decoder An FECAPI decoder object child of the generic_decoder class. + * \param input_item_size size of a block of data for the decoder. + * \param output_item_size size of a block of data the decoder will produce. + */ + static sptr make(generic_decoder::sptr my_decoder, + size_t input_item_size, + size_t output_item_size); + + virtual int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) = 0; + }; + + } /* namespace fec */ +} /* namespace gr */ + +#endif /* INCLUDED_FEC_ASYNC_DECODER_H */ diff --git a/gr-fec/include/gnuradio/fec/async_encoder.h b/gr-fec/include/gnuradio/fec/async_encoder.h index fef1883b56..a59f47d19e 100644 --- a/gr-fec/include/gnuradio/fec/async_encoder.h +++ b/gr-fec/include/gnuradio/fec/async_encoder.h @@ -1,65 +1,65 @@ -/* -*- c++ -*- */
-/*
- * Copyright 2014 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef INCLUDED_FEC_ASYNC_ENCODER_H
-#define INCLUDED_FEC_ASYNC_ENCODER_H
-
-#include <gnuradio/fec/api.h>
-#include <gnuradio/fec/generic_encoder.h>
-#include <gnuradio/block.h>
-#include <boost/shared_ptr.hpp>
-
-namespace gr {
- namespace fec {
-
- /*!
- * \brief Creates the encoder block for use in GNU Radio
- * flowgraphs from a given FECAPI object derived from the
- * generic_encoder class.
- * \ingroup error_coding_blk
- *
- * \details
- *
- * Encodes frames received as a PDU over a message port.
- */
- class FEC_API async_encoder : virtual public block
- {
- public:
- typedef boost::shared_ptr<async_encoder> sptr;
-
- /*!
- * Build the PDU-based FEC encoder block from an FECAPI encoder object.
- *
- * \param my_encoder An FECAPI encoder object child of the generic_encoder class.
- */
- static sptr make(generic_encoder::sptr my_encoder);
-
- virtual int general_work(int noutput_items,
- gr_vector_int& ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items) = 0;
- };
-
- } /* namespace fec */
-} /* namespace gr */
-
-#endif /* INCLUDED_FEC_ASYNC_ENCODER_H */
+/* -*- c++ -*- */ +/* + * Copyright 2014 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_FEC_ASYNC_ENCODER_H +#define INCLUDED_FEC_ASYNC_ENCODER_H + +#include <gnuradio/fec/api.h> +#include <gnuradio/fec/generic_encoder.h> +#include <gnuradio/block.h> +#include <boost/shared_ptr.hpp> + +namespace gr { + namespace fec { + + /*! + * \brief Creates the encoder block for use in GNU Radio + * flowgraphs from a given FECAPI object derived from the + * generic_encoder class. + * \ingroup error_coding_blk + * + * \details + * + * Encodes frames received as a PDU over a message port. + */ + class FEC_API async_encoder : virtual public block + { + public: + typedef boost::shared_ptr<async_encoder> sptr; + + /*! + * Build the PDU-based FEC encoder block from an FECAPI encoder object. + * + * \param my_encoder An FECAPI encoder object child of the generic_encoder class. + */ + static sptr make(generic_encoder::sptr my_encoder); + + virtual int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) = 0; + }; + + } /* namespace fec */ +} /* namespace gr */ + +#endif /* INCLUDED_FEC_ASYNC_ENCODER_H */ diff --git a/gr-fec/lib/async_decoder_impl.cc b/gr-fec/lib/async_decoder_impl.cc index b235f959f5..d3cfd2c05f 100644 --- a/gr-fec/lib/async_decoder_impl.cc +++ b/gr-fec/lib/async_decoder_impl.cc @@ -1,111 +1,111 @@ -/* -*- c++ -*- */
-/*
- * Copyright 2014 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "async_decoder_impl.h"
-#include <gnuradio/io_signature.h>
-#include <stdio.h>
-
-
-namespace gr {
- namespace fec {
-
- async_decoder::sptr
- async_decoder::make(generic_decoder::sptr my_decoder,
- size_t input_item_size, size_t output_item_size)
- {
- return gnuradio::get_initial_sptr
- (new async_decoder_impl(my_decoder, input_item_size, output_item_size));
- }
-
- async_decoder_impl::async_decoder_impl(generic_decoder::sptr my_decoder,
- size_t input_item_size,
- size_t output_item_size)
- : block("async_decoder",
- io_signature::make(0,0,0),
- io_signature::make(0,0,0)),
- d_input_item_size(input_item_size), d_output_item_size(output_item_size)
- {
- d_decoder = my_decoder;
- message_port_register_in(pmt::mp("pdus"));
- message_port_register_out(pmt::mp("pdus"));
- set_msg_handler(pmt::mp("pdus"), boost::bind(&async_decoder_impl::decode, this ,_1));
- }
-
- async_decoder_impl::~async_decoder_impl()
- {
- }
-
- void
- async_decoder_impl::decode(pmt::pmt_t msg)
- {
- // extract input pdu
- pmt::pmt_t meta(pmt::car(msg));
- pmt::pmt_t bits(pmt::cdr(msg));
-
- int nbits = pmt::length(bits);
- int blksize_in = d_decoder->get_input_size();
- int blksize_out = d_decoder->get_output_size();
- int nblocks = nbits/blksize_in;
-
- // nbits sanity check
- if(nbits % blksize_in != 0){
- throw std::runtime_error((boost::format("nbits_in %% blksize_in != 0 in fec_decoder_asyn! %d bits in, %d blksize") \
- % nbits % blksize_in).str());
- }
-
- printf("decoder :: blksize_in = %d, blksize_out = %d\n", blksize_in, blksize_out);
-
- pmt::pmt_t outvec(pmt::make_u8vector(blksize_out * nblocks, 0xFF));
- printf("decoder :: outvec len = %d (%d blks)\n", blksize_out * nblocks, nblocks);
-
- // get pmt buffer pointers
- size_t o0(0);
- const float* f32in = pmt::f32vector_elements(bits, o0);
- uint8_t* u8out = pmt::u8vector_writable_elements(outvec, o0);
-
- // loop over n fec blocks
- for(int i = 0; i < nblocks; i++) {
- size_t offset_in = i * blksize_in;
- size_t offset_out = i * blksize_out;
-
- // DECODE!
- d_decoder->generic_work((void*)&f32in[offset_in], (void*)&u8out[offset_out]);
- }
-
- message_port_pub(pmt::mp("pdus"), pmt::cons(meta, outvec));
- }
-
- int
- async_decoder_impl::general_work(int noutput_items,
- gr_vector_int& ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
- {
- return noutput_items;
- }
-
- } /* namespace fec */
-} /* namespace gr */
+/* -*- c++ -*- */ +/* + * Copyright 2014 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "async_decoder_impl.h" +#include <gnuradio/io_signature.h> +#include <stdio.h> + + +namespace gr { + namespace fec { + + async_decoder::sptr + async_decoder::make(generic_decoder::sptr my_decoder, + size_t input_item_size, size_t output_item_size) + { + return gnuradio::get_initial_sptr + (new async_decoder_impl(my_decoder, input_item_size, output_item_size)); + } + + async_decoder_impl::async_decoder_impl(generic_decoder::sptr my_decoder, + size_t input_item_size, + size_t output_item_size) + : block("async_decoder", + io_signature::make(0,0,0), + io_signature::make(0,0,0)), + d_input_item_size(input_item_size), d_output_item_size(output_item_size) + { + d_decoder = my_decoder; + message_port_register_in(pmt::mp("in")); + message_port_register_out(pmt::mp("out")); + set_msg_handler(pmt::mp("pdus"), boost::bind(&async_decoder_impl::decode, this ,_1)); + } + + async_decoder_impl::~async_decoder_impl() + { + } + + void + async_decoder_impl::decode(pmt::pmt_t msg) + { + // extract input pdu + pmt::pmt_t meta(pmt::car(msg)); + pmt::pmt_t bits(pmt::cdr(msg)); + + int nbits = pmt::length(bits); + int blksize_in = d_decoder->get_input_size(); + int blksize_out = d_decoder->get_output_size(); + int nblocks = nbits/blksize_in; + + // nbits sanity check + if(nbits % blksize_in != 0){ + throw std::runtime_error((boost::format("nbits_in %% blksize_in != 0 in fec_decoder_asyn! %d bits in, %d blksize") \ + % nbits % blksize_in).str()); + } + + printf("decoder :: blksize_in = %d, blksize_out = %d\n", blksize_in, blksize_out); + + pmt::pmt_t outvec(pmt::make_u8vector(blksize_out * nblocks, 0xFF)); + printf("decoder :: outvec len = %d (%d blks)\n", blksize_out * nblocks, nblocks); + + // get pmt buffer pointers + size_t o0(0); + const float* f32in = pmt::f32vector_elements(bits, o0); + uint8_t* u8out = pmt::u8vector_writable_elements(outvec, o0); + + // loop over n fec blocks + for(int i = 0; i < nblocks; i++) { + size_t offset_in = i * blksize_in; + size_t offset_out = i * blksize_out; + + // DECODE! + d_decoder->generic_work((void*)&f32in[offset_in], (void*)&u8out[offset_out]); + } + + message_port_pub(pmt::mp("pdus"), pmt::cons(meta, outvec)); + } + + int + async_decoder_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + return noutput_items; + } + + } /* namespace fec */ +} /* namespace gr */ diff --git a/gr-fec/lib/async_decoder_impl.h b/gr-fec/lib/async_decoder_impl.h index 9d1744c49d..5f4c5c44a0 100644 --- a/gr-fec/lib/async_decoder_impl.h +++ b/gr-fec/lib/async_decoder_impl.h @@ -1,55 +1,55 @@ -/* -*- c++ -*- */
-/*
- * Copyright 2014 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef INCLUDED_FEC_ASYNC_DECODER_IMPL_H
-#define INCLUDED_FEC_ASYNC_DECODER_IMPL_H
-
-#include <gnuradio/fec/async_decoder.h>
-
-namespace gr {
- namespace fec {
-
- class FEC_API async_decoder_impl : public async_decoder
- {
- private:
- generic_decoder::sptr d_decoder;
- size_t d_input_item_size;
- size_t d_output_item_size;
-
- void decode(pmt::pmt_t msg);
-
- public:
- async_decoder_impl(generic_decoder::sptr my_decoder,
- size_t input_item_size,
- size_t output_item_size);
- ~async_decoder_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 fec */
-} /* namespace gr */
-
-#endif /* INCLUDED_FEC_ASYNC_DECODER_IMPL_H */
+/* -*- c++ -*- */ +/* + * Copyright 2014 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_FEC_ASYNC_DECODER_IMPL_H +#define INCLUDED_FEC_ASYNC_DECODER_IMPL_H + +#include <gnuradio/fec/async_decoder.h> + +namespace gr { + namespace fec { + + class FEC_API async_decoder_impl : public async_decoder + { + private: + generic_decoder::sptr d_decoder; + size_t d_input_item_size; + size_t d_output_item_size; + + void decode(pmt::pmt_t msg); + + public: + async_decoder_impl(generic_decoder::sptr my_decoder, + size_t input_item_size, + size_t output_item_size); + ~async_decoder_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 fec */ +} /* namespace gr */ + +#endif /* INCLUDED_FEC_ASYNC_DECODER_IMPL_H */ diff --git a/gr-fec/lib/async_encoder_impl.cc b/gr-fec/lib/async_encoder_impl.cc index b12ece1f3a..6f9b54b3fc 100644 --- a/gr-fec/lib/async_encoder_impl.cc +++ b/gr-fec/lib/async_encoder_impl.cc @@ -1,118 +1,125 @@ -/* -*- c++ -*- */
-/*
- * Copyright 2014 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "async_encoder_impl.h"
-#include <gnuradio/io_signature.h>
-#include <stdio.h>
-
-namespace gr {
- namespace fec {
-
- async_encoder::sptr
- async_encoder::make(generic_encoder::sptr my_encoder)
- {
- return gnuradio::get_initial_sptr
- (new async_encoder_impl(my_encoder));
- }
-
- async_encoder_impl::async_encoder_impl(generic_encoder::sptr my_encoder)
- : block("async_encoder",
- io_signature::make(0,0,0),
- io_signature::make(0,0,0)),
- d_input_item_size(sizeof(char)), d_output_item_size(sizeof(char))
- {
- d_encoder = my_encoder;
- message_port_register_in(pmt::mp("pdus"));
- message_port_register_out(pmt::mp("pdus"));
- set_msg_handler(pmt::mp("pdus"), boost::bind(&async_encoder_impl::encode, this ,_1) );
- }
-
- async_encoder_impl::~async_encoder_impl()
- {
- }
-
- void
- async_encoder_impl::encode(pmt::pmt_t msg)
- {
- // extract input pdu
- pmt::pmt_t meta(pmt::car(msg));
- pmt::pmt_t bits(pmt::cdr(msg));
-
- int nbits = pmt::length(bits);
- int blksize_in = d_encoder->get_input_size();
- int blksize_out = (int)d_encoder->rate();
- int nblocks = nbits/blksize_in;
-
- printf("async_encoder: blksize_in = %d, blksize_out = %d nblocks=%d\n",
- blksize_in, blksize_out, nblocks);
-
- pmt::pmt_t outvec(pmt::make_u8vector(blksize_out * nblocks, 0xFF));
-
- printf("encoder: outvec len = %d\n", blksize_out * nblocks);
-
- // get pmt buffer pointers
- size_t o0(0);
- const uint8_t* u8in = pmt::u8vector_elements(bits,o0);
- uint8_t* u8tmp = pmt::u8vector_writable_elements(bits,o0);
- uint8_t* u8out = pmt::u8vector_writable_elements(outvec,o0);
-
- // alloc playspace
- std::vector<uint8_t> blks_out(blksize_out);
-
- // loop over n fec blocks
- for(int i = 0; i < nblocks; i++) {
- size_t offset_in = i * blksize_in;
- size_t offset_out = i * blksize_out;
-
- for(int jj = 0; jj < blksize_in; jj++) {
- u8tmp[offset_in + jj] = 0x01 & u8in[offset_in + jj];
- //printf("in[%zd]=%u ", offset_in+jj, u8tmp[offset_in + jj]);
- //fflush(stdout);
- }
-
- // ENCODE!
- d_encoder->generic_work((void*)&u8tmp[offset_in], (void*)&blks_out[0]);
-
- // convert float -> u8
- for(int j = 0; j < blksize_out; j++) {
- u8out[offset_out + j] = (blks_out[j] > 0);
- }
- }
-
- message_port_pub(pmt::mp("pdus"), pmt::cons(meta, outvec));
- }
-
- int
- async_encoder_impl::general_work(int noutput_items,
- gr_vector_int& ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
- {
- return noutput_items;
- }
-
- } /* namespace fec */
-} /* namespace gr */
+/* -*- c++ -*- */ +/* + * Copyright 2014 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "async_encoder_impl.h" +#include <gnuradio/io_signature.h> +#include <volk/volk.h> +#include <stdio.h> + +namespace gr { + namespace fec { + + async_encoder::sptr + async_encoder::make(generic_encoder::sptr my_encoder) + { + return gnuradio::get_initial_sptr + (new async_encoder_impl(my_encoder)); + } + + async_encoder_impl::async_encoder_impl(generic_encoder::sptr my_encoder) + : block("async_encoder", + io_signature::make(0,0,0), + io_signature::make(0,0,0)), + d_input_item_size(sizeof(char)), d_output_item_size(sizeof(char)) + { + d_in_port = pmt::mp("in"); + d_out_port = pmt::mp("out"); + + d_encoder = my_encoder; + message_port_register_in(d_in_port); + message_port_register_out(d_out_port); + set_msg_handler(d_in_port, boost::bind(&async_encoder_impl::encode, this ,_1) ); + } + + async_encoder_impl::~async_encoder_impl() + { + } + + void + async_encoder_impl::encode(pmt::pmt_t msg) + { + // extract input pdu + pmt::pmt_t meta(pmt::car(msg)); + pmt::pmt_t bytes(pmt::cdr(msg)); + + int nbytes = pmt::length(bytes); + int nbits = 8*nbytes; + size_t o0(0); + const uint8_t* bytes_in = pmt::u8vector_elements(bytes, o0); + uint8_t* bits_in = (uint8_t*)volk_malloc(nbits*sizeof(uint8_t), + volk_get_alignment()); + + // Stolen from unpack_k_bits + int n = 0; + for(int i = 0; i < nbytes; i++) { + uint8_t t = bytes_in[i]; + for(int j = 7; j >= 0; j--) + bits_in[n++] = (t >> j) & 0x01; + } + + d_encoder->set_frame_size(nbits); + + int nbits_out = d_encoder->get_output_size(); + int nbytes_out = nbits_out/8; + + // get pmt buffer pointers + uint8_t* bits_out = (uint8_t*)volk_malloc(nbits_out*sizeof(uint8_t), + volk_get_alignment()); + uint8_t* bytes_out = (uint8_t*)volk_malloc(nbytes_out*sizeof(uint8_t), + volk_get_alignment()); + + // ENCODE! + d_encoder->generic_work((void*)bits_in, (void*)bits_out); + + // Stolen from pack_k_bits + for(int i = 0; i < nbytes_out; i++) { + bytes_out[i] = 0x00; + for(int j = 0; j < 8; j++) { + bytes_out[i] |= (0x01 & bits_out[i*8+j])<<(8-j-1); + } + } + + //pmt::pmt_t outvec = pmt::init_u8vector(nouts, u8out); + pmt::pmt_t outvec = pmt::init_u8vector(nbytes_out, bytes_out); + pmt::pmt_t msg_pair = pmt::cons(meta, outvec); + message_port_pub(d_out_port, msg_pair); + + volk_free(bits_in); + volk_free(bits_out); + volk_free(bytes_out); + } + + int + async_encoder_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + return noutput_items; + } + + } /* namespace fec */ +} /* namespace gr */ diff --git a/gr-fec/lib/async_encoder_impl.h b/gr-fec/lib/async_encoder_impl.h index 99b628cc9b..38ae6850ed 100644 --- a/gr-fec/lib/async_encoder_impl.h +++ b/gr-fec/lib/async_encoder_impl.h @@ -1,53 +1,56 @@ -/* -*- c++ -*- */
-/*
- * Copyright 2014 Free Software Foundation, Inc.
- *
- * This file is part of GNU Radio
- *
- * GNU Radio is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * GNU Radio is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Radio; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef INCLUDED_FEC_ASYNC_ENCODER_IMPL_H
-#define INCLUDED_FEC_ASYNC_ENCODER_IMPL_H
-
-#include <gnuradio/fec/async_encoder.h>
-
-namespace gr {
- namespace fec {
-
- class FEC_API async_encoder_impl : public async_encoder
- {
- private:
- generic_encoder::sptr d_encoder;
- size_t d_input_item_size;
- size_t d_output_item_size;
-
- void encode(pmt::pmt_t msg);
-
- public:
- async_encoder_impl(generic_encoder::sptr my_encoder);
- ~async_encoder_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 fec */
-} /* namespace gr */
-
-#endif /* INCLUDED_FEC_ASYNC_ENCODER_IMPL_H */
+/* -*- c++ -*- */ +/* + * Copyright 2014 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_FEC_ASYNC_ENCODER_IMPL_H +#define INCLUDED_FEC_ASYNC_ENCODER_IMPL_H + +#include <gnuradio/fec/async_encoder.h> + +namespace gr { + namespace fec { + + class FEC_API async_encoder_impl : public async_encoder + { + private: + generic_encoder::sptr d_encoder; + size_t d_input_item_size; + size_t d_output_item_size; + + pmt::pmt_t d_in_port; + pmt::pmt_t d_out_port; + + void encode(pmt::pmt_t msg); + + public: + async_encoder_impl(generic_encoder::sptr my_encoder); + ~async_encoder_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 fec */ +} /* namespace gr */ + +#endif /* INCLUDED_FEC_ASYNC_ENCODER_IMPL_H */ |