suivit projet

This commit is contained in:
tipouic 2016-12-13 21:40:30 +01:00
parent 8b282dd506
commit bd92f5b1c0
18 changed files with 691 additions and 1032 deletions

View File

@ -72,7 +72,7 @@ static void AFHDS2A_calc_channels()
} }
} }
#if defined(TELEMETRY) #if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY)
// telemetry sensors ID // telemetry sensors ID
enum{ enum{
AFHDS2A_SENSOR_RX_VOLTAGE = 0x00, AFHDS2A_SENSOR_RX_VOLTAGE = 0x00,
@ -86,8 +86,9 @@ static void AFHDS2A_update_telemetry()
{ {
// AA | TXID | rx_id | sensor id | sensor # | value 16 bit big endian | sensor id ...... // AA | TXID | rx_id | sensor id | sensor # | value 16 bit big endian | sensor id ......
// max 7 sensors per packet // max 7 sensors per packet
#if defined AFHDS2A_TELEMETRY #ifdef AFHDS2A_FW_TELEMETRY
if (option & 0x80) { if (option & 0x80)
{
// forward telemetry to TX, skip rx and tx id to save space // forward telemetry to TX, skip rx and tx id to save space
pkt[0]= TX_RSSI; pkt[0]= TX_RSSI;
for(int i=9;i < AFHDS2A_RXPACKET_SIZE; i++) for(int i=9;i < AFHDS2A_RXPACKET_SIZE; i++)
@ -97,13 +98,16 @@ static void AFHDS2A_update_telemetry()
return; return;
} }
#endif #endif
#ifdef AFHDS2A_HUB_TELEMETRY
for(uint8_t sensor=0; sensor<7; sensor++) for(uint8_t sensor=0; sensor<7; sensor++)
{ {
// Send FrSkyD telemetry to TX
uint8_t index = 9+(4*sensor); uint8_t index = 9+(4*sensor);
switch(packet[index]) switch(packet[index])
{ {
case AFHDS2A_SENSOR_RX_VOLTAGE: case AFHDS2A_SENSOR_RX_VOLTAGE:
v_lipo = packet[index+3]<<8 | packet[index+2]; //v_lipo1 = packet[index+3]<<8 | packet[index+2];
v_lipo1 = packet[index+2];
telemetry_link=1; telemetry_link=1;
break; break;
/*case AFHDS2A_SENSOR_RX_ERR_RATE: /*case AFHDS2A_SENSOR_RX_ERR_RATE:
@ -119,6 +123,7 @@ static void AFHDS2A_update_telemetry()
break;*/ break;*/
} }
} }
#endif
} }
#endif #endif
@ -298,7 +303,7 @@ uint16_t ReadAFHDS2A()
{ {
if(packet[9] == 0xfc) if(packet[9] == 0xfc)
packet_type=AFHDS2A_PACKET_SETTINGS; // RX is asking for settings packet_type=AFHDS2A_PACKET_SETTINGS; // RX is asking for settings
#if defined(TELEMETRY) #if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY)
else else
{ {
// Read TX RSSI // Read TX RSSI
@ -346,6 +351,9 @@ uint16_t initAFHDS2A()
rx_id[i]=eeprom_read_byte((EE_ADDR)(temp+i)); rx_id[i]=eeprom_read_byte((EE_ADDR)(temp+i));
} }
hopping_frequency_no = 0; hopping_frequency_no = 0;
#if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY)
init_hub_telemetry();
#endif
return 50000; return 50000;
} }
#endif #endif

View File

@ -16,16 +16,11 @@ Multiprotocol is distributed in the hope that it will be useful,
// Last sync with hexfet new_protocols/bayang_nrf24l01.c dated 2015-12-22 // Last sync with hexfet new_protocols/bayang_nrf24l01.c dated 2015-12-22
#if defined(BAYANG_NRF24L01_INO) #if defined(BAYANG_NRF24L01_INO)
#include "iface_nrf24l01.h" #include "iface_nrf24l01.h"
#ifdef ENABLE_BAYANG_TELEMETRY
#define BAYANG_PACKET_PERIOD_TELEM 3200
uint32_t bayang_telemetry_last_rx = 0;
#endif
#define BAYANG_BIND_COUNT 1000 #define BAYANG_BIND_COUNT 1000
#define BAYANG_PACKET_PERIOD 2000 #define BAYANG_PACKET_PERIOD 1000
#define BAYANG_INITIAL_WAIT 500 #define BAYANG_INITIAL_WAIT 500
#define BAYANG_PACKET_SIZE 15 #define BAYANG_PACKET_SIZE 15
#define BAYANG_RF_NUM_CHANNELS 4 #define BAYANG_RF_NUM_CHANNELS 4
@ -33,27 +28,14 @@ Multiprotocol is distributed in the hope that it will be useful,
#define BAYANG_ADDRESS_LENGTH 5 #define BAYANG_ADDRESS_LENGTH 5
enum BAYANG_FLAGS { enum BAYANG_FLAGS {
// flags going to packet[2] // flags going to packet[2]
BAYANG_FLAG_RTH = 0x01, BAYANG_FLAG_RTH = 0x01,
BAYANG_FLAG_HEADLESS = 0x02, BAYANG_FLAG_HEADLESS = 0x02,
#ifdef ENABLE_BAYANG_TELEMETRY BAYANG_FLAG_FLIP = 0x08,
BAYANG_FLAG_TELEMETRY = 0x04, BAYANG_FLAG_VIDEO = 0x10,
#endif BAYANG_FLAG_PICTURE = 0x20,
BAYANG_FLAG_FLIP = 0x08, // flags going to packet[3]
BAYANG_FLAG_VIDEO = 0x10, BAYANG_FLAG_INVERTED = 0x80 // inverted flight on Floureon H101
BAYANG_FLAG_PICTURE = 0x20,
// flags going to packet[3]
BAYANG_FLAG_INVERTED = 0x80, // inverted flight on Floureon H101
#ifdef ENABLE_BAYANG_TELEMETRY
BAYANG_FLAG_FLIGHT_MODE0 = 0x01,
BAYANG_FLAG_FLIGHT_MODE1 = 0x02,
BAYANG_FLAG_DATA_SELECT0 = 0x04,
BAYANG_FLAG_DATA_SELECT1 = 0x08,
BAYANG_FLAG_DATA_SELECT2 = 0x10,
BAYANG_FLAG_DATA_ADJUST0 = 0x20,
BAYANG_FLAG_DATA_ADJUST1 = 0x40,
#endif
}; };
static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind)
@ -61,7 +43,12 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind)
uint8_t i; uint8_t i;
if (bind) if (bind)
{ {
packet[0]= 0xA4; #ifdef BAYANG_HUB_TELEMETRY
if(option)
packet[0]= 0xA3; // telemetry is enabled
else
#endif
packet[0]= 0xA4;
for(i=0;i<5;i++) for(i=0;i<5;i++)
packet[i+1]=rx_tx_addr[i]; packet[i+1]=rx_tx_addr[i];
for(i=0;i<4;i++) for(i=0;i<4;i++)
@ -71,12 +58,6 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind)
} }
else else
{ {
int telem_enabled = 0;
#ifdef ENABLE_BAYANG_TELEMETRY
telem_enabled = (sub_protocol == BAYANG_TELEM);
// telem_enabled &= Servo_AUX8; // enable telem with a switch
#endif
uint16_t val; uint16_t val;
packet[0] = 0xA5; packet[0] = 0xA5;
packet[1] = 0xFA; // normal mode is 0xf7, expert 0xfa packet[1] = 0xFA; // normal mode is 0xf7, expert 0xfa
@ -93,111 +74,11 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind)
packet[2] |= BAYANG_FLAG_VIDEO; packet[2] |= BAYANG_FLAG_VIDEO;
if(Servo_AUX5) if(Servo_AUX5)
packet[2] |= BAYANG_FLAG_HEADLESS; packet[2] |= BAYANG_FLAG_HEADLESS;
#ifdef ENABLE_BAYANG_TELEMETRY
if (telem_enabled)
{
packet[2] |= BAYANG_FLAG_TELEMETRY;
}
#endif
//Flags packet[3] //Flags packet[3]
packet[3] = 0x00; packet[3] = 0x00;
if(Servo_AUX6) if(Servo_AUX6)
packet[3] = BAYANG_FLAG_INVERTED; packet[3] = BAYANG_FLAG_INVERTED;
#ifdef ENABLE_BAYANG_TELEMETRY
if (telem_enabled)
{
static uint8_t dataselect = 2;
uint8_t dataselect_old = dataselect;
uint16_t partitions[4] ={1200,1400,1600,1800}; // 5 options (previous data set, data 1, data 2, data 3, next data set)
for (uint8_t i = 0; i < 4; ++i)
{
int16_t hysteresis = 0;
if (dataselect_old*2 == (i*2+1) - 1)
{
hysteresis = 25;
}
else if (dataselect_old*2 == (i*2+1) + 1)
{
hysteresis = -25;
}
if (Servo_data[AUX7] <= partitions[i] + hysteresis)
{
dataselect = i;
break;
}
else
{
dataselect = i+1;
}
}
// data adjust 1333 1666 - aux 6
static uint8_t dataadjust = 1;
uint8_t dataadjust_old = dataadjust;
partitions[0] = 1333; // three options (decreaes, do nothing, increase)
partitions[1] = 1666;
for (uint8_t i = 0; i < 2; ++i)
{
int16_t hysteresis = 0;
if (dataadjust_old*2 == (i*2+1) - 1)
{
hysteresis = 25;
}
else if (dataadjust_old*2 == (i*2+1) + 1)
{
hysteresis = -25;
}
if (Servo_data[AUX8] <= partitions[i] + hysteresis)
{
dataadjust = i;
break;
}
else
{
dataadjust = i+1;
}
}
static uint8_t flightmode = 0;
// flight mode 1250 1500 1750 - aux 1
uint8_t flightmode_old = flightmode;
partitions[0] = 1250; // 4 flight modes
partitions[1] = 1500;
partitions[2] = 1750;
for (uint8_t i = 0; i < 3; ++i)
{
int16_t hysteresis = 0;
if (flightmode_old*2 == (i*2+1) - 1)
{
hysteresis = 25;
}
else if (flightmode_old*2 == (i*2+1) + 1)
{
hysteresis = -25;
}
if (Servo_data[AUX9] <= partitions[i] + hysteresis)
{
flightmode = i;
break;
}
else
{
flightmode = i+1;
}
}
packet[3] |= (flightmode & 0x3);
packet[3] |= (dataselect & 0x7) << 2;
packet[3] |= (dataadjust & 0x3) << 5;
}
#endif
//Aileron //Aileron
val = convert_channel_10b(AILERON); val = convert_channel_10b(AILERON);
packet[4] = (val>>8) + ((val>>2) & 0xFC); packet[4] = (val>>8) + ((val>>2) & 0xFC);
@ -218,24 +99,69 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind)
packet[12] = rx_tx_addr[2]; // txid[2] packet[12] = rx_tx_addr[2]; // txid[2]
packet[13] = sub_protocol==H8S3D?0x34:0x0A; packet[13] = sub_protocol==H8S3D?0x34:0x0A;
packet[14] = 0; packet[14] = 0;
for (uint8_t i=0; i < BAYANG_PACKET_SIZE-1; i++) for (uint8_t i=0; i < BAYANG_PACKET_SIZE-1; i++)
packet[14] += packet[i]; packet[14] += packet[i];
// Power on, TX mode, 2byte CRC
// 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));
NRF24L01_WriteReg(NRF24L01_05_RF_CH, bind ? BAYANG_RF_BIND_CHANNEL:hopping_frequency[hopping_frequency_no++]); NRF24L01_WriteReg(NRF24L01_05_RF_CH, bind ? BAYANG_RF_BIND_CHANNEL:hopping_frequency[hopping_frequency_no++]);
hopping_frequency_no%=BAYANG_RF_NUM_CHANNELS; hopping_frequency_no%=BAYANG_RF_NUM_CHANNELS;
// clear packet status bits and TX FIFO // clear packet status bits and TX FIFO
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushTx(); NRF24L01_FlushTx();
XN297_WritePayload(packet, BAYANG_PACKET_SIZE); XN297_WritePayload(packet, BAYANG_PACKET_SIZE);
NRF24L01_SetTxRxMode(TXRX_OFF);
NRF24L01_SetTxRxMode(TX_EN);
// Power on, TX mode, 2byte CRC
// 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));
#ifdef BAYANG_HUB_TELEMETRY
if (option)
{ // switch radio to rx as soon as packet is sent
while (!(NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS)));
NRF24L01_WriteReg(NRF24L01_00_CONFIG, 0x03);
}
#endif
NRF24L01_SetPower(); // Set tx_power NRF24L01_SetPower(); // Set tx_power
} }
#ifdef BAYANG_HUB_TELEMETRY
static void __attribute__((unused)) check_rx(void)
{
if (NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR))
{ // data received from model
XN297_ReadPayload(packet, BAYANG_PACKET_SIZE);
NRF24L01_WriteReg(NRF24L01_07_STATUS, 255);
NRF24L01_FlushRx();
uint8_t check = packet[0];
for (uint8_t i=1; i < BAYANG_PACKET_SIZE-1; i++)
check += packet[i];
// decode data , check sum is ok as well, since there is no crc
if (packet[0] == 0x85 && packet[14] == check)
{
// uncompensated battery volts*100/2
v_lipo1 = (packet[3]<<7) + (packet[4]>>2);
// compensated battery volts*100/2
v_lipo2 = (packet[5]<<7) + (packet[6]>>2);
// reception in packets / sec
RSSI_dBm = packet[7];
//Flags
//uint8_t flags = packet[3] >> 3;
// battery low: flags & 1
telemetry_counter++;
if(telemetry_lost==0)
telemetry_link=1;
}
}
}
#endif
static void __attribute__((unused)) BAYANG_init() static void __attribute__((unused)) BAYANG_init()
{ {
NRF24L01_Initialize(); NRF24L01_Initialize();
@ -245,46 +171,63 @@ static void __attribute__((unused)) BAYANG_init()
NRF24L01_FlushTx(); NRF24L01_FlushTx();
NRF24L01_FlushRx(); NRF24L01_FlushRx();
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit
NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00); // No Auto Acknowldgement on all data pipes NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00); // No Auto Acknowldgement on all data pipes
NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, 0x01); // Enable data pipe 0 only
NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, BAYANG_PACKET_SIZE); // rx pipe 0 NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, BAYANG_PACKET_SIZE);
NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, 0x01); // Enable data pipe 0 only NRF24L01_SetBitrate(NRF24L01_BR_1M); // 1Mbps
NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03); NRF24L01_SetPower();
NRF24L01_WriteReg(NRF24L01_04_SETUP_RETR, 0x00); // no retransmits NRF24L01_Activate(0x73); // Activate feature register
NRF24L01_SetBitrate(NRF24L01_BR_1M); // 1Mbps NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes
NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x01);
NRF24L01_SetPower(); NRF24L01_Activate(0x73);
} }
uint16_t BAYANG_callback() uint16_t BAYANG_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE_on)
{ {
#ifdef ENABLE_BAYANG_TELEMETRY if(packet_count==0)
if(sub_protocol == BAYANG_TELEM)
{
return Bayang_process();
}
else
#endif
{
BAYANG_send_packet(0); BAYANG_send_packet(0);
} packet_count++;
#ifdef BAYANG_HUB_TELEMETRY
if (option)
{ // telemetry is enabled
state++;
if (state > 1000)
{
//calculate telemetry reception packet rate - packets per 1000ms
TX_RSSI = telemetry_counter;
telemetry_counter = 0;
state = 0;
telemetry_lost=0;
}
if (packet_count > 1)
check_rx();
packet_count %= 5;
}
else
#endif
packet_count%=2;
} }
else else
{ {
if (bind_counter == 0) if (bind_counter == 0)
{ {
XN297_SetTXAddr(rx_tx_addr, BAYANG_ADDRESS_LENGTH); XN297_SetTXAddr(rx_tx_addr, BAYANG_ADDRESS_LENGTH);
XN297_SetRXAddr(rx_tx_addr, BAYANG_ADDRESS_LENGTH); #ifdef BAYANG_HUB_TELEMETRY
XN297_SetRXAddr(rx_tx_addr, BAYANG_ADDRESS_LENGTH);
#endif
BIND_DONE; BIND_DONE;
} }
else else
{ {
BAYANG_send_packet(1); if(packet_count==0)
BAYANG_send_packet(1);
packet_count++;
packet_count%=4;
bind_counter--; bind_counter--;
} }
} }
@ -304,193 +247,15 @@ static void __attribute__((unused)) BAYANG_initialize_txid()
uint16_t initBAYANG(void) uint16_t initBAYANG(void)
{ {
BIND_IN_PROGRESS; // autobind protocol BIND_IN_PROGRESS; // autobind protocol
bind_counter = BAYANG_BIND_COUNT; bind_counter = BAYANG_BIND_COUNT;
BAYANG_initialize_txid(); BAYANG_initialize_txid();
BAYANG_init(); BAYANG_init();
packet_count=0;
#ifdef BAYANG_HUB_TELEMETRY
init_hub_telemetry();
telemetry_lost=1; // do not send telemetry to TX right away until we have a TX_RSSI value to prevent warning message...
#endif
return BAYANG_INITIAL_WAIT+BAYANG_PACKET_PERIOD; return BAYANG_INITIAL_WAIT+BAYANG_PACKET_PERIOD;
} }
#ifdef ENABLE_BAYANG_TELEMETRY
extern float telemetry_voltage;
extern uint16_t telemetry_rx_recv_pps;
extern uint16_t telemetry_tx_recv_pps;
extern uint16_t telemetry_tx_sent_pps;
extern uint8_t telemetry_rx_rssi;
extern uint8_t telemetry_tx_rssi;
extern uint8_t telemetry_datamode;
extern float telemetry_data[3]; // pids
extern uint8_t telemetry_dataitem;
extern uint16_t telemetry_uptime;
extern uint16_t telemetry_flighttime;
extern uint8_t telemetry_flightmode;
uint16_t telemetry_tx_sent_pkt_count;
uint32_t telemetry_tx_sent_pps_time;
uint16_t telemetry_tx_recv_pkt_count;
uint32_t telemetry_tx_recv_pps_time;
static uint32_t bayang_tx_time = 0;
uint8_t BAYANG_recv_packet() {
uint8_t received = 0;
if (NRF24L01_Strobe(NRF24L01_FF_NOP) & _BV(NRF24L01_07_RX_DR)) {
int sum = 0;
uint16_t roll, pitch, yaw, throttle;
XN297_ReadPayload(packet, BAYANG_PACKET_SIZE);
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushRx();
if (packet[0] == 0xA9) {
//serialDebug.print("data packet");
for (int i = 0; i < 14; i++) {
sum += packet[i];
}
if ( (sum & 0xFF) == packet[14] ) {
typedef union {
uint16_t v;
uint8_t bytes[2];
} val;
val v;
v.bytes[0] = packet[1];
v.bytes[1] = packet[2];
telemetry_voltage = v.v / 100.f;
telemetry_rx_recv_pps = packet[3]*2;
telemetry_rx_rssi = (uint8_t)(telemetry_rx_recv_pps*100/telemetry_tx_sent_pps);
if (telemetry_rx_rssi > 100)
telemetry_rx_rssi = 100;
telemetry_tx_rssi = (uint8_t)(telemetry_tx_recv_pps*100/telemetry_rx_recv_pps);
if (telemetry_tx_rssi > 100)
telemetry_tx_rssi = 100;
v.bytes[0] = packet[4];
v.bytes[1] = (packet[6] & 0x0F); // 12 bit # shared with flighttime
telemetry_uptime = v.v;
v.bytes[0] = packet[5];
v.bytes[1] = (packet[6] >> 4);
telemetry_flighttime = v.v;
telemetry_flightmode = packet[7] & 0x3; // 0 = level, 1 = acro,
telemetry_datamode = (packet[7] >> 2) & 0xF; // (0=acro yaw, 1=acro roll/acro pitch, 2=level roll/pitch)
telemetry_dataitem = (packet[7] >> 6) & 0x3; // (0=acro yaw, 1=acro roll/acro pitch, 2=level roll/pitch)
v.bytes[0] = packet[8];
v.bytes[1] = packet[9];
telemetry_data[0] = v.v/1000.f;
v.bytes[0] = packet[10];
v.bytes[1] = packet[11];
telemetry_data[1] = v.v/1000.f;
v.bytes[0] = packet[12];
v.bytes[1] = packet[13];
telemetry_data[2] = v.v/1000.f;
}
}
received = 1;
}
return received;
}
typedef enum
{
BAYANG_STATE_IDLE,
BAYANG_STATE_TRANSMITTING,
BAYANG_STATE_RECEIEVING,
} BayangState;
BayangState Bayang_state = BAYANG_STATE_IDLE;
uint32_t Bayang_next_send = 0;
uint16_t Bayang_process() {
uint32_t time_micros = micros();
uint16_t callback_period = 30; // asap
if (BAYANG_STATE_TRANSMITTING == Bayang_state) {
if (NRF24L01_Strobe(NRF24L01_FF_NOP) & _BV(NRF24L01_07_TX_DS) || time_micros - bayang_tx_time > 1100) {
// send finished, switch to rx to receive telemetry
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP) | _BV(NRF24L01_00_PRIM_RX));
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushRx();
Bayang_state = BAYANG_STATE_RECEIEVING;
callback_period = Bayang_next_send - time_micros - 550; // wait a while for quad to receive then send a packet
}
}
else if (BAYANG_STATE_RECEIEVING == Bayang_state) {
uint8_t change_state = 1;
// 250us is about the time it takes to read a packet over spi
if (time_micros > (Bayang_next_send-250))
{
// if it's been a while since receiving telemetry data,
// stop sending the telemetry data to the transmitter
if (time_micros - bayang_telemetry_last_rx > 1000000)
telemetry_lost = 1;
}
else if (BAYANG_recv_packet())
{
telemetry_tx_recv_pkt_count++;
// received telemetry packet
telemetry_lost = 0;
bayang_telemetry_last_rx = time_micros;
}
else
{
change_state = 0;
}
if (telemetry_tx_recv_pps_time < time_micros)
{
telemetry_tx_recv_pps = telemetry_tx_recv_pps + telemetry_tx_recv_pkt_count - telemetry_tx_recv_pps/10;
telemetry_tx_recv_pkt_count = 0;
telemetry_tx_recv_pps_time += 100000;
}
if (change_state)
{
Bayang_state = BAYANG_STATE_IDLE;
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP));
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushRx();
}
}
else if (time_micros > Bayang_next_send)
{
bayang_tx_time = time_micros;
BAYANG_send_packet(0);
Bayang_state = BAYANG_STATE_TRANSMITTING;
Bayang_next_send = time_micros + BAYANG_PACKET_PERIOD_TELEM;
callback_period = 600; // takes about 1ms to send(spi transfer + tx send)
telemetry_tx_sent_pkt_count++;
if (telemetry_tx_sent_pps_time < time_micros)
{
telemetry_tx_sent_pps = telemetry_tx_sent_pps + telemetry_tx_sent_pkt_count - telemetry_tx_sent_pps/10;
telemetry_tx_sent_pkt_count = 0;
telemetry_tx_sent_pps_time += 100000;
}
}
else
{
callback_period = Bayang_next_send - time_micros;
}
return callback_period;
}
#endif //ENABLE_BAYANG_TELEMETRY
#endif #endif

