- added simple pattern matcher
git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@428 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -28,6 +28,12 @@
|
|||||||
namespace gr {
|
namespace gr {
|
||||||
namespace jay {
|
namespace jay {
|
||||||
|
|
||||||
|
const uint8_t bit_packer_impl::m_pattern[2][18] =
|
||||||
|
{
|
||||||
|
{0x02, 0x7e, 0x02, 0x7e, 0x02, 0x7e, 0x02, 0x7e, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7e, 0x7e, 0x7e},
|
||||||
|
{0x02, 0x7e, 0x02, 0x7e, 0x02, 0x7e, 0x02, 0x7e, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7e, 0x02, 0x7e}
|
||||||
|
};
|
||||||
|
|
||||||
bit_packer::sptr
|
bit_packer::sptr
|
||||||
bit_packer::make(int numBitsIn, int numBitsOut, int endianess)
|
bit_packer::make(int numBitsIn, int numBitsOut, int endianess)
|
||||||
{
|
{
|
||||||
@@ -43,7 +49,6 @@ bit_packer_impl::bit_packer_impl(int numBitsIn, int numBitsOut, int endianess)
|
|||||||
, gr::io_signature::make(1, 1, sizeof(int))
|
, gr::io_signature::make(1, 1, sizeof(int))
|
||||||
, gr::io_signature::make(1, 1, sizeof(int)))
|
, gr::io_signature::make(1, 1, sizeof(int)))
|
||||||
, m_inputCounter(0)
|
, m_inputCounter(0)
|
||||||
, m_outputCounter(0)
|
|
||||||
, m_numBitsIn(numBitsIn)
|
, m_numBitsIn(numBitsIn)
|
||||||
, m_numBitsOut(numBitsOut)
|
, m_numBitsOut(numBitsOut)
|
||||||
, m_endianess(endianess)
|
, m_endianess(endianess)
|
||||||
@@ -80,63 +85,59 @@ bit_packer_impl::general_work (int noutput_items,
|
|||||||
{
|
{
|
||||||
if (in[i] == 0xFF)
|
if (in[i] == 0xFF)
|
||||||
{
|
{
|
||||||
m_inputCounter = 0;
|
reset();
|
||||||
m_outputCounter = 0;
|
patternMatchReset();
|
||||||
m_output = 0;
|
continue;
|
||||||
|
}
|
||||||
|
else if (in[i] == 1)
|
||||||
|
{
|
||||||
|
m_gapCount++;
|
||||||
|
}
|
||||||
|
else if (in[i] == 0)
|
||||||
|
{
|
||||||
|
m_gapCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_gapCount >= 16)
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
patternMatchReset();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_endianess == 0)
|
||||||
|
{
|
||||||
|
if(m_inputCounter == m_numBitsIn)
|
||||||
|
{
|
||||||
|
m_output <<= (m_numBitsOut - m_inputCounter);
|
||||||
|
out[j++] = m_output;
|
||||||
|
patternMatchProcess(m_output);
|
||||||
|
m_output = 0;
|
||||||
|
m_inputCounter = 0;
|
||||||
|
}
|
||||||
|
m_output <<= 1;
|
||||||
|
if (in[i] != 0)
|
||||||
|
{
|
||||||
|
m_output |= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (in[i] == 1)
|
if(m_inputCounter == m_numBitsIn)
|
||||||
{
|
{
|
||||||
m_gapCount++;
|
m_output >>= (m_numBitsOut - m_inputCounter);
|
||||||
}
|
out[j++] = m_output;
|
||||||
else
|
patternMatchProcess(m_output);
|
||||||
{
|
|
||||||
m_gapCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_gapCount >= 16)
|
|
||||||
{
|
|
||||||
m_inputCounter = 0;
|
|
||||||
m_outputCounter = 0;
|
|
||||||
m_output = 0;
|
m_output = 0;
|
||||||
continue;
|
m_inputCounter = 0;
|
||||||
}
|
}
|
||||||
if (m_endianess == 0)
|
m_output >>= 1;
|
||||||
|
if (in[i] != 0)
|
||||||
{
|
{
|
||||||
if(m_inputCounter == m_numBitsIn)
|
m_output |= 1 << (m_numBitsOut-1);
|
||||||
{
|
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
|
m_inputCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell runtime system how many input items we consumed on
|
// Tell runtime system how many input items we consumed on
|
||||||
@@ -147,6 +148,38 @@ bit_packer_impl::general_work (int noutput_items,
|
|||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bit_packer_impl::reset()
|
||||||
|
{
|
||||||
|
m_inputCounter = 0;
|
||||||
|
m_output = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bit_packer_impl::patternMatchProcess(uint8_t byte)
|
||||||
|
{
|
||||||
|
for (int i=0; i < sizeof(m_patternMatchCount)/sizeof(*m_patternMatchCount); i++)
|
||||||
|
{
|
||||||
|
int index = m_patternMatchCount[i];
|
||||||
|
if (m_pattern[i][index] != byte)
|
||||||
|
{
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
if (index == sizeof(m_pattern[i])/sizeof(m_pattern[i][0]))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Match %d\n", i);
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
m_patternMatchCount[i] = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void bit_packer_impl::patternMatchReset()
|
||||||
|
{
|
||||||
|
memset(m_patternMatchCount, 0, sizeof(m_patternMatchCount));
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace jay */
|
} /* namespace jay */
|
||||||
} /* namespace gr */
|
} /* namespace gr */
|
||||||
|
|
||||||
|
|||||||
@@ -28,27 +28,30 @@ namespace gr {
|
|||||||
|
|
||||||
class bit_packer_impl : public bit_packer
|
class bit_packer_impl : public bit_packer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Nothing to declare in this block.
|
// Nothing to declare in this block.
|
||||||
int m_inputCounter;
|
int m_inputCounter;
|
||||||
int m_outputCounter;
|
|
||||||
int m_numBitsIn;
|
int m_numBitsIn;
|
||||||
int m_numBitsOut;
|
int m_numBitsOut;
|
||||||
int m_endianess;
|
int m_endianess;
|
||||||
int m_output;
|
int m_output;
|
||||||
int m_gapCount;
|
int m_gapCount;
|
||||||
|
int m_patternMatchCount[2];
|
||||||
public:
|
static const uint8_t m_pattern[2][18];
|
||||||
bit_packer_impl(int numBitsIn, int numBitsOut, int endianess);
|
void patternMatchProcess(uint8_t byte);
|
||||||
~bit_packer_impl();
|
void patternMatchReset();
|
||||||
|
void reset();
|
||||||
|
public:
|
||||||
|
bit_packer_impl(int numBitsIn, int numBitsOut, int endianess);
|
||||||
|
~bit_packer_impl();
|
||||||
|
|
||||||
// Where all the action really happens
|
// Where all the action really happens
|
||||||
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
|
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
|
||||||
|
|
||||||
int general_work(int noutput_items,
|
int general_work(int noutput_items,
|
||||||
gr_vector_int &ninput_items,
|
gr_vector_int &ninput_items,
|
||||||
gr_vector_const_void_star &input_items,
|
gr_vector_const_void_star &input_items,
|
||||||
gr_vector_void_star &output_items);
|
gr_vector_void_star &output_items);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace jay
|
} // namespace jay
|
||||||
|
|||||||
Reference in New Issue
Block a user