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