corret use for getCurrent method
[enigma2.git] / lib / python / Components / NimManager.py
index 09928d07f0104811f111412318dd0430551dc8cf..f04d076d29d50ef87428e6a63d82adbb10a4810f 100644 (file)
@@ -18,6 +18,13 @@ from Tools import XMLTools
 from xml.sax import make_parser
 from xml.sax.handler import ContentHandler
 
+def tryOpen(filename):
+       try:
+               procFile = open(filename)
+       except IOError:
+               return ""
+       return procFile
+
 class SecConfigure:
        def addLNBSimple(self, slotid, orbpos, toneburstmode, diseqcmode, diseqcpos):
                #simple defaults
@@ -122,8 +129,34 @@ class NimManager:
 
        def getNimType(self, slotID):
                #FIXME get it from /proc
+               nimfile = tryOpen("/proc/bus/nim_sockets")
+
+               if nimfile == "":
+                       return self.nimType["empty/unknown"]
+
+               while 1:                
+                       line = nimfile.readline()
+                       if line == "":
+                               break
+                       if line.startswith("NIM Socket"):
+                               parts = line.strip().split(" ")
+                               id = int(parts[2][:1])
+                               if id == slotID:
+                                       line = nimfile.readline()
+                                       if line == "":
+                                               break
+                                       if line.startswith("   Type:"):
+                                               nimfile.close()
+                                               return self.nimType["DVB-S"]
+                                       else:
+                                               break   
+               nimfile.close()
+               return self.nimType["empty/unknown"]
+               
                if slotID == 0:
                        return self.nimType["DVB-S"]
+               elif slotID == 1:
+                       return self.nimType["DVB-S"]
                else:
                        return self.nimType["empty/unknown"]
 
@@ -195,9 +228,10 @@ class NimManager:
                #print "nimDiseqcModeChanged set to " + str(mode)
                pass
        def nimPortAChanged(self, slotid, val):
-               #print "nimDiseqcA set to " + str(val)
+               #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
                pass
        def nimPortBChanged(self, slotid, val):
+               #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
                #print "nimDiseqcB set to " + str(val)
                pass
        def nimPortCChanged(self, slotid, val):
@@ -209,8 +243,10 @@ class NimManager:
 
 
 def InitNimManager(nimmgr):
-       config.Nims = [ConfigSubsection()] * nimmgr.nimCount
-
+       config.Nims = []
+       for x in range(nimmgr.nimCount):
+               config.Nims.append(ConfigSubsection())
+               
        def nimConfigModeChanged(slotid, configElement):
                nimmgr.nimConfigModeChanged(slotid, configElement.value)
        def nimDiseqcModeChanged(slotid, configElement):
@@ -243,13 +279,13 @@ def InitNimManager(nimmgr):
                        #perhaps the instance of the slot is more useful?
                        nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
                        nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
-                       nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,x))
+                       nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
                        nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
                        nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
                        nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
                else:
                        print "pls add support for this frontend type!"         
-                       
+
        nimmgr.sec = SecConfigure(nimmgr)
 
 nimmanager = NimManager()