ose no more used frontends and re-open on demand
[enigma2.git] / lib / dvb / sec.cpp
index 48eb971d516e069529def99279f7cc5599f628ee..ab5d6397fcba617081c9467ad1d951fedb6c50b9 100644 (file)
@@ -21,14 +21,14 @@ DEFINE_REF(eDVBSatelliteEquipmentControl);
 eDVBSatelliteEquipmentControl *eDVBSatelliteEquipmentControl::instance;
 
 eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBRegisteredFrontend> &avail_frontends)
-       :m_lnbidx(-1), m_curSat(m_lnbs[0].m_satellites.end()), m_avail_frontends(avail_frontends)
+       :m_lnbidx(-1), m_curSat(m_lnbs[0].m_satellites.end()), m_avail_frontends(avail_frontends), m_rotorMoving(false)
 {
        if (!instance)
                instance = this;
 
        clear();
 
-#if 0
+#if 1
 // ASTRA
        addLNB();
        setLNBTunerMask(3);
@@ -62,7 +62,7 @@ eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBR
        addSatellite(130);
        setVoltageMode(eDVBSatelliteSwitchParameters::HV);
        setToneMode(eDVBSatelliteSwitchParameters::HILO);
-#endif
+#else
 
 // Rotor
        addLNB();
@@ -103,6 +103,7 @@ eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBR
        setVoltageMode(eDVBSatelliteSwitchParameters::HV);
        setToneMode(eDVBSatelliteSwitchParameters::HILO);
        setRotorPosNum(1); // stored pos 1
+#endif
 }
 
 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int frontend_id )
@@ -162,28 +163,18 @@ int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite
 
                                if (linked_to != -1)  // check for linked tuners..
                                {
-                                       bool found=false;
-                                       eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin());
-                                       for (; it != m_avail_frontends.end(); ++it)
-                                               if ( !linked_to )
-                                               {
-                                                       found=true;
-                                                       break;
-                                               }
-                                               else
-                                                       --linked_to;
-
-                                       if (found && it->m_inuse)
+                                       eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
+                                       if (linked_fe->m_inuse)
                                        {
                                                int ocsw = -1,
                                                        oucsw = -1,
                                                        oToneburst = -1,
                                                        oRotorPos = -1;
-                                               it->m_frontend->getData(0, ocsw);
-                                               it->m_frontend->getData(1, oucsw);
-                                               it->m_frontend->getData(2, oToneburst);
-                                               it->m_frontend->getData(6, oRotorPos);
-
+                                               linked_fe->m_frontend->getData(0, ocsw);
+                                               linked_fe->m_frontend->getData(1, oucsw);
+                                               linked_fe->m_frontend->getData(2, oToneburst);
+                                               linked_fe->m_frontend->getData(6, oRotorPos);
+#if 0
                                                eDebug("compare csw %02x == lcsw %02x",
                                                        csw, ocsw);
                                                if ( diseqc )
@@ -192,16 +183,16 @@ int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite
                                                if ( rotor )
                                                        eDebug("compare pos %d == current pos %d",
                                                                sat.orbital_position, oRotorPos);
-
+#endif
                                                if ( (csw != ocsw) ||
                                                        ( diseqc && (ucsw != oucsw || toneburst != oToneburst) ) ||
                                                        ( rotor && oRotorPos != sat.orbital_position ) )
                                                {
-                                                       eDebug("can not tune this transponder with linked tuner in use!!");
+//                                                     eDebug("can not tune this transponder with linked tuner in use!!");
                                                        ret=0;
                                                }
-                                               else
-                                                       eDebug("OK .. can tune this transponder with linked tuner in use :)");
+//                                             else
+//                                                     eDebug("OK .. can tune this transponder with linked tuner in use :)");
                                        }
                                }
                        }
@@ -250,19 +241,10 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
 
                        if (linked_to != -1)
                        {
-                               bool found=false;
-                               eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin());
-                               for (; it != m_avail_frontends.end(); ++it)
-                                       if ( !linked_to )
-                                       {
-                                               found=true;
-                                               break;
-                                       }
-                                       else
-                                               --linked_to;
-                               if (found && it->m_inuse)
+                               eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_to;
+                               if (linked_fe->m_inuse)
                                {
-                                       eDebug("[SEC] frontend is linked with another one and the other is in use.. so we dont do SEC!!");
+                                       eDebug("[SEC] frontend is linked with another and the other one is in use.. so we dont do SEC!!");
                                        linked=true;
                                }
                        }
@@ -460,7 +442,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                RotorCmd=sw_param.m_rotorPosNum;
                                        else  // we must calc gotoxx cmd
                                        {
-                                               eDebug("Entry for %d,%d° not in Rotor Table found... i try gotoXX°", sat.orbital_position / 10, sat.orbital_position % 10 );
+                                               eDebug("Entry for %d,%d? not in Rotor Table found... i try gotoXX?", sat.orbital_position / 10, sat.orbital_position % 10 );
                                                useGotoXX = true;
 
                                                int satDir = sat.orbital_position < 0 ?
@@ -910,28 +892,31 @@ RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
        if (tu1 == tu2)
                return -1;
 
-       eDVBFrontend *p1=NULL, *p2=NULL;
-       int tmp1=tu1, tmp2=tu2;
+       eDVBRegisteredFrontend *p1=NULL, *p2=NULL;
 
-       for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it)
+       int cnt=0;
+       for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_avail_frontends.begin()); it != m_avail_frontends.end(); ++it, ++cnt)
        {
-               if ( !tmp1 )
-                       p1 = it->m_frontend;
-               else
-                       --tmp1;
-               if (!tmp2)
-                       p2 = it->m_frontend;
-               else
-                       --tmp2;
+               if (cnt == tu1)
+                       p1 = *it;
+               else if (cnt == tu2)
+                       p2 = *it;
        }
        if (p1 && p2)
        {
-               p1->setData(7, tu2);
-               p1->setTone(iDVBFrontend::toneOff);
-               p1->setVoltage(iDVBFrontend::voltageOff);
-
-               p2->setData(7, tu1);
+               p1->m_frontend->setData(7, (int)p2);  // this is evil..
+               p2->m_frontend->setData(7, (int)p1);
                return 0;
        }
        return -1;
 }
+
+bool eDVBSatelliteEquipmentControl::isRotorMoving()
+{
+       return m_rotorMoving;
+}
+
+void eDVBSatelliteEquipmentControl::setRotorMoving(bool b)
+{
+       m_rotorMoving=b;
+}