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