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.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 eSecDebugNoSimulate("ret %d, score old %d", ret, score);
304 if (highest_score_lnb)
305 *highest_score_lnb = idx;
307 eSecDebugNoSimulate("score new %d", score);
311 if (score && satcount)
312 score -= (satcount-1);
313 if (score && direct_connected)
314 score += 5; // increase score for tuners with direct sat connection
315 eSecDebugNoSimulate("final score %d", score);
319 bool need_turn_fast(int turn_speed)
321 if (turn_speed == eDVBSatelliteRotorParameters::FAST)
323 else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
325 int begin = turn_speed >> 16; // high word is start time
326 int end = turn_speed&0xFFFF; // low word is end time
327 time_t now_time = ::time(0);
329 localtime_r(&now_time, &nowTime);
330 int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
331 bool neg = end <= begin;
337 if ((now >= begin && now < end) ^ neg)
343 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
345 #define eDebugNoSimulate(x...) \
352 // eDebugNoNewLine("SIMULATE:"); \
356 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
358 bool simulate = ((eDVBFrontend*)&frontend)->is_simulate();
360 if (canTune(sat, &frontend, slot_id, &lnb_idx))
362 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[lnb_idx];
363 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
364 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
366 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
367 lnb_param.m_satellites.find(sat.orbital_position);
368 if ( sit != lnb_param.m_satellites.end())
370 eDVBSatelliteSwitchParameters &sw_param = sit->second;
371 bool doSetFrontend = true;
372 bool doSetVoltageToneFrontend = true;
373 bool sendDiSEqC = false;
374 bool forceChanged = false;
375 bool needDiSEqCReset = false;
377 voltage = iDVBFrontend::voltageOff,
378 tone = iDVBFrontend::toneOff,
379 csw = di_param.m_committed_cmd,
380 ucsw = di_param.m_uncommitted_cmd,
381 toneburst = di_param.m_toneburst_param,
387 satposDependPtr = -1;
388 iDVBFrontend *sec_fe=&frontend;
389 eDVBRegisteredFrontend *linked_fe = 0;
390 eDVBSatelliteDiseqcParameters::t_diseqc_mode diseqc_mode = di_param.m_diseqc_mode;
391 eDVBSatelliteSwitchParameters::t_voltage_mode voltage_mode = sw_param.m_voltage_mode;
392 bool diseqc13V = voltage_mode == eDVBSatelliteSwitchParameters::HV_13;
395 voltage_mode = eDVBSatelliteSwitchParameters::HV;
397 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
399 if (!(m_not_linked_slot_mask & slot_id)) // frontend with direct connection?
401 long linked_prev_ptr;
402 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
403 while (linked_prev_ptr != -1)
405 linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
406 sec_fe = linked_fe->m_frontend;
407 sec_fe->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
409 if (satposDependPtr != -1) // we dont need uncommitted switch and rotor cmds on second output of a rotor lnb
410 diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
412 // in eDVBFrontend::tuneLoop we call closeFrontend and ->inc_use() in this this condition (to put the kernel frontend thread into idle state)
413 // so we must resend all diseqc stuff (voltage is disabled when the frontend is closed)
415 sec_fe->getState(state);
416 if (!linked_fe->m_inuse && state != eDVBFrontend::stateIdle)
421 sec_fe->getData(eDVBFrontend::CSW, lastcsw);
422 sec_fe->getData(eDVBFrontend::UCSW, lastucsw);
423 sec_fe->getData(eDVBFrontend::TONEBURST, lastToneburst);
424 sec_fe->getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
425 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
427 if (lastcsw == lastucsw && lastToneburst == lastucsw && lastucsw == -1)
428 needDiSEqCReset = true;
430 if ( sat.frequency > lnb_param.m_lof_threshold )
434 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
436 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
438 parm.FREQUENCY = abs(parm.FREQUENCY);
440 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
442 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
445 if ( voltage_mode == eDVBSatelliteSwitchParameters::_14V
446 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical
447 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
448 voltage = VOLTAGE(13);
449 else if ( voltage_mode == eDVBSatelliteSwitchParameters::_18V
450 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical)
451 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
452 voltage = VOLTAGE(18);
453 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
454 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
455 tone = iDVBFrontend::toneOn;
456 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
457 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
458 tone = iDVBFrontend::toneOff;
460 eSecCommandList sec_sequence;
462 if (diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
464 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
465 csw = 0xF0 | (csw << 2);
467 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
471 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
472 bool changed_csw = send_csw && (forceChanged || csw != lastcsw);
475 (di_param.m_uncommitted_cmd && diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
476 bool changed_ucsw = send_ucsw && (forceChanged || ucsw != lastucsw);
479 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
480 bool changed_burst = send_burst && (forceChanged || toneburst != lastToneburst);
482 int send_mask = 0; /*
485 4 send toneburst first
486 8 send toneburst at end */
487 if (changed_burst) // toneburst first and toneburst changed
489 if (di_param.m_command_order&1)
503 if ((di_param.m_command_order&4) && send_csw)
505 if (di_param.m_command_order==4 && send_burst)
510 if ( di_param.m_use_fast
511 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
513 && ((csw / 4) == (lastcsw / 4)) )
514 eDebugNoSimulate("dont send committed cmd (fast diseqc)");
518 if (!(di_param.m_command_order&4) && send_ucsw)
520 if (!(di_param.m_command_order&1) && send_burst)
526 eDebugNoNewLine("sendmask: ");
527 for (int i=3; i >= 0; --i)
528 if ( send_mask & (1<<i) )
529 eDebugNoNewLine("1");
531 eDebugNoNewLine("0");
534 if (doSetVoltageToneFrontend)
537 bool useGotoXX = false;
538 if ( diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
539 && !sat.no_rotor_command_on_tune )
541 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
542 RotorCmd=sw_param.m_rotorPosNum;
543 else // we must calc gotoxx cmd
545 eDebugNoSimulate("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
548 double SatLon = abs(sat.orbital_position)/10.00,
549 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
550 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
552 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
555 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
556 SiteLon = 360 - SiteLon;
558 eDebugNoSimulate("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
559 double satHourAngle =
560 calcSatHourangle( SatLon, SiteLat, SiteLon );
561 eDebugNoSimulate("PolarmountHourAngle=%lf", satHourAngle );
563 static int gotoXTable[10] =
564 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
566 if (SiteLat >= 0) // Northern Hemisphere
568 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
569 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
571 if (satHourAngle < 180) // the east
576 else // Southern Hemisphere
578 if (satHourAngle < 180) // the east
580 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
581 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
586 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
587 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
591 eDebugNoSimulate("RotorCmd = %04x", RotorCmd);
597 int vlt = iDVBFrontend::voltageOff;
598 eSecCommand::pair compare;
600 compare.tone = iDVBFrontend::toneOff;
601 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
602 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
603 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
606 vlt = iDVBFrontend::voltage13;
607 else if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
609 if (rotor_param.m_inputpower_parameters.m_use)
610 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
612 vlt = VOLTAGE(13); // in normal mode start turning with 13V
617 // check if voltage is already correct..
618 compare.voltage = vlt;
620 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
622 // check if voltage is disabled
623 compare.voltage = iDVBFrontend::voltageOff;
625 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
627 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS
628 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
629 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
630 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
632 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
633 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
634 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
636 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
639 eDVBDiseqcCommand diseqc;
640 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
642 diseqc.data[0] = 0xE0;
646 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
647 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_RESET_CMD]) );
649 // diseqc peripherial powersupply on
650 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
651 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD]) );
654 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
658 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
659 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
669 loops <<= di_param.m_repeats;
671 for ( int i = 0; i < loops;) // fill commands...
673 eDVBDiseqcCommand diseqc;
674 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
676 diseqc.data[0] = i ? 0xE1 : 0xE0;
677 diseqc.data[1] = 0x10;
678 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
680 diseqc.data[2] = 0x39;
681 diseqc.data[3] = ucsw;
683 else if ( send_mask & 1 )
685 diseqc.data[2] = 0x38;
686 diseqc.data[3] = csw;
688 else // no committed command confed.. so send uncommitted..
690 diseqc.data[2] = 0x39;
691 diseqc.data[3] = ucsw;
693 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
699 if (diseqc.data[2] == 0x38 && (send_mask & 2))
701 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
703 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
706 int delay = di_param.m_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
707 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
709 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
710 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
713 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
715 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
717 else // delay 120msek when no command is in repeat gap
718 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
721 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
724 if ( send_mask & 8 ) // toneburst at end of sequence
726 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
727 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
730 if (di_param.m_seq_repeat && seq_repeat == 0)
731 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BEFORE_SEQUENCE_REPEAT]) );
736 eDebugNoSimulate("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
737 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
739 eSecCommand::pair compare;
743 compare.tone = iDVBFrontend::toneOff;
744 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
745 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
746 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
748 compare.voltage = iDVBFrontend::voltageOff;
750 // the next is a check if voltage is switched off.. then we first set a voltage :)
751 // else we set voltage after all diseqc stuff..
752 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
754 if (rotor_param.m_inputpower_parameters.m_use)
755 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
757 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
759 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
760 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
763 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
765 eDVBDiseqcCommand diseqc;
766 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
768 diseqc.data[0] = 0xE0;
769 diseqc.data[1] = 0x31; // positioner
770 diseqc.data[2] = 0x60; // stop
771 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
772 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
773 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
774 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
775 // wait 150msec after send rotor stop cmd
776 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
778 diseqc.data[0] = 0xE0;
779 diseqc.data[1] = 0x31; // positioner
783 diseqc.data[2] = 0x6E; // drive to angular position
784 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
785 diseqc.data[4] = RotorCmd & 0xFF;
790 diseqc.data[2] = 0x6B; // goto stored sat position
791 diseqc.data[3] = RotorCmd;
792 diseqc.data[4] = 0x00;
795 if ( rotor_param.m_inputpower_parameters.m_use )
796 { // use measure rotor input power to detect rotor state
797 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed);
798 eSecCommand::rotor cmd;
799 eSecCommand::pair compare;
801 compare.voltage = VOLTAGE(18);
803 compare.voltage = VOLTAGE(13);
805 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
806 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
807 // measure idle power values
810 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
811 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
813 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
814 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
816 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
817 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
819 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
820 ////////////////////////////
821 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
822 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
823 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
824 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
826 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
827 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
828 cmd.direction=1; // check for running rotor
829 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
832 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
833 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
834 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
835 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
836 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
838 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
840 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
841 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*20) ); // 2 minutes running timeout
842 // rotor running loop
843 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
844 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
845 cmd.direction=0; // check for stopped rotor
847 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
848 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
849 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
850 /////////////////////
851 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
852 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
855 { // use normal turning mode
856 doSetVoltageToneFrontend=false;
858 eSecCommand::rotor cmd;
859 eSecCommand::pair compare;
860 compare.voltage = VOLTAGE(13);
862 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
863 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
864 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
866 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
867 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
868 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
870 compare.voltage = voltage;
872 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
873 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
874 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
877 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
878 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
879 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
880 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
882 cmd.direction=1; // check for running rotor
886 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*4) ); // 2 minutes running timeout
887 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
888 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
889 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
890 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
891 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
892 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
893 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
894 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
895 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
897 sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
898 sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
905 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
910 sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
912 sec_fe->setData(eDVBFrontend::NEW_CSW, csw);
913 sec_fe->setData(eDVBFrontend::NEW_UCSW, ucsw);
914 sec_fe->setData(eDVBFrontend::NEW_TONEBURST, di_param.m_toneburst_param);
916 if (doSetVoltageToneFrontend)
918 eSecCommand::pair compare;
919 compare.voltage = voltage;
921 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
922 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
923 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
925 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
926 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
927 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE]) );
930 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_SWITCHPARMS) );
934 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
935 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
939 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
940 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
942 frontend.setSecSequence(sec_sequence);
947 eDebugNoSimulate("found no useable satellite configuration for %s freq %d%s %s on orbital position (%d)",
948 sat.system ? "DVB-S2" : "DVB-S",
950 sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal ? "H" :
951 eDVBFrontendParametersSatellite::Polarisation::Vertical ? "V" :
952 eDVBFrontendParametersSatellite::Polarisation::CircularLeft ? "CL" : "CR",
953 sat.modulation == eDVBFrontendParametersSatellite::Modulation::Auto ? "AUTO" :
954 eDVBFrontendParametersSatellite::Modulation::QPSK ? "QPSK" :
955 eDVBFrontendParametersSatellite::Modulation::M8PSK ? "8PSK" : "QAM16",
956 sat.orbital_position );
960 RESULT eDVBSatelliteEquipmentControl::clear()
962 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
963 for (int i=0; i <= m_lnbidx; ++i)
965 m_lnbs[i].m_satellites.clear();
966 m_lnbs[i].slot_mask = 0;
970 m_not_linked_slot_mask=0;
972 //reset some tuner configuration
973 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
976 if (!strcmp(it->m_frontend->getDescription(), "BCM4501 (internal)") && !it->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp) && tmp != -1)
978 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
979 if (!f || fwrite("B", 1, 1, f) != 1)
980 eDebug("set /proc/stb/tsmux/lnb_b_input to B failed!! (%m)");
983 eDebug("set /proc/stb/tsmux/lnb_b_input to B OK");
987 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
988 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
989 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
990 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
991 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
994 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
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);
1006 /* LNB Specific Parameters */
1007 RESULT eDVBSatelliteEquipmentControl::addLNB()
1009 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
1010 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
1013 eDebug("no more LNB free... cnt is %d", m_lnbidx);
1016 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
1020 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
1022 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
1023 if ( currentLNBValid() )
1024 m_lnbs[m_lnbidx].slot_mask = slotmask;
1030 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
1032 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
1033 if ( currentLNBValid() )
1034 m_lnbs[m_lnbidx].m_lof_lo = lofl;
1040 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
1042 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
1043 if ( currentLNBValid() )
1044 m_lnbs[m_lnbidx].m_lof_hi = lofh;
1050 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
1052 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
1053 if ( currentLNBValid() )
1054 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
1060 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
1062 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
1063 if ( currentLNBValid() )
1064 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
1070 /* DiSEqC Specific Parameters */
1071 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
1073 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
1074 if ( currentLNBValid() )
1075 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
1081 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
1083 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
1084 if ( currentLNBValid() )
1085 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
1091 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
1093 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
1094 if ( currentLNBValid() )
1095 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
1101 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
1103 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
1104 if ( currentLNBValid() )
1105 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
1111 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
1113 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
1114 if ( currentLNBValid() )
1115 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
1121 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
1123 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
1124 if ( currentLNBValid() )
1125 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
1131 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
1133 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
1134 if ( currentLNBValid() )
1135 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
1141 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
1143 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
1144 if ( currentLNBValid() )
1145 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1151 /* Rotor Specific Parameters */
1152 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1154 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
1155 if ( currentLNBValid() )
1156 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1162 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1164 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
1165 if ( currentLNBValid() )
1166 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1172 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1174 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1175 if ( currentLNBValid() )
1176 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1182 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1184 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1185 if ( currentLNBValid() )
1186 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1192 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1194 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1195 if ( currentLNBValid() )
1196 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1202 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1204 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1205 if ( currentLNBValid() )
1206 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1212 /* Satellite Specific Parameters */
1213 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1215 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1216 if ( currentLNBValid() )
1218 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1219 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1220 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1222 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1223 m_lnbs[m_lnbidx].m_satellites.insert(
1224 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1227 m_curSat = ret.first;
1239 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1241 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1242 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1243 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1250 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1252 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1253 if ( currentLNBValid() )
1255 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1256 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1265 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1267 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1268 if ( currentLNBValid() )
1270 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1271 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1280 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1282 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1283 if ( currentLNBValid() )
1284 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1292 int orb_pos, lofl, lofh;
1293 sat_compare(int o, int lofl, int lofh)
1294 :orb_pos(o), lofl(lofl), lofh(lofh)
1296 sat_compare(const sat_compare &x)
1297 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1299 bool operator < (const sat_compare & cmp) const
1301 if (orb_pos == cmp.orb_pos)
1303 if ( abs(lofl-cmp.lofl) < 200000 )
1305 if (abs(lofh-cmp.lofh) < 200000)
1307 return lofh<cmp.lofh;
1309 return lofl<cmp.lofl;
1311 return orb_pos < cmp.orb_pos;
1315 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1317 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1320 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1322 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1324 if (it->m_frontend->getSlotID() == tu1)
1326 else if (it->m_frontend->getSlotID() == tu2)
1331 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1332 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1333 if (!strcmp(p1->m_frontend->getDescription(), p2->m_frontend->getDescription()) && !strcmp(p1->m_frontend->getDescription(), "BCM4501 (internal)"))
1335 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
1336 if (!f || fwrite("A", 1, 1, f) != 1)
1337 eDebug("set /proc/stb/tsmux/lnb_b_input to A failed!! (%m)");
1340 eDebug("set /proc/stb/tsmux/lnb_b_input to A OK");
1347 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1349 if (it->m_frontend->getSlotID() == tu1)
1351 else if (it->m_frontend->getSlotID() == tu2)
1356 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1357 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1364 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1366 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1370 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1372 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1374 if (it->m_frontend->getSlotID() == tu1)
1376 else if (it->m_frontend->getSlotID() == tu2)
1381 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1382 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1386 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1388 if (it->m_frontend->getSlotID() == tu1)
1390 else if (it->m_frontend->getSlotID() == tu2)
1395 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1396 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1403 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1405 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1406 m_not_linked_slot_mask |= (1 << slot_no);
1409 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1411 return m_rotorMoving;
1414 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)