fix segfault after leaving scan in some conditions
[vuplus_dvbapp] / lib / dvb / sec.cpp
1 #include <lib/dvb/dvb.h>
2 #include <lib/dvb/sec.h>
3 #include <lib/dvb/rotor_calc.h>
4
5 #if HAVE_DVB_API_VERSION < 3
6 #define FREQUENCY Frequency
7 #else
8 #define FREQUENCY frequency
9 #endif
10 #include <lib/base/eerror.h>
11
12 DEFINE_REF(eDVBSatelliteEquipmentControl);
13
14 eDVBSatelliteEquipmentControl *eDVBSatelliteEquipmentControl::instance;
15
16 eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBRegisteredFrontend> &avail_frontends)
17         :m_lnbidx(-1), m_curSat(m_lnbs[0].m_satellites.end()), m_avail_frontends(avail_frontends), m_rotorMoving(false)
18 {
19         if (!instance)
20                 instance = this;
21
22         clear();
23
24 // ASTRA
25         addLNB();
26         setLNBTunerMask(3);
27         setLNBLOFL(9750000);
28         setLNBThreshold(11750000);
29         setLNBLOFH(10607000);
30         setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
31         setToneburst(eDVBSatelliteDiseqcParameters::NO);
32         setRepeats(0);
33         setCommittedCommand(eDVBSatelliteDiseqcParameters::BB);
34         setCommandOrder(0); // committed, toneburst
35         setFastDiSEqC(true);
36         setSeqRepeat(false);
37         addSatellite(192);
38         setVoltageMode(eDVBSatelliteSwitchParameters::HV);
39         setToneMode(eDVBSatelliteSwitchParameters::HILO);
40
41 // Hotbird
42         addLNB();
43         setLNBTunerMask(3);
44         setLNBLOFL(9750000);
45         setLNBThreshold(11750000);
46         setLNBLOFH(10600000);
47         setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
48         setToneburst(eDVBSatelliteDiseqcParameters::NO);
49         setRepeats(0);
50         setCommittedCommand(eDVBSatelliteDiseqcParameters::AB);
51         setCommandOrder(0); // committed, toneburst
52         setFastDiSEqC(true);
53         setSeqRepeat(false);
54         addSatellite(130);
55         setVoltageMode(eDVBSatelliteSwitchParameters::HV);
56         setToneMode(eDVBSatelliteSwitchParameters::HILO);
57
58 // Rotor
59         addLNB();
60         setLNBTunerMask(3);
61         setLNBLOFL(9750000);
62         setLNBThreshold(11750000);
63         setLNBLOFH(10600000);
64         setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_2);
65         setToneburst(eDVBSatelliteDiseqcParameters::NO);
66         setRepeats(0);
67         setCommittedCommand(eDVBSatelliteDiseqcParameters::AA);
68         setCommandOrder(0); // committed, toneburst
69         setFastDiSEqC(true);
70         setSeqRepeat(false);
71         setLaDirection(eDVBSatelliteRotorParameters::NORTH);
72         setLoDirection(eDVBSatelliteRotorParameters::EAST);
73         setLatitude(51.017);
74         setLongitude(8.683);
75         setUseInputpower(true);
76         setInputpowerDelta(50);
77
78         addSatellite(235);
79         setVoltageMode(eDVBSatelliteSwitchParameters::HV);
80         setToneMode(eDVBSatelliteSwitchParameters::HILO);
81         setRotorPosNum(0);
82
83         addSatellite(284);
84         setVoltageMode(eDVBSatelliteSwitchParameters::HV);
85         setToneMode(eDVBSatelliteSwitchParameters::HILO);
86         setRotorPosNum(0);
87
88         addSatellite(420);
89         setVoltageMode(eDVBSatelliteSwitchParameters::HV);
90         setToneMode(eDVBSatelliteSwitchParameters::HILO);
91         setRotorPosNum(1); // stored pos 1
92 }
93
94 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int frontend_id )
95 {
96         int ret=0;
97
98         for (int idx=0; idx <= m_lnbidx; ++idx )
99         {
100                 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
101                 if ( lnb_param.tuner_mask & frontend_id ) // lnb for correct tuner?
102                 {
103                         eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
104
105                         std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
106                                 lnb_param.m_satellites.find(sat.orbital_position);
107                         if ( sit != lnb_param.m_satellites.end())
108                         {
109                                 int band=0,
110                                         linked_to=-1, // linked tuner
111                                         satpos_depends_to=-1,
112                                         csw = di_param.m_committed_cmd,
113                                         ucsw = di_param.m_uncommitted_cmd,
114                                         toneburst = di_param.m_toneburst_param,
115                                         curRotorPos;
116
117                                 fe->getData(6, curRotorPos);
118                                 fe->getData(7, linked_to);
119                                 fe->getData(8, satpos_depends_to);
120
121                                 if ( sat.frequency > lnb_param.m_lof_threshold )
122                                         band |= 1;
123                                 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
124                                         band |= 2;
125
126                                 bool rotor=false;
127                                 bool diseqc=false;
128
129                                 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
130                                 {
131                                         diseqc=true;
132                                         if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
133                                                 csw = 0xF0 | (csw << 2);
134
135                                         if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
136                                                 csw |= band;
137
138                                         if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )  // ROTOR
139                                         {
140                                                 rotor=true;
141                                                 if ( curRotorPos == sat.orbital_position )
142                                                         ret=20;  // rotor on correct orbpos = prio 20
143                                                 else
144                                                         ret=10;  // rotor must turn to correct orbpos = prio 10
145                                         }
146                                         else
147                                                 ret = 30;  // no rotor = prio 30
148                                 }
149                                 else
150                                 {
151                                         csw = band;
152                                         ret = 40;  // no diseqc = prio 40
153                                 }
154
155                                 if (linked_to != -1)  // check for linked tuners..
156                                 {
157                                         eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
158                                         if (linked_fe->m_inuse)
159                                         {
160                                                 int ocsw = -1,
161                                                         oucsw = -1,
162                                                         oToneburst = -1,
163                                                         oRotorPos = -1;
164                                                 linked_fe->m_frontend->getData(0, ocsw);
165                                                 linked_fe->m_frontend->getData(1, oucsw);
166                                                 linked_fe->m_frontend->getData(2, oToneburst);
167                                                 linked_fe->m_frontend->getData(6, oRotorPos);
168 #if 0
169                                                 eDebug("compare csw %02x == lcsw %02x",
170                                                         csw, ocsw);
171                                                 if ( diseqc )
172                                                         eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
173                                                                 ucsw, oucsw, toneburst, oToneburst);
174                                                 if ( rotor )
175                                                         eDebug("compare pos %d == current pos %d",
176                                                                 sat.orbital_position, oRotorPos);
177 #endif
178                                                 if ( (csw != ocsw) ||
179                                                         ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
180                                                         ( rotor && oRotorPos != sat.orbital_position ) )
181                                                 {
182 //                                                      eDebug("can not tune this transponder with linked tuner in use!!");
183                                                         ret=0;
184                                                 }
185 //                                              else
186 //                                                      eDebug("OK .. can tune this transponder with linked tuner in use :)");
187                                         }
188                                 }
189
190                                 if (satpos_depends_to != -1)  // check for linked tuners..
191                                 {
192                                         eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
193                                         if ( satpos_depends_to_fe->m_inuse )
194                                         {
195                                                 int oRotorPos = -1;
196                                                 satpos_depends_to_fe->m_frontend->getData(6, oRotorPos);
197                                                 if (!rotor || oRotorPos != sat.orbital_position)
198                                                 {
199 //                                                      eDebug("can not tune this transponder ... rotor on other tuner is positioned to %d", oRotorPos);
200                                                         ret=0;
201                                                 }
202                                         }
203 //                                      else
204 //                                              eDebug("OK .. can tune this transponder satpos is correct :)");
205                                 }
206                                 if (ret)
207                                 {
208                                         int lof = sat.frequency > lnb_param.m_lof_threshold ?
209                                                 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
210                                         int tuner_freq = abs(sat.frequency - lof);
211 //                                      eDebug("tuner freq %d", tuner_freq);
212                                         if (tuner_freq < 900000 || tuner_freq > 2200000)
213                                         {
214                                                 ret=0;
215 //                                              eDebug("Transponder not tuneable with this lnb... %d Khz out of tuner range",
216 //                                                      tuner_freq);
217                                         }
218                                 }
219                         }
220                 }
221         }
222         return ret;
223 }
224
225 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
226
227 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)
228 {
229         bool linked=false;
230         bool depend_satpos_mode=false;
231
232         for (int idx=0; idx <= m_lnbidx; ++idx )
233         {
234                 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
235                 if (!(lnb_param.tuner_mask & frontend_id)) // lnb for correct tuner?
236                         continue;
237                 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
238                 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
239
240                 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
241                         lnb_param.m_satellites.find(sat.orbital_position);
242                 if ( sit != lnb_param.m_satellites.end())
243                 {
244                         eDVBSatelliteSwitchParameters &sw_param = sit->second;
245                         bool doSetVoltageToneFrontend = true;
246                         bool doSetFrontend = true;
247                         int band=0,
248                                 linked_to=-1, // linked tuner
249                                 satpos_depends_to=-1,
250                                 voltage = iDVBFrontend::voltageOff,
251                                 tone = iDVBFrontend::toneOff,
252                                 csw = di_param.m_committed_cmd,
253                                 ucsw = di_param.m_uncommitted_cmd,
254                                 toneburst = di_param.m_toneburst_param,
255                                 lastcsw = -1,
256                                 lastucsw = -1,
257                                 lastToneburst = -1,
258                                 lastRotorCmd = -1,
259                                 curRotorPos = -1;
260
261                         frontend.getData(0, lastcsw);
262                         frontend.getData(1, lastucsw);
263                         frontend.getData(2, lastToneburst);
264                         frontend.getData(5, lastRotorCmd);
265                         frontend.getData(6, curRotorPos);
266                         frontend.getData(7, linked_to);
267                         frontend.getData(8, satpos_depends_to);
268
269                         if (linked_to != -1)
270                         {
271                                 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
272                                 if (linked_fe->m_inuse)
273                                 {
274                                         eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
275                                         linked=true;
276                                 }
277                         }
278
279                         if (satpos_depends_to != -1)
280                         {
281                                 eDVBRegisteredFrontend *satpos_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
282                                 if (satpos_fe->m_inuse)
283                                 {
284                                         if ( di_param.m_diseqc_mode != eDVBSatelliteDiseqcParameters::V1_2 )
285                                                 continue;
286                                         eDebug("[SEC] frontend is depending on satpos of other one.. so we dont turn rotor!!");
287                                         depend_satpos_mode=true;
288                                 }
289                         }
290
291                         if ( sat.frequency > lnb_param.m_lof_threshold )
292                                 band |= 1;
293
294                         if (band&1)
295                                 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
296                         else
297                                 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
298
299                         parm.FREQUENCY = abs(parm.FREQUENCY);
300
301                         frontend.setData(9, sat.frequency - parm.FREQUENCY);
302
303                         if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
304                                 band |= 2;
305
306                         if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
307                                 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
308                                         && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV )  )
309                                 voltage = VOLTAGE(13);
310                         else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
311                                 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
312                                         && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV )  )
313                                 voltage = VOLTAGE(18);
314                         if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
315                                 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
316                                 tone = iDVBFrontend::toneOn;
317                         else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
318                                 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
319                                 tone = iDVBFrontend::toneOff;
320
321                         eSecCommandList sec_sequence;
322
323                         if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
324                         {
325                                 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
326                                         csw = 0xF0 | (csw << 2);
327
328                                 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
329                                         csw |= band;
330
331                                 bool send_csw =
332                                         (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
333                                 bool changed_csw = send_csw && csw != lastcsw;
334
335                                 bool send_ucsw =
336                                         (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
337                                 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
338
339                                 bool send_burst =
340                                         (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
341                                 bool changed_burst = send_burst && toneburst != lastToneburst;
342
343                                 int send_mask = 0; /*
344                                         1 must send csw
345                                         2 must send ucsw
346                                         4 send toneburst first
347                                         8 send toneburst at end */
348                                 if (changed_burst) // toneburst first and toneburst changed
349                                 {
350                                         if (di_param.m_command_order&1)
351                                         {
352                                                 send_mask |= 4;
353                                                 if ( send_csw )
354                                                         send_mask |= 1;
355                                                 if ( send_ucsw )
356                                                         send_mask |= 2;
357                                         }
358                                         else
359                                                 send_mask |= 8;
360                                 }
361                                 if (changed_ucsw)
362                                 {
363                                         send_mask |= 2;
364                                         if ((di_param.m_command_order&4) && send_csw)
365                                                 send_mask |= 1;
366                                         if (di_param.m_command_order==4 && send_burst)
367                                                 send_mask |= 8;
368                                 }
369                                 if (changed_csw) 
370                                 {
371                                         if ( di_param.m_use_fast
372                                                 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
373                                                 && (lastcsw & 0xF0)
374                                                 && ((csw / 4) == (lastcsw / 4)) )
375                                                 eDebug("dont send committed cmd (fast diseqc)");
376                                         else
377                                         {
378                                                 send_mask |= 1;
379                                                 if (!(di_param.m_command_order&4) && send_ucsw)
380                                                         send_mask |= 2;
381                                                 if (!(di_param.m_command_order&1) && send_burst)
382                                                         send_mask |= 8;
383                                         }
384                                 }
385
386 #if 0
387                                 eDebugNoNewLine("sendmask: ");
388                                 for (int i=3; i >= 0; --i)
389                                         if ( send_mask & (1<<i) )
390                                                 eDebugNoNewLine("1");
391                                         else
392                                                 eDebugNoNewLine("0");
393                                 eDebug("");
394 #endif
395
396                                 int RotorCmd=-1;
397                                 bool useGotoXX = false;
398                                 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
399                                 {
400                                         if (depend_satpos_mode || linked)
401                                                 // in this both modes we dont really turn the rotor.... but in canTune we need the satpos
402                                                 frontend.setData(6, sat.orbital_position);
403                                         else
404                                         {
405                                                 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
406                                                         RotorCmd=sw_param.m_rotorPosNum;
407                                                 else  // we must calc gotoxx cmd
408                                                 {
409                                                         eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
410                                                         useGotoXX = true;
411
412                                                         double  SatLon = abs(sat.orbital_position)/10.00,
413                                                                         SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
414                                                                         SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
415
416                                                         if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
417                                                                 SiteLat = -SiteLat;
418
419                                                         if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
420                                                                 SiteLon = 360 - SiteLon;
421
422                                                         eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
423                                                         double satHourAngle =
424                                                                 calcSatHourangle( SatLon, SiteLat, SiteLon );
425                                                         eDebug("PolarmountHourAngle=%lf", satHourAngle );
426
427                                                         static int gotoXTable[10] =
428                                                                 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
429
430                                                         if (SiteLat >= 0) // Northern Hemisphere
431                                                         {
432                                                                 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
433                                                                 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
434
435                                                                 if (satHourAngle < 180) // the east
436                                                                         RotorCmd |= 0xE000;
437                                                                 else                                    // west
438                                                                         RotorCmd |= 0xD000;
439                                                         }
440                                                         else // Southern Hemisphere
441                                                         {
442                                                                 if (satHourAngle < 180) // the east
443                                                                 {
444                                                                         int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
445                                                                         RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
446                                                                         RotorCmd |= 0xD000;
447                                                                 }
448                                                                 else                                    // west
449                                                                 {
450                                                                         int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
451                                                                         RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
452                                                                         RotorCmd |= 0xE000;
453                                                                 }
454                                                         }
455                                                         eDebug("RotorCmd = %04x", RotorCmd);
456                                                 }
457                                         }
458                                 }
459
460                                 if ( send_mask )
461                                 {
462                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
463                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
464                                         eSecCommand::pair compare;
465                                         compare.voltage = iDVBFrontend::voltageOff;
466                                         compare.steps = +4;
467                                         // the next is a check if voltage is switched off.. then we first set a voltage :)
468                                         // else we set voltage after all diseqc stuff..
469                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
470
471                                         if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
472                                         {
473                                                 if (rotor_param.m_inputpower_parameters.m_use)
474                                                         compare.voltage = VOLTAGE(18);  // in input power mode turn rotor always with 18V (fast)
475                                                 else
476                                                         compare.voltage = VOLTAGE(13);  // in normal mode start turning with 13V
477                                         }
478                                         else
479                                                 compare.voltage = voltage;
480
481                                         // voltage already correct ?
482                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
483                                         compare.steps = +3;
484                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
485                                         // voltage was disabled..so we wait a longer time .. for normal switches 200ms should be enough
486                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );
487
488                                         for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
489                                         {
490                                                 if ( send_mask & 4 )
491                                                 {
492                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
493                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
494                                                 }
495
496                                                 int loops=0;
497
498                                                 if ( send_mask & 1 )
499                                                         ++loops;
500                                                 if ( send_mask & 2 )
501                                                         ++loops;
502
503                                                 for ( int i=0; i < di_param.m_repeats; ++i )
504                                                 loops *= 2;
505
506                                                 for ( int i = 0; i < loops;)  // fill commands...
507                                                 {
508                                                         eDVBDiseqcCommand diseqc;
509                                                         diseqc.len = 4;
510                                                         diseqc.data[0] = i ? 0xE1 : 0xE0;
511                                                         diseqc.data[1] = 0x10;
512                                                         if ( (send_mask & 2) && (di_param.m_command_order & 4) )
513                                                         {
514                                                                 diseqc.data[2] = 0x39;
515                                                                 diseqc.data[3] = ucsw;
516                                                         }
517                                                         else if ( send_mask & 1 )
518                                                         {
519                                                                 diseqc.data[2] = 0x38;
520                                                                 diseqc.data[3] = csw;
521                                                         }
522                                                         else
523                                                         {
524                                                                 diseqc.data[2] = 0x00;
525                                                                 diseqc.data[3] = 0x00;
526                                                         }
527                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
528
529                                                         i++;
530                                                         if ( i < loops )
531                                                         {
532                                                                 int cmd=0;
533                                                                 if (diseqc.data[2] == 0x38 && (send_mask & 2))
534                                                                         cmd=0x39;
535                                                                 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
536                                                                         cmd=0x38;
537                                                                 if (cmd)
538                                                                 {
539                                                                         static int delay = (120 - 54) / 2;  // standard says 100msek between two repeated commands
540                                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
541                                                                         diseqc.data[2]=cmd;
542                                                                         diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
543                                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
544                                                                         ++i;
545                                                                         if ( i < loops )
546                                                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
547                                                                         else
548                                                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
549                                                                 }
550                                                                 else  // delay 120msek when no command is in repeat gap
551                                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
552                                                         }
553                                                         else
554                                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
555                                                 }
556
557                                                 if ( send_mask & 8 )  // toneburst at end of sequence
558                                                 {
559                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
560                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
561                                                 }
562                                         }
563                                 }
564
565                                 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
566                                 {
567                                         eSecCommand::pair compare;
568                                         compare.voltage = iDVBFrontend::voltageOff;
569                                         compare.steps = +4;
570                                         // the next is a check if voltage is switched off.. then we first set a voltage :)
571                                         // else we set voltage after all diseqc stuff..
572                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
573
574                                         if (rotor_param.m_inputpower_parameters.m_use)
575                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
576                                         else
577                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
578
579                                         // voltage was disabled..so we wait a longer time ..
580                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
581                                         sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +7) );  // no need to send stop rotor cmd
582
583                                         if (send_mask)
584                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
585                                         else
586                                                 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +1) );
587
588                                         eDVBDiseqcCommand diseqc;
589                                         diseqc.len = 3;
590                                         diseqc.data[0] = 0xE0;
591                                         diseqc.data[1] = 0x31;  // positioner
592                                         diseqc.data[2] = 0x60;  // stop
593                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
594                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
595                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
596                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
597                                         // wait 300msec after send rotor stop cmd
598                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
599
600                                         diseqc.data[0] = 0xE0;
601                                         diseqc.data[1] = 0x31;          // positioner
602                                         if ( useGotoXX )
603                                         {
604                                                 diseqc.len = 5;
605                                                 diseqc.data[2] = 0x6E;  // drive to angular position
606                                                 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
607                                                 diseqc.data[4] = RotorCmd & 0xFF;
608                                         }
609                                         else
610                                         {
611                                                 diseqc.len = 4;
612                                                 diseqc.data[2] = 0x6B;  // goto stored sat position
613                                                 diseqc.data[3] = RotorCmd;
614                                                 diseqc.data[4] = 0x00;
615                                         }
616
617                                         if ( rotor_param.m_inputpower_parameters.m_use )
618                                         { // use measure rotor input power to detect rotor state
619                                                 eSecCommand::rotor cmd;
620                                                 eSecCommand::pair compare;
621                                                 compare.voltage = VOLTAGE(18);
622                                                 compare.steps = +2;
623                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
624                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
625 // measure idle power values
626                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );  // wait 200msec after voltage change
627                                                 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
628                                                 compare.voltage = 1;
629                                                 compare.steps = -2;
630                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
631                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
632                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );  // wait 200msec before measure
633                                                 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
634                                                 compare.voltage = 0;
635                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
636 ////////////////////////////
637                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
638                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) );  // 2 retries
639                                                 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
640                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
641                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) );  // 2 seconds rotor start timout
642 // rotor start loop
643                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // 50msec delay
644                                                 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
645                                                 cmd.direction=1;  // check for running rotor
646                                                 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
647                                                 cmd.steps=+5;
648                                                 cmd.okcount=0;
649                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );  // check if rotor has started
650                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) );  // timeout .. we assume now the rotor is already at the correct position
651                                                 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );  // goto loop start
652                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO, +9 ) );  // timeout .. we assume now the rotor is already at the correct position
653                                                 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) );  // goto loop start
654 ////////////////////
655                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) );  // 2 minutes running timeout
656                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
657 // rotor running loop
658                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec
659                                                 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
660                                                 cmd.direction=0;  // check for stopped rotor
661                                                 cmd.steps=+3;
662                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
663                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );  // timeout ? this should never happen
664                                                 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );  // running loop start
665 /////////////////////
666                                         }
667                                         else
668                                         {  // use normal turning mode
669                                                 doSetVoltageToneFrontend=false;
670                                                 doSetFrontend=false;
671                                                 eSecCommand::rotor cmd;
672                                                 eSecCommand::pair compare;
673                                                 compare.voltage = VOLTAGE(13);
674                                                 compare.steps = +2;
675                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
676                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
677                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );  // wait 200msec after voltage change
678
679                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
680                                                 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
681                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
682
683                                                 compare.voltage = voltage;
684                                                 compare.steps = +3;
685                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
686                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) );  // wait 2 second before set high voltage
687                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
688
689                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
690                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
691
692                                                 cmd.direction=1;  // check for running rotor
693                                                 cmd.deltaA=0;
694                                                 cmd.steps=+3;
695                                                 cmd.okcount=0;
696
697                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 480) );  // 2 minutes running timeout
698                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );  // 250msec delay
699                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
700                                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); 
701                                                 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) );  // goto loop start
702                                         }
703                                         sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
704                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
705                                         frontend.setData(3, RotorCmd);
706                                         frontend.setData(4, sat.orbital_position);
707                                 }
708                         }
709                         else
710                                 csw = band;
711
712                         frontend.setData(0, csw);
713                         frontend.setData(1, ucsw);
714                         frontend.setData(2, di_param.m_toneburst_param);
715
716                         if (!linked && doSetVoltageToneFrontend)
717                         {
718                                 eSecCommand::pair compare;
719                                 compare.voltage = voltage;
720                                 compare.steps = +3;
721                                 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
722                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
723                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
724
725                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
726                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
727                         }
728
729                         if (doSetFrontend)
730                         {
731                                 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
732                                 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
733                         }
734                         frontend.setSecSequence(sec_sequence);
735
736                         return 0;
737                 }
738         }
739
740         eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
741         return -1;
742 }
743
744 RESULT eDVBSatelliteEquipmentControl::clear()
745 {
746         for (int i=0; i <= m_lnbidx; ++i)
747         {
748                 m_lnbs[i].m_satellites.clear();
749                 m_lnbs[i].tuner_mask = 0;
750         }
751         m_lnbidx=-1;
752
753 // clear linked tuner configuration
754         for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
755                 it->m_frontend->setData(7, -1);
756
757         return 0;
758 }
759
760 // helper function for setTunerLinked and setTunerDepends
761 RESULT eDVBSatelliteEquipmentControl::setDependencyPointers( int tu1, int tu2, int dest_data_byte )
762 {
763         if (tu1 == tu2)
764                 return -1;
765
766         eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
767
768         int cnt=0;
769         for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
770         {
771                 if (cnt == tu1)
772                         p1 = *it;
773                 else if (cnt == tu2)
774                         p2 = *it;
775         }
776         if (p1 && p2)
777         {
778                 p1->m_frontend->setData(dest_data_byte, (int)p2);  // this is evil..
779                 p2->m_frontend->setData(dest_data_byte, (int)p1);
780                 return 0;
781         }
782         return -1;
783 }
784
785 /* LNB Specific Parameters */
786 RESULT eDVBSatelliteEquipmentControl::addLNB()
787 {
788         if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
789                 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
790         else
791         {
792                 eDebug("no more LNB free... cnt is %d", m_lnbidx);
793                 return -ENOSPC;
794         }
795         return 0;
796 }
797
798 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
799 {
800         if ( currentLNBValid() )
801                 m_lnbs[m_lnbidx].tuner_mask = tunermask;
802         else
803                 return -ENOENT;
804         return 0;
805 }
806
807 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
808 {
809         if ( currentLNBValid() )
810                 m_lnbs[m_lnbidx].m_lof_lo = lofl;
811         else
812                 return -ENOENT;
813         return 0;
814 }
815
816 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
817 {
818         if ( currentLNBValid() )
819                 m_lnbs[m_lnbidx].m_lof_hi = lofh;
820         else
821                 return -ENOENT;
822         return 0;
823 }
824
825 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
826 {
827         if ( currentLNBValid() )
828                 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
829         else
830                 return -ENOENT;
831         return 0;
832 }
833
834 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
835 {
836         if ( currentLNBValid() )
837                 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
838         else
839                 return -ENOENT;
840         return 0;
841 }
842
843 /* DiSEqC Specific Parameters */
844 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
845 {
846         if ( currentLNBValid() )
847                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
848         else
849                 return -ENOENT;
850         return 0;
851 }
852
853 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
854 {
855         if ( currentLNBValid() )
856                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
857         else
858                 return -ENOENT;
859         return 0;
860 }
861
862 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
863 {
864         if ( currentLNBValid() )
865                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
866         else
867                 return -ENOENT;
868         return 0;
869 }
870
871 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
872 {
873         if ( currentLNBValid() )
874                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
875         else
876                 return -ENOENT;
877         return 0;
878 }
879
880 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
881 {
882         if ( currentLNBValid() )
883                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
884         else
885                 return -ENOENT;
886         return 0;
887 }
888
889 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
890 {
891         if ( currentLNBValid() )
892                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
893         else
894                 return -ENOENT;
895         return 0;
896 }
897
898 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
899 {
900         if ( currentLNBValid() )
901                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
902         else
903                 return -ENOENT;
904         return 0;
905 }
906
907 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
908 {
909         if ( currentLNBValid() )
910                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
911         else
912                 return -ENOENT;
913         return 0;
914 }
915
916 /* Rotor Specific Parameters */
917 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
918 {
919         if ( currentLNBValid() )
920                 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
921         else
922                 return -ENOENT;
923         return 0;
924 }
925
926 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
927 {
928         if ( currentLNBValid() )
929                 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
930         else
931                 return -ENOENT;
932         return 0;
933 }
934
935 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
936 {
937         if ( currentLNBValid() )
938                 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
939         else
940                 return -ENOENT;
941         return 0;
942 }
943
944 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
945 {
946         if ( currentLNBValid() )
947                 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
948         else
949                 return -ENOENT;
950         return 0;
951 }
952
953 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
954 {
955         if ( currentLNBValid() )
956                 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
957         else
958                 return -ENOENT;
959         return 0;
960 }
961
962 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
963 {
964         if ( currentLNBValid() )
965                 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
966         else
967                 return -ENOENT;
968         return 0;
969 }
970
971 /* Satellite Specific Parameters */
972 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
973 {
974         if ( currentLNBValid() )
975         {
976                 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
977                         m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
978                 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
979                 {
980                         std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
981                                 m_lnbs[m_lnbidx].m_satellites.insert(
982                                         std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
983                                 );
984                         if ( ret.second )
985                                 m_curSat = ret.first;
986                         else
987                                 return -ENOMEM;
988                 }
989                 else
990                         return -EEXIST;
991         }
992         else
993                 return -ENOENT;
994         return 0;
995 }
996
997 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
998 {
999         if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1000                 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1001         else
1002                 return -ENOENT;
1003         return 0;
1004
1005 }
1006
1007 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1008 {
1009         if ( currentLNBValid() )
1010         {
1011                 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1012                         m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1013                 else
1014                         return -EPERM;
1015         }
1016         else
1017                 return -ENOENT;
1018         return 0;
1019 }
1020
1021 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1022 {
1023         if ( currentLNBValid() )
1024         {
1025                 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1026                         m_curSat->second.m_rotorPosNum=rotor_pos_num;
1027                 else
1028                         return -EPERM;
1029         }
1030         else
1031                 return -ENOENT;
1032         return 0;
1033 }
1034
1035 PyObject *eDVBSatelliteEquipmentControl::get_different_satellites(int tu1, int tu2)
1036 {
1037         PyObject *ret=0;
1038         if (tu1 != tu2)
1039         {
1040                 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1041                 int cnt=0;
1042                 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1043                 {
1044                         if (cnt == tu1)
1045                                 p1 = *it;
1046                         else if (cnt == tu2)
1047                                 p2 = *it;
1048                 }
1049                 if (p1 && p2)
1050                 {
1051                         // check for linked tuners
1052                         int tmp1, tmp2;
1053                         p1->m_frontend->getData(7, tmp1);
1054                         p2->m_frontend->getData(7, tmp2);
1055                         if ((void*)tmp1 != p2 && (void*)tmp2 != p1)
1056                         {
1057                                 // check for rotor dependency
1058                                 p1->m_frontend->getData(8, tmp1);
1059                                 p2->m_frontend->getData(8, tmp2);
1060                                 if ((void*)tmp1 != p2 && (void*)tmp2 != p1)
1061                                 {
1062                                         // here we know the tuners are not linked and no rotor dependency exist.
1063                                         // now we check all configured satellites/lnb for difference and at all difference
1064                                         // to a list of tuples with first value tuner number and second value orbital position
1065                                         // of satellite
1066                                         ret = PyList_New(0);
1067                                         // FIXMEE !! fill list (compare satellites (lofh, lofl, lof threshold, opos))
1068                                 }
1069                         }
1070                 }
1071         }
1072         if (!ret)
1073         {
1074                 Py_INCREF(Py_None);
1075                 ret = Py_None;
1076         }
1077         return ret;
1078 }
1079
1080 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1081 {
1082         return setDependencyPointers(tu1, tu2, 7);
1083 }
1084
1085 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1086 {
1087         return setDependencyPointers(tu1, tu2, 8);
1088 }
1089
1090 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1091 {
1092         return m_rotorMoving;
1093 }
1094
1095 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)
1096 {
1097         m_rotorMoving=b;
1098 }