-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtello-state.py
executable file
·62 lines (49 loc) · 1.42 KB
/
tello-state.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
60
61
import threading
import socket
import time
"""
@brief Host IP address. 0.0.0.0 referring to current
host/computer IP address.
"""
host_ip = "0.0.0.0"
"""
@brief UDP port to receive response msg from Tello.
Tello command response will send to this port.
"""
response_port = 8890
""" Welcome note """
print("\nTello Sensor States Program\n")
class Tello:
def __init__(self):
self._running = True
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.bind((host_ip, response_port)) # Bind for receiving
def terminate(self):
self._running = False
self.sock.close()
def recv(self):
""" Handler for Tello states message """
while self._running:
try:
msg, _ = self.sock.recvfrom(1024) # Read 1024-bytes from UDP socket
print("states: {}".format(msg.decode(encoding="utf-8")))
except Exception as err:
print(err)
""" Start new thread for receive Tello response message """
t = Tello()
recvThread = threading.Thread(target=t.recv)
recvThread.start()
while True:
try:
# Get input from CLI
msg = input()
# Check for "end"
if msg == "bye":
t.terminate()
recvThread.join()
print("\nGood Bye\n")
break
except KeyboardInterrupt:
t.terminate()
recvThread.join()
break