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 def getTransponders(self, pos):
129 return self.transponders[pos]
131 def getConfiguredSats(self):
132 return self.sec.getSatList()
134 def getSatDescription(self, pos):
135 return self.satellites[str(pos)]
137 def readSatsfromFile(self):
138 self.satellites = { }
139 self.transponders = { }
141 print "Reading satellites.xml"
142 parser = make_parser()
143 satHandler = self.parseSats(self.satList, self.satellites, self.transponders)
144 parser.setContentHandler(satHandler)
145 parser.parse('/etc/tuxbox/satellites.xml')
147 def getNimType(self, slotID):
148 #FIXME get it from /proc
149 nimfile = tryOpen("/proc/bus/nim_sockets")
152 # FIXME: remove this in the final version
153 # check if we have a device for 7020 comp?atibility reasons
155 open("/dev/dvb/card0/frontend" + str(slotID))
156 return self.nimType["DVB-S"]
158 return self.nimType["empty/unknown"]
162 line = nimfile.readline()
165 if line.startswith("NIM Socket"):
166 parts = line.strip().split(" ")
167 id = int(parts[2][:1])
169 line = nimfile.readline()
172 if line.startswith(" Type:"):
174 return self.nimType["DVB-S"]
178 return self.nimType["empty/unknown"]
180 def getNimName(self, slotID):
181 #FIXME get it from /proc
184 def getNimSocketCount(self):
185 #FIXME get it from /proc
188 def getConfigPrefix(self, slotid):
189 return "config.Nim" + ("A","B","C","D")[slotid] + "."
193 self.nimType = { "empty/unknown": -1,
199 self.readSatsfromFile()
201 self.nimCount = self.getNimSocketCount()
205 while x < self.nimCount:
206 tType = self.getNimType(x)
207 tName = self.getNimName(x)
208 tNim = nimSlot(x, tType, tName)
209 self.nimslots.append(tNim)
212 InitNimManager(self) #init config stuff
216 for slot in self.nimslots:
217 nimText = "Socket " + ("A", "B", "C", "D")[slot.slotid] + ": "
218 if slot.nimType == -1:
219 nimText += "empty/unknown"
221 nimText += slot.name + " ("
222 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
223 list.append((nimText, slot))
226 def getSatListForNim(self, slotid):
228 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
229 #print "slotid:", slotid
231 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
232 #print "diseqcA:", config.Nims[slotid].diseqcA.value
233 if (config.Nims[slotid].diseqcMode.value <= 3):
234 list.append(self.satList[config.Nims[slotid].diseqcA.value])
235 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
236 list.append(self.satList[config.Nims[slotid].diseqcB.value])
237 if (config.Nims[slotid].diseqcMode.value == 3):
238 list.append(self.satList[config.Nims[slotid].diseqcC.value])
239 list.append(self.satList[config.Nims[slotid].diseqcD.value])
242 #callbacks for c++ config
243 def nimConfigModeChanged(self, slotid, mode):
244 #print "nimConfigModeChanged set to " + str(mode)
246 def nimDiseqcModeChanged(self, slotid, mode):
247 #print "nimDiseqcModeChanged set to " + str(mode)
249 def nimPortAChanged(self, slotid, val):
250 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
252 def nimPortBChanged(self, slotid, val):
253 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
254 #print "nimDiseqcB set to " + str(val)
256 def nimPortCChanged(self, slotid, val):
257 #print "nimDiseqcC set to " + str(val)
259 def nimPortDChanged(self, slotid, val):
260 #print "nimDiseqcD set to " + str(val)
264 def InitNimManager(nimmgr):
266 for x in range(nimmgr.nimCount):
267 config.Nims.append(ConfigSubsection())
269 def nimConfigModeChanged(slotid, configElement):
270 nimmgr.nimConfigModeChanged(slotid, configElement.value)
271 def nimDiseqcModeChanged(slotid, configElement):
272 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
274 def nimPortAChanged(slotid, configElement):
275 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
276 def nimPortBChanged(slotid, configElement):
277 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
278 def nimPortCChanged(slotid, configElement):
279 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
280 def nimPortDChanged(slotid, configElement):
281 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
283 for slot in nimmgr.nimslots:
285 cname = nimmgr.getConfigPrefix(x)
288 if slot.nimType == nimmgr.nimType["DVB-S"]:
289 nim.configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
290 nim.diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D", "Positioner"));
291 nim.diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
292 nim.diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
293 nim.diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
294 nim.diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
295 nim.longitude = configElement(cname + "longitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
296 nim.latitude = configElement(cname + "latitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
298 #perhaps the instance of the slot is more useful?
299 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
300 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
301 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
302 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
303 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
304 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
306 print "pls add support for this frontend type!"
308 nimmgr.sec = SecConfigure(nimmgr)
310 nimmanager = NimManager()