1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-12 16:16:35 -04:00
sdrangel/plugins/channel/lora/lorabits.h

53 lines
1.3 KiB
C
Raw Normal View History

2015-01-17 10:59:44 -05:00
/*
Interleaving is "easiest" if the same number of bits is used per symbol as for FEC
Chosen mode "spreading 8, low rate" has 6 bits per symbol, so use 4:6 FEC
*/
// Needs adjusting for different sizes
2015-01-31 18:41:06 -05:00
void LoRaDemod::interleave(char* inout)
2015-01-17 10:59:44 -05:00
{
int i, index = 6;
2015-01-31 18:41:06 -05:00
char in[index * 2];
2015-01-17 10:59:44 -05:00
for (i = 0; i < index; i++)
2015-02-06 13:59:35 -05:00
in[i] = in[i + index] = inout[i];
2015-01-31 18:41:06 -05:00
// top bits are swapped ?
2015-01-17 10:59:44 -05:00
for (i = 0; i < index; i++) {
2015-02-06 13:59:35 -05:00
inout[i] = (32 & in[2 + i]) | (16 & in[1 + i]) | (8 & in[3 + i])
| (4 & in[4 + i]) | (2 & in[5 + i]) | (1 & in[6 + i]);
2015-01-17 10:59:44 -05:00
}
}
2015-01-22 17:30:55 -05:00
short LoRaDemod::toGray(short num)
2015-01-17 10:59:44 -05:00
{
2015-01-22 17:30:55 -05:00
return (num >> 1) ^ num;
2015-01-17 10:59:44 -05:00
}
2015-02-07 05:03:51 -05:00
// ignore FEC, try data in lsb, bigendian
2015-02-05 14:38:46 -05:00
void LoRaDemod::hamming(char* inout, int size)
{
int i;
char c;
for (i = 0; i < size; i++) {
c = inout[i];
c = ((c&1)<<3) | ((c&2)<<1) | ((c&4)>>1) | ((c&8)>>3);
inout[i] = c;
}
inout[i] = 0;
}
2015-02-07 05:03:51 -05:00
// example data whitening (4 bit only - needs 6 bit for FEC)
2015-02-05 14:38:46 -05:00
void LoRaDemod::prng(char* inout, int size)
{
const char otp[] = {
2015-02-07 05:03:51 -05:00
"EHFGKHGMGKGMGHG@FKDN@EHBMGBOLFALO@GIBIICJNMDFIDHAHJHMHBBHLHCHLH@IINCAOJFMLF@EKBDIAJKMNBEMBGMBKLMAHOHFHDB@DH@H@HAIKKDKAOKGDBAMIGIBCMLGCFODFAFNLECBLIHKHNBALJA"
2015-02-05 14:38:46 -05:00
};
int i, maxchars;
maxchars = sizeof( otp );
if (size < maxchars)
maxchars = size;
for (i = 0; i < maxchars; i++)
2015-02-07 05:03:51 -05:00
inout[i] ^= otp[i];
2015-02-05 14:38:46 -05:00
}