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, linked_csw=-1, linked_ucsw=-1, linked_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::CSW, linked_csw);
93 fe->getData(eDVBFrontend::UCSW, linked_ucsw);
94 fe->getData(eDVBFrontend::TONEBURST, linked_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 != linked_csw) ||
168 ( diseqc && (ucsw != linked_ucsw || toneburst != linked_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 lnb_param.guard_offset = 0; //HACK
325 voltage_mode = eDVBSatelliteSwitchParameters::HV;
327 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
329 if (!(m_not_linked_slot_mask & slot_id)) // frontend with direct connection?
331 long linked_prev_ptr;
332 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
333 while (linked_prev_ptr != -1)
335 linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
336 sec_fe = linked_fe->m_frontend;
337 sec_fe->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
339 if (satposDependPtr != -1) // we dont need uncommitted switch and rotor cmds on second output of a rotor lnb
340 diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
342 // in eDVBFrontend::tuneLoop we call closeFrontend and ->inc_use() in this this condition (to put the kernel frontend thread into idle state)
343 // so we must resend all diseqc stuff (voltage is disabled when the frontend is closed)
345 sec_fe->getState(state);
346 if (!linked_fe->m_inuse && state != eDVBFrontend::stateIdle)
351 sec_fe->getData(eDVBFrontend::CSW, lastcsw);
352 sec_fe->getData(eDVBFrontend::UCSW, lastucsw);
353 sec_fe->getData(eDVBFrontend::TONEBURST, lastToneburst);
354 sec_fe->getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
355 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
357 if (lastcsw == lastucsw && lastToneburst == lastucsw && lastucsw == -1)
358 needDiSEqCReset = true;
360 if ( sat.frequency > lnb_param.m_lof_threshold )
362 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
365 int lof = (band&1)?lnb_param.m_lof_hi:lnb_param.m_lof_lo;
370 int local= abs(sat.frequency
372 parm.FREQUENCY = ((((local * 2) / 125) + 1) / 2) * 125;
373 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
375 if ( voltage_mode == eDVBSatelliteSwitchParameters::_14V
376 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical
377 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
378 voltage = VOLTAGE(13);
379 else if ( voltage_mode == eDVBSatelliteSwitchParameters::_18V
380 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical)
381 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
382 voltage = VOLTAGE(18);
383 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
384 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
385 tone = iDVBFrontend::toneOn;
386 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
387 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
388 tone = iDVBFrontend::toneOff;
392 switch(lnb_param.SatCR_format)
396 eDebug("[prepare] JESS");
398 int tmp1 = abs(sat.frequency
401 volatile unsigned int tmp2 = (1000 + 2 * tmp1) / (2 *1000); //round to multiple of 1000
402 parm.FREQUENCY = lnb_param.SatCRvco - (tmp1 - (1000 * tmp2));
403 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - lof -(lnb_param.SatCRvco - parm.FREQUENCY));
405 lnb_param.UnicableTuningWord =
406 (band & 0x3) //Bit0:HighLow Bit1:VertHor
407 | (((lnb_param.LNBNum - 1) & 0x3F) << 2) //position number (max. 63)
408 | ((tmp2 & 0x7FF)<< 8) //frequency (-100MHz Offset)
409 | ((lnb_param.SatCR_idx & 0x1F) << 19); //adresse of SatCR (max. 32)
411 eDebug("[prepare] UnicableTuningWord %#06x",lnb_param.UnicableTuningWord);
417 eDebug("[prepare] Unicable");
418 int tmp1 = abs(sat.frequency
422 + lnb_param.guard_offset;
423 volatile unsigned int tmp2 = (4000 + 2 * tmp1) / (2 *4000); //round to multiple of 4000
425 parm.FREQUENCY = lnb_param.SatCRvco - (tmp1 - (4000 * tmp2)) + lnb_param.guard_offset;
426 lnb_param.UnicableTuningWord = tmp2
427 | ((band & 1) ? 0x400 : 0) //HighLow
428 | ((band & 2) ? 0x800 : 0) //VertHor
429 | ((lnb_param.LNBNum & 1) ? 0 : 0x1000) //Umschaltung LNB1 LNB2
430 | (lnb_param.SatCR_idx << 13); //Adresse des SatCR
432 eDebug("[prepare] UnicableTuningWord %#04x",lnb_param.UnicableTuningWord);
433 eDebug("[prepare] guard_offset %d",lnb_param.guard_offset);
435 frontend.setData(eDVBFrontend::FREQ_OFFSET, (lnb_param.UnicableTuningWord & 0x3FF) *4000 + 1400000 + lof - (2 * (lnb_param.SatCRvco - (tmp1 - (4000 * tmp2)))) );
438 voltage = VOLTAGE(13);
441 if (diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
443 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
444 csw = 0xF0 | (csw << 2);
446 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
450 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
451 bool changed_csw = send_csw && (forceChanged || csw != lastcsw);
454 (di_param.m_uncommitted_cmd && diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
455 bool changed_ucsw = send_ucsw && (forceChanged || ucsw != lastucsw);
458 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
459 bool changed_burst = send_burst && (forceChanged || toneburst != lastToneburst);
464 4 send toneburst first
465 8 send toneburst at end */
466 if (changed_burst) // toneburst first and toneburst changed
468 if (di_param.m_command_order&1)
482 if ((di_param.m_command_order&4) && send_csw)
484 if (di_param.m_command_order==4 && send_burst)
489 if ( di_param.m_use_fast
490 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
492 && ((csw / 4) == (lastcsw / 4)) )
493 eDebugNoSimulate("dont send committed cmd (fast diseqc)");
497 if (!(di_param.m_command_order&4) && send_ucsw)
499 if (!(di_param.m_command_order&1) && send_burst)
505 eDebugNoNewLine("sendmask: ");
506 for (int i=3; i >= 0; --i)
507 if ( send_mask & (1<<i) )
508 eDebugNoNewLine("1");
510 eDebugNoNewLine("0");
513 if ( diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
514 && !sat.no_rotor_command_on_tune )
516 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
517 RotorCmd=sw_param.m_rotorPosNum;
518 else // we must calc gotoxx cmd
520 eDebugNoSimulate("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
523 double SatLon = abs(sat.orbital_position)/10.00,
524 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
525 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
527 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
530 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
531 SiteLon = 360 - SiteLon;
533 eDebugNoSimulate("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
534 double satHourAngle =
535 calcSatHourangle( SatLon, SiteLat, SiteLon );
536 eDebugNoSimulate("PolarmountHourAngle=%lf", satHourAngle );
538 static int gotoXTable[10] =
539 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
541 if (SiteLat >= 0) // Northern Hemisphere
543 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
544 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
546 if (satHourAngle < 180) // the east
551 else // Southern Hemisphere
553 if (satHourAngle < 180) // the east
555 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
556 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
561 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
562 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
566 eDebugNoSimulate("RotorCmd = %04x", RotorCmd);
572 int diseqc_repeats = diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0 ? di_param.m_repeats : 0;
573 int vlt = iDVBFrontend::voltageOff;
574 eSecCommand::pair compare;
576 compare.tone = iDVBFrontend::toneOff;
577 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
578 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
579 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
582 vlt = iDVBFrontend::voltage13;
583 else if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
585 if (rotor_param.m_inputpower_parameters.m_use && !is_unicable)
586 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
588 vlt = VOLTAGE(13); // in normal mode start turning with 13V
593 // check if voltage is already correct..
594 compare.voltage = vlt;
596 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
598 // check if voltage is disabled
599 compare.voltage = iDVBFrontend::voltageOff;
601 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
603 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS
604 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
605 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
606 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
608 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
609 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
610 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
612 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
615 eDVBDiseqcCommand diseqc;
616 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
618 diseqc.data[0] = 0xE0;
622 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
623 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_RESET_CMD]) );
625 // diseqc peripherial powersupply on
626 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
627 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD]) );
630 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
634 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
635 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
645 loops <<= diseqc_repeats;
647 for ( int i = 0; i < loops;) // fill commands...
649 eDVBDiseqcCommand diseqc;
650 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
652 diseqc.data[0] = i ? 0xE1 : 0xE0;
653 diseqc.data[1] = 0x10;
654 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
656 diseqc.data[2] = 0x39;
657 diseqc.data[3] = ucsw;
659 else if ( send_mask & 1 )
661 diseqc.data[2] = 0x38;
662 diseqc.data[3] = csw;
664 else // no committed command confed.. so send uncommitted..
666 diseqc.data[2] = 0x39;
667 diseqc.data[3] = ucsw;
669 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
675 if (diseqc.data[2] == 0x38 && (send_mask & 2))
677 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
679 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
682 int delay = diseqc_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
683 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
685 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
686 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
689 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
691 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
693 else // delay 120msek when no command is in repeat gap
694 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
697 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
700 if ( send_mask & 8 ) // toneburst at end of sequence
702 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
703 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
706 if (di_param.m_seq_repeat && seq_repeat == 0)
707 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BEFORE_SEQUENCE_REPEAT]) );
713 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
717 sec_fe->setData(eDVBFrontend::NEW_CSW, csw);
718 sec_fe->setData(eDVBFrontend::NEW_UCSW, ucsw);
719 sec_fe->setData(eDVBFrontend::NEW_TONEBURST, di_param.m_toneburst_param);
723 // check if voltage is disabled
724 eSecCommand::pair compare;
726 compare.voltage = iDVBFrontend::voltageOff;
727 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
728 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
729 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS] ) );
731 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
732 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
733 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) ); // wait 20 ms after voltage change
735 eDVBDiseqcCommand diseqc;
736 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
738 long oldSatcr, oldPin, oldDiction;
739 frontend.getData(eDVBFrontend::SATCR, oldSatcr);
740 frontend.getData(eDVBFrontend::PIN, oldPin);
741 frontend.getData(eDVBFrontend::DICTION, oldDiction);
743 if((oldSatcr != -1) && (oldSatcr != lnb_param.SatCR_idx))
751 diseqc.data[0] = 0x70;
756 diseqc.data[0] = 0x71;
757 diseqc.data[4] = oldPin;
759 diseqc.data[1] = oldSatcr << 3;
760 diseqc.data[2] = 0x00;
761 diseqc.data[3] = 0x00;
768 diseqc.data[2] = 0x5A;
773 diseqc.data[2] = 0x5C;
774 diseqc.data[5] = oldPin;
776 diseqc.data[0] = 0xE0;
777 diseqc.data[1] = 0x10;
778 diseqc.data[3] = oldSatcr << 5;
779 diseqc.data[4] = 0x00;
782 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
783 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
784 frontend.setData(eDVBFrontend::SATCR, -1);
787 frontend.setData(eDVBFrontend::DICTION, lnb_param.SatCR_format);
788 //TODO frontend.setData(eDVBFrontend::PIN, lnb_param.SatCR_pin);
790 long pin = 0; // hack
792 switch(lnb_param.SatCR_format)
798 diseqc.data[0] = 0x70;
799 diseqc.data[1] = lnb_param.UnicableTuningWord >> 16;
800 diseqc.data[2] = lnb_param.UnicableTuningWord >> 8;
801 diseqc.data[3] = lnb_param.UnicableTuningWord;
806 diseqc.data[0] = 0x71;
807 diseqc.data[4] = pin;
809 diseqc.data[1] = lnb_param.UnicableTuningWord >> 16;
810 diseqc.data[2] = lnb_param.UnicableTuningWord >> 8;
811 diseqc.data[3] = lnb_param.UnicableTuningWord;
818 diseqc.data[2] = 0x5A;
823 diseqc.data[2] = 0x5C;
824 diseqc.data[5] = pin;
826 diseqc.data[0] = 0xE0;
827 diseqc.data[1] = 0x10;
828 diseqc.data[3] = lnb_param.UnicableTuningWord >> 8;
829 diseqc.data[4] = lnb_param.UnicableTuningWord;
831 frontend.setData(eDVBFrontend::SATCR, lnb_param.SatCR_idx);
833 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
834 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
835 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
836 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd && !rotor_param.m_inputpower_parameters.m_use)
837 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
840 eDebugNoSimulate("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
841 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
843 int mrt = m_params[MOTOR_RUNNING_TIMEOUT]; // in seconds!
844 eSecCommand::pair compare;
845 if (!send_mask && !is_unicable)
848 compare.tone = iDVBFrontend::toneOff;
849 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
850 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
851 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
853 compare.voltage = iDVBFrontend::voltageOff;
855 // the next is a check if voltage is switched off.. then we first set a voltage :)
856 // else we set voltage after all diseqc stuff..
857 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
859 if (rotor_param.m_inputpower_parameters.m_use)
860 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
862 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
864 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
865 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
868 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
870 eDVBDiseqcCommand diseqc;
871 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
873 diseqc.data[0] = 0xE0;
874 diseqc.data[1] = 0x31; // positioner
875 diseqc.data[2] = 0x60; // stop
876 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
877 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
878 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
879 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
880 // wait 150msec after send rotor stop cmd
881 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
883 diseqc.data[0] = 0xE0;
884 diseqc.data[1] = 0x31; // positioner
888 diseqc.data[2] = 0x6E; // drive to angular position
889 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
890 diseqc.data[4] = RotorCmd & 0xFF;
895 diseqc.data[2] = 0x6B; // goto stored sat position
896 diseqc.data[3] = RotorCmd;
897 diseqc.data[4] = 0x00;
900 // use measure rotor input power to detect motor state
901 if ( rotor_param.m_inputpower_parameters.m_use)
903 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed) && !is_unicable;
904 eSecCommand::rotor cmd;
905 eSecCommand::pair compare;
907 compare.voltage = VOLTAGE(18);
909 compare.voltage = VOLTAGE(13);
911 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
912 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
913 // measure idle power values
916 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
917 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
919 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
920 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
922 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
923 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
925 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
926 ////////////////////////////
927 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
928 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
929 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
930 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
932 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
933 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
934 cmd.direction=1; // check for running rotor
935 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
938 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
939 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
940 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
941 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
942 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
944 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
946 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
947 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*20) ); // mrt is in seconds... our SLEEP time is 50ms.. so * 20
948 // rotor running loop
949 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
950 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
951 cmd.direction=0; // check for stopped rotor
953 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
954 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
955 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
956 /////////////////////
957 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
958 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
960 // use normal motor turning mode
963 if (curRotorPos != -1)
965 mrt = abs(curRotorPos - sat.orbital_position);
969 mrt += 10; // round a little bit
970 mrt *= 2000; // (we assume a very slow rotor with just 0.5 degree per second here)
972 mrt += 3; // a little bit overhead
974 doSetVoltageToneFrontend=false;
976 eSecCommand::rotor cmd;
977 eSecCommand::pair compare;
978 compare.voltage = VOLTAGE(13);
980 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
981 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
982 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
984 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
985 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
986 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
987 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) ); // sleep one second before change voltage or tone
989 compare.voltage = voltage;
991 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
992 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
993 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
996 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
997 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
998 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
999 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 0) );
1001 cmd.direction=1; // check for running rotor
1005 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*4) ); // mrt is in seconds... our SLEEP time is 250ms.. so * 4
1006 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
1007 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
1008 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +5 ) );
1009 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
1010 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
1011 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
1012 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +4) );
1013 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
1014 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
1015 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -5) );
1016 eDebug("set rotor timeout to %d seconds", mrt);
1018 sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
1019 sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
1022 if (doSetVoltageToneFrontend && !is_unicable)
1024 eSecCommand::pair compare;
1025 compare.voltage = voltage;
1027 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
1028 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
1029 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
1030 compare.tone = tone;
1031 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
1032 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
1033 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
1036 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_SWITCHPARMS) );
1040 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
1041 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
1044 sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
1045 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
1046 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
1048 frontend.setSecSequence(sec_sequence);
1053 eDebugNoSimulate("found no useable satellite configuration for %s freq %d%s %s on orbital position (%d)",
1054 sat.system ? "DVB-S2" : "DVB-S",
1056 sat.polarisation == eDVBFrontendParametersSatellite::Polarisation_Horizontal ? "H" :
1057 eDVBFrontendParametersSatellite::Polarisation_Vertical ? "V" :
1058 eDVBFrontendParametersSatellite::Polarisation_CircularLeft ? "CL" : "CR",
1059 sat.modulation == eDVBFrontendParametersSatellite::Modulation_Auto ? "AUTO" :
1060 eDVBFrontendParametersSatellite::Modulation_QPSK ? "QPSK" :
1061 eDVBFrontendParametersSatellite::Modulation_8PSK ? "8PSK" : "QAM16",
1062 sat.orbital_position );
1066 void eDVBSatelliteEquipmentControl::prepareTurnOffSatCR(iDVBFrontend &frontend)
1068 long satcr, diction, pin;
1069 eSecCommandList sec_sequence;
1071 // check if voltage is disabled
1072 eSecCommand::pair compare;
1073 compare.steps = +9; //only close frontend
1074 compare.voltage = iDVBFrontend::voltageOff;
1076 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
1077 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1078 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
1080 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18_5) );
1081 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
1082 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
1084 eDVBDiseqcCommand diseqc;
1085 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
1086 frontend.getData(eDVBFrontend::SATCR, satcr);
1087 frontend.getData(eDVBFrontend::DICTION, diction);
1088 frontend.getData(eDVBFrontend::PIN, pin);
1096 diseqc.data[0] = 0x70;
1101 diseqc.data[0] = 0x71;
1102 diseqc.data[4] = pin;
1104 diseqc.data[1] = satcr << 3;
1105 diseqc.data[2] = 0x00;
1106 diseqc.data[3] = 0x00;
1113 diseqc.data[2] = 0x5A;
1118 diseqc.data[2] = 0x5C;
1119 diseqc.data[5] = pin;
1121 diseqc.data[0] = 0xE0;
1122 diseqc.data[1] = 0x10;
1123 diseqc.data[3] = satcr << 5;
1124 diseqc.data[4] = 0x00;
1127 frontend.setData(eDVBFrontend::SATCR, -1);
1129 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
1130 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
1131 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1132 sec_sequence.push_back( eSecCommand(eSecCommand::DELAYED_CLOSE_FRONTEND) );
1134 frontend.setSecSequence(sec_sequence);
1137 RESULT eDVBSatelliteEquipmentControl::clear()
1139 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
1140 for (int i=0; i <= m_lnbidx; ++i)
1142 m_lnbs[i].m_satellites.clear();
1143 m_lnbs[i].m_slot_mask = 0;
1144 m_lnbs[i].m_prio = -1; // auto
1148 m_not_linked_slot_mask=0;
1150 //reset some tuner configuration
1151 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1153 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1154 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1155 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1156 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1157 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1158 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1160 if (it->m_frontend->is_FBCTuner())
1162 eFBCTunerManager *fbcmng = eFBCTunerManager::getInstance();
1164 fbcmng->setDefaultFBCID(*it);
1168 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1170 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1171 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1172 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1173 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1174 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1175 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1181 /* LNB Specific Parameters */
1182 RESULT eDVBSatelliteEquipmentControl::addLNB()
1184 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
1185 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
1188 eDebug("no more LNB free... cnt is %d", m_lnbidx);
1191 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
1195 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
1197 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
1198 if ( currentLNBValid() )
1199 m_lnbs[m_lnbidx].m_slot_mask = slotmask;
1205 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
1207 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
1208 if ( currentLNBValid() )
1209 m_lnbs[m_lnbidx].m_lof_lo = lofl;
1215 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
1217 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
1218 if ( currentLNBValid() )
1219 m_lnbs[m_lnbidx].m_lof_hi = lofh;
1225 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
1227 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
1228 if ( currentLNBValid() )
1229 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
1235 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
1237 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
1238 if ( currentLNBValid() )
1239 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
1245 RESULT eDVBSatelliteEquipmentControl::setLNBPrio(int prio)
1247 eSecDebug("eDVBSatelliteEquipmentControl::setLNBPrio(%d)", prio);
1248 if ( currentLNBValid() )
1249 m_lnbs[m_lnbidx].m_prio = prio;
1255 RESULT eDVBSatelliteEquipmentControl::setLNBNum(int LNBNum)
1257 eSecDebug("eDVBSatelliteEquipmentControl::setLNBNum(%d)", LNBNum);
1258 if(!((LNBNum >= 1) && (LNBNum <= MAX_LNBNUM)))
1260 if ( currentLNBValid() )
1261 m_lnbs[m_lnbidx].LNBNum = LNBNum;
1267 /* DiSEqC Specific Parameters */
1268 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
1270 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
1271 if ( currentLNBValid() )
1272 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
1278 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
1280 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
1281 if ( currentLNBValid() )
1282 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
1288 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
1290 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
1291 if ( currentLNBValid() )
1292 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
1298 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
1300 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
1301 if ( currentLNBValid() )
1302 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
1308 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
1310 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
1311 if ( currentLNBValid() )
1312 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
1318 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
1320 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
1321 if ( currentLNBValid() )
1322 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
1328 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
1330 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
1331 if ( currentLNBValid() )
1332 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
1338 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
1340 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
1341 if ( currentLNBValid() )
1342 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1348 /* Rotor Specific Parameters */
1349 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1351 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
1352 if ( currentLNBValid() )
1353 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1359 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1361 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
1362 if ( currentLNBValid() )
1363 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1369 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1371 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1372 if ( currentLNBValid() )
1373 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1379 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1381 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1382 if ( currentLNBValid() )
1383 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1389 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1391 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1392 if ( currentLNBValid() )
1393 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1399 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1401 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1402 if ( currentLNBValid() )
1403 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1409 /* Unicable Specific Parameters */
1410 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRformat(int SatCR_format)
1412 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRformat(%d)", SatCR_format);
1413 if(!((SatCR_format >-1) && (SatCR_format < 2)))
1415 if ( currentLNBValid() )
1416 m_lnbs[m_lnbidx].SatCR_format = SatCR_format;
1422 RESULT eDVBSatelliteEquipmentControl::setLNBSatCR(int SatCR_idx)
1424 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCR(%d)", SatCR_idx);
1425 if(!((SatCR_idx >=-1) && (SatCR_idx < MAX_SATCR)))
1427 if ( currentLNBValid() )
1428 m_lnbs[m_lnbidx].SatCR_idx = SatCR_idx;
1434 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRvco(int SatCRvco)
1436 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRvco(%d)", SatCRvco);
1437 if(!((SatCRvco >= 950*1000) && (SatCRvco <= 2150*1000)))
1439 if(!((m_lnbs[m_lnbidx].SatCR_idx >= 0) && (m_lnbs[m_lnbidx].SatCR_idx < MAX_SATCR)))
1441 if ( currentLNBValid() )
1442 m_lnbs[m_lnbidx].SatCRvco = SatCRvco;
1448 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRpositions(int SatCR_positions)
1450 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRpositions(%d)", SatCR_positions);
1451 if(SatCR_positions < 1 || SatCR_positions > 2)
1453 if ( currentLNBValid() )
1454 m_lnbs[m_lnbidx].SatCR_positions = SatCR_positions;
1460 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRpositions()
1462 if ( currentLNBValid() )
1463 return m_lnbs[m_lnbidx].SatCR_positions;
1467 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRformat()
1469 if ( currentLNBValid() )
1470 return m_lnbs[m_lnbidx].SatCR_format;
1474 RESULT eDVBSatelliteEquipmentControl::getLNBSatCR()
1476 if ( currentLNBValid() )
1477 return m_lnbs[m_lnbidx].SatCR_idx;
1481 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRvco()
1483 if ( currentLNBValid() )
1484 return m_lnbs[m_lnbidx].SatCRvco;
1488 /* Satellite Specific Parameters */
1489 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1491 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1492 if ( currentLNBValid() )
1494 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1495 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1496 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1498 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1499 m_lnbs[m_lnbidx].m_satellites.insert(
1500 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1503 m_curSat = ret.first;
1515 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1517 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1518 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1519 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1526 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1528 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1529 if ( currentLNBValid() )
1531 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1532 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1541 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1543 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1544 if ( currentLNBValid() )
1546 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1547 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1556 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1558 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1559 if ( currentLNBValid() )
1560 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1568 int orb_pos, lofl, lofh;
1569 sat_compare(int o, int lofl, int lofh)
1570 :orb_pos(o), lofl(lofl), lofh(lofh)
1572 sat_compare(const sat_compare &x)
1573 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1575 bool operator < (const sat_compare & cmp) const
1577 if (orb_pos == cmp.orb_pos)
1579 if ( abs(lofl-cmp.lofl) < 200000 )
1581 if (abs(lofh-cmp.lofh) < 200000)
1583 return lofh<cmp.lofh;
1585 return lofl<cmp.lofl;
1587 return orb_pos < cmp.orb_pos;
1591 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1593 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1596 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1597 eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin());
1598 for (; it != m_avail_frontends.end(); ++it)
1600 if (it->m_frontend->getSlotID() == tu1)
1602 else if (it->m_frontend->getSlotID() == tu2)
1608 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1609 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1611 eFBCTunerManager *fbcmng = eFBCTunerManager::getInstance();
1612 if (p1->m_frontend->is_FBCTuner() && fbcmng)
1614 fbcmng->updateFBCID(p1, p2);
1619 it=m_avail_simulate_frontends.begin();
1620 for (; it != m_avail_simulate_frontends.end(); ++it)
1622 if (it->m_frontend->getSlotID() == tu1)
1624 else if (it->m_frontend->getSlotID() == tu2)
1629 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1630 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1637 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1639 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1643 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1645 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1647 if (it->m_frontend->getSlotID() == tu1)
1649 else if (it->m_frontend->getSlotID() == tu2)
1654 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1655 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1659 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_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);
1676 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1678 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1679 m_not_linked_slot_mask |= (1 << slot_no);
1682 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1684 return m_rotorMoving;
1687 void eDVBSatelliteEquipmentControl::setRotorMoving(int slot_no, bool b)
1690 m_rotorMoving |= (1 << slot_no);
1692 m_rotorMoving &= ~(1 << slot_no);