cut away 1/4th of enigma loading time by loading languages when they are used
[enigma2.git] / lib / python / Components / NimManager.py
index 00f34c6b0f3e87dfce970ce8bdf75b66f2707909..5920166d9f518d96fe0a0206157d913a6762664f 100644 (file)
@@ -5,17 +5,11 @@ from enigma import eDVBSatelliteEquipmentControl as secClass, \
        eDVBSatelliteDiseqcParameters as diseqcParam, \
        eDVBSatelliteSwitchParameters as switchParam, \
        eDVBSatelliteRotorParameters as rotorParam, \
-       eDVBResourceManager
+       eDVBResourceManager, eDVBDB
 
-import xml.dom.minidom
-from xml.dom import EMPTY_NAMESPACE
-from skin import elementsWithTag
-from Tools import XMLTools
+#from xml.sax import make_parser
+#from xml.sax.handler import ContentHandler
 
-from xml.sax import make_parser
-from xml.sax.handler import ContentHandler
-
-from Tools.BoundFunction import boundFunction
 from time import localtime, mktime
 from datetime import datetime
 
@@ -35,7 +29,7 @@ def tryOpen(filename):
        return procFile
 
 class SecConfigure:
-       def addLNBSimple(self, sec, slotid, diseqcmode, toneburstmode = diseqcParam.NO, diseqcpos = diseqcParam.SENDNO, orbpos = 0, longitude = 0, latitude = 0, loDirection = 0, laDirection = 0, turningSpeed = rotorParam.FAST):
+       def addLNBSimple(self, sec, slotid, diseqcmode, toneburstmode = diseqcParam.NO, diseqcpos = diseqcParam.SENDNO, orbpos = 0, longitude = 0, latitude = 0, loDirection = 0, laDirection = 0, turningSpeed = rotorParam.FAST, useInputPower=True, inputPowerDelta=50):
                #simple defaults
                sec.addLNB()
                tunermask = 1 << slotid
@@ -71,8 +65,8 @@ class SecConfigure:
                        sec.setLaDirection(laDirection)
                        sec.setLongitude(longitude)
                        sec.setLoDirection(loDirection)
-                       sec.setUseInputpower(True)
-                       sec.setInputpowerDelta(50)
+                       sec.setUseInputpower(useInputPower)
+                       sec.setInputpowerDelta(inputPowerDelta)
                        sec.setRotorTurningSpeed(turningSpeed)
 
                        for x in self.NimManager.satList:
@@ -108,6 +102,8 @@ class SecConfigure:
 
                nim_slots = self.NimManager.nim_slots
 
+               used_nim_slots = [ ]
+
                for slot in nim_slots:
                        x = slot.slot
                        nim = slot.config
@@ -116,13 +112,18 @@ class SecConfigure:
                                # this is stored in the *value* (not index!) of the config list
                                if nim.configMode.value == "equal":
                                        self.equal[int(nim.equalTo.value)]=x
-                               if nim.configMode.value == "loopthrough":
+                               elif nim.configMode.value == "loopthrough":
                                        self.linkNIMs(sec, x, int(nim.linkedTo.value))
                                        self.linked[int(nim.linkedTo.value)]=x
                                elif nim.configMode.value == "satposdepends":
                                        self.setSatposDepends(sec, x, int(nim.satposDependsTo.value))
                                        self.satposdepends[int(nim.satposDependsTo.value)]=x
 
+                       if slot.type is not None:
+                               used_nim_slots.append((slot.slot, slot.description, nim.configMode.value != "nothing" and True or False))
+
+               eDVBResourceManager.getInstance().setFrontendSlotInformations(used_nim_slots)
+
                for slot in nim_slots:
                        x = slot.slot
                        nim = slot.config
@@ -158,20 +159,28 @@ class SecConfigure:
                                                                loValue = rotorParam.EAST
                                                        else:
                                                                loValue = rotorParam.WEST
