rotor running detection should now work ( yet only with measure input power )
[enigma2.git] / lib / dvb / frontend.cpp
index 2cb1c7d94ae5d52d71d8575f1c0dbb8985547654..795841b830abd1d06806cbd34240945a88cbd24c 100644 (file)
@@ -275,7 +275,7 @@ eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok): m_type(-1), m_fe(fe), m_c
                ok = 0;
                return;
        }
-       eDebug("detected %s frontend", "satellite\0cable\0    terrestrial"+fe_info.type*9);
+       eDebug("detected %s frontend", "satellite\0cable\0    terrestrial"+fe_info.type*10);
        ok = 1;
 
        m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read);
@@ -288,7 +288,13 @@ eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok): m_type(-1), m_fe(fe), m_c
        m_tuneTimer = new eTimer(eApp);
        CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop);
 
-       memset(m_data, 0xFFFF, sizeof(m_data));
+       int entries = sizeof(m_data) / sizeof(int);
+       for (int i=0; i<entries; ++i)
+               m_data[i] = -1;
+
+       m_data[7] = !m_fe;
+
+       eDebug("m_data[7] = %d %d", m_data[7], m_fe);
 
        return;
 }
@@ -331,7 +337,7 @@ void eDVBFrontend::feEvent(int w)
 #if HAVE_DVB_API_VERSION < 3
                if (event.type == FE_COMPLETION_EV)
 #else
