Skip to content

Commit 5af0952

Browse files
shota3527error414
authored andcommitted
Refactor telemetry sensors for SmartPort and Crsf
* add new scheduler for telemetry sensors * used new frsky sensors Not used temp sensor for roll etc... anymore * add custome telemetry sensors for CRSF
1 parent db16f53 commit 5af0952

File tree

20 files changed

+1195
-656
lines changed

20 files changed

+1195
-656
lines changed

docs/Settings.md

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,36 @@ Control rate profile to switch to when the battery profile is selected, 0 to dis
592592

593593
---
594594

595+
### crsf_telemetry_link_rate
596+
597+
CRSF telemetry link rate
598+
599+
| Default | Min | Max |
600+
| --- | --- | --- |
601+
| 250 | 0 | 50000 |
602+
603+
---
604+
605+
### crsf_telemetry_link_ratio
606+
607+
CRSF telemetry link ratio
608+
609+
| Default | Min | Max |
610+
| --- | --- | --- |
611+
| 8 | 0 | 50000 |
612+
613+
---
614+
615+
### crsf_telemetry_mode
616+
617+
Use extended custom telemetry sensors for CRSF
618+
619+
| Default | Min | Max |
620+
| --- | --- | --- |
621+
| NATIVE | | |
622+
623+
---
624+
595625
### cruise_power
596626

597627
Power draw at cruise throttle used for remaining flight time/distance estimation in 0.01W unit
@@ -1192,26 +1222,6 @@ The tilt angle of the FPV camera in degrees, used by the FPV ANGLE MIX mode
11921222

11931223
---
11941224

1195-
### frsky_pitch_roll
1196-
1197-
S.Port telemetry: Send pitch and roll degrees*10 instead of raw accelerometer data
1198-
1199-
| Default | Min | Max |
1200-
| --- | --- | --- |
1201-
| OFF | OFF | ON |
1202-
1203-
---
1204-
1205-
### frsky_use_legacy_gps_mode_sensor_ids
1206-
1207-
S.Port telemetry: If `ON`, send the legacy telemetry IDs for modes (Tmp1) and GNSS (Tmp2). These are old IDs, deprecated, and will be removed in INAV 10.0. Tools and scripts using these IDs should be updated to use the new IDs of **470** for Modes and **480** for GNSS. Default: 'OFF'
1208-
1209-
| Default | Min | Max |
1210-
| --- | --- | --- |
1211-
| OFF | OFF | ON |
1212-
1213-
---
1214-
12151225
### fw_autotune_max_rate_deflection
12161226

12171227
The target percentage of maximum mixer output used for determining the rates in `AUTO` and `LIMIT`.

src/main/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ main_sources(COMMON_SRC
626626
telemetry/sim.h
627627
telemetry/telemetry.c
628628
telemetry/telemetry.h
629+
telemetry/sensors.c
630+
telemetry/sensors.h
629631
)
630632

631633
add_subdirectory(target)

src/main/common/crc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,18 @@ uint8_t crc8_sum_update(uint8_t crc, const void *data, uint32_t length)
142142
crc += *p;
143143
}
144144
return crc;
145+
}
146+
147+
// Fowler–Noll–Vo hash function; see https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function
148+
uint32_t fnv_update(uint32_t hash, const void *data, uint32_t length)
149+
{
150+
const uint8_t *ptr = data;
151+
const uint8_t *pend = ptr + length;
152+
153+
while (ptr != pend) {
154+
hash *= FNV_PRIME;
155+
hash ^= *ptr++;
156+
}
157+
158+
return hash;
145159
}

src/main/common/crc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <stdint.h>
2121

22+
#define FNV_PRIME 16777619
23+
2224
struct sbuf_s;
2325

2426
uint16_t crc16_ccitt(uint16_t crc, unsigned char a);
@@ -35,4 +37,7 @@ void crc8_xor_sbuf_append(struct sbuf_s *dst, uint8_t *start);
3537
uint8_t crc8(uint8_t crc, uint8_t a);
3638
uint8_t crc8_update(uint8_t crc, const void *data, uint32_t length);
3739

38-
uint8_t crc8_sum_update(uint8_t crc, const void *data, uint32_t length);
40+
uint8_t crc8_sum_update(uint8_t crc, const void *data, uint32_t length);
41+
42+
uint32_t fnv_update(uint32_t hash, const void *data, uint32_t length);
43+

