-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWirelessMain.py.save
More file actions
45 lines (39 loc) · 1.67 KB
/
Copy pathWirelessMain.py.save
File metadata and controls
45 lines (39 loc) · 1.67 KB
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
import WirelessTool, socket, traceback, colorama, time
colorama.init()
mainServer = WirelessTool.TCPEchoServer(3000,0.1)
while(not mainServer.connect(10)):
print(colorama.Fore.YELLOW + '[INFO]\t' + colorama.Style.RESET_ALL + "Waiting Subprocess Connection")
def decodeCommand(rawData):
recvLength = len(rawData)
if(recvLength < 1):
return [('Z', 0, '0')]
else:
rawData = rawData.split('\t')
dataList = []
for element in rawData:
if(len(element) == 0): # Handles the extra '' sometime when spliting
continue
elif(element == 'Z'):
return [('Z', 0, '0')]
elif(element[0] == 't'): # Temperature sensor
dataList.append((element[0], int(element[1]), element[2:]))
elif(element)
else:
print('[ERROR]\tUnexpected command received:->' + element + '<-')
return dataList
mainServer.read() # Clear ultrasonic buffer
while(True):
try:
tempDataRaw = mainServer.read()
for dataType,index,data in decodeCommand(tempDataRaw):
if(dataType == 'Z'):
pass
elif(dataType == 't' and index == 1):
print(colorama.Fore.GREEN + '[TEMP1]\t' + colorama.Style.RESET_ALL + data)
elif(dataType == 't' and index == 2):
print(colorama.Fore.GREEN + '[TEMP2]\t' + colorama.Style.RESET_ALL + data)
except BaseException as e:
print(colorama.Fore.RED + '[ERROR]\t' + colorama.Style.RESET_ALL + e.message)
print(colorama.Fore.RED + '[ERROR]\t' + colorama.Style.RESET_ALL + traceback.format_exc())
mainServer.close()
break