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 currentConfigSelectionElement
8 from config import getConfigSelectionElement
9 from config import configSequence
10 from config import configsequencearg
11 from config import configSatlist
15 import xml.dom.minidom
16 from xml.dom import EMPTY_NAMESPACE
17 from skin import elementsWithTag
18 from Tools import XMLTools
20 from xml.sax import make_parser
21 from xml.sax.handler import ContentHandler
23 from Tools.BoundFunction import boundFunction
25 def tryOpen(filename):
27 procFile = open(filename)
33 def addLNBSimple(self, slotid, diseqcmode, toneburstmode = 0, diseqcpos = 0, orbpos = 0, longitude = 0, latitude = 0, loDirection = 0, laDirection = 0):
35 sec = eDVBSatelliteEquipmentControl.getInstance()
37 sec.setLNBTunerMask(1 << slotid)
38 sec.setLNBLOFL(9750000)
39 sec.setLNBLOFH(10600000)
40 sec.setLNBThreshold(11750000)
44 sec.setVoltageMode(0) #HV
45 sec.setToneMode(0) #HILO
46 sec.setCommandOrder(0)
48 sec.setDiSEqCMode(diseqcmode)
49 sec.setToneburst(toneburstmode)
50 sec.setCommittedCommand(diseqcpos)
51 #print "set orbpos to:" + str(orbpos)
53 if (0 <= diseqcmode < 3):
54 sec.addSatellite(orbpos)
55 self.satList.append(orbpos)
56 elif (diseqcmode == 3): # diseqc 1.2
57 sec.setLatitude(latitude)
58 sec.setLaDirection(laDirection)
59 sec.setLongitude(longitude)
60 sec.setLoDirection(loDirection)
61 sec.setUseInputpower(True)
62 sec.setInputpowerDelta(50)
64 for x in self.NimManager.satList:
65 print "Add sat " + str(x[1])
66 sec.addSatellite(int(x[1]))
69 self.satList.append(int(x[1]))
72 def linkNIMs(self, nim1, nim2):
73 eDVBSatelliteEquipmentControl.getInstance().setTunerLinked(nim1, nim2)
79 eDVBSatelliteEquipmentControl.getInstance().clear()
83 for slot in self.NimManager.nimslots:
86 if slot.nimType == self.NimManager.nimType["DVB-S"]:
87 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
88 if currentConfigSelectionElement(nim.configMode) == "loopthrough":
89 self.linkNIMs(x, nim.linkedTo.value)
90 nim = config.Nims[nim.linkedTo.value]
91 elif currentConfigSelectionElement(nim.configMode) == "simple": #simple config
92 if currentConfigSelectionElement(nim.diseqcMode) == "single": #single
93 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 0, diseqcpos = 4)
94 elif currentConfigSelectionElement(nim.diseqcMode) == "toneburst_a_b": #Toneburst A/B
95 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 1, diseqcmode = 0, diseqcpos = 4)
96 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 1, diseqcmode = 0, diseqcpos = 4)
97 elif currentConfigSelectionElement(nim.diseqcMode) == "diseqc_a_b": #DiSEqC A/B
98 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 0)
99 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 1)
100 elif currentConfigSelectionElement(nim.diseqcMode) == "diseqc_a_b_c_d": #DiSEqC A/B/C/D
101 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcA.vals[nim.diseqcA.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 0)
102 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcB.vals[nim.diseqcB.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 1)
103 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcC.vals[nim.diseqcC.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 2)
104 self.addLNBSimple(slotid = x, orbpos = int(nim.diseqcD.vals[nim.diseqcD.value][1]), toneburstmode = 0, diseqcmode = 1, diseqcpos = 3)
105 elif currentConfigSelectionElement(nim.diseqcMode) == "positioner": #Positioner
106 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)
108 elif currentConfigSelectionElement(nim.configMode) == "nothing":
110 else: #advanced config
111 print "FIXME add support for advanced config"
113 def __init__(self, nimmgr):
114 self.NimManager = nimmgr
118 def __init__(self, slotid, nimtype, name):
120 self.nimType = nimtype
124 class parseSats(ContentHandler):
125 def __init__(self, satList, satellites, transponders):
126 self.isPointsElement, self.isReboundsElement = 0, 0
127 self.satList = satList
128 self.satellites = satellites
129 self.transponders = transponders
131 def startElement(self, name, attrs):
133 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
134 tpos = int(attrs.get('position',""))
137 tname = attrs.get('name',"")
138 self.satellites[tpos] = tname
139 self.satList.append( (tname, tpos) )
140 self.parsedSat = int(tpos)
141 elif (name == "transponder"):
142 freq = int(attrs.get('frequency',""))
143 sr = int(attrs.get('symbol_rate',""))
144 pol = int(attrs.get('polarization',""))
145 fec = int(attrs.get('fec_inner',""))
146 if self.parsedSat in self.transponders:
149 self.transponders[self.parsedSat] = [ ]
151 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
153 class parseCables(ContentHandler):
154 def __init__(self, cablesList, transponders):
155 self.isPointsElement, self.isReboundsElement = 0, 0
156 self.cablesList = cablesList
157 self.transponders = transponders
159 def startElement(self, name, attrs):
160 if (name == "cable"):
161 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
162 tname = attrs.get('name',"")
163 self.cablesList.append(str(tname))
164 self.parsedCab = str(tname)
165 elif (name == "transponder"):
166 freq = int(attrs.get('frequency',""))
167 sr = int(attrs.get('symbol_rate',""))
168 mod = int(attrs.get('modulation',""))
169 fec = int(attrs.get('fec_inner',""))
170 if self.parsedCab in self.transponders:
173 self.transponders[self.parsedCab] = [ ]
175 self.transponders[self.parsedCab].append((1, freq, sr, mod, fec))
177 class parseTerrestrials(ContentHandler):
178 def __init__(self, terrestrialsList, transponders):
179 self.isPointsElement, self.isReboundsElement = 0, 0
180 self.terrestrialsList = terrestrialsList
181 self.transponders = transponders
183 def startElement(self, name, attrs):
184 if (name == "terrestrial"):
185 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
186 tname = attrs.get('name',"")
187 tflags = attrs.get('flags',"")
188 self.terrestrialsList.append((tname, tflags))
189 self.parsedTer = str(tname)
190 elif (name == "transponder"):
192 freq = int(attrs.get('centre_frequency',""))
193 bw = int(attrs.get('bandwidth',""))
194 const = int(attrs.get('constellation',""))
195 crh = int(attrs.get('code_rate_hp',""))
196 crl = int(attrs.get('code_rate_lp',""))
197 guard = int(attrs.get('guard_interval',""))
198 transm = int(attrs.get('transmission_mode',""))
199 hierarchy = int(attrs.get('hierarchy_information',""))
200 inv = int(attrs.get('inversion',""))
201 if self.parsedTer in self.transponders:
204 self.transponders[self.parsedTer] = [ ]
206 self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
208 def getTransponders(self, pos):
209 return self.transponders[pos]
211 def getConfiguredSats(self):
212 return self.sec.getSatList()
214 def getSatDescription(self, pos):
215 return self.satellites[pos]
217 def readSatsfromFile(self):
218 self.satellites = { }
219 self.transponders = { }
220 self.transponderscable = { }
221 self.transpondersterrestrial = { }
223 parser = make_parser()
224 if (self.hasNimType(self.nimType["DVB-S"])):
225 print "Reading satellites.xml"
226 satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
227 parser.setContentHandler(satHandler)
228 parser.parse('/etc/tuxbox/satellites.xml')
229 if (self.hasNimType(self.nimType["DVB-C"])):
230 print "Reading cables.xml"
231 cabHandler = self.parseCables(self.cablesList, self.transponderscable)
232 parser.setContentHandler(cabHandler)
233 parser.parse('/etc/tuxbox/cables.xml')
235 if (self.hasNimType(self.nimType["DVB-T"])):
236 print "Reading terrestrial.xml"
237 terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
238 parser.setContentHandler(terHandler)
239 parser.parse('/etc/tuxbox/terrestrial.xml')
244 self.nimSocketCount = 0
245 nimfile = tryOpen("/proc/bus/nim_sockets")
248 return self.nimType["empty/unknown"]
253 line = nimfile.readline()
256 if line.strip().startswith("NIM Socket"):
257 parts = line.strip().split(" ")
258 id = int(parts[2][:1])
260 self.nimSocketCount += 1
261 elif line.strip().startswith("Type:"):
262 self.nimTypes[lastsocket] = str(line.strip()[6:])
263 elif line.strip().startswith("Name:"):
264 self.nimNames[lastsocket] = str(line.strip()[6:])
265 elif line.strip().startswith("empty"):
266 self.nimNames[lastsocket] = _("N/A")
267 self.nimTypes[lastsocket] = "empty/unknown"
271 def getNimType(self, slotID):
272 if slotID >= self.nimCount:
273 return "empty/unknown"
275 return self.nimType[self.nimTypes[slotID]]
277 def getNimName(self, slotID):
278 return self.nimNames[slotID]
280 def getNimSocketCount(self):
281 return self.nimSocketCount
283 def hasNimType(self, chktype):
284 for id, type in self.nimTypes.items():
285 if (chktype == self.nimType[str(type)]):
289 def getNimListOfType(self, type, exception = -1):
291 for x in self.nimslots:
292 if ((x.nimType == type) and (x.slotid != exception)):
293 list.append(x.slotid)
296 def getConfigPrefix(self, slotid):
297 return "config.Nim" + ("A","B","C","D")[slotid] + "."
301 self.nimType = { "empty/unknown": -1,
307 self.terrestrialsList = []
311 self.readSatsfromFile()
313 self.nimCount = self.getNimSocketCount()
317 while x < self.nimCount:
318 tType = self.getNimType(x)
319 tName = self.getNimName(x)
320 tNim = nimSlot(x, tType, tName)
321 self.nimslots.append(tNim)
324 InitNimManager(self) #init config stuff
328 for slot in self.nimslots:
329 nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
330 if slot.nimType == -1:
331 nimText += _("empty/unknown")
333 nimText += slot.name + " ("
334 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
335 list.append((nimText, slot))
338 def getSatListForNim(self, slotid):
340 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
341 #print "slotid:", slotid
343 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
344 #print "diseqcA:", config.Nims[slotid].diseqcA.value
345 if (config.Nims[slotid].diseqcMode.value <= 3):
346 list.append(self.satList[config.Nims[slotid].diseqcA.value])
347 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
348 list.append(self.satList[config.Nims[slotid].diseqcB.value])
349 if (config.Nims[slotid].diseqcMode.value == 3):
350 list.append(self.satList[config.Nims[slotid].diseqcC.value])
351 list.append(self.satList[config.Nims[slotid].diseqcD.value])
352 if (config.Nims[slotid].diseqcMode.value == 4):
353 for x in self.satList:
357 #callbacks for c++ config
358 def nimConfigModeChanged(self, slotid, mode):
359 if (mode != 2): # not linked
360 print "Unlinking slot " + str(slotid)
361 # TODO call c++ to unlink nim in slot slotid
362 if (mode == 2): # linked
365 #if (len(self.getNimListOfType(self.nimType["DVB-S"], slotid)) > 0):
366 # print "Linking slot " + str(slotid) + " to " + str(nimmgr.getConfigPrefix(slotid).value)
367 # TODO call c++ to link nim in slot slotid with nim in slot nimmgr.getConfigPrefix(slotid).value
368 def nimLinkedToChanged(self, slotid, val):
369 print "Linking slot " + str(slotid) + " to " + str(val)
371 def nimDiseqcModeChanged(self, slotid, mode):
372 #print "nimDiseqcModeChanged set to " + str(mode)
374 def nimPortAChanged(self, slotid, val):
375 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
377 def nimPortBChanged(self, slotid, val):
378 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
379 #print "nimDiseqcB set to " + str(val)
381 def nimPortCChanged(self, slotid, val):
382 #print "nimDiseqcC set to " + str(val)
384 def nimPortDChanged(self, slotid, val):
385 #print "nimDiseqcD set to " + str(val)
388 def InitNimManager(nimmgr):
390 for x in range(nimmgr.nimCount):
391 config.Nims.append(ConfigSubsection())
393 def nimConfigModeChanged(slotid, configElement):
394 nimmgr.nimConfigModeChanged(slotid, configElement.value)
395 def nimLinkedToChanged(slotid, configElement):
396 nimmgr.nimLinkedToChanged(slotid, configElement.value)
397 def nimDiseqcModeChanged(slotid, configElement):
398 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
400 def nimPortAChanged(slotid, configElement):
401 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
402 def nimPortBChanged(slotid, configElement):
403 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
404 def nimPortCChanged(slotid, configElement):
405 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
406 def nimPortDChanged(slotid, configElement):
407 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
409 for slot in nimmgr.nimslots:
411 cname = nimmgr.getConfigPrefix(x)
414 if slot.nimType == nimmgr.nimType["DVB-S"]:
416 nim.configMode = configElement(cname + "configMode", configSelection, 0, (("simple", _("Simple")), ("advanced", _("Advanced"))))
418 nim.configMode = configElement(cname + "configMode", configSelection, 0, (("simple", _("Simple")), ("nothing", _("Nothing connected")), ("loopthrough", _("Loopthrough to Socket A")), ("advanced", _("Advanced"))))
420 #important - check if just the 2nd one is LT only and the first one is DVB-S
421 if currentConfigSelectionElement(nim.configMode) == "loopthrough": #linked
422 if x == 0: #first one can never be linked to anything
423 nim.configMode.value = getConfigSelectionElement(nim.configMode, "simple") #reset to simple
424 nim.configMode.save()
426 #FIXME: make it better
427 for y in nimmgr.nimslots:
429 if y.nimType != nimmgr.nimType["DVB-S"]:
430 nim.configMode.value = getConfigSelectionElement(nim.configMode, "simple") #reset to simple
431 nim.configMode.save()
433 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"))));
434 nim.diseqcA = configElement(cname + "diseqcA", configSatlist, 192, nimmgr.satList);
435 nim.diseqcB = configElement(cname + "diseqcB", configSatlist, 130, nimmgr.satList);
436 nim.diseqcC = configElement(cname + "diseqcC", configSatlist, 0, nimmgr.satList);
437 nim.diseqcD = configElement(cname + "diseqcD", configSatlist, 0, nimmgr.satList);
438 nim.positionerMode = configElement(cname + "positionerMode", configSelection, 0, (("usals", _("USALS")), ("manual", _("manual"))));
439 nim.longitude = configElement(cname + "longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
440 nim.longitudeOrientation = configElement(cname + "longitudeOrientation", configSelection, 0, (_("East"), _("West")))
441 nim.latitude = configElement(cname + "latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
442 nim.latitudeOrientation = configElement(cname + "latitudeOrientation", configSelection, 0, (("north", _("North")), ("south", _("South"))))
443 satNimList = nimmgr.getNimListOfType(nimmgr.nimType["DVB-S"], slot.slotid)
446 satNimListNames.append((("Slot_" + ("A", "B", "C", "D")[x] + "_" + nimmgr.getNimName(x)), _("Slot ") + ("A", "B", "C", "D")[x] + ": " + nimmgr.getNimName(x)))
447 nim.linkedTo = configElement(cname + "linkedTo", configSelection, 0, satNimListNames);
449 #perhaps the instance of the slot is more useful?
450 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
451 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
452 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
453 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
454 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
455 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
456 nim.linkedTo.addNotifier(boundFunction(nimLinkedToChanged,x))
457 elif slot.nimType == nimmgr.nimType["DVB-C"]:
458 nim.cable = configElement(cname + "cable", configSelection, 0, nimmgr.cablesList);
459 elif slot.nimType == nimmgr.nimType["DVB-T"]:
460 nim.cable = configElement(cname + "terrestrial", configSelection, 0, nimmgr.terrestrialsList);
462 print "pls add support for this frontend type!"
464 nimmgr.sec = SecConfigure(nimmgr)
466 nimmanager = NimManager()