]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: report offset after manual timestamp as float
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 25 Jul 2017 08:53:48 +0000 (10:53 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 25 Jul 2017 15:40:35 +0000 (17:40 +0200)
Modify the protocol to report the offset as seconds in floating point
instead of integer number of centiseconds.

candm.h
client.c
cmdmon.c
manual.c
manual.h
pktlength.c

diff --git a/candm.h b/candm.h
index 0900343c9014596cbda508bcc7e41014272c907d..690cf2cd72c95ff79382bb52c34e340bbdbb4be9 100644 (file)
--- 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;
index fa9e14e916d026a79d1cc8d92831791e673b3850..eae69832033d15441d50b0e6db8957964c78b77c 100644 (file)
--- 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",
index 8fcd71cd09503a80d25a272222853a3ac51244d0..6057b108365e46197556ceae200b53b16ff6a40a 100644 (file)
--- 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 {
index e78b71935eafed83afc79d3eb8f3701b6f04b8ec..bf52d14e0c609f8ba5b2bef62ab4a5bbe86d71ce 100644 (file)
--- 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;
 
index 06a5d024d8206a177e240d0821a36ac93ebb5a3d..7f3d0b296e7a1a248ceb4a4c0e52607e07c62fa1 100644 (file)
--- 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);
index 84facb60d64fe0057d05c8e658439ef3ee880bfb..5f5014e731f4a23a6363d6bc85a26bbf4e1df745 100644 (file)
@@ -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 */
 };
 
 /* ================================================== */