Send channels to TX via telemetry

This commit is contained in:
Goebish 2019-10-01 18:30:44 +02:00
parent 1beaf738e4
commit c55edf11dc
2 changed files with 41 additions and 12 deletions

View File

@ -32,7 +32,31 @@ enum {
static void __attribute__((unused)) AFHDS2A_Rx_build_telemetry_packet() static void __attribute__((unused)) AFHDS2A_Rx_build_telemetry_packet()
{ {
uint32_t bits = 0;
uint8_t bitsavailable = 0;
uint8_t idx = 0;
pkt[idx++] = RX_LQI; // 0 - 130
pkt[idx++] = RX_RSSI;
pkt[idx++] = 0; // start channel
pkt[idx++] = 14; // number of channels in packet
// pack channels
for (uint8_t i = 0; i < 16; i++) {
uint16_t val = packet[9+i*2] | (packet[10+i*2] << 8);
if (val < 860)
val = 860;
else if (val > 2140)
val = 2140;
val -= 860;
bits |= val << bitsavailable;
bitsavailable += 11;
while (bitsavailable >= 8) {
pkt[idx++] = bits & 0xff;
bits >>= 8;
bitsavailable -= 8;
}
}
} }
static uint8_t __attribute__((unused)) AFHDS2A_Rx_data_ready() static uint8_t __attribute__((unused)) AFHDS2A_Rx_data_ready()
@ -132,7 +156,7 @@ uint16_t AFHDS2A_Rx_callback()
case AFHDS2A_RX_BIND2 | AFHDS2A_RX_WAIT_WRITE: case AFHDS2A_RX_BIND2 | AFHDS2A_RX_WAIT_WRITE:
//Wait for TX completion //Wait for TX completion
pps_timer = micros(); pps_timer = micros();
while (micros() - pps_timer < 700) // Wait max 700µs, using serial+telemetry exit in about 120µs while (micros() - pps_timer < 700) // Wait max 700µs, using serial+telemetry exit in about 120µs
if (!(A7105_ReadReg(A7105_00_MODE) & 0x01)) if (!(A7105_ReadReg(A7105_00_MODE) & 0x01))
break; break;
A7105_Strobe(A7105_RX); A7105_Strobe(A7105_RX);
@ -158,7 +182,7 @@ uint16_t AFHDS2A_Rx_callback()
if (millis() - pps_timer >= 1000) { if (millis() - pps_timer >= 1000) {
pps_timer = millis(); pps_timer = millis();
debugln("%ld pps", pps_counter); debugln("%ld pps", pps_counter);
RX_LQI = pps_counter; RX_LQI = pps_counter / 2;
pps_counter = 0; pps_counter = 0;
} }
@ -167,12 +191,12 @@ uint16_t AFHDS2A_Rx_callback()
hopping_frequency_no++; hopping_frequency_no++;
if(hopping_frequency_no >= AFHDS2A_RX_NUMFREQ) if(hopping_frequency_no >= AFHDS2A_RX_NUMFREQ)
hopping_frequency_no = 0; hopping_frequency_no = 0;
A7105_WriteReg(A7105_0F_PLL_I, hopping_frequency[hopping_frequency_no]); // bind channels A7105_WriteReg(A7105_0F_PLL_I, hopping_frequency[hopping_frequency_no]);
A7105_Strobe(A7105_RX); A7105_Strobe(A7105_RX);
if (afhds2a_rx_data_started) if (afhds2a_rx_data_started)
read_retry = 0; read_retry = 0;
else else
read_retry = -50; // retry longer until first packet is catched read_retry = -127; // retry longer until first packet is catched
} }
return 385; return 385;
} }

View File

@ -184,16 +184,21 @@ static void multi_send_status()
} }
#endif #endif
#ifdef FRSKYX_RX_TELEMETRY #if defined (FRSKYX_RX_TELEMETRY) || defined (AFHDS2A_RX_TELEMETRY)
void frskyx_rx_channels_frame() void receiver_channels_frame()
{ {
uint16_t len = pkt[3] * 11; // 11 bit per channel
if (len % 8 == 0)
len = 4 + (len / 8);
else
len = 5 + (len / 8);
#if defined MULTI_TELEMETRY #if defined MULTI_TELEMETRY
multi_send_header(MULTI_TELEMETRY_RX_CHANNELS, 26); multi_send_header(MULTI_TELEMETRY_RX_CHANNELS, len);
#else #else
Serial_write(0xAA); // Telemetry packet Serial_write(0xAA); // Telemetry packet
#endif #endif
for (uint8_t i = 0; i < 26; i++) for (uint8_t i = 0; i < len; i++)
Serial_write(pkt[i]); // pps, rssi, ch start, ch count, 16x ch data Serial_write(pkt[i]); // pps, rssi, ch start, ch count, packed ch data
} }
#endif #endif
@ -1032,10 +1037,10 @@ void TelemetryUpdate()
} }
#endif #endif
#if defined FRSKYX_RX_TELEMETRY #if defined (FRSKYX_RX_TELEMETRY) || defined(AFHDS2A_RX_TELEMETRY)
if (telemetry_link && protocol == PROTO_FRSKYX_RX) if (telemetry_link && (protocol == PROTO_FRSKYX_RX || protocol == PROTO_AFHDS2A_RX))
{ {
frskyx_rx_channels_frame(); receiver_channels_frame();
telemetry_link = 0; telemetry_link = 0;
return; return;
} }