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
155 while (linked_prev_ptr != -1) // check for linked tuners..
157 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
158 if (linked_fe->m_inuse)
164 linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
165 linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
166 linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
167 linked_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
169 eDebug("compare csw %02x == lcsw %02x",
172 eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
173 ucsw, oucsw, toneburst, oToneburst);
175 eDebug("compare pos %d == current pos %d",
176 sat.orbital_position, oRotorPos);
178 if ( (csw != ocsw) ||
179 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
180 ( rotor && oRotorPos != sat.orbital_position ) )
182 // eDebug("can not tune this transponder with linked tuner in use!!");
187 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
189 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
193 while (linked_next_ptr != -1) // check for linked tuners..
195 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
196 if (linked_fe->m_inuse)
202 linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
203 linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
204 linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
205 linked_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
207 eDebug("compare csw %02x == lcsw %02x",
210 eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
211 ucsw, oucsw, toneburst, oToneburst);
213 eDebug("compare pos %d == current pos %d",
214 sat.orbital_position, oRotorPos);
216 if ( (csw != ocsw) ||
217 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
218 ( rotor && oRotorPos != sat.orbital_position ) )
220 // eDebug("can not tune this transponder with linked tuner in use!!");
225 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
227 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
231 if (satpos_depends_ptr != -1)
233 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
234 if ( satpos_depends_to_fe->m_inuse )
237 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
238 if (!rotor || oRotorPos != sat.orbital_position)
240 // eDebug("can not tune this transponder ... rotor on other tuner is positioned to %d", oRotorPos);
245 // eDebug("OK .. can tune this transponder satpos is correct :)");
250 int lof = sat.frequency > lnb_param.m_lof_threshold ?
251 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
252 int tuner_freq = abs(sat.frequency - lof);
253 // eDebug("tuner freq %d", tuner_freq);
254 if (tuner_freq < 900000 || tuner_freq > 2200000)
257 // eDebug("Transponder not tuneable with this lnb... %d Khz out of tuner range",
269 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
271 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)
274 bool depend_satpos_mode=false;
276 for (int idx=0; idx <= m_lnbidx; ++idx )
278 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
279 if (!(lnb_param.tuner_mask & frontend_id)) // lnb for correct tuner?
281 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
282 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
284 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
285 lnb_param.m_satellites.find(sat.orbital_position);
286 if ( sit != lnb_param.m_satellites.end())
288 eDVBSatelliteSwitchParameters &sw_param = sit->second;
289 bool doSetVoltageToneFrontend = true;
290 bool doSetFrontend = true;
292 linked_prev_ptr=-1, // linked tuner
293 linked_next_ptr=-1, // linked tuner
294 satpos_depends_ptr=-1,
295 voltage = iDVBFrontend::voltageOff,
296 tone = iDVBFrontend::toneOff,
297 csw = di_param.m_committed_cmd,
298 ucsw = di_param.m_uncommitted_cmd,
299 toneburst = di_param.m_toneburst_param,
306 frontend.getData(eDVBFrontend::CSW, lastcsw);
307 frontend.getData(eDVBFrontend::UCSW, lastucsw);
308 frontend.getData(eDVBFrontend::TONEBURST, lastToneburst);
309 frontend.getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
310 frontend.getData(eDVBFrontend::ROTOR_POS, curRotorPos);
311 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
312 frontend.getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
313 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
315 while (linked_prev_ptr != -1) // check for linked tuners..
317 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
318 if (linked_fe->m_inuse)
320 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
324 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
328 while (linked_next_ptr != -1) // check for linked tuners..
330 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
331 if (linked_fe->m_inuse)
333 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
337 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
340 if (satpos_depends_ptr != -1)
342 eDVBRegisteredFrontend *satpos_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
343 if (satpos_fe->m_inuse)
345 if ( di_param.m_diseqc_mode != eDVBSatelliteDiseqcParameters::V1_2 )
347 eDebug("[SEC] frontend is depending on satpos of other one.. so we dont turn rotor!!");
348 depend_satpos_mode=true;
352 if ( sat.frequency > lnb_param.m_lof_threshold )
356 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
358 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
360 parm.FREQUENCY = abs(parm.FREQUENCY);
362 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
364 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
367 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
368 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
369 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
370 voltage = VOLTAGE(13);
371 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
372 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
373 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
374 voltage = VOLTAGE(18);
375 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
376 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
377 tone = iDVBFrontend::toneOn;
378 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
379 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
380 tone = iDVBFrontend::toneOff;
382 eSecCommandList sec_sequence;
384 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
386 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
387 csw = 0xF0 | (csw << 2);
389 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
393 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
394 bool changed_csw = send_csw && csw != lastcsw;
397 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
398 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
401 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
402 bool changed_burst = send_burst && toneburst != lastToneburst;
404 int send_mask = 0; /*
407 4 send toneburst first
408 8 send toneburst at end */
409 if (changed_burst) // toneburst first and toneburst changed
411 if (di_param.m_command_order&1)
425 if ((di_param.m_command_order&4) && send_csw)
427 if (di_param.m_command_order==4 && send_burst)
432 if ( di_param.m_use_fast
433 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
435 && ((csw / 4) == (lastcsw / 4)) )
436 eDebug("dont send committed cmd (fast diseqc)");
440 if (!(di_param.m_command_order&4) && send_ucsw)
442 if (!(di_param.m_command_order&1) && send_burst)
448 eDebugNoNewLine("sendmask: ");
449 for (int i=3; i >= 0; --i)
450 if ( send_mask & (1<<i) )
451 eDebugNoNewLine("1");
453 eDebugNoNewLine("0");
458 bool useGotoXX = false;
459 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
460 && !sat.no_rotor_command_on_tune )
462 if (depend_satpos_mode || linked)
463 // in this both modes we dont really turn the rotor.... but in canTune we need the satpos
464 frontend.setData(eDVBFrontend::ROTOR_POS, sat.orbital_position);
467 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
468 RotorCmd=sw_param.m_rotorPosNum;
469 else // we must calc gotoxx cmd
471 eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
474 double SatLon = abs(sat.orbital_position)/10.00,
475 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
476 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
478 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
481 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
482 SiteLon = 360 - SiteLon;
484 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
485 double satHourAngle =
486 calcSatHourangle( SatLon, SiteLat, SiteLon );
487 eDebug("PolarmountHourAngle=%lf", satHourAngle );
489 static int gotoXTable[10] =
490 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
492 if (SiteLat >= 0) // Northern Hemisphere
494 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
495 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
497 if (satHourAngle < 180) // the east
502 else // Southern Hemisphere
504 if (satHourAngle < 180) // the east
506 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
507 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
512 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
513 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
517 eDebug("RotorCmd = %04x", RotorCmd);
524 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
525 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
526 eSecCommand::pair compare;
527 compare.voltage = iDVBFrontend::voltageOff;
529 // the next is a check if voltage is switched off.. then we first set a voltage :)
530 // else we set voltage after all diseqc stuff..
531 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
533 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
535 if (rotor_param.m_inputpower_parameters.m_use)
536 compare.voltage = VOLTAGE(18); // in input power mode turn rotor always with 18V (fast)
538 compare.voltage = VOLTAGE(13); // in normal mode start turning with 13V
541 compare.voltage = voltage;
543 // voltage already correct ?
544 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
546 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
547 // voltage was disabled..so we wait a longer time .. for normal switches 750ms should be enough
548 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
550 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
554 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
555 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
565 for ( int i=0; i < di_param.m_repeats; ++i )
568 for ( int i = 0; i < loops;) // fill commands...
570 eDVBDiseqcCommand diseqc;
572 diseqc.data[0] = i ? 0xE1 : 0xE0;
573 diseqc.data[1] = 0x10;
574 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
576 diseqc.data[2] = 0x39;
577 diseqc.data[3] = ucsw;
579 else if ( send_mask & 1 )
581 diseqc.data[2] = 0x38;
582 diseqc.data[3] = csw;
584 else // no committed command confed.. so send uncommitted..
586 diseqc.data[2] = 0x39;
587 diseqc.data[3] = ucsw;
589 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
595 if (diseqc.data[2] == 0x38 && (send_mask & 2))
597 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
601 static int delay = (120 - 54) / 2; // standard says 100msek between two repeated commands
602 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
604 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
605 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
608 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
610 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
612 else // delay 120msek when no command is in repeat gap
613 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
616 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
619 if ( send_mask & 8 ) // toneburst at end of sequence
621 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
622 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
627 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
629 eSecCommand::pair compare;
632 compare.voltage = iDVBFrontend::voltageOff;
634 // the next is a check if voltage is switched off.. then we first set a voltage :)
635 // else we set voltage after all diseqc stuff..
636 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
638 if (rotor_param.m_inputpower_parameters.m_use)
639 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
641 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
643 // voltage was disabled..so we wait a longer time ..
644 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
645 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +8) ); // no need to send stop rotor cmd and recheck voltage
649 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
650 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +8) ); // no need to send stop rotor cmd and recheck voltage
653 eDVBDiseqcCommand diseqc;
655 diseqc.data[0] = 0xE0;
656 diseqc.data[1] = 0x31; // positioner
657 diseqc.data[2] = 0x60; // stop
658 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
659 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
660 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
661 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
662 // wait 300msec after send rotor stop cmd
663 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
665 diseqc.data[0] = 0xE0;
666 diseqc.data[1] = 0x31; // positioner
670 diseqc.data[2] = 0x6E; // drive to angular position
671 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
672 diseqc.data[4] = RotorCmd & 0xFF;
677 diseqc.data[2] = 0x6B; // goto stored sat position
678 diseqc.data[3] = RotorCmd;
679 diseqc.data[4] = 0x00;
682 if ( rotor_param.m_inputpower_parameters.m_use )
683 { // use measure rotor input power to detect rotor state
684 eSecCommand::rotor cmd;
685 eSecCommand::pair compare;
686 compare.voltage = VOLTAGE(18);
688 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
689 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
690 // measure idle power values
691 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
692 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
695 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
696 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
697 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec before measure
698 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
700 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
701 ////////////////////////////
702 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
703 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) ); // 2 retries
704 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
705 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
706 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
708 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
709 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
710 cmd.direction=1; // check for running rotor
711 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
714 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
715 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
716 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
717 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
718 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
720 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) ); // 2 minutes running timeout
721 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
722 // rotor running loop
723 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
724 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
725 cmd.direction=0; // check for stopped rotor
727 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
728 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); // timeout ? this should never happen
729 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
730 /////////////////////
733 { // use normal turning mode
734 doSetVoltageToneFrontend=false;
736 eSecCommand::rotor cmd;
737 eSecCommand::pair compare;
738 compare.voltage = VOLTAGE(13);
740 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
741 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
742 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
744 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
745 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
746 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
748 compare.voltage = voltage;
750 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
751 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
752 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
754 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
755 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
757 cmd.direction=1; // check for running rotor
762 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 480) ); // 2 minutes running timeout
763 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
764 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
765 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
766 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
768 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
769 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
770 frontend.setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
771 frontend.setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
777 frontend.setData(eDVBFrontend::CSW, csw);
778 frontend.setData(eDVBFrontend::UCSW, ucsw);
779 frontend.setData(eDVBFrontend::TONEBURST, di_param.m_toneburst_param);
781 if (!linked && doSetVoltageToneFrontend)
783 eSecCommand::pair compare;
784 compare.voltage = voltage;
786 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
787 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
788 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
790 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
791 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
796 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
797 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
799 frontend.setSecSequence(sec_sequence);
805 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
809 RESULT eDVBSatelliteEquipmentControl::clear()
811 for (int i=0; i <= m_lnbidx; ++i)
813 m_lnbs[i].m_satellites.clear();
814 m_lnbs[i].tuner_mask = 0;
818 // clear linked tuner configuration
819 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
821 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
822 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
823 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
829 /* LNB Specific Parameters */
830 RESULT eDVBSatelliteEquipmentControl::addLNB()
832 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
833 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
836 eDebug("no more LNB free... cnt is %d", m_lnbidx);
842 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
844 if ( currentLNBValid() )
845 m_lnbs[m_lnbidx].tuner_mask = tunermask;
851 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
853 if ( currentLNBValid() )
854 m_lnbs[m_lnbidx].m_lof_lo = lofl;
860 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
862 if ( currentLNBValid() )
863 m_lnbs[m_lnbidx].m_lof_hi = lofh;
869 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
871 if ( currentLNBValid() )
872 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
878 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
880 if ( currentLNBValid() )
881 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
887 /* DiSEqC Specific Parameters */
888 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
890 if ( currentLNBValid() )
891 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
897 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
899 if ( currentLNBValid() )
900 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
906 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
908 if ( currentLNBValid() )
909 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
915 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
917 if ( currentLNBValid() )
918 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
924 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
926 if ( currentLNBValid() )
927 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
933 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
935 if ( currentLNBValid() )
936 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
942 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
944 if ( currentLNBValid() )
945 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
951 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
953 if ( currentLNBValid() )
954 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
960 /* Rotor Specific Parameters */
961 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
963 if ( currentLNBValid() )
964 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
970 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
972 if ( currentLNBValid() )
973 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
979 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
981 if ( currentLNBValid() )
982 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
988 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
990 if ( currentLNBValid() )
991 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
997 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
999 if ( currentLNBValid() )
1000 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1006 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1008 if ( currentLNBValid() )
1009 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1015 /* Satellite Specific Parameters */
1016 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1018 if ( currentLNBValid() )
1020 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1021 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1022 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1024 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1025 m_lnbs[m_lnbidx].m_satellites.insert(
1026 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1029 m_curSat = ret.first;
1041 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1043 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1044 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1051 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1053 if ( currentLNBValid() )
1055 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1056 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1065 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1067 if ( currentLNBValid() )
1069 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1070 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1081 int orb_pos, lofl, lofh;
1082 sat_compare(int o, int lofl, int lofh)
1083 :orb_pos(o), lofl(lofl), lofh(lofh)
1085 sat_compare(const sat_compare &x)
1086 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1088 bool operator < (const sat_compare & cmp) const
1090 if (orb_pos == cmp.orb_pos)
1092 if ( abs(lofl-cmp.lofl) < 200000 )
1094 if (abs(lofh-cmp.lofh) < 200000)
1096 return lofh<cmp.lofh;
1098 return lofl<cmp.lofl;
1100 return orb_pos < cmp.orb_pos;
1104 PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int tu2)
1110 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1112 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1116 else if (cnt == tu2)
1122 // check for linked tuners
1127 p1->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp);
1129 p1 = (eDVBRegisteredFrontend*)tmp;
1138 p2->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp);
1140 p2 = (eDVBRegisteredFrontend*)tmp;
1150 // check for rotor dependency
1151 p1->m_frontend->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, tmp1);
1153 p1 = (eDVBRegisteredFrontend*)tmp1;
1154 p2->m_frontend->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, tmp2);
1156 p2 = (eDVBRegisteredFrontend*)tmp2;
1159 int tu1_mask = 1 << p1->m_frontend->getID(),
1160 tu2_mask = 1 << p2->m_frontend->getID();
1161 std::set<sat_compare> tu1sats, tu2sats;
1162 std::list<sat_compare> tu1difference, tu2difference;
1163 std::insert_iterator<std::list<sat_compare> > insert1(tu1difference, tu1difference.begin()),
1164 insert2(tu2difference, tu2difference.begin());
1165 for (int idx=0; idx <= m_lnbidx; ++idx )
1167 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
1168 for (std::map<int, eDVBSatelliteSwitchParameters>::iterator sit(lnb_param.m_satellites.begin());
1169 sit != lnb_param.m_satellites.end(); ++sit)
1171 if ( lnb_param.tuner_mask & tu1_mask )
1172 tu1sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1173 if ( lnb_param.tuner_mask & tu2_mask )
1174 tu2sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1177 std::set_difference(tu1sats.begin(), tu1sats.end(),
1178 tu2sats.begin(), tu2sats.end(),
1180 std::set_difference(tu2sats.begin(), tu2sats.end(),
1181 tu1sats.begin(), tu1sats.end(),
1183 if (!tu1sats.empty() || !tu2sats.empty())
1186 ret = PyList_New(2+tu1difference.size()+tu2difference.size());
1188 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu1difference.size()));
1189 for(std::list<sat_compare>::iterator it(tu1difference.begin()); it != tu1difference.end(); ++it)
1190 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1192 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu2difference.size()));
1193 for(std::list<sat_compare>::iterator it(tu2difference.begin()); it != tu2difference.end(); ++it)
1194 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1202 ret = PyList_New(2);
1203 PyList_SET_ITEM(ret, 0, PyInt_FromLong(0));
1204 PyList_SET_ITEM(ret, 1, PyInt_FromLong(0));
1209 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1214 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1217 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1221 else if (cnt == tu2)
1226 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (int)p2);
1227 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (int)p1);
1232 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1237 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1240 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1244 else if (cnt == tu2)
1249 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (int)p2);
1250 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (int)p1);
1256 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1258 return m_rotorMoving;
1261 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)