mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 05:53:34 +08:00
uORB: SubscriptionInterval fix timestamp wrapping when initializing less than the interval time after boot (#23384)
* SubscriptionInterval: ensure _last_update is never before timer start
This commit is contained in:
@@ -125,8 +125,16 @@ public:
|
|||||||
{
|
{
|
||||||
if (_subscription.copy(dst)) {
|
if (_subscription.copy(dst)) {
|
||||||
const hrt_abstime now = hrt_absolute_time();
|
const hrt_abstime now = hrt_absolute_time();
|
||||||
// shift last update time forward, but don't let it get further behind than the interval
|
|
||||||
_last_update = math::constrain(_last_update + _interval_us, now - _interval_us, now);
|
// make sure we don't set a timestamp before the timer started counting (now - _interval_us would wrap because it's unsigned)
|
||||||
|
if (now > _interval_us) {
|
||||||
|
// shift last update time forward, but don't let it get further behind than the interval
|
||||||
|
_last_update = math::constrain(_last_update + _interval_us, now - _interval_us, now);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_last_update = now;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +168,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
Subscription _subscription;
|
Subscription _subscription;
|
||||||
uint64_t _last_update{0}; // last update in microseconds
|
uint64_t _last_update{0}; // last subscription update in microseconds
|
||||||
uint32_t _interval_us{0}; // maximum update interval in microseconds
|
uint32_t _interval_us{0}; // maximum update interval in microseconds
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user