add dynamic m3u playlist
[enigma2.git] / lib / dvb / sec.cpp
index 3ab46c8314155e29e6b0ef8ed270302622edbcde..43d56e306c55cad242edace9d6f39d76281c4c0a 100644 (file)
@@ -93,12 +93,54 @@ eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBR
        setRotorPosNum(1); // stored pos 1
 }
 
+static void checkLinkedParams(int direction, int &linked_ptr, int &ret, const eDVBFrontendParametersSatellite &sat, int csw, int ucsw, int toneburst, bool diseqc, bool rotor)
+{
+       eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_ptr;
+       int oRotorPos = -1;
+       linked_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
+       if (linked_fe->m_inuse)
+       {
+               int ocsw = -1,
+                       oucsw = -1,
+                       oToneburst = -1;
+               linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
+               linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
+               linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
+#if 0
+               eDebug("compare csw %02x == lcsw %02x",
+                       csw, ocsw);
+               if ( diseqc )
+                       eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
+                               ucsw, oucsw, toneburst, oToneburst);
+               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!!");
+                       ret=0;
+               }
+//             else
+//                     eDebug("OK .. can tune this transponder with linked tuner in use :)");
+       }
+       else if (rotor && oRotorPos != -1)
+       {
+               ret -= abs(oRotorPos-sat.orbital_position);
+//             eDebug("decrement rotor pos for linked tuner!!");
+       }
+       linked_fe->m_frontend->getData(direction, linked_ptr);
+}
+
 int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite &sat, iDVBFrontend *fe, int frontend_id )
 {
        int ret=0, satcount=0;
 
        for (int idx=0; idx <= m_lnbidx; ++idx )
        {
+               bool rotor=false;
                eDVBSatelliteLNBParameters &lnb_param = m_lnbs[idx];
                if ( lnb_param.tuner_mask & frontend_id ) // lnb for correct tuner?
                {
@@ -129,7 +171,6 @@ int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite
                                if (!(sat.polarisation & eDVBFrontendParametersSatellite::Polarisation::Vertical))
                                        band |= 2;
 
-                               bool rotor=false;
                                bool diseqc=false;
 
                                if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
@@ -144,88 +185,21 @@ int eDVBSatelliteEquipmentControl::canTune(const eDVBFrontendParametersSatellite
                                        if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )  // ROTOR
                                                rotor = true;
 
-                                       ret = 1000;
+                                       ret=10000;
+                                       if (rotor && curRotorPos != -1)
+                                               ret -= abs(curRotorPos-sat.orbital_position);
                                }
                                else
                                {
                                        csw = band;
-                                       ret = 2000;
+                                       ret = 15000;
                                }
 
-                               while (linked_prev_ptr != -1)  // check for linked tuners..
-                               {
-                                       eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_prev_ptr;
-                                       if (linked_fe->m_inuse)
-                                       {
-                                               int ocsw = -1,
-                                                       oucsw = -1,
-                                                       oToneburst = -1,
-                                                       oRotorPos = -1;
-                                               linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
-                                               linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
-                                               linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
-                                               linked_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
-#if 0
-                                               eDebug("compare csw %02x == lcsw %02x",
-                                                       csw, ocsw);
-                                               if ( diseqc )
-                                                       eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
-                                                               ucsw, oucsw, toneburst, oToneburst);
-                                               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!!");
-                                                       ret=0;
-                                                       break;
-                                               }
-//                                             else
-//                                                     eDebug("OK .. can tune this transponder with linked tuner in use :)");
-                                       }
-                                       linked_fe->m_frontend->getData(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr);
-                               }
+                               while (ret && linked_prev_ptr != -1)  // check for linked tuners..
+                                       checkLinkedParams(eDVBFrontend::LINKED_PREV_PTR, linked_prev_ptr, ret, sat, csw, ucsw, toneburst, diseqc, rotor);
 
-                               if (ret)
-                                       while (linked_next_ptr != -1)  // check for linked tuners..
-                                       {
-                                               eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*) linked_next_ptr;
-                                               if (linked_fe->m_inuse)
-                                               {
-                                                       int ocsw = -1,
-                                                               oucsw = -1,
-                                                               oToneburst = -1,
-                                                               oRotorPos = -1;
-                                                       linked_fe->m_frontend->getData(eDVBFrontend::CSW, ocsw);
-                                                       linked_fe->m_frontend->getData(eDVBFrontend::UCSW, oucsw);
-                                                       linked_fe->m_frontend->getData(eDVBFrontend::TONEBURST, oToneburst);
-                                                       linked_fe->m_frontend->getData(eDVBFrontend::ROTOR_POS, oRotorPos);
-#if 0
-                                                       eDebug("compare csw %02x == lcsw %02x",
-                                                               csw, ocsw);
-                                                       if ( diseqc )
-                                                               eDebug("compare ucsw %02x == lucsw %02x\ncompare toneburst %02x == oToneburst %02x",
-                                                                       ucsw, oucsw, toneburst, oToneburst);
-                                                       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!!");
-                                                               ret=0;
-                                                               break;
-                                                       }
-//                                                     else
-//                                                             eDebug("OK .. can tune this transponder with linked tuner in use :)");
-                                               }
-                                               linked_fe->m_frontend->getData(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr);
-                                       }
+                               while (ret && linked_next_ptr != -1)  // check for linked tuners..
+                                       checkLinkedParams(eDVBFrontend::LINKED_NEXT_PTR, linked_next_ptr, ret, sat, csw, ucsw, toneburst, diseqc, rotor);
 
                                if (ret)
                                        if (satpos_depends_ptr != -1)
