- added
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@887 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// --------------------------------------------------------------
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <crc/crc.h>
|
||||
#include <radio/symbol.h>
|
||||
#include "Scrambler.hpp"
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Scrambler
|
||||
// --------------------------------------------------------------
|
||||
Scrambler::Scrambler(uint32_t state, uint32_t poly)
|
||||
: m_state(state)
|
||||
, m_poly(poly)
|
||||
{
|
||||
}
|
||||
|
||||
Scrambler::~Scrambler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
uint32_t Scrambler::stateGet()
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
void Scrambler::stateSet(uint32_t state)
|
||||
{
|
||||
m_state = state;
|
||||
}
|
||||
|
||||
uint8_t Scrambler::process(uint8_t src)
|
||||
{
|
||||
uint32_t i;
|
||||
uint8_t res;
|
||||
|
||||
res = (uint8_t)(src ^ m_state);
|
||||
|
||||
for (i=0; i < 8; i++)
|
||||
{
|
||||
if (m_state & 0x0001)
|
||||
{
|
||||
m_state = (m_state >> 1) ^ m_poly;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_state = (m_state >> 1);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void Scrambler::process(uint8_t *pSrcDst, uint32_t len)
|
||||
{
|
||||
while(len--)
|
||||
{
|
||||
*pSrcDst = process(*pSrcDst);
|
||||
pSrcDst++;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
Reference in New Issue
Block a user