From bb6d5c2d8d5ed3007f89398aefc5a0e8ea293e3c Mon Sep 17 00:00:00 2001 From: Matej Karasek Date: Tue, 16 Aug 2022 18:43:00 +0200 Subject: [PATCH 1/4] Updating CFLIE protocol - CPPM EMU as default istead of CRTP RPYT, allowing fixed RF channel and bitrate --- Multiprotocol/CFlie_nrf24l01.ino | 140 ++++++++++++++----------------- Multiprotocol/Multi_Protos.ino | 5 +- Multiprotocol/Multiprotocol.h | 7 ++ Multiprotocol/_Config.h | 13 +-- 4 files changed, 79 insertions(+), 86 deletions(-) diff --git a/Multiprotocol/CFlie_nrf24l01.ino b/Multiprotocol/CFlie_nrf24l01.ino index 6d36d24..40f7ab1 100644 --- a/Multiprotocol/CFlie_nrf24l01.ino +++ b/Multiprotocol/CFlie_nrf24l01.ino @@ -20,6 +20,7 @@ #include "iface_nrf24l01.h" #define CFLIE_BIND_COUNT 60 +//#define CFLIE_USE_CRTP_RPYT //============================================================================= // CRTP (Crazy RealTime Protocol) Implementation @@ -220,8 +221,8 @@ static uint8_t packet_ack() static void set_rate_channel(uint8_t rate, uint8_t channel) { - NRF24L01_WriteReg(NRF24L01_05_RF_CH, channel); // Defined by model id - NRF24L01_SetBitrate(rate); // Defined by model id + NRF24L01_WriteReg(NRF24L01_05_RF_CH, channel); + NRF24L01_SetBitrate(rate); } static void send_search_packet() @@ -232,23 +233,26 @@ static void send_search_packet() NRF24L01_WriteReg(NRF24L01_07_STATUS, (BV(NRF24L01_07_TX_DS) | BV(NRF24L01_07_MAX_RT))); NRF24L01_FlushTx(); - if (rf_ch_num++ > 125) - { - rf_ch_num = 0; - switch(data_rate) - { - case NRF24L01_BR_250K: - data_rate = NRF24L01_BR_1M; - break; - case NRF24L01_BR_1M: - data_rate = NRF24L01_BR_2M; - break; - case NRF24L01_BR_2M: - data_rate = NRF24L01_BR_250K; - break; - } - } - set_rate_channel(data_rate, rf_ch_num); + if (sub_protocol == CFLIE_AUTO) + { + if (rf_ch_num++ > 125) + { + rf_ch_num = 0; + switch(data_rate) + { + case NRF24L01_BR_250K: + data_rate = NRF24L01_BR_1M; + break; + case NRF24L01_BR_1M: + data_rate = NRF24L01_BR_2M; + break; + case NRF24L01_BR_2M: + data_rate = NRF24L01_BR_250K; + break; + } + } + } + set_rate_channel(data_rate, rf_ch_num); NRF24L01_WritePayload(buf, sizeof(buf)); @@ -355,7 +359,7 @@ static void send_crtp_rpyt_packet() send_packet(); } -/*static void send_crtp_cppm_emu_packet() +static void send_crtp_cppm_emu_packet() { struct CommanderPacketCppmEmu { struct { @@ -376,7 +380,7 @@ static void send_crtp_rpyt_packet() // Make sure the number of aux channels in use is capped to MAX_CPPM_AUX_CHANNELS // uint8_t numAuxChannels = Model.num_channels - 4; - uint8_t numAuxChannels = 2; // TODO: Figure this out correctly + uint8_t numAuxChannels = 4; if(numAuxChannels > MAX_CPPM_AUX_CHANNELS) { numAuxChannels = MAX_CPPM_AUX_CHANNELS; @@ -385,16 +389,16 @@ static void send_crtp_rpyt_packet() cpkt.hdr.numAuxChannels = numAuxChannels; // Remap AETR to AERT (RPYT) - cpkt.channelRoll = convert_channel_16b_limit(AILERON,1000,2000); + cpkt.channelRoll = convert_channel_16b_limit(AILERON,2000,1000); cpkt.channelPitch = convert_channel_16b_limit(ELEVATOR,1000,2000); // Note: T & R Swapped: cpkt.channelYaw = convert_channel_16b_limit(RUDDER, 1000, 2000); cpkt.channelThrust = convert_channel_16b_limit(THROTTLE, 1000, 2000); // Rescale the rest of the aux channels - RC channel 4 and up - for (uint8_t i = 4; i < 14; i++) + for (uint8_t i = 0; i < 10; i++) { - cpkt.channelAux[i] = convert_channel_16b_limit(i, 1000, 2000); + cpkt.channelAux[i] = convert_channel_16b_limit(i+4, 2000, 1000); } // 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() memcpy(&packet[2], (char*)&cpkt, commanderPacketSize); // Why not use sizeof(cpkt) here?? tx_payload_len = 2 + commanderPacketSize; // CRTP header, commander type, and packet send_packet(); -}*/ +} static void send_cmd_packet() { - // TODO: Fix this so we can actually configure the packet type - // switch(Model.proto_opts[PROTOOPTS_CRTP_MODE]) - // { - // case CRTP_MODE_CPPM: - // send_crtp_cppm_emu_packet(); - // break; - // case CRTP_MODE_RPYT: - // send_crtp_rpyt_packet(); - // break; - // default: - // send_crtp_rpyt_packet(); - // } - - // send_crtp_cppm_emu_packet(); // oh maAAAn - send_crtp_rpyt_packet(); + #if defined(CFLIE_USE_CRTP_RPYT) + { + send_crtp_rpyt_packet(); + } + #else + { + send_crtp_cppm_emu_packet(); + } + #endif } // State machine for setting up CRTP logging @@ -794,40 +792,24 @@ static uint8_t CFLIE_initialize_rx_tx_addr() rx_tx_addr[3] = rx_tx_addr[4] = 0xE7; // CFlie uses fixed address - // if (Model.fixed_id) { - // rf_ch_num = Model.fixed_id % 100; - // switch (Model.fixed_id / 100) { - // case 0: - // data_rate = NRF24L01_BR_250K; - // break; - // case 1: - // data_rate = NRF24L01_BR_1M; - // break; - // case 2: - // data_rate = NRF24L01_BR_2M; - // break; - // default: - // break; - // } - - // if (Model.proto_opts[PROTOOPTS_TELEMETRY] == TELEM_ON_CRTPLOG) { - // return CFLIE_INIT_CRTP_LOG; - // } else { - // return CFLIE_INIT_DATA; - // } - // } else { - // data_rate = NRF24L01_BR_250K; - // rf_ch_num = 10; - // return CFLIE_INIT_SEARCH; - // } - - // Default 1 - data_rate = NRF24L01_BR_1M; - rf_ch_num = 10; - - // Default 2 - // data_rate = NRF24L01_BR_2M; - // rf_ch_num = 110; + switch (sub_protocol) { + case CFLIE_2Mbps: + data_rate = NRF24L01_BR_2M; + rf_ch_num = option; + break; + case CFLIE_1Mbps: + data_rate = NRF24L01_BR_1M; + rf_ch_num = option; + break; + case CFLIE_250kbps: + data_rate = NRF24L01_BR_250K; + rf_ch_num = option; + break; + default: + data_rate = NRF24L01_BR_2M; + rf_ch_num = 80; + } + return CFLIE_INIT_SEARCH; } @@ -835,11 +817,11 @@ void CFLIE_init(void) { BIND_IN_PROGRESS; // autobind protocol - phase = CFLIE_initialize_rx_tx_addr(); - crtp_log_setup_state = CFLIE_CRTP_LOG_SETUP_STATE_INIT; - packet_count=0; + phase = CFLIE_initialize_rx_tx_addr(); + crtp_log_setup_state = CFLIE_CRTP_LOG_SETUP_STATE_INIT; + packet_count=0; - CFLIE_RF_init(); + CFLIE_RF_init(); } -#endif \ No newline at end of file +#endif diff --git a/Multiprotocol/Multi_Protos.ino b/Multiprotocol/Multi_Protos.ino index 001d73d..a3a48eb 100644 --- a/Multiprotocol/Multi_Protos.ino +++ b/Multiprotocol/Multi_Protos.ino @@ -166,6 +166,7 @@ const char STR_SUBTYPE_MOULKG[] = "\x06""Analog""Digit\0"; const char STR_SUBTYPE_KF606[] = "\x06""KF606\0""MIG320"; const char STR_SUBTYPE_E129[] = "\x04""E129""C186"; const char STR_SUBTYPE_FX[] = "\x03""816""620"; +const char STR_SUBTYPE_CFLIE[] = "\x07""Auto\0 ""2Mbps\0 ""1Mbps\0 ""250kbps"; #define NO_SUBTYPE nullptr #ifdef SEND_CPPM @@ -219,7 +220,7 @@ const mm_protocol_definition multi_protocols[] = { {PROTO_CABELL, STR_CABELL, STR_SUBTYPE_CABELL, 8, OPTION_OPTION, 0, 0, SW_NRF, CABELL_init, CABELL_callback }, #endif #if defined(CFLIE_NRF24L01_INO) - {PROTO_CFLIE, STR_CFLIE, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_NRF, CFLIE_init, CFLIE_callback }, // review protocol + {PROTO_CFLIE, STR_CFLIE, STR_SUBTYPE_CFLIE, 4, OPTION_RFCHAN, 0, 0, SW_NRF, CFLIE_init, CFLIE_callback }, // review protocol #endif #if defined(CG023_NRF24L01_INO) {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() } return 1000; } -#endif \ No newline at end of file +#endif diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index bf428e5..47d371c 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -460,6 +460,13 @@ enum FX FX816 = 0, FX620 = 1, }; +enum CFLIE +{ + CFLIE_AUTO = 0, + CFLIE_2Mbps = 1, + CFLIE_1Mbps = 2, + CFLIE_250kbps = 3, +}; #define NONE 0 #define P_HIGH 1 diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index c64a023..11fc702 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -220,11 +220,11 @@ #define BAYANG_NRF24L01_INO #define BAYANG_RX_NRF24L01_INO #define BUGSMINI_NRF24L01_INO -#define CABELL_NRF24L01_INO -//#define CFLIE_NRF24L01_INO -#define CG023_NRF24L01_INO +//#define CABELL_NRF24L01_INO +#define CFLIE_NRF24L01_INO +//#define CG023_NRF24L01_INO #define CX10_NRF24L01_INO //Include Q2X2 protocol -#define DM002_NRF24L01_INO +//#define DM002_NRF24L01_INO #define E016H_NRF24L01_INO #define ESKY_NRF24L01_INO #define ESKY150_NRF24L01_INO @@ -576,7 +576,10 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= { CABELL_SET_FAIL_SAFE CABELL_UNBIND PROTO_CFLIE - NONE + CFLIE_AUTO + CFLIE_2Mbps + CFLIE_1Mbps + CFLIE_250kbps PROTO_CG023 CG023 YD829 From 0e08b45a147c3cba9bed557d83a7b85391a82bf7 Mon Sep 17 00:00:00 2001 From: matejkarasek Date: Fri, 19 Aug 2022 10:10:53 +0200 Subject: [PATCH 2/4] Reenabling protocols removed earlier --- Multiprotocol/_Config.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 11fc702..dd4214e 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -220,11 +220,11 @@ #define BAYANG_NRF24L01_INO #define BAYANG_RX_NRF24L01_INO #define BUGSMINI_NRF24L01_INO -//#define CABELL_NRF24L01_INO +#define CABELL_NRF24L01_INO #define CFLIE_NRF24L01_INO -//#define CG023_NRF24L01_INO +#define CG023_NRF24L01_INO #define CX10_NRF24L01_INO //Include Q2X2 protocol -//#define DM002_NRF24L01_INO +#define DM002_NRF24L01_INO #define E016H_NRF24L01_INO #define ESKY_NRF24L01_INO #define ESKY150_NRF24L01_INO From 7e671b98dcdde244f81ddc9d795985caaa6a22e5 Mon Sep 17 00:00:00 2001 From: Matej Karasek Date: Wed, 4 Oct 2023 13:11:12 +0200 Subject: [PATCH 3/4] Enable custom address and radio channel --- Multiprotocol/CFlie_nrf24l01.ino | 56 ++++++++++++++++++-------------- Multiprotocol/Multi_Protos.ino | 2 +- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/_Config.h | 12 +++---- 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/Multiprotocol/CFlie_nrf24l01.ino b/Multiprotocol/CFlie_nrf24l01.ino index 40f7ab1..c13b0d6 100644 --- a/Multiprotocol/CFlie_nrf24l01.ino +++ b/Multiprotocol/CFlie_nrf24l01.ino @@ -233,25 +233,25 @@ static void send_search_packet() NRF24L01_WriteReg(NRF24L01_07_STATUS, (BV(NRF24L01_07_TX_DS) | BV(NRF24L01_07_MAX_RT))); NRF24L01_FlushTx(); - if (sub_protocol == CFLIE_AUTO) - { - if (rf_ch_num++ > 125) - { - rf_ch_num = 0; - switch(data_rate) - { - case NRF24L01_BR_250K: - data_rate = NRF24L01_BR_1M; - break; - case NRF24L01_BR_1M: - data_rate = NRF24L01_BR_2M; - break; - case NRF24L01_BR_2M: - data_rate = NRF24L01_BR_250K; - break; - } - } - } + // if (sub_protocol == CFLIE_AUTO) + // { + // if (rf_ch_num++ > 125) + // { + // rf_ch_num = 0; + // switch(data_rate) + // { + // case NRF24L01_BR_250K: + // data_rate = NRF24L01_BR_1M; + // break; + // case NRF24L01_BR_1M: + // data_rate = NRF24L01_BR_2M; + // break; + // case NRF24L01_BR_2M: + // data_rate = NRF24L01_BR_250K; + // break; + // } + // } + // } set_rate_channel(data_rate, rf_ch_num); NRF24L01_WritePayload(buf, sizeof(buf)); @@ -789,25 +789,31 @@ static uint8_t CFLIE_initialize_rx_tx_addr() rx_tx_addr[0] = rx_tx_addr[1] = rx_tx_addr[2] = - rx_tx_addr[3] = - rx_tx_addr[4] = 0xE7; // CFlie uses fixed address - + rx_tx_addr[3] = 0xE7; + + unsigned x10 = (RX_num / 10U) % 10; + unsigned x1 = RX_num - x10*10; + switch (sub_protocol) { case CFLIE_2Mbps: data_rate = NRF24L01_BR_2M; - rf_ch_num = option; + rf_ch_num = option; // "RF channel" in the transmitter <0, 125> + rx_tx_addr[4] = x10*16 + x1; // "Receiver" in the transmitter <0, 63> break; case CFLIE_1Mbps: data_rate = NRF24L01_BR_1M; - rf_ch_num = option; + rf_ch_num = option; // "RF channel" in the transmitter <0, 125> + rx_tx_addr[4] = x10*16 + x1; // "Receiver" in the transmitter <0, 63> break; case CFLIE_250kbps: data_rate = NRF24L01_BR_250K; - rf_ch_num = option; + rf_ch_num = option; // "RF channel" in the transmitter <0, 125> + rx_tx_addr[4] = x10*16 + x1; // "Receiver" in the transmitter <0, 63> break; default: data_rate = NRF24L01_BR_2M; rf_ch_num = 80; + rx_tx_addr[4] = 0xE7; // CFlie uses fixed address } return CFLIE_INIT_SEARCH; diff --git a/Multiprotocol/Multi_Protos.ino b/Multiprotocol/Multi_Protos.ino index fc23ae9..3ab3cc5 100644 --- a/Multiprotocol/Multi_Protos.ino +++ b/Multiprotocol/Multi_Protos.ino @@ -174,7 +174,7 @@ const char STR_SUBTYPE_MOULKG[] = "\x06""Analog""Digit\0"; const char STR_SUBTYPE_KF606[] = "\x06""KF606\0""MIG320""ZCZ50\0"; const char STR_SUBTYPE_E129[] = "\x04""E129""C186"; const char STR_SUBTYPE_FX[] = "\x04""816\0""620\0""9630"; -const char STR_SUBTYPE_CFLIE[] = "\x07""Auto\0 ""2Mbps\0 ""1Mbps\0 ""250kbps"; +const char STR_SUBTYPE_CFLIE[] = "\x07""Default\0 ""2Mbps\0 ""1Mbps\0 ""250kbps"; #define NO_SUBTYPE nullptr #ifdef SEND_CPPM diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 920d792..b20dada 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -465,7 +465,7 @@ enum FX }; enum CFLIE { - CFLIE_AUTO = 0, + CFLIE_DEFAULT = 0, CFLIE_2Mbps = 1, CFLIE_1Mbps = 2, CFLIE_250kbps = 3, diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 98181c0..296ed34 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -230,9 +230,9 @@ #define ESKY150_NRF24L01_INO #define FQ777_NRF24L01_INO #define FX_NRF24L01_INO -#define FY326_NRF24L01_INO -#define GW008_NRF24L01_INO -#define HISKY_NRF24L01_INO +//#define FY326_NRF24L01_INO +//#define GW008_NRF24L01_INO +//#define HISKY_NRF24L01_INO #define HONTAI_NRF24L01_INO #define H8_3D_NRF24L01_INO #define JJRC345_NRF24L01_INO @@ -576,10 +576,10 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= { CABELL_SET_FAIL_SAFE CABELL_UNBIND PROTO_CFLIE - CFLIE_AUTO - CFLIE_2Mbps + CFLIE_DEFAULT + CFLIE_2Mbps CFLIE_1Mbps - CFLIE_250kbps + CFLIE_250kbps PROTO_CG023 CG023 YD829 From ec79d1f1eee9c340821dcfcdbd8fb1e1ee10696d Mon Sep 17 00:00:00 2001 From: Matej Karasek Date: Fri, 2 Feb 2024 08:24:51 +0100 Subject: [PATCH 4/4] fixed subtype labels --- Multiprotocol/Multi_Protos.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Multiprotocol/Multi_Protos.ino b/Multiprotocol/Multi_Protos.ino index 3ab3cc5..4351d66 100644 --- a/Multiprotocol/Multi_Protos.ino +++ b/Multiprotocol/Multi_Protos.ino @@ -174,7 +174,7 @@ const char STR_SUBTYPE_MOULKG[] = "\x06""Analog""Digit\0"; const char STR_SUBTYPE_KF606[] = "\x06""KF606\0""MIG320""ZCZ50\0"; const char STR_SUBTYPE_E129[] = "\x04""E129""C186"; const char STR_SUBTYPE_FX[] = "\x04""816\0""620\0""9630"; -const char STR_SUBTYPE_CFLIE[] = "\x07""Default\0 ""2Mbps\0 ""1Mbps\0 ""250kbps"; +const char STR_SUBTYPE_CFLIE[] = "\x07""Default""2Mbps\0 ""1Mbps\0 ""250kbps"; #define NO_SUBTYPE nullptr #ifdef SEND_CPPM