Merge branch 'vuplus_experimental' of code.vuplus.com:/opt/repository/dvbapp into...
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / Blindscan / plugin.py
index c456f26..40a349e 100644 (file)
@@ -16,23 +16,27 @@ from Components.config import config, ConfigSubsection, ConfigSelection, ConfigY
 from Tools.HardwareInfo import HardwareInfo
 from Tools.Directories import resolveFilename, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITION
 
-from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager
+from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager, getDesktop
+
+_modelName = file('/proc/stb/info/vumodel').read().strip()
+_supportNimType = { 'AVL1208':'', 'AVL6222':'6222_', 'AVL6211':'6211_', 'BCM7356':'bcm7346_'}
 
 class Blindscan(ConfigListScreen, Screen):
-       skin="""
-               <screen name="Blindscan" position="center,center" size="560,290" title="Blindscan">
-                       <ePixmap pixmap="Vu_HD/buttons/red.png" position="5,0" size="80,40" alphatest="on" />
-                       <ePixmap pixmap="Vu_HD/buttons/green.png" position="186,0" size="80,40" alphatest="on" />
-                       <ePixmap pixmap="Vu_HD/buttons/blue.png" position="372,0" size="80,40" alphatest="on" />
-
-                       <widget source="key_red" render="Label" position="28,0" zPosition="1" size="160,30" font="Regular;20" halign="center" valign="center" transparent="1"/>
-                       <widget source="key_green" render="Label" position="213,0" zPosition="1" size="160,30" font="Regular;20" halign="center" valign="center" transparent="1"/>
-                       <widget source="key_blue" render="Label" position="400,0" zPosition="1" size="160,30" font="Regular;20" halign="center" valign="center" transparent="1"/>
-
-                       <widget name="config" position="5,50" size="550,200" scrollbarMode="showOnDemand" />
-                       <widget name="introduction" position="0,265" size="560,20" font="Regular;20" halign="center" />
+       skin =  """
+               <screen position="center,center" size="560,390" title="Blindscan">
+                       <ePixmap pixmap="skin_default/buttons/red.png" position="40,10" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/green.png" position="210,10" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/blue.png" position="380,10" size="140,40" alphatest="on" />
+
+                       <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"/>
+                       <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"/>
+                       <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"/>
+
+                       <widget name="config" position="5,70" size="550,280" scrollbarMode="showOnDemand" />
+                       <widget name="introduction" position="0,365" size="560,20" font="Regular;20" halign="center" />
                </screen>
                """
+
        def __init__(self, session): 
                Screen.__init__(self, session)
 
@@ -43,6 +47,8 @@ class Blindscan(ConfigListScreen, Screen):
                for slot in nimmanager.nim_slots:
                        if slot.isCompatible("DVB-S"):
                                self.satList.append(nimmanager.getSatListForNim(slot.slot))
+                       else:
+                               self.satList.append(None)
 
                # make config
                self.createConfig()
@@ -61,7 +67,7 @@ class Blindscan(ConfigListScreen, Screen):
                                "cancel": self.keyCancel,
                        }, -2)
                        self["key_red"] = StaticText(_("Exit"))
-                       self["key_green"] = StaticText("Start")
+                       self["key_green"] = StaticText("Scan")
                        self["key_blue"] = StaticText("Scan All")
                        self["introduction"] = Label(_("Press Green/OK to start the scan"))
                        self.createSetup()
@@ -79,6 +85,74 @@ class Blindscan(ConfigListScreen, Screen):
                        self["key_blue"] = StaticText(" ")
                        self["introduction"] = Label(_("Please setup your tuner configuration."))
 
+               self.i2c_mapping_table = None
+               self.nimSockets = self.ScanNimsocket()
+               self.makeNimSocket()
+
+       def ScanNimsocket(self, filepath = '/proc/bus/nim_sockets'):
+               _nimSocket = {}
+               fp = file(filepath)
+
+               sNo, sName, sI2C = -1, "", -1
+               for line in fp:
+                       line = line.strip()
+                       if line.startswith('NIM Socket'):
+                               sNo, sName, sI2C = -1, '', -1
+                               try:    sNo = line.split()[2][:-1]
+                               except: sNo = -1
+                       elif line.startswith('I2C_Device:'):
+                               try:    sI2C = line.split()[1]
+                               except: sI2C = -1
+                       elif line.startswith('Name:'):
+                               splitLines = line.split()
+                               try:
+                                       if splitLines[1].startswith('BCM'):
+                                               sName = splitLines[1]
+                                       else:
+                                               sName = splitLines[3][4:-1]
+                               except: sName = ""
+                       if sNo >= 0 and sName != "":
+                               if sName.startswith('BCM'):
+                                       sI2C = sNo
+                               if sI2C != -1:
+                                       _nimSocket[sNo] = [sName, sI2C]
+                               else:   _nimSocket[sNo] = [sName]
+               fp.close()
+               print "parsed nimsocket :", _nimSocket
+               return _nimSocket
+
+       def makeNimSocket(self, nimname=""):
+               is_exist_i2c = False
+               self.i2c_mapping_table = {0:2, 1:3, 2:1, 3:0}
+               if self.nimSockets is not None:
+                       for XX in self.nimSockets.keys():
+                               nimsocket = self.nimSockets[XX]
+                               if len(nimsocket) > 1:
+                                       try:    self.i2c_mapping_table[int(XX)] = int(nimsocket[1])
+                                       except: continue
+                                       is_exist_i2c = True
+               print "i2c_mapping_table :", self.i2c_mapping_table, ", is_exist_i2c :", is_exist_i2c
+               if is_exist_i2c: return
+
+               if nimname == "AVL6222":
+                       model = _modelName #file('/proc/stb/info/vumodel').read().strip()
+                       if model == "uno":
+                               self.i2c_mapping_table = {0:3, 1:3, 2:1, 3:0}
+                       elif model == "duo2":
+                               nimdata = self.nimSockets['0']
+                               try:
+                                       if nimdata[0] == "AVL6222":
+                                               self.i2c_mapping_table = {0:2, 1:2, 2:4, 3:4}
+                                       else:   self.i2c_mapping_table = {0:2, 1:4, 2:4, 3:0}
+                               except: self.i2c_mapping_table = {0:2, 1:4, 2:4, 3:0}
+                       else:   self.i2c_mapping_table = {0:2, 1:4, 2:0, 3:0}
+               else:   self.i2c_mapping_table = {0:2, 1:3, 2:1, 3:0}
+
+       def getNimSocket(self, slot_number):
+               if slot_number < 0 or slot_number > 3:
+                       return -1
+               return self.i2c_mapping_table[slot_number]
+
        def keyNone(self):
                None
        def callbackNone(self, *retval):
@@ -150,6 +224,8 @@ class Blindscan(ConfigListScreen, Screen):
                self.blindscan_stop_frequency = ConfigInteger(default = 2150*1000000)
                self.blindscan_start_symbol = ConfigInteger(default = 2*1000000)
                self.blindscan_stop_symbol = ConfigInteger(default = 45*1000000)
+               self.scan_clearallservices = ConfigYesNo(default = False)
+               self.scan_onlyfree = ConfigYesNo(default = False)
 
                # collect all nims which are *not* set to "nothing"
                nim_list = []
@@ -162,8 +238,8 @@ class Blindscan(ConfigListScreen, Screen):
                                root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
                                if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
                                        continue
-                       nim_list.append((str(n.slot), n.friendly_full_description))
-
+                       if n.isCompatible("DVB-S"):
+                               nim_list.append((str(n.slot), n.friendly_full_description))
                self.scan_nims = ConfigSelection(choices = nim_list)
 
                # sat
@@ -185,6 +261,17 @@ class Blindscan(ConfigListScreen, Screen):
                                self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], self.satList[slot.slot]))
                return True
 
+       def getSelectedSatIndex(self, v):
+               index    = 0
+               none_cnt = 0
+               for n in self.satList:
+                       if self.satList[index] == None:
+                               none_cnt = none_cnt + 1
+                       if index == int(v):
+                               return (index-none_cnt)
+                       index = index + 1
+               return -1
+
        def createSetup(self):
                self.list = []
                self.multiscanlist = []
@@ -203,13 +290,15 @@ class Blindscan(ConfigListScreen, Screen):
 
                self.scan_networkScan.value = False
                if nim.isCompatible("DVB-S") :
-                       self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
+                       self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[self.getSelectedSatIndex(index_to_scan)]))
                        self.list.append(getConfigListEntry(_('Scan start frequency'), self.blindscan_start_frequency))
                        self.list.append(getConfigListEntry(_('Scan stop frequency'), self.blindscan_stop_frequency))
                        self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
                        self.list.append(getConfigListEntry(_("Scan band"), self.blindscan_hi))
                        self.list.append(getConfigListEntry(_('Scan start symbolrate'), self.blindscan_start_symbol))
                        self.list.append(getConfigListEntry(_('Scan stop symbolrate'), self.blindscan_stop_symbol))
+                       self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
+                       self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
                        self["config"].list = self.list
                        self["config"].l.setList(self.list)
                        
@@ -271,8 +360,9 @@ class Blindscan(ConfigListScreen, Screen):
                self.tmp_tplist=[]
                tmp_pol = []
                tmp_band = []
-               tmp_list=[self.satList[0][self.scan_satselection[0].index]]
-               
+               idx_selected_sat = int(self.getSelectedSatIndex(self.scan_nims.value))
+               tmp_list=[self.satList[int(self.scan_nims.value)][self.scan_satselection[idx_selected_sat].index]]
+
                if self.blindscan_hi.value == "hi_low" :
                        tmp_band=["low","high"]
                else:
@@ -288,19 +378,35 @@ class Blindscan(ConfigListScreen, Screen):
        def keyGoAll(self):
                if self.checkSettings() == False:
                        return
-
                self.tmp_tplist=[]
                tmp_list=[]
                tmp_band=["low","high"]
                tmp_pol=["horizontal","vertical"]
+               
                for slot in nimmanager.nim_slots:
-                       if slot.isCompatible("DVB-S"):
-                               for s in self.satList[slot.slot]:
+                       device_name = "/dev/dvb/adapter0/frontend%d" % (slot.slot)
+                       if slot.isCompatible("DVB-S") and int(self.scan_nims.value) == slot.slot:
+                               for s in self.satList[slot.slot]:
                                        tmp_list.append(s)
-
                self.doRun(tmp_list, tmp_pol, tmp_band)
                
        def doRun(self, tmp_list, tmp_pol, tmp_band):
+               def GetCommand(nimIdx):
+                       _nimSocket = self.nimSockets
+                       try:
+                               sName = _nimSocket[str(nimIdx)][0]
+                               sType = _supportNimType[sName]
+                               return "vuplus_%(TYPE)sblindscan"%{'TYPE':sType}, sName
+                       except: pass
+                       return "vuplus_blindscan", ""
+               self.binName,nimName =  GetCommand(self.scan_nims.value)
+
+               self.makeNimSocket(nimName)
+               if self.binName is None:
+                       self.session.open(MessageBox, "Blindscan is not supported in " + nimName + " tuner.", MessageBox.TYPE_ERROR)
+                       print nimName + " is not support blindscan."
+                       return
+
                self.full_data = ""
                self.total_list=[]
                for x in tmp_list:
@@ -375,7 +481,12 @@ class Blindscan(ConfigListScreen, Screen):
                                         0)
                self.tuner.tune(returnvalue)
 
-               cmd = "vuplus_blindscan %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)
+               if self.getNimSocket(self.feid) < 0:
+                       print "can't find i2c number!!"
+                       return
+               try:
+                       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))
+               except: return
                print "prepared command : [%s]" % (cmd)
                self.blindscan_container = eConsoleAppContainer()
                self.blindscan_container.appClosed.append(self.blindscanContainerClose)
@@ -417,23 +528,28 @@ class Blindscan(ConfigListScreen, Screen):
                                                "ROLLOFF_25" : parm.RollOff_alpha_0_25,
                                                "ROLLOFF_35" : parm.RollOff_alpha_0_35}
                                        pilot={ "PILOT_ON" : parm.Pilot_On,
-                                               "PILOT_OFF" : parm.Pilot_Off}
+                                               "PILOT_OFF" : parm.Pilot_Off,
+                                               "PILOT_AUTO" : parm.Pilot_Unknown}
                                        pol = { "HORIZONTAL" : parm.Polarisation_Horizontal,
                                                "VERTICAL" : parm.Polarisation_Vertical}
-                                       parm.orbital_position = self.orb_position
-                                       parm.polarisation = pol[data[1]]
-                                       parm.frequency = int(data[2])
-                                       parm.symbol_rate = int(data[3])
-                                       parm.system = sys[data[4]]
-                                       parm.inversion = inv[data[5]]
-                                       parm.pilot = pilot[data[6]]
-                                       parm.fec = fec[data[7]]
-                                       parm.modulation = qam[data[8]]
-                                       parm.rolloff = roll[data[9]]
-                                       self.tmp_tplist.append(parm)
+                                       try :
+                                               parm.orbital_position = self.orb_position
+                                               parm.polarisation = pol[data[1]]
+                                               parm.frequency = int(data[2])
+                                               parm.symbol_rate = int(data[3])
+                                               parm.system = sys[data[4]]
+                                               parm.inversion = inv[data[5]]
+                                               parm.pilot = pilot[data[6]]
+                                               parm.fec = fec[data[7]]
+                                               parm.modulation = qam[data[8]]
+                                               parm.rolloff = roll[data[9]]
+                                               self.tmp_tplist.append(parm)
+                                       except: pass
                self.blindscan_session.close(True)
 
        def blindscanContainerAvail(self, str):
+               print str
+               #if str.startswith("OK"):
                self.full_data = self.full_data + str
 
        def blindscanSessionNone(self, *val):
@@ -469,7 +585,15 @@ class Blindscan(ConfigListScreen, Screen):
 
        def startScan(self, tlist, feid, networkid = 0):
                self.scan_session = None
-               self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": 0, "networkid": networkid}])
+
+               flags = 0
+               if self.scan_clearallservices.value:
+                       flags |= eComponentScan.scanRemoveServices
+               else:
+                       flags |= eComponentScan.scanDontRemoveUnscanned
+               if self.scan_onlyfree.value:
+                       flags |= eComponentScan.scanOnlyFree
+               self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags, "networkid": networkid}])
 
 def main(session, **kwargs):
        session.open(Blindscan)