From 821732bba95ccd6e4747d21c6f868968c5434834 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 30 Sep 2019 17:35:12 +0200 Subject: [PATCH 01/65] Initial S.Port send !!! No retransmit for now !!! --- Multiprotocol/AFHDS2A_a7105.ino | 6 +- Multiprotocol/Convert.ino | 142 ++++++ Multiprotocol/DSM_cyrf6936.ino | 22 +- .../{Common.ino => FrSkyDVX_common.ino} | 152 +----- Multiprotocol/FrSkyD_cc2500.ino | 8 +- Multiprotocol/FrSkyX_Rx_cc2500.ino | 14 +- Multiprotocol/FrSkyX_cc2500.ino | 139 +++--- Multiprotocol/Hitec_cc2500.ino | 38 +- Multiprotocol/Multiprotocol.h | 6 +- Multiprotocol/Multiprotocol.ino | 112 ++++- Multiprotocol/Scanner_cc2500.ino | 4 +- Multiprotocol/Telemetry.ino | 444 +++++++++--------- Multiprotocol/WFLY_cyrf6936.ino | 16 +- 13 files changed, 596 insertions(+), 507 deletions(-) create mode 100644 Multiprotocol/Convert.ino rename Multiprotocol/{Common.ino => FrSkyDVX_common.ino} (60%) diff --git a/Multiprotocol/AFHDS2A_a7105.ino b/Multiprotocol/AFHDS2A_a7105.ino index 3c7b844..4333972 100644 --- a/Multiprotocol/AFHDS2A_a7105.ino +++ b/Multiprotocol/AFHDS2A_a7105.ino @@ -90,14 +90,14 @@ static void AFHDS2A_update_telemetry() #ifdef AFHDS2A_FW_TELEMETRY if (option & 0x80) {// forward 0xAA and 0xAC telemetry to TX, skip rx and tx id to save space - pkt[0]= TX_RSSI; + packet_in[0]= TX_RSSI; debug("T(%02X)=",packet[0]); for(uint8_t i=9;i < AFHDS2A_RXPACKET_SIZE; i++) { - pkt[i-8]=packet[i]; + packet_in[i-8]=packet[i]; debug(" %02X",packet[i]); } - pkt[29]=packet[0]; // 0xAA Normal telemetry, 0xAC Extended telemetry + packet_in[29]=packet[0]; // 0xAA Normal telemetry, 0xAC Extended telemetry telemetry_link=2; debugln(""); return; diff --git a/Multiprotocol/Convert.ino b/Multiprotocol/Convert.ino new file mode 100644 index 0000000..edfc26e --- /dev/null +++ b/Multiprotocol/Convert.ino @@ -0,0 +1,142 @@ +/* + This project is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Multiprotocol is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Multiprotocol. If not, see . + */ + +/************************/ +/** Convert routines **/ +/************************/ +// Reverse a channel and store it +void reverse_channel(uint8_t num) +{ + uint16_t val=2048-Channel_data[num]; + if(val>=2048) val=2047; + Channel_data[num]=val; +} + +// Channel value is converted to ppm 860<->2140 -125%<->+125% and 988<->2012 -100%<->+100% +uint16_t convert_channel_ppm(uint8_t num) +{ + uint16_t val=Channel_data[num]; + return (((val<<2)+val)>>3)+860; //value range 860<->2140 -125%<->+125% +} + +// Channel value 100% is converted to 10bit values 0<->1023 +uint16_t convert_channel_10b(uint8_t num) +{ + uint16_t val=Channel_data[num]; + val=((val<<2)+val)>>3; + if(val<=128) return 0; + if(val>=1152) return 1023; + return val-128; +} + +// Channel value 100% is converted to 8bit values 0<->255 +uint8_t convert_channel_8b(uint8_t num) +{ + uint16_t val=Channel_data[num]; + val=((val<<2)+val)>>5; + if(val<=32) return 0; + if(val>=288) return 255; + return val-32; +} + +// Channel value 100% is converted to 8b with deadband +uint8_t convert_channel_8b_limit_deadband(uint8_t num,uint8_t min,uint8_t mid, uint8_t max, uint8_t deadband) +{ + uint16_t val=limit_channel_100(num); // 204<->1844 + uint16_t db_low=CHANNEL_MID-deadband, db_high=CHANNEL_MID+deadband; // 1024+-deadband + int32_t calc; + uint8_t out; + if(val>=db_low && val<=db_high) + return mid; + else if(valmin) out++; else out--; + } + return out; +} + +// Channel value 100% is converted to value scaled +int16_t convert_channel_16b_limit(uint8_t num,int16_t min,int16_t max) +{ + int32_t val=limit_channel_100(num); // 204<->1844 + val=(val-CHANNEL_MIN_100)*(max-min)/(CHANNEL_MAX_100-CHANNEL_MIN_100)+min; + return (uint16_t)val; +} + +// Channel value -125%<->125% is scaled to 16bit value with no limit +int16_t convert_channel_16b_nolimit(uint8_t num, int16_t min, int16_t max) +{ + int32_t val=Channel_data[num]; // 0<->2047 + val=(val-CHANNEL_MIN_100)*(max-min)/(CHANNEL_MAX_100-CHANNEL_MIN_100)+min; + return (uint16_t)val; +} + +// Channel value is converted sign + magnitude 8bit values +uint8_t convert_channel_s8b(uint8_t num) +{ + uint8_t ch; + ch = convert_channel_8b(num); + return (ch < 128 ? 127-ch : ch); +} + +// Channel value is limited to 100% +uint16_t limit_channel_100(uint8_t num) +{ + if(Channel_data[num]>=CHANNEL_MAX_100) + return CHANNEL_MAX_100; + if (Channel_data[num]<=CHANNEL_MIN_100) + return CHANNEL_MIN_100; + return Channel_data[num]; +} + +// Channel value is converted for HK310 +void convert_channel_HK310(uint8_t num, uint8_t *low, uint8_t *high) +{ + uint16_t temp=0xFFFF-(3440+((Channel_data[num]*5)>>1))/3; + *low=(uint8_t)(temp&0xFF); + *high=(uint8_t)(temp>>8); +} + +#ifdef FAILSAFE_ENABLE +// Failsafe value is converted for HK310 +void convert_failsafe_HK310(uint8_t num, uint8_t *low, uint8_t *high) +{ + uint16_t temp=0xFFFF-(3440+((Failsafe_data[num]*5)>>1))/3; + *low=(uint8_t)(temp&0xFF); + *high=(uint8_t)(temp>>8); +} +#endif + +// Channel value for FrSky (PPM is multiplied by 1.5) +uint16_t convert_channel_frsky(uint8_t num) +{ + uint16_t val=Channel_data[num]; + return ((val*15)>>4)+1290; +} diff --git a/Multiprotocol/DSM_cyrf6936.ino b/Multiprotocol/DSM_cyrf6936.ino index faea637..fc18528 100644 --- a/Multiprotocol/DSM_cyrf6936.ino +++ b/Multiprotocol/DSM_cyrf6936.ino @@ -363,12 +363,12 @@ static uint8_t __attribute__((unused)) DSM_Check_RX_packet() uint16_t sum = 384 - 0x10; for(uint8_t i = 1; i < 9; i++) { - sum += pkt[i]; + sum += packet_in[i]; if(i<5) - if(pkt[i] != (0xff ^ cyrfmfg_id[i-1])) + if(packet_in[i] != (0xff ^ cyrfmfg_id[i-1])) result=0; // bad packet } - if( pkt[9] != (sum>>8) && pkt[10] != (uint8_t)sum ) + if( packet_in[9] != (sum>>8) && packet_in[10] != (uint8_t)sum ) result=0; return result; } @@ -417,12 +417,12 @@ uint16_t ReadDsm() { // data received with no errors CYRF_WriteRegister(CYRF_07_RX_IRQ_STATUS, 0x80); // need to set RXOW before data read len=CYRF_ReadRegister(CYRF_09_RX_COUNT); - if(len>MAX_PKT-2) - len=MAX_PKT-2; - CYRF_ReadDataPacketLen(pkt+1, len); + if(len>TELEMETRY_BUFFER_SIZE-2) + len=TELEMETRY_BUFFER_SIZE-2; + CYRF_ReadDataPacketLen(packet_in+1, len); if(len==10 && DSM_Check_RX_packet()) { - pkt[0]=0x80; + packet_in[0]=0x80; telemetry_link=1; // send received data on serial phase++; return 2000; @@ -502,10 +502,10 @@ uint16_t ReadDsm() { // good data (complete with no errors) CYRF_WriteRegister(CYRF_07_RX_IRQ_STATUS, 0x80); // need to set RXOW before data read len=CYRF_ReadRegister(CYRF_09_RX_COUNT); - if(len>MAX_PKT-2) - len=MAX_PKT-2; - CYRF_ReadDataPacketLen(pkt+1, len); - pkt[0]=CYRF_ReadRegister(CYRF_13_RSSI)&0x1F;// store RSSI of the received telemetry signal + if(len>TELEMETRY_BUFFER_SIZE-2) + len=TELEMETRY_BUFFER_SIZE-2; + CYRF_ReadDataPacketLen(packet_in+1, len); + packet_in[0]=CYRF_ReadRegister(CYRF_13_RSSI)&0x1F;// store RSSI of the received telemetry signal telemetry_link=1; } CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Abort RX operation diff --git a/Multiprotocol/Common.ino b/Multiprotocol/FrSkyDVX_common.ino similarity index 60% rename from Multiprotocol/Common.ino rename to Multiprotocol/FrSkyDVX_common.ino index 14c05af..8f257ed 100644 --- a/Multiprotocol/Common.ino +++ b/Multiprotocol/FrSkyDVX_common.ino @@ -13,169 +13,27 @@ along with Multiprotocol. If not, see . */ -#ifdef ENABLE_PPM -void InitPPM() -{ - for(uint8_t i=0;i1844 - uint16_t db_low=CHANNEL_MID-deadband, db_high=CHANNEL_MID+deadband; // 1024+-deadband - int32_t calc; - uint8_t out; - if(val>=db_low && val<=db_high) - return mid; - else if(valmin) out++; else out--; - } - return out; -} - -// Reverse a channel and store it -void reverse_channel(uint8_t num) -{ - uint16_t val=2048-Channel_data[num]; - if(val>=2048) val=2047; - Channel_data[num]=val; -} -// Channel value is converted to ppm 860<->2140 -125%<->+125% and 988<->2012 -100%<->+100% -uint16_t convert_channel_ppm(uint8_t num) -{ - uint16_t val=Channel_data[num]; - return (((val<<2)+val)>>3)+860; //value range 860<->2140 -125%<->+125% -} -// Channel value 100% is converted to 10bit values 0<->1023 -uint16_t convert_channel_10b(uint8_t num) -{ - uint16_t val=Channel_data[num]; - val=((val<<2)+val)>>3; - if(val<=128) return 0; - if(val>=1152) return 1023; - return val-128; -} -// Channel value 100% is converted to 8bit values 0<->255 -uint8_t convert_channel_8b(uint8_t num) -{ - uint16_t val=Channel_data[num]; - val=((val<<2)+val)>>5; - if(val<=32) return 0; - if(val>=288) return 255; - return val-32; -} - -// Channel value 100% is converted to value scaled -int16_t convert_channel_16b_limit(uint8_t num,int16_t min,int16_t max) -{ - int32_t val=limit_channel_100(num); // 204<->1844 - val=(val-CHANNEL_MIN_100)*(max-min)/(CHANNEL_MAX_100-CHANNEL_MIN_100)+min; - return (uint16_t)val; -} - -// Channel value -125%<->125% is scaled to 16bit value with no limit -int16_t convert_channel_16b_nolimit(uint8_t num, int16_t min, int16_t max) -{ - int32_t val=Channel_data[num]; // 0<->2047 - val=(val-CHANNEL_MIN_100)*(max-min)/(CHANNEL_MAX_100-CHANNEL_MIN_100)+min; - return (uint16_t)val; -} - -// Channel value is converted sign + magnitude 8bit values -uint8_t convert_channel_s8b(uint8_t num) -{ - uint8_t ch; - ch = convert_channel_8b(num); - return (ch < 128 ? 127-ch : ch); -} - -// Channel value is limited to 100% -uint16_t limit_channel_100(uint8_t num) -{ - if(Channel_data[num]>=CHANNEL_MAX_100) - return CHANNEL_MAX_100; - if (Channel_data[num]<=CHANNEL_MIN_100) - return CHANNEL_MIN_100; - return Channel_data[num]; -} - -// Channel value is converted for HK310 -void convert_channel_HK310(uint8_t num, uint8_t *low, uint8_t *high) -{ - uint16_t temp=0xFFFF-(3440+((Channel_data[num]*5)>>1))/3; - *low=(uint8_t)(temp&0xFF); - *high=(uint8_t)(temp>>8); -} -#ifdef FAILSAFE_ENABLE -// Failsafe value is converted for HK310 -void convert_failsafe_HK310(uint8_t num, uint8_t *low, uint8_t *high) -{ - uint16_t temp=0xFFFF-(3440+((Failsafe_data[num]*5)>>1))/3; - *low=(uint8_t)(temp&0xFF); - *high=(uint8_t)(temp>>8); -} -#endif - -// Channel value for FrSky (PPM is multiplied by 1.5) -uint16_t convert_channel_frsky(uint8_t num) -{ - uint16_t val=Channel_data[num]; - return ((val*15)>>4)+1290; -} - /******************************/ /** FrSky D and X routines **/ /******************************/ #if defined(FRSKYX_CC2500_INO) || defined(FRSKYX_RX_CC2500_INO) //**CRC** -const uint16_t PROGMEM frskyX_CRC_Short[]={ +const uint16_t PROGMEM FrSkyX_CRC_Short[]={ 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7 }; -static uint16_t __attribute__((unused)) frskyX_CRCTable(uint8_t val) +static uint16_t __attribute__((unused)) FrSkyX_CRCTable(uint8_t val) { uint16_t word ; - word = pgm_read_word(&frskyX_CRC_Short[val&0x0F]) ; + word = pgm_read_word(&FrSkyX_CRC_Short[val&0x0F]) ; val /= 16 ; return word ^ (0x1081 * val) ; } -uint16_t frskyX_crc_x(uint8_t *data, uint8_t len) +uint16_t FrSkyX_crc(uint8_t *data, uint8_t len) { uint16_t crc = 0; for(uint8_t i=0; i < len; i++) - crc = (crc<<8) ^ frskyX_CRCTable((uint8_t)(crc>>8) ^ *data++); + crc = (crc<<8) ^ FrSkyX_CRCTable((uint8_t)(crc>>8) ^ *data++); return crc; } #endif diff --git a/Multiprotocol/FrSkyD_cc2500.ino b/Multiprotocol/FrSkyD_cc2500.ino index 9cfabf0..bd82890 100644 --- a/Multiprotocol/FrSkyD_cc2500.ino +++ b/Multiprotocol/FrSkyD_cc2500.ino @@ -159,12 +159,12 @@ uint16_t ReadFrSky_2way() len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; if (len && len<=(0x11+3))// 20bytes { - CC2500_ReadData(pkt, len); //received telemetry packets + CC2500_ReadData(packet_in, len); //received telemetry packets #if defined(TELEMETRY) - if(pkt[len-1] & 0x80) + if(packet_in[len-1] & 0x80) {//with valid crc packet_count=0; - frsky_check_telemetry(pkt,len); //check if valid telemetry packets and buffer them. + frsky_check_telemetry(packet_in,len); //check if valid telemetry packets and buffer them. } #endif } @@ -177,7 +177,7 @@ uint16_t ReadFrSky_2way() packet_count=0; #if defined TELEMETRY telemetry_link=0;//no link frames - pkt[6]=0;//no user frames. + packet_in[6]=0;//no user frames. #endif } } diff --git a/Multiprotocol/FrSkyX_Rx_cc2500.ino b/Multiprotocol/FrSkyX_Rx_cc2500.ino index 4b9ea1a..5bec6c6 100644 --- a/Multiprotocol/FrSkyX_Rx_cc2500.ino +++ b/Multiprotocol/FrSkyX_Rx_cc2500.ino @@ -127,7 +127,7 @@ static void __attribute__((unused)) frskyx_rx_calibrate() static uint8_t __attribute__((unused)) frskyx_rx_check_crc() { uint8_t limit = packet_length - 4; - uint16_t lcrc = frskyX_crc_x(&packet[3], limit - 3); // computed crc + uint16_t lcrc = FrSkyX_crc(&packet[3], limit - 3); // computed crc uint16_t rcrc = (packet[limit] << 8) | (packet[limit + 1] & 0xff); // received crc return lcrc == rcrc; } @@ -159,17 +159,17 @@ static void __attribute__((unused)) frskyx_rx_build_telemetry_packet() } // buid telemetry packet - pkt[idx++] = RX_LQI; - pkt[idx++] = RX_RSSI; - pkt[idx++] = 0; // start channel - pkt[idx++] = 16; // number of channels in packet + packet_in[idx++] = RX_LQI; + packet_in[idx++] = RX_RSSI; + packet_in[idx++] = 0; // start channel + packet_in[idx++] = 16; // number of channels in packet // pack channels for (int i = 0; i < 16; i++) { bits |= frskyx_rx_rc_chan[i] << bitsavailable; bitsavailable += 11; while (bitsavailable >= 8) { - pkt[idx++] = bits & 0xff; + packet_in[idx++] = bits & 0xff; bits >>= 8; bitsavailable -= 8; } @@ -351,7 +351,7 @@ uint16_t FrSkyX_Rx_callback() // packets per second if (millis() - pps_timer >= 1000) { pps_timer = millis(); - debugln("%ld pps", pps_counter); + debugln("%d pps", pps_counter); RX_LQI = pps_counter; pps_counter = 0; } diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 7fa5de1..55b7696 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -19,20 +19,20 @@ #include "iface_cc2500.h" -uint8_t FrX_chanskip; -uint8_t FrX_send_seq ; -uint8_t FrX_receive_seq ; +uint8_t FrSkyX_chanskip; +uint8_t FrSkyX_TX_Seq ; +uint8_t FrSkyX_RX_Seq ; -#define FRX_FAILSAFE_TIMEOUT 1032 +#define FrSkyX_FAILSAFE_TIMEOUT 1032 -static void __attribute__((unused)) frskyX_set_start(uint8_t ch ) +static void __attribute__((unused)) FrSkyX_set_start(uint8_t ch ) { CC2500_Strobe(CC2500_SIDLE); CC2500_WriteReg(CC2500_25_FSCAL1, calData[ch]); CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[ch]); } -static void __attribute__((unused)) frskyX_init() +static void __attribute__((unused)) FrSkyX_init() { FRSKY_init_cc2500((sub_protocol&2)?FRSKYXEU_cc2500_conf:FRSKYX_cc2500_conf); // LBT or FCC // @@ -47,7 +47,7 @@ static void __attribute__((unused)) frskyX_init() //#######END INIT######## } -static void __attribute__((unused)) frskyX_initialize_data(uint8_t adr) +static void __attribute__((unused)) FrSkyX_initialize_data(uint8_t adr) { CC2500_WriteReg(CC2500_0C_FSCTRL0,option); // Frequency offset hack CC2500_WriteReg(CC2500_18_MCSM0, 0x8); @@ -55,7 +55,7 @@ static void __attribute__((unused)) frskyX_initialize_data(uint8_t adr) CC2500_WriteReg(CC2500_07_PKTCTRL1,0x05); } -static void __attribute__((unused)) frskyX_build_bind_packet() +static void __attribute__((unused)) FrSkyX_build_bind_packet() { packet[0] = (sub_protocol & 2 ) ? 0x20 : 0x1D ; // LBT or FCC packet[1] = 0x03; @@ -75,7 +75,7 @@ static void __attribute__((unused)) frskyX_build_bind_packet() // uint8_t limit = (sub_protocol & 2 ) ? 31 : 28 ; memset(&packet[13], 0, limit - 13); - uint16_t lcrc = frskyX_crc_x(&packet[3], limit-3); + uint16_t lcrc = FrSkyX_crc(&packet[3], limit-3); // packet[limit++] = lcrc >> 8; packet[limit] = lcrc; @@ -84,14 +84,14 @@ static void __attribute__((unused)) frskyX_build_bind_packet() // 0-2047, 0 = 817, 1024 = 1500, 2047 = 2182 //64=860,1024=1500,1984=2140//Taranis 125% -static uint16_t __attribute__((unused)) frskyX_scaleForPXX( uint8_t i ) +static uint16_t __attribute__((unused)) FrSkyX_scaleForPXX( uint8_t i ) { //mapped 860,2140(125%) range to 64,1984(PXX values); uint16_t chan_val=convert_channel_frsky(i)-1226; if(i>7) chan_val|=2048; // upper channels offset return chan_val; } #ifdef FAILSAFE_ENABLE -static uint16_t __attribute__((unused)) frskyX_scaleForPXX_FS( uint8_t i ) +static uint16_t __attribute__((unused)) FrSkyX_scaleForPXX_FS( uint8_t i ) { //mapped 1,2046(125%) range to 64,1984(PXX values); uint16_t chan_val=((Failsafe_data[i]*15)>>4)+64; if(Failsafe_data[i]==FAILSAFE_CHANNEL_NOPULSES) @@ -103,8 +103,8 @@ static uint16_t __attribute__((unused)) frskyX_scaleForPXX_FS( uint8_t i ) } #endif -#define FRX_FAILSAFE_TIME 1032 -static void __attribute__((unused)) frskyX_data_frame() +#define FrSkyX_FAILSAFE_TIME 1032 +static void __attribute__((unused)) FrSkyX_build_packet() { //0x1D 0xB3 0xFD 0x02 0x56 0x07 0x15 0x00 0x00 0x00 0x04 0x40 0x00 0x04 0x40 0x00 0x04 0x40 0x00 0x04 0x40 0x08 0x00 0x00 0x00 0x00 0x00 0x00 0x96 0x12 // @@ -116,7 +116,7 @@ static void __attribute__((unused)) frskyX_data_frame() #ifdef FAILSAFE_ENABLE static uint16_t failsafe_count=0; static uint8_t FS_flag=0,failsafe_chan=0; - if (FS_flag == 0 && failsafe_count > FRX_FAILSAFE_TIME && chan_offset == 0 && IS_FAILSAFE_VALUES_on) + if (FS_flag == 0 && failsafe_count > FrSkyX_FAILSAFE_TIME && chan_offset == 0 && IS_FAILSAFE_VALUES_on) { FS_flag = 0x10; failsafe_chan = 0; @@ -137,8 +137,8 @@ static void __attribute__((unused)) frskyX_data_frame() packet[2] = rx_tx_addr[2]; packet[3] = 0x02; // - packet[4] = (FrX_chanskip<<6)|hopping_frequency_no; - packet[5] = FrX_chanskip>>2; + packet[4] = (FrSkyX_chanskip<<6)|hopping_frequency_no; + packet[5] = FrSkyX_chanskip>>2; packet[6] = RX_num; //packet[7] = FLAGS 00 - standard packet //10, 12, 14, 16, 18, 1A, 1C, 1E - failsafe packet @@ -150,35 +150,37 @@ static void __attribute__((unused)) frskyX_data_frame() #endif packet[8] = 0; // - uint8_t startChan = chan_offset; for(uint8_t i = 0; i <12 ; i+=3) + uint8_t startChan = chan_offset; + for(uint8_t i = 0; i <12 ; i+=3) {//12 bytes of channel data #ifdef FAILSAFE_ENABLE if( (FS_flag & 0x10) && ((failsafe_chan & 0x07) == (startChan & 0x07)) ) - chan_0 = frskyX_scaleForPXX_FS(failsafe_chan); + chan_0 = FrSkyX_scaleForPXX_FS(failsafe_chan); else #endif - chan_0 = frskyX_scaleForPXX(startChan); + chan_0 = FrSkyX_scaleForPXX(startChan); startChan++; // #ifdef FAILSAFE_ENABLE if( (FS_flag & 0x10) && ((failsafe_chan & 0x07) == (startChan & 0x07)) ) - chan_1 = frskyX_scaleForPXX_FS(failsafe_chan); + chan_1 = FrSkyX_scaleForPXX_FS(failsafe_chan); else #endif - chan_1 = frskyX_scaleForPXX(startChan); + chan_1 = FrSkyX_scaleForPXX(startChan); startChan++; // packet[9+i] = lowByte(chan_0); //3 bytes*4 packet[9+i+1]=(((chan_0>>8) & 0x0F)|(chan_1 << 4)); packet[9+i+2]=chan_1>>4; } - packet[21] = (FrX_receive_seq << 4) | FrX_send_seq ;//8 at start - if(sub_protocol & 0x01 ) // in X8 mode send only 8ch every 9ms chan_offset = 0 ; else chan_offset^=0x08; + //sequence + packet[21] = (FrSkyX_RX_Seq << 4) | FrSkyX_TX_Seq ;//=8 at startup + uint8_t limit = (sub_protocol & 2 ) ? 31 : 28 ; for (uint8_t i=22;i>8;//high byte packet[limit]=lcrc;//low byte } @@ -217,11 +235,11 @@ uint16_t ReadFrSkyX() switch(state) { default: - frskyX_set_start(47); + FrSkyX_set_start(47); CC2500_SetPower(); CC2500_Strobe(CC2500_SFRX); // - frskyX_build_bind_packet(); + FrSkyX_build_bind_packet(); CC2500_Strobe(CC2500_SIDLE); CC2500_WriteData(packet, packet[0]+1); if(IS_BIND_DONE) @@ -230,7 +248,7 @@ uint16_t ReadFrSkyX() state++; return 9000; case FRSKY_BIND_DONE: - frskyX_initialize_data(0); + FrSkyX_initialize_data(0); hopping_frequency_no=0; BIND_DONE; state++; @@ -242,14 +260,12 @@ uint16_t ReadFrSkyX() prev_option = option ; } CC2500_SetTxRxMode(TX_EN); - frskyX_set_start(hopping_frequency_no); + FrSkyX_set_start(hopping_frequency_no); CC2500_SetPower(); CC2500_Strobe(CC2500_SFRX); - hopping_frequency_no = (hopping_frequency_no+FrX_chanskip)%47; + hopping_frequency_no = (hopping_frequency_no+FrSkyX_chanskip)%47; CC2500_Strobe(CC2500_SIDLE); CC2500_WriteData(packet, packet[0]+1); - // -// frskyX_data_frame(); state++; return 5200; case FRSKY_DATA2: @@ -266,9 +282,9 @@ uint16_t ReadFrSkyX() if (len && (len<=(0x0E + 3))) //Telemetry frame is 17 { packet_count=0; - CC2500_ReadData(pkt, len); + CC2500_ReadData(packet_in, len); #if defined TELEMETRY - frsky_check_telemetry(pkt,len); //check if valid telemetry packets + frsky_check_telemetry(packet_in,len); //check if valid telemetry packets //parse telemetry packets here //The same telemetry function used by FrSky(D8). #endif @@ -279,10 +295,8 @@ uint16_t ReadFrSkyX() // restart sequence on missed packet - might need count or timeout instead of one missed if(packet_count>100) {//~1sec -// seq_last_sent = 0; -// seq_last_rcvd = 8; - FrX_send_seq = 0x08 ; -// FrX_receive_seq = 0 ; + FrSkyX_TX_Seq = 0x08 ; + //FrSkyX_RX_Seq = 0 ; packet_count=0; #if defined TELEMETRY telemetry_lost=1; @@ -290,11 +304,9 @@ uint16_t ReadFrSkyX() } CC2500_Strobe(CC2500_SFRX); //flush the RXFIFO } - frskyX_data_frame(); - if ( FrX_send_seq != 0x08 ) - { - FrX_send_seq = ( FrX_send_seq + 1 ) & 0x03 ; - } + FrSkyX_build_packet(); + if ( FrSkyX_TX_Seq != 0x08 ) + FrSkyX_TX_Seq = ( FrSkyX_TX_Seq + 1 ) & 0x03 ; state = FRSKY_DATA1; return 500; } @@ -306,34 +318,33 @@ uint16_t initFrSkyX() set_rx_tx_addr(MProtocol_id_master); Frsky_init_hop(); packet_count=0; - while(!FrX_chanskip) - FrX_chanskip=random(0xfefefefe)%47; + while(!FrSkyX_chanskip) + FrSkyX_chanskip=random(0xfefefefe)%47; //for test*************** //rx_tx_addr[3]=0xB3; //rx_tx_addr[2]=0xFD; //************************ - frskyX_init(); -#if defined SPORT_POLLING -#ifdef INVERT_SERIAL - start_timer4() ; -#endif + FrSkyX_init(); + +#ifdef SPORT_POLLING + #ifdef INVERT_SERIAL + start_timer4() ; + #endif #endif // if(IS_BIND_IN_PROGRESS) { state = FRSKY_BIND; - frskyX_initialize_data(1); + FrSkyX_initialize_data(1); } else { state = FRSKY_DATA1; - frskyX_initialize_data(0); + FrSkyX_initialize_data(0); } -// seq_last_sent = 0; -// seq_last_rcvd = 8; - FrX_send_seq = 0x08 ; - FrX_receive_seq = 0 ; + FrSkyX_TX_Seq = 0x08 ; + FrSkyX_RX_Seq = 0 ; return 10000; } #endif \ No newline at end of file diff --git a/Multiprotocol/Hitec_cc2500.ino b/Multiprotocol/Hitec_cc2500.ino index 760e61d..e31bac0 100644 --- a/Multiprotocol/Hitec_cc2500.ino +++ b/Multiprotocol/Hitec_cc2500.ino @@ -285,14 +285,14 @@ uint16_t ReadHITEC() return HITEC_RX1_TIMING; case HITEC_RX2: uint8_t len=CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; - if(len && len 00 8D=>RX battery voltage 0x008D/28=5.03V @@ -323,40 +323,40 @@ uint16_t ReadHITEC() // 0C,1C,A1,2B,00,16,00,00,00,00,00,16,00,2C,8E // 0C,1C,A1,2B,00,17,00,00,00,42,44,17,00,48,8D -> 42=>temperature3 0x42-0x28=26°C,44=>temperature4 0x44-0x28=28°C // 0C,1C,A1,2B,00,18,00,00,00,00,00,18,00,50,92 - debug(",telem,%02x",pkt[14]&0x7F); + debug(",telem,%02x",packet_in[14]&0x7F); #if defined(HITEC_FW_TELEMETRY) || defined(HITEC_HUB_TELEMETRY) - TX_RSSI = pkt[13]; + TX_RSSI = packet_in[13]; if(TX_RSSI >=128) TX_RSSI -= 128; else TX_RSSI += 128; - TX_LQI = pkt[14]&0x7F; + TX_LQI = packet_in[14]&0x7F; #endif #if defined(HITEC_FW_TELEMETRY) if(sub_protocol==OPT_FW) { // 8 bytes telemetry packets => see at the end of this file how to fully decode it - pkt[0]=TX_RSSI; // TX RSSI - pkt[1]=TX_LQI; // TX LQI - uint8_t offset=pkt[5]==0?1:0; + packet_in[0]=TX_RSSI; // TX RSSI + packet_in[1]=TX_LQI; // TX LQI + uint8_t offset=packet_in[5]==0?1:0; for(uint8_t i=5;i < 11; i++) - pkt[i-3]=pkt[i+offset]; // frame number followed by 5 bytes of data + packet_in[i-3]=packet_in[i+offset]; // frame number followed by 5 bytes of data telemetry_link=2; // telemetry forward available } #endif #if defined(HITEC_HUB_TELEMETRY) if(sub_protocol==OPT_HUB) { - switch(pkt[5]) // telemetry frame number + switch(packet_in[5]) // telemetry frame number { case 0x00: - v_lipo1 = (pkt[10])<<5 | (pkt[11])>>3; // calculation in float is volt=(pkt[10]<<8+pkt[11])/28 + v_lipo1 = (packet_in[10])<<5 | (packet_in[11])>>3; // calculation in float is volt=(packet_in[10]<<8+packet_in[11])/28 break; case 0x11: - v_lipo1 = (pkt[9])<<5 | (pkt[10])>>3; // calculation in float is volt=(pkt[9]<<8+pkt[10])/28 + v_lipo1 = (packet_in[9])<<5 | (packet_in[10])>>3; // calculation in float is volt=(packet_in[9]<<8+packet_in[10])/28 break; case 0x18: - v_lipo2 = (pkt[6])<<5 | (pkt[7])>>3; // calculation in float is volt=(pkt[6]<<8+pkt[7])/10 + v_lipo2 = (packet_in[6])<<5 | (packet_in[7])>>3; // calculation in float is volt=(packet_in[6]<<8+packet_in[7])/10 break; } telemetry_link=1; // telemetry hub available diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 5b7c5a0..3dd633a 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -17,9 +17,9 @@ // Version //****************** #define VERSION_MAJOR 1 -#define VERSION_MINOR 2 -#define VERSION_REVISION 1 -#define VERSION_PATCH_LEVEL 84 +#define VERSION_MINOR 3 +#define VERSION_REVISION 0 +#define VERSION_PATCH_LEVEL 1 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 8315f79..e4575c5 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -166,14 +166,14 @@ uint8_t RX_num; //Serial RX variables #define BAUD 100000 -#define RXBUFFER_SIZE 26 +#define RXBUFFER_SIZE 34 volatile uint8_t rx_buff[RXBUFFER_SIZE]; volatile uint8_t rx_ok_buff[RXBUFFER_SIZE]; volatile uint8_t discard_frame = 0; // Telemetry -#define MAX_PKT 30 -uint8_t pkt[MAX_PKT];//telemetry receiving packets +#define TELEMETRY_BUFFER_SIZE 30 +uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets #if defined(TELEMETRY) #ifdef INVERT_TELEMETRY #if not defined(ORANGE_TX) && not defined(STM32_BOARD) @@ -183,7 +183,7 @@ uint8_t pkt[MAX_PKT];//telemetry receiving packets #define INVERT_SERIAL 1 #endif uint8_t pass = 0; - uint8_t pktt[MAX_PKT];//telemetry receiving packets + uint8_t telemetry_in_buffer[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets #ifdef BASH_SERIAL // For bit-bashed serial output #define TXBUFFER_SIZE 192 @@ -217,6 +217,11 @@ uint8_t pkt[MAX_PKT];//telemetry receiving packets uint8_t sport_idx = 0; uint8_t sport_index = 0; #endif + #ifdef SPORT_SEND + #define MAX_SPORT_BUFFER 64 + uint8_t SportData[MAX_SPORT_BUFFER]; + uint8_t SportHead=0, SportTail=0; + #endif #endif // TELEMETRY // Callback @@ -399,9 +404,15 @@ void setup() #endif // Set default channels' value - InitChannel(); + for(uint8_t i=0;iCCR2=TIMER2_BASE->CNT+(6500L); // Full message should be received within timer of 3250us + TIMER2_BASE->CCR2=TIMER2_BASE->CNT+max_time;// Full message should be received within timer of 3250us TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag TIMER2_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer2/Comp2 interrupt #else - OCR1B = TCNT1+(6500L) ; // Full message should be received within timer of 3250us - TIFR1 = OCF1B_bm ; // clear OCR1B match flag - SET_TIMSK1_OCIE1B ; // enable interrupt on compare B match + OCR1B = TCNT1+max_time; // Full message should be received within timer of 3250us + TIFR1 = OCF1B_bm ; // clear OCR1B match flag + SET_TIMSK1_OCIE1B ; // enable interrupt on compare B match #endif idx++; } @@ -1915,11 +1993,11 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) else { rx_buff[idx++]=UDR0; // Store received byte - if(idx>=RXBUFFER_SIZE) + if(idx>=len) { // A full frame has been received if(!IS_RX_DONOTUPDATE_on) { //Good frame received and main is not working on the buffer - memcpy((void*)rx_ok_buff,(const void*)rx_buff,RXBUFFER_SIZE);// Duplicate the buffer + memcpy((void*)rx_ok_buff,(const void*)rx_buff,len);// Duplicate the buffer RX_FLAG_on; // flag for main to process servo data } else diff --git a/Multiprotocol/Scanner_cc2500.ino b/Multiprotocol/Scanner_cc2500.ino index 6b09b21..3210c80 100644 --- a/Multiprotocol/Scanner_cc2500.ino +++ b/Multiprotocol/Scanner_cc2500.ino @@ -109,7 +109,7 @@ uint16_t Scanner_callback() if (rf_ch_num >= (SCAN_MAX_RADIOCHANNEL + 1)) rf_ch_num = 0; if (scan_tlm_index++ == 0) - pkt[0] = rf_ch_num; // start channel for telemetry packet + packet_in[0] = rf_ch_num; // start channel for telemetry packet Scanner_scan_next(); phase = SCAN_GET_RSSI; } @@ -118,7 +118,7 @@ uint16_t Scanner_callback() rssi = Scanner_scan_rssi(); if(rssi >= max_rssi) { max_rssi = rssi; - pkt[scan_tlm_index] = rssi; + packet_in[scan_tlm_index] = rssi; } max_count++; if(max_count > SCAN_MAX_COUNT) { diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index da0b08c..b338dfe 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -37,17 +37,17 @@ uint8_t RetrySequence ; uint8_t pktx1[FRSKY_SPORT_PACKET_SIZE*FX_BUFFERS]; // Store for out of sequence packet - uint8_t FrskyxRxTelemetryValidSequence ; - struct t_fx_rx_frame + uint8_t FrSkyX_RX_ValidSeq ; + struct t_FrSkyX_RX_Frame { - uint8_t valid ; - uint8_t count ; - uint8_t payload[6] ; + boolean valid; + uint8_t count; + uint8_t payload[6]; } ; // Store for FrskyX telemetry - struct t_fx_rx_frame FrskyxRxFrames[4] ; - uint8_t NextFxFrameToForward ; + struct t_FrSkyX_RX_Frame FrSkyX_RX_Frames[4] ; + uint8_t FrSkyX_RX_NextFrame=0; #ifdef SPORT_POLLING uint8_t sport_rx_index[28] ; uint8_t ukindex ; @@ -146,18 +146,18 @@ static void multi_send_status() #ifdef MULTI_TELEMETRY void DSM_frame() { - if (pkt[0] == 0x80) + if (packet_in[0] == 0x80) { multi_send_header(MULTI_TELEMETRY_DSMBIND, 10); for (uint8_t i = 1; i < 11; i++) // 10 bytes of DSM bind response - Serial_write(pkt[i]); + Serial_write(packet_in[i]); } else { multi_send_header(MULTI_TELEMETRY_DSM, 17); for (uint8_t i = 0; i < 17; i++) // RSSI value followed by 16 bytes of telemetry data - Serial_write(pkt[i]); + Serial_write(packet_in[i]); } } #else @@ -165,7 +165,7 @@ static void multi_send_status() { Serial_write(0xAA); // Telemetry packet for (uint8_t i = 0; i < 17; i++) // RSSI value followed by 16 bytes of telemetry data - Serial_write(pkt[i]); + Serial_write(packet_in[i]); } #endif #endif @@ -178,9 +178,9 @@ static void multi_send_status() #else Serial_write(0xAA); // Telemetry packet #endif - Serial_write(pkt[0]); // start channel + Serial_write(packet_in[0]); // start channel for(uint8_t ch = 0; ch < SCAN_CHANS_PER_PACKET; ch++) - Serial_write(pkt[ch+1]); // RSSI power levels + Serial_write(packet_in[ch+1]); // RSSI power levels } #endif @@ -193,7 +193,7 @@ static void multi_send_status() Serial_write(0xAA); // Telemetry packet #endif for (uint8_t i = 0; i < 26; i++) - Serial_write(pkt[i]); // pps, rssi, ch start, ch count, 16x ch data + Serial_write(packet_in[i]); // pps, rssi, ch start, ch count, 16x ch data } #endif @@ -201,12 +201,12 @@ static void multi_send_status() void AFHDSA_short_frame() { #if defined MULTI_TELEMETRY - multi_send_header(pkt[29]==0xAA?MULTI_TELEMETRY_AFHDS2A:MULTI_TELEMETRY_AFHDS2A_AC, 29); + multi_send_header(packet_in[29]==0xAA?MULTI_TELEMETRY_AFHDS2A:MULTI_TELEMETRY_AFHDS2A_AC, 29); #else - Serial_write(pkt[29]); // Telemetry packet 0xAA or 0xAC + Serial_write(packet_in[29]); // Telemetry packet 0xAA or 0xAC #endif for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data - Serial_write(pkt[i]); + Serial_write(packet_in[i]); } #endif @@ -219,7 +219,7 @@ static void multi_send_status() Serial_write(0xAA); // Telemetry packet #endif for (uint8_t i = 0; i < 8; i++) // TX RSSI and TX LQI values followed by frame number and 5 bytes of telemetry data - Serial_write(pkt[i]); + Serial_write(packet_in[i]); } #endif @@ -247,127 +247,155 @@ void frskySendStuffed() Serial_write(START_STOP); } -void frsky_check_telemetry(uint8_t *pkt,uint8_t len) +void frsky_check_telemetry(uint8_t *packet_in,uint8_t len) { - uint8_t clen = pkt[0] + 3 ; - if(pkt[1] == rx_tx_addr[3] && pkt[2] == rx_tx_addr[2] && len == clen ) + if(packet_in[1] != rx_tx_addr[3] || packet_in[2] != rx_tx_addr[2] || len != packet_in[0] + 3 ) + return; // Bad address or length... + + telemetry_link|=1; // Telemetry data is available + // RSSI and LQI are the 2 last bytes + TX_RSSI = packet_in[len-2]; + if(TX_RSSI >=128) + TX_RSSI -= 128; + else + TX_RSSI += 128; + TX_LQI = packet_in[len-1]&0x7F; + +#if defined FRSKYD_CC2500_INO + if (protocol==PROTO_FRSKYD) { - telemetry_link|=1; // Telemetry data is available - TX_RSSI = pkt[len-2]; - if(TX_RSSI >=128) - TX_RSSI -= 128; - else - TX_RSSI += 128; - TX_LQI = pkt[len-1]&0x7F; + //Save current buffer for (uint8_t i=3;i0 && pktt[6]<=10) - { - if (protocol==PROTO_FRSKYD) - { - if ( ( pktt[7] & 0x1F ) == (telemetry_counter & 0x1F) ) - { - uint8_t topBit = 0 ; - if ( telemetry_counter & 0x80 ) - if ( ( telemetry_counter & 0x1F ) != RetrySequence ) - topBit = 0x80 ; - telemetry_counter = ( (telemetry_counter+1)%32 ) | topBit ; // Request next telemetry frame - } - else - { - // incorrect sequence - RetrySequence = pktt[7] & 0x1F ; - telemetry_counter |= 0x80 ; - pktt[6]=0 ; // Discard current packet and wait for retransmit - } + telemetry_in_buffer[i]=packet_in[i]; // Buffer telemetry values to be sent + + //Check incoming telemetry sequence + if(telemetry_in_buffer[6]>0 && telemetry_in_buffer[6]<=10) + { //Telemetry length ok + if ( ( telemetry_in_buffer[7] & 0x1F ) == (telemetry_counter & 0x1F) ) + {//Sequence is ok + uint8_t topBit = 0 ; + if ( telemetry_counter & 0x80 ) + if ( ( telemetry_counter & 0x1F ) != RetrySequence ) + topBit = 0x80 ; + telemetry_counter = ( (telemetry_counter+1)%32 ) | topBit ; // Request next telemetry frame + } + else + {//Incorrect sequence + RetrySequence = telemetry_in_buffer[7] & 0x1F ; + telemetry_counter |= 0x80 ; + telemetry_in_buffer[6]=0 ; // Discard current packet and wait for retransmit } } else - pktt[6]=0; // Discard packet - // + telemetry_in_buffer[6]=0; // Discard packet + } +#endif + #if defined SPORT_TELEMETRY && defined FRSKYX_CC2500_INO + if (protocol==PROTO_FRSKYX) + { + /*Telemetry frames(RF) SPORT info + 15 bytes payload + SPORT frame valid 6+3 bytes + [00] PKLEN 0E 0E 0E 0E + [01] TXID1 DD DD DD DD + [02] TXID2 6D 6D 6D 6D + [03] CONST 02 02 02 02 + [04] RS/RB 2C D0 2C CE //D0;CE=2*RSSI;....2C = RX battery voltage(5V from Bec) + [05] HD-SK 03 10 21 32 //TX/RX telemetry hand-shake bytes + [06] NO.BT 00 00 06 03 //No.of valid SPORT frame bytes in the frame + [07] STRM1 00 00 7E 00 + [08] STRM2 00 00 1A 00 + [09] STRM3 00 00 10 00 + [10] STRM4 03 03 03 03 + [11] STRM5 F1 F1 F1 F1 + [12] STRM6 D1 D1 D0 D0 + [13] CHKSUM1 --|2 CRC bytes sent by RX (calculated on RX side crc16/table) + [14] CHKSUM2 --|*/ telemetry_lost=0; - if (protocol==PROTO_FRSKYX) - { - uint16_t lcrc = frskyX_crc_x(&pkt[3], len-7 ) ; - if ( ( (lcrc >> 8) == pkt[len-4]) && ( (lcrc & 0x00FF ) == pkt[len-3]) ) - { - // Check if in sequence - if ( (pkt[5] & 0x0F) == 0x08 ) - { - FrX_receive_seq = 0x08 ; - NextFxFrameToForward = 0 ; - FrskyxRxFrames[0].valid = 0 ; - FrskyxRxFrames[1].valid = 0 ; - FrskyxRxFrames[2].valid = 0 ; - FrskyxRxFrames[3].valid = 0 ; - } - else if ( (pkt[5] & 0x03) == (FrX_receive_seq & 0x03 ) ) - { - // OK to process - struct t_fx_rx_frame *p ; - uint8_t count ; - p = &FrskyxRxFrames[FrX_receive_seq & 3] ; - count = pkt[6] ; - if ( count <= 6 ) - { - p->count = count ; - for ( uint8_t i = 0 ; i < count ; i += 1 ) - p->payload[i] = pkt[i+7] ; - } - else - p->count = 0 ; - p->valid = 1 ; + uint16_t lcrc = FrSkyX_crc(&packet_in[3], len-7 ) ; + if ( ( (lcrc >> 8) != packet_in[len-4]) || ( (lcrc & 0x00FF ) != packet_in[len-3]) ) + return; // Bad CRC - FrX_receive_seq = ( FrX_receive_seq + 1 ) & 0x03 ; + if(packet_in[4] & 0x80) + RX_RSSI=packet_in[4] & 0x7F ; + else + RxBt = (packet_in[4]<<1) + 1 ; - if ( FrskyxRxTelemetryValidSequence & 0x80 ) - { - FrX_receive_seq = ( FrskyxRxTelemetryValidSequence + 1 ) & 3 ; - FrskyxRxTelemetryValidSequence &= 0x7F ; - } + //Check incoming telemetry sequence + uint8_t packet_seq=packet_in[5] & 0x03; + if ( (packet_in[5] & 0x0F) == 0x08 ) + {//Request init + FrSkyX_RX_Seq = 0x08 ; + FrSkyX_RX_NextFrame = 0x00 ; + FrSkyX_RX_Frames[0].valid = false ; + FrSkyX_RX_Frames[1].valid = false ; + FrSkyX_RX_Frames[2].valid = false ; + FrSkyX_RX_Frames[3].valid = false ; + } + else if ( packet_seq == (FrSkyX_RX_Seq & 0x03 ) ) + {//In sequence + struct t_FrSkyX_RX_Frame *p ; + uint8_t count ; + // packet_in[4] RSSI + // packet_in[5] sequence control + // packet_in[6] payload count + // packet_in[7-12] payload + p = &FrSkyX_RX_Frames[packet_seq] ; + count = packet_in[6]; // Payload length + if ( count <= 6 ) + {//Store payload + p->count = count ; + for ( uint8_t i = 0 ; i < count ; i++ ) + p->payload[i] = packet_in[i+7] ; + } + else + p->count = 0 ; // Discard + p->valid = true ; + FrSkyX_RX_Seq = ( FrSkyX_RX_Seq + 1 ) & 0x03 ; // Move to next sequence + + if ( FrSkyX_RX_ValidSeq & 0x80 ) + { + FrSkyX_RX_Seq = ( FrSkyX_RX_ValidSeq + 1 ) & 3 ; + FrSkyX_RX_ValidSeq &= 0x7F ; + } + + } + else + {//Not in sequence + struct t_FrSkyX_RX_Frame *q ; + uint8_t count ; + // packet_in[4] RSSI + // packet_in[5] sequence control + // packet_in[6] payload count + // packet_in[7-12] payload + if ( packet_seq == ( ( FrSkyX_RX_Seq +1 ) & 3 ) ) + {//Received next sequence -> save it + q = &FrSkyX_RX_Frames[packet_seq] ; + count = packet_in[6]; // Payload length + if ( count <= 6 ) + {//Store payload + q->count = count ; + for ( uint8_t i = 0 ; i < count ; i++ ) + q->payload[i] = packet_in[i+7] ; } else - { - // Save and request correct packet - struct t_fx_rx_frame *q ; - uint8_t count ; - // pkt[4] RSSI - // pkt[5] sequence control - // pkt[6] payload count - // pkt[7-12] payload - pktt[6] = 0 ; // Don't process - if ( (pkt[5] & 0x03) == ( ( FrX_receive_seq +1 ) & 3 ) ) - { - q = &FrskyxRxFrames[(pkt[5] & 0x03)] ; - count = pkt[6] ; - if ( count <= 6 ) - { - q->count = count ; - for ( uint8_t i = 0 ; i < count ; i += 1 ) - { - q->payload[i] = pkt[i+7] ; - } - } - else - q->count = 0 ; - q->valid = 1 ; - - FrskyxRxTelemetryValidSequence = 0x80 | ( pkt[5] & 0x03 ) ; - } - - FrX_receive_seq = ( FrX_receive_seq & 0x03 ) | 0x04 ; // Request re-transmission - } - - if (((pktt[5] >> 4) & 0x0f) == 0x08) - FrX_send_seq = 0 ; + q->count = 0 ; + q->valid = true ; + + FrSkyX_RX_ValidSeq = 0x80 | packet_seq ; } + FrSkyX_RX_Seq = ( FrSkyX_RX_Seq & 0x03 ) | 0x04 ; // Request re-transmission of original sequence } -#endif + + //Check outgoing telemetry sequence + if (((packet_in[5] >> 4) & 0x08) == 0x08) + FrSkyX_TX_Seq = 0 ; //Request init + //debugln("s:%02X,p:%02X",FrSkyX_TX_Seq,packet_in[5] >> 4); } +#endif } void init_frskyd_link_telemetry() @@ -387,9 +415,9 @@ void frsky_link_frame() frame[0] = 0xFE; // Link frame if (protocol==PROTO_FRSKYD) { - frame[1] = pktt[3]; // A1 - frame[2] = pktt[4]; // A2 - frame[3] = pktt[5]; // RX_RSSI + frame[1] = telemetry_in_buffer[3]; // A1 + frame[2] = telemetry_in_buffer[4]; // A2 + frame[3] = telemetry_in_buffer[5]; // RX_RSSI telemetry_link &= ~1 ; // Sent telemetry_link |= 2 ; // Send hub if available } @@ -415,26 +443,26 @@ void frsky_link_frame() #if defined HUB_TELEMETRY void frsky_user_frame() { - if(pktt[6]) + if(telemetry_in_buffer[6]) {//only send valid hub frames frame[0] = 0xFD; // user frame - if(pktt[6]>USER_MAX_BYTES) + if(telemetry_in_buffer[6]>USER_MAX_BYTES) { frame[1]=USER_MAX_BYTES; // packet size - pktt[6]-=USER_MAX_BYTES; + telemetry_in_buffer[6]-=USER_MAX_BYTES; telemetry_link |= 2 ; // 2 packets need to be sent } else { - frame[1]=pktt[6]; // packet size + frame[1]=telemetry_in_buffer[6]; // packet size telemetry_link=0; // only 1 packet or processing second packet } - frame[2] = pktt[7]; + frame[2] = telemetry_in_buffer[7]; for(uint8_t i=0;iCR1 &= ~USART_CR1_TE ; - TX_INV_on; //activate inverter for both serial TX and RX signals - USART3_BASE->CR1 |= USART_CR1_TE ; - #endif - #endif multi_send_header(MULTI_TELEMETRY_SPORT, 9); uint16_t crc_s = 0; uint8_t x = p[0] ; if ( x <= 0x1B ) x = pgm_read_byte_near( &Indices[x] ) ; Serial_write(x) ; - for (uint8_t i = 1; i < 9; i++) + for (uint8_t i = 1; i < 8; i++) { - if (i == 8) - p[i] = 0xff - crc_s; - Serial_write(p[i]); - - if (i>0) - { - crc_s += p[i]; //0-1FF - crc_s += crc_s >> 8; //0-100 - crc_s &= 0x00ff; - } + Serial_write(p[i]); + crc_s += p[i]; //0-1FF + crc_s += crc_s >> 8; //0-100 + crc_s &= 0x00ff; } + Serial_write(0xff - crc_s); } #else void sportSend(uint8_t *p) { uint16_t crc_s = 0; - #ifdef SPORT_POLLING - #ifdef INVERT_SERIAL - USART3_BASE->CR1 &= ~USART_CR1_TE ; - TX_INV_on; //activate inverter for both serial TX and RX signals - USART3_BASE->CR1 |= USART_CR1_TE ; - #endif - #endif + #if defined SPORT_POLLING && defined INVERT_SERIAL + USART3_BASE->CR1 &= ~USART_CR1_TE ; + TX_INV_on; //activate inverter for both serial TX and RX signals + USART3_BASE->CR1 |= USART_CR1_TE ; + #endif Serial_write(START_STOP);//+9 Serial_write(p[0]) ; for (uint8_t i = 1; i < 9; i++) @@ -574,15 +588,11 @@ const uint8_t PROGMEM Indices[] = { 0x00, 0xA1, 0x22, 0x83, 0xE4, 0x45, else Serial_write(p[i]); - if (i>0) - { - crc_s += p[i]; //0-1FF - crc_s += crc_s >> 8; //0-100 - crc_s &= 0x00ff; - } + crc_s += p[i]; //0-1FF + crc_s += crc_s >> 8; //0-100 + crc_s &= 0x00ff; } - } - + } #endif #if defined SPORT_POLLING @@ -668,7 +678,6 @@ void __irq_timer4(void) TIMER4_BASE->CR1 = 0 ; TX_INV_on; //activate inverter for both serial TX and RX signals } - #endif void pollSport() @@ -896,7 +905,7 @@ void proces_sport_data(uint8_t data) { uint8_t dest = sport * FRSKY_SPORT_PACKET_SIZE ; uint8_t i ; - for ( i = 0 ; i < FRSKY_SPORT_PACKET_SIZE ; i += 1 ) + for ( i = 0 ; i < FRSKY_SPORT_PACKET_SIZE ; i++ ) pktx1[dest++] = pktx[i] ; // Triple buffer sport += 1 ;//ok to send } @@ -956,33 +965,24 @@ void TelemetryUpdate() if (protocol==PROTO_FRSKYX) { // FrSkyX for(;;) - { - struct t_fx_rx_frame *p ; + { //Empty buffer + struct t_FrSkyX_RX_Frame *p ; uint8_t count ; - p = &FrskyxRxFrames[NextFxFrameToForward] ; + p = &FrSkyX_RX_Frames[FrSkyX_RX_NextFrame] ; if ( p->valid ) { count = p->count ; for (uint8_t i=0; i < count ; i++) proces_sport_data(p->payload[i]) ; - p->valid = 0 ; // Sent on - NextFxFrameToForward = ( NextFxFrameToForward + 1 ) & 3 ; + p->valid = false ; // Sent + FrSkyX_RX_NextFrame = ( FrSkyX_RX_NextFrame + 1 ) & 3 ; } else - { break ; - } } - - if(telemetry_link) - { - if(pktt[4] & 0x80) - RX_RSSI=pktt[4] & 0x7F ; - else - RxBt = (pktt[4]<<1) + 1 ; - telemetry_link=0; - } - uint32_t now = micros(); + telemetry_link=0; + sportSendFrame(); +/* uint32_t now = micros(); if ((now - last) > SPORT_TIME) { #if defined SPORT_POLLING @@ -994,7 +994,7 @@ void TelemetryUpdate() #else last += SPORT_TIME ; #endif - } + }*/ } #endif // SPORT_TELEMETRY diff --git a/Multiprotocol/WFLY_cyrf6936.ino b/Multiprotocol/WFLY_cyrf6936.ino index baacbcd..c7664da 100644 --- a/Multiprotocol/WFLY_cyrf6936.ino +++ b/Multiprotocol/WFLY_cyrf6936.ino @@ -194,25 +194,25 @@ uint16_t ReadWFLY() debugln("L=%02X",len) if(len==0x10) { - CYRF_ReadDataPacketLen(pkt, len); + CYRF_ReadDataPacketLen(packet_in, len); debug("RX="); for(uint8_t i=0;i<0x0F;i++) { - debug(" %02X",pkt[i]); - if(pkt[i]==packet[i]) + debug(" %02X",packet_in[i]); + if(packet_in[i]==packet[i]) check++; // Verify quickly the content - sum+=pkt[i]; + sum+=packet_in[i]; } - debugln(" %02X",pkt[15]); - if(sum==pkt[15] && check>=10) + debugln(" %02X",packet_in[15]); + if(sum==packet_in[15] && check>=10) { // Good packet received - if(pkt[2]==0x64) + if(packet_in[2]==0x64) { // Switch to normal mode BIND_DONE; phase=WFLY_PREP_DATA; return 10000; } - memcpy((void *)packet,(void *)pkt,0x10); // Send back to the RX what we've just received with no modifications + memcpy((void *)packet,(void *)packet_in,0x10); // Send back to the RX what we've just received with no modifications } phase=WFLY_BIND_TX; return 200; From c2404d4f0da5e20c6483e53fd5a9252973492bc9 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 30 Sep 2019 20:53:10 +0200 Subject: [PATCH 02/65] Code cleanup --- Multiprotocol/FrSkyX_cc2500.ino | 27 --- Multiprotocol/Multiprotocol.h | 7 +- Multiprotocol/Multiprotocol.ino | 19 +-- Multiprotocol/Telemetry.ino | 280 +------------------------------- Multiprotocol/Validate.h | 16 +- Multiprotocol/_Config.h | 6 +- 6 files changed, 22 insertions(+), 333 deletions(-) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 55b7696..2092c38 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -184,27 +184,6 @@ static void __attribute__((unused)) FrSkyX_build_packet() uint8_t limit = (sub_protocol & 2 ) ? 31 : 28 ; for (uint8_t i=22;i Reserved 0 Flysky 1 Hubsan 2 diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index e4575c5..bf54b5b 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -55,11 +55,7 @@ #include #include HardwareTimer HWTimer2(2); -#if defined SPORT_POLLING -#ifdef INVERT_TELEMETRY - HardwareTimer HWTimer4(4); -#endif -#endif + void PPM_decode(); void ISR_COMPB(); extern "C" @@ -210,13 +206,6 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets uint8_t telemetry_link=0; uint8_t telemetry_counter=0; uint8_t telemetry_lost; - #ifdef SPORT_POLLING - #define MAX_SPORT_BUFFER 64 - uint8_t SportData[MAX_SPORT_BUFFER]; - bool ok_to_send = false; - uint8_t sport_idx = 0; - uint8_t sport_index = 0; - #endif #ifdef SPORT_SEND #define MAX_SPORT_BUFFER 64 uint8_t SportData[MAX_SPORT_BUFFER]; @@ -902,9 +891,7 @@ inline void tx_resume() { #ifdef TELEMETRY // Resume telemetry by enabling transmitter interrupt - #ifndef SPORT_POLLING if(!IS_TX_PAUSE_on) - #endif { #ifdef ORANGE_TX cli() ; @@ -1664,9 +1651,7 @@ void modules_reset() USART2_BASE->CR1 |= USART_CR1_PCE_BIT; } usart3_begin(100000,SERIAL_8E2); - #ifndef SPORT_POLLING - USART3_BASE->CR1 &= ~ USART_CR1_RE; //disable receive - #endif + USART3_BASE->CR1 &= ~ USART_CR1_RE; //disable receive USART2_BASE->CR1 &= ~ USART_CR1_TE; //disable transmit #else //ATMEGA328p diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index b338dfe..197e84e 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -48,18 +48,6 @@ uint8_t RetrySequence ; // Store for FrskyX telemetry struct t_FrSkyX_RX_Frame FrSkyX_RX_Frames[4] ; uint8_t FrSkyX_RX_NextFrame=0; - #ifdef SPORT_POLLING - uint8_t sport_rx_index[28] ; - uint8_t ukindex ; - uint8_t kindex ; - uint8_t TxData[2]; - uint8_t SportIndexPolling; - uint8_t RxData[16] ; - volatile uint8_t RxIndex=0 ; - uint8_t sport_bytes=0; - uint8_t skipped_id; - uint8_t rx_counter=0; - #endif #endif // SPORT_TELEMETRY #if defined HUB_TELEMETRY @@ -90,14 +78,6 @@ static void multi_send_header(uint8_t type, uint8_t len) static void multi_send_status() { - #ifdef SPORT_POLLING - #ifdef INVERT_SERIAL - USART3_BASE->CR1 &= ~USART_CR1_TE ; - TX_INV_on; //activate inverter for both serial TX and RX signals - USART3_BASE->CR1 |= USART_CR1_TE ; - #endif - rx_pause(); - #endif multi_send_header(MULTI_TELEMETRY_STATUS, 5); // Build flags @@ -538,7 +518,7 @@ packet_in[6]|(counter++)|00 01 02 03 04 05 06 07 08 09 0x34 0x0A 0xC3 0x56 0xF3 */ -#if defined SPORT_POLLING || defined MULTI_TELEMETRY +#if defined MULTI_TELEMETRY const uint8_t PROGMEM Indices[] = { 0x00, 0xA1, 0x22, 0x83, 0xE4, 0x45, 0xC6, 0x67, 0x48, 0xE9, 0x6A, 0xCB, 0xAC, 0x0D, 0x8E, 0x2F, 0xD0, 0x71, @@ -568,11 +548,6 @@ const uint8_t PROGMEM Indices[] = { 0x00, 0xA1, 0x22, 0x83, 0xE4, 0x45, void sportSend(uint8_t *p) { uint16_t crc_s = 0; - #if defined SPORT_POLLING && defined INVERT_SERIAL - USART3_BASE->CR1 &= ~USART_CR1_TE ; - TX_INV_on; //activate inverter for both serial TX and RX signals - USART3_BASE->CR1 |= USART_CR1_TE ; - #endif Serial_write(START_STOP);//+9 Serial_write(p[0]) ; for (uint8_t i = 1; i < 9; i++) @@ -595,198 +570,6 @@ const uint8_t PROGMEM Indices[] = { 0x00, 0xA1, 0x22, 0x83, 0xE4, 0x45, } #endif -#if defined SPORT_POLLING -uint8_t nextID() -{ - uint8_t i ; - uint8_t poll_idx ; - if (phase) - { - poll_idx = 99 ; - for ( i = 0 ; i < 28 ; i++ ) - { - if ( sport_rx_index[kindex] ) - { - poll_idx = kindex ; - } - kindex++ ; - if ( kindex>= 28 ) - { - kindex = 0 ; - phase = 0 ; - break ; - } - if ( poll_idx != 99 ) - { - break ; - } - } - if ( poll_idx != 99 ) - { - return poll_idx ; - } - } - if ( phase == 0 ) - { - for ( i = 0 ; i < 28 ; i++ ) - { - if ( sport_rx_index[ukindex] == 0 ) - { - poll_idx = ukindex ; - phase = 1 ; - } - ukindex++; - if (ukindex >= 28 ) - { - ukindex = 0 ; - } - if ( poll_idx != 99 ) - { - return poll_idx ; - } - } - if ( poll_idx == 99 ) - { - phase = 1 ; - return 0 ; - } - } - return poll_idx ; -} - -#ifdef INVERT_SERIAL -void start_timer4() -{ - TIMER4_BASE->PSC = 71; // 72-1;for 72 MHZ / 1.0sec/(71+1) - TIMER4_BASE->CCER = 0 ; - TIMER4_BASE->DIER = 0 ; - TIMER4_BASE->CCMR1 = 0 ; - TIMER4_BASE->CCMR1 = TIMER_CCMR1_OC1M ; - HWTimer4.attachInterrupt(TIMER_CH1, __irq_timer4); // Assign function to Timer2/Comp2 interrupt - nvic_irq_set_priority( NVIC_TIMER4, 14 ) ; -} - -void stop_timer4() -{ - TIMER5_BASE->CR1 = 0 ; - nvic_irq_disable( NVIC_TIMER4 ) ; -} - -void __irq_timer4(void) -{ - TIMER4_BASE->DIER = 0 ; - TIMER4_BASE->CR1 = 0 ; - TX_INV_on; //activate inverter for both serial TX and RX signals -} -#endif - -void pollSport() -{ - uint8_t pindex = nextID() ; - TxData[0] = START_STOP; - TxData[1] = pgm_read_byte_near(&Indices[pindex]) ; - if(!telemetry_lost && ((TxData[1] &0x1F)== skipped_id ||TxData[1]==0x98)) - {//98 ID(RSSI/RxBat and SWR ) and ID's from sport telemetry - pindex = nextID() ; - TxData[1] = pgm_read_byte_near(&Indices[pindex]); - } - SportIndexPolling = pindex ; - RxIndex = 0; - #ifdef INVERT_SERIAL - USART3_BASE->CR1 &= ~USART_CR1_TE ; - TX_INV_on; //activate inverter for both serial TX and RX signals - USART3_BASE->CR1 |= USART_CR1_TE ; - #endif -#ifdef MULTI_TELEMETRY - multi_send_header(MULTI_TELEMETRY_SPORT_POLLING, 1); -#else - Serial_write(TxData[0]); -#endif - RxIndex=0; - Serial_write(TxData[1]); - USART3_BASE->CR1 |= USART_CR1_TCIE ; -#ifdef INVERT_SERIAL - TIMER4_BASE->CNT = 0 ; - TIMER4_BASE->CCR1 = 3000 ; - TIMER4_BASE->DIER = TIMER_DIER_CC1IE ; - TIMER4_BASE->CR1 = TIMER_CR1_CEN ; -#endif -} - -bool checkSportPacket() -{ - uint8_t *packet = RxData ; - uint16_t crc = 0 ; - if ( RxIndex < 8 ) - return 0 ; - for ( uint8_t i = 0 ; i<8 ; i += 1 ) - { - crc += packet[i]; - crc += crc >> 8; - crc &= 0x00ff; - } - return (crc == 0x00ff) ; -} - -uint8_t unstuff() -{ - uint8_t i ; - uint8_t j ; - j = 0 ; - for ( i = 0 ; i < RxIndex ; i += 1 ) - { - if ( RxData[i] == BYTESTUFF ) - { - i += 1 ; - RxData[j] = RxData[i] ^ STUFF_MASK ; ; - } - else - RxData[j] = RxData[i] ; - j += 1 ; - } - return j ; -} - -void processSportData(uint8_t *p) -{ - - RxIndex = unstuff() ; - uint8_t x=checkSportPacket() ; - if (x) - { - SportData[sport_idx]=0x7E; - sport_idx =(sport_idx+1) & (MAX_SPORT_BUFFER-1); - SportData[sport_idx]=TxData[1]&0x1F; - sport_idx =(sport_idx+1) & (MAX_SPORT_BUFFER-1); - - for(uint8_t i=0;i<(RxIndex-1);i++) - {//no crc - if(p[i]==START_STOP || p[i]==BYTESTUFF) - {//stuff back - SportData[sport_idx]=BYTESTUFF; - sport_idx =(sport_idx+1) & (MAX_SPORT_BUFFER-1); - SportData[sport_idx]=p[i]^STUFF_MASK; - } - else - SportData[sport_idx]=p[i]; - sport_idx =(sport_idx+1) & (MAX_SPORT_BUFFER-1); - } - sport_rx_index[SportIndexPolling] = 1 ; - ok_to_send=true; - RxIndex =0 ; - } -} - -inline void rx_pause() -{ - USART3_BASE->CR1 &= ~ USART_CR1_RXNEIE; //disable rx interrupt on USART3 -} -inline void rx_resume() -{ - USART3_BASE->CR1 |= USART_CR1_RXNEIE; //enable rx interrupt on USART3 -} -#endif//end SPORT_POLLING - void sportIdle() { #if !defined MULTI_TELEMETRY @@ -796,18 +579,11 @@ void sportIdle() void sportSendFrame() { - #if defined SPORT_POLLING - rx_pause(); - #endif uint8_t i; sport_counter = (sport_counter + 1) %36; if(telemetry_lost) { - #ifdef SPORT_POLLING - pollSport(); - #else - sportIdle(); - #endif + sportIdle(); return; } if(sport_counter<6) @@ -843,26 +619,19 @@ void sportSendFrame() if(sport) { for (i=0;i SPORT_TIME) - { - #if defined SPORT_POLLING - processSportData(RxData); //process arrived data before polling - #endif - sportSendFrame(); - #ifdef STM32_BOARD - last=now; - #else - last += SPORT_TIME ; - #endif - }*/ } #endif // SPORT_TELEMETRY @@ -1163,27 +919,6 @@ void TelemetryUpdate() #endif { // Transmit interrupt #ifdef STM32_BOARD - #ifdef SPORT_POLLING - if(USART3_BASE->SR & USART_SR_TC) - { - if ( USART3_BASE->CR1 & USART_CR1_TCIE ) - { - USART3_BASE->CR1 &= ~USART_CR1_TCIE ; - TX_INV_off; - } - } - - if(USART3_BASE->SR & USART_SR_RXNE) - { - USART3_BASE->SR &= ~USART_SR_RXNE; - if (RxIndex < 16 ) - { - if(RxData[0]==TxData[0] && RxData[1]==TxData[1]) - RxIndex=0; - RxData[RxIndex++] = USART3_BASE->DR & 0xFF ; - } - } - #endif if(USART3_BASE->SR & USART_SR_TXE) { #endif @@ -1200,9 +935,6 @@ void TelemetryUpdate() if (tx_tail == tx_head) { tx_pause(); // Check if all data is transmitted . if yes disable transmitter UDRE interrupt - #ifdef SPORT_POLLING - rx_resume(); - #endif } #ifdef STM32_BOARD } diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index 4479c9b..9386c93 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -246,7 +246,7 @@ #undef NCC1701_HUB_TELEMETRY #undef HUB_TELEMETRY #undef SPORT_TELEMETRY - #undef SPORT_POLLING + #undef SPORT_SEND #undef DSM_TELEMETRY #undef MULTI_STATUS #undef MULTI_TELEMETRY @@ -294,13 +294,10 @@ #endif #if not defined(FRSKYX_CC2500_INO) #undef SPORT_TELEMETRY - #undef SPORT_POLLING + #undef SPORT_SEND #endif - #if not defined (SPORT_TELEMETRY) || not defined (STM32_BOARD) - #undef SPORT_POLLING - #endif - #if defined SPORT_POLLING && not defined INVERT_TELEMETRY - #error SPORT_POLLING has been defined but not INVERT_TELEMETRY. They should be both enabled to work. + #if not defined (SPORT_TELEMETRY) + #undef SPORT_SEND #endif #if not defined(DSM_CYRF6936_INO) #undef DSM_TELEMETRY @@ -308,10 +305,13 @@ #if not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKYX_RX_TELEMETRY) #undef TELEMETRY #undef INVERT_TELEMETRY - #undef SPORT_POLLING #endif #endif +#ifdef SPORT_SEND + #define SERIAL_DATA_ENABLE +#endif + //Make sure TX is defined correctly #ifndef AILERON #error You must select a correct channel order. diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 6f71e8c..cb598de 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -287,11 +287,9 @@ #define SCANNER_TELEMETRY // Forward spectrum scanner data to TX #define FRSKYX_RX_TELEMETRY // Forward channels data to TX -//SPORT_POLLING is an implementation of the same polling routine as XJT module for sport telemetry bidirectional communication. -//This is useful for passing sport control frames from TX to RX(ex: changing Betaflight PID or VTX channels on the fly using LUA scripts with OpentX). -//Using this feature requires to uncomment INVERT_TELEMETRY as this TX output on telemetry pin only inverted signal. +//SPORT_SEND: passing sport control frames from TX to RX(ex: SxR configuration, changing Betaflight PID or VTX channels on the fly using LUA scripts with OpentX). //!!!! This is a work in progress!!! Do not enable unless you want to test and report -//#define SPORT_POLLING +//#define SPORT_SEND /****************************/ From 11f0e55bb18a61ab8cc482faa75f01fe99a69797 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Wed, 2 Oct 2019 20:09:18 +0200 Subject: [PATCH 03/65] SPort_Send sequencer --- Multiprotocol/Binary_Signature.ino | 181 +++++++++++++++++++++++++++++ Multiprotocol/FrSkyX_cc2500.ino | 103 ++++++++++++---- Multiprotocol/Multiprotocol.h | 8 +- Multiprotocol/Multiprotocol.ino | 95 +++++++-------- Multiprotocol/Telemetry.ino | 11 +- 5 files changed, 312 insertions(+), 86 deletions(-) create mode 100644 Multiprotocol/Binary_Signature.ino diff --git a/Multiprotocol/Binary_Signature.ino b/Multiprotocol/Binary_Signature.ino new file mode 100644 index 0000000..af2f343 --- /dev/null +++ b/Multiprotocol/Binary_Signature.ino @@ -0,0 +1,181 @@ +/* + This project is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Multiprotocol is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Multiprotocol. If not, see . + */ + +/************************/ +/** Firmware Signature **/ +/************************/ + +/* +The firmware signature is appended to the compiled binary image in order to provide information +about the options used to compile the firmware file. This information is then used by Multi-module +flashing tools to verify that the image is correct / valid. + +In order for the build process to determine the options used to build the firmware this file conditionally +declares 'flag' variables for the options we are interested in. + +When the pre-compiler parses the source code these variables are either present or not in the parsed cpp file, +typically '$build_dir$/preproc/ctags_target_for_gcc_minus_e.cpp'. + +Once the .bin file is compiled an additional command-line tool scans the parsed cpp file, detects the flags, +assembles the signature, and finally appends to the end of the binary file. + +The signature is 24 bytes long: +multi-x[8-byte hex code]-[8-byte version number] + +For example: +multi-x1234abcd-01020199 + +The 8-byte hex code is a 32-bit bitmask value indicating the configuration options, currently: + +Bit(s) Option Comment +1-2 Module type Read as a two-bit value indicating a number from 0-3 which maps to a module type (AVR, STM32, OrangeRX) +3-7 Channel order Read as a five-bit value indicating a number from 0-23 which maps to as channel order (AETR, TAER, RETA, etc) +8 Bootloader support Indicates whether or not the firmware was built with support for the bootloader +9 CHECK_FOR_BOOTLOADER +10 INVERT_TELEMETRY +11 MULTI_STATUS +12 MULTI_TELEMETRY +13 DEBUG_SERIAL + +The 8-byte version number is the version number zero-padded to a fixed width of two-bytes per segment and no separator. +E.g. 1.2.3.45 becomes 01020345. + +Module types are mapped to the following decimal / binary values: + +Module Type Decimal Value Binary Valsue +AVR 0 00 +STM32 1 01 +OrangeRX 2 10 + +Channel orders are mapped to the following decimal / binary values: + +Channel Order Decimal Value Binary Value +AETR 0 00000 +AERT 1 00001 +ARET 2 00010 +ARTE 3 00011 +ATRE 4 00100 +ATER 5 00101 +EATR 6 00110 +EART 7 00111 +ERAT 8 01000 +ERTA 9 01001 +ETRA 10 01010 +ETAR 11 01011 +TEAR 12 01100 +TERA 13 01101 +TREA 14 01110 +TRAE 15 01111 +TARE 16 10000 +TAER 17 10001 +RETA 18 10010 +REAT 19 10011 +RAET 20 10100 +RATE 21 10101 +RTAE 22 10110 +RTEA 23 10111 + +*/ + +// Set the flags for detecting and writing the firmware signature +#if defined (CHECK_FOR_BOOTLOADER) + bool firmwareFlag_CHECK_FOR_BOOTLOADER = true; +#endif +#if defined (INVERT_TELEMETRY) + bool firmwareFlag_INVERT_TELEMETRY = true; +#endif +#if defined (MULTI_STATUS) + bool firmwareFlag_MULTI_STATUS = true; +#endif +#if defined (MULTI_TELEMETRY) + bool firmwareFlag_MULTI_TELEMETRY = true; +#endif +#if defined (DEBUG_SERIAL) + bool firmwareFlag_DEBUG_SERIAL = true; +#endif + +// Channel order flags +#if defined (AETR) + bool firmwareFlag_ChannelOrder_AETR = true; +#endif +#if defined (AERT) + bool firmwareFlag_ChannelOrder_AERT = true; +#endif +#if defined (ARET) + bool firmwareFlag_ChannelOrder_ARET = true; +#endif +#if defined (ARTE) + bool firmwareFlag_ChannelOrder_ARTE = true; +#endif +#if defined (ATRE) + bool firmwareFlag_ChannelOrder_ATRE = true; +#endif +#if defined (ATER) + bool firmwareFlag_ChannelOrder_ATER = true; +#endif +#if defined (EATR) + bool firmwareFlag_ChannelOrder_EATR = true; +#endif +#if defined (EART) + bool firmwareFlag_ChannelOrder_EART = true; +#endif +#if defined (ERAT) + bool firmwareFlag_ChannelOrder_ERAT = true; +#endif +#if defined (ERTA) + bool firmwareFlag_ChannelOrder_ERTA = true; +#endif +#if defined (ETRA) + bool firmwareFlag_ChannelOrder_ETRA = true; +#endif +#if defined (ETAR) + bool firmwareFlag_ChannelOrder_ETAR = true; +#endif +#if defined (TEAR) + bool firmwareFlag_ChannelOrder_TEAR = true; +#endif +#if defined (TERA) + bool firmwareFlag_ChannelOrder_TERA = true; +#endif +#if defined (TREA) + bool firmwareFlag_ChannelOrder_TREA = true; +#endif +#if defined (TRAE) + bool firmwareFlag_ChannelOrder_TRAE = true; +#endif +#if defined (TARE) + bool firmwareFlag_ChannelOrder_TARE = true; +#endif +#if defined (TAER) + bool firmwareFlag_ChannelOrder_TAER = true; +#endif +#if defined (RETA) + bool firmwareFlag_ChannelOrder_RETA = true; +#endif +#if defined (REAT) + bool firmwareFlag_ChannelOrder_REAT = true; +#endif +#if defined (RAET) + bool firmwareFlag_ChannelOrder_RAET = true; +#endif +#if defined (RATE) + bool firmwareFlag_ChannelOrder_RATE = true; +#endif +#if defined (RTAE) + bool firmwareFlag_ChannelOrder_RTAE = true; +#endif +#if defined (RTEA) + bool firmwareFlag_ChannelOrder_RTEA = true; +#endif \ No newline at end of file diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 2092c38..b2a8ef5 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -20,9 +20,19 @@ #include "iface_cc2500.h" uint8_t FrSkyX_chanskip; -uint8_t FrSkyX_TX_Seq ; +uint8_t FrSkyX_TX_Seq, FrSkyX_TX_IN_Seq; uint8_t FrSkyX_RX_Seq ; +#ifdef SPORT_SEND + struct t_FrSkyX_TX_Frame + { + uint8_t count; + uint8_t payload[6]; + } ; + // Store FrskyX telemetry + struct t_FrSkyX_TX_Frame FrSkyX_TX_Frames[4] ; +#endif + #define FrSkyX_FAILSAFE_TIMEOUT 1032 static void __attribute__((unused)) FrSkyX_set_start(uint8_t ch ) @@ -178,30 +188,70 @@ static void __attribute__((unused)) FrSkyX_build_packet() else chan_offset^=0x08; - //sequence - packet[21] = (FrSkyX_RX_Seq << 4) | FrSkyX_TX_Seq ;//=8 at startup - + //sequence and send SPort uint8_t limit = (sub_protocol & 2 ) ? 31 : 28 ; for (uint8_t i=22;i100) {//~1sec - FrSkyX_TX_Seq = 0x08 ; - //FrSkyX_RX_Seq = 0 ; + FrSkyX_TX_Seq = 0x08 ; // Request init + FrSkyX_TX_IN_Seq = 0xFF ; // No sequence received yet + #ifdef SPORT_SEND + for(uint8_t i=0;i<4;i++) + FrSkyX_TX_Frames[i].count=0; // discard frames in current output buffer + #endif packet_count=0; #if defined TELEMETRY telemetry_lost=1; @@ -284,8 +338,6 @@ uint16_t ReadFrSkyX() CC2500_Strobe(CC2500_SFRX); //flush the RXFIFO } FrSkyX_build_packet(); - if ( FrSkyX_TX_Seq != 0x08 ) - FrSkyX_TX_Seq = ( FrSkyX_TX_Seq + 1 ) & 0x03 ; state = FRSKY_DATA1; return 500; } @@ -316,8 +368,13 @@ uint16_t initFrSkyX() state = FRSKY_DATA1; FrSkyX_initialize_data(0); } - FrSkyX_TX_Seq = 0x08 ; - FrSkyX_RX_Seq = 0 ; + FrSkyX_TX_Seq = 0x08 ; // Request init + FrSkyX_TX_IN_Seq = 0xFF ; // No sequence received yet + #ifdef SPORT_SEND + for(uint8_t i=0;i<4;i++) + FrSkyX_TX_Frames[i].count=0; // discard frames in current output buffer + #endif + FrSkyX_RX_Seq = 0 ; // Seq 0 to start with return 10000; } #endif \ No newline at end of file diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index a73367c..1377e01 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 2 +#define VERSION_PATCH_LEVEL 4 //****************** // Protocols @@ -303,7 +303,7 @@ enum FRSKYX_RX struct PPM_Parameters { - uint8_t protocol : 6; + uint8_t protocol : 7; uint8_t sub_proto : 3; uint8_t rx_num : 4; uint8_t power : 1; @@ -589,8 +589,12 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- Total of 26 bytes Stream[0] = 0x55 sub_protocol values are 0..31 Stream contains channels Stream[0] = 0x54 sub_protocol values are 32..63 Stream contains channels + Stream[0] = 0x51 sub_protocol values are 64..95 Stream contains channels + Stream[0] = 0x50 sub_protocol values are 96..127 Stream contains channels Stream[0] = 0x57 sub_protocol values are 0..31 Stream contains failsafe Stream[0] = 0x56 sub_protocol values are 32..63 Stream contains failsafe + Stream[0] = 0x53 sub_protocol values are 64..95 Stream contains failsafe + Stream[0] = 0x52 sub_protocol values are 96..127 Stream contains failsafe Stream[0] |= 0x20 any of the above + 8 additional bytes at the end of the stream available for the current sub_protocol header Stream[1] = sub_protocol|BindBit|RangeCheckBit|AutoBindBit; diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index bf54b5b..2c5a05e 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -1416,40 +1416,40 @@ void update_serial_data() //Forced frequency tuning values for CC2500 protocols #if defined(FORCE_FRSKYD_TUNING) && defined(FRSKYD_CC2500_INO) if(protocol==PROTO_FRSKYD) - option=FORCE_FRSKYD_TUNING; // Use config-defined tuning value for FrSkyD + option=FORCE_FRSKYD_TUNING; // Use config-defined tuning value for FrSkyD else #endif #if defined(FORCE_FRSKYV_TUNING) && defined(FRSKYV_CC2500_INO) if(protocol==PROTO_FRSKYV) - option=FORCE_FRSKYV_TUNING; // Use config-defined tuning value for FrSkyV + option=FORCE_FRSKYV_TUNING; // Use config-defined tuning value for FrSkyV else #endif #if defined(FORCE_FRSKYX_TUNING) && defined(FRSKYX_CC2500_INO) if(protocol==PROTO_FRSKYX) - option=FORCE_FRSKYX_TUNING; // Use config-defined tuning value for FrSkyX + option=FORCE_FRSKYX_TUNING; // Use config-defined tuning value for FrSkyX else #endif #if defined(FORCE_SFHSS_TUNING) && defined(SFHSS_CC2500_INO) if (protocol==PROTO_SFHSS) - option=FORCE_SFHSS_TUNING; // Use config-defined tuning value for SFHSS + option=FORCE_SFHSS_TUNING; // Use config-defined tuning value for SFHSS else #endif #if defined(FORCE_CORONA_TUNING) && defined(CORONA_CC2500_INO) if (protocol==PROTO_CORONA) - option=FORCE_CORONA_TUNING; // Use config-defined tuning value for CORONA + option=FORCE_CORONA_TUNING; // Use config-defined tuning value for CORONA else #endif #if defined(FORCE_REDPINE_TUNING) && defined(REDPINE_CC2500_INO) if (protocol==PROTO_REDPINE) - option=FORCE_REDPINE_TUNING; // Use config-defined tuning value for REDPINE + option=FORCE_REDPINE_TUNING; // Use config-defined tuning value for REDPINE else #endif #if defined(FORCE_HITEC_TUNING) && defined(HITEC_CC2500_INO) if (protocol==PROTO_HITEC) - option=FORCE_HITEC_TUNING; // Use config-defined tuning value for HITEC + option=FORCE_HITEC_TUNING; // Use config-defined tuning value for HITEC else #endif - option=rx_ok_buff[3]; // Use radio-defined option value + option=rx_ok_buff[3]; // Use radio-defined option value #ifdef FAILSAFE_ENABLE bool failsafe=false; @@ -1483,9 +1483,13 @@ void update_serial_data() BIND_IN_PROGRESS; //launch bind right away if in autobind mode or bind is set else BIND_DONE; - protocol=(rx_ok_buff[0]==0x55?0:32) + (rx_ok_buff[1]&0x1F); //protocol no (0-63) bits 4-6 of buff[1] and bit 0 of buf[0] + protocol=rx_ok_buff[1]&0x1F; //protocol no (0-31) + if(!(rx_ok_buff[0]&1)) + protocol+=32; //protocol no (0-63) + if(!(rx_ok_buff[0]&4)) + protocol+=64; //protocol no (0-127) sub_protocol=(rx_ok_buff[2]>>4)& 0x07; //subprotocol no (0-7) bits 4-6 - RX_num=rx_ok_buff[2]& 0x0F; // rx_num bits 0---3 + RX_num=rx_ok_buff[2]& 0x0F; // rx_num bits 0-3 } else if( ((rx_ok_buff[1]&0x80)!=0) && ((cur_protocol[1]&0x80)==0) ) // Bind flag has been set @@ -1920,55 +1924,48 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { // RX interrupt static uint8_t idx=0,len=26; #ifdef ORANGE_TX - if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error + if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error #elif defined STM32_BOARD if((USART2_BASE->SR & USART_SR_RXNE) && (USART2_BASE->SR &0x0F)==0) #else - UCSR0B &= ~_BV(RXCIE0) ; // RX interrupt disable + UCSR0B &= ~_BV(RXCIE0) ; // RX interrupt disable sei() ; - if((UCSR0A&0x1C)==0) // Check frame error, data overrun and parity error + if((UCSR0A&0x1C)==0) // Check frame error, data overrun and parity error #endif { // received byte is ok to process if(idx==0||discard_frame==1) { // Let's try to sync at this point idx=0;discard_frame=0; - RX_MISSED_BUFF_off; // If rx_buff was good it's not anymore... + RX_MISSED_BUFF_off; // If rx_buff was good it's not anymore... rx_buff[0]=UDR0; #ifdef SERIAL_DATA_ENABLE #ifdef FAILSAFE_ENABLE - if((rx_buff[0]&0xDC)==0x54) // If 1st byte is 0x74, 0x75, 0x76, 0x77, 0x54, 0x55, 0x56 or 0x57 it looks ok + if((rx_buff[0]&0xD8)==0x50) // If 1st byte is 0x74, 0x75, 0x76, 0x77, 0x54, 0x55, 0x56 or 0x57 it looks ok #else - if((rx_buff[0]&0xDE)==0x54) // If 1st byte is 0x74, 0x75, 0x54 or 0x55 it looks ok + if((rx_buff[0]&0xDA)==0x50) // If 1st byte is 0x74, 0x75, 0x54 or 0x55 it looks ok #endif #else #ifdef FAILSAFE_ENABLE - if((rx_buff[0]&0xFC)==0x54) // If 1st byte is 0x58, 0x54, 0x55, 0x56 or 0x57 it looks ok + if((rx_buff[0]&0xF8)==0x50) // If 1st byte is 0x58, 0x54, 0x55, 0x56 or 0x57 it looks ok #else - if((rx_buff[0]&0xFE)==0x54) // If 1st byte is 0x58, 0x54 or 0x55 it looks ok + if((rx_buff[0]&0xFA)==0x50) // If 1st byte is 0x54 or 0x55 it looks ok #endif #endif { - uint16_t max_time; #ifdef SERIAL_DATA_ENABLE if(rx_buff[0]&0x20) - { - max_time=8500; len=34; - } else #endif - { - max_time=6500; len=26; - } TX_RX_PAUSE_on; tx_pause(); #if defined STM32_BOARD - TIMER2_BASE->CCR2=TIMER2_BASE->CNT+max_time;// Full message should be received within timer of 3250us + TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15??s=1.5 byte TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag TIMER2_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer2/Comp2 interrupt #else - OCR1B = TCNT1+max_time; // Full message should be received within timer of 3250us + OCR1B = TCNT1 + 300; // Next byte should show up within 15??s=1.5 byte TIFR1 = OCF1B_bm ; // clear OCR1B match flag SET_TIMSK1_OCIE1B ; // enable interrupt on compare B match #endif @@ -1977,39 +1974,44 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) } else { - rx_buff[idx++]=UDR0; // Store received byte + rx_buff[idx++]=UDR0; // Store received byte + #if defined STM32_BOARD + TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15??s=1.5 byte + #else + OCR1B = TCNT1 + 300; // Next byte should show up within 15??s=1.5 byte + #endif if(idx>=len) { // A full frame has been received if(!IS_RX_DONOTUPDATE_on) { //Good frame received and main is not working on the buffer memcpy((void*)rx_ok_buff,(const void*)rx_buff,len);// Duplicate the buffer - RX_FLAG_on; // flag for main to process servo data + RX_FLAG_on; // Flag for main to process servo data } else - RX_MISSED_BUFF_on; // notify that rx_buff is good - discard_frame=1; // start again + RX_MISSED_BUFF_on; // Notify that rx_buff is good + discard_frame=1; // Start again } } } else { - idx=UDR0; // Dummy read - discard_frame=1; // Error encountered discard full frame... + idx=UDR0; // Dummy read + discard_frame=1; // Error encountered discard full frame... debugln("Bad frame RX"); } if(discard_frame==1) { #ifdef STM32_BOARD - TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt + TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt #else - CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match + CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match #endif TX_RX_PAUSE_off; tx_resume(); } #if not defined (ORANGE_TX) && not defined (STM32_BOARD) cli() ; - UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable + UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable #endif } @@ -2024,10 +2026,10 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { // Timer1 compare B interrupt discard_frame=1; #ifdef STM32_BOARD - TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt + TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt debugln("Bad frame timer"); #else - CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match + CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match #endif tx_resume(); } @@ -2074,20 +2076,3 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) } } #endif - -// Set the flags for detecting and writing the firmware signature -#if defined (CHECK_FOR_BOOTLOADER) - bool firmwareFlag_CHECK_FOR_BOOTLOADER = true; -#endif -#if defined (MULTI_STATUS) - bool firmwareFlag_MULTI_STATUS = true; -#endif -#if defined (MULTI_TELEMETRY) - bool firmwareFlag_MULTI_TELEMETRY = true; -#endif -#if defined (INVERT_TELEMETRY) - bool firmwareFlag_INVERT_TELEMETRY = true; -#endif -#if defined (DEBUG_SERIAL) - bool firmwareFlag_DEBUG_SERIAL = true; -#endif diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 197e84e..ac94009 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -303,9 +303,12 @@ void frsky_check_telemetry(uint8_t *packet_in,uint8_t len) else RxBt = (packet_in[4]<<1) + 1 ; + //Save outgoing telemetry sequence + FrSkyX_TX_IN_Seq=packet_in[5] >> 4; + //Check incoming telemetry sequence uint8_t packet_seq=packet_in[5] & 0x03; - if ( (packet_in[5] & 0x0F) == 0x08 ) + if ( packet_in[5] & 0x08 ) {//Request init FrSkyX_RX_Seq = 0x08 ; FrSkyX_RX_NextFrame = 0x00 ; @@ -345,6 +348,7 @@ void frsky_check_telemetry(uint8_t *packet_in,uint8_t len) } else {//Not in sequence + debugln("NS"); struct t_FrSkyX_RX_Frame *q ; uint8_t count ; // packet_in[4] RSSI @@ -369,11 +373,6 @@ void frsky_check_telemetry(uint8_t *packet_in,uint8_t len) } FrSkyX_RX_Seq = ( FrSkyX_RX_Seq & 0x03 ) | 0x04 ; // Request re-transmission of original sequence } - - //Check outgoing telemetry sequence - if (((packet_in[5] >> 4) & 0x08) == 0x08) - FrSkyX_TX_Seq = 0 ; //Request init - //debugln("s:%02X,p:%02X",FrSkyX_TX_Seq,packet_in[5] >> 4); } #endif } From bf61295b760e4ef86e3267eaef6720da48d0f5e1 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Wed, 2 Oct 2019 21:24:50 +0200 Subject: [PATCH 04/65] Fix AFHDS2A_RX --- Multiprotocol/AFHDS2A_Rx_a7105.ino | 12 ++++++------ Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Telemetry.ino | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Multiprotocol/AFHDS2A_Rx_a7105.ino b/Multiprotocol/AFHDS2A_Rx_a7105.ino index d4c8b8e..589cbde 100644 --- a/Multiprotocol/AFHDS2A_Rx_a7105.ino +++ b/Multiprotocol/AFHDS2A_Rx_a7105.ino @@ -36,10 +36,10 @@ static void __attribute__((unused)) AFHDS2A_Rx_build_telemetry_packet() uint8_t bitsavailable = 0; uint8_t idx = 0; - pkt[idx++] = RX_LQI; // 0 - 130 - pkt[idx++] = RX_RSSI; - pkt[idx++] = 0; // start channel - pkt[idx++] = 14; // number of channels in packet + packet_in[idx++] = RX_LQI; // 0 - 130 + packet_in[idx++] = RX_RSSI; + packet_in[idx++] = 0; // start channel + packet_in[idx++] = 14; // number of channels in packet // pack channels for (uint8_t i = 0; i < 14; i++) { uint16_t val = packet[9+i*2] | (packet[10+i*2] << 8); @@ -52,7 +52,7 @@ static void __attribute__((unused)) AFHDS2A_Rx_build_telemetry_packet() bits |= val << bitsavailable; bitsavailable += 11; while (bitsavailable >= 8) { - pkt[idx++] = bits & 0xff; + packet_in[idx++] = bits & 0xff; bits >>= 8; bitsavailable -= 8; } @@ -182,7 +182,7 @@ uint16_t AFHDS2A_Rx_callback() // packets per second if (millis() - pps_timer >= 1000) { pps_timer = millis(); - debugln("%ld pps", pps_counter); + debugln("%d pps", pps_counter); RX_LQI = pps_counter / 2; pps_counter = 0; } diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index f848609..272dd8d 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 4 +#define VERSION_PATCH_LEVEL 5 //****************** // Protocols diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 86695b8..c7db2b9 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -167,7 +167,7 @@ static void multi_send_status() #if defined (FRSKYX_RX_TELEMETRY) || defined (AFHDS2A_RX_TELEMETRY) void receiver_channels_frame() { - uint16_t len = pkt[3] * 11; // 11 bit per channel + uint16_t len = packet_in[3] * 11; // 11 bit per channel if (len % 8 == 0) len = 4 + (len / 8); else From 431808286b36ec89794712d691a501f1654a753f Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 3 Oct 2019 16:38:50 +0200 Subject: [PATCH 05/65] Data Buffer signaling --- Multiprotocol/FrSkyX_cc2500.ino | 45 +++++++++++++++++++++------------ Multiprotocol/Multiprotocol.h | 25 +++++++++++++----- Multiprotocol/Multiprotocol.ino | 17 ++++++++++--- Multiprotocol/Telemetry.ino | 6 +++-- 4 files changed, 65 insertions(+), 28 deletions(-) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index b2a8ef5..9b91c84 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -27,7 +27,7 @@ uint8_t FrSkyX_RX_Seq ; struct t_FrSkyX_TX_Frame { uint8_t count; - uint8_t payload[6]; + uint8_t payload[8]; } ; // Store FrskyX telemetry struct t_FrSkyX_TX_Frame FrSkyX_TX_Frames[4] ; @@ -196,46 +196,58 @@ static void __attribute__((unused)) FrSkyX_build_packet() #ifdef SPORT_SEND if (FrSkyX_TX_IN_Seq!=0xFF) {//RX has replied at least once - debugln("R:%X,T:%X",FrSkyX_TX_IN_Seq,FrSkyX_TX_Seq); if (FrSkyX_TX_IN_Seq & 0x08) {//Request init - debugln("Init"); + //debugln("Init"); FrSkyX_TX_Seq = 0 ; for(uint8_t i=0;i<4;i++) FrSkyX_TX_Frames[i].count=0; // discard frames in current output buffer } else if (FrSkyX_TX_IN_Seq & 0x04) {//Retransmit the requested packet - debugln("Retr:%d",FrSkyX_TX_IN_Seq&0x03); + debugln("Retry:%d",FrSkyX_TX_IN_Seq&0x03); + packet[21] |= FrSkyX_TX_IN_Seq&0x03; + packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].count; for (uint8_t i=23;i<23+FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].count;i++) packet[i] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].payload[i]; - packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].count; - packet[21] |= FrSkyX_TX_IN_Seq&0x03; } else if ( FrSkyX_TX_Seq != 0x08 ) { - if(FrSkyX_TX_IN_Seq==FrSkyX_TX_Seq) + if(FrSkyX_TX_Seq==FrSkyX_TX_IN_Seq) {//Send packet from the incoming radio buffer + //debugln("Send:%d",FrSkyX_TX_Seq); + packet[21] |= FrSkyX_TX_Seq; uint8_t nbr_bytes=0; for (uint8_t i=23;i= SportTail ) + used += MAX_SPORT_BUFFER - SportHead ; + else + used -= SportHead ; + if ( used < (MAX_SPORT_BUFFER>>1) ) + DATA_BUFFER_LOW_off; + } FrSkyX_TX_Seq = ( FrSkyX_TX_Seq + 1 ) & 0x03 ; // Next iteration send next packet } else - {//Retransmit the last packet - debugln("Retr:%d",FrSkyX_TX_IN_Seq); - for (uint8_t i=23;i<23+FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count;i++) - packet[i] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].payload[i]; - packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count; + {//Not in sequence somehow, transmit what the receiver wants but why not asking for retransmit... + debugln("RX_Seq:%d,TX:%d",FrSkyX_TX_IN_Seq,FrSkyX_TX_Seq); packet[21] |= FrSkyX_TX_IN_Seq; + packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count; + for (uint8_t i=23;i<23+FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count;i++) + packet[i] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].payload[i-23]; } } else @@ -243,7 +255,7 @@ static void __attribute__((unused)) FrSkyX_build_packet() } if(packet[22]) {//Debug - debug("SPort_out: "); + debug("SP: "); for(uint8_t i=0;i SportTail ) + used += MAX_SPORT_BUFFER - SportHead ; + else + used -= SportHead ; + if ( used >= MAX_SPORT_BUFFER-(MAX_SPORT_BUFFER>>2) ) + { + DATA_BUFFER_LOW_on; + SEND_MULTI_STATUS_on; //Send Multi Status ASAP to inform the TX + debugln("Low buf=%d,h=%d,t=%d",used,SportHead,SportTail); + } } #endif } diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index c7db2b9..7487203 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -111,6 +111,8 @@ static void multi_send_status() break; } #endif + if(IS_DATA_BUFFER_LOW_on) + flags |= 0x80; } Serial_write(flags); @@ -353,7 +355,6 @@ void frsky_check_telemetry(uint8_t *packet_in,uint8_t len) } else {//Not in sequence - debugln("NS"); struct t_FrSkyX_RX_Frame *q ; uint8_t count ; // packet_in[4] RSSI @@ -725,9 +726,10 @@ void TelemetryUpdate() #if ( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) { uint32_t now = millis(); - if ((now - lastMulti) > MULTI_TIME) + if (IS_SEND_MULTI_STATUS_on || (now - lastMulti) > MULTI_TIME) { multi_send_status(); + SEND_MULTI_STATUS_off; lastMulti = now; return; } From c2bf63991fab47590c31d2ed1a1761809210c446 Mon Sep 17 00:00:00 2001 From: goebish Date: Sat, 5 Oct 2019 13:30:50 +0200 Subject: [PATCH 06/65] Fix channel and rssi scaling (#279) --- Multiprotocol/AFHDS2A_Rx_a7105.ino | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Multiprotocol/AFHDS2A_Rx_a7105.ino b/Multiprotocol/AFHDS2A_Rx_a7105.ino index 9f85779..1e1cf95 100644 --- a/Multiprotocol/AFHDS2A_Rx_a7105.ino +++ b/Multiprotocol/AFHDS2A_Rx_a7105.ino @@ -42,14 +42,15 @@ static void __attribute__((unused)) AFHDS2A_Rx_build_telemetry_packet() packet_in[idx++] = 14; // number of channels in packet // pack channels for (uint8_t i = 0; i < 14; i++) { - uint16_t val = packet[9+i*2] | (packet[10+i*2] << 8); + uint32_t val = packet[9+i*2] | (packet[10+i*2] << 8); if (val < 860) val = 860; - else if (val > 2140) - val = 2140; - val -= 860; + else if (val > 2139) + val = 2139; + // convert ppm (860-2140) to Multi (0-2047) + val = ((val-860)<<3)/5; - bits |= ((uint32_t)val) << bitsavailable; + bits |= val << bitsavailable; bitsavailable += 11; while (bitsavailable >= 8) { packet_in[idx++] = bits & 0xff; @@ -169,7 +170,7 @@ uint16_t AFHDS2A_Rx_callback() if (memcmp(&packet[1], rx_id, 4) == 0 && memcmp(&packet[5], rx_tx_addr, 4) == 0) { if (packet[0] == 0x58 && packet[37] == 0x00 && telemetry_link == 0) { // standard packet, send channels to TX int rssi = min(A7105_ReadReg(A7105_1D_RSSI_THOLD),160); - RX_RSSI = map(rssi, 160, 8, 0, 100); + RX_RSSI = map16b(rssi, 160, 8, 0, 128); AFHDS2A_Rx_build_telemetry_packet(); telemetry_link = 1; } From 9fd72b5ad55d330fe47fd780c0f5bb22cb762d16 Mon Sep 17 00:00:00 2001 From: goebish Date: Sat, 5 Oct 2019 19:02:59 +0200 Subject: [PATCH 07/65] Fix scaling for +125% (#280) --- Multiprotocol/AFHDS2A_Rx_a7105.ino | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Multiprotocol/AFHDS2A_Rx_a7105.ino b/Multiprotocol/AFHDS2A_Rx_a7105.ino index 1e1cf95..9ee15ba 100644 --- a/Multiprotocol/AFHDS2A_Rx_a7105.ino +++ b/Multiprotocol/AFHDS2A_Rx_a7105.ino @@ -45,10 +45,8 @@ static void __attribute__((unused)) AFHDS2A_Rx_build_telemetry_packet() uint32_t val = packet[9+i*2] | (packet[10+i*2] << 8); if (val < 860) val = 860; - else if (val > 2139) - val = 2139; // convert ppm (860-2140) to Multi (0-2047) - val = ((val-860)<<3)/5; + val = min(((val-860)<<3)/5, 2047); bits |= val << bitsavailable; bitsavailable += 11; From ff96146b04845b46bc8c644c58e1d6f069f40a50 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 7 Oct 2019 19:06:00 +0200 Subject: [PATCH 08/65] Enhanced serial protocol Protocol 0..255 RX_Num 0..63 Disable channel mapping -> not implemented yet Disable telemetry Data 0-9 bytes --- Multiprotocol/AFHDS2A_a7105.ino | 16 ++- Multiprotocol/BUGSMINI_nrf24l01.ino | 4 +- Multiprotocol/Bugs_a7105.ino | 6 +- Multiprotocol/FrSkyX_cc2500.ino | 5 +- Multiprotocol/Multiprotocol.h | 165 ++++++++++++---------- Multiprotocol/Multiprotocol.ino | 208 ++++++++++++++-------------- Multiprotocol/Telemetry.ino | 17 ++- Multiprotocol/Validate.h | 4 - 8 files changed, 221 insertions(+), 204 deletions(-) diff --git a/Multiprotocol/AFHDS2A_a7105.ino b/Multiprotocol/AFHDS2A_a7105.ino index 4333972..91d171d 100644 --- a/Multiprotocol/AFHDS2A_a7105.ino +++ b/Multiprotocol/AFHDS2A_a7105.ino @@ -264,11 +264,15 @@ uint16_t ReadAFHDS2A() A7105_ReadData(AFHDS2A_RXPACKET_SIZE); if(packet[0] == 0xbc && packet[9] == 0x01) { - uint8_t temp=AFHDS2A_EEPROM_OFFSET+RX_num*4; + uint8_t addr; + if(RX_num<16) + addr=AFHDS2A_EEPROM_OFFSET+RX_num*4; + else + addr=AFHDS2A_EEPROM_OFFSET2+(RX_num-16)*4; for(uint8_t i=0; i<4; i++) { rx_id[i] = packet[5+i]; - eeprom_write_byte((EE_ADDR)(temp+i),rx_id[i]); + eeprom_write_byte((EE_ADDR)(addr+i),rx_id[i]); } phase = AFHDS2A_BIND4; packet_count++; @@ -390,9 +394,13 @@ uint16_t initAFHDS2A() { phase = AFHDS2A_DATA_INIT; //Read RX ID from EEPROM based on RX_num, RX_num must be uniq for each RX - uint8_t temp=AFHDS2A_EEPROM_OFFSET+RX_num*4; + uint8_t addr; + if(RX_num<16) + addr=AFHDS2A_EEPROM_OFFSET+RX_num*4; + else + addr=AFHDS2A_EEPROM_OFFSET2+(RX_num-16)*4; for(uint8_t i=0;i<4;i++) - rx_id[i]=eeprom_read_byte((EE_ADDR)(temp+i)); + rx_id[i]=eeprom_read_byte((EE_ADDR)(addr+i)); } hopping_frequency_no = 0; #if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY) diff --git a/Multiprotocol/BUGSMINI_nrf24l01.ino b/Multiprotocol/BUGSMINI_nrf24l01.ino index a52c735..92cbb35 100644 --- a/Multiprotocol/BUGSMINI_nrf24l01.ino +++ b/Multiprotocol/BUGSMINI_nrf24l01.ino @@ -181,7 +181,7 @@ static void __attribute__((unused)) BUGSMINI_make_address() uint8_t start, length, index; //read rxid - uint8_t base_adr=BUGSMINI_EEPROM_OFFSET+RX_num*2; + uint8_t base_adr=BUGSMINI_EEPROM_OFFSET+(RX_num&0x0F)*2; uint8_t rxid_high = eeprom_read_byte((EE_ADDR)(base_adr+0)); uint8_t rxid_low = eeprom_read_byte((EE_ADDR)(base_adr+1)); @@ -272,7 +272,7 @@ uint16_t BUGSMINI_callback() if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) { // RX fifo data ready XN297_ReadPayload(packet, BUGSMINI_RX_PAYLOAD_SIZE); - base_adr=BUGSMINI_EEPROM_OFFSET+RX_num*2; + base_adr=BUGSMINI_EEPROM_OFFSET+(RX_num&0x0F)*2; eeprom_write_byte((EE_ADDR)(base_adr+0),packet[1]); // Save rxid in EEPROM eeprom_write_byte((EE_ADDR)(base_adr+1),packet[2]); // Save rxid in EEPROM NRF24L01_SetTxRxMode(TXRX_OFF); diff --git a/Multiprotocol/Bugs_a7105.ino b/Multiprotocol/Bugs_a7105.ino index feae006..6a108db 100644 --- a/Multiprotocol/Bugs_a7105.ino +++ b/Multiprotocol/Bugs_a7105.ino @@ -284,7 +284,7 @@ static void __attribute__((unused))BUGS_set_radio_data() { offset=BUGS_NUM_RFCHAN; // Read radio_id from EEPROM - uint8_t base_adr=BUGS_EEPROM_OFFSET+RX_num*2; + uint8_t base_adr=BUGS_EEPROM_OFFSET+(RX_num&0x0F)*2; uint16_t rxid=0; for(uint8_t i=0; i<2; i++) rxid|=eeprom_read_byte((EE_ADDR)(base_adr+i))<<(i*8); @@ -374,7 +374,7 @@ uint16_t ReadBUGS(void) BIND_DONE; // set radio_id rxid = (packet[1] << 8) + packet[2]; - base_adr=BUGS_EEPROM_OFFSET+RX_num*2; + base_adr=BUGS_EEPROM_OFFSET+(RX_num&0x0F)*2; for(uint8_t i=0; i<2; i++) eeprom_write_byte((EE_ADDR)(base_adr+i),rxid>>(i*8)); // Save rxid in EEPROM BUGS_set_radio_data(); @@ -437,7 +437,7 @@ uint16_t ReadBUGS(void) uint16_t initBUGS(void) { uint16_t rxid=0; - uint8_t base_adr=BUGS_EEPROM_OFFSET+RX_num*2; + uint8_t base_adr=BUGS_EEPROM_OFFSET+(RX_num&0x0F)*2; for(uint8_t i=0; i<2; i++) rxid|=eeprom_read_byte((EE_ADDR)(base_adr+i))<<(i*8); if(rxid==0xffff) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 9b91c84..f5f15c6 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -237,13 +237,16 @@ static void __attribute__((unused)) FrSkyX_build_packet() else used -= SportHead ; if ( used < (MAX_SPORT_BUFFER>>1) ) + { DATA_BUFFER_LOW_off; + debugln("Ok buf:%d",used); + } } FrSkyX_TX_Seq = ( FrSkyX_TX_Seq + 1 ) & 0x03 ; // Next iteration send next packet } else {//Not in sequence somehow, transmit what the receiver wants but why not asking for retransmit... - debugln("RX_Seq:%d,TX:%d",FrSkyX_TX_IN_Seq,FrSkyX_TX_Seq); + //debugln("RX_Seq:%d,TX:%d",FrSkyX_TX_IN_Seq,FrSkyX_TX_Seq); packet[21] |= FrSkyX_TX_IN_Seq; packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count; for (uint8_t i=23;i<23+FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count;i++) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 067a55c..5865f25 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 6 +#define VERSION_PATCH_LEVEL 8 //****************** // Protocols @@ -304,17 +304,16 @@ enum FRSKYX_RX struct PPM_Parameters { - uint8_t protocol : 7; - uint8_t sub_proto : 3; - uint8_t rx_num : 4; - uint8_t power : 1; - uint8_t autobind : 1; + uint8_t protocol; + uint8_t sub_proto : 3; + uint8_t rx_num : 4; + uint8_t power : 1; + uint8_t autobind : 1; uint8_t option; uint32_t chan_order; }; // Telemetry - enum MultiPacketTypes { MULTI_TELEMETRY_STATUS = 1, @@ -390,6 +389,7 @@ enum MultiPacketTypes #define TX_RX_PAUSE_on protocol_flags2 |= _BV(4) #define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 ) #define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 ) +#define IS_TX_PAUSE_off ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) ==0 ) //Signal OK #define INPUT_SIGNAL_off protocol_flags2 &= ~_BV(5) #define INPUT_SIGNAL_on protocol_flags2 |= _BV(5) @@ -414,6 +414,15 @@ enum MultiPacketTypes #define SEND_MULTI_STATUS_on protocol_flags3 |= _BV(1) #define IS_SEND_MULTI_STATUS_on ( ( protocol_flags3 & _BV(1) ) !=0 ) #define IS_SEND_MULTI_STATUS_off ( ( protocol_flags3 & _BV(1) ) ==0 ) +#define DISABLE_CH_MAP_off protocol_flags3 &= ~_BV(2) +#define DISABLE_CH_MAP_on protocol_flags3 |= _BV(2) +#define IS_DISABLE_CH_MAP_on ( ( protocol_flags3 & _BV(2) ) !=0 ) +#define IS_DISABLE_CH_MAP_off ( ( protocol_flags3 & _BV(2) ) ==0 ) +#define DISABLE_TELEM_off protocol_flags3 &= ~_BV(3) +#define DISABLE_TELEM_on protocol_flags3 |= _BV(3) +#define IS_DISABLE_TELEM_on ( ( protocol_flags3 & _BV(3) ) !=0 ) +#define IS_DISABLE_TELEM_off ( ( protocol_flags3 & _BV(3) ) ==0 ) + // Failsafe #define FAILSAFE_CHANNEL_HOLD 2047 @@ -587,85 +596,81 @@ enum { #define BUGSMINI_EEPROM_OFFSET 146 // RX ID, 2 bytes per model id, end is 146+32=178 #define FRSKYX_RX_EEPROM_OFFSET 178 // (3) TX ID + (1) freq_tune + (47) channels, 51 bytes, end is 178+51=229 #define AFHDS2A_RX_EEPROM_OFFSET 229 // (4) TX ID + (16) channels, 20 bytes, end is 229+20=249 -//#define CONFIG_EEPROM_OFFSET 210 // Current configuration of the multimodule +#define AFHDS2A_EEPROM_OFFSET2 249 // RX ID, 4 bytes per model id, end is 249+192=441 +//#define CONFIG_EEPROM_OFFSET 441 // Current configuration of the multimodule //**************************************** //*** MULTI protocol serial definition *** //**************************************** /* -************************** +*************************** 16 channels serial protocol -************************** +*************************** Serial: 100000 Baud 8e2 _ xxxx xxxx p -- - Total of 26 bytes - Stream[0] = 0x55 sub_protocol values are 0..31 Stream contains channels - Stream[0] = 0x54 sub_protocol values are 32..63 Stream contains channels - Stream[0] = 0x51 sub_protocol values are 64..95 Stream contains channels - Stream[0] = 0x50 sub_protocol values are 96..127 Stream contains channels - Stream[0] = 0x57 sub_protocol values are 0..31 Stream contains failsafe - Stream[0] = 0x56 sub_protocol values are 32..63 Stream contains failsafe - Stream[0] = 0x53 sub_protocol values are 64..95 Stream contains failsafe - Stream[0] = 0x52 sub_protocol values are 96..127 Stream contains failsafe - Stream[0] |= 0x20 any of the above + 8 additional data bytes at the end of the stream available for the current sub_protocol - header + Total of 26 bytes for protocol V1, variable length for protocol V2 + Stream[0] = header + 0x55 sub_protocol values are 0..31 Stream contains channels + 0x54 sub_protocol values are 32..63 Stream contains channels + 0x57 sub_protocol values are 0..31 Stream contains failsafe + 0x56 sub_protocol values are 32..63 Stream contains failsafe Stream[1] = sub_protocol|BindBit|RangeCheckBit|AutoBindBit; sub_protocol is 0..31 (bits 0..4), value should be added with 32 if Stream[0] = 0x54 | 0x56 - => Reserved 0 - Flysky 1 - Hubsan 2 - FrskyD 3 - Hisky 4 - V2x2 5 - DSM 6 - Devo 7 - YD717 8 - KN 9 - SymaX 10 - SLT 11 - CX10 12 - CG023 13 - Bayang 14 - FrskyX 15 - ESky 16 - MT99XX 17 - MJXQ 18 - SHENQI 19 - FY326 20 - SFHSS 21 - J6PRO 22 - FQ777 23 - ASSAN 24 - FrskyV 25 - HONTAI 26 - OpenLRS 27 - AFHDS2A 28 - Q2X2 29 - WK2x01 30 - Q303 31 - GW008 32 - DM002 33 - CABELL 34 - ESKY150 35 - H8_3D 36 - CORONA 37 - CFlie 38 - Hitec 39 - WFLY 40 - BUGS 41 - BUGSMINI 42 - TRAXXAS 43 - NCC1701 44 - E01X 45 - V911S 46 - GD00X 47 - V761 48 - KF606 49 - REDPINE 50 - POTENSIC 51 - ZSX 52 - FLYZONE 53 - SCANNER 54 - FRSKYX_RX 55 + Reserved 0 + Flysky 1 + Hubsan 2 + FrskyD 3 + Hisky 4 + V2x2 5 + DSM 6 + Devo 7 + YD717 8 + KN 9 + SymaX 10 + SLT 11 + CX10 12 + CG023 13 + Bayang 14 + FrskyX 15 + ESky 16 + MT99XX 17 + MJXQ 18 + SHENQI 19 + FY326 20 + SFHSS 21 + J6PRO 22 + FQ777 23 + ASSAN 24 + FrskyV 25 + HONTAI 26 + OpenLRS 27 + AFHDS2A 28 + Q2X2 29 + WK2x01 30 + Q303 31 + GW008 32 + DM002 33 + CABELL 34 + ESKY150 35 + H8_3D 36 + CORONA 37 + CFlie 38 + Hitec 39 + WFLY 40 + BUGS 41 + BUGSMINI 42 + TRAXXAS 43 + NCC1701 44 + E01X 45 + V911S 46 + GD00X 47 + V761 48 + KF606 49 + REDPINE 50 + POTENSIC 51 + ZSX 52 + FLYZONE 53 + SCANNER 54 + FRSKYX_RX 55 BindBit=> 0x80 1=Bind/0=No AutoBindBit=> 0x40 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No @@ -824,6 +829,12 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- Values are concatenated to fit in 22 bytes like in SBUS protocol. Failsafe values have exactly the same range/values than normal channels except the extremes where 0=no pulse, 2047=hold. If failsafe is not set or RX then failsafe packets should not be sent. + Stream[26] = sub_protocol bits 6 & 7|RxNum bits 4 & 5|Disable_CH_Mapping 3|Disable_Telemetry 2|future use 1|future use 0; + sub_protocol is 0..255 (bits 0..5 + bits 6..7) + RxNum value is 0..63 (bits 0..3 + bits 4..5) + Disable_CH_Mapping => 0x08 0=enable, 1=disable + Disable_Telemetry => 0x04 0=enable, 1=disable + Stream[27.. 36] = between 0 and 9 bytes for additional protocol data */ /* Multimodule Status diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 95c0b2f..82039df 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -162,10 +162,12 @@ uint8_t RX_num; //Serial RX variables #define BAUD 100000 -#define RXBUFFER_SIZE 34 +#define RXBUFFER_SIZE 36 // 26+1+9 volatile uint8_t rx_buff[RXBUFFER_SIZE]; volatile uint8_t rx_ok_buff[RXBUFFER_SIZE]; volatile uint8_t discard_frame = 0; +volatile uint8_t rx_idx=0, rx_len=0; + // Telemetry #define TELEMETRY_BUFFER_SIZE 30 @@ -664,7 +666,8 @@ uint8_t Update_All() #if ( !( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) ) if( (protocol == PROTO_FRSKYX_RX) || (protocol == PROTO_SCANNER) || (protocol==PROTO_FRSKYD) || (protocol==PROTO_BAYANG) || (protocol==PROTO_NCC1701) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_FRSKYX) || (protocol==PROTO_DSM) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC)) #endif - TelemetryUpdate(); + if(IS_DISABLE_TELEM_off) + TelemetryUpdate(); #endif #ifdef ENABLE_BIND_CH if(IS_AUTOBIND_FLAG_on && IS_BIND_CH_PREV_off && Channel_data[BIND_CH-1]>CHANNEL_MAX_COMMAND && Channel_data[THROTTLE]<(CHANNEL_MIN_100+50)) @@ -891,7 +894,7 @@ inline void tx_resume() { #ifdef TELEMETRY // Resume telemetry by enabling transmitter interrupt - if(!IS_TX_PAUSE_on) + if(IS_TX_PAUSE_off) { #ifdef ORANGE_TX cli() ; @@ -945,6 +948,7 @@ static void protocol_init() #endif TX_RX_PAUSE_off; TX_MAIN_PAUSE_off; + tx_resume(); #endif //Set global ID and rx_tx_addr @@ -1408,6 +1412,11 @@ void update_serial_data() memcpy((void*)(rx_ok_buff+4),(void*)(rx_ok_buff+4+11),11); // reassign channels 9-16 to 1-8 } #endif + #ifdef BONI // Extremely dangerous, do not enable this!!! This is really for a special case... + if(CH14_SW) + rx_ok_buff[2]=(rx_ok_buff[2]&0xF0)|((rx_ok_buff[2]+1)&0x0F); + #endif + if(rx_ok_buff[1]&0x20) //check range RANGE_FLAG_on; else @@ -1466,23 +1475,21 @@ void update_serial_data() failsafe=true; rx_ok_buff[0]&=0xFD; //remove the failsafe flag FAILSAFE_VALUES_on; //failsafe data has been received + debugln("Failsafe received"); } #endif - #ifdef SERIAL_DATA_ENABLE - bool data=false; - if(rx_ok_buff[0]&0x20) - { // Packet has additional data - data=true; - rx_ok_buff[0]&=0xDF; //remove the data flag - } - #endif - - #ifdef BONI - if(CH14_SW) - rx_ok_buff[2]=(rx_ok_buff[2]&0xF0)|((rx_ok_buff[2]+1)&0x0F); // Extremely dangerous, do not enable this!!! This is really for a special case... - #endif - + DISABLE_CH_MAP_off; + DISABLE_TELEM_off; + if(rx_len>26) // Additional protocol numbers and RX_Num available -> store them in rx_ok_buff[0] + { + rx_ok_buff[0]=(rx_ok_buff[26]&0xF0) | (rx_ok_buff[0]&0x0F); + if(rx_ok_buff[26]&0x08) + DISABLE_CH_MAP_on; + if(rx_ok_buff[26]&0x04) + DISABLE_TELEM_on; + } + if( (rx_ok_buff[0] != cur_protocol[0]) || ((rx_ok_buff[1]&0x5F) != (cur_protocol[1]&0x5F)) || ( (rx_ok_buff[2]&0x7F) != (cur_protocol[2]&0x7F) ) ) { // New model has been selected CHANGE_PROTOCOL_FLAG_on; //change protocol @@ -1494,10 +1501,12 @@ void update_serial_data() protocol=rx_ok_buff[1]&0x1F; //protocol no (0-31) if(!(rx_ok_buff[0]&1)) protocol+=32; //protocol no (0-63) - if(!(rx_ok_buff[0]&4)) - protocol+=64; //protocol no (0-127) + if(rx_len>26) + protocol|=rx_ok_buff[26]&0xC0; //protocol no (0-255) sub_protocol=(rx_ok_buff[2]>>4)& 0x07; //subprotocol no (0-7) bits 4-6 - RX_num=rx_ok_buff[2]& 0x0F; // rx_num bits 0-3 + RX_num=rx_ok_buff[2]& 0x0F; //rx_num no (0-15) + if(rx_len>26) + RX_num|=rx_ok_buff[26]&0x30; //rx_num no (0-63) } else if( ((rx_ok_buff[1]&0x80)!=0) && ((cur_protocol[1]&0x80)==0) ) // Bind flag has been set @@ -1521,7 +1530,7 @@ void update_serial_data() for(uint8_t i=0;i<3;i++) cur_protocol[i] = rx_ok_buff[i]; - // decode channel/failsafe values + // decode channel/failsafe values volatile uint8_t *p=rx_ok_buff+3; uint8_t dec=-3; for(uint8_t i=0;i27) + { // Data available for the current protocol + #ifdef SPORT_SEND + if(protocol==PROTO_FRSKYX && rx_len==35) + {//Protocol waiting for 8 bytes + #define BYTE_STUFF 0x7D + #define STUFF_MASK 0x20 + //debug("SPort_in: "); + SportData[SportTail]=0x7E; + SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1); + SportData[SportTail]=rx_ok_buff[27]&0x1F; + SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1); + for(uint8_t i=28;i<28+7;i++) { - #define BYTE_STUFF 0x7D - #define STUFF_MASK 0x20 - //TODO detect overrun of the buffer before writing... - //debug("SPort_in: "); - SportData[SportTail]=0x7E; - SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1); - SportData[SportTail]=rx_ok_buff[26]&0x1F; - SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1); - for(uint8_t i=27;i<27+7;i++) - { - if(rx_ok_buff[i]==BYTE_STUFF) - {//stuff - SportData[SportTail]=BYTE_STUFF; - SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1); - SportData[SportTail]=rx_ok_buff[i]^STUFF_MASK; - } - else - SportData[SportTail]=rx_ok_buff[i]; - //debug("%02X ",SportData[SportTail]); + if(rx_ok_buff[i]==BYTE_STUFF) + {//stuff + SportData[SportTail]=BYTE_STUFF; SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1); + SportData[SportTail]=rx_ok_buff[i]^STUFF_MASK; } - uint8_t used = SportTail; - if ( SportHead > SportTail ) - used += MAX_SPORT_BUFFER - SportHead ; else - used -= SportHead ; - if ( used >= MAX_SPORT_BUFFER-(MAX_SPORT_BUFFER>>2) ) - { - DATA_BUFFER_LOW_on; - SEND_MULTI_STATUS_on; //Send Multi Status ASAP to inform the TX - debugln("Low buf=%d,h=%d,t=%d",used,SportHead,SportTail); - } + SportData[SportTail]=rx_ok_buff[i]; + //debug("%02X ",SportData[SportTail]); + SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1); } - #endif - } - #endif // SERIAL_DATA_ENABLE + uint8_t used = SportTail; + if ( SportHead > SportTail ) + used += MAX_SPORT_BUFFER - SportHead ; + else + used -= SportHead ; + if ( used >= MAX_SPORT_BUFFER-(MAX_SPORT_BUFFER>>2) ) + { + DATA_BUFFER_LOW_on; + SEND_MULTI_STATUS_on; //Send Multi Status ASAP to inform the TX + debugln("Low buf=%d,h=%d,t=%d",used,SportHead,SportTail); + } + } + #endif //SPORT_SEND + } RX_DONOTUPDATE_off; #ifdef ORANGE_TX @@ -1592,7 +1598,9 @@ void update_serial_data() UCSR0B &= ~_BV(RXCIE0); // RX interrupt disable #endif if(IS_RX_MISSED_BUFF_on) // If the buffer is still valid - { memcpy((void*)rx_ok_buff,(const void*)rx_buff,RXBUFFER_SIZE);// Duplicate the buffer + { + rx_len=rx_idx; + memcpy((void*)rx_ok_buff,(const void*)rx_buff,rx_len);// Duplicate the buffer RX_FLAG_on; // data to be processed next time... RX_MISSED_BUFF_off; } @@ -1601,10 +1609,6 @@ void update_serial_data() #else UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable #endif - #ifdef FAILSAFE_ENABLE - if(failsafe) - debugln("RX_FS:%d,%d,%d,%d",Failsafe_data[0],Failsafe_data[1],Failsafe_data[2],Failsafe_data[3]); - #endif } void modules_reset() @@ -1940,7 +1944,6 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) ISR(USART_RX_vect) #endif { // RX interrupt - static uint8_t idx=0,len=26; #ifdef ORANGE_TX if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error #elif defined STM32_BOARD @@ -1951,69 +1954,53 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) if((UCSR0A&0x1C)==0) // Check frame error, data overrun and parity error #endif { // received byte is ok to process - if(idx==0||discard_frame==1) + if(rx_idx==0||discard_frame==1) { // Let's try to sync at this point - idx=0;discard_frame=0; RX_MISSED_BUFF_off; // If rx_buff was good it's not anymore... + rx_idx=0;discard_frame=0; rx_buff[0]=UDR0; - #ifdef SERIAL_DATA_ENABLE - #ifdef FAILSAFE_ENABLE - if((rx_buff[0]&0xD8)==0x50) // If 1st byte is 0x74, 0x75, 0x76, 0x77, 0x54, 0x55, 0x56 or 0x57 it looks ok - #else - if((rx_buff[0]&0xDA)==0x50) // If 1st byte is 0x74, 0x75, 0x54 or 0x55 it looks ok - #endif + #ifdef FAILSAFE_ENABLE + if((rx_buff[0]&0xFC)==0x54) // If 1st byte is 0x54, 0x55, 0x56 or 0x57 it looks ok #else - #ifdef FAILSAFE_ENABLE - if((rx_buff[0]&0xF8)==0x50) // If 1st byte is 0x58, 0x54, 0x55, 0x56 or 0x57 it looks ok - #else - if((rx_buff[0]&0xFA)==0x50) // If 1st byte is 0x54 or 0x55 it looks ok - #endif + if((rx_buff[0]&0xFE)==0x54) // If 1st byte is 0x54 or 0x55 it looks ok #endif { - #ifdef SERIAL_DATA_ENABLE - if(rx_buff[0]&0x20) - len=34; - else - #endif - len=26; TX_RX_PAUSE_on; tx_pause(); #if defined STM32_BOARD - TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15??s=1.5 byte + TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15us=1.5 byte TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag TIMER2_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer2/Comp2 interrupt #else - OCR1B = TCNT1 + 300; // Next byte should show up within 15??s=1.5 byte + OCR1B = TCNT1 + 300; // Next byte should show up within 15us=1.5 byte TIFR1 = OCF1B_bm ; // clear OCR1B match flag SET_TIMSK1_OCIE1B ; // enable interrupt on compare B match #endif - idx++; + rx_idx++; } } else { - rx_buff[idx++]=UDR0; // Store received byte - #if defined STM32_BOARD - TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15??s=1.5 byte - #else - OCR1B = TCNT1 + 300; // Next byte should show up within 15??s=1.5 byte - #endif - if(idx>=len) - { // A full frame has been received - if(!IS_RX_DONOTUPDATE_on) - { //Good frame received and main is not working on the buffer - memcpy((void*)rx_ok_buff,(const void*)rx_buff,len);// Duplicate the buffer - RX_FLAG_on; // Flag for main to process servo data - } - else - RX_MISSED_BUFF_on; // Notify that rx_buff is good - discard_frame=1; // Start again + if(rx_idx>=RXBUFFER_SIZE) + { + discard_frame=1; // Too many bytes being received... + debugln("RX frame too long"); + } + else + { + rx_buff[rx_idx++]=UDR0; // Store received byte + #if defined STM32_BOARD + TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15us=1.5 byte + #else + OCR1B = TCNT1 + 300; // Next byte should show up within 15us=1.5 byte + #endif } } } else { - idx=UDR0; // Dummy read + rx_idx=UDR0; // Dummy read + rx_idx=0; discard_frame=1; // Error encountered discard full frame... debugln("Bad frame RX"); } @@ -2042,13 +2029,26 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) ISR(TIMER1_COMPB_vect, ISR_NOBLOCK ) #endif { // Timer1 compare B interrupt + if(rx_idx>=26) + { // A full frame has been received + if(!IS_RX_DONOTUPDATE_on) + { //Good frame received and main is not working on the buffer + rx_len=rx_idx; + memcpy((void*)rx_ok_buff,(const void*)rx_buff,rx_idx); // Duplicate the buffer + RX_FLAG_on; // Flag for main to process servo data + } + else + RX_MISSED_BUFF_on; // Notify that rx_buff is good + } + else + debugln("RX frame too short"); discard_frame=1; #ifdef STM32_BOARD TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt - debugln("Bad frame timer"); #else CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match #endif + TX_RX_PAUSE_off; tx_resume(); } #endif //ENABLE_SERIAL diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 7487203..3b8d421 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -720,19 +720,18 @@ void TelemetryUpdate() t -= h ; if ( t < 32 ) { + debugln("TEL_BUF_FULL"); return ; } #endif - #if ( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) + #if defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) + uint32_t now = millis(); + if (IS_SEND_MULTI_STATUS_on || ((now - lastMulti) > MULTI_TIME)) { - uint32_t now = millis(); - if (IS_SEND_MULTI_STATUS_on || (now - lastMulti) > MULTI_TIME) - { - multi_send_status(); - SEND_MULTI_STATUS_off; - lastMulti = now; - return; - } + multi_send_status(); + SEND_MULTI_STATUS_off; + lastMulti = now; + return; } #endif diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index 93ccad4..fa2f13f 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -315,10 +315,6 @@ #endif #endif -#ifdef SPORT_SEND - #define SERIAL_DATA_ENABLE -#endif - //Make sure TX is defined correctly #ifndef AILERON #error You must select a correct channel order. From 240608051526de1bbb9df47814f5c89cd41d485c Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 7 Oct 2019 23:27:04 +0200 Subject: [PATCH 09/65] Update Protocols_Details.md --- Protocols_Details.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Protocols_Details.md b/Protocols_Details.md index 4ac7f5d..f1ad518 100644 --- a/Protocols_Details.md +++ b/Protocols_Details.md @@ -84,6 +84,7 @@ CFlie|38|CFlie||||||||NRF24L01| [ESky150](Protocols_Details.md#ESKY150---35)|35|ESKY150||||||||NRF24L01| [Flysky](Protocols_Details.md#FLYSKY---1)|1|Flysky|V9x9|V6x6|V912|CX20||||A7105| [Flysky AFHDS2A](Protocols_Details.md#FLYSKY-AFHDS2A---28)|28|PWM_IBUS|PPM_IBUS|PWM_SBUS|PPM_SBUS|||||A7105| +[Flysky AFHDS2A RX](Protocols_Details.md#FLYSKY-AFHDS2A-RX---56)|56|||||||||A7105| [Flyzone](Protocols_Details.md#FLYZONE---53)|53|FZ410||||||||A7105| [FQ777](Protocols_Details.md#FQ777---23)|23|FQ777||||||||NRF24L01|SSV7241 [FrskyD](Protocols_Details.md#FRSKYD---3)|3|FrskyD||||||||CC2500| @@ -169,7 +170,7 @@ Telemetry enabled protocol: Option is used to change the servo refresh rate. A value of 0 gives 50Hz (min), 70 gives 400Hz (max). Specific refresh rate value can be calculated like this option=(refresh_rate-50)/5. -**RX_Num is used to give a number a given RX. You must use a different RX_Num per RX. A maximum of 16 AFHDS2A RXs are supported.** +**RX_Num is used to give a number a given RX. You must use a different RX_Num per RX. A maximum of 64 AFHDS2A RXs are supported.** OpenTX suggested RSSI alarm threshold settings (Telemetry tab): Low=15, Critical=12. @@ -188,6 +189,15 @@ Note that the RX ouput will be AETR whatever the input channel order is. ### Sub_protocol PWM_SBUS - *2* ### Sub_protocol PPM_SBUS - *3* +## FLYSKY AFHDS2A RX - *56* +The Flysky AFHDS2A receiver protocol enables master/slave trainning, separate access from 2 different radios to the same model,... + +Available in OpenTX 2.3.2, Trainer Mode Master/Multi + +Extended limits supported + +Low power: enable/disable the LNA stage on the RF component to use depending on the distance with the TX. + ## FLYZONE - *53* Models using the Flyzone FZ-410 TX: Fokker D.VII Micro EP RTF @@ -345,6 +355,8 @@ CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8 ## FRSKYX_RX - *55* The FrSkyX receiver protocol enables master/slave trainning, separate access from 2 different radios to the same model,... +Available in OpenTX 2.3.2, Trainer Mode Master/Multi + Extended limits supported Option for this protocol corresponds to fine frequency tuning. From b0749a1bee957849b8660f975f7ec53ca6a60434 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 7 Oct 2019 23:30:17 +0200 Subject: [PATCH 10/65] DSM TH_KILL channel 14 --- Protocols_Details.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Protocols_Details.md b/Protocols_Details.md index f1ad518..4a9d5c0 100644 --- a/Protocols_Details.md +++ b/Protocols_Details.md @@ -549,7 +549,7 @@ Notes: - RX output will match the Spektrum standard TAER independently of the input configuration AETR, RETA... - RX output will match the Spektrum standard throw (1500µs +/- 400µs -> 1100..1900µs) for a 100% input. This is true for both Serial and PPM input. For PPM, make sure the end points PPM_MIN_100 and PPM_MAX_100 in _config.h are matching your TX ouput. The maximum ouput is 1000..2000µs based on an input of 125%. - If you want to override the above and get maximum throw (old way) uncomment in _config.h the line #define DSM_MAX_THROW . In this mode to achieve standard throw use a channel weight of 84%. - - TH_KILL is a feature which is enabled on channel 14 by default (can be disabled/changed) in the _config.h file. Some models (X-Vert, Blade 230S...) require a special position to instant stop the motor(s). If the channel 15 is above -50% the throttle is untouched but if it is between -50% and -100%, the throttle output will be forced between -100% and -150%. For example, a value of -80% applied on channel 14 will instantly kill the motors on the X-Vert. + - TH_KILL is a feature which is enabled on channel 14 by default (can be disabled/changed) in the _config.h file. Some models (X-Vert, Blade 230S...) require a special position to instant stop the motor(s). If the channel 14 is above -50% the throttle is untouched but if it is between -50% and -100%, the throttle output will be forced between -100% and -150%. For example, a value of -80% applied on channel 14 will instantly kill the motors on the X-Vert. ### Sub_protocol DSM2_22 - *0* DSM2, Resolution 1024, refresh rate 22ms From 897c8b6ec5a77b4a819cbe82f31960a6e126d175 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 8 Oct 2019 00:07:23 +0200 Subject: [PATCH 11/65] Remove "Disable channel mapping" --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 5865f25..2cb00b8 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 8 +#define VERSION_PATCH_LEVEL 9 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 82039df..5bc264f 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -130,10 +130,10 @@ uint8_t num_ch; #endif //Channel mapping for protocols -const uint8_t CH_AETR[]={AILERON, ELEVATOR, THROTTLE, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; -const uint8_t CH_TAER[]={THROTTLE, AILERON, ELEVATOR, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; -const uint8_t CH_RETA[]={RUDDER, ELEVATOR, THROTTLE, AILERON, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; -const uint8_t CH_EATR[]={ELEVATOR, AILERON, THROTTLE, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; +uint8_t CH_AETR[]={AILERON, ELEVATOR, THROTTLE, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; +uint8_t CH_TAER[]={THROTTLE, AILERON, ELEVATOR, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; +uint8_t CH_RETA[]={RUDDER, ELEVATOR, THROTTLE, AILERON, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; +uint8_t CH_EATR[]={ELEVATOR, AILERON, THROTTLE, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; // Mode_select variables uint8_t mode_select; @@ -1479,13 +1479,13 @@ void update_serial_data() } #endif - DISABLE_CH_MAP_off; + //DISABLE_CH_MAP_off; DISABLE_TELEM_off; - if(rx_len>26) // Additional protocol numbers and RX_Num available -> store them in rx_ok_buff[0] - { - rx_ok_buff[0]=(rx_ok_buff[26]&0xF0) | (rx_ok_buff[0]&0x0F); - if(rx_ok_buff[26]&0x08) - DISABLE_CH_MAP_on; + if(rx_len>26) + {//Additional flag received at the end + rx_ok_buff[0]=(rx_ok_buff[26]&0xF0) | (rx_ok_buff[0]&0x0F); // Additional protocol numbers and RX_Num available -> store them in rx_ok_buff[0] + //if(rx_ok_buff[26]&0x08) + // DISABLE_CH_MAP_on; if(rx_ok_buff[26]&0x04) DISABLE_TELEM_on; } From 0b19fa0bdf1e5b4de5b16770e22a3cfa7996ea17 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 8 Oct 2019 18:52:47 +0200 Subject: [PATCH 12/65] Disable channel mapping + telemetry inversion --- Multiprotocol/DSM_cyrf6936.ino | 4 +- Multiprotocol/FlySky_a7105.ino | 2 +- Multiprotocol/Hisky_nrf24l01.ino | 4 +- Multiprotocol/Multiprotocol.h | 11 +++-- Multiprotocol/Multiprotocol.ino | 69 ++++++++++++++++++++++++++++---- Multiprotocol/SFHSS_cc2500.ino | 4 +- Multiprotocol/SLT_nrf24l01.ino | 2 +- Multiprotocol/Telemetry.ino | 40 ++++++++++-------- 8 files changed, 101 insertions(+), 35 deletions(-) diff --git a/Multiprotocol/DSM_cyrf6936.ino b/Multiprotocol/DSM_cyrf6936.ino index fc18528..457d616 100644 --- a/Multiprotocol/DSM_cyrf6936.ino +++ b/Multiprotocol/DSM_cyrf6936.ino @@ -273,8 +273,8 @@ static void __attribute__((unused)) DSM_build_data_packet(uint8_t upper) /* Spektrum own remotes transmit normal values during bind and actually use this (e.g. Nano CP X) to select the transmitter mode (e.g. computer vs non-computer radio), so always send normal output */ #ifdef DSM_THROTTLE_KILL_CH - if(CH_TAER[idx]==THROTTLE && kill_ch<=604) - {//Activate throttle kill only if DSM_THROTTLE_KILL_CH below -50% + if(idx==CH1 && kill_ch<=604) + {//Activate throttle kill only if channel is throttle and DSM_THROTTLE_KILL_CH below -50% if(kill_ch>8)&0xFF; //high byte of servo timing(1000-2000us) diff --git a/Multiprotocol/Hisky_nrf24l01.ino b/Multiprotocol/Hisky_nrf24l01.ino index 2596c9a..519fbb2 100644 --- a/Multiprotocol/Hisky_nrf24l01.ino +++ b/Multiprotocol/Hisky_nrf24l01.ino @@ -123,8 +123,8 @@ static void __attribute__((unused)) build_ch_data() for (i = 0; i< 8; i++) { j=CH_AETR[i]; temp=convert_channel_16b_limit(j,0,1000); - if (j == THROTTLE) // It is clear that hisky's throttle stick is made reversely, so I adjust it here on purpose - temp = 1000 -temp; + if (j == CH3) // It is clear that hisky's throttle stick is made reversely, so I adjust it here on purpose + temp = 1000 - temp; if (j == CH7) temp = temp < 400 ? 0 : 3; // Gyro mode, 0 - 6 axis, 3 - 3 axis packet[i] = (uint8_t)(temp&0xFF); diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 2cb00b8..26c4430 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 9 +#define VERSION_PATCH_LEVEL 10 //****************** // Protocols @@ -829,11 +829,13 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- Values are concatenated to fit in 22 bytes like in SBUS protocol. Failsafe values have exactly the same range/values than normal channels except the extremes where 0=no pulse, 2047=hold. If failsafe is not set or RX then failsafe packets should not be sent. - Stream[26] = sub_protocol bits 6 & 7|RxNum bits 4 & 5|Disable_CH_Mapping 3|Disable_Telemetry 2|future use 1|future use 0; + Stream[26] = sub_protocol bits 6 & 7|RxNum bits 4 & 5|Disable_Telemetry 3|Disable_CH_Mapping 2|Future_Use 1|Telem_Invert 0; sub_protocol is 0..255 (bits 0..5 + bits 6..7) RxNum value is 0..63 (bits 0..3 + bits 4..5) - Disable_CH_Mapping => 0x08 0=enable, 1=disable - Disable_Telemetry => 0x04 0=enable, 1=disable + Disable_Telemetry => 0x08 0=enable, 1=disable + Disable_CH_Mapping => 0x04 0=enable, 1=disable + Future_Use => 0x02 0= , 1= + Telem_Invert => 0x01 0=normal, 1=invert Stream[27.. 36] = between 0 and 9 bytes for additional protocol data */ /* @@ -855,6 +857,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- 0x08 = Module is in binding mode 0x10 = Module waits a bind event to load the protocol 0x20 = Current protocol supports failsafe + 0x40 = Current protocol supports disable channel mapping 0x80 = Data buffer is almost full [3] major [4] minor diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 5bc264f..8df03c1 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -132,7 +132,7 @@ uint8_t num_ch; //Channel mapping for protocols uint8_t CH_AETR[]={AILERON, ELEVATOR, THROTTLE, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; uint8_t CH_TAER[]={THROTTLE, AILERON, ELEVATOR, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; -uint8_t CH_RETA[]={RUDDER, ELEVATOR, THROTTLE, AILERON, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; +//uint8_t CH_RETA[]={RUDDER, ELEVATOR, THROTTLE, AILERON, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; uint8_t CH_EATR[]={ELEVATOR, AILERON, THROTTLE, RUDDER, CH5, CH6, CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15, CH16}; // Mode_select variables @@ -1402,6 +1402,15 @@ static void protocol_init() void update_serial_data() { + static bool prev_ch_mapping=false; + #ifdef TELEMETRY + #ifdef INVERT_TELEMETRY + static bool prev_inv_telem=true; + #else + static bool prev_inv_telem=false; + #endif + #endif + RX_DONOTUPDATE_on; RX_FLAG_off; //data is being processed @@ -1473,21 +1482,67 @@ void update_serial_data() if(rx_ok_buff[0]&0x02) { // Packet contains failsafe instead of channels failsafe=true; - rx_ok_buff[0]&=0xFD; //remove the failsafe flag - FAILSAFE_VALUES_on; //failsafe data has been received + rx_ok_buff[0]&=0xFD; // Remove the failsafe flag + FAILSAFE_VALUES_on; // Failsafe data has been received debugln("Failsafe received"); } #endif - //DISABLE_CH_MAP_off; + DISABLE_CH_MAP_off; DISABLE_TELEM_off; if(rx_len>26) {//Additional flag received at the end rx_ok_buff[0]=(rx_ok_buff[26]&0xF0) | (rx_ok_buff[0]&0x0F); // Additional protocol numbers and RX_Num available -> store them in rx_ok_buff[0] - //if(rx_ok_buff[26]&0x08) - // DISABLE_CH_MAP_on; - if(rx_ok_buff[26]&0x04) + if(rx_ok_buff[26]&0x08) DISABLE_TELEM_on; + if(rx_ok_buff[26]&0x04) + DISABLE_CH_MAP_on; + #if defined TELEMETRY + if((rx_ok_buff[26]&0x01) ^ prev_inv_telem) + { //value changed + if(rx_ok_buff[26]&0x01) + { // Invert telemetry + debugln("Invert telem %d,%d",rx_ok_buff[26]&0x01,prev_inv_telem); + #ifdef ORANGE_TX + PORTC.PIN3CTRL |= 0x40 ; + #endif + #ifdef STM32_BOARD + TX_INV_on; + RX_INV_on; + #endif + } + else + { // Normal telemetry + debugln("Normal telem %d,%d",rx_ok_buff[26]&0x01,prev_inv_telem); + #ifdef ORANGE_TX + PORTC.PIN3CTRL &= 0xBF ; + #endif + #ifdef STM32_BOARD + TX_INV_off; + RX_INV_off; + #endif + } + prev_inv_telem=rx_ok_buff[26]&0x01; + } + #endif + } + + if(prev_ch_mapping!=IS_DISABLE_CH_MAP_on) + { + prev_ch_mapping=IS_DISABLE_CH_MAP_on; + if(IS_DISABLE_CH_MAP_on) + { + for(uint8_t i=0;i<4;i++) + CH_AETR[i]=CH_TAER[i]=CH_EATR[i]=i; + debugln("DISABLE_CH_MAP_on"); + } + else + { + CH_AETR[0]=AILERON;CH_AETR[1]=ELEVATOR;CH_AETR[2]=THROTTLE;CH_AETR[3]=RUDDER; + CH_TAER[0]=THROTTLE;CH_TAER[1]=AILERON;CH_TAER[2]=ELEVATOR;CH_TAER[3]=RUDDER; + CH_EATR[0]=ELEVATOR;CH_EATR[1]=AILERON;CH_EATR[2]=THROTTLE;CH_EATR[3]=RUDDER; + debugln("DISABLE_CH_MAP_off"); + } } if( (rx_ok_buff[0] != cur_protocol[0]) || ((rx_ok_buff[1]&0x5F) != (cur_protocol[1]&0x5F)) || ( (rx_ok_buff[2]&0x7F) != (cur_protocol[2]&0x7F) ) ) diff --git a/Multiprotocol/SFHSS_cc2500.ino b/Multiprotocol/SFHSS_cc2500.ino index 7f9dbd9..8588f00 100644 --- a/Multiprotocol/SFHSS_cc2500.ino +++ b/Multiprotocol/SFHSS_cc2500.ino @@ -173,8 +173,8 @@ static void __attribute__((unused)) SFHSS_build_data_packet() else { //Use channel value ch[i]=(ch[i]>>1)+2560; - if(CH_AETR[ch_offset+i]==THROTTLE && ch[i]<3072) // Throttle - ch[i]+=1024; + //if(IS_DISABLE_CH_MAP_off && ch_offset+i==CH3 && ch[i]<3072) // Throttle + // ch[i]+=1024; } } } diff --git a/Multiprotocol/SLT_nrf24l01.ino b/Multiprotocol/SLT_nrf24l01.ino index 3ce909f..11ee902 100644 --- a/Multiprotocol/SLT_nrf24l01.ino +++ b/Multiprotocol/SLT_nrf24l01.ino @@ -141,7 +141,7 @@ static void __attribute__((unused)) SLT_build_packet() for (uint8_t i = 0; i < 4; ++i) { uint16_t v = convert_channel_10b(CH_AETR[i]); - if(sub_protocol>SLT_V2 && (CH_AETR[i]==THROTTLE || CH_AETR[i]==ELEVATOR) ) + if(sub_protocol>SLT_V2 && (i==CH1 || i==CH3) ) v=1023-v; // reverse throttle and elevator channels for Q100/Q200/MR100 protocols packet[i] = v; e = (e >> 2) | (uint8_t) ((v >> 2) & 0xC0); diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 3b8d421..5dca7dd 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -94,23 +94,31 @@ static void multi_send_status() else if (IS_BIND_IN_PROGRESS) flags |= 0x08; - #ifdef FAILSAFE_ENABLE - //Is failsafe supported? - switch (protocol) - { - case PROTO_HISKY: - if(sub_protocol!=HK310) - break; - case PROTO_AFHDS2A: - case PROTO_DEVO: - case PROTO_SFHSS: - case PROTO_WK2x01: - case PROTO_FRSKYX: - flags |= 0x20; //Yes - default: + switch (protocol) + { + case PROTO_HISKY: + if(sub_protocol!=HK310) break; - } - #endif + case PROTO_AFHDS2A: + case PROTO_DEVO: + case PROTO_SFHSS: + case PROTO_WK2x01: + #ifdef FAILSAFE_ENABLE + flags |= 0x20; //Failsafe supported + #endif + case PROTO_DSM: + case PROTO_SLT: + case PROTO_FLYSKY: + case PROTO_ESKY: + case PROTO_J6PRO: + flags |= 0x40; //Disable_ch_mapping supported + break; + case PROTO_FRSKYX: + #ifdef FAILSAFE_ENABLE + flags |= 0x20; //Failsafe supported + #endif + break; + } if(IS_DATA_BUFFER_LOW_on) flags |= 0x80; } From 5c7f997e7ab0032a4ecb3b502a65ebabe6f01e31 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Wed, 9 Oct 2019 11:58:50 +0200 Subject: [PATCH 13/65] Send channel order in MULTI_TELEMETRY --- Multiprotocol/Multiprotocol.h | 20 ++++++++++---------- Multiprotocol/Multiprotocol.ino | 12 ++++++------ Multiprotocol/Telemetry.ino | 5 ++++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 26c4430..d46547d 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 10 +#define VERSION_PATCH_LEVEL 11 //****************** // Protocols @@ -829,13 +829,13 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- Values are concatenated to fit in 22 bytes like in SBUS protocol. Failsafe values have exactly the same range/values than normal channels except the extremes where 0=no pulse, 2047=hold. If failsafe is not set or RX then failsafe packets should not be sent. - Stream[26] = sub_protocol bits 6 & 7|RxNum bits 4 & 5|Disable_Telemetry 3|Disable_CH_Mapping 2|Future_Use 1|Telem_Invert 0; + Stream[26] = sub_protocol bits 6 & 7|RxNum bits 4 & 5|Future_Use 3|Telem_Invert 2|Disable_Telemetry 1|Disable_CH_Mapping 0 sub_protocol is 0..255 (bits 0..5 + bits 6..7) RxNum value is 0..63 (bits 0..3 + bits 4..5) - Disable_Telemetry => 0x08 0=enable, 1=disable - Disable_CH_Mapping => 0x04 0=enable, 1=disable - Future_Use => 0x02 0= , 1= - Telem_Invert => 0x01 0=normal, 1=invert + Telemetry_Invert => 0x08 0=normal, 1=invert + Future_Use => 0x04 0= , 1= + Disable_Telemetry => 0x02 0=enable, 1=disable + Disable_CH_Mapping => 0x01 0=enable, 1=disable Stream[27.. 36] = between 0 and 9 bytes for additional protocol data */ /* @@ -896,16 +896,16 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- 0x08 = Module is in binding mode 0x10 = Module waits a bind event to load the protocol 0x20 = Current protocol supports failsafe + 0x40 = Current protocol supports disable channel mapping 0x80 = Data buffer is almost full [5] major [6] minor [7] revision - [8] patchlevel, - version of multi code, should be displayed as major.minor.revision.patchlevel - + [8] patchlevel + version of multi code, should be displayed as major.minor.revision.patchlevel + [9] channel order: CH4|CH3|CH2|CH1 with CHx value A=0,E=1,T=2,R=3 more information can be added by specifing a longer length of the type, the TX will just ignore these bytes - Type 0x02 Frksy S.port telemetry Type 0x03 Frsky Hub telemetry diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 8df03c1..4fd1295 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -1493,14 +1493,14 @@ void update_serial_data() if(rx_len>26) {//Additional flag received at the end rx_ok_buff[0]=(rx_ok_buff[26]&0xF0) | (rx_ok_buff[0]&0x0F); // Additional protocol numbers and RX_Num available -> store them in rx_ok_buff[0] - if(rx_ok_buff[26]&0x08) + if(rx_ok_buff[26]&0x02) DISABLE_TELEM_on; - if(rx_ok_buff[26]&0x04) + if(rx_ok_buff[26]&0x01) DISABLE_CH_MAP_on; #if defined TELEMETRY - if((rx_ok_buff[26]&0x01) ^ prev_inv_telem) + if(((rx_ok_buff[26]&0x08)!=0) ^ prev_inv_telem) { //value changed - if(rx_ok_buff[26]&0x01) + if(rx_ok_buff[26]&0x08) { // Invert telemetry debugln("Invert telem %d,%d",rx_ok_buff[26]&0x01,prev_inv_telem); #ifdef ORANGE_TX @@ -1512,7 +1512,7 @@ void update_serial_data() #endif } else - { // Normal telemetry + { // Normal telemetry debugln("Normal telem %d,%d",rx_ok_buff[26]&0x01,prev_inv_telem); #ifdef ORANGE_TX PORTC.PIN3CTRL &= 0xBF ; @@ -1522,7 +1522,7 @@ void update_serial_data() RX_INV_off; #endif } - prev_inv_telem=rx_ok_buff[26]&0x01; + prev_inv_telem=rx_ok_buff[26]&0x08; } #endif } diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 5dca7dd..69a42de 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -78,7 +78,7 @@ static void multi_send_header(uint8_t type, uint8_t len) static void multi_send_status() { - multi_send_header(MULTI_TELEMETRY_STATUS, 5); + multi_send_header(MULTI_TELEMETRY_STATUS, 6); // Build flags uint8_t flags=0; @@ -129,6 +129,9 @@ static void multi_send_status() Serial_write(VERSION_MINOR); Serial_write(VERSION_REVISION); Serial_write(VERSION_PATCH_LEVEL); + + // Channel order + Serial_write(RUDDER<<6|THROTTLE<<4|ELEVATOR<<2|AILERON); } #endif From cd7ede006c966a1c8803d20db131136742884331 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 10 Oct 2019 23:12:09 +0200 Subject: [PATCH 14/65] Sync radio -> module --- Multiprotocol/AFHDS2A_a7105.ino | 1 + Multiprotocol/ASSAN_nrf24l01.ino | 1 + Multiprotocol/BUGSMINI_nrf24l01.ino | 1 + Multiprotocol/Bayang_nrf24l01.ino | 3 ++ Multiprotocol/Bugs_a7105.ino | 1 + Multiprotocol/CABELL_nrf224l01.ino | 3 +- Multiprotocol/CFlie_nrf24l01.ino | 7 ++-- Multiprotocol/CG023_nrf24l01.ino | 3 ++ Multiprotocol/CX10_nrf24l01.ino | 1 + Multiprotocol/Corona_cc2500.ino | 1 + Multiprotocol/DM002_nrf24l01.ino | 3 ++ Multiprotocol/DSM_cyrf6936.ino | 1 + Multiprotocol/Devo_cyrf6936.ino | 1 + Multiprotocol/E01X_nrf24l01.ino | 3 ++ Multiprotocol/ESky150_nrf24l01.ino | 3 ++ Multiprotocol/ESky_nrf24l01.ino | 3 ++ Multiprotocol/FQ777_nrf24l01.ino | 3 ++ Multiprotocol/FY326_nrf24l01.ino | 1 + Multiprotocol/FlySky_a7105.ino | 11 ++--- Multiprotocol/Flyzone_a7105.ino | 1 + Multiprotocol/FrSkyD_cc2500.ino | 1 + Multiprotocol/FrSkyV_cc2500.ino | 1 + Multiprotocol/FrSkyX_cc2500.ino | 1 + Multiprotocol/GD00X_nrf24l01.ino | 1 + Multiprotocol/GW008_nrf24l01.ino | 1 + Multiprotocol/H8_3D_nrf24l01.ino | 3 ++ Multiprotocol/Hisky_nrf24l01.ino | 2 + Multiprotocol/Hitec_cc2500.ino | 1 + Multiprotocol/Hontai_nrf24l01.ino | 6 ++- Multiprotocol/Hubsan_a7105.ino | 1 + Multiprotocol/J6Pro_cyrf6936.ino | 3 +- Multiprotocol/KF606_nrf24l01.ino | 1 + Multiprotocol/KN_nrf24l01.ino | 3 ++ Multiprotocol/MJXQ_nrf24l01.ino | 3 ++ Multiprotocol/MT99xx_nrf24l01.ino | 3 ++ Multiprotocol/Multiprotocol.h | 19 +++++++-- Multiprotocol/Multiprotocol.ino | 33 ++++++++++----- Multiprotocol/NCC1701_nrf24l01.ino | 1 + Multiprotocol/POTENSIC_nrf24l01.ino | 1 + Multiprotocol/Q303_nrf24l01.ino | 3 ++ Multiprotocol/Redpine_cc2500.ino | 11 +++-- Multiprotocol/SFHSS_cc2500.ino | 1 + Multiprotocol/SHENQI_nrf24l01.ino | 4 ++ Multiprotocol/SLT_nrf24l01.ino | 1 + Multiprotocol/Symax_nrf24l01.ino | 1 + Multiprotocol/TRAXXAS_cyrf6936.ino | 1 + Multiprotocol/Telemetry.ino | 63 +++++++++++++++++++++++++++-- Multiprotocol/V2X2_nrf24l01.ino | 1 + Multiprotocol/V761_nrf24l01.ino | 1 + Multiprotocol/V911S_nrf24l01.ino | 3 ++ Multiprotocol/Validate.h | 8 ++++ Multiprotocol/WFLY_cyrf6936.ino | 1 + Multiprotocol/WK2x01_cyrf6936.ino | 1 + Multiprotocol/YD717_nrf24l01.ino | 3 ++ Multiprotocol/ZSX_nrf24l01.ino | 1 + Multiprotocol/_Config.h | 13 +++--- 56 files changed, 216 insertions(+), 38 deletions(-) diff --git a/Multiprotocol/AFHDS2A_a7105.ino b/Multiprotocol/AFHDS2A_a7105.ino index 91d171d..5456c77 100644 --- a/Multiprotocol/AFHDS2A_a7105.ino +++ b/Multiprotocol/AFHDS2A_a7105.ino @@ -320,6 +320,7 @@ uint16_t ReadAFHDS2A() packet_type = AFHDS2A_PACKET_STICKS; phase = AFHDS2A_DATA; case AFHDS2A_DATA: + telemetry_set_input_sync(3850); AFHDS2A_build_packet(packet_type); if((A7105_ReadReg(A7105_00_MODE) & 0x01)) // Check if something has been received... data_rx=0; diff --git a/Multiprotocol/ASSAN_nrf24l01.ino b/Multiprotocol/ASSAN_nrf24l01.ino index 4504654..ce1648d 100644 --- a/Multiprotocol/ASSAN_nrf24l01.ino +++ b/Multiprotocol/ASSAN_nrf24l01.ino @@ -127,6 +127,7 @@ uint16_t ASSAN_callback() phase=ASSAN_DATA2; return 2000; case ASSAN_DATA2: + telemetry_set_input_sync(12000); case ASSAN_DATA3: ASSAN_send_packet(); phase++; // DATA 3 or 4 diff --git a/Multiprotocol/BUGSMINI_nrf24l01.ino b/Multiprotocol/BUGSMINI_nrf24l01.ino index 92cbb35..43fa1b0 100644 --- a/Multiprotocol/BUGSMINI_nrf24l01.ino +++ b/Multiprotocol/BUGSMINI_nrf24l01.ino @@ -299,6 +299,7 @@ uint16_t BUGSMINI_callback() phase = BUGSMINI_BIND1; return BUGSMINI_PACKET_INTERVAL - BUGSMINI_WRITE_WAIT; case BUGSMINI_DATA1: + telemetry_set_input_sync(BUGSMINI_PACKET_INTERVAL); if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) { // RX fifo data ready => read only 12 bytes to not overwrite channel change flag XN297_ReadPayload(packet, 12); diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index 089fca9..f31c4a5 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -283,7 +283,10 @@ uint16_t BAYANG_callback() if(IS_BIND_DONE) { if(packet_count==0) + { + telemetry_set_input_sync((option & BAYANG_OPTION_FLAG_TELEMETRY)?5*BAYANG_PACKET_PERIOD:2*BAYANG_PACKET_PERIOD); BAYANG_send_packet(0); + } packet_count++; #ifdef BAYANG_HUB_TELEMETRY if (option & BAYANG_OPTION_FLAG_TELEMETRY) diff --git a/Multiprotocol/Bugs_a7105.ino b/Multiprotocol/Bugs_a7105.ino index 6a108db..474e110 100644 --- a/Multiprotocol/Bugs_a7105.ino +++ b/Multiprotocol/Bugs_a7105.ino @@ -385,6 +385,7 @@ uint16_t ReadBUGS(void) break; case BUGS_DATA_1: + telemetry_set_input_sync(BUGS_PACKET_PERIOD); A7105_SetPower(); BUGS_build_packet(0); A7105_WriteReg(A7105_03_FIFOI, BUGS_FIFO_SIZE_TX); diff --git a/Multiprotocol/CABELL_nrf224l01.ino b/Multiprotocol/CABELL_nrf224l01.ino index ce48808..e778405 100644 --- a/Multiprotocol/CABELL_nrf224l01.ino +++ b/Multiprotocol/CABELL_nrf224l01.ino @@ -406,9 +406,10 @@ uint16_t CABELL_callback() if (IS_BIND_DONE) { CABELL_send_packet(0); // packet_period is set/adjusted in CABELL_send_packet + telemetry_set_input_sync(packet_period); return packet_period; } - if (bind_counter == 0) + else if (bind_counter == 0) { BIND_DONE; CABELL_init(); // non-bind address diff --git a/Multiprotocol/CFlie_nrf24l01.ino b/Multiprotocol/CFlie_nrf24l01.ino index b632345..9efa1cb 100644 --- a/Multiprotocol/CFlie_nrf24l01.ino +++ b/Multiprotocol/CFlie_nrf24l01.ino @@ -97,7 +97,7 @@ static inline uint8_t crtp_create_header(uint8_t port, uint8_t channel) #define TX_ADDR_SIZE 5 // Timeout for callback in uSec, 10ms=10000us for Crazyflie -#define PACKET_PERIOD 10000 +#define CFLIE_PACKET_PERIOD 10000 #define MAX_PACKET_SIZE 32 // CRTP is 32 bytes @@ -781,7 +781,8 @@ static uint16_t cflie_callback() break; case CFLIE_DATA: - // if (Model.proto_opts[PROTOOPTS_TELEMETRY] == TELEM_ON_CRTPLOG) { + telemetry_set_input_sync(CFLIE_PACKET_PERIOD); + // if (Model.proto_opts[PROTOOPTS_TELEMETRY] == TELEM_ON_CRTPLOG) { // update_telemetry_crtplog(); // } else if (Model.proto_opts[PROTOOPTS_TELEMETRY] == TELEM_ON_ACKPKT) { // update_telemetry_ackpkt(); @@ -792,7 +793,7 @@ static uint16_t cflie_callback() send_cmd_packet(); break; } - return PACKET_PERIOD; // Packet at standard protocol interval + return CFLIE_PACKET_PERIOD; // Packet at standard protocol interval } // Generate address to use from TX id and manufacturer id (STM32 unique id) diff --git a/Multiprotocol/CG023_nrf24l01.ino b/Multiprotocol/CG023_nrf24l01.ino index 77f4509..beb667c 100644 --- a/Multiprotocol/CG023_nrf24l01.ino +++ b/Multiprotocol/CG023_nrf24l01.ino @@ -138,7 +138,10 @@ static void __attribute__((unused)) CG023_init() uint16_t CG023_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(packet_period); CG023_send_packet(0); + } else { if (bind_counter == 0) diff --git a/Multiprotocol/CX10_nrf24l01.ino b/Multiprotocol/CX10_nrf24l01.ino index 4f98d44..96a7cc2 100644 --- a/Multiprotocol/CX10_nrf24l01.ino +++ b/Multiprotocol/CX10_nrf24l01.ino @@ -229,6 +229,7 @@ uint16_t CX10_callback() } break; case CX10_DATA: + telemetry_set_input_sync(packet_period); CX10_Write_Packet(0); break; } diff --git a/Multiprotocol/Corona_cc2500.ino b/Multiprotocol/Corona_cc2500.ino index c254b8f..aba0446 100644 --- a/Multiprotocol/Corona_cc2500.ino +++ b/Multiprotocol/Corona_cc2500.ino @@ -258,6 +258,7 @@ static uint16_t __attribute__((unused)) CORONA_build_packet() uint16_t ReadCORONA() { + telemetry_set_input_sync(22000); // Tune frequency if it has been changed if ( prev_option != option ) { diff --git a/Multiprotocol/DM002_nrf24l01.ino b/Multiprotocol/DM002_nrf24l01.ino index c87d89d..f319397 100644 --- a/Multiprotocol/DM002_nrf24l01.ino +++ b/Multiprotocol/DM002_nrf24l01.ino @@ -113,7 +113,10 @@ static void __attribute__((unused)) DM002_init() uint16_t DM002_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(DM002_PACKET_PERIOD); DM002_send_packet(0); + } else { if (bind_counter == 0) diff --git a/Multiprotocol/DSM_cyrf6936.ino b/Multiprotocol/DSM_cyrf6936.ino index 457d616..def9a86 100644 --- a/Multiprotocol/DSM_cyrf6936.ino +++ b/Multiprotocol/DSM_cyrf6936.ino @@ -452,6 +452,7 @@ uint16_t ReadDsm() DSM_set_sop_data_crc(); return 10000; case DSM_CH1_WRITE_A: + telemetry_set_input_sync(11000); // Always request 11ms spacing even if we don't use half of it in 22ms mode case DSM_CH1_WRITE_B: case DSM_CH2_WRITE_A: case DSM_CH2_WRITE_B: diff --git a/Multiprotocol/Devo_cyrf6936.ino b/Multiprotocol/Devo_cyrf6936.ino index cc5de95..60ec4cf 100644 --- a/Multiprotocol/Devo_cyrf6936.ino +++ b/Multiprotocol/Devo_cyrf6936.ino @@ -272,6 +272,7 @@ uint16_t devo_callback() static uint8_t txState=0; if (txState == 0) { + telemetry_set_input_sync(2400); txState = 1; DEVO_BuildPacket(); CYRF_WriteDataPacket(packet); diff --git a/Multiprotocol/E01X_nrf24l01.ino b/Multiprotocol/E01X_nrf24l01.ino index 8c9c455..7a37daf 100644 --- a/Multiprotocol/E01X_nrf24l01.ino +++ b/Multiprotocol/E01X_nrf24l01.ino @@ -287,7 +287,10 @@ uint16_t E01X_callback() } } else + { + telemetry_set_input_sync(packet_period); E01X_send_packet(0); + } return packet_period; } diff --git a/Multiprotocol/ESky150_nrf24l01.ino b/Multiprotocol/ESky150_nrf24l01.ino index bbc88c5..fe4da38 100644 --- a/Multiprotocol/ESky150_nrf24l01.ino +++ b/Multiprotocol/ESky150_nrf24l01.ino @@ -151,7 +151,10 @@ uint8_t ESKY150_convert_2bit_channel(uint8_t num) uint16_t ESKY150_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(ESKY150_SENDING_PACKET_PERIOD); ESKY150_send_packet(); + } else { NRF24L01_WritePayload(packet, ESKY150_PAYLOADSIZE); diff --git a/Multiprotocol/ESky_nrf24l01.ino b/Multiprotocol/ESky_nrf24l01.ino index 82cbda2..672ad96 100644 --- a/Multiprotocol/ESky_nrf24l01.ino +++ b/Multiprotocol/ESky_nrf24l01.ino @@ -135,7 +135,10 @@ static void __attribute__((unused)) ESKY_send_packet(uint8_t bind) uint16_t ESKY_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(ESKY_PACKET_PERIOD); ESKY_send_packet(0); + } else { ESKY_send_packet(1); diff --git a/Multiprotocol/FQ777_nrf24l01.ino b/Multiprotocol/FQ777_nrf24l01.ino index a40c4e5..86a5dfe 100644 --- a/Multiprotocol/FQ777_nrf24l01.ino +++ b/Multiprotocol/FQ777_nrf24l01.ino @@ -188,7 +188,10 @@ uint16_t FQ777_callback() } } else + { + telemetry_set_input_sync(FQ777_PACKET_PERIOD); FQ777_send_packet(0); + } return FQ777_PACKET_PERIOD; } diff --git a/Multiprotocol/FY326_nrf24l01.ino b/Multiprotocol/FY326_nrf24l01.ino index 117c7fe..eb98853 100644 --- a/Multiprotocol/FY326_nrf24l01.ino +++ b/Multiprotocol/FY326_nrf24l01.ino @@ -188,6 +188,7 @@ uint16_t FY326_callback() return FY326_PACKET_CHKTIME; break; case FY326_DATA: + telemetry_set_input_sync(FY326_PACKET_PERIOD); FY326_send_packet(0); break; } diff --git a/Multiprotocol/FlySky_a7105.ino b/Multiprotocol/FlySky_a7105.ino index 80dec64..657734a 100644 --- a/Multiprotocol/FlySky_a7105.ino +++ b/Multiprotocol/FlySky_a7105.ino @@ -168,16 +168,13 @@ uint16_t ReadFlySky() } else { + telemetry_set_input_sync(packet_period); flysky_build_packet(0); A7105_WriteData(21, hopping_frequency[hopping_frequency_no & 0x0F]); A7105_SetPower(); } hopping_frequency_no++; - - if(sub_protocol==CX20) - return 3984; - else - return 1510; //1460 on deviation but not working with the latest V911 bricks... Turnigy 9X v2 is 1533, Flysky TX for 9XR/9XR Pro is 1510, V911 TX is 1490. + return packet_period; } const uint8_t PROGMEM tx_channels[8][4] = { @@ -235,6 +232,10 @@ uint16_t initFlySky() } hopping_frequency_no=0; packet_count=0; + if(sub_protocol==CX20) + packet_period=3984; + else + packet_period=1510; //1460 on deviation but not working with the latest V911 bricks... Turnigy 9X v2 is 1533, Flysky TX for 9XR/9XR Pro is 1510, V911 TX is 1490. if(IS_BIND_IN_PROGRESS) bind_counter = FLYSKY_BIND_COUNT; else diff --git a/Multiprotocol/Flyzone_a7105.ino b/Multiprotocol/Flyzone_a7105.ino index 24c69ee..063d41b 100644 --- a/Multiprotocol/Flyzone_a7105.ino +++ b/Multiprotocol/Flyzone_a7105.ino @@ -55,6 +55,7 @@ uint16_t ReadFlyzone() if(phase>19) { phase=0; + telemetry_set_input_sync(20*1500); flyzone_build_packet(); A7105_WriteData(8, hopping_frequency[0]); A7105_SetPower(); diff --git a/Multiprotocol/FrSkyD_cc2500.ino b/Multiprotocol/FrSkyD_cc2500.ino index bd82890..a587ff8 100644 --- a/Multiprotocol/FrSkyD_cc2500.ino +++ b/Multiprotocol/FrSkyD_cc2500.ino @@ -156,6 +156,7 @@ uint16_t ReadFrSky_2way() { if (state == FRSKY_DATA1) { + telemetry_set_input_sync(9000); len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; if (len && len<=(0x11+3))// 20bytes { diff --git a/Multiprotocol/FrSkyV_cc2500.ino b/Multiprotocol/FrSkyV_cc2500.ino index f277b2c..2d19030 100644 --- a/Multiprotocol/FrSkyV_cc2500.ino +++ b/Multiprotocol/FrSkyV_cc2500.ino @@ -117,6 +117,7 @@ uint16_t ReadFRSKYV() { if(IS_BIND_DONE) { // Normal operation + telemetry_set_input_sync(9006); uint8_t chan = FRSKYV_calc_channel(); CC2500_Strobe(CC2500_SIDLE); if (option != prev_option) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index f5f15c6..39ea701 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -322,6 +322,7 @@ uint16_t ReadFrSkyX() state++; return 3100; case FRSKY_DATA4: + telemetry_set_input_sync(9000); len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; if (len && (len<=(0x0E + 3))) //Telemetry frame is 17 { diff --git a/Multiprotocol/GD00X_nrf24l01.ino b/Multiprotocol/GD00X_nrf24l01.ino index 7a1b32b..ca1a64d 100644 --- a/Multiprotocol/GD00X_nrf24l01.ino +++ b/Multiprotocol/GD00X_nrf24l01.ino @@ -208,6 +208,7 @@ uint16_t GD00X_callback() if(--bind_counter==0) BIND_DONE; GD00X_send_packet(); + telemetry_set_input_sync(packet_period); return packet_period; } diff --git a/Multiprotocol/GW008_nrf24l01.ino b/Multiprotocol/GW008_nrf24l01.ino index 3bcae2e..84669eb 100644 --- a/Multiprotocol/GW008_nrf24l01.ino +++ b/Multiprotocol/GW008_nrf24l01.ino @@ -139,6 +139,7 @@ uint16_t GW008_callback() return 5000; break; case GW008_DATA: + telemetry_set_input_sync(GW008_PACKET_PERIOD); GW008_send_packet(0); break; } diff --git a/Multiprotocol/H8_3D_nrf24l01.ino b/Multiprotocol/H8_3D_nrf24l01.ino index 8fe92f5..14f9fe5 100644 --- a/Multiprotocol/H8_3D_nrf24l01.ino +++ b/Multiprotocol/H8_3D_nrf24l01.ino @@ -177,7 +177,10 @@ static void __attribute__((unused)) H8_3D_init() uint16_t H8_3D_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(packet_period); H8_3D_send_packet(0); + } else { if (bind_counter == 0) diff --git a/Multiprotocol/Hisky_nrf24l01.ino b/Multiprotocol/Hisky_nrf24l01.ino index 519fbb2..4bbf413 100644 --- a/Multiprotocol/Hisky_nrf24l01.ino +++ b/Multiprotocol/Hisky_nrf24l01.ino @@ -151,6 +151,7 @@ uint16_t hisky_cb() phase=6; break; case 7: // build packet + telemetry_set_input_sync(5000); #ifdef FAILSAFE_ENABLE if(IS_FAILSAFE_VALUES_on && hopping_frequency_no==0) { // send failsafe every 100ms @@ -216,6 +217,7 @@ uint16_t hisky_cb() break; case 7: //Build normal packet + telemetry_set_input_sync(9000); build_ch_data(); break; case 8: diff --git a/Multiprotocol/Hitec_cc2500.ino b/Multiprotocol/Hitec_cc2500.ino index e31bac0..b88bfc1 100644 --- a/Multiprotocol/Hitec_cc2500.ino +++ b/Multiprotocol/Hitec_cc2500.ino @@ -259,6 +259,7 @@ uint16_t ReadHITEC() case HITEC_PREP: if ( prev_option == option ) { // No user frequency change + telemetry_set_input_sync(HITEC_PACKET_PERIOD); HITEC_change_chan_fast(); hopping_frequency_no++; if(hopping_frequency_no>=rf_ch_num) diff --git a/Multiprotocol/Hontai_nrf24l01.ino b/Multiprotocol/Hontai_nrf24l01.ino index 03d3f1c..d7ab693 100644 --- a/Multiprotocol/Hontai_nrf24l01.ino +++ b/Multiprotocol/Hontai_nrf24l01.ino @@ -242,9 +242,12 @@ uint16_t HONTAI_callback() } } else + { + telemetry_set_input_sync(packet_period); HONTAI_send_packet(0); + } - return sub_protocol == FQ777_951 ? FQ777_951_PACKET_PERIOD : HONTAI_PACKET_PERIOD; + return packet_period; } uint16_t initHONTAI() @@ -253,6 +256,7 @@ uint16_t initHONTAI() bind_counter = HONTAI_BIND_COUNT; HONTAI_initialize_txid(); HONTAI_init(); + packet_period = sub_protocol == FQ777_951 ? FQ777_951_PACKET_PERIOD : HONTAI_PACKET_PERIOD; return HONTAI_INITIAL_WAIT; } #endif diff --git a/Multiprotocol/Hubsan_a7105.ino b/Multiprotocol/Hubsan_a7105.ino index d454076..e38bb70 100644 --- a/Multiprotocol/Hubsan_a7105.ino +++ b/Multiprotocol/Hubsan_a7105.ino @@ -376,6 +376,7 @@ uint16_t ReadHubsan() case DATA_4: case DATA_5: if( txState == 0) { // send packet + telemetry_set_input_sync(10000); #ifdef HUBSAN_HUB_TELEMETRY rfMode = A7105_TX; #endif diff --git a/Multiprotocol/J6Pro_cyrf6936.ino b/Multiprotocol/J6Pro_cyrf6936.ino index 454739a..d6871f5 100644 --- a/Multiprotocol/J6Pro_cyrf6936.ino +++ b/Multiprotocol/J6Pro_cyrf6936.ino @@ -201,7 +201,8 @@ uint16_t ReadJ6Pro() cyrf_datainit(); phase = J6PRO_CHAN_1; case J6PRO_CHAN_1: - //Keep transmit power updated + telemetry_set_input_sync(24550); + //Keep transmit power updated CYRF_SetPower(0x28); j6pro_build_data_packet(); //return 3400; diff --git a/Multiprotocol/KF606_nrf24l01.ino b/Multiprotocol/KF606_nrf24l01.ino index f086091..9f8a7e1 100644 --- a/Multiprotocol/KF606_nrf24l01.ino +++ b/Multiprotocol/KF606_nrf24l01.ino @@ -86,6 +86,7 @@ static void __attribute__((unused)) KF606_init() uint16_t KF606_callback() { + telemetry_set_input_sync(KF606_PACKET_PERIOD); if(IS_BIND_IN_PROGRESS) if(--bind_counter==0) { diff --git a/Multiprotocol/KN_nrf24l01.ino b/Multiprotocol/KN_nrf24l01.ino index 40c8f92..64cdbc5 100644 --- a/Multiprotocol/KN_nrf24l01.ino +++ b/Multiprotocol/KN_nrf24l01.ino @@ -279,12 +279,14 @@ uint16_t initKN() packet_period = KN_WL_SENDING_PACKET_PERIOD; bind_counter = KN_WL_BIND_COUNT; packet_count = KN_WL_PACKET_SEND_COUNT; + seed = KN_WL_PACKET_SEND_COUNT * KN_WL_SENDING_PACKET_PERIOD; } else { packet_period = KN_FX_SENDING_PACKET_PERIOD; bind_counter = KN_FX_BIND_COUNT; packet_count = KN_FX_PACKET_SEND_COUNT; + seed = KN_FX_PACKET_SEND_COUNT * KN_FX_SENDING_PACKET_PERIOD; } kn_init(); phase = IS_BIND_IN_PROGRESS ? KN_PHASE_PRE_BIND : KN_PHASE_PRE_SEND; @@ -318,6 +320,7 @@ uint16_t kn_callback() case KN_PHASE_SENDING: if(packet_sent >= packet_count) { + telemetry_set_input_sync(seed); packet_sent = 0; hopping_frequency_no++; if(hopping_frequency_no >= KN_RF_CH_COUNT) hopping_frequency_no = 0; diff --git a/Multiprotocol/MJXQ_nrf24l01.ino b/Multiprotocol/MJXQ_nrf24l01.ino index a08624a..9140f6d 100644 --- a/Multiprotocol/MJXQ_nrf24l01.ino +++ b/Multiprotocol/MJXQ_nrf24l01.ino @@ -327,7 +327,10 @@ static void __attribute__((unused)) MJXQ_initialize_txid() uint16_t MJXQ_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(MJXQ_PACKET_PERIOD); MJXQ_send_packet(0); + } else { if (bind_counter == 0) diff --git a/Multiprotocol/MT99xx_nrf24l01.ino b/Multiprotocol/MT99xx_nrf24l01.ino index 1d7e1b3..cb38aa8 100644 --- a/Multiprotocol/MT99xx_nrf24l01.ino +++ b/Multiprotocol/MT99xx_nrf24l01.ino @@ -222,7 +222,10 @@ static void __attribute__((unused)) MT99XX_initialize_txid() uint16_t MT99XX_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(packet_period); MT99XX_send_packet(); + } else { if (bind_counter == 0) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index d46547d..dcad97a 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 11 +#define VERSION_PATCH_LEVEL 13 //****************** // Protocols @@ -322,9 +322,9 @@ enum MultiPacketTypes MULTI_TELEMETRY_DSM = 4, MULTI_TELEMETRY_DSMBIND = 5, MULTI_TELEMETRY_AFHDS2A = 6, - MULTI_TELEMETRY_CONFIG = 7, + MULTI_TELEMETRY_REUSE_1 = 7, MULTI_TELEMETRY_SYNC = 8, - MULTI_TELEMETRY_SPORT_BUFFER = 9, + MULTI_TELEMETRY_REUSE_2 = 9, MULTI_TELEMETRY_HITEC = 10, MULTI_TELEMETRY_SCANNER = 11, MULTI_TELEMETRY_AFHDS2A_AC = 12, @@ -926,6 +926,19 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- data[0] = RSSI value data[1-28] telemetry data + Type 0x08 Input synchronisation + Informs the TX about desired rate and current delay + length: 4 + data[0-1] Desired refresh rate in ??s + data[2-3] Time (??s) between last serial servo input received and servo input needed (lateness), TX should adjust its + sending time to minimise this value. + data[4] Interval of this message in ms + data[5] Input delay target in 10??s + Note that there are protocols (AFHDS2A) that have a refresh rate that is smaller than the maximum achievable + refresh rate via the serial protocol, in this case, the TX should double the rate and also subract this + refresh rate from the input lag if the input lag is more than the desired refresh rate. + The remote should try to get to zero of (inputdelay+target*10). + Type 0x0A Hitec telemetry data length: 8 data[0] = TX RSSI value diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 4fd1295..bb3d238 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -173,6 +173,10 @@ volatile uint8_t rx_idx=0, rx_len=0; #define TELEMETRY_BUFFER_SIZE 30 uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets #if defined(TELEMETRY) + #ifdef MULTI_SYNC + uint32_t last_serial_input=0; + uint16_t inputRefreshRate = 7000; + #endif #ifdef INVERT_TELEMETRY #if not defined(ORANGE_TX) && not defined(STM32_BOARD) // enable bit bash for serial @@ -573,12 +577,12 @@ void loop() next_callback=2000; // No PPM/serial signal check again in 2ms... TX_MAIN_PAUSE_off; tx_resume(); - while(next_callback>4000) + while(next_callback>1000) { // start to wait here as much as we can... - next_callback-=2000; // We will wait below for 2ms + next_callback-=500; // We will wait below for 0.5ms cli(); // Disable global int due to RW of 16 bits registers - OCR1A += 2000*2 ; // set compare A for callback - #ifndef STM32_BOARD + OCR1A += 500*2 ; // set compare A for callback + #ifndef STM32_BOARD TIFR1=OCF1A_bm; // clear compare A=callback flag #else TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC1IF; // Clear Timer2/Comp1 interrupt flag @@ -590,12 +594,12 @@ void loop() break; } #ifndef STM32_BOARD - while((TIFR1 & OCF1A_bm) == 0); // wait 2ms... + while((TIFR1 & OCF1A_bm) == 0); // wait 0.5ms... #else - while((TIMER2_BASE->SR & TIMER_SR_CC1IF)==0);//2ms wait + while((TIMER2_BASE->SR & TIMER_SR_CC1IF)==0);//wait 0.5ms... #endif } - // at this point we have a maximum of 4ms in next_callback + // at this point we have a maximum of 1ms in next_callback next_callback *= 2 ; cli(); // Disable global int due to RW of 16 bits registers OCR1A+= next_callback ; // set compare A for callback @@ -666,7 +670,7 @@ uint8_t Update_All() #if ( !( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) ) if( (protocol == PROTO_FRSKYX_RX) || (protocol == PROTO_SCANNER) || (protocol==PROTO_FRSKYD) || (protocol==PROTO_BAYANG) || (protocol==PROTO_NCC1701) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_FRSKYX) || (protocol==PROTO_DSM) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC)) #endif - if(IS_DISABLE_TELEM_off) + if(IS_DISABLE_TELEM_off && !(protocol==PROTO_XN297DUMP)) TelemetryUpdate(); #endif #ifdef ENABLE_BIND_CH @@ -928,6 +932,9 @@ static void protocol_init() // reset telemetry #ifdef TELEMETRY + #ifdef MULTI_SYNC + inputRefreshRate = 7000; // Default value + #endif tx_pause(); pass=0; telemetry_link=0; @@ -2027,7 +2034,9 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag TIMER2_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer2/Comp2 interrupt #else + cli(); // Disable global int due to RW of 16 bits registers OCR1B = TCNT1 + 300; // Next byte should show up within 15us=1.5 byte + sei(); // Enable global int TIFR1 = OCF1B_bm ; // clear OCR1B match flag SET_TIMSK1_OCIE1B ; // enable interrupt on compare B match #endif @@ -2047,7 +2056,9 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) #if defined STM32_BOARD TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15us=1.5 byte #else + cli(); // Disable global int due to RW of 16 bits registers OCR1B = TCNT1 + 300; // Next byte should show up within 15us=1.5 byte + sei(); // Enable global int #endif } } @@ -2085,7 +2096,11 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) #endif { // Timer1 compare B interrupt if(rx_idx>=26) - { // A full frame has been received + { + #ifdef MULTI_SYNC + last_serial_input=TCNT1; + #endif + // A full frame has been received if(!IS_RX_DONOTUPDATE_on) { //Good frame received and main is not working on the buffer rx_len=rx_idx; diff --git a/Multiprotocol/NCC1701_nrf24l01.ino b/Multiprotocol/NCC1701_nrf24l01.ino index 814bb99..de919e6 100644 --- a/Multiprotocol/NCC1701_nrf24l01.ino +++ b/Multiprotocol/NCC1701_nrf24l01.ino @@ -197,6 +197,7 @@ uint16_t NCC_callback() phase = NCC_BIND_TX2; return NCC_PACKET_INTERVAL - NCC_WRITE_WAIT; case NCC_TX3: + telemetry_set_input_sync(NCC_PACKET_INTERVAL); if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) { // RX fifo data ready NRF24L01_ReadPayload(packet, NCC_RX_PACKET_LEN); diff --git a/Multiprotocol/POTENSIC_nrf24l01.ino b/Multiprotocol/POTENSIC_nrf24l01.ino index 5851887..06577ab 100644 --- a/Multiprotocol/POTENSIC_nrf24l01.ino +++ b/Multiprotocol/POTENSIC_nrf24l01.ino @@ -109,6 +109,7 @@ uint16_t POTENSIC_callback() BIND_DONE; XN297_SetTXAddr(rx_tx_addr,5); } + telemetry_set_input_sync(POTENSIC_PACKET_PERIOD); POTENSIC_send_packet(); return POTENSIC_PACKET_PERIOD; } diff --git a/Multiprotocol/Q303_nrf24l01.ino b/Multiprotocol/Q303_nrf24l01.ino index 9eee446..93ed15a 100644 --- a/Multiprotocol/Q303_nrf24l01.ino +++ b/Multiprotocol/Q303_nrf24l01.ino @@ -354,7 +354,10 @@ static void __attribute__((unused)) Q303_initialize_txid() uint16_t Q303_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(packet_period); Q303_send_packet(0); + } else { if (bind_counter == 0) diff --git a/Multiprotocol/Redpine_cc2500.ino b/Multiprotocol/Redpine_cc2500.ino index df18f9b..463c314 100644 --- a/Multiprotocol/Redpine_cc2500.ino +++ b/Multiprotocol/Redpine_cc2500.ino @@ -125,6 +125,7 @@ static uint16_t ReadREDPINE() } else { + telemetry_set_input_sync(packet_period); CC2500_SetTxRxMode(TX_EN); REDPINE_set_channel(hopping_frequency_no); CC2500_SetPower(); @@ -133,10 +134,7 @@ static uint16_t ReadREDPINE() CC2500_Strobe(CC2500_SIDLE); hopping_frequency_no = (hopping_frequency_no + 1) % 49; CC2500_WriteData(packet, REDPINE_PACKET_SIZE); - if (sub_protocol==0) - return REDPINE_LOOPTIME_FAST*100; - else - return REDPINE_LOOPTIME_SLOW*1000; + return packet_period; } return 1; } @@ -235,6 +233,11 @@ static uint16_t initREDPINE() } hopping_frequency[49] = 0; // Last channel is the bind channel at hop 0 + if (sub_protocol==0) + packet_period = REDPINE_LOOPTIME_FAST*100; + else + packet_period = REDPINE_LOOPTIME_SLOW*1000; + bind_counter=REDPINE_BIND; REDPINE_init(sub_protocol); CC2500_SetTxRxMode(TX_EN); // enable PA diff --git a/Multiprotocol/SFHSS_cc2500.ino b/Multiprotocol/SFHSS_cc2500.ino index 8588f00..95d7066 100644 --- a/Multiprotocol/SFHSS_cc2500.ino +++ b/Multiprotocol/SFHSS_cc2500.ino @@ -235,6 +235,7 @@ uint16_t ReadSFHSS() #define SFHSS_PACKET_PERIOD 6800 #define SFHSS_DATA2_TIMING 1625 // Adjust this value between 1600 and 1650 if your RX(s) are not operating properly case SFHSS_DATA1: + telemetry_set_input_sync(6800); SFHSS_build_data_packet(); SFHSS_send_packet(); phase = SFHSS_DATA2; diff --git a/Multiprotocol/SHENQI_nrf24l01.ino b/Multiprotocol/SHENQI_nrf24l01.ino index ca3d873..745ce9b 100644 --- a/Multiprotocol/SHENQI_nrf24l01.ino +++ b/Multiprotocol/SHENQI_nrf24l01.ino @@ -63,6 +63,8 @@ void SHENQI_send_packet() } else { + if(packet_count==1) + telemetry_set_input_sync(3000+2508+6*1750); LT8900_SetAddress(rx_tx_addr,4); packet[1]=255-convert_channel_8b(RUDDER); packet[2]=255-convert_channel_16b_limit(THROTTLE,0x60,0xA0); @@ -91,7 +93,9 @@ void SHENQI_send_packet() uint16_t SHENQI_callback() { if(IS_BIND_DONE) + { SHENQI_send_packet(); + } else { if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) diff --git a/Multiprotocol/SLT_nrf24l01.ino b/Multiprotocol/SLT_nrf24l01.ino index 11ee902..aca37fc 100644 --- a/Multiprotocol/SLT_nrf24l01.ino +++ b/Multiprotocol/SLT_nrf24l01.ino @@ -213,6 +213,7 @@ uint16_t SLT_callback() switch (phase) { case SLT_BUILD: + telemetry_set_input_sync(sub_protocol==SLT_V1?20000:13730); SLT_build_packet(); phase++; return SLT_TIMING_BUILD; diff --git a/Multiprotocol/Symax_nrf24l01.ino b/Multiprotocol/Symax_nrf24l01.ino index f33a344..029e388 100644 --- a/Multiprotocol/Symax_nrf24l01.ino +++ b/Multiprotocol/Symax_nrf24l01.ino @@ -359,6 +359,7 @@ uint16_t symax_callback() } break; case SYMAX_DATA: + telemetry_set_input_sync(SYMAX_PACKET_PERIOD); SYMAX_send_packet(0); break; } diff --git a/Multiprotocol/TRAXXAS_cyrf6936.ino b/Multiprotocol/TRAXXAS_cyrf6936.ino index 4de89c6..5ed502a 100644 --- a/Multiprotocol/TRAXXAS_cyrf6936.ino +++ b/Multiprotocol/TRAXXAS_cyrf6936.ino @@ -162,6 +162,7 @@ uint16_t ReadTRAXXAS() TRAXXAS_cyrf_data_config(); phase++; case TRAXXAS_DATA: + telemetry_set_input_sync(13940); TRAXXAS_send_data_packet(); break; } diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 69a42de..3ae816c 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -20,10 +20,14 @@ uint8_t RetrySequence ; #if ( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) - #define MULTI_TIME 500 //in ms - #define INPUT_SYNC_TIME 100 //in ms - #define INPUT_ADDITIONAL_DELAY 100 // in 10µs, 100 => 1000 µs uint32_t lastMulti = 0; + #define MULTI_TIME 500 //in ms + #ifdef MULTI_SYNC + #define INPUT_SYNC_TIME 100 //in ms + #define INPUT_ADDITIONAL_DELAY 100 // in 10µs, 100 => 1000 µs + uint32_t lastInputSync = 0; + uint16_t inputDelay = 0; + #endif // MULTI_SYNC #endif // MULTI_TELEMETRY/MULTI_STATUS #if defined SPORT_TELEMETRY @@ -76,6 +80,51 @@ static void multi_send_header(uint8_t type, uint8_t len) Serial_write(len); } +inline void telemetry_set_input_sync(uint16_t refreshRate) +{ + #ifdef MULTI_SYNC + #if defined(STM32_BOARD) && defined(DEBUG_PIN) + static uint8_t c=0; + if (c++%2==0) + { DEBUG_PIN_on; } + else + { DEBUG_PIN_off; } + #endif + // Only record input Delay after a frame has really been received + // Otherwise protocols with faster refresh rates then the TX sends (e.g. 3ms vs 6ms) will screw up the calcualtion + inputRefreshRate = refreshRate; + if (last_serial_input != 0) + { + #if defined STM32_BOARD + inputDelay=TIMER2_BASE->CNT; + #else + cli(); // Disable global int due to RW of 16 bits registers + inputDelay = TCNT1; // Next byte should show up within 15us=1.5 byte + sei(); // Enable global int + #endif + inputDelay = (inputDelay - last_serial_input)>>1; + if(inputDelay > 0x8000) + inputDelay =inputDelay - 0x8000; + last_serial_input=0; + } + #else + (void)refreshRate; + #endif +} + +#ifdef MULTI_SYNC + static void mult_send_inputsync() + { + multi_send_header(MULTI_TELEMETRY_SYNC, 6); + Serial_write(inputRefreshRate >> 8); + Serial_write(inputRefreshRate & 0xff); + Serial_write(inputDelay >> 8); + Serial_write(inputDelay & 0xff); + Serial_write(INPUT_SYNC_TIME); + Serial_write(INPUT_ADDITIONAL_DELAY); + } +#endif //MULTI_SYNC + static void multi_send_status() { multi_send_header(MULTI_TELEMETRY_STATUS, 6); @@ -744,6 +793,14 @@ void TelemetryUpdate() lastMulti = now; return; } + #ifdef MULTI_SYNC + else if ( (now - lastInputSync) > INPUT_SYNC_TIME) + { + mult_send_inputsync(); + lastInputSync = now; + return; + } + #endif #endif #if defined SPORT_TELEMETRY diff --git a/Multiprotocol/V2X2_nrf24l01.ino b/Multiprotocol/V2X2_nrf24l01.ino index 9a34185..bce24bd 100644 --- a/Multiprotocol/V2X2_nrf24l01.ino +++ b/Multiprotocol/V2X2_nrf24l01.ino @@ -264,6 +264,7 @@ uint16_t ReadV2x2() case V202_DATA: if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED) return V2X2_PACKET_CHKTIME; + telemetry_set_input_sync(V2X2_PACKET_PERIOD); V2X2_send_packet(0); break; } diff --git a/Multiprotocol/V761_nrf24l01.ino b/Multiprotocol/V761_nrf24l01.ino index b9eac9f..4a8e81d 100644 --- a/Multiprotocol/V761_nrf24l01.ino +++ b/Multiprotocol/V761_nrf24l01.ino @@ -174,6 +174,7 @@ uint16_t V761_callback() } return 15730; case V761_DATA: + telemetry_set_input_sync(V761_PACKET_PERIOD); V761_send_packet(); break; } diff --git a/Multiprotocol/V911S_nrf24l01.ino b/Multiprotocol/V911S_nrf24l01.ino index 13a47dc..2747c9f 100644 --- a/Multiprotocol/V911S_nrf24l01.ino +++ b/Multiprotocol/V911S_nrf24l01.ino @@ -111,7 +111,10 @@ static void __attribute__((unused)) V911S_initialize_txid() uint16_t V911S_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(V911S_PACKET_PERIOD); V911S_send_packet(0); + } else { if (bind_counter == 0) diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index fa2f13f..b412c33 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -315,6 +315,14 @@ #endif #endif +#ifdef SPORT_TELEMETRY + #define SPORT_SEND +#endif + +#if not defined(MULTI_TELEMETRY) + #undef MULTI_SYNC +#endif + //Make sure TX is defined correctly #ifndef AILERON #error You must select a correct channel order. diff --git a/Multiprotocol/WFLY_cyrf6936.ino b/Multiprotocol/WFLY_cyrf6936.ino index c7664da..62fd66e 100644 --- a/Multiprotocol/WFLY_cyrf6936.ino +++ b/Multiprotocol/WFLY_cyrf6936.ino @@ -232,6 +232,7 @@ uint16_t ReadWFLY() packet_count=0; phase++; case WFLY_DATA: + telemetry_set_input_sync(5371); start=micros(); while ((uint8_t)((uint8_t)micros()-(uint8_t)start) < 200) if((CYRF_ReadRegister(CYRF_02_TX_CTRL) & 0x80) == 0x00) diff --git a/Multiprotocol/WK2x01_cyrf6936.ino b/Multiprotocol/WK2x01_cyrf6936.ino index 2924f13..748ee8d 100644 --- a/Multiprotocol/WK2x01_cyrf6936.ino +++ b/Multiprotocol/WK2x01_cyrf6936.ino @@ -435,6 +435,7 @@ uint16_t WK_cb() { if (packet_sent == 0) { + telemetry_set_input_sync(2800); packet_sent = 1; if(sub_protocol == WK2801) WK_BuildPacket_2801(); diff --git a/Multiprotocol/YD717_nrf24l01.ino b/Multiprotocol/YD717_nrf24l01.ino index 2fdeda4..1fcac90 100644 --- a/Multiprotocol/YD717_nrf24l01.ino +++ b/Multiprotocol/YD717_nrf24l01.ino @@ -155,7 +155,10 @@ static void __attribute__((unused)) yd717_init() uint16_t yd717_callback() { if(IS_BIND_DONE) + { + telemetry_set_input_sync(YD717_PACKET_PERIOD); yd717_send_packet(0); + } else { if (bind_counter == 0) diff --git a/Multiprotocol/ZSX_nrf24l01.ino b/Multiprotocol/ZSX_nrf24l01.ino index 3e8f6be..eedd6a1 100644 --- a/Multiprotocol/ZSX_nrf24l01.ino +++ b/Multiprotocol/ZSX_nrf24l01.ino @@ -80,6 +80,7 @@ static void __attribute__((unused)) ZSX_init() uint16_t ZSX_callback() { + telemetry_set_input_sync(ZSX_PACKET_PERIOD); if(IS_BIND_IN_PROGRESS) if(--bind_counter==0) { diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index e60b643..31df1d7 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -264,17 +264,19 @@ //For er9x it depends if you have an inveter mod or not on the telemetry pin. If you don't have an inverter comment this line. #define INVERT_TELEMETRY -//Comment if you don't want to send Multi status telemetry frames (Protocol available, Bind in progress, version...) +//Uncomment if you don't want to send Multi status telemetry frames (Protocol available, Bind in progress, version...) //Use with er9x/erksy9x, for OpenTX MULTI_TELEMETRY below is preferred instead //#define MULTI_STATUS -//Uncomment to send Multi status and allow OpenTX to autodetect the telemetry format +//Comment to send Multi status and allow OpenTX to autodetect the telemetry format //Supported by OpenTX version 2.2 RC9 and newer. NOT supported by er9x/ersky9x use MULTI_STATUS instead. #define MULTI_TELEMETRY +//Comment to not sync OpenTX and module together +#define MULTI_SYNC //Comment a line to disable a specific protocol telemetry #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, ersky9x and OpenTX -#define SPORT_TELEMETRY // Use FrSkyX SPORT format to send telemetry to TX +#define SPORT_TELEMETRY // Use FrSkyX format to send telemetry to TX #define AFHDS2A_FW_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by ersky9x and OpenTX #define AFHDS2A_HUB_TELEMETRY // Use FrSkyD Hub format to send basic telemetry to TX like er9x #define HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX @@ -289,11 +291,6 @@ #define FRSKYX_RX_TELEMETRY // Forward channels data to TX #define AFHDS2A_RX_TELEMETRY // Forward channels data to TX -//SPORT_SEND: passing sport control frames from TX to RX(ex: SxR configuration, changing Betaflight PID or VTX channels on the fly using LUA scripts with OpentX). -//!!!! This is a work in progress!!! Do not enable unless you want to test and report -//#define SPORT_SEND - - /****************************/ /*** SERIAL MODE SETTINGS ***/ /****************************/ From d434e63c22d0ce1ca56b61ec964c2b940a2f8b7a Mon Sep 17 00:00:00 2001 From: pascallanger Date: Fri, 11 Oct 2019 01:14:04 +0200 Subject: [PATCH 15/65] Multi_sync updates Only for STM32 Enable bidirectionnal serial --- Multiprotocol/Multiprotocol.ino | 12 ++++++------ Multiprotocol/Validate.h | 2 +- Multiprotocol/_Config.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index bb3d238..3494c6f 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -2027,13 +2027,13 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) if((rx_buff[0]&0xFE)==0x54) // If 1st byte is 0x54 or 0x55 it looks ok #endif { - TX_RX_PAUSE_on; - tx_pause(); #if defined STM32_BOARD TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15us=1.5 byte TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag TIMER2_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer2/Comp2 interrupt #else + TX_RX_PAUSE_on; + tx_pause(); cli(); // Disable global int due to RW of 16 bits registers OCR1B = TCNT1 + 300; // Next byte should show up within 15us=1.5 byte sei(); // Enable global int @@ -2076,9 +2076,9 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt #else CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match + TX_RX_PAUSE_off; + tx_resume(); #endif - TX_RX_PAUSE_off; - tx_resume(); } #if not defined (ORANGE_TX) && not defined (STM32_BOARD) cli() ; @@ -2117,9 +2117,9 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt #else CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match + TX_RX_PAUSE_off; + tx_resume(); #endif - TX_RX_PAUSE_off; - tx_resume(); } #endif //ENABLE_SERIAL diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index b412c33..51a2116 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -319,7 +319,7 @@ #define SPORT_SEND #endif -#if not defined(MULTI_TELEMETRY) +#if not defined(MULTI_TELEMETRY) || not defined(STM32_BOARD) #undef MULTI_SYNC #endif diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 31df1d7..3efd302 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -268,10 +268,10 @@ //Use with er9x/erksy9x, for OpenTX MULTI_TELEMETRY below is preferred instead //#define MULTI_STATUS -//Comment to send Multi status and allow OpenTX to autodetect the telemetry format +//Sends Multi status and allow OpenTX to autodetect the telemetry format. Comment to disable. //Supported by OpenTX version 2.2 RC9 and newer. NOT supported by er9x/ersky9x use MULTI_STATUS instead. #define MULTI_TELEMETRY -//Comment to not sync OpenTX and module together +//Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. #define MULTI_SYNC //Comment a line to disable a specific protocol telemetry From 6dfd54b8bea67524af6cf2dd309efad72a7f6d14 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Fri, 11 Oct 2019 10:08:25 +0200 Subject: [PATCH 16/65] Remove travis test for debug --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 43492c3..693dc91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ env: - BOARD="multi4in1:avr:multiatmega328p:bootloader=optiboot" - BOARD="multi4in1:avr:multixmega32d4" - BOARD="multi4in1:STM32F1:multistm32f103c:debug_option=none" - - BOARD="multi4in1:STM32F1:multistm32f103c:debug_option=native" + # - BOARD="multi4in1:STM32F1:multistm32f103c:debug_option=native" - BOARD="multi4in1:STM32F1:multistm32f103c:debug_option=ftdi" # notifications: From a234ccbd055f014a8c575c0dbe955e7185156257 Mon Sep 17 00:00:00 2001 From: goebish Date: Sat, 12 Oct 2019 19:50:11 +0200 Subject: [PATCH 17/65] Protocol FrSkyD (D8) receiver (#283) * Rename FrSkyX Rx to FrSky Rx * Rename protocol * Add D8 receiver sub protocol --- Multiprotocol/FrSkyDVX_common.ino | 8 +- Multiprotocol/FrSkyX_Rx_cc2500.ino | 373 ----------------------------- Multiprotocol/FrSky_Rx_cc2500.ino | 365 ++++++++++++++++++++++++++++ Multiprotocol/Multi.txt | 2 +- Multiprotocol/Multiprotocol.h | 20 +- Multiprotocol/Multiprotocol.ino | 10 +- Multiprotocol/Telemetry.ino | 6 +- Multiprotocol/Validate.h | 14 +- Multiprotocol/_Config.h | 6 +- 9 files changed, 399 insertions(+), 405 deletions(-) delete mode 100644 Multiprotocol/FrSkyX_Rx_cc2500.ino create mode 100644 Multiprotocol/FrSky_Rx_cc2500.ino diff --git a/Multiprotocol/FrSkyDVX_common.ino b/Multiprotocol/FrSkyDVX_common.ino index 8f257ed..9293634 100644 --- a/Multiprotocol/FrSkyDVX_common.ino +++ b/Multiprotocol/FrSkyDVX_common.ino @@ -17,7 +17,7 @@ /** FrSky D and X routines **/ /******************************/ -#if defined(FRSKYX_CC2500_INO) || defined(FRSKYX_RX_CC2500_INO) +#if defined(FRSKYX_CC2500_INO) || defined(FRSKY_RX_CC2500_INO) //**CRC** const uint16_t PROGMEM FrSkyX_CRC_Short[]={ 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, @@ -74,7 +74,7 @@ void Frsky_init_hop(void) /******************************/ /** FrSky V, D and X routines **/ /******************************/ -#if defined(FRSKYV_CC2500_INO) || defined(FRSKYD_CC2500_INO) || defined(FRSKYX_CC2500_INO) +#if defined(FRSKYV_CC2500_INO) || defined(FRSKYD_CC2500_INO) || defined(FRSKYX_CC2500_INO) || defined(FRSKY_RX_CC2500_INO) const PROGMEM uint8_t FRSKY_common_startreg_cc2500_conf[]= { CC2500_02_IOCFG0 , CC2500_00_IOCFG2 , @@ -119,7 +119,7 @@ void Frsky_init_hop(void) /*15_DEVIATN*/ 0x41 }; #endif - #if defined(FRSKYD_CC2500_INO) + #if defined(FRSKYD_CC2500_INO) || defined(FRSKY_RX_CC2500_INO) const PROGMEM uint8_t FRSKYD_cc2500_conf[]= { /*02_IOCFG0*/ 0x06 , /*00_IOCFG2*/ 0x06 , @@ -142,7 +142,7 @@ void Frsky_init_hop(void) /*15_DEVIATN*/ 0x42 }; #endif - #if defined(FRSKYX_CC2500_INO) + #if defined(FRSKYX_CC2500_INO) || defined(FRSKY_RX_CC2500_INO) const PROGMEM uint8_t FRSKYX_cc2500_conf[]= { //FRSKYX /*02_IOCFG0*/ 0x06 , diff --git a/Multiprotocol/FrSkyX_Rx_cc2500.ino b/Multiprotocol/FrSkyX_Rx_cc2500.ino deleted file mode 100644 index a14f490..0000000 --- a/Multiprotocol/FrSkyX_Rx_cc2500.ino +++ /dev/null @@ -1,373 +0,0 @@ -/* - This project is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Multiprotocol is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Multiprotocol. If not, see . - */ - -#if defined(FRSKYX_RX_CC2500_INO) - -#include "iface_cc2500.h" - - #define FRSKYX_FCC_LENGTH (30+2) - #define FRSKYX_LBT_LENGTH (33+2) - - enum { - FRSKYX_RX_TUNE_START, - FRSKYX_RX_TUNE_LOW, - FRSKYX_RX_TUNE_HIGH, - FRSKYX_RX_BIND, - FRSKYX_RX_DATA, - }; - - static uint8_t frskyx_rx_chanskip; - static uint8_t frskyx_rx_disable_lna; - static uint8_t frskyx_rx_data_started; - static int8_t frskyx_rx_finetune; - -static void __attribute__((unused)) frskyx_rx_strobe_rx() -{ - CC2500_Strobe(CC2500_SIDLE); - CC2500_Strobe(CC2500_SFRX); - CC2500_Strobe(CC2500_SRX); -} - -static void __attribute__((unused)) FrSkyX_Rx_initialise() { - CC2500_Reset(); - - CC2500_WriteReg(CC2500_02_IOCFG0, 0x01); - CC2500_WriteReg(CC2500_18_MCSM0, 0x18); - CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x04); - CC2500_WriteReg(CC2500_3E_PATABLE, 0xFF); - CC2500_WriteReg(CC2500_0C_FSCTRL0, 0); - CC2500_WriteReg(CC2500_0D_FREQ2, 0x5C); - CC2500_WriteReg(CC2500_13_MDMCFG1, 0x23); - CC2500_WriteReg(CC2500_14_MDMCFG0, 0x7A); - CC2500_WriteReg(CC2500_19_FOCCFG, 0x16); - CC2500_WriteReg(CC2500_1A_BSCFG, 0x6C); - CC2500_WriteReg(CC2500_1B_AGCCTRL2, 0x03); - CC2500_WriteReg(CC2500_1C_AGCCTRL1, 0x40); - CC2500_WriteReg(CC2500_1D_AGCCTRL0, 0x91); - CC2500_WriteReg(CC2500_21_FREND1, 0x56); - CC2500_WriteReg(CC2500_22_FREND0, 0x10); - CC2500_WriteReg(CC2500_23_FSCAL3, 0xA9); - CC2500_WriteReg(CC2500_24_FSCAL2, 0x0A); - CC2500_WriteReg(CC2500_25_FSCAL1, 0x00); - CC2500_WriteReg(CC2500_26_FSCAL0, 0x11); - CC2500_WriteReg(CC2500_29_FSTEST, 0x59); - CC2500_WriteReg(CC2500_2C_TEST2, 0x88); - CC2500_WriteReg(CC2500_2D_TEST1, 0x31); - CC2500_WriteReg(CC2500_2E_TEST0, 0x0B); - CC2500_WriteReg(CC2500_03_FIFOTHR, 0x07); - CC2500_WriteReg(CC2500_09_ADDR, 0x00); - - switch (sub_protocol) { - case FRSKYX_FCC: - CC2500_WriteReg(CC2500_17_MCSM1, 0x0C); - CC2500_WriteReg(CC2500_0E_FREQ1, 0x76); - CC2500_WriteReg(CC2500_0F_FREQ0, 0x27); - CC2500_WriteReg(CC2500_06_PKTLEN, 0x1E); - CC2500_WriteReg(CC2500_08_PKTCTRL0, 0x01); - CC2500_WriteReg(CC2500_0B_FSCTRL1, 0x0A); - CC2500_WriteReg(CC2500_10_MDMCFG4, 0x7B); - CC2500_WriteReg(CC2500_11_MDMCFG3, 0x61); - CC2500_WriteReg(CC2500_12_MDMCFG2, 0x13); - CC2500_WriteReg(CC2500_15_DEVIATN, 0x51); - break; - case FRSKYX_LBT: - CC2500_WriteReg(CC2500_17_MCSM1, 0x0E); - CC2500_WriteReg(CC2500_0E_FREQ1, 0x80); - CC2500_WriteReg(CC2500_0F_FREQ0, 0x00); - CC2500_WriteReg(CC2500_06_PKTLEN, 0x23); - CC2500_WriteReg(CC2500_08_PKTCTRL0, 0x01); - CC2500_WriteReg(CC2500_0B_FSCTRL1, 0x08); - CC2500_WriteReg(CC2500_10_MDMCFG4, 0x7B); - CC2500_WriteReg(CC2500_11_MDMCFG3, 0xF8); - CC2500_WriteReg(CC2500_12_MDMCFG2, 0x03); - CC2500_WriteReg(CC2500_15_DEVIATN, 0x53); - break; - } - - frskyx_rx_disable_lna = IS_POWER_FLAG_on; - CC2500_SetTxRxMode(frskyx_rx_disable_lna ? TXRX_OFF : RX_EN); // lna disable / enable - - frskyx_rx_strobe_rx(); - CC2500_WriteReg(CC2500_0A_CHANNR, 0); // bind channel - delayMicroseconds(1000); // wait for RX to activate -} - -static void __attribute__((unused)) frskyx_rx_set_channel(uint8_t channel) -{ - CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[channel]); - CC2500_WriteReg(CC2500_25_FSCAL1, calData[channel]); - frskyx_rx_strobe_rx(); -} - -static void __attribute__((unused)) frskyx_rx_calibrate() -{ - frskyx_rx_strobe_rx(); - for (unsigned c = 0; c < 47; c++) - { - CC2500_Strobe(CC2500_SIDLE); - CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[c]); - CC2500_Strobe(CC2500_SCAL); - delayMicroseconds(900); - calData[c] = CC2500_ReadReg(CC2500_25_FSCAL1); - } -} - -static uint8_t __attribute__((unused)) frskyx_rx_check_crc() -{ - uint8_t limit = packet_length - 4; - uint16_t lcrc = FrSkyX_crc(&packet[3], limit - 3); // computed crc - uint16_t rcrc = (packet[limit] << 8) | (packet[limit + 1] & 0xff); // received crc - return lcrc == rcrc; -} - -static void __attribute__((unused)) frskyx_rx_build_telemetry_packet() -{ - static uint16_t frskyx_rx_rc_chan[16]; - uint16_t pxx_channel[8]; - uint32_t bits = 0; - uint8_t bitsavailable = 0; - uint8_t idx = 0; - - // decode PXX channels - pxx_channel[0] = ((packet[10] << 8) & 0xF00) | packet[9]; - pxx_channel[1] = ((packet[11] << 4) & 0xFF0) | (packet[10] >> 4); - pxx_channel[2] = ((packet[13] << 8) & 0xF00) | packet[12]; - pxx_channel[3] = ((packet[14] << 4) & 0xFF0) | (packet[13] >> 4); - pxx_channel[4] = ((packet[16] << 8) & 0xF00) | packet[15]; - pxx_channel[5] = ((packet[17] << 4) & 0xFF0) | (packet[16] >> 4); - pxx_channel[6] = ((packet[19] << 8) & 0xF00) | packet[18]; - pxx_channel[7] = ((packet[20] << 4) & 0xFF0) | (packet[19] >> 4); - for (unsigned i = 0; i < 8; i++) { - uint8_t shifted = (pxx_channel[i] & 0x800)>0; - uint16_t channel_value = pxx_channel[i] & 0x7FF; - if (channel_value < 64) - frskyx_rx_rc_chan[shifted ? i + 8 : i] = 0; - else - frskyx_rx_rc_chan[shifted ? i + 8 : i] = min(((channel_value - 64) << 4) / 15, 2047); - } - - // buid telemetry packet - packet_in[idx++] = RX_LQI; - packet_in[idx++] = RX_RSSI; - packet_in[idx++] = 0; // start channel - packet_in[idx++] = 16; // number of channels in packet - - // pack channels - for (int i = 0; i < 16; i++) { - bits |= ((uint32_t)frskyx_rx_rc_chan[i]) << bitsavailable; - bitsavailable += 11; - while (bitsavailable >= 8) { - packet_in[idx++] = bits & 0xff; - bits >>= 8; - bitsavailable -= 8; - } - } -} - -uint16_t initFrSkyX_Rx() -{ - FrSkyX_Rx_initialise(); - state = 0; - frskyx_rx_chanskip = 1; - hopping_frequency_no = 0; - frskyx_rx_data_started = 0; - frskyx_rx_finetune = 0; - telemetry_link = 0; - if (IS_BIND_IN_PROGRESS) { - phase = FRSKYX_RX_TUNE_START; - } - else { - uint16_t temp = FRSKYX_RX_EEPROM_OFFSET; - rx_tx_addr[0] = eeprom_read_byte((EE_ADDR)temp++); - rx_tx_addr[1] = eeprom_read_byte((EE_ADDR)temp++); - rx_tx_addr[2] = eeprom_read_byte((EE_ADDR)temp++); - frskyx_rx_finetune = eeprom_read_byte((EE_ADDR)temp++); - for(uint8_t ch = 0; ch < 47; ch++) - hopping_frequency[ch] = eeprom_read_byte((EE_ADDR)temp++); - frskyx_rx_calibrate(); - CC2500_WriteReg(CC2500_18_MCSM0, 0x08); // FS_AUTOCAL = manual - CC2500_WriteReg(CC2500_09_ADDR, rx_tx_addr[0]); // set address - CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x05); // check address - if (option == 0) - CC2500_WriteReg(CC2500_0C_FSCTRL0, frskyx_rx_finetune); - else - CC2500_WriteReg(CC2500_0C_FSCTRL0, option); - frskyx_rx_set_channel(hopping_frequency_no); - phase = FRSKYX_RX_DATA; - } - packet_length = (sub_protocol == FRSKYX_LBT) ? FRSKYX_LBT_LENGTH : FRSKYX_FCC_LENGTH; - return 1000; -} - -uint16_t FrSkyX_Rx_callback() -{ - static uint32_t pps_timer=0; - static uint8_t pps_counter=0; - static int8_t read_retry = 0; - static int8_t tune_low, tune_high; - uint8_t len, ch; - - if ((prev_option != option) && (phase >= FRSKYX_RX_DATA)) { - if (option == 0) - CC2500_WriteReg(CC2500_0C_FSCTRL0, frskyx_rx_finetune); - else - CC2500_WriteReg(CC2500_0C_FSCTRL0, option); - prev_option = option; - } - - if (frskyx_rx_disable_lna != IS_POWER_FLAG_on) { - frskyx_rx_disable_lna = IS_POWER_FLAG_on; - CC2500_SetTxRxMode(frskyx_rx_disable_lna ? TXRX_OFF : RX_EN); - } - - len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; - - switch(phase) { - case FRSKYX_RX_TUNE_START: - if (len >= packet_length) { - CC2500_ReadData(packet, packet_length); - if(packet[1] == 0x03 && packet[2] == 0x01) { - if(frskyx_rx_check_crc()) { - frskyx_rx_finetune = -127; - CC2500_WriteReg(CC2500_0C_FSCTRL0, frskyx_rx_finetune); - phase = FRSKYX_RX_TUNE_LOW; - frskyx_rx_strobe_rx(); - return 1000; - } - } - } - frskyx_rx_finetune += 10; - CC2500_WriteReg(CC2500_0C_FSCTRL0, frskyx_rx_finetune); - frskyx_rx_strobe_rx(); - return 18000; - - case FRSKYX_RX_TUNE_LOW: - if (len >= packet_length) { - CC2500_ReadData(packet, packet_length); - if (frskyx_rx_check_crc()) { - tune_low = frskyx_rx_finetune; - frskyx_rx_finetune = 127; - CC2500_WriteReg(CC2500_0C_FSCTRL0, frskyx_rx_finetune); - phase = FRSKYX_RX_TUNE_HIGH; - frskyx_rx_strobe_rx(); - return 1000; - } - } - frskyx_rx_finetune += 1; - CC2500_WriteReg(CC2500_0C_FSCTRL0, frskyx_rx_finetune); - frskyx_rx_strobe_rx(); - return 18000; - - case FRSKYX_RX_TUNE_HIGH: - if (len >= packet_length) { - CC2500_ReadData(packet, packet_length); - if (frskyx_rx_check_crc()) { - tune_high = frskyx_rx_finetune; - frskyx_rx_finetune = (tune_low + tune_high) / 2; - CC2500_WriteReg(CC2500_0C_FSCTRL0, (int8_t)frskyx_rx_finetune); - if(tune_low < tune_high) - phase = FRSKYX_RX_BIND; - else - phase = FRSKYX_RX_TUNE_START; - frskyx_rx_strobe_rx(); - return 1000; - } - } - frskyx_rx_finetune -= 1; - CC2500_WriteReg(CC2500_0C_FSCTRL0, frskyx_rx_finetune); - frskyx_rx_strobe_rx(); - return 18000; - - case FRSKYX_RX_BIND: - if(len >= packet_length) { - CC2500_ReadData(packet, packet_length); - if (frskyx_rx_check_crc()) { - if (packet[5] <= 0x2D) { - for (ch = 0; ch < 5; ch++) - hopping_frequency[packet[5]+ch] = packet[6+ch]; - state |= 1 << (packet[5] / 5); - } - } - if (state == 0x3ff) { - debugln("bind complete"); - frskyx_rx_calibrate(); - rx_tx_addr[0] = packet[3]; // TXID - rx_tx_addr[1] = packet[4]; // TXID - rx_tx_addr[2] = packet[12]; // RX # - CC2500_WriteReg(CC2500_18_MCSM0, 0x08); // FS_AUTOCAL = manual - CC2500_WriteReg(CC2500_09_ADDR, rx_tx_addr[0]); // set address - CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x05); // check address - phase = FRSKYX_RX_DATA; - frskyx_rx_set_channel(hopping_frequency_no); - // store txid and channel list - uint16_t temp = FRSKYX_RX_EEPROM_OFFSET; - eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[0]); - eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[1]); - eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[2]); - eeprom_write_byte((EE_ADDR)temp++, frskyx_rx_finetune); - for (ch = 0; ch < 47; ch++) - eeprom_write_byte((EE_ADDR)temp++, hopping_frequency[ch]); - BIND_DONE; - } - frskyx_rx_strobe_rx(); - } - return 1000; - - case FRSKYX_RX_DATA: - if (len >= packet_length) { - CC2500_ReadData(packet, packet_length); - if (packet[1] == rx_tx_addr[0] && packet[2] == rx_tx_addr[1] && packet[6] == rx_tx_addr[2] && frskyx_rx_check_crc()) { - RX_RSSI = packet[packet_length-2]; - if(RX_RSSI >= 128) - RX_RSSI -= 128; - else - RX_RSSI += 128; - // hop to next channel - frskyx_rx_chanskip = ((packet[4] & 0xC0) >> 6) | ((packet[5] & 0x3F) << 2); - hopping_frequency_no = (hopping_frequency_no + frskyx_rx_chanskip) % 47; - frskyx_rx_set_channel(hopping_frequency_no); - if(packet[7] == 0 && telemetry_link == 0) { // standard packet, send channels to TX - frskyx_rx_build_telemetry_packet(); - telemetry_link = 1; - } - frskyx_rx_data_started = 1; - read_retry = 0; - pps_counter++; - } - } - - // packets per second - if (millis() - pps_timer >= 1000) { - pps_timer = millis(); - debugln("%d pps", pps_counter); - RX_LQI = pps_counter; - pps_counter = 0; - } - - // skip channel if no packet received in time - if (read_retry++ >= 9) { - hopping_frequency_no = (hopping_frequency_no + frskyx_rx_chanskip) % 47; - frskyx_rx_set_channel(hopping_frequency_no); - if(frskyx_rx_data_started) - read_retry = 0; - else - read_retry = -50; // retry longer until first packet is catched - } - break; - } - return 1000; -} - -#endif diff --git a/Multiprotocol/FrSky_Rx_cc2500.ino b/Multiprotocol/FrSky_Rx_cc2500.ino new file mode 100644 index 0000000..09e3bbf --- /dev/null +++ b/Multiprotocol/FrSky_Rx_cc2500.ino @@ -0,0 +1,365 @@ +/* + This project is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Multiprotocol is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Multiprotocol. If not, see . + */ + +#if defined(FRSKY_RX_CC2500_INO) + +#include "iface_cc2500.h" + + #define FRSKY_RX_D16FCC_LENGTH 32 + #define FRSKY_RX_D16LBT_LENGTH 35 + #define FRSKY_RX_D8_LENGTH 20 + + enum { + FRSKY_RX_TUNE_START, + FRSKY_RX_TUNE_LOW, + FRSKY_RX_TUNE_HIGH, + FRSKY_RX_BIND, + FRSKY_RX_DATA, + }; + + static uint8_t frsky_rx_chanskip; + static uint8_t frsky_rx_disable_lna; + static uint8_t frsky_rx_data_started; + static int8_t frsky_rx_finetune; + static uint16_t frsky_rx_rc_chan[16]; + +static void __attribute__((unused)) frsky_rx_strobe_rx() +{ + CC2500_Strobe(CC2500_SIDLE); + CC2500_Strobe(CC2500_SFRX); + CC2500_Strobe(CC2500_SRX); +} + +static void __attribute__((unused)) frsky_rx_initialise() { + CC2500_Reset(); + CC2500_Strobe(CC2500_SIDLE); + CC2500_WriteReg(CC2500_0A_CHANNR, 0); // bind channel + switch (sub_protocol) { + case FRSKY_RX_D16FCC: + FRSKY_init_cc2500(FRSKYX_cc2500_conf); + break; + case FRSKY_RX_D16LBT: + FRSKY_init_cc2500(FRSKYXEU_cc2500_conf); + break; + case FRSKY_RX_D8: + FRSKY_init_cc2500(FRSKYD_cc2500_conf); + CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x05); // always check address + CC2500_WriteReg(CC2500_09_ADDR, 0x03); // bind address + CC2500_WriteReg(CC2500_23_FSCAL3, 0x89); // fixed FSCAL3 ? + break; + } + frsky_rx_disable_lna = IS_POWER_FLAG_on; + CC2500_SetTxRxMode(frsky_rx_disable_lna ? TXRX_OFF : RX_EN); // lna disable / enable + frsky_rx_strobe_rx(); + delayMicroseconds(1000); // wait for RX to activate +} + +static void __attribute__((unused)) frsky_rx_set_channel(uint8_t channel) +{ + CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[channel]); + if(sub_protocol == FRSKY_RX_D8) + CC2500_WriteReg(CC2500_23_FSCAL3, 0x89); + else + CC2500_WriteReg(CC2500_25_FSCAL1, calData[channel]); + frsky_rx_strobe_rx(); +} + +static void __attribute__((unused)) frsky_rx_calibrate() +{ + frsky_rx_strobe_rx(); + for (unsigned c = 0; c < 47; c++) + { + CC2500_Strobe(CC2500_SIDLE); + CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[c]); + CC2500_Strobe(CC2500_SCAL); + delayMicroseconds(900); + calData[c] = CC2500_ReadReg(CC2500_25_FSCAL1); + } +} + +static uint8_t __attribute__((unused)) frskyx_rx_check_crc() +{ + if (sub_protocol == FRSKY_RX_D8) + return 1; + uint8_t limit = packet_length - 4; + uint16_t lcrc = FrSkyX_crc(&packet[3], limit - 3); // computed crc + uint16_t rcrc = (packet[limit] << 8) | (packet[limit + 1] & 0xff); // received crc + return lcrc == rcrc; +} + +static void __attribute__((unused)) frsky_rx_build_telemetry_packet() +{ + uint16_t raw_channel[8]; + uint32_t bits = 0; + uint8_t bitsavailable = 0; + uint8_t idx = 0; + uint8_t i; + + if (sub_protocol == FRSKY_RX_D16FCC || sub_protocol == FRSKY_RX_D16LBT) { + // decode D16 channels + raw_channel[0] = ((packet[10] << 8) & 0xF00) | packet[9]; + raw_channel[1] = ((packet[11] << 4) & 0xFF0) | (packet[10] >> 4); + raw_channel[2] = ((packet[13] << 8) & 0xF00) | packet[12]; + raw_channel[3] = ((packet[14] << 4) & 0xFF0) | (packet[13] >> 4); + raw_channel[4] = ((packet[16] << 8) & 0xF00) | packet[15]; + raw_channel[5] = ((packet[17] << 4) & 0xFF0) | (packet[16] >> 4); + raw_channel[6] = ((packet[19] << 8) & 0xF00) | packet[18]; + raw_channel[7] = ((packet[20] << 4) & 0xFF0) | (packet[19] >> 4); + for (i = 0; i < 8; i++) { + uint8_t shifted = (raw_channel[i] & 0x800)>0; + uint16_t channel_value = raw_channel[i] & 0x7FF; + if (channel_value < 64) + frsky_rx_rc_chan[shifted ? i + 8 : i] = 0; + else + frsky_rx_rc_chan[shifted ? i + 8 : i] = min(((channel_value - 64) << 4) / 15, 2047); + } + } + else { + // decode D8 channels + raw_channel[0] = ((packet[10] & 0x0F) << 8 | packet[6]); + raw_channel[1] = ((packet[10] & 0xF0) << 4 | packet[7]); + raw_channel[2] = ((packet[11] & 0x0F) << 8 | packet[8]); + raw_channel[3] = ((packet[11] & 0xF0) << 4 | packet[9]); + raw_channel[4] = ((packet[16] & 0x0F) << 8 | packet[12]); + raw_channel[5] = ((packet[16] & 0xF0) << 4 | packet[13]); + raw_channel[6] = ((packet[17] & 0x0F) << 8 | packet[14]); + raw_channel[7] = ((packet[17] & 0xF0) << 4 | packet[15]); + for (i = 0; i < 8; i++) { + if (raw_channel[i] < 1290) + raw_channel[i] = 1290; + frsky_rx_rc_chan[i] = min(((raw_channel[i] - 1290) << 4) / 15, 2047); + } + } + + // buid telemetry packet + packet_in[idx++] = RX_LQI; + packet_in[idx++] = RX_RSSI; + packet_in[idx++] = 0; // start channel + packet_in[idx++] = sub_protocol == FRSKY_RX_D8 ? 8 : 16; // number of channels in packet + + // pack channels + for (i = 0; i < packet_in[3]; i++) { + bits |= ((uint32_t)frsky_rx_rc_chan[i]) << bitsavailable; + bitsavailable += 11; + while (bitsavailable >= 8) { + packet_in[idx++] = bits & 0xff; + bits >>= 8; + bitsavailable -= 8; + } + } +} + +uint16_t initFrSky_Rx() +{ + const uint8_t frsky_rx_length[] = {FRSKY_RX_D16FCC_LENGTH, FRSKY_RX_D16LBT_LENGTH, FRSKY_RX_D8_LENGTH}; + packet_length = frsky_rx_length[sub_protocol]; + frsky_rx_initialise(); + state = 0; + frsky_rx_chanskip = 1; + hopping_frequency_no = 0; + frsky_rx_data_started = 0; + frsky_rx_finetune = 0; + telemetry_link = 0; + for(uint8_t ch=0; ch= FRSKY_RX_DATA)) { + if (option == 0) + CC2500_WriteReg(CC2500_0C_FSCTRL0, frsky_rx_finetune); + else + CC2500_WriteReg(CC2500_0C_FSCTRL0, option); + prev_option = option; + } + + if (frsky_rx_disable_lna != IS_POWER_FLAG_on) { + frsky_rx_disable_lna = IS_POWER_FLAG_on; + CC2500_SetTxRxMode(frsky_rx_disable_lna ? TXRX_OFF : RX_EN); + } + + len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; + + switch(phase) { + case FRSKY_RX_TUNE_START: + if (len >= packet_length) { + CC2500_ReadData(packet, packet_length); + if(packet[1] == 0x03 && packet[2] == 0x01) { + if(frskyx_rx_check_crc()) { + frsky_rx_finetune = -127; + CC2500_WriteReg(CC2500_0C_FSCTRL0, frsky_rx_finetune); + phase = FRSKY_RX_TUNE_LOW; + frsky_rx_strobe_rx(); + return 1000; + } + } + } + frsky_rx_finetune += 10; + CC2500_WriteReg(CC2500_0C_FSCTRL0, frsky_rx_finetune); + frsky_rx_strobe_rx(); + return 18000; + + case FRSKY_RX_TUNE_LOW: + if (len >= packet_length) { + CC2500_ReadData(packet, packet_length); + if (frskyx_rx_check_crc()) { + tune_low = frsky_rx_finetune; + frsky_rx_finetune = 127; + CC2500_WriteReg(CC2500_0C_FSCTRL0, frsky_rx_finetune); + phase = FRSKY_RX_TUNE_HIGH; + frsky_rx_strobe_rx(); + return 1000; + } + } + frsky_rx_finetune += 1; + CC2500_WriteReg(CC2500_0C_FSCTRL0, frsky_rx_finetune); + frsky_rx_strobe_rx(); + return 18000; + + case FRSKY_RX_TUNE_HIGH: + if (len >= packet_length) { + CC2500_ReadData(packet, packet_length); + if (frskyx_rx_check_crc()) { + tune_high = frsky_rx_finetune; + frsky_rx_finetune = (tune_low + tune_high) / 2; + CC2500_WriteReg(CC2500_0C_FSCTRL0, (int8_t)frsky_rx_finetune); + if(tune_low < tune_high) + phase = FRSKY_RX_BIND; + else + phase = FRSKY_RX_TUNE_START; + frsky_rx_strobe_rx(); + return 1000; + } + } + frsky_rx_finetune -= 1; + CC2500_WriteReg(CC2500_0C_FSCTRL0, frsky_rx_finetune); + frsky_rx_strobe_rx(); + return 18000; + + case FRSKY_RX_BIND: + if(len >= packet_length) { + CC2500_ReadData(packet, packet_length); + if (frskyx_rx_check_crc()) { + if (packet[5] <= 0x2D) { + for (ch = 0; ch < 5; ch++) + hopping_frequency[packet[5]+ch] = packet[6+ch]; + state |= 1 << (packet[5] / 5); + } + } + if (state == 0x3ff) { + debugln("bind complete"); + frsky_rx_calibrate(); + rx_tx_addr[0] = packet[3]; // TXID + rx_tx_addr[1] = packet[4]; // TXID + rx_tx_addr[2] = packet[12]; // RX # (D16) + if (sub_protocol == FRSKY_RX_D16FCC || sub_protocol == FRSKY_RX_D16LBT) + CC2500_WriteReg(CC2500_18_MCSM0, 0x08); // FS_AUTOCAL = manual + CC2500_WriteReg(CC2500_09_ADDR, rx_tx_addr[0]); // set address + CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x05); // check address + phase = FRSKY_RX_DATA; + frsky_rx_set_channel(hopping_frequency_no); + // store txid and channel list + uint16_t temp = FRSKY_RX_EEPROM_OFFSET; + eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[0]); + eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[1]); + eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[2]); + eeprom_write_byte((EE_ADDR)temp++, frsky_rx_finetune); + for (ch = 0; ch < 47; ch++) + eeprom_write_byte((EE_ADDR)temp++, hopping_frequency[ch]); + BIND_DONE; + } + frsky_rx_strobe_rx(); + } + return 1000; + + case FRSKY_RX_DATA: + if (len >= packet_length) { + CC2500_ReadData(packet, packet_length); + if (packet[1] == rx_tx_addr[0] && packet[2] == rx_tx_addr[1] && frskyx_rx_check_crc() && (sub_protocol == FRSKY_RX_D8 || packet[6] == rx_tx_addr[2])) { + RX_RSSI = packet[packet_length-2]; + if(RX_RSSI >= 128) + RX_RSSI -= 128; + else + RX_RSSI += 128; + // hop to next channel + if (sub_protocol == FRSKY_RX_D16FCC || sub_protocol == FRSKY_RX_D16LBT) + frsky_rx_chanskip = ((packet[4] & 0xC0) >> 6) | ((packet[5] & 0x3F) << 2); + hopping_frequency_no = (hopping_frequency_no + frsky_rx_chanskip) % 47; + frsky_rx_set_channel(hopping_frequency_no); + if((sub_protocol == FRSKY_RX_D8 || packet[7] == 0) && telemetry_link == 0) { // send channels to TX + frsky_rx_build_telemetry_packet(); + telemetry_link = 1; + } + frsky_rx_data_started = 1; + read_retry = 0; + pps_counter++; + } + } + + // packets per second + if (millis() - pps_timer >= 1000) { + pps_timer = millis(); + debugln("%d pps", pps_counter); + RX_LQI = pps_counter; + pps_counter = 0; + } + + // skip channel if no packet received in time + if (read_retry++ >= 9) { + hopping_frequency_no = (hopping_frequency_no + frsky_rx_chanskip) % 47; + frsky_rx_set_channel(hopping_frequency_no); + if(frsky_rx_data_started) + read_retry = 0; + else + read_retry = -50; // retry longer until first packet is catched + } + break; + } + return 1000; +} + +#endif diff --git a/Multiprotocol/Multi.txt b/Multiprotocol/Multi.txt index b866d0b..2542135 100644 --- a/Multiprotocol/Multi.txt +++ b/Multiprotocol/Multi.txt @@ -52,6 +52,6 @@ 52,ZSX,280 53,Flyzone,FZ-410 54,Scanner -55,FrskyX_RX,FCC,EU_LBT +55,Frsky_RX,D16FCC,D16LBT,D8 56,AFHDS2A_RX 63,XN_DUMP,250K,1M,2M diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index dcad97a..e867a25 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -81,7 +81,7 @@ enum PROTOCOLS PROTO_ZSX = 52, // =>NRF24L01 PROTO_FLYZONE = 53, // =>A7105 PROTO_SCANNER = 54, // =>CC2500 - PROTO_FRSKYX_RX = 55, // =>CC2500 + PROTO_FRSKY_RX = 55, // =>CC2500 PROTO_AFHDS2A_RX= 56, // =>A7105 PROTO_XN297DUMP = 63, // =>NRF24L01 }; @@ -290,10 +290,11 @@ enum TRAXXAS { RX6519 = 0, }; -enum FRSKYX_RX +enum FRSKY_RX { - FRSKYX_FCC = 0, - FRSKYX_LBT + FRSKY_RX_D16FCC= 0, + FRSKY_RX_D16LBT, + FRSKY_RX_D8 }; #define NONE 0 @@ -594,7 +595,7 @@ enum { #define AFHDS2A_EEPROM_OFFSET 50 // RX ID, 4 bytes per model id, end is 50+64=114 #define BUGS_EEPROM_OFFSET 114 // RX ID, 2 bytes per model id, end is 114+32=146 #define BUGSMINI_EEPROM_OFFSET 146 // RX ID, 2 bytes per model id, end is 146+32=178 -#define FRSKYX_RX_EEPROM_OFFSET 178 // (3) TX ID + (1) freq_tune + (47) channels, 51 bytes, end is 178+51=229 +#define FRSKY_RX_EEPROM_OFFSET 178 // (3) TX ID + (1) freq_tune + (47) channels, 51 bytes, end is 178+51=229 #define AFHDS2A_RX_EEPROM_OFFSET 229 // (4) TX ID + (16) channels, 20 bytes, end is 229+20=249 #define AFHDS2A_EEPROM_OFFSET2 249 // RX ID, 4 bytes per model id, end is 249+192=441 //#define CONFIG_EEPROM_OFFSET 441 // Current configuration of the multimodule @@ -670,7 +671,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- ZSX 52 FLYZONE 53 SCANNER 54 - FRSKYX_RX 55 + FRSKY_RX 55 BindBit=> 0x80 1=Bind/0=No AutoBindBit=> 0x40 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No @@ -812,9 +813,10 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- RED_SLOW 1 sub_protocol==TRAXXAS RX6519 0 - sub_protocol==FRSKYX_RX - FCC 0 - LBT 1 + sub_protocol==FRSKY_RX + FRSKY_RX_D16FCC 0 + FRSKY_RX_D16LBT 1 + FRSKY_RX_D8 2 Power value => 0x80 0=High/1=Low Stream[3] = option_protocol; diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 3494c6f..e65809b 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -668,7 +668,7 @@ uint8_t Update_All() update_led_status(); #if defined(TELEMETRY) #if ( !( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) ) - if( (protocol == PROTO_FRSKYX_RX) || (protocol == PROTO_SCANNER) || (protocol==PROTO_FRSKYD) || (protocol==PROTO_BAYANG) || (protocol==PROTO_NCC1701) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_FRSKYX) || (protocol==PROTO_DSM) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC)) + if( (protocol == PROTO_FRSKY_RX) || (protocol == PROTO_SCANNER) || (protocol==PROTO_FRSKYD) || (protocol==PROTO_BAYANG) || (protocol==PROTO_NCC1701) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_FRSKYX) || (protocol==PROTO_DSM) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC)) #endif if(IS_DISABLE_TELEM_off && !(protocol==PROTO_XN297DUMP)) TelemetryUpdate(); @@ -1086,12 +1086,12 @@ static void protocol_init() remote_callback = Scanner_callback; break; #endif - #if defined(FRSKYX_RX_CC2500_INO) - case PROTO_FRSKYX_RX: + #if defined(FRSKY_RX_CC2500_INO) + case PROTO_FRSKY_RX: PE1_off; PE2_on; //antenna RF2 - next_callback = initFrSkyX_Rx(); - remote_callback = FrSkyX_Rx_callback; + next_callback = initFrSky_Rx(); + remote_callback = FrSky_Rx_callback; break; #endif #endif diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 3ae816c..2d19b15 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -226,7 +226,7 @@ static void multi_send_status() } #endif -#if defined (FRSKYX_RX_TELEMETRY) || defined (AFHDS2A_RX_TELEMETRY) +#if defined (FRSKY_RX_TELEMETRY) || defined (AFHDS2A_RX_TELEMETRY) void receiver_channels_frame() { uint16_t len = packet_in[3] * 11; // 11 bit per channel @@ -861,8 +861,8 @@ void TelemetryUpdate() } #endif - #if defined (FRSKYX_RX_TELEMETRY) || defined(AFHDS2A_RX_TELEMETRY) - if (telemetry_link && (protocol == PROTO_FRSKYX_RX || protocol == PROTO_AFHDS2A_RX)) + #if defined (FRSKY_RX_TELEMETRY) || defined(AFHDS2A_RX_TELEMETRY) + if (telemetry_link && (protocol == PROTO_FRSKY_RX || protocol == PROTO_AFHDS2A_RX)) { receiver_channels_frame(); telemetry_link = 0; diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index 51a2116..aa11e91 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -194,7 +194,7 @@ #undef HITEC_CC2500_INO #undef XN297L_CC2500_EMU #undef SCANNER_CC2500_INO - #undef FRSKYX_RX_CC2500_INO + #undef FRSKY_RX_CC2500_INO #endif #ifndef NRF24L01_INSTALLED #undef BAYANG_NRF24L01_INO @@ -253,8 +253,8 @@ #undef MULTI_TELEMETRY #undef SCANNER_TELEMETRY #undef SCANNER_CC2500_INO - #undef FRSKYX_RX_TELEMETRY - #undef FRSKYX_RX_CC2500_INO + #undef FRSKY_RX_TELEMETRY + #undef FRSKY_RX_CC2500_INO #undef AFHDS2A_RX_TELEMETRY #undef AFHDS2A_RX_A7105_INO #else @@ -265,9 +265,9 @@ #undef SCANNER_TELEMETRY #undef SCANNER_CC2500_INO #endif - #if not defined(FRSKYX_RX_CC2500_INO) || not defined(FRSKYX_RX_TELEMETRY) - #undef FRSKYX_RX_TELEMETRY - #undef FRSKYX_RX_CC2500_INO + #if not defined(FRSKY_RX_CC2500_INO) || not defined(FRSKY_RX_TELEMETRY) + #undef FRSKY_RX_TELEMETRY + #undef FRSKY_RX_CC2500_INO #endif #if not defined(AFHDS2A_RX_A7105_INO) || not defined(AFHDS2A_RX_TELEMETRY) #undef AFHDS2A_RX_TELEMETRY @@ -309,7 +309,7 @@ #if not defined(DSM_CYRF6936_INO) #undef DSM_TELEMETRY #endif - #if not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKYX_RX_TELEMETRY) + #if not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKY_RX_TELEMETRY) #undef TELEMETRY #undef INVERT_TELEMETRY #endif diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 3efd302..3767a01 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -176,7 +176,7 @@ #define FRSKYD_CC2500_INO #define FRSKYV_CC2500_INO #define FRSKYX_CC2500_INO -#define FRSKYX_RX_CC2500_INO +#define FRSKY_RX_CC2500_INO #define HITEC_CC2500_INO #define SCANNER_CC2500_INO #define SFHSS_CC2500_INO @@ -288,7 +288,7 @@ #define HITEC_HUB_TELEMETRY // Use FrSkyD Hub format to send basic telemetry to the radios which can decode it like er9x, ersky9x and OpenTX #define HITEC_FW_TELEMETRY // Under development: Forward received telemetry packets to be decoded by ersky9x and OpenTX #define SCANNER_TELEMETRY // Forward spectrum scanner data to TX -#define FRSKYX_RX_TELEMETRY // Forward channels data to TX +#define FRSKY_RX_TELEMETRY // Forward channels data to TX #define AFHDS2A_RX_TELEMETRY // Forward channels data to TX /****************************/ @@ -545,7 +545,7 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= { CH_8 EU_16 EU_8 - PROTO_FRSKYX_RX + PROTO_FRSKY_RX FRSKYX_FCC FRSKYX_LBT PROTO_FY326 From 31ff27b1d3bb450d02d7532e177d3d50b924daf3 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sat, 12 Oct 2019 19:50:41 +0200 Subject: [PATCH 18/65] PPM mode FrSkyX to FrSkyD If TELEMETRY_FRSKYX_TO_FRSKYD is defined in PPM mode FrSkyX simple telemetry will be sent using FrSkyD format: RX_RSSI, RX_Batt, TX_RSSI, TX_LQI --- Multiprotocol/AFHDS2A_a7105.ino | 3 --- Multiprotocol/BUGSMINI_nrf24l01.ino | 3 --- Multiprotocol/Bayang_nrf24l01.ino | 4 ---- Multiprotocol/Bugs_a7105.ino | 3 --- Multiprotocol/CABELL_nrf224l01.ino | 4 ---- Multiprotocol/FrSkyD_cc2500.ino | 3 --- Multiprotocol/Hitec_cc2500.ino | 4 ---- Multiprotocol/Hubsan_a7105.ino | 3 --- Multiprotocol/Multiprotocol.h | 6 +++--- Multiprotocol/Multiprotocol.ino | 23 ++++++++++++-------- Multiprotocol/NCC1701_nrf24l01.ino | 3 --- Multiprotocol/Telemetry.ino | 33 +++++++++++++++++++---------- Multiprotocol/_Config.h | 25 +++++++++++++--------- 13 files changed, 54 insertions(+), 63 deletions(-) diff --git a/Multiprotocol/AFHDS2A_a7105.ino b/Multiprotocol/AFHDS2A_a7105.ino index 5456c77..acdfb6f 100644 --- a/Multiprotocol/AFHDS2A_a7105.ino +++ b/Multiprotocol/AFHDS2A_a7105.ino @@ -404,9 +404,6 @@ uint16_t initAFHDS2A() rx_id[i]=eeprom_read_byte((EE_ADDR)(addr+i)); } hopping_frequency_no = 0; -#if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY) - init_frskyd_link_telemetry(); -#endif return 50000; } #endif diff --git a/Multiprotocol/BUGSMINI_nrf24l01.ino b/Multiprotocol/BUGSMINI_nrf24l01.ino index 43fa1b0..8672a4e 100644 --- a/Multiprotocol/BUGSMINI_nrf24l01.ino +++ b/Multiprotocol/BUGSMINI_nrf24l01.ino @@ -376,9 +376,6 @@ uint16_t initBUGSMINI() armed = 0; arm_flags = BUGSMINI_FLAG_DISARM; // initial value from captures arm_channel_previous = BUGSMINI_CH_SW_ARM; - #ifdef BUGS_HUB_TELEMETRY - init_frskyd_link_telemetry(); - #endif return BUGSMINI_INITIAL_WAIT; } diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index f31c4a5..4d57e1b 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -352,10 +352,6 @@ uint16_t initBAYANG(void) BAYANG_initialize_txid(); BAYANG_init(); packet_count=0; - #ifdef BAYANG_HUB_TELEMETRY - init_frskyd_link_telemetry(); - telemetry_lost=1; // do not send telemetry to TX right away until we have a TX_RSSI value to prevent warning message... - #endif return BAYANG_INITIAL_WAIT+BAYANG_PACKET_PERIOD; } diff --git a/Multiprotocol/Bugs_a7105.ino b/Multiprotocol/Bugs_a7105.ino index 474e110..00f667b 100644 --- a/Multiprotocol/Bugs_a7105.ino +++ b/Multiprotocol/Bugs_a7105.ino @@ -457,9 +457,6 @@ uint16_t initBUGS(void) armed = 0; arm_flags = BUGS_FLAG_DISARM; // initial value from captures arm_channel_previous = BUGS_CH_SW_ARM; - #ifdef BUGS_HUB_TELEMETRY - init_frskyd_link_telemetry(); - #endif return 10000; } diff --git a/Multiprotocol/CABELL_nrf224l01.ino b/Multiprotocol/CABELL_nrf224l01.ino index e778405..1b7e4bf 100644 --- a/Multiprotocol/CABELL_nrf224l01.ino +++ b/Multiprotocol/CABELL_nrf224l01.ino @@ -430,10 +430,6 @@ uint16_t initCABELL(void) else bind_counter = CABELL_BIND_COUNT; CABELL_init(); - #if defined CABELL_HUB_TELEMETRY - init_frskyd_link_telemetry(); - telemetry_lost=1; // do not send telemetry to TX right away until we have a TX_RSSI value to prevent warning message... - #endif packet_period = CABELL_PACKET_PERIOD; diff --git a/Multiprotocol/FrSkyD_cc2500.ino b/Multiprotocol/FrSkyD_cc2500.ino index a587ff8..ceb415f 100644 --- a/Multiprotocol/FrSkyD_cc2500.ino +++ b/Multiprotocol/FrSkyD_cc2500.ino @@ -97,9 +97,6 @@ uint16_t initFrSky_2way() { Frsky_init_hop(); packet_count=0; - #if defined TELEMETRY - init_frskyd_link_telemetry(); - #endif if(IS_BIND_IN_PROGRESS) { frsky2way_init(1); diff --git a/Multiprotocol/Hitec_cc2500.ino b/Multiprotocol/Hitec_cc2500.ino index b88bfc1..f28f5f6 100644 --- a/Multiprotocol/Hitec_cc2500.ino +++ b/Multiprotocol/Hitec_cc2500.ino @@ -392,10 +392,6 @@ uint16_t initHITEC() rx_tx_addr[3]=0x6A; memcpy((void *)hopping_frequency,(void *)"\x00\x3A\x4A\x32\x0C\x58\x2A\x10\x26\x20\x08\x60\x68\x70\x78\x80\x88\x56\x5E\x66\x6E",HITEC_NUM_FREQUENCE); #endif - #if defined(HITEC_HUB_TELEMETRY) - if(sub_protocol==OPT_HUB) - init_frskyd_link_telemetry(); - #endif phase = HITEC_START; return 10000; } diff --git a/Multiprotocol/Hubsan_a7105.ino b/Multiprotocol/Hubsan_a7105.ino index e38bb70..014871f 100644 --- a/Multiprotocol/Hubsan_a7105.ino +++ b/Multiprotocol/Hubsan_a7105.ino @@ -465,9 +465,6 @@ uint16_t initHubsan() } packet_count=0; bind_phase=0; - #ifdef HUBSAN_HUB_TELEMETRY - init_frskyd_link_telemetry(); - #endif return 10000; } diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index dcad97a..88661a1 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 13 +#define VERSION_PATCH_LEVEL 14 //****************** // Protocols @@ -607,7 +607,7 @@ enum { 16 channels serial protocol *************************** Serial: 100000 Baud 8e2 _ xxxx xxxx p -- - Total of 26 bytes for protocol V1, variable length for protocol V2 + Total of 26 bytes for protocol V1, variable length 27..36 for protocol V2 Stream[0] = header 0x55 sub_protocol values are 0..31 Stream contains channels 0x54 sub_protocol values are 32..63 Stream contains channels @@ -836,7 +836,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- Future_Use => 0x04 0= , 1= Disable_Telemetry => 0x02 0=enable, 1=disable Disable_CH_Mapping => 0x01 0=enable, 1=disable - Stream[27.. 36] = between 0 and 9 bytes for additional protocol data + Stream[27.. 35] = between 0 and 9 bytes for additional protocol data */ /* Multimodule Status diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 3494c6f..c39c53a 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -937,8 +937,7 @@ static void protocol_init() #endif tx_pause(); pass=0; - telemetry_link=0; - telemetry_lost=1; + init_frskyd_link_telemetry(); #ifdef BASH_SERIAL TIMSK0 = 0 ; // Stop all timer 0 interrupts #ifdef INVERT_SERIAL @@ -1883,10 +1882,16 @@ void pollBoot() #if defined(TELEMETRY) void PPM_Telemetry_serial_init() { - if( (protocol==PROTO_FRSKYD) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_BAYANG)|| (protocol==PROTO_NCC1701) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI)) + if( (protocol==PROTO_FRSKYD) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_BAYANG)|| (protocol==PROTO_NCC1701) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI) + #ifdef TELEMETRY_FRSKYX_TO_FRSKYD + || (protocol==PROTO_FRSKYX) + #endif + ) initTXSerial( SPEED_9600 ) ; - if(protocol==PROTO_FRSKYX) - initTXSerial( SPEED_57600 ) ; + #ifndef TELEMETRY_FRSKYX_TO_FRSKYD + if(protocol==PROTO_FRSKYX) + initTXSerial( SPEED_57600 ) ; + #endif if(protocol==PROTO_DSM) initTXSerial( SPEED_125K ) ; } @@ -2028,14 +2033,14 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) #endif { #if defined STM32_BOARD - TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15us=1.5 byte + TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 360; // Next byte should show up within 18??s=1.5 byte TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag TIMER2_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer2/Comp2 interrupt #else TX_RX_PAUSE_on; tx_pause(); cli(); // Disable global int due to RW of 16 bits registers - OCR1B = TCNT1 + 300; // Next byte should show up within 15us=1.5 byte + OCR1B = TCNT1 + 360; // Next byte should show up within 18??s=1.5 byte sei(); // Enable global int TIFR1 = OCF1B_bm ; // clear OCR1B match flag SET_TIMSK1_OCIE1B ; // enable interrupt on compare B match @@ -2054,10 +2059,10 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { rx_buff[rx_idx++]=UDR0; // Store received byte #if defined STM32_BOARD - TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 300; // Next byte should show up within 15us=1.5 byte + TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 360; // Next byte should show up within 18??s=1.5 byte #else cli(); // Disable global int due to RW of 16 bits registers - OCR1B = TCNT1 + 300; // Next byte should show up within 15us=1.5 byte + OCR1B = TCNT1 + 360; // Next byte should show up within 18??s=1.5 byte sei(); // Enable global int #endif } diff --git a/Multiprotocol/NCC1701_nrf24l01.ino b/Multiprotocol/NCC1701_nrf24l01.ino index de919e6..dff58ab 100644 --- a/Multiprotocol/NCC1701_nrf24l01.ino +++ b/Multiprotocol/NCC1701_nrf24l01.ino @@ -269,9 +269,6 @@ uint16_t initNCC(void) hopping_frequency_no=4; // start with bind NCC_init(); phase=NCC_BIND_TX1; - #ifdef NCC1701_HUB_TELEMETRY - init_frskyd_link_telemetry(); - #endif return 10000; } diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 3ae816c..ca6a39c 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -369,7 +369,13 @@ void frsky_check_telemetry(uint8_t *packet_in,uint8_t len) RX_RSSI=packet_in[4] & 0x7F ; else RxBt = (packet_in[4]<<1) + 1 ; - + #if defined(TELEMETRY_FRSKYX_TO_FRSKYD) && defined(ENABLE_PPM) + if(mode_select != MODE_SERIAL) + {//PPM + v_lipo1=RxBt; + return; + } + #endif //Save outgoing telemetry sequence FrSkyX_TX_IN_Seq=packet_in[5] >> 4; @@ -447,6 +453,7 @@ void init_frskyd_link_telemetry() { telemetry_link=0; telemetry_counter=0; + telemetry_lost=1; v_lipo1=0; v_lipo2=0; RX_RSSI=0; @@ -467,13 +474,12 @@ void frsky_link_frame() telemetry_link |= 2 ; // Send hub if available } else - if (protocol==PROTO_HUBSAN||protocol==PROTO_AFHDS2A||protocol==PROTO_BAYANG||protocol==PROTO_NCC1701||protocol==PROTO_CABELL||protocol==PROTO_HITEC||protocol==PROTO_BUGS||protocol==PROTO_BUGSMINI) - { - frame[1] = v_lipo1; - frame[2] = v_lipo2; - frame[3] = RX_RSSI; - telemetry_link=0; - } + {//PROTO_HUBSAN, PROTO_AFHDS2A, PROTO_BAYANG, PROTO_NCC1701, PROTO_CABELL, PROTO_HITEC, PROTO_BUGS, PROTO_BUGSMINI, PROTO_FRSKYX + frame[1] = v_lipo1; + frame[2] = v_lipo2; + frame[3] = RX_RSSI; + telemetry_link=0; + } frame[4] = TX_RSSI; frame[5] = RX_LQI; frame[6] = TX_LQI; @@ -794,7 +800,7 @@ void TelemetryUpdate() return; } #ifdef MULTI_SYNC - else if ( (now - lastInputSync) > INPUT_SYNC_TIME) + if ( (now - lastInputSync) > INPUT_SYNC_TIME) { mult_send_inputsync(); lastInputSync = now; @@ -804,7 +810,11 @@ void TelemetryUpdate() #endif #if defined SPORT_TELEMETRY - if (protocol==PROTO_FRSKYX) + if (protocol==PROTO_FRSKYX + #ifdef TELEMETRY_FRSKYX_TO_FRSKYD + && mode_select==MODE_SERIAL + #endif + ) { // FrSkyX for(;;) { //Empty buffer @@ -870,8 +880,9 @@ void TelemetryUpdate() } #endif - if((telemetry_link & 1 )&& protocol != PROTO_FRSKYX) + if( telemetry_link & 1 ) { // FrSkyD + Hubsan + AFHDS2A + Bayang + Cabell + Hitec + Bugs + BugsMini + NCC1701 + // FrSkyX telemetry if in PPM frsky_link_frame(); return; } diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 3efd302..7bc6d3a 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -258,26 +258,27 @@ //Comment to invert the polarity of the output telemetry serial signal. //This function takes quite some flash space and processor power on an atmega. -//For OpenTX it must be uncommented. -//On a 9XR_PRO running ersky9x both commented and uncommented will work depending on the radio setting Invert COM1 under the Telemetry menu. -//On other addon/replacement boards like the 9xtreme board or the Ar9x board running ersky9x, you need to uncomment the line below. +//For a Taranis/T16 with an external module it must be uncommented. For a T16 internal module it must be commented. +//A 9XR_PRO running erskyTX will work with both commented and uncommented depending on the radio setting Invert COM1 under the Telemetry menu. +//On other addon/replacement boards like the 9xtreme board or the Ar9x board running erskyTX, you need to uncomment the line below. //For er9x it depends if you have an inveter mod or not on the telemetry pin. If you don't have an inverter comment this line. +//=>OpenTX 2.3.2 with a STM32 or OrangeRX module this setting can be ignored. #define INVERT_TELEMETRY //Uncomment if you don't want to send Multi status telemetry frames (Protocol available, Bind in progress, version...) -//Use with er9x/erksy9x, for OpenTX MULTI_TELEMETRY below is preferred instead +//Use with er9x/erskyTX, for OpenTX MULTI_TELEMETRY below is preferred instead //#define MULTI_STATUS //Sends Multi status and allow OpenTX to autodetect the telemetry format. Comment to disable. -//Supported by OpenTX version 2.2 RC9 and newer. NOT supported by er9x/ersky9x use MULTI_STATUS instead. +//Supported by OpenTX version 2.2 RC9 and newer. NOT supported by er9x/erskyTX use MULTI_STATUS instead. #define MULTI_TELEMETRY //Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. #define MULTI_SYNC //Comment a line to disable a specific protocol telemetry -#define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, ersky9x and OpenTX -#define SPORT_TELEMETRY // Use FrSkyX format to send telemetry to TX -#define AFHDS2A_FW_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by ersky9x and OpenTX +#define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, erskyTX and OpenTX +#define SPORT_TELEMETRY // Use FrSkyX format to send/receive telemetry +#define AFHDS2A_FW_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by erskyTX and OpenTX #define AFHDS2A_HUB_TELEMETRY // Use FrSkyD Hub format to send basic telemetry to TX like er9x #define HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX #define BAYANG_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX @@ -285,8 +286,8 @@ #define HUBSAN_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX #define NCC1701_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX #define CABELL_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX -#define HITEC_HUB_TELEMETRY // Use FrSkyD Hub format to send basic telemetry to the radios which can decode it like er9x, ersky9x and OpenTX -#define HITEC_FW_TELEMETRY // Under development: Forward received telemetry packets to be decoded by ersky9x and OpenTX +#define HITEC_HUB_TELEMETRY // Use FrSkyD Hub format to send basic telemetry to the radios which can decode it like er9x, erskyTX and OpenTX +#define HITEC_FW_TELEMETRY // Under development: Forward received telemetry packets to be decoded by erskyTX and OpenTX #define SCANNER_TELEMETRY // Forward spectrum scanner data to TX #define FRSKYX_RX_TELEMETRY // Forward channels data to TX #define AFHDS2A_RX_TELEMETRY // Forward channels data to TX @@ -340,6 +341,10 @@ // The default value is 16 to receive all possible channels but you might want to filter some "bad" channels from the PPM frame like the ones above 6 on the Walkera PL0811. #define MAX_PPM_CHANNELS 16 +/** Telemetry **/ +//Send simple FrSkyX telemetry using the FrSkyD telemetry format +#define TELEMETRY_FRSKYX_TO_FRSKYD + /** Rotary Switch Protocol Selector Settings **/ //The table below indicates which protocol to run when a specific position on the rotary switch has been selected. //All fields and values are explained below. Everything is configurable from here like in the Serial mode. From e0e51eb187f5fac9e80813d4c7d00930744190f5 Mon Sep 17 00:00:00 2001 From: goebish Date: Sat, 12 Oct 2019 20:31:09 +0200 Subject: [PATCH 19/65] Fix rc channels init (#284) --- Multiprotocol/FrSky_Rx_cc2500.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Multiprotocol/FrSky_Rx_cc2500.ino b/Multiprotocol/FrSky_Rx_cc2500.ino index 09e3bbf..205e0f2 100644 --- a/Multiprotocol/FrSky_Rx_cc2500.ino +++ b/Multiprotocol/FrSky_Rx_cc2500.ino @@ -172,7 +172,7 @@ uint16_t initFrSky_Rx() frsky_rx_data_started = 0; frsky_rx_finetune = 0; telemetry_link = 0; - for(uint8_t ch=0; ch Date: Sun, 13 Oct 2019 11:08:20 +0200 Subject: [PATCH 20/65] Global def for the common RX variables --- Multiprotocol/AFHDS2A_Rx_a7105.ino | 21 ++++++++----------- Multiprotocol/FrSky_Rx_cc2500.ino | 33 +++++++++++++----------------- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 11 ++++++++++ Multiprotocol/Validate.h | 2 +- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Multiprotocol/AFHDS2A_Rx_a7105.ino b/Multiprotocol/AFHDS2A_Rx_a7105.ino index 9ee15ba..e1a7a65 100644 --- a/Multiprotocol/AFHDS2A_Rx_a7105.ino +++ b/Multiprotocol/AFHDS2A_Rx_a7105.ino @@ -21,9 +21,6 @@ #define AFHDS2A_RX_RXPACKET_SIZE 37 #define AFHDS2A_RX_NUMFREQ 16 -static uint8_t afhds2a_rx_data_started; -static uint8_t afhds2a_rx_disable_lna; - enum { AFHDS2A_RX_BIND1, AFHDS2A_RX_BIND2, @@ -70,9 +67,9 @@ uint16_t initAFHDS2A_Rx() A7105_Init(); hopping_frequency_no = 0; packet_count = 0; - afhds2a_rx_data_started = 0; - afhds2a_rx_disable_lna = IS_POWER_FLAG_on; - CC2500_SetTxRxMode(afhds2a_rx_disable_lna ? TXRX_OFF : RX_EN); + rx_data_started = 0; + rx_disable_lna = IS_POWER_FLAG_on; + CC2500_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); A7105_Strobe(A7105_RX); if (IS_BIND_IN_PROGRESS) { @@ -102,9 +99,9 @@ uint16_t AFHDS2A_Rx_callback() #ifndef FORCE_AFHDS2A_TUNING A7105_AdjustLOBaseFreq(1); #endif - if (afhds2a_rx_disable_lna != IS_POWER_FLAG_on) { - afhds2a_rx_disable_lna = IS_POWER_FLAG_on; - CC2500_SetTxRxMode(afhds2a_rx_disable_lna ? TXRX_OFF : RX_EN); + if (rx_disable_lna != IS_POWER_FLAG_on) { + rx_disable_lna = IS_POWER_FLAG_on; + CC2500_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); } switch(phase) { @@ -155,7 +152,7 @@ uint16_t AFHDS2A_Rx_callback() case AFHDS2A_RX_BIND2 | AFHDS2A_RX_WAIT_WRITE: //Wait for TX completion pps_timer = micros(); - while (micros() - pps_timer < 700) // Wait max 700µs, using serial+telemetry exit in about 120µs + while (micros() - pps_timer < 700) // Wait max 700µs, using serial+telemetry exit in about 120µs if (!(A7105_ReadReg(A7105_00_MODE) & 0x01)) break; A7105_Strobe(A7105_RX); @@ -172,7 +169,7 @@ uint16_t AFHDS2A_Rx_callback() AFHDS2A_Rx_build_telemetry_packet(); telemetry_link = 1; } - afhds2a_rx_data_started = 1; + rx_data_started = 1; read_retry = 10; // hop to next channel pps_counter++; } @@ -193,7 +190,7 @@ uint16_t AFHDS2A_Rx_callback() hopping_frequency_no = 0; A7105_WriteReg(A7105_0F_PLL_I, hopping_frequency[hopping_frequency_no]); A7105_Strobe(A7105_RX); - if (afhds2a_rx_data_started) + if (rx_data_started) read_retry = 0; else read_retry = -127; // retry longer until first packet is catched diff --git a/Multiprotocol/FrSky_Rx_cc2500.ino b/Multiprotocol/FrSky_Rx_cc2500.ino index 205e0f2..cd2d242 100644 --- a/Multiprotocol/FrSky_Rx_cc2500.ino +++ b/Multiprotocol/FrSky_Rx_cc2500.ino @@ -29,11 +29,8 @@ FRSKY_RX_DATA, }; - static uint8_t frsky_rx_chanskip; - static uint8_t frsky_rx_disable_lna; - static uint8_t frsky_rx_data_started; - static int8_t frsky_rx_finetune; - static uint16_t frsky_rx_rc_chan[16]; +static uint8_t frsky_rx_chanskip; +static int8_t frsky_rx_finetune; static void __attribute__((unused)) frsky_rx_strobe_rx() { @@ -60,8 +57,8 @@ static void __attribute__((unused)) frsky_rx_initialise() { CC2500_WriteReg(CC2500_23_FSCAL3, 0x89); // fixed FSCAL3 ? break; } - frsky_rx_disable_lna = IS_POWER_FLAG_on; - CC2500_SetTxRxMode(frsky_rx_disable_lna ? TXRX_OFF : RX_EN); // lna disable / enable + rx_disable_lna = IS_POWER_FLAG_on; + CC2500_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); // lna disable / enable frsky_rx_strobe_rx(); delayMicroseconds(1000); // wait for RX to activate } @@ -121,9 +118,9 @@ static void __attribute__((unused)) frsky_rx_build_telemetry_packet() uint8_t shifted = (raw_channel[i] & 0x800)>0; uint16_t channel_value = raw_channel[i] & 0x7FF; if (channel_value < 64) - frsky_rx_rc_chan[shifted ? i + 8 : i] = 0; + rx_rc_chan[shifted ? i + 8 : i] = 0; else - frsky_rx_rc_chan[shifted ? i + 8 : i] = min(((channel_value - 64) << 4) / 15, 2047); + rx_rc_chan[shifted ? i + 8 : i] = min(((channel_value - 64) << 4) / 15, 2047); } } else { @@ -139,7 +136,7 @@ static void __attribute__((unused)) frsky_rx_build_telemetry_packet() for (i = 0; i < 8; i++) { if (raw_channel[i] < 1290) raw_channel[i] = 1290; - frsky_rx_rc_chan[i] = min(((raw_channel[i] - 1290) << 4) / 15, 2047); + rx_rc_chan[i] = min(((raw_channel[i] - 1290) << 4) / 15, 2047); } } @@ -151,7 +148,7 @@ static void __attribute__((unused)) frsky_rx_build_telemetry_packet() // pack channels for (i = 0; i < packet_in[3]; i++) { - bits |= ((uint32_t)frsky_rx_rc_chan[i]) << bitsavailable; + bits |= ((uint32_t)rx_rc_chan[i]) << bitsavailable; bitsavailable += 11; while (bitsavailable >= 8) { packet_in[idx++] = bits & 0xff; @@ -169,11 +166,9 @@ uint16_t initFrSky_Rx() state = 0; frsky_rx_chanskip = 1; hopping_frequency_no = 0; - frsky_rx_data_started = 0; + rx_data_started = 0; frsky_rx_finetune = 0; telemetry_link = 0; - for(uint8_t ch=0; ch<16; ch++) - frsky_rx_rc_chan[ch] = 1023; if (IS_BIND_IN_PROGRESS) { phase = FRSKY_RX_TUNE_START; } @@ -217,9 +212,9 @@ uint16_t FrSky_Rx_callback() prev_option = option; } - if (frsky_rx_disable_lna != IS_POWER_FLAG_on) { - frsky_rx_disable_lna = IS_POWER_FLAG_on; - CC2500_SetTxRxMode(frsky_rx_disable_lna ? TXRX_OFF : RX_EN); + if (rx_disable_lna != IS_POWER_FLAG_on) { + rx_disable_lna = IS_POWER_FLAG_on; + CC2500_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); } len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; @@ -334,7 +329,7 @@ uint16_t FrSky_Rx_callback() frsky_rx_build_telemetry_packet(); telemetry_link = 1; } - frsky_rx_data_started = 1; + rx_data_started = 1; read_retry = 0; pps_counter++; } @@ -352,7 +347,7 @@ uint16_t FrSky_Rx_callback() if (read_retry++ >= 9) { hopping_frequency_no = (hopping_frequency_no + frsky_rx_chanskip) % 47; frsky_rx_set_channel(hopping_frequency_no); - if(frsky_rx_data_started) + if(rx_data_started) read_retry = 0; else read_retry = -50; // retry longer until first packet is catched diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index d871190..b772ffe 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 14 +#define VERSION_PATCH_LEVEL 15 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 67a3af6..f4392c4 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -217,6 +217,13 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets uint8_t SportData[MAX_SPORT_BUFFER]; uint8_t SportHead=0, SportTail=0; #endif + + //RX protocols + #if defined(AFHDS2A_RX_A7105_INO) || defined(FRSKY_RX_CC2500_INO) + uint8_t rx_data_started; + uint8_t rx_disable_lna; + uint16_t rx_rc_chan[16]; + #endif #endif // TELEMETRY // Callback @@ -955,6 +962,10 @@ static void protocol_init() TX_RX_PAUSE_off; TX_MAIN_PAUSE_off; tx_resume(); + #if defined(AFHDS2A_RX_A7105_INO) || defined(FRSKY_RX_CC2500_INO) + for(uint8_t ch=0; ch<16; ch++) + rx_rc_chan[ch] = 1024; + #endif #endif //Set global ID and rx_tx_addr diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index aa11e91..53a9173 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -309,7 +309,7 @@ #if not defined(DSM_CYRF6936_INO) #undef DSM_TELEMETRY #endif - #if not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKY_RX_TELEMETRY) + #if not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKY_RX_TELEMETRY) && not defined(AFHDS2A_RX_TELEMETRY) #undef TELEMETRY #undef INVERT_TELEMETRY #endif From a23178e20e4cc939a420443db4fe9bb9cea4c8d3 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 13 Oct 2019 16:35:09 +0200 Subject: [PATCH 21/65] Fix ADHDS2A RX LNA switch --- Multiprotocol/AFHDS2A_Rx_a7105.ino | 8 ++++---- Multiprotocol/FrSky_Rx_cc2500.ino | 4 ++-- Multiprotocol/Multiprotocol.ino | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Multiprotocol/AFHDS2A_Rx_a7105.ino b/Multiprotocol/AFHDS2A_Rx_a7105.ino index e1a7a65..992750c 100644 --- a/Multiprotocol/AFHDS2A_Rx_a7105.ino +++ b/Multiprotocol/AFHDS2A_Rx_a7105.ino @@ -67,9 +67,9 @@ uint16_t initAFHDS2A_Rx() A7105_Init(); hopping_frequency_no = 0; packet_count = 0; - rx_data_started = 0; + rx_data_started = false; rx_disable_lna = IS_POWER_FLAG_on; - CC2500_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); + A7105_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); A7105_Strobe(A7105_RX); if (IS_BIND_IN_PROGRESS) { @@ -101,7 +101,7 @@ uint16_t AFHDS2A_Rx_callback() #endif if (rx_disable_lna != IS_POWER_FLAG_on) { rx_disable_lna = IS_POWER_FLAG_on; - CC2500_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); + A7105_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); } switch(phase) { @@ -169,7 +169,7 @@ uint16_t AFHDS2A_Rx_callback() AFHDS2A_Rx_build_telemetry_packet(); telemetry_link = 1; } - rx_data_started = 1; + rx_data_started = true; read_retry = 10; // hop to next channel pps_counter++; } diff --git a/Multiprotocol/FrSky_Rx_cc2500.ino b/Multiprotocol/FrSky_Rx_cc2500.ino index cd2d242..e05c47e 100644 --- a/Multiprotocol/FrSky_Rx_cc2500.ino +++ b/Multiprotocol/FrSky_Rx_cc2500.ino @@ -166,7 +166,7 @@ uint16_t initFrSky_Rx() state = 0; frsky_rx_chanskip = 1; hopping_frequency_no = 0; - rx_data_started = 0; + rx_data_started = false; frsky_rx_finetune = 0; telemetry_link = 0; if (IS_BIND_IN_PROGRESS) { @@ -329,7 +329,7 @@ uint16_t FrSky_Rx_callback() frsky_rx_build_telemetry_packet(); telemetry_link = 1; } - rx_data_started = 1; + rx_data_started = true; read_retry = 0; pps_counter++; } diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index f4392c4..6ed1cd8 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -220,8 +220,8 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets //RX protocols #if defined(AFHDS2A_RX_A7105_INO) || defined(FRSKY_RX_CC2500_INO) - uint8_t rx_data_started; - uint8_t rx_disable_lna; + bool rx_data_started; + bool rx_disable_lna; uint16_t rx_rc_chan[16]; #endif #endif // TELEMETRY From f964cdec98201e299e6a5318866386dfc9fc1970 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 13 Oct 2019 22:23:32 +0200 Subject: [PATCH 22/65] Update Multiprotocol.h --- Multiprotocol/Multiprotocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index b772ffe..19e3636 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -831,7 +831,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- Values are concatenated to fit in 22 bytes like in SBUS protocol. Failsafe values have exactly the same range/values than normal channels except the extremes where 0=no pulse, 2047=hold. If failsafe is not set or RX then failsafe packets should not be sent. - Stream[26] = sub_protocol bits 6 & 7|RxNum bits 4 & 5|Future_Use 3|Telem_Invert 2|Disable_Telemetry 1|Disable_CH_Mapping 0 + Stream[26] = sub_protocol bits 6 & 7|RxNum bits 4 & 5|Telemetry_Invert 3|Future_Use 2|Disable_Telemetry 1|Disable_CH_Mapping 0 sub_protocol is 0..255 (bits 0..5 + bits 6..7) RxNum value is 0..63 (bits 0..3 + bits 4..5) Telemetry_Invert => 0x08 0=normal, 1=invert From caf145c38ad2c11cd8bf9ecf3d36ff390709e0f1 Mon Sep 17 00:00:00 2001 From: goebish Date: Mon, 14 Oct 2019 00:28:39 +0200 Subject: [PATCH 23/65] Auto-detect FrSky RX format (#286) * Calibrate rf channels for D8 too * Auto-detect D16FCC, D16LBT or D8 format during bind --- Multiprotocol/FrSky_Rx_cc2500.ino | 55 ++++++++++++++++++------------- Multiprotocol/Multi.txt | 2 +- Multiprotocol/Multiprotocol.h | 16 ++------- Multiprotocol/_Config.h | 3 +- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Multiprotocol/FrSky_Rx_cc2500.ino b/Multiprotocol/FrSky_Rx_cc2500.ino index e05c47e..6f599f0 100644 --- a/Multiprotocol/FrSky_Rx_cc2500.ino +++ b/Multiprotocol/FrSky_Rx_cc2500.ino @@ -20,6 +20,14 @@ #define FRSKY_RX_D16FCC_LENGTH 32 #define FRSKY_RX_D16LBT_LENGTH 35 #define FRSKY_RX_D8_LENGTH 20 + #define FRSKY_RX_FORMATS 3 + +enum +{ + FRSKY_RX_D16FCC = 0, + FRSKY_RX_D16LBT, + FRSKY_RX_D8 +}; enum { FRSKY_RX_TUNE_START, @@ -31,6 +39,7 @@ static uint8_t frsky_rx_chanskip; static int8_t frsky_rx_finetune; +static uint8_t frsky_rx_format; static void __attribute__((unused)) frsky_rx_strobe_rx() { @@ -39,11 +48,13 @@ static void __attribute__((unused)) frsky_rx_strobe_rx() CC2500_Strobe(CC2500_SRX); } -static void __attribute__((unused)) frsky_rx_initialise() { +static void __attribute__((unused)) frsky_rx_initialise_cc2500() { + const uint8_t frsky_rx_length[] = { FRSKY_RX_D16FCC_LENGTH, FRSKY_RX_D16LBT_LENGTH, FRSKY_RX_D8_LENGTH }; + packet_length = frsky_rx_length[frsky_rx_format]; CC2500_Reset(); CC2500_Strobe(CC2500_SIDLE); CC2500_WriteReg(CC2500_0A_CHANNR, 0); // bind channel - switch (sub_protocol) { + switch (frsky_rx_format) { case FRSKY_RX_D16FCC: FRSKY_init_cc2500(FRSKYX_cc2500_conf); break; @@ -54,7 +65,7 @@ static void __attribute__((unused)) frsky_rx_initialise() { FRSKY_init_cc2500(FRSKYD_cc2500_conf); CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x05); // always check address CC2500_WriteReg(CC2500_09_ADDR, 0x03); // bind address - CC2500_WriteReg(CC2500_23_FSCAL3, 0x89); // fixed FSCAL3 ? + CC2500_WriteReg(CC2500_23_FSCAL3, 0x89); break; } rx_disable_lna = IS_POWER_FLAG_on; @@ -66,10 +77,9 @@ static void __attribute__((unused)) frsky_rx_initialise() { static void __attribute__((unused)) frsky_rx_set_channel(uint8_t channel) { CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[channel]); - if(sub_protocol == FRSKY_RX_D8) + if(frsky_rx_format == FRSKY_RX_D8) CC2500_WriteReg(CC2500_23_FSCAL3, 0x89); - else - CC2500_WriteReg(CC2500_25_FSCAL1, calData[channel]); + CC2500_WriteReg(CC2500_25_FSCAL1, calData[channel]); frsky_rx_strobe_rx(); } @@ -88,7 +98,7 @@ static void __attribute__((unused)) frsky_rx_calibrate() static uint8_t __attribute__((unused)) frskyx_rx_check_crc() { - if (sub_protocol == FRSKY_RX_D8) + if (frsky_rx_format == FRSKY_RX_D8) return 1; uint8_t limit = packet_length - 4; uint16_t lcrc = FrSkyX_crc(&packet[3], limit - 3); // computed crc @@ -104,7 +114,7 @@ static void __attribute__((unused)) frsky_rx_build_telemetry_packet() uint8_t idx = 0; uint8_t i; - if (sub_protocol == FRSKY_RX_D16FCC || sub_protocol == FRSKY_RX_D16LBT) { + if (frsky_rx_format == FRSKY_RX_D16FCC || frsky_rx_format == FRSKY_RX_D16LBT) { // decode D16 channels raw_channel[0] = ((packet[10] << 8) & 0xF00) | packet[9]; raw_channel[1] = ((packet[11] << 4) & 0xFF0) | (packet[10] >> 4); @@ -144,7 +154,7 @@ static void __attribute__((unused)) frsky_rx_build_telemetry_packet() packet_in[idx++] = RX_LQI; packet_in[idx++] = RX_RSSI; packet_in[idx++] = 0; // start channel - packet_in[idx++] = sub_protocol == FRSKY_RX_D8 ? 8 : 16; // number of channels in packet + packet_in[idx++] = frsky_rx_format == FRSKY_RX_D8 ? 8 : 16; // number of channels in packet // pack channels for (i = 0; i < packet_in[3]; i++) { @@ -160,9 +170,6 @@ static void __attribute__((unused)) frsky_rx_build_telemetry_packet() uint16_t initFrSky_Rx() { - const uint8_t frsky_rx_length[] = {FRSKY_RX_D16FCC_LENGTH, FRSKY_RX_D16LBT_LENGTH, FRSKY_RX_D8_LENGTH}; - packet_length = frsky_rx_length[sub_protocol]; - frsky_rx_initialise(); state = 0; frsky_rx_chanskip = 1; hopping_frequency_no = 0; @@ -170,20 +177,22 @@ uint16_t initFrSky_Rx() frsky_rx_finetune = 0; telemetry_link = 0; if (IS_BIND_IN_PROGRESS) { + frsky_rx_format = FRSKY_RX_D8; + frsky_rx_initialise_cc2500(); phase = FRSKY_RX_TUNE_START; } else { uint16_t temp = FRSKY_RX_EEPROM_OFFSET; + frsky_rx_format = eeprom_read_byte((EE_ADDR)temp++) % FRSKY_RX_FORMATS; rx_tx_addr[0] = eeprom_read_byte((EE_ADDR)temp++); rx_tx_addr[1] = eeprom_read_byte((EE_ADDR)temp++); rx_tx_addr[2] = eeprom_read_byte((EE_ADDR)temp++); frsky_rx_finetune = eeprom_read_byte((EE_ADDR)temp++); for (uint8_t ch = 0; ch < 47; ch++) hopping_frequency[ch] = eeprom_read_byte((EE_ADDR)temp++); - if (sub_protocol == FRSKY_RX_D16FCC || sub_protocol == FRSKY_RX_D16LBT) { - frsky_rx_calibrate(); - CC2500_WriteReg(CC2500_18_MCSM0, 0x08); // FS_AUTOCAL = manual - } + frsky_rx_initialise_cc2500(); + frsky_rx_calibrate(); + CC2500_WriteReg(CC2500_18_MCSM0, 0x08); // FS_AUTOCAL = manual CC2500_WriteReg(CC2500_09_ADDR, rx_tx_addr[0]); // set address CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x05); // check address if (option == 0) @@ -233,6 +242,8 @@ uint16_t FrSky_Rx_callback() } } } + frsky_rx_format = (frsky_rx_format + 1) % FRSKY_RX_FORMATS; // switch to next format (D16FCC, D16LBT, D8) + frsky_rx_initialise_cc2500(); frsky_rx_finetune += 10; CC2500_WriteReg(CC2500_0C_FSCTRL0, frsky_rx_finetune); frsky_rx_strobe_rx(); @@ -291,14 +302,14 @@ uint16_t FrSky_Rx_callback() rx_tx_addr[0] = packet[3]; // TXID rx_tx_addr[1] = packet[4]; // TXID rx_tx_addr[2] = packet[12]; // RX # (D16) - if (sub_protocol == FRSKY_RX_D16FCC || sub_protocol == FRSKY_RX_D16LBT) - CC2500_WriteReg(CC2500_18_MCSM0, 0x08); // FS_AUTOCAL = manual + CC2500_WriteReg(CC2500_18_MCSM0, 0x08); // FS_AUTOCAL = manual CC2500_WriteReg(CC2500_09_ADDR, rx_tx_addr[0]); // set address CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x05); // check address phase = FRSKY_RX_DATA; frsky_rx_set_channel(hopping_frequency_no); - // store txid and channel list + // store format, finetune setting, txid, channel list uint16_t temp = FRSKY_RX_EEPROM_OFFSET; + eeprom_write_byte((EE_ADDR)temp++, frsky_rx_format); eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[0]); eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[1]); eeprom_write_byte((EE_ADDR)temp++, rx_tx_addr[2]); @@ -314,18 +325,18 @@ uint16_t FrSky_Rx_callback() case FRSKY_RX_DATA: if (len >= packet_length) { CC2500_ReadData(packet, packet_length); - if (packet[1] == rx_tx_addr[0] && packet[2] == rx_tx_addr[1] && frskyx_rx_check_crc() && (sub_protocol == FRSKY_RX_D8 || packet[6] == rx_tx_addr[2])) { + if (packet[1] == rx_tx_addr[0] && packet[2] == rx_tx_addr[1] && frskyx_rx_check_crc() && (frsky_rx_format == FRSKY_RX_D8 || packet[6] == rx_tx_addr[2])) { RX_RSSI = packet[packet_length-2]; if(RX_RSSI >= 128) RX_RSSI -= 128; else RX_RSSI += 128; // hop to next channel - if (sub_protocol == FRSKY_RX_D16FCC || sub_protocol == FRSKY_RX_D16LBT) + if (frsky_rx_format == FRSKY_RX_D16FCC || frsky_rx_format == FRSKY_RX_D16LBT) frsky_rx_chanskip = ((packet[4] & 0xC0) >> 6) | ((packet[5] & 0x3F) << 2); hopping_frequency_no = (hopping_frequency_no + frsky_rx_chanskip) % 47; frsky_rx_set_channel(hopping_frequency_no); - if((sub_protocol == FRSKY_RX_D8 || packet[7] == 0) && telemetry_link == 0) { // send channels to TX + if((frsky_rx_format == FRSKY_RX_D8 || packet[7] == 0) && telemetry_link == 0) { // send channels to TX frsky_rx_build_telemetry_packet(); telemetry_link = 1; } diff --git a/Multiprotocol/Multi.txt b/Multiprotocol/Multi.txt index 2542135..06ee328 100644 --- a/Multiprotocol/Multi.txt +++ b/Multiprotocol/Multi.txt @@ -52,6 +52,6 @@ 52,ZSX,280 53,Flyzone,FZ-410 54,Scanner -55,Frsky_RX,D16FCC,D16LBT,D8 +55,Frsky_RX 56,AFHDS2A_RX 63,XN_DUMP,250K,1M,2M diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 19e3636..ddd8cba 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -290,12 +290,6 @@ enum TRAXXAS { RX6519 = 0, }; -enum FRSKY_RX -{ - FRSKY_RX_D16FCC= 0, - FRSKY_RX_D16LBT, - FRSKY_RX_D8 -}; #define NONE 0 #define P_HIGH 1 @@ -595,9 +589,9 @@ enum { #define AFHDS2A_EEPROM_OFFSET 50 // RX ID, 4 bytes per model id, end is 50+64=114 #define BUGS_EEPROM_OFFSET 114 // RX ID, 2 bytes per model id, end is 114+32=146 #define BUGSMINI_EEPROM_OFFSET 146 // RX ID, 2 bytes per model id, end is 146+32=178 -#define FRSKY_RX_EEPROM_OFFSET 178 // (3) TX ID + (1) freq_tune + (47) channels, 51 bytes, end is 178+51=229 -#define AFHDS2A_RX_EEPROM_OFFSET 229 // (4) TX ID + (16) channels, 20 bytes, end is 229+20=249 -#define AFHDS2A_EEPROM_OFFSET2 249 // RX ID, 4 bytes per model id, end is 249+192=441 +#define FRSKY_RX_EEPROM_OFFSET 178 // (1) format + (3) TX ID + (1) freq_tune + (47) channels, 52 bytes, end is 178+52=230 +#define AFHDS2A_RX_EEPROM_OFFSET 230 // (4) TX ID + (16) channels, 20 bytes, end is 230+20=250 +#define AFHDS2A_EEPROM_OFFSET2 250 // RX ID, 4 bytes per model id, end is 250+192=442 //#define CONFIG_EEPROM_OFFSET 441 // Current configuration of the multimodule //**************************************** @@ -813,10 +807,6 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- RED_SLOW 1 sub_protocol==TRAXXAS RX6519 0 - sub_protocol==FRSKY_RX - FRSKY_RX_D16FCC 0 - FRSKY_RX_D16LBT 1 - FRSKY_RX_D8 2 Power value => 0x80 0=High/1=Low Stream[3] = option_protocol; diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index ea6862f..31226e5 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -551,8 +551,7 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= { EU_16 EU_8 PROTO_FRSKY_RX - FRSKYX_FCC - FRSKYX_LBT + NONE PROTO_FY326 FY326 FY319 From 948ce9e8b80d74a2155496eed174fbc9df520031 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 15 Oct 2019 02:04:19 +0200 Subject: [PATCH 24/65] Send current protocol and sub protocol name --- Multiprotocol/Multi_Names.ino | 297 ++++++++++++++++++++++++++++++++ Multiprotocol/Multiprotocol.h | 19 +- Multiprotocol/Multiprotocol.ino | 50 +++++- Multiprotocol/Telemetry.ino | 43 ++++- Multiprotocol/Validate.h | 7 +- Multiprotocol/_Config.h | 2 + 6 files changed, 410 insertions(+), 8 deletions(-) create mode 100644 Multiprotocol/Multi_Names.ino diff --git a/Multiprotocol/Multi_Names.ino b/Multiprotocol/Multi_Names.ino new file mode 100644 index 0000000..14ca397 --- /dev/null +++ b/Multiprotocol/Multi_Names.ino @@ -0,0 +1,297 @@ +/* + This project is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Multiprotocol is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Multiprotocol. If not, see . + */ + +#if defined(MULTI_NAMES) + +const char STR_FLYSKY[] ="FlySky"; +const char STR_HUBSAN[] ="Hubsan"; +const char STR_FRSKYD[] ="FrSky D"; +const char STR_HISKY[] ="Hisky"; +const char STR_V2X2[] ="V2x2"; +const char STR_DSM[] ="DSM"; +const char STR_DEVO[] ="Devo"; +const char STR_YD717[] ="YD717"; +const char STR_KN[] ="KN"; +const char STR_SYMAX[] ="SymaX"; +const char STR_SLT[] ="SLT"; +const char STR_CX10[] ="CX10"; +const char STR_CG023[] ="CG023"; +const char STR_BAYANG[] ="Bayang"; +const char STR_FRSKYX[] ="FrSky X"; +const char STR_ESKY[] ="ESky"; +const char STR_MT99XX[] ="MT99XX"; +const char STR_MJXQ[] ="MJXq"; +const char STR_SHENQI[] ="Shenqi"; +const char STR_FY326[] ="FY326"; +const char STR_SFHSS[] ="SFHSS"; +const char STR_J6PRO[] ="J6 Pro"; +const char STR_FQ777[] ="FQ777"; +const char STR_ASSAN[] ="Assan"; +const char STR_FRSKYV[] ="FrSky V"; +const char STR_HONTAI[] ="Hontai"; +const char STR_AFHDS2A[] ="FSky 2A"; +const char STR_Q2X2[] ="Q2x2"; +const char STR_WK2x01[] ="Walkera"; +const char STR_Q303[] ="Q303"; +const char STR_GW008[] ="GW008"; +const char STR_DM002[] ="DM002"; +const char STR_CABELL[] ="Cabell"; +const char STR_ESKY150[] ="Esky150"; +const char STR_H8_3D[] ="H8 3D"; +const char STR_CORONA[] ="Corona"; +const char STR_CFLIE[] ="CFlie"; +const char STR_HITEC[] ="Hitec"; +const char STR_WFLY[] ="WFly"; +const char STR_BUGS[] ="Bugs"; +const char STR_BUGSMINI[] ="BugMini"; +const char STR_TRAXXAS[] ="Traxxas"; +const char STR_NCC1701[] ="NCC1701"; +const char STR_E01X[] ="E01X"; +const char STR_V911S[] ="V911S"; +const char STR_GD00X[] ="GD00X"; +const char STR_V761[] ="V761"; +const char STR_KF606[] ="KF606"; +const char STR_REDPINE[] ="Redpine"; +const char STR_POTENSIC[] ="Potensi"; +const char STR_ZSX[] ="ZSX"; +const char STR_FLYZONE[] ="FlyZone"; +const char STR_SCANNER[] ="Scanner"; +const char STR_FRSKY_RX[] ="FrSkyRX"; +const char STR_AFHDS2A_RX[] ="FS2A_RX"; +const char STR_XN297DUMP[] ="XN297DP"; + +const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20"; +const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501"; +const char STR_SUBTYPE_FRSKYX[] = "\x07""D16\0 ""D16 8ch""LBT(EU)""LBT 8ch"; +const char STR_SUBTYPE_HISKY[] = "\x05""Std\0 ""HK310"; +const char STR_SUBTYPE_V2X2[] = "\x06""Std\0 ""JXD506"; +const char STR_SUBTYPE_DSM[] = "\x06""2 22ms""2 11ms""X 22ms""X 11ms"; +const char STR_SUBTYPE_DEVO[] = "\x04""8ch\0""10ch""12ch""6ch\0""7ch\0"; +const char STR_SUBTYPE_YD717[] = "\x07""Std\0 ""SkyWlkr""Syma X4""XINXUN\0""NIHUI\0 "; +const char STR_SUBTYPE_KN[] = "\x06""WLtoys""FeiLun"; +const char STR_SUBTYPE_SYMAX[] = "\x03""Std""X5C"; +const char STR_SUBTYPE_SLT[] = "\x06""V1_6ch""V2_8ch""Q100\0 ""Q200\0 ""MR100\0"; +const char STR_SUBTYPE_CX10[] = "\x07""Green\0 ""Blue\0 ""DM007\0 ""-\0 ""JC3015a""JC3015b""MK33041"; +const char STR_SUBTYPE_CG023[] = "\x05""Std\0 ""YD829"; +const char STR_SUBTYPE_BAYANG[] = "\x07""Std\0 ""H8S3D\0 ""X16 AH\0""IRDrone""DHD D4"; +const char STR_SUBTYPE_MT99[] = "\x06""MT99\0 ""H7\0 ""YZ\0 ""LS\0 ""FY805"; +const char STR_SUBTYPE_MJXQ[] = "\x07""WLH08\0 ""X600\0 ""X800\0 ""H26D\0 ""E010\0 ""H26WH\0 ""Phoenix"; +const char STR_SUBTYPE_FY326[] = "\x05""Std\0 ""FY319"; +const char STR_SUBTYPE_HONTAI[] = "\x07""Std\0 ""JJRC X1""X5C1\0 ""FQ_951"; +const char STR_SUBTYPE_AFHDS2A[] = "\x08""PWM,IBUS""PPM,IBUS""PWM,SBUS""PPM,SBUS"; +const char STR_SUBTYPE_Q2X2[] = "\x04""Q222""Q242""Q282"; +const char STR_SUBTYPE_WK2x01[] = "\x06""WK2801""WK2401""W6_5_1""W6_6_1""W6_HeL""W6_HeI"; +const char STR_SUBTYPE_Q303[] = "\x06""Std\0 ""CX35\0 ""CX10D\0""CX10WD"; +const char STR_SUBTYPE_CABELL[] = "\x07""V3\0 ""V3 Telm""-\0 ""-\0 ""-\0 ""-\0 ""F-Safe\0""Unbind\0"; +const char STR_SUBTYPE_H83D[] = "\x07""Std\0 ""H20H\0 ""H20Mini""H30Mini"; +const char STR_SUBTYPE_CORONA[] = "\x05""V1\0 ""V2\0 ""FD V3"; +const char STR_SUBTYPE_HITEC[] = "\x07""Optima\0""Opt Hub""Minima\0"; +const char STR_SUBTYPE_BUGS_MINI[] = "\x06""Std\0 ""Bugs3H"; +const char STR_SUBTYPE_TRAXXAS[] = "\x04""6519"; +const char STR_SUBTYPE_E01X[] = "\x05""E012\0""E015\0""E016H"; +const char STR_SUBTYPE_GD00X[] = "\x05""GD_V1""GD_V2"; +const char STR_SUBTYPE_REDPINE[] = "\x04""Fast""Slow"; +const char STR_SUBTYPE_POTENSIC[] = "\x03""A20"; +const char STR_SUBTYPE_ZSX[] = "\x07""280JJRC"; +const char STR_SUBTYPE_FLYZONE[] = "\x05""FZ410"; +const char STR_SUBTYPE_XN297DUMP[] = "\x07""250Kbps""1Mbps\0 ""2Mbps\0 "; + +enum +{ + OPTION_NONE, + OPTION_OPTION, + OPTION_RFTUNE, + OPTION_VIDFREQ, + OPTION_FIXEDID, + OPTION_TELEM, + OPTION_SRVFREQ, +}; + +#define NO_SUBTYPE nullptr + +const mm_protocol_definition multi_protocols[] = { +// Protocol as defined in pulses\modules_constants.h, number of sub_protocols - 1, Failsafe supported, Disable channel mapping supported, Subtype string, Option type +#if defined(FLYSKY_A7105_INO) + {PROTO_FLYSKY, STR_FLYSKY, 5, STR_SUBTYPE_FLYSKY, OPTION_NONE }, +#endif +#if defined(HUBSAN_A7105_INO) + {PROTO_HUBSAN, STR_HUBSAN, 3, STR_SUBTYPE_HUBSAN, OPTION_VIDFREQ }, +#endif +#if defined(FRSKYD_CC2500_INO) + {PROTO_FRSKYD, STR_FRSKYD, 0, NO_SUBTYPE, OPTION_RFTUNE }, +#endif +#if defined(HISKY_NRF24L01_INO) + {PROTO_HISKY, STR_HISKY, 2, STR_SUBTYPE_HISKY, OPTION_NONE }, +#endif +#if defined(V2X2_NRF24L01_INO) + {PROTO_V2X2, STR_V2X2, 2, STR_SUBTYPE_V2X2, OPTION_NONE }, +#endif +#if defined(DSM_CYRF6936_INO) + {PROTO_DSM, STR_DSM, 4, STR_SUBTYPE_DSM, OPTION_NONE }, +#endif +#if defined(DEVO_CYRF6936_INO) + {PROTO_DEVO, STR_DEVO, 5, STR_SUBTYPE_DEVO, OPTION_FIXEDID }, +#endif +#if defined(YD717_NRF24L01_INO) + {PROTO_YD717, STR_YD717, 5, STR_SUBTYPE_YD717, OPTION_NONE }, +#endif +#if defined(KN_NRF24L01_INO) + {PROTO_KN, STR_KN, 2, STR_SUBTYPE_KN, OPTION_NONE }, +#endif +#if defined(SYMAX_NRF24L01_INO) + {PROTO_SYMAX, STR_SYMAX, 2, STR_SUBTYPE_SYMAX, OPTION_NONE }, +#endif +#if defined(SLT_NRF24L01_INO) + {PROTO_SLT, STR_SLT, 5, STR_SUBTYPE_SLT, OPTION_NONE }, +#endif +#if defined(CX10_NRF24L01_INO) + {PROTO_CX10, STR_CX10, 7, STR_SUBTYPE_CX10, OPTION_NONE }, +#endif +#if defined(CG023_NRF24L01_INO) + {PROTO_CG023, STR_CG023, 2, STR_SUBTYPE_CG023, OPTION_NONE }, +#endif +#if defined(BAYANG_NRF24L01_INO) + {PROTO_BAYANG, STR_BAYANG, 5, STR_SUBTYPE_BAYANG, OPTION_TELEM }, +#endif +#if defined(FRSKYX_CC2500_INO) + {PROTO_FRSKYX, STR_FRSKYX, 4, STR_SUBTYPE_FRSKYX, OPTION_NONE }, +#endif +#if defined(ESKY_NRF24L01_INO) + {PROTO_ESKY, STR_ESKY, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(MT99XX_NRF24L01_INO) + {PROTO_MT99XX, STR_MT99XX, 5, STR_SUBTYPE_MT99, OPTION_NONE }, +#endif +#if defined(MJXQ_NRF24L01_INO) + {PROTO_MJXQ, STR_MJXQ, 7, STR_SUBTYPE_MJXQ, OPTION_RFTUNE }, +#endif +#if defined(SHENQI_NRF24L01_INO) + {PROTO_SHENQI, STR_SHENQI, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(FY326_NRF24L01_INO) + {PROTO_FY326, STR_FY326, 2, STR_SUBTYPE_FY326, OPTION_NONE }, +#endif +#if defined(SFHSS_CC2500_INO) + {PROTO_SFHSS, STR_SFHSS, 0, NO_SUBTYPE, OPTION_RFTUNE }, +#endif +#if defined(J6PRO_CYRF6936_INO) + {PROTO_J6PRO, STR_J6PRO, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(FQ777_NRF24L01_INO) + {PROTO_FQ777, STR_FQ777, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(ASSAN_NRF24L01_INO) + {PROTO_ASSAN, STR_ASSAN, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(FRSKYV_CC2500_INO) + {PROTO_FRSKYV, STR_FRSKYV, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(HONTAI_NRF24L01_INO) + {PROTO_HONTAI, STR_HONTAI, 4, STR_SUBTYPE_HONTAI, OPTION_NONE }, +#endif +#if defined(AFHDS2A_A7105_INO) + {PROTO_AFHDS2A, STR_AFHDS2A, 4, STR_SUBTYPE_AFHDS2A, OPTION_SRVFREQ }, +#endif +#if defined(CX10_NRF24L01_INO) + {PROTO_Q2X2, STR_Q2X2, 3, STR_SUBTYPE_Q2X2, OPTION_NONE }, +#endif +#if defined(WK2x01_CYRF6936_INO) + {PROTO_WK_2X01, STR_WK2x01, 6, STR_SUBTYPE_WK2x01, OPTION_NONE }, +#endif +#if defined(Q303_NRF24L01_INO) + {PROTO_Q303, STR_Q303, 4, STR_SUBTYPE_Q303, OPTION_NONE }, +#endif +#if defined(GW008_NRF24L01_INO) + {PROTO_GW008, STR_GW008, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(DM002_NRF24L01_INO) + {PROTO_DM002, STR_DM002, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(CABELL_NRF24L01_INO) + {PROTO_CABELL, STR_CABELL, 8, STR_SUBTYPE_CABELL, OPTION_OPTION }, +#endif +#if defined(ESKY150_NRF24L01_INO) + {PROTO_ESKY150, STR_ESKY150, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(H8_3D_NRF24L01_INO) + {PROTO_H8_3D, STR_H8_3D, 4, STR_SUBTYPE_H83D, OPTION_NONE }, +#endif +#if defined(CORONA_CC2500_INO) + {PROTO_CORONA, STR_CORONA, 3, STR_SUBTYPE_CORONA, OPTION_RFTUNE }, +#endif +#if defined(CFLIE_NRF24L01_INO) + {PROTO_CFLIE, STR_CFLIE, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(HITEC_CC2500_INO) + {PROTO_HITEC, STR_HITEC, 3, STR_SUBTYPE_HITEC, OPTION_RFTUNE }, +#endif +#if defined(WFLY_CYRF6936_INO) + {PROTO_WFLY, STR_WFLY, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(BUGS_A7105_INO) + {PROTO_BUGS, STR_BUGS, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(BUGSMINI_NRF24L01_INO) + {PROTO_BUGSMINI, STR_BUGSMINI, 2, STR_SUBTYPE_BUGS_MINI, OPTION_NONE }, +#endif +#if defined(TRAXXAS_CYRF6936_INO) + {PROTO_TRAXXAS, STR_TRAXXAS, 1, STR_SUBTYPE_TRAXXAS, OPTION_NONE }, +#endif +#if defined(NCC1701_NRF24L01_INO) + {PROTO_NCC1701, STR_NCC1701, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(E01X_NRF24L01_INO) + {PROTO_E01X, STR_E01X, 3, STR_SUBTYPE_E01X, OPTION_OPTION }, +#endif +#if defined(V911S_NRF24L01_INO) + {PROTO_V911S, NO_SUBTYPE, 0, NO_SUBTYPE, OPTION_RFTUNE }, +#endif +#if defined(GD00X_NRF24L01_INO) + {PROTO_GD00X, STR_GD00X, 2, STR_SUBTYPE_GD00X, OPTION_RFTUNE }, +#endif +#if defined(V761_NRF24L01_INO) + {PROTO_V761, STR_V761, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(KF606_NRF24L01_INO) + {PROTO_KF606, NO_SUBTYPE, 0, NO_SUBTYPE, OPTION_RFTUNE }, +#endif +#if defined(REDPINE_CC2500_INO) + {PROTO_REDPINE, STR_REDPINE, 2, STR_SUBTYPE_REDPINE, OPTION_RFTUNE }, +#endif +#if defined(POTENSIC_NRF24L01_INO) + {PROTO_POTENSIC, STR_POTENSIC, 1, STR_SUBTYPE_POTENSIC, OPTION_NONE }, +#endif +#if defined(ZSX_NRF24L01_INO) + {PROTO_ZSX, STR_ZSX, 1, STR_SUBTYPE_ZSX, OPTION_NONE }, +#endif +#if defined(FLYZONE_A7105_INO) + {PROTO_FLYZONE, STR_FLYZONE, 1, STR_SUBTYPE_FLYZONE, OPTION_NONE }, +#endif +#if defined(SCANNER_CC2500_INO) + {PROTO_SCANNER, STR_SCANNER, 0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(FRSKY_RX_CC2500_INO) + {PROTO_FRSKY_RX, STR_FRSKY_RX, 0, NO_SUBTYPE, OPTION_RFTUNE }, +#endif +#if defined(AFHDS2A_RX_A7105_INO) + {PROTO_AFHDS2A_RX, STR_AFHDS2A_RX,0, NO_SUBTYPE, OPTION_NONE }, +#endif +#if defined(XN297DUMP_NRF24L01_INO) + {PROTO_XN297DUMP, STR_XN297DUMP, 3, STR_SUBTYPE_XN297DUMP, OPTION_NONE }, +#endif + {0x00, nullptr, 0, nullptr, 0 } +}; + +#endif \ No newline at end of file diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index ddd8cba..1edb138 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 15 +#define VERSION_PATCH_LEVEL 16 //****************** // Protocols @@ -592,7 +592,7 @@ enum { #define FRSKY_RX_EEPROM_OFFSET 178 // (1) format + (3) TX ID + (1) freq_tune + (47) channels, 52 bytes, end is 178+52=230 #define AFHDS2A_RX_EEPROM_OFFSET 230 // (4) TX ID + (16) channels, 20 bytes, end is 230+20=250 #define AFHDS2A_EEPROM_OFFSET2 250 // RX ID, 4 bytes per model id, end is 250+192=442 -//#define CONFIG_EEPROM_OFFSET 441 // Current configuration of the multimodule +//#define CONFIG_EEPROM_OFFSET 442 // Current configuration of the multimodule //**************************************** //*** MULTI protocol serial definition *** @@ -666,6 +666,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- FLYZONE 53 SCANNER 54 FRSKY_RX 55 + AFHDS2A_RX 56 BindBit=> 0x80 1=Bind/0=No AutoBindBit=> 0x40 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No @@ -896,6 +897,20 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- [8] patchlevel version of multi code, should be displayed as major.minor.revision.patchlevel [9] channel order: CH4|CH3|CH2|CH1 with CHx value A=0,E=1,T=2,R=3 + [10] Next valid protocol number, can be used to skip invalid protocols + [11] Prev valid protocol number, can be used to skip invalid protocols + [12..18] Protocol name [7], not null terminated if prototcol len == 7 + [19] Number of sub protocols + [20..27] Sub protocol name [8], not null terminated if sub prototcol len == 8 + [28] Option text to be displayed: + OPTION_NONE 0 + OPTION_OPTION 1 + OPTION_RFTUNE 2 + OPTION_VIDFREQ 3 + OPTION_FIXEDID 4 + OPTION_TELEM 5 + OPTION_SRVFREQ 6 + more information can be added by specifing a longer length of the type, the TX will just ignore these bytes Type 0x02 Frksy S.port telemetry diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 6ed1cd8..8939704 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -224,6 +224,20 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets bool rx_disable_lna; uint16_t rx_rc_chan[16]; #endif + + //Multi names + #ifdef MULTI_NAMES + struct mm_protocol_definition { + uint8_t protocol; + const char *ProtoString; + uint8_t nbrSubProto; + const char *SubProtoString; + uint8_t optionType; + }; + extern const mm_protocol_definition multi_protocols[]; + uint8_t multi_protocols_index=0xFF; + uint8_t multi_protocols_send; + #endif #endif // TELEMETRY // Callback @@ -942,6 +956,10 @@ static void protocol_init() #ifdef MULTI_SYNC inputRefreshRate = 7000; // Default value #endif + #ifdef MULTI_NAMES + multi_protocols_send = 0; + multi_protocols_index = 0xFF; + #endif tx_pause(); pass=0; init_frskyd_link_telemetry(); @@ -982,8 +1000,6 @@ static void protocol_init() PE1_on; //NRF24L01 antenna RF3 by default PE2_off; //NRF24L01 antenna RF3 by default - debugln("Protocol selected: %d, sub proto %d, rxnum %d, option %d", protocol, sub_protocol, RX_num, option); - switch(protocol) // Init the requested protocol { #ifdef A7105_INSTALLED @@ -1388,8 +1404,36 @@ static void protocol_init() #endif #endif } + debugln("Protocol selected: %d, sub proto %d, rxnum %d, option %d", protocol, sub_protocol, RX_num, option); + #ifdef MULTI_NAMES + uint8_t index=0; + while(multi_protocols[index].protocol != 0) + { + if(multi_protocols[index].protocol==protocol) + { + multi_protocols_index=index; + multi_protocols_send = 0; + SEND_MULTI_STATUS_on; + #ifdef DEBUG_SERIAL + debug("Proto=%s",multi_protocols[multi_protocols_index].ProtoString); + uint8_t nbr=multi_protocols[multi_protocols_index].nbrSubProto; + debug(", nbr_sub=%d, Sub=",nbr); + if(nbr && (sub_protocol&0x07)0) + Serial_write(multi_protocols[multi_protocols_index-1].protocol); // prev protocol number + else + Serial_write(protocol); // begining of list + // Protocol + for(uint8_t i=0;i<7;i++) + Serial_write(multi_protocols[multi_protocols_index].ProtoString[i]); // protocol name + // Sub-protocol + uint8_t nbr=multi_protocols[multi_protocols_index].nbrSubProto; + Serial_write(nbr); // number of sub protocols + uint8_t j=0; + if(nbr && (sub_protocol&0x07) Date: Tue, 15 Oct 2019 08:54:02 +0200 Subject: [PATCH 25/65] Update Multi_Names.ino --- Multiprotocol/Multi_Names.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Multiprotocol/Multi_Names.ino b/Multiprotocol/Multi_Names.ino index 14ca397..fe5e0a4 100644 --- a/Multiprotocol/Multi_Names.ino +++ b/Multiprotocol/Multi_Names.ino @@ -208,7 +208,7 @@ const mm_protocol_definition multi_protocols[] = { {PROTO_Q2X2, STR_Q2X2, 3, STR_SUBTYPE_Q2X2, OPTION_NONE }, #endif #if defined(WK2x01_CYRF6936_INO) - {PROTO_WK_2X01, STR_WK2x01, 6, STR_SUBTYPE_WK2x01, OPTION_NONE }, + {PROTO_WK2x01, STR_WK2x01, 6, STR_SUBTYPE_WK2x01, OPTION_NONE }, #endif #if defined(Q303_NRF24L01_INO) {PROTO_Q303, STR_Q303, 4, STR_SUBTYPE_Q303, OPTION_NONE }, From 7a8e099a79b3d5396dfcccc9f73b9a7234c8f270 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 15 Oct 2019 11:19:42 +0200 Subject: [PATCH 26/65] Send MULTI NAMES all the time --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 3 --- Multiprotocol/Telemetry.ino | 5 ++--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 1edb138..96d563c 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 16 +#define VERSION_PATCH_LEVEL 17 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 8939704..f821950 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -236,7 +236,6 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets }; extern const mm_protocol_definition multi_protocols[]; uint8_t multi_protocols_index=0xFF; - uint8_t multi_protocols_send; #endif #endif // TELEMETRY @@ -957,7 +956,6 @@ static void protocol_init() inputRefreshRate = 7000; // Default value #endif #ifdef MULTI_NAMES - multi_protocols_send = 0; multi_protocols_index = 0xFF; #endif tx_pause(); @@ -1412,7 +1410,6 @@ static void protocol_init() if(multi_protocols[index].protocol==protocol) { multi_protocols_index=index; - multi_protocols_send = 0; SEND_MULTI_STATUS_on; #ifdef DEBUG_SERIAL debug("Proto=%s",multi_protocols[multi_protocols_index].ProtoString); diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 0e8a299..dd2cd3a 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -128,7 +128,7 @@ inline void telemetry_set_input_sync(uint16_t refreshRate) static void multi_send_status() { #ifdef MULTI_NAMES - if(multi_protocols_send && multi_protocols_index != 0xFF) + if(multi_protocols_index != 0xFF) multi_send_header(MULTI_TELEMETRY_STATUS, 25); else #endif @@ -188,9 +188,8 @@ static void multi_send_status() Serial_write(RUDDER<<6|THROTTLE<<4|ELEVATOR<<2|AILERON); #ifdef MULTI_NAMES - if(multi_protocols_send && multi_protocols_index != 0xFF) + if(multi_protocols_index != 0xFF) { - multi_protocols_send--; // Protocol next/prev if(multi_protocols[multi_protocols_index+1].protocol != 0) Serial_write(multi_protocols[multi_protocols_index+1].protocol); // next protocol number From d71006f2ae820f82328a530f5fdb00dfd50c8910 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 15 Oct 2019 20:00:41 +0200 Subject: [PATCH 27/65] Update Multi_Names.ino --- Multiprotocol/Multi_Names.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Multiprotocol/Multi_Names.ino b/Multiprotocol/Multi_Names.ino index fe5e0a4..f93b1df 100644 --- a/Multiprotocol/Multi_Names.ino +++ b/Multiprotocol/Multi_Names.ino @@ -256,7 +256,7 @@ const mm_protocol_definition multi_protocols[] = { {PROTO_E01X, STR_E01X, 3, STR_SUBTYPE_E01X, OPTION_OPTION }, #endif #if defined(V911S_NRF24L01_INO) - {PROTO_V911S, NO_SUBTYPE, 0, NO_SUBTYPE, OPTION_RFTUNE }, + {PROTO_V911S, STR_V911S, 0, NO_SUBTYPE, OPTION_RFTUNE }, #endif #if defined(GD00X_NRF24L01_INO) {PROTO_GD00X, STR_GD00X, 2, STR_SUBTYPE_GD00X, OPTION_RFTUNE }, @@ -265,7 +265,7 @@ const mm_protocol_definition multi_protocols[] = { {PROTO_V761, STR_V761, 0, NO_SUBTYPE, OPTION_NONE }, #endif #if defined(KF606_NRF24L01_INO) - {PROTO_KF606, NO_SUBTYPE, 0, NO_SUBTYPE, OPTION_RFTUNE }, + {PROTO_KF606, STR_KF606, 0, NO_SUBTYPE, OPTION_RFTUNE }, #endif #if defined(REDPINE_CC2500_INO) {PROTO_REDPINE, STR_REDPINE, 2, STR_SUBTYPE_REDPINE, OPTION_RFTUNE }, From e297310a25de9eef7a83ac1eff00b15f241b7f37 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 15 Oct 2019 20:00:45 +0200 Subject: [PATCH 28/65] Update Scanner_cc2500.ino --- Multiprotocol/Scanner_cc2500.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Multiprotocol/Scanner_cc2500.ino b/Multiprotocol/Scanner_cc2500.ino index 3210c80..7f7cdc7 100644 --- a/Multiprotocol/Scanner_cc2500.ino +++ b/Multiprotocol/Scanner_cc2500.ino @@ -20,7 +20,7 @@ #define SCAN_MAX_RADIOCHANNEL 249 // 2483 MHz #define SCAN_CHANNEL_LOCK_TIME 210 // with precalibration, channel requires only 90 usec for synthesizer to settle #define SCAN_AVERAGE_INTVL 20 -#define SCAN_MAX_COUNT 5 +#define SCAN_MAX_COUNT 10 #define SCAN_CHANS_PER_PACKET 5 static uint8_t scan_tlm_index; From 40afd67fc6eeb511bc5e6852acdb3e4bb465e668 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Wed, 16 Oct 2019 20:18:24 +0200 Subject: [PATCH 29/65] Disable MULTI_SYNC when using RX or Scanner protocols --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Telemetry.ino | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 96d563c..f4f7c33 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 17 +#define VERSION_PATCH_LEVEL 18 //****************** // Protocols diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index dd2cd3a..32b69e1 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -840,7 +840,7 @@ void TelemetryUpdate() return; } #ifdef MULTI_SYNC - if ( (now - lastInputSync) > INPUT_SYNC_TIME) + if ( (now - lastInputSync) > INPUT_SYNC_TIME && protocol != PROTO_SCANNER && protocol != PROTO_FRSKY_RX && protocol != PROTO_AFHDS2A_RX && protocol != PROTO_XN297DUMP ) { mult_send_inputsync(); lastInputSync = now; @@ -848,7 +848,6 @@ void TelemetryUpdate() } #endif #endif - #if defined SPORT_TELEMETRY if (protocol==PROTO_FRSKYX #ifdef TELEMETRY_FRSKYX_TO_FRSKYD From a8cad1e70a9df567edc67b68a9fe05a7c1da79bc Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 17 Oct 2019 09:41:20 +0200 Subject: [PATCH 30/65] Move optionDisp to Data[19] --- Multiprotocol/Multiprotocol.h | 8 ++++---- Multiprotocol/Multiprotocol.ino | 4 ++-- Multiprotocol/Telemetry.ino | 4 +--- Multiprotocol/_Config.h | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index f4f7c33..adbf5a1 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 18 +#define VERSION_PATCH_LEVEL 19 //****************** // Protocols @@ -900,9 +900,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- [10] Next valid protocol number, can be used to skip invalid protocols [11] Prev valid protocol number, can be used to skip invalid protocols [12..18] Protocol name [7], not null terminated if prototcol len == 7 - [19] Number of sub protocols - [20..27] Sub protocol name [8], not null terminated if sub prototcol len == 8 - [28] Option text to be displayed: + [19>>4] Option text to be displayed: OPTION_NONE 0 OPTION_OPTION 1 OPTION_RFTUNE 2 @@ -910,6 +908,8 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- OPTION_FIXEDID 4 OPTION_TELEM 5 OPTION_SRVFREQ 6 + [19&0x0F] Number of sub protocols + [20..27] Sub protocol name [8], not null terminated if sub prototcol len == 8 more information can be added by specifing a longer length of the type, the TX will just ignore these bytes diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index f821950..bdbaa78 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -694,8 +694,8 @@ uint8_t Update_All() TelemetryUpdate(); #endif #ifdef ENABLE_BIND_CH - if(IS_AUTOBIND_FLAG_on && IS_BIND_CH_PREV_off && Channel_data[BIND_CH-1]>CHANNEL_MAX_COMMAND && Channel_data[THROTTLE]<(CHANNEL_MIN_100+50)) - { // Autobind is on and BIND_CH went up and Throttle is low + if(IS_AUTOBIND_FLAG_on && IS_BIND_CH_PREV_off && Channel_data[BIND_CH-1]>CHANNEL_MAX_COMMAND) + { // Autobind is on and BIND_CH went up CHANGE_PROTOCOL_FLAG_on; //reload protocol BIND_IN_PROGRESS; //enable bind BIND_CH_PREV_on; diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 32b69e1..e574193 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -203,7 +203,7 @@ static void multi_send_status() for(uint8_t i=0;i<7;i++) Serial_write(multi_protocols[multi_protocols_index].ProtoString[i]); // protocol name // Sub-protocol - uint8_t nbr=multi_protocols[multi_protocols_index].nbrSubProto; + uint8_t nbr=multi_protocols[multi_protocols_index].nbrSubProto | (multi_protocols[multi_protocols_index].optionType<<4); // add option display type Serial_write(nbr); // number of sub protocols uint8_t j=0; if(nbr && (sub_protocol&0x07) Date: Thu, 17 Oct 2019 11:38:23 +0200 Subject: [PATCH 31/65] Correct option value for FrSky protocols --- Multiprotocol/Multi_Names.ino | 4 ++-- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Multiprotocol/Multi_Names.ino b/Multiprotocol/Multi_Names.ino index f93b1df..8c73f7d 100644 --- a/Multiprotocol/Multi_Names.ino +++ b/Multiprotocol/Multi_Names.ino @@ -166,7 +166,7 @@ const mm_protocol_definition multi_protocols[] = { {PROTO_BAYANG, STR_BAYANG, 5, STR_SUBTYPE_BAYANG, OPTION_TELEM }, #endif #if defined(FRSKYX_CC2500_INO) - {PROTO_FRSKYX, STR_FRSKYX, 4, STR_SUBTYPE_FRSKYX, OPTION_NONE }, + {PROTO_FRSKYX, STR_FRSKYX, 4, STR_SUBTYPE_FRSKYX, OPTION_RFTUNE }, #endif #if defined(ESKY_NRF24L01_INO) {PROTO_ESKY, STR_ESKY, 0, NO_SUBTYPE, OPTION_NONE }, @@ -196,7 +196,7 @@ const mm_protocol_definition multi_protocols[] = { {PROTO_ASSAN, STR_ASSAN, 0, NO_SUBTYPE, OPTION_NONE }, #endif #if defined(FRSKYV_CC2500_INO) - {PROTO_FRSKYV, STR_FRSKYV, 0, NO_SUBTYPE, OPTION_NONE }, + {PROTO_FRSKYV, STR_FRSKYV, 0, NO_SUBTYPE, OPTION_RFTUNE }, #endif #if defined(HONTAI_NRF24L01_INO) {PROTO_HONTAI, STR_HONTAI, 4, STR_SUBTYPE_HONTAI, OPTION_NONE }, diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index adbf5a1..9f836dc 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 19 +#define VERSION_PATCH_LEVEL 20 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index bdbaa78..eaa930e 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -1422,7 +1422,7 @@ static void protocol_init() for(uint8_t j=0;j Date: Thu, 17 Oct 2019 16:56:15 +0200 Subject: [PATCH 32/65] Fix SLT inversion --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/SLT_nrf24l01.ino | 2 +- Multiprotocol/_Config.h | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 9f836dc..d8bba51 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 20 +#define VERSION_PATCH_LEVEL 21 //****************** // Protocols diff --git a/Multiprotocol/SLT_nrf24l01.ino b/Multiprotocol/SLT_nrf24l01.ino index aca37fc..693014a 100644 --- a/Multiprotocol/SLT_nrf24l01.ino +++ b/Multiprotocol/SLT_nrf24l01.ino @@ -141,7 +141,7 @@ static void __attribute__((unused)) SLT_build_packet() for (uint8_t i = 0; i < 4; ++i) { uint16_t v = convert_channel_10b(CH_AETR[i]); - if(sub_protocol>SLT_V2 && (i==CH1 || i==CH3) ) + if(sub_protocol>SLT_V2 && (i==CH2 || i==CH3) ) v=1023-v; // reverse throttle and elevator channels for Q100/Q200/MR100 protocols packet[i] = v; e = (e >> 2) | (uint8_t) ((v >> 2) & 0xC0); diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 4095850..2ede3f3 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -272,10 +272,11 @@ //Sends Multi status and allow OpenTX to autodetect the telemetry format. Comment to disable. //Supported by OpenTX version 2.2 RC9 and newer. NOT supported by er9x/erskyTX use MULTI_STATUS instead. #define MULTI_TELEMETRY -//Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. -#define MULTI_SYNC //Send to OpenTX the current protocol and subprotocol names. Comment to disable. #define MULTI_NAMES +//WIP DO NOT ENABLE UNLESS YOU KNOW WHAT YOU ARE DOING +//Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. +//#define MULTI_SYNC //Comment a line to disable a specific protocol telemetry #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, erskyTX and OpenTX From 6a83cb55770d864d73763db218a9e6b67ab7f3ca Mon Sep 17 00:00:00 2001 From: goebish Date: Thu, 17 Oct 2019 16:59:08 +0200 Subject: [PATCH 33/65] Frsky rx fixes (#289) * Restore previous cc2500 register init * Fix failsafe packets locks * Fix D8 checksum check --- Multiprotocol/FrSkyDVX_common.ino | 6 +- Multiprotocol/FrSky_Rx_cc2500.ino | 108 +++++++++++++++++++++++++----- 2 files changed, 96 insertions(+), 18 deletions(-) diff --git a/Multiprotocol/FrSkyDVX_common.ino b/Multiprotocol/FrSkyDVX_common.ino index 9293634..801b6e9 100644 --- a/Multiprotocol/FrSkyDVX_common.ino +++ b/Multiprotocol/FrSkyDVX_common.ino @@ -74,7 +74,7 @@ void Frsky_init_hop(void) /******************************/ /** FrSky V, D and X routines **/ /******************************/ -#if defined(FRSKYV_CC2500_INO) || defined(FRSKYD_CC2500_INO) || defined(FRSKYX_CC2500_INO) || defined(FRSKY_RX_CC2500_INO) +#if defined(FRSKYV_CC2500_INO) || defined(FRSKYD_CC2500_INO) || defined(FRSKYX_CC2500_INO) const PROGMEM uint8_t FRSKY_common_startreg_cc2500_conf[]= { CC2500_02_IOCFG0 , CC2500_00_IOCFG2 , @@ -119,7 +119,7 @@ void Frsky_init_hop(void) /*15_DEVIATN*/ 0x41 }; #endif - #if defined(FRSKYD_CC2500_INO) || defined(FRSKY_RX_CC2500_INO) + #if defined(FRSKYD_CC2500_INO) const PROGMEM uint8_t FRSKYD_cc2500_conf[]= { /*02_IOCFG0*/ 0x06 , /*00_IOCFG2*/ 0x06 , @@ -142,7 +142,7 @@ void Frsky_init_hop(void) /*15_DEVIATN*/ 0x42 }; #endif - #if defined(FRSKYX_CC2500_INO) || defined(FRSKY_RX_CC2500_INO) + #if defined(FRSKYX_CC2500_INO) const PROGMEM uint8_t FRSKYX_cc2500_conf[]= { //FRSKYX /*02_IOCFG0*/ 0x06 , diff --git a/Multiprotocol/FrSky_Rx_cc2500.ino b/Multiprotocol/FrSky_Rx_cc2500.ino index 6f599f0..a284e2a 100644 --- a/Multiprotocol/FrSky_Rx_cc2500.ino +++ b/Multiprotocol/FrSky_Rx_cc2500.ino @@ -29,13 +29,80 @@ enum FRSKY_RX_D8 }; - enum { +enum { FRSKY_RX_TUNE_START, FRSKY_RX_TUNE_LOW, FRSKY_RX_TUNE_HIGH, FRSKY_RX_BIND, FRSKY_RX_DATA, - }; +}; + +const PROGMEM uint8_t frsky_rx_common_reg[][2] = { + {CC2500_02_IOCFG0, 0x01}, + {CC2500_18_MCSM0, 0x18}, + {CC2500_07_PKTCTRL1, 0x04}, + {CC2500_3E_PATABLE, 0xFF}, + {CC2500_0C_FSCTRL0, 0}, + {CC2500_0D_FREQ2, 0x5C}, + {CC2500_13_MDMCFG1, 0x23}, + {CC2500_14_MDMCFG0, 0x7A}, + {CC2500_19_FOCCFG, 0x16}, + {CC2500_1A_BSCFG, 0x6C}, + {CC2500_1B_AGCCTRL2, 0x03}, + {CC2500_1C_AGCCTRL1, 0x40}, + {CC2500_1D_AGCCTRL0, 0x91}, + {CC2500_21_FREND1, 0x56}, + {CC2500_22_FREND0, 0x10}, + {CC2500_23_FSCAL3, 0xA9}, + {CC2500_24_FSCAL2, 0x0A}, + {CC2500_25_FSCAL1, 0x00}, + {CC2500_26_FSCAL0, 0x11}, + {CC2500_29_FSTEST, 0x59}, + {CC2500_2C_TEST2, 0x88}, + {CC2500_2D_TEST1, 0x31}, + {CC2500_2E_TEST0, 0x0B}, + {CC2500_03_FIFOTHR, 0x07}, + {CC2500_09_ADDR, 0x00}, +}; + +const PROGMEM uint8_t frsky_rx_d16fcc_reg[][2] = { + {CC2500_17_MCSM1, 0x0C}, + {CC2500_0E_FREQ1, 0x76}, + {CC2500_0F_FREQ0, 0x27}, + {CC2500_06_PKTLEN, 0x1E}, + {CC2500_08_PKTCTRL0, 0x01}, + {CC2500_0B_FSCTRL1, 0x0A}, + {CC2500_10_MDMCFG4, 0x7B}, + {CC2500_11_MDMCFG3, 0x61}, + {CC2500_12_MDMCFG2, 0x13}, + {CC2500_15_DEVIATN, 0x51}, +}; + +const PROGMEM uint8_t frsky_rx_d16lbt_reg[][2] = { + {CC2500_17_MCSM1, 0x0E}, + {CC2500_0E_FREQ1, 0x80}, + {CC2500_0F_FREQ0, 0x00}, + {CC2500_06_PKTLEN, 0x23}, + {CC2500_08_PKTCTRL0, 0x01}, + {CC2500_0B_FSCTRL1, 0x08}, + {CC2500_10_MDMCFG4, 0x7B}, + {CC2500_11_MDMCFG3, 0xF8}, + {CC2500_12_MDMCFG2, 0x03}, + {CC2500_15_DEVIATN, 0x53}, +}; + +const PROGMEM uint8_t frsky_rx_d8_reg[][2] = { + {CC2500_17_MCSM1, 0x0C}, + {CC2500_0E_FREQ1, 0x76}, + {CC2500_0F_FREQ0, 0x27}, + {CC2500_06_PKTLEN, 0x19}, + {CC2500_08_PKTCTRL0, 0x05}, + {CC2500_0B_FSCTRL1, 0x08}, + {CC2500_10_MDMCFG4, 0xAA}, + {CC2500_11_MDMCFG3, 0x39}, + {CC2500_12_MDMCFG2, 0x11}, + {CC2500_15_DEVIATN, 0x42}, +}; static uint8_t frsky_rx_chanskip; static int8_t frsky_rx_finetune; @@ -53,21 +120,27 @@ static void __attribute__((unused)) frsky_rx_initialise_cc2500() { packet_length = frsky_rx_length[frsky_rx_format]; CC2500_Reset(); CC2500_Strobe(CC2500_SIDLE); - CC2500_WriteReg(CC2500_0A_CHANNR, 0); // bind channel + for (uint8_t i = 0; i < sizeof(frsky_rx_common_reg) / 2; i++) + CC2500_WriteReg(pgm_read_byte_near(&frsky_rx_common_reg[i][0]), pgm_read_byte_near(&frsky_rx_common_reg[i][1])); + switch (frsky_rx_format) { case FRSKY_RX_D16FCC: - FRSKY_init_cc2500(FRSKYX_cc2500_conf); + for (uint8_t i = 0; i < sizeof(frsky_rx_d16fcc_reg) / 2; i++) + CC2500_WriteReg(pgm_read_byte_near(&frsky_rx_d16fcc_reg[i][0]), pgm_read_byte_near(&frsky_rx_d16fcc_reg[i][1])); break; case FRSKY_RX_D16LBT: - FRSKY_init_cc2500(FRSKYXEU_cc2500_conf); + for (uint8_t i = 0; i < sizeof(frsky_rx_d16lbt_reg) / 2; i++) + CC2500_WriteReg(pgm_read_byte_near(&frsky_rx_d16lbt_reg[i][0]), pgm_read_byte_near(&frsky_rx_d16lbt_reg[i][1])); break; case FRSKY_RX_D8: - FRSKY_init_cc2500(FRSKYD_cc2500_conf); + for (uint8_t i = 0; i < sizeof(frsky_rx_d8_reg) / 2; i++) + CC2500_WriteReg(pgm_read_byte_near(&frsky_rx_d8_reg[i][0]), pgm_read_byte_near(&frsky_rx_d8_reg[i][1])); CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x05); // always check address CC2500_WriteReg(CC2500_09_ADDR, 0x03); // bind address CC2500_WriteReg(CC2500_23_FSCAL3, 0x89); break; } + CC2500_WriteReg(CC2500_0A_CHANNR, 0); // bind channel rx_disable_lna = IS_POWER_FLAG_on; CC2500_SetTxRxMode(rx_disable_lna ? TXRX_OFF : RX_EN); // lna disable / enable frsky_rx_strobe_rx(); @@ -98,8 +171,10 @@ static void __attribute__((unused)) frsky_rx_calibrate() static uint8_t __attribute__((unused)) frskyx_rx_check_crc() { + // check D8 checksum if (frsky_rx_format == FRSKY_RX_D8) - return 1; + return (packet[packet_length-1] & 0x80) == 0x80; // check CRC_OK flag in status byte 2 + // check D16 checksum uint8_t limit = packet_length - 4; uint16_t lcrc = FrSkyX_crc(&packet[3], limit - 3); // computed crc uint16_t rcrc = (packet[limit] << 8) | (packet[limit + 1] & 0xff); // received crc @@ -123,14 +198,17 @@ static void __attribute__((unused)) frsky_rx_build_telemetry_packet() raw_channel[4] = ((packet[16] << 8) & 0xF00) | packet[15]; raw_channel[5] = ((packet[17] << 4) & 0xFF0) | (packet[16] >> 4); raw_channel[6] = ((packet[19] << 8) & 0xF00) | packet[18]; - raw_channel[7] = ((packet[20] << 4) & 0xFF0) | (packet[19] >> 4); + raw_channel[7] = ((packet[20] << 4) & 0xFF0) | (packet[19] >> 4); for (i = 0; i < 8; i++) { - uint8_t shifted = (raw_channel[i] & 0x800)>0; - uint16_t channel_value = raw_channel[i] & 0x7FF; - if (channel_value < 64) - rx_rc_chan[shifted ? i + 8 : i] = 0; - else - rx_rc_chan[shifted ? i + 8 : i] = min(((channel_value - 64) << 4) / 15, 2047); + // ignore failsafe channels + if(packet[7] != 0x10+(i<<1)) { + uint8_t shifted = (raw_channel[i] & 0x800)>0; + uint16_t channel_value = raw_channel[i] & 0x7FF; + if (channel_value < 64) + rx_rc_chan[shifted ? i + 8 : i] = 0; + else + rx_rc_chan[shifted ? i + 8 : i] = min(((channel_value - 64) << 4) / 15, 2047); + } } } else { @@ -336,7 +414,7 @@ uint16_t FrSky_Rx_callback() frsky_rx_chanskip = ((packet[4] & 0xC0) >> 6) | ((packet[5] & 0x3F) << 2); hopping_frequency_no = (hopping_frequency_no + frsky_rx_chanskip) % 47; frsky_rx_set_channel(hopping_frequency_no); - if((frsky_rx_format == FRSKY_RX_D8 || packet[7] == 0) && telemetry_link == 0) { // send channels to TX + if (telemetry_link == 0) { // send channels to TX frsky_rx_build_telemetry_packet(); telemetry_link = 1; } From 2154b754993df505e476f8ac68536dcc19852a43 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 17 Oct 2019 22:35:43 +0200 Subject: [PATCH 34/65] Fix MULTI_NAMES len... --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Telemetry.ino | 2 +- Multiprotocol/_Config.h | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index d8bba51..53532ea 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 21 +#define VERSION_PATCH_LEVEL 22 //****************** // Protocols diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index e574193..3c2fd2b 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -129,7 +129,7 @@ static void multi_send_status() { #ifdef MULTI_NAMES if(multi_protocols_index != 0xFF) - multi_send_header(MULTI_TELEMETRY_STATUS, 25); + multi_send_header(MULTI_TELEMETRY_STATUS, 24); else #endif multi_send_header(MULTI_TELEMETRY_STATUS, 6); diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 2ede3f3..c0346b1 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -274,9 +274,8 @@ #define MULTI_TELEMETRY //Send to OpenTX the current protocol and subprotocol names. Comment to disable. #define MULTI_NAMES -//WIP DO NOT ENABLE UNLESS YOU KNOW WHAT YOU ARE DOING //Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. -//#define MULTI_SYNC +#define MULTI_SYNC //Comment a line to disable a specific protocol telemetry #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, erskyTX and OpenTX From b156f661463d674e88f11b3d1c07df2b27f0d55d Mon Sep 17 00:00:00 2001 From: pascallanger Date: Fri, 25 Oct 2019 21:35:25 +0200 Subject: [PATCH 35/65] Fix Failsafe compilation --- Multiprotocol/Multiprotocol.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index eaa930e..7a16a52 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -679,7 +679,9 @@ uint8_t Update_All() Channel_data[i]=val; } PPM_FLAG_off; // wait for next frame before update - PPM_failsafe(); + #ifdef FAILSAFE_ENABLE + PPM_failsafe(); + #endif update_channels_aux(); INPUT_SIGNAL_on; // valid signal received last_signal=millis(); @@ -721,7 +723,7 @@ uint8_t Update_All() return 0; } -#ifdef ENABLE_PPM +#if defined(FAILSAFE_ENABLE) && defined(ENABLE_PPM) void PPM_failsafe() { static uint8_t counter=0; From 0fddd9c11906f8c72fc7d34ee7f113a76016e751 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Fri, 25 Oct 2019 22:03:39 +0200 Subject: [PATCH 36/65] Fix AFHDS2A RX_LQI forward on CH Hopefully... --- Multiprotocol/AFHDS2A_a7105.ino | 21 ++++++++++++++------- Multiprotocol/Multiprotocol.h | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Multiprotocol/AFHDS2A_a7105.ino b/Multiprotocol/AFHDS2A_a7105.ino index acdfb6f..7abc6de 100644 --- a/Multiprotocol/AFHDS2A_a7105.ino +++ b/Multiprotocol/AFHDS2A_a7105.ino @@ -122,7 +122,8 @@ static void AFHDS2A_update_telemetry() telemetry_link=1; break; case AFHDS2A_SENSOR_RX_ERR_RATE: - RX_LQI=packet[index+2]; + if(packet[index+2]<=100) + RX_LQI=packet[index+2]; break; case AFHDS2A_SENSOR_RX_RSSI: RX_RSSI = -packet[index+2]; @@ -349,13 +350,19 @@ uint16_t ReadAFHDS2A() if(packet[0] == 0xAA || packet[0] == 0xAC) { if(!memcmp(&packet[1], rx_tx_addr, 4)) - { // Validate TX address + { // TX address validated #ifdef AFHDS2A_LQI_CH - for(uint8_t sensor=0; sensor<7; sensor++) - {//read LQI value for RX output - uint8_t index = 9+(4*sensor); - if(packet[index]==AFHDS2A_SENSOR_RX_ERR_RATE) - RX_LQI=packet[index+2]; + if(packet[0]==0xAA && packet[9]!=0xFD) + {// Normal telemetry packet + for(uint8_t sensor=0; sensor<7; sensor++) + {//read LQI value for RX output + uint8_t index = 9+(4*sensor); + if(packet[index]==AFHDS2A_SENSOR_RX_ERR_RATE && packet[index+2]<=100) + { + RX_LQI=packet[index+2]; + break; + } + } } #endif #if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 53532ea..2c71f06 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 22 +#define VERSION_PATCH_LEVEL 23 //****************** // Protocols From 9f1bdc901c38b8dd63e0bed1045660ae4303e8de Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 27 Oct 2019 13:20:53 +0100 Subject: [PATCH 37/65] FrSkyX LBT: implement LBT instead of transmitting all the time Needs to be activated using FRSKYX_LBT for now. --- Multiprotocol/FrSkyDVX_common.ino | 3 +- Multiprotocol/FrSkyX_cc2500.ino | 47 +++++++++++++++++++++++-------- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/_Config.h | 11 ++++++-- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Multiprotocol/FrSkyDVX_common.ino b/Multiprotocol/FrSkyDVX_common.ino index 801b6e9..573d463 100644 --- a/Multiprotocol/FrSkyDVX_common.ino +++ b/Multiprotocol/FrSkyDVX_common.ino @@ -47,7 +47,8 @@ enum { FRSKY_DATA2, FRSKY_DATA3, FRSKY_DATA4, - FRSKY_DATA5 + FRSKY_DATA5, + FRSKY_DATA6 }; void Frsky_init_hop(void) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 39ea701..ac66992 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -276,6 +276,8 @@ static void __attribute__((unused)) FrSkyX_build_packet() uint16_t ReadFrSkyX() { + static bool transmit=true; + switch(state) { default: @@ -300,38 +302,55 @@ uint16_t ReadFrSkyX() case FRSKY_DATA1: if ( prev_option != option ) { - CC2500_WriteReg(CC2500_0C_FSCTRL0,option); // Frequency offset hack + CC2500_WriteReg(CC2500_0C_FSCTRL0,option); //Frequency offset hack prev_option = option ; } - CC2500_SetTxRxMode(TX_EN); FrSkyX_set_start(hopping_frequency_no); - CC2500_SetPower(); + transmit=true; +#ifdef FRSKYX_LBT + CC2500_Strobe(CC2500_SIDLE); + state++; + return 210; //Wait for the freq to stabilize + case FRSKY_DATA2: + CC2500_Strobe(CC2500_SRX); //Acquire RSSI + state++; + return 20; + case FRSKY_DATA3: + uint8_t rssi; + rssi = CC2500_ReadReg(CC2500_34_RSSI | CC2500_READ_BURST); // 0.5 db/count, RSSI value read from the RSSI status register is a 2's complement number + if ((sub_protocol & 2) && rssi > 72 && rssi < 128) //LBT and RSSI between -36 to -8.5 dBm + { + transmit=false; + debugln("Busy %d %d",hopping_frequency_no,rssi); + } +#endif + CC2500_SetTxRxMode(TX_EN); + CC2500_SetPower(); CC2500_Strobe(CC2500_SFRX); hopping_frequency_no = (hopping_frequency_no+FrSkyX_chanskip)%47; CC2500_Strobe(CC2500_SIDLE); - CC2500_WriteData(packet, packet[0]+1); - state++; + if(transmit) + CC2500_WriteData(packet, packet[0]+1); + state=FRSKY_DATA4; return 5200; - case FRSKY_DATA2: + case FRSKY_DATA4: CC2500_SetTxRxMode(RX_EN); CC2500_Strobe(CC2500_SIDLE); state++; return 200; - case FRSKY_DATA3: + case FRSKY_DATA5: CC2500_Strobe(CC2500_SRX); state++; return 3100; - case FRSKY_DATA4: + case FRSKY_DATA6: telemetry_set_input_sync(9000); len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; - if (len && (len<=(0x0E + 3))) //Telemetry frame is 17 + if (len && (len<=(0x0E + 3))) //Telemetry frame is 17 { packet_count=0; CC2500_ReadData(packet_in, len); #if defined TELEMETRY - frsky_check_telemetry(packet_in,len); //check if valid telemetry packets - //parse telemetry packets here - //The same telemetry function used by FrSky(D8). + frsky_check_telemetry(packet_in,len); //Check and parse telemetry packets #endif } else @@ -355,7 +374,11 @@ uint16_t ReadFrSkyX() } FrSkyX_build_packet(); state = FRSKY_DATA1; +#ifdef FRSKYX_LBT + return 270; +#else return 500; +#endif } return 1; } diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 2c71f06..e65312a 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 23 +#define VERSION_PATCH_LEVEL 24 //****************** // Protocols diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index c0346b1..7fa5ea3 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -222,6 +222,12 @@ /*** PROTOCOLS SETTINGS ***/ /***************************/ +//FrSkyX specific setting +//----------------------- +//EU LBT setting +//If commented the TX will not check if a channel is busy before transmitting +//#define FRSKYX_LBT + //DSM specific settings //--------------------- //The DSM protocol is using by default the Spektrum throw of 1100..1900us @100% and 1000..2000us @125%. @@ -274,8 +280,9 @@ #define MULTI_TELEMETRY //Send to OpenTX the current protocol and subprotocol names. Comment to disable. #define MULTI_NAMES -//Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. -#define MULTI_SYNC +//Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Uncomment to enable. +//!!!Work in progress!!! it's currently known to cause issues. Enable only if you know what you are doing. +//#define MULTI_SYNC //Comment a line to disable a specific protocol telemetry #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, erskyTX and OpenTX From 400fdb3cc6be6d3ae648586b5f7d95abe1487b73 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 27 Oct 2019 16:44:36 +0100 Subject: [PATCH 38/65] FrSkyX LBT RSSI timing improvement --- Multiprotocol/FrSkyX_cc2500.ino | 92 ++++++++++++++++----------------- Multiprotocol/_Config.h | 5 +- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index ac66992..06adf4c 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -297,51 +297,8 @@ uint16_t ReadFrSkyX() FrSkyX_initialize_data(0); hopping_frequency_no=0; BIND_DONE; - state++; + state++; //FRSKY_DATA1 break; - case FRSKY_DATA1: - if ( prev_option != option ) - { - CC2500_WriteReg(CC2500_0C_FSCTRL0,option); //Frequency offset hack - prev_option = option ; - } - FrSkyX_set_start(hopping_frequency_no); - transmit=true; -#ifdef FRSKYX_LBT - CC2500_Strobe(CC2500_SIDLE); - state++; - return 210; //Wait for the freq to stabilize - case FRSKY_DATA2: - CC2500_Strobe(CC2500_SRX); //Acquire RSSI - state++; - return 20; - case FRSKY_DATA3: - uint8_t rssi; - rssi = CC2500_ReadReg(CC2500_34_RSSI | CC2500_READ_BURST); // 0.5 db/count, RSSI value read from the RSSI status register is a 2's complement number - if ((sub_protocol & 2) && rssi > 72 && rssi < 128) //LBT and RSSI between -36 to -8.5 dBm - { - transmit=false; - debugln("Busy %d %d",hopping_frequency_no,rssi); - } -#endif - CC2500_SetTxRxMode(TX_EN); - CC2500_SetPower(); - CC2500_Strobe(CC2500_SFRX); - hopping_frequency_no = (hopping_frequency_no+FrSkyX_chanskip)%47; - CC2500_Strobe(CC2500_SIDLE); - if(transmit) - CC2500_WriteData(packet, packet[0]+1); - state=FRSKY_DATA4; - return 5200; - case FRSKY_DATA4: - CC2500_SetTxRxMode(RX_EN); - CC2500_Strobe(CC2500_SIDLE); - state++; - return 200; - case FRSKY_DATA5: - CC2500_Strobe(CC2500_SRX); - state++; - return 3100; case FRSKY_DATA6: telemetry_set_input_sync(9000); len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; @@ -374,11 +331,52 @@ uint16_t ReadFrSkyX() } FrSkyX_build_packet(); state = FRSKY_DATA1; -#ifdef FRSKYX_LBT - return 270; -#else +#if not defined(FRSKYX_LBT) return 500; +#endif // for LBT just continue to DATA1 right away + case FRSKY_DATA1: + if ( prev_option != option ) + { + CC2500_WriteReg(CC2500_0C_FSCTRL0,option); //Frequency offset hack + prev_option = option ; + } + FrSkyX_set_start(hopping_frequency_no); + transmit=true; +#ifdef FRSKYX_LBT + CC2500_Strobe(CC2500_SIDLE); + state++; + return 100; //Wait for the freq to stabilize + case FRSKY_DATA2: + CC2500_Strobe(CC2500_SRX); //Acquire RSSI + state++; + return 400; + case FRSKY_DATA3: + uint8_t rssi; + rssi = CC2500_ReadReg(CC2500_34_RSSI | CC2500_READ_BURST); // 0.5 db/count, RSSI value read from the RSSI status register is a 2's complement number + if ((sub_protocol & 2) && rssi > 72 && rssi < 128) //LBT and RSSI between -36 to -8.5 dBm + { + transmit=false; + debugln("Busy %d %d",hopping_frequency_no,rssi); + } #endif + CC2500_SetTxRxMode(TX_EN); + CC2500_SetPower(); + CC2500_Strobe(CC2500_SFRX); + hopping_frequency_no = (hopping_frequency_no+FrSkyX_chanskip)%47; + CC2500_Strobe(CC2500_SIDLE); + if(transmit) + CC2500_WriteData(packet, packet[0]+1); + state=FRSKY_DATA4; + return 5200; + case FRSKY_DATA4: + CC2500_SetTxRxMode(RX_EN); + CC2500_Strobe(CC2500_SIDLE); + state++; + return 200; + case FRSKY_DATA5: + CC2500_Strobe(CC2500_SRX); + state++; + return 3100; } return 1; } diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 7fa5ea3..443a384 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -224,8 +224,7 @@ //FrSkyX specific setting //----------------------- -//EU LBT setting -//If commented the TX will not check if a channel is busy before transmitting +//EU LBT setting: if commented the TX will not check if a channel is busy before transmitting. //#define FRSKYX_LBT //DSM specific settings @@ -270,6 +269,8 @@ //For er9x it depends if you have an inveter mod or not on the telemetry pin. If you don't have an inverter comment this line. //=>OpenTX 2.3.2 with a STM32 or OrangeRX module this setting can be ignored. #define INVERT_TELEMETRY +//For STM32 and OrangeRX modules, comment to prevent the TX from forcing the serial telemetry polarity normal/invert. +#define INVERT_TELEMETRY_TX //Uncomment if you don't want to send Multi status telemetry frames (Protocol available, Bind in progress, version...) //Use with er9x/erskyTX, for OpenTX MULTI_TELEMETRY below is preferred instead From 63d7e32e06bbcb82b1e783ed9f27810e631b3c2b Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 27 Oct 2019 17:02:38 +0100 Subject: [PATCH 39/65] INVERT_TELEMETRY_TX flag --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 14 ++++++-------- Multiprotocol/_Config.h | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index e65312a..baee1f4 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 24 +#define VERSION_PATCH_LEVEL 25 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 7a16a52..c860f82 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -1463,7 +1463,7 @@ static void protocol_init() void update_serial_data() { static bool prev_ch_mapping=false; - #ifdef TELEMETRY + #if defined(TELEMETRY) && defined(INVERT_TELEMETRY_TX) #ifdef INVERT_TELEMETRY static bool prev_inv_telem=true; #else @@ -1557,16 +1557,15 @@ void update_serial_data() DISABLE_TELEM_on; if(rx_ok_buff[26]&0x01) DISABLE_CH_MAP_on; - #if defined TELEMETRY + #if defined(TELEMETRY) && defined(INVERT_TELEMETRY_TX) if(((rx_ok_buff[26]&0x08)!=0) ^ prev_inv_telem) { //value changed if(rx_ok_buff[26]&0x08) { // Invert telemetry debugln("Invert telem %d,%d",rx_ok_buff[26]&0x01,prev_inv_telem); - #ifdef ORANGE_TX + #if defined (ORANGE_TX) PORTC.PIN3CTRL |= 0x40 ; - #endif - #ifdef STM32_BOARD + #elif defined (STM32_BOARD) TX_INV_on; RX_INV_on; #endif @@ -1574,10 +1573,9 @@ void update_serial_data() else { // Normal telemetry debugln("Normal telem %d,%d",rx_ok_buff[26]&0x01,prev_inv_telem); - #ifdef ORANGE_TX + #if defined (ORANGE_TX) PORTC.PIN3CTRL &= 0xBF ; - #endif - #ifdef STM32_BOARD + #elif defined (STM32_BOARD) TX_INV_off; RX_INV_off; #endif diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 443a384..334044d 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -225,7 +225,7 @@ //FrSkyX specific setting //----------------------- //EU LBT setting: if commented the TX will not check if a channel is busy before transmitting. -//#define FRSKYX_LBT +#define FRSKYX_LBT //DSM specific settings //--------------------- From a9f35f8095b5bf18dd0b31ba8a1b62cad449e411 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 27 Oct 2019 17:05:02 +0100 Subject: [PATCH 40/65] Update _Config.h --- Multiprotocol/_Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 334044d..443a384 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -225,7 +225,7 @@ //FrSkyX specific setting //----------------------- //EU LBT setting: if commented the TX will not check if a channel is busy before transmitting. -#define FRSKYX_LBT +//#define FRSKYX_LBT //DSM specific settings //--------------------- From d29461607b84a463b496eb0ad1bcd4475ff6e442 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 29 Oct 2019 00:36:57 +0100 Subject: [PATCH 41/65] Tweakes --- Multiprotocol/FrSkyX_cc2500.ino | 4 ++-- Multiprotocol/Multiprotocol.h | 12 ++++++------ Multiprotocol/Multiprotocol.ino | 22 +++++++++++++--------- Multiprotocol/Scanner_cc2500.ino | 2 +- Multiprotocol/Telemetry.ino | 5 +++++ 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 06adf4c..33fce64 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -232,7 +232,7 @@ static void __attribute__((unused)) FrSkyX_build_packet() if(nbr_bytes) {//Check the buffer status uint8_t used = SportTail; - if ( SportHead >= SportTail ) + if ( SportHead > SportTail ) used += MAX_SPORT_BUFFER - SportHead ; else used -= SportHead ; @@ -353,7 +353,7 @@ uint16_t ReadFrSkyX() case FRSKY_DATA3: uint8_t rssi; rssi = CC2500_ReadReg(CC2500_34_RSSI | CC2500_READ_BURST); // 0.5 db/count, RSSI value read from the RSSI status register is a 2's complement number - if ((sub_protocol & 2) && rssi > 72 && rssi < 128) //LBT and RSSI between -36 to -8.5 dBm + if ((sub_protocol & 2) && rssi < 128) //LBT and RSSI between -73 to -8.5 dBm (-36dBm=72) { transmit=false; debugln("Busy %d %d",hopping_frequency_no,rssi); diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 5e4b13c..31be1c9 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 25 +#define VERSION_PATCH_LEVEL 26 //****************** // Protocols @@ -299,11 +299,11 @@ enum TRAXXAS struct PPM_Parameters { - uint8_t protocol : 6; - uint8_t sub_proto : 3; - uint8_t rx_num : 4; - uint8_t power : 1; - uint8_t autobind : 1; + uint8_t protocol; + uint8_t sub_proto : 3; + uint8_t rx_num : 6; + uint8_t power : 1; + uint8_t autobind : 1; int8_t option; uint32_t chan_order; }; diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 1347e94..6df2c9b 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -1712,9 +1712,12 @@ void update_serial_data() #endif if(IS_RX_MISSED_BUFF_on) // If the buffer is still valid { - rx_len=rx_idx; - memcpy((void*)rx_ok_buff,(const void*)rx_buff,rx_len);// Duplicate the buffer - RX_FLAG_on; // data to be processed next time... + if(rx_idx>=26 && rx_idxCCR2=TIMER2_BASE->CNT + 360; // Next byte should show up within 18??s=1.5 byte + TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 500; // Next byte should show up within 250us (1 byte = 120us) TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag TIMER2_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer2/Comp2 interrupt #else TX_RX_PAUSE_on; tx_pause(); cli(); // Disable global int due to RW of 16 bits registers - OCR1B = TCNT1 + 360; // Next byte should show up within 18??s=1.5 byte + OCR1B = TCNT1 + 500; // Next byte should show up within 250us (1 byte = 120us) sei(); // Enable global int TIFR1 = OCF1B_bm ; // clear OCR1B match flag SET_TIMSK1_OCIE1B ; // enable interrupt on compare B match @@ -2111,10 +2114,10 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { rx_buff[rx_idx++]=UDR0; // Store received byte #if defined STM32_BOARD - TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 360; // Next byte should show up within 18??s=1.5 byte + TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 500; // Next byte should show up within 250us (1 byte = 120us) #else cli(); // Disable global int due to RW of 16 bits registers - OCR1B = TCNT1 + 360; // Next byte should show up within 18??s=1.5 byte + OCR1B = TCNT1 + 500; // Next byte should show up within 250us (1 byte = 120us) sei(); // Enable global int #endif } @@ -2149,11 +2152,12 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) #elif defined STM32_BOARD void ISR_COMPB() #else - ISR(TIMER1_COMPB_vect, ISR_NOBLOCK ) + ISR(TIMER1_COMPB_vect) #endif { // Timer1 compare B interrupt - if(rx_idx>=26) + if(rx_idx>=26 && rx_idx Date: Thu, 31 Oct 2019 23:33:10 +0100 Subject: [PATCH 42/65] Fix (?) protocol issues --- Multiprotocol/FrSkyDVX_common.ino | 1 - Multiprotocol/FrSkyX_cc2500.ino | 38 +++++--- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 157 ++++++++++++++---------------- Multiprotocol/Telemetry.ino | 6 +- Multiprotocol/_Config.h | 6 +- 6 files changed, 105 insertions(+), 105 deletions(-) diff --git a/Multiprotocol/FrSkyDVX_common.ino b/Multiprotocol/FrSkyDVX_common.ino index 573d463..a827f87 100644 --- a/Multiprotocol/FrSkyDVX_common.ino +++ b/Multiprotocol/FrSkyDVX_common.ino @@ -48,7 +48,6 @@ enum { FRSKY_DATA3, FRSKY_DATA4, FRSKY_DATA5, - FRSKY_DATA6 }; void Frsky_init_hop(void) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 33fce64..c79d8b1 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -277,6 +277,9 @@ static void __attribute__((unused)) FrSkyX_build_packet() uint16_t ReadFrSkyX() { static bool transmit=true; + #ifdef DEBUG_SERIAL + static uint16_t fr_time=0; + #endif switch(state) { @@ -298,8 +301,8 @@ uint16_t ReadFrSkyX() hopping_frequency_no=0; BIND_DONE; state++; //FRSKY_DATA1 - break; - case FRSKY_DATA6: + break; + case FRSKY_DATA5: telemetry_set_input_sync(9000); len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; if (len && (len<=(0x0E + 3))) //Telemetry frame is 17 @@ -309,7 +312,7 @@ uint16_t ReadFrSkyX() #if defined TELEMETRY frsky_check_telemetry(packet_in,len); //Check and parse telemetry packets #endif - } + } else { packet_count++; @@ -344,36 +347,43 @@ uint16_t ReadFrSkyX() transmit=true; #ifdef FRSKYX_LBT CC2500_Strobe(CC2500_SIDLE); - state++; - return 100; //Wait for the freq to stabilize - case FRSKY_DATA2: + delayMicroseconds(90); //Wait for the freq to stabilize CC2500_Strobe(CC2500_SRX); //Acquire RSSI state++; - return 400; - case FRSKY_DATA3: + return 500; + case FRSKY_DATA2: uint8_t rssi; rssi = CC2500_ReadReg(CC2500_34_RSSI | CC2500_READ_BURST); // 0.5 db/count, RSSI value read from the RSSI status register is a 2's complement number - if ((sub_protocol & 2) && rssi < 128) //LBT and RSSI between -73 to -8.5 dBm (-36dBm=72) + if ((sub_protocol & 2) && rssi > 72 && rssi < 128) //LBT and RSSI between -36 and -8.5 dBm { transmit=false; debugln("Busy %d %d",hopping_frequency_no,rssi); } #endif + CC2500_Strobe(CC2500_SIDLE); + CC2500_Strobe(CC2500_SFRX); CC2500_SetTxRxMode(TX_EN); CC2500_SetPower(); - CC2500_Strobe(CC2500_SFRX); hopping_frequency_no = (hopping_frequency_no+FrSkyX_chanskip)%47; - CC2500_Strobe(CC2500_SIDLE); if(transmit) + { + #ifdef DEBUG_SERIAL + uint16_t fr_cur=millis(); + fr_time=fr_cur-fr_time; + if(fr_time!=9) + debugln("Bad timing: %d",fr_time); + fr_time=fr_cur; + #endif CC2500_WriteData(packet, packet[0]+1); - state=FRSKY_DATA4; + } + state=FRSKY_DATA3; return 5200; - case FRSKY_DATA4: + case FRSKY_DATA3: CC2500_SetTxRxMode(RX_EN); CC2500_Strobe(CC2500_SIDLE); state++; return 200; - case FRSKY_DATA5: + case FRSKY_DATA4: CC2500_Strobe(CC2500_SRX); state++; return 3100; diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 31be1c9..20239a2 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 26 +#define VERSION_PATCH_LEVEL 27 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 6df2c9b..5de4cc7 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -165,7 +165,7 @@ uint8_t RX_num; #define RXBUFFER_SIZE 36 // 26+1+9 volatile uint8_t rx_buff[RXBUFFER_SIZE]; volatile uint8_t rx_ok_buff[RXBUFFER_SIZE]; -volatile uint8_t discard_frame = 0; +volatile bool discard_frame = false; volatile uint8_t rx_idx=0, rx_len=0; @@ -555,88 +555,76 @@ void setup() // Protocol scheduler void loop() { - uint16_t next_callback,diff=0xFFFF; + uint16_t next_callback, diff; + uint8_t count=0; while(1) { - if(remote_callback==0 || IS_WAIT_BIND_on || diff>2*200) - { - do + while(remote_callback==0 || IS_WAIT_BIND_on || IS_INPUT_SIGNAL_off) + if(!Update_All()) { - Update_All(); - } - while(remote_callback==0 || IS_WAIT_BIND_on); - } - #ifndef STM32_BOARD - if( (TIFR1 & OCF1A_bm) != 0) - { - cli(); // Disable global int due to RW of 16 bits registers - OCR1A=TCNT1; // Callback should already have been called... Use "now" as new sync point. - sei(); // Enable global int - } - else - while((TIFR1 & OCF1A_bm) == 0); // Wait before callback - #else - if((TIMER2_BASE->SR & TIMER_SR_CC1IF)!=0) - { - debugln("Callback miss"); - cli(); - OCR1A = TCNT1; - sei(); - } - else - while((TIMER2_BASE->SR & TIMER_SR_CC1IF )==0); // Wait before callback - #endif - do - { - TX_MAIN_PAUSE_on; - tx_pause(); - if(IS_INPUT_SIGNAL_on && remote_callback!=0) - next_callback=remote_callback(); - else - next_callback=2000; // No PPM/serial signal check again in 2ms... - TX_MAIN_PAUSE_off; - tx_resume(); - while(next_callback>1000) - { // start to wait here as much as we can... - next_callback-=500; // We will wait below for 0.5ms cli(); // Disable global int due to RW of 16 bits registers - OCR1A += 500*2 ; // set compare A for callback - #ifndef STM32_BOARD - TIFR1=OCF1A_bm; // clear compare A=callback flag - #else - TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC1IF; // Clear Timer2/Comp1 interrupt flag - #endif - sei(); // enable global int - if(Update_All()) // Protocol changed? - { - next_callback=0; // Launch new protocol ASAP - break; - } - #ifndef STM32_BOARD - while((TIFR1 & OCF1A_bm) == 0); // wait 0.5ms... - #else - while((TIMER2_BASE->SR & TIMER_SR_CC1IF)==0);//wait 0.5ms... - #endif + OCR1A=TCNT1; // Callback should already have been called... Use "now" as new sync point. + sei(); // Enable global int } - // at this point we have a maximum of 1ms in next_callback - next_callback *= 2 ; + TX_MAIN_PAUSE_on; + tx_pause(); + next_callback=remote_callback()<<1; + TX_MAIN_PAUSE_off; + tx_resume(); + cli(); // Disable global int due to RW of 16 bits registers + OCR1A+=next_callback; // Calc when next_callback should happen + #ifndef STM32_BOARD + TIFR1=OCF1A_bm; // Clear compare A=callback flag + #else + TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC1IF; // Clear Timer2/Comp1 interrupt flag + #endif + diff=OCR1A-TCNT1; // Calc the time difference + sei(); // Enable global int + if((diff&0x8000) && !(next_callback&0x8000)) + { // Negative result=callback should already have been called... cli(); // Disable global int due to RW of 16 bits registers - OCR1A+= next_callback ; // set compare A for callback - #ifndef STM32_BOARD - TIFR1=OCF1A_bm; // clear compare A=callback flag - #else - TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC1IF; // Clear Timer2/Comp1 interrupt flag - #endif - diff=OCR1A-TCNT1; // compare timer and comparator - sei(); // enable global int + OCR1A=TCNT1; // Use "now" as new sync point. + sei(); // Enable global int + debugln("Short CB:%d",next_callback); } - while(diff&0x8000); // Callback did not took more than requested time for next callback - // so we can launch Update_All before next callback + else + { + if(IS_RX_FLAG_on || IS_PPM_FLAG_on) + { // Serial or PPM is waiting... + if(++count>10) + { //The protocol does not leave engough time for an update so forcing it + count=0; + debugln("Force update"); + Update_All(); + } + } + #ifndef STM32_BOARD + while((TIFR1 & OCF1A_bm) == 0) + #else + while((TIMER2_BASE->SR & TIMER_SR_CC1IF )==0) + #endif + { + if(diff>900*2) + { //If at least 1ms is available update values + count=0; + Update_All(); + #if defined(STM32_BOARD) && defined(DEBUG_SERIAL) + if(TIMER2_BASE->SR & TIMER_SR_CC1IF ) + debugln("Long update"); + #endif + if(remote_callback==0) + break; + cli(); // Disable global int due to RW of 16 bits registers + diff=OCR1A-TCNT1; // Calc the time difference + sei(); // Enable global int + } + } + } } } -uint8_t Update_All() +bool Update_All() { #ifdef ENABLE_SERIAL #ifdef CHECK_FOR_BOOTLOADER @@ -718,9 +706,9 @@ uint8_t Update_All() if(IS_CHANGE_PROTOCOL_FLAG_on) { // Protocol needs to be changed or relaunched for bind protocol_init(); //init new protocol - return 1; + return true; } - return 0; + return false; } #if defined(FAILSAFE_ENABLE) && defined(ENABLE_PPM) @@ -778,7 +766,10 @@ static void update_led_status(void) { if(IS_INPUT_SIGNAL_on) if(millis()-last_signal>70) + { INPUT_SIGNAL_off; //no valid signal (PPM or Serial) received for 70ms + debugln("No input signal"); + } if(blink=RXBUFFER_SIZE) { - discard_frame=1; // Too many bytes being received... + discard_frame=true; // Too many bytes being received... debugln("RX frame too long"); } else @@ -2127,10 +2118,10 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { rx_idx=UDR0; // Dummy read rx_idx=0; - discard_frame=1; // Error encountered discard full frame... + discard_frame=true; // Error encountered discard full frame... debugln("Bad frame RX"); } - if(discard_frame==1) + if(discard_frame==true) { #ifdef STM32_BOARD TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt @@ -2157,7 +2148,6 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { // Timer1 compare B interrupt if(rx_idx>=26 && rx_idxDIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt + TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag #else CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match TX_RX_PAUSE_off; diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 8d11a93..9f78485 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -99,7 +99,7 @@ inline void telemetry_set_input_sync(uint16_t refreshRate) inputDelay=TIMER2_BASE->CNT; #else cli(); // Disable global int due to RW of 16 bits registers - inputDelay = TCNT1; // Next byte should show up within 15us=1.5 byte + inputDelay = TCNT1; sei(); // Enable global int #endif inputDelay = (inputDelay - last_serial_input)>>1; @@ -824,7 +824,7 @@ void TelemetryUpdate() t -= h ; if ( t < 32 ) { - debugln("TEL_BUF_FULL"); +// debugln("TEL_BUF_FULL"); return ; } #endif @@ -1055,7 +1055,7 @@ void TelemetryUpdate() } if (tx_tail == tx_head) { - tx_pause(); // Check if all data is transmitted . if yes disable transmitter UDRE interrupt + tx_pause(); // Check if all data is transmitted. If yes disable transmitter UDRE interrupt. } #ifdef STM32_BOARD } diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 443a384..2599670 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -225,6 +225,7 @@ //FrSkyX specific setting //----------------------- //EU LBT setting: if commented the TX will not check if a channel is busy before transmitting. +//!!!Work in progress!!! it's currently known to cause telemerty issues. Enable only if you know what you are doing. //#define FRSKYX_LBT //DSM specific settings @@ -281,9 +282,8 @@ #define MULTI_TELEMETRY //Send to OpenTX the current protocol and subprotocol names. Comment to disable. #define MULTI_NAMES -//Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Uncomment to enable. -//!!!Work in progress!!! it's currently known to cause issues. Enable only if you know what you are doing. -//#define MULTI_SYNC +//Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. +#define MULTI_SYNC //Comment a line to disable a specific protocol telemetry #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, erskyTX and OpenTX From 5cf2bf2cf5007d9fa997d64b40fb3ede94317f45 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Fri, 1 Nov 2019 15:11:31 +0100 Subject: [PATCH 43/65] Small tweaks --- Multiprotocol/FrSkyX_cc2500.ino | 27 ++++++++++++++------------- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 8 +++++--- Multiprotocol/Telemetry.ino | 2 +- Multiprotocol/_Config.h | 5 +++-- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index c79d8b1..37fe92f 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -132,7 +132,7 @@ static void __attribute__((unused)) FrSkyX_build_packet() failsafe_chan = 0; } else if (FS_flag & 0x10 && failsafe_chan < (sub_protocol & 0x01 ? 8-1:16-1)) { - FS_flag = 0x10 | ((FS_flag + 2) & 0x0F); //10, 12, 14, 16, 18, 1A, 1C, 1E - failsafe packet + FS_flag = 0x10 | ((FS_flag + 2) & 0x0F); //10, 12, 14, 16, 18, 1A, 1C, 1E - failsafe packet failsafe_chan ++; } else if (FS_flag & 0x10) { @@ -142,7 +142,7 @@ static void __attribute__((unused)) FrSkyX_build_packet() failsafe_count++; #endif - packet[0] = (sub_protocol & 0x02 ) ? 0x20 : 0x1D ; // LBT or FCC + packet[0] = (sub_protocol & 0x02 ) ? 0x20 : 0x1D ; // LBT or FCC packet[1] = rx_tx_addr[3]; packet[2] = rx_tx_addr[2]; packet[3] = 0x02; @@ -179,11 +179,11 @@ static void __attribute__((unused)) FrSkyX_build_packet() chan_1 = FrSkyX_scaleForPXX(startChan); startChan++; // - packet[9+i] = lowByte(chan_0); //3 bytes*4 + packet[9+i] = lowByte(chan_0); //3 bytes*4 packet[9+i+1]=(((chan_0>>8) & 0x0F)|(chan_1 << 4)); packet[9+i+2]=chan_1>>4; } - if(sub_protocol & 0x01 ) // in X8 mode send only 8ch every 9ms + if(sub_protocol & 0x01 ) //In X8 mode send only 8ch every 9ms chan_offset = 0 ; else chan_offset^=0x08; @@ -192,7 +192,7 @@ static void __attribute__((unused)) FrSkyX_build_packet() uint8_t limit = (sub_protocol & 2 ) ? 31 : 28 ; for (uint8_t i=22;i100) {//~1sec - FrSkyX_TX_Seq = 0x08 ; // Request init - FrSkyX_TX_IN_Seq = 0xFF ; // No sequence received yet + FrSkyX_TX_Seq = 0x08 ; //Request init + FrSkyX_TX_IN_Seq = 0xFF ; //No sequence received yet #ifdef SPORT_SEND for(uint8_t i=0;i<4;i++) - FrSkyX_TX_Frames[i].count=0; // discard frames in current output buffer + FrSkyX_TX_Frames[i].count=0; //Discard frames in current output buffer #endif packet_count=0; #if defined TELEMETRY telemetry_lost=1; #endif } - CC2500_Strobe(CC2500_SFRX); //flush the RXFIFO + CC2500_Strobe(CC2500_SFRX); //Flush the RXFIFO } FrSkyX_build_packet(); state = FRSKY_DATA1; diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 20239a2..f51a3b0 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 27 +#define VERSION_PATCH_LEVEL 28 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 5de4cc7..3299615 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -609,7 +609,7 @@ void loop() { //If at least 1ms is available update values count=0; Update_All(); - #if defined(STM32_BOARD) && defined(DEBUG_SERIAL) + #ifdef DEBUG_SERIAL if(TIMER2_BASE->SR & TIMER_SR_CC1IF ) debugln("Long update"); #endif @@ -2161,8 +2161,10 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) else RX_MISSED_BUFF_on; // Notify that rx_buff is good } - else - debugln("RX frame too short"); + #ifdef DEBUG_SERIAL + else + debugln("RX frame too short"); + #endif discard_frame=true; #ifdef STM32_BOARD TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 9f78485..cec1f52 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -80,7 +80,7 @@ static void multi_send_header(uint8_t type, uint8_t len) Serial_write(len); } -inline void telemetry_set_input_sync(uint16_t refreshRate) +static void telemetry_set_input_sync(uint16_t refreshRate) { #ifdef MULTI_SYNC #if defined(STM32_BOARD) && defined(DEBUG_PIN) diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 2599670..0af782c 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -225,7 +225,7 @@ //FrSkyX specific setting //----------------------- //EU LBT setting: if commented the TX will not check if a channel is busy before transmitting. -//!!!Work in progress!!! it's currently known to cause telemerty issues. Enable only if you know what you are doing. +//!!! Work in progress !!! it's currently known to cause telemerty issues. Enable only if you know what you are doing. //#define FRSKYX_LBT //DSM specific settings @@ -283,7 +283,8 @@ //Send to OpenTX the current protocol and subprotocol names. Comment to disable. #define MULTI_NAMES //Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. -#define MULTI_SYNC +//!!! Work in progress !!! Do not enable for internal module +//#define MULTI_SYNC //Comment a line to disable a specific protocol telemetry #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, erskyTX and OpenTX From 815cf4fd9959fa567f689beb8c2c0b77dce64272 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Fri, 1 Nov 2019 18:42:45 +0100 Subject: [PATCH 44/65] FrSky X telemetry quick fix --- Multiprotocol/FrSkyX_cc2500.ino | 4 ++++ Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Telemetry.ino | 8 ++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index 37fe92f..fac223e 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -304,6 +304,9 @@ uint16_t ReadFrSkyX() break; case FRSKY_DATA5: telemetry_set_input_sync(9000); + #if defined TELEMETRY + telemetry_link=1; //Send telemetry out anyway + #endif len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F; if (len && (len<=(0x0E + 3))) //Telemetry frame is 17 { @@ -329,6 +332,7 @@ uint16_t ReadFrSkyX() packet_count=0; #if defined TELEMETRY telemetry_lost=1; + telemetry_link=0; //Stop sending telemetry #endif } CC2500_Strobe(CC2500_SFRX); //Flush the RXFIFO diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index f51a3b0..a26627b 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 28 +#define VERSION_PATCH_LEVEL 29 //****************** // Protocols diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index cec1f52..1813fe2 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -824,9 +824,13 @@ void TelemetryUpdate() t -= h ; if ( t < 32 ) { -// debugln("TEL_BUF_FULL"); + //debugln("TEL_BUF_FULL %d",t); return ; } +/* else + if(t!=96) + debugln("TEL_BUF %d",t); +*/ #endif #if defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) uint32_t now = millis(); @@ -847,7 +851,7 @@ void TelemetryUpdate() #endif #endif #if defined SPORT_TELEMETRY - if (protocol==PROTO_FRSKYX + if (protocol==PROTO_FRSKYX && telemetry_link #ifdef TELEMETRY_FRSKYX_TO_FRSKYD && mode_select==MODE_SERIAL #endif From e6e4d338475057347982dbdaf74c55c5b3495f20 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sat, 2 Nov 2019 18:13:47 +0100 Subject: [PATCH 45/65] Few changes... --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 13 ++++++++----- Multiprotocol/Telemetry.ino | 23 +++++++++++------------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index a26627b..73be31d 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 29 +#define VERSION_PATCH_LEVEL 30 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 3299615..c3a51da 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -184,7 +184,6 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets #endif #define INVERT_SERIAL 1 #endif - uint8_t pass = 0; uint8_t telemetry_in_buffer[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets #ifdef BASH_SERIAL // For bit-bashed serial output @@ -583,11 +582,11 @@ void loop() sei(); // Enable global int if((diff&0x8000) && !(next_callback&0x8000)) { // Negative result=callback should already have been called... - cli(); // Disable global int due to RW of 16 bits registers + debugln("Short CB:%d",next_callback); +/* cli(); // Disable global int due to RW of 16 bits registers OCR1A=TCNT1; // Use "now" as new sync point. sei(); // Enable global int - debugln("Short CB:%d",next_callback); - } +*/ } else { if(IS_RX_FLAG_on || IS_PPM_FLAG_on) @@ -607,6 +606,11 @@ void loop() { if(diff>900*2) { //If at least 1ms is available update values + if((diff&0x8000) && !(next_callback&0x8000)) + {//should never be here + debugln("Strange"); + break; + } count=0; Update_All(); #ifdef DEBUG_SERIAL @@ -952,7 +956,6 @@ static void protocol_init() multi_protocols_index = 0xFF; #endif tx_pause(); - pass=0; init_frskyd_link_telemetry(); #ifdef BASH_SERIAL TIMSK0 = 0 ; // Stop all timer 0 interrupts diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 1813fe2..c4939bb 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -31,13 +31,10 @@ uint8_t RetrySequence ; #endif // MULTI_TELEMETRY/MULTI_STATUS #if defined SPORT_TELEMETRY - #define SPORT_TIME 12000 //12ms #define FRSKY_SPORT_PACKET_SIZE 8 #define FX_BUFFERS 4 - uint32_t last = 0; - uint8_t sport_counter=0; uint8_t RxBt = 0; - uint8_t sport = 0; + uint8_t Sport_Data = 0; uint8_t pktx1[FRSKY_SPORT_PACKET_SIZE*FX_BUFFERS]; // Store for out of sequence packet @@ -64,7 +61,6 @@ uint8_t RetrySequence ; #define STUFF_MASK 0x20 #define MAX_PKTX 10 uint8_t pktx[MAX_PKTX]; -uint8_t indx; uint8_t frame[18]; #if ( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) @@ -688,7 +684,9 @@ void sportIdle() void sportSendFrame() { + static uint8_t sport_counter=0; uint8_t i; + sport_counter = (sport_counter + 1) %36; if(telemetry_lost) { @@ -725,14 +723,14 @@ void sportSendFrame() frame[4] = RxBt;//a1; break; default: - if(sport) + if(Sport_Data) { for (i=0;i= FRSKY_SPORT_PACKET_SIZE) {//8 bytes no crc - if ( sport < FX_BUFFERS ) + if ( Sport_Data < FX_BUFFERS ) { - uint8_t dest = sport * FRSKY_SPORT_PACKET_SIZE ; + uint8_t dest = Sport_Data * FRSKY_SPORT_PACKET_SIZE ; uint8_t i ; for ( i = 0 ; i < FRSKY_SPORT_PACKET_SIZE ; i++ ) pktx1[dest++] = pktx[i] ; // Triple buffer - sport += 1 ;//ok to send + Sport_Data += 1 ;//ok to send } // else // { From ca15d7108f5bfe63b6dd272067f579cb29cbdbd1 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sat, 2 Nov 2019 20:51:41 +0100 Subject: [PATCH 46/65] Prep for HoTT protocol and fix STM32 seed --- Multiprotocol/Multi.txt | 1 + Multiprotocol/Multi_Names.ino | 6 +++++- Multiprotocol/Multiprotocol.h | 4 +++- Multiprotocol/Multiprotocol.ino | 26 +++++++++++++++++++++++--- Multiprotocol/Validate.h | 6 ++++++ Multiprotocol/_Config.h | 13 ++++++++----- 6 files changed, 46 insertions(+), 10 deletions(-) diff --git a/Multiprotocol/Multi.txt b/Multiprotocol/Multi.txt index 06ee328..f99ea1c 100644 --- a/Multiprotocol/Multi.txt +++ b/Multiprotocol/Multi.txt @@ -54,4 +54,5 @@ 54,Scanner 55,Frsky_RX 56,AFHDS2A_RX +57,HoTT 63,XN_DUMP,250K,1M,2M diff --git a/Multiprotocol/Multi_Names.ino b/Multiprotocol/Multi_Names.ino index 8c73f7d..e7c84f9 100644 --- a/Multiprotocol/Multi_Names.ino +++ b/Multiprotocol/Multi_Names.ino @@ -70,6 +70,7 @@ const char STR_FLYZONE[] ="FlyZone"; const char STR_SCANNER[] ="Scanner"; const char STR_FRSKY_RX[] ="FrSkyRX"; const char STR_AFHDS2A_RX[] ="FS2A_RX"; +const char STR_HOTT[] ="HoTT"; const char STR_XN297DUMP[] ="XN297DP"; const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20"; @@ -122,7 +123,7 @@ enum #define NO_SUBTYPE nullptr const mm_protocol_definition multi_protocols[] = { -// Protocol as defined in pulses\modules_constants.h, number of sub_protocols - 1, Failsafe supported, Disable channel mapping supported, Subtype string, Option type +// Protocol number, Protocol String, Number of sub_protocols, Sub_protocol strings, Option type #if defined(FLYSKY_A7105_INO) {PROTO_FLYSKY, STR_FLYSKY, 5, STR_SUBTYPE_FLYSKY, OPTION_NONE }, #endif @@ -288,6 +289,9 @@ const mm_protocol_definition multi_protocols[] = { #if defined(AFHDS2A_RX_A7105_INO) {PROTO_AFHDS2A_RX, STR_AFHDS2A_RX,0, NO_SUBTYPE, OPTION_NONE }, #endif +#if defined(HOTT_CC2500_INO) + {PROTO_HOTT, STR_HOTT, 0, NO_SUBTYPE, OPTION_RFTUNE }, +#endif #if defined(XN297DUMP_NRF24L01_INO) {PROTO_XN297DUMP, STR_XN297DUMP, 3, STR_SUBTYPE_XN297DUMP, OPTION_NONE }, #endif diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 73be31d..af9c204 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 30 +#define VERSION_PATCH_LEVEL 31 //****************** // Protocols @@ -83,6 +83,7 @@ enum PROTOCOLS PROTO_SCANNER = 54, // =>CC2500 PROTO_FRSKY_RX = 55, // =>CC2500 PROTO_AFHDS2A_RX= 56, // =>A7105 + PROTO_HOTT = 57, // =>CC2500 PROTO_XN297DUMP = 63, // =>NRF24L01 }; @@ -667,6 +668,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- SCANNER 54 FRSKY_RX 55 AFHDS2A_RX 56 + HOTT 57 BindBit=> 0x80 1=Bind/0=No AutoBindBit=> 0x40 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index c3a51da..3dcb562 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -319,7 +319,6 @@ void setup() pinMode(S4_pin,INPUT_PULLUP); //Random pins pinMode(PB0, INPUT_ANALOG); // set up pin for analog input - pinMode(PB1, INPUT_ANALOG); // set up pin for analog input //Timers init_HWTimer(); //0.5us @@ -437,10 +436,13 @@ void setup() modules_reset(); #ifndef ORANGE_TX - //Init the seed with a random value created from watchdog timer for all protocols requiring random values #ifdef STM32_BOARD - randomSeed((uint32_t)analogRead(PB0) << 10 | analogRead(PB1)); + uint32_t seed=0; + for(uint8_t i=0;i<4;i++) + seed=(seed<<8) | (analogRead(PB0)& 0xFF); + randomSeed(seed); #else + //Init the seed with a random value created from watchdog timer for all protocols requiring random values randomSeed(random_value()); #endif #endif @@ -501,6 +503,11 @@ void setup() if (protocol==PROTO_HITEC) option = FORCE_HITEC_TUNING; // Use config-defined tuning value for HITEC else + #endif + #if defined(FORCE_HOTT_TUNING) && defined(HOTT_CC2500_INO) + if (protocol==PROTO_HOTT) + option = FORCE_HOTT_TUNING; // Use config-defined tuning value for HOTT + else #endif option = (uint8_t)PPM_prot_line->option; // Use radio-defined option value @@ -1098,6 +1105,14 @@ static void protocol_init() remote_callback = ReadHITEC; break; #endif + #if defined(HOTT_CC2500_INO) + case PROTO_HOTT: + PE1_off; //antenna RF2 + PE2_on; + next_callback = initHOTT(); + remote_callback = ReadHOTT; + break; + #endif #if defined(SCANNER_CC2500_INO) case PROTO_SCANNER: PE1_off; @@ -1528,6 +1543,11 @@ void update_serial_data() if (protocol==PROTO_HITEC) option=FORCE_HITEC_TUNING; // Use config-defined tuning value for HITEC else + #endif + #if defined(FORCE_HOTT_TUNING) && defined(HOTT_CC2500_INO) + if (protocol==PROTO_HOTT) + option=FORCE_HOTT_TUNING; // Use config-defined tuning value for HOTT + else #endif option=rx_ok_buff[3]; // Use radio-defined option value diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index febca8b..c240c9a 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -104,6 +104,11 @@ #error "The SFHSS forced frequency tuning value is outside of the range -127..127." #endif #endif +#ifdef FORCE_HOTT_TUNING + #if ( FORCE_HOTT_TUNING < -127 ) || ( FORCE_HOTT_TUNING > 127 ) + #error "The HOTT forced frequency tuning value is outside of the range -127..127." + #endif +#endif //A7105 #ifdef FORCE_AFHDS2A_TUNING #if ( FORCE_AFHDS2A_TUNING < -300 ) || ( FORCE_AFHDS2A_TUNING > 300 ) @@ -195,6 +200,7 @@ #undef XN297L_CC2500_EMU #undef SCANNER_CC2500_INO #undef FRSKY_RX_CC2500_INO + #undef HOTT_CC2500_INO #endif #ifndef NRF24L01_INSTALLED #undef BAYANG_NRF24L01_INO diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 0af782c..305eba6 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -87,17 +87,18 @@ //#define ORANGE_TX_BLUE /** CC2500 Fine Frequency Tuning **/ -//For optimal performance the CC2500 RF module used by the FrSkyD, FrSkyV, FrSkyX, SFHSS, CORONA, Redpine and Hitec protocols needs to be tuned for each protocol. -//Initial tuning should be done via the radio menu with a genuine FrSky/Futaba/CORONA/Hitec/Redpine receiver. +//For optimal performance the CC2500 RF module used by the CORONA, FrSkyD, FrSkyV, FrSkyX, Hitec, HoTT, SFHSS and Redpine protocols needs to be tuned for each protocol. +//Initial tuning should be done via the radio menu with a genuine CORONA/FrSky/Hitec/HoTT/Futaba/Redpine receiver. //Once a good tuning value is found it can be set here and will override the radio's 'option' setting for all existing and new models which use that protocol. //For more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/tree/master/docs/Frequency_Tuning.md //Uncomment the lines below (remove the "//") and set an appropriate value (replace the "0") to enable. Valid range is -127 to +127. +//#define FORCE_CORONA_TUNING 0 //#define FORCE_FRSKYD_TUNING 0 //#define FORCE_FRSKYV_TUNING 0 //#define FORCE_FRSKYX_TUNING 0 //#define FORCE_SFHSS_TUNING 0 -//#define FORCE_CORONA_TUNING 0 //#define FORCE_HITEC_TUNING 0 +//#define FORCE_HOTT_TUNING 0 //#define FORCE_REDPINE_TUNING 0 /** A7105 Fine Frequency Tuning **/ @@ -178,6 +179,7 @@ #define FRSKYX_CC2500_INO #define FRSKY_RX_CC2500_INO #define HITEC_CC2500_INO +//#define HOTT_CC2500_INO #define SCANNER_CC2500_INO #define SFHSS_CC2500_INO #define REDPINE_CC2500_INO @@ -283,8 +285,7 @@ //Send to OpenTX the current protocol and subprotocol names. Comment to disable. #define MULTI_NAMES //Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. -//!!! Work in progress !!! Do not enable for internal module -//#define MULTI_SYNC +#define MULTI_SYNC //Comment a line to disable a specific protocol telemetry #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, erskyTX and OpenTX @@ -588,6 +589,8 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= { JJRCX1 X5C1 FQ777_951 + PROTO_HOTT + NONE PROTO_HUBSAN H107 H301 From 19b931223b6da3bd3c71e2dc96a418868f4783e8 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 3 Nov 2019 15:46:05 +0100 Subject: [PATCH 47/65] Changed serial timer source --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 53 +++++++++++++++++++-------------- Multiprotocol/Telemetry.ino | 26 ++++++++-------- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index af9c204..521f7d2 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 31 +#define VERSION_PATCH_LEVEL 32 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 3dcb562..b73cbe2 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -55,6 +55,7 @@ #include #include HardwareTimer HWTimer2(2); + HardwareTimer HWTimer3(3); void PPM_decode(); void ISR_COMPB(); @@ -174,8 +175,8 @@ volatile uint8_t rx_idx=0, rx_len=0; uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets #if defined(TELEMETRY) #ifdef MULTI_SYNC - uint32_t last_serial_input=0; - uint16_t inputRefreshRate = 7000; + uint16_t last_serial_input=0; + uint16_t inputRefreshRate=0; #endif #ifdef INVERT_TELEMETRY #if not defined(ORANGE_TX) && not defined(STM32_BOARD) @@ -590,16 +591,13 @@ void loop() if((diff&0x8000) && !(next_callback&0x8000)) { // Negative result=callback should already have been called... debugln("Short CB:%d",next_callback); -/* cli(); // Disable global int due to RW of 16 bits registers - OCR1A=TCNT1; // Use "now" as new sync point. - sei(); // Enable global int -*/ } + } else { if(IS_RX_FLAG_on || IS_PPM_FLAG_on) { // Serial or PPM is waiting... if(++count>10) - { //The protocol does not leave engough time for an update so forcing it + { //The protocol does not leave enough time for an update so forcing it count=0; debugln("Force update"); Update_All(); @@ -614,8 +612,8 @@ void loop() if(diff>900*2) { //If at least 1ms is available update values if((diff&0x8000) && !(next_callback&0x8000)) - {//should never be here - debugln("Strange"); + {//Should never get here but it is... + debugln("!!!BUG!!!"); break; } count=0; @@ -957,7 +955,7 @@ static void protocol_init() // reset telemetry #ifdef TELEMETRY #ifdef MULTI_SYNC - inputRefreshRate = 7000; // Default value + inputRefreshRate = 0; // Don't do it unless the protocol asks for it #endif #ifdef MULTI_NAMES multi_protocols_index = 0xFF; @@ -1863,14 +1861,24 @@ void modules_reset() TIMER2_BASE->ARR = 0xFFFF; // Count until 0xFFFF HWTimer2.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE); // Main scheduler - HWTimer2.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE); // Serial check + //HWTimer2.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE); // Serial check TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag - HWTimer2.attachInterrupt(TIMER_CH2,ISR_COMPB); // Assign function to Timer2/Comp2 interrupt + //HWTimer2.attachInterrupt(TIMER_CH2,ISR_COMPB); // Assign function to Timer2/Comp2 interrupt TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt HWTimer2.refresh(); // Refresh the timer's count, prescale, and overflow HWTimer2.resume(); + + HWTimer3.pause(); // Pause the timer3 while we're configuring it + TIMER3_BASE->PSC = 35; // 36-1;for 72 MHZ /0.5sec/(35+1) + TIMER3_BASE->ARR = 0xFFFF; // Count until 0xFFFF + HWTimer3.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE); // Serial check + TIMER3_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer3/Comp2 interrupt flag + HWTimer3.attachInterrupt(TIMER_CH2,ISR_COMPB); // Assign function to Timer3/Comp2 interrupt + TIMER3_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer3/Comp2 interrupt + HWTimer3.refresh(); // Refresh the timer's count, prescale, and overflow + HWTimer3.resume(); } #endif @@ -2102,9 +2110,9 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) #endif { #if defined STM32_BOARD - TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 500; // Next byte should show up within 250us (1 byte = 120us) - TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag - TIMER2_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer2/Comp2 interrupt + TIMER3_BASE->CCR2=TIMER3_BASE->CNT + 500; // Next byte should show up within 250us (1 byte = 120us) + TIMER3_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer3/Comp2 interrupt flag + TIMER3_BASE->DIER |= TIMER_DIER_CC2IE; // Enable Timer3/Comp2 interrupt #else TX_RX_PAUSE_on; tx_pause(); @@ -2128,7 +2136,7 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { rx_buff[rx_idx++]=UDR0; // Store received byte #if defined STM32_BOARD - TIMER2_BASE->CCR2=TIMER2_BASE->CNT + 500; // Next byte should show up within 250us (1 byte = 120us) + TIMER3_BASE->CCR2=TIMER3_BASE->CNT + 500; // Next byte should show up within 250us (1 byte = 120us) #else cli(); // Disable global int due to RW of 16 bits registers OCR1B = TCNT1 + 500; // Next byte should show up within 250us (1 byte = 120us) @@ -2147,7 +2155,7 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) if(discard_frame==true) { #ifdef STM32_BOARD - TIMER2_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt + TIMER3_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer3/Comp2 interrupt #else CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match TX_RX_PAUSE_off; @@ -2171,9 +2179,6 @@ static uint32_t random_id(uint16_t address, uint8_t create_new) { // Timer1 compare B interrupt if(rx_idx>=26 && rx_idxDIER &= ~TIMER_DIER_CC2IE; // Disable Timer2/Comp2 interrupt - TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC2IF; // Clear Timer2/Comp2 interrupt flag + TIMER3_BASE->DIER &= ~TIMER_DIER_CC2IE; // Disable Timer3/Comp2 interrupt #else CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match TX_RX_PAUSE_off; diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index c4939bb..7104777 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -91,16 +91,14 @@ static void telemetry_set_input_sync(uint16_t refreshRate) inputRefreshRate = refreshRate; if (last_serial_input != 0) { - #if defined STM32_BOARD - inputDelay=TIMER2_BASE->CNT; - #else - cli(); // Disable global int due to RW of 16 bits registers - inputDelay = TCNT1; - sei(); // Enable global int - #endif - inputDelay = (inputDelay - last_serial_input)>>1; - if(inputDelay > 0x8000) - inputDelay =inputDelay - 0x8000; + cli(); // Disable global int due to RW of 16 bits registers + inputDelay = TCNT1; + sei(); // Enable global int + //inputDelay = (inputDelay - last_serial_input)>>1; + inputDelay -= last_serial_input; + //if(inputDelay & 0x8000) + // inputDelay = inputDelay - 0x8000; + debugln("D=%d",inputDelay); last_serial_input=0; } #else @@ -114,8 +112,10 @@ static void telemetry_set_input_sync(uint16_t refreshRate) multi_send_header(MULTI_TELEMETRY_SYNC, 6); Serial_write(inputRefreshRate >> 8); Serial_write(inputRefreshRate & 0xff); - Serial_write(inputDelay >> 8); - Serial_write(inputDelay & 0xff); +// Serial_write(inputDelay >> 8); +// Serial_write(inputDelay & 0xff); + Serial_write(inputDelay >> 9); + Serial_write(inputDelay >> 1); Serial_write(INPUT_SYNC_TIME); Serial_write(INPUT_ADDITIONAL_DELAY); } @@ -841,7 +841,7 @@ void TelemetryUpdate() return; } #ifdef MULTI_SYNC - if ( (now - lastInputSync) > INPUT_SYNC_TIME && protocol != PROTO_SCANNER && protocol != PROTO_FRSKY_RX && protocol != PROTO_AFHDS2A_RX && protocol != PROTO_XN297DUMP ) + if ( inputRefreshRate && (now - lastInputSync) > INPUT_SYNC_TIME ) { mult_send_inputsync(); lastInputSync = now; From 6ef2934c1881aebcafc24698f383763690fab0c3 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 3 Nov 2019 15:48:14 +0100 Subject: [PATCH 48/65] Update Telemetry.ino --- Multiprotocol/Telemetry.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 7104777..7ea2f86 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -98,7 +98,6 @@ static void telemetry_set_input_sync(uint16_t refreshRate) inputDelay -= last_serial_input; //if(inputDelay & 0x8000) // inputDelay = inputDelay - 0x8000; - debugln("D=%d",inputDelay); last_serial_input=0; } #else From 7b281e47d643762564819a1441aa4d0f7645e01e Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 4 Nov 2019 09:26:12 +0100 Subject: [PATCH 49/65] HoTT work in progress --- Multiprotocol/HOTT_cc2500.ino | 214 ++++++++++++++++++++++++++++++++ Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 4 +- 3 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 Multiprotocol/HOTT_cc2500.ino diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino new file mode 100644 index 0000000..e171e4b --- /dev/null +++ b/Multiprotocol/HOTT_cc2500.ino @@ -0,0 +1,214 @@ +/* + This project is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Multiprotocol is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Multiprotocol. If not, see . + */ + +#if defined(HOTT_CC2500_INO) + +#include "iface_cc2500.h" + +#define HOTT_COARSE 0 +#define HOTT_TX_PACKET_LEN 50 +#define HOTT_RX_PACKET_LEN 22 +#define HOTT_PACKET_PERIOD 10000 + +enum { + HOTT_START = 0x00, + HOTT_CAL = 0x01, + HOTT_DATA1 = 0x02, + HOTT_RX1 = 0x03, + HOTT_RX2 = 0x04, +}; + +#define HOTT_FREQ0_VAL 0x6E + +// Some important initialization parameters, all others are either default, +// or not important in the context of transmitter +// FIFOTHR 00 +// SYNC1 D3 +// SYNC0 91 +// PKTLEN 32 - Packet length, 50 bytes +// PKTCTRL1 04 - APPEND_STATUS on=RSSI+LQI, all other are receive parameters - irrelevant +// PKTCTRL0 44 - whitening, use FIFO, use CRC, fixed packet length +// ADDR 00 +// CHANNR 10 +// FSCTRL1 09 - IF +// FSCTRL0 00 - zero freq offset +// FREQ2 5C - synthesizer frequencyfor 26MHz crystal +// FREQ1 6C +// FREQ0 B9 +// MDMCFG4 2D - +// MDMCFG3 3B - +// MDMCFG2 73 - disable DC blocking, MSK, no Manchester code, 32 bits sync word +// MDMCFG1 A3 - FEC enable, 4 preamble bytes, CHANSPC_E - 03 +// MDMCFG0 AA - CHANSPC_M - AA +// DEVIATN 47 - +// MCSM2 07 - +// MCSM1 00 - always use CCA, go to IDLE when done +// MCSM0 08 - disable autocalibration, PO_TIMEOUT - 64, no pin radio control, no forcing XTAL to stay in SLEEP +// FOCCFG 1D +const PROGMEM uint8_t HOTT_init_values[] = { + /* 00 */ 0x2F, 0x2E, 0x2F, 0x00, 0xD3, 0x91, 0x32, 0x04, + /* 08 */ 0x44, 0x00, 0x00, 0x09, 0x00, 0x5C, 0x6C, HOTT_FREQ0_VAL + HOTT_COARSE, + /* 10 */ 0x2D, 0x3B, 0x73, 0xA3, 0xAA, 0x47, 0x07, 0x00, //original 0x17=0 + /* 18 */ 0x08, 0x1D, 0x1C, 0xC7, 0x09, 0xF0, 0x87, 0x6B, + /* 20 */ 0xF0, 0xB6, 0x10, 0xEA, 0x0A, 0x00, 0x11 +}; + +static void __attribute__((unused)) HOTT_rf_init() +{ + CC2500_Strobe(CC2500_SIDLE); + + for (uint8_t i = 0; i < 39; ++i) + CC2500_WriteReg(i, pgm_read_byte_near(&HOTT_init_values[i])); + + prev_option = option; + CC2500_WriteReg(CC2500_0C_FSCTRL0, option); + + CC2500_SetTxRxMode(TX_EN); + CC2500_SetPower(); +} + +static void __attribute__((unused)) HOTT_tune_chan() +{ + CC2500_Strobe(CC2500_SIDLE); + CC2500_WriteReg(CC2500_0A_CHANNR, (rf_ch_num+1)*3); + CC2500_Strobe(CC2500_SCAL); +} + +static void __attribute__((unused)) HOTT_tune_chan_fast() +{ + CC2500_Strobe(CC2500_SIDLE); + CC2500_WriteReg(CC2500_0A_CHANNR, (rf_ch_num+1)*3); + CC2500_WriteReg(CC2500_25_FSCAL1, calData[rf_ch_num]); +} + +static void __attribute__((unused)) HOTT_tune_freq() +{ + if ( prev_option != option ) + { + CC2500_WriteReg(CC2500_0C_FSCTRL0, option); + CC2500_WriteReg(CC2500_0F_FREQ0, HOTT_FREQ0_VAL + HOTT_COARSE); + prev_option = option ; + phase = HOTT_START; // Restart the tune process if option is changed to get good tuned values + } +} + +uint8_t HOTT_hop[75]= { 48, 37, 16, 62, 9, 50, 42, 22, 68, 0, 55, 35, 21, 74, 1, 56, 31, 20, 70, 11, 45, 32, 24, 71, 8, 54, 38, 26, 61, 13, 53, 30, 15, 65, 7, 52, 34, 28, 60, 3, 47, 39, 18, 69, 2, 49, 44, 23, 72, 5, 51, 43, 19, 64, 12, 46, 33, 17, 67, 6, 58, 36, 29, 73, 14, 57, 41, 25, 63, 4, 59, 40, 27, 66, 10 }; +uint16_t HOTT_hop_val = 0xC06B; + +// Channel values are PPM*2 +static void __attribute__((unused)) HOTT_data_packet() +{ + packet[2] = hopping_frequency_no; + packet[3] = 0x00; // unknown, may be for additional channels + for(uint8_t i=4;i<28;i+=2) + { + uint16_t val=Channel_data[(i-4)>>1]; + val=(((val<<2)+val)>>2)+860*2; //value range 860<->2140 *2 <-> -125%<->+125% + packet[i] = val; + packet[i+1] = val>>8; + } + + packet[28] = 0x8C; // unknown + packet[29] = 0x02; // unknown + + CC2500_SetTxRxMode(TX_EN); + CC2500_SetPower(); + CC2500_WriteReg(CC2500_06_PKTLEN, 0x32); + CC2500_WriteData(packet, HOTT_TX_PACKET_LEN); + #if 0 + debug("P:"); + for(uint8_t i=0;i>8; + memcpy(&packet[30],"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x07\x7C\x94\x00\x0C\x50\x4D\xF2\x00\x00\xB1",20); //unknown +} + +uint16_t initHOTT() +{ + BIND_DONE; // Not a TX bind protocol + HOTT_init(); + + HOTT_rf_init(); + phase = HOTT_START; + return 10000; +} + +#endif \ No newline at end of file diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 521f7d2..1cae8b1 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 32 +#define VERSION_PATCH_LEVEL 33 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index b73cbe2..b7e1ac4 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -73,7 +73,7 @@ uint32_t blink=0,last_signal=0; // uint16_t counter; uint8_t channel; -uint8_t packet[40]; +uint8_t packet[50]; #define NUM_CHN 16 // Servo data @@ -113,6 +113,8 @@ uint8_t num_ch; #ifdef CC2500_INSTALLED #ifdef SCANNER_CC2500_INO uint8_t calData[255]; + #elif defined(HOTT_CC2500_IN0) + uint8_t calData[75]; #else uint8_t calData[50]; #endif From 5856442e0fe45ab23b1600ebb6034f9319ad039c Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 4 Nov 2019 19:16:19 +0100 Subject: [PATCH 50/65] First HoTT version --- Multiprotocol/HOTT_cc2500.ino | 80 +++++++++++++++++++++++++-------- Multiprotocol/Multiprotocol.h | 6 ++- Multiprotocol/Multiprotocol.ino | 2 +- Multiprotocol/_Config.h | 6 +-- 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index e171e4b..6344983 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -107,11 +107,41 @@ static void __attribute__((unused)) HOTT_tune_freq() uint8_t HOTT_hop[75]= { 48, 37, 16, 62, 9, 50, 42, 22, 68, 0, 55, 35, 21, 74, 1, 56, 31, 20, 70, 11, 45, 32, 24, 71, 8, 54, 38, 26, 61, 13, 53, 30, 15, 65, 7, 52, 34, 28, 60, 3, 47, 39, 18, 69, 2, 49, 44, 23, 72, 5, 51, 43, 19, 64, 12, 46, 33, 17, 67, 6, 58, 36, 29, 73, 14, 57, 41, 25, 63, 4, 59, 40, 27, 66, 10 }; uint16_t HOTT_hop_val = 0xC06B; -// Channel values are PPM*2 +static void __attribute__((unused)) HOTT_init() +{ + packet[0] = HOTT_hop_val; + packet[1] = HOTT_hop_val>>8; + #ifdef HOTT_FORCE_ID + memcpy(rx_tx_addr,"\x7C\x94\x00\x0D\x50",5); + #endif + memset(&packet[30],0xFF,9); + packet[39]=0X07; // unknown + if(IS_BIND_IN_PROGRESS) + { + packet[28] = 0x80; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets + packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets + memset(&packet[40],0xFA,5); + memcpy(&packet[45],rx_tx_addr,5); + } + else + { + packet[28] = 0x8C; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets + packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets + memcpy(&packet[40],rx_tx_addr,5); + + uint8_t addr=HOTT_EEPROM_OFFSET+RX_num*5; + for(uint8_t i=0;i<5;i++) + packet[45+i]=eeprom_read_byte((EE_ADDR)(addr+i)); + } +} + static void __attribute__((unused)) HOTT_data_packet() { packet[2] = hopping_frequency_no; - packet[3] = 0x00; // unknown, may be for additional channels + + packet[3] = 0x00; // unknown, may be for additional channels? + + // Channel values are PPM*2 for(uint8_t i=4;i<28;i+=2) { uint16_t val=Channel_data[(i-4)>>1]; @@ -120,9 +150,6 @@ static void __attribute__((unused)) HOTT_data_packet() packet[i+1] = val>>8; } - packet[28] = 0x8C; // unknown - packet[29] = 0x02; // unknown - CC2500_SetTxRxMode(TX_EN); CC2500_SetPower(); CC2500_WriteReg(CC2500_06_PKTLEN, 0x32); @@ -182,10 +209,36 @@ uint16_t ReadHOTT() if (len==HOTT_RX_PACKET_LEN+2) { CC2500_ReadData(packet_in, len); - debug("T:"); - for(uint8_t i=0;i>8; - memcpy(&packet[30],"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x07\x7C\x94\x00\x0C\x50\x4D\xF2\x00\x00\xB1",20); //unknown -} - uint16_t initHOTT() { - BIND_DONE; // Not a TX bind protocol HOTT_init(); - HOTT_rf_init(); phase = HOTT_START; return 10000; diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 1cae8b1..50a7ce8 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 33 +#define VERSION_PATCH_LEVEL 34 //****************** // Protocols @@ -593,7 +593,8 @@ enum { #define FRSKY_RX_EEPROM_OFFSET 178 // (1) format + (3) TX ID + (1) freq_tune + (47) channels, 52 bytes, end is 178+52=230 #define AFHDS2A_RX_EEPROM_OFFSET 230 // (4) TX ID + (16) channels, 20 bytes, end is 230+20=250 #define AFHDS2A_EEPROM_OFFSET2 250 // RX ID, 4 bytes per model id, end is 250+192=442 -//#define CONFIG_EEPROM_OFFSET 442 // Current configuration of the multimodule +#define HOTT_EEPROM_OFFSET 442 // RX ID, 5 bytes per model id, end is 320+442=762 +//#define CONFIG_EEPROM_OFFSET 762 // Current configuration of the multimodule //**************************************** //*** MULTI protocol serial definition *** @@ -910,6 +911,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- OPTION_FIXEDID 4 OPTION_TELEM 5 OPTION_SRVFREQ 6 + OPTION_MAXTHR 7 [19&0x0F] Number of sub protocols [20..27] Sub protocol name [8], not null terminated if sub prototcol len == 8 diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index b7e1ac4..a6de2bf 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -113,7 +113,7 @@ uint8_t num_ch; #ifdef CC2500_INSTALLED #ifdef SCANNER_CC2500_INO uint8_t calData[255]; - #elif defined(HOTT_CC2500_IN0) + #elif defined(HOTT_CC2500_INO) uint8_t calData[75]; #else uint8_t calData[50]; diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 305eba6..cddf437 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -179,7 +179,7 @@ #define FRSKYX_CC2500_INO #define FRSKY_RX_CC2500_INO #define HITEC_CC2500_INO -//#define HOTT_CC2500_INO +#define HOTT_CC2500_INO #define SCANNER_CC2500_INO #define SFHSS_CC2500_INO #define REDPINE_CC2500_INO @@ -275,8 +275,8 @@ //For STM32 and OrangeRX modules, comment to prevent the TX from forcing the serial telemetry polarity normal/invert. #define INVERT_TELEMETRY_TX -//Uncomment if you don't want to send Multi status telemetry frames (Protocol available, Bind in progress, version...) -//Use with er9x/erskyTX, for OpenTX MULTI_TELEMETRY below is preferred instead +//Uncomment if you want to send Multi status telemetry frames (Protocol available, Bind in progress, version...) +//Use with er9x/erskyTX, for OpenTX you must select MULTI_TELEMETRY below //#define MULTI_STATUS //Sends Multi status and allow OpenTX to autodetect the telemetry format. Comment to disable. From 0482627512e2d1cc96b7b200d052e44dc8ecd4b5 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 5 Nov 2019 00:31:20 +0100 Subject: [PATCH 51/65] HoTT telem --- Multiprotocol/HOTT_cc2500.ino | 86 ++++++++++++++++++++++++--------- Multiprotocol/Multiprotocol.h | 9 +++- Multiprotocol/Multiprotocol.ino | 2 +- Multiprotocol/Telemetry.ino | 21 ++++++++ Multiprotocol/Validate.h | 7 ++- Multiprotocol/_Config.h | 3 +- 6 files changed, 100 insertions(+), 28 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index 6344983..77a6741 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -17,10 +17,12 @@ #include "iface_cc2500.h" -#define HOTT_COARSE 0 +//#define HOTT_FORCE_ID // Force ID of original dump + #define HOTT_TX_PACKET_LEN 50 #define HOTT_RX_PACKET_LEN 22 #define HOTT_PACKET_PERIOD 10000 +#define HOTT_COARSE 0 enum { HOTT_START = 0x00, @@ -60,7 +62,7 @@ enum { const PROGMEM uint8_t HOTT_init_values[] = { /* 00 */ 0x2F, 0x2E, 0x2F, 0x00, 0xD3, 0x91, 0x32, 0x04, /* 08 */ 0x44, 0x00, 0x00, 0x09, 0x00, 0x5C, 0x6C, HOTT_FREQ0_VAL + HOTT_COARSE, - /* 10 */ 0x2D, 0x3B, 0x73, 0xA3, 0xAA, 0x47, 0x07, 0x00, //original 0x17=0 + /* 10 */ 0x2D, 0x3B, 0x73, 0xA3, 0xAA, 0x47, 0x07, 0x00, /* 18 */ 0x08, 0x1D, 0x1C, 0xC7, 0x09, 0xF0, 0x87, 0x6B, /* 20 */ 0xF0, 0xB6, 0x10, 0xEA, 0x0A, 0x00, 0x11 }; @@ -104,13 +106,17 @@ static void __attribute__((unused)) HOTT_tune_freq() } } -uint8_t HOTT_hop[75]= { 48, 37, 16, 62, 9, 50, 42, 22, 68, 0, 55, 35, 21, 74, 1, 56, 31, 20, 70, 11, 45, 32, 24, 71, 8, 54, 38, 26, 61, 13, 53, 30, 15, 65, 7, 52, 34, 28, 60, 3, 47, 39, 18, 69, 2, 49, 44, 23, 72, 5, 51, 43, 19, 64, 12, 46, 33, 17, 67, 6, 58, 36, 29, 73, 14, 57, 41, 25, 63, 4, 59, 40, 27, 66, 10 }; -uint16_t HOTT_hop_val = 0xC06B; +const uint8_t HOTT_hop[][75]= { { 48, 37, 16, 62, 9, 50, 42, 22, 68, 0, 55, 35, 21, 74, 1, 56, 31, 20, 70, 11, 45, 32, 24, 71, 8, 54, 38, 26, 61, 13, 53, 30, 15, 65, 7, 52, 34, 28, 60, 3, 47, 39, 18, 69, 2, 49, 44, 23, 72, 5, 51, 43, 19, 64, 12, 46, 33, 17, 67, 6, 58, 36, 29, 73, 14, 57, 41, 25, 63, 4, 59, 40, 27, 66, 10 }, + { 50, 23, 5, 34, 67, 53, 22, 12, 39, 62, 51, 21, 10, 33, 63, 59, 16, 1, 43, 66, 49, 19, 8, 30, 71, 47, 24, 2, 35, 68, 45, 25, 14, 41, 74, 55, 18, 4, 32, 61, 54, 17, 11, 31, 72, 52, 28, 6, 38, 65, 46, 15, 9, 40, 60, 48, 26, 3, 37, 70, 58, 29, 0, 36, 64, 56, 20, 7, 42, 69, 57, 27, 13, 44, 73 }, + { 73, 51, 39, 18, 9, 64, 56, 34, 16, 12, 66, 58, 36, 25, 11, 61, 47, 40, 15, 8, 71, 50, 43, 20, 6, 62, 54, 42, 19, 3, 63, 46, 44, 29, 14, 72, 49, 33, 22, 5, 69, 57, 30, 21, 10, 70, 45, 35, 26, 7, 65, 59, 31, 28, 1, 67, 48, 32, 24, 0, 60, 55, 41, 17, 2, 74, 52, 38, 27, 4, 68, 53, 37, 23, 13 }, + { 52, 60, 40, 21, 14, 50, 72, 41, 23, 13, 59, 61, 39, 16, 6, 58, 66, 33, 17, 5, 55, 64, 43, 20, 12, 54, 74, 35, 29, 3, 46, 63, 37, 22, 10, 48, 65, 31, 27, 9, 49, 73, 38, 24, 11, 56, 70, 32, 15, 1, 51, 71, 44, 18, 8, 45, 67, 36, 25, 7, 57, 62, 34, 28, 2, 53, 69, 42, 19, 4, 47, 68, 30, 26, 0 } + }; +const uint16_t HOTT_hop_val[] = { 0xC06B, 0xC34A, 0xDB24, 0x8E09 }; static void __attribute__((unused)) HOTT_init() { - packet[0] = HOTT_hop_val; - packet[1] = HOTT_hop_val>>8; + packet[0] = HOTT_hop_val[num_ch]; + packet[1] = HOTT_hop_val[num_ch]>>8; #ifdef HOTT_FORCE_ID memcpy(rx_tx_addr,"\x7C\x94\x00\x0D\x50",5); #endif @@ -141,7 +147,7 @@ static void __attribute__((unused)) HOTT_data_packet() packet[3] = 0x00; // unknown, may be for additional channels? - // Channel values are PPM*2 + // Channels value are PPM*2, -100%=1100µs, +100%=1900µs, order TAER for(uint8_t i=4;i<28;i+=2) { uint16_t val=Channel_data[(i-4)>>1]; @@ -162,11 +168,12 @@ static void __attribute__((unused)) HOTT_data_packet() #endif hopping_frequency_no++; hopping_frequency_no %= 75; - rf_ch_num=HOTT_hop[hopping_frequency_no]; + rf_ch_num=HOTT_hop[num_ch][hopping_frequency_no]; } uint16_t ReadHOTT() { + static uint8_t pps_counter=0; switch(phase) { case HOTT_START: @@ -181,7 +188,7 @@ uint16_t ReadHOTT() else { hopping_frequency_no = 0; - rf_ch_num=HOTT_hop[hopping_frequency_no]; + rf_ch_num=HOTT_hop[num_ch][hopping_frequency_no]; counter = 0; phase = HOTT_DATA1; } @@ -190,7 +197,7 @@ uint16_t ReadHOTT() /* Work cycle: 10ms */ case HOTT_DATA1: //TX - telemetry_set_input_sync(10000); + telemetry_set_input_sync(HOTT_PACKET_PERIOD); HOTT_tune_freq(); HOTT_tune_chan_fast(); HOTT_data_packet(); @@ -223,24 +230,53 @@ uint16_t ReadHOTT() BIND_DONE; HOTT_init(); } - else - { //Telemetry - // (TXID)0x7C,0x94,0x00,0x0C,0x50 - // (RXID)0x4D,0xF2,0x00,0x00,0xB1 - // unknown 0x40 bind, 0x00 normal - // 0x0X telmetry page X=0,1,2,3,4 - // Telem page 0 = 0x00, 0x33, 0x34, 0x46, 0x64, 0x33, 0x0A, 0x00, 0x00, 0x00 - if(packet_in[11]==0) - { - debug("T:"); - for(uint8_t i=0;i=128) + TX_RSSI -= 128; + else + TX_RSSI += 128; + // Reduce telemetry to 13 bytes + packet_in[0]= TX_RSSI; + packet_in[1]= TX_LQI; + debug("T="); + for(uint8_t i=11;i < HOTT_RX_PACKET_LEN; i++) + { + packet_in[i-9]=packet_in[i]; + debug(" %02X",packet_in[i]); + } debugln(""); + telemetry_link=2; } - } + pps_counter++; + #endif } } - CC2500_Strobe(CC2500_SFRX); //Flush the RXFIFO + #ifdef HOTT_FW_TELEMETRY + packet_count++; + if(packet_count>=100) + { + TX_LQI=pps_counter; + pps_counter=packet_count=0; + } + #endif + CC2500_Strobe(CC2500_SFRX); //Flush the RXFIFO phase=HOTT_DATA1; return 1000; } @@ -251,7 +287,9 @@ uint16_t initHOTT() { HOTT_init(); HOTT_rf_init(); + packet_count=0; phase = HOTT_START; + num_ch=0;//random(0xfefefefe)%4; <= TODO bug dans une des tables hop... return 10000; } diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 50a7ce8..4387c36 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 34 +#define VERSION_PATCH_LEVEL 36 //****************** // Protocols @@ -325,6 +325,7 @@ enum MultiPacketTypes MULTI_TELEMETRY_SCANNER = 11, MULTI_TELEMETRY_AFHDS2A_AC = 12, MULTI_TELEMETRY_RX_CHANNELS = 13, + MULTI_TELEMETRY_HOTT = 14, }; // Macros @@ -976,4 +977,10 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- data[3] = number of channels to follow data[4-]= packed channels data, 11 bit per channel + Type 0x0E HoTT telemetry + length: 13 + data[0] = TX_RSSI + data[1] = TX_LQI + data[2-12] = telemetry data + */ diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index a6de2bf..d9fee18 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -689,7 +689,7 @@ bool Update_All() update_led_status(); #if defined(TELEMETRY) #if ( !( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) ) - if( (protocol == PROTO_FRSKY_RX) || (protocol == PROTO_SCANNER) || (protocol==PROTO_FRSKYD) || (protocol==PROTO_BAYANG) || (protocol==PROTO_NCC1701) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_FRSKYX) || (protocol==PROTO_DSM) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC)) + if( (protocol == PROTO_FRSKY_RX) || (protocol == PROTO_SCANNER) || (protocol==PROTO_FRSKYD) || (protocol==PROTO_BAYANG) || (protocol==PROTO_NCC1701) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_FRSKYX) || (protocol==PROTO_DSM) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC) || (protocol==PROTO_HOTT)) #endif if(IS_DISABLE_TELEM_off && !(protocol==PROTO_XN297DUMP)) TelemetryUpdate(); diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 7ea2f86..86c9612 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -303,6 +303,19 @@ static void multi_send_status() } #endif +#ifdef HOTT_FW_TELEMETRY + void HOTT_short_frame() + { + #if defined MULTI_TELEMETRY + multi_send_header(MULTI_TELEMETRY_HOTT, 13); + #else + Serial_write(0xAA); // Telemetry packet + #endif + for (uint8_t i = 0; i < 13; i++) // TX RSSI and TX LQI values followed by frame number and telemetry data + Serial_write(packet_in[i]); + } +#endif + #ifdef MULTI_TELEMETRY static void multi_send_frskyhub() { @@ -900,6 +913,14 @@ void TelemetryUpdate() return; } #endif + #if defined HOTT_FW_TELEMETRY + if(telemetry_link == 2 && protocol == PROTO_HOTT) + { + HOTT_short_frame(); + telemetry_link=0; + return; + } + #endif #if defined SCANNER_TELEMETRY if (telemetry_link && protocol == PROTO_SCANNER) diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index c240c9a..ea6efe1 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -184,6 +184,7 @@ #ifndef CYRF6936_INSTALLED #undef DEVO_CYRF6936_INO #undef DSM_CYRF6936_INO + #undef HOTT_CC2500_INO #undef J6PRO_CYRF6936_INO #undef WFLY_CYRF6936_INO #undef WK2x01_CYRF6936_INO @@ -263,6 +264,7 @@ #undef FRSKY_RX_CC2500_INO #undef AFHDS2A_RX_TELEMETRY #undef AFHDS2A_RX_A7105_INO + #undef HOTT_FW_TELEMETRY #else #if defined(MULTI_TELEMETRY) && defined(MULTI_STATUS) #error You should choose either MULTI_TELEMETRY or MULTI_STATUS but not both. @@ -315,7 +317,10 @@ #if not defined(DSM_CYRF6936_INO) #undef DSM_TELEMETRY #endif - #if not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKY_RX_TELEMETRY) && not defined(AFHDS2A_RX_TELEMETRY) + #if not defined(HOTT_CC2500_INO) + #undef HOTT_FW_TELEMETRY + #endif + #if not defined(HOTT_FW_TELEMETRY) && not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BUGS_HUB_TELEMETRY) && not defined(NCC1701_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(CABELL_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY) && not defined(MULTI_TELEMETRY) && not defined(MULTI_STATUS) && not defined(HITEC_HUB_TELEMETRY) && not defined(HITEC_FW_TELEMETRY) && not defined(SCANNER_TELEMETRY) && not defined(FRSKY_RX_TELEMETRY) && not defined(AFHDS2A_RX_TELEMETRY) #undef TELEMETRY #undef INVERT_TELEMETRY #endif diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index cddf437..8afbd91 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -299,10 +299,11 @@ #define NCC1701_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX #define CABELL_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX #define HITEC_HUB_TELEMETRY // Use FrSkyD Hub format to send basic telemetry to the radios which can decode it like er9x, erskyTX and OpenTX -#define HITEC_FW_TELEMETRY // Under development: Forward received telemetry packets to be decoded by erskyTX and OpenTX +#define HITEC_FW_TELEMETRY // Forward received telemetry packets to be decoded by erskyTX and OpenTX #define SCANNER_TELEMETRY // Forward spectrum scanner data to TX #define FRSKY_RX_TELEMETRY // Forward channels data to TX #define AFHDS2A_RX_TELEMETRY // Forward channels data to TX +#define HOTT_FW_TELEMETRY // Forward received telemetry packets to be decoded by erskyTX and OpenTX /****************************/ /*** SERIAL MODE SETTINGS ***/ From 00f071965906a4285acad2a64bfe143dd0c07f03 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Tue, 5 Nov 2019 19:11:28 +0100 Subject: [PATCH 52/65] HoTT: more hop tables --- Multiprotocol/HOTT_cc2500.ino | 31 +++++++++++++++++++++++-------- Multiprotocol/Multiprotocol.h | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index 77a6741..1f70f1e 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -109,9 +109,21 @@ static void __attribute__((unused)) HOTT_tune_freq() const uint8_t HOTT_hop[][75]= { { 48, 37, 16, 62, 9, 50, 42, 22, 68, 0, 55, 35, 21, 74, 1, 56, 31, 20, 70, 11, 45, 32, 24, 71, 8, 54, 38, 26, 61, 13, 53, 30, 15, 65, 7, 52, 34, 28, 60, 3, 47, 39, 18, 69, 2, 49, 44, 23, 72, 5, 51, 43, 19, 64, 12, 46, 33, 17, 67, 6, 58, 36, 29, 73, 14, 57, 41, 25, 63, 4, 59, 40, 27, 66, 10 }, { 50, 23, 5, 34, 67, 53, 22, 12, 39, 62, 51, 21, 10, 33, 63, 59, 16, 1, 43, 66, 49, 19, 8, 30, 71, 47, 24, 2, 35, 68, 45, 25, 14, 41, 74, 55, 18, 4, 32, 61, 54, 17, 11, 31, 72, 52, 28, 6, 38, 65, 46, 15, 9, 40, 60, 48, 26, 3, 37, 70, 58, 29, 0, 36, 64, 56, 20, 7, 42, 69, 57, 27, 13, 44, 73 }, { 73, 51, 39, 18, 9, 64, 56, 34, 16, 12, 66, 58, 36, 25, 11, 61, 47, 40, 15, 8, 71, 50, 43, 20, 6, 62, 54, 42, 19, 3, 63, 46, 44, 29, 14, 72, 49, 33, 22, 5, 69, 57, 30, 21, 10, 70, 45, 35, 26, 7, 65, 59, 31, 28, 1, 67, 48, 32, 24, 0, 60, 55, 41, 17, 2, 74, 52, 38, 27, 4, 68, 53, 37, 23, 13 }, - { 52, 60, 40, 21, 14, 50, 72, 41, 23, 13, 59, 61, 39, 16, 6, 58, 66, 33, 17, 5, 55, 64, 43, 20, 12, 54, 74, 35, 29, 3, 46, 63, 37, 22, 10, 48, 65, 31, 27, 9, 49, 73, 38, 24, 11, 56, 70, 32, 15, 1, 51, 71, 44, 18, 8, 45, 67, 36, 25, 7, 57, 62, 34, 28, 2, 53, 69, 42, 19, 4, 47, 68, 30, 26, 0 } - }; -const uint16_t HOTT_hop_val[] = { 0xC06B, 0xC34A, 0xDB24, 0x8E09 }; + { 52, 60, 40, 21, 14, 50, 72, 41, 23, 13, 59, 61, 39, 16, 6, 58, 66, 33, 17, 5, 55, 64, 43, 20, 12, 54, 74, 35, 29, 3, 46, 63, 37, 22, 10, 48, 65, 31, 27, 9, 49, 73, 38, 24, 11, 56, 70, 32, 15, 1, 51, 71, 44, 18, 8, 45, 67, 36, 25, 7, 57, 62, 34, 28, 2, 53, 69, 42, 19, 4, 47, 68, 30, 26, 0 }, + { 50, 16, 34, 6, 71, 51, 24, 40, 7, 68, 57, 27, 33, 14, 70, 55, 26, 30, 5, 74, 47, 28, 44, 11, 67, 49, 15, 32, 9, 61, 52, 22, 37, 13, 66, 59, 18, 42, 3, 62, 46, 29, 31, 12, 60, 48, 19, 38, 1, 72, 58, 17, 36, 4, 64, 53, 21, 39, 0, 63, 56, 20, 41, 2, 65, 45, 25, 35, 10, 69, 54, 23, 43, 8, 73 }, + { 55, 38, 12, 62, 23, 52, 44, 3, 66, 18, 54, 36, 10, 74, 16, 56, 42, 9, 70, 17, 58, 33, 5, 69, 20, 50, 40, 1, 63, 24, 53, 37, 13, 65, 15, 48, 34, 4, 61, 22, 57, 31, 6, 64, 26, 46, 35, 11, 72, 21, 47, 30, 7, 68, 29, 45, 32, 8, 60, 19, 49, 43, 2, 67, 27, 51, 39, 0, 71, 28, 59, 41, 14, 73, 25 }, + { 70, 32, 18, 10, 58, 69, 38, 22, 2, 54, 67, 36, 19, 12, 57, 62, 34, 20, 14, 52, 63, 41, 15, 3, 51, 73, 42, 28, 6, 48, 60, 43, 29, 5, 45, 64, 31, 17, 4, 56, 65, 35, 26, 13, 53, 61, 37, 23, 1, 49, 68, 40, 16, 9, 47, 71, 39, 25, 7, 50, 66, 33, 24, 8, 59, 72, 44, 27, 11, 46, 74, 30, 21, 0, 55 }, + { 6, 45, 71, 27, 44, 10, 46, 74, 22, 32, 0, 55, 69, 21, 33, 4, 50, 66, 18, 38, 7, 57, 62, 19, 36, 1, 48, 70, 20, 40, 8, 47, 68, 15, 43, 2, 58, 61, 26, 42, 3, 56, 72, 23, 34, 14, 54, 67, 16, 37, 5, 59, 64, 24, 30, 12, 52, 65, 25, 39, 13, 49, 73, 17, 31, 9, 53, 60, 28, 35, 11, 51, 63, 29, 41 }, + { 31, 65, 50, 20, 13, 37, 66, 45, 23, 5, 32, 69, 54, 19, 7, 39, 74, 52, 27, 1, 42, 64, 53, 22, 4, 43, 70, 58, 16, 3, 40, 71, 57, 17, 0, 35, 63, 56, 18, 9, 44, 72, 51, 21, 6, 33, 67, 46, 25, 11, 30, 73, 55, 15, 8, 36, 62, 48, 24, 10, 41, 60, 49, 29, 14, 34, 61, 47, 26, 2, 38, 68, 59, 28, 12 }, + { 67, 22, 49, 36, 13, 64, 28, 57, 37, 6, 65, 29, 46, 39, 3, 70, 26, 45, 35, 1, 62, 24, 58, 34, 10, 68, 19, 53, 33, 4, 66, 21, 52, 31, 7, 74, 18, 47, 32, 5, 61, 16, 51, 38, 8, 72, 23, 55, 30, 12, 73, 17, 59, 44, 0, 60, 15, 50, 43, 14, 63, 27, 48, 42, 11, 71, 20, 54, 41, 9, 69, 25, 56, 40, 2 }, + { 19, 38, 14, 66, 57, 18, 44, 7, 74, 48, 23, 30, 6, 71, 58, 26, 32, 5, 61, 46, 20, 34, 0, 68, 45, 24, 36, 1, 70, 50, 27, 33, 10, 63, 52, 16, 42, 9, 65, 51, 15, 41, 11, 64, 53, 22, 37, 3, 60, 56, 28, 35, 4, 67, 49, 17, 39, 13, 69, 54, 25, 43, 2, 73, 55, 21, 31, 8, 62, 47, 29, 40, 12, 72, 59 }, + { 4, 52, 64, 28, 44, 14, 46, 74, 16, 32, 11, 50, 68, 27, 36, 0, 47, 70, 26, 34, 13, 57, 61, 18, 38, 6, 56, 62, 19, 40, 5, 58, 67, 17, 31, 12, 54, 63, 22, 33, 3, 53, 72, 21, 41, 10, 48, 66, 15, 35, 7, 45, 60, 20, 37, 9, 51, 69, 25, 42, 2, 59, 71, 24, 39, 1, 55, 65, 23, 30, 8, 49, 73, 29, 43 }, + { 44, 66, 19, 1, 56, 35, 62, 20, 4, 54, 39, 70, 24, 5, 55, 31, 74, 26, 12, 58, 32, 60, 17, 10, 45, 37, 63, 22, 3, 50, 33, 64, 16, 7, 51, 34, 61, 21, 8, 48, 38, 68, 29, 0, 46, 36, 72, 28, 14, 49, 42, 69, 25, 6, 57, 43, 65, 18, 2, 52, 30, 71, 23, 13, 47, 41, 67, 15, 9, 53, 40, 73, 27, 11, 59 }, + { 12, 16, 36, 46, 69, 6, 20, 44, 58, 62, 11, 19, 34, 48, 71, 1, 18, 42, 50, 74, 3, 25, 31, 47, 65, 0, 24, 33, 45, 72, 2, 23, 35, 56, 64, 10, 22, 38, 49, 63, 7, 26, 37, 51, 70, 14, 21, 30, 53, 67, 5, 15, 40, 52, 66, 9, 17, 39, 55, 60, 13, 27, 41, 54, 73, 4, 28, 32, 57, 61, 8, 29, 43, 59, 68 }, + { 63, 42, 18, 2, 57, 71, 34, 22, 10, 48, 67, 36, 25, 4, 46, 60, 31, 28, 6, 47, 74, 37, 15, 0, 55, 65, 32, 24, 12, 56, 66, 40, 27, 14, 52, 62, 38, 19, 3, 50, 73, 33, 29, 11, 53, 61, 35, 16, 7, 58, 72, 41, 26, 5, 59, 69, 30, 20, 9, 51, 68, 44, 23, 1, 49, 70, 39, 17, 8, 54, 64, 43, 21, 13, 45 }, + { 52, 1, 71, 17, 36, 47, 7, 64, 26, 32, 53, 5, 60, 20, 42, 57, 2, 66, 18, 34, 56, 4, 63, 24, 35, 46, 13, 72, 22, 30, 48, 0, 67, 21, 39, 50, 3, 74, 16, 31, 59, 14, 61, 23, 37, 45, 6, 65, 19, 44, 51, 11, 62, 27, 41, 55, 9, 68, 15, 38, 58, 8, 70, 29, 40, 54, 10, 69, 28, 33, 49, 12, 73, 25, 43 } + }; +const uint16_t HOTT_hop_val[] = { 0xC06B, 0xC34A, 0xDB24, 0x8E09, 0x272E, 0x217F, 0x155B, 0xEDE8, 0x1D31, 0x0986, 0x56F7, 0x6454, 0xC42D, 0x01D2, 0xC253, 0x1180 }; static void __attribute__((unused)) HOTT_init() { @@ -121,7 +133,7 @@ static void __attribute__((unused)) HOTT_init() memcpy(rx_tx_addr,"\x7C\x94\x00\x0D\x50",5); #endif memset(&packet[30],0xFF,9); - packet[39]=0X07; // unknown + packet[39]=0x07; // unknown if(IS_BIND_IN_PROGRESS) { packet[28] = 0x80; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets @@ -132,7 +144,7 @@ static void __attribute__((unused)) HOTT_init() else { packet[28] = 0x8C; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets - packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets + packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets, 0x8C&0x0A->no telemetry memcpy(&packet[40],rx_tx_addr,5); uint8_t addr=HOTT_EEPROM_OFFSET+RX_num*5; @@ -161,7 +173,7 @@ static void __attribute__((unused)) HOTT_data_packet() CC2500_WriteReg(CC2500_06_PKTLEN, 0x32); CC2500_WriteData(packet, HOTT_TX_PACKET_LEN); #if 0 - debug("P:"); + debug("RF:%02X P:",rf_ch_num); for(uint8_t i=0;i Date: Tue, 5 Nov 2019 19:12:06 +0100 Subject: [PATCH 53/65] DSM configurable max throw parameter through option --- Multiprotocol/DSM_cyrf6936.ino | 7 +++++-- Multiprotocol/Multi_Names.ino | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Multiprotocol/DSM_cyrf6936.ino b/Multiprotocol/DSM_cyrf6936.ino index def9a86..0fb52b9 100644 --- a/Multiprotocol/DSM_cyrf6936.ino +++ b/Multiprotocol/DSM_cyrf6936.ino @@ -230,7 +230,7 @@ static void __attribute__((unused)) DSM_update_channels() if(sub_protocol==DSM_AUTO) num_ch=12; // Force 12 channels in mode Auto else - num_ch=option; + num_ch=option & 0x7F; // Remove the Max Throw flag if(num_ch<4 || num_ch>12) num_ch=6; // Default to 6 channels if invalid choice... @@ -286,7 +286,10 @@ static void __attribute__((unused)) DSM_build_data_packet(uint8_t upper) #ifdef DSM_MAX_THROW value=Channel_data[CH_TAER[idx]]; // -100%..+100% => 1024..1976us and -125%..+125% => 904..2096us based on Redcon 6 channel DSM2 RX #else - value=convert_channel_16b_nolimit(CH_TAER[idx],0x150,0x6B0); // -100%..+100% => 1100..1900us and -125%..+125% => 1000..2000us based on Redcon 6 channel DSM2 RX + if(option & 0x80) + value=Channel_data[CH_TAER[idx]]; // -100%..+100% => 1024..1976us and -125%..+125% => 904..2096us based on Redcon 6 channel DSM2 RX + else + value=convert_channel_16b_nolimit(CH_TAER[idx],0x150,0x6B0); // -100%..+100% => 1100..1900us and -125%..+125% => 1000..2000us based on Redcon 6 channel DSM2 RX #endif if(bits==10) value>>=1; value |= (upper && i==0 ? 0x8000 : 0) | (idx << bits); diff --git a/Multiprotocol/Multi_Names.ino b/Multiprotocol/Multi_Names.ino index e7c84f9..83bebf9 100644 --- a/Multiprotocol/Multi_Names.ino +++ b/Multiprotocol/Multi_Names.ino @@ -118,6 +118,7 @@ enum OPTION_FIXEDID, OPTION_TELEM, OPTION_SRVFREQ, + OPTION_MAXTHR, }; #define NO_SUBTYPE nullptr @@ -140,7 +141,7 @@ const mm_protocol_definition multi_protocols[] = { {PROTO_V2X2, STR_V2X2, 2, STR_SUBTYPE_V2X2, OPTION_NONE }, #endif #if defined(DSM_CYRF6936_INO) - {PROTO_DSM, STR_DSM, 4, STR_SUBTYPE_DSM, OPTION_NONE }, + {PROTO_DSM, STR_DSM, 4, STR_SUBTYPE_DSM, OPTION_MAXTHR }, #endif #if defined(DEVO_CYRF6936_INO) {PROTO_DEVO, STR_DEVO, 5, STR_SUBTYPE_DEVO, OPTION_FIXEDID }, From c4c5ffec4fe3b18de81805423efeea659b0319f3 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 7 Nov 2019 01:03:57 +0100 Subject: [PATCH 54/65] HoTT: Failsafe Failsafe MUST be configured once with the desired channel values (hold or position) while the RX is up (wait 10+sec for the RX to learn the config) and then failsafe MUST be set to RX/Receiver otherwise the servos will jitter!!! --- Multiprotocol/HOTT_cc2500.ino | 47 +++++++++++++++++++++++++++++++---- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Telemetry.ino | 5 ++-- Protocols_Details.md | 33 ++++++++++++++++++------ docs/Frequency_Tuning.md | 8 +++--- 5 files changed, 77 insertions(+), 18 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index 1f70f1e..a0ab96f 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -133,7 +133,7 @@ static void __attribute__((unused)) HOTT_init() memcpy(rx_tx_addr,"\x7C\x94\x00\x0D\x50",5); #endif memset(&packet[30],0xFF,9); - packet[39]=0x07; // unknown + packet[39]=0x07; // unknown and constant if(IS_BIND_IN_PROGRESS) { packet[28] = 0x80; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets @@ -144,7 +144,7 @@ static void __attribute__((unused)) HOTT_init() else { packet[28] = 0x8C; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets - packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets, 0x8C&0x0A->no telemetry + packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets, 0x0A->no more RX telemetry memcpy(&packet[40],rx_tx_addr,5); uint8_t addr=HOTT_EEPROM_OFFSET+RX_num*5; @@ -157,13 +157,50 @@ static void __attribute__((unused)) HOTT_data_packet() { packet[2] = hopping_frequency_no; - packet[3] = 0x00; // unknown, may be for additional channels? + packet[3] = 0x00; // used for failsafe but may also be used for additional channels + #ifdef FAILSAFE_ENABLE + static uint8_t failsafe_count=0; + if(IS_FAILSAFE_VALUES_on && IS_BIND_DONE) + { + failsafe_count++; + if(failsafe_count>=3) + { + FAILSAFE_VALUES_off; + failsafe_count=0; + } + } + else + failsafe_count=0; + #endif // Channels value are PPM*2, -100%=1100µs, +100%=1900µs, order TAER + uint16_t val; for(uint8_t i=4;i<28;i+=2) { - uint16_t val=Channel_data[(i-4)>>1]; - val=(((val<<2)+val)>>2)+860*2; //value range 860<->2140 *2 <-> -125%<->+125% + val=Channel_data[(i-4)>>1]; + val=(((val<<2)+val)>>2)+860*2; // value range 860<->2140 *2 <-> -125%<->+125% + #ifdef FAILSAFE_ENABLE + if(failsafe_count==1) + { // first failsafe packet + packet[3]=0x40; + uint16_t fs=Failsafe_data[(i-4)>>1]; + if( fs == FAILSAFE_CHANNEL_HOLD || fs == FAILSAFE_CHANNEL_NOPULSES) + val|=0x8000; // channel hold flag + else + { + val=(((fs<<2)+fs)>>2)+860*2; // value range 860<->2140 *2 <-> -125%<->+125% + val|=0x4000; // channel specific position flag + } + } + else if(failsafe_count==2) + { // second failsafe packet=timing? + packet[3]=0x50; + if(i==4) + val=2; + else + val=0; + } + #endif packet[i] = val; packet[i+1] = val>>8; } diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 7aaebcf..21f412b 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 37 +#define VERSION_PATCH_LEVEL 38 //****************** // Protocols diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 86c9612..d7ec899 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -162,11 +162,12 @@ static void multi_send_status() case PROTO_J6PRO: flags |= 0x40; //Disable_ch_mapping supported break; + #ifdef FAILSAFE_ENABLE + case PROTO_HOTT: case PROTO_FRSKYX: - #ifdef FAILSAFE_ENABLE flags |= 0x20; //Failsafe supported - #endif break; + #endif } if(IS_DATA_BUFFER_LOW_on) flags |= 0x80; diff --git a/Protocols_Details.md b/Protocols_Details.md index b318af2..a008e4f 100644 --- a/Protocols_Details.md +++ b/Protocols_Details.md @@ -29,7 +29,7 @@ Here are detailed descriptions of every supported protocols (sorted by RF module ## Protocol selection in PPM mode The protocol selection is based on 2 parameters: * selection switch: this is the rotary switch on the module numbered from 0 to 15 - - switch position 0 is to select the Serial mode for er9x/ersky9x/OpenTX radio + - switch position 0 is to select the Serial mode for er9x/erskyTX/OpenTX radio - switch position 15 is to select the bank - switch position 1..14 will select the protocol 1..14 in the bank *X* * banks are used to increase the amount of accessible protocols by the switch. There are up to 5 banks giving acces to up to 70 protocol entries (5 * 14). To modify or verify which bank is currenlty active do the following: @@ -56,7 +56,7 @@ Notes: Serial mode is selected by placing the rotary switch to position 0 before power on of the radio. You've upgraded the module but the radio does not display the name of the protocol you are loking for: - * ersky9x: + * erskyTX: - Place the file [Multi.txt](https://raw.githubusercontent.com/pascallanger/DIY-Multiprotocol-TX-Module/master/Multiprotocol/Multi.txt) (which is part of the MPM source files) on the root of your SD card. - If the entry still does not appear or is broken, [upgrade](https://openrcforums.com/forum/viewtopic.php?f=7&t=4676) to version R222d2 or newer. * OpenTX: @@ -98,6 +98,7 @@ CFlie|38|CFlie||||||||NRF24L01| [Hisky](Protocols_Details.md#HISKY---4)|4|Hisky|HK310|||||||NRF24L01| [Hitec](Protocols_Details.md#HITEC---39)|39|OPT_FW|OPT_HUB|MINIMA||||||CC2500| [Hontai](Protocols_Details.md#HONTAI---26)|26|HONTAI|JJRCX1|X5C1|FQ777_951|||||NRF24L01|XN297 +[HoTT](Protocols_Details.md#HoTT---57)|57|||||||||CC2500| [Hubsan](Protocols_Details.md#HUBSAN---2)|2|H107|H301|H501||||||A7105| [J6Pro](Protocols_Details.md#J6Pro---22)|22|J6PRO||||||||CYRF6936| [KF606](Protocols_Details.md#KF606---49)|49|KF606*||||||||NRF24L01|XN297 @@ -166,7 +167,7 @@ Extended limits and failsafe supported Telemetry enabled protocol: - by defaut using FrSky Hub protocol (for example er9x): RX(A1), battery voltage FS-CVT01(A2) and RX&TX RSSI - - if using ersky9x and OpenTX: full telemetry information available + - if using erskyTX and OpenTX: full telemetry information available Option is used to change the servo refresh rate. A value of 0 gives 50Hz (min), 70 gives 400Hz (max). Specific refresh rate value can be calculated like this option=(refresh_rate-50)/5. @@ -395,20 +396,38 @@ CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9 ### Sub_protocol OPT_FW - *0* OPTIMA RXs -Full telemetry available on ersky9x and OpenTX. This is still a WIP. +Full telemetry available on OpenTX 2.3.2+, still in progress for erskyTx. **The TX must be close to the RX for the bind negotiation to complete successfully** ### Sub_protocol OPT_HUB - *1* OPTIMA RXs -Basic telemetry using FrSky Hub on er9x, ersky9x, OpenTX and any radio with FrSky telemetry support with RX voltage, VOLT2 voltage, TX RSSI and TX LQI. +Basic telemetry using FrSky Hub on er9x, erskyTX, OpenTX and any radio with FrSky telemetry support with RX voltage, VOLT2 voltage, TX RSSI and TX LQI. **The TX must be close to the RX for the bind negotiation to complete successfully** ### Sub_protocol MINIMA - *2* MINIMA, MICRO and RED receivers +## HoTT - *57* +Models: Graupner HoTT receivers (tested on GR-12L and GR-16L). + +Extended limits and failsafe supported + +**Failsafe MUST be configured once with the desired channel values (hold or position) while the RX is up (wait 10+sec for the RX to learn the config) and then failsafe MUST be set to RX/Receiver otherwise the servos will jitter!!!** + +**The RX features must be configured first on a Graupner radio before binding it with Multi (RX config not implemented).** + +Option for this protocol corresponds to fine frequency tuning. This value is different for each Module and **must** be accurate otherwise the link will not be stable. +Check the [Frequency Tuning page](/docs/Frequency_Tuning.md) to determine it. + +CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12 +---|---|---|---|---|---|---|---|---|----|----|---- +CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12 + +Basic telemetry is available on OpenTX 2.3.2+ with RX voltage, Rx temperature, RX RSSI, RX LQI, TX RSSI and TX LQI. + ## SFHSS - *21* Models: Futaba RXs and XK models. @@ -562,9 +581,9 @@ DSMX, Resolution 2048, refresh rate 11ms ### Sub_protocol AUTO - *4* The "AUTO" feature enables the TX to automatically choose what are the best settings for your DSM RX and update your model protocol settings accordingly. -The current radio firmware which are able to use the "AUTO" feature are ersky9x (9XR Pro, 9Xtreme, Taranis, ...), er9x for M128(9XR)&M2561 and OpenTX (mostly Taranis). +The current radio firmware which are able to use the "AUTO" feature are erskyTX (9XR Pro, 9Xtreme, Taranis, ...), er9x for M128(9XR)&M2561 and OpenTX (mostly Taranis). For these firmwares, you must have a telemetry enabled TX and you have to make sure you set the Telemetry "Usr proto" to "DSMx". -Also on er9x you will need to be sure to match the polarity of the telemetry serial (normal or inverted by bitbashing), while on ersky9x you can set "Invert COM1" accordinlgy. +Also on er9x you will need to be sure to match the polarity of the telemetry serial (normal or inverted by bitbashing), while on erskyTX you can set "Invert COM1" accordinlgy. ## J6Pro - *22* diff --git a/docs/Frequency_Tuning.md b/docs/Frequency_Tuning.md index 590296f..1294505 100644 --- a/docs/Frequency_Tuning.md +++ b/docs/Frequency_Tuning.md @@ -8,16 +8,17 @@ The protocols which require frequency tuning are: * **S-FHSS** (e.g. Futaba S-FHSS receivers) * **Corona** (e.g. Corona V1 FSS, Corona V2 DSSS CR8D/CR6D/CR4D and FlyDream IS-4R/IS-4R0 receivers) * **Hitec** (e.g. Optima, Minima, Micro and RED receivers) +* **HoTT** (e.g. Graupner receivers) There is a [video](#video) at the end of this page which gives an example of the tuning process. ## More information -Original FrSky, Futaba, Corona and Hitec receivers have been frequency-tuned by the manufacturer at the factory. Because of variations in the oscillator crystals used in multiprotocol modules it is necessary to fine-tune the module to match the manufacturer frequencies. +Original FrSky, Futaba, Corona Hitec and HoTT receivers have been frequency-tuned by the manufacturer at the factory. Because of variations in the oscillator crystals used in multiprotocol modules it is necessary to fine-tune the module to match the manufacturer frequencies. 'Compatible' receivers suffer the same variation in crystal oscillators as multiprotocol modules, but have to be compatible with genuine (manufacturer-tuned) transmitters so they will typically have auto-tuning built in, and will self-tune to the radio's frequency when they are bound. ## Fine-tuning procedure -**Note:** For best results, the fine-tuning procedure should be carried out with a genuine FrSky/Futaba/Corona/Hitec receiver. +**Note:** For best results, the fine-tuning procedure should be carried out with a genuine FrSky/Futaba/Corona/Hitec/HoTT receiver. The procedure can be performed in serial or PPM mode, but is easier with in serial mode where the effect of the change can be seen in real-time. @@ -49,7 +50,7 @@ Connection is lost at -73 and +35; the median is -19: ### Finally Once the **Freq** value is known it should be applied to all other models which use this protocol and, if they were previously bound, the receivers must be re-bound. -For convenience this can be done in the `_Config.h` (or `_MyConfig.h`) configuration file. +For convenience this can be applied once for all per protocol using the FORCE commands described below in `_Config.h` (or `_MyConfig.h`) configuration file. #### Forced tuning values Once known-good tuning values have been determined, they can be stored in the configuration file to be automatically applied to all models which use the given protocol. @@ -73,6 +74,7 @@ These settings can also be used to force different tuning values for different m //#define FORCE_SFHSS_TUNING 0 //#define FORCE_CORONA_TUNING 0 //#define FORCE_HITEC_TUNING 0 +//#define FORCE_HOTT_TUNING 0 ``` ## Video From 928641f535863b8927de100edc14a2b073e4d79d Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 7 Nov 2019 01:56:13 +0100 Subject: [PATCH 55/65] HoTT: add progmem to tables --- Multiprotocol/HOTT_cc2500.ino | 54 ++++++++++++++++++--------------- Multiprotocol/Multiprotocol.ino | 6 +++- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index a0ab96f..60d67ad 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -22,6 +22,7 @@ #define HOTT_TX_PACKET_LEN 50 #define HOTT_RX_PACKET_LEN 22 #define HOTT_PACKET_PERIOD 10000 +#define HOTT_NUM_RF_CHANNELS 75 #define HOTT_COARSE 0 enum { @@ -106,29 +107,34 @@ static void __attribute__((unused)) HOTT_tune_freq() } } -const uint8_t HOTT_hop[][75]= { { 48, 37, 16, 62, 9, 50, 42, 22, 68, 0, 55, 35, 21, 74, 1, 56, 31, 20, 70, 11, 45, 32, 24, 71, 8, 54, 38, 26, 61, 13, 53, 30, 15, 65, 7, 52, 34, 28, 60, 3, 47, 39, 18, 69, 2, 49, 44, 23, 72, 5, 51, 43, 19, 64, 12, 46, 33, 17, 67, 6, 58, 36, 29, 73, 14, 57, 41, 25, 63, 4, 59, 40, 27, 66, 10 }, - { 50, 23, 5, 34, 67, 53, 22, 12, 39, 62, 51, 21, 10, 33, 63, 59, 16, 1, 43, 66, 49, 19, 8, 30, 71, 47, 24, 2, 35, 68, 45, 25, 14, 41, 74, 55, 18, 4, 32, 61, 54, 17, 11, 31, 72, 52, 28, 6, 38, 65, 46, 15, 9, 40, 60, 48, 26, 3, 37, 70, 58, 29, 0, 36, 64, 56, 20, 7, 42, 69, 57, 27, 13, 44, 73 }, - { 73, 51, 39, 18, 9, 64, 56, 34, 16, 12, 66, 58, 36, 25, 11, 61, 47, 40, 15, 8, 71, 50, 43, 20, 6, 62, 54, 42, 19, 3, 63, 46, 44, 29, 14, 72, 49, 33, 22, 5, 69, 57, 30, 21, 10, 70, 45, 35, 26, 7, 65, 59, 31, 28, 1, 67, 48, 32, 24, 0, 60, 55, 41, 17, 2, 74, 52, 38, 27, 4, 68, 53, 37, 23, 13 }, - { 52, 60, 40, 21, 14, 50, 72, 41, 23, 13, 59, 61, 39, 16, 6, 58, 66, 33, 17, 5, 55, 64, 43, 20, 12, 54, 74, 35, 29, 3, 46, 63, 37, 22, 10, 48, 65, 31, 27, 9, 49, 73, 38, 24, 11, 56, 70, 32, 15, 1, 51, 71, 44, 18, 8, 45, 67, 36, 25, 7, 57, 62, 34, 28, 2, 53, 69, 42, 19, 4, 47, 68, 30, 26, 0 }, - { 50, 16, 34, 6, 71, 51, 24, 40, 7, 68, 57, 27, 33, 14, 70, 55, 26, 30, 5, 74, 47, 28, 44, 11, 67, 49, 15, 32, 9, 61, 52, 22, 37, 13, 66, 59, 18, 42, 3, 62, 46, 29, 31, 12, 60, 48, 19, 38, 1, 72, 58, 17, 36, 4, 64, 53, 21, 39, 0, 63, 56, 20, 41, 2, 65, 45, 25, 35, 10, 69, 54, 23, 43, 8, 73 }, - { 55, 38, 12, 62, 23, 52, 44, 3, 66, 18, 54, 36, 10, 74, 16, 56, 42, 9, 70, 17, 58, 33, 5, 69, 20, 50, 40, 1, 63, 24, 53, 37, 13, 65, 15, 48, 34, 4, 61, 22, 57, 31, 6, 64, 26, 46, 35, 11, 72, 21, 47, 30, 7, 68, 29, 45, 32, 8, 60, 19, 49, 43, 2, 67, 27, 51, 39, 0, 71, 28, 59, 41, 14, 73, 25 }, - { 70, 32, 18, 10, 58, 69, 38, 22, 2, 54, 67, 36, 19, 12, 57, 62, 34, 20, 14, 52, 63, 41, 15, 3, 51, 73, 42, 28, 6, 48, 60, 43, 29, 5, 45, 64, 31, 17, 4, 56, 65, 35, 26, 13, 53, 61, 37, 23, 1, 49, 68, 40, 16, 9, 47, 71, 39, 25, 7, 50, 66, 33, 24, 8, 59, 72, 44, 27, 11, 46, 74, 30, 21, 0, 55 }, - { 6, 45, 71, 27, 44, 10, 46, 74, 22, 32, 0, 55, 69, 21, 33, 4, 50, 66, 18, 38, 7, 57, 62, 19, 36, 1, 48, 70, 20, 40, 8, 47, 68, 15, 43, 2, 58, 61, 26, 42, 3, 56, 72, 23, 34, 14, 54, 67, 16, 37, 5, 59, 64, 24, 30, 12, 52, 65, 25, 39, 13, 49, 73, 17, 31, 9, 53, 60, 28, 35, 11, 51, 63, 29, 41 }, - { 31, 65, 50, 20, 13, 37, 66, 45, 23, 5, 32, 69, 54, 19, 7, 39, 74, 52, 27, 1, 42, 64, 53, 22, 4, 43, 70, 58, 16, 3, 40, 71, 57, 17, 0, 35, 63, 56, 18, 9, 44, 72, 51, 21, 6, 33, 67, 46, 25, 11, 30, 73, 55, 15, 8, 36, 62, 48, 24, 10, 41, 60, 49, 29, 14, 34, 61, 47, 26, 2, 38, 68, 59, 28, 12 }, - { 67, 22, 49, 36, 13, 64, 28, 57, 37, 6, 65, 29, 46, 39, 3, 70, 26, 45, 35, 1, 62, 24, 58, 34, 10, 68, 19, 53, 33, 4, 66, 21, 52, 31, 7, 74, 18, 47, 32, 5, 61, 16, 51, 38, 8, 72, 23, 55, 30, 12, 73, 17, 59, 44, 0, 60, 15, 50, 43, 14, 63, 27, 48, 42, 11, 71, 20, 54, 41, 9, 69, 25, 56, 40, 2 }, - { 19, 38, 14, 66, 57, 18, 44, 7, 74, 48, 23, 30, 6, 71, 58, 26, 32, 5, 61, 46, 20, 34, 0, 68, 45, 24, 36, 1, 70, 50, 27, 33, 10, 63, 52, 16, 42, 9, 65, 51, 15, 41, 11, 64, 53, 22, 37, 3, 60, 56, 28, 35, 4, 67, 49, 17, 39, 13, 69, 54, 25, 43, 2, 73, 55, 21, 31, 8, 62, 47, 29, 40, 12, 72, 59 }, - { 4, 52, 64, 28, 44, 14, 46, 74, 16, 32, 11, 50, 68, 27, 36, 0, 47, 70, 26, 34, 13, 57, 61, 18, 38, 6, 56, 62, 19, 40, 5, 58, 67, 17, 31, 12, 54, 63, 22, 33, 3, 53, 72, 21, 41, 10, 48, 66, 15, 35, 7, 45, 60, 20, 37, 9, 51, 69, 25, 42, 2, 59, 71, 24, 39, 1, 55, 65, 23, 30, 8, 49, 73, 29, 43 }, - { 44, 66, 19, 1, 56, 35, 62, 20, 4, 54, 39, 70, 24, 5, 55, 31, 74, 26, 12, 58, 32, 60, 17, 10, 45, 37, 63, 22, 3, 50, 33, 64, 16, 7, 51, 34, 61, 21, 8, 48, 38, 68, 29, 0, 46, 36, 72, 28, 14, 49, 42, 69, 25, 6, 57, 43, 65, 18, 2, 52, 30, 71, 23, 13, 47, 41, 67, 15, 9, 53, 40, 73, 27, 11, 59 }, - { 12, 16, 36, 46, 69, 6, 20, 44, 58, 62, 11, 19, 34, 48, 71, 1, 18, 42, 50, 74, 3, 25, 31, 47, 65, 0, 24, 33, 45, 72, 2, 23, 35, 56, 64, 10, 22, 38, 49, 63, 7, 26, 37, 51, 70, 14, 21, 30, 53, 67, 5, 15, 40, 52, 66, 9, 17, 39, 55, 60, 13, 27, 41, 54, 73, 4, 28, 32, 57, 61, 8, 29, 43, 59, 68 }, - { 63, 42, 18, 2, 57, 71, 34, 22, 10, 48, 67, 36, 25, 4, 46, 60, 31, 28, 6, 47, 74, 37, 15, 0, 55, 65, 32, 24, 12, 56, 66, 40, 27, 14, 52, 62, 38, 19, 3, 50, 73, 33, 29, 11, 53, 61, 35, 16, 7, 58, 72, 41, 26, 5, 59, 69, 30, 20, 9, 51, 68, 44, 23, 1, 49, 70, 39, 17, 8, 54, 64, 43, 21, 13, 45 }, - { 52, 1, 71, 17, 36, 47, 7, 64, 26, 32, 53, 5, 60, 20, 42, 57, 2, 66, 18, 34, 56, 4, 63, 24, 35, 46, 13, 72, 22, 30, 48, 0, 67, 21, 39, 50, 3, 74, 16, 31, 59, 14, 61, 23, 37, 45, 6, 65, 19, 44, 51, 11, 62, 27, 41, 55, 9, 68, 15, 38, 58, 8, 70, 29, 40, 54, 10, 69, 28, 33, 49, 12, 73, 25, 43 } - }; -const uint16_t HOTT_hop_val[] = { 0xC06B, 0xC34A, 0xDB24, 0x8E09, 0x272E, 0x217F, 0x155B, 0xEDE8, 0x1D31, 0x0986, 0x56F7, 0x6454, 0xC42D, 0x01D2, 0xC253, 0x1180 }; +const uint8_t PROGMEM HOTT_hop[][HOTT_NUM_RF_CHANNELS]= + { { 48, 37, 16, 62, 9, 50, 42, 22, 68, 0, 55, 35, 21, 74, 1, 56, 31, 20, 70, 11, 45, 32, 24, 71, 8, 54, 38, 26, 61, 13, 53, 30, 15, 65, 7, 52, 34, 28, 60, 3, 47, 39, 18, 69, 2, 49, 44, 23, 72, 5, 51, 43, 19, 64, 12, 46, 33, 17, 67, 6, 58, 36, 29, 73, 14, 57, 41, 25, 63, 4, 59, 40, 27, 66, 10 }, + { 50, 23, 5, 34, 67, 53, 22, 12, 39, 62, 51, 21, 10, 33, 63, 59, 16, 1, 43, 66, 49, 19, 8, 30, 71, 47, 24, 2, 35, 68, 45, 25, 14, 41, 74, 55, 18, 4, 32, 61, 54, 17, 11, 31, 72, 52, 28, 6, 38, 65, 46, 15, 9, 40, 60, 48, 26, 3, 37, 70, 58, 29, 0, 36, 64, 56, 20, 7, 42, 69, 57, 27, 13, 44, 73 }, + { 73, 51, 39, 18, 9, 64, 56, 34, 16, 12, 66, 58, 36, 25, 11, 61, 47, 40, 15, 8, 71, 50, 43, 20, 6, 62, 54, 42, 19, 3, 63, 46, 44, 29, 14, 72, 49, 33, 22, 5, 69, 57, 30, 21, 10, 70, 45, 35, 26, 7, 65, 59, 31, 28, 1, 67, 48, 32, 24, 0, 60, 55, 41, 17, 2, 74, 52, 38, 27, 4, 68, 53, 37, 23, 13 }, + { 52, 60, 40, 21, 14, 50, 72, 41, 23, 13, 59, 61, 39, 16, 6, 58, 66, 33, 17, 5, 55, 64, 43, 20, 12, 54, 74, 35, 29, 3, 46, 63, 37, 22, 10, 48, 65, 31, 27, 9, 49, 73, 38, 24, 11, 56, 70, 32, 15, 1, 51, 71, 44, 18, 8, 45, 67, 36, 25, 7, 57, 62, 34, 28, 2, 53, 69, 42, 19, 4, 47, 68, 30, 26, 0 }, + { 50, 16, 34, 6, 71, 51, 24, 40, 7, 68, 57, 27, 33, 14, 70, 55, 26, 30, 5, 74, 47, 28, 44, 11, 67, 49, 15, 32, 9, 61, 52, 22, 37, 13, 66, 59, 18, 42, 3, 62, 46, 29, 31, 12, 60, 48, 19, 38, 1, 72, 58, 17, 36, 4, 64, 53, 21, 39, 0, 63, 56, 20, 41, 2, 65, 45, 25, 35, 10, 69, 54, 23, 43, 8, 73 }, + { 55, 38, 12, 62, 23, 52, 44, 3, 66, 18, 54, 36, 10, 74, 16, 56, 42, 9, 70, 17, 58, 33, 5, 69, 20, 50, 40, 1, 63, 24, 53, 37, 13, 65, 15, 48, 34, 4, 61, 22, 57, 31, 6, 64, 26, 46, 35, 11, 72, 21, 47, 30, 7, 68, 29, 45, 32, 8, 60, 19, 49, 43, 2, 67, 27, 51, 39, 0, 71, 28, 59, 41, 14, 73, 25 }, + { 70, 32, 18, 10, 58, 69, 38, 22, 2, 54, 67, 36, 19, 12, 57, 62, 34, 20, 14, 52, 63, 41, 15, 3, 51, 73, 42, 28, 6, 48, 60, 43, 29, 5, 45, 64, 31, 17, 4, 56, 65, 35, 26, 13, 53, 61, 37, 23, 1, 49, 68, 40, 16, 9, 47, 71, 39, 25, 7, 50, 66, 33, 24, 8, 59, 72, 44, 27, 11, 46, 74, 30, 21, 0, 55 }, + { 6, 45, 71, 27, 44, 10, 46, 74, 22, 32, 0, 55, 69, 21, 33, 4, 50, 66, 18, 38, 7, 57, 62, 19, 36, 1, 48, 70, 20, 40, 8, 47, 68, 15, 43, 2, 58, 61, 26, 42, 3, 56, 72, 23, 34, 14, 54, 67, 16, 37, 5, 59, 64, 24, 30, 12, 52, 65, 25, 39, 13, 49, 73, 17, 31, 9, 53, 60, 28, 35, 11, 51, 63, 29, 41 }, + { 31, 65, 50, 20, 13, 37, 66, 45, 23, 5, 32, 69, 54, 19, 7, 39, 74, 52, 27, 1, 42, 64, 53, 22, 4, 43, 70, 58, 16, 3, 40, 71, 57, 17, 0, 35, 63, 56, 18, 9, 44, 72, 51, 21, 6, 33, 67, 46, 25, 11, 30, 73, 55, 15, 8, 36, 62, 48, 24, 10, 41, 60, 49, 29, 14, 34, 61, 47, 26, 2, 38, 68, 59, 28, 12 }, + { 67, 22, 49, 36, 13, 64, 28, 57, 37, 6, 65, 29, 46, 39, 3, 70, 26, 45, 35, 1, 62, 24, 58, 34, 10, 68, 19, 53, 33, 4, 66, 21, 52, 31, 7, 74, 18, 47, 32, 5, 61, 16, 51, 38, 8, 72, 23, 55, 30, 12, 73, 17, 59, 44, 0, 60, 15, 50, 43, 14, 63, 27, 48, 42, 11, 71, 20, 54, 41, 9, 69, 25, 56, 40, 2 }, + { 19, 38, 14, 66, 57, 18, 44, 7, 74, 48, 23, 30, 6, 71, 58, 26, 32, 5, 61, 46, 20, 34, 0, 68, 45, 24, 36, 1, 70, 50, 27, 33, 10, 63, 52, 16, 42, 9, 65, 51, 15, 41, 11, 64, 53, 22, 37, 3, 60, 56, 28, 35, 4, 67, 49, 17, 39, 13, 69, 54, 25, 43, 2, 73, 55, 21, 31, 8, 62, 47, 29, 40, 12, 72, 59 }, + { 4, 52, 64, 28, 44, 14, 46, 74, 16, 32, 11, 50, 68, 27, 36, 0, 47, 70, 26, 34, 13, 57, 61, 18, 38, 6, 56, 62, 19, 40, 5, 58, 67, 17, 31, 12, 54, 63, 22, 33, 3, 53, 72, 21, 41, 10, 48, 66, 15, 35, 7, 45, 60, 20, 37, 9, 51, 69, 25, 42, 2, 59, 71, 24, 39, 1, 55, 65, 23, 30, 8, 49, 73, 29, 43 }, + { 44, 66, 19, 1, 56, 35, 62, 20, 4, 54, 39, 70, 24, 5, 55, 31, 74, 26, 12, 58, 32, 60, 17, 10, 45, 37, 63, 22, 3, 50, 33, 64, 16, 7, 51, 34, 61, 21, 8, 48, 38, 68, 29, 0, 46, 36, 72, 28, 14, 49, 42, 69, 25, 6, 57, 43, 65, 18, 2, 52, 30, 71, 23, 13, 47, 41, 67, 15, 9, 53, 40, 73, 27, 11, 59 }, + { 12, 16, 36, 46, 69, 6, 20, 44, 58, 62, 11, 19, 34, 48, 71, 1, 18, 42, 50, 74, 3, 25, 31, 47, 65, 0, 24, 33, 45, 72, 2, 23, 35, 56, 64, 10, 22, 38, 49, 63, 7, 26, 37, 51, 70, 14, 21, 30, 53, 67, 5, 15, 40, 52, 66, 9, 17, 39, 55, 60, 13, 27, 41, 54, 73, 4, 28, 32, 57, 61, 8, 29, 43, 59, 68 }, + { 63, 42, 18, 2, 57, 71, 34, 22, 10, 48, 67, 36, 25, 4, 46, 60, 31, 28, 6, 47, 74, 37, 15, 0, 55, 65, 32, 24, 12, 56, 66, 40, 27, 14, 52, 62, 38, 19, 3, 50, 73, 33, 29, 11, 53, 61, 35, 16, 7, 58, 72, 41, 26, 5, 59, 69, 30, 20, 9, 51, 68, 44, 23, 1, 49, 70, 39, 17, 8, 54, 64, 43, 21, 13, 45 }, + { 52, 1, 71, 17, 36, 47, 7, 64, 26, 32, 53, 5, 60, 20, 42, 57, 2, 66, 18, 34, 56, 4, 63, 24, 35, 46, 13, 72, 22, 30, 48, 0, 67, 21, 39, 50, 3, 74, 16, 31, 59, 14, 61, 23, 37, 45, 6, 65, 19, 44, 51, 11, 62, 27, 41, 55, 9, 68, 15, 38, 58, 8, 70, 29, 40, 54, 10, 69, 28, 33, 49, 12, 73, 25, 43 } + }; +const uint16_t PROGMEM HOTT_hop_val[] = { 0xC06B, 0xC34A, 0xDB24, 0x8E09, 0x272E, 0x217F, 0x155B, 0xEDE8, 0x1D31, 0x0986, 0x56F7, 0x6454, 0xC42D, 0x01D2, 0xC253, 0x1180 }; static void __attribute__((unused)) HOTT_init() { - packet[0] = HOTT_hop_val[num_ch]; - packet[1] = HOTT_hop_val[num_ch]>>8; + packet[0] = pgm_read_word_near( &HOTT_hop_val[num_ch] ); + packet[1] = pgm_read_word_near( &HOTT_hop_val[num_ch] )>>8; + + for(uint8_t i=0; i Date: Thu, 7 Nov 2019 02:30:03 +0100 Subject: [PATCH 56/65] Failsafe improvement --- Multiprotocol/AFHDS2A_a7105.ino | 3 +++ Multiprotocol/FrSkyX_cc2500.ino | 1 + Multiprotocol/Hisky_nrf24l01.ino | 1 + Multiprotocol/Multiprotocol.h | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Multiprotocol/AFHDS2A_a7105.ino b/Multiprotocol/AFHDS2A_a7105.ino index 7abc6de..066de46 100644 --- a/Multiprotocol/AFHDS2A_a7105.ino +++ b/Multiprotocol/AFHDS2A_a7105.ino @@ -336,7 +336,10 @@ uint16_t ReadAFHDS2A() { #ifdef FAILSAFE_ENABLE if(!(packet_counter % 1569) && IS_FAILSAFE_VALUES_on) + { packet_type = AFHDS2A_PACKET_FAILSAFE; + FAILSAFE_VALUES_off; + } else #endif packet_type = AFHDS2A_PACKET_STICKS; // todo : check for settings changes diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index fac223e..754b29d 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -138,6 +138,7 @@ static void __attribute__((unused)) FrSkyX_build_packet() { FS_flag = 0; failsafe_count = 0; + FAILSAFE_VALUES_off; } failsafe_count++; #endif diff --git a/Multiprotocol/Hisky_nrf24l01.ino b/Multiprotocol/Hisky_nrf24l01.ino index 4bbf413..504842b 100644 --- a/Multiprotocol/Hisky_nrf24l01.ino +++ b/Multiprotocol/Hisky_nrf24l01.ino @@ -160,6 +160,7 @@ uint16_t hisky_cb() convert_failsafe_HK310(CH5, &packet[4],&packet[5]); packet[7]=0xAA; packet[8]=0x5A; + FAILSAFE_VALUES_off; } else #endif diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 21f412b..39cd26a 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 38 +#define VERSION_PATCH_LEVEL 39 //****************** // Protocols From b07b081a153449e9ff6eb07f59d29a91fd8130ba Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 7 Nov 2019 11:13:48 +0100 Subject: [PATCH 57/65] HoTT telemetry size change --- Multiprotocol/HOTT_cc2500.ino | 6 +++--- Multiprotocol/Multiprotocol.h | 8 +++++--- Multiprotocol/Telemetry.ino | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index 60d67ad..59a6512 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -293,7 +293,7 @@ uint16_t ReadHOTT() { //Telemetry // [0..4] = TXID // [5..9] = RXID - // [10] = 0x40 bind, 0x00 normal + // [10] = 0x40 bind, 0x00 normal, 0x80 text menu // [11] = 0x0X telmetry page X=0,1,2,3,4 ? // Telem page 0 = 0x00, 0x33, 0x34, 0x46, 0x64, 0x33, 0x0A, 0x00, 0x00, 0x00 // = 0x55, 0x32, 0x38, 0x55, 0x64, 0x32, 0xD0, 0x07, 0x00, 0x55 @@ -314,9 +314,9 @@ uint16_t ReadHOTT() packet_in[0]= TX_RSSI; packet_in[1]= TX_LQI; debug("T="); - for(uint8_t i=11;i < HOTT_RX_PACKET_LEN; i++) + for(uint8_t i=10;i < HOTT_RX_PACKET_LEN; i++) { - packet_in[i-9]=packet_in[i]; + packet_in[i-8]=packet_in[i]; debug(" %02X",packet_in[i]); } debugln(""); diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 39cd26a..481e31b 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 39 +#define VERSION_PATCH_LEVEL 40 //****************** // Protocols @@ -978,9 +978,11 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- data[4-]= packed channels data, 11 bit per channel Type 0x0E HoTT telemetry - length: 13 + length: 14 data[0] = TX_RSSI data[1] = TX_LQI - data[2-12] = telemetry data + data[2] = type + data[3] = page + data[4-13] = data */ diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index d7ec899..bb197cb 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -308,11 +308,11 @@ static void multi_send_status() void HOTT_short_frame() { #if defined MULTI_TELEMETRY - multi_send_header(MULTI_TELEMETRY_HOTT, 13); + multi_send_header(MULTI_TELEMETRY_HOTT, 14); #else Serial_write(0xAA); // Telemetry packet #endif - for (uint8_t i = 0; i < 13; i++) // TX RSSI and TX LQI values followed by frame number and telemetry data + for (uint8_t i = 0; i < 14; i++) // TX RSSI and TX LQI values followed by frame number and telemetry data Serial_write(packet_in[i]); } #endif From 2686cd0c48167d10bdd8fadada7b2a879c1103d1 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sat, 9 Nov 2019 12:10:34 +0100 Subject: [PATCH 58/65] Scanner in blocking mode for best perf --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Scanner_cc2500.ino | 73 +++++++++++++++----------------- Multiprotocol/Telemetry.ino | 4 +- 3 files changed, 37 insertions(+), 42 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 481e31b..cd61eed 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 40 +#define VERSION_PATCH_LEVEL 41 //****************** // Protocols diff --git a/Multiprotocol/Scanner_cc2500.ino b/Multiprotocol/Scanner_cc2500.ino index 33725f2..fa7c416 100644 --- a/Multiprotocol/Scanner_cc2500.ino +++ b/Multiprotocol/Scanner_cc2500.ino @@ -18,13 +18,11 @@ #include "iface_cc2500.h" #define SCAN_MAX_RADIOCHANNEL 249 // 2483 MHz -#define SCAN_CHANNEL_LOCK_TIME 210 // with precalibration, channel requires only 90 usec for synthesizer to settle +#define SCAN_CHANNEL_LOCK_TIME 90 // with precalibration, channel requires only 90 usec for synthesizer to settle #define SCAN_AVERAGE_INTVL 20 #define SCAN_MAX_COUNT 10 #define SCAN_CHANS_PER_PACKET 5 -static uint8_t scan_tlm_index; - enum ScanStates { SCAN_CHANNEL_CHANGE = 0, SCAN_GET_RSSI = 1, @@ -97,49 +95,46 @@ static int __attribute__((unused)) Scanner_scan_rssi() uint16_t Scanner_callback() { - static uint8_t max_count, max_rssi; - uint8_t rssi; - switch (phase) - { - case SCAN_CHANNEL_CHANGE: - if(telemetry_link == 0) { - max_count = 0; - max_rssi = 0; - rf_ch_num++; - if (rf_ch_num >= (SCAN_MAX_RADIOCHANNEL + 1)) - rf_ch_num = 0; - if (scan_tlm_index++ == 0) - packet_in[0] = rf_ch_num; // start channel for telemetry packet - Scanner_scan_next(); - phase = SCAN_GET_RSSI; - } - return SCAN_CHANNEL_LOCK_TIME; - case SCAN_GET_RSSI: - rssi = Scanner_scan_rssi(); - if(rssi >= max_rssi) { - max_rssi = rssi; - packet_in[scan_tlm_index] = rssi; - } - max_count++; - if(max_count > SCAN_MAX_COUNT) { - phase = SCAN_CHANNEL_CHANGE; - if (scan_tlm_index == SCAN_CHANS_PER_PACKET) - { - // send data to TX - telemetry_link = 1; - scan_tlm_index = 0; - } + uint8_t rssi,max_rssi; + + //!!!Blocking mode protocol!!! + TX_MAIN_PAUSE_off; + tx_resume(); + while(1) + { //Start + packet_in[0] = rf_ch_num; // start channel for telemetry packet + for(uint8_t i=0;i= max_rssi) max_rssi = rssi; + delayMicroseconds(SCAN_AVERAGE_INTVL); // wait before next read } + packet_in[i+1] = max_rssi; + //next channel + rf_ch_num++; + if (rf_ch_num >= (SCAN_MAX_RADIOCHANNEL + 1)) + rf_ch_num = 0; + } + telemetry_link = 1; + do + { + if(Update_All()) + return 1000; // protocol has changed, give back the control to main + } + while(telemetry_link == 1); } - return SCAN_AVERAGE_INTVL; + return 0; } uint16_t initScanner(void) { - rf_ch_num = SCAN_MAX_RADIOCHANNEL; - scan_tlm_index = 0; + rf_ch_num = 0; telemetry_link = 0; - phase = SCAN_CHANNEL_CHANGE; Scanner_cc2500_init(); CC2500_Strobe(CC2500_SRX); Scanner_calibrate(); diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index bb197cb..edc6511 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -836,7 +836,7 @@ void TelemetryUpdate() t -= h ; if ( t < 32 ) { - //debugln("TEL_BUF_FULL %d",t); + debugln("TEL_BUF_FULL %d",t); return ; } /* else @@ -846,7 +846,7 @@ void TelemetryUpdate() #endif #if defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) uint32_t now = millis(); - if (IS_SEND_MULTI_STATUS_on || ((now - lastMulti) > MULTI_TIME)) + if ((IS_SEND_MULTI_STATUS_on || ((now - lastMulti) > MULTI_TIME))&& protocol != PROTO_SCANNER) { multi_send_status(); SEND_MULTI_STATUS_off; From 1621263fb0c3149791f23042326ebeecdd1a61fe Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sat, 9 Nov 2019 12:10:56 +0100 Subject: [PATCH 59/65] HoTT telem doc update --- Multiprotocol/HOTT_cc2500.ino | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index 59a6512..e3f3cea 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -149,8 +149,8 @@ static void __attribute__((unused)) HOTT_init() } else { - packet[28] = 0x8C; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets - packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets, 0x0A->no more RX telemetry + packet[28] = 0x8C; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets, 0x0F->config menu + packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets, 0x01->config menu, 0x0A->no more RX telemetry memcpy(&packet[40],rx_tx_addr,5); uint8_t addr=HOTT_EEPROM_OFFSET+RX_num*5; @@ -293,24 +293,31 @@ uint16_t ReadHOTT() { //Telemetry // [0..4] = TXID // [5..9] = RXID - // [10] = 0x40 bind, 0x00 normal, 0x80 text menu - // [11] = 0x0X telmetry page X=0,1,2,3,4 ? - // Telem page 0 = 0x00, 0x33, 0x34, 0x46, 0x64, 0x33, 0x0A, 0x00, 0x00, 0x00 + // [10] = 0x40 bind, 0x00 normal, 0x80 config menu + // [11] = telmetry pages. For sensors 0x00 to 0x04, for config mennu 0x00 to 0x12. + // Normal telem page 0 = 0x00, 0x33, 0x34, 0x46, 0x64, 0x33, 0x0A, 0x00, 0x00, 0x00 // = 0x55, 0x32, 0x38, 0x55, 0x64, 0x32, 0xD0, 0x07, 0x00, 0x55 - // Page 0 [12] = [21] = ?? - // Page 0 [13] = RX_Voltage*10 in V - // Page 0 [14] = Temperature-20 in °C - // Page 0 [15] = RX_RSSI - // Page 0 [16] = RX_LQI ?? - // Page 0 [17] = RX_STR ?? - // Page 0 [18,19] = [19]*256+[18]=max lost packet time in ms, max value seems 2s=0x7D0 - // Page 0 [20] = 0x00 ?? + // Page 0 [12] = [21] = ?? + // Page 0 [13] = RX_Voltage*10 in V + // Page 0 [14] = Temperature-20 in °C + // Page 0 [15] = RX_RSSI + // Page 0 [16] = RX_LQI ?? + // Page 0 [17] = RX_STR ?? + // Page 0 [18,19] = [19]*256+[18]=max lost packet time in ms, max value seems 2s=0x7D0 + // Page 0 [20] = 0x00 ?? + // Config menu consists of the different telem pages put all together + // Page X [12] = seems like all the telem pages with the same value are going together to make the full config menu text. Seen so far 'a', 'b', 'c', 'd' + // Page X [13..21] = 9 ascii chars to be displayed, char is highlighted when ascii|0x80 + // Screen display is 21 characters large which means that once the first 21 chars are filled go to the begining of the next line + // Menu commands are sent through TX packets: + // packet[28]= 0xXF=>no key press, 0xXD=>down, 0xXB=>up, 0xX9=>enter, 0xXE=>right, 0xX7=>left with X=0 or D + // packet[29]= 0xX1/0xX9 with X=0 or X counting 0,1,1,2,2,..,9,9 TX_RSSI = packet_in[22]; if(TX_RSSI >=128) TX_RSSI -= 128; else TX_RSSI += 128; - // Reduce telemetry to 13 bytes + // Reduce telemetry to 14 bytes packet_in[0]= TX_RSSI; packet_in[1]= TX_LQI; debug("T="); From dad3282bbb2a56d76455c01337180152e7af4854 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sat, 9 Nov 2019 19:26:31 +0100 Subject: [PATCH 60/65] XN297Dump RF channel display --- Multiprotocol/Multi_Names.ino | 3 ++- Multiprotocol/Multiprotocol.h | 3 ++- Multiprotocol/XN297Dump_nrf24l01.ino | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Multiprotocol/Multi_Names.ino b/Multiprotocol/Multi_Names.ino index 83bebf9..98b3573 100644 --- a/Multiprotocol/Multi_Names.ino +++ b/Multiprotocol/Multi_Names.ino @@ -119,6 +119,7 @@ enum OPTION_TELEM, OPTION_SRVFREQ, OPTION_MAXTHR, + OPTION_RFCHAN }; #define NO_SUBTYPE nullptr @@ -294,7 +295,7 @@ const mm_protocol_definition multi_protocols[] = { {PROTO_HOTT, STR_HOTT, 0, NO_SUBTYPE, OPTION_RFTUNE }, #endif #if defined(XN297DUMP_NRF24L01_INO) - {PROTO_XN297DUMP, STR_XN297DUMP, 3, STR_SUBTYPE_XN297DUMP, OPTION_NONE }, + {PROTO_XN297DUMP, STR_XN297DUMP, 3, STR_SUBTYPE_XN297DUMP, OPTION_RFCHAN }, #endif {0x00, nullptr, 0, nullptr, 0 } }; diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index cd61eed..02964db 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 41 +#define VERSION_PATCH_LEVEL 42 //****************** // Protocols @@ -913,6 +913,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- OPTION_TELEM 5 OPTION_SRVFREQ 6 OPTION_MAXTHR 7 + OPTION_RFCHAN 8 [19&0x0F] Number of sub protocols [20..27] Sub protocol name [8], not null terminated if sub prototcol len == 8 diff --git a/Multiprotocol/XN297Dump_nrf24l01.ino b/Multiprotocol/XN297Dump_nrf24l01.ino index 2ff6033..7c07918 100644 --- a/Multiprotocol/XN297Dump_nrf24l01.ino +++ b/Multiprotocol/XN297Dump_nrf24l01.ino @@ -176,6 +176,10 @@ static void __attribute__((unused)) XN297Dump_overflow() static uint16_t XN297Dump_callback() { static uint32_t time=0; + + //!!!Blocking mode protocol!!! + TX_MAIN_PAUSE_off; + tx_resume(); while(1) { if(option==0xFF && bind_counter>XN297DUMP_PERIOD_SCAN) From c83b769f28e85aeed9cf1ceac72b565c9228d4b7 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 10 Nov 2019 09:25:42 +0100 Subject: [PATCH 61/65] Update Multiprotocol.ino --- Multiprotocol/Multiprotocol.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 3783926..f517db9 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -618,7 +618,7 @@ void loop() if(diff>900*2) { //If at least 1ms is available update values if((diff&0x8000) && !(next_callback&0x8000)) - {//Should never get here but it is... + {//Should never get here... debugln("!!!BUG!!!"); break; } @@ -695,7 +695,7 @@ bool Update_All() #if ( !( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) ) if( (protocol == PROTO_FRSKY_RX) || (protocol == PROTO_SCANNER) || (protocol==PROTO_FRSKYD) || (protocol==PROTO_BAYANG) || (protocol==PROTO_NCC1701) || (protocol==PROTO_BUGS) || (protocol==PROTO_BUGSMINI) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_FRSKYX) || (protocol==PROTO_DSM) || (protocol==PROTO_CABELL) || (protocol==PROTO_HITEC) || (protocol==PROTO_HOTT)) #endif - if(IS_DISABLE_TELEM_off && !(protocol==PROTO_XN297DUMP)) + if(IS_DISABLE_TELEM_off) TelemetryUpdate(); #endif #ifdef ENABLE_BIND_CH From 0e40f64c6b95467254533ac9fd92f4552892c236 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 10 Nov 2019 18:55:03 +0100 Subject: [PATCH 62/65] Enable HoTT RX config menu Use OpenTX lua script --- Multiprotocol/HOTT_cc2500.ino | 18 ++++++++++++++++++ Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Multiprotocol.ino | 14 ++++++++++++++ Protocols_Details.md | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index e3f3cea..d82f410 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -211,6 +211,20 @@ static void __attribute__((unused)) HOTT_data_packet() packet[i+1] = val>>8; } + #ifdef HOTT_FW_TELEMETRY + if(HoTT_SerialRX && HoTT_SerialRX_val >= 0xD7 && HoTT_SerialRX_val <= 0xDF) + { + packet[28] = HoTT_SerialRX_val; // 0xDX->config menu + packet[29] = 0x01; // 0x01->config menu + HoTT_SerialRX_val = 0xDF; // no touch pressed + } + else + { + packet[28] = 0x8C; // unknown 0x80 when bind starts then when RX replies start normal, 0x89/8A/8B/8C/8D/8E during normal packets, 0x0F->config menu + packet[29] = 0x02; // unknown 0x02 when bind starts then when RX replies cycle in sequence 0x1A/22/2A/0A/12, 0x02 during normal packets, 0x01->config menu, 0x0A->no more RX telemetry + } + #endif + CC2500_SetTxRxMode(TX_EN); CC2500_SetPower(); CC2500_WriteReg(CC2500_06_PKTLEN, 0x32); @@ -354,6 +368,10 @@ uint16_t initHOTT() HOTT_init(); HOTT_rf_init(); packet_count=0; + #ifdef HOTT_FW_TELEMETRY + HoTT_SerialRX_val=0; + HoTT_SerialRX=false; + #endif phase = HOTT_START; return 10000; } diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 02964db..15a1152 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 0 -#define VERSION_PATCH_LEVEL 42 +#define VERSION_PATCH_LEVEL 43 //****************** // Protocols diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index f517db9..789292b 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -243,6 +243,10 @@ uint8_t packet_in[TELEMETRY_BUFFER_SIZE];//telemetry receiving packets extern const mm_protocol_definition multi_protocols[]; uint8_t multi_protocols_index=0xFF; #endif + #ifdef HOTT_FW_TELEMETRY + uint8_t HoTT_SerialRX_val=0; + bool HoTT_SerialRX=false; + #endif #endif // TELEMETRY // Callback @@ -1682,6 +1686,9 @@ void update_serial_data() Channel_data[i]=temp; //value range 0..2047, 0=-125%, 2047=+125% } + #ifdef HOTT_FW_TELEMETRY + HoTT_SerialRX=false; + #endif if(rx_len>27) { // Data available for the current protocol #ifdef SPORT_SEND @@ -1720,6 +1727,13 @@ void update_serial_data() } } #endif //SPORT_SEND + #ifdef HOTT_FW_TELEMETRY + if(protocol==PROTO_HOTT && rx_len==28) + {//Protocol waiting for 1 byte + HoTT_SerialRX_val=rx_ok_buff[27]; + HoTT_SerialRX=true; + } + #endif } RX_DONOTUPDATE_off; diff --git a/Protocols_Details.md b/Protocols_Details.md index a008e4f..91c1bf0 100644 --- a/Protocols_Details.md +++ b/Protocols_Details.md @@ -417,7 +417,7 @@ Extended limits and failsafe supported **Failsafe MUST be configured once with the desired channel values (hold or position) while the RX is up (wait 10+sec for the RX to learn the config) and then failsafe MUST be set to RX/Receiver otherwise the servos will jitter!!!** -**The RX features must be configured first on a Graupner radio before binding it with Multi (RX config not implemented).** +The RX features configuration are done using the OpenTX script "Graupner HoTT.lua" . Option for this protocol corresponds to fine frequency tuning. This value is different for each Module and **must** be accurate otherwise the link will not be stable. Check the [Frequency Tuning page](/docs/Frequency_Tuning.md) to determine it. From 6a03972ff3142ba44db17dd7431f86ae66b31b93 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Sun, 10 Nov 2019 19:34:31 +0100 Subject: [PATCH 63/65] Update Protocols_Details.md --- Protocols_Details.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Protocols_Details.md b/Protocols_Details.md index 91c1bf0..c859a38 100644 --- a/Protocols_Details.md +++ b/Protocols_Details.md @@ -415,6 +415,8 @@ Models: Graupner HoTT receivers (tested on GR-12L and GR-16L). Extended limits and failsafe supported +**RX_Num is used to give a number a given RX. You must use a different RX_Num per RX. A maximum of 64 HoTT RXs are supported.** + **Failsafe MUST be configured once with the desired channel values (hold or position) while the RX is up (wait 10+sec for the RX to learn the config) and then failsafe MUST be set to RX/Receiver otherwise the servos will jitter!!!** The RX features configuration are done using the OpenTX script "Graupner HoTT.lua" . From 0afed7d3a49a2e96c7938559b9f25c1abf3fc4e5 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 11 Nov 2019 15:36:39 +0100 Subject: [PATCH 64/65] Fix HoTT menu for internal module --- Multiprotocol/HOTT_cc2500.ino | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Multiprotocol/HOTT_cc2500.ino b/Multiprotocol/HOTT_cc2500.ino index d82f410..0d7498f 100644 --- a/Multiprotocol/HOTT_cc2500.ino +++ b/Multiprotocol/HOTT_cc2500.ino @@ -212,11 +212,17 @@ static void __attribute__((unused)) HOTT_data_packet() } #ifdef HOTT_FW_TELEMETRY + static uint8_t prev_SerialRX_val=0; if(HoTT_SerialRX && HoTT_SerialRX_val >= 0xD7 && HoTT_SerialRX_val <= 0xDF) { - packet[28] = HoTT_SerialRX_val; // 0xDX->config menu + if(prev_SerialRX_val!=HoTT_SerialRX_val) + { + prev_SerialRX_val=HoTT_SerialRX_val; + packet[28] = HoTT_SerialRX_val; // send the touch being pressed only once + } + else + packet[28] = 0xDF; // no touch pressed packet[29] = 0x01; // 0x01->config menu - HoTT_SerialRX_val = 0xDF; // no touch pressed } else { From 712f297d86382a358e54068620b5aa229fdca702 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 11 Nov 2019 17:19:27 +0100 Subject: [PATCH 65/65] Update _Config.h --- Multiprotocol/_Config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 8afbd91..360c658 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -284,8 +284,8 @@ #define MULTI_TELEMETRY //Send to OpenTX the current protocol and subprotocol names. Comment to disable. #define MULTI_NAMES -//Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Comment to disable. -#define MULTI_SYNC +//Work in progress: Sync OpenTX frames with the current protocol timing. This feature is only available on the STM32 module. Uncomment to enable. +//#define MULTI_SYNC //Comment a line to disable a specific protocol telemetry #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded by er9x, erskyTX and OpenTX