From 13dee00eed6c474a74427792166de844ccca3e78 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 5 Sep 2019 17:24:48 +0200 Subject: [PATCH] Bsongis/rssi from 2 different modules (#6711) RSSI from 2 different modules --- radio/src/datastructs.h | 16 ++++--- radio/src/fonts.h | 2 +- .../src/gui/128x64/model_telemetry_sensor.cpp | 18 ++++++-- .../src/gui/212x64/model_telemetry_sensor.cpp | 33 +++++++++++++- .../gui/480x272/model_telemetry_sensor.cpp | 35 ++++++++++++++- radio/src/gui/gui_common.cpp | 2 +- radio/src/gui/gui_common.h | 1 + radio/src/opentx.cpp | 4 +- radio/src/pulses/pulses.h | 6 --- radio/src/storage/storage_common.cpp | 5 ++- radio/src/tasks.cpp | 5 ++- radio/src/telemetry/frsky.h | 9 ++-- radio/src/telemetry/frsky_pxx2.cpp | 4 +- radio/src/telemetry/frsky_sport.cpp | 18 +++++--- radio/src/telemetry/telemetry.cpp | 25 ++++++----- radio/src/telemetry/telemetry.h | 10 +++-- radio/src/telemetry/telemetry_sensors.cpp | 34 +++++++-------- radio/src/telemetry/telemetry_sensors.h | 43 ++++++------------- radio/src/translations/de.h.txt | 4 +- radio/src/translations/en.h.txt | 4 +- radio/src/translations/es.h.txt | 4 +- radio/src/translations/fi.h.txt | 4 +- radio/src/translations/fr.h.txt | 4 +- radio/src/translations/it.h.txt | 4 +- radio/src/translations/nl.h.txt | 4 +- radio/src/translations/pl.h.txt | 4 +- radio/src/translations/pt.h.txt | 4 +- radio/src/translations/se.h.txt | 4 +- 28 files changed, 190 insertions(+), 120 deletions(-) diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index 803600b8e..ea31ac02d 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -319,6 +319,9 @@ PACK(struct VarioData { * Telemetry Sensor structure */ +#define TELEMETRY_ENDPOINT_NONE 0xFF +#define TELEMETRY_ENDPOINT_SPORT 0x07 + PACK(struct TelemetrySensor { union { uint16_t id; // data identifier, for FrSky we can reuse existing ones. Source unit is derived from type. @@ -379,18 +382,17 @@ PACK(struct TelemetrySensor { int32_t getPrecDivisor() const; bool isSameInstance(TelemetryProtocol protocol, uint8_t instance) { + if (this->instance == instance) + return true; + if (protocol == PROTOCOL_TELEMETRY_FRSKY_SPORT) { - if (((this->instance ^ instance) & 0x9F) == 0) { + if (((this->instance ^ instance) & 0x9F) == 0 && (this->instance >> 5) != TELEMETRY_ENDPOINT_SPORT && (instance >> 5) != TELEMETRY_ENDPOINT_SPORT) { this->instance = instance; // update the instance in case we had telemetry switching return true; } - else { - return false; - } - } - else { - return this->instance == instance; } + + return false; } ); }); diff --git a/radio/src/fonts.h b/radio/src/fonts.h index a839d48ee..ace7cb7a3 100644 --- a/radio/src/fonts.h +++ b/radio/src/fonts.h @@ -41,7 +41,7 @@ void loadFonts(); extern const unsigned char font_5x7[]; extern const unsigned char font_10x14[]; -#if defined(BOLD_FONT) && !defined(BOOT) +#if defined(BOLD_FONT) && !defined(BOOT) #define BOLD_SPECIFIC_FONT extern const unsigned char font_5x7_B[]; #endif diff --git a/radio/src/gui/128x64/model_telemetry_sensor.cpp b/radio/src/gui/128x64/model_telemetry_sensor.cpp index c14ad3652..f94628fff 100644 --- a/radio/src/gui/128x64/model_telemetry_sensor.cpp +++ b/radio/src/gui/128x64/model_telemetry_sensor.cpp @@ -51,7 +51,7 @@ void menuModelSensor(event_t event) 0, // Name 0, // Type sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : (uint8_t)1, // ID / Formula - sensor->type == TELEM_TYPE_CALCULATED ? HIDDEN_ROW : LABEL(Receiver), // Receiver name + sensor->type == TELEM_TYPE_CALCULATED ? HIDDEN_ROW : READONLY_ROW, // Receiver name ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW), // Unit (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT ? (uint8_t)0 : HIDDEN_ROW), // Precision (sensor->unit >= UNIT_FIRST_VIRTUAL ? HIDDEN_ROW : (uint8_t)0), // Param1 @@ -84,7 +84,6 @@ void menuModelSensor(event_t event) LcdFlags attr = (sub==k ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0); switch (k) { - case SENSOR_FIELD_NAME: editSingleName(SENSOR_2ND_COLUMN, y, STR_NAME, sensor->label, TELEM_LABEL_LEN, event, attr); break; @@ -143,8 +142,19 @@ void menuModelSensor(event_t event) break; case SENSOR_FILED_RECEIVER_NAME: - lcdDrawTextAlignedLeft(y, STR_RECEIVER); - drawReceiverName(SENSOR_2ND_COLUMN, y, sensor->frskyInstance.rxIndex >> 2, sensor->frskyInstance.rxIndex & 0x03, 0); + lcdDrawTextAlignedLeft(y, STR_SOURCE); + if (telemetryProtocol == PROTOCOL_TELEMETRY_FRSKY_SPORT && sensor->frskyInstance.rxIndex != TELEMETRY_ENDPOINT_SPORT) { + drawReceiverName(SENSOR_2ND_COLUMN, y, sensor->frskyInstance.rxIndex >> 2, sensor->frskyInstance.rxIndex & 0x03, 0); + } +#if defined(HARDWARE_INTERNAL_MODULE) + else if (isModuleUsingSport(INTERNAL_MODULE, g_model.moduleData[INTERNAL_MODULE].type)) { + // far from perfect + lcdDrawText(SENSOR_2ND_COLUMN, y, STR_INTERNAL_MODULE); + } +#endif + else { + lcdDrawText(SENSOR_2ND_COLUMN, y, STR_EXTERNAL_MODULE); + } break; case SENSOR_FIELD_UNIT: diff --git a/radio/src/gui/212x64/model_telemetry_sensor.cpp b/radio/src/gui/212x64/model_telemetry_sensor.cpp index 2daa516cb..4321f87c3 100644 --- a/radio/src/gui/212x64/model_telemetry_sensor.cpp +++ b/radio/src/gui/212x64/model_telemetry_sensor.cpp @@ -25,6 +25,7 @@ enum SensorFields { SENSOR_FIELD_TYPE, SENSOR_FIELD_ID, SENSOR_FIELD_FORMULA=SENSOR_FIELD_ID, + SENSOR_FILED_RECEIVER_NAME, SENSOR_FIELD_UNIT, SENSOR_FIELD_PRECISION, SENSOR_FIELD_PARAM1, @@ -61,7 +62,23 @@ void menuModelSensor(event_t event) drawSensorCustomValue(25*FW, 0, s_currIdx, getValue(MIXSRC_FIRST_TELEM+3*s_currIdx)); lcdDrawFilledRect(0, 0, LCD_W, FH, SOLID, FILL_WHITE|GREY_DEFAULT); - SUBMENU(STR_MENUSENSOR, SENSOR_FIELD_MAX, { 0, 0, sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : (uint8_t)1, SENSOR_UNIT_ROWS, SENSOR_PREC_ROWS, SENSOR_PARAM1_ROWS, SENSOR_PARAM2_ROWS, SENSOR_PARAM3_ROWS, SENSOR_PARAM4_ROWS, SENSOR_AUTOOFFSET_ROWS, SENSOR_ONLYPOS_ROWS, SENSOR_FILTER_ROWS, SENSOR_PERSISTENT_ROWS, 0 }); + SUBMENU(STR_MENUSENSOR, SENSOR_FIELD_MAX, { + 0, //Name + 0, // Type + sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : (uint8_t)1, // ID / Formula + sensor->type == TELEM_TYPE_CALCULATED ? HIDDEN_ROW : READONLY_ROW, // Receiver name + SENSOR_UNIT_ROWS, + SENSOR_PREC_ROWS, + SENSOR_PARAM1_ROWS, + SENSOR_PARAM2_ROWS, + SENSOR_PARAM3_ROWS, + SENSOR_PARAM4_ROWS, + SENSOR_AUTOOFFSET_ROWS, + SENSOR_ONLYPOS_ROWS, + SENSOR_FILTER_ROWS, + SENSOR_PERSISTENT_ROWS, + 0 // Logs + }); for (uint8_t i=0; ifrskyInstance.rxIndex != TELEMETRY_ENDPOINT_SPORT) { + drawReceiverName(SENSOR_2ND_COLUMN, y, sensor->frskyInstance.rxIndex >> 2, sensor->frskyInstance.rxIndex & 0x03, 0); + } + else if (isModuleUsingSport(INTERNAL_MODULE, g_model.moduleData[INTERNAL_MODULE].type)) { + // far from perfect + lcdDrawText(SENSOR_2ND_COLUMN, y, STR_INTERNAL_MODULE); + } + else { + lcdDrawText(SENSOR_2ND_COLUMN, y, STR_EXTERNAL_MODULE); + } + break; + case SENSOR_FIELD_UNIT: lcdDrawTextAlignedLeft(y, STR_UNIT); lcdDrawTextAtIndex(SENSOR_2ND_COLUMN, y, STR_VTELEMUNIT, sensor->unit, attr); diff --git a/radio/src/gui/480x272/model_telemetry_sensor.cpp b/radio/src/gui/480x272/model_telemetry_sensor.cpp index f4d285efb..150d3e365 100644 --- a/radio/src/gui/480x272/model_telemetry_sensor.cpp +++ b/radio/src/gui/480x272/model_telemetry_sensor.cpp @@ -25,6 +25,7 @@ enum SensorFields { SENSOR_FIELD_TYPE, SENSOR_FIELD_ID, SENSOR_FIELD_FORMULA=SENSOR_FIELD_ID, + SENSOR_FILED_RECEIVER_NAME, SENSOR_FIELD_UNIT, SENSOR_FIELD_PRECISION, SENSOR_FIELD_PARAM1, @@ -57,7 +58,23 @@ bool menuModelSensor(event_t event) { TelemetrySensor * sensor = &g_model.telemetrySensors[s_currIdx]; - SUBMENU("SENSOR", ICON_MODEL_TELEMETRY, SENSOR_FIELD_MAX, { 0, 0, sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : (uint8_t)1, SENSOR_UNIT_ROWS, SENSOR_PREC_ROWS, SENSOR_PARAM1_ROWS, SENSOR_PARAM2_ROWS, SENSOR_PARAM3_ROWS, SENSOR_PARAM4_ROWS, SENSOR_AUTOOFFSET_ROWS, SENSOR_ONLYPOS_ROWS, SENSOR_FILTER_ROWS, SENSOR_PERSISTENT_ROWS, 0 }); + SUBMENU("SENSOR", ICON_MODEL_TELEMETRY, SENSOR_FIELD_MAX, { + 0, // Name + 0, // Type + sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : (uint8_t)1, // ID / Formula + sensor->type == TELEM_TYPE_CALCULATED ? HIDDEN_ROW : READONLY_ROW, // Receiver name + SENSOR_UNIT_ROWS, + SENSOR_PREC_ROWS, + SENSOR_PARAM1_ROWS, + SENSOR_PARAM2_ROWS, + SENSOR_PARAM3_ROWS, + SENSOR_PARAM4_ROWS, + SENSOR_AUTOOFFSET_ROWS, + SENSOR_ONLYPOS_ROWS, + SENSOR_FILTER_ROWS, + SENSOR_PERSISTENT_ROWS, + 0 // Logs + }); lcdDrawNumber(lcdNextPos, 3, s_currIdx+1, MENU_TITLE_COLOR|LEFT); drawSensorCustomValue(50, 3 + FH, s_currIdx, getValue(MIXSRC_FIRST_TELEM+3*s_currIdx), MENU_TITLE_COLOR|LEFT); @@ -132,6 +149,22 @@ bool menuModelSensor(event_t event) } break; + case SENSOR_FILED_RECEIVER_NAME: + lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SOURCE); + if (telemetryProtocol == PROTOCOL_TELEMETRY_FRSKY_SPORT && sensor->frskyInstance.rxIndex != TELEMETRY_ENDPOINT_SPORT) { + drawReceiverName(SENSOR_2ND_COLUMN, y, sensor->frskyInstance.rxIndex >> 2, sensor->frskyInstance.rxIndex & 0x03, 0); + } +#if defined(HARDWARE_INTERNAL_MODULE) + else if (isModuleUsingSport(INTERNAL_MODULE, g_model.moduleData[INTERNAL_MODULE].type)) { + // far from perfect + lcdDrawText(SENSOR_2ND_COLUMN, y, STR_INTERNAL_MODULE); + } +#endif + else { + lcdDrawText(SENSOR_2ND_COLUMN, y, STR_EXTERNAL_MODULE); + } + break; + case SENSOR_FIELD_UNIT: lcdDrawText(MENUS_MARGIN_LEFT, y, STR_UNIT); lcdDrawTextAtIndex(SENSOR_2ND_COLUMN, y, STR_VTELEMUNIT, sensor->unit, attr); diff --git a/radio/src/gui/gui_common.cpp b/radio/src/gui/gui_common.cpp index 2d0ccb6db..1086d2b22 100644 --- a/radio/src/gui/gui_common.cpp +++ b/radio/src/gui/gui_common.cpp @@ -538,7 +538,7 @@ bool isPxx2IsrmChannelsCountAllowed(int channels) bool isModuleUsingSport(uint8_t moduleBay, uint8_t moduleType) { - switch(moduleType) { + switch (moduleType) { case MODULE_TYPE_NONE: case MODULE_TYPE_SBUS: case MODULE_TYPE_PPM: diff --git a/radio/src/gui/gui_common.h b/radio/src/gui/gui_common.h index daafbbef3..b192e103b 100644 --- a/radio/src/gui/gui_common.h +++ b/radio/src/gui/gui_common.h @@ -61,6 +61,7 @@ bool isSwitchAvailableInMixes(int swtch); bool isSwitchAvailableInTimers(int swtch); bool isR9MModeAvailable(int mode); bool isPxx2IsrmChannelsCountAllowed(int channels); +bool isModuleUsingSport(uint8_t moduleBay, uint8_t moduleType); bool isExternalModuleAvailable(int moduleType); bool isInternalModuleAvailable(int moduleType); bool isRfProtocolAvailable(int protocol); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index cf82a20cf..7b338cc94 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -192,9 +192,7 @@ void per10ms() } #endif - if (!IS_DSM2_SERIAL_PROTOCOL(s_current_protocol[0])) { - telemetryInterrupt10ms(); - } + telemetryInterrupt10ms(); // These moved here from evalFlightModeMixes() to improve beep trigger reliability. #if defined(PWM_BACKLIGHT) diff --git a/radio/src/pulses/pulses.h b/radio/src/pulses/pulses.h index a8ac93869..e2aa1664a 100644 --- a/radio/src/pulses/pulses.h +++ b/radio/src/pulses/pulses.h @@ -40,12 +40,6 @@ #define IS_DSM2_PROTOCOL(protocol) (0) #endif -#if defined(DSM2_SERIAL) - #define IS_DSM2_SERIAL_PROTOCOL(protocol) (IS_DSM2_PROTOCOL(protocol)) -#else - #define IS_DSM2_SERIAL_PROTOCOL(protocol) (0) -#endif - #if defined(MULTIMODULE) #define IS_MULTIMODULE_PROTOCOL(protocol) (protocol==PROTOCOL_CHANNELS_MULTIMODULE) #if !defined(DSM2) diff --git a/radio/src/storage/storage_common.cpp b/radio/src/storage/storage_common.cpp index b38584b08..cd591b8d4 100644 --- a/radio/src/storage/storage_common.cpp +++ b/radio/src/storage/storage_common.cpp @@ -92,7 +92,10 @@ void postModelLoad(bool alarms) TelemetrySensor & sensor = g_model.telemetrySensors[i]; if (sensor.type == TELEM_TYPE_CALCULATED && sensor.persistent) { telemetryItems[i].value = sensor.persistentValue; - telemetryItems[i].lastReceived = TELEMETRY_VALUE_OLD; // #3595: make value visible even before the first new value is received) + telemetryItems[i].timeout = 0; // make value visible even before the first new value is received) + } + else { + telemetryItems[i].timeout = TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE; } } diff --git a/radio/src/tasks.cpp b/radio/src/tasks.cpp index 17446d3a2..40e2613d0 100644 --- a/radio/src/tasks.cpp +++ b/radio/src/tasks.cpp @@ -136,7 +136,7 @@ TASK_FUNCTION(mixerTask) uint32_t now = RTOS_GET_MS(); bool run = false; - if ((now - lastRunTime) >= 10) { + if (now - lastRunTime >= 10) { // run at least every 10ms run = true; } @@ -194,7 +194,8 @@ TASK_FUNCTION(mixerTask) } t0 = getTmr2MHz() - t0; - if (t0 > maxMixerDuration) maxMixerDuration = t0; + if (t0 > maxMixerDuration) + maxMixerDuration = t0; sendSynchronousPulses(); } diff --git a/radio/src/telemetry/frsky.h b/radio/src/telemetry/frsky.h index 3b7634ab4..f526478f6 100644 --- a/radio/src/telemetry/frsky.h +++ b/radio/src/telemetry/frsky.h @@ -209,7 +209,9 @@ class TelemetryData { TelemetryExpiringDecorator swrExternal; TelemetryFilterDecorator rssi; uint16_t xjtVersion; - bool varioHighPrecision; + uint8_t varioHighPrecision:1; + uint8_t telemetryValid:3; + uint8_t spare:4; void setSwr(uint8_t module, uint8_t value) { @@ -227,11 +229,6 @@ class TelemetryData { extern TelemetryData telemetryData; -inline bool TELEMETRY_STREAMING() -{ - return telemetryData.rssi.value() > 0; -} - inline uint8_t TELEMETRY_RSSI() { return telemetryData.rssi.value(); diff --git a/radio/src/telemetry/frsky_pxx2.cpp b/radio/src/telemetry/frsky_pxx2.cpp index e9db1fd88..d41ef1add 100644 --- a/radio/src/telemetry/frsky_pxx2.cpp +++ b/radio/src/telemetry/frsky_pxx2.cpp @@ -214,7 +214,9 @@ void processResetFrame(uint8_t module, uint8_t * frame) void processTelemetryFrame(uint8_t module, uint8_t * frame) { uint8_t origin = (module << 2) + (frame[3] & 0x03); - sportProcessTelemetryPacketWithoutCrc(origin, &frame[4]); + if (origin != TELEMETRY_ENDPOINT_SPORT) { + sportProcessTelemetryPacketWithoutCrc(origin, &frame[4]); + } } void processSpectrumAnalyserFrame(uint8_t module, uint8_t * frame) diff --git a/radio/src/telemetry/frsky_sport.cpp b/radio/src/telemetry/frsky_sport.cpp index abe52f61c..1a268e69d 100644 --- a/radio/src/telemetry/frsky_sport.cpp +++ b/radio/src/telemetry/frsky_sport.cpp @@ -85,14 +85,12 @@ const FrSkySportSensor sportSensors[] = { const FrSkySportSensor * getFrSkySportSensor(uint16_t id, uint8_t subId=0) { - const FrSkySportSensor * result = NULL; for (const FrSkySportSensor * sensor = sportSensors; sensor->firstId; sensor++) { if (id >= sensor->firstId && id <= sensor->lastId && subId == sensor->subId) { - result = sensor; - break; + return sensor; } } - return result; + return nullptr; } bool checkSportPacket(const uint8_t * packet) @@ -164,10 +162,16 @@ void sportProcessTelemetryPacketWithoutCrc(uint8_t origin, const uint8_t * packe #endif if (primId == DATA_FRAME) { + uint8_t originMask = (origin == TELEMETRY_ENDPOINT_SPORT ? 0x02 : origin >> 2); uint8_t instance = physicalId + (origin << 5); if (dataId == RSSI_ID) { - telemetryStreaming = TELEMETRY_TIMEOUT10ms; // reset counter only if valid packets are being detected data = SPORT_DATA_U8(packet); + if (data > 0) { + telemetryStreaming = TELEMETRY_TIMEOUT10ms; // reset counter only if valid packets are being detected + telemetryData.telemetryValid |= originMask; + } else { + telemetryData.telemetryValid &= ~originMask; + } if (g_model.rssiSource) { TelemetrySensor * sensor = &g_model.telemetrySensors[g_model.rssiSource - 1]; if (sensor->isSameInstance(PROTOCOL_TELEMETRY_FRSKY_SPORT, instance)) { @@ -194,7 +198,8 @@ void sportProcessTelemetryPacketWithoutCrc(uint8_t origin, const uint8_t * packe } } - if (TELEMETRY_STREAMING()/* because when Rx is OFF it happens that some old A1/A2 values are sent from the XJT module*/) { + // here we discard the frame if it comes from an origin which has RSSI = 0 (RxBt and RSSI are sent in a loop by the module in some situations) + if (TELEMETRY_STREAMING() && (telemetryData.telemetryValid & originMask)/* because when Rx is OFF it happens that some old A1/A2 values are sent from the XJT module*/) { if ((dataId >> 8) == 0) { // The old FrSky IDs processHubPacket(dataId, HUB_DATA_U16(packet)); @@ -203,6 +208,7 @@ void sportProcessTelemetryPacketWithoutCrc(uint8_t origin, const uint8_t * packe if (dataId == ADC1_ID || dataId == ADC2_ID || dataId == BATT_ID || dataId == RAS_ID) { data = SPORT_DATA_U8(packet); } + if (dataId >= GPS_LONG_LATI_FIRST_ID && dataId <= GPS_LONG_LATI_LAST_ID) { int32_t value = (data & 0x3fffffff); if (data & (1 << 30)) diff --git a/radio/src/telemetry/telemetry.cpp b/radio/src/telemetry/telemetry.cpp index 71845ef53..5c33b811b 100644 --- a/radio/src/telemetry/telemetry.cpp +++ b/radio/src/telemetry/telemetry.cpp @@ -148,20 +148,21 @@ void telemetryWakeup() SCHEDULE_NEXT_ALARMS_CHECK(1/*second*/); - bool sensor_lost = false; + bool sensorLost = false; for (int i=0; i TELEMETRY_VALUE_OLD_THRESHOLD) { + if (item.timeout == 0) { TelemetrySensor * sensor = & g_model.telemetrySensors[i]; if (sensor->unit != UNIT_DATETIME) { item.setOld(); - sensor_lost = true; + sensorLost = true; } } } } - if (sensor_lost && TELEMETRY_STREAMING() && !g_model.rssiAlarms.disabled) { + + if (sensorLost && TELEMETRY_STREAMING() && !g_model.rssiAlarms.disabled) { audioEvent(AU_SENSOR_LOST); } @@ -205,22 +206,26 @@ void telemetryWakeup() void telemetryInterrupt10ms() { - if (TELEMETRY_STREAMING()) { + if (telemetryStreaming > 0) { + bool tick160ms = (telemetryStreaming & 0x0F) == 0; for (int i=0; i 0) { + telemetryItems[i].timeout--; + } } - } - - if (telemetryStreaming > 0) { telemetryStreaming--; } else { #if !defined(SIMU) telemetryData.rssi.reset(); #endif + for (int i=0; i0 (true) == data is streaming in. 0 = no data detected for some time +inline bool TELEMETRY_STREAMING() +{ + return telemetryStreaming > 0; +} + enum TelemetryStates { TELEMETRY_INIT, TELEMETRY_OK, @@ -38,7 +43,7 @@ enum TelemetryStates { }; extern uint8_t telemetryState; -#define TELEMETRY_TIMEOUT10ms 100 // 1 second +constexpr uint8_t TELEMETRY_TIMEOUT10ms = 100; // 1 second #define TELEMETRY_SERIAL_DEFAULT 0 #define TELEMETRY_SERIAL_8E2 1 @@ -139,9 +144,6 @@ void logTelemetryWriteByte(uint8_t data); #define LOG_TELEMETRY_WRITE_BYTE(data) #endif -#define TELEMETRY_ENDPOINT_NONE 0xFF -#define TELEMETRY_ENDPOINT_SPORT 0x07 - class OutputTelemetryBuffer { public: OutputTelemetryBuffer() diff --git a/radio/src/telemetry/telemetry_sensors.cpp b/radio/src/telemetry/telemetry_sensors.cpp index e627b89cd..e0777fd4d 100644 --- a/radio/src/telemetry/telemetry_sensors.cpp +++ b/radio/src/telemetry/telemetry_sensors.cpp @@ -120,7 +120,7 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32 } } else if (unit == UNIT_DATETIME) { - uint32_t data = uint32_t(newVal); + auto data = uint32_t(newVal); if (data & 0x000000ff) { datetime.year = (uint16_t) ((data & 0xff000000) >> 24) + 2000; // SPORT GPS year is only two digits datetime.month = (uint8_t) ((data & 0x00ff0000) >> 16); @@ -150,7 +150,7 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32 distFromEarthAxis = getDistFromEarthAxis(newVal); } gps.latitude = newVal; - lastReceived = now(); + setFresh(); return; } else if (unit == UNIT_GPS_LONGITUDE) { @@ -163,7 +163,7 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32 pilotLongitude = newVal; } gps.longitude = newVal; - lastReceived = now(); + setFresh(); return; } else if (unit == UNIT_DATETIME_YEAR) { @@ -171,13 +171,13 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32 return; } else if (unit == UNIT_DATETIME_DAY_MONTH) { - uint32_t data = uint32_t(newVal); + auto data = uint32_t(newVal); datetime.month = data >> 8; datetime.day = data & 0xFF; return; } else if (unit == UNIT_DATETIME_HOUR_MIN) { - uint32_t data = uint32_t(newVal); + auto data = uint32_t(newVal); datetime.hour = (data & 0xFF); datetime.min = data >> 8; return; @@ -193,7 +193,7 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32 } else if (unit == UNIT_TEXT) { *((uint32_t*)&text[prec]) = newVal; - lastReceived = now(); + setFresh(); return; } else { @@ -252,7 +252,7 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32 } value = newVal; - lastReceived = now(); + setFresh(); } void TelemetryItem::per10ms(const TelemetrySensor & sensor) @@ -266,7 +266,7 @@ void TelemetryItem::per10ms(const TelemetrySensor & sensor) return; } else if (currentItem.isOld()) { - lastReceived = TELEMETRY_VALUE_OLD; + setOld(); return; } int32_t current = convertTelemetryValue(currentItem.value, currentSensor.unit, currentSensor.prec, UNIT_AMPS, 1); @@ -275,7 +275,7 @@ void TelemetryItem::per10ms(const TelemetrySensor & sensor) currentItem.consumption.prescale -= 3600; setValue(sensor, value+1, sensor.unit, sensor.prec); } - lastReceived = now(); + setFresh(); } break; @@ -291,7 +291,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor) if (sensor.cell.source) { TelemetryItem & cellsItem = telemetryItems[sensor.cell.source-1]; if (cellsItem.isOld()) { - lastReceived = TELEMETRY_VALUE_OLD; + setOld(); } else { unsigned int index = sensor.cell.index; @@ -340,7 +340,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor) return; } else if (gpsItem.isOld()) { - lastReceived = TELEMETRY_VALUE_OLD; + setOld(); return; } if (sensor.dist.alt) { @@ -349,7 +349,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor) return; } else if (altItem->isOld()) { - lastReceived = TELEMETRY_VALUE_OLD; + setOld(); return; } } @@ -413,7 +413,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor) return; } else if (telemetryItem.isOld()) { - lastReceived = TELEMETRY_VALUE_OLD; + setOld(); return; } } @@ -439,7 +439,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor) if (sensor.formula == TELEM_FORMULA_AVERAGE) { if (count == 0) { if (available) - lastReceived = TELEMETRY_VALUE_OLD; + setOld(); return; } else { @@ -491,18 +491,18 @@ int lastUsedTelemetryIndex() int setTelemetryValue(TelemetryProtocol protocol, uint16_t id, uint8_t subId, uint8_t instance, int32_t value, uint32_t unit, uint32_t prec) { - bool available = false; + bool sensorFound = false; for (int index=0; index> 4) & (TELEMETRY_VALUE_TIMER_CYCLE - 1); - } - TelemetryItem() { clear(); @@ -92,7 +85,7 @@ class TelemetryItem void clear() { memset(reinterpret_cast(this), 0, sizeof(TelemetryItem)); - lastReceived = TELEMETRY_VALUE_UNAVAILABLE; + timeout = TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE; } void eval(const TelemetrySensor & sensor); @@ -102,36 +95,28 @@ class TelemetryItem inline bool isAvailable() { - return (lastReceived != TELEMETRY_VALUE_UNAVAILABLE); + return (timeout != TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE); } inline bool isOld() { - return (lastReceived == TELEMETRY_VALUE_OLD); - } - - inline bool hasReceiveTime() - { - return (lastReceived < TELEMETRY_VALUE_TIMER_CYCLE); - } - - inline uint8_t getDelaySinceLastValue() - { - // assumes lastReceived is not a special value (OLD / UNAVAILABLE) - return (now() - lastReceived) & (TELEMETRY_VALUE_TIMER_CYCLE - 1); + return (timeout == TELEMETRY_SENSOR_TIMEOUT_OLD); } inline bool isFresh() { - return (hasReceiveTime() && getDelaySinceLastValue() <= 1); + return TELEMETRY_SENSOR_TIMEOUT_START - timeout <= 1; // 2 * 160ms + } + + inline void setFresh() + { + timeout = TELEMETRY_SENSOR_TIMEOUT_START; } inline void setOld() { - lastReceived = TELEMETRY_VALUE_OLD; + timeout = TELEMETRY_SENSOR_TIMEOUT_OLD; } - - void gpsReceived(); // TODO seems not used }; extern TelemetryItem telemetryItems[MAX_TELEMETRY_SENSORS]; diff --git a/radio/src/translations/de.h.txt b/radio/src/translations/de.h.txt index fbe69547c..e81326e23 100644 --- a/radio/src/translations/de.h.txt +++ b/radio/src/translations/de.h.txt @@ -836,8 +836,8 @@ #define TR_WRITING "Writing..." #define TR_CONFIRM_FORMAT "Formatieren bestätigen?" #define TR_INTERNALRF "Internes HF-Modul" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade nötig" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/en.h.txt b/radio/src/translations/en.h.txt index 9c81f3ace..ef384edd9 100644 --- a/radio/src/translations/en.h.txt +++ b/radio/src/translations/en.h.txt @@ -836,8 +836,8 @@ #define TR_WRITING "Writing..." #define TR_CONFIRM_FORMAT "Confirm Format?" #define TR_INTERNALRF "Internal RF" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/es.h.txt b/radio/src/translations/es.h.txt index 2df39e9ee..20fe25d51 100644 --- a/radio/src/translations/es.h.txt +++ b/radio/src/translations/es.h.txt @@ -860,8 +860,8 @@ #define TR_WRITING "Writing..." #define TR_CONFIRM_FORMAT "Confirm Format?" #define TR_INTERNALRF "Interna RF" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/fi.h.txt b/radio/src/translations/fi.h.txt index 4e5d36b88..cb4f0139f 100644 --- a/radio/src/translations/fi.h.txt +++ b/radio/src/translations/fi.h.txt @@ -853,8 +853,8 @@ #define TR_WRITING "Writing..." #define TR_CONFIRM_FORMAT "Confirm Format?" #define TR_INTERNALRF "Internal RF" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/fr.h.txt b/radio/src/translations/fr.h.txt index 075b1a795..d8886c75b 100644 --- a/radio/src/translations/fr.h.txt +++ b/radio/src/translations/fr.h.txt @@ -855,8 +855,8 @@ #define TR_WRITING TR("\14Ecriture...", "\032Ecriture...") #define TR_CONFIRM_FORMAT "Confirmer Formatage?" #define TR_INTERNALRF "HF interne" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/it.h.txt b/radio/src/translations/it.h.txt index 0766abbbe..9ea317cf2 100644 --- a/radio/src/translations/it.h.txt +++ b/radio/src/translations/it.h.txt @@ -854,8 +854,8 @@ #define TR_WRITING "\032Scrivendo..." #define TR_CONFIRM_FORMAT "Confermi Format?" #define TR_INTERNALRF "Modulo Interno" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/nl.h.txt b/radio/src/translations/nl.h.txt index 02e13cdd3..0a0e55ebd 100644 --- a/radio/src/translations/nl.h.txt +++ b/radio/src/translations/nl.h.txt @@ -842,8 +842,8 @@ TR_GYR_VSRCRAW #define TR_WRITING "\032Schrijven..." #define TR_CONFIRM_FORMAT "Formatteren bevestigen?" #define TR_INTERNALRF "Interne RF" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/pl.h.txt b/radio/src/translations/pl.h.txt index a1d48d91d..e55756458 100644 --- a/radio/src/translations/pl.h.txt +++ b/radio/src/translations/pl.h.txt @@ -854,8 +854,8 @@ #define TR_WRITING "\032Zapis... " #define TR_CONFIRM_FORMAT "Zatwierdź Format?" #define TR_INTERNALRF "Wewn.Moduł RF" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/pt.h.txt b/radio/src/translations/pt.h.txt index 6f1e9a723..097c6e1a8 100644 --- a/radio/src/translations/pt.h.txt +++ b/radio/src/translations/pt.h.txt @@ -844,8 +844,8 @@ #define TR_WRITING "Writing..." #define TR_CONFIRM_FORMAT "Confirm Format?" #define TR_INTERNALRF "Internal RF" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available" diff --git a/radio/src/translations/se.h.txt b/radio/src/translations/se.h.txt index 36047d908..a99e0ee25 100644 --- a/radio/src/translations/se.h.txt +++ b/radio/src/translations/se.h.txt @@ -854,8 +854,8 @@ #define TR_WRITING "\032Skriver..." #define TR_CONFIRM_FORMAT "Formatera Minnet?" #define TR_INTERNALRF "Intern Radio" -#define TR_INTERNAL_MODULE "Internal module" -#define TR_EXTERNAL_MODULE "External module" +#define TR_INTERNAL_MODULE TR("Int. module","Internal module") +#define TR_EXTERNAL_MODULE TR("Ext. module","External module") #define TR_OPENTX_UPGRADE_REQUIRED "OpenTX upgrade required" #define TR_TELEMETRY_DISABLED "Telem. disabled" #define TR_MORE_OPTIONS_AVAILABLE "More options available"