Skip to content

Commit

Permalink
optimized ntp warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Ludwig committed Feb 8, 2019
1 parent edc5603 commit c876a91
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@
from settings_functions import Settings




class MainScreen(QWidget, Ui_MainScreen):
getTimeWindow: QDialog
ntpHadWarning: bool
ntpWarnMessage: str

def __init__(self):
QWidget.__init__(self)
Expand All @@ -77,7 +76,7 @@ def __init__(self):
self.showFullScreen()
app.setOverrideCursor(QCursor(Qt.BlankCursor))
settings.endGroup()
# print("Loading Settings: ", settings.fileName())
print("Loading Settings from: ", settings.fileName())

self.labelWarning.hide()

Expand Down Expand Up @@ -161,6 +160,7 @@ def __init__(self):

# Setup check NTP Timer
self.ntpHadWarning = True
self.ntpWarnMessage = ""
self.timerNTP = QTimer()
self.timerNTP.timeout.connect(self.triggerNTPcheck)
# initial check
Expand All @@ -182,7 +182,8 @@ def __init__(self):
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
settings.beginGroup("NTP")
if settings.value('ntpcheck', True):
self.showWarning("waiting for NTP status check")
self.ntpHadWarning = True
self.ntpWarnMessage = "waiting for NTP status check"
settings.endGroup()

def radioTimerStartStop(self):
Expand Down Expand Up @@ -635,6 +636,7 @@ def constantUpdate(self):
self.updateDate()
self.updateBacktimingText()
self.updateBacktimingSeconds()
self.updateNTPstatus()

def updateDate(self):
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
Expand Down Expand Up @@ -700,6 +702,13 @@ def updateBacktimingSeconds(self):
remain_seconds = 60 - second
self.setBacktimingSecs(remain_seconds)

def updateNTPstatus(self):
if self.ntpHadWarning and len(self.ntpWarnMessage):
self.showWarning(self.ntpWarnMessage)
else:
self.ntpWarnMessage = ""
self.hideWarning()

def toggleFullScreen(self):
global app
settings = QSettings(QSettings.UserScope, "astrastudio", "OnAirScreen")
Expand Down Expand Up @@ -1060,23 +1069,23 @@ def run(self):
response = c.request(ntpserver)
if response.offset > max_deviation or response.offset < -max_deviation:
print("offset too big: %f while checking %s" % (response.offset, ntpserver))
#self.oas.showWarning("Clock not NTP synchronized: offset too big")
self.oas.ntpWarnMessage = "Clock not NTP synchronized: offset too big"
self.oas.ntpHadWarning = True
else:
if self.oas.ntpHadWarning:
self.oas.ntpHadWarning = False
#self.oas.hideWarning()
except socket.timeout:
print("NTP error: timeout while checking NTP %s" % ntpserver)
#self.oas.showWarning("Clock not NTP synchronized")
self.oas.ntpWarnMessage = "Clock not NTP synchronized"
self.oas.ntpHadWarning = True
except socket.gaierror:
print("NTP error: socket error while checking NTP %s" % ntpserver)
#self.oas.showWarning("Clock not NTP synchronized")
self.oas.ntpWarnMessage = "Clock not NTP synchronized"
self.oas.ntpHadWarning = True
except ntplib.NTPException as e:
print("NTP error:", e)
#self.oas.showWarning(str(e))
self.oas.ntpWarnMessage = str(e)
self.oas.ntpHadWarning = True
# except:
# print("unknown error checking NTP %s" % ntpserver)
Expand Down

0 comments on commit c876a91

Please sign in to comment.