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, rolloff, pilot, tsid, onid)
8 # 0 1 2 3 4 5 6 7 8 9 10 11
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 = transponder[6]
20 parm.modulation = transponder[7]
21 parm.rolloff = transponder[8]
22 parm.pilot = transponder[9]
23 feparm = eDVBFrontendParameters()
25 self.lastparm = feparm
26 self.frontend.tune(feparm)
30 self.frontend.tune(self.lastparm)
32 def getTransponderData(self):
35 self.frontend.getTransponderData(ret, True)
38 # tunes a list of transponders and checks, if they lock and optionally checks the onid/tsid combination
39 # 1) add transponders with addTransponder()
40 # 2) call run(<checkPIDs = True>)
41 # 3) finishedChecking() is called, when the run is finished
43 def __init__(self, feid, stopOnSuccess = -1, stopOnError = -1):
44 self.stopOnSuccess = stopOnSuccess
45 self.stopOnError = stopOnError
47 self.transponderlist = []
49 print "TuneTest for feid %d" % self.feid
50 if not self.openFrontend():
51 self.oldref = self.session.nav.getCurrentlyPlayingServiceReference()
52 self.session.nav.stopService() # try to disable foreground service
53 if not self.openFrontend():
54 if self.session.pipshown: # try to disable pip
55 self.session.pipshown = False
57 if not self.openFrontend():
58 self.frontend = None # in normal case this should not happen
59 self.tuner = Tuner(self.frontend)
61 self.timer.callback.append(self.updateStatus)
63 def gotTsidOnid(self, tsid, onid):
64 print "******** got tsid, onid:", tsid, onid
65 if tsid is not None and onid is not None:
66 self.pidStatus = self.INTERNAL_PID_STATUS_SUCCESSFUL
70 self.pidStatus = self.INTERNAL_PID_STATUS_FAILED
73 self.timer.start(100, True)
75 def updateStatus(self):
77 self.frontend.getFrontendStatus(dict)
81 if dict["tuner_state"] == "TUNING":
83 self.timer.start(100, True)
84 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_TUNING, self.currTuned))
85 elif self.checkPIDs and self.pidStatus == self.INTERNAL_PID_STATUS_NOOP:
87 if dict["tuner_state"] == "LOCKED":
88 print "acquiring TSID/ONID"
89 self.raw_channel.requestTsidOnid(self.gotTsidOnid)
90 self.pidStatus = self.INTERNAL_PID_STATUS_WAITING
92 self.pidStatus = self.INTERNAL_PID_STATUS_FAILED
93 elif self.checkPIDs and self.pidStatus == self.INTERNAL_PID_STATUS_WAITING:
94 print "waiting for pids"
96 if dict["tuner_state"] == "LOSTLOCK" or dict["tuner_state"] == "FAILED":
97 self.tuningtransponder = self.nextTransponder()
98 self.failedTune.append([self.currTuned, self.oldTuned, "tune_failed"])
99 if self.stopOnError != -1 and self.stopOnError <= len(self.failedTune):
101 elif dict["tuner_state"] == "LOCKED":
104 if self.currTuned is not None:
105 if self.tsid != self.currTuned[10] or self.onid != self.currTuned[11]:
106 self.failedTune.append([self.currTuned, self.oldTuned, "pids_failed", {"real": (self.tsid, self.onid), "expected": (self.currTuned[10], self.currTuned[11])}])
109 self.successfullyTune.append([self.currTuned, self.oldTuned])
110 if self.stopOnSuccess != -1 and self.stopOnSuccess <= len(self.successfullyTune):
112 elif not self.checkPIDs or (self.checkPids and not pidsFailed):
113 self.successfullyTune.append([self.currTuned, self.oldTuned])
114 if self.stopOnSuccess != -1 and self.stopOnSuccess <= len(self.successfullyTune):
116 self.tuningtransponder = self.nextTransponder()
118 print "************* tuner_state:", dict["tuner_state"]
120 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_NOOP, self.currTuned))
124 if self.tuningtransponder < len(self.transponderlist) and not stop:
125 if self.pidStatus != self.INTERNAL_PID_STATUS_WAITING:
126 self.timer.start(100, True)
127 print "restart timer"
129 print "not restarting timers (waiting for pids)"
131 self.progressCallback((self.getProgressLength(), len(self.transponderlist), self.STATUS_DONE, self.currTuned))
132 print "finishedChecking"
133 self.finishedChecking()
135 def firstTransponder(self):
136 print "firstTransponder:"
139 print "checkPIDs-loop"
140 # check for tsid != -1 and onid != -1
141 print "index:", index
142 print "len(self.transponderlist):", len(self.transponderlist)
143 while (index < len(self.transponderlist) and (self.transponderlist[index][10] == -1 or self.transponderlist[index][11] == -1)):
145 print "FirstTransponder final index:", index
148 def nextTransponder(self):
149 print "getting next transponder", self.tuningtransponder
150 index = self.tuningtransponder + 1
152 print "checkPIDs-loop"
153 # check for tsid != -1 and onid != -1
154 print "index:", index
155 print "len(self.transponderlist):", len(self.transponderlist)
156 while (index < len(self.transponderlist) and (self.transponderlist[index][10] == -1 or self.transponderlist[index][11] == -1)):
159 print "next transponder index:", index
162 def finishedChecking(self):
163 print "finished testing"
164 print "successfull:", self.successfullyTune
165 print "failed:", self.failedTune
167 def openFrontend(self):
168 res_mgr = eDVBResourceManager.getInstance()
170 self.raw_channel = res_mgr.allocateRawChannel(self.feid)
172 self.frontend = self.raw_channel.getFrontend()
176 print "getFrontend failed"
178 print "getRawChannel failed"
180 print "getResourceManager instance failed"
184 print "tuning to", self.tuningtransponder
185 if self.tuningtransponder < len(self.transponderlist):
186 self.pidStatus = self.INTERNAL_PID_STATUS_NOOP
187 self.oldTuned = self.currTuned
188 self.currTuned = self.transponderlist[self.tuningtransponder]
189 self.tuner.tune(self.transponderlist[self.tuningtransponder])
191 INTERNAL_PID_STATUS_NOOP = 0
192 INTERNAL_PID_STATUS_WAITING = 1
193 INTERNAL_PID_STATUS_SUCCESSFUL = 2
194 INTERNAL_PID_STATUS_FAILED = 3
196 def run(self, checkPIDs = False):
197 self.checkPIDs = checkPIDs
198 self.pidStatus = self.INTERNAL_PID_STATUS_NOOP
200 self.successfullyTune = []
201 self.tuningtransponder = self.firstTransponder()
203 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_START, self.currTuned))
204 self.timer.start(100, True)
206 # transponder = (frequency, symbolrate, polarisation, fec, inversion, orbpos, <system>, <modulation>, <rolloff>, <pilot>, <tsid>, <onid>)
207 # 0 1 2 3 4 5 6 7 8 9 10 11
208 def addTransponder(self, transponder):
209 self.transponderlist.append(transponder)
211 def clearTransponder(self):
212 self.transponderlist = []
214 def getProgressLength(self):
216 if self.stopOnError == -1:
217 count = len(self.transponderlist)
219 if count < self.stopOnError:
220 count = self.stopOnError
221 if self.stopOnSuccess == -1:
222 count = len(self.transponderlist)
224 if count < self.stopOnSuccess:
225 count = self.stopOnSuccess
233 # progress = (range, value, status, transponder)
234 def progressCallback(self, progress):