1+ /*
2+ This project is free software: you can redistribute it and/or modify
3+ it under the terms of the GNU General Public License as published by
4+ the Free Software Foundation, either version 3 of the License, or
5+ (at your option) any later version.
6+
7+ Multiprotocol is distributed in the hope that it will be useful,
8+ but WITHOUT ANY WARRANTY; without even the implied warranty of
9+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+ GNU General Public License for more details.
11+
12+ You should have received a copy of the GNU General Public License
13+ along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
14+ */
15+ // Compatible with WPL "Basic" TX models D12, D12KM, D22, D32, D42, D14
16+
17+ #if defined(WPL_NRF24L01_INO)
18+
19+ #include " iface_xn297.h"
20+
21+ #define FORCE_WPL_ORIGINAL_ID
22+
23+ #define WPL_PACKET_PERIOD 9875
24+ #define WPL_RF_NUM_CHANNELS 4
25+ #define WPL_PAYLOAD_SIZE 16
26+ #define WPL_BIND_COUNT 303 // 3sec
27+
28+ static void __attribute__ ((unused)) WPL_send_packet()
29+ {
30+ XN297_Hopping (hopping_frequency_no + (IS_BIND_IN_PROGRESS?0 :4 ) );
31+ hopping_frequency_no++;
32+ hopping_frequency_no &= WPL_RF_NUM_CHANNELS-1 ; // 4 RF channels
33+
34+ memset (&packet[8 ],0 ,7 );
35+ packet[0 ] = 0x94 ; // ??
36+ packet[1 ] = 0x16 ; // ??
37+ packet[2 ] = 0xCC ; // ??
38+
39+ if (IS_BIND_IN_PROGRESS)
40+ {
41+ memcpy (&packet[3 ],rx_tx_addr,5 );
42+ packet[9 ] = 0x08 ; // ?? Not bound + Headlights on
43+ }
44+ else
45+ {
46+ packet[3 ] = convert_channel_s8b (CH1); // Throttle
47+ packet[4 ] = convert_channel_s8b (CH2); // Steering
48+ packet[5 ] = convert_channel_16b_limit (CH3,0x22 ,0x5E ); // Steering trim
49+ packet[6 ] = rx_tx_addr[3 ]; // 0x32??
50+ packet[7 ] = convert_channel_s8b (CH4); // Aux
51+ packet[9 ] = 0x80 // ?? Bound
52+ | GET_FLAG (CH5_SW, 0x08 ) // Headlights 100%=on
53+ | GET_FLAG (CH6_SW, 0x04 ) // Throttle rate 100%=high
54+ | GET_FLAG (CH7_SW, 0x02 ); // Steering rate 100%=high
55+ }
56+
57+ // Send
58+ XN297_SetPower ();
59+ XN297_SetTxRxMode (TX_EN);
60+ XN297_WritePayload (packet, WPL_PAYLOAD_SIZE);
61+ }
62+
63+ static void __attribute__ ((unused)) WPL_RF_init()
64+ {
65+ XN297_Configure (XN297_CRCEN, XN297_SCRAMBLED, XN297_1M);
66+ XN297_SetTXAddr ((uint8_t *)" \x69\xA5\x37\x4D\x8B " , 5 );
67+ XN297_HoppingCalib (WPL_RF_NUM_CHANNELS*2 ); // Calibrate bind and normal channels
68+ }
69+
70+ static void __attribute__ ((unused)) WPL_initialize_txid()
71+ {
72+ // Bind frequencies
73+ memcpy (hopping_frequency ," \x17\x25\x46\x36 " , WPL_RF_NUM_CHANNELS); // 23=17, 37=25, 70=46, 54=36
74+ // Normal frequencies
75+ memcpy (hopping_frequency+4 ," \x0C\x2A\x3D\x1D " , WPL_RF_NUM_CHANNELS); // 12=0C, 42=2A, 61=3D, 29=1D
76+ #ifdef FORCE_WPL_ORIGINAL_ID
77+ memcpy (rx_tx_addr," \x96\x2A\xA9\x32\xB4 " ,5 );
78+ #endif
79+ }
80+
81+ uint16_t WPL_callback ()
82+ {
83+ #ifdef MULTI_SYNC
84+ telemetry_set_input_sync (WPL_PACKET_PERIOD);
85+ #endif
86+ if (bind_counter)
87+ if (--bind_counter==0 )
88+ BIND_DONE;
89+ WPL_send_packet ();
90+ return WPL_PACKET_PERIOD;
91+ }
92+
93+ void WPL_init ()
94+ {
95+ BIND_IN_PROGRESS; // autobind protocol
96+ WPL_initialize_txid ();
97+ WPL_RF_init ();
98+ hopping_frequency_no = 0 ;
99+ bind_counter=WPL_BIND_COUNT;
100+ }
101+
102+ #endif
103+ /* https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/issues/1120
104+ Bind packet
105+ -----------
106+ XN297 1Mb Scrambled
107+ Bind address: 69 A5 37 4D 8B
108+ RF channels: 23, 37, 70, 54
109+ Timing: 9875µs
110+ Payload 16 bytes: 94 16 CC 96 2A A9 32 B4 00 08 00 00 00 00 00 33
111+
112+ P[0] = 94 ??
113+ P[1] = 16 ??
114+ P[2] = CC ??
115+ P[3..7] = Normal address
116+ P[8] = 00 ??
117+ P[9] = 08 ?? not bound?, Throttle and Steering rate low, Headlights on
118+ P[10..14] = 00 ??
119+ P[15] = sum(P[0..14])+66 why 66...
120+
121+ Normal packet
122+ -----------
123+ XN297 1Mb Scrambled
124+ Normal address: 96 2A A9 32 B4
125+ RF channels: 12=0C, 42=2A, 61=3D, 29=1D -> no idea where they come from...
126+ Timing: 9875µs
127+ Payload 16 bytes: 94 16 CC 80 80 38 32 80 00 88 00 00 00 00 00 4E
128+ P[0] = 94 ??
129+ P[1] = 16 ??
130+ P[2] = CC ??
131+ P[3] = Throttle, not enough data on dumps... Same coding as Steering?
132+ P[4] = Steering, not enough data on dumps, looks like one side goes from 7F to 00 and the other 80 to FF which would be s8b
133+ P[5] = Steering trim 22..5E, mid gives 40 not 38... Was the trim centered on the other dumps with value 38?
134+ P[6] = 32 ?? Left over from the bind packet TX_ADDR[3]?
135+ P[7] = 80 ?? Additional channel? It moves at the same time as the trim but my guess is that it is an unconnected channel.
136+ P[8] = 00 ??
137+ P[9] = 80 ?? bound?, Throttle and Steering rate low, Headlights off
138+ |02 -> Steering rate high
139+ |04 -> Throttle rate high
140+ |08 -> Headlights on
141+ P[10..14] = 00 ??
142+ P[15] = sum(P[0..14])+66 why 66...
143+ */
0 commit comments