Initial Version of CloneMode (#342)

* Initial Version

* Bugfix and change of the handling of the RX Num.

If RX Num is 63, write a finetune value of 127 to the EEPROM.
A real finetune value of 127 means, the frequency of module is out of range and
the module should be replaced. This way the clone mode should not get unwanted
active by a module with a frequency drift arround 63.
This commit is contained in:
E1yot 2020-04-10 19:01:01 +02:00 committed by GitHub
parent 4039cbf8af
commit 08a555f187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 8 deletions

View File

@ -105,6 +105,23 @@ void FrSkyX2_init_hop(void)
hopping_frequency[47] = 0; //Bind freq
}
uint8_t hw_ver=0x02;
void Frsky_init_clone(void)
{
uint16_t temp = FRSKY_RX_EEPROM_OFFSET;
temp++;
rx_tx_addr[3] = eeprom_read_byte((EE_ADDR)temp++);
rx_tx_addr[2] = eeprom_read_byte((EE_ADDR)temp++);
hw_ver = eeprom_read_byte((EE_ADDR)temp++);
temp++;
for (uint8_t ch = 0; ch < 47; ch++)
{
hopping_frequency[ch] = eeprom_read_byte((EE_ADDR)temp++);
}
debugln("Clone mode");
}
#endif
/******************************/
/** FrSky V, D and X routines **/

View File

@ -42,7 +42,7 @@ static void __attribute__((unused)) FrSkyX_build_bind_packet()
packet[8] = hopping_frequency[idx++];
packet[9] = hopping_frequency[idx++];
packet[10] = hopping_frequency[idx++];
packet[11] = 0x02; // Unknown but constant ID?
packet[11] = hw_ver; // Unknown but constant ID?
packet[12] = RX_num;
//
memset(&packet[13], 0, packet_size - 14);
@ -54,7 +54,7 @@ static void __attribute__((unused)) FrSkyX_build_bind_packet()
else
{
//packet 1D 03 01 0E 1C 02 00 00 32 0B 00 00 A8 26 28 01 A1 00 00 00 3E F6 87 C7 00 00 00 00 C9 C9
packet[5] = 0x02; // Unknown but constant ID?
packet[5] = hw_ver; // Unknown but constant ID?
packet[6] = RX_num;
//Bind flags
packet[7]=0;
@ -119,7 +119,7 @@ static void __attribute__((unused)) FrSkyX_build_packet()
packet[0] = packet_size; // Number of bytes in the packet (after this one)
packet[1] = rx_tx_addr[3]; // ID
packet[2] = rx_tx_addr[2]; // ID
packet[3] = 0x02; // Unknown but constant ID?
packet[3] = hw_ver; // Unknown but constant ID?
//
packet[4] = (FrSkyX_chanskip<<6)|hopping_frequency_no;
packet[5] = FrSkyX_chanskip>>2;
@ -385,8 +385,9 @@ uint16_t ReadFrSkyX()
uint16_t initFrSkyX()
{
set_rx_tx_addr(MProtocol_id_master);
if(protocol==PROTO_FRSKYX)
if ((eeprom_read_byte((EE_ADDR)FRSKY_RX_EEPROM_OFFSET+4)==127) && (eeprom_read_byte((EE_ADDR)FRSKY_RX_EEPROM_OFFSET)<2))// bound in FRSKY-X RX-mode with RX Num 63 -> use clone mode
Frsky_init_clone();
else if(protocol==PROTO_FRSKYX)
Frsky_init_hop();
else
{

View File

@ -392,8 +392,17 @@ uint16_t FrSky_Rx_callback()
eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[2]);
debug("addr[2]=%02X, ", rx_tx_addr[2]);
debug("rx_num=%02X, ", packet[12]); // RX # (D16)
if (packet[12]==63)
{
// If RX Num is 63, write a finetune value of 127 to the EEPROM
// A real finetune value of 127 means, the frequency of module is out of range and the module should be replaced.
eeprom_write_byte((EE_ADDR)temp++, 127);
}
else
{
eeprom_write_byte((EE_ADDR)temp++, frsky_rx_finetune);
debugln("tune=%d", (int8_t)frsky_rx_finetune);
}
for (ch = 0; ch < 47; ch++)
{
eeprom_write_byte((EE_ADDR)temp++, hopping_frequency[ch]);