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