-                                                       turn_speed_dict = { "fast": rotorParam.FAST, "slow": rotorParam.SLOW }
-                                                       if turn_speed_dict.has_key(nim.turningSpeed.value):
-                                                               turning_speed = turn_speed_dict[nim.turningSpeed.value]
-                                                       else:
-                                                               beg_time = localtime(nim.fastTurningBegin.value)
-                                                               end_time = localtime(nim.fastTurningEnd.value)
-                                                               turning_speed = ((beg_time.tm_hour+1) * 60 + beg_time.tm_min + 1) << 16
-                                                               turning_speed |= (end_time.tm_hour+1) * 60 + end_time.tm_min + 1
+                                                       inputPowerDelta=50
+                                                       useInputPower=False
+                                                       turning_speed=0
+                                                       if nim.powerMeasurement.value:
+                                                               useInputPower=True
+                                                               inputPowerDelta=nim.powerThreshold.value
+                                                               turn_speed_dict = { "fast": rotorParam.FAST, "slow": rotorParam.SLOW }
+                                                               if turn_speed_dict.has_key(nim.turningSpeed.value):
+                                                                       turning_speed = turn_speed_dict[nim.turningSpeed.value]
+                                                               else:
+                                                                       beg_time = localtime(nim.fastTurningBegin.value)
+                                                                       end_time = localtime(nim.fastTurningEnd.value)
+                                                                       turning_speed = ((beg_time.tm_hour+1) * 60 + beg_time.tm_min + 1) << 16
+                                                                       turning_speed |= (end_time.tm_hour+1) * 60 + end_time.tm_min + 1
                                                        self.addLNBSimple(sec, slotid = x, diseqcmode = 3,
                                                                longitude = nim.longitude.float,
                                                                loDirection = loValue,
                                                                latitude = nim.latitude.float,
                                                                laDirection = laValue,
-                                                               turningSpeed = turning_speed)
+                                                               turningSpeed = turning_speed,
+                                                               useInputPower = useInputPower,
+                                                               inputPowerDelta = inputPowerDelta)
                                        elif nim.configMode.value == "advanced": #advanced config
                                                self.updateAdvanced(sec, x)
                print "sec config completed"
@@ -402,99 +411,100 @@ class NIM(object):
        empty = property(lambda self: self.type is None)
 
 class NimManager:
