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>
5 #include <lib/base/eerror.h>
11 #define eSecDebug(arg...) eDebug(arg)
13 #define eSecDebug(arg...)
16 DEFINE_REF(eDVBSatelliteEquipmentControl);
18 eDVBSatelliteEquipmentControl *eDVBSatelliteEquipmentControl::instance;
20 int eDVBSatelliteEquipmentControl::m_params[MAX_PARAMS];
22 defaults are set in python lib/python/Components/NimManager.py
23 in InitSecParams function via setParam call
26 void eDVBSatelliteEquipmentControl::setParam(int param, int value)
28 if (param >= 0 && param < MAX_PARAMS)
29 m_params[param]=value;
32 eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBRegisteredFrontend> &avail_frontends, eSmartPtrList<eDVBRegisteredFrontend> &avail_simulate_frontends)
33 :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)
40 #define eSecDebugNoSimulate(x...) \
46 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int slot_id, int *highest_score_lnb)
48 bool simulate = ((eDVBFrontend*)fe)->is_simulate();
49 bool direct_connected = m_not_linked_slot_mask & slot_id;
50 int score=0, satcount=0;
51 long linked_prev_ptr=-1, linked_next_ptr=-1, linkable_csw=-1, linkable_ucsw=-1, linkable_toneburst=-1,
52 fe_satpos_depends_ptr=-1, fe_rotor_pos=-1;
53 bool linked_in_use = false;
55 eSecDebugNoSimulate("direct_connected %d", !!direct_connected);
57 fe->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
58 fe->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
59 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, fe_satpos_depends_ptr);
61 // first we search the linkage base frontend and check if any tuner in prev direction is used
62 while (linked_prev_ptr != -1)
64 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
65 if (linked_fe->m_inuse)
67 fe = linked_fe->m_frontend;
68 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
71 fe->getData(eDVBFrontend::ROTOR_POS, fe_rotor_pos);
73 // now check also the linked tuners is in use
74 while (!linked_in_use && linked_next_ptr != -1)
76 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
77 if (linked_fe->m_inuse)
79 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, (long&)linked_next_ptr);
82 // when a linked in use tuner is found we get the tuner data...
85 fe->getData(eDVBFrontend::LINKABLE_CSW, linkable_csw);
86 fe->getData(eDVBFrontend::LINKABLE_UCSW, linkable_ucsw);
87 fe->getData(eDVBFrontend::LINKABLE_TONEBURST, linkable_toneburst);
90 if (highest_score_lnb)
91 *highest_score_lnb = -1;
93 eSecDebugNoSimulate("canTune %d", slot_id);
95 for (int idx=0; idx <= m_lnbidx; ++idx )
98 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
99 bool is_unicable = lnb_param.SatCR_idx != -1;
100 bool is_unicable_position_switch = lnb_param.SatCR_positions > 1;
102 if ( lnb_param.m_slot_mask & slot_id ) // lnb for correct tuner?
105 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
107 eSecDebugNoSimulate("lnb %d found", idx);
109 satcount += lnb_param.m_satellites.size();
111 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
112 lnb_param.m_satellites.find(sat.orbital_position);
113 if ( sit != lnb_param.m_satellites.end())
117 satpos_depends_ptr=fe_satpos_depends_ptr,
118 csw = di_param.m_committed_cmd,
119 ucsw = di_param.m_uncommitted_cmd,
120 toneburst = di_param.m_toneburst_param,
121 rotor_pos = fe_rotor_pos;
123 eSecDebugNoSimulate("sat %d found", sat.orbital_position);
125 if ( sat.frequency > lnb_param.m_lof_threshold )
127 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
130 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
133 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
134 csw = 0xF0 | (csw << 2);
136 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
139 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
150 if (sat.no_rotor_command_on_tune && !rotor) {
151 eSecDebugNoSimulate("no rotor but no_rotor_command_on_tune is set.. ignore lnb %d", idx);
155 eSecDebugNoSimulate("ret1 %d", ret);
157 if (linked_in_use && !is_unicable)
159 // compare tuner data
160 if ( (csw != linkable_csw) ||
161 ( diseqc && (ucsw != linkable_ucsw || toneburst != linkable_toneburst) ) ||
162 ( rotor && rotor_pos != sat.orbital_position ) )
168 eSecDebugNoSimulate("ret2 %d", ret);
170 else if ((satpos_depends_ptr != -1) && !(is_unicable && is_unicable_position_switch))
172 eSecDebugNoSimulate("satpos depends");
173 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
174 if (direct_connected) // current fe is direct connected.. (can turn the rotor)
176 if (satpos_depends_to_fe->m_inuse) // if the dependent frontend is in use?
178 if (!rotor || rotor_pos != sat.orbital_position) // new orbital position not equal to current orbital pos?
183 eSecDebugNoSimulate("ret3 %d", ret);
185 else // current fe is dependent of another tuner ... (so this fe can't turn the rotor!)
187 // get current orb pos of the tuner with rotor connection
188 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, rotor_pos);
189 if (!rotor || rotor_pos == -1 /* we dont know the rotor position yet */
190 || rotor_pos != sat.orbital_position ) // not the same orbital position?
195 eSecDebugNoSimulate("ret4 %d", ret);
198 if (ret && rotor && rotor_pos != -1)
199 ret -= abs(rotor_pos-sat.orbital_position);
201 eSecDebugNoSimulate("ret5 %d", ret);
203 if (ret && !is_unicable)
205 int lof = sat.frequency > lnb_param.m_lof_threshold ?
206 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
207 int tuner_freq = abs(sat.frequency - lof);
208 if (tuner_freq < 900000 || tuner_freq > 2200000)
212 if (ret && lnb_param.m_prio != -1)
213 ret = lnb_param.m_prio;
215 eSecDebugNoSimulate("ret %d, score old %d", ret, score);
219 if (highest_score_lnb)
220 *highest_score_lnb = idx;
222 eSecDebugNoSimulate("score new %d", score);
226 if (score && satcount)
228 if (score > (satcount-1))
229 score -= (satcount-1);
231 score = 1; // min score
233 if (score && direct_connected)
234 score += 5; // increase score for tuners with direct sat connection
235 eSecDebugNoSimulate("final score %d", score);
239 bool need_turn_fast(int turn_speed)
241 if (turn_speed == eDVBSatelliteRotorParameters::FAST)
243 else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
245 int begin = turn_speed >> 16; // high word is start time
246 int end = turn_speed&0xFFFF; // low word is end time
247 time_t now_time = ::time(0);
249 localtime_r(&now_time, &nowTime);
250 int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
251 bool neg = end <= begin;
257 if ((now >= begin && now < end) ^ neg)
263 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
265 #define eDebugNoSimulate(x...) \
271 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
273 bool simulate = ((eDVBFrontend*)&frontend)->is_simulate();
275 if (canTune(sat, &frontend, slot_id, &lnb_idx))
277 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[lnb_idx];
278 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
279 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
281 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
282 lnb_param.m_satellites.find(sat.orbital_position);
283 if ( sit != lnb_param.m_satellites.end())
285 eSecCommandList sec_sequence;
286 eDVBSatelliteSwitchParameters &sw_param = sit->second;
287 bool doSetFrontend = true;
288 bool doSetVoltageToneFrontend = true;
289 bool forceChanged = false;
290 bool needDiSEqCReset = false;
292 voltage = iDVBFrontend::voltageOff,
293 tone = iDVBFrontend::toneOff,
294 csw = di_param.m_committed_cmd,
295 ucsw = di_param.m_uncommitted_cmd,
296 toneburst = di_param.m_toneburst_param,
302 satposDependPtr = -1;
303 iDVBFrontend *sec_fe=&frontend;
304 eDVBRegisteredFrontend *linked_fe = 0;
305 eDVBSatelliteDiseqcParameters::t_diseqc_mode diseqc_mode = di_param.m_diseqc_mode;
306 eDVBSatelliteSwitchParameters::t_voltage_mode voltage_mode = sw_param.m_voltage_mode;
307 bool diseqc13V = voltage_mode == eDVBSatelliteSwitchParameters::HV_13;
308 bool is_unicable = lnb_param.SatCR_idx != -1;
310 bool useGotoXX = false;
314 bool direct_connected = m_not_linked_slot_mask & slot_id;
316 lnb_param.guard_offset = 0; //HACK
320 voltage_mode = eDVBSatelliteSwitchParameters::HV;
322 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
324 if (!direct_connected) // frontend with direct connection?
326 long linked_prev_ptr;
327 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
328 while (linked_prev_ptr != -1)
330 linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
331 sec_fe = linked_fe->m_frontend;
332 sec_fe->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
334 if (satposDependPtr != -1) // we dont need uncommitted switch and rotor cmds on second output of a rotor lnb
335 diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
336 #if 0 // Since following code causes lock fail for linked tuners in certain conditions, it does not apply.
338 // in eDVBFrontend::tuneLoop we call closeFrontend and ->inc_use() in this this condition (to put the kernel frontend thread into idle state)
339 // so we must resend all diseqc stuff (voltage is disabled when the frontend is closed)
341 sec_fe->getState(state);
342 if (!linked_fe->m_inuse && state != eDVBFrontend::stateIdle)
348 sec_fe->getData(eDVBFrontend::CSW, lastcsw);
349 sec_fe->getData(eDVBFrontend::UCSW, lastucsw);
350 sec_fe->getData(eDVBFrontend::TONEBURST, lastToneburst);
351 sec_fe->getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
352 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
354 if (lastcsw == lastucsw && lastToneburst == lastucsw && lastucsw == -1)
355 needDiSEqCReset = true;
357 if ( sat.frequency > lnb_param.m_lof_threshold )
359 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
362 int lof = (band&1)?lnb_param.m_lof_hi:lnb_param.m_lof_lo;
367 int local= abs(sat.frequency
369 parm.frequency = ((((local * 2) / 125) + 1) / 2) * 125;
370 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.frequency);
372 if ( voltage_mode == eDVBSatelliteSwitchParameters::_14V
373 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical
374 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
375 voltage = VOLTAGE(13);
376 else if ( voltage_mode == eDVBSatelliteSwitchParameters::_18V
377 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical)
378 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
379 voltage = VOLTAGE(18);
380 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
381 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
382 tone = iDVBFrontend::toneOn;
383 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
384 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
385 tone = iDVBFrontend::toneOff;
389 switch(lnb_param.SatCR_format)
393 eDebug("[prepare] JESS");
395 int tmp1 = abs(sat.frequency
398 volatile unsigned int tmp2 = (1000 + 2 * tmp1) / (2 *1000); //round to multiple of 1000
399 parm.frequency = lnb_param.SatCRvco - (tmp1 - (1000 * tmp2));
400 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - lof -(lnb_param.SatCRvco - parm.frequency));
402 lnb_param.UnicableTuningWord =
403 (band & 0x3) //Bit0:HighLow Bit1:VertHor
404 | (((lnb_param.LNBNum - 1) & 0x3F) << 2) //position number (max. 63)
405 | ((tmp2 & 0x7FF)<< 8) //frequency (-100MHz Offset)
406 | ((lnb_param.SatCR_idx & 0x1F) << 19); //adresse of SatCR (max. 32)
408 eDebug("[prepare] UnicableTuningWord %#06x",lnb_param.UnicableTuningWord);
414 eDebug("[prepare] Unicable");
415 int tmp1 = abs(sat.frequency
419 + lnb_param.guard_offset;
420 volatile unsigned int tmp2 = (4000 + 2 * tmp1) / (2 *4000); //round to multiple of 4000
422 parm.frequency = lnb_param.SatCRvco - (tmp1 - (4000 * tmp2)) + lnb_param.guard_offset;
423 lnb_param.UnicableTuningWord = tmp2
424 | ((band & 1) ? 0x400 : 0) //HighLow
425 | ((band & 2) ? 0x800 : 0) //VertHor
426 | ((lnb_param.LNBNum & 1) ? 0 : 0x1000) //Umschaltung LNB1 LNB2
427 | (lnb_param.SatCR_idx << 13); //Adresse des SatCR
429 eDebug("[prepare] UnicableTuningWord %#04x",lnb_param.UnicableTuningWord);
430 eDebug("[prepare] guard_offset %d",lnb_param.guard_offset);
432 frontend.setData(eDVBFrontend::FREQ_OFFSET, (lnb_param.UnicableTuningWord & 0x3FF) *4000 + 1400000 + lof - (2 * (lnb_param.SatCRvco - (tmp1 - (4000 * tmp2)))) );
435 voltage = VOLTAGE(13);
438 if (diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
440 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
441 csw = 0xF0 | (csw << 2);
443 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
447 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
450 (di_param.m_uncommitted_cmd && diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
453 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
455 bool changed_csw = false;
456 bool changed_ucsw = false;
457 bool changed_burst = false;
458 if (direct_connected || (linked_fe && (!linked_fe->m_frontend->isLoopTimerActive() || !linked_fe->m_frontend->isScheduledSendDiseqc())))
460 changed_csw = send_csw && (forceChanged || csw != lastcsw);
461 changed_ucsw = send_ucsw && (forceChanged || ucsw != lastucsw);
462 changed_burst = send_burst && (forceChanged || toneburst != lastToneburst);
468 4 send toneburst first
469 8 send toneburst at end */
470 if (changed_burst) // toneburst first and toneburst changed
472 if (di_param.m_command_order&1)
486 if ((di_param.m_command_order&4) && send_csw)
488 if (di_param.m_command_order==4 && send_burst)
493 if ( di_param.m_use_fast
494 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
496 && ((csw / 4) == (lastcsw / 4)) )
497 eDebugNoSimulate("dont send committed cmd (fast diseqc)");
501 if (!(di_param.m_command_order&4) && send_ucsw)
503 if (!(di_param.m_command_order&1) && send_burst)
509 eDebugNoNewLine("sendmask: ");
510 for (int i=3; i >= 0; --i)
511 if ( send_mask & (1<<i) )
512 eDebugNoNewLine("1");
514 eDebugNoNewLine("0");
517 if ( diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
518 && !sat.no_rotor_command_on_tune )
520 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
521 RotorCmd=sw_param.m_rotorPosNum;
522 else // we must calc gotoxx cmd
524 eDebugNoSimulate("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
527 double SatLon = abs(sat.orbital_position)/10.00,
528 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
529 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
531 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
534 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
535 SiteLon = 360 - SiteLon;
537 eDebugNoSimulate("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
538 double satHourAngle =
539 calcSatHourangle( SatLon, SiteLat, SiteLon );
540 eDebugNoSimulate("PolarmountHourAngle=%lf", satHourAngle );
542 static int gotoXTable[10] =
543 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
545 if (SiteLat >= 0) // Northern Hemisphere
547 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
548 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
550 if (satHourAngle < 180) // the east
555 else // Southern Hemisphere
557 if (satHourAngle < 180) // the east
559 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
560 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
565 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
566 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
570 eDebugNoSimulate("RotorCmd = %04x", RotorCmd);
576 int diseqc_repeats = diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0 ? di_param.m_repeats : 0;
577 int vlt = iDVBFrontend::voltageOff;
578 eSecCommand::pair compare;
580 compare.tone = iDVBFrontend::toneOff;
581 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
582 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
583 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
586 vlt = iDVBFrontend::voltage13;
587 else if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
589 if (rotor_param.m_inputpower_parameters.m_use && !is_unicable)
590 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
592 vlt = VOLTAGE(13); // in normal mode start turning with 13V
597 // check if voltage is already correct..
598 compare.voltage = vlt;
600 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
602 // check if voltage is disabled
603 compare.voltage = iDVBFrontend::voltageOff;
605 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
607 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS
608 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
609 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
610 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
612 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
613 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
614 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
616 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
619 eDVBDiseqcCommand diseqc;
620 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
622 diseqc.data[0] = 0xE0;
626 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
627 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_RESET_CMD]) );
629 // diseqc peripherial powersupply on
630 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
631 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD]) );
634 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
638 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
639 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
649 loops <<= diseqc_repeats;
651 for ( int i = 0; i < loops;) // fill commands...
653 eDVBDiseqcCommand diseqc;
654 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
656 diseqc.data[0] = i ? 0xE1 : 0xE0;
657 diseqc.data[1] = 0x10;
658 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
660 diseqc.data[2] = 0x39;
661 diseqc.data[3] = ucsw;
663 else if ( send_mask & 1 )
665 diseqc.data[2] = 0x38;
666 diseqc.data[3] = csw;
668 else // no committed command confed.. so send uncommitted..
670 diseqc.data[2] = 0x39;
671 diseqc.data[3] = ucsw;
673 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
679 if (diseqc.data[2] == 0x38 && (send_mask & 2))
681 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
683 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
686 int delay = diseqc_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
687 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
689 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
690 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
693 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
695 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
697 else // delay 120msek when no command is in repeat gap
698 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
701 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
704 if ( send_mask & 8 ) // toneburst at end of sequence
706 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
707 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
710 if (di_param.m_seq_repeat && seq_repeat == 0)
711 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BEFORE_SEQUENCE_REPEAT]) );
717 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
721 sec_fe->setData(eDVBFrontend::NEW_CSW, csw);
722 sec_fe->setData(eDVBFrontend::NEW_UCSW, ucsw);
723 sec_fe->setData(eDVBFrontend::NEW_TONEBURST, di_param.m_toneburst_param);
724 sec_fe->setData(eDVBFrontend::LINKABLE_CSW, csw);
725 sec_fe->setData(eDVBFrontend::LINKABLE_UCSW, ucsw);
726 sec_fe->setData(eDVBFrontend::LINKABLE_TONEBURST, di_param.m_toneburst_param);
730 // check if voltage is disabled
731 eSecCommand::pair compare;
733 compare.voltage = iDVBFrontend::voltageOff;
734 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
735 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
736 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS] ) );
738 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
739 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
740 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) ); // wait 20 ms after voltage change
742 eDVBDiseqcCommand diseqc;
743 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
745 long oldSatcr, oldPin, oldDiction;
746 frontend.getData(eDVBFrontend::SATCR, oldSatcr);
747 frontend.getData(eDVBFrontend::PIN, oldPin);
748 frontend.getData(eDVBFrontend::DICTION, oldDiction);
750 if((oldSatcr != -1) && (oldSatcr != lnb_param.SatCR_idx))
758 diseqc.data[0] = 0x70;
763 diseqc.data[0] = 0x71;
764 diseqc.data[4] = oldPin;
766 diseqc.data[1] = oldSatcr << 3;
767 diseqc.data[2] = 0x00;
768 diseqc.data[3] = 0x00;
775 diseqc.data[2] = 0x5A;
780 diseqc.data[2] = 0x5C;
781 diseqc.data[5] = oldPin;
783 diseqc.data[0] = 0xE0;
784 diseqc.data[1] = 0x10;
785 diseqc.data[3] = oldSatcr << 5;
786 diseqc.data[4] = 0x00;
789 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
790 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
791 frontend.setData(eDVBFrontend::SATCR, -1);
794 frontend.setData(eDVBFrontend::DICTION, lnb_param.SatCR_format);
795 //TODO frontend.setData(eDVBFrontend::PIN, lnb_param.SatCR_pin);
797 long pin = 0; // hack
799 switch(lnb_param.SatCR_format)
805 diseqc.data[0] = 0x70;
806 diseqc.data[1] = lnb_param.UnicableTuningWord >> 16;
807 diseqc.data[2] = lnb_param.UnicableTuningWord >> 8;
808 diseqc.data[3] = lnb_param.UnicableTuningWord;
813 diseqc.data[0] = 0x71;
814 diseqc.data[4] = pin;
816 diseqc.data[1] = lnb_param.UnicableTuningWord >> 16;
817 diseqc.data[2] = lnb_param.UnicableTuningWord >> 8;
818 diseqc.data[3] = lnb_param.UnicableTuningWord;
825 diseqc.data[2] = 0x5A;
830 diseqc.data[2] = 0x5C;
831 diseqc.data[5] = pin;
833 diseqc.data[0] = 0xE0;
834 diseqc.data[1] = 0x10;
835 diseqc.data[3] = lnb_param.UnicableTuningWord >> 8;
836 diseqc.data[4] = lnb_param.UnicableTuningWord;
838 frontend.setData(eDVBFrontend::SATCR, lnb_param.SatCR_idx);
840 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
841 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
842 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
843 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd && !rotor_param.m_inputpower_parameters.m_use)
844 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
847 eDebugNoSimulate("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
848 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
850 int mrt = m_params[MOTOR_RUNNING_TIMEOUT]; // in seconds!
851 eSecCommand::pair compare;
852 if (!send_mask && !is_unicable)
855 compare.tone = iDVBFrontend::toneOff;
856 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
857 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
858 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
860 compare.voltage = iDVBFrontend::voltageOff;
862 // the next is a check if voltage is switched off.. then we first set a voltage :)
863 // else we set voltage after all diseqc stuff..
864 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
866 if (rotor_param.m_inputpower_parameters.m_use)
867 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
869 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
871 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
872 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
875 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
877 eDVBDiseqcCommand diseqc;
878 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
880 diseqc.data[0] = 0xE0;
881 diseqc.data[1] = 0x31; // positioner
882 diseqc.data[2] = 0x60; // stop
883 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
884 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
885 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
886 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
887 // wait 150msec after send rotor stop cmd
888 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
890 diseqc.data[0] = 0xE0;
891 diseqc.data[1] = 0x31; // positioner
895 diseqc.data[2] = 0x6E; // drive to angular position
896 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
897 diseqc.data[4] = RotorCmd & 0xFF;
902 diseqc.data[2] = 0x6B; // goto stored sat position
903 diseqc.data[3] = RotorCmd;
904 diseqc.data[4] = 0x00;
907 // use measure rotor input power to detect motor state
908 if ( rotor_param.m_inputpower_parameters.m_use)
910 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed) && !is_unicable;
911 eSecCommand::rotor cmd;
912 eSecCommand::pair compare;
914 compare.voltage = VOLTAGE(18);
916 compare.voltage = VOLTAGE(13);
918 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
919 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
920 // measure idle power values
923 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
924 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
926 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
927 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
929 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
930 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
932 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
933 ////////////////////////////
934 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
935 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
936 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
937 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
939 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
940 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
941 cmd.direction=1; // check for running rotor
942 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
945 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
946 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
947 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
948 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
949 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
951 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
953 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
954 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*20) ); // mrt is in seconds... our SLEEP time is 50ms.. so * 20
955 // rotor running loop
956 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
957 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
958 cmd.direction=0; // check for stopped rotor
960 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
961 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
962 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
963 /////////////////////
964 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
965 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
967 // use normal motor turning mode
970 if (curRotorPos != -1)
972 mrt = abs(curRotorPos - sat.orbital_position);
976 mrt += 10; // round a little bit
977 mrt *= 2000; // (we assume a very slow rotor with just 0.5 degree per second here)
979 mrt += 3; // a little bit overhead
981 doSetVoltageToneFrontend=false;
983 eSecCommand::rotor cmd;
984 eSecCommand::pair compare;
985 compare.voltage = VOLTAGE(13);
987 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
988 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
989 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
991 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
992 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
993 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
994 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) ); // sleep one second before change voltage or tone
996 compare.voltage = voltage;
998 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
999 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
1000 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
1002 compare.tone = tone;
1003 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
1004 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
1005 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
1006 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 0) );
1008 cmd.direction=1; // check for running rotor
1012 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*4) ); // mrt is in seconds... our SLEEP time is 250ms.. so * 4
1013 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
1014 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
1015 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +5 ) );
1016 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
1017 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
1018 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
1019 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +4) );
1020 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
1021 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
1022 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -5) );
1023 eDebug("set rotor timeout to %d seconds", mrt);
1025 sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
1026 sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
1029 if (doSetVoltageToneFrontend && !is_unicable)
1031 eSecCommand::pair compare;
1032 compare.voltage = voltage;
1034 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
1035 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
1036 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
1037 compare.tone = tone;
1038 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
1039 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
1040 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
1043 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_SWITCHPARMS) );
1047 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
1048 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
1051 sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
1052 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
1053 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
1055 frontend.setSecSequence(sec_sequence);
1060 eDebugNoSimulate("found no useable satellite configuration for %s freq %d%s %s on orbital position (%d)",
1061 sat.system ? "DVB-S2" : "DVB-S",
1063 sat.polarisation == eDVBFrontendParametersSatellite::Polarisation_Horizontal ? "H" :
1064 eDVBFrontendParametersSatellite::Polarisation_Vertical ? "V" :
1065 eDVBFrontendParametersSatellite::Polarisation_CircularLeft ? "CL" : "CR",
1066 sat.modulation == eDVBFrontendParametersSatellite::Modulation_Auto ? "AUTO" :
1067 eDVBFrontendParametersSatellite::Modulation_QPSK ? "QPSK" :
1068 eDVBFrontendParametersSatellite::Modulation_8PSK ? "8PSK" : "QAM16",
1069 sat.orbital_position );
1073 void eDVBSatelliteEquipmentControl::prepareTurnOffSatCR(iDVBFrontend &frontend)
1075 long satcr, diction, pin;
1076 eSecCommandList sec_sequence;
1078 // check if voltage is disabled
1079 eSecCommand::pair compare;
1080 compare.steps = +9; //only close frontend
1081 compare.voltage = iDVBFrontend::voltageOff;
1083 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
1084 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1085 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
1087 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18_5) );
1088 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
1089 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
1091 eDVBDiseqcCommand diseqc;
1092 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
1093 frontend.getData(eDVBFrontend::SATCR, satcr);
1094 frontend.getData(eDVBFrontend::DICTION, diction);
1095 frontend.getData(eDVBFrontend::PIN, pin);
1103 diseqc.data[0] = 0x70;
1108 diseqc.data[0] = 0x71;
1109 diseqc.data[4] = pin;
1111 diseqc.data[1] = satcr << 3;
1112 diseqc.data[2] = 0x00;
1113 diseqc.data[3] = 0x00;
1120 diseqc.data[2] = 0x5A;
1125 diseqc.data[2] = 0x5C;
1126 diseqc.data[5] = pin;
1128 diseqc.data[0] = 0xE0;
1129 diseqc.data[1] = 0x10;
1130 diseqc.data[3] = satcr << 5;
1131 diseqc.data[4] = 0x00;
1134 frontend.setData(eDVBFrontend::SATCR, -1);
1136 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
1137 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
1138 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1139 sec_sequence.push_back( eSecCommand(eSecCommand::DELAYED_CLOSE_FRONTEND) );
1141 frontend.setSecSequence(sec_sequence);
1144 RESULT eDVBSatelliteEquipmentControl::clear()
1146 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
1147 for (int i=0; i <= m_lnbidx; ++i)
1149 m_lnbs[i].m_satellites.clear();
1150 m_lnbs[i].m_slot_mask = 0;
1151 m_lnbs[i].m_prio = -1; // auto
1155 m_not_linked_slot_mask=0;
1157 //reset some tuner configuration
1158 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1160 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1161 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1162 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1163 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1164 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1165 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1167 if (it->m_frontend->is_FBCTuner())
1169 eFBCTunerManager *fbcmng = eFBCTunerManager::getInstance();
1171 fbcmng->setDefaultFBCID(*it);
1175 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1177 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1178 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1179 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1180 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1181 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1182 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1188 /* LNB Specific Parameters */
1189 RESULT eDVBSatelliteEquipmentControl::addLNB()
1191 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
1192 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
1195 eDebug("no more LNB free... cnt is %d", m_lnbidx);
1198 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
1202 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
1204 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
1205 if ( currentLNBValid() )
1206 m_lnbs[m_lnbidx].m_slot_mask = slotmask;
1212 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
1214 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
1215 if ( currentLNBValid() )
1216 m_lnbs[m_lnbidx].m_lof_lo = lofl;
1222 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
1224 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
1225 if ( currentLNBValid() )
1226 m_lnbs[m_lnbidx].m_lof_hi = lofh;
1232 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
1234 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
1235 if ( currentLNBValid() )
1236 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
1242 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
1244 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
1245 if ( currentLNBValid() )
1246 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
1252 RESULT eDVBSatelliteEquipmentControl::setLNBPrio(int prio)
1254 eSecDebug("eDVBSatelliteEquipmentControl::setLNBPrio(%d)", prio);
1255 if ( currentLNBValid() )
1256 m_lnbs[m_lnbidx].m_prio = prio;
1262 RESULT eDVBSatelliteEquipmentControl::setLNBNum(int LNBNum)
1264 eSecDebug("eDVBSatelliteEquipmentControl::setLNBNum(%d)", LNBNum);
1265 if(!((LNBNum >= 1) && (LNBNum <= MAX_LNBNUM)))
1267 if ( currentLNBValid() )
1268 m_lnbs[m_lnbidx].LNBNum = LNBNum;
1274 /* DiSEqC Specific Parameters */
1275 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
1277 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
1278 if ( currentLNBValid() )
1279 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
1285 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
1287 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
1288 if ( currentLNBValid() )
1289 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
1295 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
1297 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
1298 if ( currentLNBValid() )
1299 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
1305 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
1307 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
1308 if ( currentLNBValid() )
1309 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
1315 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
1317 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
1318 if ( currentLNBValid() )
1319 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
1325 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
1327 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
1328 if ( currentLNBValid() )
1329 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
1335 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
1337 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
1338 if ( currentLNBValid() )
1339 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
1345 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
1347 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
1348 if ( currentLNBValid() )
1349 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1355 /* Rotor Specific Parameters */
1356 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1358 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
1359 if ( currentLNBValid() )
1360 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1366 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1368 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
1369 if ( currentLNBValid() )
1370 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1376 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1378 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1379 if ( currentLNBValid() )
1380 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1386 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1388 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1389 if ( currentLNBValid() )
1390 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1396 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1398 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1399 if ( currentLNBValid() )
1400 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1406 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1408 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1409 if ( currentLNBValid() )
1410 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1416 /* Unicable Specific Parameters */
1417 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRformat(int SatCR_format)
1419 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRformat(%d)", SatCR_format);
1420 if(!((SatCR_format >-1) && (SatCR_format < 2)))
1422 if ( currentLNBValid() )
1423 m_lnbs[m_lnbidx].SatCR_format = SatCR_format;
1429 RESULT eDVBSatelliteEquipmentControl::setLNBSatCR(int SatCR_idx)
1431 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCR(%d)", SatCR_idx);
1432 if(!((SatCR_idx >=-1) && (SatCR_idx < MAX_SATCR)))
1434 if ( currentLNBValid() )
1435 m_lnbs[m_lnbidx].SatCR_idx = SatCR_idx;
1441 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRvco(int SatCRvco)
1443 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRvco(%d)", SatCRvco);
1444 if(!((SatCRvco >= 950*1000) && (SatCRvco <= 2150*1000)))
1446 if(!((m_lnbs[m_lnbidx].SatCR_idx >= 0) && (m_lnbs[m_lnbidx].SatCR_idx < MAX_SATCR)))
1448 if ( currentLNBValid() )
1449 m_lnbs[m_lnbidx].SatCRvco = SatCRvco;
1455 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRpositions(int SatCR_positions)
1457 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRpositions(%d)", SatCR_positions);
1458 if(SatCR_positions < 1 || SatCR_positions > 2)
1460 if ( currentLNBValid() )
1461 m_lnbs[m_lnbidx].SatCR_positions = SatCR_positions;
1467 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRpositions()
1469 if ( currentLNBValid() )
1470 return m_lnbs[m_lnbidx].SatCR_positions;
1474 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRformat()
1476 if ( currentLNBValid() )
1477 return m_lnbs[m_lnbidx].SatCR_format;
1481 RESULT eDVBSatelliteEquipmentControl::getLNBSatCR()
1483 if ( currentLNBValid() )
1484 return m_lnbs[m_lnbidx].SatCR_idx;
1488 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRvco()
1490 if ( currentLNBValid() )
1491 return m_lnbs[m_lnbidx].SatCRvco;
1495 /* Satellite Specific Parameters */
1496 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1498 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1499 if ( currentLNBValid() )
1501 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1502 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1503 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1505 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1506 m_lnbs[m_lnbidx].m_satellites.insert(
1507 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1510 m_curSat = ret.first;
1522 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1524 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1525 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1526 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1533 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1535 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1536 if ( currentLNBValid() )
1538 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1539 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1548 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1550 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1551 if ( currentLNBValid() )
1553 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1554 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1563 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1565 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1566 if ( currentLNBValid() )
1567 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1575 int orb_pos, lofl, lofh;
1576 sat_compare(int o, int lofl, int lofh)
1577 :orb_pos(o), lofl(lofl), lofh(lofh)
1579 sat_compare(const sat_compare &x)
1580 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1582 bool operator < (const sat_compare & cmp) const
1584 if (orb_pos == cmp.orb_pos)
1586 if ( abs(lofl-cmp.lofl) < 200000 )
1588 if (abs(lofh-cmp.lofh) < 200000)
1590 return lofh<cmp.lofh;
1592 return lofl<cmp.lofl;
1594 return orb_pos < cmp.orb_pos;
1598 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1600 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1603 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1604 eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin());
1605 for (; it != m_avail_frontends.end(); ++it)
1607 if (it->m_frontend->getSlotID() == tu1)
1609 else if (it->m_frontend->getSlotID() == tu2)
1615 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1616 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1618 eFBCTunerManager *fbcmng = eFBCTunerManager::getInstance();
1619 if (p1->m_frontend->is_FBCTuner() && fbcmng)
1621 fbcmng->updateFBCID(p1, p2);
1626 it=m_avail_simulate_frontends.begin();
1627 for (; it != m_avail_simulate_frontends.end(); ++it)
1629 if (it->m_frontend->getSlotID() == tu1)
1631 else if (it->m_frontend->getSlotID() == tu2)
1636 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1637 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1644 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1646 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1650 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1652 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1654 if (it->m_frontend->getSlotID() == tu1)
1656 else if (it->m_frontend->getSlotID() == tu2)
1661 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1662 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1666 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1668 if (it->m_frontend->getSlotID() == tu1)
1670 else if (it->m_frontend->getSlotID() == tu2)
1675 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1676 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1683 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1685 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1686 m_not_linked_slot_mask |= (1 << slot_no);
1689 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1691 return m_rotorMoving;
1694 void eDVBSatelliteEquipmentControl::setRotorMoving(int slot_no, bool b)
1697 m_rotorMoving |= (1 << slot_no);
1699 m_rotorMoving &= ~(1 << slot_no);