-
Notifications
You must be signed in to change notification settings - Fork 4
/
performSimpleNavigations.go
93 lines (73 loc) · 2.41 KB
/
performSimpleNavigations.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
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
package main
import (
"dronecore"
"net/http"
"strconv"
//"github.com/gorilla/mux"
//"dronecore"
)
// This handles the Roll request, utilizing dronecore to facilitate then
// call interpreetation and validation
func droneSimpleNavRollHandler(w http.ResponseWriter, r *http.Request) {
droneName := dronecore.GetDroneNameFromURI(r)
roll := dronecore.GetNavValue(r, dronecore.ROLL)
drone := drones.GetDrone(droneName)
if drone != nil {
drone.SetRoll(roll)
go sendMessage("0", strconv.Itoa(roll), "0", "0")
msg := "Roll received " + strconv.Itoa(roll) + " for " + droneName
w.WriteHeader(http.StatusOK)
w.Header().Set(ENCODING, TEXTENC)
w.Write([]byte(msg))
Trace.Println(msg)
} else {
msg := "Roll received " + strconv.Itoa(roll) + " for " + droneName + " No drone to command"
w.Header().Set(ENCODING, TEXTENC)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(msg))
Warning.Println(msg)
}
}
func droneSimpleNavYawHandler(w http.ResponseWriter, r *http.Request) {
droneName := dronecore.GetDroneNameFromURI(r)
yaw := dronecore.GetNavValue(r, dronecore.YAW)
drone := drones.GetDrone(droneName)
if drone != nil {
drone.SetYaw(yaw)
go sendMessage(strconv.Itoa(yaw), "0", "0", "0")
msg := "Yaw received " + strconv.Itoa(yaw) + " for " + droneName
w.WriteHeader(http.StatusOK)
w.Header().Set(ENCODING, TEXTENC)
w.Write([]byte(msg))
Trace.Println(msg)
} else {
msg := "Yaw received " + strconv.Itoa(yaw) + " for " + droneName + " No drone to command"
w.Header().Set(ENCODING, TEXTENC)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(msg))
Warning.Println(msg)
}
}
func droneSimpleNavGazHandler(w http.ResponseWriter, r *http.Request) {
droneName := dronecore.GetDroneNameFromURI(r)
gaz := dronecore.GetNavValue(r, dronecore.GAZ)
drone := drones.GetDrone(droneName)
if drone != nil {
drone.SetGaz(gaz)
go sendMessage("0", "0", "0", strconv.Itoa(gaz))
msg := "Gaz received " + strconv.Itoa(gaz) + " for " + droneName
w.WriteHeader(http.StatusOK)
w.Header().Set(ENCODING, TEXTENC)
w.Write([]byte(msg))
Trace.Println(msg)
} else {
msg := "Gaz received " + strconv.Itoa(gaz) + " for " + droneName + " No drone to command"
w.Header().Set(ENCODING, TEXTENC)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(msg))
Warning.Println(msg)
}
}
func droneSimpleNavPitchHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}