comparison server/utils.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
comparison
equal deleted inserted replaced
23:b5925cb4f264 24:44c5ab5ea879
1 import os 1 import os
2 import sys 2 import sys
3 import ctypes 3 import ctypes
4 import time 4 import time
5 import select 5 import select
6
7 lightblue = None
8 try:
9 import lightblue
10 except ImportError:
11 pass
6 12
7 DEFAULT_TRIES = 3 13 DEFAULT_TRIES = 3
8 READLINE_SELECT_TIMEOUT = 20 14 READLINE_SELECT_TIMEOUT = 20
9 15
10 __all__ = ('monotonic_time', 'retry') 16 __all__ = ('monotonic_time', 'retry')
55 return inner 61 return inner
56 62
57 def readline(sock): 63 def readline(sock):
58 timeout = READLINE_SELECT_TIMEOUT 64 timeout = READLINE_SELECT_TIMEOUT
59 buf = '' 65 buf = ''
60 while true: 66 while True:
61 (rlist, wlist, xlist) = select.select([sock], [], [], timeout) 67 if not lightblue:
62 if sock not in rlist: 68 (rlist, wlist, xlist) = select.select([sock], [], [], timeout)
63 # hit timeout 69 if sock not in rlist:
64 return None 70 # hit timeout
71 return None
65 72
66 c = sock.recv(1) 73 c = sock.recv(1)
74 if c == '':
75 # lightblue timeout
76 return None
67 if c == '\r': 77 if c == '\r':
68 continue 78 continue
69 79
70 buf.append(c) 80 buf.append(c)
71 if c == '\n': 81 if c == '\n':