Clock Messages
Time synchronization types for multi-node and multi-process systems.
# simplified
from horus import Clock, TimeReference
Clock
Timestamp message for clock distribution across nodes.
Constructor
# simplified
clock = Clock(clock_ns=0, realtime_ns=0, sim_speed=1.0, paused=False, source=0, timestamp_ns=0)
Fields
| Field | Type | Description |
|---|
clock_ns | int | Clock time in nanoseconds |
realtime_ns | int | Real (wall) time in nanoseconds |
sim_speed | float | Simulation speed multiplier (1.0 = real-time) |
paused | bool | Whether the clock is paused |
source | int | Clock source: 0 = wall, 1 = sim, 2 = replay |
timestamp_ns | int | Message timestamp in nanoseconds |
Static Methods
| Method | Returns | Description |
|---|
Clock.wall_clock() | Clock | Create a wall clock (real time) |
Clock.sim_time(sim_ns, speed) | Clock | Create a simulation clock with given time and speed multiplier |
Clock.replay_time(replay_ns, speed) | Clock | Create a replay clock with given time and speed multiplier |
Methods
| Method | Returns | Description |
|---|
elapsed_since(earlier) | int | Elapsed time in nanoseconds since another clock reading |
is_paused() | bool | Check if the clock is paused |
Example
# simplified
# Wall clock
clock = Clock.wall_clock()
# Simulation clock at 2x speed
sim = Clock.sim_time(sim_ns=1_000_000_000, speed=2.0)
# Check elapsed time
elapsed = clock.elapsed_since(sim)
# Replay clock
replay = Clock.replay_time(replay_ns=500_000_000, speed=1.0)
print(replay.paused) # False
TimeReference
External time reference for synchronization (GPS, NTP, PTP).
Constructor
# simplified
tref = TimeReference(time_ref_ns=0, source="", offset_ns=0, timestamp_ns=0)
Fields
| Field | Type | Description |
|---|
time_ref_ns | int | External reference time in nanoseconds |
source | str | Time source name (e.g. "gps", "ntp", "ptp") |
offset_ns | int | Signed offset in nanoseconds (local_time - reference_time) |
timestamp_ns | int | Message timestamp in nanoseconds |
Methods
| Method | Returns | Description |
|---|
correct_timestamp(local_ns) | int | Correct a local timestamp using this reference's offset |
Example
# simplified
tref = TimeReference(time_ref_ns=1_000_000_000, source="gps", offset_ns=-500)
corrected = tref.correct_timestamp(local_ns=1_000_000_500)
See Also