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 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 if (sat.no_rotor_command_on_tune && !rotor) {
160 eSecDebugNoSimulate("no rotor but no_rotor_command_on_tune is set.. ignore lnb %d", idx);
164 eSecDebugNoSimulate("ret1 %d", ret);
168 // compare tuner data
169 if ( (csw != linked_csw) ||
170 ( diseqc && (ucsw != linked_ucsw || toneburst != linked_toneburst) ) ||
171 ( rotor && rotor_pos != sat.orbital_position ) )
177 eSecDebugNoSimulate("ret2 %d", ret);
178 if (ret) // special case when this tuner is linked to a satpos dependent tuner
180 fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
181 if (satpos_depends_ptr != -1)
183 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
184 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, rotor_pos);
185 if (!rotor || rotor_pos == -1 /* we dont know the rotor position yet */
186 || rotor_pos != sat.orbital_position ) // not the same orbital position?
192 eSecDebugNoSimulate("ret3 %d", ret);
194 else if (satpos_depends_ptr != -1)
196 eSecDebugNoSimulate("satpos depends");
197 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
198 if (direct_connected) // current fe is direct connected.. (can turn the rotor)
200 if (satpos_depends_to_fe->m_inuse) // if the dependent frontend is in use?
202 if (!rotor || rotor_pos != sat.orbital_position) // new orbital position not equal to current orbital pos?
208 else // current fe is dependent of another tuner ... (so this fe can't turn the rotor!)
210 // get current orb pos of the tuner with rotor connection
211 satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, rotor_pos);
212 if (!rotor || rotor_pos == -1 /* we dont know the rotor position yet */
213 || rotor_pos != sat.orbital_position ) // not the same orbital position?
218 eSecDebugNoSimulate("ret4 %d", ret);
221 if (ret && rotor && rotor_pos != -1)
222 ret -= abs(rotor_pos-sat.orbital_position);
224 eSecDebugNoSimulate("ret5 %d", ret);
228 int lof = sat.frequency > lnb_param.m_lof_threshold ?
229 lnb_param.m_lof_hi : lnb_param.m_lof_lo;
230 int tuner_freq = abs(sat.frequency - lof);
231 if (tuner_freq < 900000 || tuner_freq > 2200000)
235 if (ret && lnb_param.m_prio != -1)
236 ret = lnb_param.m_prio;
238 eSecDebugNoSimulate("ret %d, score old %d", ret, score);
242 if (highest_score_lnb)
243 *highest_score_lnb = idx;
245 eSecDebugNoSimulate("score new %d", score);
249 if (score && satcount)
251 if (score > (satcount-1))
252 score -= (satcount-1);
254 score = 1; // min score
256 if (score && direct_connected)
257 score += 5; // increase score for tuners with direct sat connection
258 eSecDebugNoSimulate("final score %d", score);
262 bool need_turn_fast(int turn_speed)
264 if (turn_speed == eDVBSatelliteRotorParameters::FAST)
266 else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
268 int begin = turn_speed >> 16; // high word is start time
269 int end = turn_speed&0xFFFF; // low word is end time
270 time_t now_time = ::time(0);
272 localtime_r(&now_time, &nowTime);
273 int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
274 bool neg = end <= begin;
280 if ((now >= begin && now < end) ^ neg)
286 #define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
288 #define eDebugNoSimulate(x...) \
295 // eDebugNoNewLine("SIMULATE:"); \
299 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
301 bool simulate = ((eDVBFrontend*)&frontend)->is_simulate();
303 if (canTune(sat, &frontend, slot_id, &lnb_idx))
305 eDVBSatelliteLNBParameters &lnb_param = m_lnbs[lnb_idx];
306 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
307 eDVBSatelliteRotorParameters &rotor_param = lnb_param.m_rotor_parameters;
309 std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
310 lnb_param.m_satellites.find(sat.orbital_position);
311 if ( sit != lnb_param.m_satellites.end())
313 eSecCommandList sec_sequence;
315 lnb_param.guard_offset = 0; //HACK
317 frontend.setData(eDVBFrontend::SATCR, lnb_param.SatCR_idx);
319 eDVBSatelliteSwitchParameters &sw_param = sit->second;
320 bool doSetFrontend = true;
321 bool doSetVoltageToneFrontend = true;
322 bool forceChanged = false;
323 bool needDiSEqCReset = false;
325 voltage = iDVBFrontend::voltageOff,
326 tone = iDVBFrontend::toneOff,
327 csw = di_param.m_committed_cmd,
328 ucsw = di_param.m_uncommitted_cmd,
329 toneburst = di_param.m_toneburst_param,
335 satposDependPtr = -1;
336 iDVBFrontend *sec_fe=&frontend;
337 eDVBRegisteredFrontend *linked_fe = 0;
338 eDVBSatelliteDiseqcParameters::t_diseqc_mode diseqc_mode = di_param.m_diseqc_mode;
339 eDVBSatelliteSwitchParameters::t_voltage_mode voltage_mode = sw_param.m_voltage_mode;
340 bool diseqc13V = voltage_mode == eDVBSatelliteSwitchParameters::HV_13;
343 voltage_mode = eDVBSatelliteSwitchParameters::HV;
345 frontend.getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satposDependPtr);
347 if (!(m_not_linked_slot_mask & slot_id)) // frontend with direct connection?
349 long linked_prev_ptr;
350 frontend.getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
351 while (linked_prev_ptr != -1)
353 linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
354 sec_fe = linked_fe->m_frontend;
355 sec_fe->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
357 if (satposDependPtr != -1) // we dont need uncommitted switch and rotor cmds on second output of a rotor lnb
358 diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
360 // in eDVBFrontend::tuneLoop we call closeFrontend and ->inc_use() in this this condition (to put the kernel frontend thread into idle state)
361 // so we must resend all diseqc stuff (voltage is disabled when the frontend is closed)
363 sec_fe->getState(state);
364 if (!linked_fe->m_inuse && state != eDVBFrontend::stateIdle)
369 sec_fe->getData(eDVBFrontend::CSW, lastcsw);
370 sec_fe->getData(eDVBFrontend::UCSW, lastucsw);
371 sec_fe->getData(eDVBFrontend::TONEBURST, lastToneburst);
372 sec_fe->getData(eDVBFrontend::ROTOR_CMD, lastRotorCmd);
373 sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
375 if (lastcsw == lastucsw && lastToneburst == lastucsw && lastucsw == -1)
376 needDiSEqCReset = true;
378 if ( sat.frequency > lnb_param.m_lof_threshold )
380 if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical))
383 int lof = (band&1)?lnb_param.m_lof_hi:lnb_param.m_lof_lo;
388 if(lnb_param.SatCR_idx == -1)
391 local = abs(sat.frequency
392 - ((lof - (lof % 1000)) + ((lof % 1000)>500 ? 1000 : 0)) ); //TODO für den Mist mal ein Macro schreiben
393 parm.FREQUENCY = (local - (local % 125)) + ((local % 125)>62 ? 125 : 0);
394 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - parm.FREQUENCY);
396 if ( voltage_mode == eDVBSatelliteSwitchParameters::_14V
397 || ( sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical
398 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
399 voltage = VOLTAGE(13);
400 else if ( voltage_mode == eDVBSatelliteSwitchParameters::_18V
401 || ( !(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation_Vertical)
402 && voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
403 voltage = VOLTAGE(18);
404 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
405 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && (band&1) ) )
406 tone = iDVBFrontend::toneOn;
407 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
408 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !(band&1) ) )
409 tone = iDVBFrontend::toneOff;
413 unsigned int tmp = abs(sat.frequency
414 - ((lof - (lof % 1000)) + ((lof % 1000)>500 ? 1000 : 0)) )
417 + lnb_param.guard_offset;
418 parm.FREQUENCY = (lnb_param.SatCRvco - (tmp % 4000))+((tmp%4000)>2000?4000:0)+lnb_param.guard_offset;
419 lnb_param.UnicableTuningWord = (((tmp / 4000)+((tmp%4000)>2000?1:0))
420 | ((band & 1) ? 0x400 : 0) //HighLow
421 | ((band & 2) ? 0x800 : 0) //VertHor
422 | ((lnb_param.LNBNum & 1) ? 0 : 0x1000) //Umschaltung LNB1 LNB2
423 | (lnb_param.SatCR_idx << 13)); //Adresse des SatCR
424 eDebug("[prepare] UnicableTuningWord %#04x",lnb_param.UnicableTuningWord);
425 eDebug("[prepare] guard_offset %d",lnb_param.guard_offset);
426 frontend.setData(eDVBFrontend::FREQ_OFFSET, sat.frequency - ((lnb_param.UnicableTuningWord & 0x3FF) *4000 + 1400000 - lnb_param.SatCRvco + lof));
429 if (diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
431 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
432 csw = 0xF0 | (csw << 2);
434 if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
438 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
439 bool changed_csw = send_csw && (forceChanged || csw != lastcsw);
442 (di_param.m_uncommitted_cmd && diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
443 bool changed_ucsw = send_ucsw && (forceChanged || ucsw != lastucsw);
446 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
447 bool changed_burst = send_burst && (forceChanged || toneburst != lastToneburst);
449 int send_mask = 0; /*
452 4 send toneburst first
453 8 send toneburst at end */
454 if (changed_burst) // toneburst first and toneburst changed
456 if (di_param.m_command_order&1)
470 if ((di_param.m_command_order&4) && send_csw)
472 if (di_param.m_command_order==4 && send_burst)
477 if ( di_param.m_use_fast
478 && di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO
480 && ((csw / 4) == (lastcsw / 4)) )
481 eDebugNoSimulate("dont send committed cmd (fast diseqc)");
485 if (!(di_param.m_command_order&4) && send_ucsw)
487 if (!(di_param.m_command_order&1) && send_burst)
493 eDebugNoNewLine("sendmask: ");
494 for (int i=3; i >= 0; --i)
495 if ( send_mask & (1<<i) )
496 eDebugNoNewLine("1");
498 eDebugNoNewLine("0");
501 if (doSetVoltageToneFrontend)
504 bool useGotoXX = false;
505 if ( diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2
506 && !sat.no_rotor_command_on_tune )
508 if (sw_param.m_rotorPosNum) // we have stored rotor pos?
509 RotorCmd=sw_param.m_rotorPosNum;
510 else // we must calc gotoxx cmd
512 eDebugNoSimulate("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
515 double SatLon = abs(sat.orbital_position)/10.00,
516 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
517 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
519 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
522 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
523 SiteLon = 360 - SiteLon;
525 eDebugNoSimulate("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
526 double satHourAngle =
527 calcSatHourangle( SatLon, SiteLat, SiteLon );
528 eDebugNoSimulate("PolarmountHourAngle=%lf", satHourAngle );
530 static int gotoXTable[10] =
531 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
533 if (SiteLat >= 0) // Northern Hemisphere
535 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
536 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
538 if (satHourAngle < 180) // the east
543 else // Southern Hemisphere
545 if (satHourAngle < 180) // the east
547 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
548 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
553 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
554 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
558 eDebugNoSimulate("RotorCmd = %04x", RotorCmd);
564 int vlt = iDVBFrontend::voltageOff;
565 eSecCommand::pair compare;
567 compare.tone = iDVBFrontend::toneOff;
568 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
569 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
570 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
573 vlt = iDVBFrontend::voltage13;
574 else if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
576 if (rotor_param.m_inputpower_parameters.m_use)
577 vlt = VOLTAGE(18); // in input power mode set 18V for measure input power
579 vlt = VOLTAGE(13); // in normal mode start turning with 13V
584 // check if voltage is already correct..
585 compare.voltage = vlt;
587 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
589 // check if voltage is disabled
590 compare.voltage = iDVBFrontend::voltageOff;
592 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
594 // voltage is changed... use DELAY_AFTER_VOLTAGE_CHANGE_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_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) );
597 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
599 // voltage was disabled.. use DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS
600 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, vlt) );
601 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS]) );
603 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
606 eDVBDiseqcCommand diseqc;
607 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
609 diseqc.data[0] = 0xE0;
613 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
614 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_RESET_CMD]) );
616 // diseqc peripherial powersupply on
617 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
618 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_DISEQC_PERIPHERIAL_POWERON_CMD]) );
621 for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
625 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
626 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
636 loops <<= di_param.m_repeats;
638 for ( int i = 0; i < loops;) // fill commands...
640 eDVBDiseqcCommand diseqc;
641 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
643 diseqc.data[0] = i ? 0xE1 : 0xE0;
644 diseqc.data[1] = 0x10;
645 if ( (send_mask & 2) && (di_param.m_command_order & 4) )
647 diseqc.data[2] = 0x39;
648 diseqc.data[3] = ucsw;
650 else if ( send_mask & 1 )
652 diseqc.data[2] = 0x38;
653 diseqc.data[3] = csw;
655 else // no committed command confed.. so send uncommitted..
657 diseqc.data[2] = 0x39;
658 diseqc.data[3] = ucsw;
660 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
666 if (diseqc.data[2] == 0x38 && (send_mask & 2))
668 else if (diseqc.data[2] == 0x39 && (send_mask & 1))
670 int tmp = m_params[DELAY_BETWEEN_DISEQC_REPEATS];
673 int delay = di_param.m_repeats ? (tmp - 54) / 2 : tmp; // standard says 100msek between two repeated commands
674 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
676 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
677 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
680 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
682 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
684 else // delay 120msek when no command is in repeat gap
685 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, tmp) );
688 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
691 if ( send_mask & 8 ) // toneburst at end of sequence
693 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
694 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_TONEBURST]) );
697 if (di_param.m_seq_repeat && seq_repeat == 0)
698 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BEFORE_SEQUENCE_REPEAT]) );
702 eDebugNoSimulate("RotorCmd %02x, lastRotorCmd %02lx", RotorCmd, lastRotorCmd);
703 if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
705 eSecCommand::pair compare;
706 if (!send_mask && lnb_param.SatCR_idx == -1)
709 compare.tone = iDVBFrontend::toneOff;
710 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
711 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
712 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC]) );
714 compare.voltage = iDVBFrontend::voltageOff;
716 // the next is a check if voltage is switched off.. then we first set a voltage :)
717 // else we set voltage after all diseqc stuff..
718 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
720 if (rotor_param.m_inputpower_parameters.m_use)
721 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) ); // set 18V for measure input power
723 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // in normal mode start turning with 13V
725 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_MOTOR_CMD]) ); // wait 750ms when voltage was disabled
726 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) ); // no need to send stop rotor cmd and recheck voltage
729 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_BETWEEN_SWITCH_AND_MOTOR_CMD]) ); // wait 700ms when diseqc changed
731 eDVBDiseqcCommand diseqc;
732 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
734 diseqc.data[0] = 0xE0;
735 diseqc.data[1] = 0x31; // positioner
736 diseqc.data[2] = 0x60; // stop
737 sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +5) );
738 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
739 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
740 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
741 // wait 150msec after send rotor stop cmd
742 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_MOTOR_STOP_CMD]) );
744 diseqc.data[0] = 0xE0;
745 diseqc.data[1] = 0x31; // positioner
749 diseqc.data[2] = 0x6E; // drive to angular position
750 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
751 diseqc.data[4] = RotorCmd & 0xFF;
756 diseqc.data[2] = 0x6B; // goto stored sat position
757 diseqc.data[3] = RotorCmd;
758 diseqc.data[4] = 0x00;
760 if(lnb_param.SatCR_idx == -1)
762 int mrt = m_params[MOTOR_RUNNING_TIMEOUT]; // in seconds!
763 if ( rotor_param.m_inputpower_parameters.m_use )
764 { // use measure rotor input power to detect rotor state
765 bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed);
766 eSecCommand::rotor cmd;
767 eSecCommand::pair compare;
769 compare.voltage = VOLTAGE(18);
771 compare.voltage = VOLTAGE(13);
773 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
774 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
775 // measure idle power values
778 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec after voltage change
779 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
781 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
782 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
784 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MEASURE_IDLE_INPUTPOWER]) ); // wait 150msec before measure
785 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
787 sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
788 ////////////////////////////
789 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, m_params[MOTOR_COMMAND_RETRIES]) ); // 2 retries
790 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
791 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
792 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) ); // 2 seconds rotor start timout
794 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // 50msec delay
795 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
796 cmd.direction=1; // check for running rotor
797 cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
800 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
801 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout .. we assume now the rotor is already at the correct position
802 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
803 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
804 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) ); // goto loop start
806 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
808 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
809 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*20) ); // mrt is in seconds... our SLEEP time is 50ms.. so * 20
810 // rotor running loop
811 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
812 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
813 cmd.direction=0; // check for stopped rotor
815 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
816 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); // timeout ? this should never happen
817 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
818 /////////////////////
819 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
820 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
823 { // use normal turning mode
824 if (curRotorPos != -1)
826 mrt = abs(curRotorPos - sat.orbital_position);
830 mrt += 10; // round a little bit
831 mrt *= 2000; // (we assume a very slow rotor with just 0.5 degree per second here)
833 mrt += 3; // a little bit overhead
835 doSetVoltageToneFrontend=false;
837 eSecCommand::rotor cmd;
838 eSecCommand::pair compare;
839 compare.voltage = VOLTAGE(13);
841 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
842 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
843 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_MOTOR_CMD]) ); // wait 150msec after voltage change
845 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
846 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
847 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
848 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) ); // sleep one second before change voltage or tone
850 compare.voltage = voltage;
852 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
853 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) ); // wait 2 second before set high voltage
854 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
857 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
858 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
859 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
860 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 0) );
862 cmd.direction=1; // check for running rotor
866 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*4) ); // mrt is in seconds... our SLEEP time is 250ms.. so * 4
867 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); // 250msec delay
868 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
869 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +5 ) );
870 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) ); // goto loop start
871 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
872 sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
873 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +4) );
874 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
875 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
876 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -5) );
878 eDebug("set rotor timeout to %d seconds", mrt);
879 sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
880 sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
887 sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS) );
891 sec_fe->setData(eDVBFrontend::NEW_CSW, csw);
892 sec_fe->setData(eDVBFrontend::NEW_UCSW, ucsw);
893 sec_fe->setData(eDVBFrontend::NEW_TONEBURST, di_param.m_toneburst_param);
895 if ((doSetVoltageToneFrontend) && (lnb_param.SatCR_idx == -1))
897 eSecCommand::pair compare;
898 compare.voltage = voltage;
900 sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
901 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
902 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_VOLTAGE_CHANGE]) );
904 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
905 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
906 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
909 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_SWITCHPARMS) );
911 if(lnb_param.SatCR_idx != -1)
913 // check if voltage is disabled
914 eSecCommand::pair compare;
916 compare.voltage = iDVBFrontend::voltageOff;
917 sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
918 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
919 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS] ) );
921 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18_5) );
922 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
923 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_VOLTAGE_CHANGE_BEFORE_SWITCH_CMDS]) ); // wait 20 ms after voltage change
925 eDVBDiseqcCommand diseqc;
926 memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
928 diseqc.data[0] = 0xE0;
929 diseqc.data[1] = 0x10;
930 diseqc.data[2] = 0x5A;
931 diseqc.data[3] = lnb_param.UnicableTuningWord >> 8;
932 diseqc.data[4] = lnb_param.UnicableTuningWord;
934 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
935 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_LAST_DISEQC_CMD]) );
936 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
941 sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
942 sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
945 sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
946 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
947 sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
949 frontend.setSecSequence(sec_sequence);
954 eDebugNoSimulate("found no useable satellite configuration for %s freq %d%s %s on orbital position (%d)",
955 sat.system ? "DVB-S2" : "DVB-S",
957 sat.polarisation == eDVBFrontendParametersSatellite::Polarisation_Horizontal ? "H" :
958 eDVBFrontendParametersSatellite::Polarisation_Vertical ? "V" :
959 eDVBFrontendParametersSatellite::Polarisation_CircularLeft ? "CL" : "CR",
960 sat.modulation == eDVBFrontendParametersSatellite::Modulation_Auto ? "AUTO" :
961 eDVBFrontendParametersSatellite::Modulation_QPSK ? "QPSK" :
962 eDVBFrontendParametersSatellite::Modulation_8PSK ? "8PSK" : "QAM16",
963 sat.orbital_position );
967 RESULT eDVBSatelliteEquipmentControl::clear()
969 eSecDebug("eDVBSatelliteEquipmentControl::clear()");
970 for (int i=0; i <= m_lnbidx; ++i)
972 m_lnbs[i].m_satellites.clear();
973 m_lnbs[i].m_slot_mask = 0;
974 m_lnbs[i].m_prio = -1; // auto
978 m_not_linked_slot_mask=0;
980 //reset some tuner configuration
981 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
985 if (sscanf(it->m_frontend->getDescription(), "BCM450%c (internal)", &c) == 1 && !it->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, tmp) && tmp != -1)
987 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
988 if (!f || fwrite("B", 1, 1, f) != 1)
989 eDebug("set /proc/stb/tsmux/lnb_b_input to B failed!! (%m)");
992 eDebug("set /proc/stb/tsmux/lnb_b_input to B OK");
996 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
997 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
998 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
999 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1000 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1001 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1004 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1006 it->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, -1);
1007 it->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, -1);
1008 it->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, -1);
1009 it->m_frontend->setData(eDVBFrontend::ROTOR_POS, -1);
1010 it->m_frontend->setData(eDVBFrontend::ROTOR_CMD, -1);
1011 it->m_frontend->setData(eDVBFrontend::SATCR, -1);
1017 /* LNB Specific Parameters */
1018 RESULT eDVBSatelliteEquipmentControl::addLNB()
1020 if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
1021 m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
1024 eDebug("no more LNB free... cnt is %d", m_lnbidx);
1027 eSecDebug("eDVBSatelliteEquipmentControl::addLNB(%d)", m_lnbidx);
1031 RESULT eDVBSatelliteEquipmentControl::setLNBSlotMask(int slotmask)
1033 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSlotMask(%d)", slotmask);
1034 if ( currentLNBValid() )
1035 m_lnbs[m_lnbidx].m_slot_mask = slotmask;
1041 RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
1043 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFL(%d)", lofl);
1044 if ( currentLNBValid() )
1045 m_lnbs[m_lnbidx].m_lof_lo = lofl;
1051 RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
1053 eSecDebug("eDVBSatelliteEquipmentControl::setLNBLOFH(%d)", lofh);
1054 if ( currentLNBValid() )
1055 m_lnbs[m_lnbidx].m_lof_hi = lofh;
1061 RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
1063 eSecDebug("eDVBSatelliteEquipmentControl::setLNBThreshold(%d)", threshold);
1064 if ( currentLNBValid() )
1065 m_lnbs[m_lnbidx].m_lof_threshold = threshold;
1071 RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
1073 eSecDebug("eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(%d)", onoff);
1074 if ( currentLNBValid() )
1075 m_lnbs[m_lnbidx].m_increased_voltage = onoff;
1081 RESULT eDVBSatelliteEquipmentControl::setLNBPrio(int prio)
1083 eSecDebug("eDVBSatelliteEquipmentControl::setLNBPrio(%d)", prio);
1084 if ( currentLNBValid() )
1085 m_lnbs[m_lnbidx].m_prio = prio;
1091 RESULT eDVBSatelliteEquipmentControl::setLNBNum(int LNBNum)
1093 eSecDebug("eDVBSatelliteEquipmentControl::setLNBNum(%d)", LNBNum);
1094 if(!((LNBNum >= 1) && (LNBNum <= MAX_LNBNUM)))
1096 if ( currentLNBValid() )
1097 m_lnbs[m_lnbidx].LNBNum = LNBNum;
1103 /* DiSEqC Specific Parameters */
1104 RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
1106 eSecDebug("eDVBSatelliteEquipmentControl::setDiSEqcMode(%d)", diseqcmode);
1107 if ( currentLNBValid() )
1108 m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
1114 RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
1116 eSecDebug("eDVBSatelliteEquipmentControl::setToneburst(%d)", toneburst);
1117 if ( currentLNBValid() )
1118 m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
1124 RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
1126 eSecDebug("eDVBSatelliteEquipmentControl::setRepeats(%d)", repeats);
1127 if ( currentLNBValid() )
1128 m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
1134 RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
1136 eSecDebug("eDVBSatelliteEquipmentControl::setCommittedCommand(%d)", command);
1137 if ( currentLNBValid() )
1138 m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
1144 RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
1146 eSecDebug("eDVBSatelliteEquipmentControl::setUncommittedCommand(%d)", command);
1147 if ( currentLNBValid() )
1148 m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
1154 RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
1156 eSecDebug("eDVBSatelliteEquipmentControl::setCommandOrder(%d)", order);
1157 if ( currentLNBValid() )
1158 m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
1164 RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
1166 eSecDebug("eDVBSatelliteEquipmentControl::setFastDiSEqc(%d)", onoff);
1167 if ( currentLNBValid() )
1168 m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
1174 RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
1176 eSecDebug("eDVBSatelliteEquipmentControl::setSeqRepeat(%d)", onoff);
1177 if ( currentLNBValid() )
1178 m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
1184 /* Rotor Specific Parameters */
1185 RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
1187 eSecDebug("eDVBSatelliteEquipmentControl::setLongitude(%f)", longitude);
1188 if ( currentLNBValid() )
1189 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
1195 RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
1197 eSecDebug("eDVBSatelliteEquipmentControl::setLatitude(%f)", latitude);
1198 if ( currentLNBValid() )
1199 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
1205 RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
1207 eSecDebug("eDVBSatelliteEquipmentControl::setLoDirection(%d)", direction);
1208 if ( currentLNBValid() )
1209 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
1215 RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
1217 eSecDebug("eDVBSatelliteEquipmentControl::setLaDirection(%d)", direction);
1218 if ( currentLNBValid() )
1219 m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
1225 RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
1227 eSecDebug("eDVBSatelliteEquipmentControl::setUseInputpower(%d)", onoff);
1228 if ( currentLNBValid() )
1229 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
1235 RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
1237 eSecDebug("eDVBSatelliteEquipmentControl::setInputpowerDelta(%d)", delta);
1238 if ( currentLNBValid() )
1239 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
1245 /* Unicable Specific Parameters */
1246 RESULT eDVBSatelliteEquipmentControl::setLNBSatCR(int SatCR_idx)
1248 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCR(%d)", SatCR_idx);
1249 if(!((SatCR_idx >=-1) && (SatCR_idx < MAX_SATCR)))
1251 if ( currentLNBValid() )
1252 m_lnbs[m_lnbidx].SatCR_idx = SatCR_idx;
1258 RESULT eDVBSatelliteEquipmentControl::setLNBSatCRvco(int SatCRvco)
1260 eSecDebug("eDVBSatelliteEquipmentControl::setLNBSatCRvco(%d)", SatCRvco);
1261 if(!((SatCRvco >= 950*1000) && (SatCRvco <= 2150*1000)))
1263 if(!((m_lnbs[m_lnbidx].SatCR_idx >= 0) && (m_lnbs[m_lnbidx].SatCR_idx < MAX_SATCR)))
1265 if ( currentLNBValid() )
1266 m_lnbs[m_lnbidx].SatCRvco = SatCRvco;
1271 RESULT eDVBSatelliteEquipmentControl::getLNBSatCR()
1273 if ( currentLNBValid() )
1274 return m_lnbs[m_lnbidx].SatCR_idx;
1278 RESULT eDVBSatelliteEquipmentControl::getLNBSatCRvco()
1280 if ( currentLNBValid() )
1281 return m_lnbs[m_lnbidx].SatCRvco;
1285 /* Satellite Specific Parameters */
1286 RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
1288 eSecDebug("eDVBSatelliteEquipmentControl::addSatellite(%d)", orbital_position);
1289 if ( currentLNBValid() )
1291 std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
1292 m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
1293 if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
1295 std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
1296 m_lnbs[m_lnbidx].m_satellites.insert(
1297 std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
1300 m_curSat = ret.first;
1312 RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
1314 eSecDebug("eDVBSatelliteEquipmentControl::setVoltageMode(%d)", mode);
1315 if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1316 m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
1323 RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
1325 eSecDebug("eDVBSatelliteEquipmentControl::setToneMode(%d)", mode);
1326 if ( currentLNBValid() )
1328 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1329 m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
1338 RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
1340 eSecDebug("eDVBSatelliteEquipmentControl::setRotorPosNum(%d)", rotor_pos_num);
1341 if ( currentLNBValid() )
1343 if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
1344 m_curSat->second.m_rotorPosNum=rotor_pos_num;
1353 RESULT eDVBSatelliteEquipmentControl::setRotorTurningSpeed(int speed)
1355 eSecDebug("eDVBSatelliteEquipmentControl::setRotorTurningSpeed(%d)", speed);
1356 if ( currentLNBValid() )
1357 m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_turning_speed = speed;
1365 int orb_pos, lofl, lofh;
1366 sat_compare(int o, int lofl, int lofh)
1367 :orb_pos(o), lofl(lofl), lofh(lofh)
1369 sat_compare(const sat_compare &x)
1370 :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
1372 bool operator < (const sat_compare & cmp) const
1374 if (orb_pos == cmp.orb_pos)
1376 if ( abs(lofl-cmp.lofl) < 200000 )
1378 if (abs(lofh-cmp.lofh) < 200000)
1380 return lofh<cmp.lofh;
1382 return lofl<cmp.lofl;
1384 return orb_pos < cmp.orb_pos;
1388 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
1390 eSecDebug("eDVBSatelliteEquipmentControl::setTunerLinked(%d, %d)", tu1, tu2);
1393 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1394 eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin());
1395 for (; it != m_avail_frontends.end(); ++it)
1397 if (it->m_frontend->getSlotID() == tu1)
1399 else if (it->m_frontend->getSlotID() == tu2)
1405 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1406 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1407 if (!strcmp(p1->m_frontend->getDescription(), p2->m_frontend->getDescription()) && sscanf(p1->m_frontend->getDescription(), "BCM450%c (internal)", &c) == 1)
1409 FILE *f=fopen("/proc/stb/tsmux/lnb_b_input", "w");
1410 if (!f || fwrite("A", 1, 1, f) != 1)
1411 eDebug("set /proc/stb/tsmux/lnb_b_input to A failed!! (%m)");
1414 eDebug("set /proc/stb/tsmux/lnb_b_input to A OK");
1421 it=m_avail_simulate_frontends.begin();
1422 for (; it != m_avail_simulate_frontends.end(); ++it)
1424 if (it->m_frontend->getSlotID() == tu1)
1426 else if (it->m_frontend->getSlotID() == tu2)
1431 p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (long)p2);
1432 p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (long)p1);
1439 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
1441 eSecDebug("eDVBSatelliteEquipmentControl::setTunerDepends(%d, %d)", tu1, tu2);
1445 eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
1447 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
1449 if (it->m_frontend->getSlotID() == tu1)
1451 else if (it->m_frontend->getSlotID() == tu2)
1456 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1457 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1461 for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_simulate_frontends.begin()); it != m_avail_simulate_frontends.end(); ++it)
1463 if (it->m_frontend->getSlotID() == tu1)
1465 else if (it->m_frontend->getSlotID() == tu2)
1470 p1->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p2);
1471 p2->m_frontend->setData(eDVBFrontend::SATPOS_DEPENDS_PTR, (long)p1);
1478 void eDVBSatelliteEquipmentControl::setSlotNotLinked(int slot_no)
1480 eSecDebug("eDVBSatelliteEquipmentControl::setSlotNotLinked(%d)", slot_no);
1481 m_not_linked_slot_mask |= (1 << slot_no);
1484 bool eDVBSatelliteEquipmentControl::isRotorMoving()
1486 return m_rotorMoving;
1489 void eDVBSatelliteEquipmentControl::setRotorMoving(int slot_no, bool b)
1492 m_rotorMoving |= (1 << slot_no);
1494 m_rotorMoving &= ~(1 << slot_no);