-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAATC_Monitor.py
153 lines (117 loc) · 5.03 KB
/
AATC_Monitor.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#AATC Monitor system
# Used to display the flights of drones
import socket,codecs,ast,recvall,sys,AATC_Crypto
class MonitorInterface:
"""Interface with which to allow a monitor to communicate with the server.
In essence, a cut down User with access to some other User's drone,flight,waypoint data
This will be used to display an approximatly real time view of the drones flying
A Monitor can access all public visible drones as well as those which it has been given access to.
These two sets are accessed seperatly.
"""
def __init__(self,Connection):
self._con = Connection
self._Crypto = AATC_Crypto.Crypter(self._con)
self._MonitorName = ""
print("Welcome to the AATC Connection interface")
def Send(self,Code,data):
Info = self._Crypto.Encrypt(codecs.encode(str((Code,data))))
self._con.sendall(Info)
def Recv(self): #Returns tuple of Sucess,Message,Data of which data may just be useless for that function
try:
data = self._Crypto.Decrypt(recvall.recvall(self._con))
data = ast.literal_eval(codecs.decode(data))
# Sucess, Message , Data
return data[0],data[1],data[2]
except Exception as e:
print("Socket data receive error")
print(str(e))
return (False,"Conversion/Transfer Error"+str(e),[])
##############################
def Login(self,MonitorName,MonitorPassword):
self._MonitorName = MonitorName
self.Send("Login",(MonitorName,MonitorPassword))
Sucess,Message,_ = self.Recv()
return Sucess,Message
def MonitorChangePassword(self,OldPassword,NewPassword):
self.Send("MonitorChangePassword",(OldPassword,NewPassword))
Sucess,Message,_ = self.Recv()
return Sucess,Message
def GetNoFlyZones(self):
self.Send("GetNoFlyZones",())
Sucess,Message,NoFlyZones = self.Recv()
return Sucess,Message,NoFlyZones
def GetDronesAll(self):
self.Send("GetDronesAll",())
Sucess,Message,DronesAll = self.Recv()
return Sucess,Message,DronesAll
def GetUserID(self,Username):
self.Send("GetUserID",(Username,))
Sucess,Message,UserID = self.Recv()
return Sucess,Message,UserID
def GetUsername(self,UserID):
self.Send("GetUsername",(UserID,))
Sucess,Message,Username = self.Recv()
return Sucess,Message,Username
def AddMonitor(self,MonitorName,MonitorPassword):
self.Send("AddMonitor",(MonitorName,MonitorPassword))
Sucess,Message,_ = self.Recv()
return Sucess,Message
def GetMonitorDrones(self):
self.Send("GetMonitorDrones",())
Sucess,Message,DronesMonitor = self.Recv()
return Sucess,Message,DronesMonitor
def GetMonitorFlights(self):
self.Send("GetMonitorFlights",())
Sucess,Message,FlightsMonitor = self.Recv()
return Sucess,Message,FlightsMonitor
def GetMonitorFlightWaypoints(self):
self.Send("GetMonitorFlightWaypoints",())
Sucess,Message,WaypointsMonitor = self.Recv()
return Sucess,Message,WaypointsMonitor
def GetMonitorID(self,MonitorName):
self.Send("GetMonitorID",(MonitorName,))
Sucess,Message,MonitorID = self.Recv()
return Sucess,Message,MonitorID
def GetMonitorName(self,MonitorID):
self.Send("GetMonitorName",(MonitorID,))
Sucess,Message,MonitorName = self.Recv()
return Sucess,Message,MonitorName
def RemoveMonitorPermission(self,UserID):
self.Send("RemoveMonitorPermission",(UserID,))
Sucess,Message,_ = self.Recv()
return Sucess,Message
def GetMonitorPermissionMonitor(self):
self.Send("GetMonitorPermissionMonitor",())
Sucess,Message,MonitorPermissionMonitor = self.Recv()
return Sucess,Message,MonitorPermissionMonitor
def GetFlightsAll(self):
self.Send("GetFlightsAll",())
Sucess,Message,FlightsAll = self.Recv()
return Sucess,Message,FlightsAll
def GetFlightWaypointsAll(self):
self.Send("GetFlightWaypointsAll",())
Sucess,Message,WaypointsAll = self.Recv()
return Sucess,Message,WaypointsAll
def Exit(self):
self.Send("Exit",())
Sucess,Message,_ = self.Recv()
self._con.close()
return Sucess,Message
def Connect(remote_ip,PORT): #Connect to server
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect((remote_ip, PORT))
print("Connected to > "+ remote_ip+":"+str(PORT))
return s
except Exception as e:
print("Error binding port")
print(e)
print("Check address and port is up")
print("Otherwise check server is functional")
print("Exiting...")
sys.exit()
def CreateMonitorInterface(IP = "192.168.0.19",Port = 8001): #Create interface to server
soc = Connect(IP,Port)
M = MonitorInterface(soc)
return M