refs bug #593
[vuplus_dvbapp] / lib / python / Components / NimManager.py
1 from Tools.HardwareInfo import HardwareInfo
2 from Tools.BoundFunction import boundFunction
3
4 from config import config, ConfigSubsection, ConfigSelection, ConfigFloat, \
5         ConfigSatlist, ConfigYesNo, ConfigInteger, ConfigSubList, ConfigNothing, \
6         ConfigSubDict, ConfigOnOff, ConfigDateTime
7
8 from enigma import eDVBSatelliteEquipmentControl as secClass, \
9         eDVBSatelliteLNBParameters as lnbParam, \
10         eDVBSatelliteDiseqcParameters as diseqcParam, \
11         eDVBSatelliteSwitchParameters as switchParam, \
12         eDVBSatelliteRotorParameters as rotorParam, \
13         eDVBResourceManager, eDVBDB
14
15 from time import localtime, mktime
16 from datetime import datetime
17 from Tools.BoundFunction import boundFunction
18
19 from Tools import Directories
20 import xml.etree.cElementTree
21
22 def getConfigSatlist(orbpos, satlist):
23         default_orbpos = None
24         for x in satlist:
25                 if x[0] == orbpos:
26                         default_orbpos = orbpos
27                         break
28         return ConfigSatlist(satlist, default_orbpos)
29
30 def tryOpen(filename):
31         try:
32                 procFile = open(filename)
33         except IOError:
34                 return None
35         return procFile
36
37 class SecConfigure:
38         def getConfiguredSats(self):
39                 return self.configuredSatellites
40
41         def addSatellite(self, sec, orbpos):
42                 sec.addSatellite(orbpos)
43                 self.configuredSatellites.add(orbpos)
44
45         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, fastDiSEqC = False, setVoltageTone = True, diseqc13V = False):
46                 if orbpos is None or orbpos == 3601:
47                         return
48                 #simple defaults
49                 sec.addLNB()
50                 tunermask = 1 << slotid
51                 if self.equal.has_key(slotid):
52                         for slot in self.equal[slotid]:
53                                 tunermask |= (1 << slot)
54                 if self.linked.has_key(slotid):
55                         for slot in self.linked[slotid]:
56                                 tunermask |= (1 << slot)
57                 sec.setLNBSatCR(-1)
58                 sec.setLNBNum(1)
59                 sec.setLNBLOFL(9750000)
60                 sec.setLNBLOFH(10600000)
61                 sec.setLNBThreshold(11700000)
62                 sec.setLNBIncreasedVoltage(lnbParam.OFF)
63                 sec.setRepeats(0)
64                 sec.setFastDiSEqC(fastDiSEqC)
65                 sec.setSeqRepeat(0)
66                 sec.setCommandOrder(0)
67
68                 #user values
69                 sec.setDiSEqCMode(diseqcmode)
70                 sec.setToneburst(toneburstmode)
71                 sec.setCommittedCommand(diseqcpos)
72                 sec.setUncommittedCommand(0) # SENDNO
73                 #print "set orbpos to:" + str(orbpos)
74
75                 if 0 <= diseqcmode < 3:
76                         self.addSatellite(sec, orbpos)
77                         if setVoltageTone:
78                                 if diseqc13V:
79                                         sec.setVoltageMode(switchParam.HV_13)
80                                 else:
81                                         sec.setVoltageMode(switchParam.HV)
82                                 sec.setToneMode(switchParam.HILO)
83                         else:
84                                 sec.setVoltageMode(switchParam._14V)
85                                 sec.setToneMode(switchParam.OFF)
86                 elif (diseqcmode == 3): # diseqc 1.2
87                         if self.satposdepends.has_key(slotid):
88                                 for slot in self.satposdepends[slotid]:
89                                         tunermask |= (1 << slot)
90                         sec.setLatitude(latitude)
91                         sec.setLaDirection(laDirection)
92                         sec.setLongitude(longitude)
93                         sec.setLoDirection(loDirection)
94                         sec.setUseInputpower(useInputPower)
95                         sec.setInputpowerDelta(inputPowerDelta)
96                         sec.setRotorTurningSpeed(turningSpeed)
97
98                         for x in self.NimManager.satList:
99                                 print "Add sat " + str(x[0])
100                                 self.addSatellite(sec, int(x[0]))
101                                 if diseqc13V:
102                                         sec.setVoltageMode(switchParam.HV_13)
103                                 else:
104                                         sec.setVoltageMode(switchParam.HV)
105                                 sec.setToneMode(switchParam.HILO)
106                                 sec.setRotorPosNum(0) # USALS
107                 
108                 sec.setLNBSlotMask(tunermask)
109
110         def setSatposDepends(self, sec, nim1, nim2):
111                 print "tuner", nim1, "depends on satpos of", nim2
112                 sec.setTunerDepends(nim1, nim2)
113
114         def linkNIMs(self, sec, nim1, nim2):
115                 print "link tuner", nim1, "to tuner", nim2
116                 sec.setTunerLinked(nim1, nim2)
117                 
118         def getRoot(self, slotid, connto):
119                 visited = []
120                 while (self.NimManager.getNimConfig(connto).configMode.value in ("satposdepends", "equal", "loopthrough")):
121                         connto = int(self.NimManager.getNimConfig(connto).connectedTo.value)
122                         if connto in visited: # prevent endless loop
123                                 return slotid
124                         visited.append(connto)
125                 return connto
126
127         def update(self):
128                 sec = secClass.getInstance()
129                 self.configuredSatellites = set()
130                 sec.clear() ## this do unlinking NIMs too !!
131                 print "sec config cleared"
132
133                 self.linked = { }
134                 self.satposdepends = { }
135                 self.equal = { }
136
137                 nim_slots = self.NimManager.nim_slots
138
139                 used_nim_slots = [ ]
140
141                 for slot in nim_slots:
142                         if slot.type is not None:
143                                 used_nim_slots.append((slot.slot, slot.description, slot.config.configMode.value != "nothing" and True or False, slot.isCompatible("DVB-S2")))
144                 eDVBResourceManager.getInstance().setFrontendSlotInformations(used_nim_slots)
145
146                 for slot in nim_slots:
147                         x = slot.slot
148                         nim = slot.config
149                         if slot.isCompatible("DVB-S"):
150                                 # save what nim we link to/are equal to/satposdepends to.
151                                 # this is stored in the *value* (not index!) of the config list
152                                 if nim.configMode.value == "equal":
153                                         connto = self.getRoot(x, int(nim.connectedTo.value))
154                                         if not self.equal.has_key(connto):
155                                                 self.equal[connto] = []
156                                         self.equal[connto].append(x)
157                                 elif nim.configMode.value == "loopthrough":
158                                         self.linkNIMs(sec, x, int(nim.connectedTo.value))
159                                         connto = self.getRoot(x, int(nim.connectedTo.value))
160                                         if not self.linked.has_key(connto):
161                                                 self.linked[connto] = []
162                                         self.linked[connto].append(x)
163                                 elif nim.configMode.value == "satposdepends":
164                                         self.setSatposDepends(sec, x, int(nim.connectedTo.value))
165                                         connto = self.getRoot(x, int(nim.connectedTo.value))
166                                         if not self.satposdepends.has_key(connto):
167                                                 self.satposdepends[connto] = []
168                                         self.satposdepends[connto].append(x)
169
170                 for slot in nim_slots:
171                         x = slot.slot
172                         nim = slot.config
173                         hw = HardwareInfo()
174                         if slot.isCompatible("DVB-S"):
175                                 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
176                                 if nim.configMode.value in ( "loopthrough", "satposdepends", "nothing" ):
177                                         pass
178                                 else:
179                                         sec.setSlotNotLinked(x)
180                                         if nim.configMode.value == "equal":
181                                                 pass
182                                         elif nim.configMode.value == "simple":          #simple config
183                                                 print "diseqcmode: ", nim.diseqcMode.value
184                                                 if nim.diseqcMode.value == "single":                    #single
185                                                         if nim.simpleSingleSendDiSEqC.value:
186                                                                 self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA, diseqc13V = nim.diseqc13V.value)
187                                                         else:
188                                                                 self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.NONE, diseqcpos = diseqcParam.SENDNO, diseqc13V = nim.diseqc13V.value)
189                                                 elif nim.diseqcMode.value == "toneburst_a_b":           #Toneburst A/B
190                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.A, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.SENDNO, diseqc13V = nim.diseqc13V.value)
191                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.B, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.SENDNO, diseqc13V = nim.diseqc13V.value)
192                                                 elif nim.diseqcMode.value == "diseqc_a_b":              #DiSEqC A/B
193                                                         fastDiSEqC = nim.simpleDiSEqCOnlyOnSatChange.value
194                                                         setVoltageTone = nim.simpleDiSEqCSetVoltageTone.value
195                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA, fastDiSEqC = fastDiSEqC, setVoltageTone = setVoltageTone, diseqc13V = nim.diseqc13V.value)
196                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AB, fastDiSEqC = fastDiSEqC, setVoltageTone = setVoltageTone, diseqc13V = nim.diseqc13V.value)
197                                                 elif nim.diseqcMode.value == "diseqc_a_b_c_d":          #DiSEqC A/B/C/D
198                                                         fastDiSEqC = nim.simpleDiSEqCOnlyOnSatChange.value
199                                                         setVoltageTone = nim.simpleDiSEqCSetVoltageTone.value
200                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA, fastDiSEqC = fastDiSEqC, setVoltageTone = setVoltageTone, diseqc13V = nim.diseqc13V.value)
201                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AB, fastDiSEqC = fastDiSEqC, setVoltageTone = setVoltageTone, diseqc13V = nim.diseqc13V.value)
202                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcC.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.BA, fastDiSEqC = fastDiSEqC, setVoltageTone = setVoltageTone, diseqc13V = nim.diseqc13V.value)
203                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcD.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.BB, fastDiSEqC = fastDiSEqC, setVoltageTone = setVoltageTone, diseqc13V = nim.diseqc13V.value)
204                                                 elif nim.diseqcMode.value == "positioner":              #Positioner
205                                                         if nim.latitudeOrientation.value == "north":
206                                                                 laValue = rotorParam.NORTH
207                                                         else:
208                                                                 laValue = rotorParam.SOUTH
209                                                         if nim.longitudeOrientation.value == "east":
210                                                                 loValue = rotorParam.EAST
211                                                         else:
212                                                                 loValue = rotorParam.WEST
213                                                         inputPowerDelta=nim.powerThreshold.value
214                                                         useInputPower=False
215                                                         turning_speed=0
216                                                         if nim.powerMeasurement.value:
217                                                                 useInputPower=True
218                                                                 turn_speed_dict = { "fast": rotorParam.FAST, "slow": rotorParam.SLOW }
219                                                                 if turn_speed_dict.has_key(nim.turningSpeed.value):
220                                                                         turning_speed = turn_speed_dict[nim.turningSpeed.value]
221                                                                 else:
222                                                                         beg_time = localtime(nim.fastTurningBegin.value)
223                                                                         end_time = localtime(nim.fastTurningEnd.value)
224                                                                         turning_speed = ((beg_time.tm_hour+1) * 60 + beg_time.tm_min + 1) << 16
225                                                                         turning_speed |= (end_time.tm_hour+1) * 60 + end_time.tm_min + 1
226                                                         self.addLNBSimple(sec, slotid = x, diseqcmode = 3,
227                                                                 longitude = nim.longitude.float,
228                                                                 loDirection = loValue,
229                                                                 latitude = nim.latitude.float,
230                                                                 laDirection = laValue,
231                                                                 turningSpeed = turning_speed,
232                                                                 useInputPower = useInputPower,
233                                                                 inputPowerDelta = inputPowerDelta,
234                                                                 diseqc13V = nim.diseqc13V.value)
235                                         elif nim.configMode.value == "advanced": #advanced config
236                                                 self.updateAdvanced(sec, x)
237                 print "sec config completed"
238
239         def updateAdvanced(self, sec, slotid):
240                 try:
241                         if config.Nims[slotid].advanced.unicableconnected is not None:
242                                 if config.Nims[slotid].advanced.unicableconnected.value == True:
243                                         config.Nims[slotid].advanced.unicableconnectedTo.save_forced = True
244                                         self.linkNIMs(sec, slotid, int(config.Nims[slotid].advanced.unicableconnectedTo.value))
245                                         connto = self.getRoot(slotid, int(config.Nims[slotid].advanced.unicableconnectedTo.value))
246                                         if not self.linked.has_key(connto):
247                                                 self.linked[connto] = []
248                                         self.linked[connto].append(slotid)
249                                 else:
250                                         config.Nims[slotid].advanced.unicableconnectedTo.save_forced = False
251                 except:
252                         pass
253
254                 lnbSat = {}
255                 for x in range(1,37):
256                         lnbSat[x] = []
257
258                 #wildcard for all satellites ( for rotor )
259                 for x in range(3601, 3605):
260                         lnb = int(config.Nims[slotid].advanced.sat[x].lnb.value)
261                         if lnb != 0:
262                                 for x in self.NimManager.satList:
263                                         print "add", x[0], "to", lnb
264                                         lnbSat[lnb].append(x[0])
265
266                 for x in self.NimManager.satList:
267                         lnb = int(config.Nims[slotid].advanced.sat[x[0]].lnb.value)
268                         if lnb != 0:
269                                 print "add", x[0], "to", lnb
270                                 lnbSat[lnb].append(x[0])
271
272                 for x in range(1,37):
273                         if len(lnbSat[x]) > 0:
274                                 currLnb = config.Nims[slotid].advanced.lnb[x]
275                                 sec.addLNB()
276
277                                 if x < 33:
278                                         sec.setLNBNum(x)
279
280                                 tunermask = 1 << slotid
281                                 if self.equal.has_key(slotid):
282                                         for slot in self.equal[slotid]:
283                                                 tunermask |= (1 << slot)
284                                 if self.linked.has_key(slotid):
285                                         for slot in self.linked[slotid]:
286                                                 tunermask |= (1 << slot)
287
288                                 if currLnb.lof.value != "unicable":
289                                         sec.setLNBSatCR(-1)
290
291                                 if currLnb.lof.value == "universal_lnb":
292                                         sec.setLNBLOFL(9750000)
293                                         sec.setLNBLOFH(10600000)
294                                         sec.setLNBThreshold(11700000)
295                                 elif currLnb.lof.value == "unicable":
296                                         def setupUnicable(configManufacturer, ProductDict):
297                                                 manufacturer_name = configManufacturer.value
298                                                 manufacturer = ProductDict[manufacturer_name]
299                                                 product_name = manufacturer.product.value
300                                                 sec.setLNBSatCR(manufacturer.scr[product_name].index)
301                                                 sec.setLNBSatCRvco(manufacturer.vco[product_name][manufacturer.scr[product_name].index].value*1000)
302                                                 sec.setLNBSatCRpositions(manufacturer.positions[product_name][0].value)
303                                                 sec.setLNBLOFL(manufacturer.lofl[product_name][0].value * 1000)
304                                                 sec.setLNBLOFH(manufacturer.lofh[product_name][0].value * 1000)
305                                                 sec.setLNBThreshold(manufacturer.loft[product_name][0].value * 1000)
306                                                 configManufacturer.save_forced = True
307                                                 manufacturer.product.save_forced = True
308                                                 manufacturer.vco[product_name][manufacturer.scr[product_name].index].save_forced = True
309
310                                         if currLnb.unicable.value == "unicable_user":
311 #TODO satpositions for satcruser
312                                                 sec.setLNBLOFL(currLnb.lofl.value * 1000)
313                                                 sec.setLNBLOFH(currLnb.lofh.value * 1000)
314                                                 sec.setLNBThreshold(currLnb.threshold.value * 1000)
315                                                 sec.setLNBSatCR(currLnb.satcruser.index)
316                                                 sec.setLNBSatCRvco(currLnb.satcrvcouser[currLnb.satcruser.index].value*1000)
317                                                 sec.setLNBSatCRpositions(1)     #HACK
318                                         elif currLnb.unicable.value == "unicable_matrix":
319                                                 setupUnicable(currLnb.unicableMatrixManufacturer, currLnb.unicableMatrix)
320                                         elif currLnb.unicable.value == "unicable_lnb":
321                                                 setupUnicable(currLnb.unicableLnbManufacturer, currLnb.unicableLnb)
322                                 elif currLnb.lof.value == "c_band":
323                                         sec.setLNBLOFL(5150000)
324                                         sec.setLNBLOFH(5150000)
325                                         sec.setLNBThreshold(5150000)
326                                 elif currLnb.lof.value == "user_defined":
327                                         sec.setLNBLOFL(currLnb.lofl.value * 1000)
328                                         sec.setLNBLOFH(currLnb.lofh.value * 1000)
329                                         sec.setLNBThreshold(currLnb.threshold.value * 1000)
330
331 #                               if currLnb.output_12v.value == "0V":
332 #                                       pass # nyi in drivers
333 #                               elif currLnb.output_12v.value == "12V":
334 #                                       pass # nyi in drivers
335
336                                 if currLnb.increased_voltage.value:
337                                         sec.setLNBIncreasedVoltage(lnbParam.ON)
338                                 else:
339                                         sec.setLNBIncreasedVoltage(lnbParam.OFF)
340
341                                 dm = currLnb.diseqcMode.value
342                                 if dm == "none":
343                                         sec.setDiSEqCMode(diseqcParam.NONE)
344                                 elif dm == "1_0":
345                                         sec.setDiSEqCMode(diseqcParam.V1_0)
346                                 elif dm == "1_1":
347                                         sec.setDiSEqCMode(diseqcParam.V1_1)
348                                 elif dm == "1_2":
349                                         sec.setDiSEqCMode(diseqcParam.V1_2)
350
351                                         if self.satposdepends.has_key(slotid):
352                                                 for slot in self.satposdepends[slotid]:
353                                                         tunermask |= (1 << slot)
354
355                                 if dm != "none":
356                                         if currLnb.toneburst.value == "none":
357                                                 sec.setToneburst(diseqcParam.NO)
358                                         elif currLnb.toneburst.value == "A":
359                                                 sec.setToneburst(diseqcParam.A)
360                                         elif currLnb.toneburst.value == "B":
361                                                 sec.setToneburst(diseqcParam.B)
362
363                                         # Committed Diseqc Command
364                                         cdc = currLnb.commitedDiseqcCommand.value
365
366                                         c = { "none": diseqcParam.SENDNO,
367                                                 "AA": diseqcParam.AA,
368                                                 "AB": diseqcParam.AB,
369                                                 "BA": diseqcParam.BA,
370                                                 "BB": diseqcParam.BB }
371
372                                         if c.has_key(cdc):
373                                                 sec.setCommittedCommand(c[cdc])
374                                         else:
375                                                 sec.setCommittedCommand(long(cdc))
376
377                                         sec.setFastDiSEqC(currLnb.fastDiseqc.value)
378
379                                         sec.setSeqRepeat(currLnb.sequenceRepeat.value)
380
381                                         if currLnb.diseqcMode.value == "1_0":
382                                                 currCO = currLnb.commandOrder1_0.value
383                                         else:
384                                                 currCO = currLnb.commandOrder.value
385
386                                                 udc = int(currLnb.uncommittedDiseqcCommand.value)
387                                                 if udc > 0:
388                                                         sec.setUncommittedCommand(0xF0|(udc-1))
389                                                 else:
390                                                         sec.setUncommittedCommand(0) # SENDNO
391
392                                                 sec.setRepeats({"none": 0, "one": 1, "two": 2, "three": 3}[currLnb.diseqcRepeats.value])
393
394                                         setCommandOrder = False
395
396                                         # 0 "committed, toneburst",
397                                         # 1 "toneburst, committed",
398                                         # 2 "committed, uncommitted, toneburst",
399                                         # 3 "toneburst, committed, uncommitted",
400                                         # 4 "uncommitted, committed, toneburst"
401                                         # 5 "toneburst, uncommitted, commmitted"
402                                         order_map = {"ct": 0, "tc": 1, "cut": 2, "tcu": 3, "uct": 4, "tuc": 5}
403                                         sec.setCommandOrder(order_map[currCO])
404
405                                 if dm == "1_2":
406                                         latitude = currLnb.latitude.float
407                                         sec.setLatitude(latitude)
408                                         longitude = currLnb.longitude.float
409                                         sec.setLongitude(longitude)
410                                         if currLnb.latitudeOrientation.value == "north":
411                                                 sec.setLaDirection(rotorParam.NORTH)
412                                         else:
413                                                 sec.setLaDirection(rotorParam.SOUTH)
414                                         if currLnb.longitudeOrientation.value == "east":
415                                                 sec.setLoDirection(rotorParam.EAST)
416                                         else:
417                                                 sec.setLoDirection(rotorParam.WEST)
418
419                                         if currLnb.powerMeasurement.value:
420                                                 sec.setUseInputpower(True)
421                                                 sec.setInputpowerDelta(currLnb.powerThreshold.value)
422                                                 turn_speed_dict = { "fast": rotorParam.FAST, "slow": rotorParam.SLOW }
423                                                 if turn_speed_dict.has_key(currLnb.turningSpeed.value):
424                                                         turning_speed = turn_speed_dict[currLnb.turningSpeed.value]
425                                                 else:
426                                                         beg_time = localtime(currLnb.fastTurningBegin.value)
427                                                         end_time = localtime(currLnb.fastTurningEnd.value)
428                                                         turning_speed = ((beg_time.tm_hour + 1) * 60 + beg_time.tm_min + 1) << 16
429                                                         turning_speed |= (end_time.tm_hour + 1) * 60 + end_time.tm_min + 1
430                                                 sec.setRotorTurningSpeed(turning_speed)
431                                         else:
432                                                 sec.setUseInputpower(False)
433
434                                 sec.setLNBSlotMask(tunermask)
435
436                                 sec.setLNBPrio(int(currLnb.prio.value))
437
438                                 # finally add the orbital positions
439                                 for y in lnbSat[x]:
440                                         self.addSatellite(sec, y)
441                                         if x > 32:
442                                                 satpos = x > 32 and (3604-(36 - x)) or y
443                                         else:
444                                                 satpos = y
445                                         currSat = config.Nims[slotid].advanced.sat[satpos]
446                                         if currSat.voltage.value == "polarization":
447                                                 if config.Nims[slotid].diseqc13V.value:
448                                                         sec.setVoltageMode(switchParam.HV_13)
449                                                 else:
450                                                         sec.setVoltageMode(switchParam.HV)
451                                         elif currSat.voltage.value == "13V":
452                                                 sec.setVoltageMode(switchParam._14V)
453                                         elif currSat.voltage.value == "18V":
454                                                 sec.setVoltageMode(switchParam._18V)
455
456                                         if currSat.tonemode.value == "band":
457                                                 sec.setToneMode(switchParam.HILO)
458                                         elif currSat.tonemode.value == "on":
459                                                 sec.setToneMode(switchParam.ON)
460                                         elif currSat.tonemode.value == "off":
461                                                 sec.setToneMode(switchParam.OFF)
462                                                 
463                                         if not currSat.usals.value and x < 34:
464                                                 sec.setRotorPosNum(currSat.rotorposition.value)
465                                         else:
466                                                 sec.setRotorPosNum(0) #USALS
467
468         def __init__(self, nimmgr):
469                 self.NimManager = nimmgr
470                 self.configuredSatellites = set()
471                 self.update()
472
473 class NIM(object):
474         def __init__(self, slot, type, description, has_outputs = True, internally_connectable = None, multi_type = {}, i2c = None):
475                 self.slot = slot
476
477                 if type not in ("DVB-S", "DVB-C", "DVB-T", "DVB-S2", None):
478                         print "warning: unknown NIM type %s, not using." % type
479                         type = None
480
481                 self.type = type
482                 self.description = description
483                 self.has_outputs = has_outputs
484                 self.internally_connectable = internally_connectable
485                 self.multi_type = multi_type
486                 self.i2c = i2c
487
488         def isCompatible(self, what):
489                 compatible = {
490                                 None: (None,),
491                                 "DVB-S": ("DVB-S", None),
492                                 "DVB-C": ("DVB-C", None),
493                                 "DVB-T": ("DVB-T", None),
494                                 "DVB-S2": ("DVB-S", "DVB-S2", None)
495                         }
496                 return what in compatible[self.type]
497         
498         def getType(self):
499                 return self.type
500         
501         def connectableTo(self):
502                 connectable = {
503                                 "DVB-S": ("DVB-S", "DVB-S2"),
504                                 "DVB-C": ("DVB-C",),
505                                 "DVB-T": ("DVB-T",),
506                                 "DVB-S2": ("DVB-S", "DVB-S2")
507                         }
508                 return connectable[self.type]
509
510         def getSlotName(self):
511                 # get a friendly description for a slot name.
512                 # we name them "Tuner A/B/C/...", because that's what's usually written on the back
513                 # of the device.
514                 return _("Tuner ") + chr(ord('A') + self.slot)
515
516         slot_name = property(getSlotName)
517
518         def getSlotID(self):
519                 return chr(ord('A') + self.slot)
520         
521         def getI2C(self):
522                 return self.i2c
523         
524         def hasOutputs(self):
525                 return self.has_outputs
526         
527         def internallyConnectableTo(self):
528                 return self.internally_connectable
529         
530         def isMultiType(self):
531                 return (len(self.multi_type) > 0)
532         
533         # returns dict {<slotid>: <type>}
534         def getMultiTypeList(self):
535                 return self.multi_type
536
537         slot_id = property(getSlotID)
538
539         def getFriendlyType(self):
540                 return {
541                         "DVB-S": "DVB-S", 
542                         "DVB-T": "DVB-T",
543                         "DVB-S2": "DVB-S2",
544                         "DVB-C": "DVB-C",
545                         None: _("empty")
546                         }[self.type]
547
548         friendly_type = property(getFriendlyType)
549
550         def getFriendlyFullDescription(self):
551                 nim_text = self.slot_name + ": "
552                         
553                 if self.empty:
554                         nim_text += _("(empty)")
555                 else:
556                         nim_text += self.description + " (" + self.friendly_type + ")"
557                 
558                 return nim_text
559
560         friendly_full_description = property(getFriendlyFullDescription)
561         config_mode = property(lambda self: config.Nims[self.slot].configMode.value)
562         config = property(lambda self: config.Nims[self.slot])
563         empty = property(lambda self: self.type is None)
564
565 class NimManager:
566         def getConfiguredSats(self):
567                 return self.sec.getConfiguredSats()
568
569         def getTransponders(self, pos):
570                 if self.transponders.has_key(pos):
571                         return self.transponders[pos]
572                 else:
573                         return []
574
575         def getTranspondersCable(self, nim):
576                 nimConfig = config.Nims[nim]
577                 if nimConfig.configMode.value != "nothing" and nimConfig.cable.scan_type.value == "provider":
578                         return self.transponderscable[self.cablesList[nimConfig.cable.scan_provider.index][0]]
579                 return [ ]
580
581         def getTranspondersTerrestrial(self, region):
582                 return self.transpondersterrestrial[region]
583         
584         def getCableDescription(self, nim):
585                 return self.cablesList[config.Nims[nim].scan_provider.index][0]
586
587         def getCableFlags(self, nim):
588                 return self.cablesList[config.Nims[nim].scan_provider.index][1]
589
590         def getTerrestrialDescription(self, nim):
591                 return self.terrestrialsList[config.Nims[nim].terrestrial.index][0]
592
593         def getTerrestrialFlags(self, nim):
594                 return self.terrestrialsList[config.Nims[nim].terrestrial.index][1]
595
596         def getSatDescription(self, pos):
597                 return self.satellites[pos]
598
599         def sortFunc(self, x):
600                 orbpos = x[0]
601                 if orbpos > 1800:
602                         return orbpos - 3600
603                 else:
604                         return orbpos + 1800
605
606         def readTransponders(self):
607                 # read initial networks from file. we only read files which we are interested in,
608                 # which means only these where a compatible tuner exists.
609                 self.satellites = { }
610                 self.transponders = { }
611                 self.transponderscable = { }
612                 self.transpondersterrestrial = { }
613                 db = eDVBDB.getInstance()
614                 if self.hasNimType("DVB-S"):
615                         print "Reading satellites.xml"
616                         db.readSatellites(self.satList, self.satellites, self.transponders)
617                         self.satList.sort(key = self.sortFunc) # sort by orbpos
618                         #print "SATLIST", self.satList
619                         #print "SATS", self.satellites
620                         #print "TRANSPONDERS", self.transponders
621
622                 if self.hasNimType("DVB-C"):
623                         print "Reading cables.xml"
624                         db.readCables(self.cablesList, self.transponderscable)
625 #                       print "CABLIST", self.cablesList
626 #                       print "TRANSPONDERS", self.transponders
627
628                 if self.hasNimType("DVB-T"):
629                         print "Reading terrestrial.xml"
630                         db.readTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
631 #                       print "TERLIST", self.terrestrialsList
632 #                       print "TRANSPONDERS", self.transpondersterrestrial
633
634         def enumerateNIMs(self):
635                 # enum available NIMs. This is currently very dreambox-centric and uses the /proc/bus/nim_sockets interface.
636                 # the result will be stored into nim_slots.
637                 # the content of /proc/bus/nim_sockets looks like:
638                 # NIM Socket 0:
639                 #          Type: DVB-S
640                 #          Name: BCM4501 DVB-S2 NIM (internal)
641                 # NIM Socket 1:
642                 #          Type: DVB-S
643                 #          Name: BCM4501 DVB-S2 NIM (internal)
644                 # NIM Socket 2:
645                 #          Type: DVB-T
646                 #          Name: Philips TU1216
647                 # NIM Socket 3:
648                 #          Type: DVB-S
649                 #          Name: Alps BSBE1 702A
650                 
651                 #
652                 # Type will be either "DVB-S", "DVB-S2", "DVB-T", "DVB-C" or None.
653
654                 # nim_slots is an array which has exactly one entry for each slot, even for empty ones.
655                 self.nim_slots = [ ]
656
657                 nimfile = tryOpen("/proc/bus/nim_sockets")
658
659                 if nimfile is None:
660                         return
661
662                 current_slot = None
663
664                 entries = {}
665                 for line in nimfile.readlines():
666                         if line == "":
667                                 break
668                         if line.strip().startswith("NIM Socket"):
669                                 parts = line.strip().split(" ")
670                                 current_slot = int(parts[2][:-1])
671                                 entries[current_slot] = {}
672                         elif line.strip().startswith("Type:"):
673                                 entries[current_slot]["type"] = str(line.strip()[6:])
674                         elif line.strip().startswith("Name:"):
675                                 entries[current_slot]["name"] = str(line.strip()[6:])
676                         elif line.strip().startswith("Has_Outputs:"):
677                                 input = str(line.strip()[len("Has_Outputs:") + 1:])
678                                 entries[current_slot]["has_outputs"] = (input == "yes")
679                         elif line.strip().startswith("Internally_Connectable:"):
680                                 input = int(line.strip()[len("Internally_Connectable:") + 1:])
681                                 entries[current_slot]["internally_connectable"] = input
682                         elif  line.strip().startswith("Mode"):
683                                 # "Mode 0: DVB-T" -> ["Mode 0", " DVB-T"]
684                                 split = line.strip().split(":")
685                                 # "Mode 0" -> ["Mode, "0"]
686                                 split2 = split[0].split(" ")
687                                 modes = entries[current_slot].get("multi_type", {})
688                                 modes[split2[1]] = split[1].strip()
689                                 entries[current_slot]["multi_type"] = modes
690                         elif line.strip().startswith("I2C_Device:"):
691                                 input = int(line.strip()[len("I2C_Device:") + 1:])
692                                 entries[current_slot]["i2c"] = input
693                         elif line.strip().startswith("empty"):
694                                 entries[current_slot]["type"] = None
695                                 entries[current_slot]["name"] = _("N/A")
696                 nimfile.close()
697                 
698                 for id, entry in entries.items():
699                         if not (entry.has_key("name") and entry.has_key("type")):
700                                 entry["name"] =  _("N/A")
701                                 entry["type"] = None
702                         if not (entry.has_key("i2c")):
703                                 entry["i2c"] = None
704                         if not (entry.has_key("has_outputs")):
705                                 entry["has_outputs"] = True
706                         if not (entry.has_key("internally_connectable")):
707                                 entry["internally_connectable"] = None
708                         if not (entry.has_key("multi_type")):
709                                 entry["multi_type"] = {}
710                         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"]))
711
712         def hasNimType(self, chktype):
713                 for slot in self.nim_slots:
714                         if slot.isCompatible(chktype):
715                                 return True
716                         for type in slot.getMultiTypeList().values():
717                                 if chktype == type:
718                                         return True
719                 return False
720         
721         def getNimType(self, slotid):
722                 return self.nim_slots[slotid].type
723         
724         def getNimDescription(self, slotid):
725                 return self.nim_slots[slotid].friendly_full_description
726         
727         def getNimName(self, slotid):
728                 return self.nim_slots[slotid].description
729
730         def getNimListOfType(self, type, exception = -1):
731                 # returns a list of indexes for NIMs compatible to the given type, except for 'exception'
732                 list = []
733                 for x in self.nim_slots:
734                         if x.isCompatible(type) and x.slot != exception:
735                                 list.append(x.slot)
736                 return list
737
738         def __init__(self):
739                 self.satList = [ ]
740                 self.cablesList = []
741                 self.terrestrialsList = []
742                 self.enumerateNIMs()
743                 self.readTransponders()
744                 InitNimManager(self)    #init config stuff
745
746         # get a list with the friendly full description
747         def nimList(self):
748                 list = [ ]
749                 for slot in self.nim_slots:
750                         list.append(slot.friendly_full_description)
751                 return list
752         
753         def getSlotCount(self):
754                 return len(self.nim_slots)
755         
756         def hasOutputs(self, slotid):
757                 return self.nim_slots[slotid].hasOutputs()
758         
759         def canConnectTo(self, slotid):
760                 slots = []
761                 if self.nim_slots[slotid].internallyConnectableTo() is not None:
762                         slots.append(self.nim_slots[slotid].internallyConnectableTo())
763                 for type in self.nim_slots[slotid].connectableTo(): 
764                         for slot in self.getNimListOfType(type, exception = slotid):
765                                 if self.hasOutputs(slot):
766                                         slots.append(slot)
767                 # remove nims, that have a conntectedTo reference on
768                 for testnim in slots[:]:
769                         for nim in self.getNimListOfType("DVB-S", slotid):
770                                 nimConfig = self.getNimConfig(nim)
771                                 if nimConfig.content.items.has_key("configMode") and nimConfig.configMode.value == "loopthrough" and int(nimConfig.connectedTo.value) == testnim:
772                                         slots.remove(testnim)
773                                         break 
774                 slots.sort()
775                 
776                 return slots
777         
778         def canEqualTo(self, slotid):
779                 type = self.getNimType(slotid)
780                 if type == "DVB-S2":
781                         type = "DVB-S"
782                 nimList = self.getNimListOfType(type, slotid)
783                 for nim in nimList[:]:
784                         mode = self.getNimConfig(nim)
785                         if mode.configMode.value == "loopthrough" or mode.configMode.value == "satposdepends":
786                                 nimList.remove(nim)
787                 return nimList
788
789         def canDependOn(self, slotid):
790                 type = self.getNimType(slotid)
791                 if type == "DVB-S2":
792                         type = "DVB-S"
793                 nimList = self.getNimListOfType(type, slotid)
794                 positionerList = []
795                 for nim in nimList[:]:
796                         mode = self.getNimConfig(nim)
797                         nimHaveRotor = mode.configMode.value == "simple" and mode.diseqcMode.value == "positioner"
798                         if not nimHaveRotor and mode.configMode.value == "advanced":
799                                 for x in range(3601, 3605):
800                                         lnb = int(mode.advanced.sat[x].lnb.value)
801                                         if lnb != 0:
802                                                 nimHaveRotor = True
803                                                 break
804                                 if not nimHaveRotor:
805                                         for sat in mode.advanced.sat.values():
806                                                 lnb_num = int(sat.lnb.value)
807                                                 diseqcmode = lnb_num and mode.advanced.lnb[lnb_num].diseqcMode.value or ""
808                                                 if diseqcmode == "1_2":
809                                                         nimHaveRotor = True
810                                                         break
811                         if nimHaveRotor:
812                                 alreadyConnected = False
813                                 for testnim in nimList:
814                                         testmode = self.getNimConfig(testnim)
815                                         if testmode.configMode.value == "satposdepends" and int(testmode.connectedTo.value) == int(nim):
816                                                 alreadyConnected = True
817                                                 break
818                                 if not alreadyConnected:
819                                         positionerList.append(nim)
820                 return positionerList
821         
822         def getNimConfig(self, slotid):
823                 return config.Nims[slotid]
824         
825         def getSatName(self, pos):
826                 for sat in self.satList:
827                         if sat[0] == pos:
828                                 return sat[1]
829                 return _("N/A")
830
831         def getSatList(self):
832                 return self.satList
833         
834         # returns True if something is configured to be connected to this nim
835         # if slotid == -1, returns if something is connected to ANY nim
836         def somethingConnected(self, slotid = -1):
837                 if (slotid == -1):
838                         connected = False
839                         for id in range(self.getSlotCount()):
840                                 if self.somethingConnected(id):
841                                         connected = True
842                         return connected
843                 else:
844                         nim = config.Nims[slotid]
845                         configMode = nim.configMode.value
846                 
847                         if self.nim_slots[slotid].isCompatible("DVB-S") or self.nim_slots[slotid].isCompatible("DVB-T") or self.nim_slots[slotid].isCompatible("DVB-C"):
848                                 return not (configMode == "nothing")            
849
850         def getSatListForNim(self, slotid):
851                 list = []
852                 if self.nim_slots[slotid].isCompatible("DVB-S"):
853                         nim = config.Nims[slotid]
854                         #print "slotid:", slotid
855
856                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.index]
857                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
858                         configMode = nim.configMode.value
859
860                         if configMode == "equal":
861                                 slotid = int(nim.connectedTo.value)
862                                 nim = config.Nims[slotid]
863                                 configMode = nim.configMode.value
864                         elif configMode == "loopthrough":
865                                 slotid = self.sec.getRoot(slotid, int(nim.connectedTo.value))
866                                 nim = config.Nims[slotid]
867                                 configMode = nim.configMode.value
868
869                         if configMode == "simple":
870                                 dm = nim.diseqcMode.value
871                                 if dm in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
872                                         if nim.diseqcA.orbital_position != 3601:
873                                                 list.append(self.satList[nim.diseqcA.index-1])
874                                 if dm in ("toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
875                                         if nim.diseqcB.orbital_position != 3601:
876                                                 list.append(self.satList[nim.diseqcB.index-1])
877                                 if dm == "diseqc_a_b_c_d":
878                                         if nim.diseqcC.orbital_position != 3601:
879                                                 list.append(self.satList[nim.diseqcC.index-1])
880                                         if nim.diseqcD.orbital_position != 3601:
881                                                 list.append(self.satList[nim.diseqcD.index-1])
882                                 if dm == "positioner":
883                                         for x in self.satList:
884                                                 list.append(x)
885                         elif configMode == "advanced":
886                                 for x in range(3601, 3605):
887                                         if int(nim.advanced.sat[x].lnb.value) != 0:
888                                                 for x in self.satList:
889                                                         list.append(x)
890                                 if not list:
891                                         for x in self.satList:
892                                                 if int(nim.advanced.sat[x[0]].lnb.value) != 0:
893                                                         list.append(x)
894                 return list
895
896         def getRotorSatListForNim(self, slotid):
897                 list = []
898                 if self.nim_slots[slotid].isCompatible("DVB-S"):
899                         #print "slotid:", slotid
900                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
901                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
902                         configMode = config.Nims[slotid].configMode.value
903                         if configMode == "simple":
904                                 if config.Nims[slotid].diseqcMode.value == "positioner":
905                                         for x in self.satList:
906                                                 list.append(x)
907                         elif configMode == "advanced":
908                                 nim = config.Nims[slotid]
909                                 for x in range(3601, 3605):
910                                         if int(nim.advanced.sat[x].lnb.value) != 0:
911                                                 for x in self.satList:
912                                                         list.append(x)
913                                 if not list:
914                                         for x in self.satList:
915                                                 lnbnum = int(nim.advanced.sat[x[0]].lnb.value)
916                                                 if lnbnum != 0:
917                                                         lnb = nim.advanced.lnb[lnbnum]
918                                                         if lnb.diseqcMode.value == "1_2":
919                                                                 list.append(x)
920                 return list
921
922 def InitSecParams():
923         config.sec = ConfigSubsection()
924
925         x = ConfigInteger(default=25, limits = (0, 9999))
926         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC, configElement.value))
927         config.sec.delay_after_continuous_tone_disable_before_diseqc = x
928
929         x = ConfigInteger(default=10, limits = (0, 9999))
930         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_FINAL_CONT_TONE_CHANGE, configElement.value))
931         config.sec.delay_after_final_continuous_tone_change = x
932
933         x = ConfigInteger(default=10, limits = (0, 9999))
934         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_FINAL_VOLTAGE_CHANGE, configElement.value))
935         config.sec.delay_after_final_voltage_change = x
936
937         x = ConfigInteger(default=120, limits = (0, 9999))
938         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BETWEEN_DISEQC_REPEATS, configElement.value))
939         config.sec.delay_between_diseqc_repeats = x
940
941         x = ConfigInteger(default=50, limits = (0, 9999))
942         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_LAST_DISEQC_CMD, configElement.value))
943         config.sec.delay_after_last_diseqc_command = x
944
945         x = ConfigInteger(default=50, limits = (0, 9999))
946         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_TONEBURST, configElement.value))
947         config.sec.delay_after_toneburst = x
948
949         x = ConfigInteger(default=20, limits = (0, 9999))
950         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS, configElement.value))
951         config.sec.delay_after_change_voltage_before_switch_command = x
952
953         x = ConfigInteger(default=200, limits = (0, 9999))
954         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS, configElement.value))
955         config.sec.delay_after_enable_voltage_before_switch_command = x
956
957         x = ConfigInteger(default=700, limits = (0, 9999))
958         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD, configElement.value))
959         config.sec.delay_between_switch_and_motor_command = x
960
961         x = ConfigInteger(default=500, limits = (0, 9999))
962         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER, configElement.value))
963         config.sec.delay_after_voltage_change_before_measure_idle_inputpower = x
964
965         x = ConfigInteger(default=900, limits = (0, 9999))
966         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD, configElement.value))
967         config.sec.delay_after_enable_voltage_before_motor_command = x
968
969         x = ConfigInteger(default=500, limits = (0, 9999))
970         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_MOTOR_STOP_CMD, configElement.value))
971         config.sec.delay_after_motor_stop_command = x
972
973         x = ConfigInteger(default=500, limits = (0, 9999))
974         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD, configElement.value))
975         config.sec.delay_after_voltage_change_before_motor_command = x
976
977         x = ConfigInteger(default=70, limits = (0, 9999))
978         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BEFORE_SEQUENCE_REPEAT, configElement.value))
979         config.sec.delay_before_sequence_repeat = x
980
981         x = ConfigInteger(default=360, limits = (0, 9999))
982         x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_RUNNING_TIMEOUT, configElement.value))
983         config.sec.motor_running_timeout = x
984
985         x = ConfigInteger(default=1, limits = (0, 5))
986         x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_COMMAND_RETRIES, configElement.value))
987         config.sec.motor_command_retries = x
988
989         x = ConfigInteger(default=50, limits = (0, 9999))
990         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_DISEQC_RESET_CMD, configElement.value))
991         config.sec.delay_after_diseqc_reset_cmd = x
992
993         x = ConfigInteger(default=150, limits = (0, 9999))
994         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD, configElement.value))
995         config.sec.delay_after_diseqc_peripherial_poweron_cmd = x
996
997 # TODO add support for satpos depending nims to advanced nim configuration
998 # so a second/third/fourth cable from a motorized lnb can used behind a
999 # diseqc 1.0 / diseqc 1.1 / toneburst switch
1000 # the C(++) part should can handle this
1001 # the configElement should be only visible when diseqc 1.2 is disabled
1002
1003 def InitNimManager(nimmgr):
1004         hw = HardwareInfo()
1005         addNimConfig = False
1006         try:
1007                 config.Nims
1008         except:
1009                 addNimConfig = True
1010
1011         if addNimConfig:
1012                 InitSecParams()
1013                 config.Nims = ConfigSubList()
1014                 for x in range(len(nimmgr.nim_slots)):
1015                         config.Nims.append(ConfigSubsection())
1016
1017         lnb_choices = {
1018                 "universal_lnb": _("Universal LNB"),
1019                 "unicable": _("Unicable"),
1020                 "c_band": _("C-Band"),
1021                 "user_defined": _("User defined")}
1022
1023         lnb_choices_default = "universal_lnb"
1024
1025         unicablelnbproducts = {}
1026         unicablematrixproducts = {}
1027         doc = xml.etree.cElementTree.parse("/usr/share/enigma2/unicable.xml")
1028         root = doc.getroot()
1029
1030         entry = root.find("lnb")
1031         for manufacturer in entry.getchildren():
1032                 m={}
1033                 for product in manufacturer.getchildren():
1034                         scr=[]
1035                         lscr=("scr1","scr2","scr3","scr4","scr5","scr6","scr7","scr8")
1036                         for i in range(len(lscr)):
1037                                 scr.append(product.get(lscr[i],"0"))
1038                         for i in range(len(lscr)):
1039                                 if scr[len(lscr)-i-1] == "0":
1040                                         scr.pop()
1041                                 else:
1042                                         break;
1043                         lof=[]
1044                         lof.append(int(product.get("positions",1)))
1045                         lof.append(int(product.get("lofl",9750)))
1046                         lof.append(int(product.get("lofh",10600)))
1047                         lof.append(int(product.get("threshold",11700)))
1048                         scr.append(tuple(lof))
1049                         m.update({product.get("name"):tuple(scr)})
1050                 unicablelnbproducts.update({manufacturer.get("name"):m})
1051
1052         entry = root.find("matrix")
1053         for manufacturer in entry.getchildren():
1054                 m={}
1055                 for product in manufacturer.getchildren():
1056                         scr=[]
1057                         lscr=("scr1","scr2","scr3","scr4","scr5","scr6","scr7","scr8")
1058                         for i in range(len(lscr)):
1059                                 scr.append(product.get(lscr[i],"0"))
1060                         for i in range(len(lscr)):
1061                                 if scr[len(lscr)-i-1] == "0":
1062                                         scr.pop()
1063                                 else:
1064                                         break;
1065                         lof=[]
1066                         lof.append(int(product.get("positions",1)))
1067                         lof.append(int(product.get("lofl",9750)))
1068                         lof.append(int(product.get("lofh",10600)))
1069                         lof.append(int(product.get("threshold",11700)))
1070                         scr.append(tuple(lof))
1071                         m.update({product.get("name"):tuple(scr)})
1072                 unicablematrixproducts.update({manufacturer.get("name"):m})
1073
1074         UnicableLnbManufacturers = unicablelnbproducts.keys()
1075         UnicableLnbManufacturers.sort()
1076         UnicableMatrixManufacturers = unicablematrixproducts.keys()
1077         UnicableMatrixManufacturers.sort()
1078
1079         unicable_choices = {
1080                 "unicable_lnb": _("Unicable LNB"),
1081                 "unicable_matrix": _("Unicable Martix"),
1082                 "unicable_user": "Unicable "+_("User defined")}
1083         unicable_choices_default = "unicable_lnb"
1084
1085         advanced_lnb_satcruser_choices = [ ("1", "SatCR 1"), ("2", "SatCR 2"), ("3", "SatCR 3"), ("4", "SatCR 4"),
1086                                         ("5", "SatCR 5"), ("6", "SatCR 6"), ("7", "SatCR 7"), ("8", "SatCR 8")]
1087
1088         prio_list = [ ("-1", _("Auto")) ]
1089         prio_list += [(str(prio), str(prio)) for prio in range(65)+range(14000,14065)+range(19000,19065)]
1090
1091         advanced_lnb_csw_choices = [("none", _("None")), ("AA", _("AA")), ("AB", _("AB")), ("BA", _("BA")), ("BB", _("BB"))]
1092         advanced_lnb_csw_choices += [(str(0xF0|y), "Input " + str(y+1)) for y in range(0, 16)]
1093
1094         advanced_lnb_ucsw_choices = [("0", _("None"))] + [(str(y), "Input " + str(y)) for y in range(1, 17)]
1095
1096         diseqc_mode_choices = [
1097                 ("single", _("Single")), ("toneburst_a_b", _("Toneburst A/B")),
1098                 ("diseqc_a_b", _("DiSEqC A/B")), ("diseqc_a_b_c_d", _("DiSEqC A/B/C/D")),
1099                 ("positioner", _("Positioner"))]
1100
1101         positioner_mode_choices = [("usals", _("USALS")), ("manual", _("manual"))]
1102
1103         diseqc_satlist_choices = [(3601, _('nothing connected'), 1)] + nimmgr.satList
1104         
1105         longitude_orientation_choices = [("east", _("East")), ("west", _("West"))]
1106         latitude_orientation_choices = [("north", _("North")), ("south", _("South"))]
1107         turning_speed_choices = [("fast", _("Fast")), ("slow", _("Slow")), ("fast epoch", _("Fast epoch"))]
1108         
1109         advanced_satlist_choices = nimmgr.satList + [
1110                 (3601, _('All Satellites')+' 1', 1), (3602, _('All Satellites')+' 2', 1),
1111                 (3603, _('All Satellites')+' 3', 1), (3604, _('All Satellites')+' 4', 1)]
1112         advanced_lnb_choices = [("0", "not available")] + [(str(y), "LNB " + str(y)) for y in range(1, 33)]
1113         advanced_voltage_choices = [("polarization", _("Polarization")), ("13V", _("13 V")), ("18V", _("18 V"))]
1114         advanced_tonemode_choices = [("band", _("Band")), ("on", _("On")), ("off", _("Off"))]
1115         advanced_lnb_toneburst_choices = [("none", _("None")), ("A", _("A")), ("B", _("B"))]
1116         advanced_lnb_allsat_diseqcmode_choices = [("1_2", _("1.2"))]
1117         advanced_lnb_diseqcmode_choices = [("none", _("None")), ("1_0", _("1.0")), ("1_1", _("1.1")), ("1_2", _("1.2"))]
1118         advanced_lnb_commandOrder1_0_choices = [("ct", "committed, toneburst"), ("tc", "toneburst, committed")]
1119         advanced_lnb_commandOrder_choices = [
1120                 ("ct", "committed, toneburst"), ("tc", "toneburst, committed"),
1121                 ("cut", "committed, uncommitted, toneburst"), ("tcu", "toneburst, committed, uncommitted"),
1122                 ("uct", "uncommitted, committed, toneburst"), ("tuc", "toneburst, uncommitted, commmitted")]
1123         advanced_lnb_diseqc_repeat_choices = [("none", _("None")), ("one", _("One")), ("two", _("Two")), ("three", _("Three"))]
1124         advanced_lnb_fast_turning_btime = mktime(datetime(1970, 1, 1, 7, 0).timetuple());
1125         advanced_lnb_fast_turning_etime = mktime(datetime(1970, 1, 1, 19, 0).timetuple());
1126
1127         def configLOFChanged(configElement):
1128                 if configElement.value == "unicable":
1129                         x = configElement.slot_id
1130                         lnb = configElement.lnb_id
1131                         nim = config.Nims[x]
1132                         lnbs = nim.advanced.lnb
1133                         section = lnbs[lnb]
1134                         if isinstance(section.unicable, ConfigNothing):
1135                                 if lnb == 1:
1136                                         section.unicable = ConfigSelection(unicable_choices, unicable_choices_default)
1137                                 elif lnb == 2:
1138                                         section.unicable = ConfigSelection(choices = {"unicable_matrix": _("Unicable Martix"),"unicable_user": "Unicable "+_("User defined")}, default = "unicable_matrix")
1139                                 else:
1140                                         section.unicable = ConfigSelection(choices = {"unicable_user": _("User defined")}, default = "unicable_user")
1141
1142                                 def fillUnicableConf(sectionDict, unicableproducts, vco_null_check):
1143                                         for y in unicableproducts:
1144                                                 products = unicableproducts[y].keys()
1145                                                 products.sort()
1146                                                 tmp = ConfigSubsection()
1147                                                 tmp.product = ConfigSelection(choices = products, default = products[0])
1148                                                 tmp.scr = ConfigSubDict()
1149                                                 tmp.vco = ConfigSubDict()
1150                                                 tmp.lofl = ConfigSubDict()
1151                                                 tmp.lofh = ConfigSubDict()
1152                                                 tmp.loft = ConfigSubDict()
1153                                                 tmp.positions = ConfigSubDict()
1154                                                 for z in products:
1155                                                         scrlist = []
1156                                                         vcolist = unicableproducts[y][z]
1157                                                         tmp.vco[z] = ConfigSubList()
1158                                                         for cnt in range(1,1+len(vcolist)-1):
1159                                                                 vcofreq = int(vcolist[cnt-1])
1160                                                                 if vcofreq == 0 and vco_null_check:
1161                                                                         scrlist.append(("%d" %cnt,"SCR %d " %cnt +_("not used")))
1162                                                                 else:
1163                                                                         scrlist.append(("%d" %cnt,"SCR %d" %cnt))
1164                                                                 tmp.vco[z].append(ConfigInteger(default=vcofreq, limits = (vcofreq, vcofreq)))
1165                                                                 tmp.scr[z] = ConfigSelection(choices = scrlist, default = scrlist[0][0])
1166
1167                                                                 positions = int(vcolist[len(vcolist)-1][0])
1168                                                                 tmp.positions[z] = ConfigSubList()
1169                                                                 tmp.positions[z].append(ConfigInteger(default=positions, limits = (positions, positions)))
1170
1171                                                                 lofl = vcolist[len(vcolist)-1][1]
1172                                                                 tmp.lofl[z] = ConfigSubList()
1173                                                                 tmp.lofl[z].append(ConfigInteger(default=lofl, limits = (lofl, lofl)))
1174
1175                                                                 lofh = int(vcolist[len(vcolist)-1][2])
1176                                                                 tmp.lofh[z] = ConfigSubList()
1177                                                                 tmp.lofh[z].append(ConfigInteger(default=lofh, limits = (lofh, lofh)))
1178
1179                                                                 loft = int(vcolist[len(vcolist)-1][3])
1180                                                                 tmp.loft[z] = ConfigSubList()
1181                                                                 tmp.loft[z].append(ConfigInteger(default=loft, limits = (loft, loft)))
1182                                                 sectionDict[y] = tmp
1183
1184                                 if lnb < 3:
1185                                         print "MATRIX"
1186                                         section.unicableMatrix = ConfigSubDict()
1187                                         section.unicableMatrixManufacturer = ConfigSelection(UnicableMatrixManufacturers, UnicableMatrixManufacturers[0])
1188                                         fillUnicableConf(section.unicableMatrix, unicablematrixproducts, True)
1189
1190                                 if lnb < 2:
1191                                         print "LNB"
1192                                         section.unicableLnb = ConfigSubDict()
1193                                         section.unicableLnbManufacturer = ConfigSelection(UnicableLnbManufacturers, UnicableLnbManufacturers[0])
1194                                         fillUnicableConf(section.unicableLnb, unicablelnbproducts, False)
1195
1196 #TODO satpositions for satcruser
1197                                 section.satcruser = ConfigSelection(advanced_lnb_satcruser_choices, default="1")
1198                                 tmp = ConfigSubList()
1199                                 tmp.append(ConfigInteger(default=1284, limits = (950, 2150)))
1200                                 tmp.append(ConfigInteger(default=1400, limits = (950, 2150)))
1201                                 tmp.append(ConfigInteger(default=1516, limits = (950, 2150)))
1202                                 tmp.append(ConfigInteger(default=1632, limits = (950, 2150)))
1203                                 tmp.append(ConfigInteger(default=1748, limits = (950, 2150)))
1204                                 tmp.append(ConfigInteger(default=1864, limits = (950, 2150)))
1205                                 tmp.append(ConfigInteger(default=1980, limits = (950, 2150)))
1206                                 tmp.append(ConfigInteger(default=2096, limits = (950, 2150)))
1207                                 section.satcrvcouser = tmp 
1208
1209                                 nim.advanced.unicableconnected = ConfigYesNo(default=False)
1210                                 nim.advanced.unicableconnectedTo = ConfigSelection([(str(id), nimmgr.getNimDescription(id)) for id in nimmgr.getNimListOfType("DVB-S") if id != x])
1211         
1212         def configDiSEqCModeChanged(configElement):
1213                 section = configElement.section
1214                 if configElement.value == "1_2" and isinstance(section.longitude, ConfigNothing):
1215                         section.longitude = ConfigFloat(default = [5,100], limits = [(0,359),(0,999)])
1216                         section.longitudeOrientation = ConfigSelection(longitude_orientation_choices, "east")
1217                         section.latitude = ConfigFloat(default = [50,767], limits = [(0,359),(0,999)])
1218                         section.latitudeOrientation = ConfigSelection(latitude_orientation_choices, "north")
1219                         section.powerMeasurement = ConfigYesNo(default=True)
1220                         section.powerThreshold = ConfigInteger(default=hw.get_device_name() == "dm7025" and 50 or 15, limits=(0, 100))
1221                         section.turningSpeed = ConfigSelection(turning_speed_choices, "fast")
1222                         section.fastTurningBegin = ConfigDateTime(default=advanced_lnb_fast_turning_btime, formatstring = _("%H:%M"), increment = 600)
1223                         section.fastTurningEnd = ConfigDateTime(default=advanced_lnb_fast_turning_etime, formatstring = _("%H:%M"), increment = 600)
1224
1225         def configLNBChanged(configElement):
1226                 x = configElement.slot_id
1227                 nim = config.Nims[x]
1228                 if isinstance(configElement.value, tuple):
1229                         lnb = int(configElement.value[0])
1230                 else:
1231                         lnb = int(configElement.value)
1232                 lnbs = nim.advanced.lnb
1233                 if lnb and lnb not in lnbs:
1234                         section = lnbs[lnb] = ConfigSubsection()
1235                         section.lofl = ConfigInteger(default=9750, limits = (0, 99999))
1236                         section.lofh = ConfigInteger(default=10600, limits = (0, 99999))
1237                         section.threshold = ConfigInteger(default=11700, limits = (0, 99999))
1238 #                       section.output_12v = ConfigSelection(choices = [("0V", _("0 V")), ("12V", _("12 V"))], default="0V")
1239                         section.increased_voltage = ConfigYesNo(False)
1240                         section.toneburst = ConfigSelection(advanced_lnb_toneburst_choices, "none")
1241                         section.longitude = ConfigNothing()
1242                         if lnb > 32:
1243                                 tmp = ConfigSelection(advanced_lnb_allsat_diseqcmode_choices, "1_2")
1244                                 tmp.section = section
1245                                 configDiSEqCModeChanged(tmp)
1246                         else:
1247                                 tmp = ConfigSelection(advanced_lnb_diseqcmode_choices, "none")
1248                                 tmp.section = section
1249                                 tmp.addNotifier(configDiSEqCModeChanged)
1250                         section.diseqcMode = tmp
1251                         section.commitedDiseqcCommand = ConfigSelection(advanced_lnb_csw_choices)
1252                         section.fastDiseqc = ConfigYesNo(False)
1253                         section.sequenceRepeat = ConfigYesNo(False)
1254                         section.commandOrder1_0 = ConfigSelection(advanced_lnb_commandOrder1_0_choices, "ct")
1255                         section.commandOrder = ConfigSelection(advanced_lnb_commandOrder_choices, "ct")
1256                         section.uncommittedDiseqcCommand = ConfigSelection(advanced_lnb_ucsw_choices)
1257                         section.diseqcRepeats = ConfigSelection(advanced_lnb_diseqc_repeat_choices, "none")
1258                         section.prio = ConfigSelection(prio_list, "-1")
1259                         section.unicable = ConfigNothing()
1260                         tmp = ConfigSelection(lnb_choices, lnb_choices_default)
1261                         tmp.slot_id = x
1262                         tmp.lnb_id = lnb
1263                         tmp.addNotifier(configLOFChanged, initial_call = False)
1264                         section.lof = tmp
1265
1266         def configModeChanged(configMode):
1267                 slot_id = configMode.slot_id
1268                 nim = config.Nims[slot_id]
1269                 if configMode.value == "advanced" and isinstance(nim.advanced, ConfigNothing):
1270                         # advanced config:
1271                         nim.advanced = ConfigSubsection()
1272                         nim.advanced.sat = ConfigSubDict()
1273                         nim.advanced.sats = getConfigSatlist(192, advanced_satlist_choices)
1274                         nim.advanced.lnb = ConfigSubDict()
1275                         nim.advanced.lnb[0] = ConfigNothing()
1276                         for x in nimmgr.satList:
1277                                 tmp = ConfigSubsection()
1278                                 tmp.voltage = ConfigSelection(advanced_voltage_choices, "polarization")
1279                                 tmp.tonemode = ConfigSelection(advanced_tonemode_choices, "band")
1280                                 tmp.usals = ConfigYesNo(True)
1281                                 tmp.rotorposition = ConfigInteger(default=1, limits=(1, 255))
1282                                 lnb = ConfigSelection(advanced_lnb_choices, "0")
1283                                 lnb.slot_id = slot_id
1284                                 lnb.addNotifier(configLNBChanged, initial_call = False)
1285                                 tmp.lnb = lnb
1286                                 nim.advanced.sat[x[0]] = tmp
1287                         for x in range(3601, 3605):
1288                                 tmp = ConfigSubsection()
1289                                 tmp.voltage = ConfigSelection(advanced_voltage_choices, "polarization")
1290                                 tmp.tonemode = ConfigSelection(advanced_tonemode_choices, "band")
1291                                 tmp.usals = ConfigYesNo(default=True)
1292                                 tmp.rotorposition = ConfigInteger(default=1, limits=(1, 255))
1293                                 lnbnum = 33+x-3601
1294                                 lnb = ConfigSelection([("0", "not available"), (str(lnbnum), "LNB %d"%(lnbnum))], "0")
1295                                 lnb.slot_id = slot_id
1296                                 lnb.addNotifier(configLNBChanged, initial_call = False)
1297                                 tmp.lnb = lnb
1298                                 nim.advanced.sat[x] = tmp
1299
1300         def toneAmplitudeChanged(configElement):
1301                 fe_id = configElement.fe_id
1302                 slot_id = configElement.slot_id
1303                 if nimmgr.nim_slots[slot_id].description == 'Alps BSBE2':
1304                         open("/proc/stb/frontend/%d/tone_amplitude" %(fe_id), "w").write(configElement.value)
1305                         
1306         def tunerTypeChanged(nimmgr, configElement):
1307                 fe_id = configElement.fe_id
1308                 print "tunerTypeChanged feid %d to mode %s" % (fe_id, configElement.value)
1309                 try:
1310                         oldvalue = open("/sys/module/dvb_core/parameters/dvb_shutdown_timeout", "r").readline()
1311                         open("/sys/module/dvb_core/parameters/dvb_shutdown_timeout", "w").write("0")
1312                 except:
1313                         print "[info] no /sys/module/dvb_core/parameters/dvb_shutdown_timeout available"
1314                 frontend = eDVBResourceManager.getInstance().allocateRawChannel(fe_id).getFrontend()
1315                 frontend.closeFrontend()
1316                 open("/proc/stb/frontend/%d/mode" % (fe_id), "w").write(configElement.value)
1317                 frontend.reopenFrontend()
1318                 try:
1319                         open("/sys/module/dvb_core/parameters/dvb_shutdown_timeout", "w").write(oldvalue)
1320                 except:
1321                         print "[info] no /sys/module/dvb_core/parameters/dvb_shutdown_timeout available"
1322                 nimmgr.enumerateNIMs()
1323         
1324         empty_slots = 0
1325         for slot in nimmgr.nim_slots:
1326                 x = slot.slot
1327                 nim = config.Nims[x]
1328                 addMultiType = False
1329                 try:
1330                         nim.multiType
1331                 except:
1332                         addMultiType = True
1333                 if slot.isMultiType() and addMultiType:
1334                         typeList = []
1335                         for id in slot.getMultiTypeList().keys():
1336                                 type = slot.getMultiTypeList()[id]
1337                                 typeList.append((id, type))
1338                         nim.multiType = ConfigSelection(typeList, "0")
1339                         
1340                         nim.multiType.fe_id = x - empty_slots
1341                         nim.multiType.addNotifier(boundFunction(tunerTypeChanged, nimmgr))
1342                 
1343         empty_slots = 0
1344         for slot in nimmgr.nim_slots:
1345                 x = slot.slot
1346                 nim = config.Nims[x]
1347
1348                 if slot.isCompatible("DVB-S"):
1349                         nim.toneAmplitude = ConfigSelection([("9", "600mV"), ("8", "700mV"), ("7", "800mV"), ("6", "900mV"), ("5", "1100mV")], "7")
1350                         nim.toneAmplitude.fe_id = x - empty_slots
1351                         nim.toneAmplitude.slot_id = x
1352                         nim.toneAmplitude.addNotifier(toneAmplitudeChanged)
1353                         nim.diseqc13V = ConfigYesNo(False)
1354                         nim.diseqcMode = ConfigSelection(diseqc_mode_choices, "diseqc_a_b")
1355                         nim.connectedTo = ConfigSelection([(str(id), nimmgr.getNimDescription(id)) for id in nimmgr.getNimListOfType("DVB-S") if id != x])
1356                         nim.simpleSingleSendDiSEqC = ConfigYesNo(False)
1357                         nim.simpleDiSEqCSetVoltageTone = ConfigYesNo(True)
1358                         nim.simpleDiSEqCOnlyOnSatChange = ConfigYesNo(False)
1359                         nim.diseqcA = getConfigSatlist(192, diseqc_satlist_choices)
1360                         nim.diseqcB = getConfigSatlist(130, diseqc_satlist_choices)
1361                         nim.diseqcC = ConfigSatlist(list = diseqc_satlist_choices)
1362                         nim.diseqcD = ConfigSatlist(list = diseqc_satlist_choices)
1363                         nim.positionerMode = ConfigSelection(positioner_mode_choices, "usals")
1364                         nim.longitude = ConfigFloat(default=[5,100], limits=[(0,359),(0,999)])
1365                         nim.longitudeOrientation = ConfigSelection(longitude_orientation_choices, "east")
1366                         nim.latitude = ConfigFloat(default=[50,767], limits=[(0,359),(0,999)])
1367                         nim.latitudeOrientation = ConfigSelection(latitude_orientation_choices, "north")
1368                         nim.powerMeasurement = ConfigYesNo(True)
1369                         nim.powerThreshold = ConfigInteger(default=hw.get_device_name() == "dm8000" and 15 or 50, limits=(0, 100))
1370                         nim.turningSpeed = ConfigSelection(turning_speed_choices, "fast")
1371                         btime = datetime(1970, 1, 1, 7, 0);
1372                         nim.fastTurningBegin = ConfigDateTime(default = mktime(btime.timetuple()), formatstring = _("%H:%M"), increment = 900)
1373                         etime = datetime(1970, 1, 1, 19, 0);
1374                         nim.fastTurningEnd = ConfigDateTime(default = mktime(etime.timetuple()), formatstring = _("%H:%M"), increment = 900)
1375                         config_mode_choices = [ ("nothing", _("nothing connected")),
1376                                 ("simple", _("simple")), ("advanced", _("advanced"))]
1377                         if len(nimmgr.getNimListOfType(slot.type, exception = x)) > 0:
1378                                 config_mode_choices.append(("equal", _("equal to")))
1379                                 config_mode_choices.append(("satposdepends", _("second cable of motorized LNB")))
1380                         if len(nimmgr.canConnectTo(x)) > 0:
1381                                 config_mode_choices.append(("loopthrough", _("loopthrough to")))
1382                         nim.advanced = ConfigNothing()
1383                         tmp = ConfigSelection(config_mode_choices, "nothing")
1384                         tmp.slot_id = x
1385                         tmp.addNotifier(configModeChanged, initial_call = False)
1386                         nim.configMode = tmp
1387                 elif slot.isCompatible("DVB-C"):
1388                         nim.configMode = ConfigSelection(
1389                                 choices = {
1390                                         "enabled": _("enabled"),
1391                                         "nothing": _("nothing connected"),
1392                                         },
1393                                 default = "enabled")
1394                         list = [ ]
1395                         n = 0
1396                         for x in nimmgr.cablesList:
1397                                 list.append((str(n), x[0]))
1398                                 n += 1
1399                         nim.cable = ConfigSubsection()
1400                         possible_scan_types = [("bands", _("Frequency bands")), ("steps", _("Frequency steps"))]
1401                         if n:
1402                                 possible_scan_types.append(("provider", _("Provider")))
1403                                 nim.cable.scan_provider = ConfigSelection(default = "0", choices = list)
1404                         nim.cable.scan_type = ConfigSelection(default = "bands", choices = possible_scan_types)
1405                         nim.cable.scan_band_EU_VHF_I = ConfigYesNo(default = True)
1406                         nim.cable.scan_band_EU_MID = ConfigYesNo(default = True)
1407                         nim.cable.scan_band_EU_VHF_III = ConfigYesNo(default = True)
1408                         nim.cable.scan_band_EU_UHF_IV = ConfigYesNo(default = True)
1409                         nim.cable.scan_band_EU_UHF_V = ConfigYesNo(default = True)
1410                         nim.cable.scan_band_EU_SUPER = ConfigYesNo(default = True)
1411                         nim.cable.scan_band_EU_HYPER = ConfigYesNo(default = True)
1412                         nim.cable.scan_band_US_LOW = ConfigYesNo(default = False)
1413                         nim.cable.scan_band_US_MID = ConfigYesNo(default = False)
1414                         nim.cable.scan_band_US_HIGH = ConfigYesNo(default = False)
1415                         nim.cable.scan_band_US_SUPER = ConfigYesNo(default = False)
1416                         nim.cable.scan_band_US_HYPER = ConfigYesNo(default = False)
1417                         nim.cable.scan_frequency_steps = ConfigInteger(default = 1000, limits = (1000, 10000))
1418                         nim.cable.scan_mod_qam16 = ConfigYesNo(default = False)
1419                         nim.cable.scan_mod_qam32 = ConfigYesNo(default = False)
1420                         nim.cable.scan_mod_qam64 = ConfigYesNo(default = True)
1421                         nim.cable.scan_mod_qam128 = ConfigYesNo(default = False)
1422                         nim.cable.scan_mod_qam256 = ConfigYesNo(default = True)
1423                         nim.cable.scan_sr_6900 = ConfigYesNo(default = True)
1424                         nim.cable.scan_sr_6875 = ConfigYesNo(default = True)
1425                         nim.cable.scan_sr_ext1 = ConfigInteger(default = 0, limits = (0, 7230))
1426                         nim.cable.scan_sr_ext2 = ConfigInteger(default = 0, limits = (0, 7230))
1427                 elif slot.isCompatible("DVB-T"):
1428                         nim.configMode = ConfigSelection(
1429                                 choices = {
1430                                         "enabled": _("enabled"),
1431                                         "nothing": _("nothing connected"),
1432                                         },
1433                                 default = "enabled")
1434                         list = []
1435                         n = 0
1436                         for x in nimmgr.terrestrialsList:
1437                                 list.append((str(n), x[0]))
1438                                 n += 1
1439                         nim.terrestrial = ConfigSelection(choices = list)
1440                         nim.terrestrial_5V = ConfigOnOff()
1441                 else:
1442                         empty_slots += 1
1443                         nim.configMode = ConfigSelection(choices = { "nothing": _("disabled") }, default="nothing");
1444                         if slot.type is not None:
1445                                 print "pls add support for this frontend type!", slot.type
1446 #                       assert False
1447
1448         nimmgr.sec = SecConfigure(nimmgr)
1449
1450 nimmanager = NimManager()