1 from Plugins.Plugin import PluginDescriptor
3 from Screens.Screen import Screen
4 from Screens.ServiceScan import ServiceScan
5 from Screens.MessageBox import MessageBox
6 from Screens.DefaultWizard import DefaultWizard
8 from Components.Label import Label
9 from Components.TuneTest import Tuner
10 from Components.ConfigList import ConfigListScreen
11 from Components.Sources.StaticText import StaticText
12 from Components.ActionMap import NumberActionMap, ActionMap
13 from Components.NimManager import nimmanager, getConfigSatlist
14 from Components.config import config, ConfigSubsection, ConfigSelection, ConfigYesNo, ConfigInteger, getConfigListEntry, ConfigSlider, ConfigEnableDisable
16 from Tools.HardwareInfo import HardwareInfo
17 from Tools.Directories import resolveFilename, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITION
19 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager, getDesktop
21 class Blindscan(ConfigListScreen, Screen):
23 <screen position="center,center" size="560,390" title="Blindscan">
24 <ePixmap pixmap="skin_default/buttons/red.png" position="40,10" size="140,40" alphatest="on" />
25 <ePixmap pixmap="skin_default/buttons/green.png" position="210,10" size="140,40" alphatest="on" />
26 <ePixmap pixmap="skin_default/buttons/blue.png" position="380,10" size="140,40" alphatest="on" />
28 <widget source="key_red" render="Label" position="40,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1"/>
29 <widget source="key_green" render="Label" position="210,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1"/>
30 <widget source="key_blue" render="Label" position="380,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1"/>
32 <widget name="config" position="5,70" size="550,280" scrollbarMode="showOnDemand" />
33 <widget name="introduction" position="0,365" size="560,20" font="Regular;20" halign="center" />
37 def __init__(self, session):
38 Screen.__init__(self, session)
40 self.current_play_service = self.session.nav.getCurrentlyPlayingServiceReference()
44 for slot in nimmanager.nim_slots:
45 if slot.isCompatible("DVB-S"):
46 self.satList.append(nimmanager.getSatListForNim(slot.slot))
48 self.satList.append(None)
56 ConfigListScreen.__init__(self, self.list)
57 if self.scan_nims.value != None and self.scan_nims.value != "" :
58 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", ],
60 "red": self.keyCancel,
64 "cancel": self.keyCancel,
66 self["key_red"] = StaticText(_("Exit"))
67 self["key_green"] = StaticText("Scan")
68 self["key_blue"] = StaticText("Scan All")
69 self["introduction"] = Label(_("Press Green/OK to start the scan"))
72 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", ],
74 "red": self.keyCancel,
75 "green": self.keyNone,
78 "cancel": self.keyCancel,
80 self["key_red"] = StaticText(_("Exit"))
81 self["key_green"] = StaticText(" ")
82 self["key_blue"] = StaticText(" ")
83 self["introduction"] = Label(_("Please setup your tuner configuration."))
85 self.i2c_mapping_table = None
88 def makeNimSocket(self):
89 self.i2c_mapping_table = {0:2, 1:3, 2:1, 3:0}
91 def getNimSocket(self, slot_number):
92 if slot_number < 0 or slot_number > 3:
94 return self.i2c_mapping_table[slot_number]
98 def callbackNone(self, *retval):
101 def openFrontend(self):
102 res_mgr = eDVBResourceManager.getInstance()
104 self.raw_channel = res_mgr.allocateRawChannel(self.feid)
106 self.frontend = self.raw_channel.getFrontend()
110 print "getFrontend failed"
112 print "getRawChannel failed"
114 print "getResourceManager instance failed"
117 def createConfig(self):
122 "system": eDVBFrontendParametersSatellite.System_DVB_S,
124 "inversion": eDVBFrontendParametersSatellite.Inversion_Unknown,
126 "polarization": eDVBFrontendParametersSatellite.Polarisation_Horizontal,
127 "fec": eDVBFrontendParametersSatellite.FEC_Auto,
128 "fec_s2": eDVBFrontendParametersSatellite.FEC_9_10,
129 "modulation": eDVBFrontendParametersSatellite.Modulation_QPSK
132 self.service = self.session.nav.getCurrentService()
133 if self.service is not None:
134 self.feinfo = self.service.frontendInfo()
135 frontendData = self.feinfo and self.feinfo.getAll(True)
136 if frontendData is not None:
137 ttype = frontendData.get("tuner_type", "UNKNOWN")
139 defaultSat["system"] = frontendData.get("system", eDVBFrontendParametersSatellite.System_DVB_S)
140 defaultSat["frequency"] = frontendData.get("frequency", 0) / 1000
141 defaultSat["inversion"] = frontendData.get("inversion", eDVBFrontendParametersSatellite.Inversion_Unknown)
142 defaultSat["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
143 defaultSat["polarization"] = frontendData.get("polarization", eDVBFrontendParametersSatellite.Polarisation_Horizontal)
144 if defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2:
145 defaultSat["fec_s2"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
146 defaultSat["rolloff"] = frontendData.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35)
147 defaultSat["pilot"] = frontendData.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown)
149 defaultSat["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
150 defaultSat["modulation"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
151 defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
156 self.scan_sat = ConfigSubsection()
157 self.scan_networkScan = ConfigYesNo(default = False)
160 self.blindscan_hi = ConfigSelection(default = "hi_low", choices = [("low", _("low")), ("high", _("high")), ("hi_low", _("hi_low"))])
162 #ConfigYesNo(default = True)
163 self.blindscan_start_frequency = ConfigInteger(default = 950*1000000)
164 self.blindscan_stop_frequency = ConfigInteger(default = 2150*1000000)
165 self.blindscan_start_symbol = ConfigInteger(default = 2*1000000)
166 self.blindscan_stop_symbol = ConfigInteger(default = 45*1000000)
167 self.scan_clearallservices = ConfigYesNo(default = False)
168 self.scan_onlyfree = ConfigYesNo(default = False)
170 # collect all nims which are *not* set to "nothing"
172 for n in nimmanager.nim_slots:
173 if n.config_mode == "nothing":
175 if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
177 if n.config_mode in ("loopthrough", "satposdepends"):
178 root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
179 if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
181 if n.isCompatible("DVB-S"):
182 nim_list.append((str(n.slot), n.friendly_full_description))
183 self.scan_nims = ConfigSelection(choices = nim_list)
186 self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
187 #self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [
188 self.scan_sat.polarization = ConfigSelection(default = eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1, choices = [
189 (eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1, _("horizontal_vertical")),
190 (eDVBFrontendParametersSatellite.Polarisation_Horizontal, _("horizontal")),
191 (eDVBFrontendParametersSatellite.Polarisation_Vertical, _("vertical")),
192 (eDVBFrontendParametersSatellite.Polarisation_CircularLeft, _("circular left")),
193 (eDVBFrontendParametersSatellite.Polarisation_CircularRight, _("circular right"))])
194 self.scan_scansat = {}
195 for sat in nimmanager.satList:
196 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
198 self.scan_satselection = []
199 for slot in nimmanager.nim_slots:
200 if slot.isCompatible("DVB-S"):
201 self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], self.satList[slot.slot]))
204 def getSelectedSatIndex(self, v):
207 for n in self.satList:
208 if self.satList[index] == None:
209 none_cnt = none_cnt + 1
211 return (index-none_cnt)
215 def createSetup(self):
217 self.multiscanlist = []
218 index_to_scan = int(self.scan_nims.value)
219 print "ID: ", index_to_scan
221 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
222 self.list.append(self.tunerEntry)
224 if self.scan_nims == [ ]:
227 self.systemEntry = None
228 self.modulationEntry = None
229 nim = nimmanager.nim_slots[index_to_scan]
231 self.scan_networkScan.value = False
232 if nim.isCompatible("DVB-S") :
233 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[self.getSelectedSatIndex(index_to_scan)]))
234 self.list.append(getConfigListEntry(_('Scan start frequency'), self.blindscan_start_frequency))
235 self.list.append(getConfigListEntry(_('Scan stop frequency'), self.blindscan_stop_frequency))
236 self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
237 self.list.append(getConfigListEntry(_("Scan band"), self.blindscan_hi))
238 self.list.append(getConfigListEntry(_('Scan start symbolrate'), self.blindscan_start_symbol))
239 self.list.append(getConfigListEntry(_('Scan stop symbolrate'), self.blindscan_stop_symbol))
240 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
241 self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
242 self["config"].list = self.list
243 self["config"].l.setList(self.list)
246 cur = self["config"].getCurrent()
248 if cur == self.tunerEntry or \
249 cur == self.systemEntry or \
250 (self.modulationEntry and self.systemEntry[1].value == eDVBFrontendParametersSatellite.System_DVB_S2 and cur == self.modulationEntry):
253 def checkSettings(self):
254 if self.blindscan_start_frequency.value < 950*1000000 or self.blindscan_start_frequency.value > 2150*1000000 :
255 self.session.open(MessageBox, _("Please check again.\nStart frequency must be between 950 and 2150."), MessageBox.TYPE_ERROR)
257 if self.blindscan_stop_frequency.value < 950*1000000 or self.blindscan_stop_frequency.value > 2150*1000000 :
258 self.session.open(MessageBox, _("Please check again.\nStop frequency must be between 950 and 2150."), MessageBox.TYPE_ERROR)
260 if self.blindscan_start_frequency.value > self.blindscan_stop_frequency.value :
261 self.session.open(MessageBox, _("Please check again.\nFrequency : start value is larger than stop value."), MessageBox.TYPE_ERROR)
263 if self.blindscan_start_symbol.value < 2*1000000 or self.blindscan_start_symbol.value > 45*1000000 :
264 self.session.open(MessageBox, _("Please check again.\nStart symbolrate must be between 2MHz and 45MHz."), MessageBox.TYPE_ERROR)
266 if self.blindscan_stop_symbol.value < 2*1000000 or self.blindscan_stop_symbol.value > 45*1000000 :
267 self.session.open(MessageBox, _("Please check again.\nStop symbolrate must be between 2MHz and 45MHz."), MessageBox.TYPE_ERROR)
269 if self.blindscan_start_symbol.value > self.blindscan_stop_symbol.value :
270 self.session.open(MessageBox, _("Please check again.\nSymbolrate : start value is larger than stop value."), MessageBox.TYPE_ERROR)
275 ConfigListScreen.keyLeft(self)
279 ConfigListScreen.keyRight(self)
283 self.session.nav.playService(self.current_play_service)
284 for x in self["config"].list:
289 if self.checkSettings() == False:
293 eDVBFrontendParametersSatellite.Polarisation_Horizontal : "horizontal",
294 eDVBFrontendParametersSatellite.Polarisation_Vertical : "vertical",
295 eDVBFrontendParametersSatellite.Polarisation_CircularLeft : "circular left",
296 eDVBFrontendParametersSatellite.Polarisation_CircularRight : "circular right",
297 eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1 : "horizontal_vertical"
303 idx_selected_sat = int(self.getSelectedSatIndex(self.scan_nims.value))
304 tmp_list=[self.satList[int(self.scan_nims.value)][self.scan_satselection[idx_selected_sat].index]]
306 if self.blindscan_hi.value == "hi_low" :
307 tmp_band=["low","high"]
309 tmp_band=[self.blindscan_hi.value]
311 if self.scan_sat.polarization.value == eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1 :
312 tmp_pol=["horizontal","vertical"]
314 tmp_pol=[tab_pol[self.scan_sat.polarization.value]]
316 self.doRun(tmp_list, tmp_pol, tmp_band)
319 if self.checkSettings() == False:
323 tmp_band=["low","high"]
324 tmp_pol=["horizontal","vertical"]
326 for slot in nimmanager.nim_slots:
327 device_name = "/dev/dvb/adapter0/frontend%d" % (slot.slot)
328 if slot.isCompatible("DVB-S") and int(self.scan_nims.value) == slot.slot:
329 for s in self.satList[slot.slot]:
331 self.doRun(tmp_list, tmp_pol, tmp_band)
333 def doRun(self, tmp_list, tmp_pol, tmp_band):
339 self.total_list.append([x,y,z])
340 print "add scan item : ", x, ", ", y, ", ", z
342 self.max_count = len(self.total_list)
343 self.is_runable = True
344 self.running_count = 0
345 self.clockTimer = eTimer()
346 self.clockTimer.callback.append(self.doClock)
347 self.clockTimer.start(1000)
352 if self.running_count >= self.max_count:
353 self.clockTimer.stop()
355 self.clockTimer = None
358 orb = self.total_list[self.running_count][0]
359 pol = self.total_list[self.running_count][1]
360 band = self.total_list[self.running_count][2]
361 self.running_count = self.running_count + 1
362 print "running status-[%d] : [%d][%s][%s]" %(self.running_count, orb[0], pol, band)
363 if self.running_count == self.max_count:
365 self.prepareScanData(orb, pol, band, is_scan)
367 def prepareScanData(self, orb, pol, band, is_scan):
368 self.is_runable = False
369 self.orb_position = orb[0]
370 self.feid = int(self.scan_nims.value)
371 tab_hilow = {"high" : 1, "low" : 0}
373 "horizontal" : eDVBFrontendParametersSatellite.Polarisation_Horizontal,
374 "vertical" : eDVBFrontendParametersSatellite.Polarisation_Vertical,
375 "circular left" : eDVBFrontendParametersSatellite.Polarisation_CircularLeft,
376 "circular right" : eDVBFrontendParametersSatellite.Polarisation_CircularRight
379 returnvalue = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
381 if not self.openFrontend():
382 self.oldref = self.session.nav.getCurrentlyPlayingServiceReference()
383 self.session.nav.stopService()
384 if not self.openFrontend():
385 if self.session.pipshown:
386 self.session.pipshown = False
388 if not self.openFrontend():
390 self.tuner = Tuner(self.frontend)
393 self.scan_sat.frequency.value = 12515
395 self.scan_sat.frequency.value = 11015
396 returnvalue = (self.scan_sat.frequency.value,
402 eDVBFrontendParametersSatellite.System_DVB_S,
406 self.tuner.tune(returnvalue)
408 if self.getNimSocket(self.feid) < 0:
409 print "can't find i2c number!!"
412 cmd = "vuplus_blindscan %d %d %d %d %d %d %d %d" % (self.blindscan_start_frequency.value/1000000, self.blindscan_stop_frequency.value/1000000, self.blindscan_start_symbol.value/1000000, self.blindscan_stop_symbol.value/1000000, tab_pol[pol], tab_hilow[band], self.feid, self.getNimSocket(self.feid))
413 print "prepared command : [%s]" % (cmd)
414 self.blindscan_container = eConsoleAppContainer()
415 self.blindscan_container.appClosed.append(self.blindscanContainerClose)
416 self.blindscan_container.dataAvail.append(self.blindscanContainerAvail)
417 self.blindscan_container.execute(cmd)
419 tmpstr = "Look for available transponders.\nThis works will take several minutes.\n\n - Current Status : %d/%d\n - Orbital Positions : %s\n - Polarization : %s\n - Bandwidth : %s" %(self.running_count, self.max_count, orb[1], pol, band)
421 self.blindscan_session = self.session.openWithCallback(self.blindscanSessionClose, MessageBox, _(tmpstr), MessageBox.TYPE_INFO)
423 self.blindscan_session = self.session.openWithCallback(self.blindscanSessionNone, MessageBox, _(tmpstr), MessageBox.TYPE_INFO)
425 def blindscanContainerClose(self, retval):
426 lines = self.full_data.split('\n')
429 print "cnt :", len(data), ", data :", data
432 parm = eDVBFrontendParametersSatellite()
433 sys = { "DVB-S" : eDVBFrontendParametersSatellite.System_DVB_S,
434 "DVB-S2" : eDVBFrontendParametersSatellite.System_DVB_S2}
435 qam = { "QPSK" : parm.Modulation_QPSK,
436 "8PSK" : parm.Modulation_8PSK}
437 inv = { "INVERSION_OFF" : parm.Inversion_Off,
438 "INVERSION_ON" : parm.Inversion_On,
439 "INVERSION_AUTO" : parm.Inversion_Unknown}
440 fec = { "FEC_AUTO" : parm.FEC_Auto,
441 "FEC_1_2" : parm.FEC_1_2,
442 "FEC_2_3" : parm.FEC_2_3,
443 "FEC_3_4" : parm.FEC_3_4,
444 "FEC_5_6": parm.FEC_5_6,
445 "FEC_7_8" : parm.FEC_7_8,
446 "FEC_8_9" : parm.FEC_8_9,
447 "FEC_3_5" : parm.FEC_3_5,
448 "FEC_9_10" : parm.FEC_9_10,
449 "FEC_NONE" : parm.FEC_None}
450 roll ={ "ROLLOFF_20" : parm.RollOff_alpha_0_20,
451 "ROLLOFF_25" : parm.RollOff_alpha_0_25,
452 "ROLLOFF_35" : parm.RollOff_alpha_0_35}
453 pilot={ "PILOT_ON" : parm.Pilot_On,
454 "PILOT_OFF" : parm.Pilot_Off}
455 pol = { "HORIZONTAL" : parm.Polarisation_Horizontal,
456 "VERTICAL" : parm.Polarisation_Vertical}
458 parm.orbital_position = self.orb_position
459 parm.polarisation = pol[data[1]]
460 parm.frequency = int(data[2])
461 parm.symbol_rate = int(data[3])
462 parm.system = sys[data[4]]
463 parm.inversion = inv[data[5]]
464 parm.pilot = pilot[data[6]]
465 parm.fec = fec[data[7]]
466 parm.modulation = qam[data[8]]
467 parm.rolloff = roll[data[9]]
468 self.tmp_tplist.append(parm)
471 self.blindscan_session.close(True)
473 def blindscanContainerAvail(self, str):
475 #if str.startswith("OK"):
476 self.full_data = self.full_data + str
478 def blindscanSessionNone(self, *val):
480 self.blindscan_container.sendCtrlC()
481 self.blindscan_container = None
490 self.running_count = self.max_count
492 self.is_runable = True
494 def blindscanSessionClose(self, *val):
495 self.blindscanSessionNone(val[0])
497 if self.tmp_tplist != None and self.tmp_tplist != []:
498 for p in self.tmp_tplist:
499 print "data : [%d][%d][%d][%d][%d][%d][%d][%d][%d][%d]" % (p.orbital_position, p.polarisation, p.frequency, p.symbol_rate, p.system, p.inversion, p.pilot, p.fec, p.modulation, p.modulation)
501 self.startScan(self.tmp_tplist, self.feid)
503 msg = "No found transponders!!\nPlease check the satellite connection, or scan other search condition."
505 msg = "Blindscan was canceled by the user."
506 self.session.openWithCallback(self.callbackNone, MessageBox, _(msg), MessageBox.TYPE_INFO, timeout=10)
509 def startScan(self, tlist, feid, networkid = 0):
510 self.scan_session = None
513 if self.scan_clearallservices.value:
514 flags |= eComponentScan.scanRemoveServices
516 flags |= eComponentScan.scanDontRemoveUnscanned
517 if self.scan_onlyfree.value:
518 flags |= eComponentScan.scanOnlyFree
519 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags, "networkid": networkid}])
521 def main(session, **kwargs):
522 session.open(Blindscan)
524 def Plugins(**kwargs):
525 return PluginDescriptor(name=_("Blindscan"), description="scan type(DVB-S)", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)