fix tunerlist, force both tuners as available
[enigma2.git] / lib / python / Components / NimManager.py
1 from config import config       #global config instance
2
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
10
11 from enigma import *
12
13 import xml.dom.minidom
14 from xml.dom import EMPTY_NAMESPACE
15 from skin import elementsWithTag
16 from Tools import XMLTools
17
18 from xml.sax import make_parser
19 from xml.sax.handler import ContentHandler
20
21 class SecConfigure:
22         def addLNBSimple(self, slotid, orbpos, toneburstmode, diseqcmode, diseqcpos):
23                 #simple defaults
24                 sec = eDVBSatelliteEquipmentControl.getInstance()
25                 sec.addLNB()
26                 sec.setLNBTunerMask(1 << slotid)
27                 sec.setLNBLOFL(9750000)
28                 sec.setLNBLOFH(10600000)
29                 sec.setLNBThreshold(11750000)
30                 sec.setRepeats(0)
31                 sec.setFastDiSEqC(0)
32                 sec.setSeqRepeat(0)
33                 sec.setVoltageMode(0) #HV
34                 sec.setToneMode(0)              #HILO
35                 sec.setCommandOrder(0)
36                 #user values
37                 sec.setDiSEqCMode(diseqcmode)
38                 sec.setToneburst(toneburstmode)
39                 sec.setCommittedCommand(diseqcpos)
40                 #print "set orbpos to:" + str(orbpos)
41                 sec.addSatellite(orbpos)
42                 self.satList.append(orbpos)
43
44         def getSatList(self):
45                 return self.satList
46
47         def update(self):
48                 eDVBSatelliteEquipmentControl.getInstance().clear()
49                 self.satList = []
50
51                 for slot in self.NimManager.nimslots:
52                         x = slot.slotid
53                         nim = config.Nims[x]
54                         if slot.nimType == self.NimManager.nimType["DVB-S"]:
55                                 print "slot: " + str(x) + " configmode: " + str(nim.configMode.value)
56                                 if nim.configMode.value == 0:           #simple config
57                                         if nim.diseqcMode.value == 0:                   #single
58                                                 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 0, 4)
59                                         elif nim.diseqcMode.value == 1:         #Toneburst A/B
60                                                 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 1, 0, 4)
61                                                 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 1, 0, 4)
62                                         elif nim.diseqcMode.value == 2:         #DiSEqC A/B
63                                                 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 1, 0)
64                                                 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 0, 1, 1)
65                                         elif nim.diseqcMode.value == 3:         #DiSEqC A/B/C/D
66                                                 self.addLNBSimple(x, int(nim.diseqcA.vals[nim.diseqcA.value][1]), 0, 1, 0)
67                                                 self.addLNBSimple(x, int(nim.diseqcB.vals[nim.diseqcB.value][1]), 0, 1, 1)
68                                                 self.addLNBSimple(x, int(nim.diseqcC.vals[nim.diseqcC.value][1]), 0, 1, 2)
69                                                 self.addLNBSimple(x, int(nim.diseqcD.vals[nim.diseqcD.value][1]), 0, 1, 3)
70                                         elif nim.diseqcMode.value == 4:         #Positioner
71                                                 print "FIXME: positioner suppport"
72                                         pass
73                                 else:                                                                                                                                   #advanced config
74                                         print "FIXME add support for advanced config"
75                 
76         def __init__(self, nimmgr):
77                 self.NimManager = nimmgr
78                 self.update()
79                 
80 class boundFunction:
81         def __init__(self, fnc, *args):
82                 self.fnc = fnc
83                 self.args = args
84         def __call__(self, *args):
85                 self.fnc(*self.args + args)
86
87 class nimSlot:
88         def __init__(self, slotid, nimtype, name):
89                 self.slotid = slotid
90                 self.nimType = nimtype
91                 self.name = name
92
93 class NimManager:
94         class parseSats(ContentHandler):
95                 def __init__(self, satList, satellites):
96                         self.isPointsElement, self.isReboundsElement = 0, 0
97                         self.satList = satList
98                         self.satellites = satellites
99         
100                 def startElement(self, name, attrs):
101                         if (name == "sat"):
102                                 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
103                                 tpos = attrs.get('position',"")
104                                 tname = attrs.get('name',"")
105                                 self.satellites[tpos] = tname
106                                 self.satList.append( (tname, tpos) )
107
108         def getConfiguredSats(self):
109                 return self.sec.getSatList()
110
111         def getSatDescription(self, pos):
112                 return self.satellites[str(pos)]
113
114         def readSatsfromFile(self):
115                 self.satellites = { }
116
117                 print "Reading satellites.xml"
118                 parser = make_parser()
119                 satHandler = self.parseSats(self.satList, self.satellites)
120                 parser.setContentHandler(satHandler)
121                 parser.parse('/etc/tuxbox/satellites.xml')
122
123         def getNimType(self, slotID):
124                 #FIXME get it from /proc
125                 if slotID == 0:
126                         return self.nimType["DVB-S"]
127                 elif slotID == 1:
128                         return self.nimType["DVB-S"]
129                 else:
130                         return self.nimType["empty/unknown"]
131
132         def getNimName(self, slotID):
133                 #FIXME get it from /proc
134                 return "Alps BSBE1"
135
136         def getNimSocketCount(self):
137                 #FIXME get it from /proc
138                 return 2
139
140         def getConfigPrefix(self, slotid):
141                 return "config.Nim" + ("A","B","C","D")[slotid] + "."
142                         
143         def __init__(self):
144                 #use as enum
145                 self.nimType = {                "empty/unknown": -1,
146                                                                                                 "DVB-S": 0,
147                                                                                                 "DVB-C": 1,
148                                                                                                 "DVB-T": 2}
149                 self.satList = [ ]                                                                              
150                                                                                                 
151                 self.readSatsfromFile()                                                                         
152                                                                                                 
153                 self.nimCount = self.getNimSocketCount()
154                 
155                 self.nimslots = [ ]
156                 x = 0
157                 while x < self.nimCount:
158                         tType = self.getNimType(x)
159                         tName = self.getNimName(x)
160                         tNim = nimSlot(x, tType, tName)
161                         self.nimslots.append(tNim)
162                         x += 1
163                 
164                 InitNimManager(self)    #init config stuff
165
166         def nimList(self):
167                 list = [ ]
168                 for slot in self.nimslots:
169                         nimText = "Socket " + ("A", "B", "C", "D")[slot.slotid] + ": "
170                         if slot.nimType == -1:
171                                 nimText += "empty/unknown"
172                         else:
173                                 nimText += slot.name + " ("     
174                                 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
175                         list.append((nimText, slot))
176                 return list
177         
178         def getSatListForNim(self, slotid):
179                 #print "slotid:", slotid
180                 list = []
181                 #print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
182                 #print "diseqcA:", config.Nims[slotid].diseqcA.value
183                 if (config.Nims[slotid].diseqcMode.value <= 3):
184                         list.append(self.satList[config.Nims[slotid].diseqcA.value])
185                 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
186                         list.append(self.satList[config.Nims[slotid].diseqcB.value])
187                 if (config.Nims[slotid].diseqcMode.value == 3):
188                         list.append(self.satList[config.Nims[slotid].diseqcC.value])
189                         list.append(self.satList[config.Nims[slotid].diseqcD.value])
190                 return list
191
192         #callbacks for c++ config
193         def nimConfigModeChanged(self, slotid, mode):
194                 #print "nimConfigModeChanged set to " + str(mode)
195                 pass
196         def nimDiseqcModeChanged(self, slotid, mode):
197                 #print "nimDiseqcModeChanged set to " + str(mode)
198                 pass
199         def nimPortAChanged(self, slotid, val):
200                 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
201                 pass
202         def nimPortBChanged(self, slotid, val):
203                 #print "nimDiseqcA set to " + str(slotid) + " val:" + str(val)
204                 #print "nimDiseqcB set to " + str(val)
205                 pass
206         def nimPortCChanged(self, slotid, val):
207                 #print "nimDiseqcC set to " + str(val)
208                 pass
209         def nimPortDChanged(self, slotid, val):
210                 #print "nimDiseqcD set to " + str(val)
211                 pass
212
213
214 def InitNimManager(nimmgr):
215         config.Nims = []
216         for x in range(nimmgr.nimCount):
217                 config.Nims.append(ConfigSubsection())
218                 
219         def nimConfigModeChanged(slotid, configElement):
220                 nimmgr.nimConfigModeChanged(slotid, configElement.value)
221         def nimDiseqcModeChanged(slotid, configElement):
222                 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
223                 
224         def nimPortAChanged(slotid, configElement):
225                 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
226         def nimPortBChanged(slotid, configElement):
227                 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
228         def nimPortCChanged(slotid, configElement):
229                 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
230         def nimPortDChanged(slotid, configElement):
231                 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
232
233         for slot in nimmgr.nimslots:
234                 x = slot.slotid
235                 cname = nimmgr.getConfigPrefix(x)
236                 nim = config.Nims[x]
237                 
238                 if slot.nimType == nimmgr.nimType["DVB-S"]:
239                         nim.configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
240                         nim.diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D", "Positioner"));
241                         nim.diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
242                         nim.diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
243                         nim.diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
244                         nim.diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
245                         nim.longitude = configElement(cname + "longitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
246                         nim.latitude = configElement(cname + "latitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
247                         
248                         #perhaps the instance of the slot is more useful?
249                         nim.configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
250                         nim.diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
251                         nim.diseqcA.addNotifier(boundFunction(nimPortAChanged,int(x)))
252                         nim.diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
253                         nim.diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
254                         nim.diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
255                 else:
256                         print "pls add support for this frontend type!"         
257
258         nimmgr.sec = SecConfigure(nimmgr)
259
260 nimmanager = NimManager()