ScanSetup.py: fix abort in transpondersearch when the external transponder tool is...
[enigma2.git] / lib / python / Screens / ScanSetup.py
index d0af8f7ecadf90ac05a19a20f304c02c453432b3..6c142c51fa9059f62878f4734b0e59aa2de19731 100644 (file)
@@ -8,6 +8,7 @@ from Components.ConfigList import ConfigListScreen
 from Components.NimManager import nimmanager, getConfigSatlist
 from Components.Label import Label
 from Tools.Directories import resolveFilename, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITION
+from Tools.HardwareInfo import HardwareInfo
 from Screens.MessageBox import MessageBox
 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, \
        eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, \
@@ -106,6 +107,7 @@ class CableTransponderSearchSupport:
                        if raw_channel:
                                frontend = raw_channel.getFrontend()
                                if frontend:
+                                       frontend.closeFrontend() # immediate close... 
                                        del frontend
                                        del raw_channel
                                        return True
@@ -113,12 +115,17 @@ class CableTransponderSearchSupport:
 
        def cableTransponderSearchSessionClosed(self, *val):
                print "cableTransponderSearchSessionClosed, val", val
+               self.resetTimeout()
                self.cable_search_container.appClosed.remove(self.cableTransponderSearchClosed)
                self.cable_search_container.dataAvail.remove(self.getCableTransponderData)
+               if val and len(val):
+                       if val[0]:
+                               self.setCableTransponderSearchResult(self.__tlist)
+                       else:
+                               self.cable_search_container.sendCtrlC()
+                               self.setCableTransponderSearchResult(None)
                self.cable_search_container = None
                self.cable_search_session = None
-               if val and len(val) and val[0]:
-                       self.setCableTransponderSearchResult(self.__tlist)
                self.__tlist = None
                self.cableTransponderSearchFinished()
 
@@ -138,7 +145,8 @@ class CableTransponderSearchSupport:
                                        "QAM128" : parm.Modulation_QAM128,
                                        "QAM256" : parm.Modulation_QAM256 }
                                inv = { "INVERSION_OFF" : parm.Inversion_Off,
-                                       "INVERSION_ON" : parm.Inversion_On }
+                                       "INVERSION_ON" : parm.Inversion_On,
+                                       "INVERSION_AUTO" : parm.Inversion_Unknown }
                                fec = { "FEC_AUTO" : parm.FEC_Auto,
                                        "FEC_1_2" : parm.FEC_1_2,
                                        "FEC_2_3" : parm.FEC_2_3,
@@ -159,6 +167,19 @@ class CableTransponderSearchSupport:
                tmpstr += " kHz "
                tmpstr += data[0]
                self.cable_search_session["text"].setText(tmpstr)
+               
+       def setTimeout(self):
+               try:
+                       self.oldtimeoutvalue = open("/sys/module/dvb_core/parameters/dvb_shutdown_timeout", "r").readline()
+                       open("/sys/module/dvb_core/parameters/dvb_shutdown_timeout", "w").write("0")
+               except:
+                       print "[info] no /sys/module/dvb_core/parameters/dvb_shutdown_timeout available"                
+               
+       def resetTimeout(self):
+               try:
+                       open("/sys/module/dvb_core/parameters/dvb_shutdown_timeout", "w").write(self.oldtimeoutvalue)
+               except:
+                       print "[info] no /sys/module/dvb_core/parameters/dvb_shutdown_timeout available"
 
        def startCableTransponderSearch(self, nim_idx):
                if not self.tryGetRawFrontend(nim_idx):
@@ -175,15 +196,17 @@ class CableTransponderSearchSupport:
                self.cable_search_container.appClosed.append(self.cableTransponderSearchClosed)
                self.cable_search_container.dataAvail.append(self.getCableTransponderData)
                cableConfig = config.Nims[nim_idx].cable
-               cmd = "tda1002x --init --scan --verbose --wakeup --inv 2 --bus "
-               #FIXMEEEEEE hardcoded i2c devices for dm7025 and dm8000
-               if nim_idx < 2:
-                       cmd += str(nim_idx)
+               tunername = nimmanager.getNimName(nim_idx)
+               bus = nimmanager.getI2CDevice(nim_idx)
+               if bus is None:
+                       print "ERROR: could not get I2C device for nim", nim_idx, "for cable transponder search"
+                       bus = 2
+
+               if tunername == "CXD1981":
+                       cmd = "cxd1978 --init --scan --verbose --wakeup --inv 2 --bus %d" % bus
                else:
-                       if nim_idx == 2:
-                               cmd += "2" # first nim socket on DM8000 use /dev/i2c/2
-                       else:
-                               cmd += "4" # second nim socket on DM8000 use /dev/i2c/4
+                       cmd = "tda1002x --init --scan --verbose --wakeup --inv 2 --bus %d" % bus
+               
                if cableConfig.scan_type.value == "bands":
                        cmd += " --scan-bands "
                        bands = 0
@@ -242,6 +265,7 @@ class CableTransponderSearchSupport:
                self.cable_search_container.execute(cmd)
                tmpstr = _("Try to find used transponders in cable network.. please wait...")
                tmpstr += "\n\n..."
+               self.setTimeout()
                self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
 
 class DefaultSatLists(DefaultWizard):
@@ -295,9 +319,11 @@ class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport):
 
                self.list = []
                ConfigListScreen.__init__(self, self.list)
-               self.createSetup()
-
-               self["introduction"] = Label(_("Press OK to start the scan"))
+               if not self.scan_nims.value == "":
+                       self.createSetup()
+                       self["introduction"] = Label(_("Press OK to start the scan"))
+               else:
+                       self["introduction"] = Label(_("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."))
 
        def runAsync(self, finished_cb):
                self.finished_cb = finished_cb
@@ -522,6 +548,8 @@ class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport):
                        for n in nimmanager.nim_slots:
                                if n.config_mode == "nothing":
                                        continue
+                               if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
+                                       continue
                                if n.config_mode in ("loopthrough", "satposdepends"):
                                        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
@@ -709,6 +737,8 @@ class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport):
                tlist.append(buildTerTransponder(*args, **kwargs))
 
        def keyGo(self):
+               if self.scan_nims.value == "":
+                       return
                tlist = []
                flags = None
                startScan = True
@@ -820,7 +850,10 @@ class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport):
                self.tlist = tlist
 
        def cableTransponderSearchFinished(self):
-               self.startScan(self.tlist, self.flags, self.feid)
+               if self.tlist is None:
+                       self.tlist = []
+               else:
+                       self.startScan(self.tlist, self.flags, self.feid)
 
        def startScan(self, tlist, flags, feid):
                if len(tlist):
@@ -986,7 +1019,8 @@ class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport):
                                self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
 
        def setCableTransponderSearchResult(self, tlist):
-               self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
+               if tlist is not None:
+                       self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
 
        def cableTransponderSearchFinished(self):
                self.buildTransponderList()