Skip to content

OSD: optional disarm hold on the MSP DisplayPort port only (osd_msp_disarm_hold) - #12246

Open
erwinquilloy wants to merge 1 commit into
iNavFlight:next-10.1from
erwinquilloy:osd-msp-disarm-hold
Open

erwinquilloy wants to merge 1 commit into
iNavFlight:next-10.1from
erwinquilloy:osd-msp-disarm-hold

Conversation

@erwinquilloy

Copy link
Copy Markdown

What it does

DJI air units (and other digital VTX systems that start and stop the DVR from the FC's arm state) stop recording the moment they see the disarm. INAV draws the post-flight stats screen after the disarm, so it never makes it into the goggle recording. This has been asked for several times (#10851, #11475).

This PR adds one setting, osd_msp_disarm_hold (0-7 s, default 0 = off, no change in behaviour). When it is set, the status replies sent on the MSP DisplayPort serial port only keep the ARM bit for that many seconds after a disarm, so the goggles keep recording long enough to capture the stats screen.

This is not a global change to the arm state

I've read the earlier discussions. The objections were that the arm state must stay true, that a delay would reach ground stations, Bluetooth/WiFi adapters, companion computers and other MSP devices, and that INAV can't tell which device is asking. I agree with all of that, and this PR is built around it:

  • The flight controller disarms immediately. ARMING_FLAG(ARMED), the motors, the mixer, failsafe, logging and every other part of the firmware are untouched. Nothing in this PR delays or changes the disarm itself.
  • Only one port is affected: the UART with the MSP DisplayPort function (FUNCTION_MSP_OSD). INAV does know what is on that port. The user configured it as the DisplayPort OSD for the air unit. The change is a small wrapper around the command handler that only mspOsdSerialProcess() uses, and it edits the reply bytes after the normal handler has written them.
  • Every other MSP user sees the real state, unchanged. They all call mspFcProcessCommand() directly and never go through the wrapper:
    • every regular MSP serial port, e.g. mLRS, Bluetooth/WiFi adapters, companion computers and the configurator (mspSerialProcess() in fc_tasks.c)
    • MSP over CRSF / SmartPort telemetry (telemetry/msp_shared.c)
    • MSP over MAVLink (fc/fc_mavlink.c)
    • the legacy DJI HD OSD port (FUNCTION_DJI_HD_OSD, osd_dji_hd.c, its own handler)
  • An MSP device can't end up on the same UART as the DisplayPort. isSerialConfigValid() only allows MSP to share a port with telemetry, blackbox or log, and the DisplayPort OSD has its own mspPort, opened with FUNCTION_MSP_OSD. So a GCS, adapter or receiver link cannot receive the held replies.
  • Only the arm indication changes, and only in three status messages. All other bytes of those replies, and all other messages on that port, are left alone:
    • MSP_STATUS / MSP_STATUS_EX: mode flags byte 6, bit 0. This is BOXARM, which initActiveBoxIds() always adds first, and it is also the DJI ARM bit in the O4 workaround reply.
    • MSP2_INAV_STATUS: ARMED in armingFlags (byte 9) and mode flags byte 13, bit 0.
  • A re-arm cancels the hold at once. The hold starts when this port first answers after the disarm, and it is clamped to 7 s even if a bad value is loaded. It uses millis() with a wrap-safe compare. It doesn't use lastDisarmTimeUs, because 32-bit micros wrap after about 71 min.

The code

The whole runtime change is in src/main/io/displayport_msp_osd.c:

static bool disarmHoldWasArmed = false;
static bool disarmHoldActive = false;
static timeMs_t disarmHoldUntil = 0;

static bool mspOsdDisarmHold(void)
{
    if (ARMING_FLAG(ARMED)) {
        disarmHoldWasArmed = true;
        disarmHoldActive = false;
        return false;
    }
    const timeMs_t now = millis();
    if (disarmHoldWasArmed) {
        disarmHoldWasArmed = false;
        const uint8_t hold = MIN(osdConfig()->msp_disarm_hold, 7);
        disarmHoldActive = hold > 0;
        disarmHoldUntil = now + (timeMs_t)hold * 1000;
    }
    if (disarmHoldActive && (int32_t)(now - disarmHoldUntil) >= 0) {
        disarmHoldActive = false;
    }
    return disarmHoldActive;
}

static mspResult_e disarmHoldProcessMspCommand(mspPacket_t *cmd, mspPacket_t *reply, mspPostProcessFnPtr *mspPostProcessFn)
{
    uint8_t * const start = reply->buf.ptr;
    const mspResult_e result = fixDjiBrokenO4ProcessMspCommand(cmd, reply, mspPostProcessFn);
    const bool hold = mspOsdDisarmHold();   // every command: notices the disarm even between status requests
    if (!hold || result != MSP_RESULT_ACK) {
        return result;
    }
    const int len = reply->buf.ptr - start;
    if ((cmd->cmd == MSP_STATUS || cmd->cmd == MSP_STATUS_EX) && len >= 10) {
        start[6] |= 0x01;               // mode flags from byte 6, bit 0 = ARM (first active box; DJI order too)
    } else if (cmd->cmd == MSP2_INAV_STATUS && len >= 14) {
        start[9] |= (uint8_t)ARMED;     // armingFlags (u32, little-endian) from byte 9
        start[13] |= 0x01;              // mode flags from byte 13, bit 0 = ARM
    }
    return result;
}

void mspOsdSerialProcess(mspProcessCommandFnPtr mspProcessCommandFn)
{
    if (mspPort.port) {
        mspProcessCommand = mspProcessCommandFn;
        mspSerialProcessOnePort(&mspPort, MSP_SKIP_NON_MSP_DATA, disarmHoldProcessMspCommand);
    }
}

reply->buf.ptr is the start of the reply buffer when the handler is called (mspSerialProcessReceivedCommand() in msp_serial.c), so start[n] is byte n of the payload. The length checks keep the patch inside what the handler actually wrote.

Other files:

  • src/main/fc/settings.yaml: osd_msp_disarm_hold, uint8, 0-7, default 0, condition: USE_MSP_OSD.
  • src/main/io/osd.h: uint8_t msp_disarm_hold appended at the end of osdConfig_t. The PG version is unchanged, so existing saved OSD settings load as they are and the new field takes its default of 0.
  • src/main/io/osd.c: reset template default.
  • docs/Settings.md: regenerated with src/utils/update_cli_docs.py.

5 files, +74 / -2. Flash cost is about 200 bytes.

Usage

set osd_msp_disarm_hold = 3
save

Use 0 (default) for off and 1-7 for seconds. CLI only, no configurator change needed.

Testing

SITL (next-10.1 + this PR), three ports at once:

  • UART1: plain MSP, used as the control and "truth" port.
  • UART2: plain MSP standing in for an mLRS / companion device.
  • UART3: MSP DisplayPort standing in for the air unit.
  • Arm/disarm via MSP RC on an aux channel. MSP_STATUS, MSP_STATUS_EX and MSP2_INAV_STATUS are polled on UART2 and UART3 after every disarm.
osd_msp_disarm_hold plain MSP port (UART2) after disarm DisplayPort (UART3) after disarm
3 disarmed immediately, every message, every cycle ARM held for ~3.0 s, then disarmed
0 disarmed immediately disarmed immediately (identical to stock)

With hold 3, over 6 arm/disarm cycles, the DisplayPort held ARM for 3.00, 2.97, 2.97, 3.00, 2.97 and 2.98 s, measured from the moment the truth port reported the disarm. The plain MSP port showed the disarm on the first sample in 18 of 18 checks (3 messages × 6 cycles). With hold 0, both ports were identical to stock over 3 cycles. The FC's own armingFlags always dropped ARMED at the disarm. While armed, no port ever reported disarmed.

Host unit test (the two functions compiled against stubs): boot state, hold timing, re-arm during hold, hold 0 unchanged, clamp to 7, millis() wrap. All pass.

Hardware (built on 9.1.0, where the same commit applies without changes):

  • Matek F405-WMO + DJI air unit, ELRS on a CRSF receiver port, osd_msp_disarm_hold = 7. The motor stops at disarm and the goggles keep recording for 7 s, including the stats screen.
  • Same aircraft with mLRS on a regular MSP port. The motor cuts instantly at disarm and mLRS sees the disarm immediately.

Builds with -DWARNINGS_AS_ERRORS=ON on next-10.1: MATEKH743 (H7), MATEKF405TE (F4), TBS_LUCID_FC (AT32F435), SITL.

Not covered

  • The legacy FUNCTION_DJI_HD_OSD port (old DJI FPV system protocol) is not changed. It has its own handler, and the hold could be added there the same way if wanted.
  • Air units that decide recording from something other than the ARM bit in these status messages are not affected either way.

DJI goggles record only while the FC reports ARMED, so the stats screen,
drawn at disarm, is never recorded. osd_msp_disarm_hold (0-7 s, default
0 = off) keeps the ARM bit in the status replies on the MSP DisplayPort
(MSP_OSD) serial port only, for that long after a disarm.

The flight controller disarms at once. Every other MSP user (MSP ports such
as mLRS, MSP over CRSF / SmartPort, MSP in MAVLink, the configurator) is
answered by mspFcProcessCommand directly and sees the real arm state.
MSP_STATUS / MSP_STATUS_EX / MSP2_INAV_STATUS: only mode bit 0 (ARM, and
ARMED in INAV_STATUS armingFlags) changes. The new field is appended to
osdConfig_t, so saved OSD settings load unchanged.
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Hold the ARM indication briefly on MSP DisplayPort after disarm

✨ Enhancement 📝 Documentation ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Add an optional 0–7 second ARM indication hold so goggles can record post-flight stats.
• Limit the hold to MSP DisplayPort status replies; the FC and other MSP clients see the real
 disarm.
• Default the setting to off and document its CLI range.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 0 capabilities

  • Fault-specific containment limits risk to the originating changed behavior.
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before: each MSP DisplayPort status reply reflected the current arm state produced by the existing MSP command handler.
  • After: the change adds a stateful armed/disarmed transition, a configurable timer with expiry, early cancellation on re-arm, command-result checks, and separate byte offsets for MSP_STATUS/MSP_STATUS_EX versus MSP2_INAV_STATUS.
  • New correctness conditions are that the hold starts only after an observed armed-to-disarmed transition, expires at the configured deadline, is cleared on re-arm, and rewrites only the correct status fields without affecting other commands or ports.
  • The underlying MSP serialization and box-mode helpers are reused; their existence alone is not treated as added complexity.
Sources

src/main/io/displayport_msp_osd.c[634-638]

void mspOsdSerialProcess(mspProcessCommandFnPtr mspProcessCommandFn)
{
    if (mspPort.port) {
        mspProcessCommand = mspProcessCommandFn;
        mspSerialProcessOnePort(&mspPort, MSP_SKIP_NON_MSP_DATA, disarmHoldProcessMspCommand);
Potential damage 🟢 Low 🩹 Reversible

  • Conservative damage bound for the originating changed behavior; downstream capabilities remain contained.
  • A wrong status indication can cause the goggles to miss the intended post-disarm statistics recording or to show a temporarily incorrect armed indication.
  • This is confined to the DisplayPort air-unit integration and is recoverable for future flights by correcting/reverting the setting or code.
  • A recording already missed cannot be reconstructed, but the change does not corrupt flight-controller state, stored configuration beyond the user setting, or other transport responses.
  • Code rollback or setting osd_msp_disarm_hold=0 prevents future activation.
  • Recovery of the actual flight-controller state is immediate because disarm is not delayed.
  • Previously missed video/statistics content would require an external recording and cannot be restored after the fact; no persistent FC-state repair or external compensation is required.
Assessed commit e16e748
Diagram

sequenceDiagram
    actor Goggles
    participant Hold as DisplayPort wrapper
    participant Handler as MSP handler
    participant FC as Arm state
    participant Config as OSD setting
    actor Other as Other MSP clients
    Goggles->>Hold: Request status
    Hold->>Handler: Process command
    Handler->>FC: Read real state
    FC-->>Handler: Arm state
    Handler-->>Hold: Status reply
    Hold->>Config: Check hold duration
    Config-->>Hold: 0–7 seconds
    Hold-->>Goggles: Hold ARM bit if eligible
    Other->>Handler: Request status
    Handler-->>Other: Real status reply
Loading
High-Level Assessment

Keep the port-local reply wrapper: it preserves the FC’s real disarm state and avoids changing replies for unrelated MSP clients. Changing the central MSP handler or delaying disarm was considered but would broaden the effect beyond the configured DisplayPort port.

Files changed (5) +74 / -2

Enhancement (1) +52 / -1
displayport_msp_osd.cApply a timed ARM indication hold to DisplayPort status replies +52/-1

Apply a timed ARM indication hold to DisplayPort status replies

• Wraps the existing DisplayPort MSP handler and, during an active post-disarm hold, sets only the ARM-related bits in eligible status replies. The hold ends on timeout or re-arm, while the underlying FC state and other MSP paths remain unchanged.

src/main/io/displayport_msp_osd.c

Documentation (1) +10 / -0
Settings.mdDocument the DisplayPort disarm-hold setting +10/-0

Document the DisplayPort disarm-hold setting

• Adds the setting’s purpose, port-isolation behavior, default, and 0–7 second range.

docs/Settings.md

Other (3) +12 / -1
settings.yamlExpose the optional CLI setting +7/-0

Expose the optional CLI setting

• Defines 'osd_msp_disarm_hold' for MSP OSD builds with a zero default and a 0–7 second range.

src/main/fc/settings.yaml

osd.cInitialize the hold duration to its configured default +4/-1

Initialize the hold duration to its configured default

• Adds the MSP OSD setting to the OSD configuration reset template when MSP OSD is enabled.

src/main/io/osd.c

osd.hStore the disarm-hold duration in OSD configuration +1/-0

Store the disarm-hold duration in OSD configuration

• Appends a duration field to 'osdConfig_t' for the DisplayPort-only hold.

src/main/io/osd.h

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Extended status replies disagree on arming 🐞 Bug ≡ Correctness
Description
disarmHoldProcessMspCommand() sets the ARM mode bit in MSP_STATUS_EX but leaves that reply's
separate armingFlags field at its real, disarmed value. When the standard status handler produces
the reply during a hold, consumers reading armingFlags still see disarmed even though the mode
flags say armed.
Code

src/main/io/displayport_msp_osd.c[R625-626]

+    if ((cmd->cmd == MSP_STATUS || cmd->cmd == MSP_STATUS_EX) && len >= 10) {
+        start[6] |= 0x01;               // mode flags from byte 6, bit 0 = ARM (first active box; DJI order too)
Evidence
The standard handler writes four mode-flag bytes starting at offset 6, then a profile byte and
two-byte load value before writing the two-byte armingFlags field at offsets 13–14. The changed
branch edits only offset 6, while the separate MSP2_INAV_STATUS branch explicitly edits its
arming-flags field. The O4 workaround constructs a different MSP_STATUS_EX payload, so the
standard offset applies only when that workaround does not handle the reply.

src/main/fc/fc_msp.c[561-583]
src/main/io/displayport_msp_osd.c[625-630]
src/main/io/displayport_msp_osd.c[529-565]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
During a disarm hold, standard `MSP_STATUS_EX` replies set the ARM mode bit but leave the separate `armingFlags` field disarmed. The DJI O4 workaround produces a different reply layout and must not be patched at the standard field offset.

## Fix Focus Areas
- src/main/io/displayport_msp_osd.c[625-629]
- src/main/fc/fc_msp.c[561-583]

## Recommended Fix
For standard `MSP_STATUS_EX` replies during the hold, set `ARMED` in the serialized `armingFlags` field at payload byte 13 after checking that the field was written. Distinguish standard replies from DJI O4 workaround replies before applying that offset, and test both paths.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Cross-repo context — repo relationships
  Explored: repo: iNavFlight/iNavFlight.github.io (sha: 39626a75) — View relationship
Review mode: Auto: ⚖️ Balanced: Localized firmware protocol behavior carries timing and status-format risks.

Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@jaroszmm

jaroszmm commented Nov 21, 2026 •

Copy link
Copy Markdown

https://www.youtube.com/watch?v=Phk2TsFHvSo - long video with disarm delay in action at the end

https://youtu.be/4VapQdlyU4o - bench testing

I have tested that in both INAV and Ardupilot custom build crafts. Checked Crossfire, MLRS, ELRS and R9 RC links. In every case there were no issues upon disarming - everything stopped as normal, and OSD got recorded for a set amount of seconds.

The long video has the disarm delay at the end visible, the short one is bench testing with forced arming.

@fatbaldmen

Copy link
Copy Markdown

Tested this in flight today on a fixed wing. Rc protocol is CRSF (Mlrs using MSP-X). I also used KiteGC Mobile to upload a WP mission via MSP. The flight was flawless, no issues using KiteGC while the Displayport delay active. Video is sped up but the delay did let the recording continue for 5 seconds after disarm.

Yesterday I tested this on the bench with forced FC arming, and a normal arming in the backyard. I discovered zero issues in all three test.

https://youtu.be/pWU5NcisQJQ?si=CbKtUlkZVPbuh_i7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants