[ScanSetup] Fix error on complete scan with T2 tuners.
[vuplus_dvbapp] / lib / python / Screens / ScanSetup.py
index 08ce21e..6fdeb53 100644 (file)
@@ -67,7 +67,7 @@ def getInitialCableTransponderList(tlist, nim):
                        #print "inversion:", 2
                        tlist.append(parm)
 
-def getInitialTerrestrialTransponderList(tlist, region):
+def getInitialTerrestrialTransponderList(tlist, region, skip_t2 = False):
        list = nimmanager.getTranspondersTerrestrial(region)
 
        #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv,system,plpid))
@@ -77,6 +77,9 @@ def getInitialTerrestrialTransponderList(tlist, region):
 
        for x in list:
                if x[0] == 2: #TERRESTRIAL
+                       if skip_t2 and x[10] == eDVBFrontendParametersTerrestrial.System_DVB_T2:
+                               # Should be searching on TerrestrialTransponderSearchSupport.
+                               continue
                        parm = buildTerTransponder(x[1], x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8], x[10], x[11])
                        tlist.append(parm)
 
@@ -95,6 +98,34 @@ cable_bands = {
        "DVBC_BAND_US_HYPER" : 1 << 11,
 }
 
+cable_autoscan_nimtype = {
+'SSH108' : 'ssh108',
+'TT3L10' : 'tt3l10',
+'TURBO' : 'vuplus_turbo_c'
+}
+
+terrestrial_autoscan_nimtype = {
+'SSH108' : 'ssh108_t2_scan',
+'TT3L10' : 'tt3l10_t2_scan',
+'TURBO' : 'vuplus_turbo_t'
+}
+
+def GetDeviceId(filter, nim_idx):
+       tuners={}
+       device_id = 0
+       socket_id = 0
+       for nim in nimmanager.nim_slots:
+               name_token = nim.description.split(' ')
+               name = name_token[-1][4:-1]
+               if name == filter:
+                       if socket_id == nim_idx:
+                               break
+
+                       if device_id:   device_id = 0
+                       else:                   device_id = 1
+               socket_id += 1
+       return device_id
+
 class CableTransponderSearchSupport:
 #      def setCableTransponderSearchResult(self, tlist):
 #              pass
@@ -170,32 +201,26 @@ class CableTransponderSearchSupport:
                        self.cable_search_session["text"].setText(tmpstr)
 
        def startCableTransponderSearch(self, nim_idx):
-               def GetCommand(nimIdx):
-                       _supportNimType   = { 'SSH108':'ssh108' }
-                       _nimSocket = {}
-                       fp = file('/proc/bus/nim_sockets')
-
-                       sNo, sName = -1, ""
-                       for line in fp:
-                               line = line.strip()
-                               if line.startswith('NIM Socket'):
-                                       try:    sNo = line.split()[2][:-1]
-                                       except: sNo = -1
-                               elif line.startswith('Name:'):
-                                       try:    sName = line.split()[3][4:-1]
-                                       except: sName = ""
-                               if sNo >= 0 and sName != "":
-                                       _nimSocket[sNo] = sName
-                                       sNo, sName = -1, ''
-                       fp.close()
-                       print 'parsed nim_sockets :', _nimSocket
-
+               def GetCommand(nim_idx):
+                       global cable_autoscan_nimtype
                        try:
-                               sName = _nimSocket[str(nimIdx)]
-                               sType = _supportNimType[sName]
-                               return sType
-                       except: pass
-                       return 'tda1002x'
+                               nim_name = nimmanager.getNimName(nim_idx)
+                               if nim_name is not None and nim_name != "":
+                                       device_id = ""
+                                       nim_name = nim_name.split(' ')[-1][4:-1]
+                                       if nim_name == 'TT3L10':
+                                               try:
+                                                       device_id = GetDeviceId('TT3L10', nim_idx)
+                                                       device_id = "--device=%s" % (device_id)
+                                               except Exception, err:
+                                                       print "GetCommand ->", err
+                                                       device_id = "--device=0"
+#                                              print nim_idx, nim_name, cable_autoscan_nimtype[nim_name], device_id
+                                       command = "%s %s" % (cable_autoscan_nimtype[nim_name], device_id)
+                                       return command
+                       except Exception, err:
+                               print "GetCommand ->", err
+                       return "tda1002x"
 
                if not self.tryGetRawFrontend(nim_idx):
                        self.session.nav.stopService()
@@ -322,6 +347,7 @@ class TerrestrialTransponderSearchSupport:
                print self.terrestrial_search_data
                data = self.terrestrial_search_data.split()
                if len(data):
+#                      print "[setTerrestrialTransponderData] data : ", data
                        if data[0] == 'OK':
                                # DVB-T : OK frequency bandwidth delivery system -1
                                # DVB-T2 : OK frequency bandwidth delivery system number_of_plp plp_id0:plp_type0
@@ -341,7 +367,7 @@ class TerrestrialTransponderSearchSupport:
                                        self.__tlist.append(parm)
                                else:
                                        plp_list = data[5:]
-                                       plp_num = data[4]
+                                       plp_num = int(data[4])
                                        if len(plp_list) > plp_num:
                                                plp_list = plp_list[:plp_num]
                                        for plp in plp_list:
@@ -362,7 +388,7 @@ class TerrestrialTransponderSearchSupport:
                                                parm.plpid = int(plp_id)
                                                self.__tlist.append(parm)
 
-                       tmpstr = _("Try to find used Transponders in cable network.. please wait...")
+                       tmpstr = _("Try to find used Transponders in terrestrial network.. please wait...")
                        tmpstr += "\n\n"
                        tmpstr += data[1][:-3]
                        tmpstr += " kHz "
@@ -406,16 +432,28 @@ class TerrestrialTransponderSearchSupport:
                else:
                        return None
 
-       def startTerrestrialTransponderSearch(self, nim_idx, region):
-               def GetCommand(nimIdx):
-                       _supportNimType   = { 'SSH108':'ssh108_t2_scan' }
-                       description = nimmanager.getNimName(nimIdx)
-                       try:
-                               tunername = description.split()[2][4:-1]
-                       except:
-                               tunername = description
-                       return  _supportNimType.get(tunername, 'ssh108_t2_scan')
+       def terrestrialTransponderGetCmd(self, nim_idx):
+               global terrestrial_autoscan_nimtype
+               try:
+                       nim_name = nimmanager.getNimName(nim_idx)
+                       if nim_name is not None and nim_name != "":
+                               device_id = ""
+                               nim_name = nim_name.split(' ')[-1][4:-1]
+                               if nim_name == 'TT3L10':
+                                       try:
+                                               device_id = GetDeviceId('TT3L10', nim_idx)
+                                               device_id = "--device %s" % (device_id)
+                                       except Exception, err:
+                                               print "terrestrialTransponderGetCmd ->", err
+                                               device_id = "--device 0"
+#                                      print nim_idx, nim_name, terrestrial_autoscan_nimtype[nim_name], device_id
+                               command = "%s %s" % (terrestrial_autoscan_nimtype[nim_name], device_id)
+                               return command
+               except Exception, err:
+                       print "terrestrialTransponderGetCmd ->", err
+               return ""
 
+       def startTerrestrialTransponderSearch(self, nim_idx, region):
                if not self.tryGetRawFrontend(nim_idx):
                        self.session.nav.stopService()
                        if not self.tryGetRawFrontend(nim_idx):
@@ -430,11 +468,11 @@ class TerrestrialTransponderSearchSupport:
                self.terrestrial_search_container.appClosed.append(self.terrestrialTransponderSearchClosed)
                self.terrestrial_search_container.dataAvail.append(self.getTerrestrialTransponderData)
 
-               self.terrestrial_search_binName = GetCommand(nim_idx)
+               self.terrestrial_search_binName = self.terrestrialTransponderGetCmd(nim_idx)
 
                self.terrestrial_search_bus = nimmanager.getI2CDevice(nim_idx)
                if self.terrestrial_search_bus is None:
-                       print "ERROR: could not get I2C device for nim", nim_idx, "for terrestrial transponder search"
+#                      print "ERROR: could not get I2C device for nim", nim_idx, "for terrestrial transponder search"
                        self.terrestrial_search_bus = 2
 
                self.terrestrial_search_list = []
@@ -1095,9 +1133,15 @@ class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport, Terrest
                                                        plpid = self.scan_ter.plp_id.value)
                                removeAll = False
                        elif self.scan_typeterrestrial.value == "complete":
-                               getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(index_to_scan))
+                               skip_t2 = True
                                if nim.isCompatible("DVB-T2"):
-                                       action = SEARCH_TERRESTRIAL2_TRANSPONDERS
+                                       scan_util = len(self.terrestrialTransponderGetCmd(nim.slot)) and True or False
+                                       if scan_util:
+                                               action = SEARCH_TERRESTRIAL2_TRANSPONDERS
+                                       else:
+                                               skip_t2 = False
+
+                               getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(index_to_scan), skip_t2)
 
                flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
 
@@ -1172,7 +1216,7 @@ class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport, Terres
                if nim.isCompatible("DVB-S"):
                        networks = nimmanager.getSatListForNim(nim.slot)
                elif not nim.empty:
-                       networks = [ nim.type ] # "DVB-C" or "DVB-T". TODO: seperate networks for different C/T tuners, if we want to support that.
+                       networks = [ nim.getType() ] # "DVB-C" or "DVB-T". TODO: seperate networks for different C/T tuners, if we want to support that.
                else:
                        # empty tuners provide no networks.
                        networks = [ ]
@@ -1222,7 +1266,7 @@ class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport, Terres
                if "DVB-T2" in known_networks: # we need to remove "DVB-T" when networks have "DVB-T2"
                        nims_dvb_t = []
                        for nim in nims_to_scan:
-                               if nim.type == "DVB-T":
+                               if nim.getType() == "DVB-T":
                                        nims_dvb_t.append(nim)
 
                        for nim in nims_dvb_t:
@@ -1283,9 +1327,14 @@ class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport, Terres
                                        else:
                                                action = SEARCH_CABLE_TRANSPONDERS
                                elif nim.isCompatible("DVB-T"):
-                                       getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot))
+                                       skip_t2 = True
                                        if nim.isCompatible("DVB-T2"):
-                                               action = SEARCH_TERRESTRIAL2_TRANSPONDERS
+                                               scan_util = len(self.terrestrialTransponderGetCmd(nim.slot)) and True or False
+                                               if scan_util:
+                                                       action = SEARCH_TERRESTRIAL2_TRANSPONDERS
+                                               else:
+                                                       skip_t2 = False
+                                       getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot), skip_t2)
                                else:
                                        assert False