@@ -18,18 +18,21 @@ Multiprotocol is distributed in the hope that it will be useful,
1818
1919#include " iface_xn297.h"
2020
21- #define FX_INITIAL_WAIT 500
22- #define FX_BIND_COUNT 300 // 3sec
23- #define FX_SWITCH 20
24- #define FX_NUM_CHANNELS 4
25-
26- #define FX816_PACKET_PERIOD 10000
27- #define FX816_BIND_CHANNEL 40
28- #define FX816_PAYLOAD_SIZE 6
29-
30- #define FX620_PACKET_PERIOD 3250
31- #define FX620_BIND_CHANNEL 18
32- #define FX620_PAYLOAD_SIZE 7
21+ #define FX_INITIAL_WAIT 500
22+ #define FX_BIND_COUNT 300 // 3sec
23+ #define FX_SWITCH 20
24+ #define FX_NUM_CHANNELS 4
25+
26+ #define FX816_PACKET_PERIOD 10000
27+ #define FX816_BIND_CHANNEL 40
28+ #define FX816_PAYLOAD_SIZE 6
29+ #define FX816_CH_OFFSET 3
30+
31+ #define FX620_PACKET_PERIOD 3250
32+ #define FX620_BIND_PACKET_PERIOD 4500
33+ #define FX620_BIND_CHANNEL 18
34+ #define FX620_PAYLOAD_SIZE 7
35+ #define FX620_CH_OFFSET 1
3336
3437#define FORCE_FX620_ID
3538
@@ -45,15 +48,15 @@ static void __attribute__((unused)) FX_send_packet()
4548 memset (packet,0x00 ,packet_length);
4649
4750 // Channels
48- uint8_t offset=sub_protocol == FX816 ? 3 : 1 ;
49- uint8_t val=convert_channel_8b (AILERON); // Can FX620 have a proportional value, the original radio does not but...
51+ uint8_t offset=sub_protocol == FX816 ? FX816_CH_OFFSET:FX620_CH_OFFSET ;
52+ uint8_t val=convert_channel_8b (AILERON);
5053 if (val>127 +FX_SWITCH)
5154 packet[offset] = sub_protocol == FX816 ? 1 :0xFF ;
5255 else if (val<127 -FX_SWITCH)
5356 packet[offset] = sub_protocol == FX816 ? 2 :0x00 ;
5457 else
5558 packet[offset] = sub_protocol == FX816 ? 0 :0x7F ;
56- packet[offset+1 ] = convert_channel_16b_limit (THROTTLE,0 ,100 );
59+ packet[offset+1 ] = convert_channel_16b_limit (THROTTLE,0 ,100 ); // FX816:0x00..0x63, FX620:0x00..0x5E but that should work
5760
5861 // Bind and specifics
5962 if (sub_protocol == FX816)
@@ -86,7 +89,7 @@ static void __attribute__((unused)) FX_send_packet()
8689 packet[packet_length-1 ]=val;
8790
8891 // Debug
89- #if 0
92+ #if 1
9093 for (uint8_t i=0 ;i<packet_length;i++)
9194 debug (" %02X " ,packet[i]);
9295 debugln (" " );
@@ -121,8 +124,8 @@ static void __attribute__((unused)) FX_initialize_txid()
121124 // I didn't open the plane to find out if I could connect there so this is the best I came up with with few trial and errors...
122125 rx_tx_addr[0 ]=0x35 +(rx_tx_addr[3 ]&0x07 ); // Original dump=0x35
123126 rx_tx_addr[1 ]=0x09 ; // Original dump=0x09
124- memcpy (hopping_frequency," \x09\x1B\x30\x42 " ,FX816_NUM_CHANNELS); // Original dump=9=0x09,27=0x1B,48=0x30,66=0x42
125- for (uint8_t i=0 ;i<FX816_NUM_CHANNELS ;i++)
127+ memcpy (hopping_frequency," \x09\x1B\x30\x42 " ,FX_NUM_CHANNELS); // Original dump=9=0x09,27=0x1B,48=0x30,66=0x42
128+ for (uint8_t i=0 ;i<FX_NUM_CHANNELS ;i++)
126129 hopping_frequency[i]+=rx_tx_addr[3 ]&0x07 ;
127130
128131 packet_length = FX816_PAYLOAD_SIZE;
@@ -136,13 +139,11 @@ static void __attribute__((unused)) FX_initialize_txid()
136139 memcpy (rx_tx_addr,(uint8_t *)" \x34\xA9\x32 " ,3 );
137140 hopping_frequency[0 ] = 0x18 ; // on dump: 24 34 44 54
138141 #endif
139- // no idea if this is true...
140- hopping_frequency[1 ] = 10 + hopping_frequency[0 ];
141- hopping_frequency[2 ] = 20 + hopping_frequency[0 ];
142- hopping_frequency[3 ] = 30 + hopping_frequency[0 ];
142+ for (uint8_t i=1 ;i<FX_NUM_CHANNELS;i++)
143+ hopping_frequency[i] = i*10 + hopping_frequency[0 ];
143144
144145 packet_length = FX620_PAYLOAD_SIZE;
145- packet_period = FX620_PACKET_PERIOD ;
146+ packet_period = FX620_BIND_PACKET_PERIOD ;
146147 }
147148}
148149
@@ -156,7 +157,10 @@ uint16_t FX_callback()
156157 {
157158 BIND_DONE;
158159 if (sub_protocol == FX620)
160+ {
159161 XN297_SetTXAddr (rx_tx_addr, 3 );
162+ packet_period = FX620_PACKET_PERIOD;
163+ }
160164 }
161165 FX_send_packet ();
162166 return packet_period;
0 commit comments