add possibility to select "second cable of motorized LNB" also when the rotor is...
[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 not nimHaveRotor:
687                                         for sat in mode.advanced.sat.values():
688                                                 lnb_num = int(sat.lnb.value)
689                                                 diseqcmode = lnb_num and mode.advanced.lnb[lnb_num].diseqcMode.value or ""
690                                                 if diseqcmode == "1_2":
691                                                         nimHaveRotor = True
692                                                         break
693                         if nimHaveRotor:
694                                 alreadyConnected = False
695                                 for testnim in nimList:
696                                         testmode = self.getNimConfig(testnim)
697                                         if testmode.configMode.value == "satposdepends" and int(testmode.connectedTo.value) == int(nim):
698                                                 alreadyConnected = True
699                                                 break
700                                 if not alreadyConnected:
701                                         positionerList.append(nim)
702                 return positionerList
703         
704         def getNimConfig(self, slotid):
705                 return config.Nims[slotid]
706         
707         def getSatName(self, pos):
708                 for sat in self.satList:
709                         if sat[0] == pos:
710                                 return sat[1]
711                 return _("N/A")
712
713         def getSatList(self):
714                 return self.satList
715
716         def getSatListForNim(self, slotid):
717                 list = []
718                 if self.nim_slots[slotid].isCompatible("DVB-S"):
719                         nim = config.Nims[slotid]
720                         #print "slotid:", slotid
721
722                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.index]
723                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
724                         configMode = nim.configMode.value
725
726                         if configMode == "equal":
727                                 slotid = int(nim.connectedTo.value)
728                                 nim = config.Nims[slotid]
729                                 configMode = nim.configMode.value
730                         elif configMode == "loopthrough":
731                                 slotid = self.sec.getRoot(slotid, int(nim.connectedTo.value))
732                                 nim = config.Nims[slotid]
733                                 configMode = nim.configMode.value
734
735                         if configMode == "simple":
736                                 dm = nim.diseqcMode.value
737                                 if dm in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
738                                         list.append(self.satList[nim.diseqcA.index])
739                                 if dm in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
740                                         list.append(self.satList[nim.diseqcB.index])
741                                 if dm == "diseqc_a_b_c_d":
742                                         list.append(self.satList[nim.diseqcC.index])
743                                         list.append(self.satList[nim.diseqcD.index])
744                                 if dm == "positioner":
745                                         for x in self.satList:
746                                                 list.append(x)
747                         elif configMode == "advanced":
748                                 for x in range(3601, 3605):
749                                         if int(nim.advanced.sat[x].lnb.value) != 0:
750                                                 for x in self.satList:
751                                                         list.append(x)
752                                 if not list:
753                                         for x in self.satList:
754                                                 if int(nim.advanced.sat[x[0]].lnb.value) != 0:
755                                                         list.append(x)
756                 return list
757
758         def getRotorSatListForNim(self, slotid):
759                 list = []
760                 if self.nim_slots[slotid].isCompatible("DVB-S"):
761                         #print "slotid:", slotid
762                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
763                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
764                         configMode = config.Nims[slotid].configMode.value
765                         if configMode == "simple":
766                                 if config.Nims[slotid].diseqcMode.value == "positioner":
767                                         for x in self.satList:
768                                                 list.append(x)
769                         elif configMode == "advanced":
770                                 nim = config.Nims[slotid]
771                                 for x in range(3601, 3605):
772                                         if int(nim.advanced.sat[x].lnb.value) != 0:
773                                                 for x in self.satList:
774                                                         list.append(x)
775                                 if not list:
776                                         for x in self.satList:
777                                                 lnbnum = int(nim.advanced.sat[x[0]].lnb.value)
778                                                 if lnbnum != 0:
779                                                         lnb = nim.advanced.lnb[lnbnum]
780                                                         if lnb.diseqcMode.value == "1_2":
781                                                                 list.append(x)
782                 return list
783
784 def InitSecParams():
785         config.sec = ConfigSubsection()
786
787         x = ConfigInteger(default=15, limits = (0, 9999))
788         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_CONT_TONE, configElement.value))
789         config.sec.delay_after_continuous_tone_change = x
790
791         x = ConfigInteger(default=10, limits = (0, 9999))
792         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_FINAL_VOLTAGE_CHANGE, configElement.value))
793         config.sec.delay_after_final_voltage_change = x
794
795         x = ConfigInteger(default=120, limits = (0, 9999))
796         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BETWEEN_DISEQC_REPEATS, configElement.value))
797         config.sec.delay_between_diseqc_repeats = x
798
799         x = ConfigInteger(default=50, limits = (0, 9999))
800         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_LAST_DISEQC_CMD, configElement.value))
801         config.sec.delay_after_last_diseqc_command = x
802
803         x = ConfigInteger(default=50, limits = (0, 9999))
804         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_TONEBURST, configElement.value))
805         config.sec.delay_after_toneburst = x
806
807         x = ConfigInteger(default=20, limits = (0, 9999))
808         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS, configElement.value))
809         config.sec.delay_after_change_voltage_before_switch_command = x
810
811         x = ConfigInteger(default=200, limits = (0, 9999))
812         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS, configElement.value))
813         config.sec.delay_after_enable_voltage_before_switch_command = x
814
815         x = ConfigInteger(default=700, limits = (0, 9999))
816         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD, configElement.value))
817         config.sec.delay_between_switch_and_motor_command = x
818
819         x = ConfigInteger(default=500, limits = (0, 9999))
820         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER, configElement.value))
821         config.sec.delay_after_voltage_change_before_measure_idle_inputpower = x
822
823         x = ConfigInteger(default=750, limits = (0, 9999))
824         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD, configElement.value))
825         config.sec.delay_after_enable_voltage_before_motor_command = x
826
827         x = ConfigInteger(default=500, limits = (0, 9999))
828         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_MOTOR_STOP_CMD, configElement.value))
829         config.sec.delay_after_motor_stop_command = x
830
831         x = ConfigInteger(default=500, limits = (0, 9999))
832         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD, configElement.value))
833         config.sec.delay_after_voltage_change_before_motor_command = x
834
835         x = ConfigInteger(default=70, limits = (0, 9999))
836         x.addNotifier(lambda configElement: secClass.setParam(secClass.DELAY_BEFORE_SEQUENCE_REPEAT, configElement.value))
837         config.sec.delay_before_sequence_repeat = x
838
839         x = ConfigInteger(default=360, limits = (0, 9999))
840         x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_RUNNING_TIMEOUT, configElement.value))
841         config.sec.motor_running_timeout = x
842
843         x = ConfigInteger(default=1, limits = (0, 5))
844         x.addNotifier(lambda configElement: secClass.setParam(secClass.MOTOR_COMMAND_RETRIES, configElement.value))
845         config.sec.motor_command_retries = x
846
847 # TODO add support for satpos depending nims to advanced nim configuration
848 # so a second/third/fourth cable from a motorized lnb can used behind a
849 # diseqc 1.0 / diseqc 1.1 / toneburst switch
850 # the C(++) part should can handle this
851 # the configElement should be only visible when diseqc 1.2 is disabled
852
853 def InitNimManager(nimmgr):
854         InitSecParams()
855         hw = HardwareInfo()
856
857         config.Nims = ConfigSubList()
858         for x in range(len(nimmgr.nim_slots)):
859                 config.Nims.append(ConfigSubsection())
860
861         for slot in nimmgr.nim_slots:
862                 x = slot.slot
863                 nim = config.Nims[x]
864                 
865                 if slot.isCompatible("DVB-S"):
866                         choices = { "nothing": _("nothing connected"),
867                                         "simple": _("simple"),
868                                         "advanced": _("advanced")}
869                         if len(nimmgr.getNimListOfType(slot.type, exception = x)) > 0:
870                                 choices["equal"] = _("equal to")
871                                 choices["satposdepends"] = _("second cable of motorized LNB")
872                         if len(nimmgr.canConnectTo(x)) > 0:
873                                 choices["loopthrough"] = _("loopthrough to")
874                         nim.configMode = ConfigSelection(choices = choices, default = "nothing")
875
876 #                       for y in nimmgr.nim_slots:
877 #                               if y.slot == 0:
878 #                                       if not y.isCompatible("DVB-S"):
879 #                                               # reset to simple
880 #                                               nim.configMode.value = "simple"
881 #                                               nim.configMode.save()
882
883                         nim.diseqcMode = ConfigSelection(
884                                 choices = [
885                                         ("single", _("Single")),
886                                         ("toneburst_a_b", _("Toneburst A/B")),
887                                         ("diseqc_a_b", _("DiSEqC A/B")),
888                                         ("diseqc_a_b_c_d", _("DiSEqC A/B/C/D")),
889                                         ("positioner", _("Positioner"))],
890                                 default = "diseqc_a_b")
891
892                         choices = []
893                         for id in nimmgr.getNimListOfType("DVB-S"):
894                                 if id != x:
895                                         choices.append((str(id), nimmgr.getNimDescription(id)))
896                         nim.connectedTo = ConfigSelection(choices = choices)
897                         nim.diseqcA = getConfigSatlist(192, nimmgr.satList)
898                         nim.diseqcB = getConfigSatlist(130, nimmgr.satList)
899                         nim.diseqcC = ConfigSatlist(list = nimmgr.satList)
900                         nim.diseqcD = ConfigSatlist(list = nimmgr.satList)
901                         nim.positionerMode = ConfigSelection(
902                                 choices = [
903                                         ("usals", _("USALS")),
904                                         ("manual", _("manual"))],
905                                 default = "usals")
906                         nim.longitude = ConfigFloat(default=[5,100], limits=[(0,359),(0,999)])
907                         nim.longitudeOrientation = ConfigSelection(choices={"east": _("East"), "west": _("West")}, default = "east")
908                         nim.latitude = ConfigFloat(default=[50,767], limits=[(0,359),(0,999)])
909                         nim.latitudeOrientation = ConfigSelection(choices={"north": _("North"), "south": _("South")}, default="north")
910                         nim.powerMeasurement = ConfigYesNo(default=True)
911                         nim.powerThreshold = ConfigInteger(default=50, limits=(0, 100))
912                         nim.turningSpeed = ConfigSelection(choices = [("fast", _("Fast")), ("slow", _("Slow")), ("fast epoch", _("Fast epoch")) ], default = "fast")
913                         btime = datetime(1970, 1, 1, 7, 0);
914                         nim.fastTurningBegin = ConfigDateTime(default = mktime(btime.timetuple()), formatstring = _("%H:%M"), increment = 900)
915                         etime = datetime(1970, 1, 1, 19, 0);
916                         nim.fastTurningEnd = ConfigDateTime(default = mktime(etime.timetuple()), formatstring = _("%H:%M"), increment = 900)
917
918                         # advanced config:
919                         nim.advanced = ConfigSubsection()
920                         tmp = [(3601, _('All Satellites')+' 1', 1), (3602, _('All Satellites')+' 2', 1), (3603, _('All Satellites')+' 3', 1), (3604, _('All Satellites')+' 4', 1)]
921                         nim.advanced.sats = getConfigSatlist(192,nimmgr.satList+tmp)
922                         nim.advanced.sat = ConfigSubDict()
923                         lnbs = [("0", "not available")]
924                         for y in range(1, 33):
925                                 lnbs.append((str(y), "LNB " + str(y)))
926
927                         for x in nimmgr.satList:
928                                 nim.advanced.sat[x[0]] = ConfigSubsection()
929                                 nim.advanced.sat[x[0]].voltage = ConfigSelection(choices={"polarization": _("Polarization"), "13V": _("13 V"), "18V": _("18 V")}, default = "polarization")
930                                 nim.advanced.sat[x[0]].tonemode = ConfigSelection(choices={"band": _("Band"), "on": _("On"), "off": _("Off")}, default = "band")
931                                 nim.advanced.sat[x[0]].usals = ConfigYesNo(default=True)
932                                 nim.advanced.sat[x[0]].rotorposition = ConfigInteger(default=1, limits=(1, 255))
933                                 nim.advanced.sat[x[0]].lnb = ConfigSelection(choices = lnbs)
934
935                         for x in range(3601, 3605):
936                                 nim.advanced.sat[x] = ConfigSubsection()
937                                 nim.advanced.sat[x].voltage = ConfigSelection(choices={"polarization": _("Polarization"), "13V": _("13 V"), "18V": _("18 V")}, default = "polarization")
938                                 nim.advanced.sat[x].tonemode = ConfigSelection(choices={"band": _("Band"), "on": _("On"), "off": _("Off")}, default = "band")
939                                 nim.advanced.sat[x].usals = ConfigYesNo(default=True)
940                                 nim.advanced.sat[x].rotorposition = ConfigInteger(default=1, limits=(1, 255))
941                                 lnbnum = 33+x-3601
942                                 nim.advanced.sat[x].lnb = ConfigSelection(choices = [("0", "not available"), (str(lnbnum), "LNB %d"%(lnbnum))], default="0")
943
944                         csw = [("none", _("None")), ("AA", _("AA")), ("AB", _("AB")), ("BA", _("BA")), ("BB", _("BB"))]
945                         for y in range(0, 16):
946                                 csw.append((str(0xF0|y), "Input " + str(y+1)))
947
948                         ucsw = [("0", _("None"))]
949                         for y in range(1, 17):
950                                 ucsw.append((str(y), "Input " + str(y)))
951
952                         nim.advanced.lnb = ConfigSubList()
953                         nim.advanced.lnb.append(ConfigNothing())
954                         for x in range(1, 37):
955                                 nim.advanced.lnb.append(ConfigSubsection())
956                                 nim.advanced.lnb[x].lof = ConfigSelection(choices={"universal_lnb": _("Universal LNB"), "c_band": _("C-Band"), "user_defined": _("User defined")}, default="universal_lnb")
957                                 nim.advanced.lnb[x].lofl = ConfigInteger(default=9750, limits = (0, 99999))
958                                 nim.advanced.lnb[x].lofh = ConfigInteger(default=10600, limits = (0, 99999))
959                                 nim.advanced.lnb[x].threshold = ConfigInteger(default=11700, limits = (0, 99999))
960 #                               nim.advanced.lnb[x].output_12v = ConfigSelection(choices = [("0V", _("0 V")), ("12V", _("12 V"))], default="0V")
961                                 nim.advanced.lnb[x].increased_voltage = ConfigYesNo(default=False)
962                                 nim.advanced.lnb[x].toneburst = ConfigSelection(choices = [("none", _("None")), ("A", _("A")), ("B", _("B"))], default = "none")
963                                 if x > 32:
964                                         nim.advanced.lnb[x].diseqcMode = ConfigSelection(choices = [("1_2", _("1.2"))], default = "1_2")
965                                 else:
966                                         nim.advanced.lnb[x].diseqcMode = ConfigSelection(choices = [("none", _("None")), ("1_0", _("1.0")), ("1_1", _("1.1")), ("1_2", _("1.2"))], default = "none")
967                                 nim.advanced.lnb[x].commitedDiseqcCommand = ConfigSelection(choices = csw)
968                                 nim.advanced.lnb[x].fastDiseqc = ConfigYesNo(default=False)
969                                 nim.advanced.lnb[x].sequenceRepeat = ConfigYesNo(default=False)
970                                 nim.advanced.lnb[x].commandOrder1_0 = ConfigSelection(choices = [("ct", "committed, toneburst"), ("tc", "toneburst, committed")], default = "ct")
971                                 nim.advanced.lnb[x].commandOrder = ConfigSelection(choices = [
972                                                 ("ct", "committed, toneburst"),
973                                                 ("tc", "toneburst, committed"),
974                                                 ("cut", "committed, uncommitted, toneburst"),
975                                                 ("tcu", "toneburst, committed, uncommitted"),
976                                                 ("uct", "uncommitted, committed, toneburst"),
977                                                 ("tuc", "toneburst, uncommitted, commmitted")],
978                                                 default="ct")
979                                 nim.advanced.lnb[x].uncommittedDiseqcCommand = ConfigSelection(choices = ucsw)
980                                 nim.advanced.lnb[x].diseqcRepeats = ConfigSelection(choices = [("none", _("None")), ("one", _("One")), ("two", _("Two")), ("three", _("Three"))], default = "none")
981                                 nim.advanced.lnb[x].longitude = ConfigFloat(default = [5,100], limits = [(0,359),(0,999)])
982                                 nim.advanced.lnb[x].longitudeOrientation = ConfigSelection(choices = [("east", _("East")), ("west", _("West"))], default = "east")
983                                 nim.advanced.lnb[x].latitude = ConfigFloat(default = [50,767], limits = [(0,359),(0,999)])
984                                 nim.advanced.lnb[x].latitudeOrientation = ConfigSelection(choices = [("north", _("North")), ("south", _("South"))], default = "north")
985                                 nim.advanced.lnb[x].powerMeasurement = ConfigYesNo(default=True)
986                                 nim.advanced.lnb[x].powerThreshold = ConfigInteger(default=hw.get_device_name() == "dm8000" and 15 or 50, limits=(0, 100))
987                                 nim.advanced.lnb[x].turningSpeed = ConfigSelection(choices = [("fast", _("Fast")), ("slow", _("Slow")), ("fast epoch", _("Fast epoch"))], default = "fast")
988                                 btime = datetime(1970, 1, 1, 7, 0);
989                                 nim.advanced.lnb[x].fastTurningBegin = ConfigDateTime(default=mktime(btime.timetuple()), formatstring = _("%H:%M"), increment = 600)
990                                 etime = datetime(1970, 1, 1, 19, 0);
991                                 nim.advanced.lnb[x].fastTurningEnd = ConfigDateTime(default=mktime(etime.timetuple()), formatstring = _("%H:%M"), increment = 600)
992                 elif slot.isCompatible("DVB-C"):
993                         nim.configMode = ConfigSelection(
994                                 choices = {
995                                         "enabled": _("enabled"),
996                                         "nothing": _("nothing connected"),
997                                         },
998                                 default = "enabled")
999                         list = [ ]
1000                         n = 0
1001                         for x in nimmgr.cablesList:
1002                                 list.append((str(n), x[0]))
1003                                 n += 1
1004                         nim.cable = ConfigSubsection()
1005                         possible_scan_types = [("bands", _("Frequency bands")), ("steps", _("Frequency steps"))]
1006                         if n:
1007                                 possible_scan_types.append(("provider", _("Provider")))
1008                                 nim.cable.scan_provider = ConfigSelection(default = "0", choices = list)
1009                         nim.cable.scan_type = ConfigSelection(default = "bands", choices = possible_scan_types)
1010                         nim.cable.scan_band_EU_VHF_I = ConfigYesNo(default = True)
1011                         nim.cable.scan_band_EU_MID = ConfigYesNo(default = True)
1012                         nim.cable.scan_band_EU_VHF_III = ConfigYesNo(default = True)
1013                         nim.cable.scan_band_EU_UHF_IV = ConfigYesNo(default = True)
1014                         nim.cable.scan_band_EU_UHF_V = ConfigYesNo(default = True)
1015                         nim.cable.scan_band_EU_SUPER = ConfigYesNo(default = True)
1016                         nim.cable.scan_band_EU_HYPER = ConfigYesNo(default = True)
1017                         nim.cable.scan_band_US_LOW = ConfigYesNo(default = False)
1018                         nim.cable.scan_band_US_MID = ConfigYesNo(default = False)
1019                         nim.cable.scan_band_US_HIGH = ConfigYesNo(default = False)
1020                         nim.cable.scan_band_US_SUPER = ConfigYesNo(default = False)
1021                         nim.cable.scan_band_US_HYPER = ConfigYesNo(default = False)
1022                         nim.cable.scan_frequency_steps = ConfigInteger(default = 1000, limits = (1000, 10000))
1023                         nim.cable.scan_mod_qam16 = ConfigYesNo(default = False)
1024                         nim.cable.scan_mod_qam32 = ConfigYesNo(default = False)
1025                         nim.cable.scan_mod_qam64 = ConfigYesNo(default = True)
1026                         nim.cable.scan_mod_qam128 = ConfigYesNo(default = False)
1027                         nim.cable.scan_mod_qam256 = ConfigYesNo(default = True)
1028                         nim.cable.scan_sr_6900 = ConfigYesNo(default = True)
1029                         nim.cable.scan_sr_6875 = ConfigYesNo(default = True)
1030                         nim.cable.scan_sr_ext1 = ConfigInteger(default = 0, limits = (0, 7230))
1031                         nim.cable.scan_sr_ext2 = ConfigInteger(default = 0, limits = (0, 7230))
1032                 elif slot.isCompatible("DVB-T"):
1033                         nim.configMode = ConfigSelection(
1034                                 choices = {
1035                                         "enabled": _("enabled"),
1036                                         "nothing": _("nothing connected"),
1037                                         },
1038                                 default = "enabled")
1039                         list = []
1040                         n = 0
1041                         for x in nimmgr.terrestrialsList:
1042                                 list.append((str(n), x[0]))
1043                                 n += 1
1044                         nim.terrestrial = ConfigSelection(choices = list)
1045                         nim.terrestrial_5V = ConfigOnOff()
1046                 else:
1047                         nim.configMode = ConfigSelection(choices = { "nothing": _("disabled") }, default="nothing");
1048                         if slot.type is not None:
1049                                 print "pls add support for this frontend type!", slot.type
1050 #                       assert False
1051
1052         nimmgr.sec = SecConfigure(nimmgr)
1053
1054 nimmanager = NimManager()