Skip to content

Commit bb6d5c2

Browse files
committed
Updating CFLIE protocol - CPPM EMU as default istead of CRTP RPYT, allowing fixed RF channel and bitrate
1 parent d7f9ef6 commit bb6d5c2

File tree

4 files changed

+79
-86
lines changed

4 files changed

+79
-86
lines changed

Multiprotocol/CFlie_nrf24l01.ino

Lines changed: 61 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "iface_nrf24l01.h"
2121

2222
#define CFLIE_BIND_COUNT 60
23+
//#define CFLIE_USE_CRTP_RPYT
2324

2425
//=============================================================================
2526
// CRTP (Crazy RealTime Protocol) Implementation
@@ -220,8 +221,8 @@ static uint8_t packet_ack()
220221

221222
static void set_rate_channel(uint8_t rate, uint8_t channel)
222223
{
223-
NRF24L01_WriteReg(NRF24L01_05_RF_CH, channel); // Defined by model id
224-
NRF24L01_SetBitrate(rate); // Defined by model id
224+
NRF24L01_WriteReg(NRF24L01_05_RF_CH, channel);
225+
NRF24L01_SetBitrate(rate);
225226
}
226227

227228
static void send_search_packet()
@@ -232,23 +233,26 @@ static void send_search_packet()
232233
NRF24L01_WriteReg(NRF24L01_07_STATUS, (BV(NRF24L01_07_TX_DS) | BV(NRF24L01_07_MAX_RT)));
233234
NRF24L01_FlushTx();
234235

235-
if (rf_ch_num++ > 125)
236-
{
237-
rf_ch_num = 0;
238-
switch(data_rate)
239-
{
240-
case NRF24L01_BR_250K:
241-
data_rate = NRF24L01_BR_1M;
242-
break;
243-
case NRF24L01_BR_1M:
244-
data_rate = NRF24L01_BR_2M;
245-
break;
246-
case NRF24L01_BR_2M:
247-
data_rate = NRF24L01_BR_250K;
248-
break;
249-
}
250-
}
251-
set_rate_channel(data_rate, rf_ch_num);
236+
if (sub_protocol == CFLIE_AUTO)
237+
{
238+
if (rf_ch_num++ > 125)
239+
{
240+
rf_ch_num = 0;
241+
switch(data_rate)
242+
{
243+
case NRF24L01_BR_250K:
244+
data_rate = NRF24L01_BR_1M;
245+
break;
246+
case NRF24L01_BR_1M:
247+
data_rate = NRF24L01_BR_2M;
248+
break;
249+
case NRF24L01_BR_2M:
250+
data_rate = NRF24L01_BR_250K;
251+
break;
252+
}
253+
}
254+
}
255+
set_rate_channel(data_rate, rf_ch_num);
252256

253257
NRF24L01_WritePayload(buf, sizeof(buf));
254258

@@ -355,7 +359,7 @@ static void send_crtp_rpyt_packet()
355359
send_packet();
356360
}
357361

358-
/*static void send_crtp_cppm_emu_packet()
362+
static void send_crtp_cppm_emu_packet()
359363
{
360364
struct CommanderPacketCppmEmu {
361365
struct {
@@ -376,7 +380,7 @@ static void send_crtp_rpyt_packet()
376380

377381
// Make sure the number of aux channels in use is capped to MAX_CPPM_AUX_CHANNELS
378382
// uint8_t numAuxChannels = Model.num_channels - 4;
379-
uint8_t numAuxChannels = 2; // TODO: Figure this out correctly
383+
uint8_t numAuxChannels = 4;
380384
if(numAuxChannels > MAX_CPPM_AUX_CHANNELS)
381385
{
382386
numAuxChannels = MAX_CPPM_AUX_CHANNELS;
@@ -385,16 +389,16 @@ static void send_crtp_rpyt_packet()
385389
cpkt.hdr.numAuxChannels = numAuxChannels;
386390

387391
// Remap AETR to AERT (RPYT)
388-
cpkt.channelRoll = convert_channel_16b_limit(AILERON,1000,2000);
392+
cpkt.channelRoll = convert_channel_16b_limit(AILERON,2000,1000);
389393
cpkt.channelPitch = convert_channel_16b_limit(ELEVATOR,1000,2000);
390394
// Note: T & R Swapped:
391395
cpkt.channelYaw = convert_channel_16b_limit(RUDDER, 1000, 2000);
392396
cpkt.channelThrust = convert_channel_16b_limit(THROTTLE, 1000, 2000);
393397

394398
// Rescale the rest of the aux channels - RC channel 4 and up
395-
for (uint8_t i = 4; i < 14; i++)
399+
for (uint8_t i = 0; i < 10; i++)
396400
{
397-
cpkt.channelAux[i] = convert_channel_16b_limit(i, 1000, 2000);
401+
cpkt.channelAux[i] = convert_channel_16b_limit(i+4, 2000, 1000);
398402
}
399403

400404
// Total size of the commander packet is a 1-byte header, 4 2-byte channels and
@@ -409,25 +413,19 @@ static void send_crtp_rpyt_packet()
409413
memcpy(&packet[2], (char*)&cpkt, commanderPacketSize); // Why not use sizeof(cpkt) here??
410414
tx_payload_len = 2 + commanderPacketSize; // CRTP header, commander type, and packet
411415
send_packet();
412-
}*/
416+
}
413417

