change order of terrestrial parameters to match e2's enums
[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, 30000)))
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
176                         # cable
177                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
178                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 0, ("auto", "off", "on"))
179                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 0, ("Auto", "16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM"))
180                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 0, ("Auto", "1/2", "2/3", "3/4", "4/5", "5/6", "7/8", "8/9"))
181                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 30000)))
182
183                         # terrestial
184                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (10000, 14000)))
185                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, ("off", "on", "Auto"))
186                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 3, ("8MHz", "7MHz", "6MHz", "Auto"))
187                         config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 6, ("None", "1/2", "2/3", "3/4", "5/6", "7/8", "Auto"))
188                         config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 6, ("None", "1/2", "2/3", "3/4", "5/6", "7/8", "Auto"))
189                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, ("QPSK", "QAM16", "Auto"))
190                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, ("2K", "8K", "Auto"))
191                         config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 4, ("1/32", "1/16", "1/8", "1/4", "Auto"))
192                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, ("None", "1", "2", "4", "Auto"))
193
194                         config.scan.scansat = {}
195                         for sat in nimmanager.satList:
196                                 #print sat[1]
197                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, ("yes", "no"))
198
199                         config.scan.satselection = []
200                         slotid = 0
201                         for slot in nimmanager.nimslots:
202                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
203                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
204
205         def keyLeft(self):
206                 self["config"].handleKey(config.key["prevElement"])
207                 self.newConfig()
208
209         def keyRight(self):
210                 self["config"].handleKey(config.key["nextElement"])
211                 self.newConfig()
212
213         def keyNumberGlobal(self, number):
214                 print "You pressed number " + str(number)
215                 if (self["config"].getCurrent()[1].parent.enabled == True):
216                         self["config"].handleKey(config.key[str(number)])
217
218         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
219                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
220                 print "orbpos: " + str(orbital_position)
221                 parm = eDVBFrontendParametersSatellite()
222                 parm.frequency = frequency * 1000
223                 parm.symbol_rate = symbol_rate * 1000
224                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
225                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
226                 #parm.fec = 6                                   # AUTO
227                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
228                 #parm.inversion = 2             #AUTO
229                 parm.orbital_position = int(orbital_position)
230                 tlist.append(parm)
231
232         # FIXME use correct parameters
233         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
234                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
235                 parm = eDVBFrontendParametersCable()
236                 parm.frequency = frequency * 1000
237                 parm.symbol_rate = symbol_rate * 1000
238                 parm.modulation = modulation # eDVBFrontendParametersSatellite.Polarisation.Verti       
239                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
240                 #parm.fec = 6                                   # AUTO
241                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
242                 #parm.inversion = 2             #AUTO
243                 tlist.append(parm)
244
245         # FIXME use correct parameters
246         def addTerTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
247                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
248                 print "orbpos: " + str(orbital_position)
249                 parm = eDVBFrontendParametersTerrestrial()
250                 parm.frequency = frequency * 1000
251                 parm.symbol_rate = symbol_rate * 1000
252                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
253                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
254                 #parm.fec = 6                                   # AUTO
255                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
256                 #parm.inversion = 2             #AUTO
257                 parm.orbital_position = int(orbital_position)
258                 tlist.append(parm)
259
260         def keyGo(self):
261                 tlist = []
262                 flags = 0
263                 if (config.scan.type.value == 0): # single transponder scan
264                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
265                                 self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
266                                                                                           config.scan.sat.symbolrate.value[0],
267                                                                                           config.scan.sat.polarization.value,
268                                                                                           config.scan.sat.fec.value,
269                                                                                           config.scan.sat.inversion.value,
270                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
271                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
272                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
273                                                                                           config.scan.cab.symbolrate.value[0],
274                                                                                           config.scan.cab.modulation.value,
275                                                                                           config.scan.cab.fec.value,
276                                                                                           config.scan.cab.inversion.value)
277                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
278                                 self.addTerTransponder(tlist, config.scan.sat.frequency.value[0],
279                                                                                           config.scan.sat.symbolrate.value[0],
280                                                                                           config.scan.sat.polarization.value,
281                                                                                           config.scan.sat.fec.value,
282                                                                                           config.scan.sat.inversion.value,
283                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
284
285                 if (config.scan.type.value == 1): # single sat scan
286                         getInitialTransponderList(tlist, int(self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1]))
287                         flags |= eComponentScan.scanNetworkSearch
288
289                 if (config.scan.type.value == 2): # multi sat scan
290                         SatList = nimmanager.getSatListForNim(config.scan.nims.value)
291
292                         for x in self.list:
293                                 if x[1].parent.value == 0:
294                                         print "   " + str(x[1].parent.configPath)
295                                         getInitialTransponderList(tlist, x[1].parent.configPath)
296                         flags |= eComponentScan.scanNetworkSearch
297
298                 for x in self["config"].list:
299                         x[1].save()
300
301                 feid = config.scan.nims.value
302                 # flags |= eComponentScan.scanSearchBAT
303                 self.session.openWithCallback(self.keyCancel, ServiceScan, tlist, feid, flags)
304
305                 #self.close()
306
307         def keyCancel(self):
308                 for x in self["config"].list:
309                         x[1].cancel()
310                 self.close()
311
312 class ScanSimple(Screen):
313
314         def keyOK(self):
315                 print "start scan for sats:"
316                 tlist = [ ]
317                 for x in self.list:
318                         if x[1].parent.value == 0:
319                                 print "   " + str(x[1].parent.configPath)
320                                 getInitialTransponderList(tlist, x[1].parent.configPath)
321
322                 feid = 0 # FIXME
323                 self.session.openWithCallback(self.keyCancel, ServiceScan, tlist, feid, eComponentScan.scanNetworkSearch)
324
325         def keyCancel(self):
326                 self.close()
327
328         def keyLeft(self):
329                 self["config"].handleKey(config.key["prevElement"])
330
331         def keyRight(self):
332                 self["config"].handleKey(config.key["nextElement"])
333
334         def Satexists(self, tlist, pos):
335                 for x in tlist:
336                         if x == pos:
337                                 return 1
338                 return 0
339
340         def __init__(self, session):
341                 Screen.__init__(self, session)
342
343                 self["actions"] = ActionMap(["SetupActions"],
344                 {
345                         "ok": self.keyOK,
346                         "cancel": self.keyCancel,
347                         "left": self.keyLeft,
348                         "right": self.keyRight,
349                 }, -1)
350
351                 self.list = []
352                 tlist = []
353
354                 SatList = nimmanager.getConfiguredSats()
355
356                 for x in SatList:
357                         if self.Satexists(tlist, x) == 0:
358                                 tlist.append(x)
359                                 sat = configElement_nonSave(x, configSelection, 0, ("Enable", "Disable"))
360                                 self.list.append(getConfigListEntry(nimmanager.getSatDescription(x), sat))
361
362                 self["config"] = ConfigList(self.list)
363                 self["header"] = Label("Automatic Scan")
364                 self["footer"] = Label("Press OK to scan")