long offset_cs;
double dfreq_ppm, new_afreq_ppm;
UTI_TimevalNetworkToHost(&rx_message->data.settime.ts, &ts);
- if (MNL_AcceptTimestamp(&ts, &offset_cs, &dfreq_ppm, &new_afreq_ppm)) {
+ if (!MNL_IsEnabled()) {
+ tx_message->status = htons(STT_NOTENABLED);
+ } else if (MNL_AcceptTimestamp(&ts, &offset_cs, &dfreq_ppm, &new_afreq_ppm)) {
tx_message->status = htons(STT_SUCCESS);
tx_message->reply = htons(RPY_MANUAL_TIMESTAMP);
tx_message->data.manual_timestamp.centiseconds = htonl((int32_t)offset_cs);
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 {
- tx_message->status = htons(STT_NOTENABLED);
+ tx_message->status = htons(STT_FAILED);
}
}
(measured-predicted)) */
} Sample;
+#define MIN_SAMPLE_SEPARATION 1.0
+
#define MAX_SAMPLES 16
static Sample samples[16];
MNL_AcceptTimestamp(struct timeval *ts, long *offset_cs, double *dfreq_ppm, double *new_afreq_ppm)
{
struct timeval now;
- double offset;
+ double offset, diff;
int i;
if (enabled) {
-
- /* Check whether timestamp is within margin of old one */
LCL_ReadCookedTime(&now, NULL);
+ /* Make sure the provided timestamp is sane and the sample
+ is not too close to the last one */
+
+ if (!UTI_IsTimeOffsetSane(ts, 0.0))
+ return 0;
+
+ if (n_samples) {
+ UTI_DiffTimevalsToDouble(&diff, &now, &samples[n_samples - 1].when);
+ if (diff < MIN_SAMPLE_SEPARATION)
+ return 0;
+ }
+
UTI_DiffTimevalsToDouble(&offset, &now, ts);
/* Check if buffer full up */
n_samples = 0;
}
+/* ================================================== */
+
+int
+MNL_IsEnabled(void)
+{
+ return enabled;
+}
+
/* ================================================== */
/* Generate report data for the REQ_MANUAL_LIST command/monitoring
protocol */
extern void MNL_Enable(void);
extern void MNL_Disable(void);
extern void MNL_Reset(void);
+extern int MNL_IsEnabled(void);
extern void MNL_ReportSamples(RPT_ManualSamplesReport *report, int max, int *n);
extern int MNL_DeleteSample(int index);