Files
GnuRadio/gr-jay/lib/bit_packer_impl.cc
T
jens 1305b8be7a - add gap sync
git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@425 b431acfa-c32f-4a4a-93f1-934dc6c82436
2019-02-10 17:24:17 +00:00

153 lines
3.2 KiB
C++

/* -*- c++ -*- */
/*
* Copyright 2019 Jay Arrowfield.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "bit_packer_impl.h"
namespace gr {
namespace jay {
bit_packer::sptr
bit_packer::make(int numBitsIn, int numBitsOut, int endianess)
{
return gnuradio::get_initial_sptr
(new bit_packer_impl(numBitsIn, numBitsOut, endianess));
}
/*
* The private constructor
*/
bit_packer_impl::bit_packer_impl(int numBitsIn, int numBitsOut, int endianess)
: gr::block("bit_packer"
, gr::io_signature::make(1, 1, sizeof(int))
, gr::io_signature::make(1, 1, sizeof(int)))
, m_inputCounter(0)
, m_outputCounter(0)
, m_numBitsIn(numBitsIn)
, m_numBitsOut(numBitsOut)
, m_endianess(endianess)
, m_gapCount(0)
{}
/*
* Our virtual destructor.
*/
bit_packer_impl::~bit_packer_impl()
{
}
void
bit_packer_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
/* <+forecast+> e.g. ninput_items_required[0] = noutput_items */
ninput_items_required[0] = m_numBitsIn*noutput_items;
}
int
bit_packer_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const int *in = (const int *) input_items[0];
int *out = (int *) output_items[0];
// Do <+signal processing+>
size_t i = 0;
size_t j = 0;
for (i=0; i < ninput_items[0]; i++)
{
if (in[i] == 0xFF)
{
m_inputCounter = 0;
m_outputCounter = 0;
m_output = 0;
}
else
{
if (in[i] == 1)
{
m_gapCount++;
}
else
{
m_gapCount = 0;
}
if (m_gapCount >= 16)
{
m_inputCounter = 0;
m_outputCounter = 0;
m_output = 0;
continue;
}
if (m_endianess == 0)
{
if(m_inputCounter == m_numBitsIn)
{
m_output <<= (m_numBitsOut - m_outputCounter);
out[j++] = m_output;
m_output = 0;
m_inputCounter = 0;
m_outputCounter = 0;
}
m_output <<= 1;
if (in[i] != 0)
{
m_output |= 1;
}
}
else
{
if(m_inputCounter == m_numBitsIn)
{
m_output >>= (m_numBitsOut - m_outputCounter);
out[j++] = m_output;
m_output = 0;
m_inputCounter = 0;
m_outputCounter = 0;
}
m_output >>= 1;
if (in[i] != 0)
{
m_output |= 1 << (m_numBitsOut-1);
}
}
m_inputCounter++;
m_outputCounter++;
}
}
// Tell runtime system how many input items we consumed on
// each input stream.
consume_each (i);
// Tell runtime system how many output items we produced.
return j;
}
} /* namespace jay */
} /* namespace gr */