mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-13 11:44:31 +00:00
Add bit unstuffing algorithm.
For use in AIS. Probably useful elsewhere, too...
This commit is contained in:
parent
31ff13f1c0
commit
c936e09702
@ -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__*/
|
||||
|
Loading…
Reference in New Issue
Block a user