414418
static void send_cmd_packet()
415419
{
416-
// TODO: Fix this so we can actually configure the packet type
417-
// switch(Model.proto_opts[PROTOOPTS_CRTP_MODE])
418-
// {
419-
// case CRTP_MODE_CPPM:
420-
// send_crtp_cppm_emu_packet();
421-
// break;
422-
// case CRTP_MODE_RPYT:
423-
// send_crtp_rpyt_packet();
424-
// break;
425-
// default:
426-
// send_crtp_rpyt_packet();
427-
// }
428-
429-
// send_crtp_cppm_emu_packet(); // oh maAAAn
430-
send_crtp_rpyt_packet();
420+
#if defined(CFLIE_USE_CRTP_RPYT)
421+
{
422+
send_crtp_rpyt_packet();
423+
}
424+
#else
425+
{
426+
send_crtp_cppm_emu_packet();
427+
}
428+
#endif
431429
}
432430

433431
// State machine for setting up CRTP logging
@@ -794,52 +792,36 @@ static uint8_t CFLIE_initialize_rx_tx_addr()
794792
rx_tx_addr[3] =
795793
rx_tx_addr[4] = 0xE7; // CFlie uses fixed address
796794

797-
// if (Model.fixed_id) {
798-
// rf_ch_num = Model.fixed_id % 100;
799-
// switch (Model.fixed_id / 100) {
800-
// case 0:
801-
// data_rate = NRF24L01_BR_250K;
802-
// break;
803-
// case 1:
804-
// data_rate = NRF24L01_BR_1M;
805-
// break;
806-
// case 2:
807-
// data_rate = NRF24L01_BR_2M;
808-
// break;
809-
// default:
810-
// break;
811-
// }
812-
813-
// if (Model.proto_opts[PROTOOPTS_TELEMETRY] == TELEM_ON_CRTPLOG) {
814-
// return CFLIE_INIT_CRTP_LOG;
815-
// } else {
816-
// return CFLIE_INIT_DATA;
817-
// }
818-
// } else {
819-
// data_rate = NRF24L01_BR_250K;
820-
// rf_ch_num = 10;
821-
// return CFLIE_INIT_SEARCH;
822-
// }
823-
824-
// Default 1
825-
data_rate = NRF24L01_BR_1M;
826-
rf_ch_num = 10;
827-
828-
// Default 2
829-
// data_rate = NRF24L01_BR_2M;
830-
// rf_ch_num = 110;
795+
switch (sub_protocol) {
796+
case CFLIE_2Mbps:
797+
data_rate = NRF24L01_BR_2M;
798+
rf_ch_num = option;
799+
break;
800+
case CFLIE_1Mbps:
801+
data_rate = NRF24L01_BR_1M;
802+
rf_ch_num = option;
803+
break;
804+
case CFLIE_250kbps:
805+
data_rate = NRF24L01_BR_250K;
806+
rf_ch_num = option;
807+
break;
808+
default:
809+
data_rate = NRF24L01_BR_2M;
810+
rf_ch_num = 80;
811+
}
812+
831813
return CFLIE_INIT_SEARCH;
832814
}
833815

