mavlink_msg_vk_bms_status.h 21 KB

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