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