Skip to content

Commit ecfe179

Browse files
committed
V761 telemetry fix
1 parent f97aa35 commit ecfe179

2 files changed

Lines changed: 43 additions & 33 deletions

File tree

Multiprotocol/Multiprotocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define VERSION_MAJOR 1
2020
#define VERSION_MINOR 3
2121
#define VERSION_REVISION 3
22-
#define VERSION_PATCH_LEVEL 32
22+
#define VERSION_PATCH_LEVEL 33
2323

2424
#define MODE_SERIAL 0
2525

Multiprotocol/V761_nrf24l01.ino

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Multiprotocol is distributed in the hope that it will be useful,
3030
#define TOPRC_PACKET_PERIOD 14120 // Timeout for callback in uSec
3131

3232
#define V761_WRITE_TIME 450
33+
#define V761_TELEM_PACKET_PERIOD 14088 // Timeout for callback in uSec
3334
//#define V761_TELEM_DEBUG
3435

3536
enum
@@ -72,6 +73,10 @@ static void __attribute__((unused)) V761_send_packet()
7273
}
7374
else
7475
{
76+
#ifdef V761_TELEM_DEBUG
77+
debug_time("");
78+
debugln(" Ph:%d",hopping_frequency_no);
79+
#endif
7580
XN297_Hopping(hopping_frequency_no++);
7681
if(hopping_frequency_no >= V761_RF_NUM_CHANNELS)
7782
{
@@ -228,22 +233,24 @@ uint16_t V761_callback()
228233
return 15730;
229234
#ifdef V761_HUB_TELEMETRY
230235
case V761_RX_CHECK:
231-
rx = XN297_IsRX(); // Needed for the NRF24L01 since otherwise the bit gets cleared
232-
packet_count++;
233-
if(packet_count > 6*21) // About 1 sec with no telemetry
236+
rx = XN297_IsRX(); // Needed for the NRF24L01 since otherwise the bit gets cleared
237+
XN297_SetTxRxMode(TXRX_OFF);
238+
if(packet_count > 4*63) // Around 3.5sec with no telemetry
239+
{
234240
telemetry_lost = 1;
235-
if(packet_telem++ >= 100)
236-
TX_LQI = packet_telem = 0;
237-
if(!telemetry_lost && !rx && (packet_count%22) == 0)
238-
{// Should have received a telem packet but... Send telem to the radio to keep it alive
239-
TX_LQI++;
240-
RX_RSSI = 100 - TX_LQI;
241-
telemetry_link = 1;
242-
#ifdef V761_TELEM_DEBUG
243-
debugln("Miss");
244-
#endif
241+
packet_period = V761_PACKET_PERIOD;
242+
}
243+
else
244+
{
245+
packet_count++;
246+
if(!telemetry_lost && !rx && (packet_count%64) == 0)
247+
{// Should have received a telem packet but... Send telem to the radio to keep it alive
248+
telemetry_link = 1;
249+
#ifdef V761_TELEM_DEBUG
250+
debugln("Miss");
251+
#endif
252+
}
245253
}
246-
XN297_SetTxRxMode(TXRX_OFF);
247254
phase++;
248255
#endif
249256
case V761_DATA:
@@ -252,11 +259,8 @@ uint16_t V761_callback()
252259
#endif
253260
V761_send_packet();
254261
#ifdef V761_HUB_TELEMETRY
255-
if(hopping_frequency_no == 1)
256-
{ // Start RX on RF channel 0
257-
phase++;
258-
return V761_WRITE_TIME;
259-
}
262+
if(sub_protocol == V761_TOPRC)
263+
break;
260264
if(rx)
261265
{ // Check if a packet has been received
262266
#ifdef V761_TELEM_DEBUG
@@ -268,14 +272,25 @@ uint16_t V761_callback()
268272
debug("OK:");
269273
for(uint8_t i=0;i<V761_RXPAYLOAD_SIZE;i++)
270274
debug(" %02X",packet_in[i]);
275+
debug(" pps:%d", packet_count);
271276
#endif
272277
// packet_in[] = AA 00 55 -> battery ok
273278
// packet_in[] = 55 00 AA -> low battery
274-
v_lipo1=packet_in[0] >> 1;
275-
RX_RSSI = 100 - TX_LQI;
276-
telemetry_link = 1;
277-
telemetry_lost = 0;
278-
packet_count = 0;
279+
crc8 = 0;
280+
for(uint8_t i=0;i<V761_RXPAYLOAD_SIZE;i++)
281+
crc8 ^= packet_in[i];
282+
if(crc8 == 0xFF)
283+
{
284+
v_lipo1 = packet_in[0] >> 1;
285+
telemetry_link = 1;
286+
telemetry_lost = 0;
287+
packet_count = 0;
288+
packet_period = V761_TELEM_PACKET_PERIOD;
289+
}
290+
#ifdef V761_TELEM_DEBUG
291+
else // Bad packet
292+
debug(" NOK");
293+
#endif
279294
}
280295
#ifdef V761_TELEM_DEBUG
281296
else // Bad packet
@@ -284,23 +299,17 @@ uint16_t V761_callback()
284299
#endif
285300
rx = false;
286301
}
287-
break;
302+
phase++;
303+
return V761_WRITE_TIME;
288304
case V761_RX:
289305
{ // Wait for packet to be sent before switching to receive mode
290306
uint16_t start=(uint16_t)micros();
291307
while ((uint16_t)((uint16_t)micros()-(uint16_t)start) < 500)
292-
{
293308
if(XN297_IsPacketSent())
294309
break;
295-
}
296310
}
297311
XN297_SetTxRxMode(RX_EN);
298312
phase = V761_RX_CHECK;
299-
if(!telemetry_lost && packet_count%20==0)
300-
{ // Telemetry packets are sent every 21 packets but with a huge jitter from 4ms to 10+ms
301-
hopping_frequency_no++; //don't send next packet to ensure we have enough time to receive the telemetry
302-
return 2 * packet_period - V761_WRITE_TIME;
303-
}
304313
return packet_period - V761_WRITE_TIME;
305314
#else
306315
break;
@@ -343,6 +352,7 @@ void V761_init(void)
343352
#ifdef V761_HUB_TELEMETRY
344353
packet_count = 0;
345354
telemetry_lost = 1;
355+
RX_RSSI = 100; // Dummy value
346356
#endif
347357
}
348358

0 commit comments

Comments
 (0)