From 31a9f6860ddfe75e9e89285c31a10a7742c08d9b Mon Sep 17 00:00:00 2001 From: pascallanger Date: Thu, 15 Feb 2024 15:51:20 +0100 Subject: [PATCH] New protocol SGF22 Only 1 ID! --- Lua_scripts/MultiChan.txt | 1 + Multiprotocol/Multi.txt | 1 + Multiprotocol/Multi_Protos.ino | 4 + Multiprotocol/Multiprotocol.h | 3 +- Multiprotocol/SGF22_nrf24l01.ino | 132 +++++++++++++++++++++++++++++++ Multiprotocol/_Config.h | 1 + 6 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 Multiprotocol/SGF22_nrf24l01.ino diff --git a/Lua_scripts/MultiChan.txt b/Lua_scripts/MultiChan.txt index 8d7835c..4af68fa 100644 --- a/Lua_scripts/MultiChan.txt +++ b/Lua_scripts/MultiChan.txt @@ -212,3 +212,4 @@ 94,0,Scorpio 95,0,Bluefly,HP100,0,CH5,CH6,CH7,CH8 96,0,BumbleB +97,0,SGF22,Std,1,MODE,FLIP,LED diff --git a/Multiprotocol/Multi.txt b/Multiprotocol/Multi.txt index f420d6a..c7244bf 100644 --- a/Multiprotocol/Multi.txt +++ b/Multiprotocol/Multi.txt @@ -93,3 +93,4 @@ 94,Scorpio 95,BlueFly 96,BumbleB +97,SGF22 diff --git a/Multiprotocol/Multi_Protos.ino b/Multiprotocol/Multi_Protos.ino index 32bd83e..3ffc349 100644 --- a/Multiprotocol/Multi_Protos.ino +++ b/Multiprotocol/Multi_Protos.ino @@ -108,6 +108,7 @@ const char STR_XERALL[] ="Xerall"; const char STR_SCORPIO[] ="Scorpio"; const char STR_BLUEFLY[] ="BlueFly"; const char STR_BUMBLEB[] ="BumbleB"; +const char STR_SGF22[] ="SGF22"; const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20"; const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501"; @@ -444,6 +445,9 @@ const mm_protocol_definition multi_protocols[] = { #if defined(SCORPIO_CYRF6936_INO) {PROTO_SCORPIO, STR_SCORPIO, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_CYRF, SCORPIO_init, SCORPIO_callback }, #endif + #if defined(SGF22_NRF24L01_INO) + {PROTO_SGF22, STR_SGF22, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_NRF, SGF22_init, SGF22_callback }, + #endif #if defined(SHENQI_NRF24L01_INO) {PROTO_SHENQI, STR_SHENQI, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_NRF, SHENQI_init, SHENQI_callback }, #endif diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 9726000..47c6b8e 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 3 -#define VERSION_PATCH_LEVEL 47 +#define VERSION_PATCH_LEVEL 48 #define MODE_SERIAL 0 @@ -124,6 +124,7 @@ enum PROTOCOLS PROTO_SCORPIO = 94, // =>CYRF6936 PROTO_BLUEFLY = 95, // =>CC2500 & NRF24L01 PROTO_BUMBLEB = 96, // =>CC2500 & NRF24L01 + PROTO_SGF22 = 97, // =>NRF24L01 PROTO_NANORF = 126, // =>NRF24L01 diff --git a/Multiprotocol/SGF22_nrf24l01.ino b/Multiprotocol/SGF22_nrf24l01.ino new file mode 100644 index 0000000..b1f92a9 --- /dev/null +++ b/Multiprotocol/SGF22_nrf24l01.ino @@ -0,0 +1,132 @@ +/* + This project is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + +Multiprotocol is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Multiprotocol. If not, see . + */ +// Compatible with SGF22 R11 + +#if defined(SGF22_NRF24L01_INO) + +#include "iface_xn297.h" + +#define FORCE_SGF22_ORIGINAL_ID + +#define SGF22_PACKET_PERIOD 11950 //10240 +#define SGF22_BIND_RF_CHANNEL 78 +#define SGF22_PAYLOAD_SIZE 12 +#define SGF22_BIND_COUNT 50 +#define SGF22_RF_NUM_CHANNELS 4 + +static void __attribute__((unused)) SGF22_send_packet() +{ + if(IS_BIND_IN_PROGRESS) + { + packet[0] = 0x5B; + packet[8] = 0x00; // ??? do they have to be 0 for bind to succeed ? + packet[9] = 0x00; // ??? do they have to be 0 for bind to succeed ? + packet[10] = 0xAA; + packet[11] = 0x55; + } + else + { + //hop + XN297_Hopping(packet_sent & 0x03); // ??? from the dumps I can't really say how hop and seq are sync, there could be an offset (0,1,2,3)... + if( (packet_sent & 0x03) == 0x02) + packet_count = packet_sent; + packet_sent++; + if(packet_sent > 0x7B) + packet_sent = 0; + //packet + packet[0] = 0x1B; + packet[8] = 0x04 | GET_FLAG(CH6_SW, 0x08); // roll + if(Channel_data[CH5] > CHANNEL_MIN_COMMAND) + packet[8] |= 0x40; // mode 1 - 6g + if(Channel_data[CH5] > CHANNEL_MAX_COMMAND) + packet[8] |= 0x80; // mode 0 - vertical + packet[9] = GET_FLAG(CH7_SW, 0x40); // light + packet[10] = 0x42; // no fine tune + packet[11] = 0x10; // no fine tune + } + packet[1] = packet_count; // sequence + packet[2] = rx_tx_addr[2]; + packet[3] = rx_tx_addr[3]; + packet[4] = convert_channel_8b(THROTTLE); + packet[5] = convert_channel_8b(RUDDER); + packet[6] = convert_channel_8b(ELEVATOR); + packet[7] = convert_channel_8b(AILERON); + + XN297_SetPower(); + XN297_SetTxRxMode(TX_EN); + XN297_WriteEnhancedPayload(packet, SGF22_PAYLOAD_SIZE,0); + #if 0 + debug_time(""); + for(uint8_t i=0; i21=0x15,52=0x34,36=0x24,68=0x44 + #endif +} + +static void __attribute__((unused)) SGF22_RF_init() +{ + XN297_Configure(XN297_CRCEN, XN297_SCRAMBLED, XN297_1M); + XN297_SetTXAddr((uint8_t*)"\xC7\x95\x3C\xBB\xA5", 5); + XN297_RFChannel(SGF22_BIND_RF_CHANNEL); // Set bind channel +} + +uint16_t SGF22_callback() +{ + if(phase == 0) + { + phase++; + #ifdef MULTI_SYNC + telemetry_set_input_sync(SGF22_PACKET_PERIOD); + #endif + SGF22_send_packet(); + if(IS_BIND_IN_PROGRESS) + { + if(--bind_counter==0) + BIND_DONE; + } + } + else + {//send 3 times in total the same packet + NRF24L01_Strobe(REUSE_TX_PL); + phase++; + if(phase > 2) + { + phase = 0; + return SGF22_PACKET_PERIOD - 2*1550; + } + } + return 1550; +} + +void SGF22_init() +{ + BIND_IN_PROGRESS; // autobind protocol + SGF22_initialize_txid(); + SGF22_RF_init(); + bind_counter=SGF22_BIND_COUNT; + packet_sent = packet_count = 0x26; + phase = 0; +} + +#endif diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 986d6c7..a88b650 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -245,6 +245,7 @@ #define POTENSIC_NRF24L01_INO #define PROPEL_NRF24L01_INO #define REALACC_NRF24L01_INO +#define SGF22_NRF24L01_INO #define SHENQI_NRF24L01_INO #define SYMAX_NRF24L01_INO #define TIGER_NRF24L01_INO