-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerMessenger.py
More file actions
executable file
·52 lines (41 loc) · 1.31 KB
/
ServerMessenger.py
File metadata and controls
executable file
·52 lines (41 loc) · 1.31 KB
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
#!/usr/bin/python
import requests
import json
import Constants
from Drone import *
class ServerMessenger:
def __init__(self):
baseAddress = Constants.SERVER_BASE_ADDR
self.fullAddress = baseAddress + '/drone'
self.tickingAddress = baseAddress + '/test'
def getInstructionsFromServer(self, drone):
url = self.fullAddress + '/' + drone.uid
response = requests.get(url)
data = json.loads(response.text)
return data
def notifyServerForTick(self):
requests.get(self.tickingAddress)
def postTestCase(self, noFlyZones, mannedAviation):
pass
# Update the server using a PUT request.
def updateServer(self, drone):
headers = {'content-type': 'application/json'}
vel = drone.velocityVector
currentPolar = drone.polarPosition
payload = {
'uid':drone.did,
'velocity': {
'x': vel.x,
'y': vel.y,
'z': vel.z
},
'position': {
'x': currentPolar.lat,
'y': currentPolar.lng,
'z': currentPolar.alt
},
'status':drone.status,
'waypoints': drone.waypoints
}
url = self.fullAddress + '/' + drone.did
response = requests.put(url, data=json.dumps(payload), headers=headers)