msp_protocol.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. msp_protocol.h imported from betaflight for use in ArduPilot
  3. Many thanks to tbe Cleanflight and Betaflight developers for a great
  4. reference implementation of this protocol
  5. */
  6. /*
  7. * This file is part of Cleanflight.
  8. *
  9. * Cleanflight is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * Cleanflight is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * MSP Guidelines, emphasis is used to clarify.
  24. *
  25. * Each FlightController (FC, Server) MUST change the API version when any MSP command is added, deleted, or changed.
  26. *
  27. * If you fork the FC source code and release your own version, you MUST change the Flight Controller Identifier.
  28. *
  29. * NEVER release a modified copy of this code that shares the same Flight controller IDENT and API version
  30. * if the API doesn't match EXACTLY.
  31. *
  32. * Consumers of the API (API clients) SHOULD first attempt to get a response from the MSP_API_VERSION command.
  33. * If no response is obtained then client MAY try the legacy MSP_IDENT command.
  34. *
  35. * API consumers should ALWAYS handle communication failures gracefully and attempt to continue
  36. * without the information if possible. Clients MAY log/display a suitable message.
  37. *
  38. * API clients should NOT attempt any communication if they can't handle the returned API MAJOR VERSION.
  39. *
  40. * API clients SHOULD attempt communication if the API MINOR VERSION has increased from the time
  41. * the API client was written and handle command failures gracefully. Clients MAY disable
  42. * functionality that depends on the commands while still leaving other functionality intact.
  43. * that the newer API version may cause problems before using API commands that change FC state.
  44. *
  45. * It is for this reason that each MSP command should be specific as possible, such that changes
  46. * to commands break as little functionality as possible.
  47. *
  48. * API client authors MAY use a compatibility matrix/table when determining if they can support
  49. * a given command from a given flight controller at a given api version level.
  50. *
  51. * Developers MUST NOT create new MSP commands that do more than one thing.
  52. *
  53. * Failure to follow these guidelines will likely invoke the wrath of developers trying to write tools
  54. * that use the API and the users of those tools.
  55. */
  56. #pragma once
  57. /* Protocol numbers used both by the wire format, config system, and
  58. field setters.
  59. */
  60. #define MSP_PROTOCOL_VERSION 0
  61. #define API_VERSION_MAJOR 1 // increment when major changes are made
  62. #define API_VERSION_MINOR 37 // increment after a release, to set the version for all changes to go into the following release (if no changes to MSP are made between the releases, this can be reverted before the release)
  63. #define API_VERSION_LENGTH 2
  64. #define MULTIWII_IDENTIFIER "MWII";
  65. #define BASEFLIGHT_IDENTIFIER "BAFL";
  66. #define BETAFLIGHT_IDENTIFIER "BTFL"
  67. #define CLEANFLIGHT_IDENTIFIER "CLFL"
  68. #define INAV_IDENTIFIER "INAV"
  69. #define RACEFLIGHT_IDENTIFIER "RCFL"
  70. #define ARDUPILOT_IDENTIFIER "ARDU"
  71. #define FLIGHT_CONTROLLER_IDENTIFIER_LENGTH 4
  72. #define FLIGHT_CONTROLLER_VERSION_LENGTH 3
  73. #define FLIGHT_CONTROLLER_VERSION_MASK 0xFFF
  74. #define BOARD_IDENTIFIER_LENGTH 4 // 4 UPPER CASE alpha numeric characters that identify the board being used.
  75. #define BOARD_HARDWARE_REVISION_LENGTH 2
  76. // These are baseflight specific flags but they are useless now since MW 2.3 uses the upper 4 bits for the navigation version.
  77. #define CAP_PLATFORM_32BIT ((uint32_t)1 << 31)
  78. #define CAP_BASEFLIGHT_CONFIG ((uint32_t)1 << 30)
  79. // MW 2.3 stores NAVI_VERSION in the top 4 bits of the capability mask.
  80. #define CAP_NAVI_VERSION_BIT_4_MSB ((uint32_t)1 << 31)
  81. #define CAP_NAVI_VERSION_BIT_3 ((uint32_t)1 << 30)
  82. #define CAP_NAVI_VERSION_BIT_2 ((uint32_t)1 << 29)
  83. #define CAP_NAVI_VERSION_BIT_1_LSB ((uint32_t)1 << 28)
  84. #define CAP_DYNBALANCE ((uint32_t)1 << 2)
  85. #define CAP_FLAPS ((uint32_t)1 << 3)
  86. #define CAP_NAVCAP ((uint32_t)1 << 4)
  87. #define CAP_EXTAUX ((uint32_t)1 << 5)
  88. #define MSP_API_VERSION 1 //out message
  89. #define MSP_FC_VARIANT 2 //out message
  90. #define MSP_FC_VERSION 3 //out message
  91. #define MSP_BOARD_INFO 4 //out message
  92. #define MSP_BUILD_INFO 5 //out message
  93. #define MSP_NAME 10 //out message Returns user set board name - betaflight
  94. #define MSP_SET_NAME 11 //in message Sets board name - betaflight
  95. //
  96. // MSP commands for Cleanflight original features
  97. //
  98. #define MSP_BATTERY_CONFIG 32
  99. #define MSP_SET_BATTERY_CONFIG 33
  100. #define MSP_MODE_RANGES 34 //out message Returns all mode ranges
  101. #define MSP_SET_MODE_RANGE 35 //in message Sets a single mode range
  102. #define MSP_FEATURE_CONFIG 36
  103. #define MSP_SET_FEATURE_CONFIG 37
  104. #define MSP_BOARD_ALIGNMENT_CONFIG 38
  105. #define MSP_SET_BOARD_ALIGNMENT_CONFIG 39
  106. #define MSP_CURRENT_METER_CONFIG 40
  107. #define MSP_SET_CURRENT_METER_CONFIG 41
  108. #define MSP_MIXER_CONFIG 42
  109. #define MSP_SET_MIXER_CONFIG 43
  110. #define MSP_RX_CONFIG 44
  111. #define MSP_SET_RX_CONFIG 45
  112. #define MSP_LED_COLORS 46
  113. #define MSP_SET_LED_COLORS 47
  114. #define MSP_LED_STRIP_CONFIG 48
  115. #define MSP_SET_LED_STRIP_CONFIG 49
  116. #define MSP_RSSI_CONFIG 50
  117. #define MSP_SET_RSSI_CONFIG 51
  118. #define MSP_ADJUSTMENT_RANGES 52
  119. #define MSP_SET_ADJUSTMENT_RANGE 53
  120. // private - only to be used by the configurator, the commands are likely to change
  121. #define MSP_CF_SERIAL_CONFIG 54
  122. #define MSP_SET_CF_SERIAL_CONFIG 55
  123. #define MSP_VOLTAGE_METER_CONFIG 56
  124. #define MSP_SET_VOLTAGE_METER_CONFIG 57
  125. #define MSP_SONAR_ALTITUDE 58 //out message get sonar altitude [cm]
  126. #define MSP_PID_CONTROLLER 59
  127. #define MSP_SET_PID_CONTROLLER 60
  128. #define MSP_ARMING_CONFIG 61
  129. #define MSP_SET_ARMING_CONFIG 62
  130. //
  131. // Baseflight MSP commands (if enabled they exist in Cleanflight)
  132. //
  133. #define MSP_RX_MAP 64 //out message get channel map (also returns number of channels total)
  134. #define MSP_SET_RX_MAP 65 //in message set rx map, numchannels to set comes from MSP_RX_MAP
  135. // FIXME - Provided for backwards compatibility with configurator code until configurator is updated.
  136. // DEPRECATED - DO NOT USE "MSP_BF_CONFIG" and MSP_SET_BF_CONFIG. In Cleanflight, isolated commands already exist and should be used instead.
  137. #define MSP_BF_CONFIG 66 //out message baseflight-specific settings that aren't covered elsewhere
  138. #define MSP_SET_BF_CONFIG 67 //in message baseflight-specific settings save
  139. #define MSP_REBOOT 68 //in message reboot settings
  140. // Use MSP_BUILD_INFO instead
  141. // DEPRECATED - #define MSP_BF_BUILD_INFO 69 //out message build date as well as some space for future expansion
  142. #define MSP_DATAFLASH_SUMMARY 70 //out message - get description of dataflash chip
  143. #define MSP_DATAFLASH_READ 71 //out message - get content of dataflash chip
  144. #define MSP_DATAFLASH_ERASE 72 //in message - erase dataflash chip
  145. // No-longer needed
  146. // DEPRECATED - #define MSP_LOOP_TIME 73 //out message Returns FC cycle time i.e looptime parameter // DEPRECATED
  147. // DEPRECATED - #define MSP_SET_LOOP_TIME 74 //in message Sets FC cycle time i.e looptime parameter // DEPRECATED
  148. #define MSP_FAILSAFE_CONFIG 75 //out message Returns FC Fail-Safe settings
  149. #define MSP_SET_FAILSAFE_CONFIG 76 //in message Sets FC Fail-Safe settings
  150. #define MSP_RXFAIL_CONFIG 77 //out message Returns RXFAIL settings
  151. #define MSP_SET_RXFAIL_CONFIG 78 //in message Sets RXFAIL settings
  152. #define MSP_SDCARD_SUMMARY 79 //out message Get the state of the SD card
  153. #define MSP_BLACKBOX_CONFIG 80 //out message Get blackbox settings
  154. #define MSP_SET_BLACKBOX_CONFIG 81 //in message Set blackbox settings
  155. #define MSP_TRANSPONDER_CONFIG 82 //out message Get transponder settings
  156. #define MSP_SET_TRANSPONDER_CONFIG 83 //in message Set transponder settings
  157. #define MSP_OSD_CONFIG 84 //out message Get osd settings - betaflight
  158. #define MSP_SET_OSD_CONFIG 85 //in message Set osd settings - betaflight
  159. #define MSP_OSD_CHAR_READ 86 //out message Get osd settings - betaflight
  160. #define MSP_OSD_CHAR_WRITE 87 //in message Set osd settings - betaflight
  161. #define MSP_VTX_CONFIG 88 //out message Get vtx settings - betaflight
  162. #define MSP_SET_VTX_CONFIG 89 //in message Set vtx settings - betaflight
  163. // Betaflight Additional Commands
  164. #define MSP_ADVANCED_CONFIG 90
  165. #define MSP_SET_ADVANCED_CONFIG 91
  166. #define MSP_FILTER_CONFIG 92
  167. #define MSP_SET_FILTER_CONFIG 93
  168. #define MSP_PID_ADVANCED 94
  169. #define MSP_SET_PID_ADVANCED 95
  170. #define MSP_SENSOR_CONFIG 96
  171. #define MSP_SET_SENSOR_CONFIG 97
  172. #define MSP_CAMERA_CONTROL 98
  173. #define MSP_SET_ARMING_DISABLED 99
  174. //
  175. // OSD specific
  176. //
  177. #define MSP_OSD_VIDEO_CONFIG 180
  178. #define MSP_SET_OSD_VIDEO_CONFIG 181
  179. // External OSD displayport mode messages
  180. #define MSP_DISPLAYPORT 182
  181. #define MSP_COPY_PROFILE 183
  182. #define MSP_BEEPER_CONFIG 184
  183. #define MSP_SET_BEEPER_CONFIG 185
  184. #define MSP_SET_TX_INFO 186 // in message Used to send runtime information from TX lua scripts to the firmware
  185. #define MSP_TX_INFO 187 // out message Used by TX lua scripts to read information from the firmware
  186. //
  187. // Multwii original MSP commands
  188. //
  189. // See MSP_API_VERSION and MSP_MIXER_CONFIG
  190. //DEPRECATED - #define MSP_IDENT 100 //out message mixerMode + multiwii version + protocol version + capability variable
  191. #define MSP_STATUS 101 //out message cycletime & errors_count & sensor present & box activation & current setting number
  192. #define MSP_RAW_IMU 102 //out message 9 DOF
  193. #define MSP_SERVO 103 //out message servos
  194. #define MSP_MOTOR 104 //out message motors
  195. #define MSP_RC 105 //out message rc channels and more
  196. #define MSP_RAW_GPS 106 //out message fix, numsat, lat, lon, alt, speed, ground course
  197. #define MSP_COMP_GPS 107 //out message distance home, direction home
  198. #define MSP_ATTITUDE 108 //out message 2 angles 1 heading
  199. #define MSP_ALTITUDE 109 //out message altitude, variometer
  200. #define MSP_ANALOG 110 //out message vbat, powermetersum, rssi if available on RX
  201. #define MSP_RC_TUNING 111 //out message rc rate, rc expo, rollpitch rate, yaw rate, dyn throttle PID
  202. #define MSP_PID 112 //out message P I D coeff (9 are used currently)
  203. // Legacy Multiicommand that was never used.
  204. //DEPRECATED - #define MSP_BOX 113 //out message BOX setup (number is dependant of your setup)
  205. // Legacy command that was under constant change due to the naming vagueness, avoid at all costs - use more specific commands instead.
  206. //DEPRECATED - #define MSP_MISC 114 //out message powermeter trig
  207. // Legacy Multiicommand that was never used and always wrong
  208. //DEPRECATED - #define MSP_MOTOR_PINS 115 //out message which pins are in use for motors & servos, for GUI
  209. #define MSP_BOXNAMES 116 //out message the aux switch names
  210. #define MSP_PIDNAMES 117 //out message the PID names
  211. #define MSP_WP 118 //out message get a WP, WP# is in the payload, returns (WP#, lat, lon, alt, flags) WP#0-home, WP#16-poshold
  212. #define MSP_BOXIDS 119 //out message get the permanent IDs associated to BOXes
  213. #define MSP_SERVO_CONFIGURATIONS 120 //out message All servo configurations.
  214. #define MSP_NAV_STATUS 121 //out message Returns navigation status
  215. #define MSP_NAV_CONFIG 122 //out message Returns navigation parameters
  216. #define MSP_MOTOR_3D_CONFIG 124 //out message Settings needed for reversible ESCs
  217. #define MSP_RC_DEADBAND 125 //out message deadbands for yaw alt pitch roll
  218. #define MSP_SENSOR_ALIGNMENT 126 //out message orientation of acc,gyro,mag
  219. #define MSP_LED_STRIP_MODECOLOR 127 //out message Get LED strip mode_color settings
  220. #define MSP_VOLTAGE_METERS 128 //out message Voltage (per meter)
  221. #define MSP_CURRENT_METERS 129 //out message Amperage (per meter)
  222. #define MSP_BATTERY_STATE 130 //out message Connected/Disconnected, Voltage, Current Used
  223. #define MSP_MOTOR_CONFIG 131 //out message Motor configuration (min/max throttle, etc)
  224. #define MSP_GPS_CONFIG 132 //out message GPS configuration
  225. #define MSP_COMPASS_CONFIG 133 //out message Compass configuration
  226. #define MSP_ESC_SENSOR_DATA 134 //out message Extra ESC data from 32-Bit ESCs (Temperature, RPM)
  227. #define MSP_SET_RAW_RC 200 //in message 8 rc chan
  228. #define MSP_SET_RAW_GPS 201 //in message fix, numsat, lat, lon, alt, speed
  229. #define MSP_SET_PID 202 //in message P I D coeff (9 are used currently)
  230. // Legacy multiiwii command that was never used.
  231. //DEPRECATED - #define MSP_SET_BOX 203 //in message BOX setup (number is dependant of your setup)
  232. #define MSP_SET_RC_TUNING 204 //in message rc rate, rc expo, rollpitch rate, yaw rate, dyn throttle PID, yaw expo
  233. #define MSP_ACC_CALIBRATION 205 //in message no param
  234. #define MSP_MAG_CALIBRATION 206 //in message no param
  235. // Legacy command that was under constant change due to the naming vagueness, avoid at all costs - use more specific commands instead.
  236. //DEPRECATED - #define MSP_SET_MISC 207 //in message powermeter trig + 8 free for future use
  237. #define MSP_RESET_CONF 208 //in message no param
  238. #define MSP_SET_WP 209 //in message sets a given WP (WP#,lat, lon, alt, flags)
  239. #define MSP_SELECT_SETTING 210 //in message Select Setting Number (0-2)
  240. #define MSP_SET_HEADING 211 //in message define a new heading hold direction
  241. #define MSP_SET_SERVO_CONFIGURATION 212 //in message Servo settings
  242. #define MSP_SET_MOTOR 214 //in message PropBalance function
  243. #define MSP_SET_NAV_CONFIG 215 //in message Sets nav config parameters - write to the eeprom
  244. #define MSP_SET_MOTOR_3D_CONFIG 217 //in message Settings needed for reversible ESCs
  245. #define MSP_SET_RC_DEADBAND 218 //in message deadbands for yaw alt pitch roll
  246. #define MSP_SET_RESET_CURR_PID 219 //in message resetting the current pid profile to defaults
  247. #define MSP_SET_SENSOR_ALIGNMENT 220 //in message set the orientation of the acc,gyro,mag
  248. #define MSP_SET_LED_STRIP_MODECOLOR 221 //in message Set LED strip mode_color settings
  249. #define MSP_SET_MOTOR_CONFIG 222 //out message Motor configuration (min/max throttle, etc)
  250. #define MSP_SET_GPS_CONFIG 223 //out message GPS configuration
  251. #define MSP_SET_COMPASS_CONFIG 224 //out message Compass configuration
  252. // #define MSP_BIND 240 //in message no param
  253. // #define MSP_ALARMS 242
  254. #define MSP_EEPROM_WRITE 250 //in message no param
  255. #define MSP_RESERVE_1 251 //reserved for system usage
  256. #define MSP_RESERVE_2 252 //reserved for system usage
  257. #define MSP_DEBUGMSG 253 //out message debug string buffer
  258. #define MSP_DEBUG 254 //out message debug1,debug2,debug3,debug4
  259. #define MSP_RESERVE_3 255 //reserved for system usage
  260. // Additional commands that are not compatible with MultiWii
  261. #define MSP_STATUS_EX 150 //out message cycletime, errors_count, CPU load, sensor present etc
  262. #define MSP_UID 160 //out message Unique device ID
  263. #define MSP_GPSSVINFO 164 //out message get Signal Strength (only U-Blox)
  264. #define MSP_GPSSTATISTICS 166 //out message get GPS debugging data
  265. #define MSP_ACC_TRIM 240 //out message get acc angle trim values
  266. #define MSP_SET_ACC_TRIM 239 //in message set acc angle trim values
  267. #define MSP_SERVO_MIX_RULES 241 //out message Returns servo mixer configuration
  268. #define MSP_SET_SERVO_MIX_RULE 242 //in message Sets servo mixer configuration
  269. #define MSP_SET_4WAY_IF 245 //in message Sets 4way interface
  270. #define MSP_SET_RTC 246 //in message Sets the RTC clock
  271. #define MSP_RTC 247 //out message Gets the RTC clock