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 static void checkLinkedParams(int direction, int &linked_ptr, int &ret, const eDVBFrontendParametersSatellite &sat, int csw, int ucsw, int toneburst, bool diseqc, bool rotor)
98 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_ptr;
100 linked_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
101 if (linked_fe->m_inuse)
106 linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
107 linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
108 linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
110 eDebug("compare csw %02x == lcsw %02x",
113 eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
114 ucsw, oucsw, toneburst, oToneburst);
116 eDebug("compare pos %d == current pos %d",
117 sat.orbital_position, oRotorPos);
119 if ( (csw != ocsw) ||
120 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
121 ( rotor && oRotorPos != sat.orbital_position ) )
123 // eDebug("can not tune this transponder with linked tuner in use!!");
127 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
129 else if (rotor && oRotorPos != -1)
131 ret -= abs(oRotorPos-sat.orbital_position);
132 // eDebug("decrement rotor pos for linked tuner!!");
134 linked_fe->m_frontend->getData(direction, linked_ptr);
137 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int frontend_id )
139 int ret=0, satcount=0;
141 for (int idx=0; idx <= m_lnbidx; ++idx )
144 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
145 if ( lnb_param.tuner_mask & frontend_id ) // lnb for correct tuner?
147 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
149 satcount += lnb_param.m_satellites.size();
151 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
152 lnb_param.m_satellites.find(sat.orbital_position);
153 if ( sit != lnb_param.m_satellites.end())
158 satpos_depends_ptr=-1,
159 csw = di_param.m_committed_cmd,
160 ucsw = di_param.m_uncommitted_cmd,
161 toneburst = di_param.m_toneburst_param,
164 fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
165 fe->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
166 fe->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
167 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
169 if ( sat.frequency > lnb_param.m_lof_threshold )
171 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
176 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
179 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
180 csw = 0xF0 | (csw << 2);
182 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
185 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
189 if (rotor && curRotorPos != -1)
190 ret -= abs(curRotorPos-sat.orbital_position);
198 while (ret && linked_prev_ptr != -1) // check for linked tuners..
199 checkLinkedParams(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr, ret, sat, csw, ucsw, toneburst, diseqc, rotor);
201 while (ret && linked_next_ptr != -1) // check for linked tuners..
202 checkLinkedParams(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr, ret, sat, csw, ucsw, toneburst, diseqc, rotor);
205 if (satpos_depends_ptr != -1)
207 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
208 if ( satpos_depends_to_fe->m_inuse )
211 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
212 if (!rotor || oRotorPos != sat.orbital_position)
214 // eDebug("can not tune this transponder ... rotor on other tuner is positioned to %d", oRotorPos);
219 // eDebug("OK .. can tune this transponder satpos is correct :)");
224 int lof = sat.frequency > lnb_param.m_lof_threshold ?
225 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
226 int tuner_freq = abs(sat.frequency - lof);
227 // eDebug("tuner freq %d", tuner_freq);
228 if (tuner_freq < 900000 || tuner_freq > 2200000)
231 // eDebug("Transponder not tuneable with this lnb... %d Khz out of tuner range",
243 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
245 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)
248 bool depend_satpos_mode=false;
250 for (int idx=0; idx <= m_lnbidx; ++idx )
252 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
253 if (!(lnb_param.tuner_mask & frontend_id)) // lnb for correct tuner?
255 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
256 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
258 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
259 lnb_param.m_satellites.find(sat.orbital_position);
260 if ( sit != lnb_param.m_satellites.end())
262 eDVBSatelliteSwitchParameters &sw_param = sit->second;
263 bool doSetVoltageToneFrontend = true;
264 bool doSetFrontend = true;
266 linked_prev_ptr=-1, // linked tuner
267 linked_next_ptr=-1, // linked tuner
268 satpos_depends_ptr=-1,
269 voltage = iDVBFrontend::voltageOff,
270 tone = iDVBFrontend::toneOff,
271 csw = di_param.m_committed_cmd,
272 ucsw = di_param.m_uncommitted_cmd,
273 toneburst = di_param.m_toneburst_param,
280 frontend.getData(eDVBFrontend::CSW, lastcsw);
281 frontend.getData(eDVBFrontend::UCSW, lastucsw);
282 frontend.getData(eDVBFrontend::TONEBURST, lastToneburst);
283 frontend.getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
284 frontend.getData(eDVBFrontend::ROTOR_POS, curRotorPos);
285 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
286 frontend.getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
287 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
289 while (linked_prev_ptr != -1) // check for linked tuners..
291 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
292 if (linked_fe->m_inuse)
294 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
298 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
302 while (linked_next_ptr != -1) // check for linked tuners..
304 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
305 if (linked_fe->m_inuse)
307 eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
311 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
314 if (satpos_depends_ptr != -1)
316 eDVBRegisteredFrontend *satpos_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
317 if (satpos_fe->m_inuse)
319 if ( di_param.m_diseqc_mode != eDVBSatelliteDiseqcParameters::V1_2 )
321 eDebug("[SEC] frontend is depending on satpos of other one.. so we dont turn rotor!!");
322 depend_satpos_mode=true;
326 if ( sat.frequency > lnb_param.m_lof_threshold )
330 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
332 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
334 parm.FREQUENCY = abs(parm.FREQUENCY);
336 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
338 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
341 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
342 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
343 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
344 voltage = VOLTAGE(13);
345 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
346 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
347 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
348 voltage = VOLTAGE(18);
349 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
350 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
351 tone = iDVBFrontend::toneOn;
352 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
353 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
354 tone = iDVBFrontend::toneOff;
356 eSecCommandList sec_sequence;
358 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
360 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
361 csw = 0xF0 | (csw << 2);
363 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
367 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
368 bool changed_csw = send_csw && csw != lastcsw;
371 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
372 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
375 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
376 bool changed_burst = send_burst && toneburst != lastToneburst;
378 int send_mask = 0; /*
381 4 send toneburst first
382 8 send toneburst at end */
383 if (changed_burst) // toneburst first and toneburst changed
385 if (di_param.m_command_order&1)
399 if ((di_param.m_command_order&4) && send_csw)
401 if (di_param.m_command_order==4 && send_burst)
406 if ( di_param.m_use_fast
407 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
409 && ((csw / 4) == (lastcsw / 4)) )
410 eDebug("dont send committed cmd (fast diseqc)");
414 if (!(di_param.m_command_order&4) && send_ucsw)
416 if (!(di_param.m_command_order&1) && send_burst)
422 eDebugNoNewLine("sendmask: ");
423 for (int i=3; i >= 0; --i)
424 if ( send_mask & (1<<i) )
425 eDebugNoNewLine("1");
427 eDebugNoNewLine("0");
432 bool useGotoXX = false;
433 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
434 && !sat.no_rotor_command_on_tune )
436 if (depend_satpos_mode || linked)
437 // in this both modes we dont really turn the rotor.... but in canTune we need the satpos
438 frontend.setData(eDVBFrontend::ROTOR_POS, sat.orbital_position);
441 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
442 RotorCmd=sw_param.m_rotorPosNum;
443 else // we must calc gotoxx cmd
445 eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
448 double SatLon = abs(sat.orbital_position)/10.00,
449 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
450 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
452 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
455 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
456 SiteLon = 360 - SiteLon;
458 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
459 double satHourAngle =
460 calcSatHourangle( SatLon, SiteLat, SiteLon );
461 eDebug("PolarmountHourAngle=%lf", satHourAngle );
463 static int gotoXTable[10] =
464 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
466 if (SiteLat >= 0) // Northern Hemisphere
468 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
469 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
471 if (satHourAngle < 180) // the east
476 else // Southern Hemisphere
478 if (satHourAngle < 180) // the east
480 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
481 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
486 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
487 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
491 eDebug("RotorCmd = %04x", RotorCmd);
498 eSecCommand::pair compare;
500 compare.tone = iDVBFrontend::toneOff;
501 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
502 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
503 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
504 compare.voltage = iDVBFrontend::voltageOff;
506 // the next is a check if voltage is switched off.. then we first set a voltage :)
507 // else we set voltage after all diseqc stuff..
508 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
510 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
512 if (rotor_param.m_inputpower_parameters.m_use)
513 compare.voltage = VOLTAGE(18); // in input power mode turn rotor always with 18V (fast)
515 compare.voltage = VOLTAGE(13); // in normal mode start turning with 13V
518 compare.voltage = voltage;
520 // voltage already correct ?
521 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
523 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
524 // voltage was disabled..so we wait a longer time .. for normal switches 750ms should be enough
525 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
527 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
531 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
532 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
542 loops <<= di_param.m_repeats;
544 for ( int i = 0; i < loops;) // fill commands...
546 eDVBDiseqcCommand diseqc;
548 diseqc.data[0] = i ? 0xE1 : 0xE0;
549 diseqc.data[1] = 0x10;
550 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
552 diseqc.data[2] = 0x39;
553 diseqc.data[3] = ucsw;
555 else if ( send_mask & 1 )
557 diseqc.data[2] = 0x38;
558 diseqc.data[3] = csw;
560 else // no committed command confed.. so send uncommitted..
562 diseqc.data[2] = 0x39;
563 diseqc.data[3] = ucsw;
565 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
571 if (diseqc.data[2] == 0x38 && (send_mask & 2))
573 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
577 int delay = di_param.m_repeats ? (120 - 54) / 2 : 120; // standard says 100msek between two repeated commands
578 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
580 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
581 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
584 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
586 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
588 else // delay 120msek when no command is in repeat gap
589 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
592 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
595 if ( send_mask & 8 ) // toneburst at end of sequence
597 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
598 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
603 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
605 eSecCommand::pair compare;
609 compare.tone = iDVBFrontend::toneOff;
610 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
611 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
612 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
614 compare.voltage = iDVBFrontend::voltageOff;
616 // the next is a check if voltage is switched off.. then we first set a voltage :)
617 // else we set voltage after all diseqc stuff..
618 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
620 if (rotor_param.m_inputpower_parameters.m_use)
621 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
623 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // turn always with 18V
625 // voltage was disabled..so we wait a longer time ..
626 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
627 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
631 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
632 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
635 eDVBDiseqcCommand diseqc;
637 diseqc.data[0] = 0xE0;
638 diseqc.data[1] = 0x31; // positioner
639 diseqc.data[2] = 0x60; // stop
640 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
641 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
642 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
643 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
644 // wait 300msec after send rotor stop cmd
645 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
647 diseqc.data[0] = 0xE0;
648 diseqc.data[1] = 0x31; // positioner
652 diseqc.data[2] = 0x6E; // drive to angular position
653 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
654 diseqc.data[4] = RotorCmd & 0xFF;
659 diseqc.data[2] = 0x6B; // goto stored sat position
660 diseqc.data[3] = RotorCmd;
661 diseqc.data[4] = 0x00;
664 if ( rotor_param.m_inputpower_parameters.m_use )
665 { // use measure rotor input power to detect rotor state
666 eSecCommand::rotor cmd;
667 eSecCommand::pair compare;
668 compare.voltage = VOLTAGE(18);
670 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
671 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
672 // measure idle power values
673 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
674 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
677 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
678 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
679 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec before measure
680 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
682 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
683 ////////////////////////////
684 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
685 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) ); // 2 retries
686 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
687 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
688 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
690 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
691 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
692 cmd.direction=1; // check for running rotor
693 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
696 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
697 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
698 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
699 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
700 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
702 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) ); // 2 minutes running timeout
703 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
704 // rotor running loop
705 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
706 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
707 cmd.direction=0; // check for stopped rotor
709 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
710 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); // timeout ? this should never happen
711 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
712 /////////////////////
715 { // use normal turning mode
716 doSetVoltageToneFrontend=false;
718 eSecCommand::rotor cmd;
719 eSecCommand::pair compare;
720 compare.voltage = VOLTAGE(13);
722 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
723 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
724 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) ); // wait 200msec after voltage change
726 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
727 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
728 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
730 compare.voltage = voltage;
732 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
733 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
734 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
737 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
738 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
739 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
740 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
742 cmd.direction=1; // check for running rotor
747 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 480) ); // 2 minutes running timeout
748 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
749 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
750 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
751 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
753 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
754 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
755 frontend.setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
756 frontend.setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
762 frontend.setData(eDVBFrontend::CSW, csw);
763 frontend.setData(eDVBFrontend::UCSW, ucsw);
764 frontend.setData(eDVBFrontend::TONEBURST, di_param.m_toneburst_param);
766 if (!linked && doSetVoltageToneFrontend)
768 eSecCommand::pair compare;
769 compare.voltage = voltage;
771 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
772 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
773 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
776 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
777 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
778 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
783 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
784 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
786 frontend.setSecSequence(sec_sequence);
792 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
796 RESULT eDVBSatelliteEquipmentControl::clear()
798 for (int i=0; i <= m_lnbidx; ++i)
800 m_lnbs[i].m_satellites.clear();
801 m_lnbs[i].tuner_mask = 0;
805 // clear linked tuner configuration
806 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
808 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
809 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
810 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
816 /* LNB Specific Parameters */
817 RESULT eDVBSatelliteEquipmentControl::addLNB()
819 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
820 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
823 eDebug("no more LNB free... cnt is %d", m_lnbidx);
829 RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
831 if ( currentLNBValid() )
832 m_lnbs[m_lnbidx].tuner_mask = tunermask;
838 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
840 if ( currentLNBValid() )
841 m_lnbs[m_lnbidx].m_lof_lo = lofl;
847 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
849 if ( currentLNBValid() )
850 m_lnbs[m_lnbidx].m_lof_hi = lofh;
856 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
858 if ( currentLNBValid() )
859 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
865 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
867 if ( currentLNBValid() )
868 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
874 /* DiSEqC Specific Parameters */
875 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
877 if ( currentLNBValid() )
878 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
884 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
886 if ( currentLNBValid() )
887 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
893 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
895 if ( currentLNBValid() )
896 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
902 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
904 if ( currentLNBValid() )
905 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
911 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
913 if ( currentLNBValid() )
914 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
920 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
922 if ( currentLNBValid() )
923 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
929 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
931 if ( currentLNBValid() )
932 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
938 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
940 if ( currentLNBValid() )
941 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
947 /* Rotor Specific Parameters */
948 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
950 if ( currentLNBValid() )
951 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
957 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
959 if ( currentLNBValid() )
960 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
966 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
968 if ( currentLNBValid() )
969 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
975 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
977 if ( currentLNBValid() )
978 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
984 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
986 if ( currentLNBValid() )
987 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
993 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
995 if ( currentLNBValid() )
996 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1002 /* Satellite Specific Parameters */
1003 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1005 if ( currentLNBValid() )
1007 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1008 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1009 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1011 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1012 m_lnbs[m_lnbidx].m_satellites.insert(
1013 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1016 m_curSat = ret.first;
1028 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1030 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1031 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1038 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1040 if ( currentLNBValid() )
1042 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1043 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1052 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1054 if ( currentLNBValid() )
1056 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1057 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1068 int orb_pos, lofl, lofh;
1069 sat_compare(int o, int lofl, int lofh)
1070 :orb_pos(o), lofl(lofl), lofh(lofh)
1072 sat_compare(const sat_compare &x)
1073 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1075 bool operator < (const sat_compare & cmp) const
1077 if (orb_pos == cmp.orb_pos)
1079 if ( abs(lofl-cmp.lofl) < 200000 )
1081 if (abs(lofh-cmp.lofh) < 200000)
1083 return lofh<cmp.lofh;
1085 return lofl<cmp.lofl;
1087 return orb_pos < cmp.orb_pos;
1091 PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int tu2)
1097 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1099 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1103 else if (cnt == tu2)
1109 // check for linked tuners
1114 p1->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp);
1116 p1 = (eDVBRegisteredFrontend*)tmp;
1125 p2->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp);
1127 p2 = (eDVBRegisteredFrontend*)tmp;
1137 // check for rotor dependency
1138 p1->m_frontend->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, tmp1);
1140 p1 = (eDVBRegisteredFrontend*)tmp1;
1141 p2->m_frontend->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, tmp2);
1143 p2 = (eDVBRegisteredFrontend*)tmp2;
1146 int tu1_mask = 1 << p1->m_frontend->getID(),
1147 tu2_mask = 1 << p2->m_frontend->getID();
1148 std::set<sat_compare> tu1sats, tu2sats;
1149 std::list<sat_compare> tu1difference, tu2difference;
1150 std::insert_iterator<std::list<sat_compare> > insert1(tu1difference, tu1difference.begin()),
1151 insert2(tu2difference, tu2difference.begin());
1152 for (int idx=0; idx <= m_lnbidx; ++idx )
1154 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
1155 for (std::map<int, eDVBSatelliteSwitchParameters>::iterator sit(lnb_param.m_satellites.begin());
1156 sit != lnb_param.m_satellites.end(); ++sit)
1158 if ( lnb_param.tuner_mask & tu1_mask )
1159 tu1sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1160 if ( lnb_param.tuner_mask & tu2_mask )
1161 tu2sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
1164 std::set_difference(tu1sats.begin(), tu1sats.end(),
1165 tu2sats.begin(), tu2sats.end(),
1167 std::set_difference(tu2sats.begin(), tu2sats.end(),
1168 tu1sats.begin(), tu1sats.end(),
1170 if (!tu1sats.empty() || !tu2sats.empty())
1173 ret = PyList_New(2+tu1difference.size()+tu2difference.size());
1175 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu1difference.size()));
1176 for(std::list<sat_compare>::iterator it(tu1difference.begin()); it != tu1difference.end(); ++it)
1177 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1179 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu2difference.size()));
1180 for(std::list<sat_compare>::iterator it(tu2difference.begin()); it != tu2difference.end(); ++it)
1181 PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
1189 ret = PyList_New(2);
1190 PyList_SET_ITEM(ret, 0, PyInt_FromLong(0));
1191 PyList_SET_ITEM(ret, 1, PyInt_FromLong(0));
1196 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1200 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1203 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1207 else if (cnt == tu2)
1212 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (int)p2);
1213 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (int)p1);
1220 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1225 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1228 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
1232 else if (cnt == tu2)
1237 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (int)p2);
1238 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (int)p1);
1244 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1246 return m_rotorMoving;
1249 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)