summaryrefslogtreecommitdiff
path: root/contrib/ntpshmviz
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2015-05-08 18:56:53 -0700
committerGary E. Miller <gem@rellim.com>2015-05-08 18:56:53 -0700
commita5cfafa8f32fb6da2094bf4cae91f8070345771b (patch)
tree0f4ab89c745a4700a1392db86a641be8ba23adcd /contrib/ntpshmviz
parent955d3679ad44b8aa716fe8a35399c8316f783266 (diff)
downloadgpsd-a5cfafa8f32fb6da2094bf4cae91f8070345771b.tar.gz
Stop rounding nSec timespecs to 10 uSec. Fix divide by zero.
A timespec does not fit in a Python float. It does fit in a Numpy float128. Stop throwing away precision! Thanks to DrDaemonEye and Jon Schlueter <jon.schlueter@gmail.com>
Diffstat (limited to 'contrib/ntpshmviz')
-rwxr-xr-xcontrib/ntpshmviz15
1 files changed, 10 insertions, 5 deletions
diff --git a/contrib/ntpshmviz b/contrib/ntpshmviz
index 17c754d4..37118d1c 100755
--- a/contrib/ntpshmviz
+++ b/contrib/ntpshmviz
@@ -13,6 +13,8 @@
#
import gtk, stripchart, sys
+# need numpy for float128, normal python floats are too small to hold a timespec
+import numpy
class ntpOffset:
def __init__(self, stream):
@@ -92,6 +94,9 @@ class ntpOffset:
# gtk.Adjustment(value, lower, upper, step_incr, page_incr,
# page_size)
spread = self.ntp_upper[ntp_unit] - self.ntp_lower[ntp_unit]
+ # prevent divide by zero
+ if spread == 0:
+ spread = 1
vadj_ntp = gtk.Adjustment(
self.ntp_lower[ntp_unit], # initial value
self.ntp_lower[ntp_unit] - 0.001, # lower extreme
@@ -128,7 +133,7 @@ class ntpOffset:
if line[:1] != '#':
line = line.lstrip()
record = line.split(' ')
- offset = (float(record[3]) - float(record[4]))
+ offset = numpy.float128(record[3]) - numpy.float128(record[4])
# If the NTP unit is in the dictionary
# append the offset to the list
@@ -137,17 +142,17 @@ class ntpOffset:
if record[1] not in self.ntp_data:
self.ntp_data[record[1]] = []
line_counts[record[1]] = 0
- self.ntp_upper[record[1]] = round(offset, 5)
- self.ntp_lower[record[1]] = round(offset, 5)
+ self.ntp_upper[record[1]] = round(offset, 9)
+ self.ntp_lower[record[1]] = round(offset, 9)
self.ntp_data[record[1]].append(offset)
line_counts[record[1]] += 1
# Update the bounds of the NTP unit if needed
if offset > self.ntp_upper[record[1]]:
- self.ntp_upper[record[1]] = round(offset, 5)
+ self.ntp_upper[record[1]] = round(offset, 9)
if offset < self.ntp_lower[record[1]]:
- self.ntp_lower[record[1]] = round(offset, 5)
+ self.ntp_lower[record[1]] = round(offset, 9)
# Update the max record count if needed
if line_counts[record[1]] > self.lines: