cmdmon: report offset after manual timestamp as float

Modify the protocol to report the offset as seconds in floating point
instead of integer number of centiseconds.
This commit is contained in:
Miroslav Lichvar 2017-07-25 10:53:48 +02:00
parent 6ec3dc1650
commit 01a29c7a11
6 changed files with 20 additions and 19 deletions

10
candm.h
View file

@ -362,8 +362,9 @@ typedef struct {
domain socket. domain socket.
Version 6 (no authentication) : changed format of client accesses by index Version 6 (no authentication) : changed format of client accesses by index
(using new request/reply types), new fields and flags in NTP source request (using new request/reply types) and manual timestamp, new fields and flags
and report, new commands: ntpdata, refresh, serverstats in NTP source request and report, new commands: ntpdata, refresh,
serverstats
*/ */
#define PROTO_VERSION_NUMBER 6 #define PROTO_VERSION_NUMBER 6
@ -461,7 +462,8 @@ typedef struct {
#define RPY_SERVER_STATS 14 #define RPY_SERVER_STATS 14
#define RPY_CLIENT_ACCESSES_BY_INDEX2 15 #define RPY_CLIENT_ACCESSES_BY_INDEX2 15
#define RPY_NTP_DATA 16 #define RPY_NTP_DATA 16
#define N_REPLY_TYPES 17 #define RPY_MANUAL_TIMESTAMP2 17
#define N_REPLY_TYPES 18
/* Status codes */ /* Status codes */
#define STT_SUCCESS 0 #define STT_SUCCESS 0
@ -569,7 +571,7 @@ typedef struct {
} RPY_Rtc; } RPY_Rtc;
typedef struct { typedef struct {
uint32_t centiseconds; Float offset;
Float dfreq_ppm; Float dfreq_ppm;
Float new_afreq_ppm; Float new_afreq_ppm;
int32_t EOR; int32_t EOR;

View file

@ -2585,7 +2585,6 @@ process_cmd_settime(char *line)
time_t now, new_time; time_t now, new_time;
CMD_Request request; CMD_Request request;
CMD_Reply reply; CMD_Reply reply;
long offset_cs;
double dfreq_ppm, new_afreq_ppm; double dfreq_ppm, new_afreq_ppm;
double offset; double offset;
@ -2599,9 +2598,8 @@ process_cmd_settime(char *line)
ts.tv_nsec = 0; ts.tv_nsec = 0;
UTI_TimespecHostToNetwork(&ts, &request.data.settime.ts); UTI_TimespecHostToNetwork(&ts, &request.data.settime.ts);
request.command = htons(REQ_SETTIME); request.command = htons(REQ_SETTIME);
if (request_reply(&request, &reply, RPY_MANUAL_TIMESTAMP, 1)) { if (request_reply(&request, &reply, RPY_MANUAL_TIMESTAMP2, 1)) {
offset_cs = ntohl(reply.data.manual_timestamp.centiseconds); offset = UTI_FloatNetworkToHost(reply.data.manual_timestamp.offset);
offset = 0.01 * (double)(int32_t)offset_cs;
dfreq_ppm = UTI_FloatNetworkToHost(reply.data.manual_timestamp.dfreq_ppm); dfreq_ppm = UTI_FloatNetworkToHost(reply.data.manual_timestamp.dfreq_ppm);
new_afreq_ppm = UTI_FloatNetworkToHost(reply.data.manual_timestamp.new_afreq_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", printf("Clock was %.2f seconds fast. Frequency change = %.2fppm, new frequency = %.2fppm\n",

View file

@ -568,14 +568,13 @@ static void
handle_settime(CMD_Request *rx_message, CMD_Reply *tx_message) handle_settime(CMD_Request *rx_message, CMD_Reply *tx_message)
{ {
struct timespec ts; struct timespec ts;
long offset_cs; double offset, dfreq_ppm, new_afreq_ppm;
double dfreq_ppm, new_afreq_ppm;
UTI_TimespecNetworkToHost(&rx_message->data.settime.ts, &ts); UTI_TimespecNetworkToHost(&rx_message->data.settime.ts, &ts);
if (!MNL_IsEnabled()) { if (!MNL_IsEnabled()) {
tx_message->status = htons(STT_NOTENABLED); tx_message->status = htons(STT_NOTENABLED);
} else if (MNL_AcceptTimestamp(&ts, &offset_cs, &dfreq_ppm, &new_afreq_ppm)) { } else if (MNL_AcceptTimestamp(&ts, &offset, &dfreq_ppm, &new_afreq_ppm)) {
tx_message->reply = htons(RPY_MANUAL_TIMESTAMP); tx_message->reply = htons(RPY_MANUAL_TIMESTAMP2);
tx_message->data.manual_timestamp.centiseconds = htonl((int32_t)offset_cs); 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.dfreq_ppm = UTI_FloatHostToNetwork(dfreq_ppm);
tx_message->data.manual_timestamp.new_afreq_ppm = UTI_FloatHostToNetwork(new_afreq_ppm); tx_message->data.manual_timestamp.new_afreq_ppm = UTI_FloatHostToNetwork(new_afreq_ppm);
} else { } else {

View file

@ -97,7 +97,8 @@ MNL_Finalise(void)
/* ================================================== */ /* ================================================== */
static 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 agos[MAX_SAMPLES], offsets[MAX_SAMPLES];
double b0, b1; double b0, b1;
@ -152,7 +153,7 @@ estimate_and_set_system(struct timespec *now, int offset_provided, double offset
0.0, skew); 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 (dfreq_ppm) *dfreq_ppm = 1.0e6 * freq;
if (new_afreq_ppm) *new_afreq_ppm = LCL_ReadAbsoluteFrequency(); 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 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; struct timespec now;
double offset, diff; 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; samples[n_samples].orig_offset = offset;
++n_samples; ++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; return 1;

View file

@ -33,7 +33,7 @@
extern void MNL_Initialise(void); extern void MNL_Initialise(void);
extern void MNL_Finalise(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_Enable(void);
extern void MNL_Disable(void); extern void MNL_Disable(void);

View file

@ -123,7 +123,7 @@ static const uint16_t reply_lengths[] = {
RPY_LENGTH_ENTRY(null), /* NULL */ RPY_LENGTH_ENTRY(null), /* NULL */
RPY_LENGTH_ENTRY(n_sources), /* N_SOURCES */ RPY_LENGTH_ENTRY(n_sources), /* N_SOURCES */
RPY_LENGTH_ENTRY(source_data), /* SOURCE_DATA */ 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(tracking), /* TRACKING */
RPY_LENGTH_ENTRY(sourcestats), /* SOURCESTATS */ RPY_LENGTH_ENTRY(sourcestats), /* SOURCESTATS */
RPY_LENGTH_ENTRY(rtc), /* RTC */ 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(server_stats), /* SERVER_STATS */
RPY_LENGTH_ENTRY(client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX2 */ RPY_LENGTH_ENTRY(client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX2 */
RPY_LENGTH_ENTRY(ntp_data), /* NTP_DATA */ RPY_LENGTH_ENTRY(ntp_data), /* NTP_DATA */
RPY_LENGTH_ENTRY(manual_timestamp), /* MANUAL_TIMESTAMP2 */
}; };
/* ================================================== */ /* ================================================== */