Mercurial > templog
diff server/ts.py @ 24:44c5ab5ea879
- some fixes for server code
- don't turn off bluetooth in avr code
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Jun 2012 22:32:49 +0800 |
parents | b5925cb4f264 |
children | 2943f62c8e62 |
line wrap: on
line diff
--- a/server/ts.py Mon Jun 04 23:50:42 2012 +0800 +++ b/server/ts.py Wed Jun 06 22:32:49 2012 +0800 @@ -5,6 +5,8 @@ # time that the bluetooth takes to get going? EXTRA_WAKEUP = 0 +FETCH_TRIES = 3 + # avoid turning off the bluetooth etc. TESTING = True @@ -25,11 +27,14 @@ if lightblue: s = lightblue.socket() s.connect((addr, 1)) + s.settimeout(3) else: s = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) s.connect((addr, 1)) - s.setnonblocking(True) + s.setblocking(False) + + time.sleep(30) return s @@ -53,6 +58,7 @@ @retry() def fetch(sock): + print "fetch" sock.send("fetch\n") crc = 0 @@ -65,7 +71,7 @@ crc = crc16(l, crc) lines.append(l) - while true: + while True: l = readline(sock) crc = crc16(l, crc) @@ -75,6 +81,8 @@ lines.append(l) + print lines + l = readline(sock) recv_crc = None try: @@ -139,7 +147,7 @@ def sleep_for(secs): until = monotonic_time() + secs while True: - length = until < monotonic_time() + length = until - monotonic_time() if length <= 0: return time.sleep(length)