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):
22 size = getDesktop(0).size()
23 position_params = size.width() > 750 and ('center') or ('140')
25 <screen name="Blindscan" position="center,%s" size="560,370" title="Blindscan">
26 <ePixmap pixmap="Vu_HD/buttons/red.png" position="5,0" size="80,40" alphatest="on" />
27 <ePixmap pixmap="Vu_HD/buttons/green.png" position="186,0" size="80,40" alphatest="on" />
28 <ePixmap pixmap="Vu_HD/buttons/blue.png" position="372,0" size="80,40" alphatest="on" />
30 <widget source="key_red" render="Label" position="28,0" zPosition="1" size="160,30" font="Regular;20" halign="center" valign="center" transparent="1"/>
31 <widget source="key_green" render="Label" position="213,0" zPosition="1" size="160,30" font="Regular;20" halign="center" valign="center" transparent="1"/>
32 <widget source="key_blue" render="Label" position="400,0" zPosition="1" size="160,30" font="Regular;20" halign="center" valign="center" transparent="1"/>
34 <widget name="config" position="5,50" size="550,280" scrollbarMode="showOnDemand" />
35 <widget name="introduction" position="0,345" size="560,20" font="Regular;20" halign="center" />
39 def __init__(self, session):
40 Screen.__init__(self, session)
42 self.current_play_service = self.session.nav.getCurrentlyPlayingServiceReference()
46 for slot in nimmanager.nim_slots:
47 if slot.isCompatible("DVB-S"):
48 self.satList.append(nimmanager.getSatListForNim(slot.slot))
50 self.satList.append(None)
58 ConfigListScreen.__init__(self, self.list)
59 if self.scan_nims.value != None and self.scan_nims.value != "" :
60 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", ],
62 "red": self.keyCancel,
66 "cancel": self.keyCancel,
68 self["key_red"] = StaticText(_("Exit"))
69 self["key_green"] = StaticText("Scan")
70 self["key_blue"] = StaticText("Scan All")
71 self["introduction"] = Label(_("Press Green/OK to start the scan"))
74 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", ],
76 "red": self.keyCancel,
77 "green": self.keyNone,
80 "cancel": self.keyCancel,
82 self["key_red"] = StaticText(_("Exit"))
83 self["key_green"] = StaticText(" ")
84 self["key_blue"] = StaticText(" ")
85 self["introduction"] = Label(_("Please setup your tuner configuration."))
87 self.i2c_mapping_table = None
90 def makeNimSocket(self):
91 self.i2c_mapping_table = {0:2, 1:3, 2:1, 3:0}
93 def getNimSocket(self, slot_number):
94 if slot_number < 0 or slot_number > 3:
96 return self.i2c_mapping_table[slot_number]
100 def callbackNone(self, *retval):
103 def openFrontend(self):
104 res_mgr = eDVBResourceManager.getInstance()
106 self.raw_channel = res_mgr.allocateRawChannel(self.feid)
108 self.frontend = self.raw_channel.getFrontend()
112 print "getFrontend failed"
114 print "getRawChannel failed"
116 print "getResourceManager instance failed"
119 def createConfig(self):
124 "system": eDVBFrontendParametersSatellite.System_DVB_S,
126 "inversion": eDVBFrontendParametersSatellite.Inversion_Unknown,
128 "polarization": eDVBFrontendParametersSatellite.Polarisation_Horizontal,
129 "fec": eDVBFrontendParametersSatellite.FEC_Auto,
130 "fec_s2": eDVBFrontendParametersSatellite.FEC_9_10,
131 "modulation": eDVBFrontendParametersSatellite.Modulation_QPSK
134 self.service = self.session.nav.getCurrentService()
135 if self.service is not None:
136 self.feinfo = self.service.frontendInfo()
137 frontendData = self.feinfo and self.feinfo.getAll(True)
138 if frontendData is not None:
139 ttype = frontendData.get("tuner_type", "UNKNOWN")
141 defaultSat["system"] = frontendData.get("system", eDVBFrontendParametersSatellite.System_DVB_S)
142 defaultSat["frequency"] = frontendData.get("frequency", 0) / 1000
143 defaultSat["inversion"] = frontendData.get("inversion", eDVBFrontendParametersSatellite.Inversion_Unknown)
144 defaultSat["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
145 defaultSat["polarization"] = frontendData.get("polarization", eDVBFrontendParametersSatellite.Polarisation_Horizontal)
146 if defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2:
147 defaultSat["fec_s2"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
148 defaultSat["rolloff"] = frontendData.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35)
149 defaultSat["pilot"] = frontendData.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown)
151 defaultSat["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
152 defaultSat["modulation"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
153 defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
158 self.scan_sat = ConfigSubsection()
159 self.scan_networkScan = ConfigYesNo(default = False)
162 self.blindscan_hi = ConfigSelection(default = "hi_low", choices = [("low", _("low")), ("high", _("high")), ("hi_low", _("hi_low"))])
164 #ConfigYesNo(default = True)
165 self.blindscan_start_frequency = ConfigInteger(default = 950*1000000)
166 self.blindscan_stop_frequency = ConfigInteger(default = 2150*1000000)
167 self.blindscan_start_symbol = ConfigInteger(default = 2*1000000)
168 self.blindscan_stop_symbol = ConfigInteger(default = 45*1000000)
169 self.scan_clearallservices = ConfigYesNo(default = False)
170 self.scan_onlyfree = ConfigYesNo(default = False)
172 # collect all nims which are *not* set to "nothing"
174 for n in nimmanager.nim_slots:
175 if n.config_mode == "nothing":
177 if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
179 if n.config_mode in ("loopthrough", "satposdepends"):
180 root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
181 if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
183 if n.isCompatible("DVB-S"):
184 nim_list.append((str(n.slot), n.friendly_full_description))
185 self.scan_nims = ConfigSelection(choices = nim_list)
188 self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
189 #self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [
190 self.scan_sat.polarization = ConfigSelection(default = eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1, choices = [
191 (eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1, _("horizontal_vertical")),
192 (eDVBFrontendParametersSatellite.Polarisation_Horizontal, _("horizontal")),
193 (eDVBFrontendParametersSatellite.Polarisation_Vertical, _("vertical")),
194 (eDVBFrontendParametersSatellite.Polarisation_CircularLeft, _("circular left")),
195 (eDVBFrontendParametersSatellite.Polarisation_CircularRight, _("circular right"))])
196 self.scan_scansat = {}
197 for sat in nimmanager.satList:
198 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
200 self.scan_satselection = []
201 for slot in nimmanager.nim_slots:
202 if slot.isCompatible("DVB-S"):
203 self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], self.satList[slot.slot]))
206 def getSelectedSatIndex(self, v):
209 for n in self.satList:
210 if self.satList[index] == None:
211 none_cnt = none_cnt + 1
213 return (index-none_cnt)
217 def createSetup(self):
219 self.multiscanlist = []
220 index_to_scan = int(self.scan_nims.value)
221 print "ID: ", index_to_scan
223 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
224 self.list.append(self.tunerEntry)
226 if self.scan_nims == [ ]:
229 self.systemEntry = None
230 self.modulationEntry = None
231 nim = nimmanager.nim_slots[index_to_scan]
233 self.scan_networkScan.value = False
234 if nim.isCompatible("DVB-S") :
235 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[self.getSelectedSatIndex(index_to_scan)]))
236 self.list.append(getConfigListEntry(_('Scan start frequency'), self.blindscan_start_frequency))
237 self.list.append(getConfigListEntry(_('Scan stop frequency'), self.blindscan_stop_frequency))
238 self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
239 self.list.append(getConfigListEntry(_("Scan band"), self.blindscan_hi))
240 self.list.append(getConfigListEntry(_('Scan start symbolrate'), self.blindscan_start_symbol))
241 self.list.append(getConfigListEntry(_('Scan stop symbolrate'), self.blindscan_stop_symbol))
242 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
243 self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
244 self["config"].list = self.list
245 self["config"].l.setList(self.list)
248 cur = self["config"].getCurrent()
250 if cur == self.tunerEntry or \
251 cur == self.systemEntry or \
252 (self.modulationEntry and self.systemEntry[1].value == eDVBFrontendParametersSatellite.System_DVB_S2 and cur == self.modulationEntry):
255 def checkSettings(self):
256 if self.blindscan_start_frequency.value < 950*1000000 or self.blindscan_start_frequency.value > 2150*1000000 :
257 self.session.open(MessageBox, _("Please check again.\nStart frequency must be between 950 and 2150."), MessageBox.TYPE_ERROR)
259 if self.blindscan_stop_frequency.value < 950*1000000 or self.blindscan_stop_frequency.value > 2150*1000000 :
260 self.session.open(MessageBox, _("Please check again.\nStop frequency must be between 950 and 2150."), MessageBox.TYPE_ERROR)
262 if self.blindscan_start_frequency.value > self.blindscan_stop_frequency.value :
263 self.session.open(MessageBox, _("Please check again.\nFrequency : start value is larger than stop value."), MessageBox.TYPE_ERROR)
265 if self.blindscan_start_symbol.value < 2*1000000 or self.blindscan_start_symbol.value > 45*1000000 :
266 self.session.open(MessageBox, _("Please check again.\nStart symbolrate must be between 2MHz and 45MHz."), MessageBox.TYPE_ERROR)
268 if self.blindscan_stop_symbol.value < 2*1000000 or self.blindscan_stop_symbol.value > 45*1000000 :
269 self.session.open(MessageBox, _("Please check again.\nStop symbolrate must be between 2MHz and 45MHz."), MessageBox.TYPE_ERROR)
271 if self.blindscan_start_symbol.value > self.blindscan_stop_symbol.value :
272 self.session.open(MessageBox, _("Please check again.\nSymbolrate : start value is larger than stop value."), MessageBox.TYPE_ERROR)
277 ConfigListScreen.keyLeft(self)
281 ConfigListScreen.keyRight(self)
285 self.session.nav.playService(self.current_play_service)
286 for x in self["config"].list:
291 if self.checkSettings() == False:
295 eDVBFrontendParametersSatellite.Polarisation_Horizontal : "horizontal",
296 eDVBFrontendParametersSatellite.Polarisation_Vertical : "vertical",
297 eDVBFrontendParametersSatellite.Polarisation_CircularLeft : "circular left",
298 eDVBFrontendParametersSatellite.Polarisation_CircularRight : "circular right",
299 eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1 : "horizontal_vertical"
305 idx_selected_sat = int(self.getSelectedSatIndex(self.scan_nims.value))
306 tmp_list=[self.satList[int(self.scan_nims.value)][self.scan_satselection[idx_selected_sat].index]]
308 if self.blindscan_hi.value == "hi_low" :
309 tmp_band=["low","high"]
311 tmp_band=[self.blindscan_hi.value]
313 if self.scan_sat.polarization.value == eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1 :
314 tmp_pol=["horizontal","vertical"]
316 tmp_pol=[tab_pol[self.scan_sat.polarization.value]]
318 self.doRun(tmp_list, tmp_pol, tmp_band)
321 if self.checkSettings() == False:
325 tmp_band=["low","high"]
326 tmp_pol=["horizontal","vertical"]
328 for slot in nimmanager.nim_slots:
329 device_name = "/dev/dvb/adapter0/frontend%d" % (slot.slot)
330 if slot.isCompatible("DVB-S") and int(self.scan_nims.value) == slot.slot:
331 for s in self.satList[slot.slot]:
333 self.doRun(tmp_list, tmp_pol, tmp_band)
335 def doRun(self, tmp_list, tmp_pol, tmp_band):
341 self.total_list.append([x,y,z])
342 print "add scan item : ", x, ", ", y, ", ", z
344 self.max_count = len(self.total_list)
345 self.is_runable = True
346 self.running_count = 0
347 self.clockTimer = eTimer()
348 self.clockTimer.callback.append(self.doClock)
349 self.clockTimer.start(1000)
354 if self.running_count >= self.max_count:
355 self.clockTimer.stop()
357 self.clockTimer = None
360 orb = self.total_list[self.running_count][0]
361 pol = self.total_list[self.running_count][1]
362 band = self.total_list[self.running_count][2]
363 self.running_count = self.running_count + 1
364 print "running status-[%d] : [%d][%s][%s]" %(self.running_count, orb[0], pol, band)
365 if self.running_count == self.max_count:
367 self.prepareScanData(orb, pol, band, is_scan)
369 def prepareScanData(self, orb, pol, band, is_scan):
370 self.is_runable = False
371 self.orb_position = orb[0]
372 self.feid = int(self.scan_nims.value)
373 tab_hilow = {"high" : 1, "low" : 0}
375 "horizontal" : eDVBFrontendParametersSatellite.Polarisation_Horizontal,
376 "vertical" : eDVBFrontendParametersSatellite.Polarisation_Vertical,
377 "circular left" : eDVBFrontendParametersSatellite.Polarisation_CircularLeft,
378 "circular right" : eDVBFrontendParametersSatellite.Polarisation_CircularRight
381 returnvalue = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
383 if not self.openFrontend():
384 self.oldref = self.session.nav.getCurrentlyPlayingServiceReference()
385 self.session.nav.stopService()
386 if not self.openFrontend():
387 if self.session.pipshown:
388 self.session.pipshown = False
390 if not self.openFrontend():
392 self.tuner = Tuner(self.frontend)
395 self.scan_sat.frequency.value = 12515
397 self.scan_sat.frequency.value = 11015
398 returnvalue = (self.scan_sat.frequency.value,
404 eDVBFrontendParametersSatellite.System_DVB_S,
408 self.tuner.tune(returnvalue)
410 if self.getNimSocket(self.feid) < 0:
411 print "can't find i2c number!!"
414 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))
415 print "prepared command : [%s]" % (cmd)
416 self.blindscan_container = eConsoleAppContainer()
417 self.blindscan_container.appClosed.append(self.blindscanContainerClose)
418 self.blindscan_container.dataAvail.append(self.blindscanContainerAvail)
419 self.blindscan_container.execute(cmd)
421 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)
423 self.blindscan_session = self.session.openWithCallback(self.blindscanSessionClose, MessageBox, _(tmpstr), MessageBox.TYPE_INFO)
425 self.blindscan_session = self.session.openWithCallback(self.blindscanSessionNone, MessageBox, _(tmpstr), MessageBox.TYPE_INFO)
427 def blindscanContainerClose(self, retval):
428 lines = self.full_data.split('\n')
431 print "cnt :", len(data), ", data :", data
434 parm = eDVBFrontendParametersSatellite()
435 sys = { "DVB-S" : eDVBFrontendParametersSatellite.System_DVB_S,
436 "DVB-S2" : eDVBFrontendParametersSatellite.System_DVB_S2}
437 qam = { "QPSK" : parm.Modulation_QPSK,
438 "8PSK" : parm.Modulation_8PSK}
439 inv = { "INVERSION_OFF" : parm.Inversion_Off,
440 "INVERSION_ON" : parm.Inversion_On,
441 "INVERSION_AUTO" : parm.Inversion_Unknown}
442 fec = { "FEC_AUTO" : parm.FEC_Auto,
443 "FEC_1_2" : parm.FEC_1_2,
444 "FEC_2_3" : parm.FEC_2_3,
445 "FEC_3_4" : parm.FEC_3_4,
446 "FEC_5_6": parm.FEC_5_6,
447 "FEC_7_8" : parm.FEC_7_8,
448 "FEC_8_9" : parm.FEC_8_9,
449 "FEC_3_5" : parm.FEC_3_5,
450 "FEC_9_10" : parm.FEC_9_10,
451 "FEC_NONE" : parm.FEC_None}
452 roll ={ "ROLLOFF_20" : parm.RollOff_alpha_0_20,
453 "ROLLOFF_25" : parm.RollOff_alpha_0_25,
454 "ROLLOFF_35" : parm.RollOff_alpha_0_35}
455 pilot={ "PILOT_ON" : parm.Pilot_On,
456 "PILOT_OFF" : parm.Pilot_Off}
457 pol = { "HORIZONTAL" : parm.Polarisation_Horizontal,
458 "VERTICAL" : parm.Polarisation_Vertical}
460 parm.orbital_position = self.orb_position
461 parm.polarisation = pol[data[1]]
462 parm.frequency = int(data[2])
463 parm.symbol_rate = int(data[3])
464 parm.system = sys[data[4]]
465 parm.inversion = inv[data[5]]
466 parm.pilot = pilot[data[6]]
467 parm.fec = fec[data[7]]
468 parm.modulation = qam[data[8]]
469 parm.rolloff = roll[data[9]]
470 self.tmp_tplist.append(parm)
473 self.blindscan_session.close(True)
475 def blindscanContainerAvail(self, str):
477 #if str.startswith("OK"):
478 self.full_data = self.full_data + str
480 def blindscanSessionNone(self, *val):
482 self.blindscan_container.sendCtrlC()
483 self.blindscan_container = None
492 self.running_count = self.max_count
494 self.is_runable = True
496 def blindscanSessionClose(self, *val):
497 self.blindscanSessionNone(val[0])
499 if self.tmp_tplist != None and self.tmp_tplist != []:
500 for p in self.tmp_tplist:
501 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)
503 self.startScan(self.tmp_tplist, self.feid)
505 msg = "No found transponders!!\nPlease check the satellite connection, or scan other search condition."
507 msg = "Blindscan was canceled by the user."
508 self.session.openWithCallback(self.callbackNone, MessageBox, _(msg), MessageBox.TYPE_INFO, timeout=10)
511 def startScan(self, tlist, feid, networkid = 0):
512 self.scan_session = None
515 if self.scan_clearallservices.value:
516 flags |= eComponentScan.scanRemoveServices
518 flags |= eComponentScan.scanDontRemoveUnscanned
519 if self.scan_onlyfree.value:
520 flags |= eComponentScan.scanOnlyFree
521 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags, "networkid": networkid}])
523 def main(session, **kwargs):
524 session.open(Blindscan)
526 def Plugins(**kwargs):
527 return PluginDescriptor(name=_("Blindscan"), description="scan type(DVB-S)", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)