-       class parseSats(ContentHandler):
-               def __init__(self, satList, satellites, transponders):
-                       self.isPointsElement, self.isReboundsElement = 0, 0
-                       self.satList = satList
-                       self.satellites = satellites
-                       self.transponders = transponders
-       
-               def startElement(self, name, attrs):
-                       if (name == "sat"):
-                               #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
-                               tpos = int(attrs.get('position',""))
-                               if tpos < 0:
-                                       tpos = 3600 + tpos
-                               tname = attrs.get('name',"").encode("UTF-8")
-                               self.satellites[tpos] = tname
-                               self.satList.append( (tpos, tname) )
-                               self.parsedSat = int(tpos)
-                       elif (name == "transponder"):
-                               modulation = int(attrs.get('modulation',"1")) # QPSK default
-                               system = int(attrs.get('system',"0")) # DVB-S default
-                               freq = int(attrs.get('frequency',""))
-                               sr = int(attrs.get('symbol_rate',""))
-                               pol = int(attrs.get('polarization',""))
-                               fec = int(attrs.get('fec_inner',"0")) # AUTO default
-                               if self.parsedSat in self.transponders:
-                                       pass
-                               else:
-                                       self.transponders[self.parsedSat] = [ ]
-
-                               self.transponders[self.parsedSat].append((0, freq, sr, pol, fec, system, modulation))
-
-       class parseCables(ContentHandler):
-               def __init__(self, cablesList, transponders):
-                       self.isPointsElement, self.isReboundsElement = 0, 0
-                       self.cablesList = cablesList
-                       for x in self.cablesList:
-                               self.cablesList.remove(x)
-                       self.transponders = transponders
-       
-               def startElement(self, name, attrs):
-                       if (name == "cable"):
-                               #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
-                               tname = attrs.get('name',"").encode("UTF-8")
-                               tflags = int(attrs.get('flags',"0"))
-                               self.cablesList.append((tname, tflags))
-                               self.parsedCab = tname
-                       elif (name == "transponder"):
-                               freq = int(attrs.get('frequency',""))
-                               while freq > 999999:
-                                       freq /= 10
-                               sr = int(attrs.get('symbol_rate',"0"))
-                               mod = int(attrs.get('modulation',"3")) # QAM64 default
-                               fec = int(attrs.get('fec_inner',"0")) # AUTO default
-                               if self.parsedCab in self.transponders:
-                                       pass
-                               else:
-                                       self.transponders[self.parsedCab] = [ ]
-                               self.transponders[self.parsedCab].append((1, freq, sr, mod, fec))
-
-       class parseTerrestrials(ContentHandler):
-               def __init__(self, terrestrialsList, transponders):
-                       self.isPointsElement, self.isReboundsElement = 0, 0
-                       self.terrestrialsList = terrestrialsList
-                       self.transponders = transponders
-       
-               def startElement(self, name, attrs):
-                       if (name == "terrestrial"):
-                               #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
-                               tname = attrs.get('name',"").encode("UTF-8")
-                               tflags = attrs.get('flags',"")
-                               self.terrestrialsList.append((tname, tflags))
-                               self.parsedTer = str(tname)
-                       elif (name == "transponder"):
-                               # TODO finish this!
-                               freq = int(attrs.get('centre_frequency',""))
-                               bw = int(attrs.get('bandwidth',"3")) # AUTO
-                               const = int(attrs.get('constellation',"1")) # AUTO
-                               crh = int(attrs.get('code_rate_hp',"5")) # AUTO
-                               if crh > 5: # our terrestrial.xml is buggy... 6 for AUTO
-                                       crh = 5
-                               crl = int(attrs.get('code_rate_lp',"5")) # AUTO
-                               if crl > 5: # our terrestrial.xml is buggy... 6 for AUTO
-                                       crl = 5
-                               guard = int(attrs.get('guard_interval',"4")) # AUTO
-                               transm = int(attrs.get('transmission_mode',"2")) # AUTO
-                               hierarchy = int(attrs.get('hierarchy_information',"4")) # AUTO
-                               inv = int(attrs.get('inversion',"2")) # AUTO
-                               if self.parsedTer in self.transponders:
-                                       pass
-                               else:
-                                       self.transponders[self.parsedTer] = [ ]
-
-                               self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
+#      class parseSats(ContentHandler):
+#              def __init__(self, satList, satellites, transponders):
+#                      self.isPointsElement, self.isReboundsElement = 0, 0
+#                      self.satList = satList
+#                      self.satellites = satellites
+#                      self.transponders = transponders
+#      
+#              def startElement(self, name, attrs):
+#                      if (name == "sat"):
+#                              #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
+#                              tpos = int(attrs.get('position',""))
+#                              if tpos < 0:
+#                                      tpos = 3600 + tpos
+#                              tname = attrs.get('name',"").encode("UTF-8")
+#                              tflags = int(attrs.get('flags', '0'))
+#                              self.satellites[tpos] = tname
+#                              self.satList.append( (tpos, tname, tflags) )
+#                              self.parsedSat = int(tpos)
+#                      elif (name == "transponder"):
+#                              modulation = int(attrs.get('modulation',"1")) # QPSK default
+#                              system = int(attrs.get('system',"0")) # DVB-S default
+#                              freq = int(attrs.get('frequency',""))
+#                              sr = int(attrs.get('symbol_rate',""))
+#                              pol = int(attrs.get('polarization',""))
+#                              fec = int(attrs.get('fec_inner',"0")) # AUTO default
+#                              if self.parsedSat in self.transponders:
+#                                      pass
+#                              else:
+#                                      self.transponders[self.parsedSat] = [ ]
+#
+#                              self.transponders[self.parsedSat].append((0, freq, sr, pol, fec, system, modulation))
+
+#      class parseCables(ContentHandler):
+#              def __init__(self, cablesList, transponders):
+#                      self.isPointsElement, self.isReboundsElement = 0, 0
+#                      self.cablesList = cablesList
+#                      for x in self.cablesList:
+#                              self.cablesList.remove(x)
+#                      self.transponders = transponders
+#      
+#              def startElement(self, name, attrs):
+#                      if (name == "cable"):
+#                              #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
+#                              tname = attrs.get('name',"").encode("UTF-8")
+#                              tflags = int(attrs.get('flags', '0'))
+#                              self.cablesList.append((tname, tflags))
+#                              self.parsedCab = tname
+#                      elif (name == "transponder"):
+#                              freq = int(attrs.get('frequency',""))
+#                              while freq > 999999:
+#                                      freq /= 10
+#                              sr = int(attrs.get('symbol_rate',"0"))
+#                              mod = int(attrs.get('modulation',"3")) # QAM64 default
+#                              fec = int(attrs.get('fec_inner',"0")) # AUTO default
+#                              if self.parsedCab in self.transponders:
+#                                      pass
+#                              else:
+#                                      self.transponders[self.parsedCab] = [ ]
+#                              self.transponders[self.parsedCab].append((1, freq, sr, mod, fec))
+#
+#      class parseTerrestrials(ContentHandler):
+#              def __init__(self, terrestrialsList, transponders):
+#                      self.isPointsElement, self.isReboundsElement = 0, 0
+#                      self.terrestrialsList = terrestrialsList
+#                      self.transponders = transponders
+#      
+#              def startElement(self, name, attrs):
+#                      if (name == "terrestrial"):
+#                              #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
+#                              tname = attrs.get('name',"").encode("UTF-8")
+#                              tflags = int(attrs.get('flags', '0'))
+#                              self.terrestrialsList.append((tname, tflags))
+#                              self.parsedTer = str(tname)
+#                      elif (name == "transponder"):
+#                              # TODO finish this!
+#                              freq = int(attrs.get('centre_frequency',""))
+#                              bw = int(attrs.get('bandwidth',"3")) # AUTO
+#                              const = int(attrs.get('constellation',"1")) # AUTO
+#                              crh = int(attrs.get('code_rate_hp',"5")) # AUTO
+#                              if crh > 5: # our terrestrial.xml is buggy... 6 for AUTO
+#                                      crh = 5
+#                              crl = int(attrs.get('code_rate_lp',"5")) # AUTO
+#                              if crl > 5: # our terrestrial.xml is buggy... 6 for AUTO
+#                                      crl = 5
+#                              guard = int(attrs.get('guard_interval',"4")) # AUTO
+#                              transm = int(attrs.get('transmission_mode',"2")) # AUTO
+#                              hierarchy = int(attrs.get('hierarchy_information',"4")) # AUTO
+#                              inv = int(attrs.get('inversion',"2")) # AUTO
+#                              if self.parsedTer in self.transponders:
+#                                      pass
+#                              else:
+#                                      self.transponders[self.parsedTer] = [ ]
+#
+#                              self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
 
        def getTransponders(self, pos):
                if self.transponders.has_key(pos):
