mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-09 19:01:37 +08:00
commander: elapsed time checks avoid subtracting unsigned integers
- avoid the possibility of unsigned underflow from subtracting two HRT timestamps (uint64_t) - most of these aren't problematic, but people tend to replicate the pattern, so it's better to be safe - likely wasn't a problem when people were using hrt_absolute_time() in place, but if using an existing timestamp there's the possibility it's older than a more recent topic update
This commit is contained in:
@@ -1699,7 +1699,7 @@ void Commander::run()
|
||||
const bool nav_state_or_failsafe_changed = handleModeIntentionAndFailsafe();
|
||||
|
||||
// Run arming checks @ 10Hz
|
||||
if (now - _last_health_and_arming_check >= 100_ms || _status_changed || nav_state_or_failsafe_changed) {
|
||||
if ((now >= _last_health_and_arming_check + 100_ms) || _status_changed || nav_state_or_failsafe_changed) {
|
||||
_last_health_and_arming_check = now;
|
||||
|
||||
perf_begin(_preflight_check_perf);
|
||||
@@ -1767,7 +1767,7 @@ void Commander::run()
|
||||
_actuator_armed.prearmed = getPrearmState();
|
||||
|
||||
// publish states (armed, control_mode, vehicle_status, failure_detector_status) at 2 Hz or immediately when changed
|
||||
if (now - _vehicle_status.timestamp >= 500_ms || _status_changed || nav_state_or_failsafe_changed
|
||||
if ((now >= _vehicle_status.timestamp + 500_ms) || _status_changed || nav_state_or_failsafe_changed
|
||||
|| !(_actuator_armed == actuator_armed_prev)) {
|
||||
|
||||
// publish actuator_armed first (used by output modules)
|
||||
|
||||
Reference in New Issue
Block a user