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')
150 nimfile = tryOpen("/proc/bus/nim_sockets")
153 return self.nimType["empty/unknown"]
158 line = nimfile.readline()
161 if line.strip().startswith("NIM Socket"):
162 parts = line.strip().split(" ")
163 id = int(parts[2][:1])
165 elif line.strip().startswith("Type:"):
166 self.nimTypes[lastsocket] = str(line.strip()[6:])
167 elif line.strip().startswith("Name:"):
168 self.nimNames[lastsocket] = str(line.strip()[6:])
173 def getNimType(self, slotID):
174 return self.nimType[self.nimTypes[slotID]]
176 def getNimName(self, slotID):
177 return self.nimNames[slotID]
179 def getNimSocketCount(self):
180 #FIXME get it from /proc
183 def getConfigPrefix(self, slotid):
184 return "config.Nim" + ("A","B","C","D")[slotid] + "."
188 self.nimType = { "empty/unknown": -1,
194 self.readSatsfromFile()
196 self.nimCount = self.getNimSocketCount()
202 while x < self.nimCount:
203 tType = self.getNimType(x)
204 tName = self.getNimName(x)
205 tNim = nimSlot(x, tType, tName)
206 self.nimslots.append(tNim)
209 InitNimManager(self) #init config stuff
213 for slot in self.nimslots:
214 nimText = _("Socket ") + ("A", "B", "C", "D")[slot.slotid] + ": "
215 if slot.nimType == -1:
216 nimText += _("empty/unknown")
218 nimText += slot.name + " ("
219 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
220 list.append((nimText, slot))
223 def getSatListForNim(self, slotid):
225 if (self.getNimType(slotid) != self.nimType["empty/unknown"]):
226 #print "slotid:", slotid
228 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
229 #print "diseqcA:", config.Nims[slotid].diseqcA.value
230 if (config.Nims[slotid].diseqcMode.value <= 3):
231 list.append(self.satList[config.Nims[slotid].diseqcA.value])
232 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
233 list.append(self.satList[config.Nims[slotid].diseqcB.value])
234 if (config.Nims[slotid].diseqcMode.value == 3):
235 list.append(self.satList[config.Nims[slotid].diseqcC.value])
236 list.append(self.satList[config.Nims[slotid].diseqcD.value])
239 #callbacks for c++ config
240 def nimConfigModeChanged(self, slotid, mode):
241 #print "nimConfigModeChanged set to " + str(mode)
243 def nimDiseqcModeChanged(self, slotid, mode):
244 #print "nimDiseqcModeChanged set to " + str(mode)
246 def nimPortAChanged(self, slotid, val):
247 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
249 def nimPortBChanged(self, slotid, val):
250 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
251 #print "nimDiseqcB set to " + str(val)
253 def nimPortCChanged(self, slotid, val):
254 #print "nimDiseqcC set to " + str(val)
256 def nimPortDChanged(self, slotid, val):
257 #print "nimDiseqcD set to " + str(val)
261 def InitNimManager(nimmgr):
263 for x in range(nimmgr.nimCount):
264 config.Nims.append(ConfigSubsection())
266 def nimConfigModeChanged(slotid, configElement):
267 nimmgr.nimConfigModeChanged(slotid, configElement.value)
268 def nimDiseqcModeChanged(slotid, configElement):
269 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
271 def nimPortAChanged(slotid, configElement):
272 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
273 def nimPortBChanged(slotid, configElement):
274 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
275 def nimPortCChanged(slotid, configElement):
276 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
277 def nimPortDChanged(slotid, configElement):
278 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
280 for slot in nimmgr.nimslots:
282 cname = nimmgr.getConfigPrefix(x)
285 if slot.nimType == nimmgr.nimType["DVB-S"]:
286 nim.configMode = configElement(cname + "configMode",configSelection, 0, (_("Simple"), _("Advanced")));
287 nim.diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, (_("Single"), _("Toneburst A/B"), _("DiSEqC A/B"), _("DiSEqC A/B/C/D"), _("Positioner")));
288 nim.diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
289 nim.diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
290 nim.diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
291 nim.diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
292 nim.longitude = configElement(cname + "longitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
293 nim.latitude = configElement(cname + "latitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
295 #perhaps the instance of the slot is more useful?
296 nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
297 nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
298 nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
299 nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
300 nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
301 nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
303 print "pls add support for this frontend type!"
305 nimmgr.sec = SecConfigure(nimmgr)
307 nimmanager = NimManager()