-               eDebug("fe event: status %x, inversion %s", event.status, (event.parameters.inversion == INVERSION_ON) ? "on" : "off");
+               eDebug("(%d)fe event: status %x, inversion %s", m_fe, event.status, (event.parameters.inversion == INVERSION_ON) ? "on" : "off");
                if (event.status & FE_HAS_LOCK)
 #endif
                {
@@ -501,6 +507,7 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                if (!m_timeoutCount)
                                {
                                        eDebug("[SEC] rotor timout");
+                                       m_sec->setRotorMoving(false);
                                        setSecSequencePos(m_sec_sequence.current()->steps);
                                }
                                else
@@ -551,6 +558,7 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                        eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
                                        if ( cmd.okcount > 6 )
                                        {
+                                               m_sec->setRotorMoving(cmd.direction);
                                                eDebug("[SEC] rotor is %s", txt);
                                                if (setSecSequencePos(cmd.steps))
                                                        break;
@@ -609,6 +617,8 @@ RESULT eDVBFrontend::getFrontendType(int &t)
 
 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
 {
+       eDebug("(%d)tune", m_fe);
+
        if (m_type == -1)
                return -ENODEV;
 
@@ -633,7 +643,7 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                        return -ENOENT;
                }
                
-               res = m_sec->prepare(*this, parm, feparm);
+               res = m_sec->prepare(*this, parm, feparm, 1 << m_fe);
                if (res)
                        return res;
 #if HAVE_DVB_API_VERSION < 3
@@ -645,10 +655,115 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
        }
        case feCable:
        {
+#if HAVE_DVB_API_VERSION >= 3
                eDVBFrontendParametersCable feparm;
                if (where.getDVBC(feparm))
                        return -EINVAL;
-               eFatal("cable tuning nyi");
+#if HAVE_DVB_API_VERSION < 3
+               parm.Frequency = feparm.frequency * 1000;
+               parm.u.qam.SymbolRate = feparm.symbol_rate;
+#else
+               parm.frequency = feparm.frequency * 1000;
+               parm.u.qam.symbol_rate = feparm.symbol_rate;
+#endif
+               fe_modulation_t mod;
+               switch (feparm.modulation)
+               {
+               case eDVBFrontendParametersCable::Modulation::QAM16:
+                       mod = QAM_16;
+                       break;
+               case eDVBFrontendParametersCable::Modulation::QAM32:
+                       mod = QAM_32;
+                       break;
+               case eDVBFrontendParametersCable::Modulation::QAM64:
+                       mod = QAM_64;
+                       break;
+               case eDVBFrontendParametersCable::Modulation::QAM128:
+                       mod = QAM_128;
+                       break;
+               case eDVBFrontendParametersCable::Modulation::QAM256:
+                       mod = QAM_256;
+                       break;                  
+               case eDVBFrontendParametersCable::Modulation::Auto:
+                       mod = QAM_AUTO;
+                       break;                  
+               }
+#if HAVE_DVB_API_VERSION < 3
+               parm.u.qam.QAM = mod;
+#else
+               parm.u.qam.modulation = mod;
+#endif
+               switch (feparm.inversion)
+               {               
+               case eDVBFrontendParametersCable::Inversion::On:
+                       #if HAVE_DVB_API_VERSION < 3
+                       parm.Inversion =
+                       #else
+                       parm.inversion =
+                       #endif
+                               INVERSION_ON;
+                       break;
+               case eDVBFrontendParametersCable::Inversion::Off:
+                       #if HAVE_DVB_API_VERSION < 3
+                       parm.Inversion =
+                       #else
+                       parm.inversion =
+                       #endif
+                               INVERSION_OFF;
+                       break;
+               case eDVBFrontendParametersCable::Inversion::Unknown:
+                       #if HAVE_DVB_API_VERSION < 3
+                       parm.Inversion =
+                       #else
+                       parm.inversion =
+                       #endif
+                               INVERSION_AUTO;
+                       break;
+               }
+               
+               fe_code_rate_t fec_inner;
+               switch (feparm.fec_inner)
+               {               
+               case eDVBFrontendParametersCable::FEC::fNone:
+                       fec_inner = FEC_NONE;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f1_2:
+                       fec_inner = FEC_1_2;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f2_3:
+                       fec_inner = FEC_2_3;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f3_4:
+                       fec_inner = FEC_3_4;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f4_5:
+                       fec_inner = FEC_4_5;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f5_6:
+                       fec_inner = FEC_5_6;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f6_7:
+                       fec_inner = FEC_6_7;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f7_8:
+                       fec_inner = FEC_7_8;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f8_9:
+                       fec_inner = FEC_8_9;
+                       break;
+               case eDVBFrontendParametersCable::FEC::fAuto:
+                       fec_inner = FEC_AUTO;
+                       break;
+               }
+#if HAVE_DVB_API_VERSION < 3
+               parm.u.qam.FEC_inner = fec_inner;
+#else
+               parm.u.qam.fec_inner = fec_inner;
+#endif
+#else
+               eFatal("Old API not fully supported");
+#endif // old api
+               break;
        }
        case feTerrestrial:
        {
@@ -890,7 +1005,7 @@ RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list)
 
 RESULT eDVBFrontend::getData(int num, int &data)
 {
-       if ( num < 7 )
+       if ( num < (int)(sizeof(m_data)/sizeof(int)) )
        {
                data = m_data[num];
                return 0;
@@ -900,8 +1015,10 @@ RESULT eDVBFrontend::getData(int num, int &data)
 
 RESULT eDVBFrontend::setData(int num, int val)
 {
-       if ( num < 7 )
+       if ( num < (int)(sizeof(m_data)/sizeof(int)) )
        {
+               if ( num == 0 )
+                       eDebug("(%d) set csw %02x", m_fe, val);
                m_data[num] = val;
                return 0;
        }
@@ -910,14 +1027,16 @@ RESULT eDVBFrontend::setData(int num, int val)
 
 int eDVBFrontend::isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)
 {
-       if (m_type != eDVBFrontend::feSatellite)
-               return 1;
-
-       ASSERT(m_sec);
-
-       eDVBFrontendParametersSatellite sat_parm;
-
-       ASSERT(!feparm->getDVBS(sat_parm));
+       int type;
+       if (feparm->getSystem(type) || type != m_type)
+               return 0;
 
-       return m_sec->canTune(sat_parm, this, m_fe ? m_fe << 1 : 1);
+       if (m_type == eDVBFrontend::feSatellite)
+       {
+               ASSERT(m_sec);
+               eDVBFrontendParametersSatellite sat_parm;
+               ASSERT(!feparm->getDVBS(sat_parm));
+               return m_sec->canTune(sat_parm, this, 1 << m_fe);
+       }
+       return 1;
 }