mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 09:53:33 +08:00
GlobalTimeSyncSlave: methods isActive(), getMasterNodeID()
This commit is contained in:
@@ -19,6 +19,7 @@ void GlobalTimeSyncSlave::adjustFromMsg(const ReceivedDataStructure<protocol::Gl
|
||||
int(msg.getSrcNodeID().get()), int(msg.getIfaceIndex()));
|
||||
|
||||
getSystemClock().adjustUtc(adjustment);
|
||||
last_adjustment_ts_ = msg.getMonotonicTimestamp();
|
||||
state = Update;
|
||||
}
|
||||
|
||||
@@ -84,4 +85,15 @@ int GlobalTimeSyncSlave::start()
|
||||
return sub_.start(GlobalTimeSyncCallback(this, &GlobalTimeSyncSlave::handleGlobalTimeSync));
|
||||
}
|
||||
|
||||
bool GlobalTimeSyncSlave::isActive() const
|
||||
{
|
||||
const MonotonicDuration since_prev_adj = getSystemClock().getMonotonic() - last_adjustment_ts_;
|
||||
return !last_adjustment_ts_.isZero() && since_prev_adj.toMSec() <= protocol::GlobalTimeSync::PUBLISHER_TIMEOUT_MS;
|
||||
}
|
||||
|
||||
NodeID GlobalTimeSyncSlave::getMasterNodeID() const
|
||||
{
|
||||
return isActive() ? master_nid_ : NodeID();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user