E016H v2: new protocol WIP only 1 ID

This commit is contained in:
Pascal Langer
2020-12-17 18:05:04 +01:00
parent f18847df57
commit 321e4aee34
9 changed files with 208 additions and 16 deletions

View File

@@ -0,0 +1,146 @@
/*
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/>.
*/
#if defined(E016H_CC2500_INO)
#include "iface_nrf250k.h"
#define FORCE_E016H_ORIGINAL_ID
#define E016H_INITIAL_WAIT 500
#define E016H_PACKET_PERIOD 10000
#define E016H_RF_BIND_CHANNEL 5
#define E016H_PAYLOAD_SIZE 11
#define E016H_BIND_COUNT 300 //3sec
static void __attribute__((unused)) E016H_send_packet()
{
packet[0 ] = rx_tx_addr[0];
if(IS_BIND_IN_PROGRESS)
{
packet[1 ] = 0x02;
if(bind_counter)
bind_counter--;
else
{
BIND_DONE;
XN297L_RFChannel(hopping_frequency_no); // Set main channel
}
}
else
packet[1 ] = 0x20;
packet[2 ] = rx_tx_addr[2];
packet[3 ] = rx_tx_addr[3];
//channels TREA
uint8_t channel;
if(IS_BIND_IN_PROGRESS)
channel=0x64; // Throttle must be centered during bind
else
channel=convert_channel_8b_limit_deadband(THROTTLE,0x00,0x64,0xC8, 160);
packet[4 ] = channel;
channel=convert_channel_16b_limit(RUDDER,0x00,0xC8);
packet[5 ] = channel;
channel=convert_channel_16b_limit(ELEVATOR,0x00,0xC8);
packet[6 ] = channel;
channel=convert_channel_16b_limit(AILERON,0x00,0xC8);
packet[7 ] = channel;
//flags
packet[8 ] = GET_FLAG(CH7_SW, 0x01) // 0x01=Flip
| GET_FLAG(CH8_SW, 0x02) // 0x02=Headless
| GET_FLAG(CH9_SW, 0x04); // 0x04=One Key Return
packet[9 ] = 0x02; // Speed control 0x00:low, 0x01:medium, 0x02:high
packet[10] = GET_FLAG(CH5_SW, 0x01) // 0x01=TakeOff/Land (momentary switch)
| GET_FLAG(CH6_SW, 0x04); // 0x04=Emergeny Stop (momentary switch)
if(option==0)
option=1; // Select the CC2500
XN297L_SetPower(); // Set tx_power
XN297L_SetFreqOffset(); // Set frequency offset
//Build real packet and send it
static uint8_t pid=0;
crc=0;
// stop TX/RX
CC2500_Strobe(CC2500_SIDLE);
// flush tx FIFO
CC2500_Strobe(CC2500_SFTX);
// packet length
CC2500_WriteReg(CC2500_3F_TXFIFO, 6 + 4 + 1 + 11 + 2); // preamble + address + packet_control + payload + crc
// preamble+address
CC2500_WriteRegisterMulti(CC2500_3F_TXFIFO, (uint8_t*)"\xAA\xAA\xAA\xAA\xAA\xAA\xE7\xE7\xE7\xE7", 10);
// packet control
CC2500_WriteReg(CC2500_3F_TXFIFO, 0x50+(pid<<2));
pid++;
// payload
debug("P:")
for (uint8_t i = 0; i < E016H_PAYLOAD_SIZE; ++i)
{
uint8_t byte = (bit_reverse(packet[i])<<1) | (packet[i+1]&0x01);
debug(" %02X",byte)
CC2500_WriteReg(CC2500_3F_TXFIFO,byte);
crc=crc16_update(crc, byte, 8);
}
// crc
CC2500_WriteReg(CC2500_3F_TXFIFO,crc >> 8);
CC2500_WriteReg(CC2500_3F_TXFIFO,crc);
debugln(" %04X",crc)
// transmit
CC2500_Strobe(CC2500_STX);
}
uint16_t E016H_callback()
{
E016H_send_packet();
return E016H_PACKET_PERIOD;
}
static void __attribute__((unused)) E016H_initialize_txid()
{
//need to figure out ID&Freq
#ifdef FORCE_E016H_ORIGINAL_ID
rx_tx_addr[0]=0x0A;
rx_tx_addr[1]=0x02; // not used in the code
rx_tx_addr[2]=0x27;
rx_tx_addr[3]=0x1B;
hopping_frequency_no = 44;
#endif
}
uint16_t initE016H()
{
//Config CC2500
if(option==0)
option=1; // Select the CC2500
XN297L_Init();
XN297L_RFChannel(E016H_RF_BIND_CHANNEL); // Set bind channel
E016H_initialize_txid();
bind_counter = E016H_BIND_COUNT;
BIND_IN_PROGRESS; // Autobind protocol
return E016H_INITIAL_WAIT;
}
#endif

