reset frontend type on tuner type change also on simulated tuner
[vuplus_dvbapp] / lib / python / Components / NimManager.py
index 2a1cbad..bd1a363 100644 (file)
@@ -10,7 +10,7 @@ from enigma import eDVBSatelliteEquipmentControl as secClass, \
        eDVBSatelliteDiseqcParameters as diseqcParam, \
        eDVBSatelliteSwitchParameters as switchParam, \
        eDVBSatelliteRotorParameters as rotorParam, \
-       eDVBResourceManager, eDVBDB
+       eDVBResourceManager, eDVBDB, eEnv
 
 from time import localtime, mktime
 from datetime import datetime
@@ -110,9 +110,16 @@ class SecConfigure:
        def setSatposDepends(self, sec, nim1, nim2):
                print "tuner", nim1, "depends on satpos of", nim2
                sec.setTunerDepends(nim1, nim2)
+               
+       def linkInternally(self, slotid):
+               nim = self.NimManager.getNim(slotid)
+               if nim.internallyConnectableTo is not None:
+                       nim.setInternalLink()
 
        def linkNIMs(self, sec, nim1, nim2):
                print "link tuner", nim1, "to tuner", nim2
+               if nim2 == (nim1 - 1):
+                       self.linkInternally(nim1)
                sec.setTunerLinked(nim1, nim2)
                
        def getRoot(self, slotid, connto):
@@ -127,6 +134,9 @@ class SecConfigure:
        def update(self):
                sec = secClass.getInstance()
                self.configuredSatellites = set()
+               for slotid in self.NimManager.getNimListOfType("DVB-S"):
+                       if self.NimManager.nimInternallyConnectableTo(slotid) is not None:
+                               self.NimManager.nimRemoveInternalLink(slotid)
                sec.clear() ## this do unlinking NIMs too !!
                print "sec config cleared"
 
@@ -140,7 +150,7 @@ class SecConfigure:
 
                for slot in nim_slots:
                        if slot.type is not None:
-                               used_nim_slots.append((slot.slot, slot.description, slot.config.configMode.value != "nothing" and True or False, slot.isCompatible("DVB-S2")))
+                               used_nim_slots.append((slot.slot, slot.description, slot.config.configMode.value != "nothing" and True or False, slot.isCompatible("DVB-S2"), slot.frontend_id is None and -1 or slot.frontend_id))
                eDVBResourceManager.getInstance().setFrontendSlotInformations(used_nim_slots)
 
                for slot in nim_slots:
@@ -380,6 +390,7 @@ class SecConfigure:
 
                                        if currLnb.diseqcMode.value == "1_0":
                                                currCO = currLnb.commandOrder1_0.value
+                                               sec.setRepeats(0)
                                        else:
                                                currCO = currLnb.commandOrder.value
 
@@ -471,7 +482,7 @@ class SecConfigure:
                self.update()
 
 class NIM(object):
-       def __init__(self, slot, type, description, has_outputs = True, internally_connectable = None, multi_type = {}, i2c = None):
+       def __init__(self, slot, type, description, has_outputs = True, internally_connectable = None, multi_type = {}, frontend_id = None, i2c = None, is_empty = False):
                self.slot = slot
 
                if type not in ("DVB-S", "DVB-C", "DVB-T", "DVB-S2", None):
@@ -484,8 +495,12 @@ class NIM(object):
                self.internally_connectable = internally_connectable
                self.multi_type = multi_type
                self.i2c = i2c
+               self.frontend_id = frontend_id
+               self.__is_empty = is_empty
 
        def isCompatible(self, what):
