New protocol MJXQ

This commit is contained in:
pascallanger
2016-02-04 13:35:16 +01:00
parent db8e4a03a8
commit 86d3d26273
9 changed files with 360 additions and 94 deletions

View File

@@ -12,7 +12,7 @@
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 Cheerson CX-10 blue & newer red pcb, CX-10A, CX11, CX-10 green pcb, DM007, Floureon FX-10, CX-Stars
// compatible with Cheerson CX-10 blue & newer red pcb, CX-10A, CX11, CX-10 green pcb, DM007, Floureon FX-10, JXD 509 (Q282)
// Last sync with hexfet new_protocols/cx10_nrf24l01.c dated 2015-11-26
#if defined(CX10_NRF24L01_INO)
@@ -27,7 +27,7 @@
#define CX10A_PACKET_PERIOD 6000
#define CX10A_BIND_COUNT 400 // 2 seconds
#define INITIAL_WAIT 500
#define CX10_INITIAL_WAIT 500
// flags
#define CX10_FLAG_FLIP 0x10 // goes to rudder channel
@@ -38,8 +38,8 @@
#define CX10_FLAG_SNAPSHOT 0x04
// frequency channel management
#define RF_BIND_CHANNEL 0x02
#define NUM_RF_CHANNELS 4
#define CX10_RF_BIND_CHANNEL 0x02
#define CX10_NUM_RF_CHANNELS 4
enum {
CX10_BIND1 = 0,
@@ -87,63 +87,61 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
switch(sub_protocol)
{
case CX10_BLUE:
if(Servo_AUX3) flags |= 0x10; // Channel 7 - picture
if(Servo_AUX4) flags |= 0x08; // Channel 8 - video
flags |= GET_FLAG(!Servo_AUX3, 0x10) // Channel 7 - picture
|GET_FLAG( Servo_AUX4, 0x08); // Channel 8 - video
break;
case Q282:
case Q242:
memcpy(&packet[15], "\x10\x10\xaa\xaa\x00\x00", 6);
//FLIP|LED|PICTURE|VIDEO|HEADLESS|RTH|XCAL|YCAL
if(Servo_AUX1) flags2 =0x80; // Channel 5 - FLIP
if(Servo_AUX2) flags2|=0x40; // Channel 6 - LED
if(Servo_AUX5) flags2|=0x08; // Channel 9 - HEADLESS
flags2 = GET_FLAG(Servo_AUX1, 0x80) // Channel 5 - FLIP
|GET_FLAG(Servo_AUX2, 0x40) // Channel 6 - LED
|GET_FLAG(Servo_AUX5, 0x08) // Channel 9 - HEADLESS
|GET_FLAG(Servo_AUX7, 0x04) // Channel 11 - XCAL
|GET_FLAG(Servo_AUX8, 0x02); // Channel 12 - YCAL or Start/Stop motors on JXD 509
if(sub_protocol==Q282)
{
if(Servo_AUX3) flags2|=0x10; // Channel 7 - picture
if(Servo_AUX4) // Channel 8 - video
flags=3;
if(Servo_AUX4) // Channel 8 - video
{
if (!(video_state & 0x20)) video_state ^= 0x21;
}
else
if (video_state & 0x20) video_state &= 0x01;
flags2 |= video_state;
flags=3;
flags2 |= video_state
|GET_FLAG(Servo_AUX3,0x10); // Channel 7 - picture
}
else
{
if(Servo_AUX3) flags2|=0x01; // Channel 7 - picture
if(Servo_AUX4) flags2|=0x10; // Channel 8 - video
flags=2;
flags2|= GET_FLAG(Servo_AUX3,0x01) // Channel 7 - picture
|GET_FLAG(Servo_AUX4,0x10); // Channel 8 - video
packet[17]=0x00;
packet[18]=0x00;
}
if(Servo_AUX6) flags |=0x80; // Channel 10 - RTH
if(Servo_AUX7) flags2|=0x04; // Channel 11 - XCAL
if(Servo_AUX8) flags2|=0x02; // Channel 12 - YCAL
if(Servo_AUX6) flags |=0x80; // Channel 10 - RTH
break;
case DM007:
//FLIP|MODE|PICTURE|VIDEO|HEADLESS
if(Servo_AUX3) flags2 = CX10_FLAG_SNAPSHOT; // Channel 7 - picture
if(Servo_AUX4) flags2|= CX10_FLAG_VIDEO; // Channel 8 - video
if(Servo_AUX5) flags |= CX10_FLAG_HEADLESS; // Channel 9 - headless
break;
case JC3015_1:
//FLIP|MODE|PICTURE|VIDEO
if(Servo_AUX3) flags2 = _BV(3); // Channel 7 - picture
if(Servo_AUX4) flags2|= _BV(4); // Channel 8 - video
flags2= GET_FLAG(Servo_AUX3,CX10_FLAG_SNAPSHOT) // Channel 7 - picture
|GET_FLAG(Servo_AUX4,CX10_FLAG_VIDEO); // Channel 8 - video
if(Servo_AUX5) flags |= CX10_FLAG_HEADLESS; // Channel 9 - headless
break;
case JC3015_2:
//FLIP|MODE|LED|DFLIP
if(Servo_AUX3) flags2 = _BV(3); // Channel 7 - LED
if(Servo_AUX4) flags2|= _BV(4); // Channel 8 - DFLIP
if(Servo_AUX4) packet[12] &= ~CX10_FLAG_FLIP;
case JC3015_1:
//FLIP|MODE|PICTURE|VIDEO
flags2= GET_FLAG(Servo_AUX3,_BV(3)) // Channel 7
|GET_FLAG(Servo_AUX4,_BV(4)); // Channel 8
break;
case MK33041:
//FLIP|MODE|PICTURE|VIDEO|HEADLESS|RTH
if(Servo_AUX3) flags |= _BV(7); // Channel 7 - picture
if(Servo_AUX4) flags2 = _BV(0); // Channel 8 - video
if(Servo_AUX5) flags2|= _BV(5); // Channel 9 - headless
if(Servo_AUX6) flags |= _BV(2); // Channel 10 - rth
flags|=GET_FLAG(Servo_AUX3,_BV(7)) // Channel 7 - picture
|GET_FLAG(Servo_AUX6,_BV(2)); // Channel 10 - rth
flags2=GET_FLAG(Servo_AUX4,_BV(0)) // Channel 8 - video
|GET_FLAG(Servo_AUX5,_BV(5)); // Channel 9 - headless
break;
}
packet[13+offset]=flags;
@@ -153,11 +151,11 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
// Why CRC0? xn297 does not interpret it - either 16-bit CRC or nothing
XN297_Configure(BV(NRF24L01_00_EN_CRC) | BV(NRF24L01_00_CRCO) | BV(NRF24L01_00_PWR_UP));
if (bind)
NRF24L01_WriteReg(NRF24L01_05_RF_CH, RF_BIND_CHANNEL);
NRF24L01_WriteReg(NRF24L01_05_RF_CH, CX10_RF_BIND_CHANNEL);
else
{
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no++]);
hopping_frequency_no %= NUM_RF_CHANNELS;
hopping_frequency_no %= CX10_NUM_RF_CHANNELS;
}
// clear packet status bits and TX FIFO
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
@@ -179,7 +177,7 @@ static void __attribute__((unused)) CX10_init()
NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00); // No Auto Acknowledgment on all data pipes
NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, 0x01); // Enable data pipe 0 only
NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, packet_length); // rx pipe 0 (used only for blue board)
NRF24L01_WriteReg(NRF24L01_05_RF_CH, RF_BIND_CHANNEL);
NRF24L01_WriteReg(NRF24L01_05_RF_CH, CX10_RF_BIND_CHANNEL);
NRF24L01_SetBitrate(NRF24L01_BR_1M); // 1Mbps
NRF24L01_SetPower();
}
@@ -236,7 +234,7 @@ uint16_t CX10_callback() {
return packet_period;
}
static void __attribute__((unused)) initialize_txid()
static void __attribute__((unused)) CX10_initialize_txid()
{
rx_tx_addr[1]%= 0x30;
if(sub_protocol==Q282)
@@ -287,10 +285,10 @@ uint16_t initCX10(void)
phase = CX10_BIND1;
bind_counter = CX10_BIND_COUNT;
}
initialize_txid();
CX10_initialize_txid();
CX10_init();
BIND_IN_PROGRESS; // autobind protocol
return INITIAL_WAIT+packet_period;
return CX10_INITIAL_WAIT+packet_period;
}
#endif