diff --git a/candm.h b/candm.h index 0900343..690cf2c 100644 --- a/candm.h +++ b/candm.h @@ -362,8 +362,9 @@ typedef struct { domain socket. Version 6 (no authentication) : changed format of client accesses by index - (using new request/reply types), new fields and flags in NTP source request - and report, new commands: ntpdata, refresh, serverstats + (using new request/reply types) and manual timestamp, new fields and flags + in NTP source request and report, new commands: ntpdata, refresh, + serverstats */ #define PROTO_VERSION_NUMBER 6 @@ -461,7 +462,8 @@ typedef struct { #define RPY_SERVER_STATS 14 #define RPY_CLIENT_ACCESSES_BY_INDEX2 15 #define RPY_NTP_DATA 16 -#define N_REPLY_TYPES 17 +#define RPY_MANUAL_TIMESTAMP2 17 +#define N_REPLY_TYPES 18 /* Status codes */ #define STT_SUCCESS 0 @@ -569,7 +571,7 @@ typedef struct { } RPY_Rtc; typedef struct { - uint32_t centiseconds; + Float offset; Float dfreq_ppm; Float new_afreq_ppm; int32_t EOR; diff --git a/client.c b/client.c index fa9e14e..eae6983 100644 --- a/client.c +++ b/client.c @@ -2585,7 +2585,6 @@ process_cmd_settime(char *line) time_t now, new_time; CMD_Request request; CMD_Reply reply; - long offset_cs; double dfreq_ppm, new_afreq_ppm; double offset; @@ -2599,9 +2598,8 @@ process_cmd_settime(char *line) ts.tv_nsec = 0; UTI_TimespecHostToNetwork(&ts, &request.data.settime.ts); request.command = htons(REQ_SETTIME); - if (request_reply(&request, &reply, RPY_MANUAL_TIMESTAMP, 1)) { - offset_cs = ntohl(reply.data.manual_timestamp.centiseconds); - offset = 0.01 * (double)(int32_t)offset_cs; + if (request_reply(&request, &reply, RPY_MANUAL_TIMESTAMP2, 1)) { + offset = UTI_FloatNetworkToHost(reply.data.manual_timestamp.offset); dfreq_ppm = UTI_FloatNetworkToHost(reply.data.manual_timestamp.dfreq_ppm); new_afreq_ppm = UTI_FloatNetworkToHost(reply.data.manual_timestamp.new_afreq_ppm); printf("Clock was %.2f seconds fast. Frequency change = %.2fppm, new frequency = %.2fppm\n", diff --git a/cmdmon.c b/cmdmon.c index 8fcd71c..6057b10 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -568,14 +568,13 @@ static void handle_settime(CMD_Request *rx_message, CMD_Reply *tx_message) { struct timespec ts; - long offset_cs; - double dfreq_ppm, new_afreq_ppm; + double offset, dfreq_ppm, new_afreq_ppm; UTI_TimespecNetworkToHost(&rx_message->data.settime.ts, &ts); if (!MNL_IsEnabled()) { tx_message->status = htons(STT_NOTENABLED); - } else if (MNL_AcceptTimestamp(&ts, &offset_cs, &dfreq_ppm, &new_afreq_ppm)) { - tx_message->reply = htons(RPY_MANUAL_TIMESTAMP); - tx_message->data.manual_timestamp.centiseconds = htonl((int32_t)offset_cs); + } else if (MNL_AcceptTimestamp(&ts, &offset, &dfreq_ppm, &new_afreq_ppm)) { + tx_message->reply = htons(RPY_MANUAL_TIMESTAMP2); + tx_message->data.manual_timestamp.offset = UTI_FloatHostToNetwork(offset); tx_message->data.manual_timestamp.dfreq_ppm = UTI_FloatHostToNetwork(dfreq_ppm); tx_message->data.manual_timestamp.new_afreq_ppm = UTI_FloatHostToNetwork(new_afreq_ppm); } else { diff --git a/manual.c b/manual.c index e78b719..bf52d14 100644 --- a/manual.c +++ b/manual.c @@ -97,7 +97,8 @@ MNL_Finalise(void) /* ================================================== */ static void -estimate_and_set_system(struct timespec *now, int offset_provided, double offset, long *offset_cs, double *dfreq_ppm, double *new_afreq_ppm) +estimate_and_set_system(struct timespec *now, int offset_provided, double offset, + double *reg_offset, double *dfreq_ppm, double *new_afreq_ppm) { double agos[MAX_SAMPLES], offsets[MAX_SAMPLES]; double b0, b1; @@ -152,7 +153,7 @@ estimate_and_set_system(struct timespec *now, int offset_provided, double offset 0.0, skew); } - if (offset_cs) *offset_cs = (long)(0.5 + 100.0 * b0); + if (reg_offset) *reg_offset = b0; if (dfreq_ppm) *dfreq_ppm = 1.0e6 * freq; if (new_afreq_ppm) *new_afreq_ppm = LCL_ReadAbsoluteFrequency(); @@ -166,7 +167,7 @@ estimate_and_set_system(struct timespec *now, int offset_provided, double offset /* ================================================== */ int -MNL_AcceptTimestamp(struct timespec *ts, long *offset_cs, double *dfreq_ppm, double *new_afreq_ppm) +MNL_AcceptTimestamp(struct timespec *ts, double *reg_offset, double *dfreq_ppm, double *new_afreq_ppm) { struct timespec now; double offset, diff; @@ -203,7 +204,7 @@ MNL_AcceptTimestamp(struct timespec *ts, long *offset_cs, double *dfreq_ppm, dou samples[n_samples].orig_offset = offset; ++n_samples; - estimate_and_set_system(&now, 1, offset, offset_cs, dfreq_ppm, new_afreq_ppm); + estimate_and_set_system(&now, 1, offset, reg_offset, dfreq_ppm, new_afreq_ppm); return 1; diff --git a/manual.h b/manual.h index 06a5d02..7f3d0b2 100644 --- a/manual.h +++ b/manual.h @@ -33,7 +33,7 @@ extern void MNL_Initialise(void); extern void MNL_Finalise(void); -extern int MNL_AcceptTimestamp(struct timespec *ts, long *offset_cs, double *dfreq_ppm, double *new_afreq_ppm); +extern int MNL_AcceptTimestamp(struct timespec *ts, double *reg_offset, double *dfreq_ppm, double *new_afreq_ppm); extern void MNL_Enable(void); extern void MNL_Disable(void); diff --git a/pktlength.c b/pktlength.c index 84facb6..5f5014e 100644 --- a/pktlength.c +++ b/pktlength.c @@ -123,7 +123,7 @@ static const uint16_t reply_lengths[] = { RPY_LENGTH_ENTRY(null), /* NULL */ RPY_LENGTH_ENTRY(n_sources), /* N_SOURCES */ RPY_LENGTH_ENTRY(source_data), /* SOURCE_DATA */ - RPY_LENGTH_ENTRY(manual_timestamp), /* MANUAL_TIMESTAMP */ + 0, /* MANUAL_TIMESTAMP */ RPY_LENGTH_ENTRY(tracking), /* TRACKING */ RPY_LENGTH_ENTRY(sourcestats), /* SOURCESTATS */ RPY_LENGTH_ENTRY(rtc), /* RTC */ @@ -136,6 +136,7 @@ static const uint16_t reply_lengths[] = { RPY_LENGTH_ENTRY(server_stats), /* SERVER_STATS */ RPY_LENGTH_ENTRY(client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX2 */ RPY_LENGTH_ENTRY(ntp_data), /* NTP_DATA */ + RPY_LENGTH_ENTRY(manual_timestamp), /* MANUAL_TIMESTAMP2 */ }; /* ================================================== */