5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
23 void frskyDProcessPacket(const uint8_t *packet
);
25 #if defined(TELEMETRY_FRSKY_SPORT)
26 bool checkSportPacket(const uint8_t *packet
);
27 void sportProcessTelemetryPacket(const uint8_t * packet
);
28 bool checkSportPacket(const uint8_t *packet
);
29 void frskyCalculateCellStats(void);
30 void displayVoltagesScreen();
33 #if defined(TELEMETRY_FRSKY) && !defined(CPUARM)
38 g_model
.frsky
.usrProto
= 1;
39 telemetryData
.hub
.gpsFix
= 1;
41 uint8_t pkt1
[] = { 0xfd, 0x07, 0x00, 0x5e, 0x14, 0x2c, 0x00, 0x5e, 0x1c, 0x03 };
42 uint8_t pkt2
[] = { 0xfd, 0x07, 0x00, 0x00, 0x5e, 0x13, 0x38, 0x0c, 0x5e, 0x1b };
43 uint8_t pkt3
[] = { 0xfd, 0x07, 0x00, 0xc9, 0x06, 0x5e, 0x23, 0x4e, 0x00, 0x5e };
44 uint8_t pkt4
[] = { 0xfd, 0x07, 0x00, 0x12, 0xef, 0x2e, 0x5e, 0x1a, 0x98, 0x26 };
45 uint8_t pkt5
[] = { 0xfd, 0x07, 0x00, 0x5e, 0x22, 0x45, 0x00, 0x5e, 0x11, 0x02 };
46 uint8_t pkt6
[] = { 0xfd, 0x07, 0x00, 0x00, 0x5e, 0x19, 0x93, 0x00, 0x5e, 0x04 };
47 uint8_t pkt7
[] = { 0xfd, 0x03, 0x00, 0x64, 0x00, 0x5e };
48 frskyDProcessPacket(pkt1
);
49 frskyDProcessPacket(pkt2
);
50 frskyDProcessPacket(pkt3
);
51 frskyDProcessPacket(pkt4
);
52 frskyDProcessPacket(pkt5
);
53 frskyDProcessPacket(pkt6
);
54 frskyDProcessPacket(pkt7
);
55 EXPECT_EQ(telemetryData
.hub
.gpsCourse_bp
, 44);
56 EXPECT_EQ(telemetryData
.hub
.gpsCourse_ap
, 03);
57 EXPECT_EQ(telemetryData
.hub
.gpsLongitude_bp
/ 100, 120);
58 EXPECT_EQ(telemetryData
.hub
.gpsLongitude_bp
% 100, 15);
59 EXPECT_EQ(telemetryData
.hub
.gpsLongitude_ap
, 0x2698);
60 EXPECT_EQ(telemetryData
.hub
.gpsLatitudeNS
, 'N');
61 EXPECT_EQ(telemetryData
.hub
.gpsLongitudeEW
, 'E');
62 EXPECT_EQ(telemetryData
.hub
.fuelLevel
, 100);
65 TEST(FrSky
, dateNtime
)
69 g_model
.frsky
.usrProto
= 1;
70 telemetryData
.hub
.gpsFix
= 1;
72 uint8_t pkt1
[] = { 0xfd, 0x07, 0x00, 0x5e, 0x15, 0x0f, 0x07, 0x5e, 0x16, 0x0b };
73 uint8_t pkt2
[] = { 0xfd, 0x07, 0x00, 0x00, 0x5e, 0x17, 0x06, 0x12, 0x5e, 0x18 };
74 uint8_t pkt3
[] = { 0xfd, 0x03, 0x00, 0x32, 0x00, 0x5e };
75 frskyDProcessPacket(pkt1
);
76 frskyDProcessPacket(pkt2
);
77 frskyDProcessPacket(pkt3
);
78 EXPECT_EQ(telemetryData
.hub
.day
, 15);
79 EXPECT_EQ(telemetryData
.hub
.month
, 07);
80 EXPECT_EQ(telemetryData
.hub
.year
, 11);
81 EXPECT_EQ(telemetryData
.hub
.hour
, 06);
82 EXPECT_EQ(telemetryData
.hub
.min
, 18);
83 EXPECT_EQ(telemetryData
.hub
.sec
, 50);
87 #if defined(TELEMETRY_FRSKY) && defined(CPUARM)
88 TEST(FrSky
, TelemetryValueWithMinAveraging
)
91 The following expected[] array is filled
92 with values that correspond to 4 elements
93 long averaging buffer.
94 If length of averaging buffer is changed, this
95 values must be adjusted
97 uint8_t expected
[] = { 10, 12, 17, 25, 35, 45, 55, 65, 75, 85, 92, 97, 100, 100, 100, 100, 100};
100 TelemetryValueWithMin testVal
;
103 EXPECT_EQ(RAW_FRSKY_MINMAX(testVal
), 10);
104 EXPECT_EQ(testVal
.value
, expected
[testPos
++]);
105 for(int n
=2; n
<10; ++n
) {
107 EXPECT_EQ(RAW_FRSKY_MINMAX(testVal
), n
*10);
108 EXPECT_EQ(testVal
.value
, expected
[testPos
++]);
110 for(int n
=2; n
<10; ++n
) {
112 EXPECT_EQ(RAW_FRSKY_MINMAX(testVal
), 100);
113 EXPECT_EQ(testVal
.value
, expected
[testPos
++]);
117 TEST(FrSky
, Vfas_0x39_HiPrecision
)
121 EXPECT_EQ(telemetryItems
[0].value
, 0);
123 allowNewSensors
= true;
125 // normal precision, resolution 0.1V
126 processHubPacket(VFAS_ID
, 1234); // set value of 123.4V
127 EXPECT_EQ(telemetryItems
[0].value
, 12340); // stored value has resolution of 0.01V
129 // now high precision, resolution 0.01V
130 processHubPacket(VFAS_ID
, VFAS_D_HIPREC_OFFSET
); // set value of 0V
131 EXPECT_EQ(telemetryItems
[0].value
, 0);
132 processHubPacket(VFAS_ID
, VFAS_D_HIPREC_OFFSET
+ 12345); // set value of 123.45V
133 EXPECT_EQ(telemetryItems
[0].value
, 12345);
134 processHubPacket(VFAS_ID
, VFAS_D_HIPREC_OFFSET
+ 30012); // set value of 300.12V
135 EXPECT_EQ(telemetryItems
[0].value
, 30012);
138 TEST(FrSky
, HubAltNegative
)
142 EXPECT_EQ(telemetryItems
[0].value
, 0);
144 allowNewSensors
= true;
146 // altimeter auto offset
147 processHubPacket(BARO_ALT_BP_ID
, 0);
148 processHubPacket(BARO_ALT_AP_ID
, 0);
149 EXPECT_EQ(telemetryItems
[0].value
, 0);
151 // low precision altimeter, bp always less than 10
152 processHubPacket(BARO_ALT_BP_ID
, 12); // set value of 12.3m
153 processHubPacket(BARO_ALT_AP_ID
, 3);
154 EXPECT_EQ(telemetryItems
[0].value
, 123); // altitude stored has resolution of 0.1m
156 processHubPacket(BARO_ALT_BP_ID
, -12); // set value of -12.3m
157 processHubPacket(BARO_ALT_AP_ID
, 3);
158 EXPECT_EQ(telemetryItems
[0].value
, -123);
160 // hi precision altimeter, bp can be two decimals
164 // altimeter auto offset
165 processHubPacket(BARO_ALT_BP_ID
, 0);
166 processHubPacket(BARO_ALT_AP_ID
, 0);
167 EXPECT_EQ(telemetryItems
[0].value
, 0);
169 // first trigger hi precision, by setting AP above 9
170 processHubPacket(BARO_ALT_BP_ID
, -1); // set value of -1.35m
171 processHubPacket(BARO_ALT_AP_ID
, 35);
172 EXPECT_EQ(telemetryItems
[0].value
, -13);
174 processHubPacket(BARO_ALT_BP_ID
, 12); // set value of 12.35m
175 processHubPacket(BARO_ALT_AP_ID
, 35);
176 EXPECT_EQ(telemetryItems
[0].value
, 123);
178 // now test with the AP less than 10 to check if hiprecision is still active
179 processHubPacket(BARO_ALT_BP_ID
, 12); // set value of 12.05m
180 processHubPacket(BARO_ALT_AP_ID
, 05);
181 EXPECT_EQ(telemetryItems
[0].value
, 120);
188 allowNewSensors
= true;
190 EXPECT_EQ(telemetryItems
[0].value
, 0);
192 // latitude 15 degrees north, 30.5000 minutes = 15.508333333333333 degrees
193 processHubPacket(GPS_LAT_BP_ID
, 1530); // DDDMM.
194 processHubPacket(GPS_LAT_AP_ID
, 5000); // .MMMM
195 processHubPacket(GPS_LAT_NS_ID
, 'N');
197 // longitude 45 degrees west, 20.5000 minutes = 45.34166666666667 degrees
198 processHubPacket(GPS_LONG_BP_ID
, 4520);
199 processHubPacket(GPS_LONG_AP_ID
, 5000);
200 processHubPacket(GPS_LONG_EW_ID
, 'E');
202 EXPECT_EQ(telemetryItems
[0].gps
.latitude
, 15508333);
203 EXPECT_EQ(telemetryItems
[0].gps
.longitude
, 45341666);
206 #endif // defined(TELEMETRY_FRSKY) && defined(CPUARM)
208 #if defined(TELEMETRY_FRSKY_SPORT)
209 TEST(FrSkySPORT
, checkCrc
)
212 uint8_t pkt1
[] = { 0x7E, 0x98, 0x10, 0x10, 0x00, 0x7E, 0x02, 0x00, 0x00, 0x5F };
213 EXPECT_EQ(checkSportPacket(pkt1
+1), true);
215 uint8_t pkt2
[] = { 0x7E, 0x1C, 0x31, 0x00, 0x10, 0x85, 0x64, 0x00, 0x00, 0xD4 };
216 EXPECT_EQ(checkSportPacket(pkt2
+1), true);
219 void setSportPacketCrc(uint8_t * packet
)
222 for (int i
=1; i
<FRSKY_SPORT_PACKET_SIZE
-1; i
++) {
223 crc
+= packet
[i
]; //0-1FF
224 crc
+= crc
>> 8; //0-100
226 crc
+= crc
>> 8; //0-0FF
229 packet
[FRSKY_SPORT_PACKET_SIZE
-1] = 0xFF - (crc
& 0x00ff);
230 //TRACE("crc set: %x", packet[FRSKY_SPORT_PACKET_SIZE-1]);
233 void generateSportCellPacket(uint8_t * packet
, uint8_t cells
, uint8_t battnumber
, uint16_t cell1
, uint16_t cell2
, uint8_t sensorId
=DATA_ID_FLVSS
)
235 packet
[0] = sensorId
;
236 packet
[1] = 0x10; //DATA_FRAME
237 *((uint16_t *)(packet
+2)) = 0x0300; //CELLS_FIRST_ID
239 data
+= (cells
<< 4) + battnumber
;
240 data
+= ((cell1
* 5) & 0xFFF) << 8;
241 data
+= ((cell2
* 5) & 0xFFF) << 20;
242 *((int32_t *)(packet
+4)) = data
;
243 setSportPacketCrc(packet
);
246 #define _V(volts) (volts/TELEMETRY_CELL_VOLTAGE_MUTLIPLIER)
248 TEST(FrSkySPORT
, FrSkyDCells
)
252 allowNewSensors
= true;
254 uint8_t pkt1
[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x07, 0xD0, 0x00, 0x00, 0x12 };
255 EXPECT_EQ(checkSportPacket(pkt1
+1), true);
256 sportProcessTelemetryPacket(pkt1
+1);
257 uint8_t pkt2
[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x17, 0xD0, 0x00, 0x00, 0x02 };
258 EXPECT_EQ(checkSportPacket(pkt2
+1), true);
259 sportProcessTelemetryPacket(pkt2
+1);
260 uint8_t pkt3
[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x27, 0xD0, 0x00, 0x00, 0xF1 };
261 EXPECT_EQ(checkSportPacket(pkt3
+1), true);
262 sportProcessTelemetryPacket(pkt3
+1);
263 sportProcessTelemetryPacket(pkt1
+1);
264 sportProcessTelemetryPacket(pkt2
+1);
265 sportProcessTelemetryPacket(pkt3
+1);
266 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
267 EXPECT_EQ(telemetryItems
[0].value
, 1200);
268 for (int i
=0; i
<3; i
++) {
269 EXPECT_EQ(telemetryItems
[0].cells
.values
[i
].state
, 1);
270 EXPECT_EQ(telemetryItems
[0].cells
.values
[i
].value
, 400);
274 TEST(FrSkySPORT
, frskySetCellVoltage
)
276 uint8_t packet
[FRSKY_SPORT_PACKET_SIZE
];
280 allowNewSensors
= true;
282 // test that simulates 3 cell battery
283 generateSportCellPacket(packet
, 3, 0, _V(410), _V(420)); sportProcessTelemetryPacket(packet
);
284 EXPECT_EQ(checkSportPacket(packet
), true) << "Bad CRC generation in setSportPacketCrc()";
285 generateSportCellPacket(packet
, 3, 2, _V(430), _V( 0)); sportProcessTelemetryPacket(packet
);
287 generateSportCellPacket(packet
, 3, 0, _V(405), _V(300)); sportProcessTelemetryPacket(packet
);
288 generateSportCellPacket(packet
, 3, 2, _V(430), _V( 0)); sportProcessTelemetryPacket(packet
);
290 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
291 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 405);
292 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 300);
293 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 430);
294 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 0);
295 EXPECT_EQ(telemetryItems
[0].value
, 1135);
296 EXPECT_EQ(telemetryItems
[0].valueMin
, 1135);
297 EXPECT_EQ(telemetryItems
[0].valueMax
, 1260);
299 generateSportCellPacket(packet
, 3, 0, _V(405), _V(250)); sportProcessTelemetryPacket(packet
);
300 generateSportCellPacket(packet
, 3, 2, _V(430), _V( 0)); sportProcessTelemetryPacket(packet
);
302 generateSportCellPacket(packet
, 3, 0, _V(410), _V(420)); sportProcessTelemetryPacket(packet
);
303 generateSportCellPacket(packet
, 3, 2, _V(430), _V( 0)); sportProcessTelemetryPacket(packet
);
305 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
306 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 410);
307 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 420);
308 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 430);
309 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 0);
310 EXPECT_EQ(telemetryItems
[0].value
, 1260);
311 EXPECT_EQ(telemetryItems
[0].valueMin
, 1085);
312 EXPECT_EQ(telemetryItems
[0].valueMax
, 1260);
314 //add another two cells - 5 cell battery
315 generateSportCellPacket(packet
, 5, 0, _V(418), _V(408)); sportProcessTelemetryPacket(packet
);
316 generateSportCellPacket(packet
, 5, 2, _V(415), _V(420)); sportProcessTelemetryPacket(packet
);
317 generateSportCellPacket(packet
, 5, 4, _V(410), _V( 0)); sportProcessTelemetryPacket(packet
);
319 EXPECT_EQ(telemetryItems
[0].cells
.count
, 5);
320 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 418);
321 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 408);
322 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 415);
323 EXPECT_EQ(telemetryItems
[0].cells
.values
[3].value
, 420);
324 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 410);
325 EXPECT_EQ(telemetryItems
[0].cells
.values
[5].value
, 0);
326 EXPECT_EQ(telemetryItems
[0].value
, 2071);
327 EXPECT_EQ(telemetryItems
[0].valueMin
, 2071);
328 EXPECT_EQ(telemetryItems
[0].valueMax
, 2071);
330 //simulate very low voltage for cell 3
331 generateSportCellPacket(packet
, 5, 0, _V(418), _V(408)); sportProcessTelemetryPacket(packet
);
332 generateSportCellPacket(packet
, 5, 2, _V(100), _V(420)); sportProcessTelemetryPacket(packet
);
333 generateSportCellPacket(packet
, 5, 4, _V(410), _V( 0)); sportProcessTelemetryPacket(packet
);
335 EXPECT_EQ(telemetryItems
[0].cells
.count
, 5);
336 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 418);
337 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 408);
338 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 100);
339 EXPECT_EQ(telemetryItems
[0].cells
.values
[3].value
, 420);
340 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 410);
341 EXPECT_EQ(telemetryItems
[0].cells
.values
[5].value
, 0);
342 EXPECT_EQ(telemetryItems
[0].value
, 1756);
343 EXPECT_EQ(telemetryItems
[0].valueMin
, 1756);
344 EXPECT_EQ(telemetryItems
[0].valueMax
, 2071);
346 //back to normal (but with reversed order of packets)
347 generateSportCellPacket(packet
, 5, 4, _V(410), _V( 0)); sportProcessTelemetryPacket(packet
);
348 generateSportCellPacket(packet
, 5, 0, _V(418), _V(408)); sportProcessTelemetryPacket(packet
);
349 generateSportCellPacket(packet
, 5, 2, _V(412), _V(420)); sportProcessTelemetryPacket(packet
);
350 generateSportCellPacket(packet
, 5, 4, _V(410), _V( 0)); sportProcessTelemetryPacket(packet
);
352 EXPECT_EQ(telemetryItems
[0].cells
.count
, 5);
353 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 418);
354 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 408);
355 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 412);
356 EXPECT_EQ(telemetryItems
[0].cells
.values
[3].value
, 420);
357 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 410);
358 EXPECT_EQ(telemetryItems
[0].cells
.values
[5].value
, 0);
359 EXPECT_EQ(telemetryItems
[0].value
, 2068);
360 EXPECT_EQ(telemetryItems
[0].valueMin
, 1756);
361 EXPECT_EQ(telemetryItems
[0].valueMax
, 2071);
366 #if !defined(COLORLCD)
367 g_model
.frsky
.voltsSource
= FRSKY_VOLTS_SOURCE_A1
;
371 TEST(FrSkySPORT
, StrangeCellsBug
)
375 allowNewSensors
= true;
377 uint8_t pkt
[] = { 0x7E, 0x48, 0x10, 0x00, 0x03, 0x30, 0x15, 0x50, 0x81, 0xD5 };
378 EXPECT_EQ(checkSportPacket(pkt
+1), true);
379 sportProcessTelemetryPacket(pkt
+1);
380 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
381 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 0); // now we ignore such low values
382 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 413);
385 TEST(FrSkySPORT
, frskySetCellVoltageTwoSensors
)
387 uint8_t packet
[FRSKY_SPORT_PACKET_SIZE
];
391 allowNewSensors
= true;
393 //sensor 1: 3 cell battery
394 generateSportCellPacket(packet
, 3, 0, _V(418), _V(416)); sportProcessTelemetryPacket(packet
);
395 generateSportCellPacket(packet
, 3, 2, _V(415), _V( 0)); sportProcessTelemetryPacket(packet
);
397 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
398 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 418);
399 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 416);
400 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 415);
401 EXPECT_EQ(telemetryItems
[0].cells
.values
[3].value
, 0);
402 EXPECT_EQ(telemetryItems
[0].value
, 1249);
403 EXPECT_EQ(telemetryItems
[0].valueMin
, 1249);
404 EXPECT_EQ(telemetryItems
[0].valueMax
, 1249);
406 //sensor 2: 4 cell battery
407 generateSportCellPacket(packet
, 4, 0, _V(410), _V(420), DATA_ID_FLVSS
+1); sportProcessTelemetryPacket(packet
);
408 generateSportCellPacket(packet
, 4, 2, _V(400), _V(405), DATA_ID_FLVSS
+1); sportProcessTelemetryPacket(packet
);
410 EXPECT_EQ(telemetryItems
[1].cells
.count
, 4);
411 EXPECT_EQ(telemetryItems
[1].cells
.values
[0].value
, 410);
412 EXPECT_EQ(telemetryItems
[1].cells
.values
[1].value
, 420);
413 EXPECT_EQ(telemetryItems
[1].cells
.values
[2].value
, 400);
414 EXPECT_EQ(telemetryItems
[1].cells
.values
[3].value
, 405);
415 EXPECT_EQ(telemetryItems
[1].value
, 1635);
416 EXPECT_EQ(telemetryItems
[1].valueMin
, 1635);
417 EXPECT_EQ(telemetryItems
[1].valueMax
, 1635);
419 g_model
.telemetrySensors
[2].type
= TELEM_TYPE_CALCULATED
;
420 g_model
.telemetrySensors
[2].formula
= TELEM_FORMULA_ADD
;
421 g_model
.telemetrySensors
[2].prec
= 1;
422 g_model
.telemetrySensors
[2].calc
.sources
[0] = 1;
423 g_model
.telemetrySensors
[2].calc
.sources
[1] = 2;
427 EXPECT_EQ(telemetryItems
[2].value
, 287);
428 EXPECT_EQ(telemetryItems
[2].valueMin
, 287);
429 EXPECT_EQ(telemetryItems
[2].valueMax
, 287);
431 //now change some voltages
432 generateSportCellPacket(packet
, 3, 2, _V(415), _V( 0)); sportProcessTelemetryPacket(packet
);
433 generateSportCellPacket(packet
, 4, 2, _V(390), _V(370), DATA_ID_FLVSS
+1); sportProcessTelemetryPacket(packet
);
434 generateSportCellPacket(packet
, 3, 0, _V(420), _V(410)); sportProcessTelemetryPacket(packet
);
435 generateSportCellPacket(packet
, 4, 0, _V(410), _V(420), DATA_ID_FLVSS
+1); sportProcessTelemetryPacket(packet
);
439 EXPECT_EQ(telemetryItems
[2].value
, 283);
440 EXPECT_EQ(telemetryItems
[2].valueMin
, 283);
441 EXPECT_EQ(telemetryItems
[2].valueMax
, 287);
446 #if !defined(COLORLCD)
447 g_model
.frsky
.voltsSource
= FRSKY_VOLTS_SOURCE_A1
;
451 void generateSportFasVoltagePacket(uint8_t * packet
, uint32_t voltage
)
453 packet
[0] = 0x22; //DATA_ID_FAS
454 packet
[1] = 0x10; //DATA_FRAME
455 *((uint16_t *)(packet
+2)) = 0x0210; //VFAS_FIRST_ID
456 *((int32_t *)(packet
+4)) = voltage
; // unit 10mV
457 setSportPacketCrc(packet
);
460 TEST(FrSkySPORT
, frskyVfas
)
462 uint8_t packet
[FRSKY_SPORT_PACKET_SIZE
];
466 allowNewSensors
= true;
469 generateSportFasVoltagePacket(packet
, 5000); sportProcessTelemetryPacket(packet
);
470 EXPECT_EQ(telemetryItems
[0].value
, 5000);
471 EXPECT_EQ(telemetryItems
[0].valueMin
, 5000);
472 EXPECT_EQ(telemetryItems
[0].valueMax
, 5000);
474 generateSportFasVoltagePacket(packet
, 6524); sportProcessTelemetryPacket(packet
);
475 EXPECT_EQ(telemetryItems
[0].value
, 6524);
476 EXPECT_EQ(telemetryItems
[0].valueMin
, 6524); // the batt was changed (val > old max)
477 EXPECT_EQ(telemetryItems
[0].valueMax
, 6524);
479 generateSportFasVoltagePacket(packet
, 1248); sportProcessTelemetryPacket(packet
);
480 EXPECT_EQ(telemetryItems
[0].value
, 1248);
481 EXPECT_EQ(telemetryItems
[0].valueMin
, 1248);
482 EXPECT_EQ(telemetryItems
[0].valueMax
, 6524);
484 generateSportFasVoltagePacket(packet
, 2248); sportProcessTelemetryPacket(packet
);
485 EXPECT_EQ(telemetryItems
[0].value
, 2248);
486 EXPECT_EQ(telemetryItems
[0].valueMin
, 1248);
487 EXPECT_EQ(telemetryItems
[0].valueMax
, 6524);
490 void generateSportFasCurrentPacket(uint8_t * packet
, uint32_t current
)
492 packet
[0] = 0x22; //DATA_ID_FAS
493 packet
[1] = 0x10; //DATA_FRAME
494 *((uint16_t *)(packet
+2)) = 0x0200; //CURR_FIRST_ID
495 *((int32_t *)(packet
+4)) = current
;
496 setSportPacketCrc(packet
);
499 TEST(FrSkySPORT
, frskyCurrent
)
501 uint8_t packet
[FRSKY_SPORT_PACKET_SIZE
];
505 allowNewSensors
= true;
508 generateSportFasCurrentPacket(packet
, 0); sportProcessTelemetryPacket(packet
);
509 g_model
.telemetrySensors
[0].custom
.offset
= -5; /* unit: 1/10 amps */
510 generateSportFasCurrentPacket(packet
, 0); sportProcessTelemetryPacket(packet
);
511 EXPECT_EQ(telemetryItems
[0].value
, 0);
512 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
513 EXPECT_EQ(telemetryItems
[0].valueMax
, 0);
515 // measured current less then offset - value should be zero
516 generateSportFasCurrentPacket(packet
, 4); sportProcessTelemetryPacket(packet
);
517 EXPECT_EQ(telemetryItems
[0].value
, 0);
518 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
519 EXPECT_EQ(telemetryItems
[0].valueMax
, 0);
521 generateSportFasCurrentPacket(packet
, 10); sportProcessTelemetryPacket(packet
);
522 EXPECT_EQ(telemetryItems
[0].value
, 5);
523 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
524 EXPECT_EQ(telemetryItems
[0].valueMax
, 5);
526 generateSportFasCurrentPacket(packet
, 500); sportProcessTelemetryPacket(packet
);
527 EXPECT_EQ(telemetryItems
[0].value
, 495);
528 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
529 EXPECT_EQ(telemetryItems
[0].valueMax
, 495);
531 generateSportFasCurrentPacket(packet
, 200); sportProcessTelemetryPacket(packet
);
532 EXPECT_EQ(telemetryItems
[0].value
, 195);
533 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
534 EXPECT_EQ(telemetryItems
[0].valueMax
, 495);
536 // test with positive offset
538 g_model
.telemetrySensors
[0].custom
.offset
= +5; /* unit: 1/10 amps */
540 generateSportFasCurrentPacket(packet
, 0); sportProcessTelemetryPacket(packet
);
541 EXPECT_EQ(telemetryItems
[0].value
, 5);
542 EXPECT_EQ(telemetryItems
[0].valueMin
, 5);
543 EXPECT_EQ(telemetryItems
[0].valueMax
, 5);
545 generateSportFasCurrentPacket(packet
, 500); sportProcessTelemetryPacket(packet
);
546 EXPECT_EQ(telemetryItems
[0].value
, 505);
547 EXPECT_EQ(telemetryItems
[0].valueMin
, 5);
548 EXPECT_EQ(telemetryItems
[0].valueMax
, 505);
550 generateSportFasCurrentPacket(packet
, 200); sportProcessTelemetryPacket(packet
);
551 EXPECT_EQ(telemetryItems
[0].value
, 205);
552 EXPECT_EQ(telemetryItems
[0].valueMin
, 5);
553 EXPECT_EQ(telemetryItems
[0].valueMax
, 505);
556 #endif //#if defined(TELEMETRY_FRSKY_SPORT)