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 == 1:
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 = 0, loDirection = 0, latitude = 0, laDirection = 0)
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 = attrs.get('position',"")
131 tname = attrs.get('name',"")
132 self.satellites[tpos] = tname
133 self.satList.append( (tname, tpos) )
134 self.parsedSat = int(tpos)
135 elif (name == "transponder"):
136 freq = int(attrs.get('frequency',""))
137 sr = int(attrs.get('symbol_rate',""))
138 pol = int(attrs.get('polarization',""))
139 fec = int(attrs.get('fec_inner',""))
140 if self.parsedSat in self.transponders:
143 self.transponders[self.parsedSat] = [ ]
145 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
147 class parseCables(ContentHandler):
148 def __init__(self, cablesList, transponders):
149 self.isPointsElement, self.isReboundsElement = 0, 0
150 self.cablesList = cablesList
151 self.transponders = transponders
153 def startElement(self, name, attrs):
154 if (name == "cable"):
155 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
156 tname = attrs.get('name',"")
157 self.cablesList.append(str(tname))
158 self.parsedCab = str(tname)
159 elif (name == "transponder"):
160 freq = int(attrs.get('frequency',""))
161 sr = int(attrs.get('symbol_rate',""))
162 mod = int(attrs.get('modulation',""))
163 fec = int(attrs.get('fec_inner',""))
164 if self.parsedCab in self.transponders:
167 self.transponders[self.parsedCab] = [ ]
169 self.transponders[self.parsedCab].append((0, freq, sr, mod, fec))
171 class parseTerrestrials(ContentHandler):
172 def __init__(self, terrestrialsList, transponders):
173 self.isPointsElement, self.isReboundsElement = 0, 0
174 self.terrestrialsList = terrestrialsList
175 self.transponders = transponders
177 def startElement(self, name, attrs):
178 if (name == "terrestrial"):
179 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
180 tname = attrs.get('name',"")
181 tflags = attrs.get('flags',"")
182 self.terrestrialsList.append((tname, tflags))
183 self.parsedTer = str(tname)
184 elif (name == "transponder"):
186 freq = int(attrs.get('centre_frequency',""))
187 bw = int(attrs.get('bandwidth',""))
188 const = int(attrs.get('constellation',""))
189 crh = int(attrs.get('code_rate_hp',""))
190 crl = int(attrs.get('code_rate_lp',""))
191 guard = int(attrs.get('guard_interval',""))
192 transm = int(attrs.get('transmission_mode',""))
193 hierarchy = int(attrs.get('hierarchy_information',""))
194 inv = int(attrs.get('inversion',""))
195 if self.parsedTer in self.transponders:
198 self.transponders[self.parsedTer] = [ ]
200 self.transponders[self.parsedTer].append((0, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
202 def getTransponders(self, pos):
203 return self.transponders[pos]
205 def getConfiguredSats(self):
206 return self.sec.getSatList()
208 def getSatDescription(self, pos):
209 return self.satellites[str(pos)]
211 def readSatsfromFile(self):
212 self.satellites = { }
213 self.transponders = { }
214 self.transponderscable = { }
215 self.transpondersterrestrial = { }
217 parser = make_parser()
218 if (self.hasNimType(self.nimType["DVB-S"])):
219 print "Reading satellites.xml"
220 satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
221 parser.setContentHandler(satHandler)
222 parser.parse('/etc/tuxbox/satellites.xml')
223 if (self.hasNimType(self.nimType["DVB-C"])):
224 print "Reading cables.xml"
225 cabHandler = self.parseCables(self.cablesList, self.transponderscable)
226 parser.setContentHandler(cabHandler)
227 parser.parse('/etc/tuxbox/cables.xml')
229 if (self.hasNimType(self.nimType["DVB-T"])):
230 print "Reading terrestrial.xml"
231 terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
232 parser.setContentHandler(terHandler)
233 parser.parse('/etc/tuxbox/terrestrial.xml')
238 self.nimSocketCount = 0
239 nimfile = tryOpen("/proc/bus/nim_sockets")
242 return self.nimType["empty/unknown"]
247 line = nimfile.readline()
250 if line.strip().startswith("NIM Socket"):
251 parts = line.strip().split(" ")
252 id = int(parts[2][:1])
254 self.nimSocketCount += 1
255 elif line.strip().startswith("Type:"):
256 self.nimTypes[lastsocket] = str(line.strip()[6:])
257 elif line.strip().startswith("Name:"):
258 self.nimNames[lastsocket] = str(line.strip()[6:])
259 elif line.strip().startswith("empty"):
260 self.nimNames[lastsocket] = _("N/A")
261 self.nimTypes[lastsocket] = "empty/unknown"
265 def getNimType(self, slotID):
266 if slotID >= self.nimCount:
267 return "empty/unknown"
269 return self.nimType[self.nimTypes[slotID]]
271 def getNimName(self, slotID):
272 return self.nimNames[slotID]
274 def getNimSocketCount(self):
275 return self.nimSocketCount
277 def hasNimType(self, chktype):
278 for id, type in self.nimTypes.items():
279 if (chktype == self.nimType[str(type)]):
283 def getNimListOfType(self, type, exception = -1):
285 for x in self.nimslots:
286 if ((x.nimType == type) and (x.slotid != exception)):
287 list.append(x.slotid)
290 def getConfigPrefix(self, slotid):
291 return "config.Nim" + ("A","B","C","D")[slotid] + "."
295 self.nimType = { "empty/unknown": -1,
301 self.terrestrialsList = []
305 self.readSatsfromFile()
307 self.nimCount = self.getNimSocketCount()
311 while x < self.nimCount:
312 tType = self.getNimType(x)
313 tName = self.getNimName(x)
314 tNim = nimSlot(x, tType, tName)
315 self.nimslots.append(tNim)
318 InitNimManager(self) #init config stuff
322 for slot in self.nimslots:
323 nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
324 if slot.nimType == -1:
325 nimText += _("empty/unknown")
327 nimText += slot.name + " ("
328 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
329 list.append((nimText, slot))
332 def getSatListForNim(self, slotid):
334 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
335 #print "slotid:", slotid
337 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
338 #print "diseqcA:", config.Nims[slotid].diseqcA.value
339 if (config.Nims[slotid].diseqcMode.value <= 3):
340 list.append(self.satList[config.Nims[slotid].diseqcA.value])
341 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
342 list.append(self.satList[config.Nims[slotid].diseqcB.value])
343 if (config.Nims[slotid].diseqcMode.value == 3):
344 list.append(self.satList[config.Nims[slotid].diseqcC.value])
345 list.append(self.satList[config.Nims[slotid].diseqcD.value])
348 #callbacks for c++ config
349 def nimConfigModeChanged(self, slotid, mode):
350 if (mode != 1): # not linked
351 print "Unlinking slot " + str(slotid)
352 # TODO call c++ to unlink nim in slot slotid
353 if (mode == 1): # linked
356 #if (len(self.getNimListOfType(self.nimType["DVB-S"], slotid)) > 0):
357 # print "Linking slot " + str(slotid) + " to " + str(nimmgr.getConfigPrefix(slotid).value)
358 # TODO call c++ to link nim in slot slotid with nim in slot nimmgr.getConfigPrefix(slotid).value
359 def nimLinkedToChanged(self, slotid, val):
360 print "Linking slot " + str(slotid) + " to " + str(val)
362 def nimDiseqcModeChanged(self, slotid, mode):
363 #print "nimDiseqcModeChanged set to " + str(mode)
365 def nimPortAChanged(self, slotid, val):
366 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
368 def nimPortBChanged(self, slotid, val):
369 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
370 #print "nimDiseqcB set to " + str(val)
372 def nimPortCChanged(self, slotid, val):
373 #print "nimDiseqcC set to " + str(val)
375 def nimPortDChanged(self, slotid, val):
376 #print "nimDiseqcD set to " + str(val)
379 def InitNimManager(nimmgr):
381 for x in range(nimmgr.nimCount):
382 config.Nims.append(ConfigSubsection())
384 def nimConfigModeChanged(slotid, configElement):
385 nimmgr.nimConfigModeChanged(slotid, configElement.value)
386 def nimLinkedToChanged(slotid, configElement):
387 nimmgr.nimLinkedToChanged(slotid, configElement.value)
388 def nimDiseqcModeChanged(slotid, configElement):
389 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
391 def nimPortAChanged(slotid, configElement):
392 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
393 def nimPortBChanged(slotid, configElement):
394 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
395 def nimPortCChanged(slotid, configElement):
396 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
397 def nimPortDChanged(slotid, configElement):
398 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
400 for slot in nimmgr.nimslots:
402 cname = nimmgr.getConfigPrefix(x)
405 if slot.nimType == nimmgr.nimType["DVB-S"]:
406 nim.configMode = configElement(cname + "configMode", configSelection, 0, (_("Simple"), _("Loopthrough to Socket A"))) # "Advanced"));
408 #important - check if just the 2nd one is LT only and the first one is DVB-S
409 if nim.configMode.value == 1: #linked
410 if x == 0: #first one can never be linked to anything
411 nim.configMode.value = 0 #reset to simple
412 nim.configMode.save()
414 #FIXME: make it better
415 for y in nimmgr.nimslots:
417 if y.nimType != nimmgr.nimType["DVB-S"]:
418 nim.configMode.value = 0 #reset to simple
419 nim.configMode.save()
421 nim.diseqcMode = configElement(cname + "diseqcMode", configSelection, 2, (_("Single"), _("Toneburst A/B"), _("DiSEqC A/B"), _("DiSEqC A/B/C/D"), _("Positioner")));
422 nim.diseqcA = configElement(cname + "diseqcA", configSatlist, 192, nimmgr.satList);
423 nim.diseqcB = configElement(cname + "diseqcB", configSatlist, 130, nimmgr.satList);
424 nim.diseqcC = configElement(cname + "diseqcC", configSatlist, 0, nimmgr.satList);
425 nim.diseqcD = configElement(cname + "diseqcD", configSatlist, 0, nimmgr.satList);
426 nim.positionerMode = configElement(cname + "positionerMode", configSelection, 0, (_("USALS"), _("manual")));
427 nim.longitude = configElement(cname + "longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
428 nim.longitudeOrientation = configElement(cname + "longitudeOrientation", configSelection, 0, (_("East"), _("West")))
429 nim.latitude = configElement(cname + "latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
430 nim.latitudeOrientation = configElement(cname + "latitudeOrientation", configSelection, 0, (_("North"), _("South")))
431 satNimList = nimmgr.getNimListOfType(nimmgr.nimType["DVB-S"], slot.slotid)
434 satNimListNames.append(_("Slot ") + ("A", "B", "C", "D")[x] + ": " + nimmgr.getNimName(x))
435 nim.linkedTo = configElement(cname + "linkedTo", configSelection, 0, satNimListNames);
437 #perhaps the instance of the slot is more useful?
438 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
439 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
440 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
441 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
442 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
443 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
444 nim.linkedTo.addNotifier(boundFunction(nimLinkedToChanged,x))
445 elif slot.nimType == nimmgr.nimType["DVB-C"]:
446 nim.cable = configElement(cname + "cable", configSelection, 0, nimmgr.cablesList);
447 elif slot.nimType == nimmgr.nimType["DVB-T"]:
448 nim.cable = configElement(cname + "terrestrial", configSelection, 0, nimmgr.terrestrialsList);
450 print "pls add support for this frontend type!"
452 nimmgr.sec = SecConfigure(nimmgr)
454 nimmanager = NimManager()