GNU Radio Manual and C++ API Reference  3.7.4.1
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
unpack_k_bits.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014 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_GR_BLOCKS_UNPACK_K_BITS_H
24 #define INCLUDED_GR_BLOCKS_UNPACK_K_BITS_H
25 
26 #include <gnuradio/blocks/api.h>
27 #include <vector>
28 
29 namespace gr {
30  namespace blocks {
31  namespace kernel {
32 
33  /*!
34  * \brief Converts a byte with k relevent bits to k output bytes with 1 bit in the LSB.
35  *
36  * This is the algorithm kernel for the gr::blocks::unpack_k_bits_bb block.
37  *
38  * Example:
39  * k = 4
40  * in = [0xf5, 0x08]
41  * out = [0,1,0,1, 1,0,0,0]
42  *
43  * k = 8
44  * in = [0xf5, 0x08]
45  * out = [1,1,1,1, 0,1,0,1, 0,0,0,0, 1,0,0,0]
46  * \ingroup byte_operators_blk
47  */
49  {
50  public:
51  /*!
52  * \brief Make an unpack_k_bits object.
53  * \param k number of bits to unpack.
54  */
55  unpack_k_bits(unsigned k);
56  ~unpack_k_bits();
57 
58  /*!
59  * \brief Perform the unpacking.
60  *
61  * This function performs no bounds checking. It assumes that the
62  * input, \p in, has of length \p nbytes and that the output
63  * vector, \p out, has k*nbytes available for writing.
64  *
65  * \param bits output vector (1-bit per byte) of the unpacked data
66  * \param bytes The input vector of bytes to unpack
67  * \param nbytes The number of input bytes
68  */
69  void unpack(unsigned char *bits, const unsigned char *bytes, int nbytes) const;
70 
71  /*!
72  * Unpacks in reverse order from unpack().
73  */
74  void unpack_rev(unsigned char *bits, const unsigned char *bytes, int nbytes) const;
75 
76  int k() const;
77 
78  private:
79  unsigned d_k;
80  };
81 
82  } /* namespace kernel */
83  } /* namespace blocks */
84 } /* namespace gr */
85 
86 #endif /* INCLUDED_GR_BLOCKS_UNPACK_K_BITS_BB_H */
Converts a byte with k relevent bits to k output bytes with 1 bit in the LSB.
Definition: unpack_k_bits.h:48
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:30