Skip to content

Commit 707afcf

Browse files
committed
Always send LinkStats to handset
1 parent 64e872d commit 707afcf

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/src/tx_main.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ uint32_t SyncPacketLastSent = 0;
8484
static enum { stbIdle, stbRequested, stbBoosting } syncTelemBoostState = stbIdle;
8585
////////////////////////////////////////////////
8686

87-
volatile uint32_t LastTLMpacketRecvMillis = 0;
88-
uint32_t TLMpacketReported = 0;
87+
static uint32_t LastTLMpacketRecvMillis = 0;
88+
static uint32_t LinkStatsLastReported_Ms = 0;
8989
static bool commitInProgress = false;
9090

9191
LQCALC<25> LQCalc;
@@ -975,6 +975,8 @@ static void UpdateConnectDisconnectStatus()
975975
(connectionState == awaitingModelId && (now - rfModeLastChangedMS) > ExpressLRS_currAirRate_RFperfParams->DisconnectTimeoutMs))
976976
{
977977
setConnectionState(disconnected);
978+
linkStats.uplink_Link_quality = 0;
979+
LinkStatsLastReported_Ms = 0; // Notify immediately
978980
connectionHasModelMatch = true;
979981
}
980982
}
@@ -1400,6 +1402,20 @@ static void cyclePower()
14001402
}
14011403
}
14021404

1405+
static void checkSendLinkStatsToHandset(uint32_t now)
1406+
{
1407+
if ((now - LinkStatsLastReported_Ms) > firmwareOptions.tlm_report_interval)
1408+
{
1409+
uint8_t linkStatisticsFrame[CRSF_FRAME_NOT_COUNTED_BYTES + CRSF_FRAME_SIZE(sizeof(crsfLinkStatistics_t))];
1410+
1411+
crsfRouter.makeLinkStatisticsPacket(linkStatisticsFrame);
1412+
// the linkStats originates from the OTA connector so we don't send it back there.
1413+
crsfRouter.deliverMessage(&otaConnector, (crsf_header_t *)linkStatisticsFrame);
1414+
sendCRSFTelemetryToBackpack(linkStatisticsFrame);
1415+
LinkStatsLastReported_Ms = now;
1416+
}
1417+
}
1418+
14031419
void setup()
14041420
{
14051421
if (setupHardwareFromOptions())
@@ -1531,20 +1547,7 @@ void loop()
15311547
CheckConfigChangePending();
15321548
DynamicPower_Update(now);
15331549
VtxPitmodeSwitchUpdate();
1534-
1535-
/* Send TLM updates to handset if connected + reporting period
1536-
* is elapsed. This keeps handset happy dispite of the telemetry ratio */
1537-
if ((connectionState == connected) && (LastTLMpacketRecvMillis != 0) &&
1538-
(now >= (uint32_t)(firmwareOptions.tlm_report_interval + TLMpacketReported)))
1539-
{
1540-
uint8_t linkStatisticsFrame[CRSF_FRAME_NOT_COUNTED_BYTES + CRSF_FRAME_SIZE(sizeof(crsfLinkStatistics_t))];
1541-
1542-
crsfRouter.makeLinkStatisticsPacket(linkStatisticsFrame);
1543-
// the linkStats originates from the OTA connector so we don't send it back there.
1544-
crsfRouter.deliverMessage(&otaConnector, (crsf_header_t *)linkStatisticsFrame);
1545-
sendCRSFTelemetryToBackpack(linkStatisticsFrame);
1546-
TLMpacketReported = now;
1547-
}
1550+
checkSendLinkStatsToHandset(now);
15481551

15491552
if (TelemetryReceiver.HasFinishedData())
15501553
{

0 commit comments

Comments
 (0)