[Git][NTPsec/ntpsec][master] ntpheatusb: retry TEMPer failures.
Gary E. Miller
gitlab at mg.gitlab.com
Wed Mar 29 00:42:35 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
f2c037ca by Gary E. Miller at 2017-03-28T17:42:17-07:00
ntpheatusb: retry TEMPer failures.
Wnen ntplogtemp and ntpheatusb both read the TEMPer both fail. So
retry a few times. Be sure to turn off the relay on exit.
- - - - -
1 changed file:
- contrib/ntpheatusb
Changes:
=====================================
contrib/ntpheatusb
=====================================
--- a/contrib/ntpheatusb
+++ b/contrib/ntpheatusb
@@ -27,6 +27,7 @@
# More info on the blog post: https://blog.ntpsec.org/2017/03/21/More_Heat.html
import argparse
+import atexit
import subprocess
import sys
import time
@@ -166,6 +167,9 @@ period = float(args.wait[0])
usbrelay_on = ['usbrelay', '959BI_1=1']
usbrelay_off = ['usbrelay', '959BI_1=0']
+# turn off the usb relay on exit. no need to cook..
+atexit.register(run_binary, usbrelay_off)
+
# to adjust the PID variables
# set I and D to zero
#
@@ -204,15 +208,25 @@ try:
step = -11
pid.setPoint(temp_gate)
- # grab the needed output
- output = run_binary(["temper-poll", "-c"])
- try:
- # make sure it is a temperature
- temp = float(output[0])
- except:
- # bad data, exit
- # FIXME, should try to recover?
- print("temper read failed: %s" % output)
+ # only one device can read the TEMPer at a time
+ # collisions will happen, so retry a few times
+ for attempt in range(0, 3):
+ # grab the needed output
+ fail = False
+ output = run_binary(["temper-poll", "-c"])
+ try:
+ # make sure it is a temperature
+ temp = float(output[0])
+ break
+ except:
+ # bad data, try aagin
+ fail = True
+ if args.verbose:
+ print("temper read failed: %s" % output)
+
+ if fail:
+ # give up
+ print("temper fatal error")
sys.exit(1)
# the +20 is to create an 80/20 band around the setpoint
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f2c037ca11c7b9de54af9e6f8f03581b3506e972
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170329/58307a2e/attachment.html>
More information about the vc
mailing list