diff options
Diffstat (limited to 'gr-fec/lib')
-rw-r--r-- | gr-fec/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-fec/lib/async_decoder_impl.cc | 111 | ||||
-rw-r--r-- | gr-fec/lib/async_decoder_impl.h | 55 | ||||
-rw-r--r-- | gr-fec/lib/async_encoder_impl.cc | 118 | ||||
-rw-r--r-- | gr-fec/lib/async_encoder_impl.h | 53 |
5 files changed, 339 insertions, 0 deletions
diff --git a/gr-fec/lib/CMakeLists.txt b/gr-fec/lib/CMakeLists.txt index 42940be4c4..16f47c8ab8 100644 --- a/gr-fec/lib/CMakeLists.txt +++ b/gr-fec/lib/CMakeLists.txt @@ -55,6 +55,8 @@ list(APPEND gnuradio_fec_sources encoder_impl.cc tagged_decoder_impl.cc tagged_encoder_impl.cc + async_decoder_impl.cc + async_encoder_impl.cc cc_decoder_impl.cc cc_encoder_impl.cc ccsds_encoder_impl.cc diff --git a/gr-fec/lib/async_decoder_impl.cc b/gr-fec/lib/async_decoder_impl.cc new file mode 100644 index 0000000000..b235f959f5 --- /dev/null +++ b/gr-fec/lib/async_decoder_impl.cc @@ -0,0 +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 */
diff --git a/gr-fec/lib/async_decoder_impl.h b/gr-fec/lib/async_decoder_impl.h new file mode 100644 index 0000000000..9d1744c49d --- /dev/null +++ b/gr-fec/lib/async_decoder_impl.h @@ -0,0 +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 */
diff --git a/gr-fec/lib/async_encoder_impl.cc b/gr-fec/lib/async_encoder_impl.cc new file mode 100644 index 0000000000..b12ece1f3a --- /dev/null +++ b/gr-fec/lib/async_encoder_impl.cc @@ -0,0 +1,118 @@ +/* -*- 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 */
diff --git a/gr-fec/lib/async_encoder_impl.h b/gr-fec/lib/async_encoder_impl.h new file mode 100644 index 0000000000..99b628cc9b --- /dev/null +++ b/gr-fec/lib/async_encoder_impl.h @@ -0,0 +1,53 @@ +/* -*- 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 */
|