1 #include <lib/dvb/dvb.h>
2 #include <lib/dvb/sec.h>
3 #include <lib/dvb/rotor_calc.h>
4 #include <lib/dvb/dvbtime.h>
8 #if HAVE_DVB_API_VERSION < 3
9 #define FREQUENCY Frequency
11 #define FREQUENCY frequency
13 #include <lib/base/eerror.h>
18 #define eSecDebug(arg...) eDebug(arg)
20 #define eSecDebug(arg...)
23 DEFINE_REF(eDVBSatelliteEquipmentControl);
25 eDVBSatelliteEquipmentControl *eDVBSatelliteEquipmentControl::instance;
27 int eDVBSatelliteEquipmentControl::m_params[MAX_PARAMS];
29 defaults are set in python lib/python/Components/NimManager.py
30 in InitSecParams function via setParam call
33 void eDVBSatelliteEquipmentControl::setParam(int param, int value)
35 if (param >= 0 && param < MAX_PARAMS)
36 m_params[param]=value;
39 eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBRegisteredFrontend> &avail_frontends)
40 :m_lnbidx(-1), m_curSat(m_lnbs[0].m_satellites.end()), m_avail_frontends(avail_frontends), m_rotorMoving(false)
51 setLNBThreshold(11700000);
53 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
54 setToneburst(eDVBSatelliteDiseqcParameters::NO);
56 setCommittedCommand(eDVBSatelliteDiseqcParameters::BB);
57 setCommandOrder(0); // committed, toneburst
61 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
62 setToneMode(eDVBSatelliteSwitchParameters::HILO);
68 setLNBThreshold(11700000);
70 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_0);
71 setToneburst(eDVBSatelliteDiseqcParameters::NO);
73 setCommittedCommand(eDVBSatelliteDiseqcParameters::AB);
74 setCommandOrder(0); // committed, toneburst
78 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
79 setToneMode(eDVBSatelliteSwitchParameters::HILO);
85 setLNBThreshold(11700000);
87 setDiSEqCMode(eDVBSatelliteDiseqcParameters::V1_2);
88 setToneburst(eDVBSatelliteDiseqcParameters::NO);
90 setCommittedCommand(eDVBSatelliteDiseqcParameters::AA);
91 setCommandOrder(0); // committed, toneburst
94 setLaDirection(eDVBSatelliteRotorParameters::NORTH);
95 setLoDirection(eDVBSatelliteRotorParameters::EAST);
98 setUseInputpower(true);
99 setInputpowerDelta(50);
102 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
103 setToneMode(eDVBSatelliteSwitchParameters::HILO);
107 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
108 setToneMode(eDVBSatelliteSwitchParameters::HILO);
112 setVoltageMode(eDVBSatelliteSwitchParameters::HV);
113 setToneMode(eDVBSatelliteSwitchParameters::HILO);
114 setRotorPosNum(1); // stored pos 1
117 static void checkLinkedParams(int direction, long &linked_ptr, int &ret, const eDVBFrontendParametersSatellite &sat, int csw, int ucsw, int toneburst, bool diseqc, bool rotor, int RotorPos)
119 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_ptr;
120 if (linked_fe->m_inuse)
125 linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
126 linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
127 linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
129 eDebug("compare csw %02x == lcsw %02x",
132 eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
133 ucsw, oucsw, toneburst, oToneburst);
135 eDebug("compare pos %d == current pos %d",
136 sat.orbital_position, oRotorPos);
138 if ( (csw != ocsw) ||
139 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
140 ( rotor && RotorPos != sat.orbital_position ) )
142 // eDebug("can not tune this transponder with linked tuner in use!!");
146 // eDebug("OK .. can tune this transponder with linked tuner in use :)");
148 linked_fe->m_frontend->getData(direction, (long&)linked_ptr);
151 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int slot_id )
153 int ret=0, satcount=0;
155 for (int idx=0; idx <= m_lnbidx; ++idx )
158 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
159 if ( lnb_param.slot_mask & slot_id ) // lnb for correct tuner?
161 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
163 satcount += lnb_param.m_satellites.size();
165 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
166 lnb_param.m_satellites.find(sat.orbital_position);
167 if ( sit != lnb_param.m_satellites.end())
172 satpos_depends_ptr=-1,
173 csw = di_param.m_committed_cmd,
174 ucsw = di_param.m_uncommitted_cmd,
175 toneburst = di_param.m_toneburst_param,
178 fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
179 fe->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
180 fe->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
181 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
183 if ( sat.frequency > lnb_param.m_lof_threshold )
185 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
190 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
193 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
194 csw = 0xF0 | (csw << 2);
196 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
199 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
203 if (rotor && curRotorPos != -1)
204 ret -= abs(curRotorPos-sat.orbital_position);
212 while (ret && linked_prev_ptr != -1) // check for linked tuners..
213 checkLinkedParams(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr, ret, sat, csw, ucsw, toneburst, diseqc, rotor, curRotorPos);
215 while (ret && linked_next_ptr != -1) // check for linked tuners..
216 checkLinkedParams(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr, ret, sat, csw, ucsw, toneburst, diseqc, rotor, curRotorPos);
219 if (satpos_depends_ptr != -1)
221 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
222 if ( satpos_depends_to_fe->m_inuse )
224 if (!rotor || curRotorPos != sat.orbital_position)
226 // eDebug("can not tune this transponder ... rotor on other tuner is positioned to %d", oRotorPos);
231 // eDebug("OK .. can tune this transponder satpos is correct :)");
236 int lof = sat.frequency > lnb_param.m_lof_threshold ?
237 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
238 int tuner_freq = abs(sat.frequency - lof);
239 // eDebug("tuner freq %d", tuner_freq);
240 if (tuner_freq < 900000 || tuner_freq > 2200000)
243 // eDebug("Transponder not tuneable with this lnb... %d Khz out of tuner range",
252 if (ret && m_not_linked_slot_mask & slot_id)
253 ret += 5; // increase score for tuners with direct sat connection
257 bool need_turn_fast(int turn_speed)
259 if (turn_speed == eDVBSatelliteRotorParameters::FAST)
261 else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
263 int begin = turn_speed >> 16; // high word is start time
264 int end = turn_speed&0xFFFF; // low word is end time
265 time_t now_time = ::time(0);
267 localtime_r(&now_time, &nowTime);
268 int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
269 bool neg = end <= begin;
275 if ((now >= begin && now < end) ^ neg)
281 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
283 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
285 for (int idx=0; idx <= m_lnbidx; ++idx )
287 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
288 if (!(lnb_param.slot_mask & slot_id)) // lnb for correct tuner?
290 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
291 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
293 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
294 lnb_param.m_satellites.find(sat.orbital_position);
295 if ( sit != lnb_param.m_satellites.end())
297 eDVBSatelliteSwitchParameters &sw_param = sit->second;
298 bool doSetFrontend = true;
299 bool doSetVoltageToneFrontend = true;
300 bool allowDiseqc1_2 = true;
302 voltage = iDVBFrontend::voltageOff,
303 tone = iDVBFrontend::toneOff,
304 csw = di_param.m_committed_cmd,
305 ucsw = di_param.m_uncommitted_cmd,
306 toneburst = di_param.m_toneburst_param,
312 satposDependPtr = -1;
314 frontend.getData(eDVBFrontend::CSW, lastcsw);
315 frontend.getData(eDVBFrontend::UCSW, lastucsw);
316 frontend.getData(eDVBFrontend::TONEBURST, lastToneburst);
317 frontend.getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
318 frontend.getData(eDVBFrontend::ROTOR_POS, curRotorPos);
319 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
321 if (satposDependPtr != -1 && !(m_not_linked_slot_mask & slot_id))
322 allowDiseqc1_2 = false;
324 if ( sat.frequency > lnb_param.m_lof_threshold )
328 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
330 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
332 parm.FREQUENCY = abs(parm.FREQUENCY);
334 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
336 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
339 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
340 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
341 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
342 voltage = VOLTAGE(13);
343 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
344 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
345 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
346 voltage = VOLTAGE(18);
347 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
348 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
349 tone = iDVBFrontend::toneOn;
350 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
351 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
352 tone = iDVBFrontend::toneOff;
354 eSecCommandList sec_sequence;
356 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
358 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
359 csw = 0xF0 | (csw << 2);
361 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
365 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
366 bool changed_csw = send_csw && csw != lastcsw;
369 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
370 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
373 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
374 bool changed_burst = send_burst && toneburst != lastToneburst;
376 int send_mask = 0; /*
379 4 send toneburst first
380 8 send toneburst at end */
381 if (changed_burst) // toneburst first and toneburst changed
383 if (di_param.m_command_order&1)
397 if ((di_param.m_command_order&4) && send_csw)
399 if (di_param.m_command_order==4 && send_burst)
404 if ( di_param.m_use_fast
405 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
407 && ((csw / 4) == (lastcsw / 4)) )
408 eDebug("dont send committed cmd (fast diseqc)");
412 if (!(di_param.m_command_order&4) && send_ucsw)
414 if (!(di_param.m_command_order&1) && send_burst)
420 eDebugNoNewLine("sendmask: ");
421 for (int i=3; i >= 0; --i)
422 if ( send_mask & (1<<i) )
423 eDebugNoNewLine("1");
425 eDebugNoNewLine("0");
428 if (doSetVoltageToneFrontend)
431 bool useGotoXX = false;
432 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
433 && !sat.no_rotor_command_on_tune
436 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
437 RotorCmd=sw_param.m_rotorPosNum;
438 else // we must calc gotoxx cmd
440 eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
443 double SatLon = abs(sat.orbital_position)/10.00,
444 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
445 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
447 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
450 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
451 SiteLon = 360 - SiteLon;
453 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
454 double satHourAngle =
455 calcSatHourangle( SatLon, SiteLat, SiteLon );
456 eDebug("PolarmountHourAngle=%lf", satHourAngle );
458 static int gotoXTable[10] =
459 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
461 if (SiteLat >= 0) // Northern Hemisphere
463 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
464 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
466 if (satHourAngle < 180) // the east
471 else // Southern Hemisphere
473 if (satHourAngle < 180) // the east
475 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
476 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
481 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
482 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
486 eDebug("RotorCmd = %04x", RotorCmd);
492 int vlt = iDVBFrontend::voltageOff;
493 eSecCommand::pair compare;
495 compare.tone = iDVBFrontend::toneOff;
496 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
497 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
498 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
500 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
502 if (rotor_param.m_inputpower_parameters.m_use)
503 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
505 vlt = VOLTAGE(13); // in normal mode start turning with 13V
510 // check if voltage is already correct..
511 compare.voltage = vlt;
513 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
515 // check if voltage is disabled
516 compare.voltage = iDVBFrontend::voltageOff;
518 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
520 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS
521 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
522 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
523 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
525 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
526 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
527 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
529 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
533 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
534 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
544 loops <<= di_param.m_repeats;
546 for ( int i = 0; i < loops;) // fill commands...
548 eDVBDiseqcCommand diseqc;
549 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
551 diseqc.data[0] = i ? 0xE1 : 0xE0;
552 diseqc.data[1] = 0x10;
553 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
555 diseqc.data[2] = 0x39;
556 diseqc.data[3] = ucsw;
558 else if ( send_mask & 1 )
560 diseqc.data[2] = 0x38;
561 diseqc.data[3] = csw;
563 else // no committed command confed.. so send uncommitted..
565 diseqc.data[2] = 0x39;
566 diseqc.data[3] = ucsw;
568 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
574 if (diseqc.data[2] == 0x38 && (send_mask & 2))
576 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
578 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
581 int delay = di_param.m_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
582 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
584 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
585 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
588 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
590 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
592 else // delay 120msek when no command is in repeat gap
593 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
596 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
599 if ( send_mask & 8 ) // toneburst at end of sequence
601 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
602 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
607 eDebug("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
608 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
610 eSecCommand::pair compare;
614 compare.tone = iDVBFrontend::toneOff;
615 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
616 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
617 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
619 compare.voltage = iDVBFrontend::voltageOff;
621 // the next is a check if voltage is switched off.. then we first set a voltage :)
622 // else we set voltage after all diseqc stuff..
623 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
625 if (rotor_param.m_inputpower_parameters.m_use)
626 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
628 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
630 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
631 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
634 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
636 eDVBDiseqcCommand diseqc;
637 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
639 diseqc.data[0] = 0xE0;
640 diseqc.data[1] = 0x31; // positioner
641 diseqc.data[2] = 0x60; // stop
642 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
643 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
644 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
645 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
646 // wait 150msec after send rotor stop cmd
647 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
649 diseqc.data[0] = 0xE0;
650 diseqc.data[1] = 0x31; // positioner
654 diseqc.data[2] = 0x6E; // drive to angular position
655 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
656 diseqc.data[4] = RotorCmd & 0xFF;
661 diseqc.data[2] = 0x6B; // goto stored sat position
662 diseqc.data[3] = RotorCmd;
663 diseqc.data[4] = 0x00;
666 if ( rotor_param.m_inputpower_parameters.m_use )
667 { // use measure rotor input power to detect rotor state
668 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed);
669 eSecCommand::rotor cmd;
670 eSecCommand::pair compare;
671 compare.voltage = VOLTAGE(18);
673 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
674 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
675 // measure idle power values
676 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
677 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
680 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
681 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
682 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
683 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
685 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
686 ////////////////////////////
687 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
688 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
689 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
690 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
691 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
693 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
694 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
695 cmd.direction=1; // check for running rotor
696 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
699 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
700 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
701 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
702 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO, turn_fast ? 9 : 8 ) ); // timeout .. we assume now the rotor is already at the correct position
703 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
706 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
707 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*20) ); // 2 minutes running timeout
708 // rotor running loop
709 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
710 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
711 cmd.direction=0; // check for stopped rotor
713 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
714 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
715 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
716 /////////////////////
717 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
718 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
721 { // use normal turning mode
722 doSetVoltageToneFrontend=false;
724 eSecCommand::rotor cmd;
725 eSecCommand::pair compare;
726 compare.voltage = VOLTAGE(13);
728 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
729 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
730 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
732 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
733 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
734 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
736 compare.voltage = voltage;
738 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
739 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
740 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
743 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
744 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
745 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
746 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
748 cmd.direction=1; // check for running rotor
752 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*4) ); // 2 minutes running timeout
753 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
754 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
755 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
756 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
757 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
758 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
760 frontend.setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
761 frontend.setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
768 frontend.setData(eDVBFrontend::CSW, csw);
769 frontend.setData(eDVBFrontend::UCSW, ucsw);
770 frontend.setData(eDVBFrontend::TONEBURST, di_param.m_toneburst_param);
772 if (doSetVoltageToneFrontend)
774 eSecCommand::pair compare;
775 compare.voltage = voltage;
777 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
778 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
779 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
781 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
782 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
783 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
788 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
789 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
791 frontend.setSecSequence(sec_sequence);
797 eDebug("found no useable satellite configuration for orbital position (%d)", sat.orbital_position );
801 RESULT eDVBSatelliteEquipmentControl::clear()
803 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
804 for (int i=0; i <= m_lnbidx; ++i)
806 m_lnbs[i].m_satellites.clear();
807 m_lnbs[i].slot_mask = 0;
811 m_not_linked_slot_mask=0;
813 //reset some tuner configuration
814 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
817 if (!strcmp(it->m_frontend->getDescription(), "BCM4501 (internal)") && !it->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp) && tmp != -1)
819 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
820 if (!f || fwrite("B", 1, 1, f) != 1)
821 eDebug("set /proc/stb/tsmux/lnb_b_input to B failed!! (%m)");
824 eDebug("set /proc/stb/tsmux/lnb_b_input to B OK");
828 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
829 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
830 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
831 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
832 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
838 /* LNB Specific Parameters */
839 RESULT eDVBSatelliteEquipmentControl::addLNB()
841 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
842 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
845 eDebug("no more LNB free... cnt is %d", m_lnbidx);
848 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
852 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
854 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
855 if ( currentLNBValid() )
856 m_lnbs[m_lnbidx].slot_mask = slotmask;
862 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
864 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
865 if ( currentLNBValid() )
866 m_lnbs[m_lnbidx].m_lof_lo = lofl;
872 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
874 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
875 if ( currentLNBValid() )
876 m_lnbs[m_lnbidx].m_lof_hi = lofh;
882 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
884 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
885 if ( currentLNBValid() )
886 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
892 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
894 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
895 if ( currentLNBValid() )
896 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
902 /* DiSEqC Specific Parameters */
903 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
905 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
906 if ( currentLNBValid() )
907 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
913 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
915 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
916 if ( currentLNBValid() )
917 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
923 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
925 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
926 if ( currentLNBValid() )
927 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
933 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
935 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
936 if ( currentLNBValid() )
937 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
943 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
945 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
946 if ( currentLNBValid() )
947 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
953 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
955 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
956 if ( currentLNBValid() )
957 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
963 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
965 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
966 if ( currentLNBValid() )
967 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
973 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
975 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
976 if ( currentLNBValid() )
977 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
983 /* Rotor Specific Parameters */
984 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
986 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
987 if ( currentLNBValid() )
988 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
994 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
996 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
997 if ( currentLNBValid() )
998 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1004 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1006 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1007 if ( currentLNBValid() )
1008 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1014 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1016 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1017 if ( currentLNBValid() )
1018 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1024 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1026 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1027 if ( currentLNBValid() )
1028 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1034 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1036 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1037 if ( currentLNBValid() )
1038 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1044 /* Satellite Specific Parameters */
1045 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1047 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1048 if ( currentLNBValid() )
1050 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1051 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1052 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1054 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1055 m_lnbs[m_lnbidx].m_satellites.insert(
1056 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1059 m_curSat = ret.first;
1071 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1073 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1074 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1075 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1082 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1084 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1085 if ( currentLNBValid() )
1087 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1088 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1097 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1099 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1100 if ( currentLNBValid() )
1102 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1103 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1112 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1114 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1115 if ( currentLNBValid() )
1116 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1124 int orb_pos, lofl, lofh;
1125 sat_compare(int o, int lofl, int lofh)
1126 :orb_pos(o), lofl(lofl), lofh(lofh)
1128 sat_compare(const sat_compare &x)
1129 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1131 bool operator < (const sat_compare & cmp) const
1133 if (orb_pos == cmp.orb_pos)
1135 if ( abs(lofl-cmp.lofl) < 200000 )
1137 if (abs(lofh-cmp.lofh) < 200000)
1139 return lofh<cmp.lofh;
1141 return lofl<cmp.lofl;
1143 return orb_pos < cmp.orb_pos;
1147 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1149 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1152 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1154 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1156 if (it->m_frontend->getSlotID() == tu1)
1158 else if (it->m_frontend->getSlotID() == tu2)
1163 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1164 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1165 if (!strcmp(p1->m_frontend->getDescription(), p2->m_frontend->getDescription()) && !strcmp(p1->m_frontend->getDescription(), "BCM4501 (internal)"))
1167 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
1168 if (!f || fwrite("A", 1, 1, f) != 1)
1169 eDebug("set /proc/stb/tsmux/lnb_b_input to A failed!! (%m)");
1172 eDebug("set /proc/stb/tsmux/lnb_b_input to A OK");
1182 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1184 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1188 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1190 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1192 if (it->m_frontend->getSlotID() == tu1)
1194 else if (it->m_frontend->getSlotID() == tu2)
1199 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1200 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1206 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1208 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1209 m_not_linked_slot_mask |= (1 << slot_no);
1212 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1214 return m_rotorMoving;
1217 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)