diff --git a/Multiprotocol/AFHDS2A_a7105.ino b/Multiprotocol/AFHDS2A_a7105.ino index 869b5a8..5fc8963 100644 --- a/Multiprotocol/AFHDS2A_a7105.ino +++ b/Multiprotocol/AFHDS2A_a7105.ino @@ -72,7 +72,7 @@ static void AFHDS2A_calc_channels() } } -#if defined(TELEMETRY) +#if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY) // telemetry sensors ID enum{ 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 ...... // max 7 sensors per packet -#if defined AFHDS2A_TELEMETRY - if (option & 0x80) { +#ifdef AFHDS2A_FW_TELEMETRY + if (option & 0x80) + { // forward telemetry to TX, skip rx and tx id to save space pkt[0]= TX_RSSI; for(int i=9;i < AFHDS2A_RXPACKET_SIZE; i++) @@ -96,14 +97,17 @@ static void AFHDS2A_update_telemetry() telemetry_link=2; return; } -#endif +#endif +#ifdef AFHDS2A_HUB_TELEMETRY for(uint8_t sensor=0; sensor<7; sensor++) { + // Send FrSkyD telemetry to TX uint8_t index = 9+(4*sensor); switch(packet[index]) { 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; break; /*case AFHDS2A_SENSOR_RX_ERR_RATE: @@ -119,6 +123,7 @@ static void AFHDS2A_update_telemetry() break;*/ } } +#endif } #endif @@ -298,7 +303,7 @@ uint16_t ReadAFHDS2A() { if(packet[9] == 0xfc) packet_type=AFHDS2A_PACKET_SETTINGS; // RX is asking for settings - #if defined(TELEMETRY) + #if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY) else { // Read TX RSSI @@ -346,6 +351,9 @@ uint16_t initAFHDS2A() rx_id[i]=eeprom_read_byte((EE_ADDR)(temp+i)); } hopping_frequency_no = 0; +#if defined(AFHDS2A_FW_TELEMETRY) || defined(AFHDS2A_HUB_TELEMETRY) + init_hub_telemetry(); +#endif return 50000; } #endif diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index b485a66..7e377c0 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -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 #if defined(BAYANG_NRF24L01_INO) + #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_PACKET_PERIOD 2000 +#define BAYANG_PACKET_PERIOD 1000 #define BAYANG_INITIAL_WAIT 500 #define BAYANG_PACKET_SIZE 15 #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 enum BAYANG_FLAGS { - // flags going to packet[2] - BAYANG_FLAG_RTH = 0x01, - BAYANG_FLAG_HEADLESS = 0x02, -#ifdef ENABLE_BAYANG_TELEMETRY - BAYANG_FLAG_TELEMETRY = 0x04, -#endif - BAYANG_FLAG_FLIP = 0x08, - BAYANG_FLAG_VIDEO = 0x10, - 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 - + // flags going to packet[2] + BAYANG_FLAG_RTH = 0x01, + BAYANG_FLAG_HEADLESS = 0x02, + BAYANG_FLAG_FLIP = 0x08, + BAYANG_FLAG_VIDEO = 0x10, + BAYANG_FLAG_PICTURE = 0x20, + // flags going to packet[3] + BAYANG_FLAG_INVERTED = 0x80 // inverted flight on Floureon H101 }; 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; 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++) packet[i+1]=rx_tx_addr[i]; for(i=0;i<4;i++) @@ -71,12 +58,6 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) } 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; packet[0] = 0xA5; 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; if(Servo_AUX5) packet[2] |= BAYANG_FLAG_HEADLESS; - -#ifdef ENABLE_BAYANG_TELEMETRY - if (telem_enabled) - { - packet[2] |= BAYANG_FLAG_TELEMETRY; - } -#endif - - //Flags packet[3] packet[3] = 0x00; if(Servo_AUX6) 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 val = convert_channel_10b(AILERON); 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[13] = sub_protocol==H8S3D?0x34:0x0A; 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]; + NRF24L01_WriteReg(NRF24L01_05_RF_CH, bind ? BAYANG_RF_BIND_CHANNEL:hopping_frequency[hopping_frequency_no++]); + hopping_frequency_no%=BAYANG_RF_NUM_CHANNELS; + + // clear packet status bits and TX FIFO + NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); + NRF24L01_FlushTx(); + + 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)); - NRF24L01_WriteReg(NRF24L01_05_RF_CH, bind ? BAYANG_RF_BIND_CHANNEL:hopping_frequency[hopping_frequency_no++]); - hopping_frequency_no%=BAYANG_RF_NUM_CHANNELS; - - // clear packet status bits and TX FIFO - NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); - NRF24L01_FlushTx(); - XN297_WritePayload(packet, BAYANG_PACKET_SIZE); + #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 } +#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() { NRF24L01_Initialize(); @@ -245,46 +171,63 @@ static void __attribute__((unused)) BAYANG_init() NRF24L01_FlushTx(); 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_11_RX_PW_P0, BAYANG_PACKET_SIZE); // rx pipe 0 - NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, 0x01); // Enable data pipe 0 only - NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03); - NRF24L01_WriteReg(NRF24L01_04_SETUP_RETR, 0x00); // no retransmits - NRF24L01_SetBitrate(NRF24L01_BR_1M); // 1Mbps - NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes - NRF24L01_SetPower(); - + NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, 0x01); // Enable data pipe 0 only + NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, BAYANG_PACKET_SIZE); + NRF24L01_SetBitrate(NRF24L01_BR_1M); // 1Mbps + NRF24L01_SetPower(); + NRF24L01_Activate(0x73); // Activate feature register + NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes + NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x01); + NRF24L01_Activate(0x73); } uint16_t BAYANG_callback() { if(IS_BIND_DONE_on) { -#ifdef ENABLE_BAYANG_TELEMETRY - if(sub_protocol == BAYANG_TELEM) - { - return Bayang_process(); - } - else -#endif - { + if(packet_count==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 { if (bind_counter == 0) { 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; } else { - BAYANG_send_packet(1); + if(packet_count==0) + BAYANG_send_packet(1); + packet_count++; + packet_count%=4; bind_counter--; } } @@ -304,193 +247,15 @@ static void __attribute__((unused)) BAYANG_initialize_txid() uint16_t initBAYANG(void) { BIND_IN_PROGRESS; // autobind protocol - bind_counter = BAYANG_BIND_COUNT; + bind_counter = BAYANG_BIND_COUNT; BAYANG_initialize_txid(); 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; } - -#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 \ No newline at end of file diff --git a/Multiprotocol/CC2500_SPI.ino b/Multiprotocol/CC2500_SPI.ino index ac39670..8e17b46 100644 --- a/Multiprotocol/CC2500_SPI.ino +++ b/Multiprotocol/CC2500_SPI.ino @@ -86,8 +86,8 @@ void CC2500_SetTxRxMode(uint8_t mode) { if(mode == TX_EN) {//from deviation firmware - CC2500_WriteReg(CC2500_02_IOCFG0, 0x2F | 0x40); CC2500_WriteReg(CC2500_00_IOCFG2, 0x2F); + CC2500_WriteReg(CC2500_02_IOCFG0, 0x2F | 0x40); } else if (mode == RX_EN) diff --git a/Multiprotocol/CG023_nrf24l01.ino b/Multiprotocol/CG023_nrf24l01.ino index 91425a8..5b2a406 100644 --- a/Multiprotocol/CG023_nrf24l01.ino +++ b/Multiprotocol/CG023_nrf24l01.ino @@ -67,12 +67,12 @@ enum H8_3D_FLAGS { enum H8_3D_FLAGS_2 { // 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_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) @@ -122,12 +122,16 @@ static void __attribute__((unused)) CG023_send_packet(uint8_t bind) packet[17] = H8_3D_FLAG_RATE_HIGH | GET_FLAG(Servo_AUX1,H8_3D_FLAG_FLIP) | GET_FLAG(Servo_AUX2,H8_3D_FLAG_LIGTH) //H22 light - | GET_FLAG(Servo_AUX3,H8_3D_FLAG_HEADLESS) - | GET_FLAG(Servo_AUX4,H8_3D_FLAG_RTH); // 180/360 flip mode on H8 3D - packet[18] = GET_FLAG(Servo_AUX5,H8_3D_FLAG_CALIBRATE) - | GET_FLAG(Servo_AUX5,H8_3D_FLAG_CALIBRATE2) - | GET_FLAG(Servo_AUX6,H8_3D_FLAG_SNAPSHOT) - | GET_FLAG(Servo_AUX7,H8_3D_FLAG_VIDEO); + | GET_FLAG(Servo_AUX5,H8_3D_FLAG_HEADLESS) + | GET_FLAG(Servo_AUX6,H8_3D_FLAG_RTH); // 180/360 flip mode on H8 3D + packet[18] = GET_FLAG(Servo_AUX3,H8_3D_FLAG_PICTURE) + | GET_FLAG(Servo_AUX4,H8_3D_FLAG_VIDEO) + | GET_FLAG(Servo_AUX7,H8_3D_FLAG_CALIBRATE1) + | GET_FLAG(Servo_AUX8,H8_3D_FLAG_CALIBRATE2); + if(Servo_data[AUX9]PPM_MAX_COMMAND) + packet[18] |= H8_3D_FLAG_CAM_UP; } uint8_t sum = packet[9]; for (uint8_t i=10; i < H8_3D_PACKET_SIZE-1; i++) diff --git a/Multiprotocol/CX10_nrf24l01.ino b/Multiprotocol/CX10_nrf24l01.ino index ee87a44..6b3786d 100644 --- a/Multiprotocol/CX10_nrf24l01.ino +++ b/Multiprotocol/CX10_nrf24l01.ino @@ -57,9 +57,10 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind) packet[3] = rx_tx_addr[2]; packet[4] = rx_tx_addr[3]; // packet[5] to [8] (aircraft id) is filled during bind for blue board - uint16_t aileron=Servo_data[AILERON]; - uint16_t elevator=3000-Servo_data[ELEVATOR]; - uint16_t rudder=3000-Servo_data[RUDDER]; + uint16_t aileron=map(limit_channel_100(AILERON),servo_min_100,servo_max_100,1000,2000); + uint16_t elevator=map(limit_channel_100(ELEVATOR),servo_min_100,servo_max_100,2000,1000); + 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 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; case Q282: case Q242: - aileron = 3000 - aileron; - rudder = 3000 - rudder; case Q222: memcpy(&packet[15], "\x10\x10\xaa\xaa\x00\x00", 6); //FLIP|LED|PICTURE|VIDEO|HEADLESS|RTH|XCAL|YCAL 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_AUX7, 0x04) // Channel 11 - XCAL |GET_FLAG(Servo_AUX8, 0x02); // Channel 12 - YCAL or Start/Stop motors on JXD 509 - if(sub_protocol==Q282) - { - 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) + if(sub_protocol==Q242) { flags=2; 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; } else - { // Q222 - flags=0; + { // Q282 & Q222 + 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 break; @@ -146,11 +141,11 @@ static void __attribute__((unused)) CX10_Write_Packet(uint8_t bind) break; } packet[5+offset] = lowByte(aileron); - packet[6+offset]= highByte(aileron); - packet[7+offset]= lowByte(elevator); - packet[8+offset]= highByte(elevator); - packet[9+offset] = lowByte(Servo_data[THROTTLE]); - packet[10+offset]= highByte(Servo_data[THROTTLE]); + packet[6+offset] = highByte(aileron); + packet[7+offset] = lowByte(elevator); + packet[8+offset] = highByte(elevator); + packet[9+offset] = lowByte(throttle); + packet[10+offset]= highByte(throttle); packet[11+offset]= lowByte(rudder); packet[12+offset]|= highByte(rudder); packet[13+offset]=flags; diff --git a/Multiprotocol/FY326_nrf24l01.ino b/Multiprotocol/FY326_nrf24l01.ino index fdb441d..2daaae2 100644 --- a/Multiprotocol/FY326_nrf24l01.ino +++ b/Multiprotocol/FY326_nrf24l01.ino @@ -15,6 +15,7 @@ // Last sync with hexfet new_protocols/fy326_nrf24l01.c dated 2015-07-29 #if defined(FY326_NRF24L01_INO) + #include "iface_nrf24l01.h" #define FY326_INITIAL_WAIT 500 @@ -26,11 +27,9 @@ #define FY326_NUM_RF_CHANNELS 5 enum { - FY326_INIT1 = 0, - FY326_BIND1, + FY326_BIND1=0, FY326_BIND2, FY326_DATA, - FY319_INIT1, FY319_BIND1, FY319_BIND2, }; @@ -42,32 +41,34 @@ static void __attribute__((unused)) FY326_send_packet(uint8_t bind) { packet[0] = rx_tx_addr[3]; if(bind) - packet[1] = 0x55; + packet[1] = 0x55; else packet[1] = GET_FLAG(Servo_AUX3, 0x80) // Headless | GET_FLAG(Servo_AUX2, 0x40) // RTH | GET_FLAG(Servo_AUX1, 0x02) // Flip | GET_FLAG(Servo_AUX5, 0x01) // Calibrate | 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[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 - if(sub_protocol == FY319) { - packet[6] = 255 - convert_channel_8b_scale(AILERON, 0, 255); - packet[7] = convert_channel_8b_scale(ELEVATOR, 0, 255); - packet[8] = 255 - convert_channel_8b_scale(RUDDER, 0, 255); - } - else { + if(sub_protocol==FY319) + { + packet[6] = convert_channel_8b(AILERON); + packet[7] = convert_channel_8b(ELEVATOR); + packet[8] = convert_channel_8b(RUDDER); + } + else + { packet[6] = rx_tx_addr[0]; packet[7] = rx_tx_addr[1]; packet[8] = rx_tx_addr[2]; } - packet[9] = CHAN_TO_TRIM(packet[2]); // aileron_trim; - packet[10] = CHAN_TO_TRIM(packet[3]); // elevator_trim; - packet[11] = CHAN_TO_TRIM(packet[4]); // rudder_trim; - packet[12] = 0; // throttle_trim; - packet[13] = rxid; + packet[9] = CHAN_TO_TRIM(packet[2]); // aileron_trim; + packet[10] = CHAN_TO_TRIM(packet[3]); // elevator_trim; + packet[11] = CHAN_TO_TRIM(packet[4]); // rudder_trim; + packet[12] = 0; // throttle_trim; + packet[13] = rxid; packet[14] = rx_tx_addr[4]; 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++]); hopping_frequency_no %= FY326_NUM_RF_CHANNELS; + } - } - - // clear packet status bits and TX FIFO - NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); - NRF24L01_FlushTx(); + // clear packet status bits and TX FIFO + NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); + NRF24L01_FlushTx(); 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() { - NRF24L01_Initialize(); - NRF24L01_SetTxRxMode(TX_EN); - if(sub_protocol == FY319) - NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03); // Five-byte rx/tx address - else - NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x01); // Three-byte rx/tx address + NRF24L01_Initialize(); + NRF24L01_SetTxRxMode(TX_EN); + if(sub_protocol==FY319) + NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03); // Five-byte rx/tx address + else + 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_0A_RX_ADDR_P0, (uint8_t *)"\x15\x59\x23\xc6\x29", 5); NRF24L01_FlushTx(); @@ -107,136 +107,118 @@ static void __attribute__((unused)) FY326_init() NRF24L01_WriteReg(NRF24L01_05_RF_CH, FY326_RF_BIND_CHANNEL); NRF24L01_SetBitrate(NRF24L01_BR_250K); NRF24L01_SetPower(); - - NRF24L01_Activate(0x73); + + NRF24L01_Activate(0x73); NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x3f); NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x07); NRF24L01_Activate(0x73); + + //Switch to RX + NRF24L01_SetTxRxMode(TXRX_OFF); + NRF24L01_FlushRx(); + NRF24L01_SetTxRxMode(RX_EN); } uint16_t FY326_callback() { - uint8_t i; - switch (phase) { - case FY319_INIT1: - NRF24L01_SetTxRxMode(TXRX_OFF); - 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 + switch (phase) + { + case FY319_BIND1: + if(NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) + { 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: + rxid = packet[13]; + packet[0] = rx_tx_addr[3]; + packet[1] = 0x80; + packet[14]= rx_tx_addr[4]; + NRF24L01_SetTxRxMode(TXRX_OFF); + NRF24L01_SetTxRxMode(TX_EN); + NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); + NRF24L01_FlushTx(); + bind_counter = 255; + for(uint8_t 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_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)) { // TX data sent -> switch to RX mode - NRF24L01_SetTxRxMode(TXRX_OFF); - NRF24L01_FlushRx(); - NRF24L01_SetTxRxMode(RX_EN); - phase = FY326_BIND1; - } + NRF24L01_SetTxRxMode(TXRX_OFF); + NRF24L01_FlushRx(); + NRF24L01_SetTxRxMode(RX_EN); + phase = FY326_BIND1; + } else return FY326_PACKET_CHKTIME; - break; - - case FY326_DATA: - FY326_send_packet(0); - break; - } + break; + case FY326_DATA: + FY326_send_packet(0); + break; + } return FY326_PACKET_PERIOD; } static void __attribute__((unused)) FY326_initialize_txid() { - if(sub_protocol == FY319) { - hopping_frequency[0] = (rx_tx_addr[0]&0x0f) & ~0x80; - hopping_frequency[1] = (rx_tx_addr[0] >> 4) & ~0x80; - hopping_frequency[2] = (rx_tx_addr[1]&0x0f) & ~0x80; - hopping_frequency[3] = (rx_tx_addr[1] >> 4) & ~0x80; - hopping_frequency[4] = (rx_tx_addr[2] >> 4) & ~0x80; - } else { - hopping_frequency[0] = (rx_tx_addr[0]&0x0f); - 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); - } + hopping_frequency[0] = (rx_tx_addr[0]&0x0f); + 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); + if(sub_protocol==FY319) + for(uint8_t i=0;i<5;i++) + hopping_frequency[i]=rx_tx_addr[0] & ~0x80; } uint16_t initFY326(void) { BIND_IN_PROGRESS; // autobind protocol rxid = 0xAA; - bind_counter = 0; + bind_counter = FY326_BIND_COUNT; FY326_initialize_txid(); - FY326_init(); - if(sub_protocol == FY319) - phase = FY319_INIT1; - else - phase = FY326_INIT1; + FY326_init(); + if(sub_protocol==FY319) + { + phase=FY319_BIND1; + } + else + phase=FY326_BIND1; return FY326_INITIAL_WAIT; } diff --git a/Multiprotocol/Hontai_nrf24l01.ino b/Multiprotocol/Hontai_nrf24l01.ino index f522ef8..be99427 100644 --- a/Multiprotocol/Hontai_nrf24l01.ino +++ b/Multiprotocol/Hontai_nrf24l01.ino @@ -19,9 +19,9 @@ #define HONTAI_BIND_COUNT 80 #define HONTAI_PACKET_PERIOD 13500 - +#define FQ777_951_PACKET_PERIOD 10000 #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_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) { - uint8_t packet_size; if (bind) { memcpy(packet, rx_tx_addr, 5); memset(&packet[5], 0, 3); - packet_size=HONTAI_BIND_HONTAI_PACKET_SIZE; } else { -/* - if(sub_protocol == FORMAT_JJRCX1) - 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 + memset(packet,0,HONTAI_PACKET_SIZE); + packet[3] = convert_channel_8b_scale(THROTTLE, 0, 127) << 1; // Throttle packet[4] = convert_channel_8b_scale(AILERON, 63, 0); // Aileron packet[5] = convert_channel_8b_scale(ELEVATOR, 0, 63); // Elevator 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 else 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) 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 - - switch(sub_protocol) { - case FORMAT_HONTAI: - packet[0] = 0x0b; - packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture - packet[4] |= GET_FLAG(Servo_AUX6, 0x80) // RTH - | GET_FLAG(Servo_AUX5, 0x40); // Headless - packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate - | GET_FLAG(Servo_AUX1, 0x40); // Flip - packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video - packet[8] = convert_channel_8b_scale(RUDDER, 0, 32)-16; // Rudder trim - break; - case FORMAT_X5C1: - case FORMAT_JJRCX1: - packet[0] = GET_FLAG(Servo_AUX2, 0x02); //Arm - packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture - packet[4] |= 0x80; // unknown - if (sub_protocol == FORMAT_X5C1) - packet[4] |= GET_FLAG(Servo_AUX2, 0x40); // Lights (X5C1) - packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate - | GET_FLAG(Servo_AUX1, 0x40); // Flip - packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video - packet[8] = 0xc0 // high rate, no rudder trim - | GET_FLAG(Servo_AUX6, 0x02) // RTH - | GET_FLAG(Servo_AUX5, 0x01); // Headless - break; - case FORMAT_FQ777: - // todo: add missing calibration flag - packet[0] = GET_FLAG(Servo_AUX3, 0x01) // Picture - | GET_FLAG(Servo_AUX4, 0x02); // Video - packet[3] |= GET_FLAG(Servo_AUX1, 0x01); // Flip - packet[4] |= 0xc0; // high rate (mid=0xa0, low=0x60) - packet[6] |= GET_FLAG(Servo_AUX5, 0x40); // Headless - if((packet[4] & 0x3f) > 0x3d && (packet[5] & 0x3f) < 3) - packet[5] |= 0x80; // accelerometer recalibration - break; - packet[8] = convert_channel_8b_scale(RUDDER, 0, 32)-16; // Rudder trim - } - - packet_size=HONTAI_PACKET_SIZE; + switch(sub_protocol) + { + case FORMAT_HONTAI: + packet[0] = 0x0B; + packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture + packet[4] |= GET_FLAG(Servo_AUX6, 0x80) // RTH + | GET_FLAG(Servo_AUX5, 0x40); // Headless + packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate + | GET_FLAG(Servo_AUX1, 0x40); // Flip + packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video + break; + case FORMAT_JJRCX1: + packet[0] = GET_FLAG(Servo_AUX2, 0x02); // Arm + packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture + packet[4] |= 0x80; // unknown + packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate + | GET_FLAG(Servo_AUX1, 0x40); // Flip + packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video + packet[8] = 0xC0 // high rate, no rudder trim + | GET_FLAG(Servo_AUX6, 0x02) // RTH + | GET_FLAG(Servo_AUX5, 0x01); // Headless + break; + case FORMAT_X5C1: + packet[0] = 0x0B; + packet[3] |= GET_FLAG(Servo_AUX3, 0x01); // Picture + packet[4] = 0x80 // unknown + | GET_FLAG(Servo_AUX2, 0x40); // Lights + packet[5] |= GET_FLAG(Servo_AUX7, 0x80) // Calibrate + | GET_FLAG(Servo_AUX1, 0x40); // Flip + packet[6] |= GET_FLAG(Servo_AUX4, 0x80); // Video + packet[8] = 0xC0 // high rate, no rudder trim + | GET_FLAG(Servo_AUX6, 0x02) // RTH + | GET_FLAG(Servo_AUX5, 0x01); // Headless + break; + case FORMAT_FQ777_951: + packet[0] = GET_FLAG(Servo_AUX3, 0x01) // Picture + | GET_FLAG(Servo_AUX4, 0x02); // Video + packet[3] |= GET_FLAG(Servo_AUX1, 0x01); // Flip + packet[4] |= 0xC0; // High rate (mid=0xa0, low=0x60) + 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 if(sub_protocol == FORMAT_JJRCX1) @@ -184,9 +141,9 @@ static void __attribute__((unused)) HONTAI_send_packet(uint8_t bind) NRF24L01_FlushTx(); if(sub_protocol == FORMAT_JJRCX1) - NRF24L01_WritePayload(packet, packet_size); + NRF24L01_WritePayload(packet, bind ? HONTAI_BIND_PACKET_SIZE:HONTAI_PACKET_SIZE); else - XN297_WritePayload(packet, packet_size); + XN297_WritePayload(packet, bind ? HONTAI_BIND_PACKET_SIZE:HONTAI_PACKET_SIZE); NRF24L01_SetPower(); } @@ -224,12 +181,11 @@ static void __attribute__((unused)) HONTAI_init() 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 - {0x0a, 0x1e, 0x2d}, // JJRC X1 - {0x05, 0x19, 0x28}}; // FQ777-951 + {0x0a, 0x1e, 0x2d}}; // JJRC X1 -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}, {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}, @@ -240,10 +196,10 @@ static void __attribute__((unused)) HONTAI_init2() uint8_t data_tx_addr[5]; //TX address - data_tx_addr[0] = pgm_read_byte_near( &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[2] = pgm_read_byte_near( &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[0] = pgm_read_byte_near( &HONTAI_addr_vals[0][ rx_tx_addr[3] & 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( &HONTAI_addr_vals[2][ rx_tx_addr[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; if(sub_protocol == FORMAT_JJRCX1) 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 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; } static void __attribute__((unused)) HONTAI_initialize_txid() { 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[1] = 0x4b; @@ -288,7 +244,7 @@ uint16_t HONTAI_callback() else HONTAI_send_packet(0); - return HONTAI_PACKET_PERIOD; + return sub_protocol == FORMAT_FQ777_951 ? FQ777_951_PACKET_PERIOD : HONTAI_PACKET_PERIOD; } uint16_t initHONTAI() diff --git a/Multiprotocol/Hubsan_a7105.ino b/Multiprotocol/Hubsan_a7105.ino index 4b681ec..84f7d46 100644 --- a/Multiprotocol/Hubsan_a7105.ino +++ b/Multiprotocol/Hubsan_a7105.ino @@ -249,7 +249,7 @@ static void __attribute__((unused)) hubsan_build_packet() hubsan_update_crc(); } -#if defined(TELEMETRY) +#ifdef HUBSAN_HUB_TELEMETRY static uint8_t __attribute__((unused)) hubsan_check_integrity() { if( (packet[0]&0xFE) != 0xE0 ) @@ -263,7 +263,7 @@ static uint8_t __attribute__((unused)) hubsan_check_integrity() uint16_t ReadHubsan() { -#if defined(TELEMETRY) +#ifdef HUBSAN_HUB_TELEMETRY static uint8_t rfMode=0; #endif static uint8_t txState=0; @@ -348,7 +348,7 @@ uint16_t ReadHubsan() case DATA_4: case DATA_5: if( txState == 0) { // send packet -#if defined(TELEMETRY) +#ifdef HUBSAN_HUB_TELEMETRY rfMode = A7105_TX; #endif if( phase == DATA_1) @@ -370,7 +370,7 @@ uint16_t ReadHubsan() delay=3000; } else { -#if defined(TELEMETRY) +#ifdef HUBSAN_HUB_TELEMETRY if( rfMode == A7105_TX) {// switch to rx mode 3ms after packet sent for( i=0; i<10; i++) @@ -392,7 +392,7 @@ uint16_t ReadHubsan() A7105_ReadData(16); 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; } A7105_Strobe(A7105_RX); @@ -428,8 +428,8 @@ uint16_t initHubsan() { phase = BIND_1; packet_count=0; id_data=ID_NORMAL; -#if defined(TELEMETRY) - telemetry_link=0; +#ifdef HUBSAN_HUB_TELEMETRY + init_hub_telemetry(); #endif return 10000; } diff --git a/Multiprotocol/MJXQ_nrf24l01.ino b/Multiprotocol/MJXQ_nrf24l01.ino index 04cf9d6..3da90ff 100644 --- a/Multiprotocol/MJXQ_nrf24l01.ino +++ b/Multiprotocol/MJXQ_nrf24l01.ino @@ -36,6 +36,40 @@ const uint8_t PROGMEM MJXQ_map_rfchan[][4] = { {0x0A, 0x3C, 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_DOWN 0x08 @@ -84,17 +118,18 @@ static void __attribute__((unused)) MJXQ_send_packet(uint8_t bind) packet[14] = 0xC0; // bind value // Servo_AUX1 FLIP -// Servo_AUX2 LED +// Servo_AUX2 LED / ARM // Servo_AUX3 PICTURE // Servo_AUX4 VIDEO // Servo_AUX5 HEADLESS // Servo_AUX6 RTH // Servo_AUX7 AUTOFLIP // X800, X600 -// Servo_AUX8 ARM // H26WH +// Servo_AUX8 PAN +// Servo_AUX9 TILT switch(sub_protocol) { - case H26D: case H26WH: + case H26D: packet[10]=MJXQ_pan_tilt_value(); // fall through on purpose - no break 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_AUX3, 0x08) //PICTURE | GET_FLAG(Servo_AUX4, 0x10) //VIDEO - | GET_FLAG(!Servo_AUX2, 0x20); // air/ground mode - } - if (sub_protocol == H26WH) { - packet[10] &= ~0x40; - packet[14] &= ~0x24; - packet[14] |= GET_FLAG(Servo_AUX2, 0x04); + | GET_FLAG(!Servo_AUX2, 0x20); // LED or air/ground mode + if(sub_protocol==H26WH) + { + packet[10] |=0x40; //High rate + packet[14] &= ~0x24; // unset air/ground & arm flags + packet[14] |= GET_FLAG(Servo_AUX2, 0x02); // arm + } } break; 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]; 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]); hopping_frequency_no %= 2 * MJXQ_RF_NUM_CHANNELS; // channels repeated NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); NRF24L01_FlushTx(); - switch (Model.proto_opts[PROTOOPTS_FORMAT]) { - case H26D: - case H26WH: - NRF24L01_WritePayload(packet, MJXQ_PACKET_SIZE); - break; - default: - XN297_WritePayload(packet, MJXQ_PACKET_SIZE); - break; + // Power on, TX mode, 2byte CRC and send packet + if (sub_protocol == H26D || sub_protocol == H26WH) + { + NRF24L01_SetTxRxMode(TX_EN); + NRF24L01_WritePayload(packet, MJXQ_PACKET_SIZE); + } + else + { + XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP)); + XN297_WritePayload(packet, MJXQ_PACKET_SIZE); } - NRF24L01_SetPower(); } @@ -179,21 +205,20 @@ static void __attribute__((unused)) MJXQ_init() { uint8_t addr[MJXQ_ADDRESS_LENGTH]; memcpy(addr, "\x6d\x6a\x77\x77\x77", MJXQ_ADDRESS_LENGTH); - NRF24L01_Initialize(); - NRF24L01_SetTxRxMode(TX_EN); - if (sub_protocol == WLH08) memcpy(hopping_frequency, "\x12\x22\x32\x42", MJXQ_RF_NUM_CHANNELS); else - if (sub_protocol == H26D || sub_protocol == H26WH || sub_protocol == E010) - memcpy(hopping_frequency, "\x36\x3e\x46\x2e", MJXQ_RF_NUM_CHANNELS); + if (sub_protocol == H26D || sub_protocol == H26D || sub_protocol == E010) + memcpy(hopping_frequency, "\x2e\x36\x3e\x46", MJXQ_RF_NUM_CHANNELS); else { memcpy(hopping_frequency, "\x0a\x35\x42\x3d", MJXQ_RF_NUM_CHANNELS); memcpy(addr, "\x6d\x6a\x73\x73\x73", MJXQ_ADDRESS_LENGTH); } - + NRF24L01_Initialize(); + NRF24L01_SetTxRxMode(TX_EN); + if (sub_protocol == H26D || sub_protocol == H26WH) { NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x03); // 5-byte RX/TX address @@ -204,11 +229,11 @@ static void __attribute__((unused)) MJXQ_init() NRF24L01_FlushTx(); NRF24L01_FlushRx(); - 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_02_EN_RXADDR, 0x01); // Enable data pipe 0 only - 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_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_02_EN_RXADDR, 0x01); // Enable data pipe 0 only + NRF24L01_WriteReg(NRF24L01_04_SETUP_RETR, 0x00); // no retransmits + NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, MJXQ_PACKET_SIZE); if (sub_protocol == E010) NRF24L01_SetBitrate(NRF24L01_BR_250K); // 250K else @@ -218,30 +243,52 @@ static void __attribute__((unused)) MJXQ_init() static void __attribute__((unused)) MJXQ_init2() { - if (sub_protocol == H26D) - memcpy(hopping_frequency, "\x32\x3e\x42\x4e", MJXQ_RF_NUM_CHANNELS); - else - if (sub_protocol != WLH08 && sub_protocol != E010) + switch(sub_protocol) + { + case H26D: + 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= sizeof(ls_mys_byte)) - ls_counter=0; - } + else + if(sub_protocol==FY805) + { + packet[6]=0x20; + //Rate 0x01? + //Flip ? + packet[7]=0x01 + |GET_FLAG( Servo_AUX1, FLAG_MT_FLIP ) + |GET_FLAG( Servo_AUX5, FLAG_FY805_HEADLESS ); //HEADLESS + 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; for(uint8_t i=0; i<8; i++) @@ -135,7 +152,10 @@ static void __attribute__((unused)) MT99XX_send_packet() if(sub_protocol == LS) NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x2D); // LS always transmits on the same channel 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_FlushTx(); XN297_WritePayload(packet, MT99XX_PACKET_SIZE); @@ -184,10 +204,17 @@ static void __attribute__((unused)) MT99XX_initialize_txid() rx_tx_addr[2] = 0x00; } else - if(sub_protocol == LS) - rx_tx_addr[0] = 0xCC; - else //MT99 & H7 + if(sub_protocol == FY805) + { + rx_tx_addr[0] = 0x81; // test (SB id) + rx_tx_addr[1] = 0x0F; 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]; channel_offset = (((checksum_offset & 0xf0)>>4) + (checksum_offset & 0x0f)) % 8; } @@ -209,7 +236,10 @@ uint16_t MT99XX_callback() if(sub_protocol == LS) NRF24L01_WriteReg(NRF24L01_05_RF_CH, 0x2D); // LS always transmits on the same channel 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_FlushTx(); XN297_WritePayload(packet, MT99XX_PACKET_SIZE); // bind packet @@ -256,6 +286,12 @@ uint16_t initMT99XX(void) packet[2] = 0x05; packet[3] = 0x11; 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[5] = rx_tx_addr[1]; diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index e8e4692..44facad 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -150,7 +150,8 @@ uint8_t pkt[MAX_PKT];//telemetry receiving packets volatile uint8_t tx_head=0; volatile uint8_t tx_tail=0; #endif // BASH_SERIAL - uint8_t v_lipo; + uint8_t v_lipo1; + uint8_t v_lipo2; int16_t RSSI_dBm; uint8_t TX_RSSI; uint8_t telemetry_link=0; @@ -333,7 +334,6 @@ void setup() cur_protocol[1] = protocol; sub_protocol = PPM_prot[mode_select].sub_proto; RX_num = PPM_prot[mode_select].rx_num; - MProtocol_id = RX_num + MProtocol_id_master; option = PPM_prot[mode_select].option; if(PPM_prot[mode_select].power) POWER_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 { update_serial_data(); // Update protocol and data - + INPUT_SIGNAL_on; //valid signal received + last_signal=millis(); } #endif //ENABLE_SERIAL #ifdef ENABLE_PPM @@ -492,11 +493,7 @@ void Update_All() #endif //ENABLE_PPM update_channels_aux(); #if defined(TELEMETRY) - if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) - #ifdef ENABLE_BAYANG_TELEMETRY - || (protocol==MODE_BAYANG) - #endif - ) + if((protocol==MODE_FRSKYD) || (protocol==MODE_BAYANG) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) ) TelemetryUpdate(); #endif update_led_status(); @@ -528,9 +525,6 @@ static void update_channels_aux(void) { // Protocol needs to be changed LED_off; //led off during protocol init modules_reset(); //reset all modules - #ifdef ENABLE_PPM - AUTOBIND_FLAG_on; - #endif //ENABLE_PPM protocol_init(); //init new protocol } } @@ -646,6 +640,10 @@ static void protocol_init() TX_MAIN_PAUSE_off; #endif + //Set global ID and rx_tx_addr + MProtocol_id = RX_num + MProtocol_id_master; + set_rx_tx_addr(MProtocol_id); + blink=millis(); if(IS_BIND_BUTTON_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] 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 - MProtocol_id=MProtocol_id_master+RX_num;//personalized RX bind + rx num - set_rx_tx_addr(MProtocol_id); //set rx_tx_addr } else 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) 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 ) ; - if(protocol==MODE_FRSKYX - #ifdef ENABLE_BAYANG_TELEMETRY - || protocol==MODE_BAYANG - #endif - ) + if(protocol==MODE_FRSKYX) initTXSerial( SPEED_57600 ) ; if(protocol==MODE_DSM) initTXSerial( SPEED_125K ) ; diff --git a/Multiprotocol/NRF24l01_SPI.ino b/Multiprotocol/NRF24l01_SPI.ino index c844e9d..480a6ef 100644 --- a/Multiprotocol/NRF24l01_SPI.ino +++ b/Multiprotocol/NRF24l01_SPI.ino @@ -27,6 +27,7 @@ uint8_t rf_setup; void NRF24L01_Initialize() { rf_setup = 0x09; + XN297_SetScrambledMode(XN297_SCRAMBLED); } 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) { NRF_CSN_off; @@ -92,22 +84,12 @@ static void NRF24L01_ReadPayload(uint8_t * data, uint8_t length) data[i] = SPI_Read(); 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; - result =SPI_Write(state); + SPI_Write(state); NRF_CSN_on; - return result; } void NRF24L01_FlushTx() @@ -120,6 +102,20 @@ void NRF24L01_FlushRx() 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) { NRF_CSN_off; @@ -391,17 +387,9 @@ void XN297_ReadPayload(uint8_t* msg, uint8_t len) NRF24L01_ReadPayload(msg, len); for(uint8_t i=0; i> 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> 2; + // Base row is defined by lowest 2 bits + sum &=0x03; 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 hopping_frequency[i] = (val & 0x0f) ? val : val - 3; } @@ -189,19 +185,14 @@ static void __attribute__((unused)) V2X2_send_packet(uint8_t bind) // Channel 9 if (Servo_AUX5) flags2 = V2X2_FLAG_HEADLESS; - - if(sub_protocol == FORMAT_JXD506) { - // Channel 10 - if (Servo_AUX6) flags2 |= JXD_FLAG_START_STOP; + if(sub_protocol==JXD506) + { // Channel 11 - if (Servo_AUX7) flags2 |= JXD_FLAG_EMERGENCY; - - // Channel 12 down - if (Servo_data[AUX8] < PPM_SWITCH_B) flags2 |= JXD_FLAG_CAMERA_DN; - // Channel 12 up - if (Servo_data[AUX8] > PPM_SWITCH) flags2 |= JXD_FLAG_CAMERA_UP; - - } else { + if (Servo_AUX7) + flags2 |= V2X2_FLAG_EMERGENCY; + } + else + { // Channel 10 if (Servo_AUX6) 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[8] = rx_tx_addr[2]; packet[9] = rx_tx_addr[3]; - // empty + // flags packet[10] = flags2; packet[11] = 0x00; packet[12] = 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; V2X2_add_pkt_checksum(); @@ -250,7 +253,7 @@ uint16_t ReadV2x2() break; case V202_BIND2: if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED) { - return PACKET_CHKTIME; + return V2X2_PACKET_CHKTIME; } V2X2_send_packet(1); if (--counter == 0) { @@ -260,13 +263,13 @@ uint16_t ReadV2x2() break; case V202_DATA: if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED) { - return PACKET_CHKTIME; + return V2X2_PACKET_CHKTIME; } V2X2_send_packet(0); break; } // Packet every 4ms - return PACKET_PERIOD; + return V2X2_PACKET_PERIOD; } uint16_t initV2x2() @@ -275,7 +278,7 @@ uint16_t initV2x2() // if (IS_AUTOBIND_FLAG_on) { - counter = BIND_COUNT; + counter = V2X2_BIND_COUNT; phase = V202_INIT2; } else diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index f54a13f..74852e6 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -85,24 +85,34 @@ //Make sure telemetry is selected correctly #ifndef TELEMETRY #undef INVERT_TELEMETRY - #undef DSM_TELEMETRY - #undef SPORT_TELEMETRY + #undef AFHDS2A_FW_TELEMETRY + #undef AFHDS2A_HUB_TELEMETRY + #undef BAYANG_HUB_TELEMETRY + #undef HUBSAN_HUB_TELEMETRY #undef HUB_TELEMETRY - #undef AFHDS2A_TELEMETRY + #undef SPORT_TELEMETRY + #undef DSM_TELEMETRY #else - #if not defined(DSM_CYRF6936_INO) - #undef DSM_TELEMETRY + #if not defined(BAYANG_NRF24L01_INO) + #undef BAYANG_HUB_TELEMETRY #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 #endif #if not defined(FRSKYX_CC2500_INO) #undef SPORT_TELEMETRY #endif - #if not defined(AFHDS2A_A7105_INO) - #undef AFHDS2A_TELEMETRY + #if not defined(DSM_CYRF6936_INO) + #undef DSM_TELEMETRY #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 INVERT_TELEMETRY #endif diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index bc16d7d..73b18e2 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -129,11 +129,14 @@ //#define INVERT_TELEMETRY //Comment a line to disable a protocol telemetry - #define DSM_TELEMETRY - #define SPORT_TELEMETRY - #define HUB_TELEMETRY - #define AFHDS2A_TELEMETRY -// #define ENABLE_BAYANG_TELEMETRY // uncomment to enable bayang telemtry for H101 acro firmware - https://github.com/bikemike/H101-acro/tree/telemetry + #define DSM_TELEMETRY // Forward received telemetry packet directly to TX to be decoded + #define SPORT_TELEMETRY // Use FrSkyX SPORT format to send telemetry to TX + #define AFHDS2A_FW_TELEMETRY // Forward received telemetry packet directly to TX to be decoded + #define HUB_TELEMETRY // Use FrSkyD Hub format to send telemetry to TX + #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 ***/ @@ -233,7 +236,8 @@ const PPM_Parameters PPM_prot[15]= { Hisky HK310 MODE_V2X2 - NONE + V2X2 + JXD506 MODE_DSM DSM2_22 DSM2_11 @@ -275,7 +279,6 @@ const PPM_Parameters PPM_prot[15]= { H8_3D MODE_BAYANG BAYANG - BAYANG TELEMETRY H8S3D MODE_FRSKYX CH_16 @@ -287,6 +290,7 @@ const PPM_Parameters PPM_prot[15]= { H7 YZ LS + FY805 MODE_MJXQ WLH08 X600 @@ -312,7 +316,7 @@ const PPM_Parameters PPM_prot[15]= { FORMAT_HONTAI FORMAT_JJRCX1 FORMAT_X5C1 - FQ777-951 + FORMAT_FQ777_951 MODE_AFHDS2A PWM_IBUS PPM_IBUS diff --git a/Multiprotocol/multiprotocol.h b/Multiprotocol/multiprotocol.h index 7b920a8..9e53f5f 100644 --- a/Multiprotocol/multiprotocol.h +++ b/Multiprotocol/multiprotocol.h @@ -141,15 +141,15 @@ enum CG023 enum BAYANG { BAYANG = 0, - BAYANG_TELEM = 1, - H8S3D = 2 + H8S3D = 1 }; enum MT99XX { MT99 = 0, H7 = 1, YZ = 2, - LS = 3 + LS = 3, + FY805 = 4 }; enum MJXQ { @@ -170,7 +170,12 @@ enum HONTAI FORMAT_HONTAI = 0, FORMAT_JJRCX1 = 1, FORMAT_X5C1 = 2, - FORMAT_FQ777 = 3 + FORMAT_FQ777_951 =3 +}; +enum V2X2 +{ + V2X2 = 0, + JXD506 = 1, }; enum HUBSAN @@ -520,22 +525,19 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- H8_3D 2 sub_protocol==BAYANG BAYANG 0 - BAYANG TELEM 1 - H8S3D 2 + H8S3D 1 sub_protocol==MT99XX MT99 0 H7 1 YZ 2 LS 3 + FY805 4 sub_protocol==MJXQ WLH08 0 X600 1 X800 2 H26D 3 E010 4 - sub_protocol==FY326 - FY326 0 - FY319 1 sub_protocol==FRSKYX CH_16 0 CH_8 1 @@ -543,15 +545,19 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- FORMAT_HONTAI 0 FORMAT_JJRCX1 1 FORMAT_X5C1 2 - FQ777-521 3 - sub_protocol==BAYANG - BAYANG 0 - BAYANG_TELEM 1 + FORMAT_FQ777_951 3 sub_protocol==AFHDS2A PWM_IBUS 0 PPM_IBUS 1 PWM_SBUS 2 PPM_SBUS 3 + sub_protocol==V2X2 + V2X2 0 + JXD506 1 + sub_protocol==FY326 + FY326 0 + FY319 1 + Power value => 0x80 0=High/1=Low Stream[3] = option_protocol; option_protocol value is -127..127 diff --git a/Multiprotocol/sync.ffs_db b/Multiprotocol/sync.ffs_db index 30f54e3..40a7d88 100644 Binary files a/Multiprotocol/sync.ffs_db and b/Multiprotocol/sync.ffs_db differ