GNU Radio C++ API Reference  gcd20ee2
The Free & Open Software Radio Ecosystem
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  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_GR_BLOCKS_PACK_K_BITS_H
12 #define INCLUDED_GR_BLOCKS_PACK_K_BITS_H
13 
14 #include <gnuradio/blocks/api.h>
15 
16 namespace gr {
17 namespace blocks {
18 namespace kernel {
19 
20 /*!
21  * \brief Converts a vector of bytes with 1 bit in the LSB to a
22  * byte with k relevant bits.
23  *
24  * Example:
25  * k = 4
26  * in = [0,1,0,1, 0x81,0x00,0x00,0x00]
27  * out = [0x05, 0x08]
28  *
29  * k = 8
30  * in = [1,1,1,1, 0,1,0,1, 0,0,0,0, 1,0,0,0]
31  * out = [0xf5, 0x08]
32  * \ingroup byte_operators_blk
33  */
35 {
36 public:
37  /*!
38  * \brief Make a pack_k_bits object.
39  * \param k number of bits to be packed.
40  */
41  pack_k_bits(unsigned k);
43 
44  /*!
45  * \brief Perform the packing.
46  *
47  * This block performs no bounds checking. It assumes that the
48  * input, \p in, has of length k*nbytes and that the output
49  * vector, \p out, has \p nbytes available for writing.
50  *
51  * \param bytes output vector (k-bits per byte) of the unpacked data
52  * \param bits The input vector of bits to pack
53  * \param nbytes The number of output bytes
54  */
55  void pack(unsigned char* bytes, const unsigned char* bits, int nbytes) const;
56 
57  /*!
58  * Same as pack() but reverses the bits.
59  */
60  void pack_rev(unsigned char* bytes, const unsigned char* bits, int nbytes) const;
61 
62  int k() const;
63 
64 private:
65  unsigned d_k;
66 };
67 
68 } /* namespace kernel */
69 } /* namespace blocks */
70 } /* namespace gr */
71 
72 #endif /* INCLUDED_GR_BLOCKS_PACK_K_BITS_H */
Converts a vector of bytes with 1 bit in the LSB to a byte with k relevant bits.
Definition: pack_k_bits.h:35
pack_k_bits(unsigned k)
Make a pack_k_bits object.
void pack_rev(unsigned char *bytes, const unsigned char *bits, int nbytes) const
void pack(unsigned char *bytes, const unsigned char *bits, int nbytes) const
Perform the packing.
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29