comparison server/ts.py @ 25:2943f62c8e62

- Make the python work on openwrt - main.c: Stay awake for testing print CRC as unsigned
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jun 2012 23:05:35 +0800
parents 44c5ab5ea879
children d3e5934fe55c
comparison
equal deleted inserted replaced
24:44c5ab5ea879 25:2943f62c8e62
9 9
10 # avoid turning off the bluetooth etc. 10 # avoid turning off the bluetooth etc.
11 TESTING = True 11 TESTING = True
12 12
13 import sys 13 import sys
14 import httplib 14 #import httplib
15 import time 15 import time
16 import traceback 16 import traceback
17 17
18 from utils import monotonic_time, retry, readline 18 from utils import monotonic_time, retry, readline
19 19
31 else: 31 else:
32 s = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) 32 s = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
33 s.connect((addr, 1)) 33 s.connect((addr, 1))
34 34
35 s.setblocking(False) 35 s.setblocking(False)
36
37 time.sleep(30)
38 36
39 return s 37 return s
40 38
41 # from http://blog.stalkr.net/2011/04/pctf-2011-32-thats-no-bluetooth.html 39 # from http://blog.stalkr.net/2011/04/pctf-2011-32-thats-no-bluetooth.html
42 def crc16(buff, crc = 0, poly = 0x8408): 40 def crc16(buff, crc = 0, poly = 0x8408):
85 83
86 l = readline(sock) 84 l = readline(sock)
87 recv_crc = None 85 recv_crc = None
88 try: 86 try:
89 k, v = l.rstrip('\n').split('=') 87 k, v = l.rstrip('\n').split('=')
88 print k,v
90 if k == 'CRC': 89 if k == 'CRC':
91 recv_crc = int(v) 90 recv_crc = int(v)
92 if recv_crc < 0 or recv_crc > 0xffff: 91 if recv_crc < 0 or recv_crc > 0xffff:
93 recv_crc = None 92 recv_crc = None
94 except ValueError: 93 except ValueError:
120 print>>sys.stderr, "Bad response to btoff '%s'\n" % l 119 print>>sys.stderr, "Bad response to btoff '%s'\n" % l
121 120
122 return int(next_wake) 121 return int(next_wake)
123 122
124 def do_comms(sock): 123 def do_comms(sock):
124 print "do_comms"
125 d = None 125 d = None
126 # serial could be unreliable, try a few times 126 # serial could be unreliable, try a few times
127 for i in range(FETCH_TRIES): 127 for i in range(FETCH_TRIES):
128 d = fetch(sock) 128 d = fetch(sock)
129 if d: 129 if d: