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