src/main/fc/fc_core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ static void updateArmingStatus(void)
203203
if (ARMING_FLAG(ARMED)) {
204204
LED0_ON;
205205
} else {
206+
207+
// Check if the power on arming grace time has elapsed
208+
if ((isArmingDisabledReason() & ARMING_DISABLED_BOOT_GRACE_TIME) && (millis() >= 3000)) {
209+
// If so, unset the grace time arming disable flag
210+
DISABLE_ARMING_FLAG(ARMING_DISABLED_BOOT_GRACE_TIME);
211+
}
212+
206213
/* CHECK: Run-time calibration */
207214
static bool calibratingFinishedBeep = false;
208215
if (areSensorsCalibrating()) {

src/main/fc/fc_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ void init(void)
611611
}
612612
#endif
613613

614+
ENABLE_ARMING_FLAG(ARMING_DISABLED_BOOT_GRACE_TIME);
615+
614616
#ifdef USE_BLACKBOX
615617

616618
//Do not allow blackbox to be run faster that 1kHz. It can cause UAV to drop dead when digital ESC protocol is used

src/main/fc/runtime_config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ const armingFlag_e armDisableReasonsChecklist[] = {
5858
ARMING_DISABLED_SERVO_AUTOTRIM,
5959
ARMING_DISABLED_OOM,
6060
ARMING_DISABLED_NO_PREARM,
61-
ARMING_DISABLED_DSHOT_BEEPER
61+
ARMING_DISABLED_DSHOT_BEEPER,
62+
ARMING_DISABLED_BOOT_GRACE_TIME
6263
};
6364

6465
armingFlag_e isArmingDisabledReason(void)

src/main/fc/runtime_config.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef enum {
4848
ARMING_DISABLED_NO_PREARM = (1 << 28),
4949
ARMING_DISABLED_DSHOT_BEEPER = (1 << 29),
5050
ARMING_DISABLED_LANDING_DETECTED = (1 << 30),
51+
ARMING_DISABLED_BOOT_GRACE_TIME = (1 << 31),
5152

5253
ARMING_DISABLED_ALL_FLAGS = (ARMING_DISABLED_GEOZONE | ARMING_DISABLED_FAILSAFE_SYSTEM | ARMING_DISABLED_NOT_LEVEL |
5354
ARMING_DISABLED_SENSORS_CALIBRATING | ARMING_DISABLED_SYSTEM_OVERLOADED | ARMING_DISABLED_NAVIGATION_UNSAFE |
@@ -57,7 +58,7 @@ typedef enum {
5758
ARMING_DISABLED_CMS_MENU | ARMING_DISABLED_OSD_MENU | ARMING_DISABLED_ROLLPITCH_NOT_CENTERED |
5859
ARMING_DISABLED_SERVO_AUTOTRIM | ARMING_DISABLED_OOM | ARMING_DISABLED_INVALID_SETTING |
5960
ARMING_DISABLED_PWM_OUTPUT_ERROR | ARMING_DISABLED_NO_PREARM | ARMING_DISABLED_DSHOT_BEEPER |
60-
ARMING_DISABLED_LANDING_DETECTED),
61+
ARMING_DISABLED_LANDING_DETECTED | ARMING_DISABLED_BOOT_GRACE_TIME),
6162
} armingFlag_e;
6263

6364
// Arming blockers that can be overriden by emergency arming.
@@ -71,7 +72,9 @@ typedef enum {
7172
| ARMING_DISABLED_COMPASS_NOT_CALIBRATED \
7273
| ARMING_DISABLED_ACCELEROMETER_NOT_CALIBRATED \
7374
| ARMING_DISABLED_ARM_SWITCH \
74-
| ARMING_DISABLED_HARDWARE_FAILURE)
75+
| ARMING_DISABLED_HARDWARE_FAILURE \
76+
| ARMING_DISABLED_BOOT_GRACE_TIME \
77+
)
7578

7679

7780
extern uint32_t armingFlags;

src/main/fc/settings.yaml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ tables:
103103
- name: bat_voltage_source
104104
values: ["RAW", "SAG_COMP"]
105105
enum: batVoltageSource_e
106+
- name: crsf_telemetry_modes
107+
values: [ "OFF", "NATIVE", "CUSTOM" ]
108+
enum: crsfTelemetryMode_e
106109
- name: smartport_fuel_unit
107110
values: ["PERCENT", "MAH", "MWH"]
108111
enum: smartportFuelUnit_e
@@ -3113,14 +3116,24 @@ groups:
31133116
description: "Determines if the telemetry protocol default signal inversion is reversed. This should be OFF in most cases unless a custom or hacked RX is used."
31143117
default_value: OFF
31153118
type: bool
3116-
- name: frsky_pitch_roll
3117-
description: "S.Port telemetry: Send pitch and roll degrees*10 instead of raw accelerometer data"
3118-
default_value: OFF
3119-
type: bool
3120-
- name: frsky_use_legacy_gps_mode_sensor_ids
3121-
description: "S.Port telemetry: If `ON`, send the legacy telemetry IDs for modes (Tmp1) and GNSS (Tmp2). These are old IDs, deprecated, and will be removed in INAV 10.0. Tools and scripts using these IDs should be updated to use the new IDs of **470** for Modes and **480** for GNSS. Default: 'OFF'"
3122-
default_value: OFF
3123-
type: bool
3119+
- name: crsf_telemetry_mode
3120+
description: "Use extended custom telemetry sensors for CRSF"
3121+
default_value: NATIVE
3122+
condition: USE_TELEMETRY_LTM
3123+
table: crsf_telemetry_modes
3124+
type: uint8_t
3125+
- name: crsf_telemetry_link_rate
3126+
description: "CRSF telemetry link rate"
3127+
default_value: 250
3128+
type: uint16_t
3129+
min: 0
3130+
max: 50000
3131+
- name: crsf_telemetry_link_ratio
3132+
description: "CRSF telemetry link ratio"
3133+
default_value: 8
3134+
type: uint16_t
3135+
min: 0
3136+
max: 50000
31243137
- name: report_cell_voltage
31253138
description: "S.Port and IBUS telemetry: Send the average cell voltage if set to ON"
31263139
default_value: OFF

src/main/io/osd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,8 @@ static const char * osdArmingDisabledReasonMessage(void)
966966
// Cases without message
967967
case ARMING_DISABLED_LANDING_DETECTED:
968968
FALLTHROUGH;
969+
case ARMING_DISABLED_BOOT_GRACE_TIME:
970+
FALLTHROUGH;
969971
case ARMING_DISABLED_CMS_MENU:
970972
FALLTHROUGH;
971973
case ARMING_DISABLED_OSD_MENU:

0 commit comments

Comments
 (0)