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