kopia lustrzana https://github.com/cyoung/stratux
Issue a warning and disable features when FF broadcast messages are received.
Fixes #332.pull/339/head
rodzic
a93501f8f4
commit
65537dbdc8
|
@ -10,6 +10,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"golang.org/x/net/icmp"
|
"golang.org/x/net/icmp"
|
||||||
"golang.org/x/net/ipv4"
|
"golang.org/x/net/ipv4"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -45,6 +46,7 @@ type networkConnection struct {
|
||||||
nextMessageTime time.Time // The next time that the device is "able" to receive a message.
|
nextMessageTime time.Time // The next time that the device is "able" to receive a message.
|
||||||
numOverflows uint32 // Number of times the queue has overflowed - for calculating the amount to chop off from the queue.
|
numOverflows uint32 // Number of times the queue has overflowed - for calculating the amount to chop off from the queue.
|
||||||
SleepFlag bool // Whether or not this client has been marked as sleeping - only used for debugging (relies on messages being sent to update this flag in sendToAllConnectedClients()).
|
SleepFlag bool // Whether or not this client has been marked as sleeping - only used for debugging (relies on messages being sent to update this flag in sendToAllConnectedClients()).
|
||||||
|
FFCrippled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var messageQueue chan networkMessage
|
var messageQueue chan networkMessage
|
||||||
|
@ -436,6 +438,61 @@ func networkStatsCounter() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
ffMonitor().
|
||||||
|
Watches for "i-want-to-play-ffm-udp", "i-can-play-ffm-udp", and "i-cannot-play-ffm-udp" UDP messages broadcasted on
|
||||||
|
port 50113. Tags the client, issues a warning, and disables AHRS.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
func ffMonitor() {
|
||||||
|
ff_warned := false // Has a warning been issued via globalStatus.Errors?
|
||||||
|
|
||||||
|
addr := net.UDPAddr{Port: 50113, IP: net.ParseIP("0.0.0.0")}
|
||||||
|
conn, err := net.ListenUDP("udp", &addr)
|
||||||
|
defer conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("ffMonitor(): error listening on port 50113: %s\n", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
buf := make([]byte, 1024)
|
||||||
|
n, addr, err := conn.ReadFrom(buf)
|
||||||
|
ipAndPort := strings.Split(addr.String(), ":")
|
||||||
|
ip := ipAndPort[0]
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("err: %s\n", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Got message, check if it's in the correct format.
|
||||||
|
if n < 3 || buf[0] != 0xFF || buf[1] != 0xFE {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
s := string(buf[2:n])
|
||||||
|
s = strings.Replace(s, "\x00", "", -1)
|
||||||
|
ffIpAndPort := ip + ":4000"
|
||||||
|
netMutex.Lock()
|
||||||
|
p, ok := outSockets[ffIpAndPort]
|
||||||
|
if !ok {
|
||||||
|
// Can't do anything, the client isn't even technically connected.
|
||||||
|
netMutex.Unlock()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(s, "i-want-to-play-ffm-udp") || strings.HasPrefix(s, "i-can-play-ffm-udp") || strings.HasPrefix(s, "i-cannot-play-ffm-udp") {
|
||||||
|
p.FFCrippled = true
|
||||||
|
//FIXME: AHRS doesn't need to be disabled globally, just messages need to be filtered.
|
||||||
|
globalSettings.AHRS_Enabled = false
|
||||||
|
if !ff_warned {
|
||||||
|
e := errors.New("Stratux is not supported by your EFB app. Your EFB app is known to regularly make changes that cause compatibility issues with Stratux. See the README for a list of apps that officially support Stratux.")
|
||||||
|
addSystemError(e)
|
||||||
|
ff_warned = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outSockets[ffIpAndPort] = p
|
||||||
|
netMutex.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func initNetwork() {
|
func initNetwork() {
|
||||||
messageQueue = make(chan networkMessage, 1024) // Buffered channel, 1024 messages.
|
messageQueue = make(chan networkMessage, 1024) // Buffered channel, 1024 messages.
|
||||||
outSockets = make(map[string]networkConnection)
|
outSockets = make(map[string]networkConnection)
|
||||||
|
@ -446,4 +503,5 @@ func initNetwork() {
|
||||||
go messageQueueSender()
|
go messageQueueSender()
|
||||||
go sleepMonitor()
|
go sleepMonitor()
|
||||||
go networkStatsCounter()
|
go networkStatsCounter()
|
||||||
|
go ffMonitor()
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue