Move estimated offset and error to sourcestats report

And print the estimated offset in sourcestats output.
This commit is contained in:
Miroslav Lichvar 2009-12-13 14:53:58 +01:00
parent feb86e336a
commit b32432c232
9 changed files with 56 additions and 47 deletions

View file

@ -475,8 +475,6 @@ typedef struct {
Float orig_latest_meas;
Float latest_meas;
Float latest_meas_err;
Float est_offset;
Float est_offset_err;
int32_t EOR;
} RPY_Source_Data;
@ -503,6 +501,8 @@ typedef struct {
Float sd;
Float resid_freq_ppm;
Float skew_ppm;
Float est_offset;
Float est_offset_err;
int32_t EOR;
} RPY_Sourcestats;

View file

@ -3569,9 +3569,9 @@ An example report is
@example
@group
210 Number of sources = 1
Name/IP Address NP NR Span Frequency Freq Skew Std Dev
========================================================================
abc.def.ghi 11 5 46m -0.001 0.045 25us
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
===============================================================================
abc.def.ghi 11 5 46m -0.001 0.045 1us 25us
@end group
@end example
@ -3609,6 +3609,9 @@ million. In this case, the computer's clock is estimated to be running
This is the estimated error bounds on @code{Freq} (again in parts per
million).
@item Offset
This is the estimated offset of the source.
@item Std Dev
This is the estimated sample standard deviation.

View file

