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
);
24 bool checkSportPacket(const uint8_t *packet
);
25 void sportProcessTelemetryPacket(const uint8_t * packet
);
26 bool checkSportPacket(const uint8_t *packet
);
28 TEST(FrSky
, TelemetryValueWithMinAveraging
)
31 The following expected[] array is filled
32 with values that correspond to 4 elements
33 long averaging buffer.
34 If length of averaging buffer is changed, this
35 values must be adjusted
37 uint8_t expected
[] = { 10, 12, 17, 25, 35, 45, 55, 65, 75, 85, 92, 97, 100, 100, 100, 100, 100};
40 TelemetryMinDecorator
<TelemetryFilterDecorator
<TelemetryValue
>> testVal
;
43 EXPECT_EQ(testVal
.value(), expected
[testPos
++]);
44 for (int n
= 2; n
< 10; ++n
) {
46 EXPECT_EQ(testVal
.value(), expected
[testPos
++]);
48 for (int n
= 2; n
< 10; ++n
) {
50 EXPECT_EQ(testVal
.value(), expected
[testPos
++]);
54 TEST(FrSky
, Vfas_0x39_HiPrecision
)
58 EXPECT_EQ(telemetryItems
[0].value
, 0);
59 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
60 telemetryData
.telemetryValid
= 0x07;
61 allowNewSensors
= true;
63 // normal precision, resolution 0.1V
64 processHubPacket(VFAS_ID
, 1234); // set value of 123.4V
65 EXPECT_EQ(telemetryItems
[0].value
, 12340); // stored value has resolution of 0.01V
67 // now high precision, resolution 0.01V
68 processHubPacket(VFAS_ID
, VFAS_D_HIPREC_OFFSET
); // set value of 0V
69 EXPECT_EQ(telemetryItems
[0].value
, 0);
70 processHubPacket(VFAS_ID
, VFAS_D_HIPREC_OFFSET
+ 12345); // set value of 123.45V
71 EXPECT_EQ(telemetryItems
[0].value
, 12345);
72 processHubPacket(VFAS_ID
, VFAS_D_HIPREC_OFFSET
+ 30012); // set value of 300.12V
73 EXPECT_EQ(telemetryItems
[0].value
, 30012);
76 TEST(FrSky
, HubAltNegative
)
80 EXPECT_EQ(telemetryItems
[0].value
, 0);
81 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
82 telemetryData
.telemetryValid
= 0x07;
83 allowNewSensors
= true;
85 // altimeter auto offset
86 processHubPacket(BARO_ALT_BP_ID
, 0);
87 processHubPacket(BARO_ALT_AP_ID
, 0);
88 EXPECT_EQ(telemetryItems
[0].value
, 0);
90 // low precision altimeter, bp always less than 10
91 processHubPacket(BARO_ALT_BP_ID
, 12); // set value of 12.3m
92 processHubPacket(BARO_ALT_AP_ID
, 3);
93 EXPECT_EQ(telemetryItems
[0].value
, 123); // altitude stored has resolution of 0.1m
95 processHubPacket(BARO_ALT_BP_ID
, -12); // set value of -12.3m
96 processHubPacket(BARO_ALT_AP_ID
, 3);
97 EXPECT_EQ(telemetryItems
[0].value
, -123);
99 // hi precision altimeter, bp can be two decimals
103 // altimeter auto offset
104 processHubPacket(BARO_ALT_BP_ID
, 0);
105 processHubPacket(BARO_ALT_AP_ID
, 0);
106 EXPECT_EQ(telemetryItems
[0].value
, 0);
108 // first trigger hi precision, by setting AP above 9
109 processHubPacket(BARO_ALT_BP_ID
, -1); // set value of -1.35m
110 processHubPacket(BARO_ALT_AP_ID
, 35);
111 EXPECT_EQ(telemetryItems
[0].value
, -13);
113 processHubPacket(BARO_ALT_BP_ID
, 12); // set value of 12.35m
114 processHubPacket(BARO_ALT_AP_ID
, 35);
115 EXPECT_EQ(telemetryItems
[0].value
, 123);
117 // now test with the AP less than 10 to check if hiprecision is still active
118 processHubPacket(BARO_ALT_BP_ID
, 12); // set value of 12.05m
119 processHubPacket(BARO_ALT_AP_ID
, 05);
120 EXPECT_EQ(telemetryItems
[0].value
, 120);
127 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
128 telemetryData
.telemetryValid
= 0x07;
129 allowNewSensors
= true;
131 EXPECT_EQ(telemetryItems
[0].value
, 0);
133 // latitude 15 degrees north, 30.5000 minutes = 15.508333333333333 degrees
134 processHubPacket(GPS_LAT_BP_ID
, 1530); // DDDMM.
135 processHubPacket(GPS_LAT_AP_ID
, 5000); // .MMMM
136 processHubPacket(GPS_LAT_NS_ID
, 'N');
138 // longitude 45 degrees west, 20.5000 minutes = 45.34166666666667 degrees
139 processHubPacket(GPS_LONG_BP_ID
, 4520);
140 processHubPacket(GPS_LONG_AP_ID
, 5000);
141 processHubPacket(GPS_LONG_EW_ID
, 'E');
143 EXPECT_EQ(telemetryItems
[0].gps
.latitude
, 15508333);
144 EXPECT_EQ(telemetryItems
[0].gps
.longitude
, 45341666);
147 TEST(FrSkySPORT
, checkCrc
)
150 uint8_t pkt1
[] = { 0x7E, 0x98, 0x10, 0x10, 0x00, 0x7E, 0x02, 0x00, 0x00, 0x5F };
151 EXPECT_EQ(checkSportPacket(pkt1
+1), true);
153 uint8_t pkt2
[] = { 0x7E, 0x1C, 0x31, 0x00, 0x10, 0x85, 0x64, 0x00, 0x00, 0xD4 };
154 EXPECT_EQ(checkSportPacket(pkt2
+1), true);
157 void setSportPacketCrc(uint8_t * packet
)
160 for (int i
=1; i
<FRSKY_SPORT_PACKET_SIZE
-1; i
++) {
161 crc
+= packet
[i
]; //0-1FF
162 crc
+= crc
>> 8; //0-100
164 crc
+= crc
>> 8; //0-0FF
167 packet
[FRSKY_SPORT_PACKET_SIZE
-1] = 0xFF - (crc
& 0x00ff);
168 //TRACE("crc set: %x", packet[FRSKY_SPORT_PACKET_SIZE-1]);
171 void generateSportCellPacket(uint8_t * packet
, uint8_t cells
, uint8_t battnumber
, uint16_t cell1
, uint16_t cell2
, uint8_t sensorId
=DATA_ID_FLVSS
)
173 packet
[0] = sensorId
;
174 packet
[1] = 0x10; //DATA_FRAME
175 *((uint16_t *)(packet
+2)) = 0x0300; //CELLS_FIRST_ID
177 data
+= (cells
<< 4) + battnumber
;
178 data
+= ((cell1
* 5) & 0xFFF) << 8;
179 data
+= ((cell2
* 5) & 0xFFF) << 20;
180 *((int32_t *)(packet
+4)) = data
;
181 setSportPacketCrc(packet
);
184 TEST(FrSkySPORT
, FrSkyDCells
)
188 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
189 telemetryData
.telemetryValid
= 0x07;
190 allowNewSensors
= true;
192 uint8_t pkt1
[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x07, 0xD0, 0x00, 0x00, 0x12 };
193 EXPECT_EQ(checkSportPacket(pkt1
+1), true);
194 sportProcessTelemetryPacket(pkt1
+1);
195 uint8_t pkt2
[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x17, 0xD0, 0x00, 0x00, 0x02 };
196 EXPECT_EQ(checkSportPacket(pkt2
+1), true);
197 sportProcessTelemetryPacket(pkt2
+1);
198 uint8_t pkt3
[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x27, 0xD0, 0x00, 0x00, 0xF1 };
199 EXPECT_EQ(checkSportPacket(pkt3
+1), true);
200 sportProcessTelemetryPacket(pkt3
+1);
201 sportProcessTelemetryPacket(pkt1
+1);
202 sportProcessTelemetryPacket(pkt2
+1);
203 sportProcessTelemetryPacket(pkt3
+1);
204 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
205 EXPECT_EQ(telemetryItems
[0].value
, 1200);
206 for (int i
=0; i
<3; i
++) {
207 EXPECT_EQ(telemetryItems
[0].cells
.values
[i
].state
, 1);
208 EXPECT_EQ(telemetryItems
[0].cells
.values
[i
].value
, 400);
212 TEST(FrSkySPORT
, frskySetCellVoltage
)
214 uint8_t packet
[FRSKY_SPORT_PACKET_SIZE
];
218 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
219 telemetryData
.telemetryValid
= 0x07;
220 allowNewSensors
= true;
222 // test that simulates 3 cell battery
223 generateSportCellPacket(packet
, 3, 0, 410, 420); sportProcessTelemetryPacket(packet
);
224 EXPECT_EQ(checkSportPacket(packet
), true) << "Bad CRC generation in setSportPacketCrc()";
225 generateSportCellPacket(packet
, 3, 2, 430, 0); sportProcessTelemetryPacket(packet
);
227 generateSportCellPacket(packet
, 3, 0, 405, 300); sportProcessTelemetryPacket(packet
);
228 generateSportCellPacket(packet
, 3, 2, 430, 0); sportProcessTelemetryPacket(packet
);
230 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
231 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 405);
232 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 300);
233 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 430);
234 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 0);
235 EXPECT_EQ(telemetryItems
[0].value
, 1135);
236 EXPECT_EQ(telemetryItems
[0].valueMin
, 1135);
237 EXPECT_EQ(telemetryItems
[0].valueMax
, 1260);
239 generateSportCellPacket(packet
, 3, 0, 405, 250); sportProcessTelemetryPacket(packet
);
240 generateSportCellPacket(packet
, 3, 2, 430, 0); sportProcessTelemetryPacket(packet
);
242 generateSportCellPacket(packet
, 3, 0, 410, 420); sportProcessTelemetryPacket(packet
);
243 generateSportCellPacket(packet
, 3, 2, 430, 0); sportProcessTelemetryPacket(packet
);
245 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
246 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 410);
247 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 420);
248 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 430);
249 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 0);
250 EXPECT_EQ(telemetryItems
[0].value
, 1260);
251 EXPECT_EQ(telemetryItems
[0].valueMin
, 1085);
252 EXPECT_EQ(telemetryItems
[0].valueMax
, 1260);
254 //add another two cells - 5 cell battery
255 generateSportCellPacket(packet
, 5, 0, 418, 408); sportProcessTelemetryPacket(packet
);
256 generateSportCellPacket(packet
, 5, 2, 415, 420); sportProcessTelemetryPacket(packet
);
257 generateSportCellPacket(packet
, 5, 4, 410, 0); sportProcessTelemetryPacket(packet
);
259 EXPECT_EQ(telemetryItems
[0].cells
.count
, 5);
260 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 418);
261 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 408);
262 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 415);
263 EXPECT_EQ(telemetryItems
[0].cells
.values
[3].value
, 420);
264 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 410);
265 EXPECT_EQ(telemetryItems
[0].cells
.values
[5].value
, 0);
266 EXPECT_EQ(telemetryItems
[0].value
, 2071);
267 EXPECT_EQ(telemetryItems
[0].valueMin
, 2071);
268 EXPECT_EQ(telemetryItems
[0].valueMax
, 2071);
270 //simulate very low voltage for cell 3
271 generateSportCellPacket(packet
, 5, 0, 418, 408); sportProcessTelemetryPacket(packet
);
272 generateSportCellPacket(packet
, 5, 2, 100, 420); sportProcessTelemetryPacket(packet
);
273 generateSportCellPacket(packet
, 5, 4, 410, 0); sportProcessTelemetryPacket(packet
);
275 EXPECT_EQ(telemetryItems
[0].cells
.count
, 5);
276 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 418);
277 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 408);
278 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 100);
279 EXPECT_EQ(telemetryItems
[0].cells
.values
[3].value
, 420);
280 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 410);
281 EXPECT_EQ(telemetryItems
[0].cells
.values
[5].value
, 0);
282 EXPECT_EQ(telemetryItems
[0].value
, 1756);
283 EXPECT_EQ(telemetryItems
[0].valueMin
, 1756);
284 EXPECT_EQ(telemetryItems
[0].valueMax
, 2071);
286 //back to normal (but with reversed order of packets)
287 generateSportCellPacket(packet
, 5, 4, 410, 0); sportProcessTelemetryPacket(packet
);
288 generateSportCellPacket(packet
, 5, 0, 418, 408); sportProcessTelemetryPacket(packet
);
289 generateSportCellPacket(packet
, 5, 2, 412, 420); sportProcessTelemetryPacket(packet
);
290 generateSportCellPacket(packet
, 5, 4, 410, 0); sportProcessTelemetryPacket(packet
);
292 EXPECT_EQ(telemetryItems
[0].cells
.count
, 5);
293 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 418);
294 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 408);
295 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 412);
296 EXPECT_EQ(telemetryItems
[0].cells
.values
[3].value
, 420);
297 EXPECT_EQ(telemetryItems
[0].cells
.values
[4].value
, 410);
298 EXPECT_EQ(telemetryItems
[0].cells
.values
[5].value
, 0);
299 EXPECT_EQ(telemetryItems
[0].value
, 2068);
300 EXPECT_EQ(telemetryItems
[0].valueMin
, 1756);
301 EXPECT_EQ(telemetryItems
[0].valueMax
, 2071);
307 TEST(FrSkySPORT
, StrangeCellsBug
)
311 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
312 telemetryData
.telemetryValid
= 0x07;
313 allowNewSensors
= true;
315 uint8_t pkt
[] = { 0x7E, 0x48, 0x10, 0x00, 0x03, 0x30, 0x15, 0x50, 0x81, 0xD5 };
316 EXPECT_EQ(checkSportPacket(pkt
+1), true);
317 sportProcessTelemetryPacket(pkt
+1);
318 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
319 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 0); // now we ignore such low values
320 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 413);
323 TEST(FrSkySPORT
, frskySetCellVoltageTwoSensors
)
325 uint8_t packet
[FRSKY_SPORT_PACKET_SIZE
];
329 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
330 telemetryData
.telemetryValid
= 0x07;
331 allowNewSensors
= true;
333 //sensor 1: 3 cell battery
334 generateSportCellPacket(packet
, 3, 0, 418, 416); sportProcessTelemetryPacket(packet
);
335 generateSportCellPacket(packet
, 3, 2, 415, 0); sportProcessTelemetryPacket(packet
);
337 EXPECT_EQ(telemetryItems
[0].cells
.count
, 3);
338 EXPECT_EQ(telemetryItems
[0].cells
.values
[0].value
, 418);
339 EXPECT_EQ(telemetryItems
[0].cells
.values
[1].value
, 416);
340 EXPECT_EQ(telemetryItems
[0].cells
.values
[2].value
, 415);
341 EXPECT_EQ(telemetryItems
[0].cells
.values
[3].value
, 0);
342 EXPECT_EQ(telemetryItems
[0].value
, 1249);
343 EXPECT_EQ(telemetryItems
[0].valueMin
, 1249);
344 EXPECT_EQ(telemetryItems
[0].valueMax
, 1249);
346 //sensor 2: 4 cell battery
347 generateSportCellPacket(packet
, 4, 0, 410, 420, DATA_ID_FLVSS
+1); sportProcessTelemetryPacket(packet
);
348 generateSportCellPacket(packet
, 4, 2, 400, 405, DATA_ID_FLVSS
+1); sportProcessTelemetryPacket(packet
);
350 EXPECT_EQ(telemetryItems
[1].cells
.count
, 4);
351 EXPECT_EQ(telemetryItems
[1].cells
.values
[0].value
, 410);
352 EXPECT_EQ(telemetryItems
[1].cells
.values
[1].value
, 420);
353 EXPECT_EQ(telemetryItems
[1].cells
.values
[2].value
, 400);
354 EXPECT_EQ(telemetryItems
[1].cells
.values
[3].value
, 405);
355 EXPECT_EQ(telemetryItems
[1].value
, 1635);
356 EXPECT_EQ(telemetryItems
[1].valueMin
, 1635);
357 EXPECT_EQ(telemetryItems
[1].valueMax
, 1635);
359 g_model
.telemetrySensors
[2].type
= TELEM_TYPE_CALCULATED
;
360 g_model
.telemetrySensors
[2].formula
= TELEM_FORMULA_ADD
;
361 g_model
.telemetrySensors
[2].prec
= 1;
362 g_model
.telemetrySensors
[2].calc
.sources
[0] = 1;
363 g_model
.telemetrySensors
[2].calc
.sources
[1] = 2;
367 EXPECT_EQ(telemetryItems
[2].value
, 287);
368 EXPECT_EQ(telemetryItems
[2].valueMin
, 287);
369 EXPECT_EQ(telemetryItems
[2].valueMax
, 287);
371 //now change some voltages
372 generateSportCellPacket(packet
, 3, 2, 415, 0); sportProcessTelemetryPacket(packet
);
373 generateSportCellPacket(packet
, 4, 2, 390, 370, DATA_ID_FLVSS
+1); sportProcessTelemetryPacket(packet
);
374 generateSportCellPacket(packet
, 3, 0, 420, 410); sportProcessTelemetryPacket(packet
);
375 generateSportCellPacket(packet
, 4, 0, 410, 420, DATA_ID_FLVSS
+1); sportProcessTelemetryPacket(packet
);
379 EXPECT_EQ(telemetryItems
[2].value
, 283);
380 EXPECT_EQ(telemetryItems
[2].valueMin
, 283);
381 EXPECT_EQ(telemetryItems
[2].valueMax
, 287);
387 void generateSportFasVoltagePacket(uint8_t * packet
, uint32_t voltage
)
389 packet
[0] = 0x22; //DATA_ID_FAS
390 packet
[1] = 0x10; //DATA_FRAME
391 *((uint16_t *)(packet
+2)) = 0x0210; //VFAS_FIRST_ID
392 *((int32_t *)(packet
+4)) = voltage
; // unit 10mV
393 setSportPacketCrc(packet
);
396 TEST(FrSkySPORT
, frskyVfas
)
398 uint8_t packet
[FRSKY_SPORT_PACKET_SIZE
];
402 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
403 telemetryData
.telemetryValid
= 0x07;
404 allowNewSensors
= true;
407 generateSportFasVoltagePacket(packet
, 5000); sportProcessTelemetryPacket(packet
);
408 EXPECT_EQ(telemetryItems
[0].value
, 5000);
409 EXPECT_EQ(telemetryItems
[0].valueMin
, 5000);
410 EXPECT_EQ(telemetryItems
[0].valueMax
, 5000);
412 generateSportFasVoltagePacket(packet
, 6524); sportProcessTelemetryPacket(packet
);
413 EXPECT_EQ(telemetryItems
[0].value
, 6524);
414 EXPECT_EQ(telemetryItems
[0].valueMin
, 6524); // the batt was changed (val > old max)
415 EXPECT_EQ(telemetryItems
[0].valueMax
, 6524);
417 generateSportFasVoltagePacket(packet
, 1248); sportProcessTelemetryPacket(packet
);
418 EXPECT_EQ(telemetryItems
[0].value
, 1248);
419 EXPECT_EQ(telemetryItems
[0].valueMin
, 1248);
420 EXPECT_EQ(telemetryItems
[0].valueMax
, 6524);
422 generateSportFasVoltagePacket(packet
, 2248); sportProcessTelemetryPacket(packet
);
423 EXPECT_EQ(telemetryItems
[0].value
, 2248);
424 EXPECT_EQ(telemetryItems
[0].valueMin
, 1248);
425 EXPECT_EQ(telemetryItems
[0].valueMax
, 6524);
428 void generateSportFasCurrentPacket(uint8_t * packet
, uint32_t current
)
430 packet
[0] = 0x22; //DATA_ID_FAS
431 packet
[1] = 0x10; //DATA_FRAME
432 *((uint16_t *)(packet
+2)) = 0x0200; //CURR_FIRST_ID
433 *((int32_t *)(packet
+4)) = current
;
434 setSportPacketCrc(packet
);
437 TEST(FrSkySPORT
, frskyCurrent
)
439 uint8_t packet
[FRSKY_SPORT_PACKET_SIZE
];
443 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
444 telemetryData
.telemetryValid
= 0x07;
445 allowNewSensors
= true;
448 generateSportFasCurrentPacket(packet
, 0);
449 sportProcessTelemetryPacket(packet
);
450 g_model
.telemetrySensors
[0].custom
.offset
= -5; /* unit: 1/10 amps */
451 generateSportFasCurrentPacket(packet
, 0); sportProcessTelemetryPacket(packet
);
452 EXPECT_EQ(telemetryItems
[0].value
, 0);
453 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
454 EXPECT_EQ(telemetryItems
[0].valueMax
, 0);
456 // measured current less then offset - value should be zero
457 generateSportFasCurrentPacket(packet
, 4); sportProcessTelemetryPacket(packet
);
458 EXPECT_EQ(telemetryItems
[0].value
, 0);
459 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
460 EXPECT_EQ(telemetryItems
[0].valueMax
, 0);
462 generateSportFasCurrentPacket(packet
, 10); sportProcessTelemetryPacket(packet
);
463 EXPECT_EQ(telemetryItems
[0].value
, 5);
464 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
465 EXPECT_EQ(telemetryItems
[0].valueMax
, 5);
467 generateSportFasCurrentPacket(packet
, 500); sportProcessTelemetryPacket(packet
);
468 EXPECT_EQ(telemetryItems
[0].value
, 495);
469 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
470 EXPECT_EQ(telemetryItems
[0].valueMax
, 495);
472 generateSportFasCurrentPacket(packet
, 200); sportProcessTelemetryPacket(packet
);
473 EXPECT_EQ(telemetryItems
[0].value
, 195);
474 EXPECT_EQ(telemetryItems
[0].valueMin
, 0);
475 EXPECT_EQ(telemetryItems
[0].valueMax
, 495);
477 // test with positive offset
479 telemetryStreaming
= TELEMETRY_TIMEOUT10ms
;
480 telemetryData
.telemetryValid
= 0x07;
481 g_model
.telemetrySensors
[0].custom
.offset
= +5; /* unit: 1/10 amps */
483 generateSportFasCurrentPacket(packet
, 0); sportProcessTelemetryPacket(packet
);
484 EXPECT_EQ(telemetryItems
[0].value
, 5);
485 EXPECT_EQ(telemetryItems
[0].valueMin
, 5);
486 EXPECT_EQ(telemetryItems
[0].valueMax
, 5);
488 generateSportFasCurrentPacket(packet
, 500); sportProcessTelemetryPacket(packet
);
489 EXPECT_EQ(telemetryItems
[0].value
, 505);
490 EXPECT_EQ(telemetryItems
[0].valueMin
, 5);
491 EXPECT_EQ(telemetryItems
[0].valueMax
, 505);
493 generateSportFasCurrentPacket(packet
, 200); sportProcessTelemetryPacket(packet
);
494 EXPECT_EQ(telemetryItems
[0].value
, 205);
495 EXPECT_EQ(telemetryItems
[0].valueMin
, 5);
496 EXPECT_EQ(telemetryItems
[0].valueMax
, 505);