mavlink_msg_vk_bms_status.h 23 KB

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