Merge branch '2.3' into 2.4
# Conflicts: # radio/src/fonts/480x272/font_dblsize.png # radio/src/fonts/480x272/font_xxlsize.png # radio/src/gui/128x64/model_setup.cpp # radio/src/gui/128x64/radio_setup.cpp # radio/src/gui/480x272/model_receiver_options.cpp # radio/src/gui/480x272/model_setup.cpp # radio/src/gui/480x272/radio_calibration.cpp # radio/src/gui/480x272/radio_hardware.cpp # radio/src/gui/common/stdlcd/draw_functions.cpp # radio/src/gui/gui_common.cpp # radio/src/keys.h # radio/src/lua/interface.cpp # radio/src/pulses/afhds3.h # radio/src/rtos.h # radio/src/switches.cpp # radio/src/targets/common/arm/stm32/aux_serial_driver.cpp # radio/src/targets/horus/CMakeLists.txt # radio/src/targets/horus/lcd_driver.cpp # radio/src/targets/horus/startup_stm32f42_43xxx.s # radio/src/targets/taranis/CMakeLists.txt # radio/src/telemetry/crossfire.h # radio/src/telemetry/multi.cpp # radio/src/translations.cpp # radio/src/translations/it.h.txt # radio/src/translations/untranslated.h # radio/util/font2png.py # tools/commit-tests.sh
This commit is contained in:
@@ -184,6 +184,25 @@ void processCrossfireTelemetryFrame()
|
||||
break;
|
||||
}
|
||||
|
||||
case RADIO_ID:
|
||||
if (telemetryRxBuffer[3] == 0xEA // radio address
|
||||
&& telemetryRxBuffer[5] == 0x10 // timing correction frame
|
||||
) {
|
||||
|
||||
uint32_t update_interval;
|
||||
int32_t offset;
|
||||
if (getCrossfireTelemetryValue<4>(6, (int32_t&)update_interval) && getCrossfireTelemetryValue<4>(10, offset)) {
|
||||
|
||||
// values are in 10th of micro-seconds
|
||||
update_interval /= 10;
|
||||
offset /= 10;
|
||||
|
||||
TRACE("[XF] Rate: %d, Lag: %d", update_interval, offset);
|
||||
getModuleSyncStatus(EXTERNAL_MODULE).update(update_interval, offset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(LUA)
|
||||
default:
|
||||
if (luaInputTelemetryFifo && luaInputTelemetryFifo->hasSpace(telemetryRxBufferCount-2) ) {
|
||||
|
||||
@@ -102,12 +102,12 @@ const uint8_t CROSSFIRE_FRAME_PERIODS[] = {
|
||||
4,
|
||||
16,
|
||||
};
|
||||
#if SPORT_MAX_BAUDRATE < 400000
|
||||
#define CROSSFIRE_BAUDRATE CROSSFIRE_BAUDRATES[g_eeGeneral.telemetryBaudrate]
|
||||
#define CROSSFIRE_PERIOD CROSSFIRE_FRAME_PERIODS[g_eeGeneral.telemetryBaudrate]
|
||||
#if SPORT_MAX_BAUDRATE < 400000 || defined(DEBUG)
|
||||
#define CROSSFIRE_BAUDRATE CROSSFIRE_BAUDRATES[g_eeGeneral.telemetryBaudrate]
|
||||
#define CROSSFIRE_PERIOD (CROSSFIRE_PERIODS[g_eeGeneral.telemetryBaudrate] * 1000)
|
||||
#else
|
||||
#define CROSSFIRE_BAUDRATE 400000
|
||||
#define CROSSFIRE_PERIOD 4 // 4ms
|
||||
#define CROSSFIRE_PERIOD 4000 /* us; 250 Hz */
|
||||
#endif
|
||||
|
||||
#define CROSSFIRE_TELEM_MIRROR_BAUDRATE 115200
|
||||
|
||||
@@ -43,12 +43,19 @@ enum
|
||||
GHOST_ID_TOTAL_LATENCY = 0x0007, // Tx-side total latency
|
||||
GHOST_ID_VTX_FREQ = 0x0008, // Vtx Frequency (in MHz)
|
||||
GHOST_ID_VTX_POWER = 0x0009, // Vtx Power (in mW)
|
||||
GHOST_ID_VTX_CHAN = 0x000a, // Vtx Channel
|
||||
GHOST_ID_VTX_BAND = 0x000b, // Vtx Band
|
||||
GHOST_ID_VTX_CHAN = 0x000A, // Vtx Channel
|
||||
GHOST_ID_VTX_BAND = 0x000B, // Vtx Band
|
||||
|
||||
GHOST_ID_PACK_VOLTS = 0x000c, // Battery Pack Voltage
|
||||
GHOST_ID_PACK_AMPS = 0x000d, // Battery Pack Current
|
||||
GHOST_ID_PACK_MAH = 0x000e, // Battery Pack mAh consumed
|
||||
GHOST_ID_PACK_VOLTS = 0x000C, // Battery Pack Voltage
|
||||
GHOST_ID_PACK_AMPS = 0x000D, // Battery Pack Current
|
||||
GHOST_ID_PACK_MAH = 0x000E, // Battery Pack mAh consumed
|
||||
|
||||
GHOST_ID_GPS_LAT = 0x000F, // GPS Latitude
|
||||
GHOST_ID_GPS_LONG = 0x0010, // GPS Longitude
|
||||
GHOST_ID_GPS_ALT = 0x0011, // GPS Altitude
|
||||
GHOST_ID_GPS_HDG = 0x0012, // GPS Heading
|
||||
GHOST_ID_GPS_GSPD = 0x0013, // GPS Ground Speed
|
||||
GHOST_ID_GPS_SATS = 0x0014 // GPS Satellite Count
|
||||
};
|
||||
|
||||
const GhostSensor ghostSensors[] = {
|
||||
@@ -70,6 +77,13 @@ const GhostSensor ghostSensors[] = {
|
||||
{GHOST_ID_PACK_AMPS, ZSTR_CURR, UNIT_AMPS, 2},
|
||||
{GHOST_ID_PACK_MAH, ZSTR_CAPACITY, UNIT_MAH, 0},
|
||||
|
||||
{GHOST_ID_GPS_LAT, ZSTR_GPS, UNIT_GPS_LATITUDE, 0},
|
||||
{GHOST_ID_GPS_LONG, ZSTR_GPS, UNIT_GPS_LONGITUDE, 0},
|
||||
{GHOST_ID_GPS_GSPD, ZSTR_GSPD, UNIT_KMH, 1},
|
||||
{GHOST_ID_GPS_HDG, ZSTR_HDG, UNIT_DEGREE, 3},
|
||||
{GHOST_ID_GPS_ALT, ZSTR_ALT, UNIT_METERS, 0},
|
||||
{GHOST_ID_GPS_SATS, ZSTR_SATELLITES, UNIT_RAW, 0},
|
||||
|
||||
{0x00, NULL, UNIT_RAW, 0},
|
||||
};
|
||||
|
||||
@@ -88,7 +102,11 @@ void processGhostTelemetryValue(uint8_t index, int32_t value)
|
||||
return;
|
||||
|
||||
const GhostSensor * sensor = getGhostSensor(index);
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_GHOST, sensor->id, 0, 0, value, sensor->unit, sensor->precision);
|
||||
uint16_t id = sensor->id;
|
||||
if (id == GHOST_ID_GPS_LONG) {
|
||||
id = GHOST_ID_GPS_LAT;
|
||||
}
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_GHOST, id, 0, 0, value, sensor->unit, sensor->precision);
|
||||
}
|
||||
|
||||
void processGhostTelemetryValueString(const GhostSensor * sensor, const char * str)
|
||||
@@ -105,16 +123,19 @@ bool checkGhostTelemetryFrameCRC()
|
||||
return (crc == telemetryRxBuffer[len + 1]);
|
||||
}
|
||||
|
||||
// hifirst
|
||||
uint16_t getTelemetryValue_u16(uint8_t index)
|
||||
{
|
||||
return (telemetryRxBuffer[index] << 8) | telemetryRxBuffer[index + 1];
|
||||
}
|
||||
|
||||
// lofirst
|
||||
uint16_t getTelemetryValue_u16le(uint8_t index)
|
||||
{
|
||||
return (telemetryRxBuffer[index + 1] << 8) | telemetryRxBuffer[index];
|
||||
}
|
||||
|
||||
// hifirst
|
||||
uint32_t getTelemetryValue_s32(uint8_t index)
|
||||
{
|
||||
uint32_t val = 0;
|
||||
@@ -123,6 +144,15 @@ uint32_t getTelemetryValue_s32(uint8_t index)
|
||||
return val;
|
||||
}
|
||||
|
||||
// lofirst
|
||||
uint32_t getTelemetryValue_s32le(uint8_t index)
|
||||
{
|
||||
uint32_t val = 0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
val <<= 8, val |= telemetryRxBuffer[index + 3 - i];
|
||||
return val;
|
||||
}
|
||||
|
||||
void processGhostTelemetryFrame()
|
||||
{
|
||||
if (!checkGhostTelemetryFrameCRC()) {
|
||||
@@ -132,6 +162,19 @@ void processGhostTelemetryFrame()
|
||||
|
||||
uint8_t id = telemetryRxBuffer[2];
|
||||
switch(id) {
|
||||
case GHST_DL_OPENTX_SYNC:
|
||||
{
|
||||
uint32_t update_interval = getTelemetryValue_s32(3);
|
||||
int32_t offset = getTelemetryValue_s32(7);
|
||||
|
||||
// values are in units of 100ns
|
||||
update_interval /= 10;
|
||||
offset /= 10;
|
||||
|
||||
getModuleSyncStatus(EXTERNAL_MODULE).update(update_interval, offset);
|
||||
}
|
||||
break;
|
||||
|
||||
case GHST_DL_LINK_STAT:
|
||||
{
|
||||
#if defined(BLUETOOTH)
|
||||
@@ -213,15 +256,40 @@ void processGhostTelemetryFrame()
|
||||
case GHST_DL_PACK_STAT: {
|
||||
#if defined(BLUETOOTH)
|
||||
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY && bluetooth.state == BLUETOOTH_STATE_CONNECTED) {
|
||||
bluetooth.write(telemetryRxBuffer, telemetryRxBufferCount);
|
||||
}
|
||||
bluetooth.write(telemetryRxBuffer, telemetryRxBufferCount);
|
||||
}
|
||||
#endif
|
||||
processGhostTelemetryValue(GHOST_ID_PACK_VOLTS, getTelemetryValue_u16le(3));
|
||||
processGhostTelemetryValue(GHOST_ID_PACK_AMPS, getTelemetryValue_u16le(5));
|
||||
processGhostTelemetryValue(GHOST_ID_PACK_MAH, getTelemetryValue_u16le(7) * 10);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GHST_DL_GPS_PRIMARY: {
|
||||
#if defined(BLUETOOTH)
|
||||
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY && bluetooth.state == BLUETOOTH_STATE_CONNECTED) {
|
||||
bluetooth.write(telemetryRxBuffer, telemetryRxBufferCount);
|
||||
}
|
||||
#endif
|
||||
processGhostTelemetryValue(GHOST_ID_GPS_LAT, getTelemetryValue_s32le(3) / 10);
|
||||
processGhostTelemetryValue(GHOST_ID_GPS_LONG, getTelemetryValue_s32le(7) / 10);
|
||||
processGhostTelemetryValue(GHOST_ID_GPS_ALT, (int16_t) getTelemetryValue_u16le(11));
|
||||
break;
|
||||
}
|
||||
|
||||
case GHST_DL_GPS_SECONDARY: {
|
||||
#if defined(BLUETOOTH)
|
||||
if (g_eeGeneral.bluetoothMode == BLUETOOTH_TELEMETRY && bluetooth.state == BLUETOOTH_STATE_CONNECTED) {
|
||||
bluetooth.write(telemetryRxBuffer, telemetryRxBufferCount);
|
||||
}
|
||||
#endif
|
||||
processGhostTelemetryValue(GHOST_ID_GPS_HDG, getTelemetryValue_u16le(5) / 10);
|
||||
|
||||
// ground speed is passed via GHST as cm/s, converted to km/h for OpenTx
|
||||
processGhostTelemetryValue(GHOST_ID_GPS_GSPD, (getTelemetryValue_u16le(3) * 36 + 50) / 100);
|
||||
processGhostTelemetryValue(GHOST_ID_GPS_SATS, telemetryRxBuffer[7]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +340,9 @@ void ghostSetDefault(int index, uint8_t id, uint8_t subId)
|
||||
const GhostSensor * sensor = getGhostSensor(id);
|
||||
if (sensor) {
|
||||
TelemetryUnit unit = sensor->unit;
|
||||
if (unit == UNIT_GPS_LATITUDE || unit == UNIT_GPS_LONGITUDE) {
|
||||
unit = UNIT_GPS;
|
||||
}
|
||||
uint8_t prec = min<uint8_t>(2, sensor->precision);
|
||||
telemetrySensor.init(sensor->name, unit, prec);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
#define GHST_DL_VTX_STAT 0x22
|
||||
#define GHST_DL_PACK_STAT 0x23
|
||||
#define GHST_DL_MENU_DESC 0x24
|
||||
#define GHST_DL_GPS_PRIMARY 0x25
|
||||
#define GHST_DL_GPS_SECONDARY 0x26
|
||||
|
||||
#define GHST_RC_CTR_VAL_12BIT 0x7C0 // 0x3e0 << 1
|
||||
#define GHST_RC_CTR_VAL_8BIT 0x7C
|
||||
@@ -113,7 +115,7 @@ enum GhostTelemetryBaudrates
|
||||
};
|
||||
#endif
|
||||
#define GHOST_BAUDRATE 400000
|
||||
#define GHOST_PERIOD 4
|
||||
#define GHOST_PERIOD 4000 /* us */
|
||||
|
||||
enum GhostLineFlags
|
||||
{
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
struct MLinkSensor
|
||||
{
|
||||
const uint16_t id;
|
||||
const char * name;
|
||||
const TelemetryUnit unit;
|
||||
const uint8_t precision;
|
||||
};
|
||||
|
||||
const MLinkSensor mlinkSensors[] = {
|
||||
{MLINK_RX_VOLTAGE, ZSTR_BATT, UNIT_VOLTS, 1},
|
||||
{MLINK_VOLTAGE, ZSTR_VFAS, UNIT_VOLTS, 1},
|
||||
{MLINK_CURRENT, ZSTR_CURR, UNIT_AMPS, 1},
|
||||
{MLINK_VARIO, ZSTR_VSPD, UNIT_METERS_PER_SECOND, 1},
|
||||
{MLINK_SPEED, ZSTR_SPEED, UNIT_KMH, 1},
|
||||
{MLINK_RPM, ZSTR_RPM, UNIT_RPMS, 0},
|
||||
{MLINK_TEMP, ZSTR_TEMP1, UNIT_CELSIUS, 1},
|
||||
{MLINK_HEADING, ZSTR_HDG, UNIT_DEGREE, 1},
|
||||
{MLINK_ALT, ZSTR_ALT , UNIT_METERS, 0},
|
||||
{MLINK_FUEL, ZSTR_FUEL, UNIT_PERCENT, 0},
|
||||
{MLINK_CAPACITY, ZSTR_CAPACITY, UNIT_MAH, 0},
|
||||
{MLINK_FLOW, ZSTR_FLOW, UNIT_MILLILITERS, 0},
|
||||
{MLINK_DISTANCE, ZSTR_DIST, UNIT_KM, 1},
|
||||
{MLINK_LQI, ZSTR_RSSI, UNIT_RAW, 0},
|
||||
{MLINK_LOSS, ZSTR_LOSS, UNIT_RAW, 0},
|
||||
{MLINK_TX_RSSI, ZSTR_TX_RSSI, UNIT_RAW, 0},
|
||||
{MLINK_TX_LQI, ZSTR_TX_QUALITY, UNIT_RAW, 0},
|
||||
};
|
||||
|
||||
const MLinkSensor * getMLinkSensor(uint16_t id)
|
||||
{
|
||||
for (const MLinkSensor * sensor = mlinkSensors; sensor->id; sensor++) {
|
||||
if (id == sensor->id)
|
||||
return sensor;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void processMLinkPacket(const uint8_t * packet)
|
||||
{
|
||||
const uint8_t * data = packet + 2;
|
||||
|
||||
// Multi telem
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_TX_RSSI, 0, 0, (packet[0] * 100) / 31, UNIT_RAW, 0);
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_TX_LQI, 0, 0, packet[1], UNIT_RAW, 0);
|
||||
|
||||
// M-Link telem
|
||||
if (data[0] == 0x13) { // Telemetry type RX-9
|
||||
for (uint8_t i = 1; i < 5; i += 3) { //2 sensors per packet
|
||||
int32_t val = (int16_t )(data[i + 2] << 8 | data[i + 1]);
|
||||
val = val >> 1; // remove alarm flag
|
||||
uint8_t adress = (data[i] & 0xF0) >> 4;
|
||||
switch (data[i] & 0x0F) {
|
||||
case MLINK_VOLTAGE:
|
||||
if ((data[i] & 0xF0) == 0x00){
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_RX_VOLTAGE, 0, adress, val, UNIT_VOLTS, 1);
|
||||
}
|
||||
else {
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_VOLTAGE, 0, adress, val, UNIT_VOLTS, 1);
|
||||
}
|
||||
break;
|
||||
case MLINK_CURRENT:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_CURRENT, 0, adress, val, UNIT_AMPS, 1);
|
||||
break;
|
||||
case MLINK_VARIO:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_VARIO, 0, adress, val, UNIT_METERS_PER_SECOND, 1);
|
||||
break;
|
||||
case MLINK_SPEED:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_SPEED, 0, adress, val, UNIT_KMH, 1);
|
||||
break;
|
||||
case MLINK_RPM:
|
||||
if (val < 0) {
|
||||
val = -val * 10;
|
||||
}
|
||||
else {
|
||||
val = val * 100;
|
||||
}
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_RPM, 0, adress, val, UNIT_RPMS, 0);
|
||||
break;
|
||||
case MLINK_TEMP:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_TEMP, 0, adress, val, UNIT_CELSIUS, 1);
|
||||
break;
|
||||
case MLINK_HEADING:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_HEADING, 0, adress, val, UNIT_DEGREE, 1);
|
||||
break;
|
||||
case MLINK_ALT:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_ALT, 0, adress, val, UNIT_METERS, 0);
|
||||
break;
|
||||
case MLINK_FUEL:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_FUEL, 0, adress, val, UNIT_PERCENT, 0);
|
||||
break;
|
||||
case MLINK_CAPACITY:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_CAPACITY, 0, adress, val, UNIT_MAH, 0);
|
||||
break;
|
||||
case MLINK_FLOW:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_FLOW, 0, adress, val, UNIT_MILLILITERS, 0);
|
||||
break;
|
||||
case MLINK_DISTANCE:
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_DISTANCE, 0, adress, val, UNIT_KM, 1);
|
||||
break;
|
||||
case MLINK_LQI:
|
||||
uint8_t mlinkRssi = data[i + 1] >> 1;
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_LQI, 0, 0, mlinkRssi, UNIT_RAW, 0);
|
||||
telemetryData.rssi.set(mlinkRssi);
|
||||
if (mlinkRssi > 0) {
|
||||
telemetryStreaming = TELEMETRY_TIMEOUT10ms;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet[2] == 0x03) { // Telemetry type RX-5
|
||||
uint16_t mlinkRssi = (packet[4] * 100) / 35;
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_LQI, 0, 0, mlinkRssi, UNIT_RAW, 0);
|
||||
telemetryData.rssi.set(mlinkRssi);
|
||||
if (mlinkRssi > 0) {
|
||||
telemetryStreaming = TELEMETRY_TIMEOUT10ms;
|
||||
}
|
||||
setTelemetryValue(PROTOCOL_TELEMETRY_MLINK, MLINK_LOSS, 0, 0, packet[7], UNIT_RAW, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void mlinkSetDefault(int index, uint16_t id, uint8_t subId, uint8_t instance)
|
||||
{
|
||||
TelemetrySensor &telemetrySensor = g_model.telemetrySensors[index];
|
||||
telemetrySensor.id = id;
|
||||
telemetrySensor.subId = subId;
|
||||
telemetrySensor.instance = instance;
|
||||
|
||||
const MLinkSensor * sensor = getMLinkSensor(id);
|
||||
if (sensor) {
|
||||
TelemetryUnit unit = sensor->unit;
|
||||
uint8_t prec = min<uint8_t>(2, sensor->precision);
|
||||
telemetrySensor.init(sensor->name, unit, prec);
|
||||
if (unit == UNIT_RPMS) {
|
||||
telemetrySensor.custom.ratio = 1;
|
||||
telemetrySensor.custom.offset = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
telemetrySensor.init(id);
|
||||
}
|
||||
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
enum {
|
||||
MLINK_VOLTAGE = 1,
|
||||
MLINK_CURRENT = 2,
|
||||
MLINK_VARIO = 3,
|
||||
MLINK_SPEED = 4,
|
||||
MLINK_RPM = 5,
|
||||
MLINK_TEMP = 6,
|
||||
MLINK_HEADING = 7,
|
||||
MLINK_ALT = 8,
|
||||
MLINK_FUEL = 9,
|
||||
MLINK_LQI = 10,
|
||||
MLINK_CAPACITY = 11,
|
||||
MLINK_FLOW = 12,
|
||||
MLINK_DISTANCE = 13,
|
||||
MLINK_RX_VOLTAGE = 16, // out of range ID for specific RxBt treatment
|
||||
MLINK_LOSS = 17, // out of range ID for handling number of loss
|
||||
MLINK_TX_RSSI = 18, // out of range ID for handling Telemetry RSSi reported by multi
|
||||
MLINK_TX_LQI = 19, // out of range ID for handling Telemetry LQI reported by multi
|
||||
};
|
||||
|
||||
void processMLinkTelemetryData(uint8_t data, uint8_t* rxBuffer, uint8_t& rxBufferCount);
|
||||
void mlinkSetDefault(int index, uint16_t id, uint8_t subId, uint8_t instance);
|
||||
|
||||
// Used by multi protocol
|
||||
void processMLinkPacket(const uint8_t *packet);
|
||||
+14
-125
@@ -42,6 +42,7 @@ enum MultiPacketTypes : uint8_t
|
||||
FlyskyIBusTelemetryAC,
|
||||
MultiRxChannels,
|
||||
HottTelemetry,
|
||||
MLinkTelemetry
|
||||
};
|
||||
|
||||
enum MultiBufferState : uint8_t
|
||||
@@ -63,7 +64,6 @@ enum MultiBufferState : uint8_t
|
||||
#if defined(INTERNAL_MODULE_MULTI)
|
||||
|
||||
static MultiModuleStatus multiModuleStatus[NUM_MODULES] = {MultiModuleStatus(), MultiModuleStatus()};
|
||||
static MultiModuleSyncStatus multiSyncStatus[NUM_MODULES] = {MultiModuleSyncStatus(), MultiModuleSyncStatus()};
|
||||
static uint8_t multiBindStatus[NUM_MODULES] = {MULTI_BIND_NONE, MULTI_BIND_NONE};
|
||||
|
||||
static MultiBufferState multiTelemetryBufferState[NUM_MODULES];
|
||||
@@ -74,11 +74,6 @@ MultiModuleStatus &getMultiModuleStatus(uint8_t module)
|
||||
return multiModuleStatus[module];
|
||||
}
|
||||
|
||||
MultiModuleSyncStatus &getMultiSyncStatus(uint8_t module)
|
||||
{
|
||||
return multiSyncStatus[module];
|
||||
}
|
||||
|
||||
uint8_t getMultiBindStatus(uint8_t module)
|
||||
{
|
||||
return multiBindStatus[module];
|
||||
@@ -111,7 +106,6 @@ uint8_t intTelemetryRxBufferCount;
|
||||
#else // !INTERNAL_MODULE_MULTI
|
||||
|
||||
static MultiModuleStatus multiModuleStatus;
|
||||
static MultiModuleSyncStatus multiSyncStatus;
|
||||
static uint8_t multiBindStatus = MULTI_BIND_NONE;
|
||||
|
||||
static MultiBufferState multiTelemetryBufferState;
|
||||
@@ -122,11 +116,6 @@ MultiModuleStatus& getMultiModuleStatus(uint8_t)
|
||||
return multiModuleStatus;
|
||||
}
|
||||
|
||||
MultiModuleSyncStatus& getMultiSyncStatus(uint8_t)
|
||||
{
|
||||
return multiSyncStatus;
|
||||
}
|
||||
|
||||
uint8_t getMultiBindStatus(uint8_t)
|
||||
{
|
||||
return multiBindStatus;
|
||||
@@ -254,23 +243,14 @@ static void processMultiStatusPacket(const uint8_t * data, uint8_t module, uint8
|
||||
|
||||
static void processMultiSyncPacket(const uint8_t * data, uint8_t module)
|
||||
{
|
||||
MultiModuleSyncStatus &status = getMultiSyncStatus(module);
|
||||
ModuleSyncStatus &status = getModuleSyncStatus(module);
|
||||
|
||||
status.lastUpdate = get_tmr10ms();
|
||||
status.interval = data[4];
|
||||
status.target = data[5];
|
||||
#if !defined(PPM_PIN_SERIAL)
|
||||
auto oldlag = status.inputLag;
|
||||
(void) oldlag;
|
||||
#endif
|
||||
uint16_t refreshRate = data[0] << 8 | data[1];
|
||||
int16_t inputLag = data[2] << 8 | data[3];
|
||||
|
||||
status.calcAdjustedRefreshRate(data[0] << 8 | data[1], data[2] << 8 | data[3]);
|
||||
|
||||
#if !defined(PPM_PIN_SERIAL)
|
||||
TRACE("MP ADJ: rest: %d, lag %04d, diff: %04d target: %d, interval: %d, Refresh: %d, intAdjRefresh: %d, adjRefresh %d\r\n",
|
||||
module == EXTERNAL_MODULE ? extmodulePulsesData.dsm2.rest : 0,
|
||||
status.inputLag, oldlag - status.inputLag, status.target, status.interval, status.refreshRate, status.adjustedRefreshRate / 50,
|
||||
status.getAdjustedRefreshRate());
|
||||
status.update(refreshRate, inputLag);
|
||||
#if defined(DEBUG)
|
||||
serialPrint("MP ADJ: R %d, L %04d", refreshRate, inputLag);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -379,6 +359,13 @@ static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
|
||||
TRACE("[MP] Received HoTT telemetry len %d < 14", len);
|
||||
break;
|
||||
|
||||
case MLinkTelemetry:
|
||||
if (len > 6)
|
||||
processMLinkPacket(data);
|
||||
else
|
||||
TRACE("[MP] Received M-Link telemetry len %d < 6", len);
|
||||
break;
|
||||
|
||||
case FrSkyHubTelemetry:
|
||||
if (len >= 4)
|
||||
frskyDProcessPacket(data);
|
||||
@@ -434,104 +421,6 @@ static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
|
||||
}
|
||||
}
|
||||
|
||||
#define MIN_REFRESH_RATE 5500
|
||||
|
||||
void MultiModuleSyncStatus::calcAdjustedRefreshRate(uint16_t newRefreshRate, uint16_t newInputLag)
|
||||
{
|
||||
// Check how far off we are from our target, positive means we are too slow, negative we are too fast
|
||||
int lagDifference = newInputLag - inputLag;
|
||||
|
||||
// The refresh rate that we target
|
||||
// Below is least common multiple of MIN_REFRESH_RATE and requested rate
|
||||
uint16_t targetRefreshRate = (uint16_t) (newRefreshRate * ((MIN_REFRESH_RATE / (newRefreshRate - 1)) + 1));
|
||||
|
||||
// Overflow, reverse sample
|
||||
if (lagDifference < -targetRefreshRate / 2)
|
||||
lagDifference = -lagDifference;
|
||||
|
||||
|
||||
// Reset adjusted refresh if rate has changed
|
||||
if (newRefreshRate != refreshRate) {
|
||||
refreshRate = newRefreshRate;
|
||||
adjustedRefreshRate = targetRefreshRate;
|
||||
if (adjustedRefreshRate >= 30000)
|
||||
adjustedRefreshRate /= 2;
|
||||
|
||||
// Our refresh rate in ps
|
||||
adjustedRefreshRate *= 1000;
|
||||
return;
|
||||
}
|
||||
|
||||
// Caluclate how many samples went into the reported input Lag (*10)
|
||||
int numsamples = interval * 10000 / targetRefreshRate;
|
||||
|
||||
// Convert lagDifference to ps
|
||||
lagDifference = lagDifference * 1000;
|
||||
|
||||
// Calculate the time we intentionally were late/early
|
||||
if (inputLag > target * 10 + 30)
|
||||
lagDifference += numsamples * 500;
|
||||
else if (inputLag < target * 10 - 30)
|
||||
lagDifference -= numsamples * 500;
|
||||
|
||||
// Caculate the time in ps each frame is to slow (positive), fast(negative)
|
||||
int perframeps = lagDifference * 10 / numsamples;
|
||||
|
||||
if (perframeps > 20000)
|
||||
perframeps = 20000;
|
||||
|
||||
if (perframeps < -20000)
|
||||
perframeps = -20000;
|
||||
|
||||
adjustedRefreshRate = (adjustedRefreshRate + perframeps);
|
||||
|
||||
// Safeguards
|
||||
if (adjustedRefreshRate < MIN_REFRESH_RATE * 1000)
|
||||
adjustedRefreshRate = MIN_REFRESH_RATE * 1000;
|
||||
if (adjustedRefreshRate > 30 * 1000 * 1000)
|
||||
adjustedRefreshRate = 30 * 1000 * 1000;
|
||||
|
||||
inputLag = newInputLag;
|
||||
}
|
||||
|
||||
static uint8_t counter;
|
||||
|
||||
const uint16_t MultiModuleSyncStatus::getAdjustedRefreshRate()
|
||||
{
|
||||
if (!isValid() || refreshRate == 0)
|
||||
return 18000;
|
||||
|
||||
counter = (uint8_t) (counter + 1 % 10);
|
||||
uint16_t rate = (uint16_t) ((adjustedRefreshRate + counter * 50) / 500);
|
||||
// Check how far off we are from our target, positive means we are too slow, negative we are too fast
|
||||
if (inputLag > target * 10 + 30)
|
||||
return (uint16_t) (rate - 1);
|
||||
else if (inputLag < target * 10 - 30)
|
||||
return (uint16_t) (rate + 1);
|
||||
else
|
||||
return rate;
|
||||
}
|
||||
|
||||
void MultiModuleSyncStatus::getRefreshString(char * statusText)
|
||||
{
|
||||
if (!isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
char * tmp = statusText;
|
||||
#if defined(DEBUG)
|
||||
*tmp++ = 'L';
|
||||
tmp = strAppendUnsigned(tmp, inputLag, 5);
|
||||
tmp = strAppend(tmp, "us R ");
|
||||
tmp = strAppendUnsigned(tmp, (uint32_t) (adjustedRefreshRate / 1000), 5);
|
||||
tmp = strAppend(tmp, STR_US);
|
||||
#else
|
||||
tmp = strAppend(tmp, "Sync at ");
|
||||
tmp = strAppendUnsigned(tmp, (uint32_t) (adjustedRefreshRate / 1000000));
|
||||
tmp = strAppend(tmp, " ms");
|
||||
#endif
|
||||
}
|
||||
|
||||
void MultiModuleStatus::getStatusString(char * statusText) const
|
||||
{
|
||||
if (!isValid()) {
|
||||
|
||||
@@ -94,28 +94,6 @@ void processMultiTelemetryData(uint8_t data, uint8_t module);
|
||||
|
||||
#define MULTI_SCANNER_MAX_CHANNEL 249
|
||||
|
||||
// This should be put into the Module definition if other modules gain this functionality
|
||||
struct MultiModuleSyncStatus {
|
||||
uint32_t adjustedRefreshRate = 9000 * 1000; // in ps
|
||||
tmr10ms_t lastUpdate;
|
||||
uint16_t refreshRate;
|
||||
uint16_t inputLag;
|
||||
uint8_t interval;
|
||||
uint8_t target;
|
||||
|
||||
inline bool isValid() const
|
||||
{
|
||||
return (get_tmr10ms() - lastUpdate < 100);
|
||||
}
|
||||
|
||||
void getRefreshString(char * refreshText);
|
||||
const uint16_t getAdjustedRefreshRate();
|
||||
void calcAdjustedRefreshRate(uint16_t newRefreshRate, uint16_t newInputLag);
|
||||
};
|
||||
|
||||
MultiModuleSyncStatus& getMultiSyncStatus(uint8_t module);
|
||||
|
||||
|
||||
struct MultiModuleStatus {
|
||||
|
||||
uint8_t major;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "opentx.h"
|
||||
#include "multi.h"
|
||||
#include "pulses/afhds3.h"
|
||||
#include "mixer_scheduler.h"
|
||||
|
||||
uint8_t telemetryStreaming = 0;
|
||||
uint8_t telemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE]; // Receive buffer. 9 bytes (full packet), worst case 18 bytes with byte-stuffing (+1)
|
||||
@@ -373,3 +374,86 @@ OutputTelemetryBuffer outputTelemetryBuffer __DMA;
|
||||
#if defined(LUA)
|
||||
Fifo<uint8_t, LUA_TELEMETRY_INPUT_FIFO_SIZE> * luaInputTelemetryFifo = NULL;
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
static ModuleSyncStatus moduleSyncStatus[NUM_MODULES];
|
||||
|
||||
ModuleSyncStatus &getModuleSyncStatus(uint8_t moduleIdx)
|
||||
{
|
||||
return moduleSyncStatus[moduleIdx];
|
||||
}
|
||||
#else
|
||||
static ModuleSyncStatus moduleSyncStatus;
|
||||
|
||||
ModuleSyncStatus &getModuleSyncStatus(uint8_t moduleIdx)
|
||||
{
|
||||
return moduleSyncStatus;
|
||||
}
|
||||
#endif
|
||||
|
||||
ModuleSyncStatus::ModuleSyncStatus()
|
||||
{
|
||||
memset(this, 0, sizeof(ModuleSyncStatus));
|
||||
}
|
||||
|
||||
void ModuleSyncStatus::update(uint16_t newRefreshRate, uint16_t newInputLag)
|
||||
{
|
||||
if (!newRefreshRate)
|
||||
return;
|
||||
|
||||
if (newRefreshRate < MIN_REFRESH_RATE)
|
||||
newRefreshRate = newRefreshRate * (MIN_REFRESH_RATE / (newRefreshRate + 1));
|
||||
else if (newRefreshRate > MAX_REFRESH_RATE)
|
||||
newRefreshRate = MAX_REFRESH_RATE;
|
||||
|
||||
refreshRate = newRefreshRate;
|
||||
inputLag = newInputLag;
|
||||
currentLag = newInputLag;
|
||||
lastUpdate = get_tmr10ms();
|
||||
|
||||
TRACE("[SYNC] update rate = %dus; lag = %dus",refreshRate,currentLag);
|
||||
}
|
||||
|
||||
uint16_t ModuleSyncStatus::getAdjustedRefreshRate()
|
||||
{
|
||||
int16_t lag = currentLag;
|
||||
int32_t newRefreshRate = refreshRate;
|
||||
|
||||
if (lag == 0) {
|
||||
return refreshRate;
|
||||
}
|
||||
|
||||
newRefreshRate += lag;
|
||||
|
||||
if (newRefreshRate < MIN_REFRESH_RATE) {
|
||||
newRefreshRate = MIN_REFRESH_RATE;
|
||||
}
|
||||
else if (newRefreshRate > MAX_REFRESH_RATE) {
|
||||
newRefreshRate = MAX_REFRESH_RATE;
|
||||
}
|
||||
|
||||
currentLag -= newRefreshRate - refreshRate;
|
||||
TRACE("[SYNC] mod rate = %dus; lag = %dus",newRefreshRate,currentLag);
|
||||
|
||||
return (uint16_t)newRefreshRate;
|
||||
}
|
||||
|
||||
void ModuleSyncStatus::getRefreshString(char * statusText)
|
||||
{
|
||||
if (!isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
char * tmp = statusText;
|
||||
#if defined(DEBUG)
|
||||
*tmp++ = 'L';
|
||||
tmp = strAppendUnsigned(tmp, inputLag, 5);
|
||||
tmp = strAppend(tmp, "us R ");
|
||||
tmp = strAppendUnsigned(tmp, (uint32_t) (refreshRate / 1000), 5);
|
||||
tmp = strAppend(tmp, "us");
|
||||
#else
|
||||
tmp = strAppend(tmp, "Sync at ");
|
||||
tmp = strAppendUnsigned(tmp, (uint32_t) (refreshRate / 1000000));
|
||||
tmp = strAppend(tmp, " ms");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "hitec.h"
|
||||
#include "hott.h"
|
||||
#include "multi.h"
|
||||
#include "mlink.h"
|
||||
#endif
|
||||
#include "myeeprom.h"
|
||||
#if defined(MULTIMODULE) || defined(AFHDS3)
|
||||
@@ -291,4 +292,33 @@ extern Fifo<uint8_t, LUA_TELEMETRY_INPUT_FIFO_SIZE> * luaInputTelemetryFifo;
|
||||
|
||||
void processPXX2Frame(uint8_t module, const uint8_t *frame);
|
||||
|
||||
// Module pulse synchronization
|
||||
struct ModuleSyncStatus
|
||||
{
|
||||
// feedback input: last received values
|
||||
uint16_t refreshRate; // in us
|
||||
int16_t inputLag; // in us
|
||||
|
||||
tmr10ms_t lastUpdate; // in 10ms
|
||||
int16_t currentLag; // in us
|
||||
|
||||
inline bool isValid() {
|
||||
// 2 seconds
|
||||
return (get_tmr10ms() - lastUpdate < 200);
|
||||
}
|
||||
|
||||
// Set feedback from RF module
|
||||
void update(uint16_t newRefreshRate, uint16_t newInputLag);
|
||||
|
||||
// Get computed settings for scheduler
|
||||
uint16_t getAdjustedRefreshRate();
|
||||
|
||||
// Status string for the UI
|
||||
void getRefreshString(char* refreshText);
|
||||
|
||||
ModuleSyncStatus();
|
||||
};
|
||||
|
||||
ModuleSyncStatus& getModuleSyncStatus(uint8_t moduleIdx);
|
||||
|
||||
#endif // _TELEMETRY_H_
|
||||
|
||||
@@ -559,6 +559,10 @@ int setTelemetryValue(TelemetryProtocol protocol, uint16_t id, uint8_t subId, ui
|
||||
case PROTOCOL_TELEMETRY_HOTT:
|
||||
hottSetDefault(index, id, subId, instance);
|
||||
break;
|
||||
|
||||
case PROTOCOL_TELEMETRY_MLINK:
|
||||
mlinkSetDefault(index, id, subId, instance);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(LUA)
|
||||
|
||||
Reference in New Issue
Block a user