-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (36 loc) · 1.72 KB
/
main.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
import zmq
import argparse
import AI_stream
if __name__ == "__main__":
# Parse cmd arguments -> HoloLens IP Address
parser = argparse.ArgumentParser()
parser.add_argument("--host", required=True, help="Indicate the HoloLens IP address")
args = parser.parse_args()
# Initialize TCP communications
context = zmq.Context()
client_socket = context.socket(zmq.REP)
client_socket.bind("tcp://*:5555")
AIServer = AI_stream.AIServer(args.host)
# Start requests server
while(True):
print("Server ready for requests") # Start, SetActiveClassList, GetObjectList or Stop
request = client_socket.recv() # Code blocks here until a request is received
print(f"Received request: {request.decode('UTF-8')}") # decode from bytes to str
# Turn on sensor streaming
#if request.decode('UTF-8') == "Start":
if request.decode('UTF-8') == "Start":
response = AIServer.ServerStart()
# If header is ACL, set ActiveClassList
elif request.decode('UTF-8').split(' ')[0] == "ACL":
response = AIServer.ServerSetActiveClassList(request.decode('UTF-8').split(' ')[1:])
# If header is OL, return the ObjectList with requested information
elif request.decode('UTF-8').split(' ')[0] == "OL":
response = AIServer.ServerGetObjectList(request.decode('UTF-8').split(' ')[1:])
# Turn off sensor streaming
elif request.decode('UTF-8') == "Stop":
response = AIServer.ServerStop()
else:
response = "Unknown command"
# Answer to the client
print(response)
client_socket.send_string(response)