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((sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters))-1), m_curSat(m_lnbs[0].m_satellites.end()), m_avail_frontends(avail_frontends), m_avail_simulate_frontends(avail_simulate_frontends), m_rotorMoving(0)
47 #define eSecDebugNoSimulate(x...) \
53 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int slot_id, int *highest_score_lnb)
55 bool simulate = ((eDVBFrontend*)fe)->is_simulate();
56 bool direct_connected = m_not_linked_slot_mask & slot_id;
57 int score=0, satcount=0;
58 long linked_prev_ptr=-1, linked_next_ptr=-1, linkable_csw=-1, linkable_ucsw=-1, linkable_toneburst=-1,
59 fe_satpos_depends_ptr=-1, fe_rotor_pos=-1;
60 bool linked_in_use = false;
62 eSecDebugNoSimulate("direct_connected %d", !!direct_connected);
64 fe->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
65 fe->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
66 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, fe_satpos_depends_ptr);
68 // first we search the linkage base frontend and check if any tuner in prev direction is used
69 while (linked_prev_ptr != -1)
71 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
72 if (linked_fe->m_inuse)
74 fe = linked_fe->m_frontend;
75 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
78 fe->getData(eDVBFrontend::ROTOR_POS, fe_rotor_pos);
80 // now check also the linked tuners is in use
81 while (!linked_in_use && linked_next_ptr != -1)
83 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
84 if (linked_fe->m_inuse)
86 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, (long&)linked_next_ptr);
89 // when a linked in use tuner is found we get the tuner data...
92 fe->getData(eDVBFrontend::LINKABLE_CSW, linkable_csw);
93 fe->getData(eDVBFrontend::LINKABLE_UCSW, linkable_ucsw);
94 fe->getData(eDVBFrontend::LINKABLE_TONEBURST, linkable_toneburst);
97 if (highest_score_lnb)
98 *highest_score_lnb = -1;
100 eSecDebugNoSimulate("canTune %d", slot_id);
102 for (int idx=0; idx <= m_lnbidx; ++idx )
105 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
106 bool is_unicable = lnb_param.SatCR_idx != -1;
107 bool is_unicable_position_switch = lnb_param.SatCR_positions > 1;
109 if ( lnb_param.m_slot_mask & slot_id ) // lnb for correct tuner?
112 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
114 eSecDebugNoSimulate("lnb %d found", idx);
116 satcount += lnb_param.m_satellites.size();
118 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
119 lnb_param.m_satellites.find(sat.orbital_position);
120 if ( sit != lnb_param.m_satellites.end())
124 satpos_depends_ptr=fe_satpos_depends_ptr,
125 csw = di_param.m_committed_cmd,
126 ucsw = di_param.m_uncommitted_cmd,
127 toneburst = di_param.m_toneburst_param,
128 rotor_pos = fe_rotor_pos;
130 eSecDebugNoSimulate("sat %d found", sat.orbital_position);
132 if ( sat.frequency > lnb_param.m_lof_threshold )
134 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
137 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
140 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
141 csw = 0xF0 | (csw << 2);
143 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
146 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
157 if (sat.no_rotor_command_on_tune && !rotor) {
158 eSecDebugNoSimulate("no rotor but no_rotor_command_on_tune is set.. ignore lnb %d", idx);
162 eSecDebugNoSimulate("ret1 %d", ret);
164 if (linked_in_use && !is_unicable)
166 // compare tuner data
167 if ( (csw != linkable_csw) ||
168 ( diseqc && (ucsw != linkable_ucsw || toneburst != linkable_toneburst) ) ||
169 ( rotor && rotor_pos != sat.orbital_position ) )
175 eSecDebugNoSimulate("ret2 %d", ret);
177 else if ((satpos_depends_ptr != -1) && !(is_unicable && is_unicable_position_switch))
179 eSecDebugNoSimulate("satpos depends");
180 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
181 if (direct_connected) // current fe is direct connected.. (can turn the rotor)
183 if (satpos_depends_to_fe->m_inuse) // if the dependent frontend is in use?
185 if (!rotor || rotor_pos != sat.orbital_position) // new orbital position not equal to current orbital pos?
190 eSecDebugNoSimulate("ret3 %d", ret);
192 else // current fe is dependent of another tuner ... (so this fe can't turn the rotor!)
194 // get current orb pos of the tuner with rotor connection
195 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, rotor_pos);
196 if (!rotor || rotor_pos == -1 /* we dont know the rotor position yet */
197 || rotor_pos != sat.orbital_position ) // not the same orbital position?
202 eSecDebugNoSimulate("ret4 %d", ret);
205 if (ret && rotor && rotor_pos != -1)
206 ret -= abs(rotor_pos-sat.orbital_position);
208 eSecDebugNoSimulate("ret5 %d", ret);
210 if (ret && !is_unicable)
212 int lof = sat.frequency > lnb_param.m_lof_threshold ?
213 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
214 int tuner_freq = abs(sat.frequency - lof);
215 if (tuner_freq < 900000 || tuner_freq > 2200000)
219 if (ret && lnb_param.m_prio != -1)
220 ret = lnb_param.m_prio;
222 eSecDebugNoSimulate("ret %d, score old %d", ret, score);
226 if (highest_score_lnb)
227 *highest_score_lnb = idx;
229 eSecDebugNoSimulate("score new %d", score);
233 if (score && satcount)
235 if (score > (satcount-1))
236 score -= (satcount-1);
238 score = 1; // min score
240 if (score && direct_connected)
241 score += 5; // increase score for tuners with direct sat connection
242 eSecDebugNoSimulate("final score %d", score);
246 bool need_turn_fast(int turn_speed)
248 if (turn_speed == eDVBSatelliteRotorParameters::FAST)
250 else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
252 int begin = turn_speed >> 16; // high word is start time
253 int end = turn_speed&0xFFFF; // low word is end time
254 time_t now_time = ::time(0);
256 localtime_r(&now_time, &nowTime);
257 int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
258 bool neg = end <= begin;
264 if ((now >= begin && now < end) ^ neg)
270 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
272 #define eDebugNoSimulate(x...) \
278 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
280 bool simulate = ((eDVBFrontend*)&frontend)->is_simulate();
282 if (canTune(sat, &frontend, slot_id, &lnb_idx))
284 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[lnb_idx];
285 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
286 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
288 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
289 lnb_param.m_satellites.find(sat.orbital_position);
290 if ( sit != lnb_param.m_satellites.end())
292 eSecCommandList sec_sequence;
293 eDVBSatelliteSwitchParameters &sw_param = sit->second;
294 bool doSetFrontend = true;
295 bool doSetVoltageToneFrontend = true;
296 bool forceChanged = false;
297 bool needDiSEqCReset = false;
299 voltage = iDVBFrontend::voltageOff,
300 tone = iDVBFrontend::toneOff,
301 csw = di_param.m_committed_cmd,
302 ucsw = di_param.m_uncommitted_cmd,
303 toneburst = di_param.m_toneburst_param,
309 satposDependPtr = -1;
310 iDVBFrontend *sec_fe=&frontend;
311 eDVBRegisteredFrontend *linked_fe = 0;
312 eDVBSatelliteDiseqcParameters::t_diseqc_mode diseqc_mode = di_param.m_diseqc_mode;
313 eDVBSatelliteSwitchParameters::t_voltage_mode voltage_mode = sw_param.m_voltage_mode;
314 bool diseqc13V = voltage_mode == eDVBSatelliteSwitchParameters::HV_13;
315 bool is_unicable = lnb_param.SatCR_idx != -1;
317 bool useGotoXX = false;
321 bool direct_connected = m_not_linked_slot_mask & slot_id;
323 lnb_param.guard_offset = 0; //HACK
327 voltage_mode = eDVBSatelliteSwitchParameters::HV;
329 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
331 if (!direct_connected) // frontend with direct connection?
333 long linked_prev_ptr;
334 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
335 while (linked_prev_ptr != -1)
337 linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
338 sec_fe = linked_fe->m_frontend;
339 sec_fe->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
341 if (satposDependPtr != -1) // we dont need uncommitted switch and rotor cmds on second output of a rotor lnb
342 diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
343 #if 0 // Since following code causes lock fail for linked tuners in certain conditions, it does not apply.
345 // in eDVBFrontend::tuneLoop we call closeFrontend and ->inc_use() in this this condition (to put the kernel frontend thread into idle state)
346 // so we must resend all diseqc stuff (voltage is disabled when the frontend is closed)
348 sec_fe->getState(state);
349 if (!linked_fe->m_inuse && state != eDVBFrontend::stateIdle)
355 sec_fe->getData(eDVBFrontend::CSW, lastcsw);
356 sec_fe->getData(eDVBFrontend::UCSW, lastucsw);
357 sec_fe->getData(eDVBFrontend::TONEBURST, lastToneburst);
358 sec_fe->getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
359 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
361 if (lastcsw == lastucsw && lastToneburst == lastucsw && lastucsw == -1)
362 needDiSEqCReset = true;
364 if ( sat.frequency > lnb_param.m_lof_threshold )
366 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
369 int lof = (band&1)?lnb_param.m_lof_hi:lnb_param.m_lof_lo;
374 int local= abs(sat.frequency
376 parm.FREQUENCY = ((((local * 2) / 125) + 1) / 2) * 125;
377 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
379 if ( voltage_mode == eDVBSatelliteSwitchParameters::_14V
380 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical
381 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
382 voltage = VOLTAGE(13);
383 else if ( voltage_mode == eDVBSatelliteSwitchParameters::_18V
384 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical)
385 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
386 voltage = VOLTAGE(18);
387 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
388 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
389 tone = iDVBFrontend::toneOn;
390 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
391 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
392 tone = iDVBFrontend::toneOff;
396 switch(lnb_param.SatCR_format)
400 eDebug("[prepare] JESS");
402 int tmp1 = abs(sat.frequency
405 volatile unsigned int tmp2 = (1000 + 2 * tmp1) / (2 *1000); //round to multiple of 1000
406 parm.FREQUENCY = lnb_param.SatCRvco - (tmp1 - (1000 * tmp2));
407 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - lof -(lnb_param.SatCRvco - parm.FREQUENCY));
409 lnb_param.UnicableTuningWord =
410 (band & 0x3) //Bit0:HighLow Bit1:VertHor
411 | (((lnb_param.LNBNum - 1) & 0x3F) << 2) //position number (max. 63)
412 | ((tmp2 & 0x7FF)<< 8) //frequency (-100MHz Offset)
413 | ((lnb_param.SatCR_idx & 0x1F) << 19); //adresse of SatCR (max. 32)
415 eDebug("[prepare] UnicableTuningWord %#06x",lnb_param.UnicableTuningWord);
421 eDebug("[prepare] Unicable");
422 int tmp1 = abs(sat.frequency
426 + lnb_param.guard_offset;
427 volatile unsigned int tmp2 = (4000 + 2 * tmp1) / (2 *4000); //round to multiple of 4000
429 parm.FREQUENCY = lnb_param.SatCRvco - (tmp1 - (4000 * tmp2)) + lnb_param.guard_offset;
430 lnb_param.UnicableTuningWord = tmp2
431 | ((band & 1) ? 0x400 : 0) //HighLow
432 | ((band & 2) ? 0x800 : 0) //VertHor
433 | ((lnb_param.LNBNum & 1) ? 0 : 0x1000) //Umschaltung LNB1 LNB2
434 | (lnb_param.SatCR_idx << 13); //Adresse des SatCR
436 eDebug("[prepare] UnicableTuningWord %#04x",lnb_param.UnicableTuningWord);
437 eDebug("[prepare] guard_offset %d",lnb_param.guard_offset);
439 frontend.setData(eDVBFrontend::FREQ_OFFSET, (lnb_param.UnicableTuningWord & 0x3FF) *4000 + 1400000 + lof - (2 * (lnb_param.SatCRvco - (tmp1 - (4000 * tmp2)))) );
442 voltage = VOLTAGE(13);
445 if (diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
447 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
448 csw = 0xF0 | (csw << 2);
450 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
454 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
457 (di_param.m_uncommitted_cmd && diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
460 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
462 bool changed_csw = false;
463 bool changed_ucsw = false;
464 bool changed_burst = false;
465 if (direct_connected || (linked_fe && (!linked_fe->m_frontend->isLoopTimerActive() || !linked_fe->m_frontend->isScheduledSendDiseqc())))
467 changed_csw = send_csw && (forceChanged || csw != lastcsw);
468 changed_ucsw = send_ucsw && (forceChanged || ucsw != lastucsw);
469 changed_burst = send_burst && (forceChanged || toneburst != lastToneburst);
475 4 send toneburst first
476 8 send toneburst at end */
477 if (changed_burst) // toneburst first and toneburst changed
479 if (di_param.m_command_order&1)
493 if ((di_param.m_command_order&4) && send_csw)
495 if (di_param.m_command_order==4 && send_burst)
500 if ( di_param.m_use_fast
501 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
503 && ((csw / 4) == (lastcsw / 4)) )
504 eDebugNoSimulate("dont send committed cmd (fast diseqc)");
508 if (!(di_param.m_command_order&4) && send_ucsw)
510 if (!(di_param.m_command_order&1) && send_burst)
516 eDebugNoNewLine("sendmask: ");
517 for (int i=3; i >= 0; --i)
518 if ( send_mask & (1<<i) )
519 eDebugNoNewLine("1");
521 eDebugNoNewLine("0");
524 if ( diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
525 && !sat.no_rotor_command_on_tune )
527 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
528 RotorCmd=sw_param.m_rotorPosNum;
529 else // we must calc gotoxx cmd
531 eDebugNoSimulate("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
534 double SatLon = abs(sat.orbital_position)/10.00,
535 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
536 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
538 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
541 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
542 SiteLon = 360 - SiteLon;
544 eDebugNoSimulate("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
545 double satHourAngle =
546 calcSatHourangle( SatLon, SiteLat, SiteLon );
547 eDebugNoSimulate("PolarmountHourAngle=%lf", satHourAngle );
549 static int gotoXTable[10] =
550 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
552 if (SiteLat >= 0) // Northern Hemisphere
554 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
555 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
557 if (satHourAngle < 180) // the east
562 else // Southern Hemisphere
564 if (satHourAngle < 180) // the east
566 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
567 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
572 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
573 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
577 eDebugNoSimulate("RotorCmd = %04x", RotorCmd);
583 int diseqc_repeats = diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0 ? di_param.m_repeats : 0;
584 int vlt = iDVBFrontend::voltageOff;
585 eSecCommand::pair compare;
587 compare.tone = iDVBFrontend::toneOff;
588 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
589 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
590 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
593 vlt = iDVBFrontend::voltage13;
594 else if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
596 if (rotor_param.m_inputpower_parameters.m_use && !is_unicable)
597 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
599 vlt = VOLTAGE(13); // in normal mode start turning with 13V
604 // check if voltage is already correct..
605 compare.voltage = vlt;
607 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
609 // check if voltage is disabled
610 compare.voltage = iDVBFrontend::voltageOff;
612 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
614 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS
615 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
616 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
617 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
619 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
620 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
621 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
623 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
626 eDVBDiseqcCommand diseqc;
627 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
629 diseqc.data[0] = 0xE0;
633 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
634 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_RESET_CMD]) );
636 // diseqc peripherial powersupply on
637 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
638 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD]) );
641 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
645 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
646 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
656 loops <<= diseqc_repeats;
658 for ( int i = 0; i < loops;) // fill commands...
660 eDVBDiseqcCommand diseqc;
661 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
663 diseqc.data[0] = i ? 0xE1 : 0xE0;
664 diseqc.data[1] = 0x10;
665 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
667 diseqc.data[2] = 0x39;
668 diseqc.data[3] = ucsw;
670 else if ( send_mask & 1 )
672 diseqc.data[2] = 0x38;
673 diseqc.data[3] = csw;
675 else // no committed command confed.. so send uncommitted..
677 diseqc.data[2] = 0x39;
678 diseqc.data[3] = ucsw;
680 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
686 if (diseqc.data[2] == 0x38 && (send_mask & 2))
688 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
690 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
693 int delay = diseqc_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
694 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
696 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
697 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
700 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
702 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
704 else // delay 120msek when no command is in repeat gap
705 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
708 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
711 if ( send_mask & 8 ) // toneburst at end of sequence
713 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
714 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
717 if (di_param.m_seq_repeat && seq_repeat == 0)
718 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BEFORE_SEQUENCE_REPEAT]) );
724 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
728 sec_fe->setData(eDVBFrontend::NEW_CSW, csw);
729 sec_fe->setData(eDVBFrontend::NEW_UCSW, ucsw);
730 sec_fe->setData(eDVBFrontend::NEW_TONEBURST, di_param.m_toneburst_param);
731 sec_fe->setData(eDVBFrontend::LINKABLE_CSW, csw);
732 sec_fe->setData(eDVBFrontend::LINKABLE_UCSW, ucsw);
733 sec_fe->setData(eDVBFrontend::LINKABLE_TONEBURST, di_param.m_toneburst_param);
737 // check if voltage is disabled
738 eSecCommand::pair compare;
740 compare.voltage = iDVBFrontend::voltageOff;
741 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
742 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
743 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS] ) );
745 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
746 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
747 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) ); // wait 20 ms after voltage change
749 eDVBDiseqcCommand diseqc;
750 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
752 long oldSatcr, oldPin, oldDiction;
753 frontend.getData(eDVBFrontend::SATCR, oldSatcr);
754 frontend.getData(eDVBFrontend::PIN, oldPin);
755 frontend.getData(eDVBFrontend::DICTION, oldDiction);
757 if((oldSatcr != -1) && (oldSatcr != lnb_param.SatCR_idx))
765 diseqc.data[0] = 0x70;
770 diseqc.data[0] = 0x71;
771 diseqc.data[4] = oldPin;
773 diseqc.data[1] = oldSatcr << 3;
774 diseqc.data[2] = 0x00;
775 diseqc.data[3] = 0x00;
782 diseqc.data[2] = 0x5A;
787 diseqc.data[2] = 0x5C;
788 diseqc.data[5] = oldPin;
790 diseqc.data[0] = 0xE0;
791 diseqc.data[1] = 0x10;
792 diseqc.data[3] = oldSatcr << 5;
793 diseqc.data[4] = 0x00;
796 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
797 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
798 frontend.setData(eDVBFrontend::SATCR, -1);
801 frontend.setData(eDVBFrontend::DICTION, lnb_param.SatCR_format);
802 //TODO frontend.setData(eDVBFrontend::PIN, lnb_param.SatCR_pin);
804 long pin = 0; // hack
806 switch(lnb_param.SatCR_format)
812 diseqc.data[0] = 0x70;
813 diseqc.data[1] = lnb_param.UnicableTuningWord >> 16;
814 diseqc.data[2] = lnb_param.UnicableTuningWord >> 8;
815 diseqc.data[3] = lnb_param.UnicableTuningWord;
820 diseqc.data[0] = 0x71;
821 diseqc.data[4] = pin;
823 diseqc.data[1] = lnb_param.UnicableTuningWord >> 16;
824 diseqc.data[2] = lnb_param.UnicableTuningWord >> 8;
825 diseqc.data[3] = lnb_param.UnicableTuningWord;
832 diseqc.data[2] = 0x5A;
837 diseqc.data[2] = 0x5C;
838 diseqc.data[5] = pin;
840 diseqc.data[0] = 0xE0;
841 diseqc.data[1] = 0x10;
842 diseqc.data[3] = lnb_param.UnicableTuningWord >> 8;
843 diseqc.data[4] = lnb_param.UnicableTuningWord;
845 frontend.setData(eDVBFrontend::SATCR, lnb_param.SatCR_idx);
847 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
848 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
849 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
850 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd && !rotor_param.m_inputpower_parameters.m_use)
851 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
854 eDebugNoSimulate("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
855 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
857 int mrt = m_params[MOTOR_RUNNING_TIMEOUT]; // in seconds!
858 eSecCommand::pair compare;
859 if (!send_mask && !is_unicable)
862 compare.tone = iDVBFrontend::toneOff;
863 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
864 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
865 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
867 compare.voltage = iDVBFrontend::voltageOff;
869 // the next is a check if voltage is switched off.. then we first set a voltage :)
870 // else we set voltage after all diseqc stuff..
871 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
873 if (rotor_param.m_inputpower_parameters.m_use)
874 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
876 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
878 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
879 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
882 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
884 eDVBDiseqcCommand diseqc;
885 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
887 diseqc.data[0] = 0xE0;
888 diseqc.data[1] = 0x31; // positioner
889 diseqc.data[2] = 0x60; // stop
890 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
891 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
892 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
893 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
894 // wait 150msec after send rotor stop cmd
895 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
897 diseqc.data[0] = 0xE0;
898 diseqc.data[1] = 0x31; // positioner
902 diseqc.data[2] = 0x6E; // drive to angular position
903 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
904 diseqc.data[4] = RotorCmd & 0xFF;
909 diseqc.data[2] = 0x6B; // goto stored sat position
910 diseqc.data[3] = RotorCmd;
911 diseqc.data[4] = 0x00;
914 // use measure rotor input power to detect motor state
915 if ( rotor_param.m_inputpower_parameters.m_use)
917 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed) && !is_unicable;
918 eSecCommand::rotor cmd;
919 eSecCommand::pair compare;
921 compare.voltage = VOLTAGE(18);
923 compare.voltage = VOLTAGE(13);
925 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
926 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
927 // measure idle power values
930 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
931 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
933 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
934 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
936 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
937 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
939 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
940 ////////////////////////////
941 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
942 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
943 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
944 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
946 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
947 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
948 cmd.direction=1; // check for running rotor
949 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
952 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
953 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
954 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
955 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
956 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
958 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
960 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
961 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*20) ); // mrt is in seconds... our SLEEP time is 50ms.. so * 20
962 // rotor running loop
963 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
964 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
965 cmd.direction=0; // check for stopped rotor
967 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
968 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
969 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
970 /////////////////////
971 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
972 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
974 // use normal motor turning mode
977 if (curRotorPos != -1)
979 mrt = abs(curRotorPos - sat.orbital_position);
983 mrt += 10; // round a little bit
984 mrt *= 2000; // (we assume a very slow rotor with just 0.5 degree per second here)
986 mrt += 3; // a little bit overhead
988 doSetVoltageToneFrontend=false;
990 eSecCommand::rotor cmd;
991 eSecCommand::pair compare;
992 compare.voltage = VOLTAGE(13);
994 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
995 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
996 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
998 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
999 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
1000 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
1001 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) ); // sleep one second before change voltage or tone
1003 compare.voltage = voltage;
1005 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
1006 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
1007 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
1009 compare.tone = tone;
1010 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
1011 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
1012 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
1013 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 0) );
1015 cmd.direction=1; // check for running rotor
1019 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*4) ); // mrt is in seconds... our SLEEP time is 250ms.. so * 4
1020 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
1021 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
1022 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +5 ) );
1023 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
1024 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
1025 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
1026 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +4) );
1027 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
1028 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
1029 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -5) );
1030 eDebug("set rotor timeout to %d seconds", mrt);
1032 sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
1033 sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
1036 if (doSetVoltageToneFrontend && !is_unicable)
1038 eSecCommand::pair compare;
1039 compare.voltage = voltage;
1041 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
1042 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
1043 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
1044 compare.tone = tone;
1045 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
1046 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
1047 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
1050 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_SWITCHPARMS) );
1054 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
1055 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
1058 sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
1059 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
1060 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
1062 frontend.setSecSequence(sec_sequence);
1067 eDebugNoSimulate("found no useable satellite configuration for %s freq %d%s %s on orbital position (%d)",
1068 sat.system ? "DVB-S2" : "DVB-S",
1070 sat.polarisation == eDVBFrontendParametersSatellite::Polarisation_Horizontal ? "H" :
1071 eDVBFrontendParametersSatellite::Polarisation_Vertical ? "V" :
1072 eDVBFrontendParametersSatellite::Polarisation_CircularLeft ? "CL" : "CR",
1073 sat.modulation == eDVBFrontendParametersSatellite::Modulation_Auto ? "AUTO" :
1074 eDVBFrontendParametersSatellite::Modulation_QPSK ? "QPSK" :
1075 eDVBFrontendParametersSatellite::Modulation_8PSK ? "8PSK" : "QAM16",
1076 sat.orbital_position );
1080 void eDVBSatelliteEquipmentControl::prepareTurnOffSatCR(iDVBFrontend &frontend)
1082 long satcr, diction, pin;
1083 eSecCommandList sec_sequence;
1085 // check if voltage is disabled
1086 eSecCommand::pair compare;
1087 compare.steps = +9; //only close frontend
1088 compare.voltage = iDVBFrontend::voltageOff;
1090 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
1091 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1092 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
1094 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18_5) );
1095 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
1096 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
1098 eDVBDiseqcCommand diseqc;
1099 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
1100 frontend.getData(eDVBFrontend::SATCR, satcr);
1101 frontend.getData(eDVBFrontend::DICTION, diction);
1102 frontend.getData(eDVBFrontend::PIN, pin);
1110 diseqc.data[0] = 0x70;
1115 diseqc.data[0] = 0x71;
1116 diseqc.data[4] = pin;
1118 diseqc.data[1] = satcr << 3;
1119 diseqc.data[2] = 0x00;
1120 diseqc.data[3] = 0x00;
1127 diseqc.data[2] = 0x5A;
1132 diseqc.data[2] = 0x5C;
1133 diseqc.data[5] = pin;
1135 diseqc.data[0] = 0xE0;
1136 diseqc.data[1] = 0x10;
1137 diseqc.data[3] = satcr << 5;
1138 diseqc.data[4] = 0x00;
1141 frontend.setData(eDVBFrontend::SATCR, -1);
1143 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
1144 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
1145 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1146 sec_sequence.push_back( eSecCommand(eSecCommand::DELAYED_CLOSE_FRONTEND) );
1148 frontend.setSecSequence(sec_sequence);
1151 RESULT eDVBSatelliteEquipmentControl::clear()
1153 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
1154 for (int i=0; i <= m_lnbidx; ++i)
1156 m_lnbs[i].m_satellites.clear();
1157 m_lnbs[i].m_slot_mask = 0;
1158 m_lnbs[i].m_prio = -1; // auto
1162 m_not_linked_slot_mask=0;
1164 //reset some tuner configuration
1165 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1167 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1168 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1169 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1170 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1171 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1172 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1174 if (it->m_frontend->is_FBCTuner())
1176 eFBCTunerManager *fbcmng = eFBCTunerManager::getInstance();
1178 fbcmng->setDefaultFBCID(*it);
1182 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1184 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1185 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1186 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1187 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1188 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1189 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1195 /* LNB Specific Parameters */
1196 RESULT eDVBSatelliteEquipmentControl::addLNB()
1198 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
1199 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
1202 eDebug("no more LNB free... cnt is %d", m_lnbidx);
1205 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
1209 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
1211 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
1212 if ( currentLNBValid() )
1213 m_lnbs[m_lnbidx].m_slot_mask = slotmask;
1219 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
1221 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
1222 if ( currentLNBValid() )
1223 m_lnbs[m_lnbidx].m_lof_lo = lofl;
1229 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
1231 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
1232 if ( currentLNBValid() )
1233 m_lnbs[m_lnbidx].m_lof_hi = lofh;
1239 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
1241 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
1242 if ( currentLNBValid() )
1243 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
1249 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
1251 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
1252 if ( currentLNBValid() )
1253 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
1259 RESULT eDVBSatelliteEquipmentControl::setLNBPrio(int prio)
1261 eSecDebug("eDVBSatelliteEquipmentControl::setLNBPrio(%d)", prio);
1262 if ( currentLNBValid() )
1263 m_lnbs[m_lnbidx].m_prio = prio;
1269 RESULT eDVBSatelliteEquipmentControl::setLNBNum(int LNBNum)
1271 eSecDebug("eDVBSatelliteEquipmentControl::setLNBNum(%d)", LNBNum);
1272 if(!((LNBNum >= 1) && (LNBNum <= MAX_LNBNUM)))
1274 if ( currentLNBValid() )
1275 m_lnbs[m_lnbidx].LNBNum = LNBNum;
1281 /* DiSEqC Specific Parameters */
1282 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
1284 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
1285 if ( currentLNBValid() )
1286 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
1292 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
1294 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
1295 if ( currentLNBValid() )
1296 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
1302 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
1304 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
1305 if ( currentLNBValid() )
1306 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
1312 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
1314 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
1315 if ( currentLNBValid() )
1316 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
1322 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
1324 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
1325 if ( currentLNBValid() )
1326 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
1332 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
1334 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
1335 if ( currentLNBValid() )
1336 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
1342 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
1344 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
1345 if ( currentLNBValid() )
1346 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
1352 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
1354 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
1355 if ( currentLNBValid() )
1356 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1362 /* Rotor Specific Parameters */
1363 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1365 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
1366 if ( currentLNBValid() )
1367 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1373 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1375 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
1376 if ( currentLNBValid() )
1377 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1383 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1385 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1386 if ( currentLNBValid() )
1387 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1393 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1395 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1396 if ( currentLNBValid() )
1397 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1403 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1405 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1406 if ( currentLNBValid() )
1407 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1413 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1415 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1416 if ( currentLNBValid() )
1417 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1423 /* Unicable Specific Parameters */
1424 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRformat(int SatCR_format)
1426 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRformat(%d)", SatCR_format);
1427 if(!((SatCR_format >-1) && (SatCR_format < 2)))
1429 if ( currentLNBValid() )
1430 m_lnbs[m_lnbidx].SatCR_format = SatCR_format;
1436 RESULT eDVBSatelliteEquipmentControl::setLNBSatCR(int SatCR_idx)
1438 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCR(%d)", SatCR_idx);
1439 if(!((SatCR_idx >=-1) && (SatCR_idx < MAX_SATCR)))
1441 if ( currentLNBValid() )
1442 m_lnbs[m_lnbidx].SatCR_idx = SatCR_idx;
1448 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRvco(int SatCRvco)
1450 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRvco(%d)", SatCRvco);
1451 if(!((SatCRvco >= 950*1000) && (SatCRvco <= 2150*1000)))
1453 if(!((m_lnbs[m_lnbidx].SatCR_idx >= 0) && (m_lnbs[m_lnbidx].SatCR_idx < MAX_SATCR)))
1455 if ( currentLNBValid() )
1456 m_lnbs[m_lnbidx].SatCRvco = SatCRvco;
1462 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRpositions(int SatCR_positions)
1464 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRpositions(%d)", SatCR_positions);
1465 if(SatCR_positions < 1 || SatCR_positions > 2)
1467 if ( currentLNBValid() )
1468 m_lnbs[m_lnbidx].SatCR_positions = SatCR_positions;
1474 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRpositions()
1476 if ( currentLNBValid() )
1477 return m_lnbs[m_lnbidx].SatCR_positions;
1481 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRformat()
1483 if ( currentLNBValid() )
1484 return m_lnbs[m_lnbidx].SatCR_format;
1488 RESULT eDVBSatelliteEquipmentControl::getLNBSatCR()
1490 if ( currentLNBValid() )
1491 return m_lnbs[m_lnbidx].SatCR_idx;
1495 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRvco()
1497 if ( currentLNBValid() )
1498 return m_lnbs[m_lnbidx].SatCRvco;
1502 /* Satellite Specific Parameters */
1503 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1505 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1506 if ( currentLNBValid() )
1508 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1509 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1510 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1512 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1513 m_lnbs[m_lnbidx].m_satellites.insert(
1514 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1517 m_curSat = ret.first;
1529 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1531 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1532 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1533 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1540 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1542 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1543 if ( currentLNBValid() )
1545 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1546 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1555 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1557 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1558 if ( currentLNBValid() )
1560 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1561 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1570 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1572 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1573 if ( currentLNBValid() )
1574 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1582 int orb_pos, lofl, lofh;
1583 sat_compare(int o, int lofl, int lofh)
1584 :orb_pos(o), lofl(lofl), lofh(lofh)
1586 sat_compare(const sat_compare &x)
1587 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1589 bool operator < (const sat_compare & cmp) const
1591 if (orb_pos == cmp.orb_pos)
1593 if ( abs(lofl-cmp.lofl) < 200000 )
1595 if (abs(lofh-cmp.lofh) < 200000)
1597 return lofh<cmp.lofh;
1599 return lofl<cmp.lofl;
1601 return orb_pos < cmp.orb_pos;
1605 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1607 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1610 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1611 eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin());
1612 for (; it != m_avail_frontends.end(); ++it)
1614 if (it->m_frontend->getSlotID() == tu1)
1616 else if (it->m_frontend->getSlotID() == tu2)
1622 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1623 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1625 eFBCTunerManager *fbcmng = eFBCTunerManager::getInstance();
1626 if (p1->m_frontend->is_FBCTuner() && fbcmng)
1628 fbcmng->updateFBCID(p1, p2);
1633 it=m_avail_simulate_frontends.begin();
1634 for (; it != m_avail_simulate_frontends.end(); ++it)
1636 if (it->m_frontend->getSlotID() == tu1)
1638 else if (it->m_frontend->getSlotID() == tu2)
1643 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1644 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1651 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1653 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1657 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1659 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1661 if (it->m_frontend->getSlotID() == tu1)
1663 else if (it->m_frontend->getSlotID() == tu2)
1668 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1669 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1673 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1675 if (it->m_frontend->getSlotID() == tu1)
1677 else if (it->m_frontend->getSlotID() == tu2)
1682 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1683 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1690 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1692 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1693 m_not_linked_slot_mask |= (1 << slot_no);
1696 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1698 return m_rotorMoving;
1701 void eDVBSatelliteEquipmentControl::setRotorMoving(int slot_no, bool b)
1704 m_rotorMoving |= (1 << slot_no);
1706 m_rotorMoving &= ~(1 << slot_no);