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;
246 bool doSetFrontend = true;
248 linked_to=-1, // linked tuner
249 satpos_depends_to=-1,
250 voltage = iDVBFrontend::voltageOff,
251 tone = iDVBFrontend::toneOff,
252 csw = di_param.m_committed_cmd,
253 ucsw = di_param.m_uncommitted_cmd,
254 toneburst = di_param.m_toneburst_param,
261 frontend.getData(0, lastcsw);
262 frontend.getData(1, lastucsw);
263 frontend.getData(2, lastToneburst);
264 frontend.getData(5, lastRotorCmd);
265 frontend.getData(6, curRotorPos);
266 frontend.getData(7, linked_to);
267 frontend.getData(8, satpos_depends_to);
271 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
272 if (linked_fe->m_inuse)
274 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
279 if (satpos_depends_to != -1)
281 eDVBRegisteredFrontend *satpos_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
282 if (satpos_fe->m_inuse)
284 if ( di_param.m_diseqc_mode != eDVBSatelliteDiseqcParameters::V1_2 )
286 eDebug("[SEC] frontend is depending on satpos of other one.. so we dont turn rotor!!");
287 depend_satpos_mode=true;
291 if ( sat.frequency > lnb_param.m_lof_threshold )
295 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
297 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
299 parm.FREQUENCY = abs(parm.FREQUENCY);
301 frontend.setData(9, sat.frequency - parm.FREQUENCY);
303 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
306 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
307 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
308 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
309 voltage = VOLTAGE(13);
310 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
311 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
312 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
313 voltage = VOLTAGE(18);
314 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
315 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
316 tone = iDVBFrontend::toneOn;
317 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
318 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
319 tone = iDVBFrontend::toneOff;
321 eSecCommandList sec_sequence;
323 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
325 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
326 csw = 0xF0 | (csw << 2);
328 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
332 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
333 bool changed_csw = send_csw && csw != lastcsw;
336 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
337 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
340 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
341 bool changed_burst = send_burst && toneburst != lastToneburst;
343 int send_mask = 0; /*
346 4 send toneburst first
347 8 send toneburst at end */
348 if (changed_burst) // toneburst first and toneburst changed
350 if (di_param.m_command_order&1)
364 if ((di_param.m_command_order&4) && send_csw)
366 if (di_param.m_command_order==4 && send_burst)
371 if ( di_param.m_use_fast
372 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
374 && ((csw / 4) == (lastcsw / 4)) )
375 eDebug("dont send committed cmd (fast diseqc)");
379 if (!(di_param.m_command_order&4) && send_ucsw)
381 if (!(di_param.m_command_order&1) && send_burst)
387 eDebugNoNewLine("sendmask: ");
388 for (int i=3; i >= 0; --i)
389 if ( send_mask & (1<<i) )
390 eDebugNoNewLine("1");
392 eDebugNoNewLine("0");
397 bool useGotoXX = false;
398 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
400 if (depend_satpos_mode || linked)
401 // in this both modes we dont really turn the rotor.... but in canTune we need the satpos
402 frontend.setData(6, sat.orbital_position);
405 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
406 RotorCmd=sw_param.m_rotorPosNum;
407 else // we must calc gotoxx cmd
409 eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
412 double SatLon = abs(sat.orbital_position)/10.00,
413 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
414 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
416 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
419 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
420 SiteLon = 360 - SiteLon;
422 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
423 double satHourAngle =
424 calcSatHourangle( SatLon, SiteLat, SiteLon );
425 eDebug("PolarmountHourAngle=%lf", satHourAngle );
427 static int gotoXTable[10] =
428 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
430 if (SiteLat >= 0) // Northern Hemisphere
432 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
433 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
435 if (satHourAngle < 180) // the east
440 else // Southern Hemisphere
442 if (satHourAngle < 180) // the east
444 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
445 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
450 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
451 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
455 eDebug("RotorCmd = %04x", RotorCmd);
462 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
463 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
464 eSecCommand::pair compare;
465 compare.voltage = iDVBFrontend::voltageOff;
467 // the next is a check if voltage is switched off.. then we first set a voltage :)
468 // else we set voltage after all diseqc stuff..
469 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
471 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
473 if (rotor_param.m_inputpower_parameters.m_use)
474 compare.voltage = VOLTAGE(18); // in input power mode turn rotor always with 18V (fast)
476 compare.voltage = VOLTAGE(13); // in normal mode start turning with 13V
479 compare.voltage = voltage;
481 // voltage already correct ?
482 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
484 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
485 // voltage was disabled..so we wait a longer time .. for normal switches 200ms should be enough
486 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );
488 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
492 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
493 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
503 for ( int i=0; i < di_param.m_repeats; ++i )
506 for ( int i = 0; i < loops;) // fill commands...
508 eDVBDiseqcCommand diseqc;
510 diseqc.data[0] = i ? 0xE1 : 0xE0;
511 diseqc.data[1] = 0x10;
512 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
514 diseqc.data[2] = 0x39;
515 diseqc.data[3] = ucsw;
517 else if ( send_mask & 1 )
519 diseqc.data[2] = 0x38;
520 diseqc.data[3] = csw;
524 diseqc.data[2] = 0x00;
525 diseqc.data[3] = 0x00;
527 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
533 if (diseqc.data[2] == 0x38 && (send_mask & 2))
535 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
539 static int delay = (120 - 54) / 2; // standard says 100msek between two repeated commands
540 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
542 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
543 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
546 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
548 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
550 else // delay 120msek when no command is in repeat gap
551 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
554 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
557 if ( send_mask & 8 ) // toneburst at end of sequence
559 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
560 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
565 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
567 eSecCommand::pair compare;
568 compare.voltage = iDVBFrontend::voltageOff;
570 // the next is a check if voltage is switched off.. then we first set a voltage :)
571 // else we set voltage after all diseqc stuff..
572 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
574 if (rotor_param.m_inputpower_parameters.m_use)
575 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
577 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
579 // voltage was disabled..so we wait a longer time ..
580 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
581 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +7) ); // no need to send stop rotor cmd
584 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
586 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +1) );
588 eDVBDiseqcCommand diseqc;
590 diseqc.data[0] = 0xE0;
591 diseqc.data[1] = 0x31; // positioner
592 diseqc.data[2] = 0x60; // stop
593 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
594 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
595 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
596 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
597 // wait 300msec after send rotor stop cmd
598 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
600 diseqc.data[0] = 0xE0;
601 diseqc.data[1] = 0x31; // positioner
605 diseqc.data[2] = 0x6E; // drive to angular position
606 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
607 diseqc.data[4] = RotorCmd & 0xFF;
612 diseqc.data[2] = 0x6B; // goto stored sat position
613 diseqc.data[3] = RotorCmd;
614 diseqc.data[4] = 0x00;
617 if ( rotor_param.m_inputpower_parameters.m_use )
618 { // use measure rotor input power to detect rotor state
619 eSecCommand::rotor cmd;
620 eSecCommand::pair compare;
621 compare.voltage = VOLTAGE(18);
623 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
624 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
625 // measure idle power values
626 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
627 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
630 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
631 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
632 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec before measure
633 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
635 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
636 ////////////////////////////
637 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
638 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) ); // 2 retries
639 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
640 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
641 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
643 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
644 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
645 cmd.direction=1; // check for running rotor
646 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
649 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
650 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
651 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
652 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
653 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
655 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) ); // 2 minutes running timeout
656 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
657 // rotor running loop
658 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
659 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
660 cmd.direction=0; // check for stopped rotor
662 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
663 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); // timeout ? this should never happen
664 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
665 /////////////////////
668 { // use normal turning mode
669 doSetVoltageToneFrontend=false;
671 eSecCommand::rotor cmd;
672 eSecCommand::pair compare;
673 compare.voltage = VOLTAGE(13);
675 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
676 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
677 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
679 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
680 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
681 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
683 compare.voltage = voltage;
685 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
686 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
687 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
689 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
690 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
692 cmd.direction=1; // check for running rotor
697 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 480) ); // 2 minutes running timeout
698 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
699 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
700 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
701 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
703 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
704 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
705 frontend.setData(3, RotorCmd);
706 frontend.setData(4, sat.orbital_position);
712 frontend.setData(0, csw);
713 frontend.setData(1, ucsw);
714 frontend.setData(2, di_param.m_toneburst_param);
716 if (!linked && doSetVoltageToneFrontend)
718 eSecCommand::pair compare;
719 compare.voltage = voltage;
721 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
722 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
723 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
725 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
726 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
731 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
732 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
734 frontend.setSecSequence(sec_sequence);
740 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
744 RESULT eDVBSatelliteEquipmentControl::clear()
746 for (int i=0; i <= m_lnbidx; ++i)
748 m_lnbs[i].m_satellites.clear();
749 m_lnbs[i].tuner_mask = 0;
753 // clear linked tuner configuration
754 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
755 it->m_frontend->setData(7, -1);
760 // helper function for setTunerLinked and setTunerDepends
761 RESULT eDVBSatelliteEquipmentControl::setDependencyPointers( int tu1, int tu2, int dest_data_byte )
766 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
769 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
778 p1->m_frontend->setData(dest_data_byte, (int)p2); // this is evil..
779 p2->m_frontend->setData(dest_data_byte, (int)p1);
785 /* LNB Specific Parameters */
786 RESULT eDVBSatelliteEquipmentControl::addLNB()
788 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
789 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
792 eDebug("no more LNB free... cnt is %d", m_lnbidx);
798 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
800 if ( currentLNBValid() )
801 m_lnbs[m_lnbidx].tuner_mask = tunermask;
807 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
809 if ( currentLNBValid() )
810 m_lnbs[m_lnbidx].m_lof_lo = lofl;
816 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
818 if ( currentLNBValid() )
819 m_lnbs[m_lnbidx].m_lof_hi = lofh;
825 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
827 if ( currentLNBValid() )
828 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
834 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
836 if ( currentLNBValid() )
837 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
843 /* DiSEqC Specific Parameters */
844 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
846 if ( currentLNBValid() )
847 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
853 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
855 if ( currentLNBValid() )
856 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
862 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
864 if ( currentLNBValid() )
865 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
871 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
873 if ( currentLNBValid() )
874 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
880 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
882 if ( currentLNBValid() )
883 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
889 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
891 if ( currentLNBValid() )
892 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
898 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
900 if ( currentLNBValid() )
901 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
907 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
909 if ( currentLNBValid() )
910 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
916 /* Rotor Specific Parameters */
917 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
919 if ( currentLNBValid() )
920 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
926 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
928 if ( currentLNBValid() )
929 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
935 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
937 if ( currentLNBValid() )
938 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
944 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
946 if ( currentLNBValid() )
947 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
953 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
955 if ( currentLNBValid() )
956 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
962 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
964 if ( currentLNBValid() )
965 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
971 /* Satellite Specific Parameters */
972 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
974 if ( currentLNBValid() )
976 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
977 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
978 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
980 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
981 m_lnbs[m_lnbidx].m_satellites.insert(
982 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
985 m_curSat = ret.first;
997 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
999 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1000 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1007 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1009 if ( currentLNBValid() )
1011 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1012 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1021 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1023 if ( currentLNBValid() )
1025 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1026 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1035 PyObject *eDVBSatelliteEquipmentControl::get_different_satellites(int tu1, int tu2)
1040 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1042 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1046 else if (cnt == tu2)
1051 // check for linked tuners
1053 p1->m_frontend->getData(7, tmp1);
1054 p2->m_frontend->setData(7, tmp2);
1055 if ((void*)tmp1 != p2 && (void*)tmp2 != p1)
1057 // check for rotor dependency
1058 p1->m_frontend->getData(8, tmp1);
1059 p2->m_frontend->setData(8, tmp2);
1060 if ((void*)tmp1 != p2 && (void*)tmp2 != p1)
1062 // here we know the tuners are not linked and no rotor dependency exist.
1063 // now we check all configured satellites/lnb for difference and at all difference
1064 // to a list of tuples with first value tuner number and second value orbital position
1066 ret = PyList_New(0);
1067 // FIXMEE !! fill list (compare satellites (lofh, lofl, lof threshold, opos))
1080 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1082 return setDependencyPointers(tu1, tu2, 7);
1085 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1087 return setDependencyPointers(tu1, tu2, 8);
1090 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1092 return m_rotorMoving;
1095 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)