- improved syncronization

- fixed inverted bit 

git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@395 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-01-09 14:50:44 +00:00
parent d7f5f09cb8
commit bd2b639547
2 changed files with 77 additions and 54 deletions
+64 -50
View File
@@ -35,16 +35,19 @@ preamble_sync::sptr preamble_sync::make()
return gnuradio::get_initial_sptr (new preamble_sync_impl());
}
const char* preamble_sync_impl::stateNames[NUM_STATES] = {"PreambleSlow", "SyncSlow", "DataSlow", "PreambleFast", "SyncFast", "DataFast"};
/*
* The private constructor
*/
preamble_sync_impl::preamble_sync_impl()
: gr::block("preamble_sync", gr::io_signature::make(1, 1, sizeof(uint8_t)), gr::io_signature::make(1, 1, sizeof(uint8_t)))
, m_state(Init)
, m_stateNext(Init)
, m_state(PreambleSlow)
, m_stateNext(PreambleSlow)
, m_word(0)
, m_wordCount(0)
, m_preambleCount(0)
, m_wordSize(1)
, m_dataCount(0)
{
}
@@ -62,8 +65,8 @@ void preamble_sync_impl::forecast (int noutput_items, gr_vector_int &ninput_item
int preamble_sync_impl::general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
{
size_t const word_size = 8;
uint8_t zero = 0x01;
const uint8_t fastSyncWord[4] = {0x7C, 0xD2, 0x15, 0xD8};
const uint8_t *in = (const uint8_t *) input_items[0];
uint8_t *out = (uint8_t *) output_items[0];
@@ -74,14 +77,23 @@ int preamble_sync_impl::general_work (int noutput_items, gr_vector_int &ninput_i
{
if (in[i] == 0xFF)
{
if (m_state != Init)
if (m_state != PreambleSlow)
{
m_state = Init;
fprintf(stderr, "Init\n");
m_state = PreambleSlow;
m_wordCount = 0;
fprintf(stderr, "Reset\n");
}
continue;
}
m_word = (m_word << 1) | in[i];
if (in[i] == zero)
{
m_word = (m_word << 1) | 0;
}
else
{
m_word = (m_word << 1) | 1;
}
if (m_wordCount != 0)
{
@@ -89,63 +101,64 @@ int preamble_sync_impl::general_work (int noutput_items, gr_vector_int &ninput_i
continue;
}
m_word &= (typeof(m_word))(1 << word_size)-1;
m_stateNext = m_state;
switch (m_state)
{
case Init:
if (m_word != 0xCC)
case PreambleSlow:
if ((m_word & 0xFF) == 0xCC)
{
m_wordCount = 0;
m_preambleCount = 8;
m_wordSize = 1;
m_stateNext = SyncSlow;
}
else
break;
case SyncSlow:
if ((m_word & 0xFF) == 0x3F)
{
m_wordCount = word_size-1;
if (m_preambleCount)
m_wordSize = 8;
m_dataCount = 1;
out[j++] = m_word;
m_stateNext = DataSlow;
}
break;
case DataSlow:
m_dataCount++;
out[j++] = m_word;
if (m_dataCount == 0xA0)
{
m_wordSize = 1;
m_stateNext = PreambleFast;
}
break;
case PreambleFast:
if ((m_word & 0xFF) == 0xAA)
{
m_wordSize = 8;
m_dataCount = 0;
m_stateNext = SyncFast;
}
break;
case SyncFast:
if ((m_word & 0xFF) == fastSyncWord[m_dataCount])
{
out[j++] = m_word;
m_dataCount++;
if (m_dataCount == 4)
{
m_preambleCount--;
}
else
{
m_stateNext = Preamble;
fprintf(stderr, "Preamble\n");
m_stateNext = DataFast;
}
}
break;
case Preamble:
m_wordCount = word_size-1;
if (m_word == 0xC0)
{
m_stateNext = Sync;
fprintf(stderr, "Sync 1\n");
}
else if (m_word == 0xCF)
{
m_stateNext = Sync;
fprintf(stderr, "Sync 2\n");
}
else if (m_word == 0xF0)
{
m_wordCount = word_size/2-1;
m_stateNext = Sync;
fprintf(stderr, "Sync 3\n");
}
else if (m_word != 0xCC)
{
m_wordCount = 0;
m_stateNext = Init;
}
break;
case Sync:
m_wordCount = word_size-1;
case DataFast:
m_wordSize = 8;
out[j++] = m_word;
break;
}
if (m_state != m_stateNext)
{
fprintf(stderr, "State changed\n");
fprintf(stderr, "State changed: %s => %s\n", stateNames[m_state], stateNames[m_stateNext]);
}
m_wordCount = m_wordSize - 1;
m_state = m_stateNext;
}
@@ -155,6 +168,7 @@ int preamble_sync_impl::general_work (int noutput_items, gr_vector_int &ninput_i
// Tell runtime system how many output items we produced.
return j;
}
} /* namespace jay */
+13 -4
View File
@@ -33,16 +33,25 @@ class preamble_sync_impl : public preamble_sync
private:
enum State
{
Init,
Preamble,
Sync
PreambleSlow = 0,
SyncSlow,
DataSlow,
PreambleFast,
SyncFast,
DataFast,
NUM_STATES
};
static const char *stateNames[NUM_STATES];
State m_state;
State m_stateNext;
uint32_t m_word;
size_t m_wordCount;
size_t m_preambleCount;
size_t m_wordSize;
size_t m_dataCount;
public:
preamble_sync_impl();
~preamble_sync_impl();