+/* LNB Specific Parameters */
+RESULT eDVBSatelliteEquipmentControl::addLNB()
+{
+ if ( (m_lnbidx+1) < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)))
+ m_curSat=m_lnbs[++m_lnbidx].m_satellites.end();
+ else
+ {
+ eDebug("no more LNB free... cnt is %d", m_lnbidx);
+ return -ENOSPC;
+ }
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setLNBTunerMask(int tunermask)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].tuner_mask = tunermask;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setLNBLOFL(int lofl)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_lof_lo = lofl;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setLNBLOFH(int lofh)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_lof_hi = lofh;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setLNBThreshold(int threshold)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_lof_threshold = threshold;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setLNBIncreasedVoltage(bool onoff)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_increased_voltage = onoff;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+/* DiSEqC Specific Parameters */
+RESULT eDVBSatelliteEquipmentControl::setDiSEqCMode(int diseqcmode)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_diseqc_parameters.m_diseqc_mode = (eDVBSatelliteDiseqcParameters::t_diseqc_mode)diseqcmode;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setToneburst(int toneburst)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_diseqc_parameters.m_toneburst_param = (eDVBSatelliteDiseqcParameters::t_toneburst_param)toneburst;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setRepeats(int repeats)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_diseqc_parameters.m_repeats=repeats;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setCommittedCommand(int command)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_diseqc_parameters.m_committed_cmd=command;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setUncommittedCommand(int command)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_diseqc_parameters.m_uncommitted_cmd = command;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setCommandOrder(int order)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_diseqc_parameters.m_command_order=order;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setFastDiSEqC(bool onoff)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_diseqc_parameters.m_use_fast=onoff;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setSeqRepeat(bool onoff)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_diseqc_parameters.m_seq_repeat = onoff;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+/* Rotor Specific Parameters */
+RESULT eDVBSatelliteEquipmentControl::setLongitude(float longitude)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_longitude=longitude;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setLatitude(float latitude)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_latitude=latitude;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setLoDirection(int direction)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_lo_direction=direction;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setLaDirection(int direction)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_rotor_parameters.m_gotoxx_parameters.m_la_direction=direction;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setUseInputpower(bool onoff)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_use=onoff;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setInputpowerDelta(int delta)
+{
+ if ( currentLNBValid() )
+ m_lnbs[m_lnbidx].m_rotor_parameters.m_inputpower_parameters.m_delta=delta;
+ else
+ return -ENOENT;
+ return 0;
+}
+
+/* Satellite Specific Parameters */
+RESULT eDVBSatelliteEquipmentControl::addSatellite(int orbital_position)
+{
+ if ( currentLNBValid() )
+ {
+ std::map<int, eDVBSatelliteSwitchParameters>::iterator it =
+ m_lnbs[m_lnbidx].m_satellites.find(orbital_position);
+ if ( it == m_lnbs[m_lnbidx].m_satellites.end() )
+ {
+ std::pair<std::map<int, eDVBSatelliteSwitchParameters>::iterator, bool > ret =
+ m_lnbs[m_lnbidx].m_satellites.insert(
+ std::pair<int, eDVBSatelliteSwitchParameters>(orbital_position, eDVBSatelliteSwitchParameters())
+ );
+ if ( ret.second )
+ m_curSat = ret.first;
+ else
+ return -ENOMEM;
+ }
+ else
+ return -EEXIST;
+ }
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setVoltageMode(int mode)
+{
+ if ( currentLNBValid() && m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
+ m_curSat->second.m_voltage_mode = (eDVBSatelliteSwitchParameters::t_voltage_mode)mode;
+ else
+ return -ENOENT;
+ return 0;
+
+}
+
+RESULT eDVBSatelliteEquipmentControl::setToneMode(int mode)
+{
+ if ( currentLNBValid() )
+ {
+ if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
+ m_curSat->second.m_22khz_signal = (eDVBSatelliteSwitchParameters::t_22khz_signal)mode;
+ else
+ return -EPERM;
+ }
+ else
+ return -ENOENT;
+ return 0;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setRotorPosNum(int rotor_pos_num)
+{
+ if ( currentLNBValid() )
+ {
+ if ( m_curSat != m_lnbs[m_lnbidx].m_satellites.end() )
+ m_curSat->second.m_rotorPosNum=rotor_pos_num;
+ else
+ return -EPERM;
+ }
+ else
+ return -ENOENT;
+ return 0;
+}
+
+struct sat_compare
+{
+ int orb_pos, lofl, lofh;
+ sat_compare(int o, int lofl, int lofh)
+ :orb_pos(o), lofl(lofl), lofh(lofh)
+ {}
+ sat_compare(const sat_compare &x)
+ :orb_pos(x.orb_pos), lofl(x.lofl), lofh(x.lofh)
+ {}
+ bool operator < (const sat_compare & cmp) const
+ {
+ if (orb_pos == cmp.orb_pos)
+ {
+ if ( abs(lofl-cmp.lofl) < 200000 )
+ {
+ if (abs(lofh-cmp.lofh) < 200000)
+ return false;
+ return lofh<cmp.lofh;
+ }
+ return lofl<cmp.lofl;
+ }
+ return orb_pos < cmp.orb_pos;
+ }
+};
+
+PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int tu2)
+{
+ PyObject *ret=0;
+
+ int tu1_mask = 1 << tu1,
+ tu2_mask = 1 << tu2;
+
+ if (tu1 != tu2)
+ {
+ eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
+ int cnt=0;
+ for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
+ {
+ if (cnt == tu1)
+ p1 = *it;
+ else if (cnt == tu2)
+ p2 = *it;
+ }
+ if (p1 && p2)
+ {
+ // check for linked tuners
+ int tmp1, tmp2;
+ p1->m_frontend->getData(7, tmp1);
+ p2->m_frontend->getData(7, tmp2);
+ if ((void*)tmp1 != p2 && (void*)tmp2 != p1)
+ {
+ // check for rotor dependency
+ p1->m_frontend->getData(8, tmp1);
+ p2->m_frontend->getData(8, tmp2);
+ if ((void*)tmp1 != p2 && (void*)tmp2 != p1)
+ {
+ std::set<sat_compare> tu1sats, tu2sats;
+ std::list<sat_compare> tu1difference, tu2difference;
+ std::insert_iterator<std::list<sat_compare> > insert1(tu1difference, tu1difference.begin()),
+ insert2(tu2difference, tu2difference.begin());
+ for (int idx=0; idx <= m_lnbidx; ++idx )
+ {
+ eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
+ for (std::map<int, eDVBSatelliteSwitchParameters>::iterator sit(lnb_param.m_satellites.begin());
+ sit != lnb_param.m_satellites.end(); ++sit)
+ {
+ if ( lnb_param.tuner_mask & tu1_mask )
+ tu1sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
+ if ( lnb_param.tuner_mask & tu2_mask )
+ tu2sats.insert(sat_compare(sit->first, lnb_param.m_lof_lo, lnb_param.m_lof_hi));
+ }
+ }
+ std::set_difference(tu1sats.begin(), tu1sats.end(),
+ tu2sats.begin(), tu2sats.end(),
+ insert1);
+ std::set_difference(tu2sats.begin(), tu2sats.end(),
+ tu1sats.begin(), tu1sats.end(),
+ insert2);
+ if (!tu1sats.empty() || !tu2sats.empty())
+ {
+ int idx=0;
+ ret = PyList_New(2+tu1difference.size()+tu2difference.size());
+
+ PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu1difference.size()));
+ for(std::list<sat_compare>::iterator it(tu1difference.begin()); it != tu1difference.end(); ++it)
+ PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
+
+ PyList_SET_ITEM(ret, idx++, PyInt_FromLong(tu2difference.size()));
+ for(std::list<sat_compare>::iterator it(tu2difference.begin()); it != tu2difference.end(); ++it)
+ PyList_SET_ITEM(ret, idx++, PyInt_FromLong(it->orb_pos));
+ }
+ }
+ }
+ }
+ }
+ if (!ret)
+ {
+ ret = PyList_New(2);
+ PyList_SET_ITEM(ret, 0, PyInt_FromLong(0));
+ PyList_SET_ITEM(ret, 1, PyInt_FromLong(0));
+ }
+ return ret;
+}
+
+RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
+{
+ return setDependencyPointers(tu1, tu2, 7);
+}
+
+RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)
+{
+ return setDependencyPointers(tu1, tu2, 8);
+}
+
+bool eDVBSatelliteEquipmentControl::isRotorMoving()
+{
+ return m_rotorMoving;
+}
+
+void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)
+{
+ m_rotorMoving=b;
+}