mavlink_get_info.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef MAVLINK_USE_MESSAGE_INFO
4 #define MAVLINK_HAVE_GET_MESSAGE_INFO
5 
6 /*
7  return the message_info struct for a message
8 */
9 MAVLINK_HELPER const mavlink_message_info_t *mavlink_get_message_info_by_id(uint32_t msgid)
10 {
11  static const mavlink_message_info_t mavlink_message_info[] = MAVLINK_MESSAGE_INFO;
12  /*
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
15  */
16  uint32_t low=0, high=sizeof(mavlink_message_info)/sizeof(mavlink_message_info[0]);
17  while (low < high) {
18  uint32_t mid = (low+1+high)/2;
19  if (msgid < mavlink_message_info[mid].msgid) {
20  high = mid-1;
21  continue;
22  }
23  if (msgid > mavlink_message_info[mid].msgid) {
24  low = mid;
25  continue;
26  }
27  low = mid;
28  break;
29  }
30  if (mavlink_message_info[low].msgid == msgid) {
31  return &mavlink_message_info[low];
32  }
33  return NULL;
34 }
35 
36 /*
37  return the message_info struct for a message
38 */
40 {
41  return mavlink_get_message_info_by_id(msg->msgid);
42 }
43 
44 /*
45  return the message_info struct for a message
46 */
47 MAVLINK_HELPER const mavlink_message_info_t *mavlink_get_message_info_by_name(const char *name)
48 {
49  static const struct { const char *name; uint32_t msgid; } mavlink_message_names[] = MAVLINK_MESSAGE_NAMES;
50  /*
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
53  */
54  uint32_t low=0, high=sizeof(mavlink_message_names)/sizeof(mavlink_message_names[0]);
55  while (low < high) {
56  uint32_t mid = (low+1+high)/2;
57  int cmp = strcmp(mavlink_message_names[mid].name, name);
58  if (cmp == 0) {
59  return mavlink_get_message_info_by_id(mavlink_message_names[mid].msgid);
60  }
61  if (cmp > 0) {
62  high = mid-1;
63  } else {
64  low = mid;
65  }
66  }
67  return NULL;
68 }
69 #endif // MAVLINK_USE_MESSAGE_INFO
70 
71 
#define mavlink_get_message_info(msg)
Definition: testmav.c:40
#define MAVLINK_MESSAGE_INFO


mavlink
Author(s): Lorenz Meier
autogenerated on Sun Apr 7 2019 02:06:02