@@ -19,14 +19,16 @@ Multiprotocol is distributed in the hope that it will be useful,
1919#include " iface_xn297.h"
2020
2121// #define FORCE_SGF22_ORIGINAL_ID
22+ #define FORCE_SGF22_CX10_ORIGINAL_ID
2223
2324#define SGF22_PACKET_PERIOD 11950 // 10240
24- #define SGF22_BIND_RF_CHANNEL 78
2525#define SGF22_PAYLOAD_SIZE 12
2626#define SGF22_BIND_COUNT 50
2727#define SGF22_RF_NUM_CHANNELS 4
28+ #define SGF22_BIND_RF_CHANNEL 78
2829#define SGF22_F22S_BIND_RF_CHANNEL 10
2930#define SGF22_J20_BIND_RF_CHANNEL 28
31+ #define SGF22_CX10_BIND_RF_CHANNEL 48
3032
3133// packet[8]
3234#define SGF22_FLAG_3D 0x00
@@ -79,26 +81,43 @@ static void __attribute__((unused)) SGF22_send_packet()
7981 packet_sent = 0 ;
8082 // packet
8183 packet[0 ] = 0x1B ;
82- packet[8 ] = SGF22_FLAG_3D // CH5 -100%, F22 & F22S - 3D mode, J20 - Gyro off
83- | GET_FLAG (CH6_SW, SGF22_FLAG_ROLL) // roll
84- | GET_FLAG (CH7_SW, SGF22_FLAG_LIGHT) // push up throttle trim for light in the stock TX
85- | GET_FLAG (CH9_SW, SGF22_FLAG_VIDEO) // push down throttle trim for video in the stock TX
86- | GET_FLAG (CH11_SW, SGF22_FX922_FLAG_BALANCE)
87- | GET_FLAG (CH12_SW, SGF22_FX922_FLAG_BALANCEHIGH);
88- if (Channel_data[CH5] > CHANNEL_MAX_COMMAND)
89- packet[8 ] |= SGF22_FLAG_VERTICAL; // CH5 100%, vertical mode (torque)
90- else if (Channel_data[CH5] > CHANNEL_MIN_COMMAND )
84+ if (sub_protocol != SGF22_CX10)
85+ {// SGF22_F22,SGF22_F22S,SGF22_J20
86+ packet[8 ] = SGF22_FLAG_3D // CH5 -100%, F22 & F22S - 3D mode, J20 - Gyro off
87+ | GET_FLAG (CH6_SW, SGF22_FLAG_ROLL) // roll
88+ | GET_FLAG (CH7_SW, SGF22_FLAG_LIGHT) // push up throttle trim for light in the stock TX
89+ | GET_FLAG (CH9_SW, SGF22_FLAG_VIDEO) // push down throttle trim for video in the stock TX
90+ | GET_FLAG (CH11_SW, SGF22_FX922_FLAG_BALANCE)
91+ | GET_FLAG (CH12_SW, SGF22_FX922_FLAG_BALANCEHIGH);
92+ if (Channel_data[CH5] > CHANNEL_MAX_COMMAND)
93+ packet[8 ] |= SGF22_FLAG_VERTICAL; // CH5 100%, vertical mode (torque)
94+ else if (Channel_data[CH5] > CHANNEL_MIN_COMMAND )
9195 packet[8 ] |= ( sub_protocol == SGF22_J20 ? SGF22_J20_FLAG_HORIZONTAL : SGF22_FLAG_6G ); // CH5 0%, F22 & F22S - 6G mode, J20 - Horizontal mode
92- packet[9 ] = GET_FLAG (CH8_SW, SGF22_FLAG_PHOTO) // F22: photo, press in throttle trim in the stock TX, J20: invert flight
96+ }
97+ else // SGF22_CX10 114548
98+ {
99+ if (CH6_SW)
100+ flags = 0x06 ; // high rate
101+ else
102+ if (Channel_data[CH6] < CHANNEL_MIN_COMMAND)
103+ flags = 0x04 ; // low rate
104+ else
105+ flags = 0x05 ; // mid rate
106+ packet[8 ] = flags
107+ | GET_FLAG (CH5_SW, 0x08 ); // flip
108+ }
109+ packet[9 ] = GET_FLAG (CH8_SW, SGF22_FLAG_PHOTO) // F22: photo, press in throttle trim in the stock TX, J20: invert flight
93110 | GET_FLAG (CH10_SW, ( sub_protocol == SGF22_J20 ? SGF22_J20_FLAG_FIXHEIGHT : SGF22_FLAG_TRIMRESET )) ; // F22: Both sticks down inwards in the stock TX, J20: Altitude hold
94- packet[10 ] = 0x42 ; // no fine tune
95- packet[11 ] = 0x10 ; // no fine tune
111+ packet[10 ] = 0x42 ; // no fine tune
112+ packet[11 ] = 0x10 ; // no fine tune
96113 }
97114 if (sub_protocol == SGF22_F22S)
98115 packet[0 ] += 6 ;
99116 else if (sub_protocol == SGF22_J20)
100117 packet[0 ] += 3 ;
101- packet[1 ] = packet_count; // sequence
118+ else if (sub_protocol == SGF22_CX10)
119+ packet[0 ] += 0x6A ;
120+ packet[1 ] = packet_count; // sequence
102121 packet[2 ] = rx_tx_addr[2 ];
103122 packet[3 ] = rx_tx_addr[3 ];
104123 packet[4 ] = convert_channel_8b (THROTTLE);
@@ -108,7 +127,10 @@ static void __attribute__((unused)) SGF22_send_packet()
108127
109128 XN297_SetPower ();
110129 XN297_SetTxRxMode (TX_EN);
111- XN297_WriteEnhancedPayload (packet, SGF22_PAYLOAD_SIZE,0 );
130+ if (sub_protocol != SGF22_CX10)
131+ XN297_WriteEnhancedPayload (packet, SGF22_PAYLOAD_SIZE,0 );
132+ else
133+ XN297_WritePayload (packet, SGF22_PAYLOAD_SIZE);
112134 #if 0
113135 debug_time("");
114136 for(uint8_t i=0; i<SGF22_PAYLOAD_SIZE; i++)
@@ -132,7 +154,7 @@ static void __attribute__((unused)) SGF22_initialize_txid()
132154 { 0x18 , 0x37 , 0x27 , 0x47 } };
133155 memcpy (hopping_frequency, &hop[val], SGF22_RF_NUM_CHANNELS);
134156
135- /* //Same code sze ...
157+ /* //Same code size ...
136158 hopping_frequency[0] = 0x0C + 3 * val;
137159 hopping_frequency[1] = hopping_frequency[0] + 0x1E;
138160 if(val > 1) hopping_frequency[1]++;
@@ -145,6 +167,20 @@ static void __attribute__((unused)) SGF22_initialize_txid()
145167 rx_tx_addr[3 ] = 0x61 ; // TX2:51 TX3:0C
146168 memcpy (hopping_frequency," \x15\x34\x24\x44 " , SGF22_RF_NUM_CHANNELS); // Original dump=>21=0x15,52=0x34,36=0x24,68=0x44
147169 #endif
170+ #ifdef FORCE_SGF22_CX10_ORIGINAL_ID
171+ if (rx_tx_addr[3 ] & 1 )
172+ {
173+ rx_tx_addr[2 ] = 0x4C ;
174+ rx_tx_addr[3 ] = 0xD7 ;
175+ memcpy (hopping_frequency, " \x37\x42\x47\x3c " , SGF22_RF_NUM_CHANNELS);
176+ }
177+ else
178+ {
179+ rx_tx_addr[2 ] = 0x50 ;
180+ rx_tx_addr[3 ] = 0xE1 ;
181+ memcpy (hopping_frequency, " \x3b\x4b\x46\x41 " , SGF22_RF_NUM_CHANNELS);
182+ }
183+ #endif
148184 #if 0
149185 debug("ID: %02X %02X, C: ",rx_tx_addr[2],rx_tx_addr[3]);
150186 for(uint8_t i=0; i<SGF22_RF_NUM_CHANNELS; i++)
@@ -161,7 +197,7 @@ static void __attribute__((unused)) SGF22_RF_init()
161197 XN297_SetRXAddr ((uint8_t *)" \xC7\x95\x3C\xBB\xA5 " , SGF22_PAYLOAD_SIZE);
162198 #endif
163199
164- const uint8_t bind_chan[] = {SGF22_BIND_RF_CHANNEL, SGF22_F22S_BIND_RF_CHANNEL, SGF22_J20_BIND_RF_CHANNEL};
200+ const uint8_t bind_chan[] = {SGF22_BIND_RF_CHANNEL, SGF22_F22S_BIND_RF_CHANNEL, SGF22_J20_BIND_RF_CHANNEL, SGF22_CX10_BIND_RF_CHANNEL};
165201 XN297_RFChannel (bind_chan[sub_protocol]); // Set bind channel
166202}
167203
0 commit comments