View File

@ -86,8 +86,8 @@ void CC2500_SetTxRxMode(uint8_t mode)
{ {
if(mode == TX_EN) if(mode == TX_EN)
{//from deviation firmware {//from deviation firmware
CC2500_WriteReg(CC2500_02_IOCFG0, 0x2F | 0x40);
CC2500_WriteReg(CC2500_00_IOCFG2, 0x2F); CC2500_WriteReg(CC2500_00_IOCFG2, 0x2F);
CC2500_WriteReg(CC2500_02_IOCFG0, 0x2F | 0x40);
} }
else else
if (mode == RX_EN) if (mode == RX_EN)

View File

@ -67,12 +67,12 @@ enum H8_3D_FLAGS {
enum H8_3D_FLAGS_2 { enum H8_3D_FLAGS_2 {
// flags going to packet[18] // flags going to packet[18]
H8_3D_FLAG_VIDEO = 0x80,
H8_3D_FLAG_PICTURE = 0x40,
H8_3D_FLAG_CALIBRATE1 = 0x20, // H8 3D acc calibration, H20 headless calib
H8_3D_FLAG_CALIBRATE2 = 0x10, // H11D and H20 acc calibration
H8_3D_FLAG_CAM_DN = 0x08,
H8_3D_FLAG_CAM_UP = 0x04, H8_3D_FLAG_CAM_UP = 0x04,
H8_3D_FLAG_CAM_DOWN = 0x08,
H8_3D_FLAG_CALIBRATE2 = 0x10, // acc calib. (H11D, H20)
H8_3D_FLAG_CALIBRATE = 0x20, // acc calib. (H8 3D), headless calib (H20)
H8_3D_FLAG_SNAPSHOT = 0x40,
H8_3D_FLAG_VIDEO = 0x80,
}; };
static void __attribute__((unused)) CG023_send_packet(uint8_t bind) static void __attribute__((unused)) CG023_send_packet(uint8_t bind)
@ -122,12 +122,16 @@ static void __attribute__((unused)) CG023_send_packet(uint8_t bind)
packet[17] = H8_3D_FLAG_RATE_HIGH packet[17] = H8_3D_FLAG_RATE_HIGH
| GET_FLAG(Servo_AUX1,H8_3D_FLAG_FLIP) | GET_FLAG(Servo_AUX1,H8_3D_FLAG_FLIP)
| GET_FLAG(Servo_AUX2,H8_3D_FLAG_LIGTH) //H22 light | GET_FLAG(Servo_AUX2,H8_3D_FLAG_LIGTH) //H22 light
| GET_FLAG(Servo_AUX3,H8_3D_FLAG_HEADLESS) | GET_FLAG(Servo_AUX5,H8_3D_FLAG_HEADLESS)
| GET_FLAG(Servo_AUX4,H8_3D_FLAG_RTH); // 180/360 flip mode on H8 3D | GET_FLAG(Servo_AUX6,H8_3D_FLAG_RTH); // 180/360 flip mode on H8 3D
packet[18] = GET_FLAG(Servo_AUX5,H8_3D_FLAG_CALIBRATE) packet[18] = GET_FLAG(Servo_AUX3,H8_3D_FLAG_PICTURE)
| GET_FLAG(Servo_AUX5,H8_3D_FLAG_CALIBRATE2) | GET_FLAG(Servo_AUX4,H8_3D_FLAG_VIDEO)
| GET_FLAG(Servo_AUX6,H8_3D_FLAG_SNAPSHOT) | GET_FLAG(Servo_AUX7,H8_3D_FLAG_CALIBRATE1)
| GET_FLAG(Servo_AUX7,H8_3D_FLAG_VIDEO); | GET_FLAG(Servo_AUX8,H8_3D_FLAG_CALIBRATE2);
if(Servo_data[AUX9]<PPM_MIN_COMMAND)
packet[18] |= H8_3D_FLAG_CAM_DN;
if(Servo_data[AUX9]>PPM_MAX_COMMAND)
packet[18] |= H8_3D_FLAG_CAM_UP;
} }
uint8_t sum = packet[9]; uint8_t sum = packet[9];
for (uint8_t i=10; i < H8_3D_PACKET_SIZE-1; i++) for (uint8_t i=10; i < H8_3D_PACKET_SIZE-1; i++)

View File

