add missing components for advanced sat setup
[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                                         currSat = config.Nims[slotid].advanced.sat[y]
231                                         if currentConfigSelectionElement(currSat.voltage) == "polarization":
232                                                 pass
233                                         elif currentConfigSelectionElement(currSat.voltage) == "13V":
234                                                 pass
235                                         elif currentConfigSelectionElement(currSat.voltage) == "18V":
236                                                 pass
237
238                                         if currentConfigSelectionElement(currSat.tonemode) == "band":
239                                                 pass
240                                         elif currentConfigSelectionElement(currSat.tonemode) == "on":
241                                                 pass
242                                         elif currentConfigSelectionElement(currSat.tonemode) == "off":
243                                                 pass
244                                         
245                                         if  currentConfigSelectionElement(currSat.usals) == "no":
246                                                 pass # use currSat.rotorposition.value to set the stored rotor position
247                                         else:
248                                                 pass # use usals for this sat!
249                                         
250                                         
251         def __init__(self, nimmgr):
252                 self.NimManager = nimmgr
253                 self.update()
254                 
255 class nimSlot:
256         def __init__(self, slotid, nimtype, name):
257                 self.slotid = slotid
258                 self.nimType = nimtype
259                 self.name = name
260
261 class NimManager:
262         class parseSats(ContentHandler):
263                 def __init__(self, satList, satellites, transponders):
264                         self.isPointsElement, self.isReboundsElement = 0, 0
265                         self.satList = satList
266                         self.satellites = satellites
267                         self.transponders = transponders
268         
269                 def startElement(self, name, attrs):
270                         if (name == "sat"):
271                                 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
272                                 tpos = int(attrs.get('position',""))
273                                 if tpos < 0:
274                                         tpos = 3600 + tpos
275                                 tname = attrs.get('name',"")
276                                 self.satellites[tpos] = tname
277                                 self.satList.append( (tname, tpos) )
278                                 self.parsedSat = int(tpos)
279                         elif (name == "transponder"):
280                                 freq = int(attrs.get('frequency',""))
281                                 sr = int(attrs.get('symbol_rate',""))
282                                 pol = int(attrs.get('polarization',""))
283                                 fec = int(attrs.get('fec_inner',""))
284                                 if self.parsedSat in self.transponders:
285                                         pass
286                                 else:
287                                         self.transponders[self.parsedSat] = [ ]
288
289                                 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
290
291         class parseCables(ContentHandler):
292                 def __init__(self, cablesList, transponders):
293                         self.isPointsElement, self.isReboundsElement = 0, 0
294                         self.cablesList = cablesList
295                         self.transponders = transponders
296         
297                 def startElement(self, name, attrs):
298                         if (name == "cable"):
299                                 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
300                                 tname = attrs.get('name',"")
301                                 self.cablesList.append(str(tname))
302                                 self.parsedCab = str(tname)
303                         elif (name == "transponder"):
304                                 freq = int(attrs.get('frequency',""))
305                                 sr = int(attrs.get('symbol_rate',""))
306                                 mod = int(attrs.get('modulation',""))
307                                 fec = int(attrs.get('fec_inner',""))
308                                 if self.parsedCab in self.transponders:
309                                         pass
310                                 else:
311                                         self.transponders[self.parsedCab] = [ ]
312
313                                 self.transponders[self.parsedCab].append((1, freq, sr, mod, fec))
314
315         class parseTerrestrials(ContentHandler):
316                 def __init__(self, terrestrialsList, transponders):
317                         self.isPointsElement, self.isReboundsElement = 0, 0
318                         self.terrestrialsList = terrestrialsList
319                         self.transponders = transponders
320         
321                 def startElement(self, name, attrs):
322                         if (name == "terrestrial"):
323                                 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
324                                 tname = attrs.get('name',"")
325                                 tflags = attrs.get('flags',"")
326                                 self.terrestrialsList.append((tname, tflags))
327                                 self.parsedTer = str(tname)
328                         elif (name == "transponder"):
329                                 # TODO finish this!
330                                 freq = int(attrs.get('centre_frequency',""))
331                                 bw = int(attrs.get('bandwidth',""))
332                                 const = int(attrs.get('constellation',""))
333                                 crh = int(attrs.get('code_rate_hp',""))
334                                 crl = int(attrs.get('code_rate_lp',""))
335                                 guard = int(attrs.get('guard_interval',""))
336                                 transm = int(attrs.get('transmission_mode',""))
337                                 hierarchy = int(attrs.get('hierarchy_information',""))
338                                 inv = int(attrs.get('inversion',""))
339                                 if self.parsedTer in self.transponders:
340                                         pass
341                                 else:
342                                         self.transponders[self.parsedTer] = [ ]
343
344                                 self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
345
346         def getTransponders(self, pos):
347                 return self.transponders[pos]
348
349         def getConfiguredSats(self):
350                 return self.sec.getSatList()
351
352         def getSatDescription(self, pos):
353                 return self.satellites[pos]
354
355         def readSatsfromFile(self):
356                 self.satellites = { }
357                 self.transponders = { }
358                 self.transponderscable = { }
359                 self.transpondersterrestrial = { }              
360                 
361                 parser = make_parser()
362                 if (self.hasNimType(self.nimType["DVB-S"])):
363                         print "Reading satellites.xml"
364                         satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
365                         parser.setContentHandler(satHandler)
366                         parser.parse('/etc/tuxbox/satellites.xml')
367                 if (self.hasNimType(self.nimType["DVB-C"])):
368                         print "Reading cables.xml"
369                         cabHandler = self.parseCables(self.cablesList, self.transponderscable)
370                         parser.setContentHandler(cabHandler)
371                         parser.parse('/etc/tuxbox/cables.xml')
372
373                 if (self.hasNimType(self.nimType["DVB-T"])):
374                         print "Reading terrestrial.xml"
375                         terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
376                         parser.setContentHandler(terHandler)
377                         parser.parse('/etc/tuxbox/terrestrial.xml')
378                 
379         def parseProc(self):
380                 self.nimTypes = {}
381                 self.nimNames = {}              
382                 self.nimSocketCount = 0
383                 nimfile = tryOpen("/proc/bus/nim_sockets")
384
385                 if nimfile == "":
386                                 return self.nimType["empty/unknown"]
387                         
388                 lastsocket = -1
389
390                 while 1:                
391                         line = nimfile.readline()
392                         if line == "":
393                                 break
394                         if line.strip().startswith("NIM Socket"):
395                                 parts = line.strip().split(" ")
396                                 id = int(parts[2][:1])
397                                 lastsocket = int(id)
398                                 self.nimSocketCount += 1
399                         elif line.strip().startswith("Type:"):
400                                 self.nimTypes[lastsocket] = str(line.strip()[6:])
401                         elif line.strip().startswith("Name:"):
402                                 self.nimNames[lastsocket] = str(line.strip()[6:])
403                         elif line.strip().startswith("empty"):
404                                 self.nimNames[lastsocket] = _("N/A")
405                                 self.nimTypes[lastsocket] = "empty/unknown"
406
407                 nimfile.close()
408
409         def getNimType(self, slotID):
410                 if slotID >= self.nimCount:
411                         return "empty/unknown"
412                 else:   
413                         return self.nimType[self.nimTypes[slotID]]
414                         
415         def getNimName(self, slotID):
416                 return self.nimNames[slotID]
417
418         def getNimSocketCount(self):
419                 return self.nimSocketCount
420         
421         def hasNimType(self, chktype):
422                 for id, type in self.nimTypes.items():
423                         if (chktype == self.nimType[str(type)]):
424                                 return True
425                 return False
426         
427         def getNimListOfType(self, type, exception = -1):
428                 list = []
429                 for x in self.nimslots:
430                         if ((x.nimType == type) and (x.slotid != exception)):
431                                 list.append(x.slotid)
432                 return list
433
434         def getConfigPrefix(self, slotid):
435                 return "config.Nim" + ("A","B","C","D")[slotid] + "."
436                         
437         def __init__(self):
438                 #use as enum
439                 self.nimType = {                "empty/unknown": -1,
440                                                                                                 "DVB-S": 0,
441                                                                                                 "DVB-C": 1,
442                                                                                                 "DVB-T": 2}
443                 self.satList = [ ]
444                 self.cablesList = []
445                 self.terrestrialsList = []
446                                                                                                 
447                 self.parseProc()
448
449                 self.readSatsfromFile()                                                 
450                 
451                 self.nimCount = self.getNimSocketCount()
452                 
453                 self.nimslots = [ ]
454                 x = 0
455                 while x < self.nimCount:
456                         tType = self.getNimType(x)
457                         tName = self.getNimName(x)
458                         tNim = nimSlot(x, tType, tName)
459                         self.nimslots.append(tNim)
460                         x += 1
461                 
462                 InitNimManager(self)    #init config stuff
463
464         def nimList(self):
465                 list = [ ]
466                 for slot in self.nimslots:
467                         nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
468                         if slot.nimType == -1:
469                                 nimText += _("empty/unknown")
470                         else:
471                                 nimText += slot.name + " ("     
472                                 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
473                         list.append((nimText, slot))
474                 return list
475         
476         def getSatListForNim(self, slotid):
477                 list = []
478                 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
479                         #print "slotid:", slotid
480                         
481                         #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
482                         #print "diseqcA:", config.Nims[slotid].diseqcA.value
483                         if (config.Nims[slotid].diseqcMode.value <= 3):
484                                 list.append(self.satList[config.Nims[slotid].diseqcA.value])
485                         if (0 < config.Nims[slotid].diseqcMode.value <= 3):
486                                 list.append(self.satList[config.Nims[slotid].diseqcB.value])
487                         if (config.Nims[slotid].diseqcMode.value == 3):
488                                 list.append(self.satList[config.Nims[slotid].diseqcC.value])
489                                 list.append(self.satList[config.Nims[slotid].diseqcD.value])
490                         if (config.Nims[slotid].diseqcMode.value == 4):
491                                 for x in self.satList:
492                                         list.append(x)
493                 return list
494
495         #callbacks for c++ config
496         def nimConfigModeChanged(self, slotid, mode):
497                 if (mode != 2): # not linked
498                         print "Unlinking slot " + str(slotid)
499                         # TODO call c++ to unlink nim in slot slotid
500                 if (mode == 2): # linked
501                         pass
502                         #FIXME!!!
503                         #if (len(self.getNimListOfType(self.nimType["DVB-S"], slotid)) > 0):
504                         #       print "Linking slot " + str(slotid) + " to " + str(nimmgr.getConfigPrefix(slotid).value)
505                         # TODO call c++ to link nim in slot slotid with nim in slot nimmgr.getConfigPrefix(slotid).value
506         def nimLinkedToChanged(self, slotid, val):
507                 print "Linking slot " + str(slotid) + " to " + str(val)
508
509         def nimDiseqcModeChanged(self, slotid, mode):
510                 #print "nimDiseqcModeChanged set to " + str(mode)
511                 pass
512         def nimPortAChanged(self, slotid, val):
513                 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
514                 pass
515         def nimPortBChanged(self, slotid, val):
516                 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
517                 #print "nimDiseqcB set to " + str(val)
518                 pass
519         def nimPortCChanged(self, slotid, val):
520                 #print "nimDiseqcC set to " + str(val)
521                 pass
522         def nimPortDChanged(self, slotid, val):
523                 #print "nimDiseqcD set to " + str(val)
524                 pass
525
526 def InitNimManager(nimmgr):
527         config.Nims = []
528         for x in range(nimmgr.nimCount):
529                 config.Nims.append(ConfigSubsection())
530                 
531         def nimConfigModeChanged(slotid, configElement):
532                 nimmgr.nimConfigModeChanged(slotid, configElement.value)
533         def nimLinkedToChanged(slotid, configElement):
534                 nimmgr.nimLinkedToChanged(slotid, configElement.value)
535         def nimDiseqcModeChanged(slotid, configElement):
536                 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
537                 
538         def nimPortAChanged(slotid, configElement):
539                 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
540         def nimPortBChanged(slotid, configElement):
541                 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
542         def nimPortCChanged(slotid, configElement):
543                 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
544         def nimPortDChanged(slotid, configElement):
545                 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
546
547         for slot in nimmgr.nimslots:
548                 x = slot.slotid
549                 cname = nimmgr.getConfigPrefix(x)
550                 nim = config.Nims[x]
551                 
552                 if slot.nimType == nimmgr.nimType["DVB-S"]:
553                         if slot.slotid == 0:
554                                 nim.configMode = configElement(cname + "configMode", configSelection, 0, (("simple", _("Simple")), ("advanced", _("Advanced"))))
555                         else:                                                   
556                                 nim.configMode = configElement(cname + "configMode", configSelection, 0, (("simple", _("Simple")), ("nothing", _("Nothing connected")), ("loopthrough", _("Loopthrough to Socket A")), ("advanced", _("Advanced"))))
557                         
558                         #important - check if just the 2nd one is LT only and the first one is DVB-S
559                         if currentConfigSelectionElement(nim.configMode) == "loopthrough": #linked
560                                 if x == 0:                                                                              #first one can never be linked to anything
561                                         nim.configMode.value = getConfigSelectionElement(nim.configMode, "simple")              #reset to simple
562                                         nim.configMode.save()
563                                 else:
564                                         #FIXME: make it better
565                                         for y in nimmgr.nimslots:
566                                                 if y.slotid == 0:
567                                                         if y.nimType != nimmgr.nimType["DVB-S"]:
568                                                                 nim.configMode.value = getConfigSelectionElement(nim.configMode, "simple")              #reset to simple
569                                                                 nim.configMode.save()
570
571                         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"))));
572                         nim.diseqcA = configElement(cname + "diseqcA", configSatlist, 192, nimmgr.satList);
573                         nim.diseqcB = configElement(cname + "diseqcB", configSatlist, 130, nimmgr.satList);
574                         nim.diseqcC = configElement(cname + "diseqcC", configSatlist, 0, nimmgr.satList);
575                         nim.diseqcD = configElement(cname + "diseqcD", configSatlist, 0, nimmgr.satList);
576                         nim.positionerMode = configElement(cname + "positionerMode", configSelection, 0, (("usals", _("USALS")), ("manual", _("manual"))));
577                         nim.longitude = configElement(cname + "longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
578                         nim.longitudeOrientation = configElement(cname + "longitudeOrientation", configSelection, 0, (_("East"), _("West")))
579                         nim.latitude = configElement(cname + "latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
580                         nim.latitudeOrientation = configElement(cname + "latitudeOrientation", configSelection, 0, (("north", _("North")), ("south", _("South"))))
581                         satNimList = nimmgr.getNimListOfType(nimmgr.nimType["DVB-S"], slot.slotid)
582                         satNimListNames = []
583                         for x in satNimList:
584                                 satNimListNames.append((("Slot_" + ("A", "B", "C", "D")[x] + "_" + nimmgr.getNimName(x)), _("Slot ") + ("A", "B", "C", "D")[x] + ": " + nimmgr.getNimName(x)))
585                         nim.linkedTo = configElement(cname + "linkedTo", configSelection, 0, satNimListNames);
586                         
587                         #perhaps the instance of the slot is more useful?
588                         nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
589                         nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
590                         nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
591                         nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
592                         nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
593                         nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
594                         nim.linkedTo.addNotifier(boundFunction(nimLinkedToChanged,x))
595                         
596                         # advanced config:
597                         nim.advanced = ConfigSubsection()
598                         nim.advanced.sats = configElement(cname + "advanced.sats", configSatlist, 192, nimmgr.satList);
599                         nim.advanced.sat = {}
600                         lnbs = ["not available"]
601                         for y in range(1, 33):
602                                 lnbs.append("LNB " + str(y))
603                         for x in nimmgr.satList:
604                                 nim.advanced.sat[x[1]] = ConfigSubsection()
605                                 nim.advanced.sat[x[1]].voltage = configElement(cname + "advanced.sat" + str(x[1]) + ".voltage", configSelection, 0, (("polarization", _("Polarization")), ("13V", _("13 V")), ("18V", _("18 V"))))
606                                 nim.advanced.sat[x[1]].tonemode = configElement(cname + "advanced.sat" + str(x[1]) + ".tonemode", configSelection, 0, (("band", _("Band")), ("on", _("On")), ("off", _("Off"))))
607                                 nim.advanced.sat[x[1]].usals = configElement(cname + "advanced.sat" + str(x[1]) + ".usals", configSelection, 0, (("yes", _("Yes")), ("no", _("No"))))
608                                 nim.advanced.sat[x[1]].rotorposition = configElement(cname + "advanced.sat" + str(x[1]) + ".rotorposition", configSequence, [1], configsequencearg.get("INTEGER", (1, 255)))
609                                 nim.advanced.sat[x[1]].lnb = configElement(cname + "advanced.sat" + str(x[1]) + ".lnb", configSelection, 0, lnbs)
610                         
611                         nim.advanced.lnb = [0]
612                         for x in range(1, 33):
613                                 nim.advanced.lnb.append(ConfigSubsection())
614                                 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"))))
615                                 nim.advanced.lnb[x].lofl = configElement(cname + "advanced.lnb" + str(x) + ".lofl", configSequence, [9750], configsequencearg.get("INTEGER", (0, 99999)))
616                                 nim.advanced.lnb[x].lofh = configElement(cname + "advanced.lnb" + str(x) + ".lofh", configSequence, [10600], configsequencearg.get("INTEGER", (0, 99999)))
617                                 nim.advanced.lnb[x].threshold = configElement(cname + "advanced.lnb" + str(x) + ".threshold", configSequence, [11750], configsequencearg.get("INTEGER", (0, 99999)))
618                                 nim.advanced.lnb[x].output_12v = configElement(cname + "advanced.lnb" + str(x) + ".output_12v", configSelection, 0, (("0V", _("0 V")), ("12V", _("12 V"))))
619                                 nim.advanced.lnb[x].increased_voltage = configElement(cname + "advanced.lnb" + str(x) + ".increased_voltage", configSelection, 0, (("no", _("No")), ("yes", _("Yes"))))
620                                 nim.advanced.lnb[x].toneburst = configElement(cname + "advanced.lnb" + str(x) + ".toneburst", configSelection, 0, (("none", _("None")), ("A", _("A")), ("B", _("B"))))
621                                 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"))))
622                                 nim.advanced.lnb[x].commitedDiseqcCommand = configElement(cname + "advanced.lnb" + str(x) + ".commitedDiseqcCommand", configSelection, 0, (("none", _("None")), ("AA", _("AA")), ("AB", _("AB")), ("BA", _("BA")), ("BB", _("BB"))))
623                                 nim.advanced.lnb[x].fastDiseqc = configElement(cname + "advanced.lnb" + str(x) + ".fastDiseqc", configSelection, 0, (("no", _("No")), ("yes", _("Yes"))))
624                                 nim.advanced.lnb[x].sequenceRepeat = configElement(cname + "advanced.lnb" + str(x) + ".sequenceRepeat", configSelection, 0, (("no", _("No")), ("yes", _("Yes"))))
625                                 nim.advanced.lnb[x].commandOrder1_0 = configElement(cname + "advanced.lnb" + str(x) + ".commandOrder1_0", configSelection, 0, ("committed, toneburst", "toneburst, committed"))
626                                 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"))
627                                 disCmd = ["none"]
628                                 for y in range(1, 17):
629                                         disCmd.append("Input " + str(y))
630                                 nim.advanced.lnb[x].uncommittedDiseqcCommand = configElement(cname + "advanced.lnb" + str(x) + ".uncommittedDiseqcCommand", configSelection, 0, disCmd)
631                                 nim.advanced.lnb[x].diseqcRepeats = configElement(cname + "advanced.lnb" + str(x) + ".diseqcRepeats", configSelection, 0, (("none", _("None")), ("one", _("One")), ("two", _("Two")), ("three", _("Three"))))
632                                 nim.advanced.lnb[x].longitude = configElement(cname + "advanced.lnb" + str(x) + ".longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
633                                 nim.advanced.lnb[x].longitudeOrientation = configElement(cname + "advanced.lnb" + str(x) + ".longitudeOrientation", configSelection, 0, (_("East"), _("West")))
634                                 nim.advanced.lnb[x].latitude = configElement(cname + "advanced.lnb" + str(x) + ".latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
635                                 nim.advanced.lnb[x].latitudeOrientation = configElement(cname + "advanced.lnb" + str(x) + ".latitudeOrientation", configSelection, 0, (("north", _("North")), ("south", _("South"))))
636                                 nim.advanced.lnb[x].powerMeasurement = configElement(cname + "advanced.lnb" + str(x) + ".powerMeasurement", configSelection, 0, (("yes", _("Yes")), ("no", _("No"))))
637                                 nim.advanced.lnb[x].powerThreshold = configElement(cname + "advanced.lnb" + str(x) + ".powerThreshold", configSequence, [50], configsequencearg.get("INTEGER", (0, 100)))
638                 elif slot.nimType == nimmgr.nimType["DVB-C"]:
639                         nim.cable = configElement(cname + "cable", configSelection, 0, nimmgr.cablesList);
640                 elif slot.nimType == nimmgr.nimType["DVB-T"]:
641                         nim.cable = configElement(cname + "terrestrial", configSelection, 0, nimmgr.terrestrialsList);
642                 else:
643                         print "pls add support for this frontend type!"         
644
645         nimmgr.sec = SecConfigure(nimmgr)
646
647 nimmanager = NimManager()