+               if not self.isSupported():
+                       return False
                compatible = {
                                None: (None,),
                                "DVB-S": ("DVB-S", None),
@@ -527,9 +542,26 @@ class NIM(object):
        def internallyConnectableTo(self):
                return self.internally_connectable
        
+       def setInternalLink(self):
+               if self.internally_connectable is not None:
+                       print "setting internal link on frontend id", self.frontend_id
+                       open("/proc/stb/frontend/%d/rf_switch" % self.frontend_id, "w").write("internal")
+               
+       def removeInternalLink(self):
+               if self.internally_connectable is not None:
+                       print "removing internal link on frontend id", self.frontend_id
+                       open("/proc/stb/frontend/%d/rf_switch" % self.frontend_id, "w").write("external")
+       
        def isMultiType(self):
                return (len(self.multi_type) > 0)
        
+       def isEmpty(self):
+               return self.__is_empty
+       
+       # empty tuners are supported!
+       def isSupported(self):
+               return (self.frontend_id is not None) or self.__is_empty
+       
        # returns dict {<slotid>: <type>}
        def getMultiTypeList(self):
                return self.multi_type
@@ -552,8 +584,10 @@ class NIM(object):
                        
                if self.empty:
                        nim_text += _("(empty)")
+               elif not self.isSupported():
+                       nim_text += self.description + " (" + _("not supported") + ")"
                else:
-                       nim_text += self.description + " (" + self.friendly_type + ")"
+                       nim_text += self.description + " (" + self.friendly_type + ")"
                
                return nim_text
 
@@ -671,14 +705,19 @@ class NimManager:
                                entries[current_slot] = {}
                        elif line.strip().startswith("Type:"):
                                entries[current_slot]["type"] = str(line.strip()[6:])
+                               entries[current_slot]["isempty"] = False
                        elif line.strip().startswith("Name:"):
                                entries[current_slot]["name"] = str(line.strip()[6:])
+                               entries[current_slot]["isempty"] = False
                        elif line.strip().startswith("Has_Outputs:"):
                                input = str(line.strip()[len("Has_Outputs:") + 1:])
                                entries[current_slot]["has_outputs"] = (input == "yes")
                        elif line.strip().startswith("Internally_Connectable:"):
                                input = int(line.strip()[len("Internally_Connectable:") + 1:])
                                entries[current_slot]["internally_connectable"] = input
+                       elif line.strip().startswith("Frontend_Device:"):
+                               input = int(line.strip()[len("Frontend_Device:") + 1:])
+                               entries[current_slot]["frontend_device"] = input
                        elif  line.strip().startswith("Mode"):
                                # "Mode 0: DVB-T" -> ["Mode 0", " DVB-T"]
                                split = line.strip().split(":")
@@ -693,8 +732,11 @@ class NimManager:
                        elif line.strip().startswith("empty"):
                                entries[current_slot]["type"] = None
                                entries[current_slot]["name"] = _("N/A")
+                               entries[current_slot]["isempty"] = True
                nimfile.close()
                
+               from os import path
+               
                for id, entry in entries.items():
                        if not (entry.has_key("name") and entry.has_key("type")):
                                entry["name"] =  _("N/A")
@@ -703,11 +745,16 @@ class NimManager:
                                entry["i2c"] = None
                        if not (entry.has_key("has_outputs")):
                                entry["has_outputs"] = True
-                       if not (entry.has_key("internally_connectable")):
-                               entry["internally_connectable"] = None
+                       if entry.has_key("frontend_device"): # check if internally connectable
+                               if path.exists("/proc/stb/frontend/%d/rf_switch" % entry["frontend_device"]):
+                                       entry["internally_connectable"] = entry["frontend_device"] - 1
+                               else:
+                                       entry["internally_connectable"] = None
+                       else:
+                               entry["frontend_device"] = entry["internally_connectable"] = None
                        if not (entry.has_key("multi_type")):
                                entry["multi_type"] = {}
-                       self.nim_slots.append(NIM(slot = id, description = entry["name"], type = entry["type"], has_outputs = entry["has_outputs"], internally_connectable = entry["internally_connectable"], multi_type = entry["multi_type"], i2c = entry["i2c"]))
+                       self.nim_slots.append(NIM(slot = id, description = entry["name"], type = entry["type"], has_outputs = entry["has_outputs"], internally_connectable = entry["internally_connectable"], multi_type = entry["multi_type"], frontend_id = entry["frontend_device"], i2c = entry["i2c"], is_empty = entry["isempty"]))
 
        def hasNimType(self, chktype):
                for slot in self.nim_slots:
@@ -726,6 +773,12 @@ class NimManager:
        
        def getNimName(self, slotid):
                return self.nim_slots[slotid].description
+       
+       def getNim(self, slotid):
+               return self.nim_slots[slotid]
+       
+       def getI2CDevice(self, slotid):
+               return self.nim_slots[slotid].getI2C()
 
        def getNimListOfType(self, type, exception = -1):
                # returns a list of indexes for NIMs compatible to the given type, except for 'exception'
@@ -756,6 +809,12 @@ class NimManager:
        def hasOutputs(self, slotid):
                return self.nim_slots[slotid].hasOutputs()
        
+       def nimInternallyConnectableTo(self, slotid):
+               return self.nim_slots[slotid].internallyConnectableTo()
+       
+       def nimRemoveInternalLink(self, slotid):
+               self.nim_slots[slotid].removeInternalLink()
+       
        def canConnectTo(self, slotid):
                slots = []
                if self.nim_slots[slotid].internallyConnectableTo() is not None:
@@ -1024,7 +1083,7 @@ def InitNimManager(nimmgr):
 
        unicablelnbproducts = {}
        unicablematrixproducts = {}
-       doc = xml.etree.cElementTree.parse("/usr/share/enigma2/unicable.xml")
+       doc = xml.etree.cElementTree.parse(eEnv.resolve("${datadir}/enigma2/unicable.xml"))
        root = doc.getroot()
 
        entry = root.find("lnb")
@@ -1302,25 +1361,32 @@ def InitNimManager(nimmgr):
                slot_id = configElement.slot_id
                if nimmgr.nim_slots[slot_id].description == 'Alps BSBE2':
                        open("/proc/stb/frontend/%d/tone_amplitude" %(fe_id), "w").write(configElement.value)
-                       
+
        def tunerTypeChanged(nimmgr, configElement):
                fe_id = configElement.fe_id
-               print "tunerTypeChanged feid %d to mode %s" % (fe_id, configElement.value)
-               try:
-                       oldvalue = 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"
-               frontend = eDVBResourceManager.getInstance().allocateRawChannel(fe_id).getFrontend()
-               frontend.closeFrontend()
-               open("/proc/stb/frontend/%d/mode" % (fe_id), "w").write(configElement.value)
-               frontend.reopenFrontend()
-               try:
-                       open("/sys/module/dvb_core/parameters/dvb_shutdown_timeout", "w").write(oldvalue)
-               except:
-                       print "[info] no /sys/module/dvb_core/parameters/dvb_shutdown_timeout available"
-               nimmgr.enumerateNIMs()
-       
+
+               cur_type = int(open("/proc/stb/frontend/%d/mode" % (fe_id), "r").read())
+               if cur_type != int(configElement.value):
+                       print "tunerTypeChanged feid %d from %d to mode %d" % (fe_id, cur_type, int(configElement.value))
+
+                       try:
+                               oldvalue = 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"
+
+                       frontend = eDVBResourceManager.getInstance().allocateRawChannel(fe_id).getFrontend()
+                       frontend.closeFrontend()
+                       open("/proc/stb/frontend/%d/mode" % (fe_id), "w").write(configElement.value)
+                       frontend.reopenFrontend()
+                       try:
+                               open("/sys/module/dvb_core/parameters/dvb_shutdown_timeout", "w").write(oldvalue)
+                       except:
+                               print "[info] no /sys/module/dvb_core/parameters/dvb_shutdown_timeout available"
+                       nimmgr.enumerateNIMs()
+               else:
+                       print "tuner type is already already %d" %cur_type
+
        empty_slots = 0
        for slot in nimmgr.nim_slots:
                x = slot.slot
@@ -1346,7 +1412,7 @@ def InitNimManager(nimmgr):
                nim = config.Nims[x]
 
                if slot.isCompatible("DVB-S"):
-                       nim.toneAmplitude = ConfigSelection([("9", "600mV"), ("8", "700mV"), ("7", "800mV"), ("6", "900mV"), ("5", "1100mV")], "7")
+                       nim.toneAmplitude = ConfigSelection([("11", "340mV"), ("10", "360mV"), ("9", "600mV"), ("8", "700mV"), ("7", "800mV"), ("6", "900mV"), ("5", "1100mV")], "7")
                        nim.toneAmplitude.fe_id = x - empty_slots
                        nim.toneAmplitude.slot_id = x
                        nim.toneAmplitude.addNotifier(toneAmplitudeChanged)