f8dab1230207ea6ad5eccbf5e7cb66ee0665da58
[enigma2.git] / lib / python / Components / NimManager.py
1 from config import config, ConfigSubsection, ConfigSelection, ConfigFloat, \
2         ConfigSatlist, ConfigYesNo, ConfigInteger, ConfigSubList, ConfigNothing, \
3         ConfigSubDict, ConfigOnOff, ConfigDateTime
4
5 from enigma import eDVBSatelliteEquipmentControl as secClass, \
6         eDVBSatelliteLNBParameters as lnbParam, \
7         eDVBSatelliteDiseqcParameters as diseqcParam, \
8         eDVBSatelliteSwitchParameters as switchParam, \
9         eDVBSatelliteRotorParameters as rotorParam, \
10         eDVBResourceManager, eDVBDB
11
12 from time import localtime, mktime
13 from datetime import datetime
14
15 from sets import Set
16
17 def getConfigSatlist(orbpos, satlist):
18         default_orbpos = None
19         for x in satlist:
20                 if x[0] == orbpos:
21                         default_orbpos = orbpos
22                         break
23         return ConfigSatlist(satlist, default_orbpos)
24
25 def tryOpen(filename):
26         try:
27                 procFile = open(filename)
28         except IOError:
29                 return None
30         return procFile
31
32 class SecConfigure:
33         def getConfiguredSats(self):
34                 return self.configuredSatellites
35
36         def addSatellite(self, sec, orbpos):
37                 sec.addSatellite(orbpos)
38                 self.configuredSatellites.add(orbpos)
39
40         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):
41                 if orbpos is None:
42                         return
43                 #simple defaults
44                 sec.addLNB()
45                 tunermask = 1 << slotid
46                 if self.equal.has_key(slotid):
47                         for slot in self.equal[slotid]:
48                                 tunermask |= (1 << slot)
49                 elif self.linked.has_key(slotid):
50                         for slot in self.linked[slotid]:
51                                 tunermask |= (1 << slot)
52                 sec.setLNBLOFL(9750000)
53                 sec.setLNBLOFH(10600000)
54                 sec.setLNBThreshold(11700000)
55                 sec.setLNBIncreasedVoltage(lnbParam.OFF)
56                 sec.setRepeats(0)
57                 sec.setFastDiSEqC(0)
58                 sec.setSeqRepeat(0)
59                 sec.setVoltageMode(switchParam.HV)
60                 sec.setToneMode(switchParam.HILO)
61                 sec.setCommandOrder(0)
62
63                 #user values
64                 sec.setDiSEqCMode(diseqcmode)
65                 sec.setToneburst(toneburstmode)
66                 sec.setCommittedCommand(diseqcpos)
67                 sec.setUncommittedCommand(0) # SENDNO
68                 #print "set orbpos to:" + str(orbpos)
69
70                 if 0 <= diseqcmode < 3:
71                         self.addSatellite(sec, orbpos)
72                 elif (diseqcmode == 3): # diseqc 1.2
73                         if self.satposdepends.has_key(slotid):
74                                 for slot in self.satposdepends[slotid]:
75                                         tunermask |= (1 << slot)
76                         sec.setLatitude(latitude)
77                         sec.setLaDirection(laDirection)
78                         sec.setLongitude(longitude)
79                         sec.setLoDirection(loDirection)
80                         sec.setUseInputpower(useInputPower)
81                         sec.setInputpowerDelta(inputPowerDelta)
82                         sec.setRotorTurningSpeed(turningSpeed)
83
84                         for x in self.NimManager.satList:
85                                 print "Add sat " + str(x[0])
86                                 self.addSatellite(sec, int(x[0]))
87                                 sec.setVoltageMode(0)
88                                 sec.setToneMode(0)
89                                 sec.setRotorPosNum(0) # USALS
90                 
91                 sec.setLNBSlotMask(tunermask)
92
93         def setSatposDepends(self, sec, nim1, nim2):
94                 print "tuner", nim1, "depends on satpos of", nim2
95                 sec.setTunerDepends(nim1, nim2)
96
97         def linkNIMs(self, sec, nim1, nim2):
98                 print "link tuner", nim1, "to tuner", nim2
99                 sec.setTunerLinked(nim1, nim2)
100                 
101         def getRoot(self, slotid, connto):
102                 visited = []
103                 while (self.NimManager.getNimConfig(connto).configMode.value in ["satposdepends", "equal", "loopthrough"]):
104                         connto = int(self.NimManager.getNimConfig(connto).connectedTo.value)
105                         if connto in visited: # prevent endless loop
106                                 return slotid
107                         visited.append(connto)
108                 return connto
109
110         def update(self):
111                 sec = secClass.getInstance()
112                 self.configuredSatellites = Set()
113                 sec.clear() ## this do unlinking NIMs too !!
114                 print "sec config cleared"
115
116                 self.linked = { }
117                 self.satposdepends = { }
118                 self.equal = { }
119
120                 nim_slots = self.NimManager.nim_slots
121
122                 used_nim_slots = [ ]
123
124                 for slot in nim_slots:
125                         if slot.type is not None:
126                                 used_nim_slots.append((slot.slot, slot.description, slot.config.configMode.value != "nothing" and True or False))
127                 eDVBResourceManager.getInstance().setFrontendSlotInformations(used_nim_slots)
128
129                 for slot in nim_slots:
130                         x = slot.slot
131                         nim = slot.config
132                         if slot.isCompatible("DVB-S"):
133                                 # save what nim we link to/are equal to/satposdepends to.
134                                 # this is stored in the *value* (not index!) of the config list
135                                 if nim.configMode.value == "equal":
136                                         connto = self.getRoot(x, int(nim.connectedTo.value))
137                                         if not self.equal.has_key(connto):
138                                                 self.equal[connto] = []
139                                         self.equal[connto].append(x)
140                                 elif nim.configMode.value == "loopthrough":
141                                         self.linkNIMs(sec, x, int(nim.connectedTo.value))
142                                         connto = self.getRoot(x, int(nim.connectedTo.value))
143                                         if not self.linked.has_key(connto):
144                                                 self.linked[connto] = []
145                                         self.linked[connto].append(x)
146                                 elif nim.configMode.value == "satposdepends":
147                                         self.setSatposDepends(sec, x, int(nim.connectedTo.value))
148                                         connto = self.getRoot(x, int(nim.connectedTo.value))
149                                         if not self.satposdepends.has_key(connto):
150                                                 self.satposdepends[connto] = []
151                                         self.satposdepends[connto].append(x)
152
153                 for slot in nim_slots:
154                         x = slot.slot
155                         nim = slot.config
156                         if slot.isCompatible("DVB-S"):
157                                 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
158                                 print "diseqcmode: ", nim.diseqcMode.value
159                                 if nim.configMode.value in [ "loopthrough", "satposdepends", "nothing" ]:
160                                         pass
161                                 else:
162                                         sec.setSlotNotLinked(x)
163                                         if nim.configMode.value == "equal":
164                                                 pass
165                                         elif nim.configMode.value == "simple":          #simple config
166                                                 if nim.diseqcMode.value == "single":                    #single
167                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.NONE, diseqcpos = diseqcParam.SENDNO)
168                                                 elif nim.diseqcMode.value == "toneburst_a_b":           #Toneburst A/B
169                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.A, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.SENDNO)
170                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.B, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.SENDNO)
171                                                 elif nim.diseqcMode.value == "diseqc_a_b":              #DiSEqC A/B
172                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA)
173                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AB)
174                                                 elif nim.diseqcMode.value == "diseqc_a_b_c_d":          #DiSEqC A/B/C/D
175                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcA.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AA)
176                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcB.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.AB)
177                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcC.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.BA)
178                                                         self.addLNBSimple(sec, slotid = x, orbpos = nim.diseqcD.orbital_position, toneburstmode = diseqcParam.NO, diseqcmode = diseqcParam.V1_0, diseqcpos = diseqcParam.BB)
179                                                 elif nim.diseqcMode.value == "positioner":              #Positioner
180                                                         if nim.latitudeOrientation.value == "north":
181                                                                 laValue = rotorParam.NORTH
182                                                         else:
183                                                                 laValue = rotorParam.SOUTH
184                                                         if nim.longitudeOrientation.value == "east":
185                                                                 loValue = rotorParam.EAST
186                                                         else:
187                                                                 loValue = rotorParam.WEST
188                                                         inputPowerDelta=50
189                                                         useInputPower=False
190                                                         turning_speed=0
191                                                         if nim.powerMeasurement.value:
192                                                                 useInputPower=True
193                                                                 inputPowerDelta=nim.powerThreshold.value
194                                                                 turn_speed_dict = { "fast": rotorParam.FAST, "slow": rotorParam.SLOW }
195                                                                 if turn_speed_dict.has_key(nim.turningSpeed.value):
196                                                                         turning_speed = turn_speed_dict[nim.turningSpeed.value]
197                                                                 else:
198                                                                         beg_time = localtime(nim.fastTurningBegin.value)
199                                                                         end_time = localtime(nim.fastTurningEnd.value)
200                                                                         turning_speed = ((beg_time.tm_hour+1) * 60 + beg_time.tm_min + 1) << 16
201                                                                         turning_speed |= (end_time.tm_hour+1) * 60 + end_time.tm_min + 1
202                                                         self.addLNBSimple(sec, slotid = x, diseqcmode = 3,
203                                                                 longitude = nim.longitude.float,
204                                                                 loDirection = loValue,
205                                                                 latitude = nim.latitude.float,
206                                                                 laDirection = laValue,
207                                                                 turningSpeed = turning_speed,
208                                                                 useInputPower = useInputPower,
209                                                                 inputPowerDelta = inputPowerDelta)
210                                         elif nim.configMode.value == "advanced": #advanced config
211                                                 self.updateAdvanced(sec, x)
212                 print "sec config completed"
213
214         def updateAdvanced(self, sec, slotid):
215                 lnbSat = {}
216                 for x in range(1,129):
217                         lnbSat[x] = []
218
219                 #wildcard for all satellites ( for rotor )
220                 for x in range(3601, 3605):
221                         lnb = int(config.Nims[slotid].advanced.sat[x].lnb.value)
222                         if lnb != 0:
223                                 for x in self.NimManager.satList:
224                                         print "add", x[0], "to", lnb
225                                         lnbSat[lnb].append(x[0])
226
227                 for x in self.NimManager.satList:
228                         lnb = int(config.Nims[slotid].advanced.sat[x[0]].lnb.value)
229                         if lnb != 0:
230                                 print "add", x[0], "to", lnb
231                                 lnbSat[lnb].append(x[0])
232
233                 for x in range(1,129):
234                         if len(lnbSat[x]) > 0:
235                                 currLnb = config.Nims[slotid].advanced.lnb[x]
236                                 sec.addLNB()
237
238                                 tunermask = 1 << slotid
239                                 if self.equal.has_key(slotid):
240                                         for slot in self.equal[slotid]:
241                                                 tunermask |= (1 << slot)
242                                 elif self.linked.has_key(slotid):
243                                         for slot in self.linked[slotid]:
244                                                 tunermask |= (1 << slot)
245
246                                 if currLnb.lof.value == "universal_lnb":
247                                         sec.setLNBLOFL(9750000)
248                                         sec.setLNBLOFH(10600000)
249                                         sec.setLNBThreshold(11700000)
250                                 elif currLnb.lof.value == "c_band":
251                                         sec.setLNBLOFL(5150000)
252                                         sec.setLNBLOFH(5150000)
253                                         sec.setLNBThreshold(5150000)
254                                 elif currLnb.lof.value == "user_defined":
255                                         sec.setLNBLOFL(currLnb.lofl.value * 1000)
256                                         sec.setLNBLOFH(currLnb.lofh.value * 1000)
257                                         sec.setLNBThreshold(currLnb.threshold.value * 1000)
258
259 #                               if currLnb.output_12v.value == "0V":
260 #                                       pass # nyi in drivers
261 #                               elif currLnb.output_12v.value == "12V":
262 #                                       pass # nyi in drivers
263
264                                 if currLnb.increased_voltage.value:
265                                         sec.setLNBIncreasedVoltage(lnbParam.ON)
266                                 else:
267                                         sec.setLNBIncreasedVoltage(lnbParam.OFF)
268
269                                 dm = currLnb.diseqcMode.value
270                                 if dm == "none":
271                                         sec.setDiSEqCMode(diseqcParam.NONE)
272                                 elif dm == "1_0":
273                                         sec.setDiSEqCMode(diseqcParam.V1_0)
274                                 elif dm == "1_1":
275                                         sec.setDiSEqCMode(diseqcParam.V1_1)
276                                 elif dm == "1_2":
277                                         sec.setDiSEqCMode(diseqcParam.V1_2)
278
279                                         if self.satposdepends.has_key(slotid):  # only useable with rotors
280                                                 tunermask |= (1 << self.satposdepends[slotid])
281
282                                 if dm != "none":
283                                         if currLnb.toneburst.value == "none":
284                                                 sec.setToneburst(diseqcParam.NO)
285                                         elif currLnb.toneburst.value == "A":
286                                                 sec.setToneburst(diseqcParam.A)
287                                         elif currLnb.toneburst.value == "B":
288                                                 sec.setToneburst(diseqcParam.B)
289
290                                         # Committed Diseqc Command
291                                         cdc = currLnb.commitedDiseqcCommand.value
292
293                                         c = { "none": diseqcParam.SENDNO,
294                                                 "AA": diseqcParam.AA,
295                                                 "AB": diseqcParam.AB,
296                                                 "BA": diseqcParam.BA,
297                                                 "BB": diseqcParam.BB }
298
299                                         if c.has_key(cdc):
300                                                 sec.setCommittedCommand(c[cdc])
301                                         else:
302                                                 sec.setCommittedCommand(long(cdc))
303
304                                         sec.setFastDiSEqC(currLnb.fastDiseqc.value)
305
306                                         sec.setSeqRepeat(currLnb.sequenceRepeat.value)
307
308                                         if currLnb.diseqcMode.value == "1_0":
309                                                 currCO = currLnb.commandOrder1_0.value
310                                         else:
311                                                 currCO = currLnb.commandOrder.value
312
313                                                 udc = int(currLnb.uncommittedDiseqcCommand.value)
314                                                 if udc > 0:
315                                                         sec.setUncommittedCommand(0xF0|(udc-1))
316                                                 else:
317                                                         sec.setUncommittedCommand(0) # SENDNO
318
319                                                 sec.setRepeats({"none": 0, "one": 1, "two": 2, "three": 3}[currLnb.diseqcRepeats.value])
320
321                                         setCommandOrder = False
322
323                                         # 0 "committed, toneburst",
324                                         # 1 "toneburst, committed",
325                                         # 2 "committed, uncommitted, toneburst",
326                                         # 3 "toneburst, committed, uncommitted",
327                                         # 4 "uncommitted, committed, toneburst"
328                                         # 5 "toneburst, uncommitted, commmitted"
329                                         order_map = {"ct": 0, "tc": 1, "cut": 2, "tcu": 3, "uct": 4, "tuc": 5}
330                                         sec.setCommandOrder(order_map[currCO])
331
332                                 if dm == "1_2":
333                                         latitude = currLnb.latitude.float
334                                         sec.setLatitude(latitude)
335                                         longitude = currLnb.longitude.float
336                                         sec.setLongitude(longitude)
337                                         if currLnb.latitudeOrientation.value == "north":
338                                                 sec.setLaDirection(rotorParam.NORTH)
339                                         else:
340                                                 sec.setLaDirection(rotorParam.SOUTH)
341                                         if currLnb.longitudeOrientation.value == "east":
342                                                 sec.setLoDirection(rotorParam.EAST)
343                                         else:
344                                                 sec.setLoDirection(rotorParam.WEST)
345
346                                 if currLnb.powerMeasurement.value:
347                                         sec.setUseInputpower(True)
348                                         sec.setInputpowerDelta(currLnb.powerThreshold.value)
349                                         turn_speed_dict = { "fast": rotorParam.FAST, "slow": rotorParam.SLOW }
350                                         if turn_speed_dict.has_key(currLnb.turningSpeed.value):
351                                                 turning_speed = turn_speed_dict[currLnb.turningSpeed.value]
352                                         else:
353                                                 beg_time = localtime(currLnb.fastTurningBegin.value)
354                                                 end_time = localtime(currLnb.fastTurningEnd.value)
355                                                 turning_speed = ((beg_time.tm_hour + 1) * 60 + beg_time.tm_min + 1) << 16
356                                                 turning_speed |= (end_time.tm_hour + 1) * 60 + end_time.tm_min + 1
357                                         sec.setRotorTurningSpeed(turning_speed)
358                                 else:
359                                         sec.setUseInputpower(False)
360
361                                 sec.setLNBSlotMask(tunermask)
362
363                                 # finally add the orbital positions
364                                 for y in lnbSat[x]:
365                                         self.addSatellite(sec, y)
366                                         currSat = config.Nims[slotid].advanced.sat[y]
367
368                                         if currSat.voltage.value == "polarization":
369                                                 sec.setVoltageMode(switchParam.HV)
370                                         elif currSat.voltage.value == "13V":
371                                                 sec.setVoltageMode(switchParam._14V)
372                                         elif currSat.voltage.value == "18V":
373                                                 sec.setVoltageMode(switchParam._18V)
374                                                 
375                                         if currSat.tonemode == "band":
376                                                 sec.setToneMode(switchParam.HILO)
377                                         elif currSat.tonemode == "on":
378                                                 sec.setToneMode(switchParam.ON)
379                                         elif currSat.tonemode == "off":
380                                                 sec.setToneMode(switchParam.OFF)
381                                                 
382                                         if not currSat.usals.value and x < 125:
383                                                 sec.setRotorPosNum(currSat.rotorposition.value)
384                                         else:
385                                                 sec.setRotorPosNum(0) #USALS
386
387         def __init__(self, nimmgr):
388                 self.NimManager = nimmgr
389                 self.configuredSatellites = Set()
390                 self.update()
391
392 class NIM(object):
393         def __init__(self, slot, type, description, has_outputs = True, internally_connectable = None):
394                 self.slot = slot
395
396                 if type not in ["DVB-S", "DVB-C", "DVB-T", "DVB-S2", None]:
397                         print "warning: unknown NIM type %s, not using." % type
398                         type = None
399
400                 self.type = type
401                 self.description = description
402                 self.has_outputs = has_outputs
403                 self.internally_connectable = internally_connectable
404
405         def isCompatible(self, what):
406                 compatible = {
407                                 None: [None],
408                                 "DVB-S": ["DVB-S", None],
409                                 "DVB-C": ["DVB-C", None],
410                                 "DVB-T": ["DVB-T", None],
411                                 "DVB-S2": ["DVB-S", "DVB-S2", None]
412                         }
413                 return what in compatible[self.type]
414         
415         def connectableTo(self):
416                 connectable = {
417                                 "DVB-S": ["DVB-S", "DVB-S2"],
418                                 "DVB-C": ["DVB-C"],
419                                 "DVB-T": ["DVB-T"],
420                                 "DVB-S2": ["DVB-S", "DVB-S2"]
421                         }
422                 return connectable[self.type]
423
424         def getSlotName(self):
425                 # get a friendly description for a slot name.
426                 # we name them "Tuner A/B/C/...", because that's what's usually written on the back
427                 # of the device.
428                 return _("Tuner ") + chr(ord('A') + self.slot)
429
430         slot_name = property(getSlotName)
431
432         def getSlotID(self):
433                 return chr(ord('A') + self.slot)
434         
435         def hasOutputs(self):
436                 return self.has_outputs
437         
438         def internallyConnectableTo(self):
439                 return self.internally_connectable
440
441         slot_id = property(getSlotID)
442
443         def getFriendlyType(self):
444                 return {
445                         "DVB-S": "DVB-S", 
446                         "DVB-T": "DVB-T",
447                         "DVB-S2": "DVB-S2",
448                         "DVB-C": "DVB-C",
449                         None: _("empty")
450                         }[self.type]
451
452         friendly_type = property(getFriendlyType)
453
454         def getFriendlyFullDescription(self):
455                 nim_text = self.slot_name + ": "
456                         
457                 if self.empty:
458                         nim_text += _("(empty)")
459                 else:
460                         nim_text += self.description + " (" + self.friendly_type + ")"
461                 
462                 return nim_text
463
464         friendly_full_description = property(getFriendlyFullDescription)
465         config_mode = property(lambda self: config.Nims[self.slot].configMode.value)
466         config = property(lambda self: config.Nims[self.slot])
467         empty = property(lambda self: self.type is None)
468
469 class NimManager:
470         def getConfiguredSats(self):
471                 return self.sec.getConfiguredSats()
472
473         def getTransponders(self, pos):
474                 if self.transponders.has_key(pos):
475                         return self.transponders[pos]
476                 else:
477                         return []
478
479         def getTranspondersCable(self, nim):
480                 nimConfig = config.Nims[nim]
481                 if nimConfig.configMode.value != "nothing" and nimConfig.cable.scan_type.value == "provider":
482                         return self.transponderscable[self.cablesList[nimConfig.cable.scan_provider.index][0]]
483                 return [ ]
484
485         def getTranspondersTerrestrial(self, region):
486                 return self.transpondersterrestrial[region]
487         
488         def getCableDescription(self, nim):
489                 return self.cablesList[config.Nims[nim].scan_provider.index][0]
490
491         def getCableFlags(self, nim):
492                 return self.cablesList[config.Nims[nim].scan_provider.index][1]
493
494         def getTerrestrialDescription(self, nim):
495                 return self.terrestrialsList[config.Nims[nim].terrestrial.index][0]
496
497         def getTerrestrialFlags(self, nim):
498                 return self.terrestrialsList[config.Nims[nim].terrestrial.index][1]
499
500         def getSatDescription(self, pos):
501                 return self.satellites[pos]
502
503         def readTransponders(self):
504                 # read initial networks from file. we only read files which we are interested in,
505                 # which means only these where a compatible tuner exists.
506                 self.satellites = { }
507                 self.transponders = { }
508                 self.transponderscable = { }
509                 self.transpondersterrestrial = { }
510                 db = eDVBDB.getInstance()
511                 if self.hasNimType("DVB-S"):
512                         print "Reading satellites.xml"
513                         db.readSatellites(self.satList, self.satellites, self.transponders)
514 #                       print "SATLIST", self.satList
515 #                       print "SATS", self.satellites
516 #                       print "TRANSPONDERS", self.transponders
517
518                 if self.hasNimType("DVB-C"):
519                         print "Reading cables.xml"
520                         db.readCables(self.cablesList, self.transponderscable)
521 #                       print "CABLIST", self.cablesList
522 #                       print "TRANSPONDERS", self.transponders
523
524                 if self.hasNimType("DVB-T"):
525                         print "Reading terrestrial.xml"
526                         db.readTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
527 #                       print "TERLIST", self.terrestrialsList
528 #                       print "TRANSPONDERS", self.transpondersterrestrial
529
530         def enumerateNIMs(self):
531                 # enum available NIMs. This is currently very dreambox-centric and uses the /proc/bus/nim_sockets interface.
532                 # the result will be stored into nim_slots.
533                 # the content of /proc/bus/nim_sockets looks like:
534                 # NIM Socket 0:
535                 #          Type: DVB-S
536                 #          Name: BCM4501 DVB-S2 NIM (internal)
537                 # NIM Socket 1:
538                 #          Type: DVB-S
539                 #          Name: BCM4501 DVB-S2 NIM (internal)
540                 # NIM Socket 2:
541                 #          Type: DVB-T
542                 #          Name: Philips TU1216
543                 # NIM Socket 3:
544                 #          Type: DVB-S
545                 #          Name: Alps BSBE1 702A
546                 
547                 #
548                 # Type will be either "DVB-S", "DVB-S2", "DVB-T", "DVB-C" or None.
549
550                 # nim_slots is an array which has exactly one entry for each slot, even for empty ones.
551                 self.nim_slots = [ ]
552
553                 nimfile = tryOpen("/proc/bus/nim_sockets")
554
555                 if nimfile is None:
556                         return
557
558                 current_slot = None
559
560                 entries = {}
561                 for line in nimfile.readlines():
562                         if line == "":
563                                 break
564                         if line.strip().startswith("NIM Socket"):
565                                 parts = line.strip().split(" ")
566                                 current_slot = int(parts[2][:-1])
567                                 entries[current_slot] = {}
568                         elif line.strip().startswith("Type:"):
569                                 entries[current_slot]["type"] = str(line.strip()[6:])
570                         elif line.strip().startswith("Name:"):
571                                 entries[current_slot]["name"] = str(line.strip()[6:])
572                         elif line.strip().startswith("Has_Outputs:"):
573                                 input = str(line.strip()[len("Has_Outputs:") + 1:])
574                                 entries[current_slot]["has_outputs"] = (input == "yes")
575                         elif line.strip().startswith("Internally_Connectable:"):
576                                 input = int(line.strip()[len("Internally_Connectable:") + 1:])
577                                 entries[current_slot]["internally_connectable"] = input 
578                         elif line.strip().startswith("empty"):
579                                 entries[current_slot]["type"] = None
580                                 entries[current_slot]["name"] = _("N/A")
581                 nimfile.close()
582                 
583                 for id, entry in entries.items():
584                         if not (entry.has_key("name") and entry.has_key("type")):
585                                 entry["name"] =  _("N/A")
586                                 entry["type"] = None
587                         if not (entry.has_key("has_outputs")):
588                                 entry["has_outputs"] = True
589                         if not (entry.has_key("internally_connectable")):
590                                 entry["internally_connectable"] = None
591                         self.nim_slots.append(NIM(slot = id, description = entry["name"], type = entry["type"], has_outputs = entry["has_outputs"], internally_connectable = entry["internally_connectable"]))
592
593         def hasNimType(self, chktype):
594                 for slot in self.nim_slots:
595                         if slot.isCompatible(chktype):
596                                 return True
597                 return False
598         
599         def getNimType(self, slotid):
600                 return self.nim_slots[slotid].type
601         
602         def getNimDescription(self, slotid):
603                 return self.nim_slots[slotid].friendly_full_description
604
605         def getNimListOfType(self, type, exception = -1):
606                 # returns a list of indexes for NIMs compatible to the given type, except for 'exception'
607                 list = []
608                 for x in self.nim_slots:
609                         if x.isCompatible(type) and x.slot != exception:
610                                 list.append(x.slot)
611                 return list
612
613         def __init__(self):
614                 self.satList = [ ]
615                 self.cablesList = []
616                 self.terrestrialsList = []
617                 self.enumerateNIMs()
618                 self.readTransponders()
619                 InitNimManager(self)    #init config stuff
620
621         # get a list with the friendly full description
622         def nimList(self):
623                 list = [ ]
624                 for slot in self.nim_slots:
625                         list.append(slot.friendly_full_description)
626                 return list
627         
628         def getSlotCount(self):
629                 return len(self.nim_slots)
630         
631         def hasOutputs(self, slotid):
632                 return self.nim_slots[slotid].hasOutputs()
633         
634         def canConnectTo(self, slotid):
635                 slots = []
636                 if self.nim_slots[slotid].internallyConnectableTo() is not None:
637                         slots.append(self.nim_slots[slotid].internallyConnectableTo())
638                 for type in self.nim_slots[slotid].connectableTo(): 
639                         for slot in self.getNimListOfType(type, exception = slotid):
640                                 if self.hasOutputs(slot):
641                                         slots.append(slot)
642                 # remove nims, that have a conntectedTo reference on
643                 for testnim in slots[:]:
644                         for nim in self.getNimListOfType("DVB-S", slotid):
645                                 nimConfig = self.getNimConfig(nim)
646                                 if nimConfig.content.items.has_key("configMode") and nimConfig.configMode.value == "loopthrough" and int(nimConfig.connectedTo.value) == testnim:
647                                         slots.remove(testnim)
648                                         break 
649                 slots.sort()
650                 
651                 return slots
652         
653         def canEqualTo(self, slotid):
654                 type = self.getNimType(slotid)
655                 if self.getNimConfig(slotid) == "DVB-S2":
656                         type = "DVB-S"
657                 nimList = self.getNimListOfType(type, slotid)
658                 for nim in nimList[:]:
659                         mode = self.getNimConfig(nim)
660                         if mode.configMode.value == "loopthrough" or mode.configMode.value == "satposdepends":
661                                 nimList.remove(nim)
662                 return nimList
663         
664         def canDependOn(self, slotid):
665                 type = self.getNimType(slotid)
666                 if self.getNimConfig(slotid) == "DVB-S2":
667                         type = "DVB-S"
668                 nimList = self.getNimListOfType(type, slotid)
669                 positionerList = []
670                 for nim in nimList[:]:
671                         mode = self.getNimConfig(nim)
672                         if mode.configMode.value == "simple" and mode.diseqcMode.value == "positioner":
673                                 alreadyConnected = False
674                                 for testnim in nimList:
675                                         testmode = self.getNimConfig(testnim)
676                                         if testmode.configMode.value == "satposdepends" and int(testmode.connectedTo.value) == int(nim):
677                                                 alreadyConnected = True
678                                                 break
679                                 if not alreadyConnected:
680                                         positionerList.append(nim)
681                 return positionerList
682         
683         def getNimConfig(self, slotid):
684                 return config.Nims[slotid]
685         
686         def getSatName(self, pos):
687                 for sat in self.satList:
688                         if sat[0] == pos:
689                                 return sat[1]
690                 return _("N/A")
691
692         def getSatList(self):
693                 return self.satList
694
695         def getSatListForNim(self, slotid):
696                 list = []
697                 if self.nim_slots[slotid].isCompatible("DVB-S"):
698                         nim = config.Nims[slotid]
699                         #print "slotid:", slotid
700
701                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.index]
702                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
703                         configMode = nim.configMode.value
704
705                         if configMode == "equal":
706                                 slotid = int(nim.connectedTo.value)
707                                 nim = config.Nims[slotid]
708                                 configMode = nim.configMode.value
709                         elif configMode == "loopthrough":
710                                 slotid = self.sec.getRoot(slotid, int(nim.connectedTo.value))
711                                 nim = config.Nims[slotid]
712                                 configMode = nim.configMode.value
713
714                         if configMode == "simple":
715                                 dm = nim.diseqcMode.value
716                                 if dm in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
717                                         list.append(self.satList[nim.diseqcA.index])
718                                 if dm in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
719                                         list.append(self.satList[nim.diseqcB.index])
720                                 if dm == "diseqc_a_b_c_d":
721                                         list.append(self.satList[nim.diseqcC.index])
722                                         list.append(self.satList[nim.diseqcD.index])
723                                 if dm == "positioner":
724                                         for x in self.satList:
725                                                 list.append(x)
726                         elif configMode == "advanced":
727                                 for x in self.satList:
728                                         if int(nim.advanced.sat[x[0]].lnb.value) != 0:
729                                                 list.append(x)
730                 return list
731
732         def getRotorSatListForNim(self, slotid):
733                 list = []
734                 if self.nim_slots[slotid].isCompatible("DVB-S"):
735                         #print "slotid:", slotid
736                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
737                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
738                         configMode = config.Nims[slotid].configMode.value
739                         if configMode == "simple":
740                                 if config.Nims[slotid].diseqcMode.value == "positioner":
741                                         for x in self.satList:
742                                                 list.append(x)
743                         elif configMode == "advanced":
744                                 for x in self.satList:
745                                         nim = config.Nims[slotid]
746                                         lnbnum = int(nim.advanced.sat[x[0]].lnb.value)
747                                         if lnbnum != 0:
748                                                 lnb = nim.advanced.lnb[lnbnum]
749                                                 if lnb.diseqcMode.value == "1_2":
750                                                         list.append(x)
751                 return list
752
753 def InitSecParams():
754         config.sec = ConfigSubsection()
755
756         x = ConfigInteger(default=15, limits = (0, 9999))
757         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_CONT_TONE, configElement.value))
758         config.sec.delay_after_continuous_tone_change = x
759
760         x = ConfigInteger(default=10, limits = (0, 9999))
761         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_FINAL_VOLTAGE_CHANGE, configElement.value))
762         config.sec.delay_after_final_voltage_change = x
763
764         x = ConfigInteger(default=120, limits = (0, 9999))
765         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BETWEEN_DISEQC_REPEATS, configElement.value))
766         config.sec.delay_between_diseqc_repeats = x
767
768         x = ConfigInteger(default=50, limits = (0, 9999))
769         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_LAST_DISEQC_CMD, configElement.value))
770         config.sec.delay_after_last_diseqc_command = x
771
772         x = ConfigInteger(default=50, limits = (0, 9999))
773         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_TONEBURST, configElement.value))
774         config.sec.delay_after_toneburst = x
775
776         x = ConfigInteger(default=20, limits = (0, 9999))
777         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS, configElement.value))
778         config.sec.delay_after_change_voltage_before_switch_command = x
779
780         x = ConfigInteger(default=200, limits = (0, 9999))
781         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS, configElement.value))
782         config.sec.delay_after_enable_voltage_before_switch_command = x
783
784         x = ConfigInteger(default=700, limits = (0, 9999))
785         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD, configElement.value))
786         config.sec.delay_between_switch_and_motor_command = x
787
788         x = ConfigInteger(default=500, limits = (0, 9999))
789         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER, configElement.value))
790         config.sec.delay_after_voltage_change_before_measure_idle_inputpower = x
791
792         x = ConfigInteger(default=750, limits = (0, 9999))
793         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD, configElement.value))
794         config.sec.delay_after_enable_voltage_before_motor_command = x
795
796         x = ConfigInteger(default=500, limits = (0, 9999))
797         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_MOTOR_STOP_CMD, configElement.value))
798         config.sec.delay_after_motor_stop_command = x
799
800         x = ConfigInteger(default=500, limits = (0, 9999))
801         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD, configElement.value))
802         config.sec.delay_after_voltage_change_before_motor_command = x
803
804         x = ConfigInteger(default=360, limits = (0, 9999))
805         x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_RUNNING_TIMEOUT, configElement.value))
806         config.sec.motor_running_timeout = x
807
808         x = ConfigInteger(default=1, limits = (0, 5))
809         x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_COMMAND_RETRIES, configElement.value))
810         config.sec.motor_command_retries = x
811
812 # TODO add support for satpos depending nims to advanced nim configuration
813 # so a second/third/fourth cable from a motorized lnb can used behind a
814 # diseqc 1.0 / diseqc 1.1 / toneburst switch
815 # the C(++) part should can handle this
816 # the configElement should be only visible when diseqc 1.2 is disabled
817
818 def InitNimManager(nimmgr):
819         InitSecParams()
820
821         config.Nims = ConfigSubList()
822         for x in range(len(nimmgr.nim_slots)):
823                 config.Nims.append(ConfigSubsection())
824
825         for slot in nimmgr.nim_slots:
826                 x = slot.slot
827                 nim = config.Nims[x]
828                 
829                 if slot.isCompatible("DVB-S"):
830                         choices = { "nothing": _("nothing connected"),
831                                         "simple": _("simple"),
832                                         "advanced": _("advanced")}
833                         if len(nimmgr.getNimListOfType(slot.type, exception = x)) > 0:
834                                 choices["equal"] = _("equal to")
835                                 choices["satposdepends"] = _("second cable of motorized LNB")
836                         if len(nimmgr.canConnectTo(x)) > 0:
837                                 choices["loopthrough"] = _("loopthrough to")
838                         nim.configMode = ConfigSelection(choices = choices, default = "nothing")
839
840                         #important - check if just the 2nd one is LT only and the first one is DVB-S
841                         # CHECKME: is this logic correct for >2 slots?
842 #                       if nim.configMode.value in ["loopthrough", "satposdepends", "equal"]:
843 #                               if x == 0: # first one can never be linked to anything
844 #                                       # reset to simple
845 #                                       nim.configMode.value = "simple"
846 #                                       nim.configMode.save()
847 #                               else:
848                                         #FIXME: make it better
849                         for y in nimmgr.nim_slots:
850                                 if y.slot == 0:
851                                         if not y.isCompatible("DVB-S"):
852                                                 # reset to simple
853                                                 nim.configMode.value = "simple"
854                                                 nim.configMode.save()
855
856                         nim.diseqcMode = ConfigSelection(
857                                 choices = [
858                                         ("single", _("Single")),
859                                         ("toneburst_a_b", _("Toneburst A/B")),
860                                         ("diseqc_a_b", _("DiSEqC A/B")),
861                                         ("diseqc_a_b_c_d", _("DiSEqC A/B/C/D")),
862                                         ("positioner", _("Positioner"))],
863                                 default = "diseqc_a_b")
864
865                         choices = []
866                         for id in nimmgr.getNimListOfType("DVB-S"):
867                                 if id != x:
868                                         choices.append((str(id), nimmgr.getNimDescription(id)))
869                         nim.connectedTo = ConfigSelection(choices = choices)
870                         nim.diseqcA = getConfigSatlist(192, nimmgr.satList)
871                         nim.diseqcB = getConfigSatlist(130, nimmgr.satList)
872                         nim.diseqcC = ConfigSatlist(list = nimmgr.satList)
873                         nim.diseqcD = ConfigSatlist(list = nimmgr.satList)
874                         nim.positionerMode = ConfigSelection(
875                                 choices = [
876                                         ("usals", _("USALS")),
877                                         ("manual", _("manual"))],
878                                 default = "usals")
879                         nim.longitude = ConfigFloat(default=[5,100], limits=[(0,359),(0,999)])
880                         nim.longitudeOrientation = ConfigSelection(choices={"east": _("East"), "west": _("West")}, default = "east")
881                         nim.latitude = ConfigFloat(default=[50,767], limits=[(0,359),(0,999)])
882                         nim.latitudeOrientation = ConfigSelection(choices={"north": _("North"), "south": _("South")}, default="north")
883                         nim.powerMeasurement = ConfigYesNo(default=True)
884                         nim.powerThreshold = ConfigInteger(default=50, limits=(0, 100))
885                         nim.turningSpeed = ConfigSelection(choices = [("fast", _("Fast")), ("slow", _("Slow")), ("fast epoch", _("Fast epoch")) ], default = "fast")
886                         btime = datetime(1970, 1, 1, 7, 0);
887                         nim.fastTurningBegin = ConfigDateTime(default = mktime(btime.timetuple()), formatstring = _("%H:%M"), increment = 900)
888                         etime = datetime(1970, 1, 1, 19, 0);
889                         nim.fastTurningEnd = ConfigDateTime(default = mktime(etime.timetuple()), formatstring = _("%H:%M"), increment = 900)
890
891                         # advanced config:
892                         nim.advanced = ConfigSubsection()
893                         tmp = [(3601, _('All Satellites 1'), 1), (3602, _('All Satellites 2'), 1), (3603, _('All Satellites 3'), 1), (3604, _('All Satellites 4'), 1)]
894                         nim.advanced.sats = getConfigSatlist(192,nimmgr.satList+tmp)
895                         nim.advanced.sat = ConfigSubDict()
896                         lnbs = [("0", "not available")]
897                         for y in range(1, 125):
898                                 lnbs.append((str(y), "LNB " + str(y)))
899
900                         for x in nimmgr.satList:
901                                 nim.advanced.sat[x[0]] = ConfigSubsection()
902                                 nim.advanced.sat[x[0]].voltage = ConfigSelection(choices={"polarization": _("Polarization"), "13V": _("13 V"), "18V": _("18 V")}, default = "polarization")
903                                 nim.advanced.sat[x[0]].tonemode = ConfigSelection(choices={"band": _("Band"), "on": _("On"), "off": _("Off")}, default = "band")
904                                 nim.advanced.sat[x[0]].usals = ConfigYesNo(default=True)
905                                 nim.advanced.sat[x[0]].rotorposition = ConfigInteger(default=1, limits=(1, 255))
906                                 nim.advanced.sat[x[0]].lnb = ConfigSelection(choices = lnbs)
907
908                         for x in range(3601, 3605):
909                                 nim.advanced.sat[x] = ConfigSubsection()
910                                 nim.advanced.sat[x].voltage = ConfigSelection(choices={"polarization": _("Polarization"), "13V": _("13 V"), "18V": _("18 V")}, default = "polarization")
911                                 nim.advanced.sat[x].tonemode = ConfigSelection(choices={"band": _("Band"), "on": _("On"), "off": _("Off")}, default = "band")
912                                 nim.advanced.sat[x].usals = ConfigYesNo(default=True)
913                                 nim.advanced.sat[x].rotorposition = ConfigInteger(default=1, limits=(1, 255))
914                                 lnbnum = 125+x-3601
915                                 nim.advanced.sat[x].lnb = ConfigSelection(choices = [("0", "not available"), (str(lnbnum), "LNB %d"%(lnbnum))], default="0")
916
917                         csw = [("none", _("None")), ("AA", _("AA")), ("AB", _("AB")), ("BA", _("BA")), ("BB", _("BB"))]
918                         for y in range(0, 16):
919                                 csw.append((str(0xF0|y), "Input " + str(y+1)))
920
921                         ucsw = [("0", _("None"))]
922                         for y in range(1, 17):
923                                 ucsw.append((str(y), "Input " + str(y)))
924
925                         nim.advanced.lnb = ConfigSubList()
926                         nim.advanced.lnb.append(ConfigNothing())
927                         for x in range(1, 129):
928                                 nim.advanced.lnb.append(ConfigSubsection())
929                                 nim.advanced.lnb[x].lof = ConfigSelection(choices={"universal_lnb": _("Universal LNB"), "c_band": _("C-Band"), "user_defined": _("User defined")}, default="universal_lnb")
930                                 nim.advanced.lnb[x].lofl = ConfigInteger(default=9750, limits = (0, 99999))
931                                 nim.advanced.lnb[x].lofh = ConfigInteger(default=10600, limits = (0, 99999))
932                                 nim.advanced.lnb[x].threshold = ConfigInteger(default=11700, limits = (0, 99999))
933 #                               nim.advanced.lnb[x].output_12v = ConfigSelection(choices = [("0V", _("0 V")), ("12V", _("12 V"))], default="0V")
934                                 nim.advanced.lnb[x].increased_voltage = ConfigYesNo(default=False)
935                                 nim.advanced.lnb[x].toneburst = ConfigSelection(choices = [("none", _("None")), ("A", _("A")), ("B", _("B"))], default = "none")
936                                 if x > 124:
937                                         nim.advanced.lnb[x].diseqcMode = ConfigSelection(choices = [("1_2", _("1.2"))], default = "1_2")
938                                 else:
939                                         nim.advanced.lnb[x].diseqcMode = ConfigSelection(choices = [("none", _("None")), ("1_0", _("1.0")), ("1_1", _("1.1")), ("1_2", _("1.2"))], default = "none")
940                                 nim.advanced.lnb[x].commitedDiseqcCommand = ConfigSelection(choices = csw)
941                                 nim.advanced.lnb[x].fastDiseqc = ConfigYesNo(default=False)
942                                 nim.advanced.lnb[x].sequenceRepeat = ConfigYesNo(default=False)
943                                 nim.advanced.lnb[x].commandOrder1_0 = ConfigSelection(choices = [("ct", "committed, toneburst"), ("tc", "toneburst, committed")], default = "ct")
944                                 nim.advanced.lnb[x].commandOrder = ConfigSelection(choices = [
945                                                 ("ct", "committed, toneburst"),
946                                                 ("tc", "toneburst, committed"),
947                                                 ("cut", "committed, uncommitted, toneburst"),
948                                                 ("tcu", "toneburst, committed, uncommitted"),
949                                                 ("uct", "uncommitted, committed, toneburst"),
950                                                 ("tuc", "toneburst, uncommitted, commmitted")],
951                                                 default="ct")
952                                 nim.advanced.lnb[x].uncommittedDiseqcCommand = ConfigSelection(choices = ucsw)
953                                 nim.advanced.lnb[x].diseqcRepeats = ConfigSelection(choices = [("none", _("None")), ("one", _("One")), ("two", _("Two")), ("three", _("Three"))], default = "none")
954                                 nim.advanced.lnb[x].longitude = ConfigFloat(default = [5,100], limits = [(0,359),(0,999)])
955                                 nim.advanced.lnb[x].longitudeOrientation = ConfigSelection(choices = [("east", _("East")), ("west", _("West"))], default = "east")
956                                 nim.advanced.lnb[x].latitude = ConfigFloat(default = [50,767], limits = [(0,359),(0,999)])
957                                 nim.advanced.lnb[x].latitudeOrientation = ConfigSelection(choices = [("north", _("North")), ("south", _("South"))], default = "north")
958                                 nim.advanced.lnb[x].powerMeasurement = ConfigYesNo(default=True)
959                                 nim.advanced.lnb[x].powerThreshold = ConfigInteger(default=50, limits=(0, 100))
960                                 nim.advanced.lnb[x].turningSpeed = ConfigSelection(choices = [("fast", _("Fast")), ("slow", _("Slow")), ("fast epoch", _("Fast epoch"))], default = "fast")
961                                 btime = datetime(1970, 1, 1, 7, 0);
962                                 nim.advanced.lnb[x].fastTurningBegin = ConfigDateTime(default=mktime(btime.timetuple()), formatstring = _("%H:%M"), increment = 600)
963                                 etime = datetime(1970, 1, 1, 19, 0);
964                                 nim.advanced.lnb[x].fastTurningEnd = ConfigDateTime(default=mktime(etime.timetuple()), formatstring = _("%H:%M"), increment = 600)
965                 elif slot.isCompatible("DVB-C"):
966                         nim.configMode = ConfigSelection(
967                                 choices = {
968                                         "enabled": _("enabled"),
969                                         "nothing": _("nothing connected"),
970                                         },
971                                 default = "enabled")
972                         list = [ ]
973                         n = 0
974                         for x in nimmgr.cablesList:
975                                 list.append((str(n), x[0]))
976                                 n += 1
977                         nim.cable = ConfigSubsection()
978                         possible_scan_types = [("bands", _("Frequency bands")), ("steps", _("Frequency steps"))]
979                         if n:
980                                 possible_scan_types.append(("provider", _("Provider")))
981                                 nim.cable.scan_provider = ConfigSelection(default = "0", choices = list)
982                         nim.cable.scan_type = ConfigSelection(default = "bands", choices = possible_scan_types)
983                         nim.cable.scan_band_EU_VHF_I = ConfigYesNo(default = True)
984                         nim.cable.scan_band_EU_MID = ConfigYesNo(default = True)
985                         nim.cable.scan_band_EU_VHF_III = ConfigYesNo(default = True)
986                         nim.cable.scan_band_EU_UHF_IV = ConfigYesNo(default = True)
987                         nim.cable.scan_band_EU_UHF_V = ConfigYesNo(default = True)
988                         nim.cable.scan_band_EU_SUPER = ConfigYesNo(default = True)
989                         nim.cable.scan_band_EU_HYPER = ConfigYesNo(default = True)
990                         nim.cable.scan_band_US_LOW = ConfigYesNo(default = False)
991                         nim.cable.scan_band_US_MID = ConfigYesNo(default = False)
992                         nim.cable.scan_band_US_HIGH = ConfigYesNo(default = False)
993                         nim.cable.scan_band_US_SUPER = ConfigYesNo(default = False)
994                         nim.cable.scan_band_US_HYPER = ConfigYesNo(default = False)
995                         nim.cable.scan_frequency_steps = ConfigInteger(default = 1000, limits = (1000, 10000))
996                         nim.cable.scan_mod_qam16 = ConfigYesNo(default = False)
997                         nim.cable.scan_mod_qam32 = ConfigYesNo(default = False)
998                         nim.cable.scan_mod_qam64 = ConfigYesNo(default = True)
999                         nim.cable.scan_mod_qam128 = ConfigYesNo(default = False)
1000                         nim.cable.scan_mod_qam256 = ConfigYesNo(default = True)
1001                         nim.cable.scan_sr_6900 = ConfigYesNo(default = True)
1002                         nim.cable.scan_sr_6875 = ConfigYesNo(default = True)
1003                         nim.cable.scan_sr_ext1 = ConfigInteger(default = 0, limits = (0, 7230))
1004                         nim.cable.scan_sr_ext2 = ConfigInteger(default = 0, limits = (0, 7230))
1005                 elif slot.isCompatible("DVB-T"):
1006                         nim.configMode = ConfigSelection(
1007                                 choices = {
1008                                         "enabled": _("enabled"),
1009                                         "nothing": _("nothing connected"),
1010                                         },
1011                                 default = "enabled")
1012                         list = []
1013                         n = 0
1014                         for x in nimmgr.terrestrialsList:
1015                                 list.append((str(n), x[0]))
1016                                 n += 1
1017                         nim.terrestrial = ConfigSelection(choices = list)
1018                         nim.terrestrial_5V = ConfigOnOff()
1019                 else:
1020                         nim.configMode = ConfigSelection(choices = { "nothing": _("disabled") }, default="nothing");
1021                         print "pls add support for this frontend type!"         
1022 #                       assert False
1023
1024         nimmgr.sec = SecConfigure(nimmgr)
1025
1026 nimmanager = NimManager()