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