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;
54 protocolDetectionTimer
= millis();
58 //set default protocol
59 for(uint8_t i
=0; i
< sizeof(protocols
) / sizeof(uint8_t); i
++){
60 if(protocols
[i
] == default_protocol
){
67 void disableProtocolDetection(void){
68 detectionIsEnabled
= false;
72 bool isProtocolDetectionEnabled(void){
73 return detectionIsEnabled
;
76 uint16_t getProtocol(void){
77 return protocolDetected
;
80 void protocolDetectionParser(uint8_t c
)
82 if(!detectionIsEnabled
)
85 if(millis() - protocolDetectionTimer
>= 3000){
87 if(current_protocol
>= sizeof(protocols
) / sizeof(uint8_t)) current_protocol
= 0;
88 protocolDetectionTimer
= millis();
92 switch(protocols
[current_protocol
]){
94 mfd_encodeTargetData(c
);
96 case TP_GPS_TELEMETRY
:
97 gps_encodeTargetData(c
);
100 mavlink_encodeTargetData(c
);
103 rvosd_encodeTargetData(c
);
106 frskyd_encodeTargetData(c
);
109 frskyx_encodeTargetData(c
);
112 ltm_encodeTargetData(c
);
115 pitlab_encodeTargetData(c
);
118 crossfire_encodeTargetData(c
);
124 if(protocol_fixes
> 2) {
125 protocolDetected
= protocols
[current_protocol
];