lib/python/Tools/DreamboxHardware.py: add function to set RTC Time
[enigma2.git] / lib / python / Tools / DreamboxHardware.py
1 from fcntl import ioctl
2 from struct import pack, unpack
3
4 def getFPVersion():
5         ret = None
6         try:
7                 ret = long(open("/proc/stb/fp/version", "r").read())
8         except IOError:
9                 try:
10                         fp = open("/dev/dbox/fp0")
11                         ret = ioctl(fp.fileno(),0)
12                 except IOError:
13                         print "getFPVersion failed!"
14         return ret
15
16 def setFPWakeuptime(wutime):
17         try:
18                 open("/proc/stb/fp/wakeup_time", "w").write(str(wutime))
19         except IOError:
20                 try:
21                         fp = open("/dev/dbox/fp0")
22                         ioctl(fp.fileno(), 6, pack('L', wutime)) # set wake up
23                 except IOError:
24                         print "setFPWakeupTime failed!"
25
26 def setRTCtime(wutime):
27         try:
28                 open("/proc/stb/fp/rtc", "w").write(str(wutime))
29         except IOError:
30                 try:
31                         fp = open("/dev/dbox/fp0")
32                         ioctl(fp.fileno(), 0x101, pack('L', wutime)) # set wake up
33                 except IOError:
34                         print "setRTCtime failed!"
35
36 def getFPWakeuptime():
37         ret = 0
38         try:
39                 ret = long(open("/proc/stb/fp/wakeup_time", "r").read())
40         except IOError:
41                 try:
42                         fp = open("/dev/dbox/fp0")
43                         ret = unpack('L', ioctl(fp.fileno(), 5, '    '))[0] # get wakeuptime
44                 except IOError:
45                         print "getFPWakeupTime failed!"
46         return ret
47
48 def getFPWasTimerWakeup():
49         was_wakeup = False
50         try:
51                 was_wakeup = int(open("/proc/stb/fp/was_timer_wakeup", "r").read()) and True or False
52         except:
53                 try:
54                         fp = open("/dev/dbox/fp0")
55                         was_wakeup = unpack('B', ioctl(fp.fileno(), 9, ' '))[0] and True or False
56                 except IOError:
57                         print "wasTimerWakeup failed!"
58         return was_wakeup
59
60 def clearFPWasTimerWakeup():
61         try:
62                 open("/proc/stb/fp/was_timer_wakeup", "w").write('0')
63         except:
64                 try:
65                         fp = open("/dev/dbox/fp0")
66                         ioctl(fp.fileno(), 10)
67                 except IOError:
68                         print "clearFPWasTimerWakeup failed!"