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