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