kopia lustrzana https://github.com/mobilinkd/m17-cxx-demod
Initial BER sync recovery.
rodzic
7efe2e0c1b
commit
72a6b6b3c2
|
@ -328,6 +328,9 @@ struct PRBS9
|
|||
uint8_t sync_count = 0;
|
||||
uint32_t bit_count = 0;
|
||||
uint32_t err_count = 0;
|
||||
std::array<uint8_t, 16> history;
|
||||
size_t hist_count = 0;
|
||||
size_t hist_pos = 0;
|
||||
|
||||
// PRBS generator.
|
||||
bool operator()()
|
||||
|
@ -352,6 +355,23 @@ struct PRBS9
|
|||
synced = true;
|
||||
err_count = 0;
|
||||
bit_count = LOCK_COUNT;
|
||||
history.fill(0);
|
||||
hist_count = 0;
|
||||
hist_pos = 0;
|
||||
sync_count = 0;
|
||||
}
|
||||
}
|
||||
} else if (hist_count > 25) {
|
||||
result = (bit ^ (state >> TAP_1) ^ (state >> TAP_2)) & 1;
|
||||
state = ((state << 1) | bit) & MASK;
|
||||
if (result) {
|
||||
sync_count = 0;
|
||||
} else {
|
||||
if (++sync_count == LOCK_COUNT) {
|
||||
history.fill(0);
|
||||
hist_count = 0;
|
||||
hist_pos = 0;
|
||||
sync_count = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -360,7 +380,15 @@ struct PRBS9
|
|||
state = ((state << 1) | result) & MASK;
|
||||
|
||||
bit_count += 1;
|
||||
err_count += (result != bit);
|
||||
hist_count -= (history[hist_pos >> 3] & (1 << (hist_pos & 7))) != 0;
|
||||
if (result != bit) {
|
||||
err_count += 1;
|
||||
hist_count += 1;
|
||||
history[hist_pos >> 3] |= (1 << (hist_pos & 7));
|
||||
} else {
|
||||
history[hist_pos >> 3] &= ~(1 << (hist_pos & 7));
|
||||
}
|
||||
if (++hist_pos == 128) hist_pos = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -378,6 +406,9 @@ struct PRBS9
|
|||
sync_count = 0;
|
||||
bit_count = 0;
|
||||
err_count = 0;
|
||||
history.fill(0);
|
||||
hist_count = 0;
|
||||
hist_pos = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -217,18 +217,32 @@ TEST_F(UtilTest, PRBS9)
|
|||
}
|
||||
}
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
TEST_F(UtilTest, PRBS9_FULL)
|
||||
{
|
||||
mobilinkd::PRBS9 prbs_generator;
|
||||
mobilinkd::PRBS9 prbs_validator;
|
||||
|
||||
uint16_t byte = 0;
|
||||
uint16_t bits = 0;
|
||||
for (size_t i = 0; i != 1000; ++i) {
|
||||
bool n = prbs_generator();
|
||||
byte <<= 1;
|
||||
byte |= n;
|
||||
if (++bits == 8) {
|
||||
std::cout << std::hex << std::setw(2) << byte << " ";
|
||||
byte = 0;
|
||||
bits = 0;
|
||||
}
|
||||
|
||||
if (i == 499) n = !n;
|
||||
else if (i == 510) n = !n;
|
||||
prbs_validator(n);
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
ASSERT_TRUE(prbs_validator.sync());
|
||||
EXPECT_EQ(prbs_validator.bits(), 1000);
|
||||
EXPECT_EQ(prbs_validator.errors(), 2);
|
||||
|
|
Ładowanie…
Reference in New Issue