1 from enigma import eDVBFrontendParametersSatellite, eDVBFrontendParameters, eDVBResourceManager, eTimer
4 def __init__(self, frontend):
5 self.frontend = frontend
7 # transponder = (frequency, symbolrate, polarisation, fec, inversion, orbpos, system, modulation)
9 def tune(self, transponder):
11 print "tuning to transponder with data", transponder
12 parm = eDVBFrontendParametersSatellite()
13 parm.frequency = transponder[0] * 1000
14 parm.symbol_rate = transponder[1] * 1000
15 parm.polarisation = transponder[2]
16 parm.fec = transponder[3]
17 parm.inversion = transponder[4]
18 parm.orbital_position = transponder[5]
19 parm.system = 0 # FIXMEE !! HARDCODED DVB-S (add support for DVB-S2)
20 parm.modulation = 1 # FIXMEE !! HARDCODED QPSK
21 feparm = eDVBFrontendParameters()
23 self.lastparm = feparm
24 self.frontend.tune(feparm)
28 self.frontend.tune(self.lastparm)
30 # tunes a list of transponders and checks, if they lock and optionally checks the onid/tsid combination
31 # 1) add transponders with addTransponder()
32 # 2) call run(<checkPIDs = True>)
33 # 3) finishedChecking() is called, when the run is finished
35 def __init__(self, feid, stopOnSuccess = -1, stopOnError = -1):
36 self.stopOnSuccess = stopOnSuccess
37 self.stopOnError = stopOnError
39 self.transponderlist = []
41 print "TuneTest for feid %d" % self.feid
42 if not self.openFrontend():
43 self.oldref = self.session.nav.getCurrentlyPlayingServiceReference()
44 self.session.nav.stopService() # try to disable foreground service
45 if not self.openFrontend():
46 if self.session.pipshown: # try to disable pip
47 self.session.pipshown = False
49 if not self.openFrontend():
50 self.frontend = None # in normal case this should not happen
51 self.tuner = Tuner(self.frontend)
53 self.timer.callback.append(self.updateStatus)
55 def gotTsidOnid(self, tsid, onid):
56 print "******** got tsid, onid:", tsid, onid
57 if tsid is not None and onid is not None:
58 self.pidStatus = self.INTERNAL_PID_STATUS_SUCCESSFUL
62 self.pidStatus = self.INTERNAL_PID_STATUS_FAILED
65 self.timer.start(100, True)
67 def updateStatus(self):
69 self.frontend.getFrontendStatus(dict)
73 if dict["tuner_state"] == "TUNING":
75 self.timer.start(100, True)
76 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_TUNING, self.currTuned))
77 elif self.checkPIDs and self.pidStatus == self.INTERNAL_PID_STATUS_NOOP:
79 if dict["tuner_state"] == "LOCKED":
80 print "acquiring TSID/ONID"
81 self.raw_channel.requestTsidOnid(self.gotTsidOnid)
82 self.pidStatus = self.INTERNAL_PID_STATUS_WAITING
84 self.pidStatus = self.INTERNAL_PID_STATUS_FAILED
85 elif self.checkPIDs and self.pidStatus == self.INTERNAL_PID_STATUS_WAITING:
86 print "waiting for pids"
88 if dict["tuner_state"] == "LOSTLOCK" or dict["tuner_state"] == "FAILED":
89 self.tuningtransponder = self.nextTransponder()
90 self.failedTune.append([self.currTuned, self.oldTuned, "tune_failed"])
91 if self.stopOnError != -1 and self.stopOnError <= len(self.failedTune):
93 elif dict["tuner_state"] == "LOCKED":
96 if self.currTuned is not None:
97 if self.tsid != self.currTuned[8] or self.onid != self.currTuned[9]:
98 self.failedTune.append([self.currTuned, self.oldTuned, "pids_failed", {"real": (self.tsid, self.onid), "expected": (self.currTuned[8], self.currTuned[9])}])
101 self.successfullyTune.append([self.currTuned, self.oldTuned])
102 if self.stopOnSuccess != -1 and self.stopOnSuccess <= len(self.successfullyTune):
104 elif not self.checkPIDs or (self.checkPids and not pidsFailed):
105 self.successfullyTune.append([self.currTuned, self.oldTuned])
106 if self.stopOnSuccess != -1 and self.stopOnSuccess <= len(self.successfullyTune):
108 self.tuningtransponder = self.nextTransponder()
110 print "************* tuner_state:", dict["tuner_state"]
112 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_NOOP, self.currTuned))
116 if self.tuningtransponder < len(self.transponderlist) and not stop:
117 if self.pidStatus != self.INTERNAL_PID_STATUS_WAITING:
118 self.timer.start(100, True)
119 print "restart timer"
121 print "not restarting timers (waiting for pids)"
123 self.progressCallback((self.getProgressLength(), len(self.transponderlist), self.STATUS_DONE, self.currTuned))
124 print "finishedChecking"
125 self.finishedChecking()
127 def firstTransponder(self):
128 print "firstTransponder:"
131 print "checkPIDs-loop"
132 # check for tsid != -1 and onid != -1
133 print "index:", index
134 print "len(self.transponderlist):", len(self.transponderlist)
135 while (index < len(self.transponderlist) and (self.transponderlist[index][8] == -1 or self.transponderlist[index][9] == -1)):
137 print "FirstTransponder final index:", index
140 def nextTransponder(self):
141 print "getting next transponder", self.tuningtransponder
142 index = self.tuningtransponder + 1
144 print "checkPIDs-loop"
145 # check for tsid != -1 and onid != -1
146 print "index:", index
147 print "len(self.transponderlist):", len(self.transponderlist)
148 while (index < len(self.transponderlist) and (self.transponderlist[index][8] == -1 or self.transponderlist[index][9] == -1)):
151 print "next transponder index:", index
154 def finishedChecking(self):
155 print "finished testing"
156 print "successfull:", self.successfullyTune
157 print "failed:", self.failedTune
159 def openFrontend(self):
160 res_mgr = eDVBResourceManager.getInstance()
162 self.raw_channel = res_mgr.allocateRawChannel(self.feid)
164 self.frontend = self.raw_channel.getFrontend()
168 print "getFrontend failed"
170 print "getRawChannel failed"
172 print "getResourceManager instance failed"
176 print "tuning to", self.tuningtransponder
177 if self.tuningtransponder < len(self.transponderlist):
178 self.pidStatus = self.INTERNAL_PID_STATUS_NOOP
179 self.oldTuned = self.currTuned
180 self.currTuned = self.transponderlist[self.tuningtransponder]
181 self.tuner.tune(self.transponderlist[self.tuningtransponder])
183 INTERNAL_PID_STATUS_NOOP = 0
184 INTERNAL_PID_STATUS_WAITING = 1
185 INTERNAL_PID_STATUS_SUCCESSFUL = 2
186 INTERNAL_PID_STATUS_FAILED = 3
188 def run(self, checkPIDs = False):
189 self.checkPIDs = checkPIDs
190 self.pidStatus = self.INTERNAL_PID_STATUS_NOOP
192 self.successfullyTune = []
193 self.tuningtransponder = self.firstTransponder()
195 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_START, self.currTuned))
196 self.timer.start(100, True)
198 # transponder = (frequency, symbolrate, polarisation, fec, inversion, orbpos, <system>, <modulation>, <tsid>, <onid>)
199 # 0 1 2 3 4 5 6 7 8 9
200 def addTransponder(self, transponder):
201 self.transponderlist.append(transponder)
203 def clearTransponder(self):
204 self.transponderlist = []
206 def getProgressLength(self):
208 if self.stopOnError == -1:
209 count = len(self.transponderlist)
211 if count < self.stopOnError:
212 count = self.stopOnError
213 if self.stopOnSuccess == -1:
214 count = len(self.transponderlist)
216 if count < self.stopOnSuccess:
217 count = self.stopOnSuccess
225 # progress = (range, value, status, transponder)
226 def progressCallback(self, progress):