diff --git a/Multiprotocol/Multi_Protos.ino b/Multiprotocol/Multi_Protos.ino index 242f4a7..53a6703 100644 --- a/Multiprotocol/Multi_Protos.ino +++ b/Multiprotocol/Multi_Protos.ino @@ -138,7 +138,7 @@ 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_HEIGHT[] = "\x03""5ch""8ch"; +const char STR_SUBTYPE_HEIGHT[] = "\x03""5ch""8ch"; const char STR_SUBTYPE_FX816[] = "\x03""P38"; const char STR_SUBTYPE_XN297DUMP[] = "\x07""250Kbps""1Mbps\0 ""2Mbps\0 ""Auto\0 ""NRF\0 ""CC2500\0"; const char STR_SUBTYPE_ESKY150[] = "\x03""4ch""7ch"; @@ -470,3 +470,70 @@ const mm_protocol_definition multi_protocols[] = { #endif {0xFF, nullptr, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr } }; + +#ifdef TELEMETRY +uint16_t PROTOLIST_callback() +{ + if(option != prev_option) + {//Only send once + /* Type 0x11 Protocol list export via telemetry. Used by the protocol PROTO_PROTOLIST=0, the list entry is given by the option field. + length: variable + data[0] = protocol number, 0xFF is an invalid list entry (Option value too large) + data[1..n] = protocol name null terminated + data[n+1] = flags + flags>>4 Option text number to be displayed (check multi status for description) + flags&0x01 failsafe supported + flags&0x02 Channel Map Disabled supported + data[n+2] = number of sub protocols + data[n+3] = sub protocols text length, only sent if nbr_sub != 0 + data[n+4..] = sub protocol names, only sent if nbr_sub != 0 + */ + prev_option = option; + + if(option >= (sizeof(multi_protocols)/sizeof(mm_protocol_definition)) - 1) + {//option is above the end of the list + //Header + multi_send_header(MULTI_TELEMETRY_PROTO, 1); + //Error + Serial_write(0xFF); + } + else + {//valid option value + uint8_t proto_len = strlen(multi_protocols[option].ProtoString) + 1; + uint8_t nbr_sub = multi_protocols[option].nbrSubProto; + uint8_t sub_len = 0; + if(nbr_sub) + sub_len = multi_protocols[option].SubProtoString[0]; + + //Header + multi_send_header(MULTI_TELEMETRY_PROTO, 1 + proto_len + 1 + 1 + (nbr_sub?1:0) + (nbr_sub * sub_len)); + //Protocol number + Serial_write(multi_protocols[option].protocol); + //Protocol name + for(uint8_t i=0;iA7105 PROTO_HUBSAN = 2, // =>A7105 PROTO_FRSKYD = 3, // =>CC2500 @@ -517,6 +518,7 @@ enum MultiPacketTypes MULTI_TELEMETRY_HOTT = 14, MULTI_TELEMETRY_MLINK = 15, MULTI_TELEMETRY_CONFIG = 16, + MULTI_TELEMETRY_PROTO = 17, }; // Macros @@ -1289,4 +1291,17 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- Type 0x10 Config telemetry length: 22 data[0..21] = Config data + + Type 0x11 Protocol list export via telemetry. Used by the protocol PROTO_PROTOLIST=0, the list entry is given by the option field. + length: variable + data[0] = protocol number, 0xFF is an invalid list entry (Option value too large) + data[1..n] = protocol name null terminated + data[n+1] = flags + flags>>4 Option text number to be displayed (check multi status for description) + flags&0x01 failsafe supported + flags&0x02 Channel Map Disabled supported + data[n+2] = number of sub protocols + data[n+3] = sub protocols text length, only sent if nbr_sub != 0 + data[n+4..] = sub protocol names, only sent if nbr_sub != 0 + */ diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 835ce29..7e2161e 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -1134,18 +1134,18 @@ static void protocol_init() if(IS_WAIT_BIND_off) { remote_callback = 0; // No protocol - LED_off; // Led off during protocol init modules_reset(); // Reset all modules + LED_off; // Led off during protocol init crc16_polynomial = 0x1021; // Default CRC crc16_polynomial crc8_polynomial = 0x31; // Default CRC crc8_polynomial prev_option = option; + multi_protocols_index = 0xFF; // reset telemetry #ifdef TELEMETRY #ifdef MULTI_SYNC inputRefreshRate = 0; // Don't do it unless the protocol asks for it #endif - multi_protocols_index = 0xFF; tx_pause(); init_frskyd_link_telemetry(); pps_timer=millis(); @@ -1167,7 +1167,7 @@ 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) || defined(BAYANG_RX_NRF24L01_INO) + #if defined(AFHDS2A_RX_A7105_INO) || defined(FRSKY_RX_CC2500_INO) || defined(BAYANG_RX_NRF24L01_INO) || defined(DSM_RX_CYRF6936_INO) for(uint8_t ch=0; ch<16; ch++) rx_rc_chan[ch] = 1024; #endif @@ -1188,54 +1188,69 @@ static void protocol_init() #endif DATA_BUFFER_LOW_off; - SUB_PROTO_VALID; + SUB_PROTO_INVALID; option_override = 0xFF; blink=millis(); debugln("Protocol selected: %d, sub proto %d, rxnum %d, option %d", protocol, sub_protocol, RX_num, option); - uint8_t index=0; - #if defined(FRSKYX_CC2500_INO) && defined(EU_MODULE) - if( ! ( (protocol == PROTO_FRSKYX || protocol == PROTO_FRSKYX2) && sub_protocol < 2 ) ) - #endif - while(multi_protocols[index].protocol != 0xFF) + if(protocol) { - if(multi_protocols[index].protocol==protocol) + uint8_t index=0; + #if defined(FRSKYX_CC2500_INO) && defined(EU_MODULE) + if( ! ( (protocol == PROTO_FRSKYX || protocol == PROTO_FRSKYX2) && sub_protocol < 2 ) ) + #endif + while(multi_protocols[index].protocol != 0xFF) { - //Save index - multi_protocols_index = index; - //Set the RF switch - rf_switch(multi_protocols[multi_protocols_index].rfSwitch); - //Init protocol - multi_protocols[multi_protocols_index].Init(); - //Save call back function address - remote_callback = multi_protocols[multi_protocols_index].CallBack; - //Send a telemetry status right now - #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)SR = 0x1E5F & ~TIMER_SR_CC1IF; // Clear Timer2/Comp1 interrupt flag - #endif - sei(); // enable global int - BIND_BUTTON_FLAG_off; // do not bind/reset id anymore even if protocol change + if(protocol) + { + //Wait 5ms after protocol init + cli(); // disable global int + OCR1A = TCNT1 + 5000*2; // set compare A for callback + #ifndef STM32_BOARD + TIFR1 = OCF1A_bm ; // clear compare A flag + #else + TIMER2_BASE->SR = 0x1E5F & ~TIMER_SR_CC1IF; // Clear Timer2/Comp1 interrupt flag + #endif + sei(); // enable global int + BIND_BUTTON_FLAG_off; // do not bind/reset id anymore even if protocol change + } } void update_serial_data() diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 4cf014e..4ce8558 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -123,45 +123,32 @@ static void telemetry_set_input_sync(uint16_t refreshRate) static void multi_send_status() { + if(protocol == 0) return; + multi_send_header(MULTI_TELEMETRY_STATUS, 24); // Build flags uint8_t flags=0; - if (IS_INPUT_SIGNAL_on) + if(IS_INPUT_SIGNAL_on) flags |= 0x01; - if (mode_select==MODE_SERIAL) + if(mode_select==MODE_SERIAL) flags |= 0x02; - if (remote_callback != 0) + if(remote_callback != 0) { - flags |= 0x04; - if(multi_protocols_index == 0xFF) - { - if(protocol!=PROTO_SCANNER) - flags &= ~0x04; //Invalid protocol - } - else if(IS_SUB_PROTO_INVALID) - { - flags &= ~0x04; //Invalid sub protocol - } - else if(sub_protocol&0x07) - { - uint8_t nbr=multi_protocols[multi_protocols_index].nbrSubProto; - //if(protocol==PROTO_DSM) nbr++; //Auto sub_protocol - if((sub_protocol&0x07)>=nbr ) - flags &= ~0x04; //Invalid sub protocol - } - if (IS_WAIT_BIND_on) + if(multi_protocols_index != 0xFF && IS_SUB_PROTO_VALID) + flags |= 0x04; //Invalid protocol / sub protocol, can't make the distinction since there is no more flags... + if(IS_WAIT_BIND_on) flags |= 0x10; else - if (IS_BIND_IN_PROGRESS) + if(IS_BIND_IN_PROGRESS) flags |= 0x08; if(multi_protocols_index != 0xFF) { if(multi_protocols[multi_protocols_index].chMap) - flags |= 0x40; //Disable_ch_mapping supported + flags |= 0x40; //Disable_ch_mapping supported #ifdef FAILSAFE_ENABLE if(multi_protocols[multi_protocols_index].failSafe) - flags |= 0x20; //Failsafe supported + flags |= 0x20; //Failsafe supported #endif } if(IS_DATA_BUFFER_LOW_on) @@ -226,7 +213,7 @@ static void multi_send_status() else Serial_write(nbr | (option_override<<4)); // number of sub protocols && option_override type uint8_t j=0; - if(nbr && (sub_protocol&0x07)