mavlink_msg_diagnostic.h 7.42 KB
Newer Older
James Goppert's avatar
James Goppert committed
1 2 3
// MESSAGE DIAGNOSTIC PACKING

#define MAVLINK_MSG_ID_DIAGNOSTIC 173
lm's avatar
lm committed
4 5
#define MAVLINK_MSG_ID_DIAGNOSTIC_LEN 18
#define MAVLINK_MSG_173_LEN 18
lm's avatar
lm committed
6 7
#define MAVLINK_MSG_ID_DIAGNOSTIC_KEY 0xFE
#define MAVLINK_MSG_173_KEY 0xFE
James Goppert's avatar
James Goppert committed
8 9 10

typedef struct __mavlink_diagnostic_t 
{
lm's avatar
lm committed
11 12 13 14 15 16
	float diagFl1;	///< Diagnostic float 1
	float diagFl2;	///< Diagnostic float 2
	float diagFl3;	///< Diagnostic float 3
	int16_t diagSh1;	///< Diagnostic short 1
	int16_t diagSh2;	///< Diagnostic short 2
	int16_t diagSh3;	///< Diagnostic short 3
James Goppert's avatar
James Goppert committed
17 18 19 20

} mavlink_diagnostic_t;

/**
James Goppert's avatar
James Goppert committed
21 22 23 24
 * @brief Pack a diagnostic message
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
James Goppert's avatar
James Goppert committed
25 26 27 28 29 30 31 32 33 34 35
 *
 * @param diagFl1 Diagnostic float 1
 * @param diagFl2 Diagnostic float 2
 * @param diagFl3 Diagnostic float 3
 * @param diagSh1 Diagnostic short 1
 * @param diagSh2 Diagnostic short 2
 * @param diagSh3 Diagnostic short 3
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_diagnostic_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, float diagFl1, float diagFl2, float diagFl3, int16_t diagSh1, int16_t diagSh2, int16_t diagSh3)
{
lm's avatar
lm committed
36
	mavlink_diagnostic_t *p = (mavlink_diagnostic_t *)&msg->payload[0];
James Goppert's avatar
James Goppert committed
37 38
	msg->msgid = MAVLINK_MSG_ID_DIAGNOSTIC;

lm's avatar
lm committed
39 40 41 42 43 44
	p->diagFl1 = diagFl1;	// float:Diagnostic float 1
	p->diagFl2 = diagFl2;	// float:Diagnostic float 2
	p->diagFl3 = diagFl3;	// float:Diagnostic float 3
	p->diagSh1 = diagSh1;	// int16_t:Diagnostic short 1
	p->diagSh2 = diagSh2;	// int16_t:Diagnostic short 2
	p->diagSh3 = diagSh3;	// int16_t:Diagnostic short 3
James Goppert's avatar
James Goppert committed
45

lm's avatar
lm committed
46
	return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_DIAGNOSTIC_LEN);
James Goppert's avatar
James Goppert committed
47 48
}

James Goppert's avatar
James Goppert committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/**
 * @brief Pack a diagnostic message
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message was sent over
 * @param msg The MAVLink message to compress the data into
 * @param diagFl1 Diagnostic float 1
 * @param diagFl2 Diagnostic float 2
 * @param diagFl3 Diagnostic float 3
 * @param diagSh1 Diagnostic short 1
 * @param diagSh2 Diagnostic short 2
 * @param diagSh3 Diagnostic short 3
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_diagnostic_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, float diagFl1, float diagFl2, float diagFl3, int16_t diagSh1, int16_t diagSh2, int16_t diagSh3)
James Goppert's avatar
James Goppert committed
64
{
lm's avatar
lm committed
65
	mavlink_diagnostic_t *p = (mavlink_diagnostic_t *)&msg->payload[0];
James Goppert's avatar
James Goppert committed
66 67
	msg->msgid = MAVLINK_MSG_ID_DIAGNOSTIC;

lm's avatar
lm committed
68 69 70 71 72 73
	p->diagFl1 = diagFl1;	// float:Diagnostic float 1
	p->diagFl2 = diagFl2;	// float:Diagnostic float 2
	p->diagFl3 = diagFl3;	// float:Diagnostic float 3
	p->diagSh1 = diagSh1;	// int16_t:Diagnostic short 1
	p->diagSh2 = diagSh2;	// int16_t:Diagnostic short 2
	p->diagSh3 = diagSh3;	// int16_t:Diagnostic short 3
James Goppert's avatar
James Goppert committed
74

lm's avatar
lm committed
75
	return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_DIAGNOSTIC_LEN);
James Goppert's avatar
James Goppert committed
76 77
}

James Goppert's avatar
James Goppert committed
78 79 80 81 82 83 84 85
/**
 * @brief Encode a diagnostic struct into a message
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 * @param diagnostic C-struct to read the message contents from
 */
James Goppert's avatar
James Goppert committed
86 87 88 89 90
static inline uint16_t mavlink_msg_diagnostic_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_diagnostic_t* diagnostic)
{
	return mavlink_msg_diagnostic_pack(system_id, component_id, msg, diagnostic->diagFl1, diagnostic->diagFl2, diagnostic->diagFl3, diagnostic->diagSh1, diagnostic->diagSh2, diagnostic->diagSh3);
}

lm's avatar
lm committed
91 92

#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
James Goppert's avatar
James Goppert committed
93 94 95 96 97 98 99 100 101 102 103
/**
 * @brief Send a diagnostic message
 * @param chan MAVLink channel to send the message
 *
 * @param diagFl1 Diagnostic float 1
 * @param diagFl2 Diagnostic float 2
 * @param diagFl3 Diagnostic float 3
 * @param diagSh1 Diagnostic short 1
 * @param diagSh2 Diagnostic short 2
 * @param diagSh3 Diagnostic short 3
 */
lm's avatar
lm committed
104 105 106 107 108
static inline void mavlink_msg_diagnostic_send(mavlink_channel_t chan, float diagFl1, float diagFl2, float diagFl3, int16_t diagSh1, int16_t diagSh2, int16_t diagSh3)
{
	mavlink_header_t hdr;
	mavlink_diagnostic_t payload;

lm's avatar
lm committed
109 110 111 112 113 114 115
	MAVLINK_BUFFER_CHECK_START( chan, MAVLINK_MSG_ID_DIAGNOSTIC_LEN )
	payload.diagFl1 = diagFl1;	// float:Diagnostic float 1
	payload.diagFl2 = diagFl2;	// float:Diagnostic float 2
	payload.diagFl3 = diagFl3;	// float:Diagnostic float 3
	payload.diagSh1 = diagSh1;	// int16_t:Diagnostic short 1
	payload.diagSh2 = diagSh2;	// int16_t:Diagnostic short 2
	payload.diagSh3 = diagSh3;	// int16_t:Diagnostic short 3
lm's avatar
lm committed
116 117 118 119 120 121 122 123 124

	hdr.STX = MAVLINK_STX;
	hdr.len = MAVLINK_MSG_ID_DIAGNOSTIC_LEN;
	hdr.msgid = MAVLINK_MSG_ID_DIAGNOSTIC;
	hdr.sysid = mavlink_system.sysid;
	hdr.compid = mavlink_system.compid;
	hdr.seq = mavlink_get_channel_status(chan)->current_tx_seq;
	mavlink_get_channel_status(chan)->current_tx_seq = hdr.seq + 1;
	mavlink_send_mem(chan, (uint8_t *)&hdr.STX, MAVLINK_NUM_HEADER_BYTES );
125
	mavlink_send_mem(chan, (uint8_t *)&payload, sizeof(payload) );
lm's avatar
lm committed
126

lm's avatar
lm committed
127 128 129 130 131 132
	crc_init(&hdr.ck);
	crc_calculate_mem((uint8_t *)&hdr.len, &hdr.ck, MAVLINK_CORE_HEADER_LEN);
	crc_calculate_mem((uint8_t *)&payload, &hdr.ck, hdr.len );
	crc_accumulate( 0xFE, &hdr.ck); /// include key in X25 checksum
	mavlink_send_mem(chan, (uint8_t *)&hdr.ck, MAVLINK_NUM_CHECKSUM_BYTES);
	MAVLINK_BUFFER_CHECK_END
James Goppert's avatar
James Goppert committed
133 134 135 136 137 138 139 140 141 142 143 144
}

#endif
// MESSAGE DIAGNOSTIC UNPACKING

/**
 * @brief Get field diagFl1 from diagnostic message
 *
 * @return Diagnostic float 1
 */
static inline float mavlink_msg_diagnostic_get_diagFl1(const mavlink_message_t* msg)
{
lm's avatar
lm committed
145 146
	mavlink_diagnostic_t *p = (mavlink_diagnostic_t *)&msg->payload[0];
	return (float)(p->diagFl1);
James Goppert's avatar
James Goppert committed
147 148 149 150 151 152 153 154 155
}

/**
 * @brief Get field diagFl2 from diagnostic message
 *
 * @return Diagnostic float 2
 */
static inline float mavlink_msg_diagnostic_get_diagFl2(const mavlink_message_t* msg)
{
lm's avatar
lm committed
156 157
	mavlink_diagnostic_t *p = (mavlink_diagnostic_t *)&msg->payload[0];
	return (float)(p->diagFl2);
James Goppert's avatar
James Goppert committed
158 159 160 161 162 163 164 165 166
}

/**
 * @brief Get field diagFl3 from diagnostic message
 *
 * @return Diagnostic float 3
 */
static inline float mavlink_msg_diagnostic_get_diagFl3(const mavlink_message_t* msg)
{
lm's avatar
lm committed
167 168
	mavlink_diagnostic_t *p = (mavlink_diagnostic_t *)&msg->payload[0];
	return (float)(p->diagFl3);
James Goppert's avatar
James Goppert committed
169 170 171 172 173 174 175 176 177
}

/**
 * @brief Get field diagSh1 from diagnostic message
 *
 * @return Diagnostic short 1
 */
static inline int16_t mavlink_msg_diagnostic_get_diagSh1(const mavlink_message_t* msg)
{
lm's avatar
lm committed
178 179
	mavlink_diagnostic_t *p = (mavlink_diagnostic_t *)&msg->payload[0];
	return (int16_t)(p->diagSh1);
James Goppert's avatar
James Goppert committed
180 181 182 183 184 185 186 187 188
}

/**
 * @brief Get field diagSh2 from diagnostic message
 *
 * @return Diagnostic short 2
 */
static inline int16_t mavlink_msg_diagnostic_get_diagSh2(const mavlink_message_t* msg)
{
lm's avatar
lm committed
189 190
	mavlink_diagnostic_t *p = (mavlink_diagnostic_t *)&msg->payload[0];
	return (int16_t)(p->diagSh2);
James Goppert's avatar
James Goppert committed
191 192 193 194 195 196 197 198 199
}

/**
 * @brief Get field diagSh3 from diagnostic message
 *
 * @return Diagnostic short 3
 */
static inline int16_t mavlink_msg_diagnostic_get_diagSh3(const mavlink_message_t* msg)
{
lm's avatar
lm committed
200 201
	mavlink_diagnostic_t *p = (mavlink_diagnostic_t *)&msg->payload[0];
	return (int16_t)(p->diagSh3);
James Goppert's avatar
James Goppert committed
202 203
}

James Goppert's avatar
James Goppert committed
204 205 206 207 208 209
/**
 * @brief Decode a diagnostic message into a struct
 *
 * @param msg The message to decode
 * @param diagnostic C-struct to decode the message contents into
 */
James Goppert's avatar
James Goppert committed
210 211
static inline void mavlink_msg_diagnostic_decode(const mavlink_message_t* msg, mavlink_diagnostic_t* diagnostic)
{
lm's avatar
lm committed
212
	memcpy( diagnostic, msg->payload, sizeof(mavlink_diagnostic_t));
James Goppert's avatar
James Goppert committed
213
}