mavlink_msg_vk_bms_status.h 24 KB

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