38,7 → 38,6 |
|
*/ |
|
|
/* |
Connection of DSL to SV1 of FC: |
( DSL Pin1 is on side of channel 4 ) |
96,8 → 95,7 |
uint8_t PacketBuffer[6]; |
//uint8_t Jitter = 0; // same measurement as RC_Quality in rc.c |
|
typedef union |
{ |
typedef union { |
int16_t Servo[2]; |
uint8_t byte[4]; |
} ChannelPair_t; |
104,12 → 102,10 |
|
ChannelPair_t ChannelPair; |
|
|
// This function is called, when a new servo signal is properly received. |
// Parameters: servo - servo number (0-9) |
// signal - servo signal between 7373 (1ms) and 14745 (2ms) |
void dsl_new_signal(uint8_t channel, int16_t signal) |
{ |
void dsl_new_signal(uint8_t channel, int16_t signal) { |
int16_t tmp; |
uint8_t index = channel + 1; // mk channels start with 1 |
|
120,23 → 116,27 |
signal-= 11059; // shift to neutral |
signal/= 24; // scale to mk rc resolution |
|
if(abs(signal-PPM_in[index]) < 6) |
{ |
if(RC_Quality < 200) RC_Quality +=10; |
else RC_Quality = 200; |
if (abs(signal-PPM_in[index]) < 6) { |
if (RC_Quality < 200) |
RC_Quality += 10; |
else |
RC_Quality = 200; |
} |
|
// calculate exponential history for signal |
tmp = (3 * (PPM_in[index]) + signal) / 4; |
if(tmp > signal+1) tmp--; else |
if(tmp < signal-1) tmp++; |
if (tmp > signal + 1) |
tmp--; |
else if (tmp < signal - 1) |
tmp++; |
// calculate signal difference on good signal level |
if(RC_Quality >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for noise reduction |
else PPM_diff[index] = 0; |
if (RC_Quality >= 195) |
PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for noise reduction |
else |
PPM_diff[index] = 0; |
PPM_in[index] = tmp; // update channel value |
|
if(index == 4) |
{ |
if (index == 4) { |
NewPpmData = 0; |
} |
} |
143,13 → 143,11 |
|
// This function is called within dsl_parser(), when a complete |
// data packet with valid checksum has been received. |
void dsl_decode_packet(void) |
{ |
void dsl_decode_packet(void) { |
uint8_t i; |
|
// check for header condition |
if((PacketBuffer[0] & 0xF0) == 0x10) |
{ |
if ((PacketBuffer[0] & 0xF0) == 0x10) { |
if(PacketBuffer[0] == 0x1F) // separate status frame |
{ |
dsl_Allocation = PacketBuffer[1]; // Get frequency allocation |
157,17 → 155,14 |
dsl_RSSI = PacketBuffer[3]; // Get signal quality |
dsl_Battery = PacketBuffer[4]; // Get voltage of battery supply |
// ?? = PacketBuffer[5]; |
if(dsl_RSSI == 0) |
{ |
if (dsl_RSSI == 0) { |
RC_Quality = 0; |
for (i = 0; i<5; i++) |
{ |
for (i = 0; i < 5; i++) { |
PPM_diff[i] = 0; |
PPM_in[i] = 0; |
} |
} |
} |
else // probably a channel pair |
} else // probably a channel pair |
{ |
i = PacketBuffer[0] & 0x0F; // last 4 bits of the header indicates the channel pair |
if(i < 10)// maximum 12 channels |
184,10 → 179,8 |
} // EOF header condition |
} |
|
|
// this function should be called within the UART RX ISR |
void dsl_parser(uint8_t c) |
{ |
void dsl_parser(uint8_t c) { |
static uint8_t last_c = 0; |
static uint8_t crc = 0; |
static uint8_t cnt = 0; |
194,8 → 187,7 |
static uint8_t packet_len = 0; |
|
// check for sync condition |
if ((c==0xFF) && (last_c==0xFF)) |
{ |
if ((c == 0xFF) && (last_c == 0xFF)) { |
cnt = 0; // reset byte counter |
crc = 0; // reset checksum |
return; |
203,21 → 195,24 |
|
if(cnt == 0) // begin of a packet |
{ |
if(c == 0x1F) packet_len = 5; // a status packet has 5 bytes + crc |
else packet_len = 4; // a channel pair packet has 4 bytes + crc |
if (c == 0x1F) |
packet_len = 5; // a status packet has 5 bytes + crc |
else |
packet_len = 4; // a channel pair packet has 4 bytes + crc |
} |
if(cnt > packet_len) // packet complete, crc byte received |
{ |
// calculate checksum |
crc = ~crc; |
if (crc == 0xFF) crc = 0xFE; |
if (crc == 0xFF) |
crc = 0xFE; |
// if crc matches decode the packet |
if (c == crc) dsl_decode_packet(); |
if (c == crc) |
dsl_decode_packet(); |
// handle next packet |
cnt = 0; |
crc = 0; |
} |
else // collect channel data bytes |
} else // collect channel data bytes |
{ |
PacketBuffer[cnt++] = c; |
crc += c; |