Mercurial > templog
comparison server/ts.py @ 27:dbbd503119ba
Add some web server handling
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 12 Jun 2012 00:09:09 +0800 |
parents | d3e5934fe55c |
children | e3e0ed7758f9 |
comparison
equal
deleted
inserted
replaced
26:d3e5934fe55c | 27:dbbd503119ba |
---|---|
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 # for wrt |
15 sys.path.append('/root/python') | |
16 import httplib | |
15 import time | 17 import time |
16 import traceback | 18 import traceback |
17 | 19 |
18 from utils import monotonic_time, retry, readline, crc16 | 20 from utils import monotonic_time, retry, readline, crc16 |
19 | 21 |
58 crc = crc16(l, crc) | 60 crc = crc16(l, crc) |
59 | 61 |
60 if l == 'END\n': | 62 if l == 'END\n': |
61 break | 63 break |
62 | 64 |
63 lines.append(l) | 65 lines.append(l.rstrip('\n')) |
64 | 66 |
65 print lines | 67 print lines |
66 | 68 |
67 l = readline(sock) | 69 l = readline(sock) |
68 recv_crc = None | 70 recv_crc = None |
82 | 84 |
83 if recv_crc != crc: | 85 if recv_crc != crc: |
84 print>>sys.stderr, "Bad CRC: calculated 0x%x vs received 0x%x\n" % (crc, recv_crc) | 86 print>>sys.stderr, "Bad CRC: calculated 0x%x vs received 0x%x\n" % (crc, recv_crc) |
85 return None | 87 return None |
86 | 88 |
87 return ''.join(lines) | 89 return lines |
88 | 90 |
89 @retry() | 91 @retry() |
90 def turn_off(sock): | 92 def turn_off(sock): |
91 if TESTING: | 93 if TESTING: |
92 return None | 94 return None |
113 break | 115 break |
114 time.sleep(1) | 116 time.sleep(1) |
115 if not d: | 117 if not d: |
116 return | 118 return |
117 | 119 |
118 res = send_results() | 120 res = send_results(d) |
119 if not res: | 121 if not res: |
120 return | 122 return |
121 | 123 |
122 clear_meas(sock) | 124 clear_meas(sock) |
123 | 125 |