mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 18:48:11 +00:00
New 0 protocol: enable to list all protocols and sub protocols
This commit is contained in:
parent
016b282246
commit
5c00ce6b88
@ -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;i<proto_len;i++)
|
||||
Serial_write(multi_protocols[option].ProtoString[i]);
|
||||
//Flags
|
||||
uint8_t flags=0;
|
||||
#ifdef FAILSAFE_ENABLE
|
||||
if(multi_protocols[multi_protocols_index].failSafe)
|
||||
flags |= 0x01; //Failsafe supported
|
||||
#endif
|
||||
if(multi_protocols[multi_protocols_index].chMap)
|
||||
flags |= 0x02; //Disable_ch_mapping supported
|
||||
Serial_write( flags | (multi_protocols[option].optionType<<4)); // flags && option type
|
||||
//Number of sub protocols
|
||||
Serial_write(nbr_sub);
|
||||
|
||||
if(nbr_sub !=0 )
|
||||
{
|
||||
//Sub protocols texts length
|
||||
Serial_write(sub_len);
|
||||
//Sub protocols texts
|
||||
for(uint8_t i=1;i<nbr_sub*sub_len;i++)
|
||||
Serial_write(multi_protocols[option].SubProtoString[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1000;
|
||||
}
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_REVISION 2
|
||||
#define VERSION_PATCH_LEVEL 97
|
||||
#define VERSION_PATCH_LEVEL 98
|
||||
|
||||
#define MODE_SERIAL 0
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
//******************
|
||||
enum PROTOCOLS
|
||||
{
|
||||
PROTO_PROTOLIST = 0, // NO RF
|
||||
PROTO_FLYSKY = 1, // =>A7105
|
||||
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
|
||||
|
||||
*/
|
||||
|
@ -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)<nbr)
|
||||
{
|
||||
uint8_t len=multi_protocols[multi_protocols_index].SubProtoString[0];
|
||||
uint8_t offset=len*(sub_protocol&0x07)+1;
|
||||
for(uint8_t j=0;j<len;j++)
|
||||
debug("%c",multi_protocols[multi_protocols_index].SubProtoString[j+offset]);
|
||||
if(multi_protocols[index].protocol==protocol)
|
||||
{
|
||||
//Save index
|
||||
multi_protocols_index = index;
|
||||
//Check sub protocol validity
|
||||
if( ((sub_protocol&0x07) == 0) || (sub_protocol&0x07) < multi_protocols[index].nbrSubProto )
|
||||
SUB_PROTO_VALID;
|
||||
if(IS_SUB_PROTO_VALID)
|
||||
{//Start the protocol
|
||||
//Set the RF switch
|
||||
rf_switch(multi_protocols[index].rfSwitch);
|
||||
//Init protocol
|
||||
multi_protocols[index].Init(); // Init could invalidate the sub proto in case it is not suuported
|
||||
if(IS_SUB_PROTO_VALID)
|
||||
remote_callback = multi_protocols[index].CallBack; //Save call back function address
|
||||
}
|
||||
debug(", Opt=%d",multi_protocols[multi_protocols_index].optionType);
|
||||
debug(", FS=%d",multi_protocols[multi_protocols_index].failSafe);
|
||||
debug(", CHMap=%d",multi_protocols[multi_protocols_index].chMap);
|
||||
debugln(", rfSw=%d",multi_protocols[multi_protocols_index].rfSwitch);
|
||||
#endif
|
||||
break;
|
||||
#ifdef DEBUG_SERIAL
|
||||
debug("Proto=%s", multi_protocols[index].ProtoString);
|
||||
debug(", nbr_sub=%d, Sub=", multi_protocols[index].nbrSubProto);
|
||||
if(IS_SUB_PROTO_VALID)
|
||||
{
|
||||
uint8_t len=multi_protocols[index].SubProtoString[0];
|
||||
uint8_t offset=len*(sub_protocol&0x07)+1;
|
||||
for(uint8_t j=0;j<len;j++)
|
||||
debug("%c",multi_protocols[index].SubProtoString[j+offset]);
|
||||
}
|
||||
debug(", Opt=%d",multi_protocols[index].optionType);
|
||||
debug(", FS=%d",multi_protocols[index].failSafe);
|
||||
debug(", CHMap=%d",multi_protocols[index].chMap);
|
||||
debugln(", rfSw=%d",multi_protocols[index].rfSwitch);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
index++;
|
||||
//Send a telemetry status right now
|
||||
SEND_MULTI_STATUS_on;
|
||||
Update_Telem();
|
||||
}
|
||||
//Send an update right away
|
||||
SEND_MULTI_STATUS_on;
|
||||
Update_Telem();
|
||||
#ifdef TELEMETRY
|
||||
else
|
||||
{//protocol=PROTO_PROTOLIST=0
|
||||
remote_callback = PROTOLIST_callback;
|
||||
prev_option = option + 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if defined(WAIT_FOR_BIND) && defined(ENABLE_BIND_CH)
|
||||
if( IS_AUTOBIND_FLAG_on && IS_BIND_CH_PREV_off && (cur_protocol[1]&0x80)==0 && mode_select == MODE_SERIAL)
|
||||
{ // Autobind is active but no bind requested by either BIND_CH or BIND. But do not wait if in PPM mode...
|
||||
@ -1246,16 +1261,19 @@ static void protocol_init()
|
||||
WAIT_BIND_off;
|
||||
CHANGE_PROTOCOL_FLAG_off;
|
||||
|
||||
//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
|
||||
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()
|
||||
|
@ -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)<nbr)
|
||||
if(IS_SUB_PROTO_VALID)
|
||||
{
|
||||
uint8_t len=multi_protocols[multi_protocols_index].SubProtoString[0];
|
||||
uint8_t offset=len*(sub_protocol&0x07)+1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user