Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Some AFHDS2A/AFHDS3 GPS/ALT telemetry handling issues #3582

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions radio/src/telemetry/flysky_ibus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ enum

AFHDS3_FRM_TEMP = 0x57, //virtual
AFHDS3_FRM_EXT_V = 0x58, //virtual
AFHDS2A_ID_PRES = 0x41, // Pressure

AFHDS2A_ID_TX_V = 0x7F, // TX Voltage

Expand Down Expand Up @@ -189,13 +188,13 @@ const FlySkySensor flySkySensors[] = {
{ AFHDS2A_ID_ODO1, STR_SENSOR_ODO1, UNIT_METERS, 2 }, // 2 bytes Odometer1 -- some magic with 330 needed
{ AFHDS2A_ID_ODO2, STR_SENSOR_ODO2, UNIT_METERS, 2 }, // 2 bytes Odometer2 -- some magic with 330 needed
{ AFHDS2A_ID_SPE, STR_SENSOR_ASPD, UNIT_KMH, 2 }, // 2 bytes Speed km/h -- some magic with 330 needed
{ AFHDS2A_ID_GPS_LAT, STR_SENSOR_GPS, UNIT_RAW, 7 }, // 4 bytes signed WGS84 in degrees * 1E7
{ AFHDS2A_ID_GPS_LON, STR_SENSOR_GPS, UNIT_RAW, 7 }, // 4 bytes signed WGS84 in degrees * 1E7
{ AFHDS2A_ID_GPS_LAT, STR_SENSOR_GPS, UNIT_RAW, 0 }, // 4 bytes signed WGS84 in degrees * 1E7
{ AFHDS2A_ID_GPS_LON, STR_SENSOR_GPS, UNIT_RAW, 0 }, // 4 bytes signed WGS84 in degrees * 1E7
{ AFHDS2A_ID_GPS_ALT, STR_SENSOR_GPSALT, UNIT_METERS, 2 }, // 4 bytes signed GPS alt m*100
{ AFHDS2A_ID_ALT, STR_SENSOR_ALT, UNIT_METERS, 2 }, // 4 bytes signed Alt m*100
{ AFHDS2A_ID_RX_SIG_AFHDS3, STR_SENSOR_RX_QUALITY, UNIT_RAW, 0 }, // RX error rate
{ AFHDS2A_ID_RX_SIG_AFHDS3, STR_SENSOR_RX_QUALITY, UNIT_PERCENT, 0 }, // RX error rate
{ AFHDS2A_ID_RX_SNR_AFHDS3, STR_SENSOR_RX_SNR, UNIT_DB, 1 }, // RX SNR
{ AFHDS2A_ID_TX_RSSI, STR_SENSOR_TX_RSSI, UNIT_RAW, 0 }, // Pseudo sensor for TRSSI
{ AFHDS2A_ID_TX_RSSI, STR_SENSOR_TX_RSSI, UNIT_DBM, 0 }, // Pseudo sensor for TRSSI

{ 0x00, NULL, UNIT_RAW, 0 }, // sentinel
};
Expand Down Expand Up @@ -315,7 +314,7 @@ void processFlySkySensor(const uint8_t * packet, uint8_t type)
if (type == 0xAA)
value = (packet[3] << 8) | packet[2];
else
value = (packet[5] << 24) | (packet[4] << 16) | (packet[3] << 8) | packet[2];
value = (packet[6] << 24) | (packet[5] << 16) | (packet[4] << 8) | packet[3];

id = id ? id : SENSOR_TYPE_RX_VOL; // Remapped

Expand All @@ -331,7 +330,7 @@ void processFlySkySensor(const uint8_t * packet, uint8_t type)
telemetryData.rssi.set(value);
if(value>0) telemetryStreaming = TELEMETRY_TIMEOUT10ms;
}
else if (id == AFHDS2A_ID_PRES && value) {
else if (id == SENSOR_TYPE_PRES && value) {
// Extract temperature to a new sensor
setTelemetryValue(PROTOCOL_TELEMETRY_FLYSKY_IBUS, id | 0x100, 0, instance, ((value >> 19) - 400), UNIT_CELSIUS, 1);
// Extract alt to a new sensor
Expand Down Expand Up @@ -398,8 +397,8 @@ void processFlySkyPacket(const uint8_t * packet)
setFlyskyTelemetryValue(AFHDS2A_ID_TX_RSSI, 0, packet[0], UNIT_RAW, 0);

const uint8_t * buffer = packet + 1;
int sesnor = 0;
while (sesnor++ < 7) {
int sensor = 0;
while (sensor++ < 7) {
if (*buffer == SENSOR_TYPE_END) break;
processFlySkySensor(buffer, 0xAA);
buffer += 4;
Expand Down