Merge pull request #9527 from mikeller/add_missing_acc_calibration_to_status
[betaflight.git] / src / main / msp / msp.h
blobcc19c8767d422c5a5f9e0eb4dab67c304451b54b
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;
51 int16_t cmd;
52 uint8_t flags;
53 int16_t result;
54 uint8_t direction;
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);
65 void mspInit(void);
66 mspResult_e mspFcProcessCommand(mspDescriptor_t srcDesc, mspPacket_t *cmd, mspPacket_t *reply, mspPostProcessFnPtr *mspPostProcessFn);
67 void mspFcProcessReply(mspPacket_t *reply);
69 mspDescriptor_t mspDescriptorAlloc(void);