[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 46/57: blocks: adding an option to swap the
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 46/57: blocks: adding an option to swap the order of the output bits of a repack_bits block. |
Date: |
Wed, 21 May 2014 03:10:31 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
trondeau pushed a commit to branch master
in repository gnuradio.
commit fbe59ce5a58477c6f60cff59b81c0cd3a8e2e024
Author: Tom Rondeau <address@hidden>
Date: Fri May 16 15:53:35 2014 -0400
blocks: adding an option to swap the order of the output bits of a
repack_bits block.
---
gr-blocks/grc/blocks_repack_bits_bb.xml | 22 +++-
gr-blocks/include/gnuradio/blocks/repack_bits_bb.h | 12 ++-
gr-blocks/lib/repack_bits_bb_impl.cc | 117 +++++++++++++--------
gr-blocks/lib/repack_bits_bb_impl.h | 7 +-
gr-blocks/python/blocks/qa_repack_bits_bb.py | 14 ++-
5 files changed, 116 insertions(+), 56 deletions(-)
diff --git a/gr-blocks/grc/blocks_repack_bits_bb.xml
b/gr-blocks/grc/blocks_repack_bits_bb.xml
index 4ad5ec6..47aa73b 100644
--- a/gr-blocks/grc/blocks_repack_bits_bb.xml
+++ b/gr-blocks/grc/blocks_repack_bits_bb.xml
@@ -2,25 +2,29 @@
<name>Repack Bits</name>
<key>blocks_repack_bits_bb</key>
<import>from gnuradio import blocks</import>
- <make>blocks.repack_bits_bb($k, $l, $len_tag_key, $align_output)</make>
+ <make>blocks.repack_bits_bb($k, $l, $len_tag_key, $align_output,
$swap)</make>
+
<param>
<name>Bits per input byte</name>
<key>k</key>
<value>1</value>
<type>int</type>
</param>
+
<param>
<name>Bits per output byte</name>
<key>l</key>
<value>8</value>
<type>int</type>
</param>
+
<param>
<name>Length Tag Key</name>
<key>len_tag_key</key>
<value>""</value>
<type>string</type>
</param>
+
<param>
<name>Packet Alignment</name>
<key>align_output</key>
@@ -35,6 +39,22 @@
<key>False</key>
</option>
</param>
+
+ <param>
+ <name>Swap Bits</name>
+ <key>swap</key>
+ <value>False</value>
+ <type>enum</type>
+ <option>
+ <name>Yes</name>
+ <key>True</key>
+ </option>
+ <option>
+ <name>No</name>
+ <key>False</key>
+ </option>
+ </param>
+
<sink>
<name>in</name>
<type>byte</type>
diff --git a/gr-blocks/include/gnuradio/blocks/repack_bits_bb.h
b/gr-blocks/include/gnuradio/blocks/repack_bits_bb.h
index c594966..425cfa0 100644
--- a/gr-blocks/include/gnuradio/blocks/repack_bits_bb.h
+++ b/gr-blocks/include/gnuradio/blocks/repack_bits_bb.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012 Free Software Foundation, Inc.
+ * Copyright 2012,2014 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -25,6 +25,7 @@
#include <gnuradio/blocks/api.h>
#include <gnuradio/tagged_stream_block.h>
+#include <gnuradio/endianness.h>
namespace gr {
namespace blocks {
@@ -50,17 +51,18 @@ namespace gr {
typedef boost::shared_ptr<repack_bits_bb> sptr;
/*!
- * \param k Number of relevant bits on the input stream
- * \param l Number of relevant bits on the output stream
+ * \param k Number of relevant bits on the input stream.
+ * \param l Number of relevant bits on the output stream.
* \param len_tag_key If not empty, this is the key for the length tag.
* \param align_output If len_tag_key is given, this controls if the
input
* or the output is aligned.
+ * \param swap Swaps the output bits
*/
- static sptr make(int k, int l=8, const std::string &len_tag_key="", bool
align_output=false);
+ static sptr make(int k, int l=8, const std::string &len_tag_key="",
+ bool align_output=false, bool swap=false);
};
} // namespace blocks
} // namespace gr
#endif /* INCLUDED_BLOCKS_REPACK_BITS_BB_H */
-
diff --git a/gr-blocks/lib/repack_bits_bb_impl.cc
b/gr-blocks/lib/repack_bits_bb_impl.cc
index af83187..acf133e 100644
--- a/gr-blocks/lib/repack_bits_bb_impl.cc
+++ b/gr-blocks/lib/repack_bits_bb_impl.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012 Free Software Foundation, Inc.
+ * Copyright 2012,2014 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -31,26 +31,30 @@ namespace gr {
namespace blocks {
repack_bits_bb::sptr
- repack_bits_bb::make(int k, int l, const std::string &len_tag_key, bool
align_output)
+ repack_bits_bb::make(int k, int l, const std::string &len_tag_key,
+ bool align_output, bool swap)
{
- return gnuradio::get_initial_sptr (new repack_bits_bb_impl(k, l,
len_tag_key, align_output));
+ return gnuradio::get_initial_sptr
+ (new repack_bits_bb_impl(k, l, len_tag_key,
+ align_output, swap));
}
- repack_bits_bb_impl::repack_bits_bb_impl(int k, int l, const std::string
&len_tag_key, bool align_output)
+ repack_bits_bb_impl::repack_bits_bb_impl(int k, int l,
+ const std::string &len_tag_key,
+ bool align_output, bool swap)
: tagged_stream_block("repack_bits_bb",
- io_signature::make(1, 1, sizeof (char)),
- io_signature::make(1, 1, sizeof (char)),
- len_tag_key),
- d_k(k), d_l(l),
- d_packet_mode(!len_tag_key.empty()),
- d_in_index(0), d_out_index(0),
- d_align_output(align_output)
+ io_signature::make(1, 1, sizeof (char)),
+ io_signature::make(1, 1, sizeof (char)),
+ len_tag_key),
+ d_k(k), d_l(l), d_packet_mode(!len_tag_key.empty()),
+ d_in_index(0), d_out_index(0), d_align_output(align_output),
+ d_swap(swap)
{
- if (d_k > 8 || d_k < 1 || d_l > 8 || d_l < 1) {
+ if(d_k > 8 || d_k < 1 || d_l > 8 || d_l < 1) {
throw std::invalid_argument("k and l must be in [1, 8]");
}
- set_relative_rate((double) d_k / d_l);
+ set_relative_rate(static_cast<double>(d_k) / static_cast<double>(d_l));
}
repack_bits_bb_impl::~repack_bits_bb_impl()
@@ -61,7 +65,7 @@ namespace gr {
repack_bits_bb_impl::calculate_output_stream_length(const gr_vector_int
&ninput_items)
{
int n_out_bytes_required = (ninput_items[0] * d_k) / d_l;
- if ((ninput_items[0] * d_k) % d_l && (!d_packet_mode || (d_packet_mode
&& !d_align_output))) {
+ if((ninput_items[0] * d_k) % d_l && (!d_packet_mode || (d_packet_mode &&
!d_align_output))) {
n_out_bytes_required++;
}
@@ -69,50 +73,72 @@ namespace gr {
}
int
- repack_bits_bb_impl::work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
+ repack_bits_bb_impl::work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
{
- const unsigned char *in = (const unsigned char *) input_items[0];
- unsigned char *out = (unsigned char *) output_items[0];
+ const unsigned char *in = (const unsigned char *)input_items[0];
+ unsigned char *out = (unsigned char *)output_items[0];
int bytes_to_write = noutput_items;
- if (d_packet_mode) { // noutput_items could be larger than necessary
+ if(d_packet_mode) { // noutput_items could be larger than necessary
int bytes_to_read = ninput_items[0];
bytes_to_write = bytes_to_read * d_k / d_l;
- if (!d_align_output && (((bytes_to_read * d_k) % d_l) != 0)) {
+ if(!d_align_output && (((bytes_to_read * d_k) % d_l) != 0)) {
bytes_to_write++;
}
}
int n_read = 0;
int n_written = 0;
- while(n_written < bytes_to_write && n_read < ninput_items[0]) {
- if (d_out_index == 0) { // Starting a fresh byte
- out[n_written] = 0;
- }
- out[n_written] |= ((in[n_read] >> d_in_index) & 0x01) << d_out_index;
-
- d_in_index = (d_in_index + 1) % d_k;
- d_out_index = (d_out_index + 1) % d_l;
- if (d_in_index == 0) {
- n_read++;
- d_in_index = 0;
- }
- if (d_out_index == 0) {
- n_written++;
- d_out_index = 0;
- }
+ if(!d_swap) {
+ while(n_written < bytes_to_write && n_read < ninput_items[0]) {
+ if(d_out_index == 0) { // Starting a fresh byte
+ out[n_written] = 0;
+ }
+ out[n_written] |= ((in[n_read] >> d_in_index) & 0x01) << d_out_index;
+
+ d_in_index = (d_in_index + 1) % d_k;
+ d_out_index = (d_out_index + 1) % d_l;
+ if(d_in_index == 0) {
+ n_read++;
+ d_in_index = 0;
+ }
+ if(d_out_index == 0) {
+ n_written++;
+ d_out_index = 0;
+ }
+ }
+ }
+ else {
+ while(n_written < bytes_to_write && n_read < ninput_items[0]) {
+ if(d_out_index == 0) { // Starting a fresh byte
+ out[n_written] = 0;
+ }
+ out[n_written] |= ((in[n_read] >> d_in_index) & 0x01) <<
(d_l-1-d_out_index);
+
+ d_in_index = (d_in_index + 1) % d_k;
+ d_out_index = (d_out_index + 1) % d_l;
+ if(d_in_index == 0) {
+ n_read++;
+ d_in_index = 0;
+ }
+ if(d_out_index == 0) {
+ n_written++;
+ d_out_index = 0;
+ }
+ }
}
- if (d_packet_mode) {
- if (d_out_index) {
- n_written++;
- d_out_index = 0;
- }
- } else {
- consume_each(n_read);
+ if(d_packet_mode) {
+ if(d_out_index) {
+ n_written++;
+ d_out_index = 0;
+ }
+ }
+ else {
+ consume_each(n_read);
}
return n_written;
@@ -120,4 +146,3 @@ namespace gr {
} /* namespace blocks */
} /* namespace gr */
-
diff --git a/gr-blocks/lib/repack_bits_bb_impl.h
b/gr-blocks/lib/repack_bits_bb_impl.h
index ffb8349..3e7d9e6 100644
--- a/gr-blocks/lib/repack_bits_bb_impl.h
+++ b/gr-blocks/lib/repack_bits_bb_impl.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012 Free Software Foundation, Inc.
+ * Copyright 2012,2014 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -37,12 +37,14 @@ namespace gr {
int d_in_index; // Current bit of input byte
int d_out_index; // Current bit of output byte
bool d_align_output; //! true if the output shall be aligned, false if
the input shall be aligned
+ bool d_swap;
protected:
int calculate_output_stream_length(const gr_vector_int &ninput_items);
public:
- repack_bits_bb_impl(int k, int l, const std::string &len_tag_key, bool
align_output);
+ repack_bits_bb_impl(int k, int l, const std::string &len_tag_key,
+ bool align_output, bool swap=false);
~repack_bits_bb_impl();
int work(int noutput_items,
@@ -55,4 +57,3 @@ namespace gr {
} // namespace gr
#endif /* INCLUDED_BLOCKS_REPACK_BITS_BB_IMPL_H */
-
diff --git a/gr-blocks/python/blocks/qa_repack_bits_bb.py
b/gr-blocks/python/blocks/qa_repack_bits_bb.py
index d9bbfe4..ad3f772 100755
--- a/gr-blocks/python/blocks/qa_repack_bits_bb.py
+++ b/gr-blocks/python/blocks/qa_repack_bits_bb.py
@@ -121,6 +121,18 @@ class qa_repack_bits_bb (gr_unittest.TestCase):
self.assertEqual(pmt.symbol_to_string(out_tag.key), tag_name)
self.assertEqual(pmt.to_long(out_tag.value), len(expected_data))
+ def test_006_msb0 (self):
+ """ 8 -> 3 """
+ src_data = 200*(0b11110100, 0b11111111, 0b00111111)
+ expected_data = 200*((0b001,) + (0b011,) + (0b111,)*5 + (0b100,))
+ k = 8
+ l = 3
+ src = blocks.vector_source_b(src_data, False, 1)
+ repack = blocks.repack_bits_bb(k, l, swap=True)
+ sink = blocks.vector_sink_b()
+ self.tb.connect(src, repack, sink)
+ self.tb.run ()
+ self.assertEqual(sink.data(), expected_data)
+
if __name__ == '__main__':
gr_unittest.run(qa_repack_bits_bb, "qa_repack_bits_bb.xml")
-
- [Commit-gnuradio] [gnuradio] 35/57: runtime: don't add the log appender --> adds to C++, too., (continued)
- [Commit-gnuradio] [gnuradio] 35/57: runtime: don't add the log appender --> adds to C++, too., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 43/57: digital: added option to packet_utils.unmake_packet to check or not check the CRC., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 44/57: blocks: adds kernels for pack_k_bits and unpack_k_bits., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 30/57: runtime: configuring loggers in gr Python module for easy use in Python., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 39/57: digital: modified tagged stream correlate access code., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 37/57: Revert "blocks: add optional argument to deinterleave and interleave ctors to not set relative rate.", git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 42/57: fec: wip: fixing formatting., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 32/57: blocks: add optional argument to deinterleave and interleave ctors to not set relative rate., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 48/57: fec: wip: adding extended encoder for async version., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 47/57: digital: don't need the FEC info for the tagged stream corr access code., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 46/57: blocks: adding an option to swap the order of the output bits of a repack_bits block.,
git <=
- [Commit-gnuradio] [gnuradio] 45/57: fec: wip: using unpack/pack k bits kernels instead of copying logic in here., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 56/57: Merge branch 'fecapi', git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 51/57: Revert "blocks: adding an option to swap the order of the output bits of a repack_bits block.", git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 22/57: fec: wip: adding block that correlates against an access code and produces a tagged stream ofthe payload (stripped access code)., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 53/57: fec: wip: adding qa code., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 50/57: fec: wip: adding concept of padding for CC encoder/decoder., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 54/57: fec: mostly documentation updates, spell check, etc., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 55/57: fec: wip: fixing up allocated memory; allowing async encoder deployment to be used with CCSDS (packed input requirement)., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 41/57: digital: adding an async message passsing CRC32 calc/check block for PDUs., git, 2014/05/20
- [Commit-gnuradio] [gnuradio] 38/57: fec: wip: cleaning up tagged decoder, rep code., git, 2014/05/20