Skip to content

Commit f538884

Browse files
committed
XK2 low batt telemetry
1 parent d3e5acf commit f538884

File tree

5 files changed

+81
-32
lines changed

5 files changed

+81
-32
lines changed

Multiprotocol/FX_nrf24l01.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ Multiprotocol is distributed in the hope that it will be useful,
3434
#define FX620_CH_OFFSET 1
3535

3636
#define FX9630_PACKET_PERIOD 8124 //8156 on QIDI-560
37-
#define FX9630_BIND_PACKET_PERIOD 8124
3837
#define FX9630_BIND_CHANNEL 51
3938
#define FX9630_PAYLOAD_SIZE 8
4039
#define FX9630_NUM_CHANNELS 3
4140
#define FX9630_WRITE_TIME 500
4241

43-
#define FX_QF012_BIND_PACKET_PERIOD 12194
42+
#define FX_QF012_PACKET_PERIOD 12194
4443
#define FX_QF012_RX_PAYLOAD_SIZE 3
4544

4645
//#define FORCE_FX620_ID
@@ -199,7 +198,7 @@ static void __attribute__((unused)) FX_RF_init()
199198
{
200199
XN297_SetTXAddr((uint8_t *)"\x56\x78\x90\x12", 4);
201200
XN297_RFChannel(FX9630_BIND_CHANNEL);
202-
packet_period = sub_protocol == FX_QF012 ? FX_QF012_BIND_PACKET_PERIOD : FX9630_BIND_PACKET_PERIOD;
201+
packet_period = sub_protocol == FX_QF012 ? FX_QF012_PACKET_PERIOD : FX9630_PACKET_PERIOD;
203202
packet_length = FX9630_PAYLOAD_SIZE;
204203
}
205204
}
@@ -291,7 +290,7 @@ uint16_t FX_callback()
291290
{//Good CRC
292291
//packets: A5 00 11 -> A5 01 11
293292
telemetry_link = 1;
294-
v_lipo1 = packet_in[1] == 0x01 ? 60:81; // low voltage
293+
v_lipo1 = packet_in[1] ? 60:81; // low voltage 3.7V
295294
#if 0
296295
for(uint8_t i=0; i < FX_QF012_RX_PAYLOAD_SIZE; i++)
297296
debug(" %02X", packet_in[i]);

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 4
22-
#define VERSION_PATCH_LEVEL 48
22+
#define VERSION_PATCH_LEVEL 49
2323

2424
#define MODE_SERIAL 0
2525

Multiprotocol/XK2_ccnrf.ino

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,30 @@ Multiprotocol is distributed in the hope that it will be useful,
2121
//#define FORCE_XK2_ID
2222
//#define FORCE_XK2_P10_ID
2323

24-
#define XK2_RF_BIND_CHANNEL 71
24+
#define XK2_RF_BIND_CHANNEL 71
2525
#define XK2_P10_RF_BIND_CHANNEL 69
26-
#define XK2_PAYLOAD_SIZE 9
27-
#define XK2_PACKET_PERIOD 4911
28-
#define XK2_RF_NUM_CHANNELS 4
26+
#define XK2_PAYLOAD_SIZE 9
27+
#define XK2_PACKET_PERIOD 4911
28+
#define XK2_RF_NUM_CHANNELS 4
29+
#define XK2_WRITE_TIME 1000
2930

3031
enum {
3132
XK2_BIND1,
3233
XK2_BIND2,
3334
XK2_DATA_PREP,
34-
XK2_DATA
35+
XK2_DATA,
36+
XK2_RX,
3537
};
3638

39+
static uint8_t __attribute__((unused)) XK2_checksum(uint8_t init)
40+
{
41+
for(uint8_t i=0; i<XK2_PAYLOAD_SIZE-1; i++)
42+
init += packet[i];
43+
if(sub_protocol == XK2_P10)
44+
init += 0x10;
45+
return init;
46+
}
47+
3748
static void __attribute__((unused)) XK2_send_packet()
3849
{
3950
static uint8_t trim_ch=0;
@@ -47,8 +58,6 @@ static void __attribute__((unused)) XK2_send_packet()
4758
//memcpy(&packet[4], rx_id , 3);
4859
//Unknown
4960
packet[7] = 0x00;
50-
//Checksum seed
51-
packet[8] = 0xC0;
5261
}
5362
else
5463
{
@@ -77,19 +86,13 @@ static void __attribute__((unused)) XK2_send_packet()
7786
packet[5] |= 0x10; //Gyro off (senior mode)
7887
else if(Channel_data[CH6] > CHANNEL_MIN_COMMAND)
7988
packet[5] |= 0x08; //3D
80-
81-
//Telemetry not received=00, Telemetry received=01 but sometimes switch to 1 even if telemetry is not there...
82-
packet[6] = 0x00;
89+
//Requiest telemetry flag
90+
packet[6] = 0x01;
8391
//RXID checksum
8492
packet[7] = crc8; //Sum RX_ID[0..2]
85-
//Checksum seed
86-
packet[8] = num_ch; //Based on TX ID
8793
}
8894
//Checksum
89-
for(uint8_t i=0; i<XK2_PAYLOAD_SIZE-1; i++)
90-
packet[8] += packet[i];
91-
if(sub_protocol == XK2_P10)
92-
packet[8] += 0x10;
95+
packet[8] = XK2_checksum(IS_BIND_IN_PROGRESS ? 0xC0 : num_ch);
9396

9497
// Send
9598
XN297_SetFreqOffset();
@@ -160,6 +163,8 @@ static void __attribute__((unused)) XK2_initialize_txid()
160163

161164
uint16_t XK2_callback()
162165
{
166+
static bool rx = false;
167+
163168
switch(phase)
164169
{
165170
case XK2_BIND1:
@@ -178,13 +183,8 @@ uint16_t XK2_callback()
178183
debug(" %02X",packet[i]);
179184
debugln("");
180185
#endif
181-
crc8 = 0xBF;
182-
for(uint8_t i=0; i<XK2_PAYLOAD_SIZE-1; i++)
183-
crc8 += packet[i];
184-
if(sub_protocol == XK2_P10)
185-
crc8 += 0x10;
186-
if(crc8 != packet[8])
187-
{
186+
if(XK2_checksum(0xBF) != packet[8])
187+
{//Wrong checksum
188188
phase = XK2_BIND1;
189189
return 1000;
190190
}
@@ -209,23 +209,67 @@ uint16_t XK2_callback()
209209
XN297_SetTxRxMode(TXRX_OFF);
210210
XN297_SetTxRxMode(TX_EN);
211211
XN297_SetTXAddr(rx_tx_addr, 5);
212+
#ifdef XK2_HUB_TELEMETRY
213+
XN297_SetRXAddr(rx_tx_addr, XK2_PAYLOAD_SIZE);
214+
#endif
212215
BIND_DONE;
213216
phase++;
214217
case XK2_DATA:
215218
#ifdef MULTI_SYNC
216219
telemetry_set_input_sync(XK2_PACKET_PERIOD);
217220
#endif
221+
#ifdef XK2_HUB_TELEMETRY
222+
rx = XN297_IsRX();
223+
XN297_SetTxRxMode(TXRX_OFF);
224+
#endif
225+
XK2_send_packet();
226+
#ifdef XK2_HUB_TELEMETRY
227+
if(rx)
228+
{
229+
XN297_ReadPayload(packet, XK2_PAYLOAD_SIZE);
230+
#if 0
231+
debug("RX");
232+
for(uint8_t i=0; i<XK2_PAYLOAD_SIZE; i++)
233+
debug(" %02X",packet[i]);
234+
debugln("");
235+
#endif
236+
if(XK2_checksum(0xCC) == packet[8] && memcmp(packet, rx_tx_addr, 3) == 0)
237+
{//Good checksum and TXID
238+
//packets: E5 20 F2 00 00 00 00 00 C3 -> E5 20 F2 80 00 00 00 00 43
239+
telemetry_link = 1;
240+
v_lipo1 = packet[3] ? 137:162; // low voltage 7.1V
241+
}
242+
}
243+
#endif
218244
if(bind_counter)
219245
{
220246
bind_counter--;
221247
if(bind_counter == 0)
222-
{
223248
phase = XK2_DATA_PREP;
224-
//phase = XK2_BIND1;
225-
}
249+
break;
226250
}
227-
XK2_send_packet();
251+
#ifndef XK2_HUB_TELEMETRY
228252
break;
253+
#else
254+
phase++;
255+
return XK2_WRITE_TIME;
256+
default: //XK2_RX
257+
/*{ // Wait for packet to be sent before switching to receive mode
258+
uint16_t start=(uint16_t)micros(), count=0;
259+
while ((uint16_t)((uint16_t)micros()-(uint16_t)start) < 500)
260+
{
261+
if(XN297_IsPacketSent())
262+
break;
263+
count++;
264+
}
265+
debugln("%d",count);
266+
}*/
267+
//Switch to RX
268+
XN297_SetTxRxMode(TXRX_OFF);
269+
XN297_SetTxRxMode(RX_EN);
270+
phase = XK2_DATA;
271+
return XK2_PACKET_PERIOD-XK2_WRITE_TIME;
272+
#endif
229273
}
230274
return XK2_PACKET_PERIOD;
231275
}
@@ -242,6 +286,9 @@ void XK2_init()
242286
phase = XK2_DATA_PREP;
243287
bind_counter = 0;
244288
hopping_frequency_no = 0;
289+
#ifdef XK2_HUB_TELEMETRY
290+
RX_RSSI = 100; // Dummy value
291+
#endif
245292
}
246293

247294
#endif

Multiprotocol/_Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@
350350
#define V761_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
351351
#define KAMTOM_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
352352
#define FX_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
353+
#define XK2_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
353354
#define YUXIANG_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
354355
#define PROPEL_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
355356
#define CABELL_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX

Protocols_Details.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,8 @@ A|E|T|R|Rate|Mode|Hover|Light
15791579

15801580
The plane does not need to be bound each time if it is powered on **after** the radio/protocol is on.
15811581

1582+
Telemetry is supported. The plane sends a battery status of good->empty which is visible in A1 (good=8.4V->empty=7.1V) and RSSI gets a dummy value of 100.
1583+
15821584
The rudder trim is driven from the rudder channel to increase the range (Original TX rudder has no range once the motor has been turned on...).
15831585

15841586
Mode: -100%=6G, 0%=3D, +100%=Gyro off (Senior mode)

0 commit comments

Comments
 (0)