-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtello_command.py
executable file
·58 lines (45 loc) · 1.4 KB
/
tello_command.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
import threading
import socket
import time
"""
@brief Tello IP address. Use local IP address since
host computer/device is a WiFi client to Tello.
"""
tello_ip = "192.168.10.1"
"""
Tello port to send command message.
"""
command_port = 8889
"""
@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 = 9000
""" Welcome note """
print("\nTello Command 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 response message """
while self._running:
try:
msg, _ = self.sock.recvfrom(1024) # Read 1024-bytes from UDP socket
print("response: {}".format(msg.decode(encoding="utf-8")))
except Exception as err:
print(err)
def send(self, msg):
""" Handler for send message to Tello """
msg = msg.encode(encoding="utf-8")
self.sock.sendto(msg, (tello_ip, command_port))
print("message: {}".format(msg)) # Print message