Firmware
uORB.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2015 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #ifndef _UORB_UORB_H
35 #define _UORB_UORB_H
36 
42 #include <sys/types.h>
43 #include <stdint.h>
44 #include <stdbool.h>
45 
46 
50 struct orb_metadata {
51  const char *o_name;
52  const uint16_t o_size;
53  const uint16_t o_size_no_padding;
54  const char *o_fields;
55 };
56 
57 typedef const struct orb_metadata *orb_id_t;
58 
62 #define ORB_MULTI_MAX_INSTANCES 4 // This must be < 10 (because it's the last char of the node path)
63 
68 enum ORB_PRIO {
69  ORB_PRIO_MIN = 1, // leave 0 free for other purposes, eg. marking an uninitialized value
70  ORB_PRIO_VERY_LOW = 25,
71  ORB_PRIO_LOW = 50,
72  ORB_PRIO_DEFAULT = 75,
73  ORB_PRIO_HIGH = 100,
74  ORB_PRIO_VERY_HIGH = 125,
75  ORB_PRIO_MAX = 255
76 };
77 
87 #define ORB_ID(_name) &__orb_##_name
88 
94 #if defined(__cplusplus)
95 # define ORB_DECLARE(_name) extern "C" const struct orb_metadata __orb_##_name __EXPORT
96 #else
97 # define ORB_DECLARE(_name) extern const struct orb_metadata __orb_##_name __EXPORT
98 #endif
99 
114 #define ORB_DEFINE(_name, _struct, _size_no_padding, _fields) \
115  const struct orb_metadata __orb_##_name = { \
116  #_name, \
117  sizeof(_struct), \
118  _size_no_padding, \
119  _fields \
120  }; struct hack
121 
122 __BEGIN_DECLS
123 
134 typedef void *orb_advert_t;
135 
139 extern orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data) __EXPORT;
140 
144 extern orb_advert_t orb_advertise_queue(const struct orb_metadata *meta, const void *data,
145  unsigned int queue_size) __EXPORT;
146 
150 extern orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance,
151  int priority) __EXPORT;
152 
156 extern orb_advert_t orb_advertise_multi_queue(const struct orb_metadata *meta, const void *data, int *instance,
157  int priority, unsigned int queue_size) __EXPORT;
158 
162 extern int orb_unadvertise(orb_advert_t handle) __EXPORT;
163 
167 extern int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data) __EXPORT;
168 
177 static inline int orb_publish_auto(const struct orb_metadata *meta, orb_advert_t *handle, const void *data,
178  int *instance,
179  int priority)
180 {
181  if (!*handle) {
182  *handle = orb_advertise_multi(meta, data, instance, priority);
183 
184  if (*handle) {
185  return 0;
186  }
187 
188  } else {
189  return orb_publish(meta, *handle, data);
190  }
191 
192  return -1;
193 }
194 
198 extern int orb_subscribe(const struct orb_metadata *meta) __EXPORT;
199 
203 extern int orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance) __EXPORT;
204 
208 extern int orb_unsubscribe(int handle) __EXPORT;
209 
213 extern int orb_copy(const struct orb_metadata *meta, int handle, void *buffer) __EXPORT;
214 
218 extern int orb_check(int handle, bool *updated) __EXPORT;
219 
223 extern int orb_stat(int handle, uint64_t *time) __EXPORT;
224 
228 extern int orb_exists(const struct orb_metadata *meta, int instance) __EXPORT;
229 
236 extern int orb_group_count(const struct orb_metadata *meta) __EXPORT;
237 
241 extern int orb_priority(int handle, int32_t *priority) __EXPORT;
242 
246 extern int orb_set_interval(int handle, unsigned interval) __EXPORT;
247 
251 extern int orb_get_interval(int handle, unsigned *interval) __EXPORT;
252 
253 __END_DECLS
254 
255 /* Diverse uORB header defines */ //XXX: move to better location
256 #define ORB_ID_VEHICLE_ATTITUDE_CONTROLS ORB_ID(actuator_controls_0)
257 typedef uint8_t arming_state_t;
258 typedef uint8_t main_state_t;
259 typedef uint8_t hil_state_t;
260 typedef uint8_t navigation_state_t;
261 typedef uint8_t switch_pos_t;
262 
263 #endif /* _UORB_UORB_H */
const uint16_t o_size_no_padding
object size w/o padding at the end (for logger)
Definition: uORB.h:53
int orb_stat(int handle, uint64_t *time) __EXPORT
Definition: uORB.cpp:100
orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data) __EXPORT
Definition: uORB.cpp:43
int orb_get_interval(int handle, unsigned *interval) __EXPORT
Definition: uORB.cpp:131
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
const char * o_name
unique object name
Definition: uORB.h:51
ORB_PRIO
Topic priority.
Definition: uORB.h:68
int orb_subscribe(const struct orb_metadata *meta) __EXPORT
Definition: uORB.cpp:75
Definition: I2C.hpp:51
orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance, int priority) __EXPORT
Definition: uORB.cpp:53
int orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance) __EXPORT
Definition: uORB.cpp:80
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data) __EXPORT
Definition: uORB.cpp:70
int orb_unadvertise(orb_advert_t handle) __EXPORT
Definition: uORB.cpp:65
int orb_set_interval(int handle, unsigned interval) __EXPORT
Definition: uORB.cpp:126
int orb_priority(int handle, int32_t *priority) __EXPORT
Definition: uORB.cpp:121
int orb_group_count(const struct orb_metadata *meta) __EXPORT
Get the number of published instances of a topic group.
Definition: uORB.cpp:110
Object metadata.
Definition: uORB.h:50
const char * o_fields
semicolon separated list of fields (with type)
Definition: uORB.h:54
int orb_unsubscribe(int handle) __EXPORT
Definition: uORB.cpp:85
Definition: video_device.h:50
int orb_exists(const struct orb_metadata *meta, int instance) __EXPORT
Definition: uORB.cpp:105
const uint16_t o_size
object size
Definition: uORB.h:52
orb_advert_t orb_advertise_multi_queue(const struct orb_metadata *meta, const void *data, int *instance, int priority, unsigned int queue_size) __EXPORT
Definition: uORB.cpp:59
int orb_copy(const struct orb_metadata *meta, int handle, void *buffer) __EXPORT
Definition: uORB.cpp:90
orb_advert_t orb_advertise_queue(const struct orb_metadata *meta, const void *data, unsigned int queue_size) __EXPORT
Definition: uORB.cpp:48
int orb_check(int handle, bool *updated) __EXPORT
Definition: uORB.cpp:95