Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 95 additions & 5 deletions Multiprotocol/CX10_nrf24l01.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#define CX10_PACKET_PERIOD 1316 // Timeout for callback in uSec
#define CX10A_PACKET_PERIOD 6000

#define CX10N_PACKET_SIZE 12
#define CX10N_BIND_COUNT 100
#define CX10N_PACKET_PERIOD 4000
#define CX10N_RF_BIND_CHANNEL 48

#define CX10_INITIAL_WAIT 500

// flags
Expand All @@ -51,18 +56,39 @@ static void __attribute__((unused)) CX10_Write_Packet()
uint8_t offset = 0;
if(sub_protocol == CX10_BLUE)
offset = 4;

#if 0

packet[0] = IS_BIND_IN_PROGRESS ? 0xAA : 0x55;
packet[1] = rx_tx_addr[0];
packet[2] = rx_tx_addr[1];
packet[3] = rx_tx_addr[2];
packet[4] = rx_tx_addr[3];

#endif

packet[0] = IS_BIND_IN_PROGRESS ? 0xC5 : 0x85;
packet[1] = IS_BIND_IN_PROGRESS ? 0x11 : packet_count++;
packet[2] = rx_tx_addr[2];
packet[3] = rx_tx_addr[3];

#if 0

// packet[5] to [8] (aircraft id) is filled during bind for blue board
uint16_t aileron= convert_channel_16b_limit(AILERON ,1000,2000);
uint16_t elevator=convert_channel_16b_limit(ELEVATOR,2000,1000);
uint16_t throttle=convert_channel_16b_limit(THROTTLE,1000,2000);
uint16_t rudder= convert_channel_16b_limit(RUDDER ,2000,1000);

#endif

uint8_t aileron = convert_channel_8b(AILERON);
uint8_t elevator = convert_channel_8b(ELEVATOR);
uint8_t throttle = convert_channel_8b(THROTTLE);
uint8_t rudder = convert_channel_8b(RUDDER);

// Channel 5 - flip flag
packet[12+offset] = GET_FLAG(CH5_SW,CX10_FLAG_FLIP); // flip flag applied on rudder
// packet[12+offset] = GET_FLAG(CH5_SW,CX10_FLAG_FLIP); // flip flag applied on rudder

// Channel 6 - rate mode is 2 lsb of packet 13
if(CH6_SW) // rate 3 / headless on CX-10A
Expand All @@ -72,6 +98,10 @@ static void __attribute__((unused)) CX10_Write_Packet()
flags = 0x00; // rate 1
else
flags = 0x01; // rate 2


#if 0

uint8_t flags2=0; // packet 14

uint8_t video_state=packet[14] & 0x21;
Expand Down Expand Up @@ -150,7 +180,29 @@ static void __attribute__((unused)) CX10_Write_Packet()
packet[12+offset]|= highByte(rudder);
packet[13+offset]=flags;
packet[14+offset]=flags2;


#endif

packet[4] = throttle;
packet[5] = rudder;
packet[6] = elevator;
packet[7] = aileron;

if(IS_BIND_DONE) {
packet[8] = !CH5_SW ? 0x04 + flags : 0x0C;

// TODO horizontal and vertical adjustments
packet[10] = 0x42;
packet[11] = 0x10;

} else {

packet[8] = 0x00;

packet[10] = 0xAA;
packet[11] = 0x55;
}

// Send
if(IS_BIND_DONE)
{
Expand All @@ -165,9 +217,11 @@ static void __attribute__((unused)) CX10_Write_Packet()
static void __attribute__((unused)) CX10_RF_init()
{
XN297_Configure(XN297_CRCEN, XN297_SCRAMBLED, XN297_1M);
XN297_SetTXAddr((uint8_t *)"\xcc\xcc\xcc\xcc\xcc", 5);
// XN297_SetTXAddr((uint8_t *)"\xcc\xcc\xcc\xcc\xcc", 5);
XN297_SetTXAddr((uint8_t *)"\xC7\x95\x3C\xBB\xA5", 5);
XN297_SetRXAddr((uint8_t *)"\xcc\xcc\xcc\xcc\xcc", packet_length);
XN297_RFChannel(CX10_RF_BIND_CHANNEL);
// XN297_RFChannel(CX10_RF_BIND_CHANNEL);
XN297_RFChannel(CX10N_RF_BIND_CHANNEL);
}

uint16_t CX10_callback()
Expand Down Expand Up @@ -234,17 +288,42 @@ static void __attribute__((unused)) CX10_initialize_txid()
}
else
{

#if 0

hopping_frequency[0] = 0x03 + (rx_tx_addr[0] & 0x0F);
hopping_frequency[1] = 0x16 + (rx_tx_addr[0] >> 4);
hopping_frequency[2] = 0x2D + (rx_tx_addr[1] & 0x0F);
hopping_frequency[3] = 0x40 + (rx_tx_addr[1] >> 4);

#endif

rx_tx_addr[2] = 0x4C;
rx_tx_addr[3] = 0xD7;

hopping_frequency[0] = 55;
hopping_frequency[1] = 66;
hopping_frequency[2] = 71;
hopping_frequency[3] = 60;

/*
rx_tx_addr[2] = 0x50;
rx_tx_addr[3] = 0xE1;

hopping_frequency[0] = 59;
hopping_frequency[1] = 75;
hopping_frequency[2] = 70;
hopping_frequency[3] = 65;
*/
}
}

void CX10_init(void)
{
BIND_IN_PROGRESS; // autobind protocol


#if 0

if(protocol == PROTO_Q2X2)
sub_protocol|=0x08; // Increase the number of sub_protocols for CX-10

Expand All @@ -269,6 +348,17 @@ void CX10_init(void)
phase = CX10_BIND1;
bind_counter = CX10_BIND_COUNT;
}

#endif

packet_length = CX10N_PACKET_SIZE;
packet_period = CX10N_PACKET_PERIOD;
packet_count = 0;
phase = CX10_BIND1;
bind_counter = CX10N_BIND_COUNT;

packet[9] = 0x00;

CX10_initialize_txid();
CX10_RF_init();
}
Expand Down
38 changes: 33 additions & 5 deletions Multiprotocol/SGF22_nrf24l01.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Multiprotocol is distributed in the hope that it will be useful,
#define SGF22_RF_NUM_CHANNELS 4
#define SGF22_F22S_BIND_RF_CHANNEL 10
#define SGF22_J20_BIND_RF_CHANNEL 28
#define CX10_BIND_RF_CHANNEL 48

//packet[8]
#define SGF22_FLAG_3D 0x00
Expand Down Expand Up @@ -61,7 +62,9 @@ static void __attribute__((unused)) SGF22_send_packet()
{
if(IS_BIND_IN_PROGRESS)
{
packet[ 0] = 0x5B;
// packet[ 0] = 0x5B;
packet[ 0] = 0xC5;
packet[ 1] = 0x11;
packet[ 8] = 0x00; // ??? do they have to be 0 for bind to succeed ?
packet[ 9] = 0x00; // ??? do they have to be 0 for bind to succeed ?
packet[10] = 0xAA;
Expand All @@ -78,7 +81,9 @@ static void __attribute__((unused)) SGF22_send_packet()
if(packet_sent > 0x7B)
packet_sent = 0;
//packet
packet[0] = 0x1B;
// packet[0] = 0x1B;
packet[0] = 0x85;
packet[1] = packet_count; // sequence
packet[8] = SGF22_FLAG_3D // CH5 -100%, F22 & F22S - 3D mode, J20 - Gyro off
| GET_FLAG(CH6_SW, SGF22_FLAG_ROLL) // roll
| GET_FLAG(CH7_SW, SGF22_FLAG_LIGHT) // push up throttle trim for light in the stock TX
Expand All @@ -89,6 +94,17 @@ static void __attribute__((unused)) SGF22_send_packet()
packet[8] |= SGF22_FLAG_VERTICAL; // CH5 100%, vertical mode (torque)
else if(Channel_data[CH5] > CHANNEL_MIN_COMMAND )
packet[8] |= ( sub_protocol == SGF22_J20 ? SGF22_J20_FLAG_HORIZONTAL : SGF22_FLAG_6G ); // CH5 0%, F22 & F22S - 6G mode, J20 - Horizontal mode

// Channel 6 - packet 8 is rate mode or flip mode
if(CH6_SW) // rate 3
flags = 0x02;
else
if(Channel_data[CH6] < CHANNEL_MIN_COMMAND)
flags = 0x00; // rate 1
else
flags = 0x01;
packet[8] = !CH5_SW ? 0x04 + flags : 0x0C;

packet[9] = GET_FLAG(CH8_SW, SGF22_FLAG_PHOTO) // F22: photo, press in throttle trim in the stock TX, J20: invert flight
| GET_FLAG(CH10_SW, ( sub_protocol == SGF22_J20 ? SGF22_J20_FLAG_FIXHEIGHT : SGF22_FLAG_TRIMRESET )) ; // F22: Both sticks down inwards in the stock TX, J20: Altitude hold
packet[10] = 0x42; // no fine tune
Expand All @@ -98,7 +114,7 @@ static void __attribute__((unused)) SGF22_send_packet()
packet[0] += 6;
else if (sub_protocol == SGF22_J20)
packet[0] += 3;
packet[1] = packet_count; // sequence
// packet[1] = packet_count; // sequence
packet[2] = rx_tx_addr[2];
packet[3] = rx_tx_addr[3];
packet[4] = convert_channel_8b(THROTTLE);
Expand All @@ -108,7 +124,8 @@ static void __attribute__((unused)) SGF22_send_packet()

XN297_SetPower();
XN297_SetTxRxMode(TX_EN);
XN297_WriteEnhancedPayload(packet, SGF22_PAYLOAD_SIZE,0);
// XN297_WriteEnhancedPayload(packet, SGF22_PAYLOAD_SIZE,0);
XN297_WritePayload(packet, SGF22_PAYLOAD_SIZE);
#if 0
debug_time("");
for(uint8_t i=0; i<SGF22_PAYLOAD_SIZE; i++)
Expand Down Expand Up @@ -151,6 +168,16 @@ static void __attribute__((unused)) SGF22_initialize_txid()
debug(" %02X",hopping_frequency[i]);
debugln("");
#endif

rx_tx_addr[2] = 0x4C;
rx_tx_addr[3] = 0xD7;
memcpy(hopping_frequency, "\x37\x42\x47\x3c", SGF22_RF_NUM_CHANNELS);

/*
rx_tx_addr[2] = 0x50;
rx_tx_addr[3] = 0xE1;
memcpy(hopping_frequency, "\x3b\x4b\x46\x41", SGF22_RF_NUM_CHANNELS);
*/
}

static void __attribute__((unused)) SGF22_RF_init()
Expand All @@ -161,7 +188,8 @@ static void __attribute__((unused)) SGF22_RF_init()
XN297_SetRXAddr((uint8_t*)"\xC7\x95\x3C\xBB\xA5", SGF22_PAYLOAD_SIZE);
#endif

const uint8_t bind_chan[] = {SGF22_BIND_RF_CHANNEL, SGF22_F22S_BIND_RF_CHANNEL, SGF22_J20_BIND_RF_CHANNEL};
// const uint8_t bind_chan[] = {SGF22_BIND_RF_CHANNEL, SGF22_F22S_BIND_RF_CHANNEL, SGF22_J20_BIND_RF_CHANNEL};
const uint8_t bind_chan[] = {CX10_BIND_RF_CHANNEL, SGF22_F22S_BIND_RF_CHANNEL, SGF22_J20_BIND_RF_CHANNEL};
XN297_RFChannel(bind_chan[sub_protocol]); // Set bind channel
}

Expand Down