mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-24 15:40:31 +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:
@@ -74,7 +74,7 @@ MavlinkOrbSubscription::get_instance() const
|
||||
}
|
||||
|
||||
bool
|
||||
MavlinkOrbSubscription::update(uint64_t *time, void* data)
|
||||
MavlinkOrbSubscription::update(uint64_t *time, void *data)
|
||||
{
|
||||
// TODO this is NOT atomic operation, we can get data newer than time
|
||||
// if topic was published between orb_stat and orb_copy calls.
|
||||
@@ -106,11 +106,34 @@ MavlinkOrbSubscription::update(uint64_t *time, void* data)
|
||||
}
|
||||
|
||||
bool
|
||||
MavlinkOrbSubscription::update(void* data)
|
||||
MavlinkOrbSubscription::update(void *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
|
||||
MavlinkOrbSubscription::is_published()
|
||||
{
|
||||
|
||||
@@ -54,26 +54,37 @@ public:
|
||||
~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.
|
||||
* 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 zeroes.
|
||||
* @return true only if topic was updated based on a timestamp and
|
||||
* copied to buffer successfully.
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Copy topic data to given buffer.
|
||||
*
|
||||
* @return true only if topic data copied successfully.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* This call will return true if the topic was ever published.
|
||||
* @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();
|
||||
orb_id_t get_topic() const;
|
||||
|
||||
Reference in New Issue
Block a user