From f56c9deb00a5b1f658fffd5dd38f1628df8f1de3 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 19 Dec 2016 17:33:30 +0100 Subject: [PATCH] MULTI_TELEMETRY: couple of additions --- Multiprotocol/Multiprotocol.h | 9 +- Multiprotocol/Multiprotocol.ino | 23 +++-- Multiprotocol/Telemetry.ino | 175 ++++++++++++++++---------------- Multiprotocol/Validate.h | 5 +- Multiprotocol/_Config.h | 6 +- 5 files changed, 118 insertions(+), 100 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 741f0c6..5354123 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -13,6 +13,13 @@ along with Multiprotocol. If not, see . */ +//****************** +// Version +//****************** +#define VERSION_MAJOR 1 +#define VERSION_MINOR 16 +#define VERSION_PATCH_LEVEL 1 + //****************** // Protocols //****************** @@ -565,7 +572,7 @@ Type = 0x01 Multimodule Status: 0x04 = protocol is valid 0x08 = module is in binding mode [5] major - [6] mior + [6] minor [7-8] patchlevel version of multi code, should be displayed as major.minor.patchlevel diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 75c435d..2a051aa 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -491,7 +491,7 @@ void Update_All() update_channels_aux(); #if defined(TELEMETRY) #if !defined(MULTI_TELEMETRY) - if((protocol==MODE_FRSKYD) || (protocol==MODE_BAYANG) || (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) ) #endif TelemetryUpdate(); #endif @@ -1004,12 +1004,21 @@ void Mprotocol_serial_init() #if defined(TELEMETRY) void PPM_Telemetry_serial_init() { - if( (protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_BAYANG) ) - initTXSerial( SPEED_9600 ) ; - if(protocol==MODE_FRSKYX) - initTXSerial( SPEED_57600 ) ; - if(protocol==MODE_DSM) - initTXSerial( SPEED_125K ) ; + #ifdef MULTI_TELEMETRY + Mprotocol_serial_init(); + #ifndef ORANGE_TX + #ifndef STM32_BOARD + UCSR0B &= ~(_BV(RXEN0)|_BV(RXCIE0));//rx disable and interrupt + #endif + #endif + #else + if( (protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_BAYANG) ) + initTXSerial( SPEED_9600 ) ; + if(protocol==MODE_FRSKYX) + initTXSerial( SPEED_57600 ) ; + if(protocol==MODE_DSM) + initTXSerial( SPEED_125K ) ; + #endif } #endif diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino index 2abf2a7..3ceb65d 100644 --- a/Multiprotocol/Telemetry.ino +++ b/Multiprotocol/Telemetry.ino @@ -78,8 +78,8 @@ static void multi_send_status() multi_send_header(MULTI_TELEMETRY_STATUS, 5); // Build flags - uint8_t flags; - if (millis()-last_signal<70) + uint8_t flags=0; + if (IS_INPUT_SIGNAL_on) flags |= 0x01; if (mode_select==MODE_SERIAL) flags |= 0x02; @@ -89,50 +89,50 @@ static void multi_send_status() flags |= 0x08; Serial_write(flags); - // Version number: 1.15.0 - Serial_write(1); - Serial_write(15); - Serial_write(0); + // Version number example: 1.16.1 + Serial_write(VERSION_MAJOR); + Serial_write(VERSION_MINOR); + Serial_write(VERSION_PATCH_LEVEL); Serial_write(0); } #endif #ifdef DSM_TELEMETRY -#if defined MULTI_TELEMETRY -void DSM_frame() -{ - if (pkt[0] == 0x80) { - multi_send_header(MULTI_TELEMETRY_DSMBIND, 10); - for (uint8_t i = 1; i < 11; i++) // 10 byte of DSM bind response - Serial_write(pkt[i]); + #ifdef MULTI_TELEMETRY + void DSM_frame() + { + if (pkt[0] == 0x80) { + multi_send_header(MULTI_TELEMETRY_DSMBIND, 10); + for (uint8_t i = 1; i < 11; i++) // 10 byte of DSM bind response + Serial_write(pkt[i]); - } else { - multi_send_header(MULTI_TELEMETRY_DSM, 17); - for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data - Serial_write(pkt[i]); - } -} -#else -void DSM_frame() -{ - Serial_write(0xAA); // Telemetry packet - for (uint8_t i = 0; i < 17; i++) // RSSI value followed by 16 bytes of telemetry data - Serial_write(pkt[i]); -} -#endif + } else { + multi_send_header(MULTI_TELEMETRY_DSM, 17); + for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data + Serial_write(pkt[i]); + } + } + #else + void DSM_frame() + { + Serial_write(0xAA); // Telemetry packet + for (uint8_t i = 0; i < 17; i++) // RSSI value followed by 16 bytes of telemetry data + Serial_write(pkt[i]); + } + #endif #endif #ifdef AFHDS2A_FW_TELEMETRY -void AFHDSA_short_frame() -{ -#if defined MULTI_TELEMETRY - multi_send_header(MULTI_TELEMETRY_AFHDS2A, 29); -#else - Serial_write(0xAA); // Telemetry packet -#endif - for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data - Serial_write(pkt[i]); -} + void AFHDSA_short_frame() + { + #if defined MULTI_TELEMETRY + multi_send_header(MULTI_TELEMETRY_AFHDS2A, 29); + #else + Serial_write(0xAA); // Telemetry packet + #endif + for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data + Serial_write(pkt[i]); + } #endif void frskySendStuffed() @@ -222,11 +222,11 @@ void frsky_link_frame() frame[4] = TX_RSSI; } frame[5] = frame[6] = frame[7] = frame[8] = 0; -#if defined MULTI_TELEMETRY - multi_send_frskyhub(); -#else - frskySendStuffed(); -#endif + #if defined MULTI_TELEMETRY + multi_send_frskyhub(); + #else + frskySendStuffed(); + #endif } #if defined HUB_TELEMETRY @@ -292,11 +292,11 @@ void frsky_user_frame() if(!indx) return; frame[1] = indx; -#if defined MULTI_TELEMETRY - multi_send_frskyhub(); -#else - frskySendStuffed(); -#endif + #if defined MULTI_TELEMETRY + multi_send_frskyhub(); + #else + frskySendStuffed(); + #endif } else pass=0; @@ -368,60 +368,59 @@ pkt[6]|(counter++)|00 01 02 03 04 05 06 07 08 09 */ #ifdef MULTI_TELEMETRY -void sportSend(uint8_t *p) -{ - multi_send_header(MULTI_TELEMETRY_SPORT, 9); - uint16_t crc_s = 0; - Serial_write(p[0]) ; - for (uint8_t i = 1; i < 9; i++) + void sportSend(uint8_t *p) { - if (i == 8) - p[i] = 0xff - crc_s; - Serial_write(p[i]); - - if (i>0) + multi_send_header(MULTI_TELEMETRY_SPORT, 9); + uint16_t crc_s = 0; + Serial_write(p[0]) ; + for (uint8_t i = 1; i < 9; i++) { - crc_s += p[i]; //0-1FF - crc_s += crc_s >> 8; //0-100 - crc_s &= 0x00ff; + if (i == 8) + p[i] = 0xff - crc_s; + Serial_write(p[i]); + + if (i>0) + { + crc_s += p[i]; //0-1FF + crc_s += crc_s >> 8; //0-100 + crc_s &= 0x00ff; + } } } -} - #else -void sportSend(uint8_t *p) -{ - uint16_t crc_s = 0; - Serial_write(START_STOP);//+9 - Serial_write(p[0]) ; - for (uint8_t i = 1; i < 9; i++) + void sportSend(uint8_t *p) { - if (i == 8) - p[i] = 0xff - crc_s; - - if ((p[i] == START_STOP) || (p[i] == BYTESTUFF)) + uint16_t crc_s = 0; + Serial_write(START_STOP);//+9 + Serial_write(p[0]) ; + for (uint8_t i = 1; i < 9; i++) { - Serial_write(BYTESTUFF);//stuff again - Serial_write(STUFF_MASK ^ p[i]); - } - else - Serial_write(p[i]); - - if (i>0) - { - crc_s += p[i]; //0-1FF - crc_s += crc_s >> 8; //0-100 - crc_s &= 0x00ff; + if (i == 8) + p[i] = 0xff - crc_s; + + if ((p[i] == START_STOP) || (p[i] == BYTESTUFF)) + { + Serial_write(BYTESTUFF);//stuff again + Serial_write(STUFF_MASK ^ p[i]); + } + else + Serial_write(p[i]); + + if (i>0) + { + crc_s += p[i]; //0-1FF + crc_s += crc_s >> 8; //0-100 + crc_s &= 0x00ff; + } } } -} #endif void sportIdle() { -#if !defined MULTI_TELEMETRY - Serial_write(START_STOP); -#endif + #if !defined MULTI_TELEMETRY + Serial_write(START_STOP); + #endif } void sportSendFrame() diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index 3402a0a..6fbd9e3 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -74,8 +74,9 @@ #undef BAYANG_HUB_TELEMETRY #undef HUBSAN_HUB_TELEMETRY #undef HUB_TELEMETRY - #undef SPORT_TELEMETRY - #undef DSM_TELEMETRY + #undef SPORT_TELEMETRY + #undef DSM_TELEMETRY + #undef MULTI_TELEMETRY #else #if not defined(BAYANG_NRF24L01_INO) #undef BAYANG_HUB_TELEMETRY diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 6a55657..d40966c 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -89,7 +89,6 @@ #define SYMAX_NRF24L01_INO #define V2X2_NRF24L01_INO #define YD717_NRF24L01_INO - #define MT99XX_NRF24L01_INO #define MJXQ_NRF24L01_INO #define SHENQI_NRF24L01_INO @@ -111,6 +110,10 @@ //For ER9X and ERSKY9X it must be commented. For OpenTX it must be uncommented. //#define INVERT_TELEMETRY +//Uncomment to send also Multi status and wrap other telemetry to allow TX to autodetect the format +//Only for newest OpenTX version +//#define MULTI_TELEMETRY + //Comment a line to disable a protocol 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 @@ -119,7 +122,6 @@ #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 -#define MULTI_TELEMETRY // Send also Multi status and wrap other telemetry to allow TX to autodetect the format /****************************/ /*** SERIAL MODE SETTINGS ***/