1 from enigma import eDVBFrontendParametersSatellite, eDVBFrontendParameters, eDVBResourceManager, eTimer
4 def __init__(self, frontend, ignore_rotor=False):
5 self.frontend = frontend
6 self.ignore_rotor = ignore_rotor
8 # transponder = (frequency, symbolrate, polarisation, fec, inversion, orbpos, system, modulation, rolloff, pilot, tsid, onid)
9 # 0 1 2 3 4 5 6 7 8 9 10 11
10 def tune(self, transponder):
12 print "tuning to transponder with data", transponder
13 parm = eDVBFrontendParametersSatellite()
14 parm.frequency = transponder[0] * 1000
15 parm.symbol_rate = transponder[1] * 1000
16 parm.polarisation = transponder[2]
17 parm.fec = transponder[3]
18 parm.inversion = transponder[4]
19 parm.orbital_position = transponder[5]
20 parm.system = transponder[6]
21 parm.modulation = transponder[7]
22 parm.rolloff = transponder[8]
23 parm.pilot = transponder[9]
24 feparm = eDVBFrontendParameters()
25 feparm.setDVBS(parm, self.ignore_rotor)
26 self.lastparm = feparm
27 self.frontend.tune(feparm)
31 self.frontend.tune(self.lastparm)
33 def getTransponderData(self):
36 self.frontend.getTransponderData(ret, True)
39 # tunes a list of transponders and checks, if they lock and optionally checks the onid/tsid combination
40 # 1) add transponders with addTransponder()
41 # 2) call run(<checkPIDs = True>)
42 # 3) finishedChecking() is called, when the run is finished
44 def __init__(self, feid, stopOnSuccess = -1, stopOnError = -1):
45 self.stopOnSuccess = stopOnSuccess
46 self.stopOnError = stopOnError
48 self.transponderlist = []
50 print "TuneTest for feid %d" % self.feid
51 if not self.openFrontend():
52 self.oldref = self.session.nav.getCurrentlyPlayingServiceReference()
53 self.session.nav.stopService() # try to disable foreground service
54 if not self.openFrontend():
55 if self.session.pipshown: # try to disable pip
56 self.session.pipshown = False
58 if not self.openFrontend():
59 self.frontend = None # in normal case this should not happen
60 self.tuner = Tuner(self.frontend)
62 self.timer.callback.append(self.updateStatus)
64 def gotTsidOnid(self, tsid, onid):
65 print "******** got tsid, onid:", tsid, onid
66 if tsid is not None and onid is not None:
67 self.pidStatus = self.INTERNAL_PID_STATUS_SUCCESSFUL
71 self.pidStatus = self.INTERNAL_PID_STATUS_FAILED
74 self.timer.start(100, True)
76 def updateStatus(self):
78 self.frontend.getFrontendStatus(dict)
82 if dict["tuner_state"] == "TUNING":
84 self.timer.start(100, True)
85 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_TUNING, self.currTuned))
86 elif self.checkPIDs and self.pidStatus == self.INTERNAL_PID_STATUS_NOOP:
88 if dict["tuner_state"] == "LOCKED":
89 print "acquiring TSID/ONID"
90 self.raw_channel.requestTsidOnid(self.gotTsidOnid)
91 self.pidStatus = self.INTERNAL_PID_STATUS_WAITING
93 self.pidStatus = self.INTERNAL_PID_STATUS_FAILED
94 elif self.checkPIDs and self.pidStatus == self.INTERNAL_PID_STATUS_WAITING:
95 print "waiting for pids"
97 if dict["tuner_state"] == "LOSTLOCK" or dict["tuner_state"] == "FAILED":
98 self.tuningtransponder = self.nextTransponder()
99 self.failedTune.append([self.currTuned, self.oldTuned, "tune_failed", dict]) # last parameter is the frontend status)
100 if self.stopOnError != -1 and self.stopOnError <= len(self.failedTune):
102 elif dict["tuner_state"] == "LOCKED":
105 if self.currTuned is not None:
106 if self.tsid != self.currTuned[10] or self.onid != self.currTuned[11]:
107 self.failedTune.append([self.currTuned, self.oldTuned, "pids_failed", {"real": (self.tsid, self.onid), "expected": (self.currTuned[10], self.currTuned[11])}, dict]) # last parameter is the frontend status
110 self.successfullyTune.append([self.currTuned, self.oldTuned, dict]) # 3rd parameter is the frontend status
111 if self.stopOnSuccess != -1 and self.stopOnSuccess <= len(self.successfullyTune):
113 elif not self.checkPIDs or (self.checkPids and not pidsFailed):
114 self.successfullyTune.append([self.currTuned, self.oldTuned, dict]) # 3rd parameter is the frontend status
115 if self.stopOnSuccess != -1 and self.stopOnSuccess <= len(self.successfullyTune):
117 self.tuningtransponder = self.nextTransponder()
119 print "************* tuner_state:", dict["tuner_state"]
121 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_NOOP, self.currTuned))
125 if self.tuningtransponder < len(self.transponderlist) and not stop:
126 if self.pidStatus != self.INTERNAL_PID_STATUS_WAITING:
127 self.timer.start(100, True)
128 print "restart timer"
130 print "not restarting timers (waiting for pids)"
132 self.progressCallback((self.getProgressLength(), len(self.transponderlist), self.STATUS_DONE, self.currTuned))
133 print "finishedChecking"
134 self.finishedChecking()
136 def firstTransponder(self):
137 print "firstTransponder:"
140 print "checkPIDs-loop"
141 # check for tsid != -1 and onid != -1
142 print "index:", index
143 print "len(self.transponderlist):", len(self.transponderlist)
144 while (index < len(self.transponderlist) and (self.transponderlist[index][10] == -1 or self.transponderlist[index][11] == -1)):
146 print "FirstTransponder final index:", index
149 def nextTransponder(self):
150 print "getting next transponder", self.tuningtransponder
151 index = self.tuningtransponder + 1
153 print "checkPIDs-loop"
154 # check for tsid != -1 and onid != -1
155 print "index:", index
156 print "len(self.transponderlist):", len(self.transponderlist)
157 while (index < len(self.transponderlist) and (self.transponderlist[index][10] == -1 or self.transponderlist[index][11] == -1)):
160 print "next transponder index:", index
163 def finishedChecking(self):
164 print "finished testing"
165 print "successfull:", self.successfullyTune
166 print "failed:", self.failedTune
168 def openFrontend(self):
169 res_mgr = eDVBResourceManager.getInstance()
171 self.raw_channel = res_mgr.allocateRawChannel(self.feid)
173 self.frontend = self.raw_channel.getFrontend()
177 print "getFrontend failed"
179 print "getRawChannel failed"
181 print "getResourceManager instance failed"
185 print "tuning to", self.tuningtransponder
186 if self.tuningtransponder < len(self.transponderlist):
187 self.pidStatus = self.INTERNAL_PID_STATUS_NOOP
188 self.oldTuned = self.currTuned
189 self.currTuned = self.transponderlist[self.tuningtransponder]
190 self.tuner.tune(self.transponderlist[self.tuningtransponder])
192 INTERNAL_PID_STATUS_NOOP = 0
193 INTERNAL_PID_STATUS_WAITING = 1
194 INTERNAL_PID_STATUS_SUCCESSFUL = 2
195 INTERNAL_PID_STATUS_FAILED = 3
197 def run(self, checkPIDs = False):
198 self.checkPIDs = checkPIDs
199 self.pidStatus = self.INTERNAL_PID_STATUS_NOOP
201 self.successfullyTune = []
202 self.tuningtransponder = self.firstTransponder()
204 self.progressCallback((self.getProgressLength(), self.tuningtransponder, self.STATUS_START, self.currTuned))
205 self.timer.start(100, True)
207 # transponder = (frequency, symbolrate, polarisation, fec, inversion, orbpos, <system>, <modulation>, <rolloff>, <pilot>, <tsid>, <onid>)
208 # 0 1 2 3 4 5 6 7 8 9 10 11
209 def addTransponder(self, transponder):
210 self.transponderlist.append(transponder)
212 def clearTransponder(self):
213 self.transponderlist = []
215 def getProgressLength(self):
217 if self.stopOnError == -1:
218 count = len(self.transponderlist)
220 if count < self.stopOnError:
221 count = self.stopOnError
222 if self.stopOnSuccess == -1:
223 count = len(self.transponderlist)
225 if count < self.stopOnSuccess:
226 count = self.stopOnSuccess
234 # progress = (range, value, status, transponder)
235 def progressCallback(self, progress):