mavlink_msg_vk_bms_status.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. #pragma once
  2. // MESSAGE VK_BMS_STATUS PACKING
  3. #define MAVLINK_MSG_ID_VK_BMS_STATUS 53003
  4. typedef struct __mavlink_vk_bms_status_t {
  5. uint32_t time_boot_ms; /*< [ms] Timestamp in ms from system boot.*/
  6. uint32_t voltage; /*< [mV] BMS voltage in mV*/
  7. uint32_t err_code; /*< BMS error code,
  8. 0 means no error*/
  9. int16_t current; /*< [cA] BMS current in cA, negative value means in charging*/
  10. int16_t temperature; /*< [degC] BMS temperature in degC*/
  11. uint16_t cell_num; /*< BMS cell numbers*/
  12. uint16_t cell_volt[30]; /*< [mV] BMS cell voltage in mV*/
  13. int8_t cap_percent; /*< [%] BMS remaining power in percentage*/
  14. uint8_t bat_id; /*< BMS id, start from
  15. 0*/
  16. } mavlink_vk_bms_status_t;
  17. #define MAVLINK_MSG_ID_VK_BMS_STATUS_LEN 80
  18. #define MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN 80
  19. #define MAVLINK_MSG_ID_53003_LEN 80
  20. #define MAVLINK_MSG_ID_53003_MIN_LEN 80
  21. #define MAVLINK_MSG_ID_VK_BMS_STATUS_CRC 43
  22. #define MAVLINK_MSG_ID_53003_CRC 43
  23. #define MAVLINK_MSG_VK_BMS_STATUS_FIELD_CELL_VOLT_LEN 30
  24. #if MAVLINK_COMMAND_24BIT
  25. #define MAVLINK_MESSAGE_INFO_VK_BMS_STATUS { \
  26. 53003, \
  27. "VK_BMS_STATUS", \
  28. 9, \
  29. { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_vk_bms_status_t, time_boot_ms) }, \
  30. { "voltage", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_vk_bms_status_t, voltage) }, \
  31. { "current", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_vk_bms_status_t, current) }, \
  32. { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_vk_bms_status_t, temperature) }, \
  33. { "cap_percent", NULL, MAVLINK_TYPE_INT8_T, 0, 78, offsetof(mavlink_vk_bms_status_t, cap_percent) }, \
  34. { "bat_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 79, offsetof(mavlink_vk_bms_status_t, bat_id) }, \
  35. { "err_code", "0x%04x", MAVLINK_TYPE_UINT32_T, 0, 8, offsetof(mavlink_vk_bms_status_t, err_code) }, \
  36. { "cell_num", NULL, MAVLINK_TYPE_UINT16_T, 0, 16, offsetof(mavlink_vk_bms_status_t, cell_num) }, \
  37. { "cell_volt", NULL, MAVLINK_TYPE_UINT16_T, 30, 18, offsetof(mavlink_vk_bms_status_t, cell_volt) }, \
  38. } \
  39. }
  40. #else
  41. #define MAVLINK_MESSAGE_INFO_VK_BMS_STATUS { \
  42. "VK_BMS_STATUS", \
  43. 9, \
  44. { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_vk_bms_status_t, time_boot_ms) }, \
  45. { "voltage", NULL, MAVLINK_TYPE_UINT32_T, 0, 4, offsetof(mavlink_vk_bms_status_t, voltage) }, \
  46. { "current", NULL, MAVLINK_TYPE_INT16_T, 0, 12, offsetof(mavlink_vk_bms_status_t, current) }, \
  47. { "temperature", NULL, MAVLINK_TYPE_INT16_T, 0, 14, offsetof(mavlink_vk_bms_status_t, temperature) }, \
  48. { "cap_percent", NULL, MAVLINK_TYPE_INT8_T, 0, 78, offsetof(mavlink_vk_bms_status_t, cap_percent) }, \
  49. { "bat_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 79, offsetof(mavlink_vk_bms_status_t, bat_id) }, \
  50. { "err_code", "0x%04x", MAVLINK_TYPE_UINT32_T, 0, 8, offsetof(mavlink_vk_bms_status_t, err_code) }, \
  51. { "cell_num", NULL, MAVLINK_TYPE_UINT16_T, 0, 16, offsetof(mavlink_vk_bms_status_t, cell_num) }, \
  52. { "cell_volt", NULL, MAVLINK_TYPE_UINT16_T, 30, 18, offsetof(mavlink_vk_bms_status_t, cell_volt) }, \
  53. } \
  54. }
  55. #endif
  56. /**
  57. * @brief Pack a vk_bms_status message
  58. * @param system_id ID of this system
  59. * @param component_id ID of this component (e.g. 200 for IMU)
  60. * @param msg The MAVLink message to compress the data into
  61. *
  62. * @param time_boot_ms [ms] Timestamp in ms from system boot.
  63. * @param voltage [mV] BMS voltage in mV
  64. * @param current [cA] BMS current in cA, negative value means in charging
  65. * @param temperature [degC] BMS temperature in degC
  66. * @param cap_percent [%] BMS remaining power in percentage
  67. * @param bat_id BMS id, start from
  68. 0
  69. * @param err_code BMS error code,
  70. 0 means no error
  71. * @param cell_num BMS cell numbers
  72. * @param cell_volt [mV] BMS cell voltage in mV
  73. * @return length of the message in bytes (excluding serial stream start sign)
  74. */
  75. static inline uint16_t mavlink_msg_vk_bms_status_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  76. uint32_t time_boot_ms, uint32_t voltage, int16_t current, int16_t temperature, int8_t cap_percent, uint8_t bat_id, uint32_t err_code, uint16_t cell_num, const uint16_t *cell_volt)
  77. {
  78. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  79. char buf[MAVLINK_MSG_ID_VK_BMS_STATUS_LEN];
  80. _mav_put_uint32_t(buf, 0, time_boot_ms);
  81. _mav_put_uint32_t(buf, 4, voltage);
  82. _mav_put_uint32_t(buf, 8, err_code);
  83. _mav_put_int16_t(buf, 12, current);
  84. _mav_put_int16_t(buf, 14, temperature);
  85. _mav_put_uint16_t(buf, 16, cell_num);
  86. _mav_put_int8_t(buf, 78, cap_percent);
  87. _mav_put_uint8_t(buf, 79, bat_id);
  88. _mav_put_uint16_t_array(buf, 18, cell_volt, 30);
  89. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN);
  90. #else
  91. mavlink_vk_bms_status_t packet;
  92. packet.time_boot_ms = time_boot_ms;
  93. packet.voltage = voltage;
  94. packet.err_code = err_code;
  95. packet.current = current;
  96. packet.temperature = temperature;
  97. packet.cell_num = cell_num;
  98. packet.cap_percent = cap_percent;
  99. packet.bat_id = bat_id;
  100. mav_array_memcpy(packet.cell_volt, cell_volt, sizeof(uint16_t)*30);
  101. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN);
  102. #endif
  103. msg->msgid = MAVLINK_MSG_ID_VK_BMS_STATUS;
  104. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_CRC);
  105. }
  106. /**
  107. * @brief Pack a vk_bms_status message
  108. * @param system_id ID of this system
  109. * @param component_id ID of this component (e.g. 200 for IMU)
  110. * @param status MAVLink status structure
  111. * @param msg The MAVLink message to compress the data into
  112. *
  113. * @param time_boot_ms [ms] Timestamp in ms from system boot.
  114. * @param voltage [mV] BMS voltage in mV
  115. * @param current [cA] BMS current in cA, negative value means in charging
  116. * @param temperature [degC] BMS temperature in degC
  117. * @param cap_percent [%] BMS remaining power in percentage
  118. * @param bat_id BMS id, start from
  119. 0
  120. * @param err_code BMS error code,
  121. 0 means no error
  122. * @param cell_num BMS cell numbers
  123. * @param cell_volt [mV] BMS cell voltage in mV
  124. * @return length of the message in bytes (excluding serial stream start sign)
  125. */
  126. static inline uint16_t mavlink_msg_vk_bms_status_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
  127. uint32_t time_boot_ms, uint32_t voltage, int16_t current, int16_t temperature, int8_t cap_percent, uint8_t bat_id, uint32_t err_code, uint16_t cell_num, const uint16_t *cell_volt)
  128. {
  129. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  130. char buf[MAVLINK_MSG_ID_VK_BMS_STATUS_LEN];
  131. _mav_put_uint32_t(buf, 0, time_boot_ms);
  132. _mav_put_uint32_t(buf, 4, voltage);
  133. _mav_put_uint32_t(buf, 8, err_code);
  134. _mav_put_int16_t(buf, 12, current);
  135. _mav_put_int16_t(buf, 14, temperature);
  136. _mav_put_uint16_t(buf, 16, cell_num);
  137. _mav_put_int8_t(buf, 78, cap_percent);
  138. _mav_put_uint8_t(buf, 79, bat_id);
  139. _mav_put_uint16_t_array(buf, 18, cell_volt, 30);
  140. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN);
  141. #else
  142. mavlink_vk_bms_status_t packet;
  143. packet.time_boot_ms = time_boot_ms;
  144. packet.voltage = voltage;
  145. packet.err_code = err_code;
  146. packet.current = current;
  147. packet.temperature = temperature;
  148. packet.cell_num = cell_num;
  149. packet.cap_percent = cap_percent;
  150. packet.bat_id = bat_id;
  151. mav_array_memcpy(packet.cell_volt, cell_volt, sizeof(uint16_t)*30);
  152. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN);
  153. #endif
  154. msg->msgid = MAVLINK_MSG_ID_VK_BMS_STATUS;
  155. #if MAVLINK_CRC_EXTRA
  156. return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_CRC);
  157. #else
  158. return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN);
  159. #endif
  160. }
  161. /**
  162. * @brief Pack a vk_bms_status message on a channel
  163. * @param system_id ID of this system
  164. * @param component_id ID of this component (e.g. 200 for IMU)
  165. * @param chan The MAVLink channel this message will be sent over
  166. * @param msg The MAVLink message to compress the data into
  167. * @param time_boot_ms [ms] Timestamp in ms from system boot.
  168. * @param voltage [mV] BMS voltage in mV
  169. * @param current [cA] BMS current in cA, negative value means in charging
  170. * @param temperature [degC] BMS temperature in degC
  171. * @param cap_percent [%] BMS remaining power in percentage
  172. * @param bat_id BMS id, start from
  173. 0
  174. * @param err_code BMS error code,
  175. 0 means no error
  176. * @param cell_num BMS cell numbers
  177. * @param cell_volt [mV] BMS cell voltage in mV
  178. * @return length of the message in bytes (excluding serial stream start sign)
  179. */
  180. static inline uint16_t mavlink_msg_vk_bms_status_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  181. mavlink_message_t* msg,
  182. uint32_t time_boot_ms,uint32_t voltage,int16_t current,int16_t temperature,int8_t cap_percent,uint8_t bat_id,uint32_t err_code,uint16_t cell_num,const uint16_t *cell_volt)
  183. {
  184. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  185. char buf[MAVLINK_MSG_ID_VK_BMS_STATUS_LEN];
  186. _mav_put_uint32_t(buf, 0, time_boot_ms);
  187. _mav_put_uint32_t(buf, 4, voltage);
  188. _mav_put_uint32_t(buf, 8, err_code);
  189. _mav_put_int16_t(buf, 12, current);
  190. _mav_put_int16_t(buf, 14, temperature);
  191. _mav_put_uint16_t(buf, 16, cell_num);
  192. _mav_put_int8_t(buf, 78, cap_percent);
  193. _mav_put_uint8_t(buf, 79, bat_id);
  194. _mav_put_uint16_t_array(buf, 18, cell_volt, 30);
  195. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN);
  196. #else
  197. mavlink_vk_bms_status_t packet;
  198. packet.time_boot_ms = time_boot_ms;
  199. packet.voltage = voltage;
  200. packet.err_code = err_code;
  201. packet.current = current;
  202. packet.temperature = temperature;
  203. packet.cell_num = cell_num;
  204. packet.cap_percent = cap_percent;
  205. packet.bat_id = bat_id;
  206. mav_array_memcpy(packet.cell_volt, cell_volt, sizeof(uint16_t)*30);
  207. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN);
  208. #endif
  209. msg->msgid = MAVLINK_MSG_ID_VK_BMS_STATUS;
  210. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_CRC);
  211. }
  212. /**
  213. * @brief Encode a vk_bms_status struct
  214. *
  215. * @param system_id ID of this system
  216. * @param component_id ID of this component (e.g. 200 for IMU)
  217. * @param msg The MAVLink message to compress the data into
  218. * @param vk_bms_status C-struct to read the message contents from
  219. */
  220. static inline uint16_t mavlink_msg_vk_bms_status_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_vk_bms_status_t* vk_bms_status)
  221. {
  222. return mavlink_msg_vk_bms_status_pack(system_id, component_id, msg, vk_bms_status->time_boot_ms, vk_bms_status->voltage, vk_bms_status->current, vk_bms_status->temperature, vk_bms_status->cap_percent, vk_bms_status->bat_id, vk_bms_status->err_code, vk_bms_status->cell_num, vk_bms_status->cell_volt);
  223. }
  224. /**
  225. * @brief Encode a vk_bms_status struct on a channel
  226. *
  227. * @param system_id ID of this system
  228. * @param component_id ID of this component (e.g. 200 for IMU)
  229. * @param chan The MAVLink channel this message will be sent over
  230. * @param msg The MAVLink message to compress the data into
  231. * @param vk_bms_status C-struct to read the message contents from
  232. */
  233. static inline uint16_t mavlink_msg_vk_bms_status_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_vk_bms_status_t* vk_bms_status)
  234. {
  235. return mavlink_msg_vk_bms_status_pack_chan(system_id, component_id, chan, msg, vk_bms_status->time_boot_ms, vk_bms_status->voltage, vk_bms_status->current, vk_bms_status->temperature, vk_bms_status->cap_percent, vk_bms_status->bat_id, vk_bms_status->err_code, vk_bms_status->cell_num, vk_bms_status->cell_volt);
  236. }
  237. /**
  238. * @brief Encode a vk_bms_status struct with provided status structure
  239. *
  240. * @param system_id ID of this system
  241. * @param component_id ID of this component (e.g. 200 for IMU)
  242. * @param status MAVLink status structure
  243. * @param msg The MAVLink message to compress the data into
  244. * @param vk_bms_status C-struct to read the message contents from
  245. */
  246. static inline uint16_t mavlink_msg_vk_bms_status_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_vk_bms_status_t* vk_bms_status)
  247. {
  248. return mavlink_msg_vk_bms_status_pack_status(system_id, component_id, _status, msg, vk_bms_status->time_boot_ms, vk_bms_status->voltage, vk_bms_status->current, vk_bms_status->temperature, vk_bms_status->cap_percent, vk_bms_status->bat_id, vk_bms_status->err_code, vk_bms_status->cell_num, vk_bms_status->cell_volt);
  249. }
  250. /**
  251. * @brief Send a vk_bms_status message
  252. * @param chan MAVLink channel to send the message
  253. *
  254. * @param time_boot_ms [ms] Timestamp in ms from system boot.
  255. * @param voltage [mV] BMS voltage in mV
  256. * @param current [cA] BMS current in cA, negative value means in charging
  257. * @param temperature [degC] BMS temperature in degC
  258. * @param cap_percent [%] BMS remaining power in percentage
  259. * @param bat_id BMS id, start from
  260. 0
  261. * @param err_code BMS error code,
  262. 0 means no error
  263. * @param cell_num BMS cell numbers
  264. * @param cell_volt [mV] BMS cell voltage in mV
  265. */
  266. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  267. static inline void mavlink_msg_vk_bms_status_send(mavlink_channel_t chan, uint32_t time_boot_ms, uint32_t voltage, int16_t current, int16_t temperature, int8_t cap_percent, uint8_t bat_id, uint32_t err_code, uint16_t cell_num, const uint16_t *cell_volt)
  268. {
  269. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  270. char buf[MAVLINK_MSG_ID_VK_BMS_STATUS_LEN];
  271. _mav_put_uint32_t(buf, 0, time_boot_ms);
  272. _mav_put_uint32_t(buf, 4, voltage);
  273. _mav_put_uint32_t(buf, 8, err_code);
  274. _mav_put_int16_t(buf, 12, current);
  275. _mav_put_int16_t(buf, 14, temperature);
  276. _mav_put_uint16_t(buf, 16, cell_num);
  277. _mav_put_int8_t(buf, 78, cap_percent);
  278. _mav_put_uint8_t(buf, 79, bat_id);
  279. _mav_put_uint16_t_array(buf, 18, cell_volt, 30);
  280. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VK_BMS_STATUS, buf, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_CRC);
  281. #else
  282. mavlink_vk_bms_status_t packet;
  283. packet.time_boot_ms = time_boot_ms;
  284. packet.voltage = voltage;
  285. packet.err_code = err_code;
  286. packet.current = current;
  287. packet.temperature = temperature;
  288. packet.cell_num = cell_num;
  289. packet.cap_percent = cap_percent;
  290. packet.bat_id = bat_id;
  291. mav_array_memcpy(packet.cell_volt, cell_volt, sizeof(uint16_t)*30);
  292. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VK_BMS_STATUS, (const char *)&packet, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_CRC);
  293. #endif
  294. }
  295. /**
  296. * @brief Send a vk_bms_status message
  297. * @param chan MAVLink channel to send the message
  298. * @param struct The MAVLink struct to serialize
  299. */
  300. static inline void mavlink_msg_vk_bms_status_send_struct(mavlink_channel_t chan, const mavlink_vk_bms_status_t* vk_bms_status)
  301. {
  302. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  303. mavlink_msg_vk_bms_status_send(chan, vk_bms_status->time_boot_ms, vk_bms_status->voltage, vk_bms_status->current, vk_bms_status->temperature, vk_bms_status->cap_percent, vk_bms_status->bat_id, vk_bms_status->err_code, vk_bms_status->cell_num, vk_bms_status->cell_volt);
  304. #else
  305. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VK_BMS_STATUS, (const char *)vk_bms_status, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_CRC);
  306. #endif
  307. }
  308. #if MAVLINK_MSG_ID_VK_BMS_STATUS_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  309. /*
  310. This variant of _send() can be used to save stack space by re-using
  311. memory from the receive buffer. The caller provides a
  312. mavlink_message_t which is the size of a full mavlink message. This
  313. is usually the receive buffer for the channel, and allows a reply to an
  314. incoming message with minimum stack space usage.
  315. */
  316. static inline void mavlink_msg_vk_bms_status_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint32_t time_boot_ms, uint32_t voltage, int16_t current, int16_t temperature, int8_t cap_percent, uint8_t bat_id, uint32_t err_code, uint16_t cell_num, const uint16_t *cell_volt)
  317. {
  318. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  319. char *buf = (char *)msgbuf;
  320. _mav_put_uint32_t(buf, 0, time_boot_ms);
  321. _mav_put_uint32_t(buf, 4, voltage);
  322. _mav_put_uint32_t(buf, 8, err_code);
  323. _mav_put_int16_t(buf, 12, current);
  324. _mav_put_int16_t(buf, 14, temperature);
  325. _mav_put_uint16_t(buf, 16, cell_num);
  326. _mav_put_int8_t(buf, 78, cap_percent);
  327. _mav_put_uint8_t(buf, 79, bat_id);
  328. _mav_put_uint16_t_array(buf, 18, cell_volt, 30);
  329. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VK_BMS_STATUS, buf, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_CRC);
  330. #else
  331. mavlink_vk_bms_status_t *packet = (mavlink_vk_bms_status_t *)msgbuf;
  332. packet->time_boot_ms = time_boot_ms;
  333. packet->voltage = voltage;
  334. packet->err_code = err_code;
  335. packet->current = current;
  336. packet->temperature = temperature;
  337. packet->cell_num = cell_num;
  338. packet->cap_percent = cap_percent;
  339. packet->bat_id = bat_id;
  340. mav_array_memcpy(packet->cell_volt, cell_volt, sizeof(uint16_t)*30);
  341. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_VK_BMS_STATUS, (const char *)packet, MAVLINK_MSG_ID_VK_BMS_STATUS_MIN_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN, MAVLINK_MSG_ID_VK_BMS_STATUS_CRC);
  342. #endif
  343. }
  344. #endif
  345. #endif
  346. // MESSAGE VK_BMS_STATUS UNPACKING
  347. /**
  348. * @brief Get field time_boot_ms from vk_bms_status message
  349. *
  350. * @return [ms] Timestamp in ms from system boot.
  351. */
  352. static inline uint32_t mavlink_msg_vk_bms_status_get_time_boot_ms(const mavlink_message_t* msg)
  353. {
  354. return _MAV_RETURN_uint32_t(msg, 0);
  355. }
  356. /**
  357. * @brief Get field voltage from vk_bms_status message
  358. *
  359. * @return [mV] BMS voltage in mV
  360. */
  361. static inline uint32_t mavlink_msg_vk_bms_status_get_voltage(const mavlink_message_t* msg)
  362. {
  363. return _MAV_RETURN_uint32_t(msg, 4);
  364. }
  365. /**
  366. * @brief Get field current from vk_bms_status message
  367. *
  368. * @return [cA] BMS current in cA, negative value means in charging
  369. */
  370. static inline int16_t mavlink_msg_vk_bms_status_get_current(const mavlink_message_t* msg)
  371. {
  372. return _MAV_RETURN_int16_t(msg, 12);
  373. }
  374. /**
  375. * @brief Get field temperature from vk_bms_status message
  376. *
  377. * @return [degC] BMS temperature in degC
  378. */
  379. static inline int16_t mavlink_msg_vk_bms_status_get_temperature(const mavlink_message_t* msg)
  380. {
  381. return _MAV_RETURN_int16_t(msg, 14);
  382. }
  383. /**
  384. * @brief Get field cap_percent from vk_bms_status message
  385. *
  386. * @return [%] BMS remaining power in percentage
  387. */
  388. static inline int8_t mavlink_msg_vk_bms_status_get_cap_percent(const mavlink_message_t* msg)
  389. {
  390. return _MAV_RETURN_int8_t(msg, 78);
  391. }
  392. /**
  393. * @brief Get field bat_id from vk_bms_status message
  394. *
  395. * @return BMS id, start from
  396. 0
  397. */
  398. static inline uint8_t mavlink_msg_vk_bms_status_get_bat_id(const mavlink_message_t* msg)
  399. {
  400. return _MAV_RETURN_uint8_t(msg, 79);
  401. }
  402. /**
  403. * @brief Get field err_code from vk_bms_status message
  404. *
  405. * @return BMS error code,
  406. 0 means no error
  407. */
  408. static inline uint32_t mavlink_msg_vk_bms_status_get_err_code(const mavlink_message_t* msg)
  409. {
  410. return _MAV_RETURN_uint32_t(msg, 8);
  411. }
  412. /**
  413. * @brief Get field cell_num from vk_bms_status message
  414. *
  415. * @return BMS cell numbers
  416. */
  417. static inline uint16_t mavlink_msg_vk_bms_status_get_cell_num(const mavlink_message_t* msg)
  418. {
  419. return _MAV_RETURN_uint16_t(msg, 16);
  420. }
  421. /**
  422. * @brief Get field cell_volt from vk_bms_status message
  423. *
  424. * @return [mV] BMS cell voltage in mV
  425. */
  426. static inline uint16_t mavlink_msg_vk_bms_status_get_cell_volt(const mavlink_message_t* msg, uint16_t *cell_volt)
  427. {
  428. return _MAV_RETURN_uint16_t_array(msg, cell_volt, 30, 18);
  429. }
  430. /**
  431. * @brief Decode a vk_bms_status message into a struct
  432. *
  433. * @param msg The message to decode
  434. * @param vk_bms_status C-struct to decode the message contents into
  435. */
  436. static inline void mavlink_msg_vk_bms_status_decode(const mavlink_message_t* msg, mavlink_vk_bms_status_t* vk_bms_status)
  437. {
  438. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  439. vk_bms_status->time_boot_ms = mavlink_msg_vk_bms_status_get_time_boot_ms(msg);
  440. vk_bms_status->voltage = mavlink_msg_vk_bms_status_get_voltage(msg);
  441. vk_bms_status->err_code = mavlink_msg_vk_bms_status_get_err_code(msg);
  442. vk_bms_status->current = mavlink_msg_vk_bms_status_get_current(msg);
  443. vk_bms_status->temperature = mavlink_msg_vk_bms_status_get_temperature(msg);
  444. vk_bms_status->cell_num = mavlink_msg_vk_bms_status_get_cell_num(msg);
  445. mavlink_msg_vk_bms_status_get_cell_volt(msg, vk_bms_status->cell_volt);
  446. vk_bms_status->cap_percent = mavlink_msg_vk_bms_status_get_cap_percent(msg);
  447. vk_bms_status->bat_id = mavlink_msg_vk_bms_status_get_bat_id(msg);
  448. #else
  449. uint8_t len = msg->len < MAVLINK_MSG_ID_VK_BMS_STATUS_LEN? msg->len : MAVLINK_MSG_ID_VK_BMS_STATUS_LEN;
  450. memset(vk_bms_status, 0, MAVLINK_MSG_ID_VK_BMS_STATUS_LEN);
  451. memcpy(vk_bms_status, _MAV_PAYLOAD(msg), len);
  452. #endif
  453. }