834816
void CFLIE_init(void)
835817
{
836818
BIND_IN_PROGRESS; // autobind protocol
837819

838-
phase = CFLIE_initialize_rx_tx_addr();
839-
crtp_log_setup_state = CFLIE_CRTP_LOG_SETUP_STATE_INIT;
840-
packet_count=0;
820+
phase = CFLIE_initialize_rx_tx_addr();
821+
crtp_log_setup_state = CFLIE_CRTP_LOG_SETUP_STATE_INIT;
822+
packet_count=0;
841823

842-
CFLIE_RF_init();
824+
CFLIE_RF_init();
843825
}
844826

845-
#endif
827+
#endif

Multiprotocol/Multi_Protos.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const char STR_SUBTYPE_MOULKG[] = "\x06""Analog""Digit\0";
166166
const char STR_SUBTYPE_KF606[] = "\x06""KF606\0""MIG320";
167167
const char STR_SUBTYPE_E129[] = "\x04""E129""C186";
168168
const char STR_SUBTYPE_FX[] = "\x03""816""620";
169+
const char STR_SUBTYPE_CFLIE[] = "\x07""Auto\0 ""2Mbps\0 ""1Mbps\0 ""250kbps";
169170
#define NO_SUBTYPE nullptr
170171

171172
#ifdef SEND_CPPM
@@ -219,7 +220,7 @@ const mm_protocol_definition multi_protocols[] = {
219220
{PROTO_CABELL, STR_CABELL, STR_SUBTYPE_CABELL, 8, OPTION_OPTION, 0, 0, SW_NRF, CABELL_init, CABELL_callback },
220221
#endif
221222
#if defined(CFLIE_NRF24L01_INO)
222-
{PROTO_CFLIE, STR_CFLIE, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_NRF, CFLIE_init, CFLIE_callback }, // review protocol
223+
{PROTO_CFLIE, STR_CFLIE, STR_SUBTYPE_CFLIE, 4, OPTION_RFCHAN, 0, 0, SW_NRF, CFLIE_init, CFLIE_callback }, // review protocol
223224
#endif
224225
#if defined(CG023_NRF24L01_INO)
225226
{PROTO_CG023, STR_CG023, STR_SUBTYPE_CG023, 2, OPTION_NONE, 0, 0, SW_NRF, CG023_init, CG023_callback },
@@ -545,4 +546,4 @@ uint16_t PROTOLIST_callback()
545546
}
546547
return 1000;
547548
}
548-
#endif
549+
#endif

Multiprotocol/Multiprotocol.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ enum FX
460460
FX816 = 0,
461461
FX620 = 1,
462462
};
463+
enum CFLIE
464+
{
465+
CFLIE_AUTO = 0,
466+
CFLIE_2Mbps = 1,
467+
CFLIE_1Mbps = 2,
468+
CFLIE_250kbps = 3,
469+
};
463470

464471
#define NONE 0
465472
#define P_HIGH 1

Multiprotocol/_Config.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@
220220
#define BAYANG_NRF24L01_INO
221221
#define BAYANG_RX_NRF24L01_INO
222222
#define BUGSMINI_NRF24L01_INO
223-
#define CABELL_NRF24L01_INO
224-
//#define CFLIE_NRF24L01_INO
225-
#define CG023_NRF24L01_INO
223+
//#define CABELL_NRF24L01_INO
224+
#define CFLIE_NRF24L01_INO
225+
//#define CG023_NRF24L01_INO
226226
#define CX10_NRF24L01_INO //Include Q2X2 protocol
227-
#define DM002_NRF24L01_INO
227+
//#define DM002_NRF24L01_INO
228228
#define E016H_NRF24L01_INO
229229
#define ESKY_NRF24L01_INO
230230
#define ESKY150_NRF24L01_INO
@@ -576,7 +576,10 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= {
576576
CABELL_SET_FAIL_SAFE
577577
CABELL_UNBIND
578578
PROTO_CFLIE
579-
NONE
579+
CFLIE_AUTO
580+
CFLIE_2Mbps
581+
CFLIE_1Mbps
582+
CFLIE_250kbps
580583
PROTO_CG023
581584
CG023
582585
YD829

0 commit comments

Comments
 (0)