added positioner setup into satconfig
[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 configSatlist
9
10 import xml.dom.minidom
11 from xml.dom import EMPTY_NAMESPACE
12 from skin import elementsWithTag
13 from Tools import XMLTools
14
15 from xml.sax import make_parser
16 from xml.sax.handler import ContentHandler
17
18 class boundFunction:
19         def __init__(self, fnc, *args):
20                 self.fnc = fnc
21                 self.args = args
22         def __call__(self, *args):
23                 self.fnc(*self.args + args)
24
25 class nimSlot:
26         def __init__(self, slotid, nimtype, name):
27                 self.slotid = slotid
28                 self.nimType = nimtype
29                 self.name = name
30
31 class NimManager:
32         class parseSats(ContentHandler):
33                 def __init__(self, satList, satellites):
34                         self.isPointsElement, self.isReboundsElement = 0, 0
35                         self.satList = satList
36                         self.satellites = satellites
37         
38                 def startElement(self, name, attrs):
39                         if (name == "sat"):
40                                 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
41                                 tpos = attrs.get('position',"")
42                                 tname = attrs.get('name',"")
43                                 self.satellites[tpos] = tname
44                                 self.satList.append( (tname, tpos) )
45
46         def readSatsfromFile(self):
47                 self.satellites = { }
48
49                 #FIXME: path ok???
50                 print "Reading satellites.xml"
51                 parser = make_parser()
52                 satHandler = self.parseSats(self.satList, self.satellites)
53                 parser.setContentHandler(satHandler)
54                 parser.parse('/etc/tuxbox/satellites.xml')
55     
56                 #satdom = xml.dom.minidom.parse('/etc/tuxbox/satellites.xml')
57
58
59                 #for entries in elementsWithTag(satdom.childNodes, "satellites"):
60                         #for x in elementsWithTag(entries.childNodes, "sat"):
61                                 ##print "found sat " + x.getAttribute('name') + " " + str(x.getAttribute('position'))
62                                 #tpos = x.getAttribute('position')
63                                 #tname = x.getAttribute('name')
64                                 ##tname.encode('utf8')
65                                 #self.satellites[tpos] = tname
66                                 #self.satList.append( (tname, tpos) )
67
68         def getNimType(self, slotID):
69                 #FIXME get it from /proc
70                 if slotID == 0:
71                         return self.nimType["DVB-S"]
72                 else:
73                         return self.nimType["empty/unknown"]
74
75         def getNimName(self, slotID):
76                 #FIXME get it from /proc
77                 return "Alps BSBE1"
78
79         def getNimSocketCount(self):
80                 #FIXME get it from /proc
81                 return 2
82
83         def getConfigPrefix(self, slotid):
84                 return "config.Nim" + ("A","B","C","D")[slotid] + "."
85                         
86         def __init__(self):
87                 #use as enum
88                 self.nimType = {                "empty/unknown": -1,
89                                                                                                 "DVB-S": 0,
90                                                                                                 "DVB-C": 1,
91                                                                                                 "DVB-T": 2}
92                 self.satList = [ ]                                                                              
93                                                                                                 
94                 self.readSatsfromFile()                                                                         
95                                                                                                 
96                 self.nimCount = self.getNimSocketCount()
97                 
98                 self.nimslots = [ ]
99                 x = 0
100                 while x < self.nimCount:
101                         tType = self.getNimType(x)
102                         tName = self.getNimName(x)
103                         tNim = nimSlot(x, tType, tName)
104                         self.nimslots.append(tNim)
105                         x += 1
106                 
107                 InitNimManager(self)    #init config stuff
108
109         def nimList(self):
110                 list = [ ]
111                 for slot in self.nimslots:
112                         nimText = "Socket " + ("A", "B", "C", "D")[slot.slotid] + ": "
113                         if slot.nimType == -1:
114                                 nimText += "empty/unknown"
115                         else:
116                                 nimText += slot.name + " ("     
117                                 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
118                         list.append((nimText, slot))
119                 return list
120
121         #callbacks for c++ config
122         def nimConfigModeChanged(self, slotid, mode):
123                 print "nimConfigModeChanged set to " + str(mode)
124         def nimDiseqcModeChanged(self, slotid, mode):
125                 print "nimDiseqcModeChanged set to " + str(mode)
126         def nimPortAChanged(self, slotid, val):
127                 print "nimDiseqcA set to " + str(val)
128         def nimPortBChanged(self, slotid, val):
129                 print "nimDiseqcB set to " + str(val)
130         def nimPortCChanged(self, slotid, val):
131                 print "nimDiseqcC set to " + str(val)
132         def nimPortDChanged(self, slotid, val):
133                 print "nimDiseqcD set to " + str(val)
134
135
136 def InitNimManager(nimmgr):
137         config.Nims = [ConfigSubsection()] * nimmgr.nimCount
138
139         def nimConfigModeChanged(slotid, configElement):
140                 nimmgr.nimConfigModeChanged(slotid, configElement.value)
141         def nimDiseqcModeChanged(slotid, configElement):
142                 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
143                 
144         def nimPortAChanged(slotid, configElement):
145                 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
146         def nimPortBChanged(slotid, configElement):
147                 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
148         def nimPortCChanged(slotid, configElement):
149                 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
150         def nimPortDChanged(slotid, configElement):
151                 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
152
153         for slot in nimmgr.nimslots:
154                 x = slot.slotid
155                 cname = nimmgr.getConfigPrefix(x)
156                 
157                 if slot.nimType == nimmgr.nimType["DVB-S"]:
158                         config.Nims[x].configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
159                         config.Nims[x].diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D", "Positioner"));
160                         config.Nims[x].diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
161                         config.Nims[x].diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
162                         config.Nims[x].diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
163                         config.Nims[x].diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
164                         config.Nims[x].longitude = configElement(cname + "longitude",configSequence, [0,0], (("."), (1,999)));
165                         config.Nims[x].latitude = configElement(cname + "latitude",configSequence, [0,0], (("."), (1,999)));
166                         
167                         #perhaps the instance of the slot is more useful?
168                         config.Nims[x].configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
169                         config.Nims[x].diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
170                         config.Nims[x].diseqcA.addNotifier(boundFunction(nimPortAChanged,x))
171                         config.Nims[x].diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
172                         config.Nims[x].diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
173                         config.Nims[x].diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
174                 else:
175                         print "pls add support for this frontend type!"         
176
177 nimmanager = NimManager()