forked from oracledeveloperslondon/droneAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
performActions.go
59 lines (52 loc) · 1.49 KB
/
performActions.go
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
package main
import (
"dronecore"
"net/http"
)
// locates the drone and commands it to perform specific simple axtions such as takeoff and land
func droneActionHandler(w http.ResponseWriter, request *http.Request) {
status := http.StatusOK
myDrone := drones.GetDrone(dronecore.GetDroneNameFromURI(request))
action := myDrone.GetAction(request)
if myDrone != nil {
Trace.Println("droneActionHandler drone is " + myDrone.GetName() + " action is " + action)
switch action {
case dronecore.TAKEOFF:
if myDrone.GetStatus() != dronecore.Flying {
go sendAction(action)
myDrone.Takeoff()
} else {
status = http.StatusBadRequest
}
case dronecore.LAND:
if myDrone.GetStatus() == dronecore.Flying {
go sendAction(action)
myDrone.Land()
} else {
status = http.StatusBadRequest
}
case dronecore.HOVER:
if myDrone.GetStatus() == dronecore.Flying {
myDrone.SetGaz(0)
myDrone.SetRoll(0)
myDrone.SetPitch(0)
myDrone.SetYaw(0)
} else {
status = http.StatusBadRequest
}
//// TODO: Implement other axtion types
// case "cutpower",
// "return",
// "startFollowing", "stopFollowing":
// Warning.Println("Request not implemented " + action)
// status = http.StatusNotImplemented
default:
Warning.Println("Unknown action requested " + action)
status = http.StatusNotImplemented
}
} else {
Warning.Println("No drone identified so cant process request")
status = http.StatusBadRequest
}
w.WriteHeader(status)
}