kopia lustrzana https://github.com/cyoung/stratux
gofmt
rodzic
2d770d5b2e
commit
797f71a4da
|
@ -27,7 +27,7 @@ func statusSender(conn *websocket.Conn) {
|
||||||
<-timer.C
|
<-timer.C
|
||||||
|
|
||||||
update, _ := json.Marshal(InfoMessage{status: &globalStatus, settings: &globalSettings})
|
update, _ := json.Marshal(InfoMessage{status: &globalStatus, settings: &globalSettings})
|
||||||
// TODO: once we switch to hte new WebUI, we will not send settings via websocket
|
// TODO: once we switch to hte new WebUI, we will not send settings via websocket
|
||||||
// update, _ := json.Marshal(&globalStatus)
|
// update, _ := json.Marshal(&globalStatus)
|
||||||
_, err := conn.Write(update)
|
_, err := conn.Write(update)
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func handleManagementConnection(conn *websocket.Conn) {
|
||||||
// log.Printf("Web client connected.\n")
|
// log.Printf("Web client connected.\n")
|
||||||
go statusSender(conn)
|
go statusSender(conn)
|
||||||
|
|
||||||
// TODO: once we have the new WebUI established, the websocket will nolonger receive settings changes
|
// TODO: once we have the new WebUI established, the websocket will nolonger receive settings changes
|
||||||
for {
|
for {
|
||||||
var msg SettingMessage
|
var msg SettingMessage
|
||||||
err := websocket.JSON.Receive(conn, &msg)
|
err := websocket.JSON.Receive(conn, &msg)
|
||||||
|
@ -74,8 +74,8 @@ func handleManagementConnection(conn *websocket.Conn) {
|
||||||
|
|
||||||
// AJAX call - /getTraffic. Responds with currently tracked traffic targets.
|
// AJAX call - /getTraffic. Responds with currently tracked traffic targets.
|
||||||
func handleTrafficRequest(w http.ResponseWriter, r *http.Request) {
|
func handleTrafficRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
/* From JSON package docs:
|
/* From JSON package docs:
|
||||||
"JSON objects only support strings as keys; to encode a Go map type it must be of the form map[string]T (where T is any Go type supported by the json package)."
|
"JSON objects only support strings as keys; to encode a Go map type it must be of the form map[string]T (where T is any Go type supported by the json package)."
|
||||||
*/
|
*/
|
||||||
|
@ -92,73 +92,81 @@ func handleTrafficRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// AJAX call - /getSituation. Responds with current situation (lat/lon/gdspeed/track/pitch/roll/heading/etc.)
|
// AJAX call - /getSituation. Responds with current situation (lat/lon/gdspeed/track/pitch/roll/heading/etc.)
|
||||||
func handleSituationRequest(w http.ResponseWriter, r *http.Request) {
|
func handleSituationRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
situationJSON, _ := json.Marshal(&mySituation)
|
situationJSON, _ := json.Marshal(&mySituation)
|
||||||
fmt.Fprintf(w, "%s\n", situationJSON)
|
fmt.Fprintf(w, "%s\n", situationJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AJAX call - /getTowers. Responds with all ADS-B ground towers that have sent messages that we were able to parse, along with its stats.
|
// AJAX call - /getTowers. Responds with all ADS-B ground towers that have sent messages that we were able to parse, along with its stats.
|
||||||
func handleTowersRequest(w http.ResponseWriter, r *http.Request) {
|
func handleTowersRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
towersJSON, _ := json.Marshal(&ADSBTowers)
|
towersJSON, _ := json.Marshal(&ADSBTowers)
|
||||||
fmt.Fprintf(w, "%s\n", towersJSON)
|
fmt.Fprintf(w, "%s\n", towersJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AJAX call - /getSettings. Responds with all stratux.conf data.
|
// AJAX call - /getSettings. Responds with all stratux.conf data.
|
||||||
func handleSettingsGetRequest(w http.ResponseWriter, r *http.Request) {
|
func handleSettingsGetRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
settingsJSON, _ := json.Marshal(&globalSettings)
|
settingsJSON, _ := json.Marshal(&globalSettings)
|
||||||
fmt.Fprintf(w, "%s\n", settingsJSON)
|
fmt.Fprintf(w, "%s\n", settingsJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AJAX call - /setSettings. receives via POST command, any/all stratux.conf data.
|
// AJAX call - /setSettings. receives via POST command, any/all stratux.conf data.
|
||||||
func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) {
|
func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
// define header in support of cross-domain AJAX
|
// define header in support of cross-domain AJAX
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Method", "GET, POST, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Method", "GET, POST, OPTIONS")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
// for an OPTION method request, we return header without processing.
|
|
||||||
// this insures we are recognized as supporting cross-domain AJAX REST calls
|
|
||||||
if (r.Method == "POST") {
|
|
||||||
// raw, _ := httputil.DumpRequest(r, true)
|
|
||||||
// log.Printf("handleSettingsSetRequest:raw: %s\n", raw)
|
|
||||||
|
|
||||||
decoder := json.NewDecoder(r.Body);
|
// for an OPTION method request, we return header without processing.
|
||||||
for {
|
// this insures we are recognized as supporting cross-domain AJAX REST calls
|
||||||
var msg map[string]interface{} // support arbitrary JSON
|
if r.Method == "POST" {
|
||||||
|
// raw, _ := httputil.DumpRequest(r, true)
|
||||||
|
// log.Printf("handleSettingsSetRequest:raw: %s\n", raw)
|
||||||
|
|
||||||
err := decoder.Decode(&msg)
|
decoder := json.NewDecoder(r.Body)
|
||||||
if err == io.EOF {
|
for {
|
||||||
break
|
var msg map[string]interface{} // support arbitrary JSON
|
||||||
} else if err != nil {
|
|
||||||
log.Printf("handleSettingsSetRequest:error: %s\n", err.Error())
|
err := decoder.Decode(&msg)
|
||||||
} else {
|
if err == io.EOF {
|
||||||
for key, val := range msg {
|
break
|
||||||
// log.Printf("handleSettingsSetRequest:json: testing for key:%s of type %s\n", key, reflect.TypeOf(val))
|
} else if err != nil {
|
||||||
switch key {
|
log.Printf("handleSettingsSetRequest:error: %s\n", err.Error())
|
||||||
case "UAT_Enabled": globalSettings.UAT_Enabled = val.(bool)
|
} else {
|
||||||
case "ES_Enabled": globalSettings.ES_Enabled = val.(bool)
|
for key, val := range msg {
|
||||||
case "GPS_Enabled": globalSettings.GPS_Enabled = val.(bool)
|
// log.Printf("handleSettingsSetRequest:json: testing for key:%s of type %s\n", key, reflect.TypeOf(val))
|
||||||
case "AHRS_Enabled": globalSettings.AHRS_Enabled = val.(bool)
|
switch key {
|
||||||
case "DEBUG": globalSettings.DEBUG = val.(bool)
|
case "UAT_Enabled":
|
||||||
case "ReplayLog": globalSettings.ReplayLog = val.(bool)
|
globalSettings.UAT_Enabled = val.(bool)
|
||||||
case "PPM": globalSettings.PPM = int(val.(float64))
|
case "ES_Enabled":
|
||||||
default: log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key)
|
globalSettings.ES_Enabled = val.(bool)
|
||||||
}
|
case "GPS_Enabled":
|
||||||
}
|
globalSettings.GPS_Enabled = val.(bool)
|
||||||
saveSettings()
|
case "AHRS_Enabled":
|
||||||
}
|
globalSettings.AHRS_Enabled = val.(bool)
|
||||||
}
|
case "DEBUG":
|
||||||
|
globalSettings.DEBUG = val.(bool)
|
||||||
// while it may be redundent, we return the latest settings
|
case "ReplayLog":
|
||||||
settingsJSON, _ := json.Marshal(&globalSettings)
|
globalSettings.ReplayLog = val.(bool)
|
||||||
fmt.Fprintf(w, "%s\n", settingsJSON)
|
case "PPM":
|
||||||
}
|
globalSettings.PPM = int(val.(float64))
|
||||||
|
default:
|
||||||
|
log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveSettings()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// while it may be redundent, we return the latest settings
|
||||||
|
settingsJSON, _ := json.Marshal(&globalSettings)
|
||||||
|
fmt.Fprintf(w, "%s\n", settingsJSON)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func managementInterface() {
|
func managementInterface() {
|
||||||
|
|
Ładowanie…
Reference in New Issue