2b62b8d44325f8897c1e9075d6da514924d1fb6a
[enigma2.git] / lib / python / Components / NimManager.py
1 from config import config       #global config instance
2
3 from config import configElement
4 from config import ConfigSubsection
5 from config import ConfigSlider
6 from config import configSelection
7 from config import currentConfigSelectionElement
8 from config import getConfigSelectionElement
9 from config import configSequence
10 from config import configsequencearg
11 from config import configSatlist
12
13 from enigma import *
14
15 import xml.dom.minidom
16 from xml.dom import EMPTY_NAMESPACE
17 from skin import elementsWithTag
18 from Tools import XMLTools
19
20 from xml.sax import make_parser
21 from xml.sax.handler import ContentHandler
22
23 from Tools.BoundFunction import boundFunction
24
25 def tryOpen(filename):
26         try:
27                 procFile = open(filename)
28         except IOError:
29                 return ""
30         return procFile
31
32 class SecConfigure:
33         def addLNBSimple(self, slotid, diseqcmode, toneburstmode = 0, diseqcpos = 0, orbpos = 0, longitude = 0, latitude = 0, loDirection = 0, laDirection = 0):
34                 #simple defaults
35                 sec = eDVBSatelliteEquipmentControl.getInstance()
36                 sec.addLNB()
37                 sec.setLNBTunerMask(1 << slotid)
38                 sec.setLNBLOFL(9750000)
39                 sec.setLNBLOFH(10600000)
40                 sec.setLNBThreshold(11750000)
41                 sec.setRepeats(0)
42                 sec.setFastDiSEqC(0)
43                 sec.setSeqRepeat(0)
44                 sec.setVoltageMode(0) #HV
45                 sec.setToneMode(0)              #HILO
46                 sec.setCommandOrder(0)
47                 #user values
48                 sec.setDiSEqCMode(diseqcmode)
49                 sec.setToneburst(toneburstmode)
50                 sec.setCommittedCommand(diseqcpos)
51                 #print "set orbpos to:" + str(orbpos)
52
53                 if (0 <= diseqcmode < 3):
54                         sec.addSatellite(orbpos)
55                         self.satList.append(orbpos)
56                 elif (diseqcmode == 3): # diseqc 1.2
57                         sec.setLatitude(latitude)
58                         sec.setLaDirection(laDirection)
59                         sec.setLongitude(longitude)
60                         sec.setLoDirection(loDirection)
61                         sec.setUseInputpower(True)
62                         sec.setInputpowerDelta(50)
63                         
64                         for x in self.NimManager.satList:
65                                 print "Add sat " + str(x[1])
66                                 sec.addSatellite(int(x[1]))
67                                 sec.setVoltageMode(0)
68                                 sec.setToneMode(0)
69                                 self.satList.append(int(x[1]))
70                                 
71
72         def linkNIMs(self, nim1, nim2):
73                 eDVBSatelliteEquipmentControl.getInstance().setTunerLinked(nim1, nim2)
74                 
75         def getSatList(self):
76                 return self.satList
77
78         def update(self):
79                 eDVBSatelliteEquipmentControl.getInstance().clear()
80                 
81                 self.satList = []
82
83                 for slot in self.NimManager.nimslots:
84                         x = slot.slotid
85                         nim = config.Nims[x]
86                         if slot.nimType == self.NimManager.nimType["DVB-S"]:
87                                 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
88                                 if currentConfigSelectionElement(nim.configMode) == "loopthrough":
89                                         self.linkNIMs(x, nim.linkedTo.value)
90                                         nim = config.Nims[nim.linkedTo.value]
91                                 elif currentConfigSelectionElement(nim.configMode) == "simple":         #simple config
92                                         if currentConfigSelectionElement(nim.diseqcMode) == "single":                   #single
93                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 0, diseqcpos = 4)
94                                         elif currentConfigSelectionElement(nim.diseqcMode) == "toneburst_a_b":          #Toneburst A/B
95                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 1, diseqcmode = 0, diseqcpos = 4)
96                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 1, diseqcmode = 0, diseqcpos = 4)
97                                         elif currentConfigSelectionElement(nim.diseqcMode) == "diseqc_a_b":             #DiSEqC A/B
98                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 0)
99                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 1)
100                                         elif currentConfigSelectionElement(nim.diseqcMode) == "diseqc_a_b_c_d":         #DiSEqC A/B/C/D
101                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 0)
102                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 1)
103                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcC.vals[nim.diseqcC.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 2)
104                                                 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcD.vals[nim.diseqcD.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 3)
105                                         elif currentConfigSelectionElement(nim.diseqcMode) == "positioner":             #Positioner
106                                                 self.addLNBSimple(slotid = x, diseqcmode = 3, longitude = float(str(nim.longitude.value[0]) + "." + str(nim.longitude.value[1])), loDirection = nim.longitudeOrientation.value - 2, latitude = float(str(nim.latitude.value[0]) + "." + str(nim.latitude.value[1])), laDirection = nim.latitudeOrientation.value)
107                                         pass
108                                 elif currentConfigSelectionElement(nim.configMode) == "nothing":
109                                         pass
110                                 else:                                                                                                                                   #advanced config
111                                         self.updateAdvanced(x)
112
113         def updateAdvanced(self, slotid):
114                 sec = eDVBSatelliteEquipmentControl.getInstance()
115                 lnbSat = {}
116                 for x in range(1,33):
117                         lnbSat[x] = []
118                 for x in self.NimManager.satList:
119                         lnb = config.Nims[slotid].advanced.sat[x[1]].lnb.value
120                         if lnb != 0:
121                                 lnbSat[lnb].append(x[1])
122                 for x in range(1,33):
123                         if len(lnbSat[x]) > 0:
124                                 currLnb = config.Nims[slotid].advanced.lnb[x]
125                                 sec.addLNB()
126                                 sec.setLNBTunerMask(1 << slotid)
127                                 if currentConfigSelectionElement(currLnb.lof) == "universal_lnb":
128                                         sec.setLNBLOFL(9750000)
129                                         sec.setLNBLOFH(10600000)
130                                         sec.setLNBThreshold(11750000)
131                                 elif currentConfigSelectionElement(currLnb.lof) == "c_band":
132                                         sec.setLNBLOFL(5150000)
133                                         sec.setLNBLOFH(5150000)
134                                         sec.setLNBThreshold(5150000)
135                                 elif currentConfigSelectionElement(currLnb.lof) == "user_defined":
136                                         sec.setLNBLOFL(currLnb.lofl.value * 1000)
137                                         sec.setLNBLOFH(currLnb.lofh.value * 1000)
138                                         sec.setLNBThreshold(currLnb.threshold.value * 1000)
139                                         
140                                 if currentConfigSelectionElement(currLnb.output_12v) == "0V":
141                                         pass
142                                 elif currentConfigSelectionElement(currLnb.output_12v) == "12V":
143                                         pass
144                                 
145                                 if currentConfigSelectionElement(currLnb.increased_voltage) == "yes":
146                                         pass
147                                 else:
148                                         pass
149                                 
150                                 if currentConfigSelectionElement(currLnb.diseqcMode) == "none":
151                                         pass
152                                 elif currentConfigSelectionElement(currLnb.diseqcMode) == "1_0":
153                                         pass
154                                 elif currentConfigSelectionElement(currLnb.diseqcMode) == "1_1":
155                                         pass
156                                 elif currentConfigSelectionElement(currLnb.diseqcMode) == "1_2":
157                                         pass
158
159                                 if currentConfigSelectionElement(currLnb.diseqcMode) != "none":
160                                         if currentConfigSelectionElement(currLnb.toneburst) == "none":
161                                                 pass
162                                         elif currentConfigSelectionElement(currLnb.toneburst) == "A":
163                                                 pass
164                                         elif currentConfigSelectionElement(currLnb.toneburst) == "B":
165                                                 pass
166
167
168                                         if currentConfigSelectionElement(currLnb.commitedDiseqcCommand) == "none":
169                                                 pass
170                                         elif currentConfigSelectionElement(currLnb.commitedDiseqcCommand) == "AA":
171                                                 pass
172                                         elif currentConfigSelectionElement(currLnb.commitedDiseqcCommand) == "AB":
173                                                 pass
174                                         elif currentConfigSelectionElement(currLnb.commitedDiseqcCommand) == "BA":
175                                                 pass                            
176                                         elif currentConfigSelectionElement(currLnb.commitedDiseqcCommand) == "BB":
177                                                 pass
178                                 
179                                         if currentConfigSelectionElement(currLnb.fastDiseqc) == "yes":
180                                                 pass
181                                         else:
182                                                 pass
183                                 
184                                         if currentConfigSelectionElement(currLnb.sequenceRepeat) == "yes":
185                                                 pass
186                                         else:
187                                                 pass
188                                 
189                                         if currentConfigSelectionElement(currLnb.diseqcMode) == "1_0":
190                                                 currCO = currLnb.commandOrder1_0.value
191                                         else:
192                                                 currCO = currLnb.commandOrder.value
193                                                 
194                                                 pass # do something with currLnb.uncommittedDiseqcCommand.value... holds 0 for none, 1 for input 1, 2 for input 2 etc.
195                                                 
196                                                 if currentConfigSelectionElement(currLnb.diseqcRepeats) == "none":
197                                                         pass
198                                                 elif currentConfigSelectionElement(currLnb.diseqcRepeats) == "One":
199                                                         pass
200                                                 elif currentConfigSelectionElement(currLnb.diseqcRepeats) == "Two":
201                                                         pass
202                                                 elif currentConfigSelectionElement(currLnb.diseqcRepeats) == "Three":
203                                                         pass
204                                                                                 
205                                         if currCO == 0: # committed, toneburst
206                                                 pass
207                                         elif currCO == 1: # toneburst, committed
208                                                 pass
209                                         elif currCO == 2: # committed, uncommitted, toneburst
210                                                 pass
211                                         elif currCO == 3: # toneburst, committed, uncommitted
212                                                 pass
213                                         elif currCO == 4: # uncommitted, committed, toneburst
214                                                 pass
215                                         elif currCO == 5: # toneburst, uncommitted, commmitted
216                                                 pass
217                                         
218                                 if currentConfigSelectionElement(currLnb.diseqcMode) == "1_2":
219                                         sec.setLatitude(float(str(currLnb.latitude.value[0]) + "." + str(currLnb.latitude.value[1])))
220                                         sec.setLaDirection(nim.latitudeOrientation.value)
221                                         sec.setLongitude(float(str(currLnb.longitude.value[0]) + "." + str(currLnb.longitude.value[1])))
222                                         sec.setLoDirection(nim.longitudeOrientation.value - 2)
223
224                                 if currentConfigSelectionElement(currLnb.powerMeasurement) == "yes":
225                                         pass # set to currLnb.powerThreshold.value, which is an integer holding the mA value
226         
227                                 # finally add the orbital positions
228                                 for y in lnbSat[x]:
229                                         sec.addSatellite(y)
230
231         def __init__(self, nimmgr):
232                 self.NimManager = nimmgr
233                 self.update()
234                 
235 class nimSlot:
236         def __init__(self, slotid, nimtype, name):
237                 self.slotid = slotid
238                 self.nimType = nimtype
239                 self.name = name
240
241 class NimManager:
242         class parseSats(ContentHandler):
243                 def __init__(self, satList, satellites, transponders):
244                         self.isPointsElement, self.isReboundsElement = 0, 0
245                         self.satList = satList
246                         self.satellites = satellites
247                         self.transponders = transponders
248         
249                 def startElement(self, name, attrs):
250                         if (name == "sat"):
251                                 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
252                                 tpos = int(attrs.get('position',""))
253                                 if tpos < 0:
254                                         tpos = 3600 + tpos
255                                 tname = attrs.get('name',"")
256                                 self.satellites[tpos] = tname
257                                 self.satList.append( (tname, tpos) )
258                                 self.parsedSat = int(tpos)
259                         elif (name == "transponder"):
260                                 freq = int(attrs.get('frequency',""))
261                                 sr = int(attrs.get('symbol_rate',""))
262                                 pol = int(attrs.get('polarization',""))
263                                 fec = int(attrs.get('fec_inner',""))
264                                 if self.parsedSat in self.transponders:
265                                         pass
266                                 else:
267                                         self.transponders[self.parsedSat] = [ ]
268
269                                 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
270
271         class parseCables(ContentHandler):
272                 def __init__(self, cablesList, transponders):
273                         self.isPointsElement, self.isReboundsElement = 0, 0
274                         self.cablesList = cablesList
275                         self.transponders = transponders
276         
277                 def startElement(self, name, attrs):
278                         if (name == "cable"):
279                                 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
280                                 tname = attrs.get('name',"")
281                                 self.cablesList.append(str(tname))
282                                 self.parsedCab = str(tname)
283                         elif (name == "transponder"):
284                                 freq = int(attrs.get('frequency',""))
285                                 sr = int(attrs.get('symbol_rate',""))
286                                 mod = int(attrs.get('modulation',""))
287                                 fec = int(attrs.get('fec_inner',""))
288                                 if self.parsedCab in self.transponders:
289                                         pass
290                                 else:
291                                         self.transponders[self.parsedCab] = [ ]
292
293                                 self.transponders[self.parsedCab].append((1, freq, sr, mod, fec))
294
295         class parseTerrestrials(ContentHandler):
296                 def __init__(self, terrestrialsList, transponders):
297                         self.isPointsElement, self.isReboundsElement = 0, 0
298                         self.terrestrialsList = terrestrialsList
299                         self.transponders = transponders
300         
301                 def startElement(self, name, attrs):
302                         if (name == "terrestrial"):
303                                 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
304                                 tname = attrs.get('name',"")
305                                 tflags = attrs.get('flags',"")
306                                 self.terrestrialsList.append((tname, tflags))
307                                 self.parsedTer = str(tname)
308                         elif (name == "transponder"):
309                                 # TODO finish this!
310                                 freq = int(attrs.get('centre_frequency',""))
311                                 bw = int(attrs.get('bandwidth',""))
312                                 const = int(attrs.get('constellation',""))
313                                 crh = int(attrs.get('code_rate_hp',""))
314                                 crl = int(attrs.get('code_rate_lp',""))
315                                 guard = int(attrs.get('guard_interval',""))
316                                 transm = int(attrs.get('transmission_mode',""))
317                                 hierarchy = int(attrs.get('hierarchy_information',""))
318                                 inv = int(attrs.get('inversion',""))
319                                 if self.parsedTer in self.transponders:
320                                         pass
321                                 else:
322                                         self.transponders[self.parsedTer] = [ ]
323
324                                 self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
325
326         def getTransponders(self, pos):
327                 return self.transponders[pos]
328
329         def getConfiguredSats(self):
330                 return self.sec.getSatList()
331
332         def getSatDescription(self, pos):
333                 return self.satellites[pos]
334
335         def readSatsfromFile(self):
336                 self.satellites = { }
337                 self.transponders = { }
338                 self.transponderscable = { }
339                 self.transpondersterrestrial = { }              
340                 
341                 parser = make_parser()
342                 if (self.hasNimType(self.nimType["DVB-S"])):
343                         print "Reading satellites.xml"
344                         satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
345                         parser.setContentHandler(satHandler)
346                         parser.parse('/etc/tuxbox/satellites.xml')
347                 if (self.hasNimType(self.nimType["DVB-C"])):
348                         print "Reading cables.xml"
349                         cabHandler = self.parseCables(self.cablesList, self.transponderscable)
350                         parser.setContentHandler(cabHandler)
351                         parser.parse('/etc/tuxbox/cables.xml')
352
353                 if (self.hasNimType(self.nimType["DVB-T"])):
354                         print "Reading terrestrial.xml"
355                         terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
356                         parser.setContentHandler(terHandler)
357                         parser.parse('/etc/tuxbox/terrestrial.xml')
358                 
359         def parseProc(self):
360                 self.nimTypes = {}
361                 self.nimNames = {}              
362                 self.nimSocketCount = 0
363                 nimfile = tryOpen("/proc/bus/nim_sockets")
364
365                 if nimfile == "":
366                                 return self.nimType["empty/unknown"]
367                         
368                 lastsocket = -1
369
370                 while 1:                
371                         line = nimfile.readline()
372                         if line == "":
373                                 break
374                         if line.strip().startswith("NIM Socket"):
375                                 parts = line.strip().split(" ")
376                                 id = int(parts[2][:1])
377                                 lastsocket = int(id)
378                                 self.nimSocketCount += 1
379                         elif line.strip().startswith("Type:"):
380                                 self.nimTypes[lastsocket] = str(line.strip()[6:])
381                         elif line.strip().startswith("Name:"):
382                                 self.nimNames[lastsocket] = str(line.strip()[6:])
383                         elif line.strip().startswith("empty"):
384                                 self.nimNames[lastsocket] = _("N/A")
385                                 self.nimTypes[lastsocket] = "empty/unknown"
386
387                 nimfile.close()
388
389         def getNimType(self, slotID):
390                 if slotID >= self.nimCount:
391                         return "empty/unknown"
392                 else:   
393                         return self.nimType[self.nimTypes[slotID]]
394                         
395         def getNimName(self, slotID):
396                 return self.nimNames[slotID]
397
398         def getNimSocketCount(self):
399                 return self.nimSocketCount
400         
401         def hasNimType(self, chktype):
402                 for id, type in self.nimTypes.items():
403                         if (chktype == self.nimType[str(type)]):
404                                 return True
405                 return False
406         
407         def getNimListOfType(self, type, exception = -1):
408                 list = []
409                 for x in self.nimslots:
410                         if ((x.nimType == type) and (x.slotid != exception)):
411                                 list.append(x.slotid)
412                 return list
413
414         def getConfigPrefix(self, slotid):
415                 return "config.Nim" + ("A","B","C","D")[slotid] + "."
416                         
417         def __init__(self):
418                 #use as enum
419                 self.nimType = {                "empty/unknown": -1,
420                                                                                                 "DVB-S": 0,
421                                                                                                 "DVB-C": 1,
422                                                                                                 "DVB-T": 2}
423                 self.satList = [ ]
424                 self.cablesList = []
425                 self.terrestrialsList = []
426                                                                                                 
427                 self.parseProc()
428
429                 self.readSatsfromFile()                                                 
430                 
431                 self.nimCount = self.getNimSocketCount()
432                 
433                 self.nimslots = [ ]
434                 x = 0
435                 while x < self.nimCount:
436                         tType = self.getNimType(x)
437                         tName = self.getNimName(x)
438                         tNim = nimSlot(x, tType, tName)
439                         self.nimslots.append(tNim)
440                         x += 1
441                 
442                 InitNimManager(self)    #init config stuff
443
444         def nimList(self):
445                 list = [ ]
446                 for slot in self.nimslots:
447                         nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
448                         if slot.nimType == -1:
449                                 nimText += _("empty/unknown")
450                         else:
451                                 nimText += slot.name + " ("     
452                                 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
453                         list.append((nimText, slot))
454                 return list
455         
456         def getSatListForNim(self, slotid):
457                 list = []
458                 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
459                         #print "slotid:", slotid
460                         
461                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
462                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
463                         if (config.Nims[slotid].diseqcMode.value <= 3):
464                                 list.append(self.satList[config.Nims[slotid].diseqcA.value])
465                         if (0 < config.Nims[slotid].diseqcMode.value <= 3):
466                                 list.append(self.satList[config.Nims[slotid].diseqcB.value])
467                         if (config.Nims[slotid].diseqcMode.value == 3):
468                                 list.append(self.satList[config.Nims[slotid].diseqcC.value])
469                                 list.append(self.satList[config.Nims[slotid].diseqcD.value])
470                         if (config.Nims[slotid].diseqcMode.value == 4):
471                                 for x in self.satList:
472                                         list.append(x)
473                 return list
474
475         #callbacks for c++ config
476         def nimConfigModeChanged(self, slotid, mode):
477                 if (mode != 2): # not linked
478                         print "Unlinking slot " + str(slotid)
479                         # TODO call c++ to unlink nim in slot slotid
480                 if (mode == 2): # linked
481                         pass
482                         #FIXME!!!
483                         #if (len(self.getNimListOfType(self.nimType["DVB-S"], slotid)) > 0):
484                         #       print "Linking slot " + str(slotid) + " to " + str(nimmgr.getConfigPrefix(slotid).value)
485                         # TODO call c++ to link nim in slot slotid with nim in slot nimmgr.getConfigPrefix(slotid).value
486         def nimLinkedToChanged(self, slotid, val):
487                 print "Linking slot " + str(slotid) + " to " + str(val)
488
489         def nimDiseqcModeChanged(self, slotid, mode):
490                 #print "nimDiseqcModeChanged set to " + str(mode)
491                 pass
492         def nimPortAChanged(self, slotid, val):
493                 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
494                 pass
495         def nimPortBChanged(self, slotid, val):
496                 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
497                 #print "nimDiseqcB set to " + str(val)
498                 pass
499         def nimPortCChanged(self, slotid, val):
500                 #print "nimDiseqcC set to " + str(val)
501                 pass
502         def nimPortDChanged(self, slotid, val):
503                 #print "nimDiseqcD set to " + str(val)
504                 pass
505
506 def InitNimManager(nimmgr):
507         config.Nims = []
508         for x in range(nimmgr.nimCount):
509                 config.Nims.append(ConfigSubsection())
510                 
511         def nimConfigModeChanged(slotid, configElement):
512                 nimmgr.nimConfigModeChanged(slotid, configElement.value)
513         def nimLinkedToChanged(slotid, configElement):
514                 nimmgr.nimLinkedToChanged(slotid, configElement.value)
515         def nimDiseqcModeChanged(slotid, configElement):
516                 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
517                 
518         def nimPortAChanged(slotid, configElement):
519                 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
520         def nimPortBChanged(slotid, configElement):
521                 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
522         def nimPortCChanged(slotid, configElement):
523                 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
524         def nimPortDChanged(slotid, configElement):
525                 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
526
527         for slot in nimmgr.nimslots:
528                 x = slot.slotid
529                 cname = nimmgr.getConfigPrefix(x)
530                 nim = config.Nims[x]
531                 
532                 if slot.nimType == nimmgr.nimType["DVB-S"]:
533                         if slot.slotid == 0:
534                                 nim.configMode = configElement(cname + "configMode", configSelection, 0, (("simple", _("Simple")), ("advanced", _("Advanced"))))
535                         else:                                                   
536                                 nim.configMode = configElement(cname + "configMode", configSelection, 0, (("simple", _("Simple")), ("nothing", _("Nothing connected")), ("loopthrough", _("Loopthrough to Socket A")), ("advanced", _("Advanced"))))
537                         
538                         #important - check if just the 2nd one is LT only and the first one is DVB-S
539                         if currentConfigSelectionElement(nim.configMode) == "loopthrough": #linked
540                                 if x == 0:                                                                              #first one can never be linked to anything
541                                         nim.configMode.value = getConfigSelectionElement(nim.configMode, "simple")              #reset to simple
542                                         nim.configMode.save()
543                                 else:
544                                         #FIXME: make it better
545                                         for y in nimmgr.nimslots:
546                                                 if y.slotid == 0:
547                                                         if y.nimType != nimmgr.nimType["DVB-S"]:
548                                                                 nim.configMode.value = getConfigSelectionElement(nim.configMode, "simple")              #reset to simple
549                                                                 nim.configMode.save()
550
551                         nim.diseqcMode = configElement(cname + "diseqcMode", configSelection, 2, (("single", _("Single")), ("toneburst_a_b", _("Toneburst A/B")), ("diseqc_a_b", _("DiSEqC A/B")), ("diseqc_a_b_c_d", _("DiSEqC A/B/C/D")), ("positioner", _("Positioner"))));
552                         nim.diseqcA = configElement(cname + "diseqcA", configSatlist, 192, nimmgr.satList);
553                         nim.diseqcB = configElement(cname + "diseqcB", configSatlist, 130, nimmgr.satList);
554                         nim.diseqcC = configElement(cname + "diseqcC", configSatlist, 0, nimmgr.satList);
555                         nim.diseqcD = configElement(cname + "diseqcD", configSatlist, 0, nimmgr.satList);
556                         nim.positionerMode = configElement(cname + "positionerMode", configSelection, 0, (("usals", _("USALS")), ("manual", _("manual"))));
557                         nim.longitude = configElement(cname + "longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
558                         nim.longitudeOrientation = configElement(cname + "longitudeOrientation", configSelection, 0, (_("East"), _("West")))
559                         nim.latitude = configElement(cname + "latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
560                         nim.latitudeOrientation = configElement(cname + "latitudeOrientation", configSelection, 0, (("north", _("North")), ("south", _("South"))))
561                         satNimList = nimmgr.getNimListOfType(nimmgr.nimType["DVB-S"], slot.slotid)
562                         satNimListNames = []
563                         for x in satNimList:
564                                 satNimListNames.append((("Slot_" + ("A", "B", "C", "D")[x] + "_" + nimmgr.getNimName(x)), _("Slot ") + ("A", "B", "C", "D")[x] + ": " + nimmgr.getNimName(x)))
565                         nim.linkedTo = configElement(cname + "linkedTo", configSelection, 0, satNimListNames);
566                         
567                         #perhaps the instance of the slot is more useful?
568                         nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
569                         nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
570                         nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
571                         nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
572                         nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
573                         nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
574                         nim.linkedTo.addNotifier(boundFunction(nimLinkedToChanged,x))
575                         
576                         # advanced config:
577                         nim.advanced = ConfigSubsection()
578                         nim.advanced.sats = configElement(cname + "advanced.sats", configSatlist, 192, nimmgr.satList);
579                         nim.advanced.sat = {}
580                         lnbs = ["not available"]
581                         for y in range(1, 33):
582                                 lnbs.append("LNB " + str(y))
583                         for x in nimmgr.satList:
584                                 nim.advanced.sat[x[1]] = ConfigSubsection()
585                                 nim.advanced.sat[x[1]].voltage = configElement(cname + "advanced.sat" + str(x[1]) + ".voltage", configSelection, 0, (("polarization", _("Polarization")), ("13V", _("13 V")), ("18V", _("18 V"))))
586                                 nim.advanced.sat[x[1]].tonemode = configElement(cname + "advanced.sat" + str(x[1]) + ".tonemode", configSelection, 0, (("band", _("Band")), ("on", _("On")), ("off", _("Off"))))
587                                 nim.advanced.sat[x[1]].usals = configElement(cname + "advanced.sat" + str(x[1]) + ".usals", configSelection, 0, (("yes", _("Yes")), ("no", _("No"))))
588                                 nim.advanced.sat[x[1]].rotorposition = configElement(cname + "advanced.sat" + str(x[1]) + ".rotorposition", configSequence, [1], configsequencearg.get("INTEGER", (1, 255)))
589                                 nim.advanced.sat[x[1]].lnb = configElement(cname + "advanced.sat" + str(x[1]) + ".lnb", configSelection, 0, lnbs)
590                         
591                         nim.advanced.lnb = [0]
592                         for x in range(1, 33):
593                                 nim.advanced.lnb.append(ConfigSubsection())
594                                 nim.advanced.lnb[x].lof = configElement(cname + "advanced.lnb" + str(x) + ".lof", configSelection, 0, (("universal_lnb", _("Universal LNB")), ("c_band", _("C-Band")), ("user_defined", _("User defined"))))
595                                 nim.advanced.lnb[x].lofl = configElement(cname + "advanced.lnb" + str(x) + ".lofl", configSequence, [9750], configsequencearg.get("INTEGER", (0, 99999)))
596                                 nim.advanced.lnb[x].lofh = configElement(cname + "advanced.lnb" + str(x) + ".lofh", configSequence, [10600], configsequencearg.get("INTEGER", (0, 99999)))
597                                 nim.advanced.lnb[x].threshold = configElement(cname + "advanced.lnb" + str(x) + ".threshold", configSequence, [11750], configsequencearg.get("INTEGER", (0, 99999)))
598                                 nim.advanced.lnb[x].output_12v = configElement(cname + "advanced.lnb" + str(x) + ".output_12v", configSelection, 0, (("0V", _("0 V")), ("12V", _("12 V"))))
599                                 nim.advanced.lnb[x].increased_voltage = configElement(cname + "advanced.lnb" + str(x) + ".increased_voltage", configSelection, 0, (("no", _("No")), ("yes", _("Yes"))))
600                                 nim.advanced.lnb[x].toneburst = configElement(cname + "advanced.lnb" + str(x) + ".toneburst", configSelection, 0, (("none", _("None")), ("A", _("A")), ("B", _("B"))))
601                                 nim.advanced.lnb[x].diseqcMode = configElement(cname + "advanced.lnb" + str(x) + ".diseqcMode", configSelection, 0, (("none", _("None")), ("1_0", _("1.0")), ("1_1", _("1.1")), ("1_2", _("1.2"))))
602                                 nim.advanced.lnb[x].commitedDiseqcCommand = configElement(cname + "advanced.lnb" + str(x) + ".commitedDiseqcCommand", configSelection, 0, (("none", _("None")), ("AA", _("AA")), ("AB", _("AB")), ("BA", _("BA")), ("BB", _("BB"))))
603                                 nim.advanced.lnb[x].fastDiseqc = configElement(cname + "advanced.lnb" + str(x) + ".fastDiseqc", configSelection, 0, (("no", _("No")), ("yes", _("Yes"))))
604                                 nim.advanced.lnb[x].sequenceRepeat = configElement(cname + "advanced.lnb" + str(x) + ".sequenceRepeat", configSelection, 0, (("no", _("No")), ("yes", _("Yes"))))
605                                 nim.advanced.lnb[x].commandOrder1_0 = configElement(cname + "advanced.lnb" + str(x) + ".commandOrder1_0", configSelection, 0, ("committed, toneburst", "toneburst, committed"))
606                                 nim.advanced.lnb[x].commandOrder = configElement(cname + "advanced.lnb" + str(x) + ".commandOrder", configSelection, 0, ("committed, toneburst", "toneburst, committed", "committed, uncommitted, toneburst", "toneburst, committed, uncommitted", "uncommitted, committed, toneburst", "toneburst, uncommitted, commmitted"))
607                                 disCmd = ["none"]
608                                 for y in range(1, 17):
609                                         disCmd.append("Input " + str(y))
610                                 nim.advanced.lnb[x].uncommittedDiseqcCommand = configElement(cname + "advanced.lnb" + str(x) + ".uncommittedDiseqcCommand", configSelection, 0, disCmd)
611                                 nim.advanced.lnb[x].diseqcRepeats = configElement(cname + "advanced.lnb" + str(x) + ".diseqcRepeats", configSelection, 0, (("none", _("None")), ("one", _("One")), ("two", _("Two")), ("three", _("Three"))))
612                                 nim.advanced.lnb[x].longitude = configElement(cname + "advanced.lnb" + str(x) + ".longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
613                                 nim.advanced.lnb[x].longitudeOrientation = configElement(cname + "advanced.lnb" + str(x) + ".longitudeOrientation", configSelection, 0, (_("East"), _("West")))
614                                 nim.advanced.lnb[x].latitude = configElement(cname + "advanced.lnb" + str(x) + ".latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
615                                 nim.advanced.lnb[x].latitudeOrientation = configElement(cname + "advanced.lnb" + str(x) + ".latitudeOrientation", configSelection, 0, (("north", _("North")), ("south", _("South"))))
616                                 nim.advanced.lnb[x].powerMeasurement = configElement(cname + "advanced.lnb" + str(x) + ".powerMeasurement", configSelection, 0, (("yes", _("Yes")), ("no", _("No"))))
617                                 nim.advanced.lnb[x].powerThreshold = configElement(cname + "advanced.lnb" + str(x) + ".powerThreshold", configSequence, [50], configsequencearg.get("INTEGER", (0, 100)))
618                 elif slot.nimType == nimmgr.nimType["DVB-C"]:
619                         nim.cable = configElement(cname + "cable", configSelection, 0, nimmgr.cablesList);
620                 elif slot.nimType == nimmgr.nimType["DVB-T"]:
621                         nim.cable = configElement(cname + "terrestrial", configSelection, 0, nimmgr.terrestrialsList);
622                 else:
623                         print "pls add support for this frontend type!"         
624
625         nimmgr.sec = SecConfigure(nimmgr)
626
627 nimmanager = NimManager()