GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
repack_bits_bb.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_BLOCKS_REPACK_BITS_BB_H
24 #define INCLUDED_BLOCKS_REPACK_BITS_BB_H
25 
26 #include <gnuradio/blocks/api.h>
28 #include <gnuradio/endianness.h>
29 
30 namespace gr {
31  namespace blocks {
32 
33  /*!
34  * \brief Repack \p k bits from the input stream onto \p l bits of the output stream.
35  * \ingroup byte_operators_blk
36  *
37  * \details
38  * No bits are lost here; any value for k and l (within [1, 8]) is allowed.
39  * On every fresh input byte, it starts reading on the LSB, and starts copying
40  * to the LSB as well.
41  *
42  * When supplying a tag name, this block operates on tagged streams.
43  * In this case, it can happen that the input data or the output data
44  * becomes unaligned when k * input length is not equal to l * output length.
45  * In this case, the \p align_output parameter is used to decide which
46  * data packet to align.
47  *
48  * Usually, \p align_output is false for unpacking (k=8, l < 8) and false for
49  * reversing that.
50  *
51  * \section gr_blocks_repack_example Example
52  *
53  * Say you're tx'ing 8-PSK and therefore set k=8, l=3 on the transmit side
54  * before the modulator. Now assume you're transmitting a single byte of data.
55  * Your incoming tagged stream has length 1, the outgoing has length 3. However,
56  * the third item is actually only carrying 2 bits of relevant data, the bits
57  * do not align with the boundaries. So you set \p align_output = false,
58  * because the output can be unaligned.
59  *
60  * Now say you're doing the inverse: packing those three items into full
61  * bytes. How do you interpret those three bytes? Without this flag,
62  * you'd have to assume there's 9 relevant bits in there, so you'd end up
63  * with 2 bytes of output data. But in the packing case, you want the
64  * \b output to be aligned; all output bits must be useful. By asserting this flag,
65  * the packing algorithm tries to do this and in this case assumes that
66  * since we have alignment after 8 bits, the 9th can be discarded.
67  */
69  {
70  public:
71  typedef boost::shared_ptr<repack_bits_bb> sptr;
72 
73  /*!
74  * \param k Number of relevant bits on the input stream
75  * \param l Number of relevant bits on the output stream
76  * \param tsb_tag_key If not empty, this is the key for the length tag.
77  * \param align_output If tsb_tag_key is given, this controls if the input
78  * or the output is aligned.
79  * \param endianness The endianness of the output data stream (LSB or MSB).
80  */
81  static sptr make(int k, int l=8, const std::string &tsb_tag_key="",
82  bool align_output=false, endianness_t endianness=GR_LSB_FIRST);
83  virtual void set_k_and_l(int k, int l) =0;//callback function for bits per input byte k and bits per output byte l.
84  };
85 
86  } // namespace blocks
87 } // namespace gr
88 
89 #endif /* INCLUDED_BLOCKS_REPACK_BITS_BB_H */
endianness_t
Definition: endianness.h:28
Block that operates on PDUs in form of tagged streamsOverride work to provide the signal processing i...
Definition: tagged_stream_block.h:37
Repack k bits from the input stream onto l bits of the output stream.
Definition: repack_bits_bb.h:68
Definition: endianness.h:28
Include this header to use the message passing features.
Definition: logger.h:131
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:30
boost::shared_ptr< repack_bits_bb > sptr
Definition: repack_bits_bb.h:71