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(11750000);
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(11750000);
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(11750000);
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 )
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 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
108 lnb_param.m_satellites.find(sat.orbital_position);
109 if ( sit != lnb_param.m_satellites.end())
112 linked_to=-1, // linked tuner
113 satpos_depends_to=-1,
114 csw = di_param.m_committed_cmd,
115 ucsw = di_param.m_uncommitted_cmd,
116 toneburst = di_param.m_toneburst_param,
119 fe->getData(6, curRotorPos);
120 fe->getData(7, linked_to);
121 fe->getData(8, satpos_depends_to);
123 if ( sat.frequency > lnb_param.m_lof_threshold )
125 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
131 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
134 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
135 csw = 0xF0 | (csw << 2);
137 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
140 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
143 if ( curRotorPos == sat.orbital_position )
144 ret=20; // rotor on correct orbpos = prio 20
146 ret=10; // rotor must turn to correct orbpos = prio 10
149 ret = 30; // no rotor = prio 30
154 ret = 40; // no diseqc = prio 40
157 if (linked_to != -1) // check for linked tuners..
159 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
160 if (linked_fe->m_inuse)
166 linked_fe->m_frontend->getData(0, ocsw);
167 linked_fe->m_frontend->getData(1, oucsw);
168 linked_fe->m_frontend->getData(2, oToneburst);
169 linked_fe->m_frontend->getData(6, 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!!");
188 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
192 if (satpos_depends_to != -1) // check for linked tuners..
194 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
195 if ( satpos_depends_to_fe->m_inuse )
198 satpos_depends_to_fe->m_frontend->getData(6, oRotorPos);
199 if (!rotor || oRotorPos != sat.orbital_position)
201 // eDebug("can not tune this transponder ... rotor on other tuner is positioned to %d", oRotorPos);
206 // eDebug("OK .. can tune this transponder satpos is correct :)");
210 int lof = sat.frequency > lnb_param.m_lof_threshold ?
211 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
212 int tuner_freq = abs(sat.frequency - lof);
213 // eDebug("tuner freq %d", tuner_freq);
214 if (tuner_freq < 900000 || tuner_freq > 2200000)
217 // eDebug("Transponder not tuneable with this lnb... %d Khz out of tuner range",
227 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
229 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)
232 bool depend_satpos_mode=false;
234 for (int idx=0; idx <= m_lnbidx; ++idx )
236 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
237 if (!(lnb_param.tuner_mask & frontend_id)) // lnb for correct tuner?
239 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
240 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
242 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
243 lnb_param.m_satellites.find(sat.orbital_position);
244 if ( sit != lnb_param.m_satellites.end())
246 eDVBSatelliteSwitchParameters &sw_param = sit->second;
247 bool doSetVoltageToneFrontend = true;
248 bool doSetFrontend = true;
250 linked_to=-1, // linked tuner
251 satpos_depends_to=-1,
252 voltage = iDVBFrontend::voltageOff,
253 tone = iDVBFrontend::toneOff,
254 csw = di_param.m_committed_cmd,
255 ucsw = di_param.m_uncommitted_cmd,
256 toneburst = di_param.m_toneburst_param,
263 frontend.getData(0, lastcsw);
264 frontend.getData(1, lastucsw);
265 frontend.getData(2, lastToneburst);
266 frontend.getData(5, lastRotorCmd);
267 frontend.getData(6, curRotorPos);
268 frontend.getData(7, linked_to);
269 frontend.getData(8, satpos_depends_to);
273 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
274 if (linked_fe->m_inuse)
276 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
281 if (satpos_depends_to != -1)
283 eDVBRegisteredFrontend *satpos_fe = (eDVBRegisteredFrontend*) satpos_depends_to;
284 if (satpos_fe->m_inuse)
286 if ( di_param.m_diseqc_mode != eDVBSatelliteDiseqcParameters::V1_2 )
288 eDebug("[SEC] frontend is depending on satpos of other one.. so we dont turn rotor!!");
289 depend_satpos_mode=true;
293 if ( sat.frequency > lnb_param.m_lof_threshold )
297 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
299 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
301 parm.FREQUENCY = abs(parm.FREQUENCY);
303 frontend.setData(9, sat.frequency - parm.FREQUENCY);
305 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
308 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
309 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
310 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
311 voltage = VOLTAGE(13);
312 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
313 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
314 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
315 voltage = VOLTAGE(18);
316 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
317 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
318 tone = iDVBFrontend::toneOn;
319 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
320 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
321 tone = iDVBFrontend::toneOff;
323 eSecCommandList sec_sequence;
325 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
327 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
328 csw = 0xF0 | (csw << 2);
330 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
334 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
335 bool changed_csw = send_csw && csw != lastcsw;
338 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
339 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
342 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
343 bool changed_burst = send_burst && toneburst != lastToneburst;
345 int send_mask = 0; /*
348 4 send toneburst first
349 8 send toneburst at end */
350 if (changed_burst) // toneburst first and toneburst changed
352 if (di_param.m_command_order&1)
366 if ((di_param.m_command_order&4) && send_csw)
368 if (di_param.m_command_order==4 && send_burst)
373 if ( di_param.m_use_fast
374 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
376 && ((csw / 4) == (lastcsw / 4)) )
377 eDebug("dont send committed cmd (fast diseqc)");
381 if (!(di_param.m_command_order&4) && send_ucsw)
383 if (!(di_param.m_command_order&1) && send_burst)
389 eDebugNoNewLine("sendmask: ");
390 for (int i=3; i >= 0; --i)
391 if ( send_mask & (1<<i) )
392 eDebugNoNewLine("1");
394 eDebugNoNewLine("0");
399 bool useGotoXX = false;
400 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
402 if (depend_satpos_mode || linked)
403 // in this both modes we dont really turn the rotor.... but in canTune we need the satpos
404 frontend.setData(6, sat.orbital_position);
407 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
408 RotorCmd=sw_param.m_rotorPosNum;
409 else // we must calc gotoxx cmd
411 eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
414 double SatLon = abs(sat.orbital_position)/10.00,
415 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
416 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
418 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
421 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
422 SiteLon = 360 - SiteLon;
424 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
425 double satHourAngle =
426 calcSatHourangle( SatLon, SiteLat, SiteLon );
427 eDebug("PolarmountHourAngle=%lf", satHourAngle );
429 static int gotoXTable[10] =
430 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
432 if (SiteLat >= 0) // Northern Hemisphere
434 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
435 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
437 if (satHourAngle < 180) // the east
442 else // Southern Hemisphere
444 if (satHourAngle < 180) // the east
446 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
447 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
452 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
453 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
457 eDebug("RotorCmd = %04x", RotorCmd);
464 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
465 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
466 eSecCommand::pair compare;
467 compare.voltage = iDVBFrontend::voltageOff;
469 // the next is a check if voltage is switched off.. then we first set a voltage :)
470 // else we set voltage after all diseqc stuff..
471 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
473 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
475 if (rotor_param.m_inputpower_parameters.m_use)
476 compare.voltage = VOLTAGE(18); // in input power mode turn rotor always with 18V (fast)
478 compare.voltage = VOLTAGE(13); // in normal mode start turning with 13V
481 compare.voltage = voltage;
483 // voltage already correct ?
484 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
486 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
487 // voltage was disabled..so we wait a longer time .. for normal switches 200ms should be enough
488 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );
490 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
494 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
495 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
505 for ( int i=0; i < di_param.m_repeats; ++i )
508 for ( int i = 0; i < loops;) // fill commands...
510 eDVBDiseqcCommand diseqc;
512 diseqc.data[0] = i ? 0xE1 : 0xE0;
513 diseqc.data[1] = 0x10;
514 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
516 diseqc.data[2] = 0x39;
517 diseqc.data[3] = ucsw;
519 else if ( send_mask & 1 )
521 diseqc.data[2] = 0x38;
522 diseqc.data[3] = csw;
526 diseqc.data[2] = 0x00;
527 diseqc.data[3] = 0x00;
529 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
535 if (diseqc.data[2] == 0x38 && (send_mask & 2))
537 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
541 static int delay = (120 - 54) / 2; // standard says 100msek between two repeated commands
542 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
544 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
545 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
548 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
550 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
552 else // delay 120msek when no command is in repeat gap
553 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
556 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
559 if ( send_mask & 8 ) // toneburst at end of sequence
561 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
562 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
567 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
569 eSecCommand::pair compare;
570 compare.voltage = iDVBFrontend::voltageOff;
572 // the next is a check if voltage is switched off.. then we first set a voltage :)
573 // else we set voltage after all diseqc stuff..
574 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
576 if (rotor_param.m_inputpower_parameters.m_use)
577 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
579 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
581 // voltage was disabled..so we wait a longer time ..
582 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
583 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +7) ); // no need to send stop rotor cmd
586 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
588 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +1) );
590 eDVBDiseqcCommand diseqc;
592 diseqc.data[0] = 0xE0;
593 diseqc.data[1] = 0x31; // positioner
594 diseqc.data[2] = 0x60; // stop
595 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
596 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
597 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
598 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
599 // wait 300msec after send rotor stop cmd
600 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
602 diseqc.data[0] = 0xE0;
603 diseqc.data[1] = 0x31; // positioner
607 diseqc.data[2] = 0x6E; // drive to angular position
608 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
609 diseqc.data[4] = RotorCmd & 0xFF;
614 diseqc.data[2] = 0x6B; // goto stored sat position
615 diseqc.data[3] = RotorCmd;
616 diseqc.data[4] = 0x00;
619 if ( rotor_param.m_inputpower_parameters.m_use )
620 { // use measure rotor input power to detect rotor state
621 eSecCommand::rotor cmd;
622 eSecCommand::pair compare;
623 compare.voltage = VOLTAGE(18);
625 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
626 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
627 // measure idle power values
628 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
629 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
632 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
633 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
634 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec before measure
635 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
637 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
638 ////////////////////////////
639 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
640 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) ); // 2 retries
641 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
642 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
643 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
645 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
646 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
647 cmd.direction=1; // check for running rotor
648 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
651 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
652 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
653 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
654 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
655 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
657 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) ); // 2 minutes running timeout
658 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
659 // rotor running loop
660 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
661 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
662 cmd.direction=0; // check for stopped rotor
664 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
665 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); // timeout ? this should never happen
666 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
667 /////////////////////
670 { // use normal turning mode
671 doSetVoltageToneFrontend=false;
673 eSecCommand::rotor cmd;
674 eSecCommand::pair compare;
675 compare.voltage = VOLTAGE(13);
677 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
678 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
679 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
681 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
682 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
683 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
685 compare.voltage = voltage;
687 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
688 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
689 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
691 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
692 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
694 cmd.direction=1; // check for running rotor
699 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 480) ); // 2 minutes running timeout
700 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
701 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
702 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
703 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
705 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
706 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
707 frontend.setData(3, RotorCmd);
708 frontend.setData(4, sat.orbital_position);
714 frontend.setData(0, csw);
715 frontend.setData(1, ucsw);
716 frontend.setData(2, di_param.m_toneburst_param);
718 if (!linked && doSetVoltageToneFrontend)
720 eSecCommand::pair compare;
721 compare.voltage = voltage;
723 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
724 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
725 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
727 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
728 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
733 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
734 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
736 frontend.setSecSequence(sec_sequence);
742 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
746 RESULT eDVBSatelliteEquipmentControl::clear()
748 for (int i=0; i <= m_lnbidx; ++i)
750 m_lnbs[i].m_satellites.clear();
751 m_lnbs[i].tuner_mask = 0;
755 // clear linked tuner configuration
756 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
757 it->m_frontend->setData(7, -1);
762 // helper function for setTunerLinked and setTunerDepends
763 RESULT eDVBSatelliteEquipmentControl::setDependencyPointers( int tu1, int tu2, int dest_data_byte )
768 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
771 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
780 p1->m_frontend->setData(dest_data_byte, (int)p2); // this is evil..
781 p2->m_frontend->setData(dest_data_byte, (int)p1);
787 /* LNB Specific Parameters */
788 RESULT eDVBSatelliteEquipmentControl::addLNB()
790 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
791 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
794 eDebug("no more LNB free... cnt is %d", m_lnbidx);
800 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
802 if ( currentLNBValid() )
803 m_lnbs[m_lnbidx].tuner_mask = tunermask;
809 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
811 if ( currentLNBValid() )
812 m_lnbs[m_lnbidx].m_lof_lo = lofl;
818 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
820 if ( currentLNBValid() )
821 m_lnbs[m_lnbidx].m_lof_hi = lofh;
827 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
829 if ( currentLNBValid() )
830 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
836 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
838 if ( currentLNBValid() )
839 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
845 /* DiSEqC Specific Parameters */
846 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
848 if ( currentLNBValid() )
849 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
855 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
857 if ( currentLNBValid() )
858 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
864 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
866 if ( currentLNBValid() )
867 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
873 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
875 if ( currentLNBValid() )
876 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
882 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
884 if ( currentLNBValid() )
885 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
891 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
893 if ( currentLNBValid() )
894 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
900 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
902 if ( currentLNBValid() )
903 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
909 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
911 if ( currentLNBValid() )
912 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
918 /* Rotor Specific Parameters */
919 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
921 if ( currentLNBValid() )
922 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
928 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
930 if ( currentLNBValid() )
931 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
937 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
939 if ( currentLNBValid() )
940 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
946 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
948 if ( currentLNBValid() )
949 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
955 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
957 if ( currentLNBValid() )
958 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
964 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
966 if ( currentLNBValid() )
967 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
973 /* Satellite Specific Parameters */
974 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
976 if ( currentLNBValid() )
978 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
979 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
980 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
982 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
983 m_lnbs[m_lnbidx].m_satellites.insert(
984 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
987 m_curSat = ret.first;
999 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1001 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1002 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1009 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1011 if ( currentLNBValid() )
1013 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1014 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1023 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1025 if ( currentLNBValid() )
1027 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1028 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1039 int orb_pos, lofl, lofh;
1040 sat_compare(int o, int lofl, int lofh)
1041 :orb_pos(o), lofl(lofl), lofh(lofh)
1043 sat_compare(const sat_compare &x)
1044 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1046 bool operator < (const sat_compare & cmp) const
1048 if (orb_pos == cmp.orb_pos)
1050 if ( abs(lofl-cmp.lofl) < 200000 )
1052 if (abs(lofh-cmp.lofh) < 200000)
1054 return lofh<cmp.lofh;
1056 return lofl<cmp.lofl;
1058 return orb_pos < cmp.orb_pos;
1062 PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int tu2)
1066 int tu1_mask = 1 << tu1,
1067 tu2_mask = 1 << tu2;
1071 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1073 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1077 else if (cnt == tu2)
1082 // check for linked tuners
1084 p1->m_frontend->getData(7, tmp1);
1085 p2->m_frontend->getData(7, tmp2);
1086 if ((void*)tmp1 != p2 && (void*)tmp2 != p1)
1088 // check for rotor dependency
1089 p1->m_frontend->getData(8, tmp1);
1090 p2->m_frontend->getData(8, tmp2);
1091 if ((void*)tmp1 != p2 && (void*)tmp2 != p1)
1093 std::set<sat_compare> tu1sats, tu2sats;
1094 std::list<sat_compare> tu1difference, tu2difference;
1095 std::insert_iterator<std::list<sat_compare> > insert1(tu1difference, tu1difference.begin()),
1096 insert2(tu2difference, tu2difference.begin());
1097 for (int idx=0; idx <= m_lnbidx; ++idx )
1099 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
1100 for (std::map<int, eDVBSatelliteSwitchParameters>::iterator sit(lnb_param.m_satellites.begin());
1101 sit != lnb_param.m_satellites.end(); ++sit)
1103 if ( lnb_param.tuner_mask & tu1_mask )
1104 tu1sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1105 if ( lnb_param.tuner_mask & tu2_mask )
1106 tu2sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1109 std::set_difference(tu1sats.begin(), tu1sats.end(),
1110 tu2sats.begin(), tu2sats.end(),
1112 std::set_difference(tu2sats.begin(), tu2sats.end(),
1113 tu1sats.begin(), tu1sats.end(),
1115 if (!tu1sats.empty() || !tu2sats.empty())
1118 ret = PyList_New(2+tu1difference.size()+tu2difference.size());
1120 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu1difference.size()));
1121 for(std::list<sat_compare>::iterator it(tu1difference.begin()); it != tu1difference.end(); ++it)
1122 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1124 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu2difference.size()));
1125 for(std::list<sat_compare>::iterator it(tu2difference.begin()); it != tu2difference.end(); ++it)
1126 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1134 ret = PyList_New(2);
1135 PyList_SET_ITEM(ret, 0, PyInt_FromLong(0));
1136 PyList_SET_ITEM(ret, 1, PyInt_FromLong(0));
1141 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1143 return setDependencyPointers(tu1, tu2, 7);
1146 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1148 return setDependencyPointers(tu1, tu2, 8);
1151 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1153 return m_rotorMoving;
1156 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)