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...) \
54 // eDebugNoNewLine("SIMULATE:"); \
58 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int slot_id, int *highest_score_lnb)
60 bool simulate = ((eDVBFrontend*)fe)->is_simulate();
61 bool direct_connected = m_not_linked_slot_mask & slot_id;
62 int score=0, satcount=0;
63 long linked_prev_ptr=-1, linked_next_ptr=-1, linked_csw=-1, linked_ucsw=-1, linked_toneburst=-1,
64 fe_satpos_depends_ptr=-1, fe_rotor_pos=-1;
65 bool linked_in_use = false;
67 eSecDebugNoSimulate("direct_connected %d", !!direct_connected);
69 fe->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
70 fe->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
71 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, fe_satpos_depends_ptr);
73 // first we search the linkage base frontend and check if any tuner in prev direction is used
74 while (linked_prev_ptr != -1)
76 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
77 if (linked_fe->m_inuse)
79 fe = linked_fe->m_frontend;
80 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
83 fe->getData(eDVBFrontend::ROTOR_POS, fe_rotor_pos);
85 // now check also the linked tuners is in use
86 while (!linked_in_use && linked_next_ptr != -1)
88 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
89 if (linked_fe->m_inuse)
91 linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, (long&)linked_next_ptr);
94 // when a linked in use tuner is found we get the tuner data...
97 fe->getData(eDVBFrontend::CSW, linked_csw);
98 fe->getData(eDVBFrontend::UCSW, linked_ucsw);
99 fe->getData(eDVBFrontend::TONEBURST, linked_toneburst);
102 if (highest_score_lnb)
103 *highest_score_lnb = -1;
105 eSecDebugNoSimulate("canTune %d", slot_id);
107 for (int idx=0; idx <= m_lnbidx; ++idx )
110 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
111 bool is_unicable = lnb_param.SatCR_idx != -1;
112 bool is_unicable_position_switch = lnb_param.SatCR_positions > 1;
114 if ( lnb_param.m_slot_mask & slot_id ) // lnb for correct tuner?
117 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
119 eSecDebugNoSimulate("lnb %d found", idx);
121 satcount += lnb_param.m_satellites.size();
123 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
124 lnb_param.m_satellites.find(sat.orbital_position);
125 if ( sit != lnb_param.m_satellites.end())
129 satpos_depends_ptr=fe_satpos_depends_ptr,
130 csw = di_param.m_committed_cmd,
131 ucsw = di_param.m_uncommitted_cmd,
132 toneburst = di_param.m_toneburst_param,
133 rotor_pos = fe_rotor_pos;
135 eSecDebugNoSimulate("sat %d found", sat.orbital_position);
137 if ( sat.frequency > lnb_param.m_lof_threshold )
139 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
142 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
145 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
146 csw = 0xF0 | (csw << 2);
148 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
151 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
162 if (sat.no_rotor_command_on_tune && !rotor) {
163 eSecDebugNoSimulate("no rotor but no_rotor_command_on_tune is set.. ignore lnb %d", idx);
167 eSecDebugNoSimulate("ret1 %d", ret);
169 if (linked_in_use && !is_unicable)
171 // compare tuner data
172 if ( (csw != linked_csw) ||
173 ( diseqc && (ucsw != linked_ucsw || toneburst != linked_toneburst) ) ||
174 ( rotor && rotor_pos != sat.orbital_position ) )
180 eSecDebugNoSimulate("ret2 %d", ret);
182 else if ((satpos_depends_ptr != -1) && !(is_unicable && is_unicable_position_switch))
184 eSecDebugNoSimulate("satpos depends");
185 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
186 if (direct_connected) // current fe is direct connected.. (can turn the rotor)
188 if (satpos_depends_to_fe->m_inuse) // if the dependent frontend is in use?
190 if (!rotor || rotor_pos != sat.orbital_position) // new orbital position not equal to current orbital pos?
195 eSecDebugNoSimulate("ret3 %d", ret);
197 else // current fe is dependent of another tuner ... (so this fe can't turn the rotor!)
199 // get current orb pos of the tuner with rotor connection
200 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, rotor_pos);
201 if (!rotor || rotor_pos == -1 /* we dont know the rotor position yet */
202 || rotor_pos != sat.orbital_position ) // not the same orbital position?
207 eSecDebugNoSimulate("ret4 %d", ret);
210 if (ret && rotor && rotor_pos != -1)
211 ret -= abs(rotor_pos-sat.orbital_position);
213 eSecDebugNoSimulate("ret5 %d", ret);
215 if (ret && !is_unicable)
217 int lof = sat.frequency > lnb_param.m_lof_threshold ?
218 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
219 int tuner_freq = abs(sat.frequency - lof);
220 if (tuner_freq < 900000 || tuner_freq > 2200000)
224 if (ret && lnb_param.m_prio != -1)
225 ret = lnb_param.m_prio;
227 eSecDebugNoSimulate("ret %d, score old %d", ret, score);
231 if (highest_score_lnb)
232 *highest_score_lnb = idx;
234 eSecDebugNoSimulate("score new %d", score);
238 if (score && satcount)
240 if (score > (satcount-1))
241 score -= (satcount-1);
243 score = 1; // min score
245 if (score && direct_connected)
246 score += 5; // increase score for tuners with direct sat connection
247 eSecDebugNoSimulate("final score %d", score);
251 bool need_turn_fast(int turn_speed)
253 if (turn_speed == eDVBSatelliteRotorParameters::FAST)
255 else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
257 int begin = turn_speed >> 16; // high word is start time
258 int end = turn_speed&0xFFFF; // low word is end time
259 time_t now_time = ::time(0);
261 localtime_r(&now_time, &nowTime);
262 int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
263 bool neg = end <= begin;
269 if ((now >= begin && now < end) ^ neg)
275 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
277 #define eDebugNoSimulate(x...) \
284 // eDebugNoNewLine("SIMULATE:"); \
288 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
290 bool simulate = ((eDVBFrontend*)&frontend)->is_simulate();
292 if (canTune(sat, &frontend, slot_id, &lnb_idx))
294 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[lnb_idx];
295 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
296 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
298 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
299 lnb_param.m_satellites.find(sat.orbital_position);
300 if ( sit != lnb_param.m_satellites.end())
302 eSecCommandList sec_sequence;
303 eDVBSatelliteSwitchParameters &sw_param = sit->second;
304 bool doSetFrontend = true;
305 bool doSetVoltageToneFrontend = true;
306 bool forceChanged = false;
307 bool needDiSEqCReset = false;
309 voltage = iDVBFrontend::voltageOff,
310 tone = iDVBFrontend::toneOff,
311 csw = di_param.m_committed_cmd,
312 ucsw = di_param.m_uncommitted_cmd,
313 toneburst = di_param.m_toneburst_param,
319 satposDependPtr = -1;
320 iDVBFrontend *sec_fe=&frontend;
321 eDVBRegisteredFrontend *linked_fe = 0;
322 eDVBSatelliteDiseqcParameters::t_diseqc_mode diseqc_mode = di_param.m_diseqc_mode;
323 eDVBSatelliteSwitchParameters::t_voltage_mode voltage_mode = sw_param.m_voltage_mode;
324 bool diseqc13V = voltage_mode == eDVBSatelliteSwitchParameters::HV_13;
325 bool is_unicable = lnb_param.SatCR_idx != -1;
327 bool useGotoXX = false;
331 lnb_param.guard_offset = 0; //HACK
335 voltage_mode = eDVBSatelliteSwitchParameters::HV;
337 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
339 if (!(m_not_linked_slot_mask & slot_id)) // frontend with direct connection?
341 long linked_prev_ptr;
342 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
343 while (linked_prev_ptr != -1)
345 linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
346 sec_fe = linked_fe->m_frontend;
347 sec_fe->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
349 if (satposDependPtr != -1) // we dont need uncommitted switch and rotor cmds on second output of a rotor lnb
350 diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
352 // in eDVBFrontend::tuneLoop we call closeFrontend and ->inc_use() in this this condition (to put the kernel frontend thread into idle state)
353 // so we must resend all diseqc stuff (voltage is disabled when the frontend is closed)
355 sec_fe->getState(state);
356 if (!linked_fe->m_inuse && state != eDVBFrontend::stateIdle)
361 sec_fe->getData(eDVBFrontend::CSW, lastcsw);
362 sec_fe->getData(eDVBFrontend::UCSW, lastucsw);
363 sec_fe->getData(eDVBFrontend::TONEBURST, lastToneburst);
364 sec_fe->getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
365 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
367 if (lastcsw == lastucsw && lastToneburst == lastucsw && lastucsw == -1)
368 needDiSEqCReset = true;
370 if ( sat.frequency > lnb_param.m_lof_threshold )
372 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
375 int lof = (band&1)?lnb_param.m_lof_hi:lnb_param.m_lof_lo;
380 int local= abs(sat.frequency
382 parm.FREQUENCY = ((((local * 2) / 125) + 1) / 2) * 125;
383 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
385 if ( voltage_mode == eDVBSatelliteSwitchParameters::_14V
386 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical
387 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
388 voltage = VOLTAGE(13);
389 else if ( voltage_mode == eDVBSatelliteSwitchParameters::_18V
390 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical)
391 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
392 voltage = VOLTAGE(18);
393 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
394 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
395 tone = iDVBFrontend::toneOn;
396 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
397 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
398 tone = iDVBFrontend::toneOff;
402 switch(lnb_param.SatCR_format)
406 eDebug("[prepare] JESS");
408 int tmp1 = abs(sat.frequency
411 volatile unsigned int tmp2 = (1000 + 2 * tmp1) / (2 *1000); //round to multiple of 1000
412 parm.FREQUENCY = lnb_param.SatCRvco - (tmp1 - (1000 * tmp2));
413 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - lof -(lnb_param.SatCRvco - parm.FREQUENCY));
415 lnb_param.UnicableTuningWord =
416 (band & 0x3) //Bit0:HighLow Bit1:VertHor
417 | (((lnb_param.LNBNum - 1) & 0x3F) << 2) //position number (max. 63)
418 | ((tmp2 & 0x7FF)<< 8) //frequency (-100MHz Offset)
419 | ((lnb_param.SatCR_idx & 0x1F) << 19); //adresse of SatCR (max. 32)
421 eDebug("[prepare] UnicableTuningWord %#06x",lnb_param.UnicableTuningWord);
427 eDebug("[prepare] Unicable");
428 int tmp1 = abs(sat.frequency
432 + lnb_param.guard_offset;
433 volatile unsigned int tmp2 = (4000 + 2 * tmp1) / (2 *4000); //round to multiple of 4000
435 parm.FREQUENCY = lnb_param.SatCRvco - (tmp1 - (4000 * tmp2)) + lnb_param.guard_offset;
436 lnb_param.UnicableTuningWord = tmp2
437 | ((band & 1) ? 0x400 : 0) //HighLow
438 | ((band & 2) ? 0x800 : 0) //VertHor
439 | ((lnb_param.LNBNum & 1) ? 0 : 0x1000) //Umschaltung LNB1 LNB2
440 | (lnb_param.SatCR_idx << 13); //Adresse des SatCR
442 eDebug("[prepare] UnicableTuningWord %#04x",lnb_param.UnicableTuningWord);
443 eDebug("[prepare] guard_offset %d",lnb_param.guard_offset);
445 frontend.setData(eDVBFrontend::FREQ_OFFSET, (lnb_param.UnicableTuningWord & 0x3FF) *4000 + 1400000 + lof - (2 * (lnb_param.SatCRvco - (tmp1 - (4000 * tmp2)))) );
448 voltage = VOLTAGE(13);
451 if (diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
453 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
454 csw = 0xF0 | (csw << 2);
456 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
460 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
461 bool changed_csw = send_csw && (forceChanged || csw != lastcsw);
464 (di_param.m_uncommitted_cmd && diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
465 bool changed_ucsw = send_ucsw && (forceChanged || ucsw != lastucsw);
468 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
469 bool changed_burst = send_burst && (forceChanged || toneburst != lastToneburst);
474 4 send toneburst first
475 8 send toneburst at end */
476 if (changed_burst) // toneburst first and toneburst changed
478 if (di_param.m_command_order&1)
492 if ((di_param.m_command_order&4) && send_csw)
494 if (di_param.m_command_order==4 && send_burst)
499 if ( di_param.m_use_fast
500 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
502 && ((csw / 4) == (lastcsw / 4)) )
503 eDebugNoSimulate("dont send committed cmd (fast diseqc)");
507 if (!(di_param.m_command_order&4) && send_ucsw)
509 if (!(di_param.m_command_order&1) && send_burst)
515 eDebugNoNewLine("sendmask: ");
516 for (int i=3; i >= 0; --i)
517 if ( send_mask & (1<<i) )
518 eDebugNoNewLine("1");
520 eDebugNoNewLine("0");
523 if ( diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
524 && !sat.no_rotor_command_on_tune )
526 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
527 RotorCmd=sw_param.m_rotorPosNum;
528 else // we must calc gotoxx cmd
530 eDebugNoSimulate("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
533 double SatLon = abs(sat.orbital_position)/10.00,
534 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
535 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
537 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
540 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
541 SiteLon = 360 - SiteLon;
543 eDebugNoSimulate("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
544 double satHourAngle =
545 calcSatHourangle( SatLon, SiteLat, SiteLon );
546 eDebugNoSimulate("PolarmountHourAngle=%lf", satHourAngle );
548 static int gotoXTable[10] =
549 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
551 if (SiteLat >= 0) // Northern Hemisphere
553 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
554 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
556 if (satHourAngle < 180) // the east
561 else // Southern Hemisphere
563 if (satHourAngle < 180) // the east
565 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
566 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
571 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
572 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
576 eDebugNoSimulate("RotorCmd = %04x", RotorCmd);
582 int diseqc_repeats = diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0 ? di_param.m_repeats : 0;
583 int vlt = iDVBFrontend::voltageOff;
584 eSecCommand::pair compare;
586 compare.tone = iDVBFrontend::toneOff;
587 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
588 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
589 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
592 vlt = iDVBFrontend::voltage13;
593 else if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
595 if (rotor_param.m_inputpower_parameters.m_use && !is_unicable)
596 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
598 vlt = VOLTAGE(13); // in normal mode start turning with 13V
603 // check if voltage is already correct..
604 compare.voltage = vlt;
606 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
608 // check if voltage is disabled
609 compare.voltage = iDVBFrontend::voltageOff;
611 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
613 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS
614 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
615 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
616 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
618 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
619 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
620 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
622 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
625 eDVBDiseqcCommand diseqc;
626 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
628 diseqc.data[0] = 0xE0;
632 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
633 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_RESET_CMD]) );
635 // diseqc peripherial powersupply on
636 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
637 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD]) );
640 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
644 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
645 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
655 loops <<= diseqc_repeats;
657 for ( int i = 0; i < loops;) // fill commands...
659 eDVBDiseqcCommand diseqc;
660 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
662 diseqc.data[0] = i ? 0xE1 : 0xE0;
663 diseqc.data[1] = 0x10;
664 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
666 diseqc.data[2] = 0x39;
667 diseqc.data[3] = ucsw;
669 else if ( send_mask & 1 )
671 diseqc.data[2] = 0x38;
672 diseqc.data[3] = csw;
674 else // no committed command confed.. so send uncommitted..
676 diseqc.data[2] = 0x39;
677 diseqc.data[3] = ucsw;
679 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
685 if (diseqc.data[2] == 0x38 && (send_mask & 2))
687 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
689 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
692 int delay = diseqc_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
693 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
695 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
696 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
699 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
701 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
703 else // delay 120msek when no command is in repeat gap
704 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
707 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
710 if ( send_mask & 8 ) // toneburst at end of sequence
712 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
713 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
716 if (di_param.m_seq_repeat && seq_repeat == 0)
717 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BEFORE_SEQUENCE_REPEAT]) );
723 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
727 sec_fe->setData(eDVBFrontend::NEW_CSW, csw);
728 sec_fe->setData(eDVBFrontend::NEW_UCSW, ucsw);
729 sec_fe->setData(eDVBFrontend::NEW_TONEBURST, di_param.m_toneburst_param);
733 // check if voltage is disabled
734 eSecCommand::pair compare;
736 compare.voltage = iDVBFrontend::voltageOff;
737 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
738 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
739 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS] ) );
741 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
742 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
743 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) ); // wait 20 ms after voltage change
745 eDVBDiseqcCommand diseqc;
746 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
748 long oldSatcr, oldPin, oldDiction;
749 frontend.getData(eDVBFrontend::SATCR, oldSatcr);
750 frontend.getData(eDVBFrontend::PIN, oldPin);
751 frontend.getData(eDVBFrontend::DICTION, oldDiction);
753 if((oldSatcr != -1) && (oldSatcr != lnb_param.SatCR_idx))
761 diseqc.data[0] = 0x70;
766 diseqc.data[0] = 0x71;
767 diseqc.data[4] = oldPin;
769 diseqc.data[1] = oldSatcr << 3;
770 diseqc.data[2] = 0x00;
771 diseqc.data[3] = 0x00;
778 diseqc.data[2] = 0x5A;
783 diseqc.data[2] = 0x5C;
784 diseqc.data[5] = oldPin;
786 diseqc.data[0] = 0xE0;
787 diseqc.data[1] = 0x10;
788 diseqc.data[3] = oldSatcr << 5;
789 diseqc.data[4] = 0x00;
792 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
793 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
794 frontend.setData(eDVBFrontend::SATCR, -1);
797 frontend.setData(eDVBFrontend::DICTION, lnb_param.SatCR_format);
798 //TODO frontend.setData(eDVBFrontend::PIN, lnb_param.SatCR_pin);
800 long pin = 0; // hack
802 switch(lnb_param.SatCR_format)
808 diseqc.data[0] = 0x70;
809 diseqc.data[1] = lnb_param.UnicableTuningWord >> 16;
810 diseqc.data[2] = lnb_param.UnicableTuningWord >> 8;
811 diseqc.data[3] = lnb_param.UnicableTuningWord;
816 diseqc.data[0] = 0x71;
817 diseqc.data[4] = pin;
819 diseqc.data[1] = lnb_param.UnicableTuningWord >> 16;
820 diseqc.data[2] = lnb_param.UnicableTuningWord >> 8;
821 diseqc.data[3] = lnb_param.UnicableTuningWord;
828 diseqc.data[2] = 0x5A;
833 diseqc.data[2] = 0x5C;
834 diseqc.data[5] = pin;
836 diseqc.data[0] = 0xE0;
837 diseqc.data[1] = 0x10;
838 diseqc.data[3] = lnb_param.UnicableTuningWord >> 8;
839 diseqc.data[4] = lnb_param.UnicableTuningWord;
841 frontend.setData(eDVBFrontend::SATCR, lnb_param.SatCR_idx);
843 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
844 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
845 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
846 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd && !rotor_param.m_inputpower_parameters.m_use)
847 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
850 eDebugNoSimulate("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
851 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
853 int mrt = m_params[MOTOR_RUNNING_TIMEOUT]; // in seconds!
854 eSecCommand::pair compare;
855 if (!send_mask && !is_unicable)
858 compare.tone = iDVBFrontend::toneOff;
859 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
860 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
861 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
863 compare.voltage = iDVBFrontend::voltageOff;
865 // the next is a check if voltage is switched off.. then we first set a voltage :)
866 // else we set voltage after all diseqc stuff..
867 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
869 if (rotor_param.m_inputpower_parameters.m_use)
870 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
872 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
874 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
875 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
878 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
880 eDVBDiseqcCommand diseqc;
881 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
883 diseqc.data[0] = 0xE0;
884 diseqc.data[1] = 0x31; // positioner
885 diseqc.data[2] = 0x60; // stop
886 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
887 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
888 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
889 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
890 // wait 150msec after send rotor stop cmd
891 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
893 diseqc.data[0] = 0xE0;
894 diseqc.data[1] = 0x31; // positioner
898 diseqc.data[2] = 0x6E; // drive to angular position
899 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
900 diseqc.data[4] = RotorCmd & 0xFF;
905 diseqc.data[2] = 0x6B; // goto stored sat position
906 diseqc.data[3] = RotorCmd;
907 diseqc.data[4] = 0x00;
910 // use measure rotor input power to detect motor state
911 if ( rotor_param.m_inputpower_parameters.m_use)
913 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed) && !is_unicable;
914 eSecCommand::rotor cmd;
915 eSecCommand::pair compare;
917 compare.voltage = VOLTAGE(18);
919 compare.voltage = VOLTAGE(13);
921 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
922 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
923 // measure idle power values
926 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
927 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
929 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
930 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
932 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
933 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
935 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
936 ////////////////////////////
937 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
938 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
939 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
940 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
942 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
943 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
944 cmd.direction=1; // check for running rotor
945 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
948 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
949 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
950 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
951 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
952 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
954 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
956 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
957 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*20) ); // mrt is in seconds... our SLEEP time is 50ms.. so * 20
958 // rotor running loop
959 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
960 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
961 cmd.direction=0; // check for stopped rotor
963 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
964 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
965 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
966 /////////////////////
967 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
968 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
970 // use normal motor turning mode
973 if (curRotorPos != -1)
975 mrt = abs(curRotorPos - sat.orbital_position);
979 mrt += 10; // round a little bit
980 mrt *= 2000; // (we assume a very slow rotor with just 0.5 degree per second here)
982 mrt += 3; // a little bit overhead
984 doSetVoltageToneFrontend=false;
986 eSecCommand::rotor cmd;
987 eSecCommand::pair compare;
988 compare.voltage = VOLTAGE(13);
990 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
991 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
992 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
994 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
995 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
996 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
997 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) ); // sleep one second before change voltage or tone
999 compare.voltage = voltage;
1001 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
1002 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
1003 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
1005 compare.tone = tone;
1006 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
1007 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
1008 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
1009 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 0) );
1011 cmd.direction=1; // check for running rotor
1015 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*4) ); // mrt is in seconds... our SLEEP time is 250ms.. so * 4
1016 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
1017 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
1018 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +5 ) );
1019 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
1020 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
1021 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
1022 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +4) );
1023 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
1024 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
1025 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -5) );
1026 eDebug("set rotor timeout to %d seconds", mrt);
1028 sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
1029 sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
1032 if (doSetVoltageToneFrontend && !is_unicable)
1034 eSecCommand::pair compare;
1035 compare.voltage = voltage;
1037 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
1038 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
1039 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
1040 compare.tone = tone;
1041 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
1042 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
1043 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
1046 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_SWITCHPARMS) );
1050 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
1051 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
1054 sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
1055 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
1056 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
1058 frontend.setSecSequence(sec_sequence);
1063 eDebugNoSimulate("found no useable satellite configuration for %s freq %d%s %s on orbital position (%d)",
1064 sat.system ? "DVB-S2" : "DVB-S",
1066 sat.polarisation == eDVBFrontendParametersSatellite::Polarisation_Horizontal ? "H" :
1067 eDVBFrontendParametersSatellite::Polarisation_Vertical ? "V" :
1068 eDVBFrontendParametersSatellite::Polarisation_CircularLeft ? "CL" : "CR",
1069 sat.modulation == eDVBFrontendParametersSatellite::Modulation_Auto ? "AUTO" :
1070 eDVBFrontendParametersSatellite::Modulation_QPSK ? "QPSK" :
1071 eDVBFrontendParametersSatellite::Modulation_8PSK ? "8PSK" : "QAM16",
1072 sat.orbital_position );
1076 void eDVBSatelliteEquipmentControl::prepareTurnOffSatCR(iDVBFrontend &frontend)
1078 long satcr, diction, pin;
1079 eSecCommandList sec_sequence;
1081 // check if voltage is disabled
1082 eSecCommand::pair compare;
1083 compare.steps = +9; //only close frontend
1084 compare.voltage = iDVBFrontend::voltageOff;
1086 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
1087 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1088 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
1090 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18_5) );
1091 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
1092 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
1094 eDVBDiseqcCommand diseqc;
1095 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
1096 frontend.getData(eDVBFrontend::SATCR, satcr);
1097 frontend.getData(eDVBFrontend::DICTION, diction);
1098 frontend.getData(eDVBFrontend::PIN, pin);
1106 diseqc.data[0] = 0x70;
1111 diseqc.data[0] = 0x71;
1112 diseqc.data[4] = pin;
1114 diseqc.data[1] = satcr << 3;
1115 diseqc.data[2] = 0x00;
1116 diseqc.data[3] = 0x00;
1123 diseqc.data[2] = 0x5A;
1128 diseqc.data[2] = 0x5C;
1129 diseqc.data[5] = pin;
1131 diseqc.data[0] = 0xE0;
1132 diseqc.data[1] = 0x10;
1133 diseqc.data[3] = satcr << 5;
1134 diseqc.data[4] = 0x00;
1137 frontend.setData(eDVBFrontend::SATCR, -1);
1139 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
1140 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
1141 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1142 sec_sequence.push_back( eSecCommand(eSecCommand::DELAYED_CLOSE_FRONTEND) );
1144 frontend.setSecSequence(sec_sequence);
1147 RESULT eDVBSatelliteEquipmentControl::clear()
1149 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
1150 for (int i=0; i <= m_lnbidx; ++i)
1152 m_lnbs[i].m_satellites.clear();
1153 m_lnbs[i].m_slot_mask = 0;
1154 m_lnbs[i].m_prio = -1; // auto
1158 m_not_linked_slot_mask=0;
1160 //reset some tuner configuration
1161 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1163 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1164 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1165 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1166 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1167 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1168 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1171 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1173 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1174 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1175 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1176 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1177 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1178 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1184 /* LNB Specific Parameters */
1185 RESULT eDVBSatelliteEquipmentControl::addLNB()
1187 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
1188 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
1191 eDebug("no more LNB free... cnt is %d", m_lnbidx);
1194 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
1198 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
1200 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
1201 if ( currentLNBValid() )
1202 m_lnbs[m_lnbidx].m_slot_mask = slotmask;
1208 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
1210 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
1211 if ( currentLNBValid() )
1212 m_lnbs[m_lnbidx].m_lof_lo = lofl;
1218 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
1220 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
1221 if ( currentLNBValid() )
1222 m_lnbs[m_lnbidx].m_lof_hi = lofh;
1228 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
1230 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
1231 if ( currentLNBValid() )
1232 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
1238 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
1240 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
1241 if ( currentLNBValid() )
1242 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
1248 RESULT eDVBSatelliteEquipmentControl::setLNBPrio(int prio)
1250 eSecDebug("eDVBSatelliteEquipmentControl::setLNBPrio(%d)", prio);
1251 if ( currentLNBValid() )
1252 m_lnbs[m_lnbidx].m_prio = prio;
1258 RESULT eDVBSatelliteEquipmentControl::setLNBNum(int LNBNum)
1260 eSecDebug("eDVBSatelliteEquipmentControl::setLNBNum(%d)", LNBNum);
1261 if(!((LNBNum >= 1) && (LNBNum <= MAX_LNBNUM)))
1263 if ( currentLNBValid() )
1264 m_lnbs[m_lnbidx].LNBNum = LNBNum;
1270 /* DiSEqC Specific Parameters */
1271 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
1273 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
1274 if ( currentLNBValid() )
1275 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
1281 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
1283 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
1284 if ( currentLNBValid() )
1285 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
1291 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
1293 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
1294 if ( currentLNBValid() )
1295 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
1301 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
1303 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
1304 if ( currentLNBValid() )
1305 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
1311 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
1313 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
1314 if ( currentLNBValid() )
1315 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
1321 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
1323 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
1324 if ( currentLNBValid() )
1325 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
1331 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
1333 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
1334 if ( currentLNBValid() )
1335 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
1341 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
1343 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
1344 if ( currentLNBValid() )
1345 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1351 /* Rotor Specific Parameters */
1352 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1354 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
1355 if ( currentLNBValid() )
1356 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1362 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1364 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
1365 if ( currentLNBValid() )
1366 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1372 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1374 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1375 if ( currentLNBValid() )
1376 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1382 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1384 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1385 if ( currentLNBValid() )
1386 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1392 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1394 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1395 if ( currentLNBValid() )
1396 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1402 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1404 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1405 if ( currentLNBValid() )
1406 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1412 /* Unicable Specific Parameters */
1413 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRformat(int SatCR_format)
1415 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRformat(%d)", SatCR_format);
1416 if(!((SatCR_format >-1) && (SatCR_format < 2)))
1418 if ( currentLNBValid() )
1419 m_lnbs[m_lnbidx].SatCR_format = SatCR_format;
1425 RESULT eDVBSatelliteEquipmentControl::setLNBSatCR(int SatCR_idx)
1427 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCR(%d)", SatCR_idx);
1428 if(!((SatCR_idx >=-1) && (SatCR_idx < MAX_SATCR)))
1430 if ( currentLNBValid() )
1431 m_lnbs[m_lnbidx].SatCR_idx = SatCR_idx;
1437 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRvco(int SatCRvco)
1439 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRvco(%d)", SatCRvco);
1440 if(!((SatCRvco >= 950*1000) && (SatCRvco <= 2150*1000)))
1442 if(!((m_lnbs[m_lnbidx].SatCR_idx >= 0) && (m_lnbs[m_lnbidx].SatCR_idx < MAX_SATCR)))
1444 if ( currentLNBValid() )
1445 m_lnbs[m_lnbidx].SatCRvco = SatCRvco;
1451 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRpositions(int SatCR_positions)
1453 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRpositions(%d)", SatCR_positions);
1454 if(SatCR_positions < 1 || SatCR_positions > 2)
1456 if ( currentLNBValid() )
1457 m_lnbs[m_lnbidx].SatCR_positions = SatCR_positions;
1463 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRpositions()
1465 if ( currentLNBValid() )
1466 return m_lnbs[m_lnbidx].SatCR_positions;
1470 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRformat()
1472 if ( currentLNBValid() )
1473 return m_lnbs[m_lnbidx].SatCR_format;
1477 RESULT eDVBSatelliteEquipmentControl::getLNBSatCR()
1479 if ( currentLNBValid() )
1480 return m_lnbs[m_lnbidx].SatCR_idx;
1484 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRvco()
1486 if ( currentLNBValid() )
1487 return m_lnbs[m_lnbidx].SatCRvco;
1491 /* Satellite Specific Parameters */
1492 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1494 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1495 if ( currentLNBValid() )
1497 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1498 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1499 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1501 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1502 m_lnbs[m_lnbidx].m_satellites.insert(
1503 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1506 m_curSat = ret.first;
1518 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1520 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1521 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1522 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1529 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1531 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1532 if ( currentLNBValid() )
1534 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1535 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1544 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1546 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1547 if ( currentLNBValid() )
1549 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1550 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1559 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1561 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1562 if ( currentLNBValid() )
1563 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1571 int orb_pos, lofl, lofh;
1572 sat_compare(int o, int lofl, int lofh)
1573 :orb_pos(o), lofl(lofl), lofh(lofh)
1575 sat_compare(const sat_compare &x)
1576 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1578 bool operator < (const sat_compare & cmp) const
1580 if (orb_pos == cmp.orb_pos)
1582 if ( abs(lofl-cmp.lofl) < 200000 )
1584 if (abs(lofh-cmp.lofh) < 200000)
1586 return lofh<cmp.lofh;
1588 return lofl<cmp.lofl;
1590 return orb_pos < cmp.orb_pos;
1594 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1596 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1599 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1600 eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin());
1601 for (; it != m_avail_frontends.end(); ++it)
1603 if (it->m_frontend->getSlotID() == tu1)
1605 else if (it->m_frontend->getSlotID() == tu2)
1611 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1612 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1616 it=m_avail_simulate_frontends.begin();
1617 for (; it != m_avail_simulate_frontends.end(); ++it)
1619 if (it->m_frontend->getSlotID() == tu1)
1621 else if (it->m_frontend->getSlotID() == tu2)
1626 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1627 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1634 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1636 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1640 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1642 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1644 if (it->m_frontend->getSlotID() == tu1)
1646 else if (it->m_frontend->getSlotID() == tu2)
1651 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1652 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1656 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1658 if (it->m_frontend->getSlotID() == tu1)
1660 else if (it->m_frontend->getSlotID() == tu2)
1665 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1666 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1673 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1675 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1676 m_not_linked_slot_mask |= (1 << slot_no);
1679 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1681 return m_rotorMoving;
1684 void eDVBSatelliteEquipmentControl::setRotorMoving(int slot_no, bool b)
1687 m_rotorMoving |= (1 << slot_no);
1689 m_rotorMoving &= ~(1 << slot_no);