edd3bbbbabb5ed500294266bef8a618e764132b5
[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                                 # finally add the orbital positions
385                                 for y in lnbSat[x]:
386                                         self.addSatellite(sec, y)
387                                         if x > 32:
388                                                 satpos = x > 32 and (3604-(36 - x)) or y
389                                         else:
390                                                 satpos = y
391                                         currSat = config.Nims[slotid].advanced.sat[satpos]
392                                         if currSat.voltage.value == "polarization":
393                                                 if config.Nims[slotid].diseqc13V.value:
394                                                         sec.setVoltageMode(switchParam.HV_13)
395                                                 else:
396                                                         sec.setVoltageMode(switchParam.HV)
397                                         elif currSat.voltage.value == "13V":
398                                                 sec.setVoltageMode(switchParam._14V)
399                                         elif currSat.voltage.value == "18V":
400                                                 sec.setVoltageMode(switchParam._18V)
401
402                                         if currSat.tonemode.value == "band":
403                                                 sec.setToneMode(switchParam.HILO)
404                                         elif currSat.tonemode.value == "on":
405                                                 sec.setToneMode(switchParam.ON)
406                                         elif currSat.tonemode.value == "off":
407                                                 sec.setToneMode(switchParam.OFF)
408                                                 
409                                         if not currSat.usals.value and x < 34:
410                                                 sec.setRotorPosNum(currSat.rotorposition.value)
411                                         else:
412                                                 sec.setRotorPosNum(0) #USALS
413
414         def __init__(self, nimmgr):
415                 self.NimManager = nimmgr
416                 self.configuredSatellites = Set()
417                 self.update()
418
419 class NIM(object):
420         def __init__(self, slot, type, description, has_outputs = True, internally_connectable = None):
421                 self.slot = slot
422
423                 if type not in ["DVB-S", "DVB-C", "DVB-T", "DVB-S2", None]:
424                         print "warning: unknown NIM type %s, not using." % type
425                         type = None
426
427                 self.type = type
428                 self.description = description
429                 self.has_outputs = has_outputs
430                 self.internally_connectable = internally_connectable
431
432         def isCompatible(self, what):
433                 compatible = {
434                                 None: [None],
435                                 "DVB-S": ["DVB-S", None],
436                                 "DVB-C": ["DVB-C", None],
437                                 "DVB-T": ["DVB-T", None],
438                                 "DVB-S2": ["DVB-S", "DVB-S2", None]
439                         }
440                 return what in compatible[self.type]
441         
442         def connectableTo(self):
443                 connectable = {
444                                 "DVB-S": ["DVB-S", "DVB-S2"],
445                                 "DVB-C": ["DVB-C"],
446                                 "DVB-T": ["DVB-T"],
447                                 "DVB-S2": ["DVB-S", "DVB-S2"]
448                         }
449                 return connectable[self.type]
450
451         def getSlotName(self):
452                 # get a friendly description for a slot name.
453                 # we name them "Tuner A/B/C/...", because that's what's usually written on the back
454                 # of the device.
455                 return _("Tuner ") + chr(ord('A') + self.slot)
456
457         slot_name = property(getSlotName)
458
459         def getSlotID(self):
460                 return chr(ord('A') + self.slot)
461         
462         def hasOutputs(self):
463                 return self.has_outputs
464         
465         def internallyConnectableTo(self):
466                 return self.internally_connectable
467
468         slot_id = property(getSlotID)
469
470         def getFriendlyType(self):
471                 return {
472                         "DVB-S": "DVB-S", 
473                         "DVB-T": "DVB-T",
474                         "DVB-S2": "DVB-S2",
475                         "DVB-C": "DVB-C",
476                         None: _("empty")
477                         }[self.type]
478
479         friendly_type = property(getFriendlyType)
480
481         def getFriendlyFullDescription(self):
482                 nim_text = self.slot_name + ": "
483                         
484                 if self.empty:
485                         nim_text += _("(empty)")
486                 else:
487                         nim_text += self.description + " (" + self.friendly_type + ")"
488                 
489                 return nim_text
490
491         friendly_full_description = property(getFriendlyFullDescription)
492         config_mode = property(lambda self: config.Nims[self.slot].configMode.value)
493         config = property(lambda self: config.Nims[self.slot])
494         empty = property(lambda self: self.type is None)
495
496 class NimManager:
497         def getConfiguredSats(self):
498                 return self.sec.getConfiguredSats()
499
500         def getTransponders(self, pos):
501                 if self.transponders.has_key(pos):
502                         return self.transponders[pos]
503                 else:
504                         return []
505
506         def getTranspondersCable(self, nim):
507                 nimConfig = config.Nims[nim]
508                 if nimConfig.configMode.value != "nothing" and nimConfig.cable.scan_type.value == "provider":
509                         return self.transponderscable[self.cablesList[nimConfig.cable.scan_provider.index][0]]
510                 return [ ]
511
512         def getTranspondersTerrestrial(self, region):
513                 return self.transpondersterrestrial[region]
514         
515         def getCableDescription(self, nim):
516                 return self.cablesList[config.Nims[nim].scan_provider.index][0]
517
518         def getCableFlags(self, nim):
519                 return self.cablesList[config.Nims[nim].scan_provider.index][1]
520
521         def getTerrestrialDescription(self, nim):
522                 return self.terrestrialsList[config.Nims[nim].terrestrial.index][0]
523
524         def getTerrestrialFlags(self, nim):
525                 return self.terrestrialsList[config.Nims[nim].terrestrial.index][1]
526
527         def getSatDescription(self, pos):
528                 return self.satellites[pos]
529
530         def readTransponders(self):
531                 # read initial networks from file. we only read files which we are interested in,
532                 # which means only these where a compatible tuner exists.
533                 self.satellites = { }
534                 self.transponders = { }
535                 self.transponderscable = { }
536                 self.transpondersterrestrial = { }
537                 db = eDVBDB.getInstance()
538                 if self.hasNimType("DVB-S"):
539                         print "Reading satellites.xml"
540                         db.readSatellites(self.satList, self.satellites, self.transponders)
541 #                       print "SATLIST", self.satList
542 #                       print "SATS", self.satellites
543 #                       print "TRANSPONDERS", self.transponders
544
545                 if self.hasNimType("DVB-C"):
546                         print "Reading cables.xml"
547                         db.readCables(self.cablesList, self.transponderscable)
548 #                       print "CABLIST", self.cablesList
549 #                       print "TRANSPONDERS", self.transponders
550
551                 if self.hasNimType("DVB-T"):
552                         print "Reading terrestrial.xml"
553                         db.readTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
554 #                       print "TERLIST", self.terrestrialsList
555 #                       print "TRANSPONDERS", self.transpondersterrestrial
556
557         def enumerateNIMs(self):
558                 # enum available NIMs. This is currently very dreambox-centric and uses the /proc/bus/nim_sockets interface.
559                 # the result will be stored into nim_slots.
560                 # the content of /proc/bus/nim_sockets looks like:
561                 # NIM Socket 0:
562                 #          Type: DVB-S
563                 #          Name: BCM4501 DVB-S2 NIM (internal)
564                 # NIM Socket 1:
565                 #          Type: DVB-S
566                 #          Name: BCM4501 DVB-S2 NIM (internal)
567                 # NIM Socket 2:
568                 #          Type: DVB-T
569                 #          Name: Philips TU1216
570                 # NIM Socket 3:
571                 #          Type: DVB-S
572                 #          Name: Alps BSBE1 702A
573                 
574                 #
575                 # Type will be either "DVB-S", "DVB-S2", "DVB-T", "DVB-C" or None.
576
577                 # nim_slots is an array which has exactly one entry for each slot, even for empty ones.
578                 self.nim_slots = [ ]
579
580                 nimfile = tryOpen("/proc/bus/nim_sockets")
581
582                 if nimfile is None:
583                         return
584
585                 current_slot = None
586
587                 entries = {}
588                 for line in nimfile.readlines():
589                         if line == "":
590                                 break
591                         if line.strip().startswith("NIM Socket"):
592                                 parts = line.strip().split(" ")
593                                 current_slot = int(parts[2][:-1])
594                                 entries[current_slot] = {}
595                         elif line.strip().startswith("Type:"):
596                                 entries[current_slot]["type"] = str(line.strip()[6:])
597                         elif line.strip().startswith("Name:"):
598                                 entries[current_slot]["name"] = str(line.strip()[6:])
599                         elif line.strip().startswith("Has_Outputs:"):
600                                 input = str(line.strip()[len("Has_Outputs:") + 1:])
601                                 entries[current_slot]["has_outputs"] = (input == "yes")
602                         elif line.strip().startswith("Internally_Connectable:"):
603                                 input = int(line.strip()[len("Internally_Connectable:") + 1:])
604                                 entries[current_slot]["internally_connectable"] = input 
605                         elif line.strip().startswith("empty"):
606                                 entries[current_slot]["type"] = None
607                                 entries[current_slot]["name"] = _("N/A")
608                 nimfile.close()
609                 
610                 for id, entry in entries.items():
611                         if not (entry.has_key("name") and entry.has_key("type")):
612                                 entry["name"] =  _("N/A")
613                                 entry["type"] = None
614                         if not (entry.has_key("has_outputs")):
615                                 entry["has_outputs"] = True
616                         if not (entry.has_key("internally_connectable")):
617                                 entry["internally_connectable"] = None
618                         self.nim_slots.append(NIM(slot = id, description = entry["name"], type = entry["type"], has_outputs = entry["has_outputs"], internally_connectable = entry["internally_connectable"]))
619
620         def hasNimType(self, chktype):
621                 for slot in self.nim_slots:
622                         if slot.isCompatible(chktype):
623                                 return True
624                 return False
625         
626         def getNimType(self, slotid):
627                 return self.nim_slots[slotid].type
628         
629         def getNimDescription(self, slotid):
630                 return self.nim_slots[slotid].friendly_full_description
631
632         def getNimListOfType(self, type, exception = -1):
633                 # returns a list of indexes for NIMs compatible to the given type, except for 'exception'
634                 list = []
635                 for x in self.nim_slots:
636                         if x.isCompatible(type) and x.slot != exception:
637                                 list.append(x.slot)
638                 return list
639
640         def __init__(self):
641                 self.satList = [ ]
642                 self.cablesList = []
643                 self.terrestrialsList = []
644                 self.enumerateNIMs()
645                 self.readTransponders()
646                 InitNimManager(self)    #init config stuff
647
648         # get a list with the friendly full description
649         def nimList(self):
650                 list = [ ]
651                 for slot in self.nim_slots:
652                         list.append(slot.friendly_full_description)
653                 return list
654         
655         def getSlotCount(self):
656                 return len(self.nim_slots)
657         
658         def hasOutputs(self, slotid):
659                 return self.nim_slots[slotid].hasOutputs()
660         
661         def canConnectTo(self, slotid):
662                 slots = []
663                 if self.nim_slots[slotid].internallyConnectableTo() is not None:
664                         slots.append(self.nim_slots[slotid].internallyConnectableTo())
665                 for type in self.nim_slots[slotid].connectableTo(): 
666                         for slot in self.getNimListOfType(type, exception = slotid):
667                                 if self.hasOutputs(slot):
668                                         slots.append(slot)
669                 # remove nims, that have a conntectedTo reference on
670                 for testnim in slots[:]:
671                         for nim in self.getNimListOfType("DVB-S", slotid):
672                                 nimConfig = self.getNimConfig(nim)
673                                 if nimConfig.content.items.has_key("configMode") and nimConfig.configMode.value == "loopthrough" and int(nimConfig.connectedTo.value) == testnim:
674                                         slots.remove(testnim)
675                                         break 
676                 slots.sort()
677                 
678                 return slots
679         
680         def canEqualTo(self, slotid):
681                 type = self.getNimType(slotid)
682                 if type == "DVB-S2":
683                         type = "DVB-S"
684                 nimList = self.getNimListOfType(type, slotid)
685                 for nim in nimList[:]:
686                         mode = self.getNimConfig(nim)
687                         if mode.configMode.value == "loopthrough" or mode.configMode.value == "satposdepends":
688                                 nimList.remove(nim)
689                 return nimList
690
691         def canDependOn(self, slotid):
692                 type = self.getNimType(slotid)
693                 if type == "DVB-S2":
694                         type = "DVB-S"
695                 nimList = self.getNimListOfType(type, slotid)
696                 positionerList = []
697                 for nim in nimList[:]:
698                         mode = self.getNimConfig(nim)
699                         nimHaveRotor = mode.configMode.value == "simple" and mode.diseqcMode.value == "positioner"
700                         if not nimHaveRotor and mode.configMode.value == "advanced":
701                                 for x in range(3601, 3605):
702                                         lnb = int(mode.advanced.sat[x].lnb.value)
703                                         if lnb != 0:
704                                                 nimHaveRotor = True
705                                                 break
706                                 if not nimHaveRotor:
707                                         for sat in mode.advanced.sat.values():
708                                                 lnb_num = int(sat.lnb.value)
709                                                 diseqcmode = lnb_num and mode.advanced.lnb[lnb_num].diseqcMode.value or ""
710                                                 if diseqcmode == "1_2":
711                                                         nimHaveRotor = True
712                                                         break
713                         if nimHaveRotor:
714                                 alreadyConnected = False
715                                 for testnim in nimList:
716                                         testmode = self.getNimConfig(testnim)
717                                         if testmode.configMode.value == "satposdepends" and int(testmode.connectedTo.value) == int(nim):
718                                                 alreadyConnected = True
719                                                 break
720                                 if not alreadyConnected:
721                                         positionerList.append(nim)
722                 return positionerList
723         
724         def getNimConfig(self, slotid):
725                 return config.Nims[slotid]
726         
727         def getSatName(self, pos):
728                 for sat in self.satList:
729                         if sat[0] == pos:
730                                 return sat[1]
731                 return _("N/A")
732
733         def getSatList(self):
734                 return self.satList
735
736         def getSatListForNim(self, slotid):
737                 list = []
738                 if self.nim_slots[slotid].isCompatible("DVB-S"):
739                         nim = config.Nims[slotid]
740                         #print "slotid:", slotid
741
742                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.index]
743                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
744                         configMode = nim.configMode.value
745
746                         if configMode == "equal":
747                                 slotid = int(nim.connectedTo.value)
748                                 nim = config.Nims[slotid]
749                                 configMode = nim.configMode.value
750                         elif configMode == "loopthrough":
751                                 slotid = self.sec.getRoot(slotid, int(nim.connectedTo.value))
752                                 nim = config.Nims[slotid]
753                                 configMode = nim.configMode.value
754
755                         if configMode == "simple":
756                                 dm = nim.diseqcMode.value
757                                 if dm in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
758                                         if nim.diseqcA.orbital_position != 3601:
759                                                 list.append(self.satList[nim.diseqcA.index-1])
760                                 if dm in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
761                                         if nim.diseqcB.orbital_position != 3601:
762                                                 list.append(self.satList[nim.diseqcB.index-1])
763                                 if dm == "diseqc_a_b_c_d":
764                                         if nim.diseqcC.orbital_position != 3601:
765                                                 list.append(self.satList[nim.diseqcC.index-1])
766                                         if nim.diseqcD.orbital_position != 3601:
767                                                 list.append(self.satList[nim.diseqcD.index-1])
768                                 if dm == "positioner":
769                                         for x in self.satList:
770                                                 list.append(x)
771                         elif configMode == "advanced":
772                                 for x in range(3601, 3605):
773                                         if int(nim.advanced.sat[x].lnb.value) != 0:
774                                                 for x in self.satList:
775                                                         list.append(x)
776                                 if not list:
777                                         for x in self.satList:
778                                                 if int(nim.advanced.sat[x[0]].lnb.value) != 0:
779                                                         list.append(x)
780                 return list
781
782         def getRotorSatListForNim(self, slotid):
783                 list = []
784                 if self.nim_slots[slotid].isCompatible("DVB-S"):
785                         #print "slotid:", slotid
786                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
787                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
788                         configMode = config.Nims[slotid].configMode.value
789                         if configMode == "simple":
790                                 if config.Nims[slotid].diseqcMode.value == "positioner":
791                                         for x in self.satList:
792                                                 list.append(x)
793                         elif configMode == "advanced":
794                                 nim = config.Nims[slotid]
795                                 for x in range(3601, 3605):
796                                         if int(nim.advanced.sat[x].lnb.value) != 0:
797                                                 for x in self.satList:
798                                                         list.append(x)
799                                 if not list:
800                                         for x in self.satList:
801                                                 lnbnum = int(nim.advanced.sat[x[0]].lnb.value)
802                                                 if lnbnum != 0:
803                                                         lnb = nim.advanced.lnb[lnbnum]
804                                                         if lnb.diseqcMode.value == "1_2":
805                                                                 list.append(x)
806                 return list
807
808 def InitSecParams():
809         config.sec = ConfigSubsection()
810
811         x = ConfigInteger(default=15, limits = (0, 9999))
812         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_CONT_TONE, configElement.value))
813         config.sec.delay_after_continuous_tone_change = x
814
815         x = ConfigInteger(default=10, limits = (0, 9999))
816         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_FINAL_VOLTAGE_CHANGE, configElement.value))
817         config.sec.delay_after_final_voltage_change = x
818
819         x = ConfigInteger(default=120, limits = (0, 9999))
820         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BETWEEN_DISEQC_REPEATS, configElement.value))
821         config.sec.delay_between_diseqc_repeats = x
822
823         x = ConfigInteger(default=50, limits = (0, 9999))
824         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_LAST_DISEQC_CMD, configElement.value))
825         config.sec.delay_after_last_diseqc_command = x
826
827         x = ConfigInteger(default=50, limits = (0, 9999))
828         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_TONEBURST, configElement.value))
829         config.sec.delay_after_toneburst = x
830
831         x = ConfigInteger(default=20, limits = (0, 9999))
832         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS, configElement.value))
833         config.sec.delay_after_change_voltage_before_switch_command = x
834
835         x = ConfigInteger(default=200, limits = (0, 9999))
836         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS, configElement.value))
837         config.sec.delay_after_enable_voltage_before_switch_command = x
838
839         x = ConfigInteger(default=700, limits = (0, 9999))
840         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD, configElement.value))
841         config.sec.delay_between_switch_and_motor_command = x
842
843         x = ConfigInteger(default=500, limits = (0, 9999))
844         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER, configElement.value))
845         config.sec.delay_after_voltage_change_before_measure_idle_inputpower = x
846
847         x = ConfigInteger(default=750, limits = (0, 9999))
848         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD, configElement.value))
849         config.sec.delay_after_enable_voltage_before_motor_command = x
850
851         x = ConfigInteger(default=500, limits = (0, 9999))
852         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_MOTOR_STOP_CMD, configElement.value))
853         config.sec.delay_after_motor_stop_command = x
854
855         x = ConfigInteger(default=500, limits = (0, 9999))
856         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD, configElement.value))
857         config.sec.delay_after_voltage_change_before_motor_command = x
858
859         x = ConfigInteger(default=70, limits = (0, 9999))
860         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BEFORE_SEQUENCE_REPEAT, configElement.value))
861         config.sec.delay_before_sequence_repeat = x
862
863         x = ConfigInteger(default=360, limits = (0, 9999))
864         x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_RUNNING_TIMEOUT, configElement.value))
865         config.sec.motor_running_timeout = x
866
867         x = ConfigInteger(default=1, limits = (0, 5))
868         x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_COMMAND_RETRIES, configElement.value))
869         config.sec.motor_command_retries = x
870
871         x = ConfigInteger(default=50, limits = (0, 9999))
872         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_DISEQC_RESET_CMD, configElement.value))
873         config.sec.delay_after_diseqc_reset_cmd = x
874
875         x = ConfigInteger(default=150, limits = (0, 9999))
876         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD, configElement.value))
877         config.sec.delay_after_diseqc_peripherial_poweron_cmd = x
878
879 # TODO add support for satpos depending nims to advanced nim configuration
880 # so a second/third/fourth cable from a motorized lnb can used behind a
881 # diseqc 1.0 / diseqc 1.1 / toneburst switch
882 # the C(++) part should can handle this
883 # the configElement should be only visible when diseqc 1.2 is disabled
884
885 def InitNimManager(nimmgr):
886         InitSecParams()
887         hw = HardwareInfo()
888
889         config.Nims = ConfigSubList()
890         for x in range(len(nimmgr.nim_slots)):
891                 config.Nims.append(ConfigSubsection())
892
893         for slot in nimmgr.nim_slots:
894                 x = slot.slot
895                 nim = config.Nims[x]
896                 
897                 if slot.isCompatible("DVB-S"):
898                         choices = { "nothing": _("nothing connected"),
899                                         "simple": _("simple"),
900                                         "advanced": _("advanced")}
901                         if len(nimmgr.getNimListOfType(slot.type, exception = x)) > 0:
902                                 choices["equal"] = _("equal to")
903                                 choices["satposdepends"] = _("second cable of motorized LNB")
904                         if len(nimmgr.canConnectTo(x)) > 0:
905                                 choices["loopthrough"] = _("loopthrough to")
906                         nim.configMode = ConfigSelection(choices = choices, default = "nothing")
907
908 #                       for y in nimmgr.nim_slots:
909 #                               if y.slot == 0:
910 #                                       if not y.isCompatible("DVB-S"):
911 #                                               # reset to simple
912 #                                               nim.configMode.value = "simple"
913 #                                               nim.configMode.save()
914
915                         nim.diseqc13V = ConfigYesNo(default = False)
916
917                         nim.diseqcMode = ConfigSelection(
918                                 choices = [
919                                         ("single", _("Single")),
920                                         ("toneburst_a_b", _("Toneburst A/B")),
921                                         ("diseqc_a_b", _("DiSEqC A/B")),
922                                         ("diseqc_a_b_c_d", _("DiSEqC A/B/C/D")),
923                                         ("positioner", _("Positioner"))],
924                                 default = "diseqc_a_b")
925
926                         choices = []
927                         for id in nimmgr.getNimListOfType("DVB-S"):
928                                 if id != x:
929                                         choices.append((str(id), nimmgr.getNimDescription(id)))
930                         nim.connectedTo = ConfigSelection(choices = choices)
931                         nim.simpleSingleSendDiSEqC = ConfigYesNo(default=False)
932                         nim.simpleDiSEqCSetVoltageTone = ConfigYesNo(default=True)
933                         nim.simpleDiSEqCOnlyOnSatChange = ConfigYesNo(default=False)
934                         nim.diseqcA = getConfigSatlist(192, [(3601, _('nothing connected'), 1)] + nimmgr.satList)
935                         nim.diseqcB = getConfigSatlist(130, [(3601, _('nothing connected'), 1)] + nimmgr.satList)
936                         nim.diseqcC = ConfigSatlist(list = [(3601, _('nothing connected'), 1)] + nimmgr.satList)
937                         nim.diseqcD = ConfigSatlist(list = [(3601, _('nothing connected'), 1)] + nimmgr.satList)
938                         nim.positionerMode = ConfigSelection(
939                                 choices = [
940                                         ("usals", _("USALS")),
941                                         ("manual", _("manual"))],
942                                 default = "usals")
943                         nim.longitude = ConfigFloat(default=[5,100], limits=[(0,359),(0,999)])
944                         nim.longitudeOrientation = ConfigSelection(choices={"east": _("East"), "west": _("West")}, default = "east")
945                         nim.latitude = ConfigFloat(default=[50,767], limits=[(0,359),(0,999)])
946                         nim.latitudeOrientation = ConfigSelection(choices={"north": _("North"), "south": _("South")}, default="north")
947                         nim.powerMeasurement = ConfigYesNo(default=True)
948                         nim.powerThreshold = ConfigInteger(default=hw.get_device_name() == "dm8000" and 15 or 50, limits=(0, 100))
949                         nim.turningSpeed = ConfigSelection(choices = [("fast", _("Fast")), ("slow", _("Slow")), ("fast epoch", _("Fast epoch")) ], default = "fast")
950                         btime = datetime(1970, 1, 1, 7, 0);
951                         nim.fastTurningBegin = ConfigDateTime(default = mktime(btime.timetuple()), formatstring = _("%H:%M"), increment = 900)
952                         etime = datetime(1970, 1, 1, 19, 0);
953                         nim.fastTurningEnd = ConfigDateTime(default = mktime(etime.timetuple()), formatstring = _("%H:%M"), increment = 900)
954
955                         # advanced config:
956                         nim.advanced = ConfigSubsection()
957                         tmp = [(3601, _('All Satellites')+' 1', 1), (3602, _('All Satellites')+' 2', 1), (3603, _('All Satellites')+' 3', 1), (3604, _('All Satellites')+' 4', 1)]
958                         nim.advanced.sats = getConfigSatlist(192,nimmgr.satList+tmp)
959                         nim.advanced.sat = ConfigSubDict()
960                         lnbs = [("0", "not available")]
961                         for y in range(1, 33):
962                                 lnbs.append((str(y), "LNB " + str(y)))
963
964                         for x in nimmgr.satList:
965                                 nim.advanced.sat[x[0]] = ConfigSubsection()
966                                 nim.advanced.sat[x[0]].voltage = ConfigSelection(choices={"polarization": _("Polarization"), "13V": _("13 V"), "18V": _("18 V")}, default = "polarization")
967                                 nim.advanced.sat[x[0]].tonemode = ConfigSelection(choices={"band": _("Band"), "on": _("On"), "off": _("Off")}, default = "band")
968                                 nim.advanced.sat[x[0]].usals = ConfigYesNo(default=True)
969                                 nim.advanced.sat[x[0]].rotorposition = ConfigInteger(default=1, limits=(1, 255))
970                                 nim.advanced.sat[x[0]].lnb = ConfigSelection(choices = lnbs)
971
972                         for x in range(3601, 3605):
973                                 nim.advanced.sat[x] = ConfigSubsection()
974                                 nim.advanced.sat[x].voltage = ConfigSelection(choices={"polarization": _("Polarization"), "13V": _("13 V"), "18V": _("18 V")}, default = "polarization")
975                                 nim.advanced.sat[x].tonemode = ConfigSelection(choices={"band": _("Band"), "on": _("On"), "off": _("Off")}, default = "band")
976                                 nim.advanced.sat[x].usals = ConfigYesNo(default=True)
977                                 nim.advanced.sat[x].rotorposition = ConfigInteger(default=1, limits=(1, 255))
978                                 lnbnum = 33+x-3601
979                                 nim.advanced.sat[x].lnb = ConfigSelection(choices = [("0", "not available"), (str(lnbnum), "LNB %d"%(lnbnum))], default="0")
980
981                         csw = [("none", _("None")), ("AA", _("AA")), ("AB", _("AB")), ("BA", _("BA")), ("BB", _("BB"))]
982                         for y in range(0, 16):
983                                 csw.append((str(0xF0|y), "Input " + str(y+1)))
984
985                         ucsw = [("0", _("None"))]
986                         for y in range(1, 17):
987                                 ucsw.append((str(y), "Input " + str(y)))
988
989                         nim.advanced.lnb = ConfigSubList()
990                         nim.advanced.lnb.append(ConfigNothing())
991                         for x in range(1, 37):
992                                 nim.advanced.lnb.append(ConfigSubsection())
993                                 nim.advanced.lnb[x].lof = ConfigSelection(choices={"universal_lnb": _("Universal LNB"), "c_band": _("C-Band"), "user_defined": _("User defined")}, default="universal_lnb")
994                                 nim.advanced.lnb[x].lofl = ConfigInteger(default=9750, limits = (0, 99999))
995                                 nim.advanced.lnb[x].lofh = ConfigInteger(default=10600, limits = (0, 99999))
996                                 nim.advanced.lnb[x].threshold = ConfigInteger(default=11700, limits = (0, 99999))
997 #                               nim.advanced.lnb[x].output_12v = ConfigSelection(choices = [("0V", _("0 V")), ("12V", _("12 V"))], default="0V")
998                                 nim.advanced.lnb[x].increased_voltage = ConfigYesNo(default=False)
999                                 nim.advanced.lnb[x].toneburst = ConfigSelection(choices = [("none", _("None")), ("A", _("A")), ("B", _("B"))], default = "none")
1000                                 if x > 32:
1001                                         nim.advanced.lnb[x].diseqcMode = ConfigSelection(choices = [("1_2", _("1.2"))], default = "1_2")
1002                                 else:
1003                                         nim.advanced.lnb[x].diseqcMode = ConfigSelection(choices = [("none", _("None")), ("1_0", _("1.0")), ("1_1", _("1.1")), ("1_2", _("1.2"))], default = "none")
1004                                 nim.advanced.lnb[x].commitedDiseqcCommand = ConfigSelection(choices = csw)
1005                                 nim.advanced.lnb[x].fastDiseqc = ConfigYesNo(default=False)
1006                                 nim.advanced.lnb[x].sequenceRepeat = ConfigYesNo(default=False)
1007                                 nim.advanced.lnb[x].commandOrder1_0 = ConfigSelection(choices = [("ct", "committed, toneburst"), ("tc", "toneburst, committed")], default = "ct")
1008                                 nim.advanced.lnb[x].commandOrder = ConfigSelection(choices = [
1009                                                 ("ct", "committed, toneburst"),
1010                                                 ("tc", "toneburst, committed"),
1011                                                 ("cut", "committed, uncommitted, toneburst"),
1012                                                 ("tcu", "toneburst, committed, uncommitted"),
1013                                                 ("uct", "uncommitted, committed, toneburst"),
1014                                                 ("tuc", "toneburst, uncommitted, commmitted")],
1015                                                 default="ct")
1016                                 nim.advanced.lnb[x].uncommittedDiseqcCommand = ConfigSelection(choices = ucsw)
1017                                 nim.advanced.lnb[x].diseqcRepeats = ConfigSelection(choices = [("none", _("None")), ("one", _("One")), ("two", _("Two")), ("three", _("Three"))], default = "none")
1018                                 nim.advanced.lnb[x].longitude = ConfigFloat(default = [5,100], limits = [(0,359),(0,999)])
1019                                 nim.advanced.lnb[x].longitudeOrientation = ConfigSelection(choices = [("east", _("East")), ("west", _("West"))], default = "east")
1020                                 nim.advanced.lnb[x].latitude = ConfigFloat(default = [50,767], limits = [(0,359),(0,999)])
1021                                 nim.advanced.lnb[x].latitudeOrientation = ConfigSelection(choices = [("north", _("North")), ("south", _("South"))], default = "north")
1022                                 nim.advanced.lnb[x].powerMeasurement = ConfigYesNo(default=True)
1023                                 nim.advanced.lnb[x].powerThreshold = ConfigInteger(default=hw.get_device_name() == "dm8000" and 15 or 50, limits=(0, 100))
1024                                 nim.advanced.lnb[x].turningSpeed = ConfigSelection(choices = [("fast", _("Fast")), ("slow", _("Slow")), ("fast epoch", _("Fast epoch"))], default = "fast")
1025                                 btime = datetime(1970, 1, 1, 7, 0);
1026                                 nim.advanced.lnb[x].fastTurningBegin = ConfigDateTime(default=mktime(btime.timetuple()), formatstring = _("%H:%M"), increment = 600)
1027                                 etime = datetime(1970, 1, 1, 19, 0);
1028                                 nim.advanced.lnb[x].fastTurningEnd = ConfigDateTime(default=mktime(etime.timetuple()), formatstring = _("%H:%M"), increment = 600)
1029                 elif slot.isCompatible("DVB-C"):
1030                         nim.configMode = ConfigSelection(
1031                                 choices = {
1032                                         "enabled": _("enabled"),
1033                                         "nothing": _("nothing connected"),
1034                                         },
1035                                 default = "enabled")
1036                         list = [ ]
1037                         n = 0
1038                         for x in nimmgr.cablesList:
1039                                 list.append((str(n), x[0]))
1040                                 n += 1
1041                         nim.cable = ConfigSubsection()
1042                         possible_scan_types = [("bands", _("Frequency bands")), ("steps", _("Frequency steps"))]
1043                         if n:
1044                                 possible_scan_types.append(("provider", _("Provider")))
1045                                 nim.cable.scan_provider = ConfigSelection(default = "0", choices = list)
1046                         nim.cable.scan_type = ConfigSelection(default = "bands", choices = possible_scan_types)
1047                         nim.cable.scan_band_EU_VHF_I = ConfigYesNo(default = True)
1048                         nim.cable.scan_band_EU_MID = ConfigYesNo(default = True)
1049                         nim.cable.scan_band_EU_VHF_III = ConfigYesNo(default = True)
1050                         nim.cable.scan_band_EU_UHF_IV = ConfigYesNo(default = True)
1051                         nim.cable.scan_band_EU_UHF_V = ConfigYesNo(default = True)
1052                         nim.cable.scan_band_EU_SUPER = ConfigYesNo(default = True)
1053                         nim.cable.scan_band_EU_HYPER = ConfigYesNo(default = True)
1054                         nim.cable.scan_band_US_LOW = ConfigYesNo(default = False)
1055                         nim.cable.scan_band_US_MID = ConfigYesNo(default = False)
1056                         nim.cable.scan_band_US_HIGH = ConfigYesNo(default = False)
1057                         nim.cable.scan_band_US_SUPER = ConfigYesNo(default = False)
1058                         nim.cable.scan_band_US_HYPER = ConfigYesNo(default = False)
1059                         nim.cable.scan_frequency_steps = ConfigInteger(default = 1000, limits = (1000, 10000))
1060                         nim.cable.scan_mod_qam16 = ConfigYesNo(default = False)
1061                         nim.cable.scan_mod_qam32 = ConfigYesNo(default = False)
1062                         nim.cable.scan_mod_qam64 = ConfigYesNo(default = True)
1063                         nim.cable.scan_mod_qam128 = ConfigYesNo(default = False)
1064                         nim.cable.scan_mod_qam256 = ConfigYesNo(default = True)
1065                         nim.cable.scan_sr_6900 = ConfigYesNo(default = True)
1066                         nim.cable.scan_sr_6875 = ConfigYesNo(default = True)
1067                         nim.cable.scan_sr_ext1 = ConfigInteger(default = 0, limits = (0, 7230))
1068                         nim.cable.scan_sr_ext2 = ConfigInteger(default = 0, limits = (0, 7230))
1069                 elif slot.isCompatible("DVB-T"):
1070                         nim.configMode = ConfigSelection(
1071                                 choices = {
1072                                         "enabled": _("enabled"),
1073                                         "nothing": _("nothing connected"),
1074                                         },
1075                                 default = "enabled")
1076                         list = []
1077                         n = 0
1078                         for x in nimmgr.terrestrialsList:
1079                                 list.append((str(n), x[0]))
1080                                 n += 1
1081                         nim.terrestrial = ConfigSelection(choices = list)
1082                         nim.terrestrial_5V = ConfigOnOff()
1083                 else:
1084                         nim.configMode = ConfigSelection(choices = { "nothing": _("disabled") }, default="nothing");
1085                         if slot.type is not None:
1086                                 print "pls add support for this frontend type!", slot.type
1087 #                       assert False
1088
1089         nimmgr.sec = SecConfigure(nimmgr)
1090
1091 nimmanager = NimManager()