GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
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  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_BLOCKS_REPACK_BITS_BB_H
12 #define INCLUDED_BLOCKS_REPACK_BITS_BB_H
13 
14 #include <gnuradio/blocks/api.h>
15 #include <gnuradio/endianness.h>
17 
18 namespace gr {
19 namespace blocks {
20 
21 /*!
22  * \brief Repack \p k bits from the input stream onto \p l bits of the output stream.
23  * \ingroup byte_operators_blk
24  *
25  * \details
26  * No bits are lost here; any value for k and l (within [1, 8]) is allowed.
27  * On every fresh input byte, it starts reading on the LSB, and starts copying
28  * to the LSB as well.
29  *
30  * When supplying a tag name, this block operates on tagged streams.
31  * In this case, it can happen that the input data or the output data
32  * becomes unaligned when k * input length is not equal to l * output length.
33  * In this case, the \p align_output parameter is used to decide which
34  * data packet to align.
35  *
36  * Usually, \p align_output is false for unpacking (k=8, l < 8) and false for
37  * reversing that.
38  *
39  * \section gr_blocks_repack_example Example
40  *
41  * Say you're tx'ing 8-PSK and therefore set k=8, l=3 on the transmit side
42  * before the modulator. Now assume you're transmitting a single byte of data.
43  * Your incoming tagged stream has length 1, the outgoing has length 3. However,
44  * the third item is actually only carrying 2 bits of relevant data, the bits
45  * do not align with the boundaries. So you set \p align_output = false,
46  * because the output can be unaligned.
47  *
48  * Now say you're doing the inverse: packing those three items into full
49  * bytes. How do you interpret those three bytes? Without this flag,
50  * you'd have to assume there's 9 relevant bits in there, so you'd end up
51  * with 2 bytes of output data. But in the packing case, you want the
52  * \b output to be aligned; all output bits must be useful. By asserting this flag,
53  * the packing algorithm tries to do this and in this case assumes that
54  * since we have alignment after 8 bits, the 9th can be discarded.
55  */
57 {
58 public:
59  typedef std::shared_ptr<repack_bits_bb> sptr;
60 
61  /*!
62  * \param k Number of relevant bits on the input stream
63  * \param l Number of relevant bits on the output stream
64  * \param tsb_tag_key If not empty, this is the key for the length tag.
65  * \param align_output If tsb_tag_key is given, this controls if the input
66  * or the output is aligned.
67  * \param endianness The endianness of the output data stream (LSB or MSB).
68  */
69  static sptr make(int k,
70  int l = 8,
71  const std::string& tsb_tag_key = "",
72  bool align_output = false,
73  endianness_t endianness = GR_LSB_FIRST);
74  virtual void set_k_and_l(int k, int l) = 0; // callback function for bits per input
75  // byte k and bits per output byte l.
76 };
77 
78 } // namespace blocks
79 } // namespace gr
80 
81 #endif /* INCLUDED_BLOCKS_REPACK_BITS_BB_H */
Repack k bits from the input stream onto l bits of the output stream.
Definition: repack_bits_bb.h:57
std::shared_ptr< repack_bits_bb > sptr
Definition: repack_bits_bb.h:59
static sptr make(int k, int l=8, const std::string &tsb_tag_key="", bool align_output=false, endianness_t endianness=GR_LSB_FIRST)
virtual void set_k_and_l(int k, int l)=0
Block that operates on PDUs in form of tagged streams.
Definition: tagged_stream_block.h:26
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29
endianness_t
Definition: endianness.h:16
@ GR_LSB_FIRST
Definition: endianness.h:16