用法 : bleWhiten(pdu,adv_dataLen,bleWhitenStart(38));
在github 上找的,原理不清楚。
白化数据一调用,变成非白化数据。
非白化数据一调用,就变成白化数据
uint8_t swapBits(uint8_t a)
{
uint8_t v = 0;
if (a & 0x80)
v |= 0x01;
if (a & 0x40)
v |= 0x02;
if (a & 0x20)
v |= 0x04;
if (a & 0x10)
v |= 0x08;
if (a & 0x08)
v |= 0x10;
if (a & 0x04)
v |= 0x20;
if (a & 0x02)
v |= 0x40;
if (a & 0x01)
v |= 0x80;
return v;
}
/**
* @brief Implements whitening with LFSR
* @note
* @param data: location of the data to be whiten
* len: data length
* whitenCoeff: whitening coefficient
* 它是一种7位线性移位反馈样式,并通过等于(channelNum << 1)+ 1的值进行初始化
* @retval
*/
void bleWhiten(uint8_t *data, uint8_t len, uint8_t whitenCoeff)
{
uint8_t m;
while (len--)
{
for (m = 1; m; m <<= 1)
{
if (whitenCoeff & 0x80)
{
whitenCoeff ^= 0x11;
(*data) ^= m;
}
whitenCoeff <<= 1;
}
printf("0x%x \n ", *data);
data++;
}
}