@ -57,9 +57,10 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
packet[3] = rx_tx_addr[2]; packet[3] = rx_tx_addr[2];
packet[4] = rx_tx_addr[3]; packet[4] = rx_tx_addr[3];
// packet[5] to [8] (aircraft id) is filled during bind for blue board // packet[5] to [8] (aircraft id) is filled during bind for blue board
uint16_t aileron=Servo_data[AILERON]; uint16_t aileron=map(limit_channel_100(AILERON),servo_min_100,servo_max_100,1000,2000);
uint16_t elevator=3000-Servo_data[ELEVATOR]; uint16_t elevator=map(limit_channel_100(ELEVATOR),servo_min_100,servo_max_100,2000,1000);
uint16_t rudder=3000-Servo_data[RUDDER]; uint16_t throttle=map(limit_channel_100(THROTTLE),servo_min_100,servo_max_100,1000,2000);
uint16_t rudder=map(limit_channel_100(RUDDER),servo_min_100,servo_max_100,2000,1000);
// Channel 5 - flip flag // Channel 5 - flip flag
packet[12+offset] = GET_FLAG(Servo_AUX1,CX10_FLAG_FLIP); // flip flag applied on rudder packet[12+offset] = GET_FLAG(Servo_AUX1,CX10_FLAG_FLIP); // flip flag applied on rudder
@ -82,30 +83,16 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
break; break;
case Q282: case Q282:
case Q242: case Q242:
aileron = 3000 - aileron;
rudder = 3000 - rudder;
case Q222: case Q222:
memcpy(&packet[15], "\x10\x10\xaa\xaa\x00\x00", 6); memcpy(&packet[15], "\x10\x10\xaa\xaa\x00\x00", 6);
//FLIP|LED|PICTURE|VIDEO|HEADLESS|RTH|XCAL|YCAL //FLIP|LED|PICTURE|VIDEO|HEADLESS|RTH|XCAL|YCAL
flags2 = GET_FLAG(Servo_AUX1, 0x80) // Channel 5 - FLIP flags2 = GET_FLAG(Servo_AUX1, 0x80) // Channel 5 - FLIP
|GET_FLAG(Servo_AUX2, 0x40) // Channel 6 - LED |GET_FLAG(!Servo_AUX2, 0x40) // Channel 6 - LED
|GET_FLAG(Servo_AUX5, 0x08) // Channel 9 - HEADLESS |GET_FLAG(Servo_AUX5, 0x08) // Channel 9 - HEADLESS
|GET_FLAG(Servo_AUX7, 0x04) // Channel 11 - XCAL |GET_FLAG(Servo_AUX7, 0x04) // Channel 11 - XCAL
|GET_FLAG(Servo_AUX8, 0x02); // Channel 12 - YCAL or Start/Stop motors on JXD 509 |GET_FLAG(Servo_AUX8, 0x02); // Channel 12 - YCAL or Start/Stop motors on JXD 509
if(sub_protocol==Q282) if(sub_protocol==Q242)
{
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
|GET_FLAG(Servo_AUX3,0x10); // Channel 7 - picture
}
else if(sub_protocol==Q242)
{ {
flags=2; flags=2;
flags2|= GET_FLAG(Servo_AUX3,0x01) // Channel 7 - picture flags2|= GET_FLAG(Servo_AUX3,0x01) // Channel 7 - picture
@ -114,8 +101,16 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
packet[18]=0x00; packet[18]=0x00;
} }
else else
{ // Q222 { // Q282 & Q222
flags=0; flags=3; // expert
if(Servo_AUX4) // Channel 8 - Q282 video / Q222 Module 1
{
if (!(video_state & 0x20)) video_state ^= 0x21;
}
else
if (video_state & 0x20) video_state &= 0x01;
flags2 |= video_state
|GET_FLAG(Servo_AUX3,0x10); // Channel 7 - Q282 picture / Q222 Module 2
} }
if(Servo_AUX6) flags |=0x80; // Channel 10 - RTH if(Servo_AUX6) flags |=0x80; // Channel 10 - RTH
break; break;
@ -146,11 +141,11 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind)
break; break;
} }
packet[5+offset] = lowByte(aileron); packet[5+offset] = lowByte(aileron);
packet[6+offset]= highByte(aileron); packet[6+offset] = highByte(aileron);
packet[7+offset]= lowByte(elevator); packet[7+offset] = lowByte(elevator);
packet[8+offset]= highByte(elevator); packet[8+offset] = highByte(elevator);
packet[9+offset] = lowByte(Servo_data[THROTTLE]); packet[9+offset] = lowByte(throttle);
packet[10+offset]= highByte(Servo_data[THROTTLE]); packet[10+offset]= highByte(throttle);
packet[11+offset]= lowByte(rudder); packet[11+offset]= lowByte(rudder);
packet[12+offset]|= highByte(rudder); packet[12+offset]|= highByte(rudder);
packet[13+offset]=flags; packet[13+offset]=flags;

View File

@ -15,6 +15,7 @@
// Last sync with hexfet new_protocols/fy326_nrf24l01.c dated 2015-07-29 // Last sync with hexfet new_protocols/fy326_nrf24l01.c dated 2015-07-29
#if defined(FY326_NRF24L01_INO) #if defined(FY326_NRF24L01_INO)
#include "iface_nrf24l01.h" #include "iface_nrf24l01.h"
#define FY326_INITIAL_WAIT 500 #define FY326_INITIAL_WAIT 500
@ -26,11 +27,9 @@
#define FY326_NUM_RF_CHANNELS 5 #define FY326_NUM_RF_CHANNELS 5
enum { enum {
FY326_INIT1 = 0, FY326_BIND1=0,
FY326_BIND1,
FY326_BIND2, FY326_BIND2,
FY326_DATA, FY326_DATA,
FY319_INIT1,
FY319_BIND1, FY319_BIND1,
FY319_BIND2, FY319_BIND2,
}; };
@ -42,32 +41,34 @@ static void __attribute__((unused)) FY326_send_packet(uint8_t bind)
{ {
packet[0] = rx_tx_addr[3]; packet[0] = rx_tx_addr[3];
if(bind) if(bind)
packet[1] = 0x55; packet[1] = 0x55;
else else
packet[1] = GET_FLAG(Servo_AUX3, 0x80) // Headless packet[1] = GET_FLAG(Servo_AUX3, 0x80) // Headless
| GET_FLAG(Servo_AUX2, 0x40) // RTH | GET_FLAG(Servo_AUX2, 0x40) // RTH
| GET_FLAG(Servo_AUX1, 0x02) // Flip | GET_FLAG(Servo_AUX1, 0x02) // Flip
| GET_FLAG(Servo_AUX5, 0x01) // Calibrate | GET_FLAG(Servo_AUX5, 0x01) // Calibrate
| GET_FLAG(Servo_AUX4, 0x04); // Expert | GET_FLAG(Servo_AUX4, 0x04); // Expert
packet[2] = 200 - convert_channel_8b_scale(AILERON, 0, 200); // aileron packet[2] = convert_channel_8b_scale(AILERON, 0, 200); // aileron
packet[3] = convert_channel_8b_scale(ELEVATOR, 0, 200); // elevator packet[3] = convert_channel_8b_scale(ELEVATOR, 0, 200); // elevator
packet[4] = 200 - convert_channel_8b_scale(RUDDER, 0, 200); // rudder packet[4] = convert_channel_8b_scale(RUDDER, 0, 200); // rudder
packet[5] = convert_channel_8b_scale(THROTTLE, 0, 200); // throttle packet[5] = convert_channel_8b_scale(THROTTLE, 0, 200); // throttle
if(sub_protocol == FY319) { if(sub_protocol==FY319)
packet[6] = 255 - convert_channel_8b_scale(AILERON, 0, 255); {
packet[7] = convert_channel_8b_scale(ELEVATOR, 0, 255); packet[6] = convert_channel_8b(AILERON);
packet[8] = 255 - convert_channel_8b_scale(RUDDER, 0, 255); packet[7] = convert_channel_8b(ELEVATOR);
} packet[8] = convert_channel_8b(RUDDER);
else { }
else
{
packet[6] = rx_tx_addr[0]; packet[6] = rx_tx_addr[0];
packet[7] = rx_tx_addr[1]; packet[7] = rx_tx_addr[1];
packet[8] = rx_tx_addr[2]; packet[8] = rx_tx_addr[2];
} }
packet[9] = CHAN_TO_TRIM(packet[2]); // aileron_trim; packet[9] = CHAN_TO_TRIM(packet[2]); // aileron_trim;
packet[10] = CHAN_TO_TRIM(packet[3]); // elevator_trim; packet[10] = CHAN_TO_TRIM(packet[3]); // elevator_trim;
packet[11] = CHAN_TO_TRIM(packet[4]); // rudder_trim; packet[11] = CHAN_TO_TRIM(packet[4]); // rudder_trim;
packet[12] = 0; // throttle_trim; packet[12] = 0; // throttle_trim;
packet[13] = rxid; packet[13] = rxid;
packet[14] = rx_tx_addr[4]; packet[14] = rx_tx_addr[4];
if (bind) if (bind)
@ -76,12 +77,11 @@ static void __attribute__((unused)) FY326_send_packet(uint8_t bind)
{ {
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no++]); NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no++]);
hopping_frequency_no %= FY326_NUM_RF_CHANNELS; hopping_frequency_no %= FY326_NUM_RF_CHANNELS;
}
} // clear packet status bits and TX FIFO
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
// clear packet status bits and TX FIFO NRF24L01_FlushTx();
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushTx();
NRF24L01_WritePayload(packet, FY326_PACKET_SIZE); NRF24L01_WritePayload(packet, FY326_PACKET_SIZE);
@ -90,12 +90,12 @@ static void __attribute__((unused)) FY326_send_packet(uint8_t bind)
static void __attribute__((unused)) FY326_init() static void __attribute__((unused)) FY326_init()
{ {
NRF24L01_Initialize(); NRF24L01_Initialize();
NRF24L01_SetTxRxMode(TX_EN); NRF24L01_SetTxRxMode(TX_EN);
if(sub_protocol == FY319) if(sub_protocol==FY319)
NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03); // Five-byte rx/tx address NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03); // Five-byte rx/tx address
else else
NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x01); // Three-byte rx/tx address NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x01); // Three-byte rx/tx address
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t *)"\x15\x59\x23\xc6\x29", 5); NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t *)"\x15\x59\x23\xc6\x29", 5);
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t *)"\x15\x59\x23\xc6\x29", 5); NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t *)"\x15\x59\x23\xc6\x29", 5);
NRF24L01_FlushTx(); NRF24L01_FlushTx();
@ -108,135 +108,117 @@ static void __attribute__((unused)) FY326_init()
NRF24L01_SetBitrate(NRF24L01_BR_250K); NRF24L01_SetBitrate(NRF24L01_BR_250K);
NRF24L01_SetPower(); NRF24L01_SetPower();
NRF24L01_Activate(0x73); NRF24L01_Activate(0x73);
NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x3f); NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x3f);
NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x07); NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x07);
NRF24L01_Activate(0x73); NRF24L01_Activate(0x73);
//Switch to RX
NRF24L01_SetTxRxMode(TXRX_OFF);
NRF24L01_FlushRx();
NRF24L01_SetTxRxMode(RX_EN);
} }
uint16_t FY326_callback() uint16_t FY326_callback()
{ {
uint8_t i; switch (phase)
switch (phase) { {
case FY319_INIT1: case FY319_BIND1:
NRF24L01_SetTxRxMode(TXRX_OFF); if(NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR))
NRF24L01_FlushRx(); {
NRF24L01_SetTxRxMode(RX_EN);
NRF24L01_WriteReg(NRF24L01_05_RF_CH, FY326_RF_BIND_CHANNEL);
phase = FY319_BIND1;
BIND_IN_PROGRESS;
return FY326_PACKET_CHKTIME;
break;
case FY319_BIND1:
if(NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) {
NRF24L01_ReadPayload(packet, FY326_PACKET_SIZE);
rxid = packet[13];
packet[0] = rx_tx_addr[3];
packet[1] = 0x80;
packet[14]= rx_tx_addr[4];
bind_counter = FY326_BIND_COUNT;
NRF24L01_SetTxRxMode(TXRX_OFF);
NRF24L01_SetTxRxMode(TX_EN);
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushTx();
bind_counter = 255;
for(i=2; i<6; i++)
packet[i] = hopping_frequency[0];
phase = FY319_BIND2;
}
return FY326_PACKET_CHKTIME;
break;
case FY319_BIND2:
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushTx();
NRF24L01_WritePayload(packet, FY326_PACKET_SIZE);
if(bind_counter == 250)
packet[1] = 0x40;
if(--bind_counter == 0) {
BIND_DONE;
phase = FY326_DATA;
}
break;
case FY326_INIT1:
bind_counter = FY326_BIND_COUNT;
phase = FY326_BIND2;
FY326_send_packet(1);
return FY326_PACKET_CHKTIME;
break;
case FY326_BIND1:
if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR))
{ // RX fifo data ready
NRF24L01_ReadPayload(packet, FY326_PACKET_SIZE); NRF24L01_ReadPayload(packet, FY326_PACKET_SIZE);
rxid = packet[13]; rxid = packet[13];
rx_tx_addr[0] = 0xAA; packet[0] = rx_tx_addr[3];
NRF24L01_SetTxRxMode(TXRX_OFF); packet[1] = 0x80;
NRF24L01_SetTxRxMode(TX_EN); packet[14]= rx_tx_addr[4];
BIND_DONE; NRF24L01_SetTxRxMode(TXRX_OFF);
phase = FY326_DATA; NRF24L01_SetTxRxMode(TX_EN);
} NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
else NRF24L01_FlushTx();
if (bind_counter-- == 0) bind_counter = 255;
{ for(uint8_t i=2; i<6; i++)
bind_counter = FY326_BIND_COUNT; packet[i] = hopping_frequency[0];
NRF24L01_SetTxRxMode(TXRX_OFF); phase = FY319_BIND2;
NRF24L01_SetTxRxMode(TX_EN); }
FY326_send_packet(1); return FY326_PACKET_CHKTIME;
phase = FY326_BIND2; break;
return FY326_PACKET_CHKTIME; case FY319_BIND2:
} NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
break; NRF24L01_FlushTx();
NRF24L01_WritePayload(packet, FY326_PACKET_SIZE);
case FY326_BIND2: if(bind_counter == 250)
packet[1] = 0x40;
if(--bind_counter == 0)
{
BIND_DONE;
phase = FY326_DATA;
}
break;
case FY326_BIND1:
if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR))
{ // RX fifo data ready
NRF24L01_ReadPayload(packet, FY326_PACKET_SIZE);
rxid = packet[13];
rx_tx_addr[0] = 0xAA;
NRF24L01_SetTxRxMode(TXRX_OFF);
NRF24L01_SetTxRxMode(TX_EN);
BIND_DONE;
phase = FY326_DATA;
}
else
if (bind_counter-- == 0)
{
bind_counter = FY326_BIND_COUNT;
NRF24L01_SetTxRxMode(TXRX_OFF);
NRF24L01_SetTxRxMode(TX_EN);
FY326_send_packet(1);
phase = FY326_BIND2;
return FY326_PACKET_CHKTIME;
}
break;
case FY326_BIND2:
if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS)) if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS))
{ // TX data sent -> switch to RX mode { // TX data sent -> switch to RX mode
NRF24L01_SetTxRxMode(TXRX_OFF); NRF24L01_SetTxRxMode(TXRX_OFF);
NRF24L01_FlushRx(); NRF24L01_FlushRx();
NRF24L01_SetTxRxMode(RX_EN); NRF24L01_SetTxRxMode(RX_EN);
phase = FY326_BIND1; phase = FY326_BIND1;
} }
else else
return FY326_PACKET_CHKTIME; return FY326_PACKET_CHKTIME;
break; break;
case FY326_DATA:
case FY326_DATA: FY326_send_packet(0);
FY326_send_packet(0); break;
break; }
}
return FY326_PACKET_PERIOD; return FY326_PACKET_PERIOD;
} }
static void __attribute__((unused)) FY326_initialize_txid() static void __attribute__((unused)) FY326_initialize_txid()
{ {
if(sub_protocol == FY319) { hopping_frequency[0] = (rx_tx_addr[0]&0x0f);
hopping_frequency[0] = (rx_tx_addr[0]&0x0f) & ~0x80; hopping_frequency[1] = 0x10 + (rx_tx_addr[0] >> 4);
hopping_frequency[1] = (rx_tx_addr[0] >> 4) & ~0x80; hopping_frequency[2] = 0x20 + (rx_tx_addr[1]&0x0f);
hopping_frequency[2] = (rx_tx_addr[1]&0x0f) & ~0x80; hopping_frequency[3] = 0x30 + (rx_tx_addr[1] >> 4);
hopping_frequency[3] = (rx_tx_addr[1] >> 4) & ~0x80; hopping_frequency[4] = 0x40 + (rx_tx_addr[2] >> 4);
hopping_frequency[4] = (rx_tx_addr[2] >> 4) & ~0x80; if(sub_protocol==FY319)
} else { for(uint8_t i=0;i<5;i++)
hopping_frequency[0] = (rx_tx_addr[0]&0x0f); hopping_frequency[i]=rx_tx_addr[0] & ~0x80;
hopping_frequency[1] = 0x10 + (rx_tx_addr[0] >> 4);
hopping_frequency[2] = 0x20 + (rx_tx_addr[1]&0x0f);
hopping_frequency[3] = 0x30 + (rx_tx_addr[1] >> 4);
hopping_frequency[4] = 0x40 + (rx_tx_addr[2] >> 4);
}
} }
uint16_t initFY326(void) uint16_t initFY326(void)
{ {
BIND_IN_PROGRESS; // autobind protocol BIND_IN_PROGRESS; // autobind protocol
rxid = 0xAA; rxid = 0xAA;
bind_counter = 0; bind_counter = FY326_BIND_COUNT;
FY326_initialize_txid(); FY326_initialize_txid();
FY326_init(); FY326_init();
if(sub_protocol == FY319) if(sub_protocol==FY319)
phase = FY319_INIT1; {
else phase=FY319_BIND1;
phase = FY326_INIT1; }
else
phase=FY326_BIND1;
return FY326_INITIAL_WAIT; return FY326_INITIAL_WAIT;
} }

