Skip to content

Conversation

@xznhj8129
Copy link
Contributor

@xznhj8129 xznhj8129 commented Nov 29, 2025

User description

There was no way to set a Global Variable through MSP, which seems like a pretty handy thing to have.


PR Type

Enhancement


Description

  • Add MSP2_INAV_SET_GVAR command for setting Global Variables

  • Implement handler with validation for gvar index and data size

  • Update MSP protocol documentation and enum references

  • Fix documentation source references for sdcard drivers


Diagram Walkthrough

flowchart LR
  MSP["MSP2_INAV_SET_GVAR<br/>Command 0x2214"]
  Handler["Handler validates<br/>gvarIndex & dataSize"]
  GVSet["gvSet function<br/>sets GVAR value"]
  MSP -->|"5 bytes payload"| Handler
  Handler -->|"index valid"| GVSet
  Handler -->|"invalid"| Error["Return MSP_RESULT_ERROR"]
Loading

File Walkthrough

Relevant files
Enhancement
fc_msp.c
Implement MSP2_INAV_SET_GVAR command handler                         

src/main/fc/fc_msp.c

  • Added new case handler for MSP2_INAV_SET_GVAR command
  • Validates payload size is exactly 5 bytes
  • Reads gvarIndex (uint8_t) and gvarValue (int32_t) from buffer
  • Checks gvarIndex against MAX_GLOBAL_VARIABLES limit
  • Calls gvSet() to set the global variable value
+17/-0   
Configuration changes
msp_protocol_v2_inav.h
Define MSP2_INAV_SET_GVAR protocol constant                           

src/main/msp/msp_protocol_v2_inav.h

  • Added MSP2_INAV_SET_GVAR macro definition with code 0x2214
  • Positioned after MSP2_INAV_SET_GEOZONE_VERTEX in protocol definitions
  • Fixed newline at end of file
+2/-1     
msp_messages.checksum
Update message definition checksum                                             

docs/development/msp/msp_messages.checksum

  • Updated checksum to reflect new MSP2_INAV_SET_GVAR message addition
+1/-1     
Documentation
msp_messages.json
Document MSP2_INAV_SET_GVAR message structure                       

docs/development/msp/msp_messages.json

  • Added complete MSP2_INAV_SET_GVAR message definition with code 8724
  • Documented request payload with gvarIndex and value fields
  • Added notes about USE_PROGRAMMING_FRAMEWORK requirement and validation
  • Updated checksum to reflect new message definition
+23/-0   
msp_ref.md
Add MSP2_INAV_SET_GVAR to reference documentation               

docs/development/msp/msp_ref.md

  • Added MSP2_INAV_SET_GVAR to message index with code 8724
  • Added detailed documentation section with request/reply payload tables
  • Included notes about requirements and validation behavior
  • Updated JSON file revision from 2 to 3
+16/-1   
inav_enums_ref.md
Update enum documentation and fix references                         

docs/development/msp/inav_enums_ref.md

  • Fixed DEVHW_W25N01G enum name to DEVHW_W25N
  • Added LOGIC_CONDITION_OPERAND_FLIGHT_RELATIVE_WIND_OFFSET enum with
    value 49
  • Corrected sdcard driver source file references (swapped spi/sdio)
+4/-3     
rev
Bump MSP documentation revision                                                   

docs/development/msp/rev

  • Incremented MSP documentation revision from 2 to 3
+1/-1     

@qodo-merge-pro
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

Add a safety check to prevent the MSP2_INAV_SET_GVAR command from executing if the aircraft is armed. This avoids unintended flight behavior changes caused by modifying Global Variables mid-flight. [High-level, importance: 9]

Solution Walkthrough:

Before:

case MSP2_INAV_SET_GVAR:
    if (dataSize != 5) {
        return MSP_RESULT_ERROR;
    }
    {
        uint8_t gvarIndex;
        if (!sbufReadU8Safe(&gvarIndex, src)) {
            return MSP_RESULT_ERROR;
        }
        const int32_t gvarValue = (int32_t)sbufReadU32(src);
        if (gvarIndex >= MAX_GLOBAL_VARIABLES) {
            return MSP_RESULT_ERROR;
        }
        gvSet(gvarIndex, gvarValue);
    }
    break;

After:

case MSP2_INAV_SET_GVAR:
    if (ARMING_FLAG(ARMED)) {
        return MSP_RESULT_ERROR;
    }
    if (dataSize != 5) {
        return MSP_RESULT_ERROR;
    }
    {
        uint8_t gvarIndex;
        if (!sbufReadU8Safe(&gvarIndex, src)) {
            return MSP_RESULT_ERROR;
        }
        const int32_t gvarValue = (int32_t)sbufReadU32(src);
        if (gvarIndex >= MAX_GLOBAL_VARIABLES) {
            return MSP_RESULT_ERROR;
        }
        gvSet(gvarIndex, gvarValue);
    }
    break;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would defeat the point

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