1 from config import config #global config instance
3 from config import configElement
4 from config import ConfigSubsection
5 from config import ConfigSlider
6 from config import configSelection
7 from config import configSequence
8 from config import configsequencearg
9 from config import configSatlist
13 import xml.dom.minidom
14 from xml.dom import EMPTY_NAMESPACE
15 from skin import elementsWithTag
16 from Tools import XMLTools
18 from xml.sax import make_parser
19 from xml.sax.handler import ContentHandler
21 from Tools.BoundFunction import boundFunction
23 def tryOpen(filename):
25 procFile = open(filename)
31 def addLNBSimple(self, slotid, diseqcmode, toneburstmode = 0, diseqcpos = 0, orbpos = 0, longitude = 0, latitude = 0, loDirection = 0, laDirection = 0):
33 sec = eDVBSatelliteEquipmentControl.getInstance()
35 sec.setLNBTunerMask(1 << slotid)
36 sec.setLNBLOFL(9750000)
37 sec.setLNBLOFH(10600000)
38 sec.setLNBThreshold(11750000)
42 sec.setVoltageMode(0) #HV
43 sec.setToneMode(0) #HILO
44 sec.setCommandOrder(0)
46 sec.setDiSEqCMode(diseqcmode)
47 sec.setToneburst(toneburstmode)
48 sec.setCommittedCommand(diseqcpos)
49 #print "set orbpos to:" + str(orbpos)
51 if (0 <= diseqcmode < 3):
52 sec.addSatellite(orbpos)
53 self.satList.append(orbpos)
54 elif (diseqcmode == 3): # diseqc 1.2
55 sec.setLatitude(latitude)
56 sec.setLaDirection(laDirection)
57 sec.setLongitude(longitude)
58 sec.setLoDirection(loDirection)
59 sec.setUseInputpower(True)
60 sec.setInputpowerDelta(50)
62 for x in self.NimManager.satList:
63 print "Add sat " + str(x[1])
64 sec.addSatellite(int(x[1]))
67 self.satList.append(int(x[1]))
70 def linkNIMs(self, nim1, nim2):
71 eDVBSatelliteEquipmentControl.getInstance().setTunerLinked(nim1, nim2)
77 eDVBSatelliteEquipmentControl.getInstance().clear()
81 for slot in self.NimManager.nimslots:
84 if slot.nimType == self.NimManager.nimType["DVB-S"]:
85 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
86 if nim.configMode.value == 2:
87 self.linkNIMs(x, nim.linkedTo.value)
88 nim = config.Nims[nim.linkedTo.value]
89 if nim.configMode.value == 0: #simple config
90 if nim.diseqcMode.value == 0: #single
91 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 0, diseqcpos = 4)
92 elif nim.diseqcMode.value == 1: #Toneburst A/B
93 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 1, diseqcmode = 0, diseqcpos = 4)
94 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 1, diseqcmode = 0, diseqcpos = 4)
95 elif nim.diseqcMode.value == 2: #DiSEqC A/B
96 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 0)
97 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 1)
98 elif nim.diseqcMode.value == 3: #DiSEqC A/B/C/D
99 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 0)
100 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 1)
101 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcC.vals[nim.diseqcC.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 2)
102 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcD.vals[nim.diseqcD.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 3)
103 elif nim.diseqcMode.value == 4: #Positioner
104 self.addLNBSimple(slotid = x, diseqcmode = 3, longitude = float(str(nim.longitude.value[0]) + "." + str(nim.longitude.value[1])), loDirection = nim.longitudeOrientation.value - 2, latitude = float(str(nim.latitude.value[0]) + "." + str(nim.latitude.value[1])), laDirection = nim.latitudeOrientation.value)
106 else: #advanced config
107 print "FIXME add support for advanced config"
109 def __init__(self, nimmgr):
110 self.NimManager = nimmgr
114 def __init__(self, slotid, nimtype, name):
116 self.nimType = nimtype
120 class parseSats(ContentHandler):
121 def __init__(self, satList, satellites, transponders):
122 self.isPointsElement, self.isReboundsElement = 0, 0
123 self.satList = satList
124 self.satellites = satellites
125 self.transponders = transponders
127 def startElement(self, name, attrs):
129 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
130 tpos = int(attrs.get('position',""))
134 print "[NimManager.py] tpos:", tpos
135 tname = attrs.get('name',"")
136 self.satellites[tpos] = tname
137 self.satList.append( (tname, tpos) )
138 self.parsedSat = int(tpos)
139 elif (name == "transponder"):
140 freq = int(attrs.get('frequency',""))
141 sr = int(attrs.get('symbol_rate',""))
142 pol = int(attrs.get('polarization',""))
143 fec = int(attrs.get('fec_inner',""))
144 if self.parsedSat in self.transponders:
147 self.transponders[self.parsedSat] = [ ]
149 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
151 class parseCables(ContentHandler):
152 def __init__(self, cablesList, transponders):
153 self.isPointsElement, self.isReboundsElement = 0, 0
154 self.cablesList = cablesList
155 self.transponders = transponders
157 def startElement(self, name, attrs):
158 if (name == "cable"):
159 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
160 tname = attrs.get('name',"")
161 self.cablesList.append(str(tname))
162 self.parsedCab = str(tname)
163 elif (name == "transponder"):
164 freq = int(attrs.get('frequency',""))
165 sr = int(attrs.get('symbol_rate',""))
166 mod = int(attrs.get('modulation',""))
167 fec = int(attrs.get('fec_inner',""))
168 if self.parsedCab in self.transponders:
171 self.transponders[self.parsedCab] = [ ]
173 self.transponders[self.parsedCab].append((1, freq, sr, mod, fec))
175 class parseTerrestrials(ContentHandler):
176 def __init__(self, terrestrialsList, transponders):
177 self.isPointsElement, self.isReboundsElement = 0, 0
178 self.terrestrialsList = terrestrialsList
179 self.transponders = transponders
181 def startElement(self, name, attrs):
182 if (name == "terrestrial"):
183 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
184 tname = attrs.get('name',"")
185 tflags = attrs.get('flags',"")
186 self.terrestrialsList.append((tname, tflags))
187 self.parsedTer = str(tname)
188 elif (name == "transponder"):
190 freq = int(attrs.get('centre_frequency',""))
191 bw = int(attrs.get('bandwidth',""))
192 const = int(attrs.get('constellation',""))
193 crh = int(attrs.get('code_rate_hp',""))
194 crl = int(attrs.get('code_rate_lp',""))
195 guard = int(attrs.get('guard_interval',""))
196 transm = int(attrs.get('transmission_mode',""))
197 hierarchy = int(attrs.get('hierarchy_information',""))
198 inv = int(attrs.get('inversion',""))
199 if self.parsedTer in self.transponders:
202 self.transponders[self.parsedTer] = [ ]
204 self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
206 def getTransponders(self, pos):
207 return self.transponders[pos]
209 def getConfiguredSats(self):
210 return self.sec.getSatList()
212 def getSatDescription(self, pos):
213 return self.satellites[str(pos)]
215 def readSatsfromFile(self):
216 self.satellites = { }
217 self.transponders = { }
218 self.transponderscable = { }
219 self.transpondersterrestrial = { }
221 parser = make_parser()
222 if (self.hasNimType(self.nimType["DVB-S"])):
223 print "Reading satellites.xml"
224 satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
225 parser.setContentHandler(satHandler)
226 parser.parse('/etc/tuxbox/satellites.xml')
227 if (self.hasNimType(self.nimType["DVB-C"])):
228 print "Reading cables.xml"
229 cabHandler = self.parseCables(self.cablesList, self.transponderscable)
230 parser.setContentHandler(cabHandler)
231 parser.parse('/etc/tuxbox/cables.xml')
233 if (self.hasNimType(self.nimType["DVB-T"])):
234 print "Reading terrestrial.xml"
235 terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
236 parser.setContentHandler(terHandler)
237 parser.parse('/etc/tuxbox/terrestrial.xml')
242 self.nimSocketCount = 0
243 nimfile = tryOpen("/proc/bus/nim_sockets")
246 return self.nimType["empty/unknown"]
251 line = nimfile.readline()
254 if line.strip().startswith("NIM Socket"):
255 parts = line.strip().split(" ")
256 id = int(parts[2][:1])
258 self.nimSocketCount += 1
259 elif line.strip().startswith("Type:"):
260 self.nimTypes[lastsocket] = str(line.strip()[6:])
261 elif line.strip().startswith("Name:"):
262 self.nimNames[lastsocket] = str(line.strip()[6:])
263 elif line.strip().startswith("empty"):
264 self.nimNames[lastsocket] = _("N/A")
265 self.nimTypes[lastsocket] = "empty/unknown"
269 def getNimType(self, slotID):
270 if slotID >= self.nimCount:
271 return "empty/unknown"
273 return self.nimType[self.nimTypes[slotID]]
275 def getNimName(self, slotID):
276 return self.nimNames[slotID]
278 def getNimSocketCount(self):
279 return self.nimSocketCount
281 def hasNimType(self, chktype):
282 for id, type in self.nimTypes.items():
283 if (chktype == self.nimType[str(type)]):
287 def getNimListOfType(self, type, exception = -1):
289 for x in self.nimslots:
290 if ((x.nimType == type) and (x.slotid != exception)):
291 list.append(x.slotid)
294 def getConfigPrefix(self, slotid):
295 return "config.Nim" + ("A","B","C","D")[slotid] + "."
299 self.nimType = { "empty/unknown": -1,
305 self.terrestrialsList = []
309 self.readSatsfromFile()
311 self.nimCount = self.getNimSocketCount()
315 while x < self.nimCount:
316 tType = self.getNimType(x)
317 tName = self.getNimName(x)
318 tNim = nimSlot(x, tType, tName)
319 self.nimslots.append(tNim)
322 InitNimManager(self) #init config stuff
326 for slot in self.nimslots:
327 nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
328 if slot.nimType == -1:
329 nimText += _("empty/unknown")
331 nimText += slot.name + " ("
332 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
333 list.append((nimText, slot))
336 def getSatListForNim(self, slotid):
338 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
339 #print "slotid:", slotid
341 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
342 #print "diseqcA:", config.Nims[slotid].diseqcA.value
343 if (config.Nims[slotid].diseqcMode.value <= 3):
344 list.append(self.satList[config.Nims[slotid].diseqcA.value])
345 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
346 list.append(self.satList[config.Nims[slotid].diseqcB.value])
347 if (config.Nims[slotid].diseqcMode.value == 3):
348 list.append(self.satList[config.Nims[slotid].diseqcC.value])
349 list.append(self.satList[config.Nims[slotid].diseqcD.value])
350 if (config.Nims[slotid].diseqcMode.value == 4):
351 for x in self.satList:
355 #callbacks for c++ config
356 def nimConfigModeChanged(self, slotid, mode):
357 if (mode != 2): # not linked
358 print "Unlinking slot " + str(slotid)
359 # TODO call c++ to unlink nim in slot slotid
360 if (mode == 2): # linked
363 #if (len(self.getNimListOfType(self.nimType["DVB-S"], slotid)) > 0):
364 # print "Linking slot " + str(slotid) + " to " + str(nimmgr.getConfigPrefix(slotid).value)
365 # TODO call c++ to link nim in slot slotid with nim in slot nimmgr.getConfigPrefix(slotid).value
366 def nimLinkedToChanged(self, slotid, val):
367 print "Linking slot " + str(slotid) + " to " + str(val)
369 def nimDiseqcModeChanged(self, slotid, mode):
370 #print "nimDiseqcModeChanged set to " + str(mode)
372 def nimPortAChanged(self, slotid, val):
373 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
375 def nimPortBChanged(self, slotid, val):
376 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
377 #print "nimDiseqcB set to " + str(val)
379 def nimPortCChanged(self, slotid, val):
380 #print "nimDiseqcC set to " + str(val)
382 def nimPortDChanged(self, slotid, val):
383 #print "nimDiseqcD set to " + str(val)
386 def InitNimManager(nimmgr):
388 for x in range(nimmgr.nimCount):
389 config.Nims.append(ConfigSubsection())
391 def nimConfigModeChanged(slotid, configElement):
392 nimmgr.nimConfigModeChanged(slotid, configElement.value)
393 def nimLinkedToChanged(slotid, configElement):
394 nimmgr.nimLinkedToChanged(slotid, configElement.value)
395 def nimDiseqcModeChanged(slotid, configElement):
396 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
398 def nimPortAChanged(slotid, configElement):
399 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
400 def nimPortBChanged(slotid, configElement):
401 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
402 def nimPortCChanged(slotid, configElement):
403 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
404 def nimPortDChanged(slotid, configElement):
405 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
407 for slot in nimmgr.nimslots:
409 cname = nimmgr.getConfigPrefix(x)
412 if slot.nimType == nimmgr.nimType["DVB-S"]:
413 nim.configMode = configElement(cname + "configMode", configSelection, 0, (_("Simple"), _("Nothing connected"), _("Loopthrough to Socket A"))) # "Advanced"));
415 #important - check if just the 2nd one is LT only and the first one is DVB-S
416 if nim.configMode.value == 2: #linked
417 if x == 0: #first one can never be linked to anything
418 nim.configMode.value = 0 #reset to simple
419 nim.configMode.save()
421 #FIXME: make it better
422 for y in nimmgr.nimslots:
424 if y.nimType != nimmgr.nimType["DVB-S"]:
425 nim.configMode.value = 0 #reset to simple
426 nim.configMode.save()
428 nim.diseqcMode = configElement(cname + "diseqcMode", configSelection, 2, (_("Single"), _("Toneburst A/B"), _("DiSEqC A/B"), _("DiSEqC A/B/C/D"), _("Positioner")));
429 nim.diseqcA = configElement(cname + "diseqcA", configSatlist, 192, nimmgr.satList);
430 nim.diseqcB = configElement(cname + "diseqcB", configSatlist, 130, nimmgr.satList);
431 nim.diseqcC = configElement(cname + "diseqcC", configSatlist, 0, nimmgr.satList);
432 nim.diseqcD = configElement(cname + "diseqcD", configSatlist, 0, nimmgr.satList);
433 nim.positionerMode = configElement(cname + "positionerMode", configSelection, 0, (_("USALS"), _("manual")));
434 nim.longitude = configElement(cname + "longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
435 nim.longitudeOrientation = configElement(cname + "longitudeOrientation", configSelection, 0, (_("East"), _("West")))
436 nim.latitude = configElement(cname + "latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
437 nim.latitudeOrientation = configElement(cname + "latitudeOrientation", configSelection, 0, (_("North"), _("South")))
438 satNimList = nimmgr.getNimListOfType(nimmgr.nimType["DVB-S"], slot.slotid)
441 satNimListNames.append(_("Slot ") + ("A", "B", "C", "D")[x] + ": " + nimmgr.getNimName(x))
442 nim.linkedTo = configElement(cname + "linkedTo", configSelection, 0, satNimListNames);
444 #perhaps the instance of the slot is more useful?
445 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
446 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
447 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
448 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
449 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
450 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
451 nim.linkedTo.addNotifier(boundFunction(nimLinkedToChanged,x))
452 elif slot.nimType == nimmgr.nimType["DVB-C"]:
453 nim.cable = configElement(cname + "cable", configSelection, 0, nimmgr.cablesList);
454 elif slot.nimType == nimmgr.nimType["DVB-T"]:
455 nim.cable = configElement(cname + "terrestrial", configSelection, 0, nimmgr.terrestrialsList);
457 print "pls add support for this frontend type!"
459 nimmgr.sec = SecConfigure(nimmgr)
461 nimmanager = NimManager()