View File

@@ -94,6 +94,7 @@ const char STR_OMP[] ="OMP";
const char STR_MLINK[] ="M-Link";
const char STR_TEST[] ="Test";
const char STR_NANORF[] ="NanoRF";
const char STR_E016H[] ="E016Hv2";
const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20";
const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501";
@@ -212,6 +213,9 @@ const mm_protocol_definition multi_protocols[] = {
#if defined(DSM_RX_CYRF6936_INO)
{PROTO_DSM_RX, STR_DSM_RX, 0, NO_SUBTYPE, OPTION_NONE },
#endif
#if defined(E016H_CC2500_INO)
{PROTO_E016H, STR_E016H, 0, NO_SUBTYPE, OPTION_RFTUNE },
#endif
#if defined(E01X_NRF24L01_INO)
{PROTO_E01X, STR_E01X, 3, STR_SUBTYPE_E01X, OPTION_OPTION },
#endif

View File

@@ -19,7 +19,7 @@
#define VERSION_MAJOR 1
#define VERSION_MINOR 3
#define VERSION_REVISION 1
#define VERSION_PATCH_LEVEL 86
#define VERSION_PATCH_LEVEL 87
//******************
// Protocols
@@ -105,6 +105,7 @@ enum PROTOCOLS
PROTO_OMP = 77, // =>CC2500 & NRF24L01
PROTO_MLINK = 78, // =>CYRF6936
PROTO_WFLY2 = 79, // =>A7105
PROTO_E016H = 80, // =>CC2500 & NRF24L01
PROTO_NANORF = 126, // =>NRF24L01
PROTO_TEST = 127, // =>CC2500
@@ -838,6 +839,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
OMP 77
MLINK 78
WFLY2 79
E016H 80
BindBit=> 0x80 1=Bind/0=No
AutoBindBit=> 0x40 1=Yes /0=No
RangeCheck=> 0x20 1=Yes /0=No

View File

@@ -1322,6 +1322,14 @@ static void protocol_init()
remote_callback = RLINK_callback;
break;
#endif
#if defined(E016H_CC2500_INO)
case PROTO_E016H:
PE1_off;
PE2_on; //antenna RF2
next_callback = initE016H();
remote_callback = E016H_callback;
break;
#endif
#endif
#ifdef CYRF6936_INSTALLED
#if defined(DSM_CYRF6936_INO)

View File

@@ -263,6 +263,7 @@
#undef SCANNER_CC2500_INO
#undef FUTABA_CC2500_INO
#undef SKYARTEC_CC2500_INO
#undef E016H_CC2500_INO
#endif
#ifndef NRF24L01_INSTALLED
#undef ASSAN_NRF24L01_INO
@@ -274,6 +275,7 @@
#undef CG023_NRF24L01_INO
#undef CX10_NRF24L01_INO
#undef DM002_NRF24L01_INO
#undef E016H_CC2500_INO // Use both CC2500 and NRF code
#undef E01X_NRF24L01_INO
#undef ESKY_NRF24L01_INO
#undef ESKY150_NRF24L01_INO
@@ -292,7 +294,7 @@
#undef MJXQ_NRF24L01_INO
#undef MT99XX_NRF24L01_INO
#undef NCC1701_NRF24L01_INO
#undef OMP_CC2500_INO
#undef OMP_CC2500_INO // Use both CC2500 and NRF code
#undef POTENSIC_NRF24L01_INO
#undef PROPEL_NRF24L01_INO
#undef Q303_NRF24L01_INO

View File

@@ -628,11 +628,11 @@ static uint16_t XN297Dump_callback()
{
if(phase==0)
{
address_length=5;
memcpy(rx_tx_addr, (uint8_t *)"\xC9\x59\xD2\x65\x34", 5);
address_length=4;
memcpy(rx_tx_addr, (uint8_t *)"\xE7\xE7\xE7\xE7", 4);
bitrate=XN297DUMP_250K;
packet_length=16;
hopping_frequency_no=0x03;
packet_length=14;
hopping_frequency_no=5; //bind 5, normal 44
NRF24L01_Initialize();
NRF24L01_SetTxRxMode(TXRX_OFF);
@@ -669,7 +669,7 @@ static uint16_t XN297Dump_callback()
NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x01);
NRF24L01_Activate(0x73);
NRF24L01_SetPower();
NRF24L01_WriteReg(NRF24L01_00_CONFIG, _BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP) | _BV(NRF24L01_00_PRIM_RX));
NRF24L01_WriteReg(NRF24L01_00_CONFIG, _BV(NRF24L01_00_PWR_UP) | _BV(NRF24L01_00_PRIM_RX)); //_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) |
phase++;
}
else
@@ -679,21 +679,30 @@ static uint16_t XN297Dump_callback()
if(NRF24L01_ReadReg(NRF24L01_09_CD))
{
NRF24L01_ReadPayload(packet, packet_length);
if(memcmp(packet_in,packet,packet_length))
{
debug("P:");
for(uint8_t i=0;i<packet_length;i++)
debug(" %02X",packet[i]);
debugln("");
memcpy(packet_in,packet,packet_length);
}
crc=0;
for (uint8_t i = 1; i < 12; ++i)
crc = crc16_update(crc, packet[i], 8);
if(packet[12]==((crc>>8)&0xFF) && packet[13]==(crc&0xFF))
if(memcmp(&packet_in[1],&packet[1],packet_length-1))
{
/*debug("P:");
for(uint8_t i=0;i<packet_length;i++)
debug(" %02X",packet[i]);
debug(" CRC: %04X",crc);
debugln("");*/
debug("P(%02X):",packet[0]);
for(uint8_t i=1;i<packet_length-2;i++)
debug(" %02X",((bit_reverse(packet[i])<<1)|(bit_reverse(packet[i-1])>>7))&0xFF);
debugln("");
memcpy(packet_in,packet,packet_length);
}
}
// restart RX mode
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit
NRF24L01_SetTxRxMode(TXRX_OFF);
NRF24L01_SetTxRxMode(RX_EN);
NRF24L01_FlushRx();
NRF24L01_WriteReg(NRF24L01_00_CONFIG, _BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP) | _BV(NRF24L01_00_PRIM_RX));
NRF24L01_WriteReg(NRF24L01_00_CONFIG, _BV(NRF24L01_00_PWR_UP) | _BV(NRF24L01_00_PRIM_RX)); // _BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) |
}
}
}

View File

@@ -188,6 +188,7 @@
//The protocols below need a CC2500 to be installed
#define CORONA_CC2500_INO
#define E016H_CC2500_INO
#define ESKY150V2_CC2500_INO //Need both CC2500 and NRF
#define FRSKYL_CC2500_INO
#define FRSKYD_CC2500_INO
@@ -571,6 +572,8 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= {
DSMX_11
PROTO_DSM_RX
NONE
PROTO_E016H
NONE
PROTO_E01X
E012
E015