@@ -529,33 +539,43 @@ class NimManager:
        def getSatDescription(self, pos):
                return self.satellites[pos]
 
-       def readSatsfromFile(self):
+       def readTransponders(self):
                # read initial networks from file. we only read files which we are interested in,
                # which means only these where a compatible tuner exists.
                self.satellites = { }
                self.transponders = { }
                self.transponderscable = { }
-               self.transpondersterrestrial = { }              
+               self.transpondersterrestrial = { }
+               db = eDVBDB.getInstance()
 
-               parser = make_parser()
-               
+#              parser = make_parser()
                if self.hasNimType("DVB-S"):
                        print "Reading satellites.xml"
-                       satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
-                       parser.setContentHandler(satHandler)
-                       parser.parse('/etc/tuxbox/satellites.xml')
+#                      satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
+#                      parser.setContentHandler(satHandler)
+#                      parser.parse('/etc/tuxbox/satellites.xml')
+                       db.readSatellites(self.satList, self.satellites, self.transponders)
+#                      print "SATLIST", self.satList
+#                      print "SATS", self.satellites
+#                      print "TRANSPONDERS", self.transponders
 
                if self.hasNimType("DVB-C"):
                        print "Reading cables.xml"
-                       cabHandler = self.parseCables(self.cablesList, self.transponderscable)
-                       parser.setContentHandler(cabHandler)
-                       parser.parse('/etc/tuxbox/cables.xml')
+#                      cabHandler = self.parseCables(self.cablesList, self.transponderscable)
+#                      parser.setContentHandler(cabHandler)
+#                      parser.parse('/etc/tuxbox/cables.xml')
+                       db.readCables(self.cablesList, self.transponderscable)
+#                      print "CABLIST", self.cablesList
+#                      print "TRANSPONDERS", self.transponders
 
                if self.hasNimType("DVB-T"):
                        print "Reading terrestrial.xml"
-                       terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
-                       parser.setContentHandler(terHandler)
-                       parser.parse('/etc/tuxbox/terrestrial.xml')
+#                      terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
+#                      parser.setContentHandler(terHandler)
+#                      parser.parse('/etc/tuxbox/terrestrial.xml')
+                       db.readTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
+#                      print "TERLIST", self.terrestrialsList
+#                      print "TRANSPONDERS", self.transpondersterrestrial
 
        def enumerateNIMs(self):
                # enum available NIMs. This is currently very dreambox-centric and uses the /proc/bus/nim_sockets interface.
@@ -629,8 +649,7 @@ class NimManager:
                self.cablesList = []
                self.terrestrialsList = []
                self.enumerateNIMs()
-               self.readSatsfromFile()
-
+               self.readTransponders()
                InitNimManager(self)    #init config stuff
 
        # get a list with the friendly full description
@@ -720,7 +739,7 @@ def InitSecParams():
        x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_TONEBURST, configElement.value))
        config.sec.delay_after_toneburst = x
 
-       x = ConfigInteger(default=750, limits = (0, 9999))
+       x = ConfigInteger(default=200, limits = (0, 9999))
        x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS, configElement.value))
        config.sec.delay_after_enable_voltage_before_switch_command = x
 
@@ -769,17 +788,12 @@ def InitNimManager(nimmgr):
        for x in range(len(nimmgr.nim_slots)):
                config.Nims.append(ConfigSubsection())
 
-       used_nim_slots = [ ]
-
        for slot in nimmgr.nim_slots:
                x = slot.slot
                nim = config.Nims[x]
                
                # HACK: currently, we can only looptrough to socket A
 
-               if slot.type is not None:
-                       used_nim_slots.append((slot.slot, slot.description))
-
                if slot.isCompatible("DVB-S"):
                        if slot.slot == 0:
                                nim.configMode = ConfigSelection(
@@ -838,13 +852,16 @@ def InitNimManager(nimmgr):
                        nim.longitudeOrientation = ConfigSelection(choices={"east": _("East"), "west": _("West")}, default = "east")
                        nim.latitude = ConfigFloat(default=[50,767], limits=[(0,359),(0,999)])
                        nim.latitudeOrientation = ConfigSelection(choices={"north": _("North"), "south": _("South")}, default="north")
+                       nim.powerMeasurement = ConfigYesNo(default=True)
+                       nim.powerThreshold = ConfigInteger(default=50, limits=(0, 100))
                        nim.turningSpeed = ConfigSelection(choices = [("fast", _("Fast")), ("slow", _("Slow")), ("fast epoch", _("Fast epoch")) ], default = "fast")
                        btime = datetime(1970, 1, 1, 7, 0);
                        nim.fastTurningBegin = ConfigDateTime(default = mktime(btime.timetuple()), formatstring = _("%H:%M"), increment = 900)
                        etime = datetime(1970, 1, 1, 19, 0);
                        nim.fastTurningEnd = ConfigDateTime(default = mktime(etime.timetuple()), formatstring = _("%H:%M"), increment = 900)
                        # get other frontends of the same type
-                       satNimList = nimmgr.getNimListOfType(slot.type, slot.slot)
+
+                       satNimList = nimmgr.getNimListOfType("DVB-S", slot.slot)
                        satNimListNames = {}
 
                        for x in satNimList:
@@ -976,8 +993,6 @@ def InitNimManager(nimmgr):
                        print "pls add support for this frontend type!"         
 #                      assert False
 
-       eDVBResourceManager.getInstance().setFrontendSlotInformations(used_nim_slots)
-
        nimmgr.sec = SecConfigure(nimmgr)
 
 nimmanager = NimManager()