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:
parent
6ec3dc1650
commit
01a29c7a11
6 changed files with 20 additions and 19 deletions
10
candm.h
10
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;
|
||||
|
|
6
client.c
6
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",
|
||||
|
|
9
cmdmon.c
9
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 {
|
||||
|
|
9
manual.c
9
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;
|
||||
|
||||
|
|
2
manual.h
2
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);
|
||||
|
|
|
@ -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 */
|
||||
};
|
||||
|
||||
/* ================================================== */
|
||||
|
|
Loading…
Reference in a new issue