View Single Post
Old Jan 01, 2013, 10:35 AM
Cesco is offline
Find More Posts by Cesco
Registered User
Cesco's Avatar
Joined Dec 2007
651 Posts
That is my special test version, derived from your code before you added the bind goodie and other stuff. Nothing "flight worthy". I do use a 6 byte packet to test code. I dont mind sharing it, its just to experimental/bad to be intresting.

protocol
// 2 bits rf header seem enough to me
// protocol idea:
// 3 bytes per 2 channel. 9 bit data. 3 bit channel indicator. 12 bits * 2.
// 6 bytes -> 4 channels per message.
// no header. no tail.

// tx decides which channels need update
// determine old-new difference for each channel.
// send channels with biggest difference first.
// send all channels at slow rate, maybe reserve 1 channel data
// for scanning trough all 8 chan, and only send 3 diff channels

I have got the byte stuffing code, but no good / usable channel selection code yet.

RX --------------
{
int rxed[4];
unsigned char rxedno[4];

rxed[0] = rx_buf[0] + ((rx_buf[2] & 0x08) << 5);
rxed[1] = rx_buf[1] + ((rx_buf[2] & 0x80) << 1);
rxed[2] = rx_buf[3] + ((rx_buf[5] & 0x08) << 5);
rxed[3] = rx_buf[4] + ((rx_buf[5] & 0x80) << 1);

rxedno[0] = (rx_buf[2] & 0x07);
rxedno[1] = ((rx_buf[2] >> 4) & 0x07);
rxedno[2] = (rx_buf[5] & 0x07);
rxedno[3] = ((rx_buf[5] >> 4) & 0x07);

cli();
PPM[rxedno[0]]= (rxed[0] << 1);
PPM[rxedno[1]]= (rxed[1] << 1);
PPM[rxedno[2]]= (rxed[2] << 1);
PPM[rxedno[3]]= (rxed[3] << 1);
sei();
}

TX ---------------------------
{
int tosend[4];
unsigned char tosendno[4];
unsigned char i;

for (i=0;i<PPM_CHANNELS;i++) diff[i] = PPM[i] - OldPPM[i];

// sort diff.
actchan = 0;

for (i=0;i<PPM_CHANNELS;i++)
{
if ((diff[i] >= 3) | (diff[i] <= -3))
{
tosendno[actchan] = i;
actchan++;
OldPPM[i] = PPM[i];
}
if (actchan >= 4) exit;
}

cli(); // disable interrupts when copying servo positions, to avoid race on 2 byte variable
tx_buf[0] = (tosend[0] & 0xFF);
tx_buf[1] = (tosend[1] & 0xFF);
tx_buf[2] = ((tosend[0] >> 5) & 0x08) | ((tosend[1] >> 1) & 0x80);
tx_buf[2] |= (tosendno[0] & 0x07) | ((tosendno[1] & 0x07) << 4);
tx_buf[3] = (tosend[2] & 0xFF);
tx_buf[4] = (tosend[3] & 0xFF);
tx_buf[5] = ((tosend[2] >> 5) & 0x08) | ((tosend[3] >> 1) & 0x80);
tx_buf[5] |= (tosendno[2] & 0x07) | ((tosendno[3] & 0x07) << 4);
sei();

}
Cesco is offline Find More Posts by Cesco
Reply With Quote