Communication Library for Autonomous Systems v1.0
Reliable and secure communication library for autonomous vehicle systems
|
Thread-safe singleton for PTP clock synchronization. More...
#include <clock.h>
Public Types | |
enum class | State { UNSYNCHRONIZED , AWAITING_SECOND_MSG , SYNCHRONIZED } |
Public Member Functions | |
Clock (const Clock &)=delete | |
Clock & | operator= (const Clock &)=delete |
void | setSelfId (LeaderIdType id) |
Set the self ID for this clock instance (node's own PTP-relevant ID) | |
void | activate (const PtpRelevantData *new_msg_data) |
Activate the state machine with new PTP data. | |
TimestampType | getSynchronizedTime (bool *is_synchronized) |
Get the current synchronized time. | |
bool | isFullySynchronized () const |
Check if clock is fully synchronized. | |
State | getState () |
Get current synchronization state. | |
LeaderIdType | getCurrentLeader () const |
Get the current PTP leader ID. | |
TimestampType | getLocalSteadyHardwareTime () const |
TimestampType | getLocalSystemTime () |
DurationType | getMaxLeaderSilenceInterval () const |
void | reset () |
Reset the Clock singleton to its initial state (for testing only) | |
Static Public Member Functions | |
static Clock & | getInstance () |
Get the singleton instance. | |
Thread-safe singleton for PTP clock synchronization.
This class is thread-safe and can be accessed from multiple threads. All state access is protected by mutex locks. The singleton instance is initialized in a thread-safe manner using C++11's static initialization guarantees.
|
strong |
|
inline |
Activate the state machine with new PTP data.
new_msg_data | PTP data from incoming message or nullptr for timeout checks |
Thread-safe: Protected by mutex
|
inline |
Get the current PTP leader ID.
Thread-safe: Protected by mutex
|
inlinestatic |
Get the singleton instance.
Thread-safe: Uses C++11's static initialization guarantees
|
inline |
|
inline |
|
inline |
|
inline |
Get current synchronization state.
Thread-safe: Protected by mutex
|
inline |
Get the current synchronized time.
Thread-safe: Protected by mutex
|
inline |
Check if clock is fully synchronized.
Thread-safe: Protected by mutex
|
inline |
Reset the Clock singleton to its initial state (for testing only)
This method is NOT thread-safe and should only be used in test setup/teardown.
|
inline |
Set the self ID for this clock instance (node's own PTP-relevant ID)
id | The LeaderIdType of this node |
Thread-safe: Protected by mutex