|
9 | 9 | #define DRONECAN_SENSORS_HYGROMETER_HYGROMETER_H_ |
10 | 10 |
|
11 | 11 | #include "libdcnode/serialization_internal.h" |
12 | | -#include "libdcnode/dronecan.h" |
| 12 | +#include "libdcnode/dronecan.hpp" |
13 | 13 |
|
14 | | -#define DRONECAN_SENSORS_HYGROMETER_HYGROMETER_ID 1032 |
15 | | -#define DRONECAN_SENSORS_HYGROMETER_HYGROMETER_SIGNATURE 0xCEB308892BF163E8ULL |
16 | | -#define DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE 5 |
17 | | -#define DRONECAN_SENSORS_HYGROMETER_HYGROMETER UAVCAN_EXPAND(DRONECAN_SENSORS_HYGROMETER_HYGROMETER) |
| 14 | +#define DRONECAN_SENSORS_HYGROMETER_HYGROMETER_ID 1032 |
| 15 | +#define DRONECAN_SENSORS_HYGROMETER_HYGROMETER_SIGNATURE 0xCEB308892BF163E8ULL |
| 16 | +#define DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE 5 |
| 17 | +#define DRONECAN_SENSORS_HYGROMETER_HYGROMETER UAVCAN_EXPAND(DRONECAN_SENSORS_HYGROMETER_HYGROMETER) |
18 | 18 |
|
19 | | -typedef struct { |
| 19 | +typedef struct |
| 20 | +{ |
20 | 21 | float temperature; |
21 | 22 | float humidity; |
22 | 23 | uint8_t id; |
23 | 24 | } Hygrometer; |
24 | 25 |
|
25 | 26 | #ifdef __cplusplus |
26 | | -extern "C" { |
| 27 | +extern "C" |
| 28 | +{ |
27 | 29 | #endif |
28 | 30 |
|
29 | | -static inline int8_t dronecan_sensors_hygrometer_hygrometer_serialize( |
30 | | - const Hygrometer* const obj, |
31 | | - uint8_t* const buffer, |
32 | | - size_t* const inout_buffer_size_bytes) |
33 | | -{ |
34 | | - if ((obj == NULL) || (buffer == NULL) || (inout_buffer_size_bytes == NULL)) { |
35 | | - return -2; |
36 | | - } |
| 31 | + static inline int8_t dronecan_sensors_hygrometer_hygrometer_serialize( |
| 32 | + const Hygrometer *const obj, |
| 33 | + uint8_t *const buffer, |
| 34 | + size_t *const inout_buffer_size_bytes) |
| 35 | + { |
| 36 | + if ((obj == NULL) || (buffer == NULL) || (inout_buffer_size_bytes == NULL)) |
| 37 | + { |
| 38 | + return -2; |
| 39 | + } |
37 | 40 |
|
38 | | - const size_t capacity_bytes = *inout_buffer_size_bytes; |
39 | | - if (capacity_bytes < DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE) { |
40 | | - return -3; |
41 | | - } |
| 41 | + const size_t capacity_bytes = *inout_buffer_size_bytes; |
| 42 | + if (capacity_bytes < DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE) |
| 43 | + { |
| 44 | + return -3; |
| 45 | + } |
42 | 46 |
|
43 | | - uint16_t temperature = canardConvertNativeFloatToFloat16(obj->temperature); |
44 | | - canardEncodeScalar(buffer, 0, 16, &temperature); |
| 47 | + uint16_t temperature = canardConvertNativeFloatToFloat16(obj->temperature); |
| 48 | + canardEncodeScalar(buffer, 0, 16, &temperature); |
45 | 49 |
|
46 | | - uint16_t humidity = canardConvertNativeFloatToFloat16(obj->humidity); |
47 | | - canardEncodeScalar(buffer, 16, 16, &humidity); |
| 50 | + uint16_t humidity = canardConvertNativeFloatToFloat16(obj->humidity); |
| 51 | + canardEncodeScalar(buffer, 16, 16, &humidity); |
48 | 52 |
|
49 | | - canardEncodeScalar(buffer, 32, 8, &obj->id); |
| 53 | + canardEncodeScalar(buffer, 32, 8, &obj->id); |
50 | 54 |
|
51 | | - return 0; |
52 | | -} |
| 55 | + return 0; |
| 56 | + } |
53 | 57 |
|
54 | | -static inline int8_t dronecan_sensors_hygrometer_hygrometer_publish( |
55 | | - const Hygrometer* const obj, |
56 | | - uint8_t* inout_transfer_id) |
57 | | -{ |
58 | | - uint8_t buffer[DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE]; |
59 | | - size_t inout_buffer_size = DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE; |
60 | | - dronecan_sensors_hygrometer_hygrometer_serialize(obj, buffer, &inout_buffer_size); |
61 | | - uavcanPublish(DRONECAN_SENSORS_HYGROMETER_HYGROMETER_SIGNATURE, |
62 | | - DRONECAN_SENSORS_HYGROMETER_HYGROMETER_ID, |
63 | | - inout_transfer_id, |
64 | | - CANARD_TRANSFER_PRIORITY_MEDIUM, |
65 | | - buffer, |
66 | | - DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE); |
| 58 | + static inline int8_t dronecan_sensors_hygrometer_hygrometer_publish( |
| 59 | + const Hygrometer *const obj, |
| 60 | + uint8_t *inout_transfer_id) |
| 61 | + { |
| 62 | + uint8_t buffer[DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE]; |
| 63 | + size_t inout_buffer_size = DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE; |
| 64 | + dronecan_sensors_hygrometer_hygrometer_serialize(obj, buffer, &inout_buffer_size); |
| 65 | + uavcanPublish(DRONECAN_SENSORS_HYGROMETER_HYGROMETER_SIGNATURE, |
| 66 | + DRONECAN_SENSORS_HYGROMETER_HYGROMETER_ID, |
| 67 | + inout_transfer_id, |
| 68 | + CANARD_TRANSFER_PRIORITY_MEDIUM, |
| 69 | + buffer, |
| 70 | + DRONECAN_SENSORS_HYGROMETER_HYGROMETER_MESSAGE_SIZE); |
67 | 71 |
|
68 | | - return 0; |
69 | | -} |
| 72 | + return 0; |
| 73 | + } |
70 | 74 |
|
71 | 75 | #ifdef __cplusplus |
72 | 76 | } |
73 | 77 | #endif |
74 | 78 |
|
75 | | -#endif // DRONECAN_SENSORS_HYGROMETER_HYGROMETER_H_ |
| 79 | +#endif // DRONECAN_SENSORS_HYGROMETER_HYGROMETER_H_ |
0 commit comments