Skip to content

Commit

Permalink
keep crsf_stats around
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Nov 5, 2024
1 parent b53e065 commit 54fc444
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/rx/crsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "flight/control.h"
#include "util/crc.h"

crsf_stats_t crsf_stats;

void crsf_tlm_frame_start(uint8_t *buf) {
buf[0] = CRSF_SYNC_BYTE;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rx/crsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ typedef union {
crsf_frame_def_t frame;
} crsf_frame_t;

extern crsf_stats_t crsf_stats;

uint8_t crsf_crc8(uint8_t *data, uint16_t len);

void crsf_tlm_frame_start(uint8_t *buf);
Expand Down
11 changes: 4 additions & 7 deletions src/rx/unified_crsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ extern int32_t channels[16];
extern uint8_t rx_data[RX_BUFF_SIZE];

static uint8_t telemetry_counter = 0;
static uint8_t crsf_rf_mode = 0;

void rx_serial_crsf_msp_send(msp_magic_t magic, uint8_t direction, uint16_t code, const uint8_t *data, uint16_t len);

Expand All @@ -70,7 +69,7 @@ static bool msp_new_data = false;
static bool msp_is_error = false;

float rx_serial_crsf_expected_fps() {
switch (crsf_rf_mode) {
switch (crsf_stats.rf_mode) {
case RATE_FLRC_1000HZ:
return 1000;
case RATE_FLRC_500HZ:
Expand Down Expand Up @@ -104,7 +103,7 @@ float rx_serial_crsf_expected_fps() {
}

static uint16_t telemetry_interval() {
switch (crsf_rf_mode) {
switch (crsf_stats.rf_mode) {
case RATE_LORA_4HZ:
return 3;
case RATE_LORA_25HZ:
Expand Down Expand Up @@ -190,12 +189,10 @@ static packet_status_t rx_serial_crsf_process_frame(uint8_t frame_length) {
}

case CRSF_FRAMETYPE_LINK_STATISTICS: {
const crsf_stats_t *stats = (crsf_stats_t *)&rx_data[1];

crsf_rf_mode = stats->rf_mode;
memcpy(&crsf_stats, &rx_data[1], sizeof(crsf_stats));

if (profile.receiver.lqi_source == RX_LQI_SOURCE_DIRECT) {
rx_lqi_update_direct(stats->uplink_link_quality);
rx_lqi_update_direct(crsf_stats.uplink_link_quality);
}
break;
}
Expand Down

0 comments on commit 54fc444

Please sign in to comment.