+ if ( lnb_param.m_slot_mask & slot_id ) // lnb for correct tuner?
+ {
+ int ret = 0;
+ eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
+
+ eSecDebugNoSimulate("lnb %d found", idx);
+
+ satcount += lnb_param.m_satellites.size();
+
+ std::map<int, eDVBSatelliteSwitchParameters>::iterator sit =
+ lnb_param.m_satellites.find(sat.orbital_position);
+ if ( sit != lnb_param.m_satellites.end())
+ {
+ bool diseqc=false;
+ long band=0,
+ linked_prev_ptr=-1,
+ linked_next_ptr=-1,
+ satpos_depends_ptr=-1,
+ csw = di_param.m_committed_cmd,
+ ucsw = di_param.m_uncommitted_cmd,
+ toneburst = di_param.m_toneburst_param,
+ curRotorPos;
+
+ eSecDebugNoSimulate("sat %d found", sat.orbital_position);
+ fe->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
+ fe->getData(eDVBFrontend::SATPOS_DEPENDS_PTR, satpos_depends_ptr);
+
+ if ( sat.frequency > lnb_param.m_lof_threshold )
+ band |= 1;
+ if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
+ band |= 2;
+
+ if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
+ {
+ diseqc=true;
+ if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
+ csw = 0xF0 | (csw << 2);
+
+ if (di_param.m_committed_cmd <= eDVBSatelliteDiseqcParameters::SENDNO)
+ csw |= band;
+
+ if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) // ROTOR
+ rotor = true;
+
+ ret=10000;
+ }
+ else
+ {
+ csw = band;
+ ret = 15000;
+ }
+
+ eSecDebugNoSimulate("ret1 %d", ret);
+
+ if (direct_connected) // frontend with direct connection?
+ {
+ long ocsw = -1,
+ oucsw = -1,
+ oToneburst = -1;
+ eSecDebugNoSimulate("direct");
+ fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
+ fe->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
+ fe->getData(eDVBFrontend::CSW, ocsw);
+ fe->getData(eDVBFrontend::UCSW, oucsw);
+ fe->getData(eDVBFrontend::TONEBURST, oToneburst);
+ while (ret && linked_prev_ptr != -1) // check for linked tuners..
+ {
+ eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
+ if (linked_fe->m_inuse)
+ {
+ if ( (csw != ocsw) ||
+ ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
+ ( rotor && curRotorPos != sat.orbital_position ) )
+ {
+ ret=0;
+ }
+ }
+ linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
+ }
+ eSecDebugNoSimulate("ret2 %d", ret);
+ while (ret && linked_next_ptr != -1) // check for linked tuners..
+ {
+ eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
+ if (linked_fe->m_inuse)
+ {
+ if ( (csw != ocsw) ||
+ ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
+ ( rotor && curRotorPos != sat.orbital_position ) )
+ {
+ ret=0;
+ }
+ }
+ linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, (long&)linked_next_ptr);
+ }
+ eSecDebugNoSimulate("ret3 %d", ret);
+ }
+ else // linked frontend..
+ {
+ long ocsw = -1,
+ oucsw = -1,
+ oToneburst = -1;
+ while (linked_prev_ptr != -1)
+ {
+ eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
+ linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, (long&)linked_prev_ptr);
+ if (linked_prev_ptr == -1)
+ {
+ iDVBFrontend *sec_fe = linked_fe->m_frontend;
+ sec_fe->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
+ if (linked_fe->m_inuse)
+ {
+ sec_fe->getData(eDVBFrontend::CSW, ocsw);
+ sec_fe->getData(eDVBFrontend::UCSW, oucsw);
+ sec_fe->getData(eDVBFrontend::TONEBURST, oToneburst);
+ eSecDebug("(%ld != %ld) || \n(%d && (%ld != %ld || %ld != %ld) ) ||\n( %d && %ld != %d ) )",
+ csw, ocsw, diseqc, ucsw, oucsw, toneburst, oToneburst, rotor, curRotorPos, sat.orbital_position);
+ if ( (csw != ocsw) ||
+ ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
+ ( rotor && curRotorPos != sat.orbital_position ) )
+ {
+ ret=0;
+ }
+ }
+ }
+ }
+ eSecDebugNoSimulate("ret4 %d", ret);
+ }
+
+ if (ret)
+ if (satpos_depends_ptr != -1)
+ {
+ eSecDebugNoSimulate("satpos depends");
+ eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) satpos_depends_ptr;
+ if ( satpos_depends_to_fe->m_inuse )
+ {
+ if (!direct_connected)
+ satpos_depends_to_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, curRotorPos);
+ if (!rotor || curRotorPos != sat.orbital_position)
+ ret=0;
+ }
+ eSecDebugNoSimulate("ret5 %d", ret);
+ }
+
+ if (ret && rotor && curRotorPos != -1)
+ ret -= abs(curRotorPos-sat.orbital_position);
+
+ eSecDebugNoSimulate("ret6 %d", ret);
+
+ if (ret)
+ {
+ int lof = sat.frequency > lnb_param.m_lof_threshold ?
+ lnb_param.m_lof_hi : lnb_param.m_lof_lo;
+ int tuner_freq = abs(sat.frequency - lof);
+ if (tuner_freq < 900000 || tuner_freq > 2200000)
+ ret=0;
+ }
+
+ if (ret && lnb_param.m_prio != -1)
+ ret = lnb_param.m_prio;
+
+ eSecDebugNoSimulate("ret %d, score old %d", ret, score);
+ if (ret > score)
+ {
+ score = ret;
+ if (highest_score_lnb)
+ *highest_score_lnb = idx;
+ }
+ eSecDebugNoSimulate("score new %d", score);
+ }
+ }
+ }
+ if (score && satcount)
+ {
+ if (score > (satcount-1))
+ score -= (satcount-1);
+ else
+ score = 1; // min score
+ }
+ if (score && direct_connected)
+ score += 5; // increase score for tuners with direct sat connection
+ eSecDebugNoSimulate("final score %d", score);
+ return score;
+}
+
+bool need_turn_fast(int turn_speed)
+{
+ if (turn_speed == eDVBSatelliteRotorParameters::FAST)
+ return true;
+ else if (turn_speed != eDVBSatelliteRotorParameters::SLOW)
+ {
+ int begin = turn_speed >> 16; // high word is start time
+ int end = turn_speed&0xFFFF; // low word is end time
+ time_t now_time = ::time(0);
+ tm nowTime;
+ localtime_r(&now_time, &nowTime);
+ int now = (nowTime.tm_hour + 1) * 60 + nowTime.tm_min + 1;
+ bool neg = end <= begin;
+ if (neg) {
+ int tmp = begin;
+ begin = end;
+ end = tmp;
+ }
+ if ((now >= begin && now < end) ^ neg)
+ return true;
+ }
+ return false;
+}
+
+#define VOLTAGE(x) (lnb_param.m_increased_voltage ? iDVBFrontend::voltage##x##_5 : iDVBFrontend::voltage##x)
+
+#define eDebugNoSimulate(x...) \
+ do { \
+ if (!simulate) \
+ eDebug(x); \
+ } while(0)
+// else \
+// { \
+// eDebugNoNewLine("SIMULATE:"); \
+// eDebug(x); \
+// } \
+
+RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int slot_id, unsigned int tunetimeout)
+{
+ bool simulate = ((eDVBFrontend*)&frontend)->is_simulate();
+ int lnb_idx = -1;
+ if (canTune(sat, &frontend, slot_id, &lnb_idx))
+ {
+ eDVBSatelliteLNBParameters &lnb_param = m_lnbs[lnb_idx];