use boundFunction from tools
[enigma2.git] / lib / dvb / sec.cpp
1 #include <config.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()
23         :m_lnbidx(-1), m_curSat(m_lnbs[0].m_satellites.end())
24 {
25         if (!instance)
26                 instance = this;
27
28         clear();
29
30 // ASTRA
31         addLNB();
32         setLNBTunerMask(1);
33         setLNBLOFL(9750000);
34         setLNBThreshold(11750000);
35         setLNBLOFH(10600000);
36         setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
37         setToneburst(eDVBSatelliteDiseqcParameters::NO);
38         setRepeats(0);
39         setCommittedCommand(eDVBSatelliteDiseqcParameters::AA);
40         setCommandOrder(0); // committed, toneburst
41         setFastDiSEqC(false);
42         setSeqRepeat(false);
43         addSatellite(192);
44         setVoltageMode(eDVBSatelliteSwitchParameters::HV);
45         setToneMode(eDVBSatelliteSwitchParameters::HILO);
46
47 // HOTBIRD
48         addLNB();
49         setLNBTunerMask(1);
50         setLNBLOFL(9750000);
51         setLNBLOFH(10600000);
52         setLNBThreshold(11750000);
53         setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
54         setToneburst(eDVBSatelliteDiseqcParameters::NO);
55         setRepeats(0);
56         setCommittedCommand(eDVBSatelliteDiseqcParameters::AB);
57         setCommandOrder(0); // committed, toneburst
58         setFastDiSEqC(false);
59         setSeqRepeat(false);
60         addSatellite(130);
61         setVoltageMode(eDVBSatelliteSwitchParameters::HV);
62         setToneMode(eDVBSatelliteSwitchParameters::HILO);
63 }
64
65 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int frontend_id )
66 {
67         int ret=0;
68
69         for (int idx=0; idx <= m_lnbidx; ++idx )
70         {
71                 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
72                 if ( lnb_param.tuner_mask & frontend_id ) // lnb for correct tuner?
73                 {
74                         eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
75                         eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
76
77                         std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
78                                 lnb_param.m_satellites.find(sat.orbital_position);
79                         if ( sit != lnb_param.m_satellites.end())
80                         {
81                                 int curRotorPos = -1;
82                                 fe->getData(6, curRotorPos);
83
84                                 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )  // ROTOR
85                                 {
86                                         if ( curRotorPos == sat.orbital_position )
87                                                 ret=20;
88                                         else
89                                                 ret=10;
90                                 }
91                                 else if (!ret)
92                                         ret=40;
93                         }
94                 }
95         }
96         return ret;
97 }
98
99 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat, int frontend_id)
100 {
101         for (int idx=0; idx <= m_lnbidx; ++idx )
102         {
103                 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
104                 if (!(lnb_param.tuner_mask & frontend_id)) // lnb for correct tuner?
105                         continue;
106                 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
107                 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
108
109                 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
110                         lnb_param.m_satellites.find(sat.orbital_position);
111                 if ( sit != lnb_param.m_satellites.end())
112                 {
113                         eDVBSatelliteSwitchParameters &sw_param = sit->second;
114
115                         int hi=0,
116                                 voltage = iDVBFrontend::voltageOff,
117                                 tone = iDVBFrontend::toneOff,
118                                 csw = di_param.m_committed_cmd,
119                                 ucsw = di_param.m_uncommitted_cmd,
120                                 toneburst = di_param.m_toneburst_param,
121                                 lastcsw = -1,
122                                 lastucsw = -1,
123                                 lastToneburst = -1,
124                                 lastRotorCmd = -1,
125                                 curRotorPos = -1;
126
127                         frontend.getData(0, lastcsw);
128                         frontend.getData(1, lastucsw);
129                         frontend.getData(2, lastToneburst);
130                         frontend.getData(5, lastRotorCmd);
131                         frontend.getData(6, curRotorPos);
132
133                         if ( sat.frequency > lnb_param.m_lof_threshold )
134                                 hi = 1;
135
136                         if (hi)
137                                 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
138                         else
139                                 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
140
141                         parm.INVERSION = (!sat.inversion) ? INVERSION_ON : INVERSION_OFF;
142
143                         switch (sat.fec)
144                         {
145                                 default:
146                                 case eDVBFrontendParametersSatellite::FEC::fNone:
147                                         eDebug("no fec set.. assume auto");
148                                 case eDVBFrontendParametersSatellite::FEC::fAuto:
149                                         parm.u.qpsk.FEC_INNER = FEC_AUTO;
150                                         break;
151                                 case eDVBFrontendParametersSatellite::FEC::f1_2:
152                                         parm.u.qpsk.FEC_INNER = FEC_1_2;
153                                         break;
154                                 case eDVBFrontendParametersSatellite::FEC::f2_3:
155                                         parm.u.qpsk.FEC_INNER = FEC_2_3;
156                                         break;
157                                 case eDVBFrontendParametersSatellite::FEC::f3_4:
158                                         parm.u.qpsk.FEC_INNER = FEC_3_4;
159                                         break;
160                                 case eDVBFrontendParametersSatellite::FEC::f5_6:
161                                         parm.u.qpsk.FEC_INNER = FEC_5_6;
162                                         break;
163                                 case eDVBFrontendParametersSatellite::FEC::f7_8: 
164                                         parm.u.qpsk.FEC_INNER = FEC_7_8;
165                                         break;
166                         }
167
168                         parm.u.qpsk.SYMBOLRATE = sat.symbol_rate;
169
170                         if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
171                                 || ( sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Vertical
172                                         && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV )  )
173                                 voltage = iDVBFrontend::voltage13;
174                         else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
175                                 || ( sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal
176                                         && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV )  )
177                                 voltage = iDVBFrontend::voltage18;
178
179                         if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
180                                 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && hi ) )
181                                 tone = iDVBFrontend::toneOn;
182                         else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
183                                 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !hi ) )
184                                 tone = iDVBFrontend::toneOff;
185
186                         eSecCommandList sec_sequence;
187
188                         if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
189                         {
190                                 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
191                                 {
192                                         csw = 0xF0 | (csw << 2);
193                                         if (hi)
194                                                 csw |= 1;
195                                         if (sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal)
196                                                 csw |= 2;
197                                 }
198
199                                 bool send_csw =
200                                         (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
201                                 bool changed_csw = send_csw && csw != lastcsw;
202
203                                 bool send_ucsw =
204                                         (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
205                                 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
206
207                                 bool send_burst =
208                                         (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
209                                 bool changed_burst = send_burst && toneburst != lastToneburst;
210
211                                 bool send_diseqc = changed_ucsw;
212                                 if (!send_diseqc)
213                                         send_diseqc = changed_burst && (send_ucsw || send_csw);
214                                 if (!send_diseqc)
215                                 {
216                                         send_diseqc = changed_csw;
217                                         if ( send_diseqc && di_param.m_use_fast && (csw & 0xF0) && (lastcsw & 0xF0) && ((csw / 4) == (lastcsw / 4)) )
218                                                 send_diseqc = false;
219                                 }
220
221                                 if ( send_diseqc || changed_burst )
222                                 {
223                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
224                                         eSecCommand::pair compare;
225                                         compare.voltage = voltage;
226                                         compare.steps = +3;
227                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
228                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
229                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
230                                 }
231
232                                 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
233                                 {
234                                         if ( di_param.m_command_order & 1 && // toneburst at begin of sequence
235                                                 changed_burst && di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO )
236                                         {
237                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
238                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
239                                                 frontend.setData(2, di_param.m_toneburst_param);
240                                         }
241
242                                         if ( send_diseqc )
243                                         {
244                                                 int loops=0;
245
246                                                 if ( send_csw )
247                                                         ++loops;
248                                                 if ( send_ucsw )
249                                                         ++loops;
250
251                                                 for ( int i=0; i < di_param.m_repeats; ++i )
252                                                         loops *= 2;
253
254                                                 for ( int i = 0; i < loops;)  // fill commands...
255                                                 {
256                                                         eDVBDiseqcCommand diseqc;
257                                                         diseqc.len = 4;
258                                                         diseqc.data[0] = i ? 0xE1 : 0xE0;
259                                                         diseqc.data[1] = 0x10;
260
261                                                         if ( !send_csw || (send_ucsw && (di_param.m_command_order & 4) ) )
262                                                         {
263                                                                 diseqc.data[2] = 0x39;
264                                                                 diseqc.data[3] = ucsw;
265                                                         }
266                                                         else
267                                                         {
268                                                                 diseqc.data[2] = 0x38;
269                                                                 diseqc.data[3] = csw;
270                                                         }
271                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
272
273                                                         i++;
274                                                         if ( i < loops )
275                                                         {
276                                                                 int cmd=0;
277                                                                 if (diseqc.data[2] == 0x38 && send_ucsw)
278                                                                         cmd=0x39;
279                                                                 else if (diseqc.data[2] == 0x39 && send_csw)
280                                                                         cmd=0x38;
281                                                                 if (cmd)
282                                                                 {
283                                                                         static int delay = (120 - 54) / 2;  // standard says 100msek between two repeated commands
284                                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
285                                                                         diseqc.data[2]=cmd;
286                                                                         diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
287                                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
288                                                                         ++i;
289                                                                         if ( i < loops )
290                                                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
291                                                                         else
292                                                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
293                                                                 }
294                                                                 else  // delay 120msek when no command is in repeat gap
295                                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
296                                                         }
297                                                         else
298                                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
299
300                                                         frontend.setData(0, csw);
301                                                         frontend.setData(1, ucsw);
302                                                 }
303                                         }
304
305                                         if ( !(di_param.m_command_order & 1) && // toneburst at end of sequence
306                                                 (changed_burst || send_diseqc) && di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO )
307                                         {
308                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
309                                                 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
310                                                 frontend.setData(2, di_param.m_toneburst_param);
311                                         }
312                                 }
313
314                                 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
315                                 {
316                                         int RotorCmd=0;
317                                         bool useGotoXX = false;
318
319                                         if (sw_param.m_rotorPosNum) // we have stored rotor pos?
320                                                 RotorCmd=sw_param.m_rotorPosNum;
321                                         else  // we must calc gotoxx cmd
322                                         {
323                                                 eDebug("Entry for %d,%d┬░ not in Rotor Table found... i try gotoXX┬░", sat.orbital_position / 10, sat.orbital_position % 10 );
324                                                 useGotoXX = true;
325
326                                                 int satDir = sat.orbital_position < 0 ?
327                                                         eDVBSatelliteRotorParameters::WEST :
328                                                         eDVBSatelliteRotorParameters::EAST;
329
330                                                 double  SatLon = abs(sat.orbital_position)/10.00,
331                                                                 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
332                                                                 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
333
334                                                 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
335                                                         SiteLat = -SiteLat;
336
337                                                 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
338                                                         SiteLon = 360 - SiteLon;
339
340                                                 if (satDir == eDVBSatelliteRotorParameters::WEST )
341                                                         SatLon = 360 - SatLon;
342
343                                                 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
344                                                 double satHourAngle =
345                                                         calcSatHourangle( SatLon, SiteLat, SiteLon );
346                                                 eDebug("PolarmountHourAngle=%lf", satHourAngle );
347
348                                                 static int gotoXTable[10] =
349                                                         { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
350
351                                                 if (SiteLat >= 0) // Northern Hemisphere
352                                                 {
353                                                         int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
354                                                         RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
355
356                                                         if (satHourAngle < 180) // the east
357                                                                 RotorCmd |= 0xE000;
358                                                         else                                    // west
359                                                                 RotorCmd |= 0xD000;
360                                                 }
361                                                 else // Southern Hemisphere
362                                                 {
363                                                         if (satHourAngle < 180) // the east
364                                                         {
365                                                                 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
366                                                                 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
367                                                                 RotorCmd |= 0xD000;
368                                                         }
369                                                         else                                    // west
370                                                         {          
371                                                                 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
372                                                                 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
373                                                                 RotorCmd |= 0xE000;
374                                                         }
375                                                 }
376                                                 eDebug("RotorCmd = %04x", RotorCmd);
377                                         }
378                                         if ( RotorCmd != lastRotorCmd )
379                                         {
380                                                 if ( changed_burst || send_diseqc )
381                                                 {
382                                                         // override first voltage change
383                                                         *(++(++sec_sequence.begin()))=eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13);
384                                                         // wait 1 second after first switch diseqc command
385                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) );
386                                                 }
387                                                 else  // no other diseqc commands before
388                                                 {
389                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
390                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );  // wait 15msec after tone change
391                                                         eSecCommand::pair compare;
392                                                         compare.voltage = voltage;
393                                                         compare.steps = +3;
394                                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
395                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
396                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec after voltage change
397                                                 }
398
399                                                 eDVBDiseqcCommand diseqc;
400                                                 diseqc.data[0] = 0xE0;
401                                                 diseqc.data[1] = 0x31;          // positioner
402                                                 if ( useGotoXX )
403                                                 {
404                                                         diseqc.len = 5;
405                                                         diseqc.data[2] = 0x6E;  // drive to angular position
406                                                         diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
407                                                         diseqc.data[4] = RotorCmd & 0xFF;
408                                                 }
409                                                 else
410                                                 {
411                                                         diseqc.len = 4;
412                                                         diseqc.data[2] = 0x6B;  // goto stored sat position
413                                                         diseqc.data[3] = RotorCmd;
414                                                 }
415
416                                                 if ( rotor_param.m_inputpower_parameters.m_use )
417                                                 { // use measure rotor input power to detect rotor state
418                                                         eSecCommand::rotor cmd;
419 // measure idle power values
420                                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_IDLE_INPUTPOWER_AVAIL_GOTO, +8) ); // already measured?
421                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec after voltage change
422                                                         sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
423                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18) );
424                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 100) );  // wait 100msec before measure
425                                                         sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
426                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) ); // back to lower voltage
427                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec
428 ////////////////////////////
429                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
430                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec after voltage change
431                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
432                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) );  // 2 seconds rotor start timout
433 // rotor start loop
434                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // 50msec delay
435                                                         sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
436                                                         cmd.direction=1;  // check for running rotor
437                                                         cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
438                                                         cmd.steps=+3;
439                                                         cmd.okcount=0;
440                                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );  // check if rotor has started
441                                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +10 ) );  // timeout .. we assume now the rotor is already at the correct position
442                                                         sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );  // goto loop start
443 ////////////////////
444                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) );  // 2 minutes running timeout
445                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18) );
446                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
447 // rotor running loop
448                                                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec
449                                                         sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
450                                                         cmd.direction=0;  // check for stopped rotor
451                                                         cmd.steps=+3;
452                                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
453                                                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );  // timeout ? this should never happen
454                                                         sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );  // running loop start
455 /////////////////////
456                                                         sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
457                                                         frontend.setData(3, RotorCmd);
458                                                         frontend.setData(4, sat.orbital_position);
459                                                 }
460                                                 else
461                                                         eFatal("rotor turning without inputpowermeasure not implemented yet");
462                                         }
463                                 }
464                         }
465
466                         eSecCommand::pair compare;
467                         compare.voltage = voltage;
468                         compare.steps = +3;
469                         sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
470                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
471                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
472
473                         sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
474                         sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
475
476                         frontend.setSecSequence(sec_sequence);
477
478                         return 0;
479                 }
480         }
481
482         eDebug("found no satellite configuration for orbital position (%d)", sat.orbital_position );
483
484         return -1;
485 }
486
487 RESULT eDVBSatelliteEquipmentControl::clear()
488 {
489         for (int i=0; i < m_lnbidx; ++i)
490         {
491                 m_lnbs[i].m_satellites.clear();
492                 m_lnbs[i].tuner_mask = 0;
493         }
494         m_lnbidx=-1;
495         return 0;
496 }
497
498 /* LNB Specific Parameters */
499 RESULT eDVBSatelliteEquipmentControl::addLNB()
500 {
501         if ( m_lnbidx < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
502                 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
503         else
504         {
505                 eDebug("no more LNB free... cnt is %d", m_lnbidx);
506                 return -ENOSPC;
507         }
508         return 0;
509 }
510
511 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
512 {
513         if ( currentLNBValid() )
514                 m_lnbs[m_lnbidx].tuner_mask = tunermask;
515         else
516                 return -ENOENT;
517         return 0;
518 }
519
520 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
521 {
522         if ( currentLNBValid() )
523                 m_lnbs[m_lnbidx].m_lof_lo = lofl;
524         else
525                 return -ENOENT;
526         return 0;
527 }
528
529 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
530 {
531         if ( currentLNBValid() )
532                 m_lnbs[m_lnbidx].m_lof_hi = lofh;
533         else
534                 return -ENOENT;
535         return 0;
536 }
537
538 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
539 {
540         if ( currentLNBValid() )
541                 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
542         else
543                 return -ENOENT;
544         return 0;
545 }
546
547 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
548 {
549         if ( currentLNBValid() )
550                 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
551         else
552                 return -ENOENT;
553         return 0;
554 }
555
556 /* DiSEqC Specific Parameters */
557 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
558 {
559         if ( currentLNBValid() )
560                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
561         else
562                 return -ENOENT;
563         return 0;
564 }
565
566 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
567 {
568         if ( currentLNBValid() )
569                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
570         else
571                 return -ENOENT;
572         return 0;
573 }
574
575 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
576 {
577         if ( currentLNBValid() )
578                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
579         else
580                 return -ENOENT;
581         return 0;
582 }
583
584 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
585 {
586         if ( currentLNBValid() )
587                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
588         else
589                 return -ENOENT;
590         return 0;
591 }
592
593 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
594 {
595         if ( currentLNBValid() )
596                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
597         else
598                 return -ENOENT;
599         return 0;
600 }
601
602 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
603 {
604         if ( currentLNBValid() )
605                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
606         else
607                 return -ENOENT;
608         return 0;
609 }
610
611 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
612 {
613         if ( currentLNBValid() )
614                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
615         else
616                 return -ENOENT;
617         return 0;
618 }
619
620 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
621 {
622         if ( currentLNBValid() )
623                 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
624         else
625                 return -ENOENT;
626         return 0;
627 }
628
629 /* Rotor Specific Parameters */
630 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
631 {
632         if ( currentLNBValid() )
633                 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
634         else
635                 return -ENOENT;
636         return 0;
637 }
638
639 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
640 {
641         if ( currentLNBValid() )
642                 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
643         else
644                 return -ENOENT;
645         return 0;
646 }
647
648 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
649 {
650         if ( currentLNBValid() )
651                 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
652         else
653                 return -ENOENT;
654         return 0;
655 }
656
657 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
658 {
659         if ( currentLNBValid() )
660                 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
661         else
662                 return -ENOENT;
663         return 0;
664 }
665
666 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
667 {
668         if ( currentLNBValid() )
669                 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
670         else
671                 return -ENOENT;
672         return 0;
673 }
674
675 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
676 {
677         if ( currentLNBValid() )
678                 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
679         else
680                 return -ENOENT;
681         return 0;
682 }
683
684 /* Satellite Specific Parameters */
685 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
686 {
687         if ( currentLNBValid() )
688         {
689                 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
690                         m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
691                 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
692                 {
693                         std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
694                                 m_lnbs[m_lnbidx].m_satellites.insert(
695                                         std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
696                                 );
697                         if ( ret.second )
698                                 m_curSat = ret.first;
699                         else
700                                 return -ENOMEM;
701                 }
702                 else
703                         return -EEXIST;
704         }
705         else
706                 return -ENOENT;
707         return 0;
708 }
709
710 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
711 {
712         if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
713                 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
714         else
715                 return -ENOENT;
716         return 0;
717
718 }
719
720 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
721 {
722         if ( currentLNBValid() )
723         {
724                 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
725                         m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
726                 else
727                         return -EPERM;
728         }
729         else
730                 return -ENOENT;
731         return 0;
732 }
733
734 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
735 {
736         if ( currentLNBValid() )
737         {
738                 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
739                         m_curSat->second.m_rotorPosNum=rotor_pos_num;
740                 else
741                         return -EPERM;
742         }
743         else
744                 return -ENOENT;
745         return 0;
746 }