Skip to content

Add MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED command#11171

Merged
sensei-hacker merged 1 commit intoiNavFlight:maintenance-9.xfrom
sensei-hacker:feature/logic-conditions-enabled-mask
Dec 8, 2025
Merged

Add MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED command#11171
sensei-hacker merged 1 commit intoiNavFlight:maintenance-9.xfrom
sensei-hacker:feature/logic-conditions-enabled-mask

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Dec 8, 2025

User description

Adds new MSP command (0x203C) that returns an 8-byte bitmask indicating which of the 64 logic conditions are configured (differ from default values).

This enables the configurator to optimize loading by fetching only configured conditions instead of all 64.

Companion PR: iNavFlight/inav-configurator (pending)


PR Type

Enhancement


Description

  • Adds MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED command (0x203C)

  • Returns 8-byte bitmask indicating configured logic conditions

  • Optimizes configurator by reducing MSP requests from 64 to 1+N

  • Checks if logic condition differs from default reset values


Diagram Walkthrough

flowchart LR
  A["MSP Request"] -->|"0x203C"| B["Check Logic Conditions"]
  B -->|"Compare to defaults"| C["Generate 64-bit Mask"]
  C -->|"Split into 2x32-bit"| D["Return 8-byte Response"]
Loading

File Walkthrough

Relevant files
Configuration changes
msp_protocol_v2_inav.h
Define new MSP2 logic conditions configured command           

src/main/msp/msp_protocol_v2_inav.h

  • Defines new MSP2 command constant
    MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED with value 0x203C
  • Adds inline comment explaining the command returns 8-byte bitmask of
    non-default logic conditions
+1/-0     
Enhancement
fc_msp.c
Implement logic conditions configured bitmask handler       

src/main/fc/fc_msp.c

  • Implements handler for MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED command
  • Iterates through all 64 logic conditions and checks if each differs
    from default values
  • Builds 64-bit bitmask where bit N indicates if condition N is
    configured
  • Sends bitmask as two 32-bit values (lower and upper halves)
+23/-0   

Returns 8-byte bitmask indicating which logic conditions differ from defaults.
Enables configurator optimization to reduce MSP requests from 64 to 1+N.
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High-level Suggestion

To improve maintainability, centralize the logic for checking if a logic condition is in its default state into a dedicated function, such as isLogicConditionDefault(). This avoids hardcoding the default values in the MSP handler, which could lead to inconsistencies if the defaults change. [High-level, importance: 7]

Solution Walkthrough:

Before:

// src/main/fc/fc_msp.c
case MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED:
{
    uint64_t mask = 0;
    for (int i = 0; i < MAX_LOGIC_CONDITIONS; i++) {
        const logicCondition_t *lc = logicConditions(i);
        // Check if any field differs from default reset values
        bool isConfigured = (lc->enabled != 0) ||
                            (lc->activatorId != -1) ||
                            (lc->operation != 0) ||
                            (lc->operandA.type != LOGIC_CONDITION_OPERAND_TYPE_VALUE) ||
                            (lc->operandA.value != 0) ||
                            ...;
        if (isConfigured) {
            mask |= ((uint64_t)1 << i);
        }
    }
    ...
}
break;

After:

// In a relevant file like logic_conditions.c/h
bool isLogicConditionDefault(const logicCondition_t *lc) {
    logicCondition_t defaultLc;
    resetLogicCondition(&defaultLc); // Assuming a reset function exists
    return memcmp(lc, &defaultLc, sizeof(logicCondition_t)) == 0;
}

// src/main/fc/fc_msp.c
case MSP2_INAV_LOGIC_CONDITIONS_CONFIGURED:
{
    uint64_t mask = 0;
    for (int i = 0; i < MAX_LOGIC_CONDITIONS; i++) {
        const logicCondition_t *lc = logicConditions(i);
        if (!isLogicConditionDefault(lc)) {
            mask |= ((uint64_t)1 << i);
        }
    }
    ...
}
break;

@sensei-hacker sensei-hacker added this to the 9.0 milestone Dec 8, 2025
@sensei-hacker sensei-hacker merged commit 2257be3 into iNavFlight:maintenance-9.x Dec 8, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant