1 #include <lib/dvb/dvb.h>
2 #include <lib/dvb/sec.h>
3 #include <lib/dvb/rotor_calc.h>
7 #if HAVE_DVB_API_VERSION < 3
8 #define FREQUENCY Frequency
10 #define FREQUENCY frequency
12 #include <lib/base/eerror.h>
14 DEFINE_REF(eDVBSatelliteEquipmentControl);
16 eDVBSatelliteEquipmentControl *eDVBSatelliteEquipmentControl::instance;
18 eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBRegisteredFrontend> &avail_frontends)
19 :m_lnbidx(-1), m_curSat(m_lnbs[0].m_satellites.end()), m_avail_frontends(avail_frontends), m_rotorMoving(false)
30 setLNBThreshold(11700000);
32 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
33 setToneburst(eDVBSatelliteDiseqcParameters::NO);
35 setCommittedCommand(eDVBSatelliteDiseqcParameters::BB);
36 setCommandOrder(0); // committed, toneburst
40 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
41 setToneMode(eDVBSatelliteSwitchParameters::HILO);
47 setLNBThreshold(11700000);
49 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
50 setToneburst(eDVBSatelliteDiseqcParameters::NO);
52 setCommittedCommand(eDVBSatelliteDiseqcParameters::AB);
53 setCommandOrder(0); // committed, toneburst
57 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
58 setToneMode(eDVBSatelliteSwitchParameters::HILO);
64 setLNBThreshold(11700000);
66 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_2);
67 setToneburst(eDVBSatelliteDiseqcParameters::NO);
69 setCommittedCommand(eDVBSatelliteDiseqcParameters::AA);
70 setCommandOrder(0); // committed, toneburst
73 setLaDirection(eDVBSatelliteRotorParameters::NORTH);
74 setLoDirection(eDVBSatelliteRotorParameters::EAST);
77 setUseInputpower(true);
78 setInputpowerDelta(50);
81 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
82 setToneMode(eDVBSatelliteSwitchParameters::HILO);
86 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
87 setToneMode(eDVBSatelliteSwitchParameters::HILO);
91 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
92 setToneMode(eDVBSatelliteSwitchParameters::HILO);
93 setRotorPosNum(1); // stored pos 1
96 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int frontend_id )
98 int ret=0, satcount=0;
100 for (int idx=0; idx <= m_lnbidx; ++idx )
102 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
103 if ( lnb_param.tuner_mask & frontend_id ) // lnb for correct tuner?
105 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
107 satcount += lnb_param.m_satellites.size();
109 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
110 lnb_param.m_satellites.find(sat.orbital_position);
111 if ( sit != lnb_param.m_satellites.end())
116 satpos_depends_ptr=-1,
117 csw = di_param.m_committed_cmd,
118 ucsw = di_param.m_uncommitted_cmd,
119 toneburst = di_param.m_toneburst_param,
122 fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
123 fe->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
124 fe->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
125 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
127 if ( sat.frequency > lnb_param.m_lof_threshold )
129 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
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
148 if (rotor && curRotorPos != -1)
149 ret -= abs(curRotorPos-sat.orbital_position);
157 while (linked_prev_ptr != -1) // check for linked tuners..
159 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
160 if (linked_fe->m_inuse)
166 linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
167 linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
168 linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
169 linked_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
171 eDebug("compare csw %02x == lcsw %02x",
174 eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
175 ucsw, oucsw, toneburst, oToneburst);
177 eDebug("compare pos %d == current pos %d",
178 sat.orbital_position, oRotorPos);
180 if ( (csw != ocsw) ||
181 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
182 ( rotor && oRotorPos != sat.orbital_position ) )
184 // eDebug("can not tune this transponder with linked tuner in use!!");
189 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
191 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
195 while (linked_next_ptr != -1) // check for linked tuners..
197 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
198 if (linked_fe->m_inuse)
204 linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
205 linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
206 linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
207 linked_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
209 eDebug("compare csw %02x == lcsw %02x",
212 eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
213 ucsw, oucsw, toneburst, oToneburst);
215 eDebug("compare pos %d == current pos %d",
216 sat.orbital_position, oRotorPos);
218 if ( (csw != ocsw) ||
219 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
220 ( rotor && oRotorPos != sat.orbital_position ) )
222 // eDebug("can not tune this transponder with linked tuner in use!!");
227 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
229 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
233 if (satpos_depends_ptr != -1)
235 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
236 if ( satpos_depends_to_fe->m_inuse )
239 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
240 if (!rotor || oRotorPos != sat.orbital_position)
242 // eDebug("can not tune this transponder ... rotor on other tuner is positioned to %d", oRotorPos);
247 // eDebug("OK .. can tune this transponder satpos is correct :)");
252 int lof = sat.frequency > lnb_param.m_lof_threshold ?
253 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
254 int tuner_freq = abs(sat.frequency - lof);
255 // eDebug("tuner freq %d", tuner_freq);
256 if (tuner_freq < 900000 || tuner_freq > 2200000)
259 // eDebug("Transponder not tuneable with this lnb... %d Khz out of tuner range",
271 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
273 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)
276 bool depend_satpos_mode=false;
278 for (int idx=0; idx <= m_lnbidx; ++idx )
280 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
281 if (!(lnb_param.tuner_mask & frontend_id)) // lnb for correct tuner?
283 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
284 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
286 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
287 lnb_param.m_satellites.find(sat.orbital_position);
288 if ( sit != lnb_param.m_satellites.end())
290 eDVBSatelliteSwitchParameters &sw_param = sit->second;
291 bool doSetVoltageToneFrontend = true;
292 bool doSetFrontend = true;
294 linked_prev_ptr=-1, // linked tuner
295 linked_next_ptr=-1, // linked tuner
296 satpos_depends_ptr=-1,
297 voltage = iDVBFrontend::voltageOff,
298 tone = iDVBFrontend::toneOff,
299 csw = di_param.m_committed_cmd,
300 ucsw = di_param.m_uncommitted_cmd,
301 toneburst = di_param.m_toneburst_param,
308 frontend.getData(eDVBFrontend::CSW, lastcsw);
309 frontend.getData(eDVBFrontend::UCSW, lastucsw);
310 frontend.getData(eDVBFrontend::TONEBURST, lastToneburst);
311 frontend.getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
312 frontend.getData(eDVBFrontend::ROTOR_POS, curRotorPos);
313 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
314 frontend.getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
315 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
317 while (linked_prev_ptr != -1) // check for linked tuners..
319 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
320 if (linked_fe->m_inuse)
322 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
326 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
330 while (linked_next_ptr != -1) // check for linked tuners..
332 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
333 if (linked_fe->m_inuse)
335 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
339 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
342 if (satpos_depends_ptr != -1)
344 eDVBRegisteredFrontend *satpos_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
345 if (satpos_fe->m_inuse)
347 if ( di_param.m_diseqc_mode != eDVBSatelliteDiseqcParameters::V1_2 )
349 eDebug("[SEC] frontend is depending on satpos of other one.. so we dont turn rotor!!");
350 depend_satpos_mode=true;
354 if ( sat.frequency > lnb_param.m_lof_threshold )
358 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
360 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
362 parm.FREQUENCY = abs(parm.FREQUENCY);
364 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
366 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
369 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
370 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
371 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
372 voltage = VOLTAGE(13);
373 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
374 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
375 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
376 voltage = VOLTAGE(18);
377 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
378 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
379 tone = iDVBFrontend::toneOn;
380 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
381 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
382 tone = iDVBFrontend::toneOff;
384 eSecCommandList sec_sequence;
386 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
388 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
389 csw = 0xF0 | (csw << 2);
391 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
395 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
396 bool changed_csw = send_csw && csw != lastcsw;
399 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
400 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
403 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
404 bool changed_burst = send_burst && toneburst != lastToneburst;
406 int send_mask = 0; /*
409 4 send toneburst first
410 8 send toneburst at end */
411 if (changed_burst) // toneburst first and toneburst changed
413 if (di_param.m_command_order&1)
427 if ((di_param.m_command_order&4) && send_csw)
429 if (di_param.m_command_order==4 && send_burst)
434 if ( di_param.m_use_fast
435 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
437 && ((csw / 4) == (lastcsw / 4)) )
438 eDebug("dont send committed cmd (fast diseqc)");
442 if (!(di_param.m_command_order&4) && send_ucsw)
444 if (!(di_param.m_command_order&1) && send_burst)
450 eDebugNoNewLine("sendmask: ");
451 for (int i=3; i >= 0; --i)
452 if ( send_mask & (1<<i) )
453 eDebugNoNewLine("1");
455 eDebugNoNewLine("0");
460 bool useGotoXX = false;
461 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
462 && !sat.no_rotor_command_on_tune )
464 if (depend_satpos_mode || linked)
465 // in this both modes we dont really turn the rotor.... but in canTune we need the satpos
466 frontend.setData(eDVBFrontend::ROTOR_POS, sat.orbital_position);
469 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
470 RotorCmd=sw_param.m_rotorPosNum;
471 else // we must calc gotoxx cmd
473 eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
476 double SatLon = abs(sat.orbital_position)/10.00,
477 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
478 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
480 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
483 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
484 SiteLon = 360 - SiteLon;
486 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
487 double satHourAngle =
488 calcSatHourangle( SatLon, SiteLat, SiteLon );
489 eDebug("PolarmountHourAngle=%lf", satHourAngle );
491 static int gotoXTable[10] =
492 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
494 if (SiteLat >= 0) // Northern Hemisphere
496 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
497 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
499 if (satHourAngle < 180) // the east
504 else // Southern Hemisphere
506 if (satHourAngle < 180) // the east
508 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
509 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
514 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
515 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
519 eDebug("RotorCmd = %04x", RotorCmd);
526 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
527 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
528 eSecCommand::pair compare;
529 compare.voltage = iDVBFrontend::voltageOff;
531 // the next is a check if voltage is switched off.. then we first set a voltage :)
532 // else we set voltage after all diseqc stuff..
533 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
535 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
537 if (rotor_param.m_inputpower_parameters.m_use)
538 compare.voltage = VOLTAGE(18); // in input power mode turn rotor always with 18V (fast)
540 compare.voltage = VOLTAGE(13); // in normal mode start turning with 13V
543 compare.voltage = voltage;
545 // voltage already correct ?
546 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
548 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
549 // voltage was disabled..so we wait a longer time .. for normal switches 750ms should be enough
550 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
552 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
556 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
557 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
567 loops <<= di_param.m_repeats;
569 for ( int i = 0; i < loops;) // fill commands...
571 eDVBDiseqcCommand diseqc;
573 diseqc.data[0] = i ? 0xE1 : 0xE0;
574 diseqc.data[1] = 0x10;
575 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
577 diseqc.data[2] = 0x39;
578 diseqc.data[3] = ucsw;
580 else if ( send_mask & 1 )
582 diseqc.data[2] = 0x38;
583 diseqc.data[3] = csw;
585 else // no committed command confed.. so send uncommitted..
587 diseqc.data[2] = 0x39;
588 diseqc.data[3] = ucsw;
590 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
596 if (diseqc.data[2] == 0x38 && (send_mask & 2))
598 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
602 int delay = di_param.m_repeats ? (120 - 54) / 2 : 120; // standard says 100msek between two repeated commands
603 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
605 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
606 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
609 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
611 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
613 else // delay 120msek when no command is in repeat gap
614 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
617 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
620 if ( send_mask & 8 ) // toneburst at end of sequence
622 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
623 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
628 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
630 eSecCommand::pair compare;
633 compare.voltage = iDVBFrontend::voltageOff;
635 // the next is a check if voltage is switched off.. then we first set a voltage :)
636 // else we set voltage after all diseqc stuff..
637 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
639 if (rotor_param.m_inputpower_parameters.m_use)
640 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
642 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
644 // voltage was disabled..so we wait a longer time ..
645 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
646 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +8) ); // no need to send stop rotor cmd and recheck voltage
650 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
651 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +8) ); // no need to send stop rotor cmd and recheck voltage
654 eDVBDiseqcCommand diseqc;
656 diseqc.data[0] = 0xE0;
657 diseqc.data[1] = 0x31; // positioner
658 diseqc.data[2] = 0x60; // stop
659 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
660 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
661 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
662 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
663 // wait 300msec after send rotor stop cmd
664 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
666 diseqc.data[0] = 0xE0;
667 diseqc.data[1] = 0x31; // positioner
671 diseqc.data[2] = 0x6E; // drive to angular position
672 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
673 diseqc.data[4] = RotorCmd & 0xFF;
678 diseqc.data[2] = 0x6B; // goto stored sat position
679 diseqc.data[3] = RotorCmd;
680 diseqc.data[4] = 0x00;
683 if ( rotor_param.m_inputpower_parameters.m_use )
684 { // use measure rotor input power to detect rotor state
685 eSecCommand::rotor cmd;
686 eSecCommand::pair compare;
687 compare.voltage = VOLTAGE(18);
689 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
690 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
691 // measure idle power values
692 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
693 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
696 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
697 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
698 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec before measure
699 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
701 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
702 ////////////////////////////
703 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
704 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) ); // 2 retries
705 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
706 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
707 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
709 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
710 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
711 cmd.direction=1; // check for running rotor
712 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
715 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
716 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
717 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
718 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
719 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
721 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) ); // 2 minutes running timeout
722 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
723 // rotor running loop
724 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
725 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
726 cmd.direction=0; // check for stopped rotor
728 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
729 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); // timeout ? this should never happen
730 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
731 /////////////////////
734 { // use normal turning mode
735 doSetVoltageToneFrontend=false;
737 eSecCommand::rotor cmd;
738 eSecCommand::pair compare;
739 compare.voltage = VOLTAGE(13);
741 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
742 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
743 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
745 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
746 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
747 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
749 compare.voltage = voltage;
751 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
752 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
753 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
755 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
756 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
758 cmd.direction=1; // check for running rotor
763 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 480) ); // 2 minutes running timeout
764 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
765 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
766 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
767 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
769 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
770 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
771 frontend.setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
772 frontend.setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
778 frontend.setData(eDVBFrontend::CSW, csw);
779 frontend.setData(eDVBFrontend::UCSW, ucsw);
780 frontend.setData(eDVBFrontend::TONEBURST, di_param.m_toneburst_param);
782 if (!linked && doSetVoltageToneFrontend)
784 eSecCommand::pair compare;
785 compare.voltage = voltage;
787 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
788 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
789 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
791 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
792 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
797 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
798 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
800 frontend.setSecSequence(sec_sequence);
806 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
810 RESULT eDVBSatelliteEquipmentControl::clear()
812 for (int i=0; i <= m_lnbidx; ++i)
814 m_lnbs[i].m_satellites.clear();
815 m_lnbs[i].tuner_mask = 0;
819 // clear linked tuner configuration
820 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
822 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
823 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
824 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
830 /* LNB Specific Parameters */
831 RESULT eDVBSatelliteEquipmentControl::addLNB()
833 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
834 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
837 eDebug("no more LNB free... cnt is %d", m_lnbidx);
843 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
845 if ( currentLNBValid() )
846 m_lnbs[m_lnbidx].tuner_mask = tunermask;
852 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
854 if ( currentLNBValid() )
855 m_lnbs[m_lnbidx].m_lof_lo = lofl;
861 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
863 if ( currentLNBValid() )
864 m_lnbs[m_lnbidx].m_lof_hi = lofh;
870 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
872 if ( currentLNBValid() )
873 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
879 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
881 if ( currentLNBValid() )
882 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
888 /* DiSEqC Specific Parameters */
889 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
891 if ( currentLNBValid() )
892 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
898 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
900 if ( currentLNBValid() )
901 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
907 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
909 if ( currentLNBValid() )
910 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
916 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
918 if ( currentLNBValid() )
919 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
925 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
927 if ( currentLNBValid() )
928 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
934 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
936 if ( currentLNBValid() )
937 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
943 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
945 if ( currentLNBValid() )
946 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
952 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
954 if ( currentLNBValid() )
955 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
961 /* Rotor Specific Parameters */
962 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
964 if ( currentLNBValid() )
965 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
971 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
973 if ( currentLNBValid() )
974 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
980 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
982 if ( currentLNBValid() )
983 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
989 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
991 if ( currentLNBValid() )
992 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
998 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1000 if ( currentLNBValid() )
1001 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1007 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1009 if ( currentLNBValid() )
1010 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1016 /* Satellite Specific Parameters */
1017 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1019 if ( currentLNBValid() )
1021 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1022 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1023 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1025 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1026 m_lnbs[m_lnbidx].m_satellites.insert(
1027 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1030 m_curSat = ret.first;
1042 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1044 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1045 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1052 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1054 if ( currentLNBValid() )
1056 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1057 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1066 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1068 if ( currentLNBValid() )
1070 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1071 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1082 int orb_pos, lofl, lofh;
1083 sat_compare(int o, int lofl, int lofh)
1084 :orb_pos(o), lofl(lofl), lofh(lofh)
1086 sat_compare(const sat_compare &x)
1087 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1089 bool operator < (const sat_compare & cmp) const
1091 if (orb_pos == cmp.orb_pos)
1093 if ( abs(lofl-cmp.lofl) < 200000 )
1095 if (abs(lofh-cmp.lofh) < 200000)
1097 return lofh<cmp.lofh;
1099 return lofl<cmp.lofl;
1101 return orb_pos < cmp.orb_pos;
1105 PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int tu2)
1111 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1113 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1117 else if (cnt == tu2)
1123 // check for linked tuners
1128 p1->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp);
1130 p1 = (eDVBRegisteredFrontend*)tmp;
1139 p2->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp);
1141 p2 = (eDVBRegisteredFrontend*)tmp;
1151 // check for rotor dependency
1152 p1->m_frontend->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, tmp1);
1154 p1 = (eDVBRegisteredFrontend*)tmp1;
1155 p2->m_frontend->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, tmp2);
1157 p2 = (eDVBRegisteredFrontend*)tmp2;
1160 int tu1_mask = 1 << p1->m_frontend->getID(),
1161 tu2_mask = 1 << p2->m_frontend->getID();
1162 std::set<sat_compare> tu1sats, tu2sats;
1163 std::list<sat_compare> tu1difference, tu2difference;
1164 std::insert_iterator<std::list<sat_compare> > insert1(tu1difference, tu1difference.begin()),
1165 insert2(tu2difference, tu2difference.begin());
1166 for (int idx=0; idx <= m_lnbidx; ++idx )
1168 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
1169 for (std::map<int, eDVBSatelliteSwitchParameters>::iterator sit(lnb_param.m_satellites.begin());
1170 sit != lnb_param.m_satellites.end(); ++sit)
1172 if ( lnb_param.tuner_mask & tu1_mask )
1173 tu1sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1174 if ( lnb_param.tuner_mask & tu2_mask )
1175 tu2sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1178 std::set_difference(tu1sats.begin(), tu1sats.end(),
1179 tu2sats.begin(), tu2sats.end(),
1181 std::set_difference(tu2sats.begin(), tu2sats.end(),
1182 tu1sats.begin(), tu1sats.end(),
1184 if (!tu1sats.empty() || !tu2sats.empty())
1187 ret = PyList_New(2+tu1difference.size()+tu2difference.size());
1189 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu1difference.size()));
1190 for(std::list<sat_compare>::iterator it(tu1difference.begin()); it != tu1difference.end(); ++it)
1191 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1193 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu2difference.size()));
1194 for(std::list<sat_compare>::iterator it(tu2difference.begin()); it != tu2difference.end(); ++it)
1195 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1203 ret = PyList_New(2);
1204 PyList_SET_ITEM(ret, 0, PyInt_FromLong(0));
1205 PyList_SET_ITEM(ret, 1, PyInt_FromLong(0));
1210 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1215 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1218 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1222 else if (cnt == tu2)
1227 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (int)p2);
1228 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (int)p1);
1233 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1238 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1241 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1245 else if (cnt == tu2)
1250 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (int)p2);
1251 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (int)p1);
1257 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1259 return m_rotorMoving;
1262 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)