[blindscan] support bcm7346 tunner.
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / Blindscan / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2
3 from Screens.Screen import Screen
4 from Screens.ServiceScan import ServiceScan
5 from Screens.MessageBox import MessageBox
6 from Screens.DefaultWizard import DefaultWizard
7
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
15
16 from Tools.HardwareInfo import HardwareInfo
17 from Tools.Directories import resolveFilename, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITION
18
19 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager, getDesktop
20
21 _modelName = file('/proc/stb/info/vumodel').read().strip()
22 _supportNimType = { 'AVL1208':'', 'AVL6222':'6222_', 'AVL6211':'6211_', 'BCM7356':'bcm7346_'}
23
24 class Blindscan(ConfigListScreen, Screen):
25         skin =  """
26                 <screen position="center,center" size="560,390" title="Blindscan">
27                         <ePixmap pixmap="skin_default/buttons/red.png" position="40,10" size="140,40" alphatest="on" />
28                         <ePixmap pixmap="skin_default/buttons/green.png" position="210,10" size="140,40" alphatest="on" />
29                         <ePixmap pixmap="skin_default/buttons/blue.png" position="380,10" size="140,40" alphatest="on" />
30
31                         <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"/>
32                         <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"/>
33                         <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"/>
34
35                         <widget name="config" position="5,70" size="550,280" scrollbarMode="showOnDemand" />
36                         <widget name="introduction" position="0,365" size="560,20" font="Regular;20" halign="center" />
37                 </screen>
38                 """
39
40         def __init__(self, session): 
41                 Screen.__init__(self, session)
42
43                 self.current_play_service = self.session.nav.getCurrentlyPlayingServiceReference()
44
45                 # update sat list
46                 self.satList = []
47                 for slot in nimmanager.nim_slots:
48                         if slot.isCompatible("DVB-S"):
49                                 self.satList.append(nimmanager.getSatListForNim(slot.slot))
50                         else:
51                                 self.satList.append(None)
52
53                 # make config
54                 self.createConfig()
55
56                 self.list = []
57                 self.status = ""
58
59                 ConfigListScreen.__init__(self, self.list)
60                 if self.scan_nims.value != None and self.scan_nims.value != "" :
61                         self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", ],
62                         {
63                                 "red": self.keyCancel,
64                                 "green": self.keyGo,
65                                 "blue":self.keyGoAll,
66                                 "ok": self.keyGo,
67                                 "cancel": self.keyCancel,
68                         }, -2)
69                         self["key_red"] = StaticText(_("Exit"))
70                         self["key_green"] = StaticText("Scan")
71                         self["key_blue"] = StaticText("Scan All")
72                         self["introduction"] = Label(_("Press Green/OK to start the scan"))
73                         self.createSetup()
74                 else :
75                         self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", ],
76                         {
77                                 "red": self.keyCancel,
78                                 "green": self.keyNone,
79                                 "blue":self.keyNone,
80                                 "ok": self.keyNone,
81                                 "cancel": self.keyCancel,
82                         }, -2)
83                         self["key_red"] = StaticText(_("Exit"))
84                         self["key_green"] = StaticText(" ")
85                         self["key_blue"] = StaticText(" ")
86                         self["introduction"] = Label(_("Please setup your tuner configuration."))
87
88                 self.i2c_mapping_table = None
89                 self.nimSockets = self.ScanNimsocket()
90                 self.makeNimSocket()
91
92         def ScanNimsocket(self, filepath = '/proc/bus/nim_sockets'):
93                 _nimSocket = {}
94                 fp = file(filepath)
95
96                 sNo, sName, sI2C = -1, "", -1
97                 for line in fp:
98                         line = line.strip()
99                         if line.startswith('NIM Socket'):
100                                 sNo, sName, sI2C = -1, '', -1
101                                 try:    sNo = line.split()[2][:-1]
102                                 except: sNo = -1
103                         elif line.startswith('I2C_Device:'):
104                                 try:    sI2C = line.split()[1]
105                                 except: sI2C = -1
106                         elif line.startswith('Name:'):
107                                 splitLines = line.split()
108                                 try:
109                                         if splitLines[1].startswith('BCM'):
110                                                 sName = splitLines[1]
111                                         else:
112                                                 sName = splitLines[3][4:-1]
113                                 except: sName = ""
114                         if sNo >= 0 and sName != "":
115                                 if sName.startswith('BCM'):
116                                         sI2C = sNo
117                                 if sI2C != -1:
118                                         _nimSocket[sNo] = [sName, sI2C]
119                                 else:   _nimSocket[sNo] = [sName]
120                 fp.close()
121                 print "parsed nimsocket :", _nimSocket
122                 return _nimSocket
123
124         def makeNimSocket(self, nimname=""):
125                 is_exist_i2c = False
126                 self.i2c_mapping_table = {0:2, 1:3, 2:1, 3:0}
127                 if self.nimSockets is not None:
128                         for XX in self.nimSockets.keys():
129                                 nimsocket = self.nimSockets[XX]
130                                 if len(nimsocket) > 1:
131                                         try:    self.i2c_mapping_table[int(XX)] = int(nimsocket[1])
132                                         except: continue
133                                         is_exist_i2c = True
134                 print "i2c_mapping_table :", self.i2c_mapping_table, ", is_exist_i2c :", is_exist_i2c
135                 if is_exist_i2c: return
136
137                 if nimname == "AVL6222":
138                         model = _modelName #file('/proc/stb/info/vumodel').read().strip()
139                         if model == "uno":
140                                 self.i2c_mapping_table = {0:3, 1:3, 2:1, 3:0}
141                         elif model == "duo2":
142                                 nimdata = self.nimSockets['0']
143                                 try:
144                                         if nimdata[0] == "AVL6222":
145                                                 self.i2c_mapping_table = {0:2, 1:2, 2:4, 3:4}
146                                         else:   self.i2c_mapping_table = {0:2, 1:4, 2:4, 3:0}
147                                 except: self.i2c_mapping_table = {0:2, 1:4, 2:4, 3:0}
148                         else:   self.i2c_mapping_table = {0:2, 1:4, 2:0, 3:0}
149                 else:   self.i2c_mapping_table = {0:2, 1:3, 2:1, 3:0}
150
151         def getNimSocket(self, slot_number):
152                 if slot_number < 0 or slot_number > 3:
153                         return -1
154                 return self.i2c_mapping_table[slot_number]
155
156         def keyNone(self):
157                 None
158         def callbackNone(self, *retval):
159                 None
160
161         def openFrontend(self):
162                 res_mgr = eDVBResourceManager.getInstance()
163                 if res_mgr:
164                         self.raw_channel = res_mgr.allocateRawChannel(self.feid)
165                         if self.raw_channel:
166                                 self.frontend = self.raw_channel.getFrontend()
167                                 if self.frontend:
168                                         return True
169                                 else:
170                                         print "getFrontend failed"
171                         else:
172                                 print "getRawChannel failed"
173                 else:
174                         print "getResourceManager instance failed"
175                 return False
176
177         def createConfig(self):
178                 self.feinfo = None
179                 frontendData = None
180                 defaultSat = {
181                         "orbpos": 192,
182                         "system": eDVBFrontendParametersSatellite.System_DVB_S,
183                         "frequency": 11836,
184                         "inversion": eDVBFrontendParametersSatellite.Inversion_Unknown,
185                         "symbolrate": 27500,
186                         "polarization": eDVBFrontendParametersSatellite.Polarisation_Horizontal,
187                         "fec": eDVBFrontendParametersSatellite.FEC_Auto,
188                         "fec_s2": eDVBFrontendParametersSatellite.FEC_9_10,
189                         "modulation": eDVBFrontendParametersSatellite.Modulation_QPSK 
190                 }
191
192                 self.service = self.session.nav.getCurrentService()
193                 if self.service is not None:
194                         self.feinfo = self.service.frontendInfo()
195                         frontendData = self.feinfo and self.feinfo.getAll(True)
196                 if frontendData is not None:
197                         ttype = frontendData.get("tuner_type", "UNKNOWN")
198                         if ttype == "DVB-S":
199                                 defaultSat["system"] = frontendData.get("system", eDVBFrontendParametersSatellite.System_DVB_S)
200                                 defaultSat["frequency"] = frontendData.get("frequency", 0) / 1000
201                                 defaultSat["inversion"] = frontendData.get("inversion", eDVBFrontendParametersSatellite.Inversion_Unknown)
202                                 defaultSat["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
203                                 defaultSat["polarization"] = frontendData.get("polarization", eDVBFrontendParametersSatellite.Polarisation_Horizontal)
204                                 if defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2:
205                                         defaultSat["fec_s2"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
206                                         defaultSat["rolloff"] = frontendData.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35)
207                                         defaultSat["pilot"] = frontendData.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown)
208                                 else:
209                                         defaultSat["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
210                                 defaultSat["modulation"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
211                                 defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
212                 del self.feinfo
213                 del self.service
214                 del frontendData
215                 
216                 self.scan_sat = ConfigSubsection()
217                 self.scan_networkScan = ConfigYesNo(default = False)
218                 
219                 # blindscan add
220                 self.blindscan_hi = ConfigSelection(default = "hi_low", choices = [("low", _("low")), ("high", _("high")), ("hi_low", _("hi_low"))])
221
222                 #ConfigYesNo(default = True)
223                 self.blindscan_start_frequency = ConfigInteger(default = 950*1000000)
224                 self.blindscan_stop_frequency = ConfigInteger(default = 2150*1000000)
225                 self.blindscan_start_symbol = ConfigInteger(default = 2*1000000)
226                 self.blindscan_stop_symbol = ConfigInteger(default = 45*1000000)
227                 self.scan_clearallservices = ConfigYesNo(default = False)
228                 self.scan_onlyfree = ConfigYesNo(default = False)
229
230                 # collect all nims which are *not* set to "nothing"
231                 nim_list = []
232                 for n in nimmanager.nim_slots:
233                         if n.config_mode == "nothing":
234                                 continue
235                         if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
236                                 continue
237                         if n.config_mode in ("loopthrough", "satposdepends"):
238                                 root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
239                                 if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
240                                         continue
241                         if n.isCompatible("DVB-S"):
242                                 nim_list.append((str(n.slot), n.friendly_full_description))
243                 self.scan_nims = ConfigSelection(choices = nim_list)
244
245                 # sat
246                 self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
247                 #self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [
248                 self.scan_sat.polarization = ConfigSelection(default = eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1, choices = [
249                         (eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1, _("horizontal_vertical")),
250                         (eDVBFrontendParametersSatellite.Polarisation_Horizontal, _("horizontal")),
251                         (eDVBFrontendParametersSatellite.Polarisation_Vertical, _("vertical")),
252                         (eDVBFrontendParametersSatellite.Polarisation_CircularLeft, _("circular left")),
253                         (eDVBFrontendParametersSatellite.Polarisation_CircularRight, _("circular right"))])
254                 self.scan_scansat = {}
255                 for sat in nimmanager.satList:
256                         self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
257                 
258                 self.scan_satselection = []
259                 for slot in nimmanager.nim_slots:
260                         if slot.isCompatible("DVB-S"):
261                                 self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], self.satList[slot.slot]))
262                 return True
263
264         def getSelectedSatIndex(self, v):
265                 index    = 0
266                 none_cnt = 0
267                 for n in self.satList:
268                         if self.satList[index] == None:
269                                 none_cnt = none_cnt + 1
270                         if index == int(v):
271                                 return (index-none_cnt)
272                         index = index + 1
273                 return -1
274
275         def createSetup(self):
276                 self.list = []
277                 self.multiscanlist = []
278                 index_to_scan = int(self.scan_nims.value)
279                 print "ID: ", index_to_scan
280
281                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
282                 self.list.append(self.tunerEntry)
283                 
284                 if self.scan_nims == [ ]:
285                         return
286                 
287                 self.systemEntry = None
288                 self.modulationEntry = None
289                 nim = nimmanager.nim_slots[index_to_scan]
290
291                 self.scan_networkScan.value = False
292                 if nim.isCompatible("DVB-S") :
293                         self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[self.getSelectedSatIndex(index_to_scan)]))
294                         self.list.append(getConfigListEntry(_('Scan start frequency'), self.blindscan_start_frequency))
295                         self.list.append(getConfigListEntry(_('Scan stop frequency'), self.blindscan_stop_frequency))
296                         self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
297                         self.list.append(getConfigListEntry(_("Scan band"), self.blindscan_hi))
298                         self.list.append(getConfigListEntry(_('Scan start symbolrate'), self.blindscan_start_symbol))
299                         self.list.append(getConfigListEntry(_('Scan stop symbolrate'), self.blindscan_stop_symbol))
300                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
301                         self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
302                         self["config"].list = self.list
303                         self["config"].l.setList(self.list)
304                         
305         def newConfig(self):
306                 cur = self["config"].getCurrent()
307                 print "cur is", cur
308                 if cur == self.tunerEntry or \
309                         cur == self.systemEntry or \
310                         (self.modulationEntry and self.systemEntry[1].value == eDVBFrontendParametersSatellite.System_DVB_S2 and cur == self.modulationEntry):
311                         self.createSetup()
312
313         def checkSettings(self):
314                 if self.blindscan_start_frequency.value < 950*1000000 or self.blindscan_start_frequency.value > 2150*1000000 :
315                         self.session.open(MessageBox, _("Please check again.\nStart frequency must be between 950 and 2150."), MessageBox.TYPE_ERROR)
316                         return False
317                 if self.blindscan_stop_frequency.value < 950*1000000 or self.blindscan_stop_frequency.value > 2150*1000000 :
318                         self.session.open(MessageBox, _("Please check again.\nStop frequency must be between 950 and 2150."), MessageBox.TYPE_ERROR)
319                         return False
320                 if self.blindscan_start_frequency.value > self.blindscan_stop_frequency.value :
321                         self.session.open(MessageBox, _("Please check again.\nFrequency : start value is larger than stop value."), MessageBox.TYPE_ERROR)
322                         return False
323                 if self.blindscan_start_symbol.value < 2*1000000 or self.blindscan_start_symbol.value > 45*1000000 :
324                         self.session.open(MessageBox, _("Please check again.\nStart symbolrate must be between 2MHz and 45MHz."), MessageBox.TYPE_ERROR)
325                         return False
326                 if self.blindscan_stop_symbol.value < 2*1000000 or self.blindscan_stop_symbol.value > 45*1000000 :
327                         self.session.open(MessageBox, _("Please check again.\nStop symbolrate must be between 2MHz and 45MHz."), MessageBox.TYPE_ERROR)
328                         return False
329                 if self.blindscan_start_symbol.value > self.blindscan_stop_symbol.value :
330                         self.session.open(MessageBox, _("Please check again.\nSymbolrate : start value is larger than stop value."), MessageBox.TYPE_ERROR)
331                         return False
332                 return True
333
334         def keyLeft(self):
335                 ConfigListScreen.keyLeft(self)
336                 self.newConfig()
337
338         def keyRight(self):
339                 ConfigListScreen.keyRight(self)
340                 self.newConfig()
341                         
342         def keyCancel(self):
343                 self.session.nav.playService(self.current_play_service)
344                 for x in self["config"].list:
345                         x[1].cancel()
346                 self.close()
347
348         def keyGo(self):
349                 if self.checkSettings() == False:
350                         return
351
352                 tab_pol = {
353                         eDVBFrontendParametersSatellite.Polarisation_Horizontal : "horizontal", 
354                         eDVBFrontendParametersSatellite.Polarisation_Vertical : "vertical",
355                         eDVBFrontendParametersSatellite.Polarisation_CircularLeft : "circular left",
356                         eDVBFrontendParametersSatellite.Polarisation_CircularRight : "circular right",
357                         eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1 : "horizontal_vertical"
358                 }
359
360                 self.tmp_tplist=[]
361                 tmp_pol = []
362                 tmp_band = []
363                 idx_selected_sat = int(self.getSelectedSatIndex(self.scan_nims.value))
364                 tmp_list=[self.satList[int(self.scan_nims.value)][self.scan_satselection[idx_selected_sat].index]]
365
366                 if self.blindscan_hi.value == "hi_low" :
367                         tmp_band=["low","high"]
368                 else:
369                         tmp_band=[self.blindscan_hi.value]
370                         
371                 if self.scan_sat.polarization.value ==  eDVBFrontendParametersSatellite.Polarisation_CircularRight + 1 : 
372                         tmp_pol=["horizontal","vertical"]
373                 else:
374                         tmp_pol=[tab_pol[self.scan_sat.polarization.value]]
375
376                 self.doRun(tmp_list, tmp_pol, tmp_band)
377                 
378         def keyGoAll(self):
379                 if self.checkSettings() == False:
380                         return
381                 self.tmp_tplist=[]
382                 tmp_list=[]
383                 tmp_band=["low","high"]
384                 tmp_pol=["horizontal","vertical"]
385                 
386                 for slot in nimmanager.nim_slots:
387                         device_name = "/dev/dvb/adapter0/frontend%d" % (slot.slot)
388                         if slot.isCompatible("DVB-S") and int(self.scan_nims.value) == slot.slot:
389                                 for s in self.satList[slot.slot]:
390                                         tmp_list.append(s)
391                 self.doRun(tmp_list, tmp_pol, tmp_band)
392                 
393         def doRun(self, tmp_list, tmp_pol, tmp_band):
394                 def GetCommand(nimIdx):
395                         _nimSocket = self.nimSockets
396                         try:
397                                 sName = _nimSocket[str(nimIdx)][0]
398                                 sType = _supportNimType[sName]
399                                 return "vuplus_%(TYPE)sblindscan"%{'TYPE':sType}, sName
400                         except: pass
401                         return "vuplus_blindscan", ""
402                 self.binName,nimName =  GetCommand(self.scan_nims.value)
403
404                 self.makeNimSocket(nimName)
405                 if self.binName is None:
406                         self.session.open(MessageBox, "Blindscan is not supported in " + nimName + " tuner.", MessageBox.TYPE_ERROR)
407                         print nimName + " is not support blindscan."
408                         return
409
410                 self.full_data = ""
411                 self.total_list=[]
412                 for x in tmp_list:
413                         for y in tmp_pol:
414                                 for z in tmp_band:
415                                         self.total_list.append([x,y,z])
416                                         print "add scan item : ", x, ", ", y, ", ", z
417
418                 self.max_count = len(self.total_list)
419                 self.is_runable = True
420                 self.running_count = 0
421                 self.clockTimer = eTimer()
422                 self.clockTimer.callback.append(self.doClock)
423                 self.clockTimer.start(1000)
424
425         def doClock(self):
426                 is_scan = False
427                 if self.is_runable :
428                         if self.running_count >= self.max_count:
429                                 self.clockTimer.stop()
430                                 del self.clockTimer
431                                 self.clockTimer = None
432                                 print "Done"
433                                 return
434                         orb = self.total_list[self.running_count][0]
435                         pol = self.total_list[self.running_count][1]
436                         band = self.total_list[self.running_count][2]
437                         self.running_count = self.running_count + 1
438                         print "running status-[%d] : [%d][%s][%s]" %(self.running_count, orb[0], pol, band)
439                         if self.running_count == self.max_count:
440                                 is_scan = True
441                         self.prepareScanData(orb, pol, band, is_scan)
442
443         def prepareScanData(self, orb, pol, band, is_scan):
444                 self.is_runable = False
445                 self.orb_position = orb[0]
446                 self.feid = int(self.scan_nims.value)
447                 tab_hilow = {"high" : 1, "low" : 0}
448                 tab_pol = {
449                         "horizontal" : eDVBFrontendParametersSatellite.Polarisation_Horizontal, 
450                         "vertical" : eDVBFrontendParametersSatellite.Polarisation_Vertical,
451                         "circular left" : eDVBFrontendParametersSatellite.Polarisation_CircularLeft,
452                         "circular right" : eDVBFrontendParametersSatellite.Polarisation_CircularRight
453                 }
454
455                 returnvalue = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
456
457                 if not self.openFrontend():
458                         self.oldref = self.session.nav.getCurrentlyPlayingServiceReference()
459                         self.session.nav.stopService()
460                         if not self.openFrontend():
461                                 if self.session.pipshown:
462                                         self.session.pipshown = False
463                                         del self.session.pip
464                                         if not self.openFrontend():
465                                                 self.frontend = None
466                 self.tuner = Tuner(self.frontend)
467
468                 if tab_hilow[band]:
469                         self.scan_sat.frequency.value = 12515
470                 else:
471                         self.scan_sat.frequency.value = 11015
472                 returnvalue = (self.scan_sat.frequency.value,
473                                          0,
474                                          tab_pol[pol],
475                                          0,
476                                          0,
477                                          orb[0],
478                                          eDVBFrontendParametersSatellite.System_DVB_S,
479                                          0,
480                                          0,
481                                          0)
482                 self.tuner.tune(returnvalue)
483
484                 if self.getNimSocket(self.feid) < 0:
485                         print "can't find i2c number!!"
486                         return
487                 try:
488                         cmd = "%s %d %d %d %d %d %d %d %d" % (self.binName, 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))
489                 except: return
490                 print "prepared command : [%s]" % (cmd)
491                 self.blindscan_container = eConsoleAppContainer()
492                 self.blindscan_container.appClosed.append(self.blindscanContainerClose)
493                 self.blindscan_container.dataAvail.append(self.blindscanContainerAvail)
494                 self.blindscan_container.execute(cmd)
495
496                 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)
497                 if is_scan :
498                         self.blindscan_session = self.session.openWithCallback(self.blindscanSessionClose, MessageBox, _(tmpstr), MessageBox.TYPE_INFO)
499                 else:
500                         self.blindscan_session = self.session.openWithCallback(self.blindscanSessionNone, MessageBox, _(tmpstr), MessageBox.TYPE_INFO)
501
502         def blindscanContainerClose(self, retval):
503                 lines = self.full_data.split('\n')
504                 for line in lines:
505                         data = line.split()
506                         print "cnt :", len(data), ", data :", data
507                         if len(data) >= 10:
508                                 if data[0] == 'OK':
509                                         parm = eDVBFrontendParametersSatellite()
510                                         sys = { "DVB-S" : eDVBFrontendParametersSatellite.System_DVB_S,
511                                                 "DVB-S2" : eDVBFrontendParametersSatellite.System_DVB_S2}
512                                         qam = { "QPSK" : parm.Modulation_QPSK,
513                                                 "8PSK" : parm.Modulation_8PSK}
514                                         inv = { "INVERSION_OFF" : parm.Inversion_Off,
515                                                 "INVERSION_ON" : parm.Inversion_On,
516                                                 "INVERSION_AUTO" : parm.Inversion_Unknown}
517                                         fec = { "FEC_AUTO" : parm.FEC_Auto,
518                                                 "FEC_1_2" : parm.FEC_1_2,
519                                                 "FEC_2_3" : parm.FEC_2_3,
520                                                 "FEC_3_4" : parm.FEC_3_4,
521                                                 "FEC_5_6": parm.FEC_5_6,
522                                                 "FEC_7_8" : parm.FEC_7_8,
523                                                 "FEC_8_9" : parm.FEC_8_9,
524                                                 "FEC_3_5" : parm.FEC_3_5,
525                                                 "FEC_9_10" : parm.FEC_9_10,
526                                                 "FEC_NONE" : parm.FEC_None}
527                                         roll ={ "ROLLOFF_20" : parm.RollOff_alpha_0_20,
528                                                 "ROLLOFF_25" : parm.RollOff_alpha_0_25,
529                                                 "ROLLOFF_35" : parm.RollOff_alpha_0_35}
530                                         pilot={ "PILOT_ON" : parm.Pilot_On,
531                                                 "PILOT_OFF" : parm.Pilot_Off,
532                                                 "PILOT_AUTO" : parm.Pilot_Unknown}
533                                         pol = { "HORIZONTAL" : parm.Polarisation_Horizontal,
534                                                 "VERTICAL" : parm.Polarisation_Vertical}
535                                         try :
536                                                 parm.orbital_position = self.orb_position
537                                                 parm.polarisation = pol[data[1]]
538                                                 parm.frequency = int(data[2])
539                                                 parm.symbol_rate = int(data[3])
540                                                 parm.system = sys[data[4]]
541                                                 parm.inversion = inv[data[5]]
542                                                 parm.pilot = pilot[data[6]]
543                                                 parm.fec = fec[data[7]]
544                                                 parm.modulation = qam[data[8]]
545                                                 parm.rolloff = roll[data[9]]
546                                                 self.tmp_tplist.append(parm)
547                                         except: pass
548                 self.blindscan_session.close(True)
549
550         def blindscanContainerAvail(self, str):
551                 print str
552                 #if str.startswith("OK"):
553                 self.full_data = self.full_data + str
554
555         def blindscanSessionNone(self, *val):
556                 import time
557                 self.blindscan_container.sendCtrlC()
558                 self.blindscan_container = None
559                 time.sleep(2)
560
561                 if self.frontend:
562                         self.frontend = None
563                         del self.raw_channel
564
565                 if val[0] == False:
566                         self.tmp_tplist = []
567                         self.running_count = self.max_count
568
569                 self.is_runable = True
570
571         def blindscanSessionClose(self, *val):
572                 self.blindscanSessionNone(val[0])
573
574                 if self.tmp_tplist != None and self.tmp_tplist != []:
575                         for p in self.tmp_tplist:
576                                 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)
577
578                         self.startScan(self.tmp_tplist, self.feid)
579                 else:
580                         msg = "No found transponders!!\nPlease check the satellite connection, or scan other search condition." 
581                         if val[0] == False:
582                                 msg = "Blindscan was canceled by the user."
583                         self.session.openWithCallback(self.callbackNone, MessageBox, _(msg), MessageBox.TYPE_INFO, timeout=10)
584                         self.tmp_tplist = []
585
586         def startScan(self, tlist, feid, networkid = 0):
587                 self.scan_session = None
588
589                 flags = 0
590                 if self.scan_clearallservices.value:
591                         flags |= eComponentScan.scanRemoveServices
592                 else:
593                         flags |= eComponentScan.scanDontRemoveUnscanned
594                 if self.scan_onlyfree.value:
595                         flags |= eComponentScan.scanOnlyFree
596                 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags, "networkid": networkid}])
597
598 def main(session, **kwargs):
599         session.open(Blindscan)
600                                                            
601 def Plugins(**kwargs):            
602         return PluginDescriptor(name=_("Blindscan"), description="scan type(DVB-S)", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)
603