Skip to content

Commit 29b77d3

Browse files
authored
Rotate the sync slot through all the FHSS slots (ExpressLRS#825)
* Rotate sync slot and don't send if healthy connection - Rotates the sync through each of the slots in the sync FHSS channel, up to 2x per slot - If connected and LQ is >75, don't bother sync at all - Reduces SyncSpam after rate change to 500ms * Remove the downlink LQ LPF * Remove unused connectionState_e and renumber - Saves flash to have connected be 0 * Can't skip sync if TLM ratio doesn't match * Remove skipSync for now
1 parent 83ee7f1 commit 29b77d3

3 files changed

Lines changed: 28 additions & 31 deletions

File tree

src/src/common.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ expresslrs_rf_pref_params_s ExpressLRS_AirRateRFperf[RATE_MAX] = {
1515
{0, RATE_200HZ, -112, 4380, 3000, 2500, 600, 5000},
1616
{1, RATE_100HZ, -117, 8770, 3500, 2500, 600, 5000},
1717
{2, RATE_50HZ, -120, 17540, 4000, 2500, 600, 5000},
18-
{3, RATE_25HZ, -123, 17540, 6000, 4000, 0, 5000}};
18+
{3, RATE_25HZ, -123, 17540, 6000, 4000, 30, 5000}};
1919
#endif
2020

2121
#if defined(Regulatory_Domain_ISM_2400)
@@ -30,10 +30,10 @@ expresslrs_mod_settings_s ExpressLRS_AirRateConfig[RATE_MAX] = {
3030
{3, RATE_50HZ, SX1280_LORA_BW_0800, SX1280_LORA_SF9, SX1280_LORA_CR_LI_4_6, 20000, TLM_RATIO_NO_TLM, 4, 12, 8}};
3131

3232
expresslrs_rf_pref_params_s ExpressLRS_AirRateRFperf[RATE_MAX] = {
33-
{0, RATE_500HZ, -105, 1665, 2500, 2500, 0, 5000},
34-
{1, RATE_250HZ, -108, 3300, 3000, 2500, 0, 5000},
35-
{2, RATE_150HZ, -112, 5871, 3500, 2500, 0, 5000},
36-
{3, RATE_50HZ, -117, 18443, 4000, 2500, 0, 5000}};
33+
{0, RATE_500HZ, -105, 1665, 2500, 2500, 3, 5000},
34+
{1, RATE_250HZ, -108, 3300, 3000, 2500, 6, 5000},
35+
{2, RATE_150HZ, -112, 5871, 3500, 2500, 10, 5000},
36+
{3, RATE_50HZ, -117, 18443, 4000, 2500, 30, 5000}};
3737
#endif
3838

3939
expresslrs_mod_settings_s *get_elrs_airRateConfig(int8_t index);

src/src/common.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ typedef enum
3434

3535
typedef enum
3636
{
37-
bad_sync_retry = 4,
38-
bad_sync = 3,
39-
connected = 2,
40-
tentative = 1,
41-
disconnected = 0
37+
connected,
38+
tentative,
39+
disconnected
4240
} connectionState_e;
4341

4442
typedef enum

src/src/tx_main.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ SX1280Driver Radio;
2525
#include "config.h"
2626
#include "hwTimer.h"
2727
#include "LQCALC.h"
28-
#include "LowPassFilter.h"
2928
#include "telemetry_protocol.h"
3029
#include "stubborn_receiver.h"
3130
#include "stubborn_sender.h"
@@ -81,19 +80,17 @@ bool NextPacketIsMspData = false; // if true the next packet will contain the m
8180

8281
////////////SYNC PACKET/////////
8382
/// sync packet spamming on mode change vars ///
84-
#define syncSpamAResidualTimeMS 1500 // we spam some more after rate change to help link get up to speed
83+
#define syncSpamAResidualTimeMS 500 // we spam some more after rate change to help link get up to speed
8584
#define syncSpamAmount 3
8685
volatile uint8_t syncSpamCounter = 0;
8786
uint32_t rfModeLastChangedMS = 0;
88-
////////////////////////////////////////////////
89-
9087
uint32_t SyncPacketLastSent = 0;
88+
////////////////////////////////////////////////
9189

9290
volatile uint32_t LastTLMpacketRecvMillis = 0;
9391
uint32_t TLMpacketReported = 0;
9492

9593
LQCALC<10> LQCalc;
96-
LPF LPD_DownlinkLQ(1);
9794

9895
volatile bool busyTransmitting;
9996
volatile bool UpdateModelReq = false;
@@ -248,7 +245,6 @@ void ICACHE_RAM_ATTR ProcessTLMpacket()
248245
if (connectionState != connected)
249246
{
250247
connectionState = connected;
251-
LPD_DownlinkLQ.init(100);
252248
VtxConfigReadyToSend = true;
253249
DBGLN("got downlink conn");
254250
}
@@ -270,7 +266,7 @@ void ICACHE_RAM_ATTR ProcessTLMpacket()
270266
//crsf.LinkStatistics.uplink_TX_Power = POWERMGNT.powerToCrsfPower(POWERMGNT.currPower()); // TX power is updated when sent
271267
crsf.LinkStatistics.downlink_SNR = Radio.LastPacketSNR;
272268
crsf.LinkStatistics.downlink_RSSI = Radio.LastPacketRSSI;
273-
crsf.LinkStatistics.downlink_Link_quality = LPD_DownlinkLQ.update(LQCalc.getLQ()) + 1; // +1 fixes rounding issues with filter and makes it consistent with RX LQ Calculation
269+
crsf.LinkStatistics.downlink_Link_quality = LQCalc.getLQ();
274270
crsf.LinkStatistics.rf_Mode = (uint8_t)RATE_4HZ - (uint8_t)ExpressLRS_currAirRate_Modparams->enum_rate;
275271
MspSender.ConfirmCurrentPayload(Radio.RXdataBuffer[6] == 1);
276272

