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 FREQUENCY Frequency
8 #define FREQUENCY frequency
10 #include <lib/base/eerror.h>
12 DEFINE_REF(eDVBSatelliteEquipmentControl);
14 eDVBSatelliteEquipmentControl *eDVBSatelliteEquipmentControl::instance;
16 eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBRegisteredFrontend> &avail_frontends)
17 :m_lnbidx(-1), m_curSat(m_lnbs[0].m_satellites.end()), m_avail_frontends(avail_frontends), m_rotorMoving(false)
28 setLNBThreshold(11750000);
30 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
31 setToneburst(eDVBSatelliteDiseqcParameters::NO);
33 setCommittedCommand(eDVBSatelliteDiseqcParameters::BB);
34 setCommandOrder(0); // committed, toneburst
38 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
39 setToneMode(eDVBSatelliteSwitchParameters::HILO);
45 setLNBThreshold(11750000);
47 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
48 setToneburst(eDVBSatelliteDiseqcParameters::NO);
50 setCommittedCommand(eDVBSatelliteDiseqcParameters::AB);
51 setCommandOrder(0); // committed, toneburst
55 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
56 setToneMode(eDVBSatelliteSwitchParameters::HILO);
62 setLNBThreshold(11750000);
64 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_2);
65 setToneburst(eDVBSatelliteDiseqcParameters::NO);
67 setCommittedCommand(eDVBSatelliteDiseqcParameters::AA);
68 setCommandOrder(0); // committed, toneburst
71 setLaDirection(eDVBSatelliteRotorParameters::NORTH);
72 setLoDirection(eDVBSatelliteRotorParameters::EAST);
75 setUseInputpower(true);
76 setInputpowerDelta(50);
79 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
80 setToneMode(eDVBSatelliteSwitchParameters::HILO);
84 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
85 setToneMode(eDVBSatelliteSwitchParameters::HILO);
89 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
90 setToneMode(eDVBSatelliteSwitchParameters::HILO);
91 setRotorPosNum(1); // stored pos 1
94 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int frontend_id )
98 for (int idx=0; idx <= m_lnbidx; ++idx )
100 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
101 if ( lnb_param.tuner_mask & frontend_id ) // lnb for correct tuner?
103 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
105 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
106 lnb_param.m_satellites.find(sat.orbital_position);
107 if ( sit != lnb_param.m_satellites.end())
110 linked_to=-1, // linked tuner
111 satpos_depends_to=-1,
112 csw = di_param.m_committed_cmd,
113 ucsw = di_param.m_uncommitted_cmd,
114 toneburst = di_param.m_toneburst_param,
117 fe->getData(6, curRotorPos);
118 fe->getData(7, linked_to);
119 fe->getData(8, satpos_depends_to);
121 if ( sat.frequency > lnb_param.m_lof_threshold )
123 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
129 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
132 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
133 csw = 0xF0 | (csw << 2);
135 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
138 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
141 if ( curRotorPos == sat.orbital_position )
142 ret=20; // rotor on correct orbpos = prio 20
144 ret=10; // rotor must turn to correct orbpos = prio 10
147 ret = 30; // no rotor = prio 30
152 ret = 40; // no diseqc = prio 40
155 if (linked_to != -1) // check for linked tuners..
157 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
158 if (linked_fe->m_inuse)
164 linked_fe->m_frontend->getData(0, ocsw);
165 linked_fe->m_frontend->getData(1, oucsw);
166 linked_fe->m_frontend->getData(2, oToneburst);
167 linked_fe->m_frontend->getData(6, oRotorPos);
169 eDebug("compare csw %02x == lcsw %02x",
172 eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
173 ucsw, oucsw, toneburst, oToneburst);
175 eDebug("compare pos %d == current pos %d",
176 sat.orbital_position, oRotorPos);
178 if ( (csw != ocsw) ||
179 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
180 ( rotor && oRotorPos != sat.orbital_position ) )
182 // eDebug("can not tune this transponder with linked tuner in use!!");
186 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
190 if (satpos_depends_to != -1) // check for linked tuners..
192 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
193 if ( satpos_depends_to_fe->m_inuse )
196 satpos_depends_to_fe->m_frontend->getData(6, oRotorPos);
197 if (!rotor || oRotorPos != sat.orbital_position)
199 // eDebug("can not tune this transponder ... rotor on other tuner is positioned to %d", oRotorPos);
204 // eDebug("OK .. can tune this transponder satpos is correct :)");
208 int lof = sat.frequency > lnb_param.m_lof_threshold ?
209 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
210 int tuner_freq = abs(sat.frequency - lof);
211 // eDebug("tuner freq %d", tuner_freq);
212 if (tuner_freq < 900000 || tuner_freq > 2200000)
215 // eDebug("Transponder not tuneable with this lnb... %d Khz out of tuner range",
225 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
227 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)
230 bool depend_satpos_mode=false;
232 for (int idx=0; idx <= m_lnbidx; ++idx )
234 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
235 if (!(lnb_param.tuner_mask & frontend_id)) // lnb for correct tuner?
237 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
238 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
240 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
241 lnb_param.m_satellites.find(sat.orbital_position);
242 if ( sit != lnb_param.m_satellites.end())
244 eDVBSatelliteSwitchParameters &sw_param = sit->second;
245 bool doSetVoltageToneFrontend = true;
247 linked_to=-1, // linked tuner
248 satpos_depends_to=-1,
249 voltage = iDVBFrontend::voltageOff,
250 tone = iDVBFrontend::toneOff,
251 csw = di_param.m_committed_cmd,
252 ucsw = di_param.m_uncommitted_cmd,
253 toneburst = di_param.m_toneburst_param,
260 frontend.getData(0, lastcsw);
261 frontend.getData(1, lastucsw);
262 frontend.getData(2, lastToneburst);
263 frontend.getData(5, lastRotorCmd);
264 frontend.getData(6, curRotorPos);
265 frontend.getData(7, linked_to);
266 frontend.getData(8, satpos_depends_to);
270 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
271 if (linked_fe->m_inuse)
273 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
278 if (satpos_depends_to != -1)
280 eDVBRegisteredFrontend *satpos_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
281 if (satpos_fe->m_inuse)
283 if ( di_param.m_diseqc_mode != eDVBSatelliteDiseqcParameters::V1_2 )
285 eDebug("[SEC] frontend is depending on satpos of other one.. so we dont turn rotor!!");
286 depend_satpos_mode=true;
290 if ( sat.frequency > lnb_param.m_lof_threshold )
294 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
296 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
298 parm.FREQUENCY = abs(parm.FREQUENCY);
300 frontend.setData(9, sat.frequency - parm.FREQUENCY);
302 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
305 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
306 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
307 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
308 voltage = VOLTAGE(13);
309 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
310 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
311 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
312 voltage = VOLTAGE(18);
313 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
314 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
315 tone = iDVBFrontend::toneOn;
316 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
317 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
318 tone = iDVBFrontend::toneOff;
320 eSecCommandList sec_sequence;
322 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
324 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
325 csw = 0xF0 | (csw << 2);
327 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
331 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
332 bool changed_csw = send_csw && csw != lastcsw;
335 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
336 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
339 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
340 bool changed_burst = send_burst && toneburst != lastToneburst;
342 int send_mask = 0; /*
345 4 send toneburst first
346 8 send toneburst at end */
347 if (changed_burst) // toneburst first and toneburst changed
349 if (di_param.m_command_order&1)
363 if ((di_param.m_command_order&4) && send_csw)
365 if (di_param.m_command_order==4 && send_burst)
370 if ( di_param.m_use_fast
371 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
373 && ((csw / 4) == (lastcsw / 4)) )
374 eDebug("dont send committed cmd (fast diseqc)");
378 if (!(di_param.m_command_order&4) && send_ucsw)
380 if (!(di_param.m_command_order&1) && send_burst)
386 eDebugNoNewLine("sendmask: ");
387 for (int i=3; i >= 0; --i)
388 if ( send_mask & (1<<i) )
389 eDebugNoNewLine("1");
391 eDebugNoNewLine("0");
396 bool useGotoXX = false;
397 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
399 if (depend_satpos_mode || linked)
400 // in this both modes we dont really turn the rotor.... but in canTune we need the satpos
401 frontend.setData(6, sat.orbital_position);
404 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
405 RotorCmd=sw_param.m_rotorPosNum;
406 else // we must calc gotoxx cmd
408 eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
411 double SatLon = abs(sat.orbital_position)/10.00,
412 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
413 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
415 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
418 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
419 SiteLon = 360 - SiteLon;
421 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
422 double satHourAngle =
423 calcSatHourangle( SatLon, SiteLat, SiteLon );
424 eDebug("PolarmountHourAngle=%lf", satHourAngle );
426 static int gotoXTable[10] =
427 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
429 if (SiteLat >= 0) // Northern Hemisphere
431 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
432 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
434 if (satHourAngle < 180) // the east
439 else // Southern Hemisphere
441 if (satHourAngle < 180) // the east
443 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
444 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
449 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
450 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
454 eDebug("RotorCmd = %04x", RotorCmd);
461 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
462 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
463 eSecCommand::pair compare;
464 compare.voltage = iDVBFrontend::voltageOff;
466 // the next is a check if voltage is switched off.. then we first set a voltage :)
467 // else we set voltage after all diseqc stuff..
468 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
470 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
472 if (rotor_param.m_inputpower_parameters.m_use)
473 compare.voltage = VOLTAGE(18); // in input power mode turn rotor always with 18V (fast)
475 compare.voltage = VOLTAGE(13); // in normal mode start turning with 13V
478 compare.voltage = voltage;
480 // voltage already correct ?
481 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
483 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
484 // voltage was disabled..so we wait a longer time .. for normal switches 200ms should be enough
485 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );
487 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
491 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
492 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
502 for ( int i=0; i < di_param.m_repeats; ++i )
505 for ( int i = 0; i < loops;) // fill commands...
507 eDVBDiseqcCommand diseqc;
509 diseqc.data[0] = i ? 0xE1 : 0xE0;
510 diseqc.data[1] = 0x10;
511 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
513 diseqc.data[2] = 0x39;
514 diseqc.data[3] = ucsw;
516 else if ( send_mask & 1 )
518 diseqc.data[2] = 0x38;
519 diseqc.data[3] = csw;
523 diseqc.data[2] = 0x00;
524 diseqc.data[3] = 0x00;
526 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
532 if (diseqc.data[2] == 0x38 && (send_mask & 2))
534 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
538 static int delay = (120 - 54) / 2; // standard says 100msek between two repeated commands
539 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
541 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
542 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
545 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
547 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
549 else // delay 120msek when no command is in repeat gap
550 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
553 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
556 if ( send_mask & 8 ) // toneburst at end of sequence
558 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
559 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
564 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
566 eSecCommand::pair compare;
567 compare.voltage = iDVBFrontend::voltageOff;
569 // the next is a check if voltage is switched off.. then we first set a voltage :)
570 // else we set voltage after all diseqc stuff..
571 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
573 if (rotor_param.m_inputpower_parameters.m_use)
574 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
576 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
578 // voltage was disabled..so we wait a longer time ..
579 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
580 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +7) ); // no need to send stop rotor cmd
583 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
585 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +1) );
587 eDVBDiseqcCommand diseqc;
589 diseqc.data[0] = 0xE0;
590 diseqc.data[1] = 0x31; // positioner
591 diseqc.data[2] = 0x60; // stop
592 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
593 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
594 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
595 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
596 // wait 300msec after send rotor stop cmd
597 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
599 diseqc.data[0] = 0xE0;
600 diseqc.data[1] = 0x31; // positioner
604 diseqc.data[2] = 0x6E; // drive to angular position
605 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
606 diseqc.data[4] = RotorCmd & 0xFF;
611 diseqc.data[2] = 0x6B; // goto stored sat position
612 diseqc.data[3] = RotorCmd;
613 diseqc.data[4] = 0x00;
616 if ( rotor_param.m_inputpower_parameters.m_use )
617 { // use measure rotor input power to detect rotor state
618 eSecCommand::rotor cmd;
619 eSecCommand::pair compare;
620 compare.voltage = VOLTAGE(18);
622 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
623 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
624 // measure idle power values
625 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
626 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
629 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
630 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
631 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec before measure
632 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
634 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
635 ////////////////////////////
636 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
637 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) ); // 2 retries
638 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
639 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
640 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
642 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
643 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
644 cmd.direction=1; // check for running rotor
645 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
648 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
649 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
650 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
651 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
652 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
654 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) ); // 2 minutes running timeout
655 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
656 // rotor running loop
657 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
658 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
659 cmd.direction=0; // check for stopped rotor
661 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
662 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); // timeout ? this should never happen
663 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
664 /////////////////////
667 { // use normal turning mode
668 doSetVoltageToneFrontend=false;
669 eSecCommand::rotor cmd;
670 eSecCommand::pair compare;
671 compare.voltage = VOLTAGE(13);
673 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
674 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
675 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
677 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
678 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
679 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
681 compare.voltage = voltage;
683 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
684 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
685 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
687 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
688 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
690 cmd.direction=1; // check for running rotor
695 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 480) ); // 2 minutes running timeout
696 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
697 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
698 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
699 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
701 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
702 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
703 frontend.setData(3, RotorCmd);
704 frontend.setData(4, sat.orbital_position);
710 frontend.setData(0, csw);
711 frontend.setData(1, ucsw);
712 frontend.setData(2, di_param.m_toneburst_param);
717 if (doSetVoltageToneFrontend)
719 eSecCommand::pair compare;
720 compare.voltage = voltage;
722 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
723 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
724 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
726 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
727 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
729 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
730 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
733 frontend.setSecSequence(sec_sequence);
739 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
743 RESULT eDVBSatelliteEquipmentControl::clear()
745 for (int i=0; i <= m_lnbidx; ++i)
747 m_lnbs[i].m_satellites.clear();
748 m_lnbs[i].tuner_mask = 0;
752 // clear linked tuner configuration
753 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
754 it->m_frontend->setData(7, -1);
759 // helper function for setTunerLinked and setTunerDepends
760 RESULT eDVBSatelliteEquipmentControl::setDependencyPointers( int tu1, int tu2, int dest_data_byte )
765 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
768 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
777 p1->m_frontend->setData(dest_data_byte, (int)p2); // this is evil..
778 p2->m_frontend->setData(dest_data_byte, (int)p1);
784 /* LNB Specific Parameters */
785 RESULT eDVBSatelliteEquipmentControl::addLNB()
787 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
788 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
791 eDebug("no more LNB free... cnt is %d", m_lnbidx);
797 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
799 if ( currentLNBValid() )
800 m_lnbs[m_lnbidx].tuner_mask = tunermask;
806 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
808 if ( currentLNBValid() )
809 m_lnbs[m_lnbidx].m_lof_lo = lofl;
815 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
817 if ( currentLNBValid() )
818 m_lnbs[m_lnbidx].m_lof_hi = lofh;
824 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
826 if ( currentLNBValid() )
827 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
833 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
835 if ( currentLNBValid() )
836 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
842 /* DiSEqC Specific Parameters */
843 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
845 if ( currentLNBValid() )
846 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
852 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
854 if ( currentLNBValid() )
855 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
861 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
863 if ( currentLNBValid() )
864 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
870 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
872 if ( currentLNBValid() )
873 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
879 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
881 if ( currentLNBValid() )
882 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
888 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
890 if ( currentLNBValid() )
891 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
897 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
899 if ( currentLNBValid() )
900 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
906 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
908 if ( currentLNBValid() )
909 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
915 /* Rotor Specific Parameters */
916 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
918 if ( currentLNBValid() )
919 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
925 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
927 if ( currentLNBValid() )
928 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
934 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
936 if ( currentLNBValid() )
937 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
943 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
945 if ( currentLNBValid() )
946 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
952 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
954 if ( currentLNBValid() )
955 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
961 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
963 if ( currentLNBValid() )
964 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
970 /* Satellite Specific Parameters */
971 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
973 if ( currentLNBValid() )
975 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
976 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
977 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
979 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
980 m_lnbs[m_lnbidx].m_satellites.insert(
981 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
984 m_curSat = ret.first;
996 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
998 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
999 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1006 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1008 if ( currentLNBValid() )
1010 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1011 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1020 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1022 if ( currentLNBValid() )
1024 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1025 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1034 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1036 return setDependencyPointers(tu1, tu2, 7);
1039 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1041 return setDependencyPointers(tu1, tu2, 8);
1044 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1046 return m_rotorMoving;
1049 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)