mavlink_msg_vk_bms_status.h 24 KB

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