Skip to content

Commit bc814f3

Browse files
authored
Merge pull request #10215 from iNavFlight/mmosca-mavlinkrc
Further tweaks to mavlink
2 parents 9540a46 + dabdeea commit bc814f3

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

docs/Settings.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,16 @@ Rate of the extra3 message for MAVLink telemetry
25522552

25532553
---
25542554

2555+
### mavlink_min_txbuffer
2556+
2557+
Minimum percent of TX buffer space free, before attempting to transmit telemetry. Requuires RADIO_STATUS messages to be processed. 0 = always transmits.
2558+
2559+
| Default | Min | Max |
2560+
| --- | --- | --- |
2561+
| 33 | 0 | 100 |
2562+
2563+
---
2564+
25552565
### mavlink_pos_rate
25562566

25572567
Rate of the position message for MAVLink telemetry
@@ -2562,6 +2572,16 @@ Rate of the position message for MAVLink telemetry
25622572

25632573
---
25642574

2575+
### mavlink_radio_type
2576+
2577+
Mavlink radio type. Affects how RSSI and LQ are reported on OSD.
2578+
2579+
| Default | Min | Max |
2580+
| --- | --- | --- |
2581+
| GENERIC | | |
2582+
2583+
---
2584+
25652585
### mavlink_rc_chan_rate
25662586

25672587
Rate of the RC channels message for MAVLink telemetry

src/main/fc/settings.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ tables:
198198
- name: headtracker_dev_type
199199
values: ["NONE", "SERIAL", "MSP"]
200200
enum: headTrackerDevType_e
201+
- name: mavlink_radio_type
202+
values: ["GENERIC", "ELRS", "SIK"]
203+
enum: mavlinkRadio_e
201204

202205
constants:
203206
RPYL_PID_MIN: 0
@@ -3195,6 +3198,18 @@ groups:
31953198
min: 1
31963199
max: 2
31973200
default_value: 2
3201+
- name: mavlink_min_txbuffer
3202+
field: mavlink.min_txbuff
3203+
description: "Minimum percent of TX buffer space free, before attempting to transmit telemetry. Requuires RADIO_STATUS messages to be processed. 0 = always transmits."
3204+
default_value: 33
3205+
min: 0
3206+
max: 100
3207+
- name: mavlink_radio_type
3208+
description: "Mavlink radio type. Affects how RSSI and LQ are reported on OSD."
3209+
field: mavlink.radio_type
3210+
table: mavlink_radio_type
3211+
default_value: "GENERIC"
3212+
type: uint8_t
31983213

31993214
- name: PG_OSD_CONFIG
32003215
type: osdConfig_t

src/main/telemetry/mavlink.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,11 +1126,39 @@ static bool handleIncoming_PARAM_REQUEST_LIST(void) {
11261126
return true;
11271127
}
11281128

1129+
static void mavlinkParseRxStats(const mavlink_radio_status_t *msg) {
1130+
switch(telemetryConfig()->mavlink.radio_type) {
1131+
case MAVLINK_RADIO_SIK:
1132+
// rssi scaling info from: https://ardupilot.org/rover/docs/common-3dr-radio-advanced-configuration-and-technical-information.html
1133+
rxLinkStatistics.uplinkRSSI = (msg->rssi / 1.9) - 127;
1134+
rxLinkStatistics.uplinkSNR = msg->noise / 1.9;
1135+
rxLinkStatistics.uplinkLQ = msg->rssi != 255 ? scaleRange(msg->rssi, 0, 254, 0, 100) : 0;
1136+
break;
1137+
case MAVLINK_RADIO_ELRS:
1138+
rxLinkStatistics.uplinkRSSI = -msg->remrssi;
1139+
rxLinkStatistics.uplinkSNR = msg->noise;
1140+
rxLinkStatistics.uplinkLQ = scaleRange(msg->rssi, 0, 255, 0, 100);
1141+
break;
1142+
case MAVLINK_RADIO_GENERIC:
1143+
default:
1144+
rxLinkStatistics.uplinkRSSI = msg->rssi;
1145+
rxLinkStatistics.uplinkSNR = msg->noise;
1146+
rxLinkStatistics.uplinkLQ = msg->rssi != 255 ? scaleRange(msg->rssi, 0, 254, 0, 100) : 0;
1147+
break;
1148+
}
1149+
}
1150+
11291151
static bool handleIncoming_RADIO_STATUS(void) {
11301152
mavlink_radio_status_t msg;
11311153
mavlink_msg_radio_status_decode(&mavRecvMsg, &msg);
11321154
txbuff_valid = true;
11331155
txbuff_free = msg.txbuf;
1156+
1157+
if (rxConfig()->receiverType == RX_TYPE_SERIAL &&
1158+
rxConfig()->serialrx_provider == SERIALRX_MAVLINK) {
1159+
mavlinkParseRxStats(&msg);
1160+
}
1161+
11341162
return true;
11351163
}
11361164

