Bsongis/rssi from 2 different modules (#6711)
RSSI from 2 different modules
This commit is contained in:
@@ -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;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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; i<NUM_BODY_LINES; i++) {
|
||||
coord_t y = MENU_HEADER_HEIGHT + 1 + i*FH;
|
||||
@@ -130,6 +147,20 @@ void menuModelSensor(event_t event)
|
||||
}
|
||||
break;
|
||||
|
||||
case SENSOR_FILED_RECEIVER_NAME:
|
||||
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);
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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();
|
||||
}
|
||||
|
||||
@@ -209,7 +209,9 @@ class TelemetryData {
|
||||
TelemetryExpiringDecorator<TelemetryValue> swrExternal;
|
||||
TelemetryFilterDecorator<TelemetryValue> 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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -148,20 +148,21 @@ void telemetryWakeup()
|
||||
|
||||
SCHEDULE_NEXT_ALARMS_CHECK(1/*second*/);
|
||||
|
||||
bool sensor_lost = false;
|
||||
bool sensorLost = false;
|
||||
for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isTelemetryFieldAvailable(i)) {
|
||||
TelemetryItem & item = telemetryItems[i];
|
||||
if (item.hasReceiveTime() && item.getDelaySinceLastValue() > 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<MAX_TELEMETRY_SENSORS; i++) {
|
||||
const TelemetrySensor & sensor = g_model.telemetrySensors[i];
|
||||
if (sensor.type == TELEM_TYPE_CALCULATED) {
|
||||
telemetryItems[i].per10ms(sensor);
|
||||
}
|
||||
if (tick160ms && telemetryItems[i].timeout > 0) {
|
||||
telemetryItems[i].timeout--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (telemetryStreaming > 0) {
|
||||
telemetryStreaming--;
|
||||
}
|
||||
else {
|
||||
#if !defined(SIMU)
|
||||
telemetryData.rssi.reset();
|
||||
#endif
|
||||
for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
|
||||
telemetryItems[i].setOld();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,8 +233,8 @@ void telemetryReset()
|
||||
{
|
||||
memclear(&telemetryData, sizeof(telemetryData));
|
||||
|
||||
for (int index=0; index<MAX_TELEMETRY_SENSORS; index++) {
|
||||
telemetryItems[index].clear();
|
||||
for (auto & telemetryItem : telemetryItems) {
|
||||
telemetryItem.clear();
|
||||
}
|
||||
|
||||
telemetryStreaming = 0; // reset counter only if valid frsky packets are being detected
|
||||
|
||||
@@ -31,6 +31,11 @@
|
||||
|
||||
extern uint8_t telemetryStreaming; // >0 (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()
|
||||
|
||||
@@ -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<MAX_TELEMETRY_SENSORS; index++) {
|
||||
TelemetrySensor & telemetrySensor = g_model.telemetrySensors[index];
|
||||
if (telemetrySensor.type == TELEM_TYPE_CUSTOM && telemetrySensor.id == id && telemetrySensor.subId == subId && (telemetrySensor.isSameInstance(protocol, instance) || g_model.ignoreSensorIds)) {
|
||||
telemetryItems[index].setValue(telemetrySensor, value, unit, prec);
|
||||
available = true;
|
||||
sensorFound = true;
|
||||
// we continue search here, because sensors can share the same id and instance
|
||||
}
|
||||
}
|
||||
|
||||
if (available || !allowNewSensors) {
|
||||
if (sensorFound || !allowNewSensors) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,9 @@
|
||||
|
||||
#include "telemetry.h"
|
||||
|
||||
#define TELEMETRY_VALUE_TIMER_CYCLE 128 /* x160ms ~= 20.5s ; must be multiple of 2 to avoid the modulo */
|
||||
#define TELEMETRY_VALUE_OLD_THRESHOLD 62 /* x160ms ~= 10s */
|
||||
#define TELEMETRY_VALUE_UNAVAILABLE 255
|
||||
#define TELEMETRY_VALUE_OLD 254
|
||||
constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE = -2;
|
||||
constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_OLD = -1;
|
||||
constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_START = 125; // * 160ms = 20s
|
||||
|
||||
class TelemetryItem
|
||||
{
|
||||
@@ -46,7 +45,7 @@ class TelemetryItem
|
||||
int32_t pilotLatitude;
|
||||
};
|
||||
|
||||
uint8_t lastReceived; // for detection of sensor loss
|
||||
int8_t timeout; // for detection of sensor loss
|
||||
|
||||
union {
|
||||
struct {
|
||||
@@ -78,12 +77,6 @@ class TelemetryItem
|
||||
char text[16];
|
||||
};
|
||||
|
||||
static uint8_t now()
|
||||
{
|
||||
// 160ms granularity
|
||||
return (get_tmr10ms() >> 4) & (TELEMETRY_VALUE_TIMER_CYCLE - 1);
|
||||
}
|
||||
|
||||
TelemetryItem()
|
||||
{
|
||||
clear();
|
||||
@@ -92,7 +85,7 @@ class TelemetryItem
|
||||
void clear()
|
||||
{
|
||||
memset(reinterpret_cast<void*>(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];
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user