5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef OPENTX_MULTI_H
22 #define OPENTX_MULTI_H
24 #define MULTI_BUFFER_SIZE 177
25 extern uint8_t * Multi_Buffer
;
28 Multiprotocol telemetry definition
30 Serial: 100000 Baud 8e2 (same as input)
32 TLV Protocol (type, length, value), allows a TX to ignore unknown messages
34 Format: header (4 byte) + data (variable)
40 The first byte is deliberatly chosen to be different from other telemetry protocols
41 (e.g. 0xAA for DSM/Multi, 0xAA for FlySky and 0x7e for Frsky) to allow a TX to detect
42 the telemetry format of older versions
45 [3] Length (excluding the 4 header bytes)
50 Type = 0x01 Multimodule Status:
52 0x01 = Input signal detected
53 0x02 = Serial mode enabled
54 0x04 = protocol is valid
55 0x08 = module is in binding mode
60 version of multi code, should be displayed as major.minor.revision.patchlevel
62 more information can be added by specifying a longer length of the type, the TX will just ignore these bytes
65 Type 0x02 Frksy S.port telemetry
66 Type 0x03 Frsky Hub telemetry
68 *No* usual frsky byte stuffing and without start/stop byte (0x7e)
71 Type 0x04 Spektrum telemetry data
73 data[1-15] telemetry data
75 Type 0x05 DSM bind data
76 data[0-16] DSM bind data
78 technically DSM bind data is only 10 bytes but multi send 16
79 like with telemtry, check length field)
81 Type 0x06 Flysky AFHDS2 telemetry data
84 data[1-28] telemetry data
86 Type 0x0B Spectrum Scanner telemetry data
88 data[0] = start channel (2400 + x*0.333 Mhz)
89 data[1-5] power levels
93 void processMultiTelemetryData(uint8_t data
, uint8_t module
);
95 #define MULTI_SCANNER_MAX_CHANNEL 249
97 // This should be put into the Module definition if other modules gain this functionality
98 struct MultiModuleSyncStatus
{
99 uint32_t adjustedRefreshRate
= 9000 * 1000; // in ps
100 tmr10ms_t lastUpdate
;
101 uint16_t refreshRate
;
106 inline bool isValid() const
108 return (get_tmr10ms() - lastUpdate
< 100);
111 void getRefreshString(char * refreshText
);
112 const uint16_t getAdjustedRefreshRate();
113 void calcAdjustedRefreshRate(uint16_t newRefreshRate
, uint16_t newInputLag
);
116 MultiModuleSyncStatus
& getMultiSyncStatus(uint8_t module
);
119 struct MultiModuleStatus
{
128 uint8_t requiresFailsafeCheck
;
129 tmr10ms_t lastUpdate
;
131 uint8_t protocolPrev
= 0;
132 uint8_t protocolNext
= 0;
133 char protocolName
[8] = {0};
134 uint8_t protocolSubNbr
= 0;
135 char protocolSubName
[9] = {0};
136 uint8_t optionDisp
= 0;
138 void getStatusString(char * statusText
) const;
140 inline bool isValid() const { return (bool)(get_tmr10ms() - lastUpdate
< 200); }
141 inline bool isBufferFull() const { return (bool) (flags
& 0x80); }
142 inline bool supportsDisableMapping() const { return (bool) (flags
& 0x40); }
143 inline bool supportsFailsafe() const { return (bool) (flags
& 0x20); }
144 inline bool isWaitingforBind() const { return (bool) (flags
& 0x10); }
145 inline bool isBinding() const { return (bool) (flags
& 0x08); }
146 inline bool protocolValid() const { return (bool) (flags
& 0x04); }
147 inline bool serialMode() const { return (bool) (flags
& 0x02); }
148 inline bool inputDetected() const { return (bool) (flags
& 0x01); }
151 MultiModuleStatus
& getMultiModuleStatus(uint8_t module
);
153 enum MultiBindStatus
: uint8_t {
154 MULTI_NORMAL_OPERATION
,
155 MULTI_BIND_INITIATED
,
159 uint8_t getMultiBindStatus(uint8_t module
);
160 void setMultiBindStatus(uint8_t module
, uint8_t bindStatus
);
162 #endif //OPENTX_MULTI_H