mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 17:48:53 +08:00
Subscription & SubscriptionArray: add forcedUpdate() methods
Can be used to immediately get & use the data, as needed for the flight tasks.
This commit is contained in:
@@ -151,6 +151,8 @@ public:
|
||||
return -3;
|
||||
}
|
||||
|
||||
_subscription_array.forcedUpdate(); // make sure data is available for all new subscriptions
|
||||
|
||||
_current_task_index = task_number;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -76,3 +76,10 @@ void SubscriptionArray::update()
|
||||
_subscriptions[i]->update();
|
||||
}
|
||||
}
|
||||
|
||||
void SubscriptionArray::forcedUpdate()
|
||||
{
|
||||
for (int i = 0; i < _subscriptions_count; ++i) {
|
||||
_subscriptions[i]->forcedUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,15 @@ public:
|
||||
bool get(const struct orb_metadata *meta, uORB::Subscription<T> *&subscription, unsigned instance = 0);
|
||||
|
||||
/**
|
||||
* update all subscriptions
|
||||
* update all subscriptions (if new data is available)
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* update all subscriptions
|
||||
*/
|
||||
void forcedUpdate();
|
||||
|
||||
private:
|
||||
void cleanup();
|
||||
|
||||
|
||||
@@ -125,13 +125,18 @@ public:
|
||||
*/
|
||||
virtual bool update() = 0;
|
||||
|
||||
/**
|
||||
* Like update(), but does not check first if there is data available
|
||||
*/
|
||||
virtual bool forcedUpdate() = 0;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Subscription wrapper class
|
||||
*/
|
||||
template<class T>
|
||||
class __EXPORT Subscription final : public SubscriptionNode
|
||||
class __EXPORT Subscription : public SubscriptionNode
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -150,7 +155,7 @@ public:
|
||||
_data() // initialize data structure to zero
|
||||
{}
|
||||
|
||||
~Subscription() override final = default;
|
||||
~Subscription() override = default;
|
||||
|
||||
// no copy, assignment, move, move assignment
|
||||
Subscription(const Subscription &) = delete;
|
||||
@@ -161,11 +166,16 @@ public:
|
||||
/**
|
||||
* Create an update function that uses the embedded struct.
|
||||
*/
|
||||
bool update() override final
|
||||
bool update() override
|
||||
{
|
||||
return SubscriptionBase::update((void *)(&_data));
|
||||
}
|
||||
|
||||
bool forcedUpdate() override
|
||||
{
|
||||
return orb_copy(_meta, _handle, &_data) == PX4_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function gets the T struct data
|
||||
* */
|
||||
|
||||
Reference in New Issue
Block a user