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