@@ -521,9 +495,12 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
 
                                if ( send_mask )
                                {
+                                       eSecCommand::pair compare;
+                                       compare.steps = +3;
+                                       compare.tone = iDVBFrontend::toneOff;
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
                                        sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
-                                       eSecCommand::pair compare;
                                        compare.voltage = iDVBFrontend::voltageOff;
                                        compare.steps = +4;
                                        // the next is a check if voltage is switched off.. then we first set a voltage :)
@@ -562,7 +539,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                if ( send_mask & 2 )
                                                        ++loops;
 
-                                               loops *= 1 << di_param.m_repeats;
+                                               loops <<= di_param.m_repeats;
 
                                                for ( int i = 0; i < loops;)  // fill commands...
                                                {
@@ -628,6 +605,12 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                        eSecCommand::pair compare;
                                        if (!send_mask)
                                        {
+                                               compare.steps = +3;
+                                               compare.tone = iDVBFrontend::toneOff;
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
+
                                                compare.voltage = iDVBFrontend::voltageOff;
                                                compare.steps = +4;
                                                // the next is a check if voltage is switched off.. then we first set a voltage :)
@@ -641,12 +624,12 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
 
                                                // voltage was disabled..so we wait a longer time ..
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) );
-                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +8) );  // no need to send stop rotor cmd and recheck voltage
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) );  // no need to send stop rotor cmd and recheck voltage
                                        }
                                        else
                                        {
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 750) ); // wait 750ms after send switch cmd
-                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +8) );  // no need to send stop rotor cmd and recheck voltage
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +9) );  // no need to send stop rotor cmd and recheck voltage
                                        }
 
                                        eDVBDiseqcCommand diseqc;
@@ -683,19 +666,19 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                eSecCommand::rotor cmd;
                                                eSecCommand::pair compare;
                                                compare.voltage = VOLTAGE(18);
-                                               compare.steps = +2;
+                                               compare.steps = +3;
                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
 // measure idle power values
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );  // wait 200msec after voltage change
                                                sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
-                                               compare.voltage = 1;
+                                               compare.val = 1;
                                                compare.steps = -2;
                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );  // wait 200msec before measure
                                                sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
-                                               compare.voltage = 0;
+                                               compare.val = 0;
                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
 ////////////////////////////
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
@@ -735,7 +718,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                eSecCommand::rotor cmd;
                                                eSecCommand::pair compare;
                                                compare.voltage = VOLTAGE(13);
-                                               compare.steps = +2;
+                                               compare.steps = +3;
                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );  // wait 200msec after voltage change
@@ -750,7 +733,10 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) );  // wait 2 second before set high voltage
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
 
+                                               compare.tone = tone;
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
 
                                                cmd.direction=1;  // check for running rotor
@@ -786,6 +772,8 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
 
+                               compare.tone = tone;
+                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
                        }
@@ -1102,7 +1090,7 @@ struct sat_compare
 
 PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int tu2)
 {
-       PyObject *ret=0;
+       ePyObject ret;
 
        if (tu1 != tu2)
        {
@@ -1207,25 +1195,26 @@ PyObject *eDVBSatelliteEquipmentControl::get_exclusive_satellites(int tu1, int t
 
 RESULT eDVBSatelliteEquipmentControl::setTunerLinked(int tu1, int tu2)
 {
-       if (tu1 == tu2)
-               return -1;
-
-       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)
+       if (tu1 != tu2)
        {
-               p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (int)p2);
-               p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (int)p1);
-               return 0;
+               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)
+               {
+                       p1->m_frontend->setData(eDVBFrontend::LINKED_PREV_PTR, (int)p2);
+                       p2->m_frontend->setData(eDVBFrontend::LINKED_NEXT_PTR, (int)p1);
+                       return 0;
+               }
        }
+       return -1;
 }
 
 RESULT eDVBSatelliteEquipmentControl::setTunerDepends(int tu1, int tu2)