addr = (b[0]>>3) & 0x0f;
val = ((b[0] & 0x07)<<8) | b[1];
...
for (i = 0; i < 7; i++) {
uint8_t *b = &buf[2 + i*2];
// empty channel
if (b[0] == 0xff && b[1] == 0xff)
continue;
// X-Plus channel - check if first or second data package (MSB only TRUE in channel 0!)
if (((b[0] & 0x80)>>7) == 1)
packetid = 1; // Channel 12 contains X-Plus channels X+5 to X+8 when transmitted in second package
addr = (b[0]>>3) & 0x0f;
val = ((b[0] & 0x07)<<8) | b[1];
// throttle
if (addr == (int)p[RADIO_THRO_CH])
val -= 338;
else
val -= 1024;
// X-Plus channel decoding
if (addr == 12) {
// check in which packed X-Plus channel was transmitted
if (packetid == 1) { // X-Plus channels X+5 to X+8
addr = ((b[0]>>1) & 0x03) + 14;
val = ((((b[0] & 0x01)<<8) | b[1]) *2 ) - 512;
// correction for +/- range swing and interpolation
// clear data package marker
packetid = 0;
}
else { // X-Plus channels X+1 to X+4
addr = ((b[0]>>1) & 0x03);
if (addr == 0 || addr == 1)
continue; // X+1 and X+2 are duplicates of channel 10 and 11
// skip these channels due to lower resolution of
// X-Plus channels
else {
addr += 10;
val = ((((b[0] & 0x01)<<8) | b[1]) *2 ) - 512;
// correction for +/- range swing and interpolation
}
}
}
r->channels[addr] = val;
...