@ -1553,9 +1553,8 @@ process_cmd_sources(char *line)
int n_sources, i;
int verbose = 0;
double orig_latest_meas, latest_meas, est_offset;
double orig_latest_meas, latest_meas, latest_meas_err;
IPAddr ip_addr;
double latest_meas_err, est_offset_err;
uint32_t latest_meas_ago;
uint16_t poll, stratum;
uint16_t state, mode;
@ -1583,7 +1582,7 @@ process_cmd_sources(char *line)
printf("MS Name/IP address Stratum Poll LastRx Last sample\n");
printf("============================================================================\n");
/* "MS NNNNNNNNNNNNNNNNNNNNNNNNN SS PP RRRR SSSSSSS[SSSSSSS] +/- SSSSSS" */
/* "MS NNNNNNNNNNNNNNNNNNNNNNNNN SS PP RRRR SSSSSSS[SSSSSSS] +/- SSSSSS" */
for (i=0; i<n_sources; i++) {
request.command = htons(REQ_SOURCE_DATA);
@ -1598,8 +1597,6 @@ process_cmd_sources(char *line)
orig_latest_meas = UTI_FloatNetworkToHost(reply.data.source_data.orig_latest_meas);
latest_meas = UTI_FloatNetworkToHost(reply.data.source_data.latest_meas);
latest_meas_err = UTI_FloatNetworkToHost(reply.data.source_data.latest_meas_err);
est_offset = UTI_FloatNetworkToHost(reply.data.source_data.est_offset);
est_offset_err = UTI_FloatNetworkToHost(reply.data.source_data.est_offset_err);
if (mode == RPY_SD_MD_REF) {
snprintf(hostname_buf, sizeof(hostname_buf), "%s", UTI_RefidToString(ip_addr.addr.in4));
@ -1663,7 +1660,7 @@ process_cmd_sourcestats(char *line)
char hostname_buf[32];
unsigned long n_samples, n_runs, span_seconds;
double resid_freq_ppm, skew_ppm, sd;
double resid_freq_ppm, skew_ppm, sd, est_offset, est_offset_err;
unsigned long ref_id;
IPAddr ip_addr;
@ -1678,16 +1675,17 @@ process_cmd_sourcestats(char *line)
printf(" / .- Number of residual runs with same sign.\n");
printf(" | / .- Length of measurement set (time).\n");
printf(" | | / .- Est. clock freq error (ppm).\n");
printf(" | | | / .- Est error in freq.\n");
printf(" | | | | / .- On the\n");
printf(" | | | | | / samples.\n");
printf(" | | | | | |\n");
printf(" | | | / .- Est. error in freq.\n");
printf(" | | | | / .- Est. offset.\n");
printf(" | | | | | | On the -.\n");
printf(" | | | | | | samples. \\\n");
printf(" | | | | | | |\n");
}
printf("Name/IP Address NP NR Span Frequency Freq Skew Std Dev\n");
printf("========================================================================\n");
printf("Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev\n");
printf("==============================================================================\n");
/* NNNNNNNNNNNNNNNNNNNNNNNNN NP NR SSSS FFFFFFFFFF SSSSSSSSSS SSSSSSS */
/* NNNNNNNNNNNNNNNNNNNNNNNNN NP NR SSSS FFFFFFFFFF SSSSSSSSSS SSSSSSS SSSSSS*/
for (i=0; i<n_sources; i++) {
request.command = htons(REQ_SOURCESTATS);
@ -1701,6 +1699,8 @@ process_cmd_sourcestats(char *line)
resid_freq_ppm = UTI_FloatNetworkToHost(reply.data.sourcestats.resid_freq_ppm);
skew_ppm = UTI_FloatNetworkToHost(reply.data.sourcestats.skew_ppm);
sd = UTI_FloatNetworkToHost(reply.data.sourcestats.sd);
est_offset = UTI_FloatNetworkToHost(reply.data.sourcestats.est_offset);
est_offset_err = UTI_FloatNetworkToHost(reply.data.sourcestats.est_offset_err);
if (ip_addr.family == IPADDR_UNSPEC)
snprintf(hostname_buf, sizeof(hostname_buf), "%s", UTI_RefidToString(ref_id));
@ -1713,7 +1713,9 @@ process_cmd_sourcestats(char *line)
printf("%-25s %2lu %2lu ", hostname_buf, n_samples, n_runs);
print_seconds(span_seconds);
printf(" %10.3f %10.3f ", resid_freq_ppm, skew_ppm);
printf(" %10.3f %10.3f ", resid_freq_ppm, skew_ppm);
print_signed_nanoseconds(est_offset);
printf(" ");
print_nanoseconds(sd);
printf("\n");
} else {

View file

@ -1043,8 +1043,6 @@ handle_source_data(CMD_Request *rx_message, CMD_Reply *tx_message)
tx_message->data.source_data.orig_latest_meas = UTI_FloatHostToNetwork(report.orig_latest_meas);
tx_message->data.source_data.latest_meas = UTI_FloatHostToNetwork(report.latest_meas);
tx_message->data.source_data.latest_meas_err = UTI_FloatHostToNetwork(report.latest_meas_err);
tx_message->data.source_data.est_offset = UTI_FloatHostToNetwork(report.est_offset);
tx_message->data.source_data.est_offset_err = UTI_FloatHostToNetwork(report.est_offset_err);
} else {
tx_message->status = htons(STT_NOSUCHSOURCE);
}
@ -1395,8 +1393,12 @@ handle_sourcestats(CMD_Request *rx_message, CMD_Reply *tx_message)
{
int status;
RPT_SourcestatsReport report;
struct timeval now_corr;
double local_clock_err;
LCL_ReadCookedTime(&now_corr, &local_clock_err);
status = SRC_ReportSourcestats(ntohl(rx_message->data.sourcestats.index),
&report);
&report, &now_corr);
if (status) {
tx_message->status = htons(STT_SUCCESS);
@ -1409,6 +1411,8 @@ handle_sourcestats(CMD_Request *rx_message, CMD_Reply *tx_message)
tx_message->data.sourcestats.resid_freq_ppm = UTI_FloatHostToNetwork(report.resid_freq_ppm);
tx_message->data.sourcestats.skew_ppm = UTI_FloatHostToNetwork(report.skew_ppm);
tx_message->data.sourcestats.sd = UTI_FloatHostToNetwork(report.sd);
tx_message->data.sourcestats.est_offset = UTI_FloatHostToNetwork(report.est_offset);
tx_message->data.sourcestats.est_offset_err = UTI_FloatHostToNetwork(report.est_offset_err);
} else {
tx_message->status = htons(STT_NOSUCHSOURCE);
}

View file

@ -47,8 +47,6 @@ typedef struct {
double orig_latest_meas; /* seconds */
double latest_meas; /* seconds */
double latest_meas_err; /* seconds */
double est_offset; /* seconds */
double est_offset_err; /* seconds */
} RPT_SourceReport ;
typedef struct {
@ -73,6 +71,8 @@ typedef struct {
double resid_freq_ppm;
double skew_ppm;
double sd;
double est_offset;
double est_offset_err;
} RPT_SourcestatsReport;
typedef struct {

View file

@ -956,7 +956,7 @@ SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now)
/* ================================================== */
int
SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report)
SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report, struct timeval *now)
{
SRC_Instance src;
@ -969,7 +969,7 @@ SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report)
report->ip_addr = *src->ip_addr;
else
report->ip_addr.family = IPADDR_UNSPEC;
SST_DoSourcestatsReport(src->stats, report);
SST_DoSourcestatsReport(src->stats, report, now);
return 1;
}
}

