dont send a diseqc switch command when simple rotor mode is used
[enigma2.git] / lib / python / Components / NimManager.py
index 038277c53ec86853ca8865436d2b647706527f05..1ba676c9c206d24029e62a16577fe430950c4ecd 100644 (file)
@@ -4,7 +4,8 @@ from enigma import eDVBSatelliteEquipmentControl as secClass, \
        eDVBSatelliteLNBParameters as lnbParam, \
        eDVBSatelliteDiseqcParameters as diseqcParam, \
        eDVBSatelliteSwitchParameters as switchParam, \
-       eDVBSatelliteRotorParameters as rotorParam
+       eDVBSatelliteRotorParameters as rotorParam, \
+       eDVBResourceManager
 
 import xml.dom.minidom
 from xml.dom import EMPTY_NAMESPACE
@@ -32,7 +33,7 @@ def tryOpen(filename):
        return procFile
 
 class SecConfigure:
-       def addLNBSimple(self, sec, slotid, diseqcmode, toneburstmode = 0, diseqcpos = 0, orbpos = 0, longitude = 0, latitude = 0, loDirection = 0, laDirection = 0):
+       def addLNBSimple(self, sec, slotid, diseqcmode, toneburstmode = diseqcParam.NO, diseqcpos = diseqcParam.SENDNO, orbpos = 0, longitude = 0, latitude = 0, loDirection = 0, laDirection = 0):
                #simple defaults
                sec.addLNB()
                tunermask = 1 << slotid
@@ -55,6 +56,7 @@ class SecConfigure:
                sec.setDiSEqCMode(diseqcmode)
                sec.setToneburst(toneburstmode)
                sec.setCommittedCommand(diseqcpos)
+               sec.setUncommittedCommand(0) # SENDNO
                #print "set orbpos to:" + str(orbpos)
 
                if 0 <= diseqcmode < 3:
@@ -78,7 +80,7 @@ class SecConfigure:
                                sec.setRotorPosNum(0) # USALS
                                self.satList.append(int(x[0]))
 
-               sec.setLNBTunerMask(tunermask)
+               sec.setLNBSlotMask(tunermask)
 
        def setSatposDepends(self, sec, nim1, nim2):
                print "tuner", nim1, "depends on satpos of", nim2
@@ -124,38 +126,42 @@ class SecConfigure:
                        if slot.isCompatible("DVB-S"):
                                print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
                                print "diseqcmode: ", nim.configMode.value
-                               if nim.configMode.value in [ "loopthrough", "satposdepends", "equal", "nothing" ]:
+                               if nim.configMode.value in [ "loopthrough", "satposdepends", "nothing" ]:
                                        pass
-                               elif nim.configMode.value == "simple":          #simple config
-                                       if nim.diseqcMode.value == "single":                    #single
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.NONE, diseqcpos = diseqcParam.SENDNO)
-                                       elif nim.diseqcMode.value == "toneburst_a_b":           #Toneburst A/B
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.A, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.SENDNO)
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.B, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.SENDNO)
-                                       elif nim.diseqcMode.value == "diseqc_a_b":              #DiSEqC A/B
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA)
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AB)
-                                       elif nim.diseqcMode.value == "diseqc_a_b_c_d":          #DiSEqC A/B/C/D
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA)
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AB)
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcC.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.BA)
-                                               self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcD.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.BB)
-                                       elif nim.diseqcMode.value == "positioner":              #Positioner
-                                               if nim.latitudeOrientation.value == "north":
-                                                       laValue = rotorParam.NORTH
-                                               else:
-                                                       laValue = rotorParam.SOUTH
-                                               if nim.longitudeOrientation.value == "east":
-                                                       loValue = rotorParam.EAST
-                                               else:
-                                                       loValue = rotorParam.WEST
-                                               self.addLNBSimple(sec, slotid = x, diseqcmode = 3,
-                                                       longitude = nim.longitude.float,
-                                                       loDirection = loValue,
-                                                       latitude = nim.latitude.float,
-                                                       laDirection = laValue)
-                               elif nim.configMode.value == "advanced": #advanced config
-                                       self.updateAdvanced(sec, x)
+                               else:
+                                       sec.setSlotNotLinked(x)
+                                       if nim.configMode.value == "equal":
+                                               pass
+                                       elif nim.configMode.value == "simple":          #simple config
+                                               if nim.diseqcMode.value == "single":                    #single
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.NONE, diseqcpos = diseqcParam.SENDNO)
+                                               elif nim.diseqcMode.value == "toneburst_a_b":           #Toneburst A/B
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.A, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.SENDNO)
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.B, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.SENDNO)
+                                               elif nim.diseqcMode.value == "diseqc_a_b":              #DiSEqC A/B
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA)
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AB)
+                                               elif nim.diseqcMode.value == "diseqc_a_b_c_d":          #DiSEqC A/B/C/D
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA)
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AB)
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcC.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.BA)
+                                                       self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcD.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.BB)
+                                               elif nim.diseqcMode.value == "positioner":              #Positioner
+                                                       if nim.latitudeOrientation.value == "north":
+                                                               laValue = rotorParam.NORTH
+                                                       else:
+                                                               laValue = rotorParam.SOUTH
+                                                       if nim.longitudeOrientation.value == "east":
+                                                               loValue = rotorParam.EAST
+                                                       else:
+                                                               loValue = rotorParam.WEST
+                                                       self.addLNBSimple(sec, slotid = x, diseqcmode = 3,
+                                                               longitude = nim.longitude.float,
+                                                               loDirection = loValue,
+                                                               latitude = nim.latitude.float,
+                                                               laDirection = laValue)
+                                       elif nim.configMode.value == "advanced": #advanced config
+                                               self.updateAdvanced(sec, x)
                print "sec config completed"
 
        def updateAdvanced(self, sec, slotid):
@@ -284,7 +290,7 @@ class SecConfigure:
                                else:
                                        sec.setUseInputpower(False)
 
-                               sec.setLNBTunerMask(tunermask)
+                               sec.setLNBSlotMask(tunermask)
 
                                # finally add the orbital positions
                                for y in lnbSat[x]:
@@ -372,10 +378,7 @@ class NIM(object):
        friendly_full_description = property(getFriendlyFullDescription)
        config_mode = property(lambda self: config.Nims[self.slot].configMode.value)
        config = property(lambda self: config.Nims[self.slot])
-       
        empty = property(lambda self: self.type is None)
-       
-       cable_trust_nit = property(lambda self: self.config.cabletype.value == "quick")
 
 class NimManager:
        class parseSats(ContentHandler):
@@ -413,24 +416,29 @@ class NimManager:
                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")
-                               self.cablesList.append(str(tname))
-                               self.parsedCab = str(tname)
+                               tflags = int(attrs.get('flags',"0"))
+                               self.cablesList.append((tname, tflags))
+                               self.parsedCab = tname
                        elif (name == "transponder"):
                                freq = int(attrs.get('frequency',""))
-                               #sr = int(attrs.get('symbol_rate',""))
-                               #mod = int(attrs.get('modulation',"3")) # QAM64 default
-                               #fec = int(attrs.get('fec_inner',"0")) # AUTO default
+                               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))
+                               self.transponders[self.parsedCab].append((1, freq, sr, mod, fec))
 
        class parseTerrestrials(ContentHandler):
                def __init__(self, terrestrialsList, transponders):
@@ -473,15 +481,21 @@ class NimManager:
                else:
                        return []
 
-       def getTranspondersCable(self, cable):
-               return self.transponderscable[cable]
+       def getTranspondersCable(self, nim):
+               nimConfig = config.Nims[nim]
+               if nimConfig.configMode.value != "nothing" and nimConfig.cable.scan_type.value == "provider":
+                       return self.transponderscable[self.cablesList[nimConfig.cable.scan_provider.index][0]]
+               return [ ]
 
        def getTranspondersTerrestrial(self, region):
                return self.transpondersterrestrial[region]
        
        def getCableDescription(self, nim):
-               return self.cablesList[0]
-       
+               return self.cablesList[config.Nims[nim].scan_provider.index][0]
+
+       def getCableFlags(self, nim):
+               return self.cablesList[config.Nims[nim].scan_provider.index][1]
+
        def getTerrestrialDescription(self, nim):
                return self.terrestrialsList[config.Nims[nim].terrestrial.index][0]
 
