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