View file

@ -146,7 +146,7 @@ extern int SRC_IsSyncPeer(SRC_Instance inst);
extern int SRC_ReadNumberOfSources(void);
extern int SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now);
extern int SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report);
extern int SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report, struct timeval *now);
extern SRC_Type SRC_GetType(int index);

View file

@ -845,8 +845,7 @@ SST_LoadFromFile(SST_Stats inst, FILE *in)
void
SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timeval *now)
{
int n, nb;
double elapsed, sample_elapsed;
int n;
struct timeval ago;
if (inst->n_samples > 0) {
@ -858,27 +857,12 @@ SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timeval *now
UTI_DiffTimevals(&ago, now, &inst->sample_times[n]);
report->latest_meas_ago = ago.tv_sec;
if (inst->n_samples > 3) {
UTI_DiffTimevalsToDouble(&elapsed, now, &inst->offset_time);
nb = inst->best_single_sample;
UTI_DiffTimevalsToDouble(&sample_elapsed, now, &(inst->sample_times[nb]));
report->est_offset = inst->estimated_offset + elapsed * inst->estimated_frequency;
report->est_offset_err = (inst->estimated_offset_sd +
sample_elapsed * inst->skew +
(0.5*inst->root_delays[nb] + inst->root_dispersions[nb]));
} else {
report->est_offset = report->latest_meas;
report->est_offset_err = report->latest_meas_err;
}
} else {
report->latest_meas_ago = 86400 * 365 * 10;
report->orig_latest_meas = 0;
report->latest_meas = 0;
report->latest_meas_err = 0;
report->stratum = 0;
report->est_offset = 0;
report->est_offset_err = 0;
}
}
@ -893,10 +877,11 @@ SST_Skew_Direction SST_LastSkewChange(SST_Stats inst)
/* ================================================== */
void
SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report)
SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report, struct timeval *now)
{
double dspan;
int n;
double elapsed, sample_elapsed;
int n, nb;
report->n_samples = inst->n_samples;
report->n_runs = inst->nruns;
@ -905,8 +890,23 @@ SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report)
n = inst->n_samples - 1;
UTI_DiffTimevalsToDouble(&dspan, &inst->sample_times[n], &inst->sample_times[0]);
report->span_seconds = (unsigned long) (dspan + 0.5);
if (inst->n_samples > 3) {
UTI_DiffTimevalsToDouble(&elapsed, now, &inst->offset_time);
nb = inst->best_single_sample;
UTI_DiffTimevalsToDouble(&sample_elapsed, now, &(inst->sample_times[nb]));
report->est_offset = inst->estimated_offset + elapsed * inst->estimated_frequency;
report->est_offset_err = (inst->estimated_offset_sd +
sample_elapsed * inst->skew +
(0.5*inst->root_delays[nb] + inst->root_dispersions[nb]));
} else {
report->est_offset = inst->offsets[n];
report->est_offset_err = 0.5*inst->root_delays[n] + inst->root_dispersions[n];
}
} else {
report->span_seconds = 0;
report->est_offset = 0;
report->est_offset_err = 0;
}
report->resid_freq_ppm = 1.0e6 * inst->estimated_frequency;

View file

@ -140,7 +140,7 @@ extern int SST_LoadFromFile(SST_Stats inst, FILE *in);
extern void SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timeval *now);
extern void SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report);
extern void SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report, struct timeval *now);
typedef enum {
SST_Skew_Decrease,