kopia lustrzana https://github.com/cyoung/stratux
mlat feeder relay - add to main process.
rodzic
e30bb662d0
commit
47b1910da5
2
Makefile
2
Makefile
|
@ -15,7 +15,7 @@ all:
|
|||
|
||||
xgen_gdl90:
|
||||
go get -t -d -v ./main ./godump978 ./uatparse ./sensors
|
||||
go build $(BUILDINFO) -p 4 main/gen_gdl90.go main/traffic.go main/gps.go main/network.go main/managementinterface.go main/sdr.go main/ping.go main/uibroadcast.go main/monotonic.go main/datalog.go main/equations.go main/sensors.go main/cputemp.go
|
||||
go build $(BUILDINFO) -p 4 main/gen_gdl90.go main/traffic.go main/gps.go main/network.go main/managementinterface.go main/sdr.go main/ping.go main/uibroadcast.go main/monotonic.go main/datalog.go main/equations.go main/sensors.go main/cputemp.go main/adsbexchange.go
|
||||
|
||||
fancontrol:
|
||||
go get -t -d -v ./main
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/sh
|
||||
while true
|
||||
do
|
||||
sleep 30
|
||||
/usr/bin/mlat-client --input-type dump1090 --input-connect localhost:30005 --server feed.adsbexchange.com:31090 --no-udp --results beast,connect,localhost:30104
|
||||
done
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/sh
|
||||
while true
|
||||
do
|
||||
sleep 30
|
||||
/bin/nc 127.0.0.1 30005 | /bin/nc feed.adsbexchange.com 30005
|
||||
done
|
|
@ -26,8 +26,6 @@ fi
|
|||
|
||||
/usr/bin/stratux-screen.py start
|
||||
|
||||
/root/adsbexchange-mlat_maint.sh &
|
||||
/root/adsbexchange-netcat_maint.sh &
|
||||
|
||||
# Dangerzone.
|
||||
#route add default gw 10.26.36.1
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
Copyright (c) 2018 Christopher Young
|
||||
Distributable under the terms of The "BSD New" License
|
||||
that can be found in the LICENSE file, herein included
|
||||
as part of this header.
|
||||
|
||||
adsbexchange.go: adsbexchange 1090ES message transfer and mlat-client running.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
RELAY_TYPE_NC = 1
|
||||
RELAY_TYPE_MLAT_CLIENT = 2
|
||||
)
|
||||
|
||||
type RelayProcess struct {
|
||||
StartTime time.Time
|
||||
RelayType int
|
||||
closeCh chan int
|
||||
wg *sync.WaitGroup
|
||||
cmd []string
|
||||
finished bool
|
||||
}
|
||||
|
||||
var mlatclientRelay *RelayProcess
|
||||
|
||||
func (r *RelayProcess) read() {
|
||||
defer r.wg.Done()
|
||||
|
||||
// Start the relay process.
|
||||
log.Printf("Starting relay process '%s'.\n", r.cmd[0])
|
||||
cmd := exec.Command(r.cmd[0], r.cmd[1:]...)
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
stderr, _ := cmd.StderrPipe()
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
log.Printf("Error executing '%s': %s\n", r.cmd[0], err)
|
||||
os.Exit(1) //FIXME: Graceful shutdown (or restart).
|
||||
}
|
||||
|
||||
done := make(chan bool)
|
||||
|
||||
// Shutdown watcher.
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
case <-r.closeCh:
|
||||
log.Printf("Relay process '%s' read(): shutdown msg received, calling cmd.Process.Kill() ...\n", r.cmd[0])
|
||||
err := cmd.Process.Kill()
|
||||
if err == nil {
|
||||
log.Println("\t kill successful...")
|
||||
}
|
||||
return
|
||||
default:
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
stdoutBuf := make([]byte, 1024)
|
||||
stderrBuf := make([]byte, 1024)
|
||||
|
||||
// Stdout watcher.
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
default:
|
||||
n, err := stdout.Read(stdoutBuf)
|
||||
if err == nil && n > 0 {
|
||||
//FIXME: Do something with stdout buffer.
|
||||
log.Printf("stdout: %s\n", stdoutBuf[:n])
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Stderr watcher.
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
default:
|
||||
n, err := stderr.Read(stderrBuf)
|
||||
if err == nil && n > 0 {
|
||||
//FIXME: Do something with stderr buffer.
|
||||
log.Printf("stderr: %s\n", stderrBuf[:n])
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
cmd.Wait()
|
||||
|
||||
// we get here if A) the process died
|
||||
// on its own or B) cmd.Process.Kill() was called
|
||||
// from within the goroutine, either way close
|
||||
// the "done" channel, which ensures we don't leak
|
||||
// goroutines...
|
||||
close(done)
|
||||
r.finished = true
|
||||
}
|
||||
|
||||
func (r *RelayProcess) shutdown() {
|
||||
log.Printf("Shutting down relay process '%s'.\n", r.cmd[0])
|
||||
close(r.closeCh)
|
||||
r.wg.Wait()
|
||||
log.Printf("Finished shutting down relay process '%s'.", r.cmd[0])
|
||||
}
|
||||
|
||||
func makeRelayProc(relayType int, args ...string) *RelayProcess {
|
||||
ret := &RelayProcess{StartTime: stratuxClock.Time, RelayType: relayType, cmd: args}
|
||||
ret.wg = &sync.WaitGroup{}
|
||||
ret.closeCh = make(chan int)
|
||||
ret.wg.Add(1)
|
||||
go ret.read()
|
||||
return ret
|
||||
}
|
||||
|
||||
// /usr/bin/mlat-client --input-type dump1090 --input-connect localhost:30005 --lat $RECEIVERLATITUDE --lon $RECEIVERLONGITUDE --alt $RECEIVERALTITUDE --user $ADSBEXCHANGEUSERNAME --server feed.adsbexchange.com:31090 --no-udp --results beast,connect,localhost:30104
|
||||
// /bin/nc 127.0.0.1 30005 | /bin/nc feed.adsbexchange.com 30005
|
||||
|
||||
func feederProcessMonitor() {
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
if len(globalSettings.ADSBExchangeUser) > 0 {
|
||||
// Keep adsbexchange processes running.
|
||||
//TODO: Check "netcat".
|
||||
|
||||
if mlatclientRelay != nil && mlatclientRelay.finished {
|
||||
// Clean up reference.
|
||||
mlatclientRelay = nil
|
||||
}
|
||||
if (mlatclientRelay == nil) && globalStatus.GPS_satellites_locked > 0 && globalStatus.GPS_position_accuracy < 15.0 { //FIXME: 15m accuracy - set a minimum based on network requirements.
|
||||
// Check "mlat-client".
|
||||
//FIXME: mlatClientRelay never is re-set to nil if it crashes.
|
||||
mlatclientRelay = makeRelayProc(RELAY_TYPE_MLAT_CLIENT, "/usr/bin/mlat-client", "--input-type", "dump1090", "--input-connect", "localhost:30005", "--lat", strconv.FormatFloat(float64(mySituation.GPSLatitude), 'f', 5, 32), "--lon", strconv.FormatFloat(float64(mySituation.GPSLongitude), 'f', 5, 32), "--alt", strconv.FormatFloat(float64(mySituation.GPSAltitudeMSL), 'f', 1, 32), "--user", globalSettings.ADSBExchangeUser, "--server", "feed.adsbexchange.com:31090", "--no-udp", "--results", "beast,connect,localhost:30104")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func feederInit() {
|
||||
go feederProcessMonitor()
|
||||
}
|
||||
|
||||
func relayKill() {
|
||||
if mlatclientRelay != nil {
|
||||
mlatclientRelay.shutdown()
|
||||
mlatclientRelay = nil
|
||||
}
|
||||
}
|
|
@ -1069,6 +1069,7 @@ type settings struct {
|
|||
DeveloperMode bool
|
||||
GLimits string
|
||||
StaticIps []string
|
||||
ADSBExchangeUser string
|
||||
}
|
||||
|
||||
type status struct {
|
||||
|
@ -1342,6 +1343,7 @@ var sigs = make(chan os.Signal, 1) // Signal catch channel (shutdown).
|
|||
func gracefulShutdown() {
|
||||
// Shut down SDRs.
|
||||
sdrKill()
|
||||
relayKill()
|
||||
pingKill()
|
||||
|
||||
// Shut down data logging.
|
||||
|
@ -1486,6 +1488,7 @@ func main() {
|
|||
crcInit() // Initialize CRC16 table.
|
||||
|
||||
sdrInit()
|
||||
feederInit()
|
||||
pingInit()
|
||||
initTraffic()
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@ cp image/rc.local work/bin/
|
|||
cp image/dhcpd.conf work/bin/
|
||||
cp image/interfaces work/bin/
|
||||
cp image/logrotate.conf work/bin
|
||||
cp image/adsbexchange-mlat_maint.sh work/bin
|
||||
cp image/adsbexchange-netcat_maint.sh work/bin
|
||||
|
||||
cp test-data/ahrs/ahrs_table.log work/bin/
|
||||
cp ahrs_approx work/bin/
|
||||
|
|
|
@ -89,9 +89,3 @@ cd web/ && make stratuxBuild=${stratuxBuild}
|
|||
# Remove old Wi-Fi watcher script.
|
||||
rm -f /usr/sbin/wifi_watch.sh
|
||||
sed -i "/\bwifi_watch\b/d" /etc/rc.local
|
||||
|
||||
# adsbexchange maintenance scripts.
|
||||
cp -f adsbexchange-mlat_maint.sh /root/
|
||||
chmod 744 /root/adsbexchange-mlat_maint.sh
|
||||
cp -f adsbexchange-netcat_maint.sh /root/
|
||||
chmod 744 /root/adsbexchange-netcat_maint.sh
|
||||
|
|
Ładowanie…
Reference in New Issue