1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Race and STD telemetry modes

This commit is contained in:
phobos- 2022-08-01 09:47:16 +02:00
parent e45afb3a76
commit 63e7ccbc9a
3 changed files with 32 additions and 50 deletions

View file

@ -76,7 +76,7 @@ static uint8_t bindingRateIndex = 0;
static bool connectionHasModelMatch = false;
static uint8_t txPower = 0;
static uint8_t wideSwitchIndex = 0;
static uint8_t currTlmDenom = 1;
static simpleLowpassFilter_t rssiFilter;
static volatile DMA_DATA uint8_t dmaBuffer[ELRS_RX_TX_BUFF_SIZE];
@ -280,7 +280,7 @@ static void unpackChannelDataHybridWide(uint16_t *rcData, const uint8_t *payload
} else {
uint8_t bins;
uint16_t switchValue;
if (tlmRatioEnumToValue(receiver.modParams->tlmInterval) < 8) {
if (currTlmDenom < 8) {
bins = 63;
switchValue = switchByte & 0x3F; // 6-bit
} else {
@ -377,8 +377,8 @@ bool expressLrsIsFhssReq(void)
bool expressLrsTelemRespReq(void)
{
uint8_t modresult = (receiver.nonceRX + 1) % tlmRatioEnumToValue(receiver.modParams->tlmInterval);
if (receiver.inBindingMode || (receiver.connectionState == ELRS_DISCONNECTED) || (receiver.modParams->tlmInterval == TLM_RATIO_NO_TLM) || (modresult != 0)) {
uint8_t modresult = (receiver.nonceRX + 1) % currTlmDenom;
if (receiver.inBindingMode || (receiver.connectionState == ELRS_DISCONNECTED) || (currTlmDenom == 1) || (modresult != 0)) {
return false; // don't bother sending tlm if disconnected or TLM is off
} else {
return true;
@ -662,9 +662,8 @@ static bool processRFSyncPacket(volatile uint8_t *packet, const uint32_t timeSta
receiver.lastSyncPacketMs = timeStampMs;
// Will change the packet air rate in loop() if this changes
receiver.nextRateIndex = (packet[3] & 0xC0) >> 6;
uint8_t tlmRateIn = (packet[3] & 0x38) >> 3;
uint8_t switchEncMode = ((packet[3] & 0x06) >> 1) - 1; //spi implementation uses 0 based index for hybrid
receiver.nextRateIndex = ((packet[3] & 0xE0) >> 5) - 3;
uint8_t switchEncMode = ((packet[3] & 0x03) >> 0) - 1; //spi implementation uses 0 based index for hybrid
// Update switch mode encoding immediately
if (switchEncMode != rxExpressLrsSpiConfig()->switchMode) {
@ -673,8 +672,10 @@ static bool processRFSyncPacket(volatile uint8_t *packet, const uint32_t timeSta
}
// Update TLM ratio
if (receiver.modParams->tlmInterval != tlmRateIn) {
receiver.modParams->tlmInterval = tlmRateIn;
uint8_t tlmRateIn = ((packet[3] & 0x1C) >> 2) + TLM_RATIO_NO_TLM;
uint8_t tlmDenom = tlmRatioEnumToValue(tlmRateIn);
if (currTlmDenom != tlmDenom) {
currTlmDenom = tlmDenom;
telemBurstValid = false;
}
@ -730,7 +731,7 @@ rx_spi_received_e processRFPacket(volatile uint8_t *payload, uint32_t timeStampU
if (receiver.connectionState == ELRS_CONNECTED && connectionHasModelMatch) {
if (rxExpressLrsSpiConfig()->switchMode == SM_HYBRID_WIDE) {
wideSwitchIndex = hybridWideNonceToSwitchIndex(receiver.nonceRX);
if ((tlmRatioEnumToValue(receiver.modParams->tlmInterval) < 8) || wideSwitchIndex == 7) {
if ((currTlmDenom < 8) || wideSwitchIndex == 7) {
confirmCurrentTelemetryPayload((dmaBuffer[6] & 0x40) >> 6);
}
} else {
@ -776,8 +777,7 @@ static void updateTelemetryBurst(void)
telemBurstValid = true;
uint32_t hz = rateEnumToHz(receiver.modParams->enumRate);
uint32_t ratiodiv = tlmRatioEnumToValue(receiver.modParams->tlmInterval);
telemetryBurstMax = TELEM_MIN_LINK_INTERVAL * hz / ratiodiv / 1000U;
telemetryBurstMax = TELEM_MIN_LINK_INTERVAL * hz / currTlmDenom / 1000U;
// Reserve one slot for LINK telemetry
if (telemetryBurstMax > 1) {
@ -787,7 +787,7 @@ static void updateTelemetryBurst(void)
}
// Notify the sender to adjust its expected throughput
updateTelemetryRate(hz, ratiodiv, telemetryBurstMax);
updateTelemetryRate(hz, currTlmDenom, telemetryBurstMax);
}
/* If not connected will rotate through the RF modes looking for sync

View file

@ -56,8 +56,8 @@ elrsModSettings_t airRateConfig[][ELRS_RATE_MAX] = {
{
{0, RATE_200HZ, SX127x_BW_500_00_KHZ, SX127x_SF_6, SX127x_CR_4_7, 5000, TLM_RATIO_1_64, 4, 8},
{1, RATE_100HZ, SX127x_BW_500_00_KHZ, SX127x_SF_7, SX127x_CR_4_7, 10000, TLM_RATIO_1_64, 4, 8},
{2, RATE_50HZ, SX127x_BW_500_00_KHZ, SX127x_SF_8, SX127x_CR_4_7, 20000, TLM_RATIO_NO_TLM, 4, 10},
{3, RATE_25HZ, SX127x_BW_500_00_KHZ, SX127x_SF_9, SX127x_CR_4_7, 40000, TLM_RATIO_NO_TLM, 2, 10}
{2, RATE_50HZ, SX127x_BW_500_00_KHZ, SX127x_SF_8, SX127x_CR_4_7, 20000, TLM_RATIO_1_16, 4, 10},
{3, RATE_25HZ, SX127x_BW_500_00_KHZ, SX127x_SF_9, SX127x_CR_4_7, 40000, TLM_RATIO_1_8, 2, 10}
},
#endif
#ifdef USE_RX_SX1280
@ -65,7 +65,7 @@ elrsModSettings_t airRateConfig[][ELRS_RATE_MAX] = {
{0, RATE_500HZ, SX1280_LORA_BW_0800, SX1280_LORA_SF5, SX1280_LORA_CR_LI_4_6, 2000, TLM_RATIO_1_128, 4, 12},
{1, RATE_250HZ, SX1280_LORA_BW_0800, SX1280_LORA_SF6, SX1280_LORA_CR_LI_4_7, 4000, TLM_RATIO_1_64, 4, 14},
{2, RATE_150HZ, SX1280_LORA_BW_0800, SX1280_LORA_SF7, SX1280_LORA_CR_LI_4_7, 6666, TLM_RATIO_1_32, 4, 12},
{3, RATE_50HZ, SX1280_LORA_BW_0800, SX1280_LORA_SF9, SX1280_LORA_CR_LI_4_6, 20000, TLM_RATIO_NO_TLM, 2, 12}
{3, RATE_50HZ, SX1280_LORA_BW_0800, SX1280_LORA_SF9, SX1280_LORA_CR_LI_4_6, 20000, TLM_RATIO_1_16, 2, 12}
},
#endif
#if !defined(USE_RX_SX127X) && !defined(USE_RX_SX1280)
@ -472,34 +472,14 @@ void fhssGenSequence(const uint8_t UID[], const elrsFreqDomain_e dom)
uint8_t tlmRatioEnumToValue(const elrsTlmRatio_e enumval)
{
switch (enumval) {
case TLM_RATIO_NO_TLM:
// !! TLM_RATIO_STD/TLM_RATIO_DISARMED should be converted by the caller !!
if (enumval == TLM_RATIO_NO_TLM) {
return 1;
break;
case TLM_RATIO_1_2:
return 2;
break;
case TLM_RATIO_1_4:
return 4;
break;
case TLM_RATIO_1_8:
return 8;
break;
case TLM_RATIO_1_16:
return 16;
break;
case TLM_RATIO_1_32:
return 32;
break;
case TLM_RATIO_1_64:
return 64;
break;
case TLM_RATIO_1_128:
return 128;
break;
default:
return 0;
}
// 1 << (8 - (enumval - TLM_RATIO_NO_TLM))
// 1_128 = 128, 1_64 = 64, 1_32 = 32, etc
return 1 << (8 + TLM_RATIO_NO_TLM - enumval);
}
uint16_t rateEnumToHz(const elrsRfRate_e eRate)

View file

@ -86,14 +86,16 @@ typedef enum {
} elrsSwitchMode_e;
typedef enum {
TLM_RATIO_NO_TLM = 0,
TLM_RATIO_1_128 = 1,
TLM_RATIO_1_64 = 2,
TLM_RATIO_1_32 = 3,
TLM_RATIO_1_16 = 4,
TLM_RATIO_1_8 = 5,
TLM_RATIO_1_4 = 6,
TLM_RATIO_1_2 = 7,
TLM_RATIO_STD = 0, // Use suggested ratio from ModParams
TLM_RATIO_NO_TLM,
TLM_RATIO_1_128,
TLM_RATIO_1_64,
TLM_RATIO_1_32,
TLM_RATIO_1_16,
TLM_RATIO_1_8,
TLM_RATIO_1_4,
TLM_RATIO_1_2,
TLM_RATIO_DISARMED, // TLM_RATIO_STD when disarmed, TLM_RATIO_NO_TLM when armed
} elrsTlmRatio_e;
typedef enum {