diff --git a/Multiprotocol/Multi.txt b/Multiprotocol/Multi.txt index bb76f7e..9d499cf 100644 --- a/Multiprotocol/Multi.txt +++ b/Multiprotocol/Multi.txt @@ -18,7 +18,7 @@ 18,MJXq,WLH08,X600,X800,H26D,E010,H26WH 19,Shenqi 20,FY326,FY326,FY319 -21,SFHSS,XK,T8J,T10J,TM-FH +21,SFHSS 22,J6PRO 23,FQ777 24,ASSAN diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index c55bb34..30e1a80 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 1 #define VERSION_REVISION 6 -#define VERSION_PATCH_LEVEL 24 +#define VERSION_PATCH_LEVEL 25 //****************** // Protocols //****************** @@ -196,13 +196,6 @@ enum Q303 CX10D = 2, CX10WD = 3, }; -enum SFHSS -{ - XK = 0, - T10J = 1, - T8J = 2, - TM_FH = 3, -}; #define NONE 0 #define P_HIGH 1 @@ -592,11 +585,6 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- CX35 1 CX10D 2 CX10WD 3 - sub_protocol==SFHSS - XK 0 - T10J 1 - T8J 2 - TM_FH 3 Power value => 0x80 0=High/1=Low Stream[3] = option_protocol; diff --git a/Multiprotocol/NRF24l01_SPI.ino b/Multiprotocol/NRF24l01_SPI.ino index 32a12fc..bbe2ed0 100644 --- a/Multiprotocol/NRF24l01_SPI.ino +++ b/Multiprotocol/NRF24l01_SPI.ino @@ -27,6 +27,7 @@ uint8_t rf_setup; void NRF24L01_Initialize() { rf_setup = 0x09; + prev_power = 0x00; // Make sure prev_power is inline with current power XN297_SetScrambledMode(XN297_SCRAMBLED); } @@ -133,7 +134,8 @@ void NRF24L01_SetBitrate(uint8_t bitrate) // Bit 0 goes to RF_DR_HIGH, bit 1 - to RF_DR_LOW rf_setup = (rf_setup & 0xD7) | ((bitrate & 0x02) << 4) | ((bitrate & 0x01) << 3); - NRF24L01_WriteReg(NRF24L01_06_RF_SETUP, rf_setup); + prev_power=(rf_setup>>1)&0x03; // Make sure prev_power is inline with current power + NRF24L01_WriteReg(NRF24L01_06_RF_SETUP, rf_setup); } /* @@ -167,9 +169,9 @@ void NRF24L01_SetPower() #endif if(IS_RANGE_FLAG_on) power=NRF_POWER_0; - rf_setup = (rf_setup & 0xF9) | (power << 1); if(prev_power != power) { + rf_setup = (rf_setup & 0xF9) | (power << 1); NRF24L01_WriteReg(NRF24L01_06_RF_SETUP, rf_setup); prev_power=power; } diff --git a/Multiprotocol/SFHSS_cc2500.ino b/Multiprotocol/SFHSS_cc2500.ino index 960352f..edc6190 100644 --- a/Multiprotocol/SFHSS_cc2500.ino +++ b/Multiprotocol/SFHSS_cc2500.ino @@ -23,14 +23,14 @@ #define SFHSS_PACKET_LEN 13 #define SFHSS_TX_ID_LEN 2 -uint8_t fhss_code; // 0-27 +uint8_t fhss_code=0; // 0-27 enum { SFHSS_START = 0x00, SFHSS_CAL = 0x01, - SFHSS_DATA1 = 0x02, // do not change this value - SFHSS_DATA2 = 0x0B, // do not change this value - SFHSS_TUNE = 0x0F + SFHSS_DATA1 = 0x02, + SFHSS_DATA2 = 0x03, + SFHSS_TUNE = 0x04 }; #define SFHSS_FREQ0_VAL 0xC4 @@ -122,65 +122,48 @@ static void __attribute__((unused)) SFHSS_calc_next_chan() } } -/*// Channel values are 10-bit values between 86 and 906, 496 is the middle. -// Values grow down and to the right. -static void __attribute__((unused)) SFHSS_build_data_packet() -{ -#define spacer1 0x02 -#define spacer2 (spacer1 << 4) - uint8_t ch_offset = phase == SFHSS_DATA1 ? 0 : 4; - uint16_t ch1 = convert_channel_16b_nolim(CH_AETR[ch_offset+0],86,906); - uint16_t ch2 = convert_channel_16b_nolim(CH_AETR[ch_offset+1],86,906); - uint16_t ch3 = convert_channel_16b_nolim(CH_AETR[ch_offset+2],86,906); - uint16_t ch4 = convert_channel_16b_nolim(CH_AETR[ch_offset+3],86,906); - - packet[0] = 0x81; // can be 80 or 81 for Orange, only 81 for XK - packet[1] = rx_tx_addr[0]; - packet[2] = rx_tx_addr[1]; - packet[3] = 0; - packet[4] = 0; - packet[5] = (rf_ch_num << 3) | spacer1 | ((ch1 >> 9) & 0x01); - packet[6] = (ch1 >> 1); - packet[7] = (ch1 << 7) | spacer2 | ((ch2 >> 5) & 0x1F); - packet[8] = (ch2 << 3) | spacer1 | ((ch3 >> 9) & 0x01); - packet[9] = (ch3 >> 1); - packet[10] = (ch3 << 7) | spacer2 | ((ch4 >> 5) & 0x1F); - packet[11] = (ch4 << 3) | ((fhss_code >> 2) & 0x07); - packet[12] = (fhss_code << 6) | phase; -} -*/ - // Channel values are 12-bit values between 1020 and 2020, 1520 is the middle. // Futaba @140% is 2070...1520...970 // Values grow down and to the right. static void __attribute__((unused)) SFHSS_build_data_packet() { - const uint8_t SFHSS_ident[4][3]={ - { 0x81, 0x00, 0x00}, //XK - { 0x81, 0x42, 0x07}, //T8J - { 0x81, 0x0F, 0x09}, //T10J - { 0x82, 0x9A, 0x06} //TM-FH - }; - - uint8_t ch_offset = phase == SFHSS_DATA1 ? 0 : 4; + // command.bit0 is the packet number indicator: =0 -> SFHSS_DATA1, =1 -> SFHSS_DATA2 + // command.bit1 is unknown but seems to be linked to the payload[0].bit0 but more dumps are needed: payload[0]=0x82 -> =0, payload[0]=0x81 -> =1 + // command.bit2 is the failsafe transmission indicator: =0 -> normal data, =1->failsafe data + // command.bit3 is the channels indicator: =0 -> CH1-4, =1 -> CH5-8 + uint8_t command= (phase == SFHSS_DATA1) ? 0 : 1; // Building packet for Data1 or Data2 + counter+=command; + if(counter&1) command|=0x08; // Transmit lower and upper channels twice in a row + if((counter&0x3FE)==0x3FE) + { + command|=0x04; // Transmit failsafe data every 7s + counter&=0x3FF; // Reset counter + } + else + command|=0x02; // Assuming packet[0] == 0x81 + uint8_t ch_offset = ((command&0x08) >> 1) + ((command&0x04)<<1); // CH1..CH8 when failsafe is off, CH9..CH16 when failsafe is on uint16_t ch1 = convert_channel_16b_nolim(CH_AETR[ch_offset+0],2020,1020); uint16_t ch2 = convert_channel_16b_nolim(CH_AETR[ch_offset+1],2020,1020); uint16_t ch3 = convert_channel_16b_nolim(CH_AETR[ch_offset+2],2020,1020); uint16_t ch4 = convert_channel_16b_nolim(CH_AETR[ch_offset+3],2020,1020); - packet[0] = SFHSS_ident[sub_protocol][0]; // can be 80 or 81 for Orange + // XK [0]=0x81 [3]=0x00 [4]=0x00 + // T8J [0]=0x81 [3]=0x42 [4]=0x07 + // T10J [0]=0x81 [3]=0x0F [4]=0x09 + // TM-FH [0]=0x82 [3]=0x9A [4]=0x06 + packet[0] = 0x81; // can be 80 or 81 for Orange, only 81 for XK packet[1] = rx_tx_addr[0]; packet[2] = rx_tx_addr[1]; - packet[3] = SFHSS_ident[sub_protocol][1]; - packet[4] = SFHSS_ident[sub_protocol][2]; + packet[3] = rx_tx_addr[2]; // ID? + packet[4] = rx_tx_addr[3]; // ID? packet[5] = (rf_ch_num << 3) | ((ch1 >> 9) & 0x07); packet[6] = (ch1 >> 1); packet[7] = (ch1 << 7) | ((ch2 >> 5) & 0x7F ); - packet[8] = (ch2 << 3) | ((ch3 >> 9) & 0x07); + packet[8] = (ch2 << 3) | ((ch3 >> 9) & 0x07 ); packet[9] = (ch3 >> 1); packet[10] = (ch3 << 7) | ((ch4 >> 5) & 0x7F ); packet[11] = (ch4 << 3) | ((fhss_code >> 2) & 0x07 ); - packet[12] = (fhss_code << 6) | phase; + packet[12] = (fhss_code << 6) | command; } static void __attribute__((unused)) SFHSS_send_packet() @@ -204,28 +187,31 @@ uint16_t ReadSFHSS() else { rf_ch_num = 0; + counter = 0; phase = SFHSS_DATA1; } return 2000; - /* Work cycle, 6.8ms, second packet 1.65ms after first */ + /* Work cycle: 6.8ms */ +#define SFHSS_PACKET_PERIOD 6800 +#define SFHSS_DATA2_TIMING 1630 // original 1650 case SFHSS_DATA1: SFHSS_build_data_packet(); SFHSS_send_packet(); phase = SFHSS_DATA2; - return 1650; + return SFHSS_DATA2_TIMING; // original 1650 case SFHSS_DATA2: SFHSS_build_data_packet(); SFHSS_send_packet(); SFHSS_calc_next_chan(); phase = SFHSS_TUNE; - return 2000; + return (SFHSS_PACKET_PERIOD -2000 -SFHSS_DATA2_TIMING); // original 2000 case SFHSS_TUNE: phase = SFHSS_DATA1; SFHSS_tune_freq(); SFHSS_tune_chan_fast(); CC2500_SetPower(); - return 3150; + return 2000; // original 3150 } return 0; } @@ -233,13 +219,13 @@ uint16_t ReadSFHSS() // Generate internal id static void __attribute__((unused)) SFHSS_get_tx_id() { - uint32_t fixed_id; // Some receivers (Orange) behaves better if they tuned to id that has // no more than 6 consecutive zeros and ones + uint32_t fixed_id; uint8_t run_count = 0; // add guard for bit count fixed_id = 1 ^ (MProtocol_id & 1); - for (uint8_t i = 0; i < 16; ++i) + for (uint8_t i = 0; i < 32; ++i) { fixed_id = (fixed_id << 1) | (MProtocol_id & 1); MProtocol_id >>= 1; @@ -256,8 +242,10 @@ static void __attribute__((unused)) SFHSS_get_tx_id() run_count = 0; } // fixed_id = 0xBC11; - rx_tx_addr[0] = fixed_id >> 8; - rx_tx_addr[1] = fixed_id; + rx_tx_addr[0] = fixed_id >> 24; + rx_tx_addr[1] = fixed_id >> 16; + rx_tx_addr[2] = fixed_id >> 8; + rx_tx_addr[3] = fixed_id >> 0; } uint16_t initSFHSS() @@ -265,7 +253,7 @@ uint16_t initSFHSS() BIND_DONE; // Not a TX bind protocol SFHSS_get_tx_id(); - fhss_code=rx_tx_addr[2]%28; // Initialize it to random 0-27 inclusive + fhss_code=random(0xfefefefe)%28; // Initialize it to random 0-27 inclusive SFHSS_rf_init(); phase = SFHSS_START; diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index e663438..c6e6506 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -136,9 +136,9 @@ #define FQ777_NRF24L01_INO #define ASSAN_NRF24L01_INO #define HONTAI_NRF24L01_INO -#define Q303_NRF24L01_INO -#define GW008_NRF24L01_INO -#define DM002_NRF24L01_INO +#define Q303_NRF24L01_INO +#define GW008_NRF24L01_INO +#define DM002_NRF24L01_INO /**************************/ /*** FAILSAFE SETTINGS ***/ @@ -368,10 +368,7 @@ const PPM_Parameters PPM_prot[15]= { FY326 FY319 MODE_SFHSS - XK - T10J - T8J - TM_FH + NONE MODE_J6PRO NONE MODE_FQ777