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