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 def tryOpen(filename):
23 procFile = open(filename)
29 def addLNBSimple(self, slotid, orbpos, toneburstmode, diseqcmode, diseqcpos):
31 sec = eDVBSatelliteEquipmentControl.getInstance()
33 sec.setLNBTunerMask(1 << slotid)
34 sec.setLNBLOFL(9750000)
35 sec.setLNBLOFH(10600000)
36 sec.setLNBThreshold(11750000)
40 sec.setVoltageMode(0) #HV
41 sec.setToneMode(0) #HILO
42 sec.setCommandOrder(0)
44 sec.setDiSEqCMode(diseqcmode)
45 sec.setToneburst(toneburstmode)
46 sec.setCommittedCommand(diseqcpos)
47 #print "set orbpos to:" + str(orbpos)
48 sec.addSatellite(orbpos)
49 self.satList.append(orbpos)
55 eDVBSatelliteEquipmentControl.getInstance().clear()
58 for slot in self.NimManager.nimslots:
61 if slot.nimType == self.NimManager.nimType["DVB-S"]:
62 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
63 if nim.configMode.value == 0: #simple config
64 if nim.diseqcMode.value == 0: #single
65 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 0, 4)
66 elif nim.diseqcMode.value == 1: #Toneburst A/B
67 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 1, 0, 4)
68 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 1, 0, 4)
69 elif nim.diseqcMode.value == 2: #DiSEqC A/B
70 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 1, 0)
71 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 0, 1, 1)
72 elif nim.diseqcMode.value == 3: #DiSEqC A/B/C/D
73 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 1, 0)
74 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 0, 1, 1)
75 self.addLNBSimple(x, int(nim.diseqcC.vals[nim.diseqcC.value][1]), 0, 1, 2)
76 self.addLNBSimple(x, int(nim.diseqcD.vals[nim.diseqcD.value][1]), 0, 1, 3)
77 elif nim.diseqcMode.value == 4: #Positioner
78 print "FIXME: positioner suppport"
80 else: #advanced config
81 print "FIXME add support for advanced config"
83 def __init__(self, nimmgr):
84 self.NimManager = nimmgr
88 def __init__(self, fnc, *args):
91 def __call__(self, *args):
92 self.fnc(*self.args + args)
95 def __init__(self, slotid, nimtype, name):
97 self.nimType = nimtype
101 class parseSats(ContentHandler):
102 def __init__(self, satList, satellites, transponders):
103 self.isPointsElement, self.isReboundsElement = 0, 0
104 self.satList = satList
105 self.satellites = satellites
106 self.transponders = transponders
108 def startElement(self, name, attrs):
110 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
111 tpos = attrs.get('position',"")
112 tname = attrs.get('name',"")
113 self.satellites[tpos] = tname
114 self.satList.append( (tname, tpos) )
115 self.parsedSat = int(tpos)
116 elif (name == "transponder"):
117 freq = int(attrs.get('frequency',""))
118 sr = int(attrs.get('symbol_rate',""))
119 pol = int(attrs.get('polarization',""))
120 fec = int(attrs.get('fec_inner',""))
121 if self.parsedSat in self.transponders:
124 self.transponders[self.parsedSat] = [ ]
126 self.transponders[self.parsedSat].append((0, freq, sr, pol, fec))
128 class parseCables(ContentHandler):
129 def __init__(self, cablesList, transponders):
130 self.isPointsElement, self.isReboundsElement = 0, 0
131 self.cablesList = cablesList
132 self.transponders = transponders
134 def startElement(self, name, attrs):
135 if (name == "cable"):
136 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
137 tname = attrs.get('name',"")
138 self.cablesList.append(str(tname))
139 self.parsedCab = str(tname)
140 elif (name == "transponder"):
141 freq = int(attrs.get('frequency',""))
142 sr = int(attrs.get('symbol_rate',""))
143 mod = int(attrs.get('modulation',""))
144 fec = int(attrs.get('fec_inner',""))
145 if self.parsedCab in self.transponders:
148 self.transponders[self.parsedCab] = [ ]
150 self.transponders[self.parsedCab].append((0, freq, sr, mod, fec))
152 class parseTerrestrials(ContentHandler):
153 def __init__(self, terrestrialsList, transponders):
154 self.isPointsElement, self.isReboundsElement = 0, 0
155 self.terrestrialsList = terrestrialsList
156 self.transponders = transponders
158 def startElement(self, name, attrs):
159 if (name == "terrestrial"):
160 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
161 tname = attrs.get('name',"")
162 tflags = attrs.get('flags',"")
163 self.terrestrialsList.append((tname, tflags))
164 self.parsedTer = str(tname)
165 elif (name == "transponder"):
167 freq = int(attrs.get('centre_frequency',""))
168 bw = int(attrs.get('bandwidth',""))
169 const = int(attrs.get('constellation',""))
170 crh = int(attrs.get('code_rate_hp',""))
171 crl = int(attrs.get('code_rate_lp',""))
172 guard = int(attrs.get('guard_interval',""))
173 transm = int(attrs.get('transmission_mode',""))
174 hierarchy = int(attrs.get('hierarchy_information',""))
175 inv = int(attrs.get('inversion',""))
176 if self.parsedTer in self.transponders:
179 self.transponders[self.parsedTer] = [ ]
181 self.transponders[self.parsedTer].append((0, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
183 def getTransponders(self, pos):
184 return self.transponders[pos]
186 def getConfiguredSats(self):
187 return self.sec.getSatList()
189 def getSatDescription(self, pos):
190 return self.satellites[str(pos)]
192 def readSatsfromFile(self):
193 self.satellites = { }
194 self.transponders = { }
195 self.transponderscable = { }
196 self.transpondersterrestrial = { }
198 if (self.hasNimType(self.nimType["DVB-S"])):
199 print "Reading satellites.xml"
200 parser = make_parser()
201 satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
202 parser.setContentHandler(satHandler)
203 parser.parse('/etc/tuxbox/satellites.xml')
204 if (self.hasNimType(self.nimType["DVB-C"])):
205 print "Reading cables.xml"
206 cabHandler = self.parseCables(self.cablesList, self.transponderscable)
207 parser.setContentHandler(cabHandler)
208 parser.parse('/etc/tuxbox/cables.xml')
210 if (self.hasNimType(self.nimType["DVB-T"])):
211 print "Reading terrestrial.xml"
212 terHandler = self.parseTerrestrials(self.terrestrialsList, self.transpondersterrestrial)
213 parser.setContentHandler(terHandler)
214 parser.parse('/etc/tuxbox/terrestrial.xml')
219 self.nimSocketCount = 0
220 nimfile = tryOpen("/proc/bus/nim_sockets")
223 return self.nimType["empty/unknown"]
228 line = nimfile.readline()
231 if line.strip().startswith("NIM Socket"):
232 parts = line.strip().split(" ")
233 id = int(parts[2][:1])
235 self.nimSocketCount += 1
236 elif line.strip().startswith("Type:"):
237 self.nimTypes[lastsocket] = str(line.strip()[6:])
238 elif line.strip().startswith("Name:"):
239 self.nimNames[lastsocket] = str(line.strip()[6:])
240 elif line.strip().startswith("empty"):
241 self.nimNames[lastsocket] = _("N/A")
242 self.nimTypes[lastsocket] = "empty/unknown"
247 def getNimType(self, slotID):
248 return self.nimType[self.nimTypes[slotID]]
250 def getNimName(self, slotID):
251 return self.nimNames[slotID]
253 def getNimSocketCount(self):
254 return self.nimSocketCount
256 def hasNimType(self, chktype):
257 for id, type in self.nimTypes.items():
258 if (chktype == self.nimType[str(type)]):
262 def getConfigPrefix(self, slotid):
263 return "config.Nim" + ("A","B","C","D")[slotid] + "."
267 self.nimType = { "empty/unknown": -1,
273 self.terrestrialsList = []
277 self.readSatsfromFile()
279 self.nimCount = self.getNimSocketCount()
283 while x < self.nimCount:
284 tType = self.getNimType(x)
285 tName = self.getNimName(x)
286 tNim = nimSlot(x, tType, tName)
287 self.nimslots.append(tNim)
290 InitNimManager(self) #init config stuff
294 for slot in self.nimslots:
295 nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
296 if slot.nimType == -1:
297 nimText += _("empty/unknown")
299 nimText += slot.name + " ("
300 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
301 list.append((nimText, slot))
304 def getSatListForNim(self, slotid):
306 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
307 #print "slotid:", slotid
309 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
310 #print "diseqcA:", config.Nims[slotid].diseqcA.value
311 if (config.Nims[slotid].diseqcMode.value <= 3):
312 list.append(self.satList[config.Nims[slotid].diseqcA.value])
313 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
314 list.append(self.satList[config.Nims[slotid].diseqcB.value])
315 if (config.Nims[slotid].diseqcMode.value == 3):
316 list.append(self.satList[config.Nims[slotid].diseqcC.value])
317 list.append(self.satList[config.Nims[slotid].diseqcD.value])
320 #callbacks for c++ config
321 def nimConfigModeChanged(self, slotid, mode):
322 #print "nimConfigModeChanged set to " + str(mode)
324 def nimDiseqcModeChanged(self, slotid, mode):
325 #print "nimDiseqcModeChanged set to " + str(mode)
327 def nimPortAChanged(self, slotid, val):
328 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
330 def nimPortBChanged(self, slotid, val):
331 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
332 #print "nimDiseqcB set to " + str(val)
334 def nimPortCChanged(self, slotid, val):
335 #print "nimDiseqcC set to " + str(val)
337 def nimPortDChanged(self, slotid, val):
338 #print "nimDiseqcD set to " + str(val)
342 def InitNimManager(nimmgr):
344 for x in range(nimmgr.nimCount):
345 config.Nims.append(ConfigSubsection())
347 def nimConfigModeChanged(slotid, configElement):
348 nimmgr.nimConfigModeChanged(slotid, configElement.value)
349 def nimDiseqcModeChanged(slotid, configElement):
350 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
352 def nimPortAChanged(slotid, configElement):
353 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
354 def nimPortBChanged(slotid, configElement):
355 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
356 def nimPortCChanged(slotid, configElement):
357 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
358 def nimPortDChanged(slotid, configElement):
359 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
361 for slot in nimmgr.nimslots:
363 cname = nimmgr.getConfigPrefix(x)
366 if slot.nimType == nimmgr.nimType["DVB-S"]:
367 nim.configMode = configElement(cname + "configMode",configSelection, 0, (_("Simple"), _("Advanced")));
368 nim.diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, (_("Single"), _("Toneburst A/B"), _("DiSEqC A/B"), _("DiSEqC A/B/C/D"), _("Positioner")));
369 nim.diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
370 nim.diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
371 nim.diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
372 nim.diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
373 nim.longitude = configElement(cname + "longitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
374 nim.latitude = configElement(cname + "latitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
376 #perhaps the instance of the slot is more useful?
377 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
378 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
379 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
380 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
381 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
382 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
383 elif slot.nimType == nimmgr.nimType["DVB-C"]:
385 elif slot.nimType == nimmgr.nimType["DVB-T"]:
388 print "pls add support for this frontend type!"
390 nimmgr.sec = SecConfigure(nimmgr)
392 nimmanager = NimManager()