From 236b37566992b2beb125f51ed2be663278f62a97 Mon Sep 17 00:00:00 2001 From: Pascal Langer Date: Fri, 20 Jul 2018 19:13:56 +0200 Subject: [PATCH] Corona: FD_V3 sub protocol New subprotocol for FlyDream V3 number 2. --- Multiprotocol/Corona_cc2500.ino | 328 +++++++++++++++++++------------- Multiprotocol/Multi.txt | 2 +- Multiprotocol/Multiprotocol.h | 4 +- Multiprotocol/_Config.h | 1 + 4 files changed, 200 insertions(+), 135 deletions(-) diff --git a/Multiprotocol/Corona_cc2500.ino b/Multiprotocol/Corona_cc2500.ino index 7c4de79..c254b8f 100644 --- a/Multiprotocol/Corona_cc2500.ino +++ b/Multiprotocol/Corona_cc2500.ino @@ -21,10 +21,11 @@ #define CORONA_RF_NUM_CHANNELS 3 #define CORONA_ADDRESS_LENGTH 4 -#define CORONA_BIND_CHANNEL_V1 0xD1 +#define CORONA_BIND_CHANNEL_V1 0xD1 // also Flydream V3 #define CORONA_BIND_CHANNEL_V2 0xB8 #define CORONA_COARSE 0x00 -#define CORONA_CHANNEL_TIMING 1500 +#define FDV3_BIND_PERIOD 5000 +#define FDV3_CHANNEL_PERIOD 4000 const PROGMEM uint8_t CORONA_init_values[] = { /* 00 */ 0x29, 0x2E, 0x06, 0x07, 0xD3, 0x91, 0xFF, 0x04, @@ -35,13 +36,15 @@ const PROGMEM uint8_t CORONA_init_values[] = { /* 28 */ 0x00, 0x59, 0x7F, 0x3F, 0x81, 0x35, 0x0B }; +uint8_t fdv3_id_send; + static void __attribute__((unused)) CORONA_rf_init() { CC2500_Strobe(CC2500_SIDLE); for (uint8_t i = 0; i <= 0x2E; ++i) CC2500_WriteReg(i, pgm_read_byte_near(&CORONA_init_values[i])); - if(sub_protocol!=COR_V1) + if(sub_protocol==COR_V2) { CC2500_WriteReg(CC2500_0A_CHANNR, CORONA_BIND_CHANNEL_V2); CC2500_WriteReg(CC2500_0E_FREQ1, 0x80); @@ -52,6 +55,11 @@ static void __attribute__((unused)) CORONA_rf_init() CC2500_WriteReg(CC2500_1C_AGCCTRL1, 0xFB); CC2500_WriteReg(CC2500_1D_AGCCTRL0, 0xDC); } + else if(sub_protocol==FD_V3) + { + // Flydream receiver captures have deviation 50, tx captures show 47 + CC2500_WriteReg(CC2500_15_DEVIATN, 0x50); + } prev_option = option; CC2500_WriteReg(CC2500_0C_FSCTRL0, option); @@ -68,41 +76,187 @@ static void __attribute__((unused)) CORONA_init() { #ifdef CORONA_FORCE_ID // Example of ID and channels taken from dumps - if(sub_protocol==COR_V1) + switch(sub_protocol) { - memcpy((void *)rx_tx_addr,(void *)"\x1F\xFE\x6C\x35",CORONA_ADDRESS_LENGTH); - memcpy((void *)hopping_frequency,(void *)"\x17\x0D\x03\x49",CORONA_RF_NUM_CHANNELS+1); - } - else - { - memcpy((void *)rx_tx_addr,(void *)"\xFE\xFE\x02\xFB",CORONA_ADDRESS_LENGTH); - memcpy((void *)hopping_frequency,(void *)"\x14\x3D\x35",CORONA_RF_NUM_CHANNELS); - } + case COR_V1: + memcpy((void *)rx_tx_addr,(void *)"\x1F\xFE\x6C\x35",CORONA_ADDRESS_LENGTH); + memcpy((void *)hopping_frequency,(void *)"\x17\x0D\x03\x49",CORONA_RF_NUM_CHANNELS+1); + break; + case COR_V2: + memcpy((void *)rx_tx_addr,(void *)"\xFE\xFE\x02\xFB",CORONA_ADDRESS_LENGTH); + memcpy((void *)hopping_frequency,(void *)"\x14\x3D\x35",CORONA_RF_NUM_CHANNELS); + case FD_V3: + memcpy((void *)rx_tx_addr,(void *)"\x02\xFA\x38\x38",CORONA_ADDRESS_LENGTH); + memcpy((void *)hopping_frequency,(void *)"\x71\xB9\x30",CORONA_RF_NUM_CHANNELS); + break; + } #else // From dumps channels are anything between 0x00 and 0xC5 on V1. // But 0x00 and 0xB8 should be avoided on V2 since they are used for bind. - // Below code make sure channels are between 0x02 and 0xA0, spaced with a minimum of 2 and not ordered (RX only use the 1st channel unless there is an issue). + // Below code make sure channels are between 0x02 and 0xA0, spaced with + // a minimum of 2 and not ordered (RX only use the 1st channel unless there is an issue). + // Extra hopping frequency used for Flydream V3 id packets. uint8_t order=rx_tx_addr[3]&0x03; for(uint8_t i=0; i>1)] |= (i&0x01)?(val>>4)&0xF0:(val>>8)&0x0F; + } + + // TX ID + for (uint8_t i=0; i < CORONA_ADDRESS_LENGTH; i++) + packet[i+13] = rx_tx_addr[i]; + + packet[17] = 0x00; + + if (sub_protocol!=FD_V3) + { + // Packet period is based on hopping + switch (hopping_frequency_no) + { + case 0: + packet_period = sub_protocol == COR_V1 + ? 4991 + : 4248; + break; + case 1: + packet_period = sub_protocol == COR_V1 + ? 4991 + : 4345; + break; + case 2: + packet_period = sub_protocol == COR_V1 + ? 12520 + : 13468; + if (sub_protocol == COR_V2) + packet[17] = 0x03; + break; + } + } + hopping_frequency_no++; + + if (sub_protocol == FD_V3) + { + if (hopping_frequency_no == CORONA_RF_NUM_CHANNELS) + { + fdv3_id_send = 1; + packet_period = 6000; // extra delay before id packet according to captures + } + else + packet_period = FDV3_CHANNEL_PERIOD; + } + + hopping_frequency_no %= CORONA_RF_NUM_CHANNELS; + return packet_period; +} + +uint16_t ReadCORONA() { // Tune frequency if it has been changed if ( prev_option != option ) @@ -110,129 +264,37 @@ static void __attribute__((unused)) CORONA_build_packet() CC2500_WriteReg(CC2500_0C_FSCTRL0, option); prev_option = option ; } - if(IS_BIND_DONE) - { - if(state==0 || sub_protocol==COR_V1) - { // Build standard packet - // Set RF channel - CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[hopping_frequency_no]); - // Update RF power - CC2500_SetPower(); - - // Build packet - packet[0] = 0x10; // 17 bytes to follow - - // Channels - memset(packet+9, 0x00, 4); - for(uint8_t i=0; i<8; i++) - { // Channel values are packed - uint16_t val=convert_channel_ppm(i); - packet[i+1] = val; - packet[9 + (i>>1)] |= (i&0x01)?(val>>4)&0xF0:(val>>8)&0x0F; - } - - // TX ID - for(uint8_t i=0; i 0x80 0=High/1=Low Stream[3] = option_protocol; diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index b860073..54c0a31 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -544,6 +544,7 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= { PROTO_CORONA COR_V1 COR_V2 + FD_V3 PROTO_CFLIE NONE */