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
pack_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_PACK_K_BITS_H
24 #define INCLUDED_GR_BLOCKS_PACK_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 vector of bytes with 1 bit in the LSB to a
35  * byte with k relevent bits.
36  *
37  * Example:
38  * k = 4
39  * in = [0,1,0,1, 0x81,0x00,0x00,0x00]
40  * out = [0x05, 0x08]
41  *
42  * k = 8
43  * in = [1,1,1,1, 0,1,0,1, 0,0,0,0, 1,0,0,0]
44  * out = [0xf5, 0x08]
45  * \ingroup byte_operators_blk
46  */
48  {
49  public:
50  /*!
51  * \brief Make a pack_k_bits object.
52  * \param k number of bits to be packed.
53  */
54  pack_k_bits(unsigned k);
55  ~pack_k_bits();
56 
57  /*!
58  * \brief Perform the packing.
59  *
60  * This block performs no bounds checking. It assumes that the
61  * input, \p in, has of length k*nbytes and that the output
62  * vector, \p out, has \p nbytes available for writing.
63  *
64  * \param bytes output vector (k-bits per byte) of the unpacked data
65  * \param bits The input vector of bits to pack
66  * \param nbytes The number of output bytes
67  */
68  void pack(unsigned char *bytes, const unsigned char *bits, int nbytes) const;
69 
70  /*!
71  * Same as pack() but reverses the bits.
72  */
73  void pack_rev(unsigned char *bytes, const unsigned char *bits, int nbytes) const;
74 
75  int k() const;
76 
77  private:
78  unsigned d_k;
79  };
80 
81  } /* namespace kernel */
82  } /* namespace blocks */
83 } /* namespace gr */
84 
85 #endif /* INCLUDED_GR_BLOCKS_PACK_K_BITS_H */
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
Converts a vector of bytes with 1 bit in the LSB to a byte with k relevent bits.
Definition: pack_k_bits.h:47