@@ -74,12 +74,12 @@ static void __attribute__((unused)) SLT_set_freq(void)
7474 }
7575
7676 // Unique freq
77- uint8_t max_freq= 0x50 ; // V1 and V2
78- if (sub_protocol== Q200)
77+ uint8_t max_freq = 0x50 ; // V1 and V2
78+ if (sub_protocol == Q200)
7979 max_freq=45 ;
8080 for (uint8_t i = 0 ; i < SLT_NFREQCHANNELS; ++i)
8181 {
82- if (sub_protocol== Q200 && hopping_frequency[i] >= max_freq)
82+ if (sub_protocol == Q200 && hopping_frequency[i] >= max_freq)
8383 hopping_frequency[i] = hopping_frequency[i] - max_freq + 0x03 ;
8484 uint8_t done = 0 ;
8585 while (!done)
@@ -103,7 +103,7 @@ static void __attribute__((unused)) SLT_set_freq(void)
103103 #endif
104104
105105 // Bind channel
106- hopping_frequency[SLT_NFREQCHANNELS]= SLT_BIND_CHANNEL;
106+ hopping_frequency[SLT_NFREQCHANNELS] = SLT_BIND_CHANNEL;
107107
108108 // Calib all channels
109109 NRF250K_HoppingCalib (SLT_NFREQCHANNELS+1 );
@@ -154,35 +154,38 @@ static void __attribute__((unused)) SLT_build_packet()
154154
155155 // ->V1 stops here
156156
157- if (sub_protocol== Q200)
157+ if (sub_protocol == Q200)
158158 packet[6 ] = GET_FLAG (CH9_SW , FLAG_Q200_FMODE)
159159 |GET_FLAG (CH10_SW, FLAG_Q200_FLIP)
160160 |GET_FLAG (CH11_SW, FLAG_Q200_VIDON)
161161 |GET_FLAG (CH12_SW, FLAG_Q200_VIDOFF);
162- else if (sub_protocol== MR100 || sub_protocol== Q100)
162+ else if (sub_protocol == MR100 || sub_protocol == Q100)
163163 packet[6 ] = GET_FLAG (CH9_SW , FLAG_MR100_FMODE)
164164 |GET_FLAG (CH10_SW, FLAG_MR100_FLIP)
165165 |GET_FLAG (CH11_SW, FLAG_MR100_VIDEO) // Does not exist on the Q100 but...
166166 |GET_FLAG (CH12_SW, FLAG_MR100_PICTURE); // Does not exist on the Q100 but...
167- packet[7 ]=convert_channel_8b (CH7);
168- packet[8 ]=convert_channel_8b (CH8);
169- if (sub_protocol==RF_SIM) {
170- packet[9 ]=convert_channel_8b (CH9);
171- packet[10 ]=convert_channel_8b (CH10);
172- } else {
173- packet[9 ]=0xAA ; // normal mode for Q100/Q200, unknown for V2/MR100
174- packet[10 ]=0x00 ; // normal mode for Q100/Q200, unknown for V2/MR100
175- }
176- if ((sub_protocol==Q100 || sub_protocol==Q200) && CH13_SW)
167+ packet[7 ] = convert_channel_8b (CH7);
168+ packet[8 ] = convert_channel_8b (CH8);
169+ if (sub_protocol == RF_SIM)
170+ {
171+ packet[9 ] = convert_channel_8b (CH9);
172+ packet[10 ] = convert_channel_8b (CH10);
173+ }
174+ else
175+ {
176+ packet[9 ] = 0xAA ; // normal mode for Q100/Q200, unknown for V2/MR100
177+ packet[10 ] = 0x00 ; // normal mode for Q100/Q200, unknown for V2/MR100
178+ }
179+ if ((sub_protocol == Q100 || sub_protocol == Q200) && CH13_SW)
177180 {// Calibrate
178- packet[9 ]= 0x77 ; // enter calibration
179- if (calib_counter>= 20 && calib_counter<= 25 ) // 7 packets for Q100 / 3 packets for Q200
180- packet[10 ]= 0x20 ; // launch calibration
181+ packet[9 ] = 0x77 ; // enter calibration
182+ if (calib_counter >= 20 && calib_counter <= 25 ) // 7 packets for Q100 / 3 packets for Q200
183+ packet[10 ] = 0x20 ; // launch calibration
181184 calib_counter++;
182- if (calib_counter> 250 ) calib_counter= 250 ;
185+ if (calib_counter > 250 ) calib_counter = 250 ;
183186 }
184187 else
185- calib_counter= 0 ;
188+ calib_counter = 0 ;
186189}
187190
188191static void __attribute__ ((unused)) SLT_send_bind_packet()
@@ -193,8 +196,8 @@ static void __attribute__((unused)) SLT_send_bind_packet()
193196 NRF250K_SetPower ();
194197 BIND_DONE;
195198 NRF250K_SetTXAddr ((uint8_t *)" \x7E\xB8\x63\xA9 " , SLT_TXID_SIZE);
196- memcpy ((void *)packet,(void *)rx_tx_addr,SLT_TXID_SIZE);
197- if (phase== SLT_BIND2)
199+ memcpy ((void *)packet, (void *)rx_tx_addr, SLT_TXID_SIZE);
200+ if (phase == SLT_BIND2)
198201 SLT_send_packet (SLT_TXID_SIZE);
199202 else // SLT_BIND1
200203 SLT_send_packet (SLT_PAYLOADSIZE_V2);
@@ -225,9 +228,9 @@ uint16_t SLT_callback()
225228 case SLT_DATA2:
226229 phase++;
227230 SLT_send_packet (packet_length);
228- if (sub_protocol== SLT_V1)
231+ if (sub_protocol == SLT_V1)
229232 return SLT_V1_TIMING_PACKET;
230- if (sub_protocol== SLT_V1_4)
233+ if (sub_protocol == SLT_V1_4)
231234 {
232235 phase++; // Packets are sent two times only
233236 return SLT_V1_4_TIMING_PACKET;
@@ -239,24 +242,24 @@ uint16_t SLT_callback()
239242 if (++packet_count >= 100 )
240243 {// Send bind packet
241244 packet_count = 0 ;
242- if (sub_protocol== SLT_V1|| sub_protocol== SLT_V1_4)
245+ if (sub_protocol == SLT_V1 || sub_protocol == SLT_V1_4)
243246 {
244- phase= SLT_BIND2;
247+ phase = SLT_BIND2;
245248 return SLT_V1_TIMING_BIND2;
246249 }
247250 // V2
248- phase= SLT_BIND1;
251+ phase = SLT_BIND1;
249252 return SLT_V2_TIMING_BIND1;
250253 }
251254 else
252255 {// Continue to send normal packets
253256 phase = SLT_BUILD;
254- if (sub_protocol== SLT_V1)
255- return 20000 - SLT_TIMING_BUILD;
257+ if (sub_protocol == SLT_V1)
258+ return 20000 - SLT_TIMING_BUILD;
256259 if (sub_protocol==SLT_V1_4)
257- return 18000 - SLT_TIMING_BUILD- SLT_V1_4_TIMING_PACKET;
260+ return 18000 - SLT_TIMING_BUILD - SLT_V1_4_TIMING_PACKET;
258261 // V2
259- return 13730 - SLT_TIMING_BUILD;
262+ return 13730 - SLT_TIMING_BUILD;
260263 }
261264 case SLT_BIND1:
262265 SLT_send_bind_packet ();
@@ -265,12 +268,12 @@ uint16_t SLT_callback()
265268 case SLT_BIND2:
266269 SLT_send_bind_packet ();
267270 phase = SLT_BUILD;
268- if (sub_protocol== SLT_V1)
269- return 20000 - SLT_TIMING_BUILD- SLT_V1_TIMING_BIND2;
270- if (sub_protocol== SLT_V1_4)
271- return 18000 - SLT_TIMING_BUILD- SLT_V1_TIMING_BIND2- SLT_V1_4_TIMING_PACKET;
271+ if (sub_protocol == SLT_V1)
272+ return 20000 - SLT_TIMING_BUILD - SLT_V1_TIMING_BIND2;
273+ if (sub_protocol == SLT_V1_4)
274+ return 18000 - SLT_TIMING_BUILD - SLT_V1_TIMING_BIND2 - SLT_V1_4_TIMING_PACKET;
272275 // V2
273- return 13730 - SLT_TIMING_BUILD- SLT_V2_TIMING_BIND1- SLT_V2_TIMING_BIND2;
276+ return 13730 - SLT_TIMING_BUILD - SLT_V2_TIMING_BIND1 - SLT_V2_TIMING_BIND2;
274277 }
275278 return 19000 ;
276279}
@@ -281,39 +284,26 @@ void SLT_init()
281284 packet_count = 0 ;
282285 packet_sent = 0 ;
283286 hopping_frequency_no = 0 ;
284- if (sub_protocol==Q200)
285- { // Q200: Force high part of the ID otherwise it won't bind
286- rx_tx_addr[0 ]=0x01 ;
287- rx_tx_addr[1 ]=0x02 ;
288- #ifdef SLT_Q200_FORCE_ID // ID taken from TX dumps
289- rx_tx_addr[0 ]=0x01 ;rx_tx_addr[1 ]=0x02 ;rx_tx_addr[2 ]=0x6A ;rx_tx_addr[3 ]=0x31 ;
290- /* rx_tx_addr[0]=0x01;rx_tx_addr[1]=0x02;rx_tx_addr[2]=0x0B;rx_tx_addr[3]=0x57;*/
291- #endif
292- }
293- if (sub_protocol==SLT_V1_4)
294- {
295- rx_tx_addr[0 ]=0xF4 ;
296- rx_tx_addr[1 ]=0x71 ;
297- #ifdef SLT_V1_4_FORCE_ID
298- memcpy (rx_tx_addr," \xF4\x71\x8D\x01 " ,SLT_TXID_SIZE);
299- #endif
300- }
301- SLT_RF_init ();
302- SLT_set_freq ();
303- phase = SLT_BUILD;
304- if (sub_protocol==SLT_V1)
287+
288+ if (sub_protocol == SLT_V1)
305289 {
306290 packet_length = SLT_PAYLOADSIZE_V1;
307291 #ifdef MULTI_SYNC
308292 packet_period = 20000 +2 *SLT_V1_TIMING_PACKET; // 22ms
309293 #endif
310294 }
311- else if (sub_protocol== SLT_V1_4)
295+ else if (sub_protocol == SLT_V1_4)
312296 {
313297 packet_length = SLT_PAYLOADSIZE_V1_4;
314298 #ifdef MULTI_SYNC
315299 packet_period = 18000 ; // 18ms
316300 #endif
301+ // Force high part of the ID otherwise the RF frequencies do not match, only tested the 2 last bytes...
302+ rx_tx_addr[0 ]=0xF4 ;
303+ rx_tx_addr[1 ]=0x71 ;
304+ #ifdef SLT_V1_4_FORCE_ID // ID taken from TX dumps
305+ memcpy (rx_tx_addr," \xF4\x71\x8D\x01 " ,SLT_TXID_SIZE);
306+ #endif
317307 }
318308 else // V2
319309 {
@@ -322,6 +312,21 @@ void SLT_init()
322312 packet_period = 13730 +2 *SLT_V2_TIMING_PACKET; // ~18ms
323313 #endif
324314 }
315+
316+ if (sub_protocol == Q200)
317+ { // Q200: Force high part of the ID otherwise it won't bind
318+ rx_tx_addr[0 ]=0x01 ;
319+ rx_tx_addr[1 ]=0x02 ;
320+ #ifdef SLT_Q200_FORCE_ID // ID taken from TX dumps
321+ rx_tx_addr[0 ]=0x01 ;rx_tx_addr[1 ]=0x02 ;rx_tx_addr[2 ]=0x6A ;rx_tx_addr[3 ]=0x31 ;
322+ /* rx_tx_addr[0]=0x01;rx_tx_addr[1]=0x02;rx_tx_addr[2]=0x0B;rx_tx_addr[3]=0x57;*/
323+ #endif
324+ }
325+
326+ SLT_RF_init ();
327+ SLT_set_freq ();
328+
329+ phase = SLT_BUILD;
325330}
326331
327332#endif
0 commit comments