kopia lustrzana https://github.com/cyoung/stratux
Integrate gpsd connection management with managment interface.
Disabling GPS on the management interface will close the gpsd connection. Add internal function for disconnecting.pull/539/head
rodzic
9ee3c25700
commit
f572d91fc6
|
@ -984,6 +984,7 @@ type settings struct {
|
|||
ES_Enabled bool
|
||||
Ping_Enabled bool
|
||||
GPS_Enabled bool
|
||||
GpsdAddress string
|
||||
NetworkOutputs []networkConnection
|
||||
SerialOutputs map[string]serialConnection
|
||||
AHRS_Enabled bool
|
||||
|
@ -1046,6 +1047,7 @@ func defaultSettings() {
|
|||
globalSettings.UAT_Enabled = true
|
||||
globalSettings.ES_Enabled = true
|
||||
globalSettings.GPS_Enabled = true
|
||||
globalSettings.GpsdAddress = "localhost:2947"
|
||||
//FIXME: Need to change format below.
|
||||
globalSettings.NetworkOutputs = []networkConnection{
|
||||
{Conn: nil, Ip: "", Port: 4000, Capability: NETWORK_GDL90_STANDARD | NETWORK_AHRS_GDL90},
|
||||
|
|
30
main/gpsd.go
30
main/gpsd.go
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
// Channel to disconnect current gpsd connection
|
||||
var disconnectGpsd chan struct{}
|
||||
var killGpsd chan struct{}
|
||||
var gps *gpsd.Session
|
||||
|
||||
// Determine type of satellite based on PRN number.
|
||||
|
@ -201,16 +201,24 @@ func initGpsd() {
|
|||
satelliteMutex = &sync.Mutex{}
|
||||
Satellites = make(map[string]SatelliteInfo)
|
||||
|
||||
disconnectGpsd = make(chan struct{})
|
||||
killGpsd = make(chan struct{})
|
||||
|
||||
setGpsdHost(gpsd.DefaultAddress)
|
||||
if globalSettings.GPS_Enabled {
|
||||
connectGpsd(globalSettings.GpsdAddress)
|
||||
}
|
||||
}
|
||||
|
||||
func setGpsdHost(address string) {
|
||||
// Main interface for enabling and changing the gpsd connection
|
||||
// Calling will block until previous connection disconnects
|
||||
// If address is zero value, it connects to gpsd on the local machine
|
||||
func connectGpsd(address string) {
|
||||
// kill existing monitor goroutine if it exists
|
||||
if gps != nil {
|
||||
log.Printf("Stopping previous gpsd session")
|
||||
disconnectGpsd <- struct{}{}
|
||||
disconnectGpsd()
|
||||
}
|
||||
|
||||
if address == "" {
|
||||
address = gpsd.DefaultAddress
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
@ -232,9 +240,10 @@ func setGpsdHost(address string) {
|
|||
reconnect := gps.Watch()
|
||||
|
||||
select {
|
||||
case <-disconnectGpsd:
|
||||
case <-killGpsd:
|
||||
log.Printf("Gpsd %s disconnecting", address)
|
||||
gps.Close()
|
||||
gps = nil
|
||||
return
|
||||
case <-reconnect:
|
||||
log.Printf("Gpsd %s disconnected. Reconnecting..", address)
|
||||
|
@ -243,3 +252,10 @@ func setGpsdHost(address string) {
|
|||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Disconnect from gpsd
|
||||
// Blocks until connection is disconnected and all goroutines are stopped
|
||||
func disconnectGpsd() {
|
||||
log.Printf("Stopping gpsd session")
|
||||
killGpsd <- struct{}{}
|
||||
}
|
||||
|
|
|
@ -218,6 +218,12 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) {
|
|||
case "Ping_Enabled":
|
||||
globalSettings.Ping_Enabled = val.(bool)
|
||||
case "GPS_Enabled":
|
||||
switch {
|
||||
case val.(bool) == true && globalSettings.GPS_Enabled == false:
|
||||
connectGpsd(globalSettings.GpsdAddress)
|
||||
case val.(bool) == false && globalSettings.GPS_Enabled == true:
|
||||
disconnectGpsd()
|
||||
}
|
||||
globalSettings.GPS_Enabled = val.(bool)
|
||||
case "AHRS_Enabled":
|
||||
globalSettings.AHRS_Enabled = val.(bool)
|
||||
|
|
Ładowanie…
Reference in New Issue