1 from enigma import eTimer, eDVBSatelliteEquipmentControl, eDVBResourceManager, eDVBDiseqcCommand, eDVBResourceManagerPtr, iDVBChannelPtr, iDVBFrontendPtr, iDVBFrontend, eDVBFrontendParametersSatellite, eDVBFrontendParameters
2 from Screens.Screen import Screen
3 from Screens.ScanSetup import ScanSetup
4 from Screens.MessageBox import MessageBox
5 from Plugins.Plugin import PluginDescriptor
7 from Components.Label import Label
8 from Components.ConfigList import ConfigList
9 from Components.TunerInfo import TunerInfo
10 from Components.ActionMap import ActionMap
11 from Components.NimManager import nimmanager
12 from Components.MenuList import MenuList
13 from Components.config import config, ConfigSubsection, configElement_nonSave, configNothing, getConfigListEntry, configSelection, currentConfigSelectionElement, configSatlist
15 class PositionerSetup(Screen):
17 <screen position="100,100" size="560,400" title="Positioner setup..." >
18 <widget name="list" position="100,0" size="350,155" />
20 <widget name="red" position="0,155" size="140,80" backgroundColor="red" halign="center" valign="center" font="Regular;21" />
21 <widget name="green" position="140,155" size="140,80" backgroundColor="green" halign="center" valign="center" font="Regular;21" />
22 <widget name="yellow" position="280,155" size="140,80" backgroundColor="yellow" halign="center" valign="center" font="Regular;21" />
23 <widget name="blue" position="420,155" size="140,80" backgroundColor="blue" halign="center" valign="center" font="Regular;21" />
25 <widget name="snr" text="SNR:" position="0,245" size="60,22" font="Regular;21" />
26 <widget name="agc" text="AGC:" position="0,270" size="60,22" font="Regular;21" />
27 <widget name="ber" text="BER:" position="0,295" size="60,22" font="Regular;21" />
28 <widget name="lock" text="Lock:" position="0,320" size="60,22" font="Regular;21" />
29 <widget name="snr_percentage" position="220,245" size="60,22" font="Regular;21" />
30 <widget name="agc_percentage" position="220,270" size="60,22" font="Regular;21" />
31 <widget name="ber_value" position="220,295" size="60,22" font="Regular;21" />
32 <widget name="lock_state" position="60,320" size="150,22" font="Regular;21" />
33 <widget name="snr_bar" position="60,245" size="150,22" />
34 <widget name="agc_bar" position="60,270" size="150,22" />
35 <widget name="ber_bar" position="60,295" size="150,22" />
37 <widget name="frequency" text="Frequency:" position="300,245" size="120,22" font="Regular;21" />
38 <widget name="symbolrate" text="Symbolrate:" position="300,270" size="120,22" font="Regular;21" />
39 <widget name="fec" text="FEC:" position="300,295" size="120,22" font="Regular;21" />
40 <widget name="frequency_value" position="420,245" size="120,22" font="Regular;21" />
41 <widget name="symbolrate_value" position="420,270" size="120,22" font="Regular;21" />
42 <widget name="fec_value" position="420,295" size="120,22" font="Regular;21" />
44 def __init__(self, session, feid):
45 self.skin = PositionerSetup.skin
46 Screen.__init__(self, session)
48 self.session.nav.stopService()
52 self.diseqc = Diseqc(self.feid)
53 self.tuner = Tuner(self.diseqc.getFrontend())
54 self.tuner.tune((0,0,0,0,0,0,0,0,0))
56 #self.session.nav.stopService()
61 self.stopOnLock = False
64 self["red"] = self.red
65 self.green = Label("")
66 self["green"] = self.green
67 self.yellow = Label("")
68 self["yellow"] = self.yellow
70 self["blue"] = self.blue
73 self["list"] = ConfigList(self.list)
79 self["lock"] = Label()
80 self["snr_percentage"] = TunerInfo(TunerInfo.SNR_PERCENTAGE, frontendfkt = self.diseqc.getFrontend)
81 self["agc_percentage"] = TunerInfo(TunerInfo.AGC_PERCENTAGE, frontendfkt = self.diseqc.getFrontend)
82 self["ber_value"] = TunerInfo(TunerInfo.BER_VALUE, frontendfkt = self.diseqc.getFrontend)
83 self["snr_bar"] = TunerInfo(TunerInfo.SNR_BAR, frontendfkt = self.diseqc.getFrontend)
84 self["agc_bar"] = TunerInfo(TunerInfo.AGC_BAR, frontendfkt = self.diseqc.getFrontend)
85 self["ber_bar"] = TunerInfo(TunerInfo.BER_BAR, frontendfkt = self.diseqc.getFrontend)
86 self["lock_state"] = TunerInfo(TunerInfo.LOCK_STATE, frontendfkt = self.diseqc.getFrontend)
88 self["frequency"] = Label()
89 self["symbolrate"] = Label()
92 self["frequency_value"] = Label("")
93 self["symbolrate_value"] = Label("")
94 self["fec_value"] = Label("")
96 self["actions"] = ActionMap(["DirectionActions", "OkCancelActions", "ColorActions"],
105 "green": self.greenKey,
106 "yellow": self.yellowKey,
107 "blue": self.blueKey,
110 self.updateColors("tune")
112 self.statusTimer = eTimer()
113 self.statusTimer.timeout.get().append(self.updateStatus)
114 self.statusTimer.start(50, False)
116 def createConfig(self):
117 config.positioner = ConfigSubsection()
118 config.positioner.tune = configElement_nonSave("tune", configNothing, 0, None)
119 config.positioner.move = configElement_nonSave("move", configNothing, 0, None)
120 config.positioner.finemove = configElement_nonSave("finemove", configNothing, 0, None)
121 config.positioner.limits = configElement_nonSave("limits", configNothing, 0, None)
122 config.positioner.goto0 = configElement_nonSave("goto0", configNothing, 0, None)
124 for x in range(1,255):
125 storepos.append(str(x))
126 config.positioner.storage = configElement_nonSave("storage", configSelection, 0, storepos)
128 def createSetup(self):
129 self.list.append(getConfigListEntry(_("Tune"), config.positioner.tune))
130 self.list.append(getConfigListEntry(_("Positioner movement"), config.positioner.move))
131 self.list.append(getConfigListEntry(_("Positioner fine movement"), config.positioner.finemove))
132 self.list.append(getConfigListEntry(_("Set limits"), config.positioner.limits))
133 self.list.append(getConfigListEntry(_("Positioner storage"), config.positioner.storage))
134 self.list.append(getConfigListEntry(_("Goto 0"), config.positioner.goto0))
135 self["list"].l.setList(self.list)
140 def getCurrentConfigPath(self):
141 return self["list"].getCurrent()[1].parent.configPath
144 if not self.isMoving:
145 self["list"].instance.moveSelection(self["list"].instance.moveUp)
146 self.updateColors(self.getCurrentConfigPath())
149 if not self.isMoving:
150 self["list"].instance.moveSelection(self["list"].instance.moveDown)
151 self.updateColors(self.getCurrentConfigPath())
154 self["list"].handleKey(config.key["prevElement"])
157 self["list"].handleKey(config.key["nextElement"])
159 def updateColors(self, entry):
161 self.red.setText(_("Tune"))
162 self.green.setText("")
163 self.yellow.setText("")
164 self.blue.setText("")
165 elif entry == "move":
167 self.red.setText(_("Stop"))
168 self.green.setText(_("Stop"))
169 self.yellow.setText(_("Stop"))
170 self.blue.setText(_("Stop"))
172 self.red.setText(_("Move west"))
173 self.green.setText(_("Search west"))
174 self.yellow.setText(_("Search east"))
175 self.blue.setText(_("Move east"))
176 elif entry == "finemove":
178 self.green.setText(_("Step west"))
179 self.yellow.setText(_("Step east"))
180 self.blue.setText("")
181 elif entry == "limits":
182 self.red.setText(_("Limits off"))
183 self.green.setText(_("Limit west"))
184 self.yellow.setText(_("Limit east"))
185 self.blue.setText(_("Limits on"))
186 elif entry == "storage":
188 self.green.setText(_("Store position"))
189 self.yellow.setText(_("Goto position"))
190 self.blue.setText("")
191 elif entry == "goto0":
192 self.red.setText(_("Goto 0"))
193 self.green.setText("")
194 self.yellow.setText("")
195 self.blue.setText("")
198 self.green.setText("")
199 self.yellow.setText("")
200 self.blue.setText("")
203 entry = self.getCurrentConfigPath()
206 self.diseqccommand("stop")
207 self.isMoving = False
208 self.stopOnLock = False
210 self.diseqccommand("moveWest", 0)
212 self.updateColors("move")
213 elif entry == "limits":
214 self.diseqccommand("limitOff")
215 elif entry == "tune":
216 self.session.openWithCallback(self.tune, TunerScreen, self.feid)
217 elif entry == "goto0":
218 print "move to position 0"
219 self.diseqccommand("moveTo", 0)
222 entry = self.getCurrentConfigPath()
225 self.diseqccommand("stop")
226 self.isMoving = False
227 self.stopOnLock = False
230 self.stopOnLock = True
231 self.diseqccommand("moveWest", 0)
232 self.updateColors("move")
233 elif entry == "finemove":
234 print "stepping west"
235 self.diseqccommand("moveWest", 0xFF) # one step
236 elif entry == "storage":
237 print "store at position", (config.positioner.storage.value + 1)
238 self.diseqccommand("store", config.positioner.storage.value + 1)
239 elif entry == "limits":
240 self.diseqccommand("limitWest")
243 entry = self.getCurrentConfigPath()
246 self.diseqccommand("stop")
247 self.isMoving = False
248 self.stopOnLock = False
251 self.stopOnLock = True
252 self.diseqccommand("moveEast", 0)
253 self.updateColors("move")
254 elif entry == "finemove":
255 print "stepping east"
256 self.diseqccommand("moveEast", 0xFF) # one step
257 elif entry == "storage":
258 print "move to position", (config.positioner.storage.value + 1)
259 self.diseqccommand("moveTo", config.positioner.storage.value + 1)
260 elif entry == "limits":
261 self.diseqccommand("limitEast")
264 entry = self.getCurrentConfigPath()
267 self.diseqccommand("stop")
268 self.isMoving = False
269 self.stopOnLock = False
271 self.diseqccommand("moveEast", 0)
273 self.updateColors("move")
275 elif entry == "limits":
276 self.diseqccommand("limitOn")
278 def diseqccommand(self, cmd, param = 0):
279 self.diseqc.command(cmd, param)
282 def updateStatus(self):
283 self["snr_percentage"].update()
284 self["agc_percentage"].update()
285 self["ber_value"].update()
286 self["snr_bar"].update()
287 self["agc_bar"].update()
288 self["ber_bar"].update()
289 self["lock_state"].update()
290 transponderdata = self.tuner.getTransponderData()
291 self["frequency_value"].setText(str(transponderdata["frequency"]))
292 self["symbolrate_value"].setText(str(transponderdata["symbol_rate"]))
293 self["fec_value"].setText(str(transponderdata["fec_inner"]))
294 if transponderdata["tuner_locked"] == 1 and self.isMoving and self.stopOnLock:
295 self.diseqccommand("stop")
296 self.isMoving = False
297 self.stopOnLock = False
298 self.updateColors(self.getCurrentConfigPath())
300 def tune(self, transponder):
301 if transponder is not None:
302 self.tuner.tune(transponder)
305 def __init__(self, feid = 0):
308 res_mgr = eDVBResourceManagerPtr()
309 if eDVBResourceManager.getInstance(res_mgr) == 0:
310 self.raw_channel = iDVBChannelPtr()
311 if res_mgr.allocateRawChannel(self.raw_channel, self.feid) == 0:
312 self.frontend = iDVBFrontendPtr()
313 if self.raw_channel.getFrontend(self.frontend) == 0:
316 print "getFrontend failed"
318 print "getRawChannel failed"
320 print "getResourceManager instance failed"
322 def getFrontend(self):
325 def command(self, what, param = 0):
327 cmd = eDVBDiseqcCommand()
328 if what == "moveWest":
329 string = 'e03169' + ("%02x" % param)
330 elif what == "moveEast":
331 string = 'e03168' + ("%02x" % param)
332 elif what == "moveTo":
333 string = 'e0316b' + ("%02x" % param)
334 elif what == "store":
335 string = 'e0316a' + ("%02x" % param)
336 elif what == "limitOn":
338 elif what == "limitOff":
340 elif what == "limitEast":
342 elif what == "limitWest":
345 string = 'e03160' #positioner stop
346 print "diseqc command:",
349 cmd.setCommandString(string)
350 self.frontend.sendDiseqc(cmd)
353 def __init__(self, frontend):
354 self.frontend = frontend
356 def tune(self, transponder):
357 print "tuning to transponder with data", transponder
358 parm = eDVBFrontendParametersSatellite()
359 parm.frequency = transponder[0] * 1000
360 parm.symbol_rate = transponder[1] * 1000
361 parm.polarisation = transponder[2]
362 parm.fec = transponder[3]
363 parm.inversion = transponder[4]
364 parm.orbital_position = transponder[5]
365 parm.system = 0 # FIXMEE !! HARDCODED DVB-S (add support for DVB-S2)
366 parm.modulation = 1 # FIXMEE !! HARDCODED QPSK
367 feparm = eDVBFrontendParameters()
368 feparm.setDVBS(parm, True)
369 self.lastparm = feparm
370 self.frontend.tune(feparm)
373 self.frontend.tune(self.lastparm)
375 def getTransponderData(self):
376 return self.frontend.readTransponderData(True)
378 class TunerScreen(ScanSetup):
380 <screen position="90,100" size="520,400" title="Tune">
381 <widget name="config" position="20,10" size="460,350" scrollbarMode="showOnDemand" />
382 <widget name="introduction" position="20,360" size="350,30" font="Regular;23" />
385 def __init__(self, session, feid):
387 ScanSetup.__init__(self, session)
389 self["introduction"].setText("")
391 def createSetup(self):
392 self.typeOfTuningEntry = None
396 self.typeOfTuningEntry = getConfigListEntry(_('Tune'), config.tuning.type)
397 self.list.append(self.typeOfTuningEntry)
398 self.satEntry = getConfigListEntry(_('Satellite'), config.tuning.sat)
399 self.list.append(self.satEntry)
400 if currentConfigSelectionElement(config.tuning.type) == "manual_transponder":
401 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
402 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
403 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
404 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
405 self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
406 elif currentConfigSelectionElement(config.tuning.type) == "predefined_transponder":
407 self.list.append(getConfigListEntry(_("Transponder"), config.tuning.transponder))
408 self["config"].list = self.list
409 self["config"].l.setList(self.list)
412 if self["config"].getCurrent() == self.typeOfTuningEntry:
414 elif self["config"].getCurrent() == self.satEntry:
418 def createConfig(self):
419 config.tuning = ConfigSubsection()
421 config.tuning.type = configElement_nonSave("config.tuning.type", configSelection, 0, (("manual_transponder", _("Manual transponder")), ("predefined_transponder", _("Predefined satellite"))))
423 config.tuning.sat = configElement_nonSave("config.tuning.sat", configSatlist, 192, nimmanager.getRotorSatListForNim(self.feid))
424 ScanSetup.createConfig(self)
427 def updateSats(self):
428 satnum = config.tuning.sat.value
429 satlist = config.tuning.sat.vals
431 transponderlist = nimmanager.getTransponders(satlist[satnum][1])
433 for x in transponderlist:
458 list.append(str(x[1]) + "," + str(x[2]) + "," + pol + "," + fec)
459 config.tuning.transponder = configElement_nonSave("config.tuning.transponder", configSelection, 0, list)
462 returnvalue = (0, 0, 0, 0, 0, 0, 0)
463 satpos = config.tuning.sat.vals[config.tuning.sat.value][1]
464 if currentConfigSelectionElement(config.tuning.type) == "manual_transponder":
465 returnvalue = (config.scan.sat.frequency.value[0], config.scan.sat.symbolrate.value[0], config.scan.sat.polarization.value, config.scan.sat.fec.value, config.scan.sat.inversion.value, satpos)
466 elif currentConfigSelectionElement(config.tuning.type) == "predefined_transponder":
467 transponder = nimmanager.getTransponders(config.tuning.sat.vals[config.tuning.sat.value][1])[config.tuning.transponder.value]
468 returnvalue = (int(transponder[1] / 1000), int(transponder[2] / 1000), transponder[3], transponder[4], 2, config.tuning.sat.vals[config.tuning.sat.value][1], satpos)
469 self.close(returnvalue)
474 class NimSelection(Screen):
476 <screen position="140,165" size="400,100" title="select Slot">
477 <widget name="nimlist" position="20,10" size="360,75" />
480 def __init__(self, session):
481 Screen.__init__(self, session)
483 nimlist = nimmanager.getNimListOfType(nimmanager.nimType["DVB-S"])
486 nimMenuList.append((_("NIM ") + (["A", "B", "C", "D"][x]) + ": " + nimmanager.getNimName(x) + " (" + nimmanager.getNimTypeName(x) + ")", x))
488 self["nimlist"] = MenuList(nimMenuList)
490 self["actions"] = ActionMap(["OkCancelActions"],
492 "ok": self.okbuttonClick ,
496 def okbuttonClick(self):
497 selection = self["nimlist"].getCurrent()
498 self.session.open(PositionerSetup, selection[1])
500 def PositionerMain(session, **kwargs):
501 nimList = nimmanager.getNimListOfType(nimmanager.nimType["DVB-S"])
502 if len(nimList) == 0:
503 session.open(MessageBox, _("No positioner capable frontend found."), MessageBox.TYPE_ERROR)
505 if session.nav.RecordTimer.isRecording():
506 session.open(MessageBox, _("A recording is currently running. Please stop the recording before trying to configure the positioner."), MessageBox.TYPE_ERROR)
510 configured_rotor_sats = nimmanager.getRotorSatListForNim(x)
511 if len(configured_rotor_sats) != 0:
513 if len(usableNims) == 1:
514 session.open(PositionerSetup, usableNims[0])
515 elif len(usableNims) > 1:
516 session.open(NimSelection)
518 session.open(MessageBox, _("No tuner is configured for use with a diseqc positioner!"), MessageBox.TYPE_ERROR)
520 def Plugins(**kwargs):
521 return PluginDescriptor(name="Positioner setup", description="Setup your positioner", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=PositionerMain)