Ready for testing

This commit is contained in:
john_moore007 2023-08-26 15:46:09 +01:00
parent 5cb5a536e1
commit 1b711492ec
3 changed files with 93 additions and 52 deletions

View File

@ -249,8 +249,7 @@ uint16_t DSM_RX_callback()
{
// store tx info into eeprom
uint16_t temp = DSM_RX_EEPROM_OFFSET;
if (sub_protocol == DSM_CLONE)
temp = DSM_CLONE_EEPROM_OFFSET;
debug("ID=");
for(uint8_t i=0;i<4;i++)
{
@ -276,8 +275,6 @@ uint16_t DSM_RX_callback()
DSM_rx_type=packet_in[12];
debugln(", num_ch=%d, type=%02X",num_ch, DSM_rx_type);
eeprom_write_byte((EE_ADDR)temp, DSM_rx_type);
if (sub_protocol == DSM_CLONE)
eeprom_write_byte((EE_ADDR)++temp, num_ch);
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Abort RX operation
CYRF_SetTxRxMode(TX_EN); // Force end state TX
CYRF_ConfigDataCode((const uint8_t *)"\x98\x88\x1B\xE4\x30\x79\x03\x84", 16);
@ -319,6 +316,14 @@ uint16_t DSM_RX_callback()
{
BIND_DONE;
phase++; // DSM_RX_DATA_PREP
//Copy clone values to EEPROM
if (sub_protocol == DSM_CLONE)
{
uint16_t temp = DSM_CLONE_EEPROM_OFFSET;
for(uint8_t i=0; i<4; i++)
eeprom_write_byte((EE_ADDR)temp++, cyrfmfg_id[i]);
eeprom_write_byte((EE_ADDR)temp, 0xF0);
}
}
break;
case DSM_RX_DATA_PREP:
@ -490,7 +495,7 @@ void DSM_RX_init()
{
// Clear all cloned addresses
uint16_t addr = DSM_CLONE_EEPROM_OFFSET;
for(uint8_t i=0; i<7; i++)
for(uint8_t i=0; i<6; i++)
eeprom_write_byte((EE_ADDR)(addr++), 0xFF);
packet_count = 100;
}
@ -505,20 +510,14 @@ void DSM_RX_init()
uint16_t temp = DSM_RX_EEPROM_OFFSET;
if (sub_protocol == DSM_CLONE || sub_protocol == DSM_ERASE )
temp = DSM_CLONE_EEPROM_OFFSET;
debug("ID=");
for(uint8_t i=0;i<4;i++)
{
cyrfmfg_id[i]=eeprom_read_byte((EE_ADDR)temp++);
debug(" %02X", cyrfmfg_id[i]);
}
DSM_rx_type=eeprom_read_byte((EE_ADDR)temp);
DSM_rx_type=eeprom_read_byte((EE_ADDR)DSM_RX_EEPROM_OFFSET+4);
debugln(", type=%02X", DSM_rx_type);
if (sub_protocol == DSM_CLONE || sub_protocol == DSM_ERASE )
{
num_ch=eeprom_read_byte((EE_ADDR)++temp);
debugln("channels=%d", num_ch);
}
phase = DSM_RX_DATA_PREP;
}

View File

@ -21,6 +21,8 @@
//#define DSM_GR300
#define CLONE_BIT_MASK 0x20 // TODO: Fix me
#define DSM_BIND_CHANNEL 0x0d //13 This can be any odd channel
//During binding we will send BIND_COUNT/2 packets
@ -140,10 +142,86 @@ static void __attribute__((unused)) DSM_update_channels()
ch_map[i]=pgm_read_byte_near(&DSM_ch_map_progmem[idx][i]);
}
static void __attribute__((unused)) DSM_getClonedMfgData()
{
if(option&CLONE_BIT_MASK)
{
if(eeprom_read_byte((EE_ADDR)DSM_CLONE_EEPROM_OFFSET+4)==0xF0)
{
//read cloned ID from EEPROM
debugln("Using cloned ID");
uint16_t temp = DSM_CLONE_EEPROM_OFFSET;
for(uint8_t i=0;i<4;i++)
cyrfmfg_id[i] = eeprom_read_byte((EE_ADDR)temp++);
}
else
{
SUB_PROTO_INVALID;
debugln("No valid cloned ID");
}
}
else
{
SUB_PROTO_VALID;
CYRF_GetMfgData(cyrfmfg_id);
}
//Model match
cyrfmfg_id[3]^=RX_num;
//Calc sop_col
sop_col = (cyrfmfg_id[0] + cyrfmfg_id[1] + cyrfmfg_id[2] + 2) & 0x07;
//We cannot manipulate the ID if we are cloning
if(!(option&CLONE_BIT_MASK))
{
//Fix for OrangeRX using wrong DSM_pncodes by preventing access to "Col 8"
if(sop_col==0 && sub_protocol != DSMR)
{
cyrfmfg_id[rx_tx_addr[0]%3]^=0x01; //Change a bit so sop_col will be different from 0
sop_col = (cyrfmfg_id[0] + cyrfmfg_id[1] + cyrfmfg_id[2] + 2) & 0x07;
}
}
//Calc CRC seed
seed = (cyrfmfg_id[0] << 8) + cyrfmfg_id[1];
if(IS_SUB_PROTO_VALID)
{
debug("ID=")
for(uint8_t i=0;i<4;i++)
debug("%02x ", cyrfmfg_id[i]);
debugln("");
}
//Hopping frequencies
if (sub_protocol == DSMX_2F || sub_protocol == DSMX_1F)
DSM_calc_dsmx_channel();
else if(sub_protocol != DSMR)
{
uint8_t tmpch[10];
CYRF_FindBestChannels(tmpch, 10, 5, 3, 75);
//
uint8_t idx = random(0xfefefefe) % 10;
hopping_frequency[0] = tmpch[idx];
while(1)
{
idx = random(0xfefefefe) % 10;
if (tmpch[idx] != hopping_frequency[0])
break;
}
hopping_frequency[1] = tmpch[idx];
}
prev_option^=CLONE_BIT_MASK; // reset the clone flag
}
static void __attribute__((unused)) DSM_build_data_packet(uint8_t upper)
{
debugln("Opt = %02x", option);
uint8_t bits = 11;
// Check if clone flag has changed
if((prev_option&CLONE_BIT_MASK) != (option&CLONE_BIT_MASK))
DSM_getClonedMfgData();
if(prev_option!=option)
DSM_update_channels();
@ -519,43 +597,7 @@ void DSM_init()
hopping_frequency[i] = pgm_read_byte_near(&DSMR_ID_FREQ[row][i+4]);
}
else
{
CYRF_GetMfgData(cyrfmfg_id);
//Model match
cyrfmfg_id[3]^=RX_num;
}
//Calc sop_col
sop_col = (cyrfmfg_id[0] + cyrfmfg_id[1] + cyrfmfg_id[2] + 2) & 0x07;
//Fix for OrangeRX using wrong DSM_pncodes by preventing access to "Col 8"
//if(sop_col==0 && sub_protocol != DSMR)
//{
// cyrfmfg_id[rx_tx_addr[0]%3]^=0x01; //Change a bit so sop_col will be different from 0
// sop_col = (cyrfmfg_id[0] + cyrfmfg_id[1] + cyrfmfg_id[2] + 2) & 0x07;
//}
//Calc CRC seed
seed = (cyrfmfg_id[0] << 8) + cyrfmfg_id[1];
//Hopping frequencies
if (sub_protocol == DSMX_2F || sub_protocol == DSMX_1F)
DSM_calc_dsmx_channel();
else if(sub_protocol != DSMR)
{
uint8_t tmpch[10];
CYRF_FindBestChannels(tmpch, 10, 5, 3, 75);
//
uint8_t idx = random(0xfefefefe) % 10;
hopping_frequency[0] = tmpch[idx];
while(1)
{
idx = random(0xfefefefe) % 10;
if (tmpch[idx] != hopping_frequency[0])
break;
}
hopping_frequency[1] = tmpch[idx];
}
DSM_getClonedMfgData();
//
DSM_cyrf_config();

View File

@ -829,8 +829,8 @@ enum {
#define FRSKYX2_CLONE_EEPROM_OFFSET 873 // (1) format + (3) TX ID, 4 bytes, end is 877
#define DSM_RX_EEPROM_OFFSET 877 // (4) TX ID + format, 5 bytes, end is 882
#define MOULDKG_EEPROM_OFFSET 882 // RX ID, 3 bytes per model, end is 882+64*3=1074
#define DSM_CLONE_EEPROM_OFFSET 1074 // (4) TX ID, (1) RX type, (1) No of channels, end is 1090
//#define CONFIG_EEPROM_OFFSET 1090 // Current configuration of the multimodule
#define DSM_CLONE_EEPROM_OFFSET 1074 // (4) TX ID, (1) Initialized, end is 1079
//#define CONFIG_EEPROM_OFFSET 1079 // Current configuration of the multimodule
/* STM32 Flash Size */
#ifndef DISABLE_FLASH_SIZE_CHECK