diff --git a/Multiprotocol/AFHDS2A_Rx_a7105.ino b/Multiprotocol/AFHDS2A_Rx_a7105.ino index dd2ec1d..cf356cf 100644 --- a/Multiprotocol/AFHDS2A_Rx_a7105.ino +++ b/Multiprotocol/AFHDS2A_Rx_a7105.ino @@ -32,7 +32,31 @@ enum { 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() @@ -132,7 +156,7 @@ uint16_t AFHDS2A_Rx_callback() case AFHDS2A_RX_BIND2 | AFHDS2A_RX_WAIT_WRITE: //Wait for TX completion 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)) break; A7105_Strobe(A7105_RX); @@ -158,7 +182,7 @@ uint16_t AFHDS2A_Rx_callback() if (millis() - pps_timer >= 1000) { pps_timer = millis(); debugln("%ld pps", pps_counter); - RX_LQI = pps_counter; + RX_LQI = pps_counter / 2; pps_counter = 0; } @@ -167,12 +191,12 @@ uint16_t AFHDS2A_Rx_callback() hopping_frequency_no++; if(hopping_frequency_no >= AFHDS2A_RX_NUMFREQ) 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); if (afhds2a_rx_data_started) read_retry = 0; else - read_retry = -50; // retry longer until first packet is catched + read_retry = -127; // retry longer until first packet is catched } return 385; } diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index da0b08c..40e83d7 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -184,16 +184,21 @@ static void multi_send_status() } #endif -#ifdef FRSKYX_RX_TELEMETRY - void frskyx_rx_channels_frame() +#if defined (FRSKYX_RX_TELEMETRY) || defined (AFHDS2A_RX_TELEMETRY) + 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 - multi_send_header(MULTI_TELEMETRY_RX_CHANNELS, 26); + multi_send_header(MULTI_TELEMETRY_RX_CHANNELS, len); #else Serial_write(0xAA); // Telemetry packet #endif - for (uint8_t i = 0; i < 26; i++) - Serial_write(pkt[i]); // pps, rssi, ch start, ch count, 16x ch data + for (uint8_t i = 0; i < len; i++) + Serial_write(pkt[i]); // pps, rssi, ch start, ch count, packed ch data } #endif @@ -1032,10 +1037,10 @@ void TelemetryUpdate() } #endif - #if defined FRSKYX_RX_TELEMETRY - if (telemetry_link && protocol == PROTO_FRSKYX_RX) + #if defined (FRSKYX_RX_TELEMETRY) || defined(AFHDS2A_RX_TELEMETRY) + if (telemetry_link && (protocol == PROTO_FRSKYX_RX || protocol == PROTO_AFHDS2A_RX)) { - frskyx_rx_channels_frame(); + receiver_channels_frame(); telemetry_link = 0; return; }