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