fix terrestrial manual scan, use more parameters from terrestrial.xml for
[openblackhole/openblackhole-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.NimManager import nimmanager
7 from Components.Label import Label
8 from Screens.MessageBox import MessageBox
9 from enigma import eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial
10
11 def buildTerTransponder(frequency, 
12                 inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
13                 modulation = 2, transmission = 2, guard = 4,
14                 hierarchy = 4):
15
16 #       print "freq", frequency, "inv", inversion, "bw", bandwidth, "fech", fechigh, "fecl", feclow, "mod", modulation, "tm", transmission, "guard", guard, "hierarchy", hierarchy
17
18         # WARNING: normally, enums are working directly.
19         # Don't copy this (very bad)!! Instead either fix swig (good) or
20         # move this into a central place.
21         Bw8MHz = 0
22         Bw7MHz = 1
23         Bw6MHz = 2
24         #Bw5MHz = 3 #not implemented for e1 compatibilty
25         BwAuto = 3
26         
27         f1_2 = 0
28         f2_3 = 1
29         f3_4 = 2
30         f5_6 = 3
31         f7_8 = 4
32         fAuto = 5
33         
34         TM2k = 0
35         TM8k = 1
36         #TM4k = 2  #not implemented for e1 compatibilty
37         TMAuto = 2
38         
39         GI_1_32 = 0
40         GI_1_16 = 1
41         GI_1_8 = 2
42         GI_1_4 = 3
43         GI_Auto = 4
44         
45         HNone = 0
46         H1 = 1
47         H2 = 2
48         H4 = 3
49         HAuto = 4
50
51         QPSK = 0
52         QAM16 = 1
53         QAM64 = 2
54         Auto = 3
55         
56         Off = 0
57         On = 1
58         Unknown = 2
59
60         parm = eDVBFrontendParametersTerrestrial()
61
62         parm.frequency = frequency
63
64         parm.inversion = [Off, On, Unknown][inversion]
65         parm.bandwidth = [Bw8MHz, Bw7MHz, Bw6MHz, BwAuto][bandwidth] # Bw5MHz unsupported
66         parm.code_rate_HP = [fAuto, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][fechigh]
67         parm.code_rate_LP = [fAuto, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][feclow]
68         parm.modulation = [QPSK, QAM16, QAM64, Auto][modulation]
69         parm.transmission_mode = [TM2k, TM8k, TMAuto][transmission] # TM4k unsupported
70         parm.guard_interval = [GI_1_32, GI_1_16, GI_1_8, GI_1_4, GI_Auto][guard]
71         parm.hierarchy = [HNone, H1, H2, H4, HAuto][hierarchy]
72         
73         return parm
74
75 def getInitialTransponderList(tlist, pos):
76         list = nimmanager.getTransponders(pos)
77
78         for x in list:
79                 if x[0] == 0:           #SAT
80                         parm = eDVBFrontendParametersSatellite()
81                         parm.frequency = x[1]
82                         parm.symbol_rate = x[2]
83                         parm.polarisation = x[3]
84                         parm.fec = x[4]
85                         parm.inversion = 2 # AUTO
86                         parm.orbital_position = pos
87                         parm.system = x[5]
88                         parm.modulation = x[6]
89                         tlist.append(parm)
90
91 def getInitialCableTransponderList(tlist, cable):
92         list = nimmanager.getTranspondersCable(cable)
93
94         for x in list:
95                 if x[0] == 1: #CABLE
96                         parm = eDVBFrontendParametersCable()
97                         parm.frequency = x[1]
98                         parm.symbol_rate = x[2]
99                         parm.modulation = x[3]
100                         parm.fec_inner = x[4]
101                         parm.inversion = 2 # AUTO
102                         tlist.append(parm)
103
104 def getInitialTerrestrialTransponderList(tlist, region):
105         list = nimmanager.getTranspondersTerrestrial(region)
106
107         #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv))
108
109         #def buildTerTransponder(frequency, inversion = 2, bandwidth = 3, fechigh = 6, feclow = 6,
110                                 #modulation = 2, transmission = 2, guard = 4, hierarchy = 4):
111
112         for x in list:
113                 if x[0] == 2: #TERRESTRIAL
114                         parm = buildTerTransponder(x[1], x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8])
115                         tlist.append(parm)
116
117
118 class ScanSetup(Screen):
119         def __init__(self, session):
120                 Screen.__init__(self, session)
121
122                 self.updateSatList()
123                 self.service = session.nav.getCurrentService()
124                 self.feinfo = None
125                 frontendData = None
126                 if self.service is not None:
127                         self.feinfo = self.service.frontendInfo()
128                         frontendData = self.feinfo and self.feinfo.getFrontendData(True)
129                 self.createConfig(frontendData)
130                 del self.feinfo
131                 del self.service
132
133
134                 self["actions"] = NumberActionMap(["SetupActions"],
135                 {
136                         "ok": self.keyGo,
137                         "cancel": self.keyCancel,
138                         "left": self.keyLeft,
139                         "right": self.keyRight,
140                         "1": self.keyNumberGlobal,
141                         "2": self.keyNumberGlobal,
142                         "3": self.keyNumberGlobal,
143                         "4": self.keyNumberGlobal,
144                         "5": self.keyNumberGlobal,
145                         "6": self.keyNumberGlobal,
146                         "7": self.keyNumberGlobal,
147                         "8": self.keyNumberGlobal,
148                         "9": self.keyNumberGlobal,
149                         "0": self.keyNumberGlobal
150                 }, -1)
151                 
152                 self.statusTimer = eTimer()
153                 self.statusTimer.timeout.get().append(self.updateStatus)
154                 #self.statusTimer.start(5000, True)
155
156                 self.list = []
157                 self["config"] = ConfigList(self.list)
158                 self.createSetup()
159
160                 self["introduction"] = Label(_("Press OK to start the scan"))
161
162         def run(self):
163                 self.keyGo()
164
165         def updateSatList(self):
166                 self.satList = []
167                 for slot in nimmanager.nimslots:
168                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
169                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
170                         else:
171                                 self.satList.append(None)
172                                 
173         def createSetup(self):
174                 self.list = []
175                 self.multiscanlist = []
176                 print "ID: " + str(config.scan.nims.value)
177
178                 self.tunerEntry = getConfigListEntry(_("Tuner"), config.scan.nims)
179                 self.list.append(self.tunerEntry)
180                 
181                 self.typeOfScanEntry = None
182                 self.systemEntry = None
183                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
184                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.type)
185                         self.list.append(self.typeOfScanEntry)
186                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
187                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typecable)
188                         self.list.append(self.typeOfScanEntry)
189                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
190                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial)
191                         self.list.append(self.typeOfScanEntry)
192
193
194                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
195
196                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
197                                 self.systemEntry = getConfigListEntry(_('Transpondertype'), config.scan.sat.system)
198                                 self.list.append(self.systemEntry)
199                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
200                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
201                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
202                                 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
203                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
204                                 if currentConfigSelectionElement(config.scan.sat.system) == "dvb-s":
205                                         self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
206                                 elif currentConfigSelectionElement(config.scan.sat.system) == "dvb-s2":
207                                         self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec_s2))
208                                         self.list.append(getConfigListEntry(_('Modulation'), config.scan.sat.modulation))
209                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
210                                 self.updateSatList()
211                                 print config.scan.satselection[config.scan.nims.value]
212                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
213                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
214                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
215                                 # if (norotor)
216                                 tlist = []
217                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
218                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
219                                 for x in SatList:
220                                         if self.Satexists(tlist, x[1]) == 0:
221                                                 tlist.append(x[1])
222                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
223                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
224                                                 self.list.append(configEntry)
225                                                 self.multiscanlist.append(configEntry)
226                                 # if (rotor):
227                            # for sat in nimmanager.satList:
228                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
229
230
231                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
232                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
233                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
234                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
235                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
236                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
237                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
238                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.cab.networkScan))
239                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
240                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
241                                 
242                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
243                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
244                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
245                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.ter.networkScan))
246                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
247                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
248                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
249                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
250                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
251                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
252                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
253                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
254                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
255                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
256
257 #               if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"] and currentConfigSelectionElement(config.scan.type) == "single_transponder") or \
258 #                       (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"] and currentConfigSelectionElement(config.scan.typecable) == "single_transponder") or \
259 #                       (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"] and currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder"):
260 #                               self.configElementSNR = getConfigListEntry(_("SNR"), config.scan.snr)
261 #                               self.list.append(self.configElementSNR)
262 #                               self.configElementACG = getConfigListEntry(_("AGC"), config.scan.agc)
263 #                               self.list.append(self.configElementACG)
264 #                               self.configElementBER = getConfigListEntry(_("BER"), config.scan.ber)
265 #                               self.list.append(self.configElementBER)
266 #                               self.statusTimer.start(500, False)
267 #               else:
268 #                       self.statusTimer.stop()
269
270                 self["config"].list = self.list
271                 self["config"].l.setList(self.list)
272
273         def Satexists(self, tlist, pos):
274                 for x in tlist:
275                         if x == pos:
276                                 return 1
277                 return 0
278
279         def newConfig(self):
280                 print self["config"].getCurrent()
281                 if self["config"].getCurrent() == self.typeOfScanEntry:
282                         self.createSetup()
283                 elif self["config"].getCurrent() == self.tunerEntry:
284                         self.createSetup()
285                 elif self["config"].getCurrent() == self.systemEntry:
286                         self.createSetup()
287
288         def createConfig(self, frontendData):
289                                                            #("Type", frontendData["system"], TYPE_TEXT),
290                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
291                                            #("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
292                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
293                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
294                                            #("Polarization", frontendData["polarization"], TYPE_TEXT),
295                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
296                                            #("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
297                                                 #)
298                 #elif frontendData["tuner_type"] == "DVB-C":
299                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
300                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
301                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
302                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
303                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
304                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
305                         #                  ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
306                                                 #)
307                 #elif frontendData["tuner_type"] == "DVB-T":
308                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
309                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
310                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
311                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
312                                            #("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
313                                            #("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
314                                            #("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
315                                            #("Constellation", frontendData["constellation"], TYPE_TEXT),
316                                            #("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
317                                            #("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
318                                            #("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
319                         defaultSat = { "orbpos": 192, "system": 0, "frequency": [11836], "inversion": 2, "symbolrate": [27500], "polarization": 0, "fec": 0, "fec_s2": 8, "modulation": 0 }
320                         defaultCab = {"frequency": [466], "inversion": 2, "modulation": 2, "fec": 0, "symbolrate": [6900]}
321                         if frontendData is not None:
322                                 if frontendData["tuner_type"] == "DVB-S":
323                                         defaultSat["system"] = {"DVB-S": 0, "DVB-S2": 1}[frontendData["system"]]
324                                         defaultSat["frequency"] = [int(frontendData["frequency"] / 1000)]
325                                         defaultSat["inversion"] = {"INVERSION_OFF": 0, "INVERSION_ON": 1, "INVERSION_AUTO": 2}[frontendData["inversion"]]
326                                         defaultSat["symbolrate"] = [int(frontendData["symbol_rate"] / 1000)]
327                                         defaultSat["polarization"] = {"HORIZONTAL": 0, "VERTICAL": 1, "CIRCULAR_LEFT": 2, "CIRCULAR_RIGHT": 3, "UNKNOWN": 0}[frontendData["polarization"]]
328                                         defaultSat["fec"] = {"DVB-S": {"FEC_AUTO": 0, "FEC_1_2": 1, "FEC_2_3": 2, "FEC_3_4": 3, "FEC_5_6": 4, "FEC_7_8": 5, "FEC_NONE": 6}, "DVB-S2": {"FEC_1_2": 0, "FEC_2_3": 1, "FEC_3_4": 2, "FEC_4_5": 3, "FEC_5_6": 4, "FEC_7_8": 5, "FEC_8_9": 6, "FEC_9_10": 7}}[frontendData["system"]][frontendData["fec_inner"]]
329                                         defaultSat["modulation"] = {"QPSK": 0, "8PSK": 1}[frontendData["modulation"]]
330                                         defaultSat["orbpos"] = frontendData["orbital_position"]
331                                 elif frontendData["tuner_type"] == "DVB-C":
332                                         defaultCab["frequency"] = [int(frontendData["frequency"] / 1000)]
333                                         defaultCab["symbolrate"] = [int(frontendData["symbol_rate"] / 1000)]
334                                         defaultSat["inversion"] = {"INVERSION_OFF": 0, "INVERSION_ON": 1, "INVERSION_AUTO": 2}[frontendData["inversion"]]
335                                         defaultSat["fec"] = {"FEC_AUTO": 0, "FEC_1_2": 1, "FEC_2_3": 2, "FEC_3_4": 3, "FEC_5_6": 4, "FEC_7_8": 5, "FEC_8_9": 6, "FEC_NONE": 7}[frontendData["fec_inner"]]
336                                         defaultSat["modulation"] = {"QAM_AUTO": 0, "QAM_16": 1, "QAM_16": 2, "QAM_32": 3, "QAM_64": 4, "QAM_128": 5, "QAM_256": 6}[frontendData["modulation"]]
337                                                                                 
338                         config.scan = ConfigSubsection()
339                         config.scan.sat = ConfigSubsection()
340                         config.scan.cab = ConfigSubsection()
341                         config.scan.ter = ConfigSubsection()
342
343                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
344                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
345                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
346                         config.scan.clearallservices = configElement_nonSave("config.scan.clearallservices", configSelection, 0, (("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))))
347
348                         nimList = [ ]
349                         for nim in nimmanager.nimList():
350                                 nimList.append(nim[0])
351                         #nimList.append("all")
352                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
353                         
354                         # status
355                         config.scan.snr = configElement_nonSave("config.scan.snr", configSlider, 0, (1, 100))
356                         config.scan.snr.enabled = False
357                         config.scan.agc = configElement_nonSave("config.scan.agc", configSlider, 0, (1, 100))
358                         config.scan.agc.enabled = False
359                         config.scan.ber = configElement_nonSave("config.scan.ber", configSlider, 0, (1, 100))
360                         config.scan.ber.enabled = False
361
362                         # sat
363                         config.scan.sat.system = configElement_nonSave("config.scan.sat.system", configSelection, defaultSat["system"], (("dvb-s", _("DVB-S")), ("dvb-s2", _("DVB-S2"))))
364                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, defaultSat["frequency"], configsequencearg.get("INTEGER", (1, 99999)))
365                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, defaultSat["inversion"], (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
366                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, defaultSat["symbolrate"], configsequencearg.get("INTEGER", (1, 99999)))
367                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, defaultSat["polarization"], (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
368                         config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, defaultSat["fec"], (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("none", _("None"))))
369                         config.scan.sat.fec_s2 = configElement_nonSave("config.scan.sat.fec_s2", configSelection, defaultSat["fec_s2"], (("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("3_5", "3/5"), ("4_5", "4/5"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("9_10", "9/10")))
370                         config.scan.sat.modulation = configElement_nonSave("config.scan.sat.modulation", configSelection, defaultSat["modulation"], (("qpsk", "QPSK"), ("8psk", "8PSK")))
371         
372                         # cable
373                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, defaultCab["frequency"], configsequencearg.get("INTEGER", (50, 999)))
374                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, defaultCab["inversion"], (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
375                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, defaultCab["modulation"], (("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM")))
376                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, defaultCab["fec"], (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("none", _("None"))))
377                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, defaultCab["symbolrate"], configsequencearg.get("INTEGER", (1, 9999)))
378                         config.scan.cab.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
379
380                         # terrestial
381                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (100, 900)))
382                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
383                         # WORKAROUND: we can't use BW-auto
384                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 0, (("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz")))
385                         #, ("auto", _("Auto"))))
386                         config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 5, (("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))))
387                         config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 5, (("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))))
388                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 3, (("qpsk", "QPSK"), ("qam16", "QAM16"), ("qam64", "QAM64"), ("auto", _("Auto"))))
389                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, (("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))))
390                         config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 4, (("1_32", "1/32"), ("1_16", "1/16"), ("1_8", "1/8"), ("1_4", "1/4"), ("auto", _("Auto"))))
391                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))))
392                         config.scan.ter.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
393
394                         config.scan.scansat = {}
395                         for sat in nimmanager.satList:
396                                 #print sat[1]
397                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
398
399                         config.scan.satselection = []
400                         slotid = 0
401                         for slot in nimmanager.nimslots:
402                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
403                                         print str(slot.slotid) + " : " + str(self.satList)
404                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, defaultSat["orbpos"], self.satList[slot.slotid]))
405                                 else:
406                                         config.scan.satselection.append(None)
407         def keyLeft(self):
408                 self["config"].handleKey(config.key["prevElement"])
409                 self.newConfig()
410
411         def keyRight(self):
412                 self["config"].handleKey(config.key["nextElement"])
413                 self.newConfig()
414
415         def updateStatus(self):
416                 print "updatestatus"
417
418         def keyNumberGlobal(self, number):
419                 print "You pressed number " + str(number)
420                 if (self["config"].getCurrent()[1].parent.enabled == True):
421                         self["config"].handleKey(config.key[str(number)])
422
423         fecmap = { "auto": 0,
424                            "1_2": 1,
425                            "2_3": 2,
426                            "3_4": 3,
427                            "5_6": 4,
428                            "7_8": 5,
429                            "8_9": 6,
430                            "3_5": 7,
431                            "4_5": 8,
432                            "9_10": 9,
433                            "none": 15
434                            }
435
436         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation):
437                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(self.fecmap[fec]) + " inversion: " + str(inversion) + " modulation: " + str(modulation) + " system: " + str(system)
438                 print "orbpos: " + str(orbital_position)
439                 parm = eDVBFrontendParametersSatellite()
440                 if modulation == 1:
441                         parm.modulation = 2 # eDVBFrontendParametersSatellite.Modulation.8PSK
442                 else:
443                         parm.modulation = 1 # eDVBFrontendParametersSatellite.Modulation.QPSK
444                 parm.system = system
445                 parm.frequency = frequency * 1000
446                 parm.symbol_rate = symbol_rate * 1000
447                 parm.polarisation = polarisation
448                 parm.fec = self.fecmap[fec]
449                 parm.inversion = inversion
450                 parm.orbital_position = int(orbital_position)
451                 tlist.append(parm)
452
453         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
454                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
455                 parm = eDVBFrontendParametersCable()
456                 parm.frequency = frequency * 1000
457                 parm.symbol_rate = symbol_rate * 1000
458                 parm.modulation = modulation
459                 parm.fec = self.fecmap[fec]
460                 parm.inversion = inversion
461                 tlist.append(parm)
462
463         def addTerTransponder(self, tlist, *args, **kwargs):
464                 tlist.append(buildTerTransponder(*args, **kwargs))
465
466         def keyGo(self):
467                 tlist = []
468                 flags = 0
469                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
470                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
471                                 l = len(self.satList)
472                                 if l and l > config.scan.nims.value:
473                                         nimsats=self.satList[config.scan.nims.value]
474                                         l = len(config.scan.satselection)
475                                         if l and l > config.scan.nims.value:
476                                                 selsatidx=config.scan.satselection[config.scan.nims.value].value
477                                                 l = len(nimsats)
478                                                 if l and l > selsatidx:
479                                                         orbpos=nimsats[selsatidx][1]
480                                                         if currentConfigSelectionElement(config.scan.sat.system) == "dvb-s":
481                                                                 fec = currentConfigSelectionElement(config.scan.sat.fec)
482                                                         else:
483                                                                 fec = currentConfigSelectionElement(config.scan.sat.fec_s2)
484                                                         self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
485                                                                                 config.scan.sat.symbolrate.value[0],
486                                                                                 config.scan.sat.polarization.value,
487                                                                                 fec,
488                                                                                 config.scan.sat.inversion.value,
489                                                                                 orbpos,
490                                                                                 config.scan.sat.system.value,
491                                                                                 config.scan.sat.modulation.value)
492                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
493                                 sat = self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value]
494                                 getInitialTransponderList(tlist, int(sat[1]))
495                                 flags |= eComponentScan.scanNetworkSearch
496                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
497                                 if tmp == "yes":
498                                         flags |= eComponentScan.scanRemoveServices
499                                 elif tmp == "yes_hold_feeds":
500                                         flags |= eComponentScan.scanRemoveServices
501                                         flags |= eComponentScan.scanDontRemoveFeeds
502                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
503                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
504                                 for x in self.multiscanlist:
505                                         if x[1].parent.value == 0:
506                                                 print "   " + str(x[1].parent.configPath)
507                                                 getInitialTransponderList(tlist, x[1].parent.configPath)
508                                 flags |= eComponentScan.scanNetworkSearch
509                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
510                                 if tmp == "yes":
511                                         flags |= eComponentScan.scanRemoveServices
512                                 elif tmp == "yes_hold_feeds":
513                                         flags |= eComponentScan.scanRemoveServices
514                                         flags |= eComponentScan.scanDontRemoveFeeds
515
516                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
517                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
518                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
519                                                                                           config.scan.cab.symbolrate.value[0],
520                                                                                           config.scan.cab.modulation.value + 1,
521                                                                                           config.scan.cab.fec.value,
522                                                                                           config.scan.cab.inversion.value)
523                                 if currentConfigSelectionElement(config.scan.cab.networkScan) == "yes":
524                                         flags |= eComponentScan.scanNetworkSearch
525                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
526                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(config.scan.nims.value))
527                                 flags |= eComponentScan.scanNetworkSearch
528                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
529                                 if tmp == "yes":
530                                         flags |= eComponentScan.scanRemoveServices
531                                 elif tmp == "yes_hold_feeds":
532                                         flags |= eComponentScan.scanRemoveServices
533                                         flags |= eComponentScan.scanDontRemoveFeeds
534
535                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
536                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
537                                 self.addTerTransponder(tlist,
538                                                 config.scan.ter.frequency.value[0] * 1000000,
539                                                 inversion = config.scan.ter.inversion.value,
540                                                 bandwidth = config.scan.ter.bandwidth.value,
541                                                 fechigh = config.scan.ter.fechigh.value,
542                                                 feclow = config.scan.ter.feclow.value,
543                                                 modulation = config.scan.ter.modulation.value,
544                                                 transmission = config.scan.ter.transmission.value,
545                                                 guard = config.scan.ter.guard.value,
546                                                 hierarchy = config.scan.ter.hierarchy.value)
547                                 if currentConfigSelectionElement(config.scan.ter.networkScan) == "yes":
548                                         flags |= eComponentScan.scanNetworkSearch
549                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
550                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(config.scan.nims.value))
551                                 flags |= eComponentScan.scanNetworkSearch
552                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
553                                 if tmp == "yes":
554                                         flags |= eComponentScan.scanRemoveServices
555                                 elif tmp == "yes_hold_feeds":
556                                         flags |= eComponentScan.scanRemoveServices
557                                         flags |= eComponentScan.scanDontRemoveFeeds
558
559                 for x in self["config"].list:
560                         x[1].save()
561
562                 if len(tlist):
563                         feid = config.scan.nims.value
564                         # flags |= eComponentScan.scanSearchBAT
565                         self.session.openWithCallback(self.doNothing, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
566                 else:
567                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
568
569         def doNothing(self):
570                 pass
571
572         def keyCancel(self):
573                 for x in self["config"].list:
574                         x[1].cancel()
575                 self.close()
576
577 class ScanSimple(Screen):
578         def run(self):
579                 self.keyGo()
580
581         def keyGo(self):
582                 scanList = []
583                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and nimmanager.getNimType(0) == nimmanager.getNimType(1):
584                         sec = eDVBSatelliteEquipmentControl.getInstance()
585                         if sec is not None:
586                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
587                         else:
588                                 exclusive_satellites = [0,0]
589                         print "exclusive satellites", exclusive_satellites
590                         two_sat_tuners = True
591                 else:
592                         two_sat_tuners = False
593
594                 for x in self.list:
595                         slotid = x[1].parent.configPath
596                         print "Scan Tuner", slotid, "-", currentConfigSelectionElement(x[1].parent)
597                         if currentConfigSelectionElement(x[1].parent) == "yes":
598                                 scanPossible = False
599                                 tlist = [ ]
600                                 if nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-S"]:
601                                         if two_sat_tuners:
602                                                 if slotid > 0:
603                                                         idx = exclusive_satellites[0]+1
604                                                 else:
605                                                         idx = 0
606                                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
607                                                 print "exclusive_nim_sats", exclusive_nim_sats
608                                         SatList = nimmanager.getSatListForNim(slotid)
609                                         for sat in SatList:
610                                                 if not two_sat_tuners or (sat[1] in exclusive_nim_sats or slotid == 0):
611                                                         scanPossible = True
612                                                         print sat
613                                                         getInitialTransponderList(tlist, sat[1])
614                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-C"]:
615                                         scanPossible = True
616                                         getInitialCableTransponderList(tlist, nimmanager.getCableDescription(slotid))
617                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-T"]:
618                                         scanPossible = True
619                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(slotid))
620                                 if scanPossible:
621                                         flags=eComponentScan.scanNetworkSearch
622                                         tmp = currentConfigSelectionElement(config.scan.clearallservices)
623                                         if tmp == "yes":
624                                                 flags |= eComponentScan.scanRemoveServices
625                                         elif tmp == "yes_hold_feeds":
626                                                 flags |= eComponentScan.scanRemoveServices
627                                                 flags |= eComponentScan.scanDontRemoveFeeds
628                                         scanList.append({"transponders": tlist, "feid": slotid, "flags": flags})
629                 if len(scanList):
630                         self.session.openWithCallback(self.doNothing, ServiceScan, scanList = scanList)
631                 else:
632                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
633
634         def doNothing(self):
635                 pass
636
637         def keyCancel(self):
638                 self.close()
639
640         def keyLeft(self):
641                 self["config"].handleKey(config.key["prevElement"])
642
643         def keyRight(self):
644                 self["config"].handleKey(config.key["nextElement"])
645
646         def Satexists(self, tlist, pos):
647                 for x in tlist:
648                         if x == pos:
649                                 return 1
650                 return 0
651
652         def ScanNimTwoNeeded(self):
653                 if nimmanager.getNimType(0) != nimmanager.getNimType(1):
654                         return True
655                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"]: #two dvb-s nims
656                         if nimmanager.getNimConfigMode(1) in ["loopthrough", "satposdepends", "equal", "nothing"]:
657                                 return False
658                         sec = eDVBSatelliteEquipmentControl.getInstance()
659                         if sec is not None:
660                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
661                                 if len(exclusive_satellites) == 2:
662                                         return False
663                                 idx = exclusive_satellites[0]+1
664                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
665                                 if len(exclusive_nim_sats):
666                                         return True
667                 return False # two -C or two -T tuners
668
669         def __init__(self, session):
670                 Screen.__init__(self, session)
671
672                 self["actions"] = ActionMap(["SetupActions"],
673                 {
674                         "ok": self.keyGo,
675                         "cancel": self.keyCancel,
676                         "left": self.keyLeft,
677                         "right": self.keyRight,
678                 }, -1)
679
680                 self.list = []
681                 tlist = []
682
683                 nimcount = nimmanager.getNimSocketCount()
684                 if nimcount > 0:
685                         nimtype = nimmanager.getNimType(0)
686                         scan_possible=True
687                         config.scan = ConfigSubsection()
688                         config.scan.clearallservices = configElement_nonSave("config.scan.clearallservices", configSelection, 0, (("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))))
689                         self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
690                         nim = configElement_nonSave(0, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
691                         if nimtype == nimmanager.nimType["DVB-S"] and not len(nimmanager.getSatListForNim(0)):
692                                 scan_possible=False
693                         if scan_possible:
694                                 self.list.append(getConfigListEntry(_("Scan NIM") + " 0 (" + nimmanager.getNimTypeName(0) + ")", nim))
695         
696                 if nimcount > 1 and self.ScanNimTwoNeeded():
697                         nim = configElement_nonSave(1, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
698                         self.list.append(getConfigListEntry(_("Scan NIM") + " 1 (" + nimmanager.getNimTypeName(1) + ")", nim))
699
700                 self["config"] = ConfigList(self.list)
701                 self["header"] = Label(_("Automatic Scan"))
702                 self["footer"] = Label(_("Press OK to scan"))