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, orbpos, toneburstmode, diseqcmode, diseqcpos):
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)
50 sec.addSatellite(orbpos)
51 self.satList.append(orbpos)
53 def linkNIMs(self, nim1, nim2):
54 eDVBSatelliteEquipmentControl.getInstance().setTunerLinked(nim1, nim2)
60 eDVBSatelliteEquipmentControl.getInstance().clear()
64 for slot in self.NimManager.nimslots:
67 if slot.nimType == self.NimManager.nimType["DVB-S"]:
68 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
69 if nim.configMode.value == 1:
70 self.linkNIMs(x, nim.linkedTo.value)
71 nim = config.Nims[nim.linkedTo.value]
72 if nim.configMode.value == 0 or nim.configMode.value == 1: #simple config
73 if nim.diseqcMode.value == 0: #single
74 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 0, 4)
75 elif nim.diseqcMode.value == 1: #Toneburst A/B
76 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 1, 0, 4)
77 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 1, 0, 4)
78 elif nim.diseqcMode.value == 2: #DiSEqC A/B
79 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 1, 0)
80 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 0, 1, 1)
81 elif nim.diseqcMode.value == 3: #DiSEqC A/B/C/D
82 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 1, 0)
83 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 0, 1, 1)
84 self.addLNBSimple(x, int(nim.diseqcC.vals[nim.diseqcC.value][1]), 0, 1, 2)
85 self.addLNBSimple(x, int(nim.diseqcD.vals[nim.diseqcD.value][1]), 0, 1, 3)
86 elif nim.diseqcMode.value == 4: #Positioner
87 print "FIXME: positioner suppport"
89 else: #advanced config
90 print "FIXME add support for advanced config"
92 def __init__(self, nimmgr):
93 self.NimManager = nimmgr
97 def __init__(self, slotid, nimtype, name):
99 self.nimType = nimtype
103 class parseSats(ContentHandler):
104 def __init__(self, satList, satellites, transponders):
105 self.isPointsElement, self.isReboundsElement = 0, 0
106 self.satList = satList
107 self.satellites = satellites
108 self.transponders = transponders
110 def startElement(self, name, attrs):
112 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
113 tpos = attrs.get('position',"")
114 tname = attrs.get('name',"")
115 self.satellites[tpos] = tname
116 self.satList.append( (tname, tpos) )
117 self.parsedSat = int(tpos)
118 elif (name == "transponder"):
119 freq = int(attrs.get('frequency',""))
120 sr = int(attrs.get('symbol_rate',""))
121 pol = int(attrs.get('polarization',""))
122 fec = int(attrs.get('fec_inner',""))
123 if self.parsedSat in self.transponders:
126 self.transponders[self.parsedSat] = [ ]
128 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
130 class parseCables(ContentHandler):
131 def __init__(self, cablesList, transponders):
132 self.isPointsElement, self.isReboundsElement = 0, 0
133 self.cablesList = cablesList
134 self.transponders = transponders
136 def startElement(self, name, attrs):
137 if (name == "cable"):
138 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
139 tname = attrs.get('name',"")
140 self.cablesList.append(str(tname))
141 self.parsedCab = str(tname)
142 elif (name == "transponder"):
143 freq = int(attrs.get('frequency',""))
144 sr = int(attrs.get('symbol_rate',""))
145 mod = int(attrs.get('modulation',""))
146 fec = int(attrs.get('fec_inner',""))
147 if self.parsedCab in self.transponders:
150 self.transponders[self.parsedCab] = [ ]
152 self.transponders[self.parsedCab].append((0, freq, sr, mod, fec))
154 class parseTerrestrials(ContentHandler):
155 def __init__(self, terrestrialsList, transponders):
156 self.isPointsElement, self.isReboundsElement = 0, 0
157 self.terrestrialsList = terrestrialsList
158 self.transponders = transponders
160 def startElement(self, name, attrs):
161 if (name == "terrestrial"):
162 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
163 tname = attrs.get('name',"")
164 tflags = attrs.get('flags',"")
165 self.terrestrialsList.append((tname, tflags))
166 self.parsedTer = str(tname)
167 elif (name == "transponder"):
169 freq = int(attrs.get('centre_frequency',""))
170 bw = int(attrs.get('bandwidth',""))
171 const = int(attrs.get('constellation',""))
172 crh = int(attrs.get('code_rate_hp',""))
173 crl = int(attrs.get('code_rate_lp',""))
174 guard = int(attrs.get('guard_interval',""))
175 transm = int(attrs.get('transmission_mode',""))
176 hierarchy = int(attrs.get('hierarchy_information',""))
177 inv = int(attrs.get('inversion',""))
178 if self.parsedTer in self.transponders:
181 self.transponders[self.parsedTer] = [ ]
183 self.transponders[self.parsedTer].append((0, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
185 def getTransponders(self, pos):
186 return self.transponders[pos]
188 def getConfiguredSats(self):
189 return self.sec.getSatList()
191 def getSatDescription(self, pos):
192 return self.satellites[str(pos)]
194 def readSatsfromFile(self):
195 self.satellites = { }
196 self.transponders = { }
197 self.transponderscable = { }
198 self.transpondersterrestrial = { }
200 parser = make_parser()
201 if (self.hasNimType(self.nimType["DVB-S"])):
202 print "Reading satellites.xml"
203 satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
204 parser.setContentHandler(satHandler)
205 parser.parse('/etc/tuxbox/satellites.xml')
206 if (self.hasNimType(self.nimType["DVB-C"])):
207 print "Reading cables.xml"
208 cabHandler = self.parseCables(self.cablesList, self.transponderscable)
209 parser.setContentHandler(cabHandler)
210 parser.parse('/etc/tuxbox/cables.xml')
212 if (self.hasNimType(self.nimType["DVB-T"])):
213 print "Reading terrestrial.xml"
214 terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
215 parser.setContentHandler(terHandler)
216 parser.parse('/etc/tuxbox/terrestrial.xml')
221 self.nimSocketCount = 0
222 nimfile = tryOpen("/proc/bus/nim_sockets")
225 return self.nimType["empty/unknown"]
230 line = nimfile.readline()
233 if line.strip().startswith("NIM Socket"):
234 parts = line.strip().split(" ")
235 id = int(parts[2][:1])
237 self.nimSocketCount += 1
238 elif line.strip().startswith("Type:"):
239 self.nimTypes[lastsocket] = str(line.strip()[6:])
240 elif line.strip().startswith("Name:"):
241 self.nimNames[lastsocket] = str(line.strip()[6:])
242 elif line.strip().startswith("empty"):
243 self.nimNames[lastsocket] = _("N/A")
244 self.nimTypes[lastsocket] = "empty/unknown"
249 def getNimType(self, slotID):
250 return self.nimType[self.nimTypes[slotID]]
252 def getNimName(self, slotID):
253 return self.nimNames[slotID]
255 def getNimSocketCount(self):
256 return self.nimSocketCount
258 def hasNimType(self, chktype):
259 for id, type in self.nimTypes.items():
260 if (chktype == self.nimType[str(type)]):
264 def getNimListOfType(self, type, exception = -1):
266 for x in self.nimslots:
267 if ((x.nimType == type) and (x.slotid != exception)):
268 list.append(x.slotid)
271 def getConfigPrefix(self, slotid):
272 return "config.Nim" + ("A","B","C","D")[slotid] + "."
276 self.nimType = { "empty/unknown": -1,
282 self.terrestrialsList = []
286 self.readSatsfromFile()
288 self.nimCount = self.getNimSocketCount()
292 while x < self.nimCount:
293 tType = self.getNimType(x)
294 tName = self.getNimName(x)
295 tNim = nimSlot(x, tType, tName)
296 self.nimslots.append(tNim)
299 InitNimManager(self) #init config stuff
303 for slot in self.nimslots:
304 nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
305 if slot.nimType == -1:
306 nimText += _("empty/unknown")
308 nimText += slot.name + " ("
309 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
310 list.append((nimText, slot))
313 def getSatListForNim(self, slotid):
315 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
316 #print "slotid:", slotid
318 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
319 #print "diseqcA:", config.Nims[slotid].diseqcA.value
320 if (config.Nims[slotid].diseqcMode.value <= 3):
321 list.append(self.satList[config.Nims[slotid].diseqcA.value])
322 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
323 list.append(self.satList[config.Nims[slotid].diseqcB.value])
324 if (config.Nims[slotid].diseqcMode.value == 3):
325 list.append(self.satList[config.Nims[slotid].diseqcC.value])
326 list.append(self.satList[config.Nims[slotid].diseqcD.value])
329 #callbacks for c++ config
330 def nimConfigModeChanged(self, slotid, mode):
331 if (mode != 1): # not linked
332 print "Unlinking slot " + str(slotid)
333 # TODO call c++ to unlink nim in slot slotid
334 if (mode == 1): # linked
335 if (len(self.getNimListOfType(self.nimType["DVB-S"], slotid)) > 0):
336 print "Linking slot " + str(slotid) + " to " + str(nimmgr.getConfigPrefix(slotid).value)
337 # TODO call c++ to link nim in slot slotid with nim in slot nimmgr.getConfigPrefix(slotid).value
338 def nimLinkedToChanged(self, slotid, val):
339 print "Linking slot " + str(slotid) + " to " + str(val)
341 def nimDiseqcModeChanged(self, slotid, mode):
342 #print "nimDiseqcModeChanged set to " + str(mode)
344 def nimPortAChanged(self, slotid, val):
345 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
347 def nimPortBChanged(self, slotid, val):
348 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
349 #print "nimDiseqcB set to " + str(val)
351 def nimPortCChanged(self, slotid, val):
352 #print "nimDiseqcC set to " + str(val)
354 def nimPortDChanged(self, slotid, val):
355 #print "nimDiseqcD set to " + str(val)
358 def InitNimManager(nimmgr):
360 for x in range(nimmgr.nimCount):
361 config.Nims.append(ConfigSubsection())
363 def nimConfigModeChanged(slotid, configElement):
364 nimmgr.nimConfigModeChanged(slotid, configElement.value)
365 def nimLinkedToChanged(slotid, configElement):
366 nimmgr.nimLinkedToChanged(slotid, configElement.value)
367 def nimDiseqcModeChanged(slotid, configElement):
368 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
370 def nimPortAChanged(slotid, configElement):
371 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
372 def nimPortBChanged(slotid, configElement):
373 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
374 def nimPortCChanged(slotid, configElement):
375 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
376 def nimPortDChanged(slotid, configElement):
377 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
379 for slot in nimmgr.nimslots:
381 cname = nimmgr.getConfigPrefix(x)
384 if slot.nimType == nimmgr.nimType["DVB-S"]:
385 nim.configMode = configElement(cname + "configMode", configSelection, 0, (_("Simple"), _("Linked tuner"))) # "Advanced"));
386 nim.diseqcMode = configElement(cname + "diseqcMode", configSelection, 2, (_("Single"), _("Toneburst A/B"), _("DiSEqC A/B"), _("DiSEqC A/B/C/D"), _("Positioner")));
387 nim.diseqcA = configElement(cname + "diseqcA", configSatlist, 192, nimmgr.satList);
388 nim.diseqcB = configElement(cname + "diseqcB", configSatlist, 130, nimmgr.satList);
389 nim.diseqcC = configElement(cname + "diseqcC", configSatlist, 0, nimmgr.satList);
390 nim.diseqcD = configElement(cname + "diseqcD", configSatlist, 0, nimmgr.satList);
391 nim.positionerMode = configElement(cname + "positionerMode", configSelection, 0, (_("USALS"), _("manual")));
392 nim.longitude = configElement(cname + "longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
393 nim.longitudeOrientation = configElement(cname + "longitudeOrientation", configSelection, 0, (_("East"), _("West")))
394 nim.latitude = configElement(cname + "latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
395 nim.latitudeOrientation = configElement(cname + "latitudeOrientation", configSelection, 0, (_("North"), _("South")))
396 satNimList = nimmgr.getNimListOfType(nimmgr.nimType["DVB-S"], slot.slotid)
399 satNimListNames.append(_("Slot ") + ("A", "B", "C", "D")[x] + ": " + nimmgr.getNimName(x))
400 nim.linkedTo = configElement(cname + "linkedTo", configSelection, 0, satNimListNames);
402 #perhaps the instance of the slot is more useful?
403 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
404 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
405 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
406 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
407 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
408 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
409 nim.linkedTo.addNotifier(boundFunction(nimLinkedToChanged,x))
410 elif slot.nimType == nimmgr.nimType["DVB-C"]:
411 nim.cable = configElement(cname + "cable", configSelection, 0, nimmgr.cablesList);
412 elif slot.nimType == nimmgr.nimType["DVB-T"]:
413 nim.cable = configElement(cname + "terrestrial", configSelection, 0, nimmgr.terrestrialsList);
415 print "pls add support for this frontend type!"
417 nimmgr.sec = SecConfigure(nimmgr)
419 nimmanager = NimManager()