Skip to content

Commit

Permalink
feat(telemetry): extend link quality warnings range (#2251)
Browse files Browse the repository at this point in the history
* feat(telemetry): extend link quality warnings range

* Set default values to the old legacy FrSky values

* Companion support
  • Loading branch information
raphaelcoeffic authored and pfeerick committed Oct 12, 2022
1 parent c57fb36 commit 64a87bf
Show file tree
Hide file tree
Showing 34 changed files with 339 additions and 186 deletions.
49 changes: 42 additions & 7 deletions companion/src/firmwares/edgetx/yaml_modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,36 @@ struct convert<ScriptData> {
}
};

struct RFAlarms {
int warning = 0;
int critical = 0;

RFAlarms() {}

RFAlarms(const RSSIAlarmData& rhs)
: warning(rhs.warning), critical(rhs.critical)
{}
};

template <>
struct convert<RSSIAlarmData> {
static Node encode(const RSSIAlarmData& rhs)
struct convert<RFAlarms> {
static Node encode(const RFAlarms& rhs)
{
Node node;
node["disabled"] = (int)rhs.disabled;
node["warning"] = rhs.warning - 45;
node["critical"] = rhs.critical - 42;
node["warning"] = rhs.warning;
node["critical"] = rhs.critical;
return node;
}
static bool decode(const Node& node, RFAlarms& rhs)
{
node["warning"] >> rhs.warning;
node["critical"] >> rhs.critical;
return true;
}
};

template <>
struct convert<RSSIAlarmData> {
static bool decode(const Node& node, RSSIAlarmData& rhs)
{
node["disabled"] >> rhs.disabled;
Expand Down Expand Up @@ -904,7 +923,8 @@ Node convert<ModelData>::encode(const ModelData& rhs)
node["altitudeSource"] = YamlTelemSource(rhs.frsky.altitudeSource);
}

node["rssiAlarms"] = rhs.rssiAlarms;
node["rfAlarms"] = RFAlarms(rhs.rssiAlarms);
node["disableTelemetryWarning"] = (int)rhs.rssiAlarms.disabled;

for (int i=0; i<CPN_MAX_MODULES; i++) {
if (rhs.moduleData[i].protocol != PULSES_OFF) {
Expand Down Expand Up @@ -1096,7 +1116,22 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
rhs.frsky.altitudeSource = altitudeSource.src;
}

node["rssiAlarms"] >> rhs.rssiAlarms;
if (node["rssiAlarms"]) {
// Old format (pre 2.8)
node["rssiAlarms"] >> rhs.rssiAlarms;
} else if (node["rfAlarms"] || node["disableTelemetryWarning"]) {
// New format (post 2.8)
RFAlarms rfAlarms;
node["rfAlarms"] >> rfAlarms;
rhs.rssiAlarms.warning = rfAlarms.warning;
rhs.rssiAlarms.critical = rfAlarms.critical;
node["disableTelemetryWarning"] >> rhs.rssiAlarms.disabled;
} else {
// Use old defaults
rhs.rssiAlarms.warning = 45;
rhs.rssiAlarms.critical = 42;
rhs.rssiAlarms.disabled = false;
}

node["moduleData"] >> rhs.moduleData;
for (int i=0; i<CPN_MAX_MODULES; i++) {
Expand Down
4 changes: 2 additions & 2 deletions companion/src/modeledit/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ void TelemetryPanel::setup()
ui->ignoreSensorIds->setField(model->frsky.ignoreSensorIds, this);
ui->disableTelemetryAlarms->setField(model->rssiAlarms.disabled);

ui->rssiAlarmWarningSB->setRange(45 - 30, 45 + 30);
ui->rssiAlarmWarningSB->setRange(0, 127);
ui->rssiAlarmWarningSB->setValue(model->rssiAlarms.warning);
ui->rssiAlarmCriticalSB->setRange(42 - 30, 42 + 30);
ui->rssiAlarmCriticalSB->setRange(0, 127);
ui->rssiAlarmCriticalSB->setValue(model->rssiAlarms.critical);

ui->rssiSourceLabel->show();
Expand Down
2 changes: 1 addition & 1 deletion radio/src/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static inline void check_struct()
CHKSIZE(TelemetrySensor, 14);
CHKSIZE(ModuleData, 29);
CHKSIZE(GVarData, 7);
CHKSIZE(RssiAlarmData, 2);
CHKSIZE(RFAlarmData, 2);
CHKSIZE(TrainerData, 16);

#if defined(PCBXLITES)
Expand Down
34 changes: 19 additions & 15 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,21 @@ PACK(struct ScriptData {
#endif

/*
* Frsky Telemetry structure
* Frsky Telemetry structure (legacy read-only)
*/
PACK(struct RssiAlarmData {
int8_t disabled:1;
#if defined (PCBNV14)
uint8_t flysky_telemetry:1; // if set for FlySky receivers use native RSSI values instead of rescaled ones
#else
int8_t spare:1 SKIP;
#endif
int8_t warning:6;
int8_t spare2:2 SKIP;
int8_t critical:6;
inline int8_t getWarningRssi() {return 45 + warning;}
inline int8_t getCriticalRssi() {return 42 + critical;}
});
// int8_t disabled:1;
CUST_ATTR(disabled,r_rssiDisabled,nullptr);
// int8_t warning:6; + 45
CUST_ATTR(warning,r_rssiWarning,nullptr);
// int8_t critical:6; + 42
CUST_ATTR(critical,r_rssiCritical,nullptr);
});

PACK(struct RFAlarmData {
int8_t warning;
int8_t critical;
});

typedef int16_t ls_telemetry_value_t;

Expand Down Expand Up @@ -638,7 +638,8 @@ PACK(struct ModelData {
uint8_t extendedTrims:1;
uint8_t throttleReversed:1;
uint8_t enableCustomThrottleWarning:1;
uint8_t spare3:7 SKIP;
uint8_t disableTelemetryWarning:1;
uint8_t spare3:6 SKIP;
int8_t customThrottleWarningPosition;
BeepANACenter beepANACenter;
MixData mixData[MAX_MIXERS] NO_IDX;
Expand All @@ -664,7 +665,10 @@ PACK(struct ModelData {

TOPBAR_DATA

NOBACKUP(RssiAlarmData rssiAlarms);
#if defined(YAML_GENERATOR)
RssiAlarmData rssiAlarms;
#endif
NOBACKUP(RFAlarmData rfAlarms);

uint8_t thrTrimSw:3;
uint8_t potsWarnMode:2 ENUM(PotsWarnMode);
Expand Down
8 changes: 4 additions & 4 deletions radio/src/gui/128x64/model_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,18 @@ void menuModelTelemetry(event_t event)
{
bool warning = (k==ITEM_TELEMETRY_RSSI_ALARM1);
lcdDrawTextAlignedLeft(y, (warning ? STR_LOWALARM : STR_CRITICALALARM));
lcdDrawNumber(TELEM_COL3, y, warning? g_model.rssiAlarms.getWarningRssi() : g_model.rssiAlarms.getCriticalRssi(), attr, 3);
lcdDrawNumber(TELEM_COL3, y, warning? g_model.rfAlarms.warning : g_model.rfAlarms.critical, attr, 3);
if (attr && s_editMode>0) {
if (warning)
CHECK_INCDEC_MODELVAR(event, g_model.rssiAlarms.warning, -30, 30);
CHECK_INCDEC_MODELVAR(event, g_model.rfAlarms.warning, 0, 100);
else
CHECK_INCDEC_MODELVAR(event, g_model.rssiAlarms.critical, -30, 30);
CHECK_INCDEC_MODELVAR(event, g_model.rfAlarms.critical, 0, 100);
}
break;
}

case ITEM_TELEMETRY_DISABLE_ALARMS:
g_model.rssiAlarms.disabled = editCheckBox(g_model.rssiAlarms.disabled, TELEM_COL3, y, STR_DISABLE_ALARM, attr, event);
g_model.disableTelemetryWarning = editCheckBox(g_model.disableTelemetryWarning, TELEM_COL3, y, STR_DISABLE_ALARM, attr, event);
break;

#if defined(VARIO)
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void drawExternalAntennaAndRSSI()
#endif

if (TELEMETRY_RSSI() > 0) {
auto warningRSSI = g_model.rssiAlarms.getWarningRssi();
auto warningRSSI = g_model.rfAlarms.warning;
int8_t value = TELEMETRY_RSSI() - warningRSSI;
uint8_t step = (RSSI_MAX - warningRSSI) / 4;
for (uint8_t i = 1; i < 5; i++) {
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/view_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void displayRssiLine()
lcdDrawText(lcdLastLeftPos,STATUS_BAR_Y, "RSSI : ", RIGHT | SMLSIZE);
lcdDrawRect(65, 57, 38, 7);
uint8_t v = 4*rssi/11;
lcdDrawFilledRect(66+36-v, 58, v, 5, (rssi < g_model.rssiAlarms.getWarningRssi()) ? DOTTED : SOLID);
lcdDrawFilledRect(66+36-v, 58, v, 5, (rssi < g_model.rfAlarms.warning) ? DOTTED : SOLID);
}
else {
lcdDrawText(7*FW, STATUS_BAR_Y, STR_NODATA, BLINK);
Expand Down
8 changes: 4 additions & 4 deletions radio/src/gui/212x64/model_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ void menuModelTelemetry(event_t event)
{
bool warning = (k==ITEM_TELEMETRY_RSSI_ALARM1);
lcdDrawTextAlignedLeft(y, (warning ? STR_LOWALARM : STR_CRITICALALARM));
lcdDrawNumber(TELEM_COL2, y, warning? g_model.rssiAlarms.getWarningRssi() : g_model.rssiAlarms.getCriticalRssi(), LEFT|attr, 3);
lcdDrawNumber(TELEM_COL2, y, warning? g_model.rfAlarms.warning : g_model.rfAlarms.critical, LEFT|attr, 3);
if (attr && s_editMode>0) {
if (warning)
CHECK_INCDEC_MODELVAR(event, g_model.rssiAlarms.warning, -30, 30);
CHECK_INCDEC_MODELVAR(event, g_model.rfAlarms.warning, 0, 100);
else
CHECK_INCDEC_MODELVAR(event, g_model.rssiAlarms.critical, -30, 30);
CHECK_INCDEC_MODELVAR(event, g_model.rfAlarms.critical, 0, 100);
}
break;
}

case ITEM_TELEMETRY_DISABLE_ALARMS:
g_model.rssiAlarms.disabled = editCheckBox(g_model.rssiAlarms.disabled, TELEM_COL3, y, STR_DISABLE_ALARM, attr, event);
g_model.disableTelemetryWarning = editCheckBox(g_model.disableTelemetryWarning, TELEM_COL3, y, STR_DISABLE_ALARM, attr, event);
break;

#if defined(VARIO)
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/212x64/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void displayTopBar()

/* The inside of the RSSI gauge */
if (TELEMETRY_RSSI() > 0) {
displayTopBarGauge(batt_icon_x+5*FW, TELEMETRY_RSSI() / 10, TELEMETRY_RSSI() < g_model.rssiAlarms.getWarningRssi());
displayTopBarGauge(batt_icon_x+5*FW, TELEMETRY_RSSI() / 10, TELEMETRY_RSSI() < g_model.rfAlarms.warning);
}
}

Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/212x64/view_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void displayRssiLine()
lcdDrawSizedText(0, STATUS_BAR_Y, STR_RX, 2);
lcdDrawNumber(4*FW, STATUS_BAR_Y, rssi, LEADING0|RIGHT, 2);
lcdDrawRect(BAR_LEFT, 57, 78, 7);
lcdDrawFilledRect(BAR_LEFT+1, 58, 19*rssi/25, 5, (rssi < g_model.rssiAlarms.getWarningRssi()) ? DOTTED : SOLID);
lcdDrawFilledRect(BAR_LEFT+1, 58, 19*rssi/25, 5, (rssi < g_model.rfAlarms.warning) ? DOTTED : SOLID);
}
else {
lcdDrawText(7*FW, STATUS_BAR_Y, STR_NODATA, BLINK);
Expand Down
15 changes: 5 additions & 10 deletions radio/src/gui/colorlcd/model_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,17 @@ void ModelTelemetryPage::build(FormWindow * window, int8_t focusSensorIndex)
grid.nextLine();

new StaticText(window, grid.getLabelSlot(true), STR_LOWALARM, 0, COLOR_THEME_PRIMARY1);
auto edit = new NumberEdit(window, grid.getFieldSlot(), -30, 30, GET_SET_DEFAULT(g_model.rssiAlarms.warning));
edit->setDisplayHandler([](int32_t value) {
return std::to_string(g_model.rssiAlarms.getWarningRssi());
});
// window->setFirstField(edit);
auto edit = new NumberEdit(window, grid.getFieldSlot(), 0, 100,
GET_SET_DEFAULT(g_model.rfAlarms.warning));
grid.nextLine();

new StaticText(window, grid.getLabelSlot(true), STR_CRITICALALARM, 0, COLOR_THEME_PRIMARY1);
edit = new NumberEdit(window, grid.getFieldSlot(), -30, 30, GET_SET_DEFAULT(g_model.rssiAlarms.critical));
edit->setDisplayHandler([](int32_t value) {
return std::to_string(g_model.rssiAlarms.getCriticalRssi());
});
edit = new NumberEdit(window, grid.getFieldSlot(), 0, 100,
GET_SET_DEFAULT(g_model.rfAlarms.critical));
grid.nextLine();

new StaticText(window, grid.getLabelSlot(true), STR_DISABLE_ALARM, 0, COLOR_THEME_PRIMARY1);
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_model.rssiAlarms.disabled));
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_model.disableTelemetryWarning));
grid.nextLine();

if (LCD_W < LCD_H) grid.nextLine();
Expand Down
4 changes: 2 additions & 2 deletions radio/src/lua/api_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1890,8 +1890,8 @@ static int luaGetRSSI(lua_State * L)
lua_pushunsigned(L, min((uint8_t)99, TELEMETRY_RSSI()));
else
lua_pushunsigned(L, 0);
lua_pushunsigned(L, g_model.rssiAlarms.getWarningRssi());
lua_pushunsigned(L, g_model.rssiAlarms.getCriticalRssi());
lua_pushunsigned(L, g_model.rfAlarms.warning);
lua_pushunsigned(L, g_model.rfAlarms.critical);
return 3;
}

Expand Down
10 changes: 10 additions & 0 deletions radio/src/model_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ void setDefaultGVars()
#endif
}

void setDefaultRSSIValues()
{
// Set to legacy FrSky values until
// a better solution is found (module specific?)
//
g_model.rfAlarms.warning = 45;
g_model.rfAlarms.critical = 42;
}

void setVendorSpecificModelDefaults(uint8_t id)
{
#if defined(FRSKY_RELEASE)
Expand Down Expand Up @@ -108,6 +117,7 @@ void applyDefaultTemplate()
setDefaultInputs();
setDefaultMixes();
setDefaultGVars();
setDefaultRSSIValues();

setDefaultModelRegistrationID();

Expand Down
25 changes: 25 additions & 0 deletions radio/src/storage/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,31 @@ static bool w_mixSrcRaw(const YamlNode* node, uint32_t val, yaml_writer_func wf,
return true;
}

static void r_rssiDisabled(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
data += bitoffs >> 3UL;
data -= offsetof(ModelData, rfAlarms);
auto md = reinterpret_cast<ModelData*>(data);
md->disableTelemetryWarning = yaml_str2int(val, val_len);
}

static void r_rssiWarning(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
data += bitoffs >> 3UL;
auto rf_alarm = reinterpret_cast<RFAlarmData*>(data);
rf_alarm->warning = yaml_str2int(val, val_len) + 45;
}

static void r_rssiCritical(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
data += bitoffs >> 3UL;
auto rf_alarm = reinterpret_cast<RFAlarmData*>(data);
rf_alarm->critical = yaml_str2int(val, val_len) + 42;
}

static uint32_t r_vbat_min(const YamlNode* node, const char* val, uint8_t val_len)
{
int32_t v = yaml_str2int(val, val_len);
Expand Down
19 changes: 12 additions & 7 deletions radio/src/storage/yaml/yaml_datastructs_lr3pro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,14 @@ static const struct YamlNode struct_VarioData[] = {
YAML_END
};
static const struct YamlNode struct_RssiAlarmData[] = {
YAML_SIGNED( "disabled", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "warning", 6 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "critical", 6 ),
YAML_CUSTOM("disabled",r_rssiDisabled,nullptr),
YAML_CUSTOM("warning",r_rssiWarning,nullptr),
YAML_CUSTOM("critical",r_rssiCritical,nullptr),
YAML_END
};
static const struct YamlNode struct_RFAlarmData[] = {
YAML_SIGNED( "warning", 8 ),
YAML_SIGNED( "critical", 8 ),
YAML_END
};
static const struct YamlNode struct_PpmModule[] = {
Expand Down Expand Up @@ -822,7 +825,8 @@ static const struct YamlNode struct_ModelData[] = {
YAML_UNSIGNED( "extendedTrims", 1 ),
YAML_UNSIGNED( "throttleReversed", 1 ),
YAML_UNSIGNED( "enableCustomThrottleWarning", 1 ),
YAML_PADDING( 7 ),
YAML_UNSIGNED( "disableTelemetryWarning", 1 ),
YAML_PADDING( 6 ),
YAML_SIGNED( "customThrottleWarningPosition", 8 ),
YAML_UNSIGNED( "beepANACenter", 16 ),
YAML_ARRAY("mixData", 160, 64, struct_MixData, NULL),
Expand All @@ -840,7 +844,8 @@ static const struct YamlNode struct_ModelData[] = {
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ),
YAML_STRUCT("rssiAlarms", 16, struct_RssiAlarmData, NULL),
YAML_STRUCT("rssiAlarms", 0, struct_RssiAlarmData, NULL),
YAML_STRUCT("rfAlarms", 16, struct_RFAlarmData, NULL),
YAML_UNSIGNED( "thrTrimSw", 3 ),
YAML_ENUM("potsWarnMode", 2, enum_PotsWarnMode),
YAML_ENUM("jitterFilter", 2, enum_ModelOverridableEnable),
Expand Down
Loading

0 comments on commit 64a87bf

Please sign in to comment.