PX4 Firmware
PX4 Autopilot Software http://px4.io
mavlink_orb_subscription.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2014 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 /**
35  * @file mavlink_orb_subscription.h
36  * uORB subscription definition.
37  *
38  * @author Anton Babushkin <anton.babushkin@me.com>
39  */
40 
41 #ifndef MAVLINK_ORB_SUBSCRIPTION_H_
42 #define MAVLINK_ORB_SUBSCRIPTION_H_
43 
44 #include <drivers/drv_hrt.h>
45 #include <containers/List.hpp>
46 #include <uORB/Subscription.hpp>
47 
48 class MavlinkOrbSubscription : public ListNode<MavlinkOrbSubscription *>
49 {
50 public:
51 
52  MavlinkOrbSubscription(const orb_id_t topic, int instance) : _sub(topic, instance) {}
53  ~MavlinkOrbSubscription() = default;
54 
55  /**
56  * Check if subscription updated based on timestamp.
57  *
58  * @return true only if topic was updated based on a timestamp and
59  * copied to buffer successfully.
60  * If topic was not updated since last check it will return false but
61  * still copy the data.
62  * If no data available data buffer will be filled with zeros.
63  */
64  bool update(uint64_t *time, void *data) { return _sub.update(time, data); }
65 
66  /**
67  * Copy topic data to given buffer.
68  *
69  * @return true only if topic data copied successfully.
70  */
71  bool update(void *data) { return _sub.copy(data); }
72 
73  /**
74  * Check if the subscription has been updated.
75  *
76  * @return true if there has been an update which has been
77  * copied successfully.
78  */
79  bool update_if_changed(void *data) { return _sub.update(data); }
80 
81  /**
82  * Check if the topic has been published.
83  *
84  * This call will return true if the topic was ever published.
85  * @return true if the topic has been published at least once.
86  * If no data is available the buffer will be filled with zeros.
87  */
88  bool is_published();
89 
90  void subscribe_from_beginning(bool from_beginning) { _subscribe_from_beginning = from_beginning; }
91 
92  orb_id_t get_topic() const { return _sub.get_topic(); }
93  int get_instance() const { return _sub.get_instance(); }
94 
95 private:
96 
98 
99  bool _subscribe_from_beginning{false}; ///< we need to subscribe from the beginning, e.g. for vehicle_command_acks
100 };
101 
102 
103 #endif /* MAVLINK_ORB_SUBSCRIPTION_H_ */
uint8_t get_instance() const
An intrusive linked list.
LidarLite * instance
Definition: ll40ls.cpp:65
High-resolution timer with callouts and timekeeping.
uint8_t * data
Definition: dataman.cpp:149
Object metadata.
Definition: uORB.h:50
orb_id_t get_topic() const
bool update(void *dst)
Update the struct.
bool copy(void *dst)
Copy the struct.