New protocol XK

Still work in progress
Subprotocols: X450 and X420 -> not sure if they are subprotocols or just different IDs...
CH5: M-Mode=-100%, 6G-Mode=0%, V-Mode=+100%
CH6: Take off momentary switch
CH7: Emergency stop momentary switch
CH8: 3D/6G momentary switch
CH9: Photo momentary switch
This commit is contained in:
pascallanger 2020-01-14 12:19:12 +01:00
parent 9f721c528d
commit 492b9e5ed4
8 changed files with 213 additions and 4 deletions

View File

@ -285,7 +285,7 @@ uint16_t BAYANG_callback()
switch(phase)
{
case BAYANG_BIND:
if (bind_counter-- == 0)
if (--bind_counter == 0)
{
XN297_SetTXAddr(rx_tx_addr, BAYANG_ADDRESS_LENGTH);
#ifdef BAYANG_HUB_TELEMETRY
@ -326,7 +326,6 @@ uint16_t BAYANG_callback()
while ((uint16_t)((uint16_t)micros()-(uint16_t)start) < 1000) // Wait max 1ms
if((NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS)))
break;
debugln("time: %d",(uint16_t)((uint16_t)micros()-(uint16_t)start));
NRF24L01_WriteReg(NRF24L01_00_CONFIG, 0x03);
phase++; // READ
return BAYANG_PACKET_TELEM_PERIOD - BAYANG_CHECK_DELAY - BAYANG_READ_DELAY;

View File

@ -43,7 +43,7 @@
43,Traxxas,RX6519
44,NCC1701
45,E01X,E012,E015,E016H
46,V911S
46,V911S,Std
47,GD00X,GD_V1,GD_V2
48,V761
49,KF606
@ -59,4 +59,5 @@
59,Bayang_RX
60,Pelikan
61,Tiger
62,XK,X450,X420
63,XN_DUMP,250K,1M,2M,AUTO

View File

@ -75,6 +75,7 @@ const char STR_FX816[] ="FX816";
const char STR_BAYANG_RX[] ="BayanRX";
const char STR_PELIKAN[] ="Pelikan";
const char STR_TIGER[] ="Tiger";
const char STR_XK[] ="XK";
const char STR_XN297DUMP[] ="XN297DP";
const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20";
@ -115,6 +116,7 @@ const char STR_SUBTYPE_FX816[] = "\x03""P38";
const char STR_SUBTYPE_XN297DUMP[] = "\x07""250Kbps""1Mbps\0 ""2Mbps\0 ""Auto\0 ";
const char STR_SUBTYPE_ESKY150[] = "\x03""4CH""7CH";
const char STR_SUBTYPE_V911S[] = "\x04""Std\0""E119";
const char STR_SUBTYPE_XK[] = "\x04""X450""X420";
enum
{
@ -313,6 +315,9 @@ const mm_protocol_definition multi_protocols[] = {
#if defined(TIGER_NRF24L01_INO)
{PROTO_TIGER, STR_TIGER , 0, NO_SUBTYPE, OPTION_NONE },
#endif
#if defined(XK_NRF24L01_INO)
{PROTO_XK, STR_XK , 2, STR_SUBTYPE_XK, OPTION_RFTUNE },
#endif
#if defined(XN297DUMP_NRF24L01_INO)
{PROTO_XN297DUMP, STR_XN297DUMP, 4, STR_SUBTYPE_XN297DUMP, OPTION_RFCHAN },
#endif

View File

@ -19,7 +19,7 @@
#define VERSION_MAJOR 1
#define VERSION_MINOR 3
#define VERSION_REVISION 0
#define VERSION_PATCH_LEVEL 56
#define VERSION_PATCH_LEVEL 57
//******************
// Protocols
@ -88,6 +88,7 @@ enum PROTOCOLS
PROTO_BAYANG_RX = 59, // =>NRF24L01
PROTO_PELIKAN = 60, // =>A7105
PROTO_TIGER = 61, // =>NRF24L01
PROTO_XK = 62, // =>NRF24L01
PROTO_XN297DUMP = 63, // =>NRF24L01
};
@ -305,6 +306,11 @@ enum V911S
V911S_STD = 0,
V911S_E119 = 1,
};
enum XK
{
X450 = 0,
X420 = 1,
};
enum XN297DUMP
{
XN297DUMP_250K = 0,
@ -703,6 +709,8 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
BAYANG_RX 59
PELIKAN 60
TIGER 61
XK 62
XN297DUMP 63
BindBit=> 0x80 1=Bind/0=No
AutoBindBit=> 0x40 1=Yes /0=No
RangeCheck=> 0x20 1=Yes /0=No
@ -850,6 +858,12 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
sub_protocol==V911S
V911S_STD 0
V911S_E119 1
sub_protocol==XK
X450 0
X420 1
sub_protocol==V911S
V911S_STD 0
V911S_E119 1
Power value => 0x80 0=High/1=Low
Stream[3] = option_protocol;

View File

@ -1478,6 +1478,12 @@ static void protocol_init()
remote_callback = TIGER_callback;
break;
#endif
#if defined(XK_NRF24L01_INO)
case PROTO_XK:
next_callback=initXK();
remote_callback = XK_callback;
break;
#endif
#if defined(XN297DUMP_NRF24L01_INO)
case PROTO_XN297DUMP:
next_callback=initXN297Dump();

View File

@ -248,6 +248,7 @@
#undef ZSX_NRF24L01_INO
#undef BAYANG_RX_NRF24L01_INO
#undef TIGER_NRF24L01_INO
#undef XK_NRF24L01_INO
#endif
//Make sure telemetry is selected correctly

View File

@ -0,0 +1,179 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
// Compatible with X450 and X420 plane.
#if defined(XK_NRF24L01_INO)
#include "iface_xn297l.h"
#define FORCE_XK_ORIGINAL_ID
#define XK_INITIAL_WAIT 500
#define XK_PACKET_PERIOD 4000
#define XK_RF_BIND_NUM_CHANNELS 8
#define XK_RF_NUM_CHANNELS 4
#define XK_PAYLOAD_SIZE 16
#define XK_BIND_COUNT 750 //3sec
static uint16_t __attribute__((unused)) XK_convert_channel(uint8_t num)
{
uint16_t val=convert_channel_10b(num);
// 1FF..01=left, 00=center, 200..3FF=right
if(val==0x200)
val=0; // 0
else
if(val>0x200)
val--; // 200..3FE
else
{
val=0x200-val; // 200..01
if(val==0x200)
val--; // 1FF..01
}
return val;
}
static void __attribute__((unused)) XK_send_packet()
{
memset(packet,0x00,16);
memcpy(&packet[7],rx_tx_addr,3);
packet[12]=0x40;
packet[13]=0x40;
if(IS_BIND_IN_PROGRESS)
packet[14] = 0xC0;
else
{
uint16_t val=convert_channel_10b(THROTTLE);
packet[0] = val>>2; // 0..255
packet[12] |= val & 2;
val=XK_convert_channel(RUDDER);
packet[1] = val>>2;
packet[12] |= (val & 2)<<2;
val=XK_convert_channel(ELEVATOR);
packet[2] = val>>2;
packet[13] |= val & 2;
val=XK_convert_channel(AILERON);
packet[3] = val>>2;
packet[13] |= (val & 2)<<2;
memset(&packet[4],0x40,3); // Trims
if(Channel_data[CH5] > CHANNEL_MAX_COMMAND)
packet[10] = 0x10; // V-Mode
else
if(Channel_data[CH5] > CHANNEL_MIN_COMMAND)
packet[10] = 0x04; // 6G-Mode
//0x00 default M-Mode
packet[10] |= GET_FLAG(CH7_SW,0x80); // Emergency stop momentary switch
packet[11] = GET_FLAG(CH8_SW,0x03) // 3D/6G momentary switch
|GET_FLAG(CH6_SW,0x40); // Take off momentary switch
packet[14] = GET_FLAG(CH9_SW,0x01); // Photo momentary switch
}
crc=packet[0];
for(uint8_t i=1; i<XK_PAYLOAD_SIZE-1;i++)
crc+=packet[i];
packet[15]=crc;
//debug("C: %02X, P:",hopping_frequency[(IS_BIND_IN_PROGRESS?0:XK_RF_BIND_NUM_CHANNELS)+(hopping_frequency_no>>1)]);
XN297L_Hopping((IS_BIND_IN_PROGRESS?0:XK_RF_BIND_NUM_CHANNELS)+(hopping_frequency_no>>1));
hopping_frequency_no++;
if(hopping_frequency_no >= (IS_BIND_IN_PROGRESS?XK_RF_BIND_NUM_CHANNELS*2:XK_RF_NUM_CHANNELS*2))
hopping_frequency_no=0;
XN297L_WritePayload(packet, XK_PAYLOAD_SIZE);
//for(uint8_t i=0; i<XK_PAYLOAD_SIZE; i++)
// debug(" %02X",packet[i]);
//debugln("");
XN297L_SetPower(); // Set tx_power
XN297L_SetFreqOffset(); // Set frequency offset
}
const uint8_t PROGMEM XK_bind_hop[XK_RF_BIND_NUM_CHANNELS]= { 0x07, 0x24, 0x3E, 0x2B, 0x47, 0x0E, 0x39, 0x1C }; // Bind
static void __attribute__((unused)) XK_initialize_txid()
{
//bind hop
for(uint8_t i=0; i<XK_RF_BIND_NUM_CHANNELS; i++)
hopping_frequency[i]=pgm_read_byte_near( &XK_bind_hop[i] );
//#ifdef FORCE_XK_ORIGINAL_ID
if(sub_protocol==X450)
{
//TX1 X8 X450
rx_tx_addr[0]=0x04;
rx_tx_addr[1]=0x15;
rx_tx_addr[2]=0x22;
memcpy(&hopping_frequency[XK_RF_BIND_NUM_CHANNELS],"\x3B\x48\x40\x49", XK_RF_NUM_CHANNELS); // freq and order verified
//Normal packet address \x2C\x96\x2A\xA9\x32
//TX2 X450 X8?
//rx_tx_addr[0]=0x24;
//rx_tx_addr[1]=0x14;
//rx_tx_addr[2]=0x22;
//memcpy(&hopping_frequency[XK_RF_BIND_NUM_CHANNELS],"\x3A\x3B\x42\x48", XK_RF_NUM_CHANNELS); // freq unsure and order unknown
//Normal packet address \x2C\x96\x2A\xA9\x32
}
else
{
//TX3 X420
rx_tx_addr[0]=0x13;
rx_tx_addr[1]=0x24;
rx_tx_addr[2]=0x18;
memcpy(&hopping_frequency[XK_RF_BIND_NUM_CHANNELS],"\x36\x37\x41\x4E", XK_RF_NUM_CHANNELS); // freq ok but order unknown
//Normal packet address \xA6\x83\xEB\x4B\xC9
}
//#endif
}
static void __attribute__((unused)) XK_init()
{
XN297L_Init();
XN297L_SetTXAddr((uint8_t*)"\x68\x94\xA6\xD5\xC3", 5); // Bind address
XN297L_HoppingCalib(XK_RF_BIND_NUM_CHANNELS+XK_RF_NUM_CHANNELS); // Calibrate all channels
}
uint16_t XK_callback()
{
#ifdef MULTI_SYNC
telemetry_set_input_sync(XK_PACKET_PERIOD);
#endif
if(IS_BIND_IN_PROGRESS)
if(--bind_counter==0)
{
BIND_DONE;
if(sub_protocol==X450)
XN297L_SetTXAddr((uint8_t*)"\x2C\x96\x2A\xA9\x32", 5); // Normal address X450
else
XN297L_SetTXAddr((uint8_t*)"\xA6\x83\xEB\x4B\xC9", 5); // Normal address X420
}
XK_send_packet();
return XK_PACKET_PERIOD;
}
uint16_t initXK()
{
BIND_IN_PROGRESS; // autobind protocol
XK_initialize_txid();
XK_init();
hopping_frequency_no = 0;
bind_counter=XK_BIND_COUNT;
return XK_INITIAL_WAIT;
}
#endif

View File

@ -218,6 +218,7 @@
#define V2X2_NRF24L01_INO
#define V761_NRF24L01_INO
#define V911S_NRF24L01_INO
#define XK_NRF24L01_INO
#define YD717_NRF24L01_INO
#define ZSX_NRF24L01_INO
@ -676,6 +677,9 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= {
W6_6_1
W6_HEL
W6_HEL_I
PROTO_XK
X450
X420
PROTO_YD717
YD717
SKYWLKR