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, getConfigSatlist
12 from Components.MenuList import MenuList
13 from Components.config import ConfigSelection, ConfigSatlist, getConfigListEntry
16 def __init__(self, frontend):
17 self.frontend = frontend
19 def tune(self, transponder):
21 print "tuning to transponder with data", transponder
22 parm = eDVBFrontendParametersSatellite()
23 parm.frequency = transponder[0] * 1000
24 parm.symbol_rate = transponder[1] * 1000
25 parm.polarisation = transponder[2]
26 parm.fec = transponder[3]
27 parm.inversion = transponder[4]
28 parm.orbital_position = transponder[5]
29 parm.system = 0 # FIXMEE !! HARDCODED DVB-S (add support for DVB-S2)
30 parm.modulation = 1 # FIXMEE !! HARDCODED QPSK
31 feparm = eDVBFrontendParameters()
33 self.lastparm = feparm
34 self.frontend.tune(feparm)
38 self.frontend.tune(self.lastparm)
40 class Satfinder(ScanSetup):
42 <screen position="90,100" size="520,400" title="Tune">
43 <widget name="config" position="20,10" size="460,240" scrollbarMode="showOnDemand" />
44 <widget name="introduction" position="20,360" zPosition="-10" size="350,30" font="Regular;23" />
45 <widget name="snr" text="SNR:" position="0,245" size="60,22" font="Regular;21" />
46 <widget name="agc" text="AGC:" position="0,270" size="60,22" font="Regular;21" />
47 <widget name="ber" text="BER:" position="0,295" size="60,22" font="Regular;21" />
48 <widget name="lock" text="Lock:" position="0,320" size="60,22" font="Regular;21" />
49 <widget name="snr_percentage" position="220,245" size="60,22" font="Regular;21" />
50 <widget name="agc_percentage" position="220,270" size="60,22" font="Regular;21" />
51 <widget name="ber_value" position="220,295" size="60,22" font="Regular;21" />
52 <widget name="lock_state" position="60,320" size="150,22" font="Regular;21" />
53 <widget name="snr_bar" position="60,245" size="150,22" />
54 <widget name="agc_bar" position="60,270" size="150,22" />
55 <widget name="ber_bar" position="60,295" size="150,22" />
58 def openFrontend(self):
59 res_mgr = eDVBResourceManagerPtr()
60 if eDVBResourceManager.getInstance(res_mgr) == 0:
61 self.raw_channel = iDVBChannelPtr()
62 if res_mgr.allocateRawChannel(self.raw_channel, self.feid) == 0:
63 self.frontend = iDVBFrontendPtr()
64 if self.raw_channel.getFrontend(self.frontend) == 0:
67 print "getFrontend failed"
69 print "getRawChannel failed"
71 print "getResourceManager instance failed"
74 def getFrontend(self):
77 def __init__(self, session, feid):
78 self.initcomplete = False
82 if not self.openFrontend():
83 self.oldref = session.nav.getCurrentlyPlayingServiceReference()
84 session.nav.stopService() # try to disable foreground service
85 if not self.openFrontend():
86 if session.pipshown: # try to disable pip
87 session.pipshown = False
89 if not self.openFrontend():
90 self.frontend = None # in normal case this should not happen
91 self.getFrontend = None
93 ScanSetup.__init__(self, session)
94 self.tuner = Tuner(self.frontend)
99 self["lock"] = Label()
100 self["snr_percentage"] = TunerInfo(TunerInfo.SNR_PERCENTAGE, frontendfkt = self.getFrontend)
101 self["agc_percentage"] = TunerInfo(TunerInfo.AGC_PERCENTAGE, frontendfkt = self.getFrontend)
102 self["ber_value"] = TunerInfo(TunerInfo.BER_VALUE, frontendfkt = self.getFrontend)
103 self["snr_bar"] = TunerInfo(TunerInfo.SNR_BAR, frontendfkt = self.getFrontend)
104 self["agc_bar"] = TunerInfo(TunerInfo.AGC_BAR, frontendfkt = self.getFrontend)
105 self["ber_bar"] = TunerInfo(TunerInfo.BER_BAR, frontendfkt = self.getFrontend)
106 self["lock_state"] = TunerInfo(TunerInfo.LOCK_STATE, frontendfkt = self.getFrontend)
108 self["introduction"].setText("")
110 self.statusTimer = eTimer()
111 self.statusTimer.timeout.get().append(self.updateStatus)
112 self.statusTimer.start(50, False)
114 self.initcomplete = True
115 self.session = session
117 def updateStatus(self):
118 self["snr_percentage"].update()
119 self["agc_percentage"].update()
120 self["ber_value"].update()
121 self["snr_bar"].update()
122 self["agc_bar"].update()
123 self["ber_bar"].update()
124 self["lock_state"].update()
126 def createSetup(self):
127 self.typeOfTuningEntry = None
131 self.typeOfTuningEntry = getConfigListEntry(_('Tune'), self.tuning_type)
132 self.list.append(self.typeOfTuningEntry)
133 self.satEntry = getConfigListEntry(_('Satellite'), self.tuning_sat)
134 self.list.append(self.satEntry)
135 if self.tuning_type.value == "manual_transponder":
136 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
137 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
138 self.list.append(getConfigListEntry(_('Symbol Rate'), self.scan_sat.symbolrate))
139 self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
140 self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
141 elif self.tuning_transponder and self.tuning_type.value == "predefined_transponder":
142 self.list.append(getConfigListEntry(_("Transponder"), self.tuning_transponder))
143 self["config"].list = self.list
144 self["config"].l.setList(self.list)
147 if self["config"].getCurrent() == self.typeOfTuningEntry:
149 elif self["config"].getCurrent() == self.satEntry:
153 def sat_changed(self, config_element):
155 self.retune(config_element)
157 def retune(self, configElement):
158 returnvalue = (0, 0, 0, 0, 0, 0, 0)
159 satpos = self.tuning_sat.orbital_position
161 if satpos is not None:
162 if self.tuning_type.value == "manual_transponder":
163 returnvalue = (self.scan_sat.frequency.value, self.scan_sat.symbolrate.value, self.scan_sat.polarization.index, self.scan_sat.fec.index, self.scan_sat.inversion.index, satpos)
164 elif self.tuning_type.value == "predefined_transponder":
165 transponder = nimmanager.getTransponders(satpos)[self.tuning_transponder.index]
166 returnvalue = (int(transponder[1] / 1000), int(transponder[2] / 1000), transponder[3], transponder[4], 2, satpos)
167 self.tune(returnvalue)
169 def createConfig(self, foo):
170 self.tuning_transponder = None
171 self.tuning_type = ConfigSelection(choices = [("manual_transponder", _("Manual transponder")), ("predefined_transponder", _("Predefined transponder"))])
172 self.tuning_sat = getConfigSatlist(192, nimmanager.getSatListForNim(self.feid))
173 ScanSetup.createConfig(self, None)
177 self.tuning_type.addNotifier(self.retune, initial_call = False)
178 self.tuning_sat.addNotifier(self.sat_changed, initial_call = False)
179 self.scan_sat.frequency.addNotifier(self.retune, initial_call = False)
180 self.scan_sat.inversion.addNotifier(self.retune, initial_call = False)
181 self.scan_sat.symbolrate.addNotifier(self.retune, initial_call = False)
182 self.scan_sat.polarization.addNotifier(self.retune, initial_call = False)
183 self.scan_sat.fec.addNotifier(self.retune, initial_call = False)
185 def updateSats(self):
186 orb_pos = self.tuning_sat.orbital_position
187 if orb_pos is not None:
188 transponderlist = nimmanager.getTransponders(orb_pos)
190 for x in transponderlist:
215 list.append(str(x[1]) + "," + str(x[2]) + "," + pol + "," + fec)
216 self.tuning_transponder = ConfigSelection(choices = list)
217 self.tuning_transponder.addNotifier(self.retune, initial_call = False)
220 self.retune(self.tuning_type)
222 def restartPrevService(self, yesno):
227 self.session.nav.playService(self.oldref)
232 self.session.openWithCallback(self.restartPrevService, MessageBox, _("Zap back to service before satfinder?"), MessageBox.TYPE_YESNO)
234 self.restartPrevService(False)
236 def tune(self, transponder):
237 if self.initcomplete:
238 if transponder is not None:
239 self.tuner.tune(transponder)
241 class NimSelection(Screen):
243 <screen position="140,165" size="400,100" title="select Slot">
244 <widget name="nimlist" position="20,10" size="360,75" />
247 def __init__(self, session):
248 Screen.__init__(self, session)
250 nimlist = nimmanager.getNimListOfType(nimmanager.nimType["DVB-S"])
253 nimMenuList.append((_("NIM ") + (["A", "B", "C", "D"][x]) + ": " + nimmanager.getNimName(x) + " (" + nimmanager.getNimTypeName(x) + ")", x))
255 self["nimlist"] = MenuList(nimMenuList)
257 self["actions"] = ActionMap(["OkCancelActions"],
259 "ok": self.okbuttonClick ,
263 def okbuttonClick(self):
264 selection = self["nimlist"].getCurrent()
265 self.session.open(Satfinder, selection[1])
267 def SatfinderMain(session, **kwargs):
268 nimList = nimmanager.getNimListOfType(nimmanager.nimType["DVB-S"])
269 if len(nimList) == 0:
270 session.open(MessageBox, _("No satellite frontend found!!"), MessageBox.TYPE_ERROR)
272 if session.nav.RecordTimer.isRecording():
273 session.open(MessageBox, _("A recording is currently running. Please stop the recording before trying to start the satfinder."), MessageBox.TYPE_ERROR)
275 if len(nimList) == 1:
276 session.open(Satfinder, nimList[0])
278 session.open(NimSelection)
280 def SatfinderStart(menuid):
282 return [(_("Satfinder"), SatfinderMain)]
286 def Plugins(**kwargs):
287 return PluginDescriptor(name=_("Satfinder"), description="Helps setting up your dish", where = PluginDescriptor.WHERE_SETUP, fnc=SatfinderStart)