From 8012de80a4fbd6b6702f3918c7c2fb4976a4b019 Mon Sep 17 00:00:00 2001 From: Goebish Date: Thu, 19 Oct 2017 23:38:48 +0200 Subject: [PATCH 1/3] Add X16_AH format to Bayang protocol --- Multiprotocol/Bayang_nrf24l01.ino | 59 ++++++++++++++++++++++++++----- Multiprotocol/Multiprotocol.h | 4 ++- Multiprotocol/_Config.h | 1 + 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index 043dd0c..3d5af6a 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -25,6 +25,7 @@ Multiprotocol is distributed in the hope that it will be useful, #define BAYANG_PACKET_SIZE 15 #define BAYANG_RF_NUM_CHANNELS 4 #define BAYANG_RF_BIND_CHANNEL 0 +#define BAYANG_RF_BIND_CHANNEL_X16_AH 10 #define BAYANG_ADDRESS_LENGTH 5 enum BAYANG_FLAGS { @@ -35,9 +36,12 @@ enum BAYANG_FLAGS { BAYANG_FLAG_VIDEO = 0x10, BAYANG_FLAG_PICTURE = 0x20, // flags going to packet[3] - BAYANG_FLAG_INVERTED = 0x80 // inverted flight on Floureon H101 + BAYANG_FLAG_INVERTED = 0x80, // inverted flight on Floureon H101 + BAYANG_FLAG_TAKE_OFF = 0x20, // take off / landing on X16 AH }; +uint8_t bayang_bind_chan; + static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) { uint8_t i; @@ -53,15 +57,29 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[i+1]=rx_tx_addr[i]; for(i=0;i<4;i++) packet[i+6]=hopping_frequency[i]; - packet[10] = rx_tx_addr[0]; // txid[0] - packet[11] = rx_tx_addr[1]; // txid[1] + switch (sub_protocol) { + case X16_AH: + packet[10] = 0x00; + packet[11] = 0x00; + break; + default: + packet[10] = rx_tx_addr[0]; // txid[0] + packet[11] = rx_tx_addr[1]; // txid[1] + break; + } } else { uint16_t val; - packet[0] = 0xA5; + switch (sub_protocol) { + case X16_AH: + packet[0] = 0xA6; + break; + default: + packet[0] = 0xA5; + break; + } packet[1] = 0xFA; // normal mode is 0xf7, expert 0xfa - //Flags packet[2] packet[2] = 0x00; if(Servo_AUX1) @@ -78,7 +96,8 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[3] = 0x00; if(Servo_AUX6) packet[3] = BAYANG_FLAG_INVERTED; - + if(Servo_AUX7) + packet[3] |= BAYANG_FLAG_TAKE_OFF; //Aileron val = convert_channel_10b(AILERON); packet[4] = (val>>8) + ((val>>2) & 0xFC); @@ -96,13 +115,26 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[10] = (val>>8) + (val>>2 & 0xFC); packet[11] = val & 0xFF; } - packet[12] = rx_tx_addr[2]; // txid[2] - packet[13] = sub_protocol==H8S3D?0x34:0x0A; + switch (sub_protocol) { + case H8S3D: + packet[12] = rx_tx_addr[2]; // txid[2] + packet[13] = 0x34; + break; + case X16_AH: + packet[12] = 0; + packet[13] = 0; + break; + default: + packet[12] = rx_tx_addr[2]; // txid[2] + packet[13] = 0x0A; + break; + } + packet[14] = 0; 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++]); + NRF24L01_WriteReg(NRF24L01_05_RF_CH, bind ? bayang_bind_chan:hopping_frequency[hopping_frequency_no++]); hopping_frequency_no%=BAYANG_RF_NUM_CHANNELS; // clear packet status bits and TX FIFO @@ -180,6 +212,15 @@ static void __attribute__((unused)) BAYANG_init() NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x01); NRF24L01_Activate(0x73); + + switch(sub_protocol) { + case X16_AH: + bayang_bind_chan = BAYANG_RF_BIND_CHANNEL_X16_AH; + break; + default: + bayang_bind_chan = BAYANG_RF_BIND_CHANNEL; + break; + } } uint16_t BAYANG_callback() diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index c7173e4..69e998e 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -136,7 +136,8 @@ enum CG023 enum BAYANG { BAYANG = 0, - H8S3D = 1 + H8S3D = 1, + X16_AH = 2, }; enum MT99XX { @@ -537,6 +538,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- sub_protocol==BAYANG BAYANG 0 H8S3D 1 + X16_AH 2 sub_protocol==MT99XX MT99 0 H7 1 diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 513ca8b..92a4529 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -305,6 +305,7 @@ const PPM_Parameters PPM_prot[15]= { MODE_BAYANG BAYANG H8S3D + X16_AH MODE_ESKY NONE MODE_MT99XX From 6b9d7e665c567b03b0db9b8db9c7f09d4dadc0c3 Mon Sep 17 00:00:00 2001 From: Goebish Date: Sat, 21 Oct 2017 01:00:49 +0200 Subject: [PATCH 2/3] Cleanup tab indent --- Multiprotocol/Bayang_nrf24l01.ino | 69 +++++++++++++++---------------- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/_Config.h | 2 +- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index 3d5af6a..e67d185 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -57,16 +57,16 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[i+1]=rx_tx_addr[i]; for(i=0;i<4;i++) packet[i+6]=hopping_frequency[i]; - switch (sub_protocol) { - case X16_AH: - packet[10] = 0x00; - packet[11] = 0x00; - break; - default: - packet[10] = rx_tx_addr[0]; // txid[0] - packet[11] = rx_tx_addr[1]; // txid[1] - break; - } + switch (sub_protocol) { + case X16_AH: + packet[10] = 0x00; + packet[11] = 0x00; + break; + default: + packet[10] = rx_tx_addr[0]; // txid[0] + packet[11] = rx_tx_addr[1]; // txid[1] + break; + } } else { @@ -96,8 +96,8 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[3] = 0x00; if(Servo_AUX6) packet[3] = BAYANG_FLAG_INVERTED; - if(Servo_AUX7) - packet[3] |= BAYANG_FLAG_TAKE_OFF; + if(Servo_AUX7) + packet[3] |= BAYANG_FLAG_TAKE_OFF; //Aileron val = convert_channel_10b(AILERON); packet[4] = (val>>8) + ((val>>2) & 0xFC); @@ -115,20 +115,20 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) packet[10] = (val>>8) + (val>>2 & 0xFC); packet[11] = val & 0xFF; } - switch (sub_protocol) { - case H8S3D: - packet[12] = rx_tx_addr[2]; // txid[2] - packet[13] = 0x34; - break; - case X16_AH: - packet[12] = 0; - packet[13] = 0; - break; - default: - packet[12] = rx_tx_addr[2]; // txid[2] - packet[13] = 0x0A; - break; - } + switch (sub_protocol) { + case H8S3D: + packet[12] = rx_tx_addr[2]; // txid[2] + packet[13] = 0x34; + break; + case X16_AH: + packet[12] = 0; + packet[13] = 0; + break; + default: + packet[12] = rx_tx_addr[2]; // txid[2] + packet[13] = 0x0A; + break; + } packet[14] = 0; for (uint8_t i=0; i < BAYANG_PACKET_SIZE-1; i++) @@ -212,15 +212,6 @@ static void __attribute__((unused)) BAYANG_init() NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes NRF24L01_WriteReg(NRF24L01_1D_FEATURE, 0x01); NRF24L01_Activate(0x73); - - switch(sub_protocol) { - case X16_AH: - bayang_bind_chan = BAYANG_RF_BIND_CHANNEL_X16_AH; - break; - default: - bayang_bind_chan = BAYANG_RF_BIND_CHANNEL; - break; - } } uint16_t BAYANG_callback() @@ -291,6 +282,14 @@ uint16_t initBAYANG(void) BAYANG_initialize_txid(); BAYANG_init(); packet_count=0; + switch (sub_protocol) { + case X16_AH: + bayang_bind_chan = BAYANG_RF_BIND_CHANNEL_X16_AH; + break; + default: + bayang_bind_chan = BAYANG_RF_BIND_CHANNEL; + break; + } #ifdef BAYANG_HUB_TELEMETRY init_frskyd_link_telemetry(); telemetry_lost=1; // do not send telemetry to TX right away until we have a TX_RSSI value to prevent warning message... diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 69e998e..05ed8df 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -538,7 +538,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p -- sub_protocol==BAYANG BAYANG 0 H8S3D 1 - X16_AH 2 + X16_AH 2 sub_protocol==MT99XX MT99 0 H7 1 diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 92a4529..5f08722 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -305,7 +305,7 @@ const PPM_Parameters PPM_prot[15]= { MODE_BAYANG BAYANG H8S3D - X16_AH + X16_AH MODE_ESKY NONE MODE_MT99XX From b0e07c569d46a4c39db9501b0504f7e744df6917 Mon Sep 17 00:00:00 2001 From: Goebish Date: Sat, 21 Oct 2017 01:11:51 +0200 Subject: [PATCH 3/3] More indent cleanup --- Multiprotocol/Bayang_nrf24l01.ino | 46 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Multiprotocol/Bayang_nrf24l01.ino b/Multiprotocol/Bayang_nrf24l01.ino index e67d185..0601f28 100644 --- a/Multiprotocol/Bayang_nrf24l01.ino +++ b/Multiprotocol/Bayang_nrf24l01.ino @@ -71,14 +71,14 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) else { uint16_t val; - switch (sub_protocol) { - case X16_AH: - packet[0] = 0xA6; - break; - default: - packet[0] = 0xA5; - break; - } + switch (sub_protocol) { + case X16_AH: + packet[0] = 0xA6; + break; + default: + packet[0] = 0xA5; + break; + } packet[1] = 0xFA; // normal mode is 0xf7, expert 0xfa //Flags packet[2] packet[2] = 0x00; @@ -131,7 +131,7 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) } 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_bind_chan:hopping_frequency[hopping_frequency_no++]); @@ -143,19 +143,19 @@ static void __attribute__((unused)) BAYANG_send_packet(uint8_t bind) XN297_WritePayload(packet, BAYANG_PACKET_SIZE); - NRF24L01_SetTxRxMode(TXRX_OFF); - NRF24L01_SetTxRxMode(TX_EN); + 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) + if (option) { // switch radio to rx as soon as packet is sent - while (!(NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS))); + while (!(NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS))); NRF24L01_WriteReg(NRF24L01_00_CONFIG, 0x03); - } + } #endif NRF24L01_SetPower(); // Set tx_power @@ -202,16 +202,16 @@ 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_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); + 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()