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(false)
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 if ( lnb_param.m_slot_mask & slot_id ) // lnb for correct tuner?
114 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
116 eSecDebugNoSimulate("lnb %d found", idx);
118 satcount += lnb_param.m_satellites.size();
120 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
121 lnb_param.m_satellites.find(sat.orbital_position);
122 if ( sit != lnb_param.m_satellites.end())
126 satpos_depends_ptr=fe_satpos_depends_ptr,
127 csw = di_param.m_committed_cmd,
128 ucsw = di_param.m_uncommitted_cmd,
129 toneburst = di_param.m_toneburst_param,
130 rotor_pos = fe_rotor_pos;
132 eSecDebugNoSimulate("sat %d found", sat.orbital_position);
134 if ( sat.frequency > lnb_param.m_lof_threshold )
136 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
139 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
142 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
143 csw = 0xF0 | (csw << 2);
145 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
148 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
159 eSecDebugNoSimulate("ret1 %d", ret);
163 // compare tuner data
164 if ( (csw != linked_csw) ||
165 ( diseqc && (ucsw != linked_ucsw || toneburst != linked_toneburst) ) ||
166 ( rotor && rotor_pos != sat.orbital_position ) )
172 eSecDebugNoSimulate("ret2 %d", ret);
173 if (ret) // special case when this tuner is linked to a satpos dependent tuner
175 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
176 if (satpos_depends_ptr != -1)
178 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
179 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, rotor_pos);
180 if (!rotor || rotor_pos == -1 /* we dont know the rotor position yet */
181 || rotor_pos != sat.orbital_position ) // not the same orbital position?
187 eSecDebugNoSimulate("ret3 %d", ret);
189 else if (satpos_depends_ptr != -1)
191 eSecDebugNoSimulate("satpos depends");
192 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
193 if (direct_connected) // current fe is direct connected.. (can turn the rotor)
195 if (satpos_depends_to_fe->m_inuse) // if the dependent frontend is in use?
197 if (!rotor || rotor_pos != sat.orbital_position) // new orbital position not equal to current orbital pos?
203 else // current fe is dependent of another tuner ... (so this fe can't turn the rotor!)
205 // get current orb pos of the tuner with rotor connection
206 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, rotor_pos);
207 if (!rotor || rotor_pos == -1 /* we dont know the rotor position yet */
208 || rotor_pos != sat.orbital_position ) // not the same orbital position?
213 eSecDebugNoSimulate("ret4 %d", ret);
216 if (ret && rotor && rotor_pos != -1)
217 ret -= abs(rotor_pos-sat.orbital_position);
219 eSecDebugNoSimulate("ret5 %d", ret);
223 int lof = sat.frequency > lnb_param.m_lof_threshold ?
224 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
225 int tuner_freq = abs(sat.frequency - lof);
226 if (tuner_freq < 900000 || tuner_freq > 2200000)
230 if (ret && lnb_param.m_prio != -1)
231 ret = lnb_param.m_prio;
233 eSecDebugNoSimulate("ret %d, score old %d", ret, score);
237 if (highest_score_lnb)
238 *highest_score_lnb = idx;
240 eSecDebugNoSimulate("score new %d", score);
244 if (score && satcount)
246 if (score > (satcount-1))
247 score -= (satcount-1);
249 score = 1; // min score
251 if (score && direct_connected)
252 score += 5; // increase score for tuners with direct sat connection
253 eSecDebugNoSimulate("final score %d", score);
257 bool need_turn_fast(int turn_speed)
259 if (turn_speed == eDVBSatelliteRotorParameters::FAST)
261 else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
263 int begin = turn_speed >> 16; // high word is start time
264 int end = turn_speed&0xFFFF; // low word is end time
265 time_t now_time = ::time(0);
267 localtime_r(&now_time, &nowTime);
268 int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
269 bool neg = end <= begin;
275 if ((now >= begin && now < end) ^ neg)
281 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
283 #define eDebugNoSimulate(x...) \
290 // eDebugNoNewLine("SIMULATE:"); \
294 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
296 bool simulate = ((eDVBFrontend*)&frontend)->is_simulate();
298 if (canTune(sat, &frontend, slot_id, &lnb_idx))
300 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[lnb_idx];
301 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
302 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
304 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
305 lnb_param.m_satellites.find(sat.orbital_position);
306 if ( sit != lnb_param.m_satellites.end())
308 eSecCommandList sec_sequence;
310 lnb_param.guard_offset = 0; //HACK
312 frontend.setData(eDVBFrontend::SATCR, lnb_param.SatCR_idx);
314 eDVBSatelliteSwitchParameters &sw_param = sit->second;
315 bool doSetFrontend = true;
316 bool doSetVoltageToneFrontend = true;
317 bool forceChanged = false;
318 bool needDiSEqCReset = false;
320 voltage = iDVBFrontend::voltageOff,
321 tone = iDVBFrontend::toneOff,
322 csw = di_param.m_committed_cmd,
323 ucsw = di_param.m_uncommitted_cmd,
324 toneburst = di_param.m_toneburst_param,
330 satposDependPtr = -1;
331 iDVBFrontend *sec_fe=&frontend;
332 eDVBRegisteredFrontend *linked_fe = 0;
333 eDVBSatelliteDiseqcParameters::t_diseqc_mode diseqc_mode = di_param.m_diseqc_mode;
334 eDVBSatelliteSwitchParameters::t_voltage_mode voltage_mode = sw_param.m_voltage_mode;
335 bool diseqc13V = voltage_mode == eDVBSatelliteSwitchParameters::HV_13;
338 voltage_mode = eDVBSatelliteSwitchParameters::HV;
340 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
342 if (!(m_not_linked_slot_mask & slot_id)) // frontend with direct connection?
344 long linked_prev_ptr;
345 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
346 while (linked_prev_ptr != -1)
348 linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
349 sec_fe = linked_fe->m_frontend;
350 sec_fe->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
352 if (satposDependPtr != -1) // we dont need uncommitted switch and rotor cmds on second output of a rotor lnb
353 diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
355 // in eDVBFrontend::tuneLoop we call closeFrontend and ->inc_use() in this this condition (to put the kernel frontend thread into idle state)
356 // so we must resend all diseqc stuff (voltage is disabled when the frontend is closed)
358 sec_fe->getState(state);
359 if (!linked_fe->m_inuse && state != eDVBFrontend::stateIdle)
364 sec_fe->getData(eDVBFrontend::CSW, lastcsw);
365 sec_fe->getData(eDVBFrontend::UCSW, lastucsw);
366 sec_fe->getData(eDVBFrontend::TONEBURST, lastToneburst);
367 sec_fe->getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
368 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
370 if (lastcsw == lastucsw && lastToneburst == lastucsw && lastucsw == -1)
371 needDiSEqCReset = true;
373 if ( sat.frequency > lnb_param.m_lof_threshold )
375 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
378 int lof = (band&1)?lnb_param.m_lof_hi:lnb_param.m_lof_lo;
383 if(lnb_param.SatCR_idx == -1)
386 local = abs(sat.frequency
387 - ((lof - (lof % 1000)) + ((lof % 1000)>500 ? 1000 : 0)) ); //TODO für den Mist mal ein Macro schreiben
388 parm.FREQUENCY = (local - (local % 125)) + ((local % 125)>62 ? 125 : 0);
389 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
391 if ( voltage_mode == eDVBSatelliteSwitchParameters::_14V
392 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical
393 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
394 voltage = VOLTAGE(13);
395 else if ( voltage_mode == eDVBSatelliteSwitchParameters::_18V
396 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical)
397 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
398 voltage = VOLTAGE(18);
399 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
400 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
401 tone = iDVBFrontend::toneOn;
402 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
403 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
404 tone = iDVBFrontend::toneOff;
408 unsigned int tmp = abs(sat.frequency
409 - ((lof - (lof % 1000)) + ((lof % 1000)>500 ? 1000 : 0)) )
412 + lnb_param.guard_offset;
413 parm.FREQUENCY = (lnb_param.SatCRvco - (tmp % 4000))+((tmp%4000)>2000?4000:0)+lnb_param.guard_offset;
414 lnb_param.UnicableTuningWord = (((tmp / 4000)+((tmp%4000)>2000?1:0))
415 | ((band & 1) ? 0x400 : 0) //HighLow
416 | ((band & 2) ? 0x800 : 0) //VertHor
417 | ((lnb_param.LNBNum & 1) ? 0 : 0x1000) //Umschaltung LNB1 LNB2
418 | (lnb_param.SatCR_idx << 13)); //Adresse des SatCR
419 eDebug("[prepare] UnicableTuningWord %#04x",lnb_param.UnicableTuningWord);
420 eDebug("[prepare] guard_offset %d",lnb_param.guard_offset);
421 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - ((lnb_param.UnicableTuningWord & 0x3FF) *4000 + 1400000 - lnb_param.SatCRvco + lof));
424 if (diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
426 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
427 csw = 0xF0 | (csw << 2);
429 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
433 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
434 bool changed_csw = send_csw && (forceChanged || csw != lastcsw);
437 (di_param.m_uncommitted_cmd && diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
438 bool changed_ucsw = send_ucsw && (forceChanged || ucsw != lastucsw);
441 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
442 bool changed_burst = send_burst && (forceChanged || toneburst != lastToneburst);
444 int send_mask = 0; /*
447 4 send toneburst first
448 8 send toneburst at end */
449 if (changed_burst) // toneburst first and toneburst changed
451 if (di_param.m_command_order&1)
465 if ((di_param.m_command_order&4) && send_csw)
467 if (di_param.m_command_order==4 && send_burst)
472 if ( di_param.m_use_fast
473 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
475 && ((csw / 4) == (lastcsw / 4)) )
476 eDebugNoSimulate("dont send committed cmd (fast diseqc)");
480 if (!(di_param.m_command_order&4) && send_ucsw)
482 if (!(di_param.m_command_order&1) && send_burst)
488 eDebugNoNewLine("sendmask: ");
489 for (int i=3; i >= 0; --i)
490 if ( send_mask & (1<<i) )
491 eDebugNoNewLine("1");
493 eDebugNoNewLine("0");
496 if (doSetVoltageToneFrontend)
499 bool useGotoXX = false;
500 if ( diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
501 && !sat.no_rotor_command_on_tune )
503 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
504 RotorCmd=sw_param.m_rotorPosNum;
505 else // we must calc gotoxx cmd
507 eDebugNoSimulate("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
510 double SatLon = abs(sat.orbital_position)/10.00,
511 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
512 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
514 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
517 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
518 SiteLon = 360 - SiteLon;
520 eDebugNoSimulate("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
521 double satHourAngle =
522 calcSatHourangle( SatLon, SiteLat, SiteLon );
523 eDebugNoSimulate("PolarmountHourAngle=%lf", satHourAngle );
525 static int gotoXTable[10] =
526 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
528 if (SiteLat >= 0) // Northern Hemisphere
530 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
531 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
533 if (satHourAngle < 180) // the east
538 else // Southern Hemisphere
540 if (satHourAngle < 180) // the east
542 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
543 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
548 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
549 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
553 eDebugNoSimulate("RotorCmd = %04x", RotorCmd);
559 int vlt = iDVBFrontend::voltageOff;
560 eSecCommand::pair compare;
562 compare.tone = iDVBFrontend::toneOff;
563 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
564 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
565 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
568 vlt = iDVBFrontend::voltage13;
569 else if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
571 if (rotor_param.m_inputpower_parameters.m_use)
572 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
574 vlt = VOLTAGE(13); // in normal mode start turning with 13V
579 // check if voltage is already correct..
580 compare.voltage = vlt;
582 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
584 // check if voltage is disabled
585 compare.voltage = iDVBFrontend::voltageOff;
587 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
589 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS
590 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
591 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
592 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
594 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
595 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
596 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
598 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
601 eDVBDiseqcCommand diseqc;
602 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
604 diseqc.data[0] = 0xE0;
608 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
609 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_RESET_CMD]) );
611 // diseqc peripherial powersupply on
612 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
613 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD]) );
616 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
620 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
621 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
631 loops <<= di_param.m_repeats;
633 for ( int i = 0; i < loops;) // fill commands...
635 eDVBDiseqcCommand diseqc;
636 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
638 diseqc.data[0] = i ? 0xE1 : 0xE0;
639 diseqc.data[1] = 0x10;
640 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
642 diseqc.data[2] = 0x39;
643 diseqc.data[3] = ucsw;
645 else if ( send_mask & 1 )
647 diseqc.data[2] = 0x38;
648 diseqc.data[3] = csw;
650 else // no committed command confed.. so send uncommitted..
652 diseqc.data[2] = 0x39;
653 diseqc.data[3] = ucsw;
655 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
661 if (diseqc.data[2] == 0x38 && (send_mask & 2))
663 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
665 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
668 int delay = di_param.m_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
669 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
671 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
672 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
675 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
677 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
679 else // delay 120msek when no command is in repeat gap
680 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
683 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
686 if ( send_mask & 8 ) // toneburst at end of sequence
688 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
689 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
692 if (di_param.m_seq_repeat && seq_repeat == 0)
693 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BEFORE_SEQUENCE_REPEAT]) );
697 eDebugNoSimulate("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
698 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
700 eSecCommand::pair compare;
701 if (!send_mask && lnb_param.SatCR_idx == -1)
704 compare.tone = iDVBFrontend::toneOff;
705 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
706 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
707 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
709 compare.voltage = iDVBFrontend::voltageOff;
711 // the next is a check if voltage is switched off.. then we first set a voltage :)
712 // else we set voltage after all diseqc stuff..
713 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
715 if (rotor_param.m_inputpower_parameters.m_use)
716 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
718 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
720 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
721 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
724 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
726 eDVBDiseqcCommand diseqc;
727 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
729 diseqc.data[0] = 0xE0;
730 diseqc.data[1] = 0x31; // positioner
731 diseqc.data[2] = 0x60; // stop
732 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
733 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
734 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
735 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
736 // wait 150msec after send rotor stop cmd
737 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
739 diseqc.data[0] = 0xE0;
740 diseqc.data[1] = 0x31; // positioner
744 diseqc.data[2] = 0x6E; // drive to angular position
745 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
746 diseqc.data[4] = RotorCmd & 0xFF;
751 diseqc.data[2] = 0x6B; // goto stored sat position
752 diseqc.data[3] = RotorCmd;
753 diseqc.data[4] = 0x00;
755 if(lnb_param.SatCR_idx == -1)
757 if ( rotor_param.m_inputpower_parameters.m_use )
758 { // use measure rotor input power to detect rotor state
759 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed);
760 eSecCommand::rotor cmd;
761 eSecCommand::pair compare;
763 compare.voltage = VOLTAGE(18);
765 compare.voltage = VOLTAGE(13);
767 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
768 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
769 // measure idle power values
772 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
773 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
775 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
776 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
778 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
779 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
781 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
782 ////////////////////////////
783 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
784 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
785 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
786 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
788 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
789 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
790 cmd.direction=1; // check for running rotor
791 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
794 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
795 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
796 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
797 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
798 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
800 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
802 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
803 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*20) ); // 2 minutes running timeout
804 // rotor running loop
805 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
806 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
807 cmd.direction=0; // check for stopped rotor
809 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
810 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
811 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
812 /////////////////////
813 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
814 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
817 { // use normal turning mode
818 doSetVoltageToneFrontend=false;
820 eSecCommand::rotor cmd;
821 eSecCommand::pair compare;
822 compare.voltage = VOLTAGE(13);
824 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
825 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
826 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
828 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
829 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
830 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
832 compare.voltage = voltage;
834 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
835 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
836 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
839 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
840 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
841 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
842 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
844 cmd.direction=1; // check for running rotor
848 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*4) ); // 2 minutes running timeout
849 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
850 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
851 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );
852 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
853 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
854 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
855 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
856 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
857 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
860 sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
861 sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
867 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
871 sec_fe->setData(eDVBFrontend::NEW_CSW, csw);
872 sec_fe->setData(eDVBFrontend::NEW_UCSW, ucsw);
873 sec_fe->setData(eDVBFrontend::NEW_TONEBURST, di_param.m_toneburst_param);
875 if ((doSetVoltageToneFrontend) && (lnb_param.SatCR_idx == -1))
877 eSecCommand::pair compare;
878 compare.voltage = voltage;
880 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
881 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
882 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
884 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
885 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
886 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
889 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_SWITCHPARMS) );
891 if(lnb_param.SatCR_idx != -1)
893 // check if voltage is disabled
894 eSecCommand::pair compare;
896 compare.voltage = iDVBFrontend::voltageOff;
897 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
898 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
899 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS] ) );
901 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18_5) );
902 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
903 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) ); // wait 20 ms after voltage change
905 eDVBDiseqcCommand diseqc;
906 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
908 diseqc.data[0] = 0xE0;
909 diseqc.data[1] = 0x10;
910 diseqc.data[2] = 0x5A;
911 diseqc.data[3] = lnb_param.UnicableTuningWord >> 8;
912 diseqc.data[4] = lnb_param.UnicableTuningWord;
914 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
915 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
916 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
921 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
922 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
925 sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
926 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
927 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
929 frontend.setSecSequence(sec_sequence);
934 eDebugNoSimulate("found no useable satellite configuration for %s freq %d%s %s on orbital position (%d)",
935 sat.system ? "DVB-S2" : "DVB-S",
937 sat.polarisation == eDVBFrontendParametersSatellite::Polarisation_Horizontal ? "H" :
938 eDVBFrontendParametersSatellite::Polarisation_Vertical ? "V" :
939 eDVBFrontendParametersSatellite::Polarisation_CircularLeft ? "CL" : "CR",
940 sat.modulation == eDVBFrontendParametersSatellite::Modulation_Auto ? "AUTO" :
941 eDVBFrontendParametersSatellite::Modulation_QPSK ? "QPSK" :
942 eDVBFrontendParametersSatellite::Modulation_8PSK ? "8PSK" : "QAM16",
943 sat.orbital_position );
947 RESULT eDVBSatelliteEquipmentControl::clear()
949 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
950 for (int i=0; i <= m_lnbidx; ++i)
952 m_lnbs[i].m_satellites.clear();
953 m_lnbs[i].m_slot_mask = 0;
954 m_lnbs[i].m_prio = -1; // auto
958 m_not_linked_slot_mask=0;
960 //reset some tuner configuration
961 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
964 if (!strcmp(it->m_frontend->getDescription(), "BCM4501 (internal)") && !it->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp) && tmp != -1)
966 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
967 if (!f || fwrite("B", 1, 1, f) != 1)
968 eDebug("set /proc/stb/tsmux/lnb_b_input to B failed!! (%m)");
971 eDebug("set /proc/stb/tsmux/lnb_b_input to B OK");
975 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
976 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
977 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
978 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
979 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
980 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
983 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
985 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
986 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
987 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
988 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
989 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
990 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
996 /* LNB Specific Parameters */
997 RESULT eDVBSatelliteEquipmentControl::addLNB()
999 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
1000 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
1003 eDebug("no more LNB free... cnt is %d", m_lnbidx);
1006 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
1010 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
1012 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
1013 if ( currentLNBValid() )
1014 m_lnbs[m_lnbidx].m_slot_mask = slotmask;
1020 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
1022 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
1023 if ( currentLNBValid() )
1024 m_lnbs[m_lnbidx].m_lof_lo = lofl;
1030 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
1032 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
1033 if ( currentLNBValid() )
1034 m_lnbs[m_lnbidx].m_lof_hi = lofh;
1040 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
1042 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
1043 if ( currentLNBValid() )
1044 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
1050 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
1052 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
1053 if ( currentLNBValid() )
1054 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
1060 RESULT eDVBSatelliteEquipmentControl::setLNBPrio(int prio)
1062 eSecDebug("eDVBSatelliteEquipmentControl::setLNBPrio(%d)", prio);
1063 if ( currentLNBValid() )
1064 m_lnbs[m_lnbidx].m_prio = prio;
1070 RESULT eDVBSatelliteEquipmentControl::setLNBNum(int LNBNum)
1072 eSecDebug("eDVBSatelliteEquipmentControl::setLNBNum(%d)", LNBNum);
1073 if(!((LNBNum >= 1) && (LNBNum <= MAX_LNBNUM)))
1075 if ( currentLNBValid() )
1076 m_lnbs[m_lnbidx].LNBNum = LNBNum;
1082 /* DiSEqC Specific Parameters */
1083 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
1085 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
1086 if ( currentLNBValid() )
1087 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
1093 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
1095 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
1096 if ( currentLNBValid() )
1097 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
1103 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
1105 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
1106 if ( currentLNBValid() )
1107 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
1113 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
1115 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
1116 if ( currentLNBValid() )
1117 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
1123 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
1125 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
1126 if ( currentLNBValid() )
1127 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
1133 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
1135 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
1136 if ( currentLNBValid() )
1137 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
1143 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
1145 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
1146 if ( currentLNBValid() )
1147 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
1153 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
1155 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
1156 if ( currentLNBValid() )
1157 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1163 /* Rotor Specific Parameters */
1164 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1166 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
1167 if ( currentLNBValid() )
1168 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1174 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1176 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
1177 if ( currentLNBValid() )
1178 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1184 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1186 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1187 if ( currentLNBValid() )
1188 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1194 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1196 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1197 if ( currentLNBValid() )
1198 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1204 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1206 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1207 if ( currentLNBValid() )
1208 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1214 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1216 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1217 if ( currentLNBValid() )
1218 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1224 /* Unicable Specific Parameters */
1225 RESULT eDVBSatelliteEquipmentControl::setLNBSatCR(int SatCR_idx)
1227 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCR(%d)", SatCR_idx);
1228 if(!((SatCR_idx >=-1) && (SatCR_idx < MAX_SATCR)))
1230 if ( currentLNBValid() )
1231 m_lnbs[m_lnbidx].SatCR_idx = SatCR_idx;
1237 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRvco(int SatCRvco)
1239 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRvco(%d)", SatCRvco);
1240 if(!((SatCRvco >= 950*1000) && (SatCRvco <= 2150*1000)))
1242 if(!((m_lnbs[m_lnbidx].SatCR_idx >= 0) && (m_lnbs[m_lnbidx].SatCR_idx < MAX_SATCR)))
1244 if ( currentLNBValid() )
1245 m_lnbs[m_lnbidx].SatCRvco = SatCRvco;
1250 RESULT eDVBSatelliteEquipmentControl::getLNBSatCR()
1252 if ( currentLNBValid() )
1253 return m_lnbs[m_lnbidx].SatCR_idx;
1257 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRvco()
1259 if ( currentLNBValid() )
1260 return m_lnbs[m_lnbidx].SatCRvco;
1264 /* Satellite Specific Parameters */
1265 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1267 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1268 if ( currentLNBValid() )
1270 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1271 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1272 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1274 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1275 m_lnbs[m_lnbidx].m_satellites.insert(
1276 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1279 m_curSat = ret.first;
1291 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1293 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1294 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1295 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1302 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1304 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1305 if ( currentLNBValid() )
1307 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1308 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1317 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1319 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1320 if ( currentLNBValid() )
1322 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1323 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1332 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1334 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1335 if ( currentLNBValid() )
1336 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1344 int orb_pos, lofl, lofh;
1345 sat_compare(int o, int lofl, int lofh)
1346 :orb_pos(o), lofl(lofl), lofh(lofh)
1348 sat_compare(const sat_compare &x)
1349 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1351 bool operator < (const sat_compare & cmp) const
1353 if (orb_pos == cmp.orb_pos)
1355 if ( abs(lofl-cmp.lofl) < 200000 )
1357 if (abs(lofh-cmp.lofh) < 200000)
1359 return lofh<cmp.lofh;
1361 return lofl<cmp.lofl;
1363 return orb_pos < cmp.orb_pos;
1367 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1369 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1372 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1374 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1376 if (it->m_frontend->getSlotID() == tu1)
1378 else if (it->m_frontend->getSlotID() == tu2)
1383 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1384 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1385 if (!strcmp(p1->m_frontend->getDescription(), p2->m_frontend->getDescription()) && !strcmp(p1->m_frontend->getDescription(), "BCM4501 (internal)"))
1387 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
1388 if (!f || fwrite("A", 1, 1, f) != 1)
1389 eDebug("set /proc/stb/tsmux/lnb_b_input to A failed!! (%m)");
1392 eDebug("set /proc/stb/tsmux/lnb_b_input to A OK");
1399 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1401 if (it->m_frontend->getSlotID() == tu1)
1403 else if (it->m_frontend->getSlotID() == tu2)
1408 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1409 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1416 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1418 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1422 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1424 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1426 if (it->m_frontend->getSlotID() == tu1)
1428 else if (it->m_frontend->getSlotID() == tu2)
1433 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1434 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1438 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1440 if (it->m_frontend->getSlotID() == tu1)
1442 else if (it->m_frontend->getSlotID() == tu2)
1447 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1448 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1455 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1457 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1458 m_not_linked_slot_mask |= (1 << slot_no);
1461 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1463 return m_rotorMoving;
1466 void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)