Go to the documentation of this file.
5 #ifndef UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED
6 #define UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED
10 #include <uavcan/protocol/GlobalTimeSync.hpp>
52 UAVCAN_TRACE(
"GlobalTimeSyncSlave",
"Adjustment: usec=%lli snid=%i iface=%i suppress=%i",
53 static_cast<long long>(adjustment.
toUSec()),
66 UAVCAN_TRACE(
"GlobalTimeSyncSlave",
"Update: snid=%i iface=%i",
82 const bool needs_init = !master_nid_.
isValid() || prev_ts_mono_.
isZero();
83 const bool switch_master = msg.
getSrcNodeID() < master_nid_;
85 const bool pub_timeout = since_prev_msg.
toMSec() > protocol::GlobalTimeSync::RECOMMENDED_BROADCASTER_TIMEOUT_MS;
87 if (switch_master || pub_timeout || needs_init)
89 UAVCAN_TRACE(
"GlobalTimeSyncSlave",
"Force update: needs_init=%i switch_master=%i pub_timeout=%i",
90 int(needs_init),
int(switch_master),
int(pub_timeout));
97 const bool msg_invalid = msg.previous_transmission_timestamp_usec == 0;
99 const bool wrong_timing = since_prev_msg.
toMSec() > protocol::GlobalTimeSync::MAX_BROADCASTING_PERIOD_MS;
100 if (msg_invalid || wrong_tid || wrong_timing)
103 "Adjustment skipped: msg_invalid=%i wrong_tid=%i wrong_timing=%i",
104 int(msg_invalid),
int(wrong_tid),
int(wrong_timing));
108 if (state_ == Adjust)
119 UAVCAN_TRACE(
"GlobalTimeSyncSlave",
"Ignored: snid=%i iface=%i",
140 , prev_iface_index_(0xFF)
168 void suppress(
bool suppressed) { suppressed_ = suppressed; }
180 return !last_adjustment_ts_.
isZero() &&
181 (since_prev_adj.
toMSec() <= protocol::GlobalTimeSync::RECOMMENDED_BROADCASTER_TIMEOUT_MS);
198 #endif // UAVCAN_PROTOCOL_GLOBAL_TIME_SYNC_SLAVE_HPP_INCLUDED
uint8_t getIfaceIndex() const
void adjustFromMsg(const ReceivedDataStructure< protocol::GlobalTimeSync > &msg)
bool isSuppressed() const
Implicitly convertible to/from uavcan.Timestamp.
void updateFromMsg(const ReceivedDataStructure< protocol::GlobalTimeSync > &msg)
MonotonicTime getLastAdjustmentTime() const
void suppress(bool suppressed)
NodeID getMasterNodeID() const
Subscriber< protocol::GlobalTimeSync, GlobalTimeSyncCallback > sub_
#define UAVCAN_TRACE(...)
int start(const Callback &callback)
static UtcTime fromUSec(uint64_t us)
@ TransferTypeMessageBroadcast
int computeForwardDistance(TransferID rhs) const
uint8_t prev_iface_index_
void processMsg(const ReceivedDataStructure< protocol::GlobalTimeSync > &msg)
UtcTime getUtcTimestamp() const
TransferID getTransferID() const
TransferType getTransferType() const
MonotonicTime last_adjustment_ts_
GlobalTimeSyncSlave(INode &node)
MonotonicTime prev_ts_mono_
virtual void adjustUtc(UtcDuration adjustment)=0
MonotonicTime getMonotonicTimestamp() const
NodeID getSrcNodeID() const
void handleGlobalTimeSync(const ReceivedDataStructure< protocol::GlobalTimeSync > &msg)
virtual MonotonicTime getMonotonic() const =0
ISystemClock & getSystemClock() const