1 #include <lib/dvb/dvb.h>
2 #include <lib/dvb/sec.h>
3 #include <lib/dvb/rotor_calc.h>
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
11 #define INVERSION inversion
12 #define FREQUENCY frequency
13 #define FEC_INNER fec_inner
14 #define SYMBOLRATE symbol_rate
16 #include <lib/base/eerror.h>
18 DEFINE_REF(eDVBSatelliteEquipmentControl);
20 eDVBSatelliteEquipmentControl *eDVBSatelliteEquipmentControl::instance;
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)
34 setLNBThreshold(11750000);
36 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
37 setToneburst(eDVBSatelliteDiseqcParameters::NO);
39 setCommittedCommand(eDVBSatelliteDiseqcParameters::BB);
40 setCommandOrder(0); // committed, toneburst
44 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
45 setToneMode(eDVBSatelliteSwitchParameters::HILO);
51 setLNBThreshold(11750000);
53 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
54 setToneburst(eDVBSatelliteDiseqcParameters::NO);
56 setCommittedCommand(eDVBSatelliteDiseqcParameters::AB);
57 setCommandOrder(0); // committed, toneburst
61 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
62 setToneMode(eDVBSatelliteSwitchParameters::HILO);
68 setLNBThreshold(11750000);
70 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_2);
71 setToneburst(eDVBSatelliteDiseqcParameters::NO);
73 setCommittedCommand(eDVBSatelliteDiseqcParameters::AA);
74 setCommandOrder(0); // committed, toneburst
77 setLaDirection(eDVBSatelliteRotorParameters::NORTH);
78 setLoDirection(eDVBSatelliteRotorParameters::EAST);
81 setUseInputpower(true);
82 setInputpowerDelta(50);
85 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
86 setToneMode(eDVBSatelliteSwitchParameters::HILO);
90 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
91 setToneMode(eDVBSatelliteSwitchParameters::HILO);
95 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
96 setToneMode(eDVBSatelliteSwitchParameters::HILO);
97 setRotorPosNum(1); // stored pos 1
100 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int frontend_id )
104 for (int idx=0; idx <= m_lnbidx; ++idx )
106 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
107 if ( lnb_param.tuner_mask & frontend_id ) // lnb for correct tuner?
109 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
111 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
112 lnb_param.m_satellites.find(sat.orbital_position);
113 if ( sit != lnb_param.m_satellites.end())
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,
123 fe->getData(6, curRotorPos);
124 fe->getData(7, linked_to);
125 fe->getData(8, satpos_depends_to);
127 if ( sat.frequency > lnb_param.m_lof_threshold )
129 if (sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal)
135 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
138 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
139 csw = 0xF0 | (csw << 2);
141 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
144 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
147 if ( curRotorPos == sat.orbital_position )
148 ret=20; // rotor on correct orbpos = prio 20
150 ret=10; // rotor must turn to correct orbpos = prio 10
153 ret = 30; // no rotor = prio 30
158 ret = 40; // no diseqc = prio 40
161 if (linked_to != -1) // check for linked tuners..
163 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
164 if (linked_fe->m_inuse)
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);
175 eDebug("compare csw %02x == lcsw %02x",
178 eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
179 ucsw, oucsw, toneburst, oToneburst);
181 eDebug("compare pos %d == current pos %d",
182 sat.orbital_position, oRotorPos);
184 if ( (csw != ocsw) ||
185 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
186 ( rotor && oRotorPos != sat.orbital_position ) )
188 // eDebug("can not tune this transponder with linked tuner in use!!");
192 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
196 if (satpos_depends_to != -1) // check for linked tuners..
198 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
199 if ( satpos_depends_to_fe->m_inuse )
202 satpos_depends_to_fe->m_frontend->getData(6, oRotorPos);
203 if (!rotor || oRotorPos != sat.orbital_position)
205 // eDebug("can not tune this transponder ... rotor on other tuner is positioned to %d", oRotorPos);
210 // eDebug("OK .. can tune this transponder satpos is correct :)");
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);
220 for (int i=0; i < num_lofs; ++i)
222 int lof_diff = abs(lof - lofs[i]);
223 if ( lof_diff < diff )
229 if ( used_band != -1 )
233 eDebug("could not detect used lnb freq range .. disable range check !!!");
237 if ( used_band != -1 )
250 case 2: // ku-band low
254 case 3: // ku-band high
259 // check frequency in range ( +/- 75Mhz )
260 if ( (sat.frequency+75000) < range[0] )
262 if ( (sat.frequency-75000) > range[1] )
272 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
274 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)
277 bool depend_satpos_mode=false;
279 for (int idx=0; idx <= m_lnbidx; ++idx )
281 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
282 if (!(lnb_param.tuner_mask & frontend_id)) // lnb for correct tuner?
284 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
285 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
287 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
288 lnb_param.m_satellites.find(sat.orbital_position);
289 if ( sit != lnb_param.m_satellites.end())
291 eDVBSatelliteSwitchParameters &sw_param = sit->second;
292 bool doSetVoltageToneFrontend = true;
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,
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);
317 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
318 if (linked_fe->m_inuse)
320 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
325 if (satpos_depends_to != -1)
327 eDVBRegisteredFrontend *satpos_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
328 if (satpos_fe->m_inuse)
330 if ( di_param.m_diseqc_mode != eDVBSatelliteDiseqcParameters::V1_2 )
332 eDebug("[SEC] frontend is depending on satpos of other one.. so we dont turn rotor!!");
333 depend_satpos_mode=true;
337 if ( sat.frequency > lnb_param.m_lof_threshold )
341 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
343 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
345 parm.FREQUENCY = abs(parm.FREQUENCY);
347 if (sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal)
350 switch (sat.inversion)
352 case eDVBFrontendParametersCable::Inversion::On:
353 parm.INVERSION = INVERSION_ON;
355 case eDVBFrontendParametersCable::Inversion::Off:
356 parm.INVERSION = INVERSION_OFF;
359 case eDVBFrontendParametersCable::Inversion::Unknown:
360 parm.INVERSION = INVERSION_AUTO;
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;
372 case eDVBFrontendParametersSatellite::FEC::f1_2:
373 parm.u.qpsk.FEC_INNER = FEC_1_2;
375 case eDVBFrontendParametersSatellite::FEC::f2_3:
376 parm.u.qpsk.FEC_INNER = FEC_2_3;
378 case eDVBFrontendParametersSatellite::FEC::f3_4:
379 parm.u.qpsk.FEC_INNER = FEC_3_4;
381 case eDVBFrontendParametersSatellite::FEC::f5_6:
382 parm.u.qpsk.FEC_INNER = FEC_5_6;
384 case eDVBFrontendParametersSatellite::FEC::f7_8:
385 parm.u.qpsk.FEC_INNER = FEC_7_8;
389 parm.u.qpsk.SYMBOLRATE = sat.symbol_rate;
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;
406 eSecCommandList sec_sequence;
408 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
410 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
411 csw = 0xF0 | (csw << 2);
413 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
417 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
418 bool changed_csw = send_csw && csw != lastcsw;
421 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
422 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
425 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
426 bool changed_burst = send_burst && toneburst != lastToneburst;
428 int send_mask = 0; /*
431 4 send toneburst first
432 8 send toneburst at end */
433 if (changed_burst) // toneburst first and toneburst changed
435 if (di_param.m_command_order&1)
449 if ((di_param.m_command_order&4) && send_csw)
451 if (di_param.m_command_order==4 && send_burst)
456 if ( di_param.m_use_fast
457 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
459 && ((csw / 4) == (lastcsw / 4)) )
460 eDebug("dont send committed cmd (fast diseqc)");
464 if (!(di_param.m_command_order&4) && send_ucsw)
466 if (!(di_param.m_command_order&1) && send_burst)
472 eDebugNoNewLine("sendmask: ");
473 for (int i=3; i >= 0; --i)
474 if ( send_mask & (1<<i) )
475 eDebugNoNewLine("1");
477 eDebugNoNewLine("0");
482 bool useGotoXX = false;
483 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
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);
490 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
491 RotorCmd=sw_param.m_rotorPosNum;
492 else // we must calc gotoxx cmd
494 eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
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;
501 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
504 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
505 SiteLon = 360 - SiteLon;
507 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
508 double satHourAngle =
509 calcSatHourangle( SatLon, SiteLat, SiteLon );
510 eDebug("PolarmountHourAngle=%lf", satHourAngle );
512 static int gotoXTable[10] =
513 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
515 if (SiteLat >= 0) // Northern Hemisphere
517 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
518 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
520 if (satHourAngle < 180) // the east
525 else // Southern Hemisphere
527 if (satHourAngle < 180) // the east
529 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
530 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
535 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
536 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
540 eDebug("RotorCmd = %04x", RotorCmd);
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;
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) );
556 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
558 if (rotor_param.m_inputpower_parameters.m_use)
559 compare.voltage = VOLTAGE(18); // in input power mode turn rotor always with 18V (fast)
561 compare.voltage = VOLTAGE(13); // in normal mode start turning with 13V
564 compare.voltage = voltage;
566 // voltage already correct ?
567 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
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) );
573 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
577 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
578 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
588 for ( int i=0; i < di_param.m_repeats; ++i )
591 for ( int i = 0; i < loops;) // fill commands...
593 eDVBDiseqcCommand diseqc;
595 diseqc.data[0] = i ? 0xE1 : 0xE0;
596 diseqc.data[1] = 0x10;
597 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
599 diseqc.data[2] = 0x39;
600 diseqc.data[3] = ucsw;
602 else if ( send_mask & 1 )
604 diseqc.data[2] = 0x38;
605 diseqc.data[3] = csw;
609 diseqc.data[2] = 0x00;
610 diseqc.data[3] = 0x00;
612 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
618 if (diseqc.data[2] == 0x38 && (send_mask & 2))
620 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
624 static int delay = (120 - 54) / 2; // standard says 100msek between two repeated commands
625 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
627 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
628 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
631 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
633 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
635 else // delay 120msek when no command is in repeat gap
636 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
639 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
642 if ( send_mask & 8 ) // toneburst at end of sequence
644 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
645 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
650 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
652 eSecCommand::pair compare;
653 compare.voltage = iDVBFrontend::voltageOff;
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) );
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
662 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
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
669 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
671 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +1) );
673 eDVBDiseqcCommand diseqc;
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) );
685 diseqc.data[0] = 0xE0;
686 diseqc.data[1] = 0x31; // positioner
690 diseqc.data[2] = 0x6E; // drive to angular position
691 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
692 diseqc.data[4] = RotorCmd & 0xFF;
697 diseqc.data[2] = 0x6B; // goto stored sat position
698 diseqc.data[3] = RotorCmd;
699 diseqc.data[4] = 0x00;
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);
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) );
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) );
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
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;
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
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
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 /////////////////////
753 { // use normal turning mode
754 doSetVoltageToneFrontend=false;
755 eSecCommand::rotor cmd;
756 eSecCommand::pair compare;
757 compare.voltage = VOLTAGE(13);
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
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) );
767 compare.voltage = voltage;
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) );
773 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
774 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
776 cmd.direction=1; // check for running rotor
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
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);
796 frontend.setData(0, csw);
797 frontend.setData(1, ucsw);
798 frontend.setData(2, di_param.m_toneburst_param);
803 if (doSetVoltageToneFrontend)
805 eSecCommand::pair compare;
806 compare.voltage = voltage;
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) );
812 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
813 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
815 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
816 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
819 frontend.setSecSequence(sec_sequence);
825 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
829 RESULT eDVBSatelliteEquipmentControl::clear()
831 for (int i=0; i < m_lnbidx; ++i)
833 m_lnbs[i].m_satellites.clear();
834 m_lnbs[i].tuner_mask = 0;
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);
845 // helper function for setTunerLinked and setTunerDepends
846 RESULT eDVBSatelliteEquipmentControl::setDependencyPointers( int tu1, int tu2, int dest_data_byte )
851 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
854 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
863 p1->m_frontend->setData(dest_data_byte, (int)p2); // this is evil..
864 p2->m_frontend->setData(dest_data_byte, (int)p1);
870 /* LNB Specific Parameters */
871 RESULT eDVBSatelliteEquipmentControl::addLNB()
873 if ( m_lnbidx < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
874 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
877 eDebug("no more LNB free... cnt is %d", m_lnbidx);
883 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
885 if ( currentLNBValid() )
886 m_lnbs[m_lnbidx].tuner_mask = tunermask;
892 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
894 if ( currentLNBValid() )
895 m_lnbs[m_lnbidx].m_lof_lo = lofl;
901 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
903 if ( currentLNBValid() )
904 m_lnbs[m_lnbidx].m_lof_hi = lofh;
910 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
912 if ( currentLNBValid() )
913 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
919 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
921 if ( currentLNBValid() )
922 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
928 /* DiSEqC Specific Parameters */
929 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
931 if ( currentLNBValid() )
932 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
938 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
940 if ( currentLNBValid() )
941 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
947 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
949 if ( currentLNBValid() )
950 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
956 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
958 if ( currentLNBValid() )
959 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
965 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
967 if ( currentLNBValid() )
968 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
974 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
976 if ( currentLNBValid() )
977 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
983 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
985 if ( currentLNBValid() )
986 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
992 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
994 if ( currentLNBValid() )
995 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1001 /* Rotor Specific Parameters */
1002 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1004 if ( currentLNBValid() )
1005 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1011 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1013 if ( currentLNBValid() )
1014 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1020 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1022 if ( currentLNBValid() )
1023 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1029 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1031 if ( currentLNBValid() )
1032 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1038 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1040 if ( currentLNBValid() )
1041 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1047 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1049 if ( currentLNBValid() )
1050 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1056 /* Satellite Specific Parameters */
1057 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1059 if ( currentLNBValid() )
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() )
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())
1070 m_curSat = ret.first;
1082 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1084 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1085 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1092 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1094 if ( currentLNBValid() )
1096 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1097 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1106 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1108 if ( currentLNBValid() )
1110 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1111 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1120 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1122 return setDependencyPointers(tu1, tu2, 7);
1125 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1127 return setDependencyPointers(tu1, tu2, 8);
1130 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1132 return m_rotorMoving;
1135 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)