summaryrefslogtreecommitdiff
path: root/ntpshm.c
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2009-11-12 00:31:19 +0000
committerGary E. Miller <gem@rellim.com>2009-11-12 00:31:19 +0000
commit2e64cf0383287a839874cc115e84ba0f875e783b (patch)
treea81ac5dd89d81782b47f28143e187a39fe53a48a /ntpshm.c
parent51e5fadd1b043df8ef4f2ad9f0987517f1634bad (diff)
downloadgpsd-2e64cf0383287a839874cc115e84ba0f875e783b.tar.gz
Added some comments to explain the ntpd algorithm
After staring that the ->valid patch I can see no harm and a less than several billion chance that this might actually stop sending a corrupt value to ntpd.
Diffstat (limited to 'ntpshm.c')
-rw-r--r--ntpshm.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/ntpshm.c b/ntpshm.c
index 8975fe7b..6ee65011 100644
--- a/ntpshm.c
+++ b/ntpshm.c
@@ -131,6 +131,20 @@ int ntpshm_put(struct gps_device_t *session, double fixtime)
(void)gettimeofday(&tv,NULL);
microseconds = 1000000.0 * modf(fixtime,&seconds);
+ /* we use the shmTime mode 1 protocol
+ *
+ * ntpd does this:
+ *
+ * reads valid.
+ * IFF valid is 1
+ * reads count
+ * reads values
+ * reads count
+ * IFF count unchanged
+ * use values
+ * clear valid
+ *
+ */
shmTime->valid = 0;
shmTime->count++;
shmTime->clockTimeStampSec = (time_t)seconds;
@@ -199,12 +213,27 @@ int ntpshm_pps(struct gps_device_t *session, struct timeval *tv)
}
}
+ /* we use the shmTime mode 1 protocol
+ *
+ * ntpd does this:
+ *
+ * reads valid.
+ * IFF valid is 1
+ * reads count
+ * reads values
+ * reads count
+ * IFF count unchanged
+ * use values
+ * clear valid
+ *
+ */
shmTimeP->valid = 0;
shmTimeP->count++;
shmTimeP->clockTimeStampSec = seconds;
shmTimeP->clockTimeStampUSec = 0;
shmTimeP->receiveTimeStampSec = (time_t)tv->tv_sec;
shmTimeP->receiveTimeStampUSec = (int)tv->tv_usec;
+ /* this is more a jitter/dispersion than precision, but still useful */
shmTimeP->precision = offset != 0 ? (int)(ceil(log(offset) / M_LN2)) : -20;
shmTimeP->count++;
shmTimeP->valid = 1;