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, eSmartPtrList<eDVBRegisteredFrontend> &avail_simulate_frontends)
40 :m_lnbidx(-1), m_curSat(m_lnbs[0].m_satellites.end()), m_avail_frontends(avail_frontends), m_avail_simulate_frontends(avail_simulate_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 #define eSecDebugNoSimulate(x...) \
124 // eDebugNoNewLine("SIMULATE:"); \
128 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int slot_id, int *highest_score_lnb)
130 bool simulate = ((eDVBFrontend*)fe)->is_simulate();
131 bool direct_connected = m_not_linked_slot_mask & slot_id;
132 int score=0, satcount=0;
134 if (highest_score_lnb)
135 *highest_score_lnb = -1;
137 eSecDebugNoSimulate("canTune %d", slot_id);
139 for (int idx=0; idx <= m_lnbidx; ++idx )
142 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
143 if ( lnb_param.m_slot_mask & slot_id ) // lnb for correct tuner?
146 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
148 eSecDebugNoSimulate("lnb %d found", idx);
150 satcount += lnb_param.m_satellites.size();
152 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
153 lnb_param.m_satellites.find(sat.orbital_position);
154 if ( sit != lnb_param.m_satellites.end())
160 satpos_depends_ptr=-1,
161 csw = di_param.m_committed_cmd,
162 ucsw = di_param.m_uncommitted_cmd,
163 toneburst = di_param.m_toneburst_param,
166 eSecDebugNoSimulate("sat %d found", sat.orbital_position);
167 fe->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
168 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
170 if ( sat.frequency > lnb_param.m_lof_threshold )
172 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
175 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
178 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
179 csw = 0xF0 | (csw << 2);
181 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
184 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
195 eSecDebugNoSimulate("ret1 %d", ret);
197 if (direct_connected) // frontend with direct connection?
202 eSecDebugNoSimulate("direct");
203 fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
204 fe->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
205 fe->getData(eDVBFrontend::CSW, ocsw);
206 fe->getData(eDVBFrontend::UCSW, oucsw);
207 fe->getData(eDVBFrontend::TONEBURST, oToneburst);
208 while (ret && linked_prev_ptr != -1) // check for linked tuners..
210 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
211 if (linked_fe->m_inuse)
213 if ( (csw != ocsw) ||
214 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
215 ( rotor && curRotorPos != sat.orbital_position ) )
220 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
222 eSecDebugNoSimulate("ret2 %d", ret);
223 while (ret && linked_next_ptr != -1) // check for linked tuners..
225 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
226 if (linked_fe->m_inuse)
228 if ( (csw != ocsw) ||
229 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
230 ( rotor && curRotorPos != sat.orbital_position ) )
235 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, (long&)linked_next_ptr);
237 eSecDebugNoSimulate("ret3 %d", ret);
239 else // linked frontend..
244 while (linked_prev_ptr != -1)
246 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
247 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
248 if (linked_prev_ptr == -1)
250 iDVBFrontend *sec_fe = linked_fe->m_frontend;
251 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
252 if (linked_fe->m_inuse)
254 sec_fe->getData(eDVBFrontend::CSW, ocsw);
255 sec_fe->getData(eDVBFrontend::UCSW, oucsw);
256 sec_fe->getData(eDVBFrontend::TONEBURST, oToneburst);
257 eSecDebug("(%ld != %ld) || \n(%d && (%ld != %ld || %ld != %ld) ) ||\n( %d && %ld != %d ) )",
258 csw, ocsw, diseqc, ucsw, oucsw, toneburst, oToneburst, rotor, curRotorPos, sat.orbital_position);
259 if ( (csw != ocsw) ||
260 ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
261 ( rotor && curRotorPos != sat.orbital_position ) )
268 eSecDebugNoSimulate("ret4 %d", ret);
272 if (satpos_depends_ptr != -1)
274 eSecDebugNoSimulate("satpos depends");
275 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
276 if ( satpos_depends_to_fe->m_inuse )
278 if (!direct_connected)
279 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
280 if (!rotor || curRotorPos != sat.orbital_position)
283 eSecDebugNoSimulate("ret5 %d", ret);
286 if (ret && rotor && curRotorPos != -1)
287 ret -= abs(curRotorPos-sat.orbital_position);
289 eSecDebugNoSimulate("ret6 %d", ret);
293 int lof = sat.frequency > lnb_param.m_lof_threshold ?
294 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
295 int tuner_freq = abs(sat.frequency - lof);
296 if (tuner_freq < 900000 || tuner_freq > 2200000)
300 if (ret && lnb_param.m_prio != -1)
301 ret = lnb_param.m_prio;
303 eSecDebugNoSimulate("ret %d, score old %d", ret, score);
307 if (highest_score_lnb)
308 *highest_score_lnb = idx;
310 eSecDebugNoSimulate("score new %d", score);
314 if (score && satcount)
316 if (score > (satcount-1))
317 score -= (satcount-1);
319 score = 1; // min score
321 if (score && direct_connected)
322 score += 5; // increase score for tuners with direct sat connection
323 eSecDebugNoSimulate("final score %d", score);
327 bool need_turn_fast(int turn_speed)
329 if (turn_speed == eDVBSatelliteRotorParameters::FAST)
331 else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
333 int begin = turn_speed >> 16; // high word is start time
334 int end = turn_speed&0xFFFF; // low word is end time
335 time_t now_time = ::time(0);
337 localtime_r(&now_time, &nowTime);
338 int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
339 bool neg = end <= begin;
345 if ((now >= begin && now < end) ^ neg)
351 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
353 #define eDebugNoSimulate(x...) \
360 // eDebugNoNewLine("SIMULATE:"); \
364 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
366 bool simulate = ((eDVBFrontend*)&frontend)->is_simulate();
368 if (canTune(sat, &frontend, slot_id, &lnb_idx))
370 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[lnb_idx];
371 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
372 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
374 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
375 lnb_param.m_satellites.find(sat.orbital_position);
376 if ( sit != lnb_param.m_satellites.end())
378 eDVBSatelliteSwitchParameters &sw_param = sit->second;
379 bool doSetFrontend = true;
380 bool doSetVoltageToneFrontend = true;
381 bool sendDiSEqC = false;
382 bool forceChanged = false;
383 bool needDiSEqCReset = false;
385 voltage = iDVBFrontend::voltageOff,
386 tone = iDVBFrontend::toneOff,
387 csw = di_param.m_committed_cmd,
388 ucsw = di_param.m_uncommitted_cmd,
389 toneburst = di_param.m_toneburst_param,
395 satposDependPtr = -1;
396 iDVBFrontend *sec_fe=&frontend;
397 eDVBRegisteredFrontend *linked_fe = 0;
398 eDVBSatelliteDiseqcParameters::t_diseqc_mode diseqc_mode = di_param.m_diseqc_mode;
399 eDVBSatelliteSwitchParameters::t_voltage_mode voltage_mode = sw_param.m_voltage_mode;
400 bool diseqc13V = voltage_mode == eDVBSatelliteSwitchParameters::HV_13;
403 voltage_mode = eDVBSatelliteSwitchParameters::HV;
405 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
407 if (!(m_not_linked_slot_mask & slot_id)) // frontend with direct connection?
409 long linked_prev_ptr;
410 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
411 while (linked_prev_ptr != -1)
413 linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
414 sec_fe = linked_fe->m_frontend;
415 sec_fe->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
417 if (satposDependPtr != -1) // we dont need uncommitted switch and rotor cmds on second output of a rotor lnb
418 diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
420 // in eDVBFrontend::tuneLoop we call closeFrontend and ->inc_use() in this this condition (to put the kernel frontend thread into idle state)
421 // so we must resend all diseqc stuff (voltage is disabled when the frontend is closed)
423 sec_fe->getState(state);
424 if (!linked_fe->m_inuse && state != eDVBFrontend::stateIdle)
429 sec_fe->getData(eDVBFrontend::CSW, lastcsw);
430 sec_fe->getData(eDVBFrontend::UCSW, lastucsw);
431 sec_fe->getData(eDVBFrontend::TONEBURST, lastToneburst);
432 sec_fe->getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
433 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
435 if (lastcsw == lastucsw && lastToneburst == lastucsw && lastucsw == -1)
436 needDiSEqCReset = true;
438 if ( sat.frequency > lnb_param.m_lof_threshold )
442 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
444 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
446 parm.FREQUENCY = abs(parm.FREQUENCY);
448 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
450 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
453 if ( voltage_mode == eDVBSatelliteSwitchParameters::_14V
454 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
455 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
456 voltage = VOLTAGE(13);
457 else if ( voltage_mode == eDVBSatelliteSwitchParameters::_18V
458 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
459 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
460 voltage = VOLTAGE(18);
461 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
462 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
463 tone = iDVBFrontend::toneOn;
464 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
465 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
466 tone = iDVBFrontend::toneOff;
468 eSecCommandList sec_sequence;
470 if (diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
472 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
473 csw = 0xF0 | (csw << 2);
475 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
479 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
480 bool changed_csw = send_csw && (forceChanged || csw != lastcsw);
483 (di_param.m_uncommitted_cmd && diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
484 bool changed_ucsw = send_ucsw && (forceChanged || ucsw != lastucsw);
487 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
488 bool changed_burst = send_burst && (forceChanged || toneburst != lastToneburst);
490 int send_mask = 0; /*
493 4 send toneburst first
494 8 send toneburst at end */
495 if (changed_burst) // toneburst first and toneburst changed
497 if (di_param.m_command_order&1)
511 if ((di_param.m_command_order&4) && send_csw)
513 if (di_param.m_command_order==4 && send_burst)
518 if ( di_param.m_use_fast
519 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
521 && ((csw / 4) == (lastcsw / 4)) )
522 eDebugNoSimulate("dont send committed cmd (fast diseqc)");
526 if (!(di_param.m_command_order&4) && send_ucsw)
528 if (!(di_param.m_command_order&1) && send_burst)
534 eDebugNoNewLine("sendmask: ");
535 for (int i=3; i >= 0; --i)
536 if ( send_mask & (1<<i) )
537 eDebugNoNewLine("1");
539 eDebugNoNewLine("0");
542 if (doSetVoltageToneFrontend)
545 bool useGotoXX = false;
546 if ( diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
547 && !sat.no_rotor_command_on_tune )
549 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
550 RotorCmd=sw_param.m_rotorPosNum;
551 else // we must calc gotoxx cmd
553 eDebugNoSimulate("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
556 double SatLon = abs(sat.orbital_position)/10.00,
557 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
558 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
560 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
563 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
564 SiteLon = 360 - SiteLon;
566 eDebugNoSimulate("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
567 double satHourAngle =
568 calcSatHourangle( SatLon, SiteLat, SiteLon );
569 eDebugNoSimulate("PolarmountHourAngle=%lf", satHourAngle );
571 static int gotoXTable[10] =
572 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
574 if (SiteLat >= 0) // Northern Hemisphere
576 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
577 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
579 if (satHourAngle < 180) // the east
584 else // Southern Hemisphere
586 if (satHourAngle < 180) // the east
588 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
589 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
594 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
595 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
599 eDebugNoSimulate("RotorCmd = %04x", RotorCmd);
605 int vlt = iDVBFrontend::voltageOff;
606 eSecCommand::pair compare;
608 compare.tone = iDVBFrontend::toneOff;
609 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
610 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
611 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
614 vlt = iDVBFrontend::voltage13;
615 else if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
617 if (rotor_param.m_inputpower_parameters.m_use)
618 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
620 vlt = VOLTAGE(13); // in normal mode start turning with 13V
625 // check if voltage is already correct..
626 compare.voltage = vlt;
628 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
630 // check if voltage is disabled
631 compare.voltage = iDVBFrontend::voltageOff;
633 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
635 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS
636 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
637 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
638 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
640 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
641 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
642 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
644 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
647 eDVBDiseqcCommand diseqc;
648 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
650 diseqc.data[0] = 0xE0;
654 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
655 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_RESET_CMD]) );
657 // diseqc peripherial powersupply on
658 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
659 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD]) );
662 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
666 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
667 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
677 loops <<= di_param.m_repeats;
679 for ( int i = 0; i < loops;) // fill commands...
681 eDVBDiseqcCommand diseqc;
682 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
684 diseqc.data[0] = i ? 0xE1 : 0xE0;
685 diseqc.data[1] = 0x10;
686 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
688 diseqc.data[2] = 0x39;
689 diseqc.data[3] = ucsw;
691 else if ( send_mask & 1 )
693 diseqc.data[2] = 0x38;
694 diseqc.data[3] = csw;
696 else // no committed command confed.. so send uncommitted..
698 diseqc.data[2] = 0x39;
699 diseqc.data[3] = ucsw;
701 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
707 if (diseqc.data[2] == 0x38 && (send_mask & 2))
709 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
711 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
714 int delay = di_param.m_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
715 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
717 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
718 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
721 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
723 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
725 else // delay 120msek when no command is in repeat gap
726 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
729 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
732 if ( send_mask & 8 ) // toneburst at end of sequence
734 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
735 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
738 if (di_param.m_seq_repeat && seq_repeat == 0)
739 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BEFORE_SEQUENCE_REPEAT]) );
744 eDebugNoSimulate("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
745 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
747 eSecCommand::pair compare;
751 compare.tone = iDVBFrontend::toneOff;
752 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
753 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
754 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
756 compare.voltage = iDVBFrontend::voltageOff;
758 // the next is a check if voltage is switched off.. then we first set a voltage :)
759 // else we set voltage after all diseqc stuff..
760 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
762 if (rotor_param.m_inputpower_parameters.m_use)
763 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
765 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
767 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
768 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
771 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
773 eDVBDiseqcCommand diseqc;
774 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
776 diseqc.data[0] = 0xE0;
777 diseqc.data[1] = 0x31; // positioner
778 diseqc.data[2] = 0x60; // stop
779 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
780 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
781 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
782 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
783 // wait 150msec after send rotor stop cmd
784 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
786 diseqc.data[0] = 0xE0;
787 diseqc.data[1] = 0x31; // positioner
791 diseqc.data[2] = 0x6E; // drive to angular position
792 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
793 diseqc.data[4] = RotorCmd & 0xFF;
798 diseqc.data[2] = 0x6B; // goto stored sat position
799 diseqc.data[3] = RotorCmd;
800 diseqc.data[4] = 0x00;
803 if ( rotor_param.m_inputpower_parameters.m_use )
804 { // use measure rotor input power to detect rotor state
805 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed);
806 eSecCommand::rotor cmd;
807 eSecCommand::pair compare;
809 compare.voltage = VOLTAGE(18);
811 compare.voltage = VOLTAGE(13);
813 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
814 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
815 // measure idle power values
818 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
819 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
821 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
822 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
824 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
825 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
827 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
828 ////////////////////////////
829 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
830 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
831 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
832 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
834 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
835 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
836 cmd.direction=1; // check for running rotor
837 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
840 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
841 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
842 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
843 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO, turn_fast ? 10 : 9 ) ); // timeout .. we assume now the rotor is already at the correct position
844 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
846 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
848 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
849 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*20) ); // 2 minutes running timeout
850 // rotor running loop
851 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
852 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
853 cmd.direction=0; // check for stopped rotor
855 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
856 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
857 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
858 /////////////////////
859 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
860 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
863 { // use normal turning mode
864 doSetVoltageToneFrontend=false;
866 eSecCommand::rotor cmd;
867 eSecCommand::pair compare;
868 compare.voltage = VOLTAGE(13);
870 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
871 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
872 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
874 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
875 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
876 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
878 compare.voltage = voltage;
880 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
881 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
882 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
885 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
886 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
887 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
888 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
890 cmd.direction=1; // check for running rotor
894 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*4) ); // 2 minutes running timeout
895 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
896 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
897 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
898 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
899 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
900 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
901 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
902 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
903 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
905 sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
906 sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
913 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
918 sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
920 sec_fe->setData(eDVBFrontend::NEW_CSW, csw);
921 sec_fe->setData(eDVBFrontend::NEW_UCSW, ucsw);
922 sec_fe->setData(eDVBFrontend::NEW_TONEBURST, di_param.m_toneburst_param);
924 if (doSetVoltageToneFrontend)
926 eSecCommand::pair compare;
927 compare.voltage = voltage;
929 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
930 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
931 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
933 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
934 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
935 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
938 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_SWITCHPARMS) );
942 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
943 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
947 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
948 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
950 frontend.setSecSequence(sec_sequence);
955 eDebugNoSimulate("found no useable satellite configuration for %s freq %d%s %s on orbital position (%d)",
956 sat.system ? "DVB-S2" : "DVB-S",
958 sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal ? "H" :
959 eDVBFrontendParametersSatellite::Polarisation::Vertical ? "V" :
960 eDVBFrontendParametersSatellite::Polarisation::CircularLeft ? "CL" : "CR",
961 sat.modulation == eDVBFrontendParametersSatellite::Modulation::Auto ? "AUTO" :
962 eDVBFrontendParametersSatellite::Modulation::QPSK ? "QPSK" :
963 eDVBFrontendParametersSatellite::Modulation::M8PSK ? "8PSK" : "QAM16",
964 sat.orbital_position );
968 RESULT eDVBSatelliteEquipmentControl::clear()
970 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
971 for (int i=0; i <= m_lnbidx; ++i)
973 m_lnbs[i].m_satellites.clear();
974 m_lnbs[i].m_slot_mask = 0;
975 m_lnbs[i].m_prio = -1; // auto
979 m_not_linked_slot_mask=0;
981 //reset some tuner configuration
982 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
985 if (!strcmp(it->m_frontend->getDescription(), "BCM4501 (internal)") && !it->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp) && tmp != -1)
987 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
988 if (!f || fwrite("B", 1, 1, f) != 1)
989 eDebug("set /proc/stb/tsmux/lnb_b_input to B failed!! (%m)");
992 eDebug("set /proc/stb/tsmux/lnb_b_input to B OK");
996 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
997 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
998 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
999 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1000 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1003 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1005 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1006 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1007 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1008 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1009 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1015 /* LNB Specific Parameters */
1016 RESULT eDVBSatelliteEquipmentControl::addLNB()
1018 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
1019 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
1022 eDebug("no more LNB free... cnt is %d", m_lnbidx);
1025 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
1029 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
1031 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
1032 if ( currentLNBValid() )
1033 m_lnbs[m_lnbidx].m_slot_mask = slotmask;
1039 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
1041 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
1042 if ( currentLNBValid() )
1043 m_lnbs[m_lnbidx].m_lof_lo = lofl;
1049 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
1051 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
1052 if ( currentLNBValid() )
1053 m_lnbs[m_lnbidx].m_lof_hi = lofh;
1059 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
1061 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
1062 if ( currentLNBValid() )
1063 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
1069 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
1071 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
1072 if ( currentLNBValid() )
1073 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
1079 RESULT eDVBSatelliteEquipmentControl::setLNBPrio(int prio)
1081 eSecDebug("eDVBSatelliteEquipmentControl::setLNBPrio(%d)", prio);
1082 if ( currentLNBValid() )
1083 m_lnbs[m_lnbidx].m_prio = prio;
1090 /* DiSEqC Specific Parameters */
1091 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
1093 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
1094 if ( currentLNBValid() )
1095 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
1101 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
1103 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
1104 if ( currentLNBValid() )
1105 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
1111 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
1113 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
1114 if ( currentLNBValid() )
1115 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
1121 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
1123 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
1124 if ( currentLNBValid() )
1125 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
1131 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
1133 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
1134 if ( currentLNBValid() )
1135 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
1141 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
1143 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
1144 if ( currentLNBValid() )
1145 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
1151 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
1153 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
1154 if ( currentLNBValid() )
1155 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
1161 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
1163 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
1164 if ( currentLNBValid() )
1165 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1171 /* Rotor Specific Parameters */
1172 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1174 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
1175 if ( currentLNBValid() )
1176 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1182 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1184 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
1185 if ( currentLNBValid() )
1186 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1192 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1194 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1195 if ( currentLNBValid() )
1196 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1202 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1204 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1205 if ( currentLNBValid() )
1206 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1212 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1214 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1215 if ( currentLNBValid() )
1216 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1222 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1224 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1225 if ( currentLNBValid() )
1226 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1232 /* Satellite Specific Parameters */
1233 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1235 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1236 if ( currentLNBValid() )
1238 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1239 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1240 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1242 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1243 m_lnbs[m_lnbidx].m_satellites.insert(
1244 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1247 m_curSat = ret.first;
1259 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1261 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1262 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1263 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1270 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1272 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1273 if ( currentLNBValid() )
1275 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1276 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1285 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1287 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1288 if ( currentLNBValid() )
1290 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1291 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1300 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1302 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1303 if ( currentLNBValid() )
1304 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1312 int orb_pos, lofl, lofh;
1313 sat_compare(int o, int lofl, int lofh)
1314 :orb_pos(o), lofl(lofl), lofh(lofh)
1316 sat_compare(const sat_compare &x)
1317 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1319 bool operator < (const sat_compare & cmp) const
1321 if (orb_pos == cmp.orb_pos)
1323 if ( abs(lofl-cmp.lofl) < 200000 )
1325 if (abs(lofh-cmp.lofh) < 200000)
1327 return lofh<cmp.lofh;
1329 return lofl<cmp.lofl;
1331 return orb_pos < cmp.orb_pos;
1335 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1337 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1340 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1342 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1344 if (it->m_frontend->getSlotID() == tu1)
1346 else if (it->m_frontend->getSlotID() == tu2)
1351 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1352 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1353 if (!strcmp(p1->m_frontend->getDescription(), p2->m_frontend->getDescription()) && !strcmp(p1->m_frontend->getDescription(), "BCM4501 (internal)"))
1355 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
1356 if (!f || fwrite("A", 1, 1, f) != 1)
1357 eDebug("set /proc/stb/tsmux/lnb_b_input to A failed!! (%m)");
1360 eDebug("set /proc/stb/tsmux/lnb_b_input to A OK");
1367 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1369 if (it->m_frontend->getSlotID() == tu1)
1371 else if (it->m_frontend->getSlotID() == tu2)
1376 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1377 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1384 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1386 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1390 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1392 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1394 if (it->m_frontend->getSlotID() == tu1)
1396 else if (it->m_frontend->getSlotID() == tu2)
1401 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1402 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1406 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1408 if (it->m_frontend->getSlotID() == tu1)
1410 else if (it->m_frontend->getSlotID() == tu2)
1415 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1416 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1423 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1425 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1426 m_not_linked_slot_mask |= (1 << slot_no);
1429 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1431 return m_rotorMoving;
1434 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)