/* * Copyright (C) 2014 Pavel Kirienko */ #pragma once #include #include #include namespace uavcan { /** * Ref. M. Gergeleit, H. Streich - "Implementing a Distributed High-Resolution Real-Time Clock using the CAN-Bus" * http://modecs.cs.uni-salzburg.at/results/related_documents/CAN_clock.pdf */ class UAVCAN_EXPORT GlobalTimeSyncSlave : Noncopyable { typedef MethodBinder&)> GlobalTimeSyncCallback; // Static buffers are explicitly disabled because time should never be unicasted. Subscriber sub_; UtcTime prev_ts_utc_; MonotonicTime prev_ts_mono_; MonotonicTime last_adjustment_ts_; enum State { Update, Adjust } state_; NodeID master_nid_; TransferID prev_tid_; uint8_t prev_iface_index_; bool suppressed_; ISystemClock& getSystemClock() const { return sub_.getNode().getSystemClock(); } void adjustFromMsg(const ReceivedDataStructure& msg); void updateFromMsg(const ReceivedDataStructure& msg); void processMsg(const ReceivedDataStructure& msg); void handleGlobalTimeSync(const ReceivedDataStructure& msg); public: explicit GlobalTimeSyncSlave(INode& node) : sub_(node) , state_(Update) , prev_iface_index_(0xFF) , suppressed_(false) { } int start(); void suppress(bool suppressed) { suppressed_ = suppressed; } bool isSuppressed() const { return suppressed_; } bool isActive() const; NodeID getMasterNodeID() const; MonotonicTime getLastAdjustmentTime() const { return last_adjustment_ts_; } }; }