comparison server/ts.py @ 32:e18d7e89c17d

More minor work
author Matt Johnston <matt@ucc.asn.au>
date Thu, 14 Jun 2012 00:00:57 +0800
parents 048143905092
children 79124d7d3f79
comparison
equal deleted inserted replaced
31:5e75e08d20ac 32:e18d7e89c17d
107 if off != 'Off': 107 if off != 'Off':
108 print>>sys.stderr, "Bad response to btoff '%s'\n" % l 108 print>>sys.stderr, "Bad response to btoff '%s'\n" % l
109 109
110 return int(next_wake) 110 return int(next_wake)
111 111
112 @retry()
113 def clear_meas(sock):
114 sock.send("clear\n");
115 l = readline(sock)
116 if l and l.rstrip() == 'cleared':
117 return True
118
119 print>>sys.stderr, "Bad response to clear %s\n" % str(l)
120 return False
121
112 def send_results(lines): 122 def send_results(lines):
113 enc_lines = binascii.b2a_base64(zlib.compress('\n'.join(lines))) 123 enc_lines = binascii.b2a_base64(zlib.compress('\n'.join(lines)))
114 hmac.new(config.HMAC_KEY, enc_lines).hexdigest() 124 hmac.new(config.HMAC_KEY, enc_lines).hexdigest()
115 125
116 url_data = urllib.url_encode( ('lines', enc_lines), ('hmac', mac) ) 126 url_data = urllib.url_encode( ('lines', enc_lines), ('hmac', mac) )
117 con = urllib2.urlopen(config.UPDATE_URL, url_data) 127 con = urllib2.urlopen(config.UPDATE_URL, url_data)
118 128 result = con.read(100)
129 if result == 'OK':
130 return True
131 else:
132 print>>sys.stderr, "Bad result '%s'" % result
133 return False
119 134
120 def do_comms(sock): 135 def do_comms(sock):
121 print "do_comms" 136 print "do_comms"
122 d = None 137 d = None
123 # serial could be unreliable, try a few times 138 # serial could be unreliable, try a few times