-
Notifications
You must be signed in to change notification settings - Fork 6
/
dogs_client_raspberry.py
61 lines (54 loc) · 1.25 KB
/
dogs_client_raspberry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
# 引入必要的module
import serial
import socket
import pickle
import time
def main():
# read serial
x = serial.Serial('/dev/ttyUSB0', 115200)
r = []
num = 0
num1 = 0
length = 0
j = 0
s = socket.socket()
host = 'server.blackant.org'
# host = '180.109.138.23'
port = 12343
s.connect((host, port))
while True:
str_read = x.read()
# print(str_read)
i = ['%02x' % b for b in str_read]
# print(str_read_byte)
print(i)
if i[0] == 'aa' and num == 0:
num = num + 1
continue
elif i[0] == 'aa' and num == 1:
num = num + 1
continue
elif i[0] == 'f1' and num == 2:
num = num + 1
continue
if num == 3:
length = int(i[0], 16)
num = num + 1
continue
if num > 3 and num < 26:
r.extend(i)
num = num + 1
if len(r) == 21:
print('ii', r)
a = pickle.dumps(r)
s.send(a)
time.sleep(1)
if num == 26:
num = 0
num1 = 0
r = []
s.close()
if __name__ == "__main__":
main()