uavcan.equipment.ice.reciprocating.Status.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.equipment.ice.reciprocating.CylinderStatus.h>
  6. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_MAX_SIZE 196
  7. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_SIGNATURE (0xD38AA3EE75537EC6ULL)
  8. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_ID 1120
  9. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_STATE_STOPPED 0
  10. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_STATE_STARTING 1
  11. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_STATE_RUNNING 2
  12. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_STATE_FAULT 3
  13. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_GENERAL_ERROR 1
  14. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_CRANKSHAFT_SENSOR_ERROR_SUPPORTED 2
  15. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_CRANKSHAFT_SENSOR_ERROR 4
  16. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_SUPPORTED 8
  17. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_BELOW_NOMINAL 16
  18. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_ABOVE_NOMINAL 32
  19. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_OVERHEATING 64
  20. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_EGT_ABOVE_NOMINAL 128
  21. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_SUPPORTED 256
  22. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_BELOW_NOMINAL 512
  23. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_ABOVE_NOMINAL 1024
  24. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DETONATION_SUPPORTED 2048
  25. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DETONATION_OBSERVED 4096
  26. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_MISFIRE_SUPPORTED 8192
  27. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_MISFIRE_OBSERVED 16384
  28. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_SUPPORTED 32768
  29. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_BELOW_NOMINAL 65536
  30. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_ABOVE_NOMINAL 131072
  31. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DEBRIS_SUPPORTED 262144
  32. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DEBRIS_DETECTED 524288
  33. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_SPARK_PLUG_SINGLE 0
  34. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_SPARK_PLUG_FIRST_ACTIVE 1
  35. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_SPARK_PLUG_SECOND_ACTIVE 2
  36. #define UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_SPARK_PLUG_BOTH_ACTIVE 3
  37. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  38. class uavcan_equipment_ice_reciprocating_Status_cxx_iface;
  39. #endif
  40. struct uavcan_equipment_ice_reciprocating_Status {
  41. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  42. using cxx_iface = uavcan_equipment_ice_reciprocating_Status_cxx_iface;
  43. #endif
  44. uint8_t state;
  45. uint32_t flags;
  46. uint8_t engine_load_percent;
  47. uint32_t engine_speed_rpm;
  48. float spark_dwell_time_ms;
  49. float atmospheric_pressure_kpa;
  50. float intake_manifold_pressure_kpa;
  51. float intake_manifold_temperature;
  52. float coolant_temperature;
  53. float oil_pressure;
  54. float oil_temperature;
  55. float fuel_pressure;
  56. float fuel_consumption_rate_cm3pm;
  57. float estimated_consumed_fuel_volume_cm3;
  58. uint8_t throttle_position_percent;
  59. uint8_t ecu_index;
  60. uint8_t spark_plug_usage;
  61. struct { uint8_t len; struct uavcan_equipment_ice_reciprocating_CylinderStatus data[16]; }cylinder_status;
  62. };
  63. #ifdef __cplusplus
  64. extern "C"
  65. {
  66. #endif
  67. uint32_t _uavcan_equipment_ice_reciprocating_Status_encode(struct uavcan_equipment_ice_reciprocating_Status* msg, uint8_t* buffer
  68. #if CANARD_ENABLE_TAO_OPTION
  69. , bool tao
  70. #endif
  71. );
  72. bool _uavcan_equipment_ice_reciprocating_Status_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_ice_reciprocating_Status* msg);
  73. static inline uint32_t uavcan_equipment_ice_reciprocating_Status_encode(struct uavcan_equipment_ice_reciprocating_Status* msg, uint8_t* buffer
  74. #if CANARD_ENABLE_TAO_OPTION
  75. , bool tao
  76. #endif
  77. ) {
  78. return _uavcan_equipment_ice_reciprocating_Status_encode(msg, buffer
  79. #if CANARD_ENABLE_TAO_OPTION
  80. , tao
  81. #endif
  82. );
  83. }
  84. static inline bool uavcan_equipment_ice_reciprocating_Status_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_ice_reciprocating_Status* msg) {
  85. return _uavcan_equipment_ice_reciprocating_Status_decode(transfer, msg);
  86. }
  87. #if defined(CANARD_DSDLC_INTERNAL)
  88. static inline void __uavcan_equipment_ice_reciprocating_Status_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_ice_reciprocating_Status* msg, bool tao);
  89. static inline bool __uavcan_equipment_ice_reciprocating_Status_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_ice_reciprocating_Status* msg, bool tao);
  90. void __uavcan_equipment_ice_reciprocating_Status_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_ice_reciprocating_Status* msg, bool tao) {
  91. (void)buffer;
  92. (void)bit_ofs;
  93. (void)msg;
  94. (void)tao;
  95. canardEncodeScalar(buffer, *bit_ofs, 2, &msg->state);
  96. *bit_ofs += 2;
  97. canardEncodeScalar(buffer, *bit_ofs, 30, &msg->flags);
  98. *bit_ofs += 30;
  99. *bit_ofs += 16;
  100. canardEncodeScalar(buffer, *bit_ofs, 7, &msg->engine_load_percent);
  101. *bit_ofs += 7;
  102. canardEncodeScalar(buffer, *bit_ofs, 17, &msg->engine_speed_rpm);
  103. *bit_ofs += 17;
  104. {
  105. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->spark_dwell_time_ms);
  106. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  107. }
  108. *bit_ofs += 16;
  109. {
  110. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->atmospheric_pressure_kpa);
  111. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  112. }
  113. *bit_ofs += 16;
  114. {
  115. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->intake_manifold_pressure_kpa);
  116. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  117. }
  118. *bit_ofs += 16;
  119. {
  120. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->intake_manifold_temperature);
  121. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  122. }
  123. *bit_ofs += 16;
  124. {
  125. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->coolant_temperature);
  126. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  127. }
  128. *bit_ofs += 16;
  129. {
  130. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->oil_pressure);
  131. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  132. }
  133. *bit_ofs += 16;
  134. {
  135. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->oil_temperature);
  136. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  137. }
  138. *bit_ofs += 16;
  139. {
  140. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->fuel_pressure);
  141. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  142. }
  143. *bit_ofs += 16;
  144. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->fuel_consumption_rate_cm3pm);
  145. *bit_ofs += 32;
  146. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->estimated_consumed_fuel_volume_cm3);
  147. *bit_ofs += 32;
  148. canardEncodeScalar(buffer, *bit_ofs, 7, &msg->throttle_position_percent);
  149. *bit_ofs += 7;
  150. canardEncodeScalar(buffer, *bit_ofs, 6, &msg->ecu_index);
  151. *bit_ofs += 6;
  152. canardEncodeScalar(buffer, *bit_ofs, 3, &msg->spark_plug_usage);
  153. *bit_ofs += 3;
  154. #pragma GCC diagnostic push
  155. #pragma GCC diagnostic ignored "-Wtype-limits"
  156. const uint8_t cylinder_status_len = msg->cylinder_status.len > 16 ? 16 : msg->cylinder_status.len;
  157. #pragma GCC diagnostic pop
  158. if (!tao) {
  159. canardEncodeScalar(buffer, *bit_ofs, 5, &cylinder_status_len);
  160. *bit_ofs += 5;
  161. }
  162. for (size_t i=0; i < cylinder_status_len; i++) {
  163. __uavcan_equipment_ice_reciprocating_CylinderStatus_encode(buffer, bit_ofs, &msg->cylinder_status.data[i], false);
  164. }
  165. }
  166. /*
  167. decode uavcan_equipment_ice_reciprocating_Status, return true on failure, false on success
  168. */
  169. bool __uavcan_equipment_ice_reciprocating_Status_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_ice_reciprocating_Status* msg, bool tao) {
  170. (void)transfer;
  171. (void)bit_ofs;
  172. (void)msg;
  173. (void)tao;
  174. canardDecodeScalar(transfer, *bit_ofs, 2, false, &msg->state);
  175. *bit_ofs += 2;
  176. canardDecodeScalar(transfer, *bit_ofs, 30, false, &msg->flags);
  177. *bit_ofs += 30;
  178. *bit_ofs += 16;
  179. canardDecodeScalar(transfer, *bit_ofs, 7, false, &msg->engine_load_percent);
  180. *bit_ofs += 7;
  181. canardDecodeScalar(transfer, *bit_ofs, 17, false, &msg->engine_speed_rpm);
  182. *bit_ofs += 17;
  183. {
  184. uint16_t float16_val;
  185. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  186. msg->spark_dwell_time_ms = canardConvertFloat16ToNativeFloat(float16_val);
  187. }
  188. *bit_ofs += 16;
  189. {
  190. uint16_t float16_val;
  191. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  192. msg->atmospheric_pressure_kpa = canardConvertFloat16ToNativeFloat(float16_val);
  193. }
  194. *bit_ofs += 16;
  195. {
  196. uint16_t float16_val;
  197. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  198. msg->intake_manifold_pressure_kpa = canardConvertFloat16ToNativeFloat(float16_val);
  199. }
  200. *bit_ofs += 16;
  201. {
  202. uint16_t float16_val;
  203. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  204. msg->intake_manifold_temperature = canardConvertFloat16ToNativeFloat(float16_val);
  205. }
  206. *bit_ofs += 16;
  207. {
  208. uint16_t float16_val;
  209. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  210. msg->coolant_temperature = canardConvertFloat16ToNativeFloat(float16_val);
  211. }
  212. *bit_ofs += 16;
  213. {
  214. uint16_t float16_val;
  215. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  216. msg->oil_pressure = canardConvertFloat16ToNativeFloat(float16_val);
  217. }
  218. *bit_ofs += 16;
  219. {
  220. uint16_t float16_val;
  221. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  222. msg->oil_temperature = canardConvertFloat16ToNativeFloat(float16_val);
  223. }
  224. *bit_ofs += 16;
  225. {
  226. uint16_t float16_val;
  227. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  228. msg->fuel_pressure = canardConvertFloat16ToNativeFloat(float16_val);
  229. }
  230. *bit_ofs += 16;
  231. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->fuel_consumption_rate_cm3pm);
  232. *bit_ofs += 32;
  233. canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->estimated_consumed_fuel_volume_cm3);
  234. *bit_ofs += 32;
  235. canardDecodeScalar(transfer, *bit_ofs, 7, false, &msg->throttle_position_percent);
  236. *bit_ofs += 7;
  237. canardDecodeScalar(transfer, *bit_ofs, 6, false, &msg->ecu_index);
  238. *bit_ofs += 6;
  239. canardDecodeScalar(transfer, *bit_ofs, 3, false, &msg->spark_plug_usage);
  240. *bit_ofs += 3;
  241. if (!tao) {
  242. canardDecodeScalar(transfer, *bit_ofs, 5, false, &msg->cylinder_status.len);
  243. *bit_ofs += 5;
  244. }
  245. if (tao) {
  246. msg->cylinder_status.len = 0;
  247. size_t max_len = 16;
  248. uint32_t max_bits = (transfer->payload_len*8)-7; // TAO elements must be >= 8 bits
  249. while (max_bits > *bit_ofs) {
  250. if (!max_len-- || __uavcan_equipment_ice_reciprocating_CylinderStatus_decode(transfer, bit_ofs, &msg->cylinder_status.data[msg->cylinder_status.len], false)) {return true;}
  251. msg->cylinder_status.len++;
  252. }
  253. } else {
  254. #pragma GCC diagnostic push
  255. #pragma GCC diagnostic ignored "-Wtype-limits"
  256. if (msg->cylinder_status.len > 16) {
  257. return true; /* invalid value */
  258. }
  259. #pragma GCC diagnostic pop
  260. for (size_t i=0; i < msg->cylinder_status.len; i++) {
  261. if (__uavcan_equipment_ice_reciprocating_CylinderStatus_decode(transfer, bit_ofs, &msg->cylinder_status.data[i], false)) {return true;}
  262. }
  263. }
  264. return false; /* success */
  265. }
  266. #endif
  267. #ifdef CANARD_DSDLC_TEST_BUILD
  268. struct uavcan_equipment_ice_reciprocating_Status sample_uavcan_equipment_ice_reciprocating_Status_msg(void);
  269. #endif
  270. #ifdef __cplusplus
  271. } // extern "C"
  272. #ifdef DRONECAN_CXX_WRAPPERS
  273. #include <canard/cxx_wrappers.h>
  274. BROADCAST_MESSAGE_CXX_IFACE(uavcan_equipment_ice_reciprocating_Status, UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_ID, UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_SIGNATURE, UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_MAX_SIZE);
  275. #endif
  276. #endif