[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / io / smartaudio_protocol.h
blobccdc974feb710509204f863d5864fcbe6f3e0123
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "drivers/serial.h"
25 #define SMARTAUDIO_SERIAL_OPTIONS SERIAL_NOT_INVERTED | SERIAL_BIDIR_NOPULL | SERIAL_STOPBITS_2
26 #define SMARTAUDIO_DEFAULT_BAUD 4900
27 #define SMARTAUDIO_MIN_BAUD 4800
28 #define SMARTAUDIO_MAX_BAUD 4950
30 typedef struct smartaudioSettings_s {
31 uint8_t version;
32 uint8_t unlocked;
33 uint8_t channel;
34 uint8_t power;
35 uint16_t frequency;
36 uint16_t pitmodeFrequency;
37 bool userFrequencyMode;
38 bool pitmodeEnabled;
39 bool pitmodeInRangeActive;
40 bool pitmodeOutRangeActive;
41 } smartaudioSettings_t;
43 typedef struct smartaudioFrameHeader_s {
44 uint16_t startCode;
45 uint8_t length;
46 uint8_t command;
47 } __attribute__((packed)) smartaudioFrameHeader_t;
49 typedef struct smartaudioCommandOnlyFrame_s {
50 smartaudioFrameHeader_t header;
51 uint8_t crc;
52 } __attribute__((packed)) smartaudioCommandOnlyFrame_t;
54 typedef struct smartaudioU8Frame_s {
55 smartaudioFrameHeader_t header;
56 uint8_t payload;
57 uint8_t crc;
58 } __attribute__((packed)) smartaudioU8Frame_t;
60 typedef struct smartaudioU16Frame_s {
61 smartaudioFrameHeader_t header;
62 uint16_t payload;
63 uint8_t crc;
64 } __attribute__((packed)) smartaudioU16Frame_t;
66 typedef struct smartaudioU8ResponseFrame_s {
67 smartaudioFrameHeader_t header;
68 uint8_t payload;
69 uint8_t reserved;
70 uint8_t crc;
71 } __attribute__((packed)) smartaudioU8ResponseFrame_t;
73 typedef struct smartaudioU16ResponseFrame_s {
74 smartaudioFrameHeader_t header;
75 uint16_t payload;
76 uint8_t reserved;
77 uint8_t crc;
78 } __attribute__((packed)) smartaudioU16ResponseFrame_t;
80 typedef struct smartaudioSettingsResponseFrame_s {
81 smartaudioFrameHeader_t header;
82 uint8_t channel;
83 uint8_t power;
84 uint8_t operationMode;
85 uint16_t frequency;
86 uint8_t crc;
87 } __attribute__((packed)) smartaudioSettingsResponseFrame_t;
89 typedef union smartaudioFrame_u {
90 smartaudioCommandOnlyFrame_t commandOnlyFrame;
91 smartaudioU8Frame_t u8RequestFrame;
92 smartaudioU16Frame_t u16RequestFrame;
93 } __attribute__((packed)) smartaudioFrame_t;
95 size_t smartaudioFrameGetSettings(smartaudioFrame_t *smartaudioFrame);
96 size_t smartaudioFrameGetPitmodeFrequency(smartaudioFrame_t *smartaudioFrame);
97 size_t smartaudioFrameSetPower(smartaudioFrame_t *smartaudioFrame, const uint8_t power);
98 size_t smartaudioFrameSetBandChannel(smartaudioFrame_t *smartaudioFrame, const uint8_t band, const uint8_t channel);
99 size_t smartaudioFrameSetFrequency(smartaudioFrame_t *smartaudioFrame, const uint16_t frequency, const bool pitmodeFrequency);
100 size_t smartaudioFrameSetOperationMode(smartaudioFrame_t *smartaudioFrame, const smartaudioSettings_t *settings);
101 bool smartaudioParseResponseBuffer(smartaudioSettings_t *settings, const uint8_t *buffer);