@@ -1227,7 +1255,7 @@ static bool processMAVLinkIncomingTelemetry(void)
12271255
#endif
12281256
case MAVLINK_MSG_ID_RADIO_STATUS:
12291257
handleIncoming_RADIO_STATUS();
1230-
// Don't set that we handled a message, otherwise radio status packets will block telemetry messages
1258+
// Don't set that we handled a message, otherwise radio status packets will block telemetry messages.
12311259
return false;
12321260
default:
12331261
return false;
@@ -1260,7 +1288,7 @@ void handleMAVLinkTelemetry(timeUs_t currentTimeUs)
12601288
// Determine whether to send telemetry back based on flow control / pacing
12611289
if (txbuff_valid) {
12621290
// Use flow control if available
1263-
shouldSendTelemetry = txbuff_free >= 33;
1291+
shouldSendTelemetry = txbuff_free >= telemetryConfig()->mavlink.min_txbuff;
12641292
} else {
12651293
// If not, use blind frame pacing - and back off for collision avoidance if half-duplex
12661294
bool halfDuplexBackoff = (isMAVLinkTelemetryHalfDuplex() && receivedMessage);

src/main/telemetry/telemetry.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#include "telemetry/ghst.h"
5757

5858

59-
PG_REGISTER_WITH_RESET_TEMPLATE(telemetryConfig_t, telemetryConfig, PG_TELEMETRY_CONFIG, 6);
59+
PG_REGISTER_WITH_RESET_TEMPLATE(telemetryConfig_t, telemetryConfig, PG_TELEMETRY_CONFIG, 8);
6060

6161
PG_RESET_TEMPLATE(telemetryConfig_t, telemetryConfig,
6262
.telemetry_switch = SETTING_TELEMETRY_SWITCH_DEFAULT,
@@ -93,7 +93,9 @@ PG_RESET_TEMPLATE(telemetryConfig_t, telemetryConfig,
9393
.extra1_rate = SETTING_MAVLINK_EXTRA1_RATE_DEFAULT,
9494
.extra2_rate = SETTING_MAVLINK_EXTRA2_RATE_DEFAULT,
9595
.extra3_rate = SETTING_MAVLINK_EXTRA3_RATE_DEFAULT,
96-
.version = SETTING_MAVLINK_VERSION_DEFAULT
96+
.version = SETTING_MAVLINK_VERSION_DEFAULT,
97+
.min_txbuff = SETTING_MAVLINK_MIN_TXBUFFER_DEFAULT,
98+
.radio_type = SETTING_MAVLINK_RADIO_TYPE_DEFAULT
9799
}
98100
);
99101

src/main/telemetry/telemetry.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ typedef enum {
3636
LTM_RATE_SLOW
3737
} ltmUpdateRate_e;
3838

39+
typedef enum {
40+
MAVLINK_RADIO_GENERIC,
41+
MAVLINK_RADIO_ELRS,
42+
MAVLINK_RADIO_SIK,
43+
} mavlinkRadio_e;
44+
3945
typedef enum {
4046
SMARTPORT_FUEL_UNIT_PERCENT,
4147
SMARTPORT_FUEL_UNIT_MAH,
@@ -73,6 +79,8 @@ typedef struct telemetryConfig_s {
7379
uint8_t extra2_rate;
7480
uint8_t extra3_rate;
7581
uint8_t version;
82+
uint8_t min_txbuff;
83+
uint8_t radio_type;
7684
} mavlink;
7785
} telemetryConfig_t;
7886

0 commit comments

Comments
 (0)