View File

@ -19,9 +19,9 @@
#define HONTAI_BIND_COUNT 80 #define HONTAI_BIND_COUNT 80
#define HONTAI_PACKET_PERIOD 13500 #define HONTAI_PACKET_PERIOD 13500
#define FQ777_951_PACKET_PERIOD 10000
#define HONTAI_INITIAL_WAIT 500 #define HONTAI_INITIAL_WAIT 500
#define HONTAI_BIND_HONTAI_PACKET_SIZE 10 #define HONTAI_BIND_PACKET_SIZE 10
#define HONTAI_PACKET_SIZE 12 #define HONTAI_PACKET_SIZE 12
#define HONTAI_RF_BIND_CHANNEL 0 #define HONTAI_RF_BIND_CHANNEL 0
@ -61,62 +61,15 @@ static void __attribute__((unused)) crc16(uint8_t *data_p, uint8_t length)
static void __attribute__((unused)) HONTAI_send_packet(uint8_t bind) static void __attribute__((unused)) HONTAI_send_packet(uint8_t bind)
{ {
uint8_t packet_size;
if (bind) if (bind)
{ {
memcpy(packet, rx_tx_addr, 5); memcpy(packet, rx_tx_addr, 5);
memset(&packet[5], 0, 3); memset(&packet[5], 0, 3);
packet_size=HONTAI_BIND_HONTAI_PACKET_SIZE;
} }
else else
{ {
/* memset(packet,0,HONTAI_PACKET_SIZE);
if(sub_protocol == FORMAT_JJRCX1) packet[3] = convert_channel_8b_scale(THROTTLE, 0, 127) << 1; // Throttle
packet[0] = GET_FLAG(Servo_AUX2, 0x02); // Arm
else
packet[0] = 0x0b;
packet[1] = 0x00;
packet[2] = 0x00;
packet[3] = (convert_channel_8b_scale(THROTTLE, 0, 127) << 1) // Throttle
| GET_FLAG(Servo_AUX3, 0x01); // Picture
packet[4] = convert_channel_8b_scale(AILERON, 63, 0); // Aileron
if(sub_protocol == FORMAT_HONTAI)
{
packet[4] |= GET_FLAG(Servo_AUX6, 0x80) // RTH
| GET_FLAG(Servo_AUX5, 0x40); // Headless
}
else
{
packet[4] |= 0x80; // not sure what this bit does
if (sub_protocol == FORMAT_X5C1)
packet[4] |= GET_FLAG(Servo_AUX2, 0x40); // Lights (X5C1)
}
packet[5] = convert_channel_8b_scale(ELEVATOR, 0, 63) // Elevator
| GET_FLAG(Servo_AUX7, 0x80) // Calibrate
| GET_FLAG(Servo_AUX1, 0x40); // Flip
packet[6] = convert_channel_8b_scale(RUDDER, 0, 63) // Rudder
| GET_FLAG(Servo_AUX4, 0x80); // Video
if(sub_protocol == FORMAT_X5C1)
packet[7] = convert_channel_8b_scale(AILERON, 0, 63)-31; // Aileron trim
else
packet[7] = convert_channel_8b_scale(AILERON, 0, 32)-16; // Aileron trim
if(sub_protocol == FORMAT_HONTAI)
packet[8] = convert_channel_8b_scale(RUDDER, 0, 32)-16; // Rudder trim
else
{
packet[8] = 0xc0 // Always in expert mode
| GET_FLAG(Servo_AUX6, 0x02) // RTH
| GET_FLAG(Servo_AUX5, 0x01); // Headless
}
if (sub_protocol == FORMAT_X5C1)
packet[9] = convert_channel_8b_scale(ELEVATOR, 0, 63)-31; // Elevator trim
else
packet[9] = convert_channel_8b_scale(ELEVATOR, 0, 32)-16; // Elevator trim
*/
packet[1] = 0x00;
packet[2] = 0x00;
packet[3] = (convert_channel_8b_scale(THROTTLE, 0, 127) << 1); // Throttle
packet[4] = convert_channel_8b_scale(AILERON, 63, 0); // Aileron packet[4] = convert_channel_8b_scale(AILERON, 63, 0); // Aileron
packet[5] = convert_channel_8b_scale(ELEVATOR, 0, 63); // Elevator packet[5] = convert_channel_8b_scale(ELEVATOR, 0, 63); // Elevator
packet[6] = convert_channel_8b_scale(RUDDER, 0, 63); // Rudder packet[6] = convert_channel_8b_scale(RUDDER, 0, 63); // Rudder
@ -124,52 +77,56 @@ static void __attribute__((unused)) HONTAI_send_packet(uint8_t bind)
packet[7] = convert_channel_8b_scale(AILERON, 0, 63)-31; // Aileron trim packet[7] = convert_channel_8b_scale(AILERON, 0, 63)-31; // Aileron trim
else else
packet[7] = convert_channel_8b_scale(AILERON, 0, 32)-16; // Aileron trim packet[7] = convert_channel_8b_scale(AILERON, 0, 32)-16; // Aileron trim
packet[8] = convert_channel_8b_scale(RUDDER, 0, 32)-16; // Rudder trim
if (sub_protocol == FORMAT_X5C1) if (sub_protocol == FORMAT_X5C1)
packet[9] = convert_channel_8b_scale(ELEVATOR, 0, 63)-31; // Elevator trim packet[9] = convert_channel_8b_scale(ELEVATOR, 0, 63)-31; // Elevator trim
else else
packet[9] = convert_channel_8b_scale(ELEVATOR, 0, 32)-16; // Elevator trim packet[9] = convert_channel_8b_scale(ELEVATOR, 0, 32)-16; // Elevator trim
switch(sub_protocol)
switch(sub_protocol) { {
case FORMAT_HONTAI: case FORMAT_HONTAI:
packet[0] = 0x0b; packet[0] = 0x0B;
packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture
packet[4] |= GET_FLAG(Servo_AUX6, 0x80) // RTH packet[4] |= GET_FLAG(Servo_AUX6, 0x80) // RTH
| GET_FLAG(Servo_AUX5, 0x40); // Headless | GET_FLAG(Servo_AUX5, 0x40); // Headless
packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate
| GET_FLAG(Servo_AUX1, 0x40); // Flip | GET_FLAG(Servo_AUX1, 0x40); // Flip
packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video
packet[8] = convert_channel_8b_scale(RUDDER, 0, 32)-16; // Rudder trim break;
break; case FORMAT_JJRCX1:
case FORMAT_X5C1: packet[0] = GET_FLAG(Servo_AUX2, 0x02); // Arm
case FORMAT_JJRCX1: packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture
packet[0] = GET_FLAG(Servo_AUX2, 0x02); //Arm packet[4] |= 0x80; // unknown
packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate
packet[4] |= 0x80; // unknown | GET_FLAG(Servo_AUX1, 0x40); // Flip
if (sub_protocol == FORMAT_X5C1) packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video
packet[4] |= GET_FLAG(Servo_AUX2, 0x40); // Lights (X5C1) packet[8] = 0xC0 // high rate, no rudder trim
packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate | GET_FLAG(Servo_AUX6, 0x02) // RTH
| GET_FLAG(Servo_AUX1, 0x40); // Flip | GET_FLAG(Servo_AUX5, 0x01); // Headless
packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video break;
packet[8] = 0xc0 // high rate, no rudder trim case FORMAT_X5C1:
| GET_FLAG(Servo_AUX6, 0x02) // RTH packet[0] = 0x0B;
| GET_FLAG(Servo_AUX5, 0x01); // Headless packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture
break; packet[4] = 0x80 // unknown
case FORMAT_FQ777: | GET_FLAG(Servo_AUX2, 0x40); // Lights
// todo: add missing calibration flag packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate
packet[0] = GET_FLAG(Servo_AUX3, 0x01) // Picture | GET_FLAG(Servo_AUX1, 0x40); // Flip
| GET_FLAG(Servo_AUX4, 0x02); // Video packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video
packet[3] |= GET_FLAG(Servo_AUX1, 0x01); // Flip packet[8] = 0xC0 // high rate, no rudder trim
packet[4] |= 0xc0; // high rate (mid=0xa0, low=0x60) | GET_FLAG(Servo_AUX6, 0x02) // RTH
packet[6] |= GET_FLAG(Servo_AUX5, 0x40); // Headless | GET_FLAG(Servo_AUX5, 0x01); // Headless
if((packet[4] & 0x3f) > 0x3d && (packet[5] & 0x3f) < 3) break;
packet[5] |= 0x80; // accelerometer recalibration case FORMAT_FQ777_951:
break; packet[0] = GET_FLAG(Servo_AUX3, 0x01) // Picture
packet[8] = convert_channel_8b_scale(RUDDER, 0, 32)-16; // Rudder trim | GET_FLAG(Servo_AUX4, 0x02); // Video
} packet[3] |= GET_FLAG(Servo_AUX1, 0x01); // Flip
packet[4] |= 0xC0; // High rate (mid=0xa0, low=0x60)
packet_size=HONTAI_PACKET_SIZE; packet[5] |= GET_FLAG(Servo_AUX7, 0x80); // Calibrate
packet[6] |= GET_FLAG(Servo_AUX5, 0x40); // Headless
break;
}
} }
crc16(packet, packet_size); crc16(packet, bind ? HONTAI_BIND_PACKET_SIZE:HONTAI_PACKET_SIZE);
// Power on, TX mode, 2byte CRC // Power on, TX mode, 2byte CRC
if(sub_protocol == FORMAT_JJRCX1) if(sub_protocol == FORMAT_JJRCX1)
@ -184,9 +141,9 @@ static void __attribute__((unused)) HONTAI_send_packet(uint8_t bind)
NRF24L01_FlushTx(); NRF24L01_FlushTx();
if(sub_protocol == FORMAT_JJRCX1) if(sub_protocol == FORMAT_JJRCX1)
NRF24L01_WritePayload(packet, packet_size); NRF24L01_WritePayload(packet, bind ? HONTAI_BIND_PACKET_SIZE:HONTAI_PACKET_SIZE);
else else
XN297_WritePayload(packet, packet_size); XN297_WritePayload(packet, bind ? HONTAI_BIND_PACKET_SIZE:HONTAI_PACKET_SIZE);
NRF24L01_SetPower(); NRF24L01_SetPower();
} }
@ -224,12 +181,11 @@ static void __attribute__((unused)) HONTAI_init()
NRF24L01_Activate(0x73); // Deactivate feature register NRF24L01_Activate(0x73); // Deactivate feature register
} }
const uint8_t PROGMEM hopping_frequency_nonels[][3] = { const uint8_t PROGMEM HONTAI_hopping_frequency_nonels[][3] = {
{0x05, 0x19, 0x28}, // Hontai {0x05, 0x19, 0x28}, // Hontai
{0x0a, 0x1e, 0x2d}, // JJRC X1 {0x0a, 0x1e, 0x2d}}; // JJRC X1
{0x05, 0x19, 0x28}}; // FQ777-951
const uint8_t PROGMEM addr_vals[4][16] = { const uint8_t PROGMEM HONTAI_addr_vals[4][16] = {
{0x24, 0x26, 0x2a, 0x2c, 0x32, 0x34, 0x36, 0x4a, 0x4c, 0x4e, 0x54, 0x56, 0x5a, 0x64, 0x66, 0x6a}, {0x24, 0x26, 0x2a, 0x2c, 0x32, 0x34, 0x36, 0x4a, 0x4c, 0x4e, 0x54, 0x56, 0x5a, 0x64, 0x66, 0x6a},
{0x92, 0x94, 0x96, 0x9a, 0xa4, 0xa6, 0xac, 0xb2, 0xb4, 0xb6, 0xca, 0xcc, 0xd2, 0xd4, 0xd6, 0xda}, {0x92, 0x94, 0x96, 0x9a, 0xa4, 0xa6, 0xac, 0xb2, 0xb4, 0xb6, 0xca, 0xcc, 0xd2, 0xd4, 0xd6, 0xda},
{0x93, 0x95, 0x99, 0x9b, 0xa5, 0xa9, 0xab, 0xad, 0xb3, 0xb5, 0xc9, 0xcb, 0xcd, 0xd3, 0xd5, 0xd9}, {0x93, 0x95, 0x99, 0x9b, 0xa5, 0xa9, 0xab, 0xad, 0xb3, 0xb5, 0xc9, 0xcb, 0xcd, 0xd3, 0xd5, 0xd9},
@ -240,10 +196,10 @@ static void __attribute__((unused)) HONTAI_init2()
uint8_t data_tx_addr[5]; uint8_t data_tx_addr[5];
//TX address //TX address
data_tx_addr[0] = pgm_read_byte_near( &addr_vals[0][ rx_tx_addr[3] & 0x0f]); data_tx_addr[0] = pgm_read_byte_near( &HONTAI_addr_vals[0][ rx_tx_addr[3] & 0x0f]);
data_tx_addr[1] = pgm_read_byte_near( &addr_vals[1][(rx_tx_addr[3] >> 4) & 0x0f]); data_tx_addr[1] = pgm_read_byte_near( &HONTAI_addr_vals[1][(rx_tx_addr[3] >> 4) & 0x0f]);
data_tx_addr[2] = pgm_read_byte_near( &addr_vals[2][ rx_tx_addr[4] & 0x0f]); data_tx_addr[2] = pgm_read_byte_near( &HONTAI_addr_vals[2][ rx_tx_addr[4] & 0x0f]);
data_tx_addr[3] = pgm_read_byte_near( &addr_vals[3][(rx_tx_addr[4] >> 4) & 0x0f]); data_tx_addr[3] = pgm_read_byte_near( &HONTAI_addr_vals[3][(rx_tx_addr[4] >> 4) & 0x0f]);
data_tx_addr[4] = 0x24; data_tx_addr[4] = 0x24;
if(sub_protocol == FORMAT_JJRCX1) if(sub_protocol == FORMAT_JJRCX1)
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, data_tx_addr, sizeof(data_tx_addr)); NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, data_tx_addr, sizeof(data_tx_addr));
@ -252,14 +208,14 @@ static void __attribute__((unused)) HONTAI_init2()
//Hopping frequency table //Hopping frequency table
for(uint8_t i=0;i<3;i++) for(uint8_t i=0;i<3;i++)
hopping_frequency[i]=pgm_read_byte_near( &hopping_frequency_nonels[sub_protocol == FORMAT_JJRCX1?1:0][i] ); hopping_frequency[i]=pgm_read_byte_near( &HONTAI_hopping_frequency_nonels[sub_protocol == FORMAT_JJRCX1?1:0][i] );
hopping_frequency_no=0; hopping_frequency_no=0;
} }
static void __attribute__((unused)) HONTAI_initialize_txid() static void __attribute__((unused)) HONTAI_initialize_txid()
{ {
rx_tx_addr[4] = rx_tx_addr[2]; rx_tx_addr[4] = rx_tx_addr[2];
if(sub_protocol == FORMAT_HONTAI) if(sub_protocol == FORMAT_HONTAI || sub_protocol == FORMAT_FQ777_951)
{ {
rx_tx_addr[0] = 0x4c; // first three bytes some kind of model id? - set same as stock tx rx_tx_addr[0] = 0x4c; // first three bytes some kind of model id? - set same as stock tx
rx_tx_addr[1] = 0x4b; rx_tx_addr[1] = 0x4b;
@ -288,7 +244,7 @@ uint16_t HONTAI_callback()
else else
HONTAI_send_packet(0); HONTAI_send_packet(0);
return HONTAI_PACKET_PERIOD; return sub_protocol == FORMAT_FQ777_951 ? FQ777_951_PACKET_PERIOD : HONTAI_PACKET_PERIOD;
} }
uint16_t initHONTAI() uint16_t initHONTAI()

View File

@ -249,7 +249,7 @@ static void __attribute__((unused)) hubsan_build_packet()
hubsan_update_crc(); hubsan_update_crc();
} }
#if defined(TELEMETRY) #ifdef HUBSAN_HUB_TELEMETRY
static uint8_t __attribute__((unused)) hubsan_check_integrity() static uint8_t __attribute__((unused)) hubsan_check_integrity()
{ {
if( (packet[0]&0xFE) != 0xE0 ) if( (packet[0]&0xFE) != 0xE0 )
@ -263,7 +263,7 @@ static uint8_t __attribute__((unused)) hubsan_check_integrity()
uint16_t ReadHubsan() uint16_t ReadHubsan()
{ {
#if defined(TELEMETRY) #ifdef HUBSAN_HUB_TELEMETRY
static uint8_t rfMode=0; static uint8_t rfMode=0;
#endif #endif
static uint8_t txState=0; static uint8_t txState=0;
@ -348,7 +348,7 @@ uint16_t ReadHubsan()
case DATA_4: case DATA_4:
case DATA_5: case DATA_5:
if( txState == 0) { // send packet if( txState == 0) { // send packet
#if defined(TELEMETRY) #ifdef HUBSAN_HUB_TELEMETRY
rfMode = A7105_TX; rfMode = A7105_TX;
#endif #endif
if( phase == DATA_1) if( phase == DATA_1)
@ -370,7 +370,7 @@ uint16_t ReadHubsan()
delay=3000; delay=3000;
} }
else { else {
#if defined(TELEMETRY) #ifdef HUBSAN_HUB_TELEMETRY
if( rfMode == A7105_TX) if( rfMode == A7105_TX)
{// switch to rx mode 3ms after packet sent {// switch to rx mode 3ms after packet sent
for( i=0; i<10; i++) for( i=0; i<10; i++)
@ -392,7 +392,7 @@ uint16_t ReadHubsan()
A7105_ReadData(16); A7105_ReadData(16);
if( hubsan_check_integrity() ) if( hubsan_check_integrity() )
{ {
v_lipo=packet[13];// hubsan lipo voltage 8bits the real value is h_lipo/10(0x2A=42 -> 4.2V) v_lipo1=packet[13]*2;// hubsan lipo voltage 8bits the real value is h_lipo/10(0x2A=42 -> 4.2V)
telemetry_link=1; telemetry_link=1;
} }
A7105_Strobe(A7105_RX); A7105_Strobe(A7105_RX);
@ -428,8 +428,8 @@ uint16_t initHubsan() {
phase = BIND_1; phase = BIND_1;
packet_count=0; packet_count=0;
id_data=ID_NORMAL; id_data=ID_NORMAL;
#if defined(TELEMETRY) #ifdef HUBSAN_HUB_TELEMETRY
telemetry_link=0; init_hub_telemetry();
#endif #endif
return 10000; return 10000;
} }

View File

@ -36,6 +36,40 @@ const uint8_t PROGMEM MJXQ_map_rfchan[][4] = {
{0x0A, 0x3C, 0x36, 0x3F}, {0x0A, 0x3C, 0x36, 0x3F},
{0x0A, 0x43, 0x36, 0x3F} }; {0x0A, 0x43, 0x36, 0x3F} };
const uint8_t PROGMEM E010_map_txid[][2] = {
{0x4F, 0x1C},
{0x90, 0x1C},
{0x24, 0x36},
{0x7A, 0x40},
{0x61, 0x31},
{0x5D, 0x37},
{0xFD, 0x4F},
{0x86, 0x3C},
{0x41, 0x22},
{0xEE, 0xB3},
{0x9A, 0xB2},
{0xC0, 0x44},
{0x2A, 0xFE},
{0xD7, 0x6E},
{0x3C, 0xCD} // for this ID rx_tx_addr[2]=0x01
};
const uint8_t PROGMEM E010_map_rfchan[][2] = {
{0x3A, 0x35},
{0x2E, 0x36},
{0x32, 0x3E},
{0x2E, 0x3C},
{0x2F, 0x3B},
{0x33, 0x3B},
{0x33, 0x3B},
{0x34, 0x3E},
{0x34, 0x2F},
{0x39, 0x3E},
{0x2E, 0x36},
{0x2E, 0x36},
{0x2E, 0x36},
{0x3A, 0x41},
{0x32, 0x3E} };
#define MJXQ_PAN_TILT_COUNT 16 // for H26D - match stock tx timing #define MJXQ_PAN_TILT_COUNT 16 // for H26D - match stock tx timing
#define MJXQ_PAN_DOWN 0x08 #define MJXQ_PAN_DOWN 0x08
@ -84,17 +118,18 @@ static void __attribute__((unused)) MJXQ_send_packet(uint8_t bind)
packet[14] = 0xC0; // bind value packet[14] = 0xC0; // bind value
// Servo_AUX1 FLIP // Servo_AUX1 FLIP
// Servo_AUX2 LED // Servo_AUX2 LED / ARM
// Servo_AUX3 PICTURE // Servo_AUX3 PICTURE
// Servo_AUX4 VIDEO // Servo_AUX4 VIDEO
// Servo_AUX5 HEADLESS // Servo_AUX5 HEADLESS
// Servo_AUX6 RTH // Servo_AUX6 RTH
// Servo_AUX7 AUTOFLIP // X800, X600 // Servo_AUX7 AUTOFLIP // X800, X600
// Servo_AUX8 ARM // H26WH // Servo_AUX8 PAN
// Servo_AUX9 TILT
switch(sub_protocol) switch(sub_protocol)
{ {
case H26D:
case H26WH: case H26WH:
case H26D:
packet[10]=MJXQ_pan_tilt_value(); packet[10]=MJXQ_pan_tilt_value();
// fall through on purpose - no break // fall through on purpose - no break
case WLH08: case WLH08:
@ -107,12 +142,13 @@ static void __attribute__((unused)) MJXQ_send_packet(uint8_t bind)
| GET_FLAG(Servo_AUX1, 0x01) //FLIP | GET_FLAG(Servo_AUX1, 0x01) //FLIP
| GET_FLAG(Servo_AUX3, 0x08) //PICTURE | GET_FLAG(Servo_AUX3, 0x08) //PICTURE
| GET_FLAG(Servo_AUX4, 0x10) //VIDEO | GET_FLAG(Servo_AUX4, 0x10) //VIDEO
| GET_FLAG(!Servo_AUX2, 0x20); // air/ground mode | GET_FLAG(!Servo_AUX2, 0x20); // LED or air/ground mode
} if(sub_protocol==H26WH)
if (sub_protocol == H26WH) { {
packet[10] &= ~0x40; packet[10] |=0x40; //High rate
packet[14] &= ~0x24; packet[14] &= ~0x24; // unset air/ground & arm flags
packet[14] |= GET_FLAG(Servo_AUX2, 0x04); packet[14] |= GET_FLAG(Servo_AUX2, 0x02); // arm
}
} }
break; break;
case X600: case X600:
@ -145,33 +181,23 @@ static void __attribute__((unused)) MJXQ_send_packet(uint8_t bind)
for (uint8_t i=1; i < MJXQ_PACKET_SIZE-1; i++) sum += packet[i]; for (uint8_t i=1; i < MJXQ_PACKET_SIZE-1; i++) sum += packet[i];
packet[15] = sum; packet[15] = sum;
// Power on, TX mode, 2byte CRC
switch (Model.proto_opts[PROTOOPTS_FORMAT]) {
case H26D:
case H26WH:
NRF24L01_SetTxRxMode(TX_EN);
break;
default:
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP));
break;
}
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no++ / 2]); NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no++ / 2]);
hopping_frequency_no %= 2 * MJXQ_RF_NUM_CHANNELS; // channels repeated hopping_frequency_no %= 2 * MJXQ_RF_NUM_CHANNELS; // channels repeated
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushTx(); NRF24L01_FlushTx();
switch (Model.proto_opts[PROTOOPTS_FORMAT]) { // Power on, TX mode, 2byte CRC and send packet
case H26D: if (sub_protocol == H26D || sub_protocol == H26WH)
case H26WH: {
NRF24L01_WritePayload(packet, MJXQ_PACKET_SIZE); NRF24L01_SetTxRxMode(TX_EN);
break; NRF24L01_WritePayload(packet, MJXQ_PACKET_SIZE);
default: }
XN297_WritePayload(packet, MJXQ_PACKET_SIZE); else
break; {
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP));
XN297_WritePayload(packet, MJXQ_PACKET_SIZE);
} }
NRF24L01_SetPower(); NRF24L01_SetPower();
} }
@ -179,20 +205,19 @@ static void __attribute__((unused)) MJXQ_init()
{ {
uint8_t addr[MJXQ_ADDRESS_LENGTH]; uint8_t addr[MJXQ_ADDRESS_LENGTH];
memcpy(addr, "\x6d\x6a\x77\x77\x77", MJXQ_ADDRESS_LENGTH); memcpy(addr, "\x6d\x6a\x77\x77\x77", MJXQ_ADDRESS_LENGTH);
NRF24L01_Initialize();
NRF24L01_SetTxRxMode(TX_EN);
if (sub_protocol == WLH08) if (sub_protocol == WLH08)
memcpy(hopping_frequency, "\x12\x22\x32\x42", MJXQ_RF_NUM_CHANNELS); memcpy(hopping_frequency, "\x12\x22\x32\x42", MJXQ_RF_NUM_CHANNELS);
else else
if (sub_protocol == H26D || sub_protocol == H26WH || sub_protocol == E010) if (sub_protocol == H26D || sub_protocol == H26D || sub_protocol == E010)
memcpy(hopping_frequency, "\x36\x3e\x46\x2e", MJXQ_RF_NUM_CHANNELS); memcpy(hopping_frequency, "\x2e\x36\x3e\x46", MJXQ_RF_NUM_CHANNELS);
else else
{ {
memcpy(hopping_frequency, "\x0a\x35\x42\x3d", MJXQ_RF_NUM_CHANNELS); memcpy(hopping_frequency, "\x0a\x35\x42\x3d", MJXQ_RF_NUM_CHANNELS);
memcpy(addr, "\x6d\x6a\x73\x73\x73", MJXQ_ADDRESS_LENGTH); memcpy(addr, "\x6d\x6a\x73\x73\x73", MJXQ_ADDRESS_LENGTH);
} }
NRF24L01_Initialize();
NRF24L01_SetTxRxMode(TX_EN);
if (sub_protocol == H26D || sub_protocol == H26WH) if (sub_protocol == H26D || sub_protocol == H26WH)
{ {
@ -204,11 +229,11 @@ static void __attribute__((unused)) MJXQ_init()
NRF24L01_FlushTx(); NRF24L01_FlushTx();
NRF24L01_FlushRx(); NRF24L01_FlushRx();
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit
NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00); // No Auto Acknowledgment on all data pipes 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_02_EN_RXADDR, 0x01); // Enable data pipe 0 only
NRF24L01_WriteReg(NRF24L01_04_SETUP_RETR, 0x00); // no retransmits NRF24L01_WriteReg(NRF24L01_04_SETUP_RETR, 0x00); // no retransmits
NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, MJXQ_PACKET_SIZE); // rx pipe 0 (used only for blue board) NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, MJXQ_PACKET_SIZE);
if (sub_protocol == E010) if (sub_protocol == E010)
NRF24L01_SetBitrate(NRF24L01_BR_250K); // 250K NRF24L01_SetBitrate(NRF24L01_BR_250K); // 250K
else else
@ -218,30 +243,52 @@ static void __attribute__((unused)) MJXQ_init()
static void __attribute__((unused)) MJXQ_init2() static void __attribute__((unused)) MJXQ_init2()
{ {
if (sub_protocol == H26D) switch(sub_protocol)
memcpy(hopping_frequency, "\x32\x3e\x42\x4e", MJXQ_RF_NUM_CHANNELS); {
else case H26D:
if (sub_protocol != WLH08 && sub_protocol != E010) memcpy(hopping_frequency, "\x32\x3e\x42\x4e", MJXQ_RF_NUM_CHANNELS);
break;
case H26WH:
memcpy(hopping_frequency, "\x37\x32\x47\x42", MJXQ_RF_NUM_CHANNELS);
break;
case E010:
for(uint8_t i=0;i<2;i++)
{
hopping_frequency[i]=pgm_read_byte_near( &E010_map_rfchan[rx_tx_addr[3]%15][i] );
hopping_frequency[i+2]=hopping_frequency[i]+0x10;
}
break;
case WLH08:
// do nothing
break;
default:
for(uint8_t i=0;i<MJXQ_RF_NUM_CHANNELS;i++) for(uint8_t i=0;i<MJXQ_RF_NUM_CHANNELS;i++)
hopping_frequency[i]=pgm_read_byte_near( &MJXQ_map_rfchan[rx_tx_addr[3]%3][i] ); hopping_frequency[i]=pgm_read_byte_near( &MJXQ_map_rfchan[rx_tx_addr[3]%3][i] );
break;
}
} }
static void __attribute__((unused)) MJXQ_initialize_txid() static void __attribute__((unused)) MJXQ_initialize_txid()
{ {
rx_tx_addr[0]&=0xF8; switch(sub_protocol)
rx_tx_addr[2]=rx_tx_addr[3]; // Make use of RX_Num
if (sub_protocol == H26WH)
{ {
memcpy(txid, "\xa4\x03\x00", sizeof(txid)); case H26WH:
memcpy(rx_tx_addr, "\xa4\x03\x00", 3);
break;
case E010:
for(uint8_t i=0;i<2;i++)
rx_tx_addr[i]=pgm_read_byte_near( &E010_map_txid[rx_tx_addr[3]%15][i] );
rx_tx_addr[2]=(rx_tx_addr[3]%15 == 14)?1:0;
break;
case WLH08:
rx_tx_addr[0]&=0xF8;
rx_tx_addr[2]=rx_tx_addr[3]; // Make use of RX_Num
break;
default:
for(uint8_t i=0;i<3;i++)
rx_tx_addr[i]=pgm_read_byte_near( &MJXQ_map_txid[rx_tx_addr[3]%3][i] );
break;
} }
else if (sub_protocol == E010)
{
rx_tx_addr[1]=(rx_tx_addr[1]&0xF0)|0x0C;
rx_tx_addr[2]<<=4; // Make use of RX_Num
}
else
for(uint8_t i=0;i<3;i++)
rx_tx_addr[i]=pgm_read_byte_near( &MJXQ_map_txid[rx_tx_addr[3]%3][i] );
} }
uint16_t MJXQ_callback() uint16_t MJXQ_callback()

View File

@ -20,6 +20,7 @@
#include "iface_nrf24l01.h" #include "iface_nrf24l01.h"
#define MT99XX_BIND_COUNT 928 #define MT99XX_BIND_COUNT 928
#define MT99XX_PACKET_PERIOD_FY805 2460
#define MT99XX_PACKET_PERIOD_MT 2625 #define MT99XX_PACKET_PERIOD_MT 2625
#define MT99XX_PACKET_PERIOD_YZ 3125 #define MT99XX_PACKET_PERIOD_YZ 3125
#define MT99XX_INITIAL_WAIT 500 #define MT99XX_INITIAL_WAIT 500
@ -47,6 +48,11 @@ enum{
FLAG_LS_FLIP = 0x80, FLAG_LS_FLIP = 0x80,
}; };
enum{
// flags going to packet[7] (FY805)
FLAG_FY805_HEADLESS= 0x10,
};
enum { enum {
MT99XX_INIT = 0, MT99XX_INIT = 0,
MT99XX_BIND, MT99XX_BIND,
@ -89,17 +95,28 @@ static void __attribute__((unused)) MT99XX_send_packet()
packet[6] |= 0x40 | FLAG_MT_RATE2 packet[6] |= 0x40 | FLAG_MT_RATE2
| GET_FLAG( Servo_AUX3, FLAG_MT_SNAPSHOT ) | GET_FLAG( Servo_AUX3, FLAG_MT_SNAPSHOT )
| GET_FLAG( Servo_AUX4, FLAG_MT_VIDEO ); // max rate on MT99xx | GET_FLAG( Servo_AUX4, FLAG_MT_VIDEO ); // max rate on MT99xx
else //LS else
{ if(sub_protocol==FY805)
packet[6] |= FLAG_LS_RATE // max rate {
| GET_FLAG( Servo_AUX2, FLAG_LS_INVERT ) //INVERT packet[6]=0x20;
| GET_FLAG( Servo_AUX3, FLAG_LS_SNAPSHOT ) //SNAPSHOT //Rate 0x01?
| GET_FLAG( Servo_AUX4, FLAG_LS_VIDEO ) //VIDEO //Flip ?
| GET_FLAG( Servo_AUX5, FLAG_LS_HEADLESS ); //HEADLESS packet[7]=0x01
packet[7] = ls_mys_byte[ls_counter++]; |GET_FLAG( Servo_AUX1, FLAG_MT_FLIP )
if(ls_counter >= sizeof(ls_mys_byte)) |GET_FLAG( Servo_AUX5, FLAG_FY805_HEADLESS ); //HEADLESS
ls_counter=0; checksum_offset=0;
} }
else //LS
{
packet[6] |= FLAG_LS_RATE // max rate
| GET_FLAG( Servo_AUX2, FLAG_LS_INVERT ) //INVERT
| GET_FLAG( Servo_AUX3, FLAG_LS_SNAPSHOT ) //SNAPSHOT
| GET_FLAG( Servo_AUX4, FLAG_LS_VIDEO ) //VIDEO
| GET_FLAG( Servo_AUX5, FLAG_LS_HEADLESS ); //HEADLESS
packet[7] = ls_mys_byte[ls_counter++];
if(ls_counter >= sizeof(ls_mys_byte))
ls_counter=0;
}
uint8_t result=checksum_offset; uint8_t result=checksum_offset;
for(uint8_t i=0; i<8; i++) for(uint8_t i=0; i<8; i++)
@ -135,7 +152,10 @@ static void __attribute__((unused)) MT99XX_send_packet()
if(sub_protocol == LS) if(sub_protocol == LS)
NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x2D); // LS always transmits on the same channel NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x2D); // LS always transmits on the same channel
else else
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no] + channel_offset); if(sub_protocol==FY805)
NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x4B); // FY805 always transmits on the same channel
else
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no] + channel_offset);
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushTx(); NRF24L01_FlushTx();
XN297_WritePayload(packet, MT99XX_PACKET_SIZE); XN297_WritePayload(packet, MT99XX_PACKET_SIZE);
@ -184,10 +204,17 @@ static void __attribute__((unused)) MT99XX_initialize_txid()
rx_tx_addr[2] = 0x00; rx_tx_addr[2] = 0x00;
} }
else else
if(sub_protocol == LS) if(sub_protocol == FY805)
rx_tx_addr[0] = 0xCC; {
else //MT99 & H7 rx_tx_addr[0] = 0x81; // test (SB id)
rx_tx_addr[1] = 0x0F;
rx_tx_addr[2] = 0x00; rx_tx_addr[2] = 0x00;
}
else
if(sub_protocol == LS)
rx_tx_addr[0] = 0xCC;
else //MT99 & H7
rx_tx_addr[2] = 0x00;
checksum_offset = rx_tx_addr[0] + rx_tx_addr[1] + rx_tx_addr[2]; checksum_offset = rx_tx_addr[0] + rx_tx_addr[1] + rx_tx_addr[2];
channel_offset = (((checksum_offset & 0xf0)>>4) + (checksum_offset & 0x0f)) % 8; channel_offset = (((checksum_offset & 0xf0)>>4) + (checksum_offset & 0x0f)) % 8;
} }
@ -209,7 +236,10 @@ uint16_t MT99XX_callback()
if(sub_protocol == LS) if(sub_protocol == LS)
NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x2D); // LS always transmits on the same channel NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x2D); // LS always transmits on the same channel
else else
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]); if(sub_protocol==FY805)
NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x4B); // FY805 always transmits on the same channel
else
NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]);
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
NRF24L01_FlushTx(); NRF24L01_FlushTx();
XN297_WritePayload(packet, MT99XX_PACKET_SIZE); // bind packet XN297_WritePayload(packet, MT99XX_PACKET_SIZE); // bind packet
@ -256,6 +286,12 @@ uint16_t initMT99XX(void)
packet[2] = 0x05; packet[2] = 0x05;
packet[3] = 0x11; packet[3] = 0x11;
break; break;
case FY805:
packet_period = MT99XX_PACKET_PERIOD_FY805;
packet[1] = 0x15;
packet[2] = 0x12;
packet[3] = 0x17;
break;
} }
packet[4] = rx_tx_addr[0]; packet[4] = rx_tx_addr[0];
packet[5] = rx_tx_addr[1]; packet[5] = rx_tx_addr[1];

