another attempt
This commit is contained in:
No files matched your search
+13
-4
@@ -57,6 +57,15 @@ static uint32_t read_word(const uint8_t *input, const size_t bit_offset, const b
|
||||
return invert ? ~word : word;
|
||||
}
|
||||
|
||||
// Sync codeword match with up to POCSAG_SYNC_MAX_ERRORS wrong bits (like multimon-ng);
|
||||
// an exact match loses the whole batch on a single bit error.
|
||||
#define POCSAG_SYNC_MAX_ERRORS 2U
|
||||
|
||||
static unsigned sync_errors(const uint32_t word)
|
||||
{
|
||||
return (unsigned)__builtin_popcountl(word ^ POCSAG_SYNC_WORD);
|
||||
}
|
||||
|
||||
static bool is_valid_codeword(const uint32_t word)
|
||||
{
|
||||
return make_codeword(word >> 11) == word;
|
||||
@@ -109,7 +118,7 @@ static bool decode_after_address(const uint8_t *input, const size_t input_bits,
|
||||
uint32_t codeword = read_word(input, position, invert);
|
||||
|
||||
// Messages may continue across a batch boundary.
|
||||
if (codeword == POCSAG_SYNC_WORD)
|
||||
if (sync_errors(codeword) <= POCSAG_SYNC_MAX_ERRORS)
|
||||
continue;
|
||||
|
||||
// Idle or a new address codeword ends the message.
|
||||
@@ -213,12 +222,12 @@ bool POCSAG_Decode(const uint8_t *input, const size_t input_size, const uint32_t
|
||||
|
||||
message[0] = '\0';
|
||||
for (size_t bit = 0; bit + 32U <= input_bits; bit++) {
|
||||
const uint32_t word = read_word(input, bit, false);
|
||||
const unsigned errors = sync_errors(read_word(input, bit, false));
|
||||
bool invert;
|
||||
|
||||
if (word == POCSAG_SYNC_WORD)
|
||||
if (errors <= POCSAG_SYNC_MAX_ERRORS)
|
||||
invert = false;
|
||||
else if (word == (uint32_t)~POCSAG_SYNC_WORD)
|
||||
else if (32U - errors <= POCSAG_SYNC_MAX_ERRORS)
|
||||
invert = true;
|
||||
else
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user