Skip to content
Newer
Older
100644 65 lines (57 sloc) 1.47 KB
3c48fdc @sweemeng test client for putting test data sending data via arduino
authored
1 import serial
2
3 word_list = [
4 ['rock','stone','brick','sand'],
5 ['sea','river','lake','waterfall'],
6 ['boat','ship','raft','submarine'],
7 ['me','you','I','he','she'],
8 ['on','in','out','inside','outside'],
9 ['the','a','that','this'],
10 ['eating','sleeping','walking']
11 ]
12
13 def build_data():
14 header = ''
15 body = ':'
16 size = 28
17 for i in word_list:
18 tmp = ':'.join(i)
19 body = body + tmp + ':'
20 t_size = size + len(body)
21 print t_size
22 b = int_to_byte(t_size)
23 header = header + b
24 return (header,body)
25
26 def send_data(data):
27 tmp = '<'+data+'>'
28 s = serial.Serial('/dev/ttyUSB0',9600)
29 for i in tmp:
30 s.write(i)
31 v = s.read()
965b167 @sweemeng fix readme
authored
32 if i != v:
3c48fdc @sweemeng test client for putting test data sending data via arduino
authored
33 if(ord(v) in range(0,10)):
34 if(ord(i) in range(0,10)):
35 print '%s:%s' % (str(ord(i)),str(ord(v)))
36 else:
37 print '%s:%s' % (i,str(ord(v)))
38 else:
39 print '%s:%s' % (i,v)
40 s.close()
41
42
43 def int_to_byte(val):
44 t = ''
45 v = val
46 while v:
47 r = v % 10
48 t = chr(r) + t
49 v = int(v/10)
50 while len(t) < 4:
51 t = '\x00' + t
52 return t
53
54 def run():
55 t = build_data()
56 send_data(t[0]+t[1])
57
58 def byte_to_int(val):
59 tn = 1000
60 t = 0
61 for i in val:
62 t = ord(i) * tn + t
63 tn = tn / 10
64 return t
Something went wrong with that request. Please try again.