Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Timestamp wrapping when initializing SubscriptionInterval less than the interval time after boot #23384

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions platforms/common/uORB/SubscriptionInterval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ class SubscriptionInterval
{
if (_subscription.copy(dst)) {
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);
}
dagar marked this conversation as resolved.
Show resolved Hide resolved

return true;
}

Expand Down Expand Up @@ -160,7 +165,7 @@ class SubscriptionInterval
protected:

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

};
Expand Down
Loading