-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CRSF Baro Altitude and Vario, AirSpeed (fixed conflicts from #11100) #11168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sensei-hacker
wants to merge
3
commits into
iNavFlight:maintenance-9.x
Choose a base branch
from
sensei-hacker:pr-11100-crsf-baro
base: maintenance-9.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+48
−28
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |||||||||||||||||
| #include <stdbool.h> | ||||||||||||||||||
| #include <stdint.h> | ||||||||||||||||||
| #include <string.h> | ||||||||||||||||||
|
|
||||||||||||||||||
| #include <limits.h> | ||||||||||||||||||
| #include "platform.h" | ||||||||||||||||||
|
|
||||||||||||||||||
| #if defined(USE_TELEMETRY) && defined(USE_SERIALRX_CRSF) && defined(USE_TELEMETRY_CRSF) | ||||||||||||||||||
|
|
@@ -57,6 +57,7 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| #include "sensors/battery.h" | ||||||||||||||||||
| #include "sensors/sensors.h" | ||||||||||||||||||
| #include "sensors/pitotmeter.h" | ||||||||||||||||||
|
|
||||||||||||||||||
| #include "telemetry/crsf.h" | ||||||||||||||||||
| #include "telemetry/telemetry.h" | ||||||||||||||||||
|
|
@@ -225,8 +226,7 @@ static void crsfFrameGps(sbuf_t *dst) | |||||||||||||||||
| crsfSerialize32(dst, gpsSol.llh.lon); | ||||||||||||||||||
| crsfSerialize16(dst, (gpsSol.groundSpeed * 36 + 50) / 100); // gpsSol.groundSpeed is in cm/s | ||||||||||||||||||
| crsfSerialize16(dst, DECIDEGREES_TO_CENTIDEGREES(gpsSol.groundCourse)); // gpsSol.groundCourse is 0.1 degrees, need 0.01 deg | ||||||||||||||||||
| const uint16_t altitude = (getEstimatedActualPosition(Z) / 100) + 1000; | ||||||||||||||||||
| crsfSerialize16(dst, altitude); | ||||||||||||||||||
| crsfSerialize16(dst, (uint16_t)( (telemetryConfig()->crsf_use_legacy_baro_packet ? getEstimatedActualPosition(Z) : gpsSol.llh.alt ) / 100 + 1000) ); | ||||||||||||||||||
| crsfSerialize8(dst, gpsSol.numSat); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -269,16 +269,20 @@ static void crsfFrameBatterySensor(sbuf_t *dst) | |||||||||||||||||
| crsfSerialize8(dst, batteryRemainingPercentage); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const int32_t ALT_MIN_DM = 10000; | ||||||||||||||||||
| const int32_t ALT_THRESHOLD_DM = 0x8000 - ALT_MIN_DM; | ||||||||||||||||||
| const int32_t ALT_MAX_DM = 0x7ffe * 10 - 5; | ||||||||||||||||||
|
|
||||||||||||||||||
| /* | ||||||||||||||||||
| 0x09 Barometer altitude and vertical speed | ||||||||||||||||||
| Payload: | ||||||||||||||||||
| uint16_t altitude_packed ( dm - 10000 ) | ||||||||||||||||||
| */ | ||||||||||||||||||
| static void crsfBarometerAltitude(sbuf_t *dst) | ||||||||||||||||||
|
|
||||||||||||||||||
| const int32_t ALT_MIN_DM = 10000; | ||||||||||||||||||
| const int32_t ALT_THRESHOLD_DM = 0x8000 - ALT_MIN_DM; | ||||||||||||||||||
| const int32_t ALT_MAX_DM = 0x7ffe * 10 - 5; | ||||||||||||||||||
| const float VARIO_KL = 100.0f; // TBS CRSF standard | ||||||||||||||||||
| const float VARIO_KR = .026f; // TBS CRSF standard | ||||||||||||||||||
|
|
||||||||||||||||||
| static void crsfFrameBarometerAltitudeVarioSensor(sbuf_t *dst) | ||||||||||||||||||
| { | ||||||||||||||||||
| int32_t altitude_dm = lrintf(getEstimatedActualPosition(Z) / 10); | ||||||||||||||||||
| uint16_t altitude_packed; | ||||||||||||||||||
|
|
@@ -291,9 +295,15 @@ static void crsfBarometerAltitude(sbuf_t *dst) | |||||||||||||||||
| } else { | ||||||||||||||||||
| altitude_packed = ((altitude_dm + 5) / 10) | 0x8000; | ||||||||||||||||||
| } | ||||||||||||||||||
| sbufWriteU8(dst, CRSF_FRAME_BAROMETER_ALTITUDE_PAYLOAD_SIZE + CRSF_FRAME_LENGTH_TYPE_CRC); | ||||||||||||||||||
| crsfSerialize8(dst, CRSF_FRAMETYPE_BAROMETER_ALTITUDE); | ||||||||||||||||||
|
|
||||||||||||||||||
| 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 ); | ||||||||||||||||||
|
Comment on lines
+299
to
+301
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||
|
|
||||||||||||||||||
| sbufWriteU8(dst, CRSF_FRAME_BAROMETER_ALTITUDE_VARIO_PAYLOAD_SIZE + CRSF_FRAME_LENGTH_TYPE_CRC); | ||||||||||||||||||
| crsfSerialize8(dst, CRSF_FRAMETYPE_BAROMETER_ALTITUDE_VARIO_SENSOR); | ||||||||||||||||||
| crsfSerialize16(dst, altitude_packed); | ||||||||||||||||||
| crsfSerialize8(dst, vario_packed); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| typedef enum { | ||||||||||||||||||
|
|
@@ -463,8 +473,7 @@ typedef enum { | |||||||||||||||||
| CRSF_FRAME_BATTERY_SENSOR_INDEX, | ||||||||||||||||||
| CRSF_FRAME_FLIGHT_MODE_INDEX, | ||||||||||||||||||
| CRSF_FRAME_GPS_INDEX, | ||||||||||||||||||
| CRSF_FRAME_VARIO_SENSOR_INDEX, | ||||||||||||||||||
| CRSF_FRAME_BAROMETER_ALTITUDE_INDEX, | ||||||||||||||||||
| CRSF_FRAME_VARIO_OR_ALT_VARIO_SENSOR_INDEX, | ||||||||||||||||||
| CRSF_SCHEDULE_COUNT_MAX | ||||||||||||||||||
| } crsfFrameTypeIndex_e; | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -534,14 +543,9 @@ static void processCrsf(void) | |||||||||||||||||
| } | ||||||||||||||||||
| #endif | ||||||||||||||||||
| #if defined(USE_BARO) || defined(USE_GPS) | ||||||||||||||||||
| if (currentSchedule & BV(CRSF_FRAME_VARIO_SENSOR_INDEX)) { | ||||||||||||||||||
| crsfInitializeFrame(dst); | ||||||||||||||||||
| crsfFrameVarioSensor(dst); | ||||||||||||||||||
| crsfFinalize(dst); | ||||||||||||||||||
| } | ||||||||||||||||||
| if (currentSchedule & BV(CRSF_FRAME_BAROMETER_ALTITUDE_INDEX)) { | ||||||||||||||||||
| if (currentSchedule & BV(CRSF_FRAME_VARIO_OR_ALT_VARIO_SENSOR_INDEX) ) { | ||||||||||||||||||
| crsfInitializeFrame(dst); | ||||||||||||||||||
| crsfBarometerAltitude(dst); | ||||||||||||||||||
| telemetryConfig()->crsf_use_legacy_baro_packet ? crsfFrameVarioSensor(dst) : crsfFrameBarometerAltitudeVarioSensor(dst); | ||||||||||||||||||
| crsfFinalize(dst); | ||||||||||||||||||
| } | ||||||||||||||||||
| #endif | ||||||||||||||||||
|
|
@@ -575,12 +579,7 @@ void initCrsfTelemetry(void) | |||||||||||||||||
| #endif | ||||||||||||||||||
| #if defined(USE_BARO) || defined(USE_GPS) | ||||||||||||||||||
| if (sensors(SENSOR_BARO) || (STATE(FIXED_WING_LEGACY) && feature(FEATURE_GPS))) { | ||||||||||||||||||
| crsfSchedule[index++] = BV(CRSF_FRAME_VARIO_SENSOR_INDEX); | ||||||||||||||||||
| } | ||||||||||||||||||
| #endif | ||||||||||||||||||
| #ifdef USE_BARO | ||||||||||||||||||
| if (sensors(SENSOR_BARO)) { | ||||||||||||||||||
| crsfSchedule[index++] = BV(CRSF_FRAME_BAROMETER_ALTITUDE_INDEX); | ||||||||||||||||||
| crsfSchedule[index++] = BV(CRSF_FRAME_VARIO_OR_ALT_VARIO_SENSOR_INDEX); | ||||||||||||||||||
| } | ||||||||||||||||||
| #endif | ||||||||||||||||||
| crsfScheduleCount = (uint8_t)index; | ||||||||||||||||||
|
|
@@ -659,7 +658,10 @@ int getCrsfFrame(uint8_t *frame, crsfFrameType_e frameType) | |||||||||||||||||
| case CRSF_FRAMETYPE_VARIO_SENSOR: | ||||||||||||||||||
| crsfFrameVarioSensor(sbuf); | ||||||||||||||||||
| break; | ||||||||||||||||||
| } | ||||||||||||||||||
| case CRSF_FRAMETYPE_BAROMETER_ALTITUDE_VARIO_SENSOR: | ||||||||||||||||||
| crsfFrameBarometerAltitudeVarioSensor(sbuf); | ||||||||||||||||||
| break; | ||||||||||||||||||
| } | ||||||||||||||||||
| const int frameSize = crsfFinalizeBuf(sbuf, frame); | ||||||||||||||||||
| return frameSize; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.hbut lacks the implementation to create and send the airspeed frame incrsf.c. The suggestion is to either complete this feature or remove the partial code. [High-level, importance: 8]Solution Walkthrough:
Before:
After: