3 #ifdef MAVLINK_USE_MESSAGE_INFO
4 #define MAVLINK_HAVE_GET_MESSAGE_INFO
7 return the message_info struct for a message
9 MAVLINK_HELPER
const mavlink_message_info_t
*mavlink_get_message_info_by_id(uint32_t msgid
)
11 static const mavlink_message_info_t mavlink_message_info
[] = MAVLINK_MESSAGE_INFO
;
13 use a bisection search to find the right entry. A perfect hash may be better
14 Note that this assumes the table is sorted with primary key msgid
16 uint32_t low
=0, high
=sizeof(mavlink_message_info
)/sizeof(mavlink_message_info
[0]);
18 uint32_t mid
= (low
+1+high
)/2;
19 if (msgid
< mavlink_message_info
[mid
].msgid
) {
23 if (msgid
> mavlink_message_info
[mid
].msgid
) {
30 if (mavlink_message_info
[low
].msgid
== msgid
) {
31 return &mavlink_message_info
[low
];
37 return the message_info struct for a message
39 MAVLINK_HELPER
const mavlink_message_info_t
*mavlink_get_message_info(const mavlink_message_t
*msg
)
41 return mavlink_get_message_info_by_id(msg
->msgid
);
45 return the message_info struct for a message
47 MAVLINK_HELPER
const mavlink_message_info_t
*mavlink_get_message_info_by_name(const char *name
)
49 static const struct { const char *name
; uint32_t msgid
; } mavlink_message_names
[] = MAVLINK_MESSAGE_NAMES
;
51 use a bisection search to find the right entry. A perfect hash may be better
52 Note that this assumes the table is sorted with primary key name
54 uint32_t low
=0, high
=sizeof(mavlink_message_names
)/sizeof(mavlink_message_names
[0]);
56 uint32_t mid
= (low
+1+high
)/2;
57 int cmp
= strcmp(mavlink_message_names
[mid
].name
, name
);
59 return mavlink_get_message_info_by_id(mavlink_message_names
[mid
].msgid
);
69 #endif // MAVLINK_USE_MESSAGE_INFO