Use monotonic clock for SDR/network timing.

#174.
pull/196/head
Christopher Young 2016-01-07 11:29:55 -05:00
rodzic f1a0355231
commit ce5f185c0f
2 zmienionych plików z 7 dodań i 7 usunięć

Wyświetl plik

@ -209,7 +209,7 @@ func messageQueueSender() {
} }
} }
if time.Since(lastQueueTimeChange) >= 5*time.Second { if stratuxClock.Since(lastQueueTimeChange) >= 5*time.Second {
var pd float64 var pd float64
if averageSendableQueueSize > 0.0 && len(outSockets) > 0 { if averageSendableQueueSize > 0.0 && len(outSockets) > 0 {
averageSendableQueueSize = averageSendableQueueSize / float64(len(outSockets)) // It's a total, not an average, up until this point. averageSendableQueueSize = averageSendableQueueSize / float64(len(outSockets)) // It's a total, not an average, up until this point.
@ -219,7 +219,7 @@ func messageQueueSender() {
} }
queueTimer.Stop() queueTimer.Stop()
queueTimer = time.NewTicker(time.Duration(pd*1000000000.0) * time.Nanosecond) queueTimer = time.NewTicker(time.Duration(pd*1000000000.0) * time.Nanosecond)
lastQueueTimeChange = time.Now() lastQueueTimeChange = stratuxClock.Time
} }
netMutex.Unlock() netMutex.Unlock()
case <-secondTimer.C: case <-secondTimer.C:

Wyświetl plik

@ -277,7 +277,7 @@ var devMap = map[int]string{0: "", 1: ""}
func sdrWatcher() { func sdrWatcher() {
stopCheckingUATUntil := time.Time{} stopCheckingUATUntil := time.Time{}
lastUATCheck := time.Now() lastUATCheck := stratuxClock.Time
for { for {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
@ -322,20 +322,20 @@ func sdrWatcher() {
// UAT specific handling // UAT specific handling
// Shutdown UAT for 50 seconds, check every 60 seconds if the count is 0. // Shutdown UAT for 50 seconds, check every 60 seconds if the count is 0.
if time.Since(lastUATCheck) >= 1*time.Minute { if stratuxClock.Since(lastUATCheck) >= 1*time.Minute {
if UATDev != nil && globalStatus.UAT_messages_last_minute == 0 { if UATDev != nil && globalStatus.UAT_messages_last_minute == 0 {
log.Printf("Pausing UAT listening for 50 seconds - none received.\n") log.Printf("Pausing UAT listening for 50 seconds - none received.\n")
UATDev.shutdown() UATDev.shutdown()
UATDev = nil UATDev = nil
stopCheckingUATUntil = time.Now().Add(50 * time.Second) stopCheckingUATUntil = stratuxClock.Time.Add(50 * time.Second)
} }
lastUATCheck = time.Now() lastUATCheck = stratuxClock.Time
} }
// When count is one, favor UAT in the case where the user // When count is one, favor UAT in the case where the user
// has enabled both UAT and ES via the web interface. // has enabled both UAT and ES via the web interface.
id := 0 id := 0
if globalSettings.UAT_Enabled && time.Now().After(stopCheckingUATUntil) { if globalSettings.UAT_Enabled && stratuxClock.Time.After(stopCheckingUATUntil) {
// log.Println("globalSettings.UAT_Enabled == true") // log.Println("globalSettings.UAT_Enabled == true")
if count == 1 { if count == 1 {
if ESDev != nil { if ESDev != nil {