From 92362f1b73f1e61ad0cb1c581b318b360e0bb6fe Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Tue, 26 Aug 2008 10:54:46 +0000 Subject: [PATCH] add support for dm8000 rtc, add support for dm8000 deepstandby wakeup, go back to deepstandby after deepstandby timer wakeup even when not explicitely selected (this needs new drivers and / or new atmel firmware) add some sanity checks to dont break anything even with old drivers/atmel firmware --- Navigation.py | 17 ++++++++++- RecordTimer.py | 8 ++--- lib/dvb/dvbtime.cpp | 57 +++++++++++++++++++++++++++++------- lib/python/Screens/Standby.py | 8 ++--- lib/python/Tools/DreamboxHardware.py | 49 +++++++++++++++++++++++++++---- main/enigma.cpp | 23 ++++++++++++++- mytest.py | 14 +++++---- 7 files changed, 144 insertions(+), 32 deletions(-) diff --git a/Navigation.py b/Navigation.py index eb1a2b1..f46b92d 100644 --- a/Navigation.py +++ b/Navigation.py @@ -1,9 +1,11 @@ from enigma import eServiceCenter, eServiceReference, pNavigation, getBestPlayableServiceReference, iPlayableService from Components.ParentalControl import parentalControl from Tools.BoundFunction import boundFunction +from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup, clearFPWasTimerWakeup +from time import time import RecordTimer import SleepTimer - +import Screens.Standby import NavigationInstance import ServiceReference @@ -27,6 +29,19 @@ class Navigation: self.currentlyPlayingServiceReference = None self.currentlyPlayingService = None self.RecordTimer = RecordTimer.RecordTimer() + if getFPWasTimerWakeup(): + clearFPWasTimerWakeup() + if getFPWasTimerWakeup(): # sanity check to detect if the FP driver is working correct! + print "buggy fp driver detected!!! please update drivers.... ignore timer wakeup!" + setFPWakeuptime(0) + elif len(self.getRecordings()) or abs(self.RecordTimer.getNextRecordingTime() - time()) <= 360: + setFPWakeuptime(0x89ABCDEF) + if getFPWakeuptime() != 0x89ABCDEF: # sanity check to detect if the FP Atmel Firmware is working correct! + print "buggy atmel firmware detected!! atmel update needed... ignore fp timer wakeup!" + setFPWakeuptime(0) + elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open + RecordTimer.RecordTimerEntry.TryQuitMainloop(0) # start shutdown handling + setFPWakeuptime(1) self.SleepTimer = SleepTimer.SleepTimer() def dispatchEvent(self, i): diff --git a/RecordTimer.py b/RecordTimer.py index 147a38f..f93872c 100644 --- a/RecordTimer.py +++ b/RecordTimer.py @@ -79,7 +79,7 @@ class RecordTimerEntry(timer.TimerEntry, object): RecordTimerEntry.receiveRecordEvents = False @staticmethod - def TryQuitMainloop(): + def TryQuitMainloop(default_yes = True): if not RecordTimerEntry.receiveRecordEvents: print "RecordTimer.TryQuitMainloop" NavigationInstance.instance.record_event.append(RecordTimerEntry.staticGotRecordEvent) @@ -88,7 +88,7 @@ class RecordTimerEntry(timer.TimerEntry, object): # other timers start in a few seconds RecordTimerEntry.staticGotRecordEvent(None, iRecordableService.evEnd) # send normal notification for the case the user leave the standby now.. - Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1, onSessionOpenCallback=RecordTimerEntry.stopTryQuitMainloop) + Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1, onSessionOpenCallback=RecordTimerEntry.stopTryQuitMainloop, default_yes = default_yes) ################################################################# def __init__(self, serviceref, begin, end, name, description, eit, disabled = False, justplay = False, afterEvent = AFTEREVENT.NONE, checkOldTimers = False, dirname = None): @@ -271,9 +271,9 @@ class RecordTimerEntry(timer.TimerEntry, object): if self.afterEvent == AFTEREVENT.STANDBY: if not Screens.Standby.inStandby: # not already in standby Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished record timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20) - if self.afterEvent == AFTEREVENT.DEEPSTANDBY: + elif self.afterEvent == AFTEREVENT.DEEPSTANDBY: if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open - if Screens.Standby.inStandby: # not in standby + if Screens.Standby.inStandby: # in standby RecordTimerEntry.TryQuitMainloop() # start shutdown handling without screen else: Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished record timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20) diff --git a/lib/dvb/dvbtime.cpp b/lib/dvb/dvbtime.cpp index 616363f..6cfaccc 100644 --- a/lib/dvb/dvbtime.cpp +++ b/lib/dvb/dvbtime.cpp @@ -15,26 +15,61 @@ static time_t prev_time; void setRTC(time_t time) { - int fd = open("/dev/dbox/fp0", O_RDWR); - if ( fd >= 0 ) + FILE *f = fopen("/proc/stb/fp/rtc", "w"); + if (f) { - if ( ::ioctl(fd, FP_IOCTL_SET_RTC, (void*)&time ) < 0 ) - eDebug("FP_IOCTL_SET_RTC failed(%m)"); + time_t wakeup=0; + FILE *f2 = fopen("/proc/stb/fp/wakeup_time", "r"); + if (f2) + { + fscanf(f2, "%u", &wakeup); + fclose(f2); + } + if (wakeup) // atmel firmware okay? + { + if (fprintf(f, "%u", time)) + prev_time = time; + else + eDebug("write /proc/stb/fp/rtc failed (%m)"); + fclose(f); + } else - prev_time = time; - close(fd); + eDebug("dont set rtc because of buggy atmel firmware!"); + } + else + { + int fd = open("/dev/dbox/fp0", O_RDWR); + if ( fd >= 0 ) + { + if ( ::ioctl(fd, FP_IOCTL_SET_RTC, (void*)&time ) < 0 ) + eDebug("FP_IOCTL_SET_RTC failed(%m)"); + else + prev_time = time; + close(fd); + } } } time_t getRTC() { time_t rtc_time=0; - int fd = open("/dev/dbox/fp0", O_RDWR); - if ( fd >= 0 ) + FILE *f = fopen("/proc/stb/fp/rtc", "r"); + if (f) + { + // sanity check to detect corrupt atmel firmware + if (fscanf(f, "%u", &rtc_time) != 1) + eDebug("read /proc/stb/fp/rtc failed (%m)"); + fclose(f); + } + else { - if ( ::ioctl(fd, FP_IOCTL_GET_RTC, (void*)&rtc_time ) < 0 ) - eDebug("FP_IOCTL_GET_RTC failed(%m)"); - close(fd); + int fd = open("/dev/dbox/fp0", O_RDWR); + if ( fd >= 0 ) + { + if ( ::ioctl(fd, FP_IOCTL_GET_RTC, (void*)&rtc_time ) < 0 ) + eDebug("FP_IOCTL_GET_RTC failed(%m)"); + close(fd); + } } return rtc_time != prev_time ? rtc_time : 0; } diff --git a/lib/python/Screens/Standby.py b/lib/python/Screens/Standby.py index f7c819d..fd7ca8e 100644 --- a/lib/python/Screens/Standby.py +++ b/lib/python/Screens/Standby.py @@ -93,7 +93,7 @@ from time import time inTryQuitMainloop = False class TryQuitMainloop(MessageBox): - def __init__(self, session, retvalue=1, timeout=-1): + def __init__(self, session, retvalue=1, timeout=-1, default_yes = True): self.retval=retvalue recordings = len(session.nav.getRecordings()) self.connected = False @@ -102,13 +102,13 @@ class TryQuitMainloop(MessageBox): next_rec_time = session.nav.RecordTimer.getNextRecordingTime() if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360): if retvalue == 1: - MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really shutdown now?"), type = MessageBox.TYPE_YESNO, timeout = timeout) + MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really shutdown now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes) elif retvalue == 2: - MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really reboot now?"), type = MessageBox.TYPE_YESNO, timeout = timeout) + MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really reboot now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes) elif retvalue == 4: pass else: - MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really restart now?"), type = MessageBox.TYPE_YESNO, timeout = timeout) + MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really restart now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes) self.skinName = "MessageBox" session.nav.record_event.append(self.getRecordEvent) self.connected = True diff --git a/lib/python/Tools/DreamboxHardware.py b/lib/python/Tools/DreamboxHardware.py index 5eaaeec..2a0ddee 100644 --- a/lib/python/Tools/DreamboxHardware.py +++ b/lib/python/Tools/DreamboxHardware.py @@ -1,17 +1,54 @@ +from fcntl import ioctl +from struct import pack, unpack + def getFPVersion(): - from fcntl import ioctl try: fp = open("/dev/dbox/fp0") return ioctl(fp.fileno(),0) except IOError: + print "getFPVersion failed!" return None def setFPWakeuptime(wutime): - from fcntl import ioctl - from struct import pack + try: + open("/proc/stb/fp/wakeup_time", "w").write(str(wutime)) + except IOError: + try: + fp = open("/dev/dbox/fp0") + ioctl(fp.fileno(), 6, pack('L', wutime)) # set wake up + except IOError: + print "setFPWakeupTime failed!" +def getFPWakeuptime(): + ret = 0 try: - fp = open("/dev/dbox/fp0") - ioctl(fp.fileno(), 6, pack('L', wutime)) # set wake up + ret = long(open("/proc/stb/fp/wakeup_time", "r").read()) except IOError: - pass + try: + fp = open("/dev/dbox/fp0") + ret = unpack('L', ioctl(fp.fileno(), 5, ' '))[0] # get wakeuptime + except IOError: + print "getFPWakeupTime failed!" + return ret + +def getFPWasTimerWakeup(): + was_wakeup = False + try: + was_wakeup = int(open("/proc/stb/fp/was_timer_wakeup", "r").read()) and True or False + except: + try: + fp = open("/dev/dbox/fp0") + was_wakeup = unpack('B', ioctl(fp.fileno(), 9, ' '))[0] and True or False + except IOError: + print "wasTimerWakeup failed!" + return was_wakeup + +def clearFPWasTimerWakeup(): + try: + open("/proc/stb/fp/was_timer_wakeup", "w").write('0') + except: + try: + fp = open("/dev/dbox/fp0") + ioctl(fp.fileno(), 10) + except IOError: + print "clearFPWasTimerWakeup failed!" diff --git a/main/enigma.cpp b/main/enigma.cpp index 307edd5..0893b03 100644 --- a/main/enigma.cpp +++ b/main/enigma.cpp @@ -1,5 +1,8 @@ -#include #include +#include +#include +#include +#include #include #include @@ -277,6 +280,24 @@ void runMainloop() void quitMainloop(int exitCode) { + FILE *f = fopen("/proc/stb/fp/was_timer_wakeup", "w"); + if (f) + { + fprintf(f, "%d", 0); + fclose(f); + } + else + { + int fd = open("/dev/dbox/fp0", O_WRONLY); + if (fd >= 0) + { + if (ioctl(fd, 10 /*FP_CLEAR_WAKEUP_TIMER*/) < 0) + eDebug("FP_CLEAR_WAKEUP_TIMER failed (%m)"); + close(fd); + } + else + eDebug("open /dev/dbox/fp0 for wakeup timer clear failed!(%m)"); + } exit_code = exitCode; eApp->quit(0); } diff --git a/mytest.py b/mytest.py index 0c448d7..2dcd0d3 100644 --- a/mytest.py +++ b/mytest.py @@ -467,7 +467,7 @@ def runScreenTest(): profile("wakeup") from time import time - from Tools.DreamboxHardware import setFPWakeuptime + from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime #get currentTime nowTime = time() wakeupList = [ @@ -478,12 +478,16 @@ def runScreenTest(): if x != -1 ] wakeupList.sort() - if len(wakeupList): + if len(wakeupList) and getFPWakeuptime(): # getFPWakeuptime returns 1 when the sanity check in Navigation.py was okay.. startTime = wakeupList.pop(0) - if (startTime - nowTime < 330): # no time to switch box back on - setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds + if (startTime - nowTime) < 330: # no time to switch box back on + wptime = nowTime + 30 # so switch back on in 30 seconds else: - setFPWakeuptime(startTime - 300) + wptime = startTime - 300 + setFPWakeuptime(wptime) + else: + print "buggy atmel firmware detected... dont set a wakeup time!" + setFPWakeuptime(0) profile("stopService") session.nav.stopService() profile("nav shutdown") -- 2.7.4