View File

@ -150,7 +150,8 @@ uint8_t pkt[MAX_PKT];//telemetry receiving packets
volatile uint8_t tx_head=0; volatile uint8_t tx_head=0;
volatile uint8_t tx_tail=0; volatile uint8_t tx_tail=0;
#endif // BASH_SERIAL #endif // BASH_SERIAL
uint8_t v_lipo; uint8_t v_lipo1;
uint8_t v_lipo2;
int16_t RSSI_dBm; int16_t RSSI_dBm;
uint8_t TX_RSSI; uint8_t TX_RSSI;
uint8_t telemetry_link=0; uint8_t telemetry_link=0;
@ -333,7 +334,6 @@ void setup()
cur_protocol[1] = protocol; cur_protocol[1] = protocol;
sub_protocol = PPM_prot[mode_select].sub_proto; sub_protocol = PPM_prot[mode_select].sub_proto;
RX_num = PPM_prot[mode_select].rx_num; RX_num = PPM_prot[mode_select].rx_num;
MProtocol_id = RX_num + MProtocol_id_master;
option = PPM_prot[mode_select].option; option = PPM_prot[mode_select].option;
if(PPM_prot[mode_select].power) POWER_FLAG_on; if(PPM_prot[mode_select].power) POWER_FLAG_on;
if(PPM_prot[mode_select].autobind) AUTOBIND_FLAG_on; if(PPM_prot[mode_select].autobind) AUTOBIND_FLAG_on;
@ -469,7 +469,8 @@ void Update_All()
if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received
{ {
update_serial_data(); // Update protocol and data update_serial_data(); // Update protocol and data
INPUT_SIGNAL_on; //valid signal received
last_signal=millis();
} }
#endif //ENABLE_SERIAL #endif //ENABLE_SERIAL
#ifdef ENABLE_PPM #ifdef ENABLE_PPM
@ -492,11 +493,7 @@ void Update_All()
#endif //ENABLE_PPM #endif //ENABLE_PPM
update_channels_aux(); update_channels_aux();
#if defined(TELEMETRY) #if defined(TELEMETRY)
if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) if((protocol==MODE_FRSKYD) || (protocol==MODE_BAYANG) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) )
#ifdef ENABLE_BAYANG_TELEMETRY
|| (protocol==MODE_BAYANG)
#endif
)
TelemetryUpdate(); TelemetryUpdate();
#endif #endif
update_led_status(); update_led_status();
@ -528,9 +525,6 @@ static void update_channels_aux(void)
{ // Protocol needs to be changed { // Protocol needs to be changed
LED_off; //led off during protocol init LED_off; //led off during protocol init
modules_reset(); //reset all modules modules_reset(); //reset all modules
#ifdef ENABLE_PPM
AUTOBIND_FLAG_on;
#endif //ENABLE_PPM
protocol_init(); //init new protocol protocol_init(); //init new protocol
} }
} }
@ -646,6 +640,10 @@ static void protocol_init()
TX_MAIN_PAUSE_off; TX_MAIN_PAUSE_off;
#endif #endif
//Set global ID and rx_tx_addr
MProtocol_id = RX_num + MProtocol_id_master;
set_rx_tx_addr(MProtocol_id);
blink=millis(); blink=millis();
if(IS_BIND_BUTTON_FLAG_on) if(IS_BIND_BUTTON_FLAG_on)
AUTOBIND_FLAG_on; AUTOBIND_FLAG_on;
@ -988,8 +986,6 @@ void update_serial_data()
protocol=(rx_ok_buff[0]==0x55?0:32) + (rx_ok_buff[1]&0x1F); //protocol no (0-63) bits 4-6 of buff[1] and bit 0 of buf[0] protocol=(rx_ok_buff[0]==0x55?0:32) + (rx_ok_buff[1]&0x1F); //protocol no (0-63) bits 4-6 of buff[1] and bit 0 of buf[0]
sub_protocol=(rx_ok_buff[2]>>4)& 0x07; //subprotocol no (0-7) bits 4-6 sub_protocol=(rx_ok_buff[2]>>4)& 0x07; //subprotocol no (0-7) bits 4-6
RX_num=rx_ok_buff[2]& 0x0F; // rx_num bits 0---3 RX_num=rx_ok_buff[2]& 0x0F; // rx_num bits 0---3
MProtocol_id=MProtocol_id_master+RX_num;//personalized RX bind + rx num
set_rx_tx_addr(MProtocol_id); //set rx_tx_addr
} }
else else
if( ((rx_ok_buff[1]&0x80)!=0) && ((cur_protocol[1]&0x80)==0) ) // Bind flag has been set if( ((rx_ok_buff[1]&0x80)!=0) && ((cur_protocol[1]&0x80)==0) ) // Bind flag has been set
@ -1097,13 +1093,9 @@ void Mprotocol_serial_init()
#if defined(TELEMETRY) #if defined(TELEMETRY)
void PPM_Telemetry_serial_init() void PPM_Telemetry_serial_init()
{ {
if( (protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) ) if( (protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_BAYANG) )
initTXSerial( SPEED_9600 ) ; initTXSerial( SPEED_9600 ) ;
if(protocol==MODE_FRSKYX if(protocol==MODE_FRSKYX)
#ifdef ENABLE_BAYANG_TELEMETRY
|| protocol==MODE_BAYANG
#endif
)
initTXSerial( SPEED_57600 ) ; initTXSerial( SPEED_57600 ) ;
if(protocol==MODE_DSM) if(protocol==MODE_DSM)
initTXSerial( SPEED_125K ) ; initTXSerial( SPEED_125K ) ;

View File

@ -27,6 +27,7 @@ uint8_t rf_setup;
void NRF24L01_Initialize() void NRF24L01_Initialize()
{ {
rf_setup = 0x09; rf_setup = 0x09;
XN297_SetScrambledMode(XN297_SCRAMBLED);
} }
void NRF24L01_WriteReg(uint8_t reg, uint8_t data) void NRF24L01_WriteReg(uint8_t reg, uint8_t data)
@ -75,15 +76,6 @@ uint8_t NRF24L01_ReadReg(uint8_t reg)
} }
*/ */
static uint8_t __attribute__((unused)) NRF24L01_ReadPayloadLength()
{
NRF_CSN_off;
SPI_Write(R_RX_PL_WID);
uint8_t len = SPI_Read();
NRF_CSN_on;
return len;
}
static void NRF24L01_ReadPayload(uint8_t * data, uint8_t length) static void NRF24L01_ReadPayload(uint8_t * data, uint8_t length)
{ {
NRF_CSN_off; NRF_CSN_off;
@ -92,22 +84,12 @@ static void NRF24L01_ReadPayload(uint8_t * data, uint8_t length)
data[i] = SPI_Read(); data[i] = SPI_Read();
NRF_CSN_on; NRF_CSN_on;
} }
static uint8_t NRF24L01_GetDynamicPayloadSize(void)
{
NRF_CSN_off;
SPI_Write(R_RX_PL_WID);
uint8_t res = SPI_Read();
NRF_CSN_on;
return res;
}
static uint8_t NRF24L01_Strobe(uint8_t state) static void NRF24L01_Strobe(uint8_t state)
{ {
uint8_t result;
NRF_CSN_off; NRF_CSN_off;
result =SPI_Write(state); SPI_Write(state);
NRF_CSN_on; NRF_CSN_on;
return result;
} }
void NRF24L01_FlushTx() void NRF24L01_FlushTx()
@ -120,6 +102,20 @@ void NRF24L01_FlushRx()
NRF24L01_Strobe(FLUSH_RX); NRF24L01_Strobe(FLUSH_RX);
} }
static uint8_t __attribute__((unused)) NRF24L01_GetStatus()
{
return SPI_Read();
}
static uint8_t __attribute__((unused)) NRF24L01_GetDynamicPayloadSize()
{
NRF_CSN_off;
SPI_Write(R_RX_PL_WID);
uint8_t len = SPI_Read();
NRF_CSN_on;
return len;
}
void NRF24L01_Activate(uint8_t code) void NRF24L01_Activate(uint8_t code)
{ {
NRF_CSN_off; NRF_CSN_off;
@ -391,17 +387,9 @@ void XN297_ReadPayload(uint8_t* msg, uint8_t len)
NRF24L01_ReadPayload(msg, len); NRF24L01_ReadPayload(msg, len);
for(uint8_t i=0; i<len; i++) for(uint8_t i=0; i<len; i++)
{ {
if (protocol == MODE_BAYANG) { if(xn297_scramble_enabled)
if(xn297_scramble_enabled) msg[i] ^= xn297_scramble[i+xn297_addr_len];
msg[i] = bit_reverse(msg[i] ^ xn297_scramble[i+xn297_addr_len]); msg[i] = bit_reverse(msg[i]);
else
msg[i] = bit_reverse(msg[i]);
}
else {
msg[i] = bit_reverse(msg[i]);
if(xn297_scramble_enabled)
msg[i] ^= bit_reverse(xn297_scramble[i+xn297_addr_len]);
}
} }
} }

