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