Skip to content

Commit 66659eb

Browse files
committed
first implementation
1 parent a3789a5 commit 66659eb

54 files changed

Lines changed: 2215 additions & 896 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/blackbox/blackbox.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ static const blackboxSimpleFieldDefinition_t blackboxSlowFields[] = {
494494
{"failsafePhase", -1, UNSIGNED, PREDICT(0), ENCODING(TAG2_3S32)},
495495
{"rxSignalReceived", -1, UNSIGNED, PREDICT(0), ENCODING(TAG2_3S32)},
496496
{"rxFlightChannelsValid", -1, UNSIGNED, PREDICT(0), ENCODING(TAG2_3S32)},
497+
{"rxActiveLink", -1, UNSIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
498+
{"rxValidLinkMask", -1, UNSIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
499+
{"rxSwitchReason", -1, UNSIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
500+
{"rxSwitchTimeMs", -1, UNSIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
501+
{"rxDualStatus", -1, UNSIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
497502
{"rxUpdateRate", -1, UNSIGNED, PREDICT(PREVIOUS), ENCODING(UNSIGNED_VB)},
498503

499504
{"hwHealthStatus", -1, UNSIGNED, PREDICT(0), ENCODING(UNSIGNED_VB)},
@@ -616,6 +621,11 @@ typedef struct blackboxSlowState_s {
616621
uint8_t failsafePhase;
617622
bool rxSignalReceived;
618623
bool rxFlightChannelsValid;
624+
uint8_t rxActiveLink;
625+
uint8_t rxValidLinkMask;
626+
uint8_t rxSwitchReason;
627+
uint32_t rxSwitchTimeMs;
628+
uint8_t rxDualStatus;
619629
int32_t hwHealthStatus;
620630
uint16_t powerSupplyImpedance;
621631
uint16_t sagCompensatedVBat;
@@ -1397,6 +1407,11 @@ static void writeSlowFrame(void)
13971407
values[1] = slowHistory.rxSignalReceived ? 1 : 0;
13981408
values[2] = slowHistory.rxFlightChannelsValid ? 1 : 0;
13991409
blackboxWriteTag2_3S32(values);
1410+
blackboxWriteUnsignedVB(slowHistory.rxActiveLink);
1411+
blackboxWriteUnsignedVB(slowHistory.rxValidLinkMask);
1412+
blackboxWriteUnsignedVB(slowHistory.rxSwitchReason);
1413+
blackboxWriteUnsignedVB(slowHistory.rxSwitchTimeMs);
1414+
blackboxWriteUnsignedVB(slowHistory.rxDualStatus);
14001415

14011416
blackboxWriteUnsignedVB(slowHistory.rxUpdateRate);
14021417

@@ -1474,6 +1489,11 @@ static void loadSlowState(blackboxSlowState_t *slow)
14741489
slow->failsafePhase = failsafePhase();
14751490
slow->rxSignalReceived = rxIsReceivingSignal();
14761491
slow->rxFlightChannelsValid = rxAreFlightChannelsValid();
1492+
slow->rxActiveLink = rxGetActiveLink();
1493+
slow->rxValidLinkMask = rxGetValidLinkMask();
1494+
slow->rxSwitchReason = rxGetLastSwitchReason();
1495+
slow->rxSwitchTimeMs = rxGetLastSwitchTimeMs();
1496+
slow->rxDualStatus = rxGetDualRxStatus();
14771497
slow->rxUpdateRate = getRcUpdateFrequency();
14781498
slow->hwHealthStatus = (getHwGyroStatus() << 2 * 0) | // Pack hardware health status into a bit field.
14791499
(getHwAccelerometerStatus() << 2 * 1) | // Use raw hardwareSensorStatus_e values and pack them using 2 bits per value
@@ -2094,6 +2114,9 @@ static bool blackboxWriteSysinfo(void)
20942114
BLACKBOX_PRINT_HEADER_LINE("mag_hardware", "%d", MAG_NONE);
20952115
#endif
20962116
BLACKBOX_PRINT_HEADER_LINE("serialrx_provider", "%d", rxConfig()->serialrx_provider);
2117+
BLACKBOX_PRINT_HEADER_LINE("dual_rx_enabled", "%d", rxConfig()->dualRxEnabled);
2118+
BLACKBOX_PRINT_HEADER_LINE("receiver_type_rx2", "%d", rxConfig()->receiverTypeSecondary);
2119+
BLACKBOX_PRINT_HEADER_LINE("serialrx_provider_rx2", "%d", rxConfig()->serialrx_provider_secondary);
20972120
BLACKBOX_PRINT_HEADER_LINE("motor_pwm_protocol", "%d", motorConfig()->motorPwmProtocol);
20982121
BLACKBOX_PRINT_HEADER_LINE("motor_pwm_rate", "%d", getEscUpdateFrequency());
20992122
BLACKBOX_PRINT_HEADER_LINE("debug_mode", "%d", systemConfig()->debug_mode);

src/main/cms/cms_menu_osd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ static const OSD_Entry menuOsdElemsEntries[] =
290290
#if defined(USE_RX_MSP) && defined(USE_MSP_RC_OVERRIDE)
291291
OSD_ELEMENT_ENTRY("RC SOURCE", OSD_RC_SOURCE),
292292
#endif
293+
OSD_ELEMENT_ENTRY("ACTIVE RX", OSD_ACTIVE_RX_LINK),
294+
OSD_ELEMENT_ENTRY("RX1 STATS", OSD_RX1_LINK_STATS),
295+
OSD_ELEMENT_ENTRY("RX2 STATS", OSD_RX2_LINK_STATS),
293296

294297
OSD_ELEMENT_ENTRY("IMU TEMP", OSD_IMU_TEMPERATURE),
295298
#ifdef USE_BARO

src/main/fc/cli.c

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,27 +3619,50 @@ static void cliDfu(char *cmdline)
36193619
cliRebootEx(true);
36203620
}
36213621

3622-
#if defined (USE_SERIALRX_SRXL2)
3623-
void cliRxBind(char *cmdline){
3624-
UNUSED(cmdline);
3625-
if (rxConfig()->receiverType == RX_TYPE_SERIAL) {
3626-
switch (rxConfig()->serialrx_provider) {
3627-
default:
3628-
cliPrint("Not supported.");
3629-
break;
3622+
#if defined(USE_SERIALRX_SRXL2) || defined(USE_SERIALRX_CRSF)
3623+
void cliRxBind(char *cmdline)
3624+
{
3625+
rxLink_e link = rxGetActiveLink();
3626+
if (!isEmpty(cmdline)) {
3627+
const int requestedRx = fastA2I(cmdline);
3628+
if (requestedRx < 1 || requestedRx > RX_LINK_COUNT) {
3629+
cliShowArgumentRangeError("rx", 1, RX_LINK_COUNT);
3630+
return;
3631+
}
3632+
link = (rxLink_e)(requestedRx - 1);
3633+
}
3634+
3635+
if (!rxIsLinkConfigured(link)) {
3636+
cliPrint("RX not configured.");
3637+
return;
3638+
}
3639+
3640+
const uint8_t receiverType = link == RX_LINK_PRIMARY ? rxConfig()->receiverType : rxConfig()->receiverTypeSecondary;
3641+
const uint8_t provider = link == RX_LINK_PRIMARY ? rxConfig()->serialrx_provider : rxConfig()->serialrx_provider_secondary;
3642+
if (receiverType != RX_TYPE_SERIAL) {
3643+
cliPrint("Not supported.");
3644+
return;
3645+
}
3646+
3647+
switch (provider) {
3648+
default:
3649+
cliPrint("Not supported.");
3650+
break;
36303651
#if defined(USE_SERIALRX_SRXL2)
3631-
case SERIALRX_SRXL2:
3632-
srxl2Bind();
3633-
cliPrint("Binding SRXL2 receiver...");
3634-
break;
3652+
case SERIALRX_SRXL2:
3653+
srxl2Bind();
3654+
cliPrint("Binding SRXL2 receiver...");
3655+
break;
36353656
#endif
36363657
#if defined(USE_SERIALRX_CRSF)
3637-
case SERIALRX_CRSF:
3638-
crsfBind();
3658+
case SERIALRX_CRSF:
3659+
if (crsfBindLink(link)) {
36393660
cliPrint("Binding CRSF receiver...");
3640-
break;
3641-
#endif
3661+
} else {
3662+
cliPrint("RX not initialized.");
36423663
}
3664+
break;
3665+
#endif
36433666
}
36443667
}
36453668
#endif
@@ -4960,8 +4983,8 @@ const clicmd_t cmdTable[] = {
49604983
"\t<+|->[name]", cliBeeper),
49614984
#endif
49624985
CLI_COMMAND_DEF("bind_msp_rx", "initiate binding for MSP receivers (mLRS)", "<port>", cliBindMspRx),
4963-
#if defined (USE_SERIALRX_SRXL2)
4964-
CLI_COMMAND_DEF("bind_rx", "initiate binding for RX SPI or SRXL2", NULL, cliRxBind),
4986+
#if defined(USE_SERIALRX_SRXL2) || defined(USE_SERIALRX_CRSF)
4987+
CLI_COMMAND_DEF("bind_rx", "bind serial receiver; defaults to active RX", "[1|2]", cliRxBind),
49654988
#endif
49664989
#if defined(USE_BOOTLOG)
49674990
CLI_COMMAND_DEF("bootlog", "show boot log", NULL, printBootLog),

src/main/fc/fc_core.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,17 @@ void releaseSharedTelemetryPorts(void) {
645645
}
646646
}
647647

648-
void processRx(timeUs_t currentTimeUs)
648+
static bool processRx(timeUs_t currentTimeUs)
649649
{
650-
// Calculate RPY channel data
651-
calculateRxChannelsAndUpdateFailsafe(currentTimeUs);
650+
// Calculate RPY channel data. Standby-link traffic is processed by the RX
651+
// task but must not look like a new active RC sample to smoothing/navigation.
652+
const bool rxOutputUpdated = calculateRxChannelsAndUpdateFailsafe(currentTimeUs);
653+
if (!rxOutputUpdated) {
654+
// Standby RX traffic has already been decoded and its freshness/state
655+
// updated. Do not let it advance stick commands, mode logic, smoothing
656+
// or other active-control state machines.
657+
return false;
658+
}
652659

653660
// in 3D mode, we need to be able to disarm by switch at any time
654661
if (feature(FEATURE_REVERSIBLE_MOTORS)) {
@@ -858,6 +865,8 @@ void processRx(timeUs_t currentTimeUs)
858865
#endif
859866
// Sound a beeper if the flight mode state has changed
860867
updateFlightModeChangeBeeper();
868+
869+
return rxOutputUpdated;
861870
}
862871

863872
// Function for loop trigger
@@ -1076,8 +1085,7 @@ bool taskUpdateRxCheck(timeUs_t currentTimeUs, timeDelta_t currentDeltaTime)
10761085

10771086
void taskUpdateRxMain(timeUs_t currentTimeUs)
10781087
{
1079-
processRx(currentTimeUs);
1080-
isRXDataNew = true;
1088+
isRXDataNew = processRx(currentTimeUs) || isRXDataNew;
10811089
}
10821090

10831091
// returns seconds

src/main/fc/fc_init.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,16 @@ void init(void)
267267
#endif
268268

269269
#if defined(USE_SPEKTRUM_BIND) && defined(USE_SERIALRX_SPEKTRUM)
270-
if (rxConfig()->receiverType == RX_TYPE_SERIAL) {
271-
switch (rxConfig()->serialrx_provider) {
272-
case SERIALRX_SPEKTRUM1024:
273-
case SERIALRX_SPEKTRUM2048:
274-
// Spektrum satellite binding if enabled on startup.
275-
// Must be called before that 100ms sleep so that we don't lose satellite's binding window after startup.
276-
// The rest of Spektrum initialization will happen later - via spektrumInit()
277-
spektrumBind(rxConfigMutable());
278-
break;
279-
}
270+
const bool rx1Spektrum = rxConfig()->receiverType == RX_TYPE_SERIAL &&
271+
(rxConfig()->serialrx_provider == SERIALRX_SPEKTRUM1024 || rxConfig()->serialrx_provider == SERIALRX_SPEKTRUM2048);
272+
const bool rx2Spektrum = rxConfig()->dualRxEnabled && rxConfig()->receiverTypeSecondary == RX_TYPE_SERIAL &&
273+
(rxConfig()->serialrx_provider_secondary == SERIALRX_SPEKTRUM1024 || rxConfig()->serialrx_provider_secondary == SERIALRX_SPEKTRUM2048);
274+
if (rx1Spektrum || rx2Spektrum) {
275+
// Spektrum satellite binding if enabled on startup. Must be called
276+
// before the startup delay so the bind window is not missed. The bind
277+
// settings/pin are board-wide, so this applies whichever RX slot owns
278+
// the Spektrum receiver.
279+
spektrumBind(rxConfigMutable());
280280
}
281281
#endif
282282

0 commit comments

Comments
 (0)