View File

@ -18,24 +18,12 @@
#if defined TELEMETRY #if defined TELEMETRY
#if defined SPORT_TELEMETRY #if defined SPORT_TELEMETRY
float telemetry_voltage = 0.f;
uint8_t telemetry_rx_rssi = 100;
#ifdef ENABLE_BAYANG_TELEMETRY
uint16_t telemetry_rx_recv_pps = 100;
uint8_t telemetry_tx_rssi = 100;
uint16_t telemetry_tx_recv_pps = 100;
uint16_t telemetry_tx_sent_pps = 100;
uint8_t telemetry_datamode = 0;
uint8_t telemetry_dataitem = 0;
float telemetry_data[3] = {0};
uint16_t telemetry_uptime = 0;
uint16_t telemetry_flighttime = 0;
uint8_t telemetry_flightmode = 0;
#endif
#define SPORT_TIME 12000 #define SPORT_TIME 12000
#define FRSKY_SPORT_PACKET_SIZE 8 #define FRSKY_SPORT_PACKET_SIZE 8
uint32_t last = 0; uint32_t last = 0;
uint8_t sport_counter=0; uint8_t sport_counter=0;
uint8_t RxBt = 0;
uint8_t rssi;
uint8_t sport = 0; uint8_t sport = 0;
#endif #endif
#if defined HUB_TELEMETRY #if defined HUB_TELEMETRY
@ -64,7 +52,7 @@ uint8_t frame[18];
} SerialControl ; } SerialControl ;
#endif #endif
#if defined DSM_TELEMETRY #ifdef DSM_TELEMETRY
void DSM_frame() void DSM_frame()
{ {
Serial_write(0xAA); // Telemetry packet Serial_write(0xAA); // Telemetry packet
@ -73,13 +61,13 @@ void DSM_frame()
} }
#endif #endif
#if defined AFHDS2A_TELEMETRY #ifdef AFHDS2A_FW_TELEMETRY
void AFHDSA_short_frame() void AFHDSA_short_frame()
{ {
Serial_write(0xAA); // Telemetry packet Serial_write(0xAA); // Telemetry packet
for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data
Serial_write(pkt[i]); Serial_write(pkt[i]);
} }
#endif #endif
void frskySendStuffed() void frskySendStuffed()
@ -139,6 +127,16 @@ void frsky_check_telemetry(uint8_t *pkt,uint8_t len)
} }
} }
void init_hub_telemetry()
{
telemetry_link=0;
telemetry_counter=0;
v_lipo1=0;
v_lipo2=0;
RSSI_dBm=0;
TX_RSSI=0;
}
void frsky_link_frame() void frsky_link_frame()
{ {
frame[0] = 0xFE; frame[0] = 0xFE;
@ -151,11 +149,11 @@ void frsky_link_frame()
frame[4] = (uint8_t)RSSI_dBm; frame[4] = (uint8_t)RSSI_dBm;
} }
else else
if (protocol==MODE_HUBSAN||protocol==MODE_AFHDS2A) if (protocol==MODE_HUBSAN||protocol==MODE_AFHDS2A||protocol==MODE_BAYANG)
{ {
frame[1] = v_lipo*2; //v_lipo; common 0x2A=42/10=4.2V frame[1] = v_lipo1;
frame[2] = frame[1]; frame[2] = v_lipo2;
frame[3] = protocol==MODE_HUBSAN?0x00:(uint8_t)RSSI_dBm; frame[3] = (uint8_t)RSSI_dBm;
frame[4] = TX_RSSI; frame[4] = TX_RSSI;
} }
frame[5] = frame[6] = frame[7] = frame[8] = 0; frame[5] = frame[6] = frame[7] = frame[8] = 0;
@ -331,182 +329,51 @@ void sportIdle()
void sportSendFrame() void sportSendFrame()
{ {
uint8_t i; uint8_t i;
#ifdef ENABLE_BAYANG_TELEMETRY
uint32_t temp;
uint16_t temp16;
uint8_t* bytes;
#endif
sport_counter = (sport_counter + 1) %36; sport_counter = (sport_counter + 1) %36;
if(telemetry_lost) if(telemetry_lost)
{ {
sportIdle(); sportIdle();
return; return;
} }
if(sport_counter<6)
uint8_t num_frames = 6;
#ifdef ENABLE_BAYANG_TELEMETRY
if (protocol == MODE_BAYANG) { num_frames = 14; }
#endif
if(sport_counter<num_frames)
{ {
frame[0] = 0x98; frame[0] = 0x98;
frame[1] = 0x10; frame[1] = 0x10;
for (i=5;i<8;i++) for (i=5;i<8;i++)
frame[i]=0; frame[i]=0;
} }
#ifdef ENABLE_BAYANG_TELEMETRY switch (sport_counter)
if (protocol == MODE_BAYANG) {
switch (sport_counter)
{
case 0:
frame[2] = 0x05;
frame[3] = 0xf1;
frame[4] = 0x02 ;//dummy values if swr 20230f00
frame[5] = 0x23;
frame[6] = 0x0F;
break;
case 1: // RSSI
frame[2] = 0x01;
frame[3] = 0xf1;
frame[4] = telemetry_rx_rssi;
break;
case 2: //BATT
frame[2] = 0x04;
frame[3] = 0xf1;
frame[4] = telemetry_voltage/4.f * 255.f/3.3f;//a1;
break;
case 3: //FCS VOLTAGE
frame[2] = 0x10;
frame[3] = 0x02;
temp = (uint32_t)(telemetry_voltage * 100);
bytes = (uint8_t *) &temp;
frame[4] = bytes[0];
frame[5] = bytes[1];
frame[6] = bytes[2];
frame[7] = bytes[3];
break;
case 4: //RPM (use this as vTX frequency)
frame[2] = 0x00;
frame[3] = 0x05;
frame[4] = 0;
frame[5] = 0;
frame[6] = 0;
frame[7] = 0;
//frskySerial.sendData(0x0500,temp);
break;
case 5: // xjt accx
frame[2] = 0x24;
frame[3] = 0x00;
temp16 = (uint16_t)(telemetry_data[0]*1000);
bytes = (uint8_t *) &temp16;
frame[4] = bytes[0];
frame[5] = bytes[1];
break;
case 6: // xjt accy
frame[2] = 0x25;
frame[3] = 0x00;
temp16 = (uint16_t)(telemetry_data[1]*1000);
bytes = (uint8_t *) &temp16;
frame[4] = bytes[0];
frame[5] = bytes[1];
break;
case 7: // xjt accz
frame[2] = 0x26;
frame[3] = 0x00;
temp16 = (uint16_t)(telemetry_data[2]*1000);
bytes = (uint8_t *) &temp16;
frame[4] = bytes[0];
frame[5] = bytes[1];
break;
case 8: // xjt gps hour minute
frame[2] = 0x17;
frame[3] = 0x00;
temp16 = telemetry_dataitem; // hours
temp16 |= (telemetry_uptime / 60) << 8; // minutes
bytes = (uint8_t *) &temp16;
frame[4] = bytes[0];
frame[5] = bytes[1];
break;
case 9: // xjt gps seconds
frame[2] = 0x18;
frame[3] = 0x00;
frame[4] = telemetry_uptime % 60;
break;
case 10: // xjt gps day/month
frame[2] = 0x15;
frame[3] = 0x00;
frame[4] = telemetry_flighttime / 60;
frame[5] = telemetry_flighttime % 60;
break;
case 11: // xjt gps year
frame[2] = 0x16;
frame[3] = 0x00;
frame[4] = telemetry_flightmode;
break;
case 12: // xjt t1
frame[2] = 0x02;
frame[3] = 0x00;
frame[4] = telemetry_tx_sent_pps >> 1; // divided by 2
frame[5] = telemetry_rx_recv_pps >> 1; // divided by 2
break;
case 13: // xjt t2
frame[2] = 0x05;
frame[3] = 0x00;
frame[4] = telemetry_tx_recv_pps >> 1; // divided by 2
frame[5] = 0;
break;
default:
if(sport)
{
for (i=0;i<FRSKY_SPORT_PACKET_SIZE;i++)
frame[i]=pktx1[i];
sport=0;
break;
}
else
{
sportIdle();
return;
}
}
}
else
#endif
{ {
switch (sport_counter) case 0:
{ frame[2] = 0x05;
case 0: frame[3] = 0xf1;
frame[2] = 0x05; frame[4] = 0x02 ;//dummy values if swr 20230f00
frame[3] = 0xf1; frame[5] = 0x23;
frame[4] = 0x02 ;//dummy values if swr 20230f00 frame[6] = 0x0F;
frame[5] = 0x23; break;
frame[6] = 0x0F; case 2: // RSSI
frame[2] = 0x01;
frame[3] = 0xf1;
frame[4] = rssi;
break;
case 4: //BATT
frame[2] = 0x04;
frame[3] = 0xf1;
frame[4] = RxBt;//a1;
break;
default:
if(sport)
{
for (i=0;i<FRSKY_SPORT_PACKET_SIZE;i++)
frame[i]=pktx1[i];
sport=0;
break; break;
case 2: // RSSI }
frame[2] = 0x01; else
frame[3] = 0xf1; {
frame[4] = telemetry_rx_rssi; sportIdle();
break; return;
case 4: //BATT }
frame[2] = 0x04;
frame[3] = 0xf1;
frame[4] = RxBt;//a1;
break;
default:
if(sport)
{
for (i=0;i<FRSKY_SPORT_PACKET_SIZE;i++)
frame[i]=pktx1[i];
sport=0;
break;
}
else
{
sportIdle();
return;
}
}
} }
sportSend(frame); sportSend(frame);
} }
@ -603,18 +470,14 @@ void TelemetryUpdate()
#endif #endif
#if defined SPORT_TELEMETRY #if defined SPORT_TELEMETRY
if (protocol==MODE_FRSKYX if (protocol==MODE_FRSKYX)
#ifdef ENABLE_BAYANG_TELEMETRY
|| protocol == MODE_BAYANG
#endif
)
{ // FrSkyX { // FrSkyX
if(telemetry_link) if(telemetry_link)
{ {
if(pktt[4] & 0x80) if(pktt[4] & 0x80)
telemetry_rx_rssi=pktt[4] & 0x7F ; rssi=pktt[4] & 0x7F ;
else else
telemetry_voltage = (pktt[4]<<1) + 1 ; RxBt = (pktt[4]<<1) + 1 ;
if(pktt[6]<=6) if(pktt[6]<=6)
for (uint8_t i=0; i < pktt[6]; i++) for (uint8_t i=0; i < pktt[6]; i++)
proces_sport_data(pktt[7+i]); proces_sport_data(pktt[7+i]);
@ -641,15 +504,15 @@ void TelemetryUpdate()
return; return;
} }
#endif #endif
#if defined AFHDS2A_TELEMETRY #if defined AFHDS2A_FW_TELEMETRY
if(telemetry_link == 2 && protocol == MODE_AFHDS2A) if(telemetry_link == 2 && protocol == MODE_AFHDS2A)
{ {
AFHDSA_short_frame(); AFHDSA_short_frame();
telemetry_link=0; telemetry_link=0;
} }
#endif #endif
if(telemetry_link && protocol != MODE_FRSKYX ) if(telemetry_link && protocol != MODE_FRSKYX )
{ // FrSkyD + Hubsan + AFHDS2A { // FrSkyD + Hubsan + AFHDS2A + Bayang
frsky_link_frame(); frsky_link_frame();
telemetry_link=0; telemetry_link=0;
return; return;

View File

@ -15,20 +15,19 @@
// compatible with WLToys V2x2, JXD JD38x, JD39x, JJRC H6C, Yizhan Tarantula X6 ... // compatible with WLToys V2x2, JXD JD38x, JD39x, JJRC H6C, Yizhan Tarantula X6 ...
// Last sync with hexfet new_protocols/v202_nrf24l01.c dated 2015-03-15 // Last sync with hexfet new_protocols/v202_nrf24l01.c dated 2015-03-15
// ajout jdx506 : https://github.com/DeviationTX/deviation/compare/master...goebish:protocol_jxd_506
#if defined(V2X2_NRF24L01_INO) #if defined(V2X2_NRF24L01_INO)
#include "iface_nrf24l01.h" #include "iface_nrf24l01.h"
#define BIND_COUNT 1000 #define V2X2_BIND_COUNT 1000
// Timeout for callback in uSec, 4ms=4000us for V202 // Timeout for callback in uSec, 4ms=4000us for V202
#define PACKET_PERIOD 4000 #define V2X2_PACKET_PERIOD 4000
// //
// Time to wait for packet to be sent (no ACK, so very short) // Time to wait for packet to be sent (no ACK, so very short)
#define PACKET_CHKTIME 100 #define V2X2_PACKET_CHKTIME 100
#define V2X2_PAYLOADSIZE 16
// //
enum { enum {
@ -43,15 +42,14 @@ enum {
V2X2_FLAG_HEADLESS = 0x02, V2X2_FLAG_HEADLESS = 0x02,
V2X2_FLAG_MAG_CAL_X = 0x08, V2X2_FLAG_MAG_CAL_X = 0x08,
V2X2_FLAG_MAG_CAL_Y = 0x20, V2X2_FLAG_MAG_CAL_Y = 0x20,
// V2X2_FLAG_EMERGENCY = 0x80, // JXD-506
JXD_FLAG_START_STOP= 0x40, // arm / disarm JXD-506 // flags going to byte 11 (JXD-506)
JXD_FLAG_EMERGENCY = 0x80, // JXD-506 V2X2_FLAG_START_STOP = 0x40,
JXD_FLAG_CAMERA_UP = 0x01, // JXD-506 V2X2_FLAG_CAMERA_UP = 0x01,
JXD_FLAG_CAMERA_DN = 0x02, // JXD-506 V2X2_FLAG_CAMERA_DN = 0x02,
}; };
// //
#define V2X2_PAYLOADSIZE 16
enum { enum {
V202_INIT2 = 0, V202_INIT2 = 0,
@ -61,8 +59,6 @@ enum {
V202_DATA//4 V202_DATA//4
}; };
// static u32 bind_count;
// This is frequency hopping table for V202 protocol // This is frequency hopping table for V202 protocol
// The table is the first 4 rows of 32 frequency hopping // The table is the first 4 rows of 32 frequency hopping
// patterns, all other rows are derived from the first 4. // patterns, all other rows are derived from the first 4.
@ -71,7 +67,7 @@ enum {
// number in this case. // number in this case.
// The pattern is defined by 5 least significant bits of // The pattern is defined by 5 least significant bits of
// sum of 3 bytes comprising TX id // sum of 3 bytes comprising TX id
static const uint8_t freq_hopping[][16] = { const uint8_t PROGMEM freq_hopping[][16] = {
{ 0x27, 0x1B, 0x39, 0x28, 0x24, 0x22, 0x2E, 0x36, { 0x27, 0x1B, 0x39, 0x28, 0x24, 0x22, 0x2E, 0x36,
0x19, 0x21, 0x29, 0x14, 0x1E, 0x12, 0x2D, 0x18 }, // 00 0x19, 0x21, 0x29, 0x14, 0x1E, 0x12, 0x2D, 0x18 }, // 00
{ 0x2E, 0x33, 0x25, 0x38, 0x19, 0x12, 0x18, 0x16, { 0x2E, 0x33, 0x25, 0x38, 0x19, 0x12, 0x18, 0x16,
@ -130,12 +126,12 @@ static void __attribute__((unused)) V2X2_set_tx_id(void)
{ {
uint8_t sum; uint8_t sum;
sum = rx_tx_addr[1] + rx_tx_addr[2] + rx_tx_addr[3]; sum = rx_tx_addr[1] + rx_tx_addr[2] + rx_tx_addr[3];
// Base row is defined by lowest 2 bits
const uint8_t *fh_row = freq_hopping[sum & 0x03];
// Higher 3 bits define increment to corresponding row // Higher 3 bits define increment to corresponding row
uint8_t increment = (sum & 0x1e) >> 2; uint8_t increment = (sum & 0x1e) >> 2;
// Base row is defined by lowest 2 bits
sum &=0x03;
for (uint8_t i = 0; i < 16; ++i) { for (uint8_t i = 0; i < 16; ++i) {
uint8_t val = fh_row[i] + increment; uint8_t val = pgm_read_byte_near(&freq_hopping[sum][i]) + increment;
// Strange avoidance of channels divisible by 16 // Strange avoidance of channels divisible by 16
hopping_frequency[i] = (val & 0x0f) ? val : val - 3; hopping_frequency[i] = (val & 0x0f) ? val : val - 3;
} }
@ -189,19 +185,14 @@ static void __attribute__((unused)) V2X2_send_packet(uint8_t bind)
// Channel 9 // Channel 9
if (Servo_AUX5) if (Servo_AUX5)
flags2 = V2X2_FLAG_HEADLESS; flags2 = V2X2_FLAG_HEADLESS;
if(sub_protocol==JXD506)
if(sub_protocol == FORMAT_JXD506) { {
// Channel 10
if (Servo_AUX6) flags2 |= JXD_FLAG_START_STOP;
// Channel 11 // Channel 11
if (Servo_AUX7) flags2 |= JXD_FLAG_EMERGENCY; if (Servo_AUX7)
flags2 |= V2X2_FLAG_EMERGENCY;
// Channel 12 down }
if (Servo_data[AUX8] < PPM_SWITCH_B) flags2 |= JXD_FLAG_CAMERA_DN; else
// Channel 12 up {
if (Servo_data[AUX8] > PPM_SWITCH) flags2 |= JXD_FLAG_CAMERA_UP;
} else {
// Channel 10 // Channel 10
if (Servo_AUX6) if (Servo_AUX6)
flags2 |= V2X2_FLAG_MAG_CAL_X; flags2 |= V2X2_FLAG_MAG_CAL_X;
@ -214,12 +205,24 @@ static void __attribute__((unused)) V2X2_send_packet(uint8_t bind)
packet[7] = rx_tx_addr[1]; packet[7] = rx_tx_addr[1];
packet[8] = rx_tx_addr[2]; packet[8] = rx_tx_addr[2];
packet[9] = rx_tx_addr[3]; packet[9] = rx_tx_addr[3];
// empty // flags
packet[10] = flags2; packet[10] = flags2;
packet[11] = 0x00; packet[11] = 0x00;
packet[12] = 0x00; packet[12] = 0x00;
packet[13] = 0x00; packet[13] = 0x00;
// if(sub_protocol==JXD506)
{
// Channel 10
if (Servo_AUX6)
packet[11] = V2X2_FLAG_START_STOP;
// Channel 12
if(Servo_data[AUX8] > PPM_MAX_COMMAND)
packet[11] |= V2X2_FLAG_CAMERA_UP;
else if(Servo_data[AUX8] < PPM_MIN_COMMAND)
packet[11] |= V2X2_FLAG_CAMERA_DN;
packet[12] = 0x40;
packet[13] = 0x40;
}
packet[14] = flags; packet[14] = flags;
V2X2_add_pkt_checksum(); V2X2_add_pkt_checksum();
@ -250,7 +253,7 @@ uint16_t ReadV2x2()
break; break;
case V202_BIND2: case V202_BIND2:
if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED) { if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED) {
return PACKET_CHKTIME; return V2X2_PACKET_CHKTIME;
} }
V2X2_send_packet(1); V2X2_send_packet(1);
if (--counter == 0) { if (--counter == 0) {
@ -260,13 +263,13 @@ uint16_t ReadV2x2()
break; break;
case V202_DATA: case V202_DATA:
if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED) { if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED) {
return PACKET_CHKTIME; return V2X2_PACKET_CHKTIME;
} }
V2X2_send_packet(0); V2X2_send_packet(0);
break; break;
} }
// Packet every 4ms // Packet every 4ms
return PACKET_PERIOD; return V2X2_PACKET_PERIOD;
} }
uint16_t initV2x2() uint16_t initV2x2()
@ -275,7 +278,7 @@ uint16_t initV2x2()
// //
if (IS_AUTOBIND_FLAG_on) if (IS_AUTOBIND_FLAG_on)
{ {
counter = BIND_COUNT; counter = V2X2_BIND_COUNT;
phase = V202_INIT2; phase = V202_INIT2;
} }
else else

View File

@ -85,24 +85,34 @@
//Make sure telemetry is selected correctly //Make sure telemetry is selected correctly
#ifndef TELEMETRY #ifndef TELEMETRY
#undef INVERT_TELEMETRY #undef INVERT_TELEMETRY
#undef DSM_TELEMETRY #undef AFHDS2A_FW_TELEMETRY
#undef SPORT_TELEMETRY #undef AFHDS2A_HUB_TELEMETRY
#undef BAYANG_HUB_TELEMETRY
#undef HUBSAN_HUB_TELEMETRY
#undef HUB_TELEMETRY #undef HUB_TELEMETRY
#undef AFHDS2A_TELEMETRY #undef SPORT_TELEMETRY
#undef DSM_TELEMETRY
#else #else
#if not defined(DSM_CYRF6936_INO) #if not defined(BAYANG_NRF24L01_INO)
#undef DSM_TELEMETRY #undef BAYANG_HUB_TELEMETRY
#endif #endif
#if not defined(FRSKYD_CC2500_INO) && not defined(HUBSAN_A7105_INO) && not defined(AFHDS2A_A7105_INO) #if not defined(HUBSAN_A7105_INO)
#undef HUBSAN_HUB_TELEMETRY
#endif
#if not defined(AFHDS2A_A7105_INO)
#undef AFHDS2A_HUB_TELEMETRY
#undef AFHDS2A_FW_TELEMETRY
#endif
#if not defined(FRSKYD_CC2500_INO)
#undef HUB_TELEMETRY #undef HUB_TELEMETRY
#endif #endif
#if not defined(FRSKYX_CC2500_INO) #if not defined(FRSKYX_CC2500_INO)
#undef SPORT_TELEMETRY #undef SPORT_TELEMETRY
#endif #endif
#if not defined(AFHDS2A_A7105_INO) #if not defined(DSM_CYRF6936_INO)
#undef AFHDS2A_TELEMETRY #undef DSM_TELEMETRY
#endif #endif
#if not defined(DSM_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(AFHDS2A_TELEMETRY) #if not defined(DSM_TELEMETRY) && not defined(SPORT_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(HUBSAN_HUB_TELEMETRY) && not defined(BAYANG_HUB_TELEMETRY) && not defined(AFHDS2A_HUB_TELEMETRY) && not defined(AFHDS2A_FW_TELEMETRY)
#undef TELEMETRY #undef TELEMETRY
#undef INVERT_TELEMETRY #undef INVERT_TELEMETRY
#endif #endif

View File

@ -129,11 +129,14 @@
//#define INVERT_TELEMETRY //#define INVERT_TELEMETRY
//Comment a line to disable a protocol telemetry //Comment a line to disable a protocol telemetry
#define DSM_TELEMETRY #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded
#define SPORT_TELEMETRY #define SPORT_TELEMETRY // Use FrSkyX SPORT format to send telemetry to TX
#define HUB_TELEMETRY #define AFHDS2A_FW_TELEMETRY // Forward received telemetry packet directly to TX to be decoded
#define AFHDS2A_TELEMETRY #define HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
// #define ENABLE_BAYANG_TELEMETRY // uncomment to enable bayang telemtry for H101 acro firmware - https://github.com/bikemike/H101-acro/tree/telemetry #define AFHDS2A_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
#define BAYANG_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
#define HUBSAN_HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX
/****************************/ /****************************/
/*** SERIAL MODE SETTINGS ***/ /*** SERIAL MODE SETTINGS ***/
@ -233,7 +236,8 @@ const PPM_Parameters PPM_prot[15]= {
Hisky Hisky
HK310 HK310
MODE_V2X2 MODE_V2X2
NONE V2X2
JXD506
MODE_DSM MODE_DSM
DSM2_22 DSM2_22
DSM2_11 DSM2_11
@ -275,7 +279,6 @@ const PPM_Parameters PPM_prot[15]= {
H8_3D H8_3D
MODE_BAYANG MODE_BAYANG
BAYANG BAYANG
BAYANG TELEMETRY
H8S3D H8S3D
MODE_FRSKYX MODE_FRSKYX
CH_16 CH_16
@ -287,6 +290,7 @@ const PPM_Parameters PPM_prot[15]= {
H7 H7
YZ YZ
LS LS
FY805
MODE_MJXQ MODE_MJXQ
WLH08 WLH08
X600 X600
@ -312,7 +316,7 @@ const PPM_Parameters PPM_prot[15]= {
FORMAT_HONTAI FORMAT_HONTAI
FORMAT_JJRCX1 FORMAT_JJRCX1
FORMAT_X5C1 FORMAT_X5C1
FQ777-951 FORMAT_FQ777_951
MODE_AFHDS2A MODE_AFHDS2A
PWM_IBUS PWM_IBUS
PPM_IBUS PPM_IBUS

View File

@ -141,15 +141,15 @@ enum CG023
enum BAYANG enum BAYANG
{ {
BAYANG = 0, BAYANG = 0,
BAYANG_TELEM = 1, H8S3D = 1
H8S3D = 2
}; };
enum MT99XX enum MT99XX
{ {
MT99 = 0, MT99 = 0,
H7 = 1, H7 = 1,
YZ = 2, YZ = 2,
LS = 3 LS = 3,
FY805 = 4
}; };
enum MJXQ enum MJXQ
{ {
@ -170,7 +170,12 @@ enum HONTAI
FORMAT_HONTAI = 0, FORMAT_HONTAI = 0,
FORMAT_JJRCX1 = 1, FORMAT_JJRCX1 = 1,
FORMAT_X5C1 = 2, FORMAT_X5C1 = 2,
FORMAT_FQ777 = 3 FORMAT_FQ777_951 =3
};
enum V2X2
{
V2X2 = 0,
JXD506 = 1,
}; };
enum HUBSAN enum HUBSAN
@ -520,22 +525,19 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
H8_3D 2 H8_3D 2
sub_protocol==BAYANG sub_protocol==BAYANG
BAYANG 0 BAYANG 0
BAYANG TELEM 1 H8S3D 1
H8S3D 2
sub_protocol==MT99XX sub_protocol==MT99XX
MT99 0 MT99 0
H7 1 H7 1
YZ 2 YZ 2
LS 3 LS 3
FY805 4
sub_protocol==MJXQ sub_protocol==MJXQ
WLH08 0 WLH08 0
X600 1 X600 1
X800 2 X800 2
H26D 3 H26D 3
E010 4 E010 4
sub_protocol==FY326
FY326 0
FY319 1
sub_protocol==FRSKYX sub_protocol==FRSKYX
CH_16 0 CH_16 0
CH_8 1 CH_8 1
@ -543,15 +545,19 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
FORMAT_HONTAI 0 FORMAT_HONTAI 0
FORMAT_JJRCX1 1 FORMAT_JJRCX1 1
FORMAT_X5C1 2 FORMAT_X5C1 2
FQ777-521 3 FORMAT_FQ777_951 3
sub_protocol==BAYANG
BAYANG 0
BAYANG_TELEM 1
sub_protocol==AFHDS2A sub_protocol==AFHDS2A
PWM_IBUS 0 PWM_IBUS 0
PPM_IBUS 1 PPM_IBUS 1
PWM_SBUS 2 PWM_SBUS 2
PPM_SBUS 3 PPM_SBUS 3
sub_protocol==V2X2
V2X2 0
JXD506 1
sub_protocol==FY326
FY326 0
FY319 1
Power value => 0x80 0=High/1=Low Power value => 0x80 0=High/1=Low
Stream[3] = option_protocol; Stream[3] = option_protocol;
option_protocol value is -127..127 option_protocol value is -127..127

Binary file not shown.