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 = attrs.get('position',"")
133 tname = attrs.get('name',"")
134 self.satellites[tpos] = tname
135 self.satList.append( (tname, tpos) )
136 self.parsedSat = int(tpos)
137 elif (name == "transponder"):
138 freq = int(attrs.get('frequency',""))
139 sr = int(attrs.get('symbol_rate',""))
140 pol = int(attrs.get('polarization',""))
141 fec = int(attrs.get('fec_inner',""))
142 if self.parsedSat in self.transponders:
145 self.transponders[self.parsedSat] = [ ]
147 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
149 class parseCables(ContentHandler):
150 def __init__(self, cablesList, transponders):
151 self.isPointsElement, self.isReboundsElement = 0, 0
152 self.cablesList = cablesList
153 self.transponders = transponders
155 def startElement(self, name, attrs):
156 if (name == "cable"):
157 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
158 tname = attrs.get('name',"")
159 self.cablesList.append(str(tname))
160 self.parsedCab = str(tname)
161 elif (name == "transponder"):
162 freq = int(attrs.get('frequency',""))
163 sr = int(attrs.get('symbol_rate',""))
164 mod = int(attrs.get('modulation',""))
165 fec = int(attrs.get('fec_inner',""))
166 if self.parsedCab in self.transponders:
169 self.transponders[self.parsedCab] = [ ]
171 self.transponders[self.parsedCab].append((1, freq, sr, mod, fec))
173 class parseTerrestrials(ContentHandler):
174 def __init__(self, terrestrialsList, transponders):
175 self.isPointsElement, self.isReboundsElement = 0, 0
176 self.terrestrialsList = terrestrialsList
177 self.transponders = transponders
179 def startElement(self, name, attrs):
180 if (name == "terrestrial"):
181 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
182 tname = attrs.get('name',"")
183 tflags = attrs.get('flags',"")
184 self.terrestrialsList.append((tname, tflags))
185 self.parsedTer = str(tname)
186 elif (name == "transponder"):
188 freq = int(attrs.get('centre_frequency',""))
189 bw = int(attrs.get('bandwidth',""))
190 const = int(attrs.get('constellation',""))
191 crh = int(attrs.get('code_rate_hp',""))
192 crl = int(attrs.get('code_rate_lp',""))
193 guard = int(attrs.get('guard_interval',""))
194 transm = int(attrs.get('transmission_mode',""))
195 hierarchy = int(attrs.get('hierarchy_information',""))
196 inv = int(attrs.get('inversion',""))
197 if self.parsedTer in self.transponders:
200 self.transponders[self.parsedTer] = [ ]
202 self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
204 def getTransponders(self, pos):
205 return self.transponders[pos]
207 def getConfiguredSats(self):
208 return self.sec.getSatList()
210 def getSatDescription(self, pos):
211 return self.satellites[str(pos)]
213 def readSatsfromFile(self):
214 self.satellites = { }
215 self.transponders = { }
216 self.transponderscable = { }
217 self.transpondersterrestrial = { }
219 parser = make_parser()
220 if (self.hasNimType(self.nimType["DVB-S"])):
221 print "Reading satellites.xml"
222 satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
223 parser.setContentHandler(satHandler)
224 parser.parse('/etc/tuxbox/satellites.xml')
225 if (self.hasNimType(self.nimType["DVB-C"])):
226 print "Reading cables.xml"
227 cabHandler = self.parseCables(self.cablesList, self.transponderscable)
228 parser.setContentHandler(cabHandler)
229 parser.parse('/etc/tuxbox/cables.xml')
231 if (self.hasNimType(self.nimType["DVB-T"])):
232 print "Reading terrestrial.xml"
233 terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
234 parser.setContentHandler(terHandler)
235 parser.parse('/etc/tuxbox/terrestrial.xml')
240 self.nimSocketCount = 0
241 nimfile = tryOpen("/proc/bus/nim_sockets")
244 return self.nimType["empty/unknown"]
249 line = nimfile.readline()
252 if line.strip().startswith("NIM Socket"):
253 parts = line.strip().split(" ")
254 id = int(parts[2][:1])
256 self.nimSocketCount += 1
257 elif line.strip().startswith("Type:"):
258 self.nimTypes[lastsocket] = str(line.strip()[6:])
259 elif line.strip().startswith("Name:"):
260 self.nimNames[lastsocket] = str(line.strip()[6:])
261 elif line.strip().startswith("empty"):
262 self.nimNames[lastsocket] = _("N/A")
263 self.nimTypes[lastsocket] = "empty/unknown"
267 def getNimType(self, slotID):
268 if slotID >= self.nimCount:
269 return "empty/unknown"
271 return self.nimType[self.nimTypes[slotID]]
273 def getNimName(self, slotID):
274 return self.nimNames[slotID]
276 def getNimSocketCount(self):
277 return self.nimSocketCount
279 def hasNimType(self, chktype):
280 for id, type in self.nimTypes.items():
281 if (chktype == self.nimType[str(type)]):
285 def getNimListOfType(self, type, exception = -1):
287 for x in self.nimslots:
288 if ((x.nimType == type) and (x.slotid != exception)):
289 list.append(x.slotid)
292 def getConfigPrefix(self, slotid):
293 return "config.Nim" + ("A","B","C","D")[slotid] + "."
297 self.nimType = { "empty/unknown": -1,
303 self.terrestrialsList = []
307 self.readSatsfromFile()
309 self.nimCount = self.getNimSocketCount()
313 while x < self.nimCount:
314 tType = self.getNimType(x)
315 tName = self.getNimName(x)
316 tNim = nimSlot(x, tType, tName)
317 self.nimslots.append(tNim)
320 InitNimManager(self) #init config stuff
324 for slot in self.nimslots:
325 nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
326 if slot.nimType == -1:
327 nimText += _("empty/unknown")
329 nimText += slot.name + " ("
330 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
331 list.append((nimText, slot))
334 def getSatListForNim(self, slotid):
336 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
337 #print "slotid:", slotid
339 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
340 #print "diseqcA:", config.Nims[slotid].diseqcA.value
341 if (config.Nims[slotid].diseqcMode.value <= 3):
342 list.append(self.satList[config.Nims[slotid].diseqcA.value])
343 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
344 list.append(self.satList[config.Nims[slotid].diseqcB.value])
345 if (config.Nims[slotid].diseqcMode.value == 3):
346 list.append(self.satList[config.Nims[slotid].diseqcC.value])
347 list.append(self.satList[config.Nims[slotid].diseqcD.value])
348 if (config.Nims[slotid].diseqcMode.value == 4):
349 for x in self.satList:
353 #callbacks for c++ config
354 def nimConfigModeChanged(self, slotid, mode):
355 if (mode != 2): # not linked
356 print "Unlinking slot " + str(slotid)
357 # TODO call c++ to unlink nim in slot slotid
358 if (mode == 2): # linked
361 #if (len(self.getNimListOfType(self.nimType["DVB-S"], slotid)) > 0):
362 # print "Linking slot " + str(slotid) + " to " + str(nimmgr.getConfigPrefix(slotid).value)
363 # TODO call c++ to link nim in slot slotid with nim in slot nimmgr.getConfigPrefix(slotid).value
364 def nimLinkedToChanged(self, slotid, val):
365 print "Linking slot " + str(slotid) + " to " + str(val)
367 def nimDiseqcModeChanged(self, slotid, mode):
368 #print "nimDiseqcModeChanged set to " + str(mode)
370 def nimPortAChanged(self, slotid, val):
371 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
373 def nimPortBChanged(self, slotid, val):
374 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
375 #print "nimDiseqcB set to " + str(val)
377 def nimPortCChanged(self, slotid, val):
378 #print "nimDiseqcC set to " + str(val)
380 def nimPortDChanged(self, slotid, val):
381 #print "nimDiseqcD set to " + str(val)
384 def InitNimManager(nimmgr):
386 for x in range(nimmgr.nimCount):
387 config.Nims.append(ConfigSubsection())
389 def nimConfigModeChanged(slotid, configElement):
390 nimmgr.nimConfigModeChanged(slotid, configElement.value)
391 def nimLinkedToChanged(slotid, configElement):
392 nimmgr.nimLinkedToChanged(slotid, configElement.value)
393 def nimDiseqcModeChanged(slotid, configElement):
394 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
396 def nimPortAChanged(slotid, configElement):
397 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
398 def nimPortBChanged(slotid, configElement):
399 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
400 def nimPortCChanged(slotid, configElement):
401 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
402 def nimPortDChanged(slotid, configElement):
403 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
405 for slot in nimmgr.nimslots:
407 cname = nimmgr.getConfigPrefix(x)
410 if slot.nimType == nimmgr.nimType["DVB-S"]:
411 nim.configMode = configElement(cname + "configMode", configSelection, 0, (_("Simple"), _("Nothing connected"), _("Loopthrough to Socket A"))) # "Advanced"));
413 #important - check if just the 2nd one is LT only and the first one is DVB-S
414 if nim.configMode.value == 2: #linked
415 if x == 0: #first one can never be linked to anything
416 nim.configMode.value = 0 #reset to simple
417 nim.configMode.save()
419 #FIXME: make it better
420 for y in nimmgr.nimslots:
422 if y.nimType != nimmgr.nimType["DVB-S"]:
423 nim.configMode.value = 0 #reset to simple
424 nim.configMode.save()
426 nim.diseqcMode = configElement(cname + "diseqcMode", configSelection, 2, (_("Single"), _("Toneburst A/B"), _("DiSEqC A/B"), _("DiSEqC A/B/C/D"), _("Positioner")));
427 nim.diseqcA = configElement(cname + "diseqcA", configSatlist, 192, nimmgr.satList);
428 nim.diseqcB = configElement(cname + "diseqcB", configSatlist, 130, nimmgr.satList);
429 nim.diseqcC = configElement(cname + "diseqcC", configSatlist, 0, nimmgr.satList);
430 nim.diseqcD = configElement(cname + "diseqcD", configSatlist, 0, nimmgr.satList);
431 nim.positionerMode = configElement(cname + "positionerMode", configSelection, 0, (_("USALS"), _("manual")));
432 nim.longitude = configElement(cname + "longitude", configSequence, [5,100], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
433 nim.longitudeOrientation = configElement(cname + "longitudeOrientation", configSelection, 0, (_("East"), _("West")))
434 nim.latitude = configElement(cname + "latitude", configSequence, [50,767], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
435 nim.latitudeOrientation = configElement(cname + "latitudeOrientation", configSelection, 0, (_("North"), _("South")))
436 satNimList = nimmgr.getNimListOfType(nimmgr.nimType["DVB-S"], slot.slotid)
439 satNimListNames.append(_("Slot ") + ("A", "B", "C", "D")[x] + ": " + nimmgr.getNimName(x))
440 nim.linkedTo = configElement(cname + "linkedTo", configSelection, 0, satNimListNames);
442 #perhaps the instance of the slot is more useful?
443 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
444 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
445 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
446 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
447 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
448 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
449 nim.linkedTo.addNotifier(boundFunction(nimLinkedToChanged,x))
450 elif slot.nimType == nimmgr.nimType["DVB-C"]:
451 nim.cable = configElement(cname + "cable", configSelection, 0, nimmgr.cablesList);
452 elif slot.nimType == nimmgr.nimType["DVB-T"]:
453 nim.cable = configElement(cname + "terrestrial", configSelection, 0, nimmgr.terrestrialsList);
455 print "pls add support for this frontend type!"
457 nimmgr.sec = SecConfigure(nimmgr)
459 nimmanager = NimManager()