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.