-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
101 lines (79 loc) · 2.86 KB
/
app.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from sim_client import Ui_MainWindow
import sys
import requests
import subprocess
import os
import distro
from sys import platform
# check if distro is ubuntu 22.04
distro = distro.name(pretty=True).replace(" ", "_").replace(".", "_")
print(distro)
if "22_04" in distro:
print("setting qt platform to wayland")
os.environ['QT_QPA_PLATFORM'] = "wayland"
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
mavp2p_process = None
api_ip = "intelligentquads.com"
# TODO make node_ip querryable
http = "https"
def __init__(self, *args, obj=None, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowIcon(QtGui.QIcon('imgs/icon.png'))
self.setupUi(self)
self.connect_pb.clicked.connect(self.connect)
self.disconnect_pb.clicked.connect(self.disconnect)
test_env = os.getenv('TEST_ENV')
print(f"test env {test_env}")
if test_env == "TRUE":
self.api_ip = "localhost"
self.http = "http"
def request_connection(self, uuid):
print(f"requesting sim data from {self.api_ip}")
URL = f"{self.http}://{self.api_ip}/get_connection"
PARAMS = {'uuid': uuid}
r = requests.get(url=URL, params=PARAMS)
data = r.json()
print(data)
return data
def run_mavp2p(self, con_data):
# tcpc:164.92.113.203:30771 udpc:127.0.0.1:14550
client1_ip = self.mavlink1_ip.text()
client1_port = self.mavlink1_port_le.text()
client2_ip = self.mavlink2_ip.text()
client2_port = self.mavlink2_port_le.text()
client3_ip = self.mavlink3_ip.text()
client3_port = self.mavlink3_port_le.text()
if platform == "linux" or platform == "linux2":
mavp2p_path = "./mavp2p/mavp2p_linux/mavp2p"
elif platform == "darwin":
print("todo")
return
elif platform == "win32":
mavp2p_path = "./mavp2p/mavp2p_windows/mavp2p"
port = con_data["port"]
node_ip = con_data["ip"]
self.mavp2p_process = subprocess.Popen(
[f"{mavp2p_path}", f"tcpc:{node_ip}:{port}", f"udpc:{client1_ip}:{client1_port}", f"udpc:{client2_ip}:{client2_port}", f"udpc:{client3_ip}:{client3_port}"])
def connect(self):
uuid = self.sim_uuid_le.text()
print(f"uuid {uuid}")
self.disconnect()
data = self.request_connection(uuid)
self.run_mavp2p(data)
def disconnect(self):
if self.mavp2p_process:
print("disconnecting")
self.mavp2p_process.terminate()
self.mavp2p_process = None
print("done")
return
def main():
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
window.disconnect()
if __name__ == '__main__':
main()