2 * This file is part of u360gts, aka amv-open360tracker 32bits:
3 * https://github.com/raul-ortega/amv-open360tracker-32bits
5 * The code below is an adaptation by Ra�l Ortega of the original code of Ghettostation antenna tracker
6 * https://github.com/KipK/Ghettostation
8 * u360gts is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * u360gts is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with u360gts. If not, see <http://www.gnu.org/licenses/>.
29 #include "config/runtime_config.h"
31 static uint16_t protocolDetected
= 0;
32 uint8_t current_protocol
= 0;
33 uint32_t protocolDetectionTimer
= 0;
34 bool detectionIsEnabled
= false;
35 uint8_t protocol_fixes
= 0;
39 static const uint16_t protocols
[] = {
51 void enableProtocolDetection(uint16_t default_protocol
) {
53 detectionIsEnabled
= true;
57 //set default protocol
58 for(uint8_t i
=0; i
< sizeof(protocols
) / sizeof(uint8_t); i
++){
59 if(protocols
[i
] == default_protocol
){
65 protocolDetectionTimer
= 0;
68 void disableProtocolDetection(void){
69 detectionIsEnabled
= false;
73 bool isProtocolDetectionEnabled(void){
74 return detectionIsEnabled
;
77 uint16_t getProtocol(void){
78 return protocolDetected
;
81 void protocolDetectionParser(uint8_t c
)
84 if(protocolDetectionTimer
== 0)
85 protocolDetectionTimer
= millis();
87 if(millis() - protocolDetectionTimer
>= 3000){
89 if(current_protocol
>= sizeof(protocols
) / sizeof(uint16_t)) current_protocol
= 0;
90 protocolDetectionTimer
= millis();
94 switch(protocols
[current_protocol
]){
96 mfd_encodeTargetData(c
);
98 case TP_GPS_TELEMETRY
:
99 gps_encodeTargetData(c
);
102 mavlink_encodeTargetData(c
);
105 rvosd_encodeTargetData(c
);
108 frskyd_encodeTargetData(c
);
111 frskyx_encodeTargetData(c
);
114 ltm_encodeTargetData(c
);
117 pitlab_encodeTargetData(c
);
120 crossfire_encodeTargetData(c
);
126 if(protocol_fixes
> 1) {
127 protocolDetected
= protocols
[current_protocol
];