Skip to content

Conversation

@sensei-hacker
Copy link
Member

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

User description

Fixes merge conflicts from #11100


PR Type

Enhancement


Description

  • Adds barometer altitude and vario sensor support to CRSF telemetry

  • Combines altitude and vertical speed into single packet frame

  • Implements legacy barometer packet mode configuration option

  • Updates frame type definitions and payload sizes for new sensors


Diagram Walkthrough

flowchart LR
  A["CRSF Telemetry"] --> B["Legacy Mode"]
  A --> C["New Mode"]
  B --> D["Vario Sensor Frame"]
  B --> E["Altitude in GPS Frame"]
  C --> F["Combined Alt-Vario Frame"]
  C --> G["ASL Altitude in GPS Frame"]
  F --> H["Altitude + Vertical Speed"]
Loading

File Walkthrough

Relevant files
Enhancement
crsf.h
Add barometer altitude vario sensor frame types                   

src/main/rx/crsf.h

  • Added CRSF_FRAME_BAROMETER_ALTITUDE_VARIO_PAYLOAD_SIZE constant (3
    bytes)
  • Added CRSF_FRAME_AIRSPEED_PAYLOAD_SIZE constant (2 bytes)
  • Renamed CRSF_FRAMETYPE_BAROMETER_ALTITUDE to
    CRSF_FRAMETYPE_BAROMETER_ALTITUDE_VARIO_SENSOR
  • Added CRSF_FRAMETYPE_AIRSPEED_SENSOR frame type definition
+4/-1     
crsf.c
Implement barometer altitude vario sensor telemetry           

src/main/telemetry/crsf.c

  • Added #include for SCHAR_MIN/SCHAR_MAX constants
  • Added #include "sensors/pitotmeter.h" for airspeed sensor support
  • Modified GPS frame to use configurable altitude source (legacy or GPS
    ASL)
  • Renamed crsfBarometerAltitude() to
    crsfFrameBarometerAltitudeVarioSensor()
  • Implemented vario (vertical speed) calculation using logarithmic
    formula with TBS CRSF standard constants
  • Consolidated vario and barometer altitude frame scheduling into single
    index
  • Updated frame processing to conditionally send legacy vario or new
    combined altitude-vario packet
+27/-25 
Configuration changes
telemetry.c
Add legacy barometer packet configuration option                 

src/main/telemetry/telemetry.c

  • Incremented telemetry config version from 8 to 9
  • Added crsf_use_legacy_baro_packet field to telemetry config reset
    template
  • Fixed trailing comma in mavlink configuration structure
+3/-2     
telemetry.h
Add legacy baro packet config field                                           

src/main/telemetry/telemetry.h

  • Added bool crsf_use_legacy_baro_packet field to telemetryConfig_t
    structure
+1/-0     
settings.yaml
Add CRSF legacy baro packet YAML setting                                 

src/main/fc/settings.yaml

  • Added crsf_use_legacy_baro_packet setting definition to telemetry
    config group
  • Set type as bool with default value OFF
  • Included description matching Settings.md documentation
+4/-0     
Documentation
Settings.md
Document CRSF legacy barometer packet setting                       

docs/Settings.md

  • Added documentation for crsf_use_legacy_baro_packet setting
  • Explains behavior difference between legacy and new altitude packet
    modes
  • Documents default value as OFF
+9/-0     

@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

The PR introduces definitions for airspeed telemetry in crsf.h but lacks the implementation to create and send the airspeed frame in crsf.c. The suggestion is to either complete this feature or remove the partial code. [High-level, importance: 8]

Solution Walkthrough:

Before:

// src/main/rx/crsf.h
...
enum {
    ...
    CRSF_FRAME_AIRSPEED_PAYLOAD_SIZE = 2,
    ...
};
...
typedef enum {
    ...
    CRSF_FRAMETYPE_AIRSPEED_SENSOR = 0x0A,
    ...
} crsfFrameType_e;

// src/main/telemetry/crsf.c
// No function to create the airspeed frame exists.
// No scheduling logic for the airspeed frame exists.

After:

// src/main/telemetry/crsf.c

// 1. Implement the frame creation function
static void crsfFrameAirspeedSensor(sbuf_t *dst)
{
    sbufWriteU8(dst, CRSF_FRAME_AIRSPEED_PAYLOAD_SIZE + CRSF_FRAME_LENGTH_TYPE_CRC);
    crsfSerialize8(dst, CRSF_FRAMETYPE_AIRSPEED_SENSOR);
    crsfSerialize16(dst, getAirspeed()); // Assuming getAirspeed() is available
}

// 2. Add to the frame scheduler
typedef enum {
    ...
    CRSF_FRAME_VARIO_OR_ALT_VARIO_SENSOR_INDEX,
    CRSF_FRAME_AIRSPEED_INDEX, // Add new index
    CRSF_SCHEDULE_COUNT_MAX
} crsfFrameTypeIndex_e;

// 3. Schedule and send the frame
// ... in initCrsfTelemetry() and processCrsf()

Comment on lines +299 to +301
float vario_sm = getEstimatedActualVelocity(Z);
int8_t sign = vario_sm < 0 ? -1 : ( vario_sm > 0 ? 1 : 0 );
int8_t vario_packed = (int8_t)constrain( lrintf(__builtin_logf(ABS(vario_sm) / VARIO_KL + 1) / VARIO_KR * sign ), SCHAR_MIN, SCHAR_MAX );
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Compute in float, clamp to int bounds, and cast once at the end to avoid premature narrowing and ensure correct range handling. [Learned best practice, importance: 6]

Suggested change
float vario_sm = getEstimatedActualVelocity(Z);
int8_t sign = vario_sm < 0 ? -1 : ( vario_sm > 0 ? 1 : 0 );
int8_t vario_packed = (int8_t)constrain( lrintf(__builtin_logf(ABS(vario_sm) / VARIO_KL + 1) / VARIO_KR * sign ), SCHAR_MIN, SCHAR_MAX );
float vario_sm = getEstimatedActualVelocity(Z);
int sign = (vario_sm < 0.0f) ? -1 : ((vario_sm > 0.0f) ? 1 : 0);
float vario_scaled = (__builtin_logf(fabsf(vario_sm) / VARIO_KL + 1.0f) / VARIO_KR) * sign;
float vario_clamped = constrainf(vario_scaled, (float)SCHAR_MIN, (float)SCHAR_MAX);
int8_t vario_packed = (int8_t)lrintf(vario_clamped);

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.

2 participants