kopia lustrzana https://github.com/cyoung/stratux
rodzic
e0dde8d5de
commit
57a9fbf393
|
@ -21,9 +21,11 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
humanize "github.com/dustin/go-humanize"
|
humanize "github.com/dustin/go-humanize"
|
||||||
|
@ -1200,8 +1202,23 @@ func openReplayFile(fn string) ReadCloser {
|
||||||
}
|
}
|
||||||
|
|
||||||
var stratuxClock *monotonic
|
var stratuxClock *monotonic
|
||||||
|
var sigs = make(chan os.Signal, 1) // Signal catch channel (shutdown).
|
||||||
|
|
||||||
|
// Graceful shutdown.
|
||||||
|
func signalWatcher() {
|
||||||
|
sig := <-sigs
|
||||||
|
log.Printf("signal caught: %s - shutting down.\n", sig.String())
|
||||||
|
// Shut down SDRs.
|
||||||
|
sdrKill()
|
||||||
|
//TODO: Any other graceful shutdown functions.
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Catch signals for graceful shutdown.
|
||||||
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
go signalWatcher()
|
||||||
|
|
||||||
stratuxClock = NewMonotonic() // Start our "stratux clock".
|
stratuxClock = NewMonotonic() // Start our "stratux clock".
|
||||||
|
|
||||||
// replayESFilename := flag.String("eslog", "none", "ES Log filename")
|
// replayESFilename := flag.String("eslog", "none", "ES Log filename")
|
||||||
|
|
22
main/sdr.go
22
main/sdr.go
|
@ -284,6 +284,17 @@ func (e *ES) shutdown() {
|
||||||
|
|
||||||
var devMap = map[int]string{0: "", 1: ""}
|
var devMap = map[int]string{0: "", 1: ""}
|
||||||
|
|
||||||
|
var sdrShutdown bool
|
||||||
|
|
||||||
|
func sdrKill() {
|
||||||
|
// Send signal to shutdown to sdrWatcher().
|
||||||
|
sdrShutdown = true
|
||||||
|
// Spin until all devices have been de-initialized.
|
||||||
|
for UATDev != nil || ESDev != nil {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Watch for config/device changes.
|
// Watch for config/device changes.
|
||||||
func sdrWatcher() {
|
func sdrWatcher() {
|
||||||
stopCheckingUATUntil := time.Time{}
|
stopCheckingUATUntil := time.Time{}
|
||||||
|
@ -292,6 +303,17 @@ func sdrWatcher() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
if sdrShutdown {
|
||||||
|
if UATDev != nil {
|
||||||
|
UATDev.shutdown()
|
||||||
|
UATDev = nil
|
||||||
|
}
|
||||||
|
if ESDev != nil {
|
||||||
|
ESDev.shutdown()
|
||||||
|
ESDev = nil
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
count := rtl.GetDeviceCount()
|
count := rtl.GetDeviceCount()
|
||||||
atomic.StoreUint32(&globalStatus.Devices, uint32(count))
|
atomic.StoreUint32(&globalStatus.Devices, uint32(count))
|
||||||
// log.Println("DeviceCount...", count)
|
// log.Println("DeviceCount...", count)
|
||||||
|
|
Ładowanie…
Reference in New Issue