@@ -398,27 +394,30 @@ void ICACHE_RAM_ATTR SendRCdataToRF()
398394
}
399395
}
400396

401-
uint32_t SyncInterval;
402-
397+
uint32_t now = millis();
398+
static uint8_t syncSlot;
403399
#if defined(NO_SYNC_ON_ARM)
404-
SyncInterval = 250;
400+
uint32_t SyncInterval = 250;
405401
bool skipSync = IsArmed();
406402
#else
407-
SyncInterval = (connectionState == connected) ? ExpressLRS_currAirRate_RFperfParams->SyncPktIntervalConnected : ExpressLRS_currAirRate_RFperfParams->SyncPktIntervalDisconnected;
403+
uint32_t SyncInterval = (connectionState == connected) ? ExpressLRS_currAirRate_RFperfParams->SyncPktIntervalConnected : ExpressLRS_currAirRate_RFperfParams->SyncPktIntervalDisconnected;
408404
bool skipSync = false;
409405
#endif
410406

411407
uint8_t NonceFHSSresult = NonceTX % ExpressLRS_currAirRate_Modparams->FHSShopInterval;
412-
bool NonceFHSSresultWindow = (NonceFHSSresult == 1 || NonceFHSSresult == 2) ? true : false; // restrict to the middle nonce ticks (not before or after freq chance)
413-
bool WithinSyncSpamResidualWindow = (millis() - rfModeLastChangedMS < syncSpamAResidualTimeMS) ? true : false;
408+
bool WithinSyncSpamResidualWindow = now - rfModeLastChangedMS < syncSpamAResidualTimeMS;
414409

415-
if ((syncSpamCounter || WithinSyncSpamResidualWindow) && NonceFHSSresultWindow)
410+
// Sync spam only happens on slot 1 and 2 and can't be disabled
411+
if ((syncSpamCounter || WithinSyncSpamResidualWindow) && (NonceFHSSresult == 1 || NonceFHSSresult == 2))
416412
{
417413
GenerateSyncPacketData();
418414
}
419-
else if ((!skipSync) && ((millis() > (SyncPacketLastSent + SyncInterval)) && (Radio.currFreq == GetInitialFreq()) && NonceFHSSresultWindow)) // don't sync just after we changed freqs (helps with hwTimer.init() being in sync from the get go)
415+
// Regular sync rotates through 4x slots, twice on each slot, and telemetry pushes it to the next slot up
416+
// But only on the sync FHSS channel and with a timed delay between them
417+
else if ((!skipSync) && ((syncSlot / 2) <= NonceFHSSresult) && (now - SyncPacketLastSent > SyncInterval) && (Radio.currFreq == GetInitialFreq()))
420418
{
421419
GenerateSyncPacketData();
420+
syncSlot = (syncSlot + 1) % (ExpressLRS_currAirRate_Modparams->FHSShopInterval * 2);
422421
}
423422
else
424423
{
@@ -603,7 +602,7 @@ void registerLuaParameters() {
603602
{
604603
//confirm run on ELRSv2.lua or start command from CRSF configurator,
605604
//since ELRS LUA can do 2 step confirmation, it needs confirmation to start wifi to prevent stuck on
606-
//unintentional button press.
605+
//unintentional button press.
607606
setLuaCommandValue(&luaWebUpdate,2); //running status
608607
webUpdateMode = true;
609608
DBGLN("Wifi Update Mode Requested!");
@@ -614,7 +613,7 @@ void registerLuaParameters() {
614613
setLuaCommandValue(&luaWebUpdate,0);
615614
}
616615
});
617-
616+
618617
registerLUAParameter(&luaBLEJoystick, [](uint8_t id, uint8_t arg){
619618
if (arg > 0 && arg < 4) //start command, 1 = start
620619
//2 = running
@@ -626,7 +625,7 @@ void registerLuaParameters() {
626625
{
627626
//confirm run on ELRSv2.lua or start command from CRSF configurator,
628627
//since ELRS LUA can do 2 step confirmation, it needs confirmation to start wifi to prevent stuck on
629-
//unintentional button press.
628+
//unintentional button press.
630629
setLuaCommandValue(&luaBLEJoystick,2); //running status
631630
BLEjoystickActive = true;
632631
#ifndef DEBUG_SUPPRESS
@@ -669,7 +668,7 @@ void resetLuaParams(){
669668

670669
uint8_t dynamic = config.GetDynamicPower() ? config.GetBoostChannel() + 1 : 0;
671670
setLuaTextSelectionValue(&luaDynamicPower,dynamic);
672-
671+
673672
setLuaTextSelectionValue(&luaVtxBand,config.GetVtxBand());
674673
setLuaTextSelectionValue(&luaVtxChannel,config.GetVtxChannel());
675674
setLuaTextSelectionValue(&luaVtxPwr,config.GetVtxPower());
@@ -721,7 +720,7 @@ void UARTconnected()
721720
static void ChangeRadioParams()
722721
{
723722
config.SetModelId(crsf.getModelID());
724-
723+
725724
SetRFLinkRate(config.GetRate());
726725
POWERMGNT.setPower((PowerLevels_e)config.GetPower());
727726
OtaSetSwitchMode((OtaSwitchMode_e)config.GetSwitchMode());
@@ -1029,7 +1028,7 @@ void loop()
10291028
msp.markPacketReceived();
10301029
}
10311030
}
1032-
1031+
10331032
if (VtxConfigReadyToSend)
10341033
{
10351034
VtxConfigReadyToSend = false;

0 commit comments

Comments
 (0)