Skip to content

Commit 39a9955

Browse files
frankiearzupfeerick
authored andcommitted
feat(dsm): process new format for Spektrum Sky_ID GPS frames (#5355)
1 parent b6ff1a3 commit 39a9955

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

radio/src/telemetry/spektrum.cpp

+41-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#define I2C_ESC 0x20 // Electronic Speed Control
7777
#define I2C_ALPHA6 0x24 // Alpha6 Stabilizer - Blade Helis
7878
#define I2C_GPS_BIN 0x26 // GPS, binary format
79+
#define I2C_REMOTE_ID 0x27 // Spektrum SkyID/RemoteID
7980
#define I2C_FP_BATT 0x34 // Flight Battery Capacity (Dual)
8081
#define I2C_CELLS 0x3A // 6S Cell Monitor (LiPo taps)
8182
#define I2C_VARIO 0x40 // Vario
@@ -562,6 +563,7 @@ void processSpektrumPacket(const uint8_t *packet)
562563
#if TEST_CAPTURED_MESSAGE
563564
// Only for Testing when we don't have the sensor, but have sample data
564565
i2cAddress = replaceForTestingPackage(packet);
566+
instance = packet[3];
565567
#endif
566568

567569
if (i2cAddress == I2C_FWD_PGM) {
@@ -611,13 +613,13 @@ void processSpektrumPacket(const uint8_t *packet)
611613
else if (i2cAddress == I2C_FLITECTRL) {
612614
// AS3X + SAFE information: Flight Mode
613615
processAS3XPacket(packet);
614-
// Continue for backward compatibility with scripts using 05XX sensors
616+
return; // not a sensor... this is to cleanup many auto-generated 05XX sensors
615617
} // I2C_FLITECTRL
616618

617619
else if (i2cAddress == I2C_ALPHA6) {
618620
// Alpha6 Flight Controller (Blade Helis): Flight Mode
619621
processAlpha6Packet(packet);
620-
// Continue for backward compatibility with scripts using 24XX sensors
622+
return; // not a sensor... this is to cleanup many auto-generated 24XX sensors
621623
} // I2C_ALPHA6
622624

623625
else if (i2cAddress == I2C_SMART_BAT_BASE_ADDRESS) {
@@ -626,6 +628,24 @@ void processSpektrumPacket(const uint8_t *packet)
626628
i2cAddress = i2cAddress + (packet[4] >> 4);
627629
} // I2C_SMART_BAT_BASE_ADDRESS
628630

631+
else if (i2cAddress == I2C_REMOTE_ID) {
632+
if (instance == I2C_GPS_LOC || instance == I2C_GPS_STAT) {
633+
// RemoteID/SkyID GPS Data embeded in RemoteID packages
634+
// The format is exactly the same (with the exception of the I2C_ID and Instance),
635+
// so we just need to continue processing it as if the frame was a GPS telemetry data.
636+
// The instance is populated with 0x16/0x17 when is GPS, and 0x00 when it is the
637+
// usual RemoteID data
638+
i2cAddress = instance;
639+
instance = 0;
640+
} else {
641+
// Currently we are not processing any other of the RemoteID telemetry frames
642+
// we can add in the future a new sensor(s) to record the Remote system ID if we want
643+
// to log it as part of the telemetry data.
644+
return; // not a sensor... this is to cleanup many auto-generated 27XX sensors
645+
}
646+
} // I2C_REMOTE_ID
647+
648+
629649
bool handled = false;
630650
for (const SpektrumSensor * sensor = spektrumSensors; sensor->i2caddress; sensor++) {
631651
// Optimization... the sensor table is sorted incrementally by i2cAddress
@@ -1092,6 +1112,7 @@ static bool real0x16 = false;
10921112
static bool real0x17 = false;
10931113
static bool real0x34 = false;
10941114
static bool real0x3A = false;
1115+
static bool real0x27 = false;
10951116

10961117
// *********** GPS LOC (BCD) ******************************
10971118
// Example 0x16: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
@@ -1126,6 +1147,13 @@ static char test3Adata[] = {0x3A, 0x00, 0x01, 0x9A, 0x01, 0x9B, 0x01, 0x9C,
11261147
0x01, 0x91 };
11271148

11281149

1150+
// RemoteID (0x27), embeds Gps data in its frames, but by puting the real I2C frame
1151+
// address as the instance, everything else is the same
1152+
static char test27data_16[] = {0x27, 0x16, 0x97, 0x00, 0x54, 0x71, 0x12, 0x28,
1153+
0x40, 0x80, 0x09, 0x11, 0x85, 0x14, 0x13, 0xBD}; // > 99 Flag
1154+
static char test27data_17[] = {0x27, 0x17, 0x25, 0x00, 0x00,
1155+
0x28, 0x18, 0x21, 0x06, 0x00};
1156+
11291157
static uint8_t replaceForTestingPackage(const uint8_t *packet)
11301158
{
11311159
uint8_t i2cAddress = packet[2] & 0x7f;
@@ -1135,6 +1163,7 @@ static uint8_t replaceForTestingPackage(const uint8_t *packet)
11351163
else if (i2cAddress == I2C_GPS_STAT) real0x17 = true;
11361164
else if (i2cAddress == I2C_FP_BATT) real0x34 = true;
11371165
else if (i2cAddress == I2C_CELLS) real0x3A = true;
1166+
else if (i2cAddress == I2C_REMOTE_ID) real0x27 = true;
11381167

11391168
// Only Substiture AS3X/SAFE I2C_FLITECTRL packages, since they are constantly brodcast
11401169
if (i2cAddress != I2C_FLITECTRL) {
@@ -1146,13 +1175,23 @@ static uint8_t replaceForTestingPackage(const uint8_t *packet)
11461175
// return original packet
11471176
break;
11481177
case 1: // return GSP LOG
1178+
if (!real0x27) {
1179+
test27data_16[4]=test27data_16[4]+1;
1180+
test27data_16[8]=test27data_16[8]+1;
1181+
memcpy((char *)packet + 2, test27data_16, 16);
1182+
real0x16=true; // disable test of regular GPS frames, and use the RemoteID
1183+
}
11491184
if (!real0x16) {
11501185
test16data[4]=test16data[4]+1;
11511186
test16data[8]=test16data[8]+1;
11521187
memcpy((char *)packet + 2, test16data, 16);
11531188
}
11541189
break;
11551190
case 2: // Return GPS STAT
1191+
if (!real0x27) {
1192+
memcpy((char *)packet + 2, test27data_17, 10);
1193+
real0x17=true; // disable test of regular GPS frames, and use the RemoteID
1194+
}
11561195
if (!real0x17) memcpy((char *)packet + 2, test17data, 10);
11571196
break;
11581197
case 3: // Return Dual Bat monitor

0 commit comments

Comments
 (0)