From c9de0b4cf2ff69c88a5cccd53770b2492b95bb77 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Wed, 23 Nov 2016 21:56:00 +0100 Subject: [PATCH] Q2X2 protocol addition for Q222/Q242/Q282 Q2X2 protocol : 29 Sub-protocols: - Q222 : 0 - Q242 : 1 - Q282 : 2 --- Multiprotocol/CX10_nrf24l01.ino | 48 +++++++++++++++++---------------- Multiprotocol/Multiprotocol.h | 23 +++++++++++----- Multiprotocol/Multiprotocol.ino | 2 ++ Multiprotocol/SLT_nrf24l01.ino | 1 + Multiprotocol/_Config.h | 6 +++-- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/Multiprotocol/CX10_nrf24l01.ino b/Multiprotocol/CX10_nrf24l01.ino index f836e02..11bd62d 100644 --- a/Multiprotocol/CX10_nrf24l01.ino +++ b/Multiprotocol/CX10_nrf24l01.ino @@ -22,7 +22,7 @@ #define CX10_BIND_COUNT 4360 // 6 seconds #define CX10_PACKET_SIZE 15 #define CX10A_PACKET_SIZE 19 // CX10 blue board packets have 19-byte payload -#define Q282_PACKET_SIZE 21 +#define Q2X2_PACKET_SIZE 21 #define CX10_PACKET_PERIOD 1316 // Timeout for callback in uSec #define CX10A_PACKET_PERIOD 6000 @@ -91,6 +91,7 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind) break; case Q282: case Q242: + case Q222: memcpy(&packet[15], "\x10\x10\xaa\xaa\x00\x00", 6); //FLIP|LED|PICTURE|VIDEO|HEADLESS|RTH|XCAL|YCAL flags2 = GET_FLAG(Servo_AUX1, 0x80) // Channel 5 - FLIP @@ -111,7 +112,7 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind) flags2 |= video_state |GET_FLAG(Servo_AUX3,0x10); // Channel 7 - picture } - else + else if(sub_protocol==Q282) { flags=2; flags2|= GET_FLAG(Servo_AUX3,0x01) // Channel 7 - picture @@ -119,6 +120,12 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind) packet[17]=0x00; packet[18]=0x00; } + else + { // Q222 + flags=0; + packet[15]=0x0C; + packet[16]=0x07; + } if(Servo_AUX6) flags |=0x80; // Channel 10 - RTH break; case DM007: @@ -233,28 +240,23 @@ uint16_t CX10_callback() static void __attribute__((unused)) CX10_initialize_txid() { rx_tx_addr[1]%= 0x30; - if(sub_protocol==Q282) + if(sub_protocol&0x08) //Q2X2 protocols { - hopping_frequency[0] = 0x46; - hopping_frequency[1] = 0x48; - hopping_frequency[2] = 0x4a; - hopping_frequency[3] = 0x4c; + uint8_t offset=0; //Q282 + if(sub_protocol==Q242) + offset=2; + if(sub_protocol==Q222) + offset=3; + for(uint8_t i=0;i<4;i++) + hopping_frequency[i]=0x46+2*i+offset; } else - if(sub_protocol==Q242) - { - hopping_frequency[0] = 0x48; - hopping_frequency[1] = 0x4a; - hopping_frequency[2] = 0x4c; - hopping_frequency[3] = 0x4e; - } - else - { - hopping_frequency[0] = 0x03 + (rx_tx_addr[0] & 0x0F); - hopping_frequency[1] = 0x16 + (rx_tx_addr[0] >> 4); - hopping_frequency[2] = 0x2D + (rx_tx_addr[1] & 0x0F); - hopping_frequency[3] = 0x40 + (rx_tx_addr[1] >> 4); - } + { + hopping_frequency[0] = 0x03 + (rx_tx_addr[0] & 0x0F); + hopping_frequency[1] = 0x16 + (rx_tx_addr[0] >> 4); + hopping_frequency[2] = 0x2D + (rx_tx_addr[1] & 0x0F); + hopping_frequency[3] = 0x40 + (rx_tx_addr[1] >> 4); + } } uint16_t initCX10(void) @@ -272,8 +274,8 @@ uint16_t initCX10(void) } else { - if(sub_protocol==Q282||sub_protocol==Q242) - packet_length = Q282_PACKET_SIZE; + if(sub_protocol&0x08) //Q2X2 protocols + packet_length = Q2X2_PACKET_SIZE; else packet_length = CX10_PACKET_SIZE; packet_period = CX10_PACKET_PERIOD; diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index d64aab7..0b10aae 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -47,6 +47,7 @@ enum PROTOCOLS MODE_HONTAI = 26, // =>NRF24L01 MODE_OPENLRS = 27, // =>OpenLRS hardware MODE_AFHDS2A = 28, // =>A7105 + MODE_Q2X2 = 29, // =>NRF24L01, extension of CX-10 protocol }; enum Flysky @@ -101,14 +102,18 @@ enum SLT }; enum CX10 { - CX10_GREEN = 0, - CX10_BLUE = 1, // also compatible with CX10-A, CX12 - DM007 = 2, - Q282 = 3, + CX10_GREEN = 0, + CX10_BLUE = 1, // also compatible with CX10-A, CX12 + DM007 = 2, JC3015_1 = 4, JC3015_2 = 5, MK33041 = 6, - Q242 = 7 +}; +enum Q2X2 +{ + Q222 = 8, + Q242 = 9, + Q282 = 10, }; enum CG023 { @@ -398,6 +403,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- HONTAI 26 OpenLRS 27 AFHDS2A 28 + Q2X2 29 BindBit=> 0x80 1=Bind/0=No AutoBindBit=> 0x40 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No @@ -434,11 +440,14 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- CX10_GREEN 0 CX10_BLUE 1 // also compatible with CX10-A, CX12 DM007 2 - Q282 3 + --- 3 JC3015_1 4 JC3015_2 5 MK33041 6 - Q242 7 + sub_protocol==Q2X2 + Q222 0 + Q242 1 + Q282 2 sub_protocol==SLT SLT 0 VISTA 1 diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index cc217ae..af181bb 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -761,6 +761,8 @@ static void protocol_init() break; #endif #if defined(CX10_NRF24L01_INO) + case MODE_Q2X2: + sub_protocol|=0x08; // Increase the number of sub_protocols for CX-10 case MODE_CX10: next_callback=initCX10(); remote_callback = CX10_callback; diff --git a/Multiprotocol/SLT_nrf24l01.ino b/Multiprotocol/SLT_nrf24l01.ino index 34f70e0..fe8597a 100644 --- a/Multiprotocol/SLT_nrf24l01.ino +++ b/Multiprotocol/SLT_nrf24l01.ino @@ -222,6 +222,7 @@ uint16_t initSLT() if(sub_protocol == VISTA) memcpy(hopping_frequency+6,"\x13\x0F\x0B\x10\x08\x16\x1D\x24\x06",9); SLT_init(); + SLT_build_packet(); phase = SLT_BIND; return 50000; } diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index e3d538e..4a1d950 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -75,7 +75,7 @@ //The protocols below need a NRF24L01 to be installed #define BAYANG_NRF24L01_INO #define CG023_NRF24L01_INO -#define CX10_NRF24L01_INO +#define CX10_NRF24L01_INO // Include Q2X2 protocol #define ESKY_NRF24L01_INO #define HISKY_NRF24L01_INO #define KN_NRF24L01_INO @@ -212,11 +212,13 @@ const PPM_Parameters PPM_prot[15]= { CX10_GREEN CX10_BLUE DM007 - Q282 JC3015_1 JC3015_2 MK33041 + MODE_Q2X2 + Q222 Q242 + Q282 MODE_SLT SLT VISTA