GNU Radio Manual and C++ API Reference  v3.9.2.0-89-gb7c7001e
The Free & Open Software Radio Ecosystem
generic_decoder.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013-2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_FEC_GENERIC_DECODER_H
12 #define INCLUDED_FEC_GENERIC_DECODER_H
13 
14 #include <gnuradio/fec/api.h>
15 #include <gnuradio/logger.h>
16 #include <boost/format.hpp>
17 #include <memory>
18 
19 namespace gr {
20 namespace fec {
21 
22 /*!
23  * \brief Parent class for FECAPI objects.
24  *
25  * \ingroup error_coding_blk
26  *
27  * \details
28  *
29  * Parent of a decoder variable class for FECAPI that will fit
30  * into the gr::fec::decoder block to handle FEC decoding. This
31  * class provides the basic information required to fit into the
32  * FECAPI structure. It provides information about input and
33  * output data types, potential data conversions, and a few other
34  * parameters useful to establish the decoder's behavior.
35  *
36  * We create objects from FECAPI-derived classes to go into the
37  * actual GNU Radio decoder block. Each object contains its own
38  * state and so there should be a one-to-one mapping of an FECAPI
39  * object and a GR decoder block. Sharing these objects is not
40  * guaranteed to be thread-safe.
41  *
42  * This is a pure virtual class and must be derived from by a
43  * child class.
44  *
45  * \sa gr::fec::code::cc_decoder
46  * \sa gr::fec::code::ccsds_decoder
47  */
49 {
50 protected:
52 
53 public:
54  friend class decoder;
55  virtual void generic_work(void* inbuffer, void* outbuffer) = 0;
56  static int base_unique_id;
57  int my_id;
58  int unique_id();
59  std::string d_name;
60  std::string alias() { return (boost::format("%s%d") % d_name % unique_id()).str(); }
61 
62 public:
63  typedef std::shared_ptr<generic_decoder> sptr;
64 
65  generic_decoder(void){};
66  generic_decoder(std::string name);
67  virtual ~generic_decoder();
68 
69  /*!
70  * Returns the rate of the code. For every r input bits, there
71  * is 1 output bit, so the rate is 1/r. Used for setting things
72  * like the encoder block's relative rate.
73  *
74  * This function MUST be reimplemented by the child class.
75  */
76  virtual double rate() = 0;
77 
78  /*!
79  * Returns the input size in items that the decoder object uses
80  * to decode a full frame. Often, this number is the number of
81  * bits per frame if the input format is unpacked. If the block
82  * expects packed bytes, then this value should be the number of
83  * bytes (number of bits / 8) per input frame.
84  *
85  * The child class MUST implement this function.
86  */
87  virtual int get_input_size() = 0;
88 
89  /*!
90  * Returns the output size in items that the decoder object
91  * produces after decoding a full frame. Often, this number is
92  * the number of bits in the outputted frame if the input format
93  * is unpacked. If the block produces packed bytes, then this
94  * value should be the number of bytes (number of bits / 8) per
95  * frame produced. This value is generally something like
96  * get_input_size()/R for a 1/R rate code.
97  *
98  * The child class MUST implement this function.
99  */
100  virtual int get_output_size() = 0;
101 
102  /*!
103  * Sets up history for the decoder when the decoder is required
104  * to look ahead in the data stream in order to finish
105  * its processing.
106  *
107  * The child class MAY implement this function. If not
108  * reimplemented, it returns 0.
109  */
110  virtual int get_history();
111 
112  /*!
113  * Some decoders require the input items to float around a
114  * particular soft value. We can set that floating value by
115  * setting this value to return some non-zero number.
116  *
117  * The fec.extended_decoder block will use this to create an
118  * add_const_ff block before the decoder block to adjust all
119  * input samples appropriately.
120  *
121  * The child class MAY implement this function. If not
122  * reimplemented, it returns 0.
123  */
124  virtual float get_shift();
125 
126  /*!
127  * Sets the size of an input item, as in the size of a char or
128  * float item.
129  *
130  * The child class SHOULD implement this function. If not
131  * reimplemented, it returns sizeof(float) as the decoders
132  * typically expect floating point input types.
133  */
134  virtual int get_input_item_size();
135 
136  /*!
137  * Sets the size of an output item, as in the size of a char or
138  * float item.
139  *
140  * The child class SHOULD implement this function. If not
141  * reimplemented, it returns sizeof(char) as the decoders
142  * typically expect to produce bits or bytes.
143  */
144  virtual int get_output_item_size();
145 
146  /*!
147  * Set up a conversion type required to setup the data properly
148  * for this decoder. The decoder itself will not implement the
149  * conversion and expects an external wrapper (e.g.,
150  * fec.extended_decoder) to read this value and "do the right
151  * thing" to format the data.
152  *
153  * The default behavior is 'none', which means no conversion is
154  * required. Whatever the get_input_item_size() value returns,
155  * the input is expected to conform directly to this.
156  *
157  * This may also return 'uchar', which indicates that the
158  * wrapper should convert the standard float samples to unsigned
159  * characters, either hard sliced or 8-bit soft symbols. See
160  * gr::fec::code::cc_decoder as an example decoder that uses
161  * this conversion format.
162  *
163  * If 'packed_bits', the block expects the inputs to be packed
164  * hard bits. Each input item is a unsigned char where each of
165  * the 8-bits is a hard bit value.
166  *
167  * The child class SHOULD implement this function. If not
168  * reimplemented, it returns "none".
169  */
170  virtual const char* get_input_conversion();
171 
172  /*!
173  * Set up a conversion type required to understand the output
174  * style of this decoder. Generally, follow-on processing
175  * expects unpacked bits, so we specify the conversion type here
176  * to indicate what the wrapper (e.g., fec.extended_decoder)
177  * should do to convert the output samples from the decoder into
178  * unpacked bits.
179  *
180  * The default behavior is 'none', which means no conversion is
181  * required. This should mean that the output data is produced
182  * from this decoder as unpacked bit.
183  *
184  * If 'unpack', the block produces packed bytes that should be
185  * unpacked by the wrapper. See gr::fec::code::ccsds_decoder as
186  * an example of a decoder that produces packed bytes.
187  *
188  * The child class SHOULD implement this function. If not
189  * reimplemented, it returns "none".
190  */
191  virtual const char* get_output_conversion();
192 
193  /*!
194  * Updates the size of a decoded frame.
195  *
196  * The child class MUST implement this function and interpret
197  * how the \p frame_size information affects the block's
198  * behavior. It should also provide bounds checks.
199  */
200  virtual bool set_frame_size(unsigned int frame_size) = 0;
201 
202 
203  /*!
204  * Get repetitions to decode.
205  *
206  * The child class should implement this function and return the
207  * number of iterations required to decode.
208  */
209  virtual float get_iterations() { return -1; }
210 };
211 
212 /*! see generic_decoder::get_output_size() */
214 
215 /*! see generic_decoder::get_input_size() */
217 
218 /*! see generic_decoder::get_shift() */
220 
221 /*! see generic_decoder::get_history() */
223 
224 /*! see generic_decoder::get_input_item_size() */
226 
227 /*! see generic_decoder::get_output_item_size() */
229 
230 /*! see generic_decoder::get_input_conversion() */
232 
233 /*! see generic_decoder::get_output_conversion() */
235 
236 } /* namespace fec */
237 } /* namespace gr */
238 
239 #endif /* INCLUDED_FEC_GENRIC_DECODER_H */
General FEC decoding block that takes in a decoder variable object (derived from gr::fec::general_dec...
Definition: decoder.h:55
Parent class for FECAPI objects.
Definition: generic_decoder.h:49
static int base_unique_id
Definition: generic_decoder.h:56
virtual int get_output_size()=0
virtual int get_input_item_size()
gr::logger_ptr d_logger
Definition: generic_decoder.h:51
int my_id
Definition: generic_decoder.h:57
virtual double rate()=0
virtual int get_output_item_size()
virtual int get_input_size()=0
generic_decoder(void)
Definition: generic_decoder.h:65
virtual bool set_frame_size(unsigned int frame_size)=0
virtual float get_iterations()
Definition: generic_decoder.h:209
virtual float get_shift()
std::shared_ptr< generic_decoder > sptr
Definition: generic_decoder.h:63
virtual int get_history()
std::string d_name
Definition: generic_decoder.h:59
std::string alias()
Definition: generic_decoder.h:60
generic_decoder(std::string name)
virtual const char * get_output_conversion()
virtual void generic_work(void *inbuffer, void *outbuffer)=0
virtual const char * get_input_conversion()
#define FEC_API
Definition: gr-fec/include/gnuradio/fec/api.h:18
FEC_API const char * get_decoder_input_conversion(generic_decoder::sptr my_decoder)
FEC_API int get_decoder_input_size(generic_decoder::sptr my_decoder)
FEC_API int get_decoder_input_item_size(generic_decoder::sptr my_decoder)
FEC_API int get_history(generic_decoder::sptr my_decoder)
FEC_API float get_shift(generic_decoder::sptr my_decoder)
FEC_API const char * get_decoder_output_conversion(generic_decoder::sptr my_decoder)
FEC_API int get_decoder_output_size(generic_decoder::sptr my_decoder)
FEC_API int get_decoder_output_item_size(generic_decoder::sptr my_decoder)
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
log4cpp::Category * logger_ptr
GR_LOG macros.
Definition: logger.h:60