pull/527/head
Christopher Young 2016-11-17 12:42:24 -05:00
commit 12df162b25
2 zmienionych plików z 43 dodań i 0 usunięć

Wyświetl plik

@ -35,6 +35,25 @@ type SettingMessage struct {
// Weather updates channel. // Weather updates channel.
var weatherUpdate *uibroadcaster var weatherUpdate *uibroadcaster
var trafficUpdate *uibroadcaster var trafficUpdate *uibroadcaster
var gdl90Update *uibroadcaster
func handleGdl90WS(conn *websocket.Conn) {
// Subscribe the socket to receive updates.
gdl90Update.AddSocket(conn)
// Connection closes when function returns. Since uibroadcast is writing and we don't need to read anything (for now), just keep it busy.
for {
buf := make([]byte, 1024)
_, err := conn.Read(buf)
if err != nil {
break
}
if buf[0] != 0 { // Dummy.
continue
}
time.Sleep(1 * time.Second)
}
}
// Situation updates channel. // Situation updates channel.
var situationUpdate *uibroadcaster var situationUpdate *uibroadcaster
@ -520,11 +539,18 @@ func managementInterface() {
trafficUpdate = NewUIBroadcaster() trafficUpdate = NewUIBroadcaster()
situationUpdate = NewUIBroadcaster() situationUpdate = NewUIBroadcaster()
weatherRawUpdate = NewUIBroadcaster() weatherRawUpdate = NewUIBroadcaster()
gdl90Update = NewUIBroadcaster()
http.HandleFunc("/", defaultServer) http.HandleFunc("/", defaultServer)
http.Handle("/logs/", http.StripPrefix("/logs/", http.FileServer(http.Dir("/var/log")))) http.Handle("/logs/", http.StripPrefix("/logs/", http.FileServer(http.Dir("/var/log"))))
http.HandleFunc("/view_logs/", viewLogs) http.HandleFunc("/view_logs/", viewLogs)
http.HandleFunc("/gdl90",
func(w http.ResponseWriter, req *http.Request) {
s := websocket.Server{
Handler: websocket.Handler(handleGdl90WS)}
s.ServeHTTP(w, req)
})
http.HandleFunc("/status", http.HandleFunc("/status",
func(w http.ResponseWriter, req *http.Request) { func(w http.ResponseWriter, req *http.Request) {
s := websocket.Server{ s := websocket.Server{

17
main/network.go 100755 → 100644
Wyświetl plik

@ -15,6 +15,7 @@ import (
"golang.org/x/net/icmp" "golang.org/x/net/icmp"
"golang.org/x/net/ipv4" "golang.org/x/net/ipv4"
"io/ioutil" "io/ioutil"
"encoding/json"
"log" "log"
"math" "math"
"math/rand" "math/rand"
@ -143,6 +144,7 @@ func sendToAllConnectedClients(msg networkMessage) {
if (msg.msgType & NETWORK_GDL90_STANDARD) != 0 { if (msg.msgType & NETWORK_GDL90_STANDARD) != 0 {
// It's a GDL90 message. Send to serial output channel (which may or may not cause something to happen). // It's a GDL90 message. Send to serial output channel (which may or may not cause something to happen).
serialOutputChan <- msg.msg serialOutputChan <- msg.msg
networkGDL90Chan <- msg.msg
} }
netMutex.Lock() netMutex.Lock()
@ -192,6 +194,19 @@ func sendToAllConnectedClients(msg networkMessage) {
} }
var serialOutputChan chan []byte var serialOutputChan chan []byte
var networkGDL90Chan chan []byte
func networkOutWatcher() {
//ticker := time.NewTicker(10 * time.Second)
//var nmsg gdl90NetMessage
for {
select {
case ch := <-networkGDL90Chan:
gdlJSON, _ := json.Marshal(ch)
gdl90Update.Send(gdlJSON)
}
}
}
// Monitor serial output channel, send to serial port. // Monitor serial output channel, send to serial port.
func serialOutWatcher() { func serialOutWatcher() {
@ -603,6 +618,7 @@ func ffMonitor() {
func initNetwork() { func initNetwork() {
messageQueue = make(chan networkMessage, 1024) // Buffered channel, 1024 messages. messageQueue = make(chan networkMessage, 1024) // Buffered channel, 1024 messages.
serialOutputChan = make(chan []byte, 1024) // Buffered channel, 1024 GDL90 messages. serialOutputChan = make(chan []byte, 1024) // Buffered channel, 1024 GDL90 messages.
networkGDL90Chan = make(chan []byte, 1024)
outSockets = make(map[string]networkConnection) outSockets = make(map[string]networkConnection)
pingResponse = make(map[string]time.Time) pingResponse = make(map[string]time.Time)
netMutex = &sync.Mutex{} netMutex = &sync.Mutex{}
@ -612,4 +628,5 @@ func initNetwork() {
go sleepMonitor() go sleepMonitor()
go networkStatsCounter() go networkStatsCounter()
go serialOutWatcher() go serialOutWatcher()
go networkOutWatcher()
} }