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.
23 void processFrskyTelemetryData(uint8_t data
)
25 #if defined(PCBSKY9X) && defined(BLUETOOTH)
26 // TODO if (g_model.bt_telemetry)
30 #if defined(AUX_SERIAL)
31 if (g_eeGeneral
.auxSerialMode
== UART_MODE_TELEMETRY_MIRROR
) {
36 if (pushFrskyTelemetryData(data
)) {
37 if (IS_FRSKY_SPORT_PROTOCOL()) {
38 sportProcessTelemetryPacket(telemetryRxBuffer
);
41 frskyDProcessPacket(telemetryRxBuffer
);
46 bool pushFrskyTelemetryData(uint8_t data
)
48 static uint8_t dataState
= STATE_DATA_IDLE
;
51 case STATE_DATA_START
:
52 if (data
== START_STOP
) {
53 if (IS_FRSKY_SPORT_PROTOCOL()) {
54 dataState
= STATE_DATA_IN_FRAME
;
55 telemetryRxBufferCount
= 0;
59 if (telemetryRxBufferCount
< TELEMETRY_RX_PACKET_SIZE
) {
60 telemetryRxBuffer
[telemetryRxBufferCount
++] = data
;
62 dataState
= STATE_DATA_IN_FRAME
;
66 case STATE_DATA_IN_FRAME
:
67 if (data
== BYTE_STUFF
) {
68 dataState
= STATE_DATA_XOR
; // XOR next byte
70 else if (data
== START_STOP
) {
71 if (IS_FRSKY_SPORT_PROTOCOL()) {
72 dataState
= STATE_DATA_IN_FRAME
;
73 telemetryRxBufferCount
= 0;
76 // end of frame detected
77 dataState
= STATE_DATA_IDLE
;
82 else if (telemetryRxBufferCount
< TELEMETRY_RX_PACKET_SIZE
) {
83 telemetryRxBuffer
[telemetryRxBufferCount
++] = data
;
88 if (telemetryRxBufferCount
< TELEMETRY_RX_PACKET_SIZE
) {
89 telemetryRxBuffer
[telemetryRxBufferCount
++] = data
^ STUFF_MASK
;
91 dataState
= STATE_DATA_IN_FRAME
;
95 if (data
== START_STOP
) {
96 telemetryRxBufferCount
= 0;
97 dataState
= STATE_DATA_START
;
103 if (IS_FRSKY_SPORT_PROTOCOL() && telemetryRxBufferCount
>= FRSKY_SPORT_PACKET_SIZE
) {
104 // end of frame detected
105 dataState
= STATE_DATA_IDLE
;