Add bit unstuffing algorithm.

For use in AIS. Probably useful elsewhere, too...
This commit is contained in:
Jared Boone 2015-09-26 14:14:39 -07:00
parent 31ff13f1c0
commit c936e09702

View File

@ -23,6 +23,7 @@
#define __SYMBOL_CODING_H__
#include <cstdint>
#include <cstddef>
namespace symbol_coding {
@ -38,6 +39,32 @@ private:
uint_fast8_t last { 0 };
};
class Unstuff {
public:
uint_fast8_t is_stuffing_bit(const uint_fast8_t symbol) {
history = (history << 1) | (symbol & 1);
return (history & mask) == match;
}
void configure(
const uint32_t pattern,
const size_t length
) {
match = pattern;
mask = (1U << length) - 1;
reset();
}
void reset() {
history = 0;
}
private:
uint32_t history { 0 };
uint32_t match { 0b111110 };
uint32_t mask { 0b111111 };
};
} /* namespace symbol_coding */
#endif/*__SYMBOL_CODING_H__*/