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)
57 eDVBSatelliteEquipmentControl.getInstance().clear()
60 for slot in self.NimManager.nimslots:
63 if slot.nimType == self.NimManager.nimType["DVB-S"]:
64 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
65 if nim.configMode.value == 0: #simple config
66 if nim.diseqcMode.value == 0: #single
67 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 0, 4)
68 elif nim.diseqcMode.value == 1: #Toneburst A/B
69 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 1, 0, 4)
70 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 1, 0, 4)
71 elif nim.diseqcMode.value == 2: #DiSEqC A/B
72 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 1, 0)
73 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 0, 1, 1)
74 elif nim.diseqcMode.value == 3: #DiSEqC A/B/C/D
75 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 1, 0)
76 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 0, 1, 1)
77 self.addLNBSimple(x, int(nim.diseqcC.vals[nim.diseqcC.value][1]), 0, 1, 2)
78 self.addLNBSimple(x, int(nim.diseqcD.vals[nim.diseqcD.value][1]), 0, 1, 3)
79 elif nim.diseqcMode.value == 4: #Positioner
80 print "FIXME: positioner suppport"
82 else: #advanced config
83 print "FIXME add support for advanced config"
85 def __init__(self, nimmgr):
86 self.NimManager = nimmgr
90 def __init__(self, slotid, nimtype, name):
92 self.nimType = nimtype
96 class parseSats(ContentHandler):
97 def __init__(self, satList, satellites, transponders):
98 self.isPointsElement, self.isReboundsElement = 0, 0
99 self.satList = satList
100 self.satellites = satellites
101 self.transponders = transponders
103 def startElement(self, name, attrs):
105 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
106 tpos = attrs.get('position',"")
107 tname = attrs.get('name',"")
108 self.satellites[tpos] = tname
109 self.satList.append( (tname, tpos) )
110 self.parsedSat = int(tpos)
111 elif (name == "transponder"):
112 freq = int(attrs.get('frequency',""))
113 sr = int(attrs.get('symbol_rate',""))
114 pol = int(attrs.get('polarization',""))
115 fec = int(attrs.get('fec_inner',""))
116 if self.parsedSat in self.transponders:
119 self.transponders[self.parsedSat] = [ ]
121 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
123 class parseCables(ContentHandler):
124 def __init__(self, cablesList, transponders):
125 self.isPointsElement, self.isReboundsElement = 0, 0
126 self.cablesList = cablesList
127 self.transponders = transponders
129 def startElement(self, name, attrs):
130 if (name == "cable"):
131 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
132 tname = attrs.get('name',"")
133 self.cablesList.append(str(tname))
134 self.parsedCab = str(tname)
135 elif (name == "transponder"):
136 freq = int(attrs.get('frequency',""))
137 sr = int(attrs.get('symbol_rate',""))
138 mod = int(attrs.get('modulation',""))
139 fec = int(attrs.get('fec_inner',""))
140 if self.parsedCab in self.transponders:
143 self.transponders[self.parsedCab] = [ ]
145 self.transponders[self.parsedCab].append((0, freq, sr, mod, fec))
147 class parseTerrestrials(ContentHandler):
148 def __init__(self, terrestrialsList, transponders):
149 self.isPointsElement, self.isReboundsElement = 0, 0
150 self.terrestrialsList = terrestrialsList
151 self.transponders = transponders
153 def startElement(self, name, attrs):
154 if (name == "terrestrial"):
155 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
156 tname = attrs.get('name',"")
157 tflags = attrs.get('flags',"")
158 self.terrestrialsList.append((tname, tflags))
159 self.parsedTer = str(tname)
160 elif (name == "transponder"):
162 freq = int(attrs.get('centre_frequency',""))
163 bw = int(attrs.get('bandwidth',""))
164 const = int(attrs.get('constellation',""))
165 crh = int(attrs.get('code_rate_hp',""))
166 crl = int(attrs.get('code_rate_lp',""))
167 guard = int(attrs.get('guard_interval',""))
168 transm = int(attrs.get('transmission_mode',""))
169 hierarchy = int(attrs.get('hierarchy_information',""))
170 inv = int(attrs.get('inversion',""))
171 if self.parsedTer in self.transponders:
174 self.transponders[self.parsedTer] = [ ]
176 self.transponders[self.parsedTer].append((0, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
178 def getTransponders(self, pos):
179 return self.transponders[pos]
181 def getConfiguredSats(self):
182 return self.sec.getSatList()
184 def getSatDescription(self, pos):
185 return self.satellites[str(pos)]
187 def readSatsfromFile(self):
188 self.satellites = { }
189 self.transponders = { }
190 self.transponderscable = { }
191 self.transpondersterrestrial = { }
193 parser = make_parser()
194 if (self.hasNimType(self.nimType["DVB-S"])):
195 print "Reading satellites.xml"
196 satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
197 parser.setContentHandler(satHandler)
198 parser.parse('/etc/tuxbox/satellites.xml')
199 if (self.hasNimType(self.nimType["DVB-C"])):
200 print "Reading cables.xml"
201 cabHandler = self.parseCables(self.cablesList, self.transponderscable)
202 parser.setContentHandler(cabHandler)
203 parser.parse('/etc/tuxbox/cables.xml')
205 if (self.hasNimType(self.nimType["DVB-T"])):
206 print "Reading terrestrial.xml"
207 terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
208 parser.setContentHandler(terHandler)
209 parser.parse('/etc/tuxbox/terrestrial.xml')
214 self.nimSocketCount = 0
215 nimfile = tryOpen("/proc/bus/nim_sockets")
218 return self.nimType["empty/unknown"]
223 line = nimfile.readline()
226 if line.strip().startswith("NIM Socket"):
227 parts = line.strip().split(" ")
228 id = int(parts[2][:1])
230 self.nimSocketCount += 1
231 elif line.strip().startswith("Type:"):
232 self.nimTypes[lastsocket] = str(line.strip()[6:])
233 elif line.strip().startswith("Name:"):
234 self.nimNames[lastsocket] = str(line.strip()[6:])
235 elif line.strip().startswith("empty"):
236 self.nimNames[lastsocket] = _("N/A")
237 self.nimTypes[lastsocket] = "empty/unknown"
242 def getNimType(self, slotID):
243 return self.nimType[self.nimTypes[slotID]]
245 def getNimName(self, slotID):
246 return self.nimNames[slotID]
248 def getNimSocketCount(self):
249 return self.nimSocketCount
251 def hasNimType(self, chktype):
252 for id, type in self.nimTypes.items():
253 if (chktype == self.nimType[str(type)]):
257 def getNimListOfType(self, type, exception = -1):
259 for x in self.nimslots:
260 if ((x.nimType == type) and (x.slotid != exception)):
261 list.append(x.slotid)
264 def getConfigPrefix(self, slotid):
265 return "config.Nim" + ("A","B","C","D")[slotid] + "."
269 self.nimType = { "empty/unknown": -1,
275 self.terrestrialsList = []
279 self.readSatsfromFile()
281 self.nimCount = self.getNimSocketCount()
285 while x < self.nimCount:
286 tType = self.getNimType(x)
287 tName = self.getNimName(x)
288 tNim = nimSlot(x, tType, tName)
289 self.nimslots.append(tNim)
292 InitNimManager(self) #init config stuff
296 for slot in self.nimslots:
297 nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
298 if slot.nimType == -1:
299 nimText += _("empty/unknown")
301 nimText += slot.name + " ("
302 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
303 list.append((nimText, slot))
306 def getSatListForNim(self, slotid):
308 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
309 #print "slotid:", slotid
311 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
312 #print "diseqcA:", config.Nims[slotid].diseqcA.value
313 if (config.Nims[slotid].diseqcMode.value <= 3):
314 list.append(self.satList[config.Nims[slotid].diseqcA.value])
315 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
316 list.append(self.satList[config.Nims[slotid].diseqcB.value])
317 if (config.Nims[slotid].diseqcMode.value == 3):
318 list.append(self.satList[config.Nims[slotid].diseqcC.value])
319 list.append(self.satList[config.Nims[slotid].diseqcD.value])
322 #callbacks for c++ config
323 def nimConfigModeChanged(self, slotid, mode):
324 #print "nimConfigModeChanged set to " + str(mode)
326 def nimDiseqcModeChanged(self, slotid, mode):
327 #print "nimDiseqcModeChanged set to " + str(mode)
329 def nimPortAChanged(self, slotid, val):
330 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
332 def nimPortBChanged(self, slotid, val):
333 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
334 #print "nimDiseqcB set to " + str(val)
336 def nimPortCChanged(self, slotid, val):
337 #print "nimDiseqcC set to " + str(val)
339 def nimPortDChanged(self, slotid, val):
340 #print "nimDiseqcD set to " + str(val)
344 def InitNimManager(nimmgr):
346 for x in range(nimmgr.nimCount):
347 config.Nims.append(ConfigSubsection())
349 def nimConfigModeChanged(slotid, configElement):
350 nimmgr.nimConfigModeChanged(slotid, configElement.value)
351 def nimDiseqcModeChanged(slotid, configElement):
352 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
354 def nimPortAChanged(slotid, configElement):
355 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
356 def nimPortBChanged(slotid, configElement):
357 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
358 def nimPortCChanged(slotid, configElement):
359 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
360 def nimPortDChanged(slotid, configElement):
361 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
363 for slot in nimmgr.nimslots:
365 cname = nimmgr.getConfigPrefix(x)
368 if slot.nimType == nimmgr.nimType["DVB-S"]:
369 nim.configMode = configElement(cname + "configMode", configSelection, 0, (_("Simple"), _("Linked tuner"))) # _("Advanced")));
370 nim.diseqcMode = configElement(cname + "diseqcMode", configSelection, 2, (_("Single"), _("Toneburst A/B"), _("DiSEqC A/B"), _("DiSEqC A/B/C/D"), _("Positioner")));
371 nim.diseqcA = configElement(cname + "diseqcA", configSatlist, 192, nimmgr.satList);
372 nim.diseqcB = configElement(cname + "diseqcB", configSatlist, 130, nimmgr.satList);
373 nim.diseqcC = configElement(cname + "diseqcC", configSatlist, 0, nimmgr.satList);
374 nim.diseqcD = configElement(cname + "diseqcD", configSatlist, 0, nimmgr.satList);
375 nim.longitude = configElement(cname + "longitude", configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
376 nim.latitude = configElement(cname + "latitude", configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
378 satNimList = nimmgr.getNimListOfType(nimmgr.nimType["DVB-S"], slot.slotid)
381 satNimListNames.append(_("Slot ") + ("A", "B", "C", "D")[x] + ": " + nimmgr.getNimName(x))
382 nim.linkedTo = configElement(cname + "linkedTo", configSelection, 0, satNimListNames);
384 #perhaps the instance of the slot is more useful?
385 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
386 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
387 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
388 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
389 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
390 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
391 elif slot.nimType == nimmgr.nimType["DVB-C"]:
392 nim.cable = configElement(cname + "cable", configSelection, 0, nimmgr.cablesList);
393 elif slot.nimType == nimmgr.nimType["DVB-T"]:
394 nim.cable = configElement(cname + "terrestrial", configSelection, 0, nimmgr.terrestrialsList);
396 print "pls add support for this frontend type!"
398 nimmgr.sec = SecConfigure(nimmgr)
400 nimmanager = NimManager()