mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 19:07:45 +08:00
mavlink: add function to copy only if updated
The MavlinkOrbSubscription only had an interface to either always copy or copy based on a timestamp. This commit adds a copy interface if the topic has been updated.
This commit is contained in:
@@ -111,6 +111,29 @@ MavlinkOrbSubscription::update(void* data)
|
|||||||
return !orb_copy(_topic, _fd, data);
|
return !orb_copy(_topic, _fd, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
MavlinkOrbSubscription::update_if_changed(void *data)
|
||||||
|
{
|
||||||
|
bool updated;
|
||||||
|
if (orb_check(_fd, &updated)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!updated) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orb_copy(_topic, _fd, data)) {
|
||||||
|
if (data != nullptr) {
|
||||||
|
/* error copying topic data */
|
||||||
|
memset(data, 0, _topic->o_size);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MavlinkOrbSubscription::is_published()
|
MavlinkOrbSubscription::is_published()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,11 +54,13 @@ public:
|
|||||||
~MavlinkOrbSubscription();
|
~MavlinkOrbSubscription();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if subscription updated and get data.
|
* Check if subscription updated based on timestamp.
|
||||||
*
|
*
|
||||||
* @return true only if topic was updated and data copied to buffer successfully.
|
* @return true only if topic was updated based on a timestamp and
|
||||||
* If topic was not updated since last check it will return false but still copy the data.
|
* copied to buffer successfully.
|
||||||
* If no data available data buffer will be filled with zeroes.
|
* If topic was not updated since last check it will return false but
|
||||||
|
* still copy the data.
|
||||||
|
* If no data available data buffer will be filled with zeros.
|
||||||
*/
|
*/
|
||||||
bool update(uint64_t *time, void *data);
|
bool update(uint64_t *time, void *data);
|
||||||
|
|
||||||
@@ -69,11 +71,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool update(void *data);
|
bool update(void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the subscription has been updated.
|
||||||
|
*
|
||||||
|
* @return true if there has been an update which has been
|
||||||
|
* copied successfully.
|
||||||
|
*/
|
||||||
|
bool update_if_changed(void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the topic has been published.
|
* Check if the topic has been published.
|
||||||
*
|
*
|
||||||
* This call will return true if the topic was ever published.
|
* This call will return true if the topic was ever published.
|
||||||
* @return true if the topic has been published at least once.
|
* @return true if the topic has been published at least once.
|
||||||
|
* If no data is available the buffer will be filled with zeros.
|
||||||
*/
|
*/
|
||||||
bool is_published();
|
bool is_published();
|
||||||
orb_id_t get_topic() const;
|
orb_id_t get_topic() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user