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 eSecCommand::pair compare;
528 compare.tone = iDVBFrontend::toneOff;
529 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
530 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
531 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
532 compare.voltage = iDVBFrontend::voltageOff;
534 // the next is a check if voltage is switched off.. then we first set a voltage :)
535 // else we set voltage after all diseqc stuff..
536 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
538 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
540 if (rotor_param.m_inputpower_parameters.m_use)
541 compare.voltage = VOLTAGE(18); // in input power mode turn rotor always with 18V (fast)
543 compare.voltage = VOLTAGE(13); // in normal mode start turning with 13V
546 compare.voltage = voltage;
548 // voltage already correct ?
549 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
551 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
552 // voltage was disabled..so we wait a longer time .. for normal switches 750ms should be enough
553 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
555 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
559 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
560 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
570 loops <<= di_param.m_repeats;
572 for ( int i = 0; i < loops;) // fill commands...
574 eDVBDiseqcCommand diseqc;
576 diseqc.data[0] = i ? 0xE1 : 0xE0;
577 diseqc.data[1] = 0x10;
578 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
580 diseqc.data[2] = 0x39;
581 diseqc.data[3] = ucsw;
583 else if ( send_mask & 1 )
585 diseqc.data[2] = 0x38;
586 diseqc.data[3] = csw;
588 else // no committed command confed.. so send uncommitted..
590 diseqc.data[2] = 0x39;
591 diseqc.data[3] = ucsw;
593 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
599 if (diseqc.data[2] == 0x38 && (send_mask & 2))
601 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
605 int delay = di_param.m_repeats ? (120 - 54) / 2 : 120; // standard says 100msek between two repeated commands
606 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
608 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
609 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
612 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
614 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
616 else // delay 120msek when no command is in repeat gap
617 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
620 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
623 if ( send_mask & 8 ) // toneburst at end of sequence
625 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
626 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
631 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
633 eSecCommand::pair compare;
636 compare.voltage = iDVBFrontend::voltageOff;
638 // the next is a check if voltage is switched off.. then we first set a voltage :)
639 // else we set voltage after all diseqc stuff..
640 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
642 if (rotor_param.m_inputpower_parameters.m_use)
643 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
645 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
647 // voltage was disabled..so we wait a longer time ..
648 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
649 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
653 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
654 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
657 eDVBDiseqcCommand diseqc;
659 diseqc.data[0] = 0xE0;
660 diseqc.data[1] = 0x31; // positioner
661 diseqc.data[2] = 0x60; // stop
662 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
663 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
664 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
665 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
666 // wait 300msec after send rotor stop cmd
667 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
669 diseqc.data[0] = 0xE0;
670 diseqc.data[1] = 0x31; // positioner
674 diseqc.data[2] = 0x6E; // drive to angular position
675 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
676 diseqc.data[4] = RotorCmd & 0xFF;
681 diseqc.data[2] = 0x6B; // goto stored sat position
682 diseqc.data[3] = RotorCmd;
683 diseqc.data[4] = 0x00;
686 if ( rotor_param.m_inputpower_parameters.m_use )
687 { // use measure rotor input power to detect rotor state
688 eSecCommand::rotor cmd;
689 eSecCommand::pair compare;
690 compare.voltage = VOLTAGE(18);
692 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
693 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
694 // measure idle power values
695 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
696 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
699 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
700 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
701 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec before measure
702 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
704 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
705 ////////////////////////////
706 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
707 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) ); // 2 retries
708 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
709 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
710 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
712 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
713 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
714 cmd.direction=1; // check for running rotor
715 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
718 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
719 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
720 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
721 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
722 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
724 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) ); // 2 minutes running timeout
725 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
726 // rotor running loop
727 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
728 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
729 cmd.direction=0; // check for stopped rotor
731 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
732 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); // timeout ? this should never happen
733 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
734 /////////////////////
737 { // use normal turning mode
738 doSetVoltageToneFrontend=false;
740 eSecCommand::rotor cmd;
741 eSecCommand::pair compare;
742 compare.voltage = VOLTAGE(13);
744 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
745 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
746 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
748 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
749 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
750 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
752 compare.voltage = voltage;
754 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
755 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
756 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
759 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
760 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
761 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
762 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
764 cmd.direction=1; // check for running rotor
769 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 480) ); // 2 minutes running timeout
770 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
771 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
772 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
773 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
775 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
776 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
777 frontend.setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
778 frontend.setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
784 frontend.setData(eDVBFrontend::CSW, csw);
785 frontend.setData(eDVBFrontend::UCSW, ucsw);
786 frontend.setData(eDVBFrontend::TONEBURST, di_param.m_toneburst_param);
788 if (!linked && doSetVoltageToneFrontend)
790 eSecCommand::pair compare;
791 compare.voltage = voltage;
793 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
794 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
795 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
798 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
799 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
800 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
805 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
806 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
808 frontend.setSecSequence(sec_sequence);
814 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
818 RESULT eDVBSatelliteEquipmentControl::clear()
820 for (int i=0; i <= m_lnbidx; ++i)
822 m_lnbs[i].m_satellites.clear();
823 m_lnbs[i].tuner_mask = 0;
827 // clear linked tuner configuration
828 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
830 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
831 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
832 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
838 /* LNB Specific Parameters */
839 RESULT eDVBSatelliteEquipmentControl::addLNB()
841 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
842 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
845 eDebug("no more LNB free... cnt is %d", m_lnbidx);
851 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
853 if ( currentLNBValid() )
854 m_lnbs[m_lnbidx].tuner_mask = tunermask;
860 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
862 if ( currentLNBValid() )
863 m_lnbs[m_lnbidx].m_lof_lo = lofl;
869 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
871 if ( currentLNBValid() )
872 m_lnbs[m_lnbidx].m_lof_hi = lofh;
878 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
880 if ( currentLNBValid() )
881 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
887 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
889 if ( currentLNBValid() )
890 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
896 /* DiSEqC Specific Parameters */
897 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
899 if ( currentLNBValid() )
900 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
906 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
908 if ( currentLNBValid() )
909 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
915 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
917 if ( currentLNBValid() )
918 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
924 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
926 if ( currentLNBValid() )
927 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
933 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
935 if ( currentLNBValid() )
936 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
942 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
944 if ( currentLNBValid() )
945 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
951 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
953 if ( currentLNBValid() )
954 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
960 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
962 if ( currentLNBValid() )
963 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
969 /* Rotor Specific Parameters */
970 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
972 if ( currentLNBValid() )
973 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
979 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
981 if ( currentLNBValid() )
982 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
988 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
990 if ( currentLNBValid() )
991 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
997 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
999 if ( currentLNBValid() )
1000 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1006 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1008 if ( currentLNBValid() )
1009 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1015 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1017 if ( currentLNBValid() )
1018 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1024 /* Satellite Specific Parameters */
1025 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1027 if ( currentLNBValid() )
1029 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1030 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1031 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1033 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1034 m_lnbs[m_lnbidx].m_satellites.insert(
1035 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1038 m_curSat = ret.first;
1050 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1052 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1053 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1060 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1062 if ( currentLNBValid() )
1064 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1065 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1074 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1076 if ( currentLNBValid() )
1078 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1079 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1090 int orb_pos, lofl, lofh;
1091 sat_compare(int o, int lofl, int lofh)
1092 :orb_pos(o), lofl(lofl), lofh(lofh)
1094 sat_compare(const sat_compare &x)
1095 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1097 bool operator < (const sat_compare & cmp) const
1099 if (orb_pos == cmp.orb_pos)
1101 if ( abs(lofl-cmp.lofl) < 200000 )
1103 if (abs(lofh-cmp.lofh) < 200000)
1105 return lofh<cmp.lofh;
1107 return lofl<cmp.lofl;
1109 return orb_pos < cmp.orb_pos;
1113 PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int tu2)
1119 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1121 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1125 else if (cnt == tu2)
1131 // check for linked tuners
1136 p1->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp);
1138 p1 = (eDVBRegisteredFrontend*)tmp;
1147 p2->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp);
1149 p2 = (eDVBRegisteredFrontend*)tmp;
1159 // check for rotor dependency
1160 p1->m_frontend->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, tmp1);
1162 p1 = (eDVBRegisteredFrontend*)tmp1;
1163 p2->m_frontend->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, tmp2);
1165 p2 = (eDVBRegisteredFrontend*)tmp2;
1168 int tu1_mask = 1 << p1->m_frontend->getID(),
1169 tu2_mask = 1 << p2->m_frontend->getID();
1170 std::set<sat_compare> tu1sats, tu2sats;
1171 std::list<sat_compare> tu1difference, tu2difference;
1172 std::insert_iterator<std::list<sat_compare> > insert1(tu1difference, tu1difference.begin()),
1173 insert2(tu2difference, tu2difference.begin());
1174 for (int idx=0; idx <= m_lnbidx; ++idx )
1176 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
1177 for (std::map<int, eDVBSatelliteSwitchParameters>::iterator sit(lnb_param.m_satellites.begin());
1178 sit != lnb_param.m_satellites.end(); ++sit)
1180 if ( lnb_param.tuner_mask & tu1_mask )
1181 tu1sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1182 if ( lnb_param.tuner_mask & tu2_mask )
1183 tu2sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1186 std::set_difference(tu1sats.begin(), tu1sats.end(),
1187 tu2sats.begin(), tu2sats.end(),
1189 std::set_difference(tu2sats.begin(), tu2sats.end(),
1190 tu1sats.begin(), tu1sats.end(),
1192 if (!tu1sats.empty() || !tu2sats.empty())
1195 ret = PyList_New(2+tu1difference.size()+tu2difference.size());
1197 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu1difference.size()));
1198 for(std::list<sat_compare>::iterator it(tu1difference.begin()); it != tu1difference.end(); ++it)
1199 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1201 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu2difference.size()));
1202 for(std::list<sat_compare>::iterator it(tu2difference.begin()); it != tu2difference.end(); ++it)
1203 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1211 ret = PyList_New(2);
1212 PyList_SET_ITEM(ret, 0, PyInt_FromLong(0));
1213 PyList_SET_ITEM(ret, 1, PyInt_FromLong(0));
1218 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1223 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1226 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1230 else if (cnt == tu2)
1235 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (int)p2);
1236 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (int)p1);
1241 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1246 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1249 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1253 else if (cnt == tu2)
1258 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (int)p2);
1259 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (int)p1);
1265 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1267 return m_rotorMoving;
1270 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)