fixed parameters for dvb-c
[enigma2.git] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from ServiceScan import *
3 from Components.config import *
4 from Components.ActionMap import NumberActionMap
5 from Components.ConfigList import ConfigList
6 from Components.config import config
7 from Components.config import getConfigListEntry
8 from Components.NimManager import nimmanager
9 from Components.Label import Label
10 from enigma import eDVBFrontendParametersSatellite, eComponentScan
11
12 def getInitialTransponderList(tlist, pos):
13         print pos
14         list = nimmanager.getTransponders(pos)
15
16         for x in list:
17                 if x[0] == 0:           #SAT
18                         parm = eDVBFrontendParametersSatellite()
19                         parm.frequency = x[1]
20                         parm.symbol_rate = x[2]
21                         parm.polarisation = x[3] # eDVBFrontendParametersSatellite.Polarisation.Vertical
22                         #parm.fec = x[4]                        # eDVBFrontendParametersSatellite.FEC.f3_4;
23                         parm.fec = 6                                    # AUTO
24                         #parm.inversion = 1     #eDVBFrontendParametersSatellite.Inversion.Off;
25                         parm.inversion = 2              #AUTO
26                         parm.orbital_position = pos
27                         tlist.append(parm)
28
29 class ScanSetup(Screen):
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 self.updateSatList()
34                 self.createConfig()
35
36
37                 self["actions"] = NumberActionMap(["SetupActions"],
38                 {
39                         "ok": self.keyGo,
40                         "cancel": self.keyCancel,
41                         "left": self.keyLeft,
42                         "right": self.keyRight,
43                         "1": self.keyNumberGlobal,
44                         "2": self.keyNumberGlobal,
45                         "3": self.keyNumberGlobal,
46                         "4": self.keyNumberGlobal,
47                         "5": self.keyNumberGlobal,
48                         "6": self.keyNumberGlobal,
49                         "7": self.keyNumberGlobal,
50                         "8": self.keyNumberGlobal,
51                         "9": self.keyNumberGlobal,
52                         "0": self.keyNumberGlobal
53                 }, -1)
54
55                 self.list = []
56                 self["config"] = ConfigList(self.list)
57                 self.createSetup()
58
59                 self["introduction"] = Label("Press OK to start the scan")
60
61         def updateSatList(self):
62                 self.satList = []
63                 for slot in nimmanager.nimslots:
64                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
65                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
66
67         def createSetup(self):
68                 self.list = []
69
70                 self.list.append(getConfigListEntry(_("Tuner"), config.scan.nims))
71                 
72                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
73                         self.list.append(getConfigListEntry(_("Type of scan"), config.scan.type))
74                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
75                         self.list.append(getConfigListEntry(_("Type of scan"), config.scan.typecable))
76                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
77                         self.list.append(getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial))
78
79
80                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
81                         if (config.scan.type.value == 0): # single transponder scan
82                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
83                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
84                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
85                                 self.list.append(getConfigListEntry(_('Symbolrate'), config.scan.sat.symbolrate))
86                                 self.list.append(getConfigListEntry("Polarity", config.scan.sat.polarization))
87                                 self.list.append(getConfigListEntry("FEC", config.scan.sat.fec))
88                         if (config.scan.type.value == 1): # single satellite scan
89                                 self.updateSatList()
90                                 print config.scan.satselection[config.scan.nims.value]
91                                 self.list.append(getConfigListEntry("Satellite", config.scan.satselection[config.scan.nims.value]))
92                         if (config.scan.type.value == 2): # multi sat scan
93                                 # if (norotor)
94                                 tlist = []
95                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
96         
97                                 for x in SatList:
98                                         if self.Satexists(tlist, x[1]) == 0:
99                                                 tlist.append(x[1])
100                                                 sat = configElement_nonSave(x[1], configSelection, 0, ("Enable", "Disable"))
101                                                 self.list.append(getConfigListEntry(nimmanager.getSatDescription(x[1]), sat))
102         
103                                 # if (rotor):
104                            # for sat in nimmanager.satList:
105                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
106
107
108                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
109                         if (config.scan.typecable.value == 0): # single transponder
110                                 self.list.append(getConfigListEntry("Frequency", config.scan.cab.frequency))
111                                 self.list.append(getConfigListEntry("Inversion", config.scan.cab.inversion))
112                                 self.list.append(getConfigListEntry("Symbolrate", config.scan.cab.symbolrate))
113                                 self.list.append(getConfigListEntry("Modulation", config.scan.cab.modulation))
114                                 self.list.append(getConfigListEntry("FEC", config.scan.cab.fec))
115                         if (config.scan.typecable.value == 1): # complete
116                                 pass
117         
118                                 
119                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
120                         if (config.scan.typeterrestrial.value == 0): # single transponder
121                                 self.list.append(getConfigListEntry("Frequency", config.scan.ter.frequency))
122                                 self.list.append(getConfigListEntry("Inversion", config.scan.ter.inversion))
123                                 self.list.append(getConfigListEntry("Bandwidth", config.scan.ter.bandwidth))
124                                 self.list.append(getConfigListEntry("Code rate high", config.scan.ter.fechigh))
125                                 self.list.append(getConfigListEntry("Code rate low", config.scan.ter.feclow))
126                                 self.list.append(getConfigListEntry("Modulation", config.scan.ter.modulation))
127                                 self.list.append(getConfigListEntry("Transmission mode", config.scan.ter.transmission))
128                                 self.list.append(getConfigListEntry("Guard interval mode", config.scan.ter.guard))
129                                 self.list.append(getConfigListEntry("Hierarchy mode", config.scan.ter.hierarchy))
130                         if (config.scan.typeterrestrial.value == 1): # complete
131                                 pass
132
133
134
135
136                 self["config"].list = self.list
137                 self["config"].l.setList(self.list)
138
139         def Satexists(self, tlist, pos):
140                 for x in tlist:
141                         if x == pos:
142                                 return 1
143                 return 0
144
145         def newConfig(self):
146                 print self["config"].getCurrent()
147                 if self["config"].getCurrent()[0] == _("Type of scan"):
148                         self.createSetup()
149                 if self["config"].getCurrent()[0] == _("Tuner"):
150                         self.createSetup()
151
152         def createConfig(self):
153                         config.scan = ConfigSubsection()
154                         config.scan.sat = ConfigSubsection()
155                         config.scan.cab = ConfigSubsection()
156                         config.scan.ter = ConfigSubsection()
157
158                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, ("Single transponder", "Single satellite", "Multisat"))
159                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, ("Single transponder", "Complete"))
160                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, ("Single transponder", "Complete"))
161
162                         nimList = [ ]
163                         for nim in nimmanager.nimList():
164                                 nimList.append(nim[0])
165                         nimList.append("all")
166                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
167
168                         # sat
169                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (10000, 14000)))
170                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, ("on", "off", "auto"))
171                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 9999)))
172                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, ("horizontal", "vertical",  "circular left", "circular right"))
173                         config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, 7, ("None", "1/2", "2/3", "3/4", "5/6", "7/8", "auto"))
174
175                         # cable
176                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 9999)))
177                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, ("off", "on", "Auto"))
178                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 2, ("16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM", "Auto"))
179                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 9, ("None", "1/2", "2/3", "3/4", "4/5", "5/6", "6/7", "7/8", "8/9", "Auto"))
180                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 30000)))
181
182                         # terrestial
183                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
184                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, ("off", "on", "Auto"))
185                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 3, ("8MHz", "7MHz", "6MHz", "Auto"))
186                         config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 6, ("None", "1/2", "2/3", "3/4", "5/6", "7/8", "Auto"))
187                         config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 6, ("None", "1/2", "2/3", "3/4", "5/6", "7/8", "Auto"))
188                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, ("QPSK", "QAM16", "Auto"))
189                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, ("2K", "8K", "Auto"))
190                         config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 4, ("1/32", "1/16", "1/8", "1/4", "Auto"))
191                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, ("None", "1", "2", "4", "Auto"))
192
193                         config.scan.scansat = {}
194                         for sat in nimmanager.satList:
195                                 #print sat[1]
196                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, ("yes", "no"))
197
198                         config.scan.satselection = []
199                         slotid = 0
200                         for slot in nimmanager.nimslots:
201                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
202                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
203
204         def keyLeft(self):
205                 self["config"].handleKey(config.key["prevElement"])
206                 self.newConfig()
207
208         def keyRight(self):
209                 self["config"].handleKey(config.key["nextElement"])
210                 self.newConfig()
211
212         def keyNumberGlobal(self, number):
213                 print "You pressed number " + str(number)
214                 if (self["config"].getCurrent()[1].parent.enabled == True):
215                         self["config"].handleKey(config.key[str(number)])
216
217         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
218                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
219                 print "orbpos: " + str(orbital_position)
220                 parm = eDVBFrontendParametersSatellite()
221                 parm.frequency = frequency * 1000
222                 parm.symbol_rate = symbol_rate * 1000
223                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
224                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
225                 #parm.fec = 6                                   # AUTO
226                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
227                 #parm.inversion = 2             #AUTO
228                 parm.orbital_position = int(orbital_position)
229                 tlist.append(parm)
230
231         # FIXME use correct parameters
232         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
233                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
234                 parm = eDVBFrontendParametersCable()
235                 parm.frequency = frequency * 1000
236                 parm.symbol_rate = symbol_rate * 1000
237                 parm.modulation = modulation # eDVBFrontendParametersSatellite.Polarisation.Verti       
238                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
239                 #parm.fec = 6                                   # AUTO
240                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
241                 #parm.inversion = 2             #AUTO
242                 tlist.append(parm)
243
244         # FIXME use correct parameters
245         def addTerTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
246                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
247                 print "orbpos: " + str(orbital_position)
248                 parm = eDVBFrontendParametersTerrestrial()
249                 parm.frequency = frequency * 1000
250                 parm.symbol_rate = symbol_rate * 1000
251                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
252                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
253                 #parm.fec = 6                                   # AUTO
254                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
255                 #parm.inversion = 2             #AUTO
256                 parm.orbital_position = int(orbital_position)
257                 tlist.append(parm)
258
259         def keyGo(self):
260                 tlist = []
261                 flags = 0
262                 if (config.scan.type.value == 0): # single transponder scan
263                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
264                                 self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
265                                                                                           config.scan.sat.symbolrate.value[0],
266                                                                                           config.scan.sat.polarization.value,
267                                                                                           config.scan.sat.fec.value,
268                                                                                           config.scan.sat.inversion.value,
269                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
270                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
271                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
272                                                                                           config.scan.cab.symbolrate.value[0],
273                                                                                           config.scan.cab.modulation.value,
274                                                                                           config.scan.cab.fec.value,
275                                                                                           config.scan.cab.inversion.value)
276                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
277                                 self.addTerTransponder(tlist, config.scan.sat.frequency.value[0],
278                                                                                           config.scan.sat.symbolrate.value[0],
279                                                                                           config.scan.sat.polarization.value,
280                                                                                           config.scan.sat.fec.value,
281                                                                                           config.scan.sat.inversion.value,
282                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
283
284                 if (config.scan.type.value == 1): # single sat scan
285                         getInitialTransponderList(tlist, int(self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1]))
286                         flags |= eComponentScan.scanNetworkSearch
287
288                 if (config.scan.type.value == 2): # multi sat scan
289                         SatList = nimmanager.getSatListForNim(config.scan.nims.value)
290
291                         for x in self.list:
292                                 if x[1].parent.value == 0:
293                                         print "   " + str(x[1].parent.configPath)
294                                         getInitialTransponderList(tlist, x[1].parent.configPath)
295                         flags |= eComponentScan.scanNetworkSearch
296
297                 for x in self["config"].list:
298                         x[1].save()
299
300                 feid = config.scan.nims.value
301                 # flags |= eComponentScan.scanSearchBAT
302                 self.session.openWithCallback(self.keyCancel, ServiceScan, tlist, feid, flags)
303
304                 #self.close()
305
306         def keyCancel(self):
307                 for x in self["config"].list:
308                         x[1].cancel()
309                 self.close()
310
311 class ScanSimple(Screen):
312
313         def keyOK(self):
314                 print "start scan for sats:"
315                 tlist = [ ]
316                 for x in self.list:
317                         if x[1].parent.value == 0:
318                                 print "   " + str(x[1].parent.configPath)
319                                 getInitialTransponderList(tlist, x[1].parent.configPath)
320
321                 feid = 0 # FIXME
322                 self.session.openWithCallback(self.keyCancel, ServiceScan, tlist, feid, eComponentScan.scanNetworkSearch)
323
324         def keyCancel(self):
325                 self.close()
326
327         def keyLeft(self):
328                 self["config"].handleKey(config.key["prevElement"])
329
330         def keyRight(self):
331                 self["config"].handleKey(config.key["nextElement"])
332
333         def Satexists(self, tlist, pos):
334                 for x in tlist:
335                         if x == pos:
336                                 return 1
337                 return 0
338
339         def __init__(self, session):
340                 Screen.__init__(self, session)
341
342                 self["actions"] = ActionMap(["SetupActions"],
343                 {
344                         "ok": self.keyOK,
345                         "cancel": self.keyCancel,
346                         "left": self.keyLeft,
347                         "right": self.keyRight,
348                 }, -1)
349
350                 self.list = []
351                 tlist = []
352
353                 SatList = nimmanager.getConfiguredSats()
354
355                 for x in SatList:
356                         if self.Satexists(tlist, x) == 0:
357                                 tlist.append(x)
358                                 sat = configElement_nonSave(x, configSelection, 0, ("Enable", "Disable"))
359                                 self.list.append(getConfigListEntry(nimmanager.getSatDescription(x), sat))
360
361                 self["config"] = ConfigList(self.list)
362                 self["header"] = Label("Automatic Scan")
363                 self["footer"] = Label("Press OK to scan")