Add RANGEFINDER and OPTICALFLOW MT build option (#14042)
[betaflight.git] / src / main / msp / msp.h
blob7392e02052b49e56239b68531b7c47a708ce0889
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 "common/streambuf.h"
25 #define MSP_V2_FRAME_ID 255
27 typedef enum {
28 MSP_V1 = 0,
29 MSP_V2_OVER_V1 = 1,
30 MSP_V2_NATIVE = 2,
31 MSP_VERSION_COUNT
32 } mspVersion_e;
34 #define MSP_VERSION_MAGIC_INITIALIZER { 'M', 'M', 'X' }
36 // return positive for ACK, negative on error, zero for no reply
37 typedef enum {
38 MSP_RESULT_ACK = 1,
39 MSP_RESULT_ERROR = -1,
40 MSP_RESULT_NO_REPLY = 0,
41 MSP_RESULT_CMD_UNKNOWN = -2, // don't know how to process command, try next handler
42 } mspResult_e;
44 typedef enum {
45 MSP_DIRECTION_REPLY = 0,
46 MSP_DIRECTION_REQUEST = 1
47 } mspDirection_e;
49 typedef struct mspPacket_s {
50 sbuf_t buf; // payload only w/o header or crc
51 int16_t cmd;
52 int16_t result;
53 uint8_t flags; // MSPv2 flags byte. It looks like unused (yet?).
54 uint8_t direction; // It also looks like unused and might be deleted.
55 } mspPacket_t;
57 typedef int mspDescriptor_t;
59 struct serialPort_s;
60 typedef void (*mspPostProcessFnPtr)(struct serialPort_s *port); // msp post process function, used for gracefully handling reboots, etc.
61 typedef mspResult_e (*mspProcessCommandFnPtr)(mspDescriptor_t srcDesc, mspPacket_t *cmd, mspPacket_t *reply, mspPostProcessFnPtr *mspPostProcessFn);
62 typedef void (*mspProcessReplyFnPtr)(mspPacket_t *cmd);
64 void mspInit(void);
65 mspResult_e mspFcProcessCommand(mspDescriptor_t srcDesc, mspPacket_t *cmd, mspPacket_t *reply, mspPostProcessFnPtr *mspPostProcessFn);
66 void mspFcProcessReply(mspPacket_t *reply);
68 mspDescriptor_t mspDescriptorAlloc(void);