Skip to content

Commit

Permalink
radio link stats: handle RSSI_DBM slightly better
Browse files Browse the repository at this point in the history
  • Loading branch information
olliw42 committed Dec 31, 2023
1 parent 1b4a4cb commit 0a26282
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 9 additions & 6 deletions libraries/AP_RCProtocol/AP_RCProtocol_MavlinkRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ void AP_RCProtocol_MAVLinkRadio::update_radio_link_stats(const mavlink_radio_lin
}

if (packet->flags & RADIO_LINK_STATS_FLAGS_RSSI_DBM) {
// rssi is in dBm, convert to AP rssi using the same logic as in CRSF driver
// AP rssi: -1 for unknown, 0 for no link, 255 for maximum link
if (_rssi < 50) {
// rssi is in negative dBm, 255 = unknown, 254 = no link connection, 0...253 = 0...-253 dBm
// convert to AP rssi using the same logic as in CRSF driver
// AP rssi: -1 for unknown, 0 for no link connection, 255 for maximum link
if (_rssi == 254) {
rssi = 0; // no connection
} else if (_rssi < 50) {
rssi = 255;
} else if (_rssi > 120) {
rssi = 0;
rssi = 1; // connection, but very low rssi
} else {
rssi = int16_t(roundf((1.0f - (_rssi - 50.0f) / 70.0f) * 255.0f));
rssi = int16_t(roundf((1.0f - ((float)_rssi - 50.0f) / 70.0f) * 255.0f));
}
} else {
// _rssi is 0..254, scale it to 0..255 with rounding
// _rssi is in mavlink scale 0..254, scale it to 0..255 with rounding
rssi = (_rssi * 255 + 127) / 254;
}
}
Expand Down
3 changes: 0 additions & 3 deletions libraries/AP_RSSI/AP_RSSI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ class AP_RSSI

// return true if rssi reading is enabled
bool enabled() const { return RssiType(rssi_type.get()) != RssiType::TYPE_DISABLED; }
//OW RADIOLINK
bool enabled(RssiType type) const { return RssiType(rssi_type.get()) == type; }
//OWEND

// Read the receiver RSSI value as a float 0.0f - 1.0f.
// 0.0 represents weakest signal, 1.0 represents maximum signal.
Expand Down

0 comments on commit 0a26282

Please sign in to comment.