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