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):
103 self.isPointsElement, self.isReboundsElement = 0, 0
104 self.satList = satList
105 self.satellites = satellites
107 def startElement(self, name, attrs):
109 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
110 tpos = attrs.get('position',"")
111 tname = attrs.get('name',"")
112 self.satellites[tpos] = tname
113 self.satList.append( (tname, tpos) )
115 def getConfiguredSats(self):
116 return self.sec.getSatList()
118 def getSatDescription(self, pos):
119 return self.satellites[str(pos)]
121 def readSatsfromFile(self):
122 self.satellites = { }
124 print "Reading satellites.xml"
125 parser = make_parser()
126 satHandler = self.parseSats(self.satList, self.satellites)
127 parser.setContentHandler(satHandler)
128 parser.parse('/etc/tuxbox/satellites.xml')
130 def getNimType(self, slotID):
131 #FIXME get it from /proc
132 nimfile = tryOpen("/proc/bus/nim_sockets")
135 # FIXME: remove this in the final version
136 # check if we have a device for 7020 comp?atibility reasons
138 open("/dev/dvb/card0/frontend" + str(slotID))
139 return self.nimType["DVB-S"]
141 return self.nimType["empty/unknown"]
145 line = nimfile.readline()
148 if line.startswith("NIM Socket"):
149 parts = line.strip().split(" ")
150 id = int(parts[2][:1])
152 line = nimfile.readline()
155 if line.startswith(" Type:"):
157 return self.nimType["DVB-S"]
161 return self.nimType["empty/unknown"]
163 def getNimName(self, slotID):
164 #FIXME get it from /proc
167 def getNimSocketCount(self):
168 #FIXME get it from /proc
171 def getConfigPrefix(self, slotid):
172 return "config.Nim" + ("A","B","C","D")[slotid] + "."
176 self.nimType = { "empty/unknown": -1,
182 self.readSatsfromFile()
184 self.nimCount = self.getNimSocketCount()
188 while x < self.nimCount:
189 tType = self.getNimType(x)
190 tName = self.getNimName(x)
191 tNim = nimSlot(x, tType, tName)
192 self.nimslots.append(tNim)
195 InitNimManager(self) #init config stuff
199 for slot in self.nimslots:
200 nimText = "Socket " + ("A", "B", "C", "D")[slot.slotid] + ": "
201 if slot.nimType == -1:
202 nimText += "empty/unknown"
204 nimText += slot.name + " ("
205 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
206 list.append((nimText, slot))
209 def getSatListForNim(self, slotid):
211 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
212 #print "slotid:", slotid
214 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
215 #print "diseqcA:", config.Nims[slotid].diseqcA.value
216 if (config.Nims[slotid].diseqcMode.value <= 3):
217 list.append(self.satList[config.Nims[slotid].diseqcA.value])
218 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
219 list.append(self.satList[config.Nims[slotid].diseqcB.value])
220 if (config.Nims[slotid].diseqcMode.value == 3):
221 list.append(self.satList[config.Nims[slotid].diseqcC.value])
222 list.append(self.satList[config.Nims[slotid].diseqcD.value])
225 #callbacks for c++ config
226 def nimConfigModeChanged(self, slotid, mode):
227 #print "nimConfigModeChanged set to " + str(mode)
229 def nimDiseqcModeChanged(self, slotid, mode):
230 #print "nimDiseqcModeChanged set to " + str(mode)
232 def nimPortAChanged(self, slotid, val):
233 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
235 def nimPortBChanged(self, slotid, val):
236 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
237 #print "nimDiseqcB set to " + str(val)
239 def nimPortCChanged(self, slotid, val):
240 #print "nimDiseqcC set to " + str(val)
242 def nimPortDChanged(self, slotid, val):
243 #print "nimDiseqcD set to " + str(val)
247 def InitNimManager(nimmgr):
249 for x in range(nimmgr.nimCount):
250 config.Nims.append(ConfigSubsection())
252 def nimConfigModeChanged(slotid, configElement):
253 nimmgr.nimConfigModeChanged(slotid, configElement.value)
254 def nimDiseqcModeChanged(slotid, configElement):
255 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
257 def nimPortAChanged(slotid, configElement):
258 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
259 def nimPortBChanged(slotid, configElement):
260 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
261 def nimPortCChanged(slotid, configElement):
262 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
263 def nimPortDChanged(slotid, configElement):
264 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
266 for slot in nimmgr.nimslots:
268 cname = nimmgr.getConfigPrefix(x)
271 if slot.nimType == nimmgr.nimType["DVB-S"]:
272 nim.configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
273 nim.diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D", "Positioner"));
274 nim.diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
275 nim.diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
276 nim.diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
277 nim.diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
278 nim.longitude = configElement(cname + "longitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
279 nim.latitude = configElement(cname + "latitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
281 #perhaps the instance of the slot is more useful?
282 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
283 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
284 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
285 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
286 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
287 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
289 print "pls add support for this frontend type!"
291 nimmgr.sec = SecConfigure(nimmgr)
293 nimmanager = NimManager()