Skip to content
lucaf edited this page Feb 14, 2018 · 4 revisions

Welcome to the NTPSync wiki!

NtpSync is a utility which implements an NTP client, based on Cristian's synchronization algorithm.

The package provides a C library and the relative Python wrapper plus an example of usage for python2.7 (NtpSyncTest.py). The NTP client runs in a thread.

Supported platforms: OS X, Linux

A brief description of the C API:

int ntp_sync_start(char *ip_address, double max_offset_ms, int inter_sync_delay_ms)

Start the synchronization thread

  • ip_address: IP address of the NTP server
  • max_offset_ms: maximum tolerated offset between clocks, in millisecs
  • inter_sync_delay_ms: period between syncronizations, in millisecs

void ntp_sync_stop()

Stop the synchronization thread

void ntp_sync_set_time(double ms)

Set the time zero value of the internal reference clock

  • ms: time value to set, in milliseconds

double ntp_sync_get_time()

Get a timestamp from the internal reference clock

double ntp_sync_start_time()

Get the time zero value of the internal reference clock

int ntp_sync_error()

Get the last error occurred

Possible values:

  • 0 = eNtpSyncError_no // all is fine
  • 1 = eNtpSyncError_send // connection issue
  • 2 = eNtpSyncError_receive // connection issue
  • 3 = eNtpSyncError_version // packet version issue
  • 4 = eNtpSyncError_kod // received a kiss of death packet
  • 5 = eNtpSyncError_unexpected // unexpected timestamp value
  • 6 = eNtpSyncError_accuracy_broken // failed to synchronize

void ntp_sync_on_error(tCbOnErr cb, void *prm)

Set a callback which will be executed whenever an error occurs

  • cb: callback function
  • prm: callback parameter

double ntp_sync_monotonic_time()

Utility function which provides a monotonic timestamp in milliseconds (unrelated to the internal reference clock)