@@ -717,6 +731,15 @@ def InitSecParams():
        x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_COMMAND_RETRIES, configElement.value))
        config.sec.motor_command_retries = x
 
+       x = ConfigInteger(default=20, limits = (0, 9999))
+       x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS, configElement.value))
+       config.sec.delay_after_change_voltage_before_switch_command = x
+
+# TODO add support for satpos depending nims to advanced nim configuration
+# so a second/third/fourth cable from a motorized lnb can used behind a
+# diseqc 1.0 / diseqc 1.1 / toneburst switch
+# the C(++) part should can handle this
+# the configElement should be only visible when diseqc 1.2 is disabled
 
 def InitNimManager(nimmgr):
        InitSecParams()
@@ -725,12 +748,17 @@ 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(
@@ -861,13 +889,45 @@ def InitNimManager(nimmgr):
                                nim.advanced.lnb[x].powerThreshold = ConfigInteger(default=50, limits=(0, 100))
 
                elif slot.isCompatible("DVB-C"):
-                       nim.cabletype = ConfigSelection(choices = [("quick", _("Quick")), ("complete", _("Complete"))], default = "complete")
                        nim.configMode = ConfigSelection(
                                choices = {
                                        "enabled": _("enabled"),
                                        "nothing": _("nothing connected"),
                                        },
                                default = "enabled")
+                       list = [ ]
+                       n = 0
+                       for x in nimmgr.cablesList:
+                               list.append((str(n), x[0]))
+                               n += 1
+                       nim.cable = ConfigSubsection()
+                       possible_scan_types = [("bands", _("Frequency bands")), ("steps", _("Frequency steps"))]
+                       if n:
+                               possible_scan_types.append(("provider", _("Provider")))
+                       nim.cable.scan_type = ConfigSelection(default = "bands", choices = possible_scan_types)
+                       nim.cable.scan_provider = ConfigSelection(default = "0", choices = list)
+                       nim.cable.scan_band_EU_VHF_I = ConfigYesNo(default = True)
+                       nim.cable.scan_band_EU_MID = ConfigYesNo(default = True)
+                       nim.cable.scan_band_EU_VHF_III = ConfigYesNo(default = True)
+                       nim.cable.scan_band_EU_UHF_IV = ConfigYesNo(default = True)
+                       nim.cable.scan_band_EU_UHF_V = ConfigYesNo(default = True)
+                       nim.cable.scan_band_EU_SUPER = ConfigYesNo(default = True)
+                       nim.cable.scan_band_EU_HYPER = ConfigYesNo(default = True)
+                       nim.cable.scan_band_US_LOW = ConfigYesNo(default = False)
+                       nim.cable.scan_band_US_MID = ConfigYesNo(default = False)
+                       nim.cable.scan_band_US_HIGH = ConfigYesNo(default = False)
+                       nim.cable.scan_band_US_SUPER = ConfigYesNo(default = False)
+                       nim.cable.scan_band_US_HYPER = ConfigYesNo(default = False)
+                       nim.cable.scan_frequency_steps = ConfigInteger(default = 1000, limits = (1000, 10000))
+                       nim.cable.scan_mod_qam16 = ConfigYesNo(default = False)
+                       nim.cable.scan_mod_qam32 = ConfigYesNo(default = False)
+                       nim.cable.scan_mod_qam64 = ConfigYesNo(default = True)
+                       nim.cable.scan_mod_qam128 = ConfigYesNo(default = False)
+                       nim.cable.scan_mod_qam256 = ConfigYesNo(default = True)
+                       nim.cable.scan_sr_6900 = ConfigYesNo(default = True)
+                       nim.cable.scan_sr_6875 = ConfigYesNo(default = True)
+                       nim.cable.scan_sr_ext1 = ConfigInteger(default = 0, limits = (0, 7230))
+                       nim.cable.scan_sr_ext2 = ConfigInteger(default = 0, limits = (0, 7230))
                elif slot.isCompatible("DVB-T"):
                        nim.configMode = ConfigSelection(
                                choices = {
@@ -887,6 +947,8 @@ 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()