Extract some bits.

This commit is contained in:
John Greb 2015-02-09 23:54:51 +00:00
parent d749284821
commit 2d55f3f347
3 changed files with 47 additions and 30 deletions

View File

@ -4,16 +4,25 @@
*/
// Needs adjusting for different sizes
void LoRaDemod::interleave(char* inout)
void LoRaDemod::interleave(char* inout, int size)
{
int i, index = 6;
char in[index * 2];
for (i = 0; i < index; i++)
in[i] = in[i + index] = inout[i];
// top bits are swapped ?
for (i = 0; i < index; i++) {
inout[i] = (32 & in[2 + i]) | (16 & in[1 + i]) | (8 & in[3 + i])
int i, j;
char in[6 * 2];
short s;
for (j = 0; j < size; j+=6) {
for (i = 0; i < 6; i++)
in[i] = in[i + 6] = inout[i + j];
// top bits are swapped
for (i = 0; i < 6; i++) {
s = (32 & in[2 + i]) | (16 & in[1 + i]) | (8 & in[3 + i])
| (4 & in[4 + i]) | (2 & in[5 + i]) | (1 & in[6 + i]);
// bits are also rotated
s = (s << 3) | (s >> 3);
s &= 63;
s = (s >> i) | (s << (6 - i));
inout[i + j] = s & 63;
}
}
}
@ -22,24 +31,32 @@ short LoRaDemod::toGray(short num)
return (num >> 1) ^ num;
}
// ignore FEC, try data in lsb, bigendian
void LoRaDemod::hamming(char* inout, int size)
// ignore FEC, try to extract raw bits
void LoRaDemod::hamming(char* c, 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;
c[i] = ((c[i] & 1)<<3) | ((c[i] & 2)<<0) | ((c[i] & 4)>>0) | ((c[i] & 8)>>3);
i++;
c[i] = ((c[i] & 1)<<2) | ((c[i] & 2)<<2) | ((c[i] & 4)>>1) | ((c[i] & 8)>>3);
i++;
c[i] = ((c[i] & 1)<<3) | ((c[i] & 2)<<1) | ((c[i] & 4)>>1) | ((c[i] & 8)>>3);
i++;
c[i] = ((c[i] & 1)<<3) | ((c[i] & 2)<<1) | ((c[i] & 4)>>1) | ((c[i] & 8)>>3);
i++;
c[i] = ((c[i] & 1)<<3) | ((c[i] & 2)<<1) | ((c[i] & 4)>>1) | ((c[i] & 8)>>3);
i++;
c[i] = ((c[i] & 1)<<3) | ((c[i] & 2)<<1) | ((c[i] & 4)>>2) | ((c[i] & 8)>>2);
}
inout[i] = 0;
c[i] = 0;
}
// example data whitening (4 bit only - needs 6 bit for FEC)
void LoRaDemod::prng(char* inout, int size)
{
const char otp[] = {
"EHFGKHGMGKGMGHG@FKDN@EHBMGBOLFALO@GIBIICJNMDFIDHAHJHMHBBHLHCHLH@IINCAOJFMLF@EKBDIAJKMNBEMBGMBKLMAHOHFHDB@DH@H@HAIKKDKAOKGDBAMIGIBCMLGCFODFAFNLECBLIHKHNBALJA"
"LBMGEJJENKKKJBN@KB@KAEDDMMDONIN@N@KFBGBCMCMCMIBJHBDHNJDJALDHE@A@DFGOBOMIM@M@BBBCBAMBMKDENDLEDKNKNBNHKJ@JADD@EAAADBOCGAGBLCDANFLGDCNGLOMOBIHHMLBHB@BHMJGJBLMLED@B"
};
int i, maxchars;
@ -47,6 +64,6 @@ void LoRaDemod::prng(char* inout, int size)
if (size < maxchars)
maxchars = size;
for (i = 0; i < maxchars; i++)
inout[i] ^= otp[i];
inout[i] ^= 0xf & otp[i];
}

View File

@ -73,27 +73,27 @@ void LoRaDemod::configure(MessageQueue* messageQueue, Real Bandwidth)
void LoRaDemod::dumpRaw()
{
char hex[] = {"0123456789ABCDEFXXXX"};
short bin, j, max;
max = m_time / 4 - 3;
if (max > 80)
max = 80; // 80 symbols is about 40 chars
char text[256];
max = m_time / 4 - 3;
if (max > 100)
max = 100; // about 2 symbols to each char
for ( j=0; j < max; j++) {
bin = (history[j * 4 + 12] + m_tune ) & (LORA_SFFT_LEN - 1);
text[j] = toGray(bin >> 1);
}
for ( j=0; j < max; j+=6)
interleave(&text[j]);
interleave(text, max);
prng(text, max);
hamming(text, max);
for ( j=0; j < max; j++) {
text[j] = hex[ (0xf & text[j]) ];
for ( j=0; j < max / 2; j++) {
text[j] = (text[j * 2 + 2] << 4) | (0xf & text[j * 2 + 1]);
if ((text[j] < 32 )||( text[j] > 126))
text[j] = 0x5f;
}
// for ( j=0; j < max / 2; j++) {
// if ((text[j] < 32 )||( text[j] > 126))
// text[j] = 0x5f;
// }
text[j] = 0;
printf("%s\n", text);
}

View File

@ -44,7 +44,7 @@ public:
private:
int detect(Complex sample, Complex angle);
void interleave(char* inout);
void interleave(char* inout, int size);
void dumpRaw(void);
short synch (short bin);
short toGray(short bin);