add possibility to disable debug output
[enigma2.git] / lib / dvb / frontend.cpp
index 25eb97662357aab42c8ecbdf4021825e69245a69..af627e26a9683717cfdcdf7d2b45e24e2258af1e 100644 (file)
@@ -125,6 +125,7 @@ void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescripto
        if ( fec != FEC::fNone && fec > FEC::f9_10 )
                fec = FEC::fAuto;
        inversion = Inversion::Unknown;
        if ( fec != FEC::fNone && fec > FEC::f9_10 )
                fec = FEC::fAuto;
        inversion = Inversion::Unknown;
+       pilot = Pilot::Unknown;
        orbital_position  = ((descriptor.getOrbitalPosition() >> 12) & 0xF) * 1000;
        orbital_position += ((descriptor.getOrbitalPosition() >> 8) & 0xF) * 100;
        orbital_position += ((descriptor.getOrbitalPosition() >> 4) & 0xF) * 10;
        orbital_position  = ((descriptor.getOrbitalPosition() >> 12) & 0xF) * 1000;
        orbital_position += ((descriptor.getOrbitalPosition() >> 8) & 0xF) * 100;
        orbital_position += ((descriptor.getOrbitalPosition() >> 4) & 0xF) * 10;
@@ -138,16 +139,16 @@ void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescripto
                eDebug("satellite_delivery_descriptor non valid modulation type.. force QPSK");
                modulation=QPSK;
        }
                eDebug("satellite_delivery_descriptor non valid modulation type.. force QPSK");
                modulation=QPSK;
        }
-       roll_off = descriptor.getRollOff();
+       rolloff = descriptor.getRollOff();
        if (system == System::DVB_S2)
        {
        if (system == System::DVB_S2)
        {
-               eDebug("SAT DVB-S2 freq %d, %s, pos %d, sr %d, fec %d, modulation %d, roll_off %d",
+               eDebug("SAT DVB-S2 freq %d, %s, pos %d, sr %d, fec %d, modulation %d, rolloff %d",
                        frequency,
                        polarisation ? "hor" : "vert",
                        orbital_position,
                        symbol_rate, fec,
                        modulation,
                        frequency,
                        polarisation ? "hor" : "vert",
                        orbital_position,
                        symbol_rate, fec,
                        modulation,
-                       roll_off);
+                       rolloff);
        }
        else
        {
        }
        else
        {
@@ -203,7 +204,8 @@ void eDVBFrontendParametersTerrestrial::set(const TerrestrialDeliverySystemDescr
                guard_interval, hierarchy, modulation);
 }
 
                guard_interval, hierarchy, modulation);
 }
 
-eDVBFrontendParameters::eDVBFrontendParameters(): m_type(-1)
+eDVBFrontendParameters::eDVBFrontendParameters()
+       :m_type(-1), m_flags(0)
 {
 }
 
 {
 }
 
@@ -290,6 +292,8 @@ RESULT eDVBFrontendParameters::calculateDifference(const iDVBFrontendParameters
                        diff = 1<<28;
                else if (exact && sat.fec != osat.fec && sat.fec != eDVBFrontendParametersSatellite::FEC::fAuto && osat.fec != eDVBFrontendParametersSatellite::FEC::fAuto)
                        diff = 1<<27;
                        diff = 1<<28;
                else if (exact && sat.fec != osat.fec && sat.fec != eDVBFrontendParametersSatellite::FEC::fAuto && osat.fec != eDVBFrontendParametersSatellite::FEC::fAuto)
                        diff = 1<<27;
+               else if (exact && sat.modulation != osat.modulation && sat.modulation != eDVBFrontendParametersSatellite::Modulation::Auto && osat.modulation != eDVBFrontendParametersSatellite::Modulation::Auto)
+                       diff = 1<<27;
                else
                {
                        diff = abs(sat.frequency - osat.frequency);
                else
                {
                        diff = abs(sat.frequency - osat.frequency);
@@ -369,9 +373,42 @@ RESULT eDVBFrontendParameters::getHash(unsigned long &hash) const
        }
        case iDVBFrontend::feCable:
                hash = 0xFFFF0000;
        }
        case iDVBFrontend::feCable:
                hash = 0xFFFF0000;
+               hash |= (cable.frequency/1000)&0xFFFF;
                return 0;
        case iDVBFrontend::feTerrestrial:
                hash = 0xEEEE0000;
                return 0;
        case iDVBFrontend::feTerrestrial:
                hash = 0xEEEE0000;
+               hash |= (terrestrial.frequency/1000)&0xFFFF;
+               return 0;
+       default:
+               return -1;
+       }
+}
+
+RESULT eDVBFrontendParameters::calcLockTimeout(unsigned int &timeout) const
+{
+       switch (m_type)
+       {
+       case iDVBFrontend::feSatellite:
+       {
+                       /* high symbol rate transponders tune faster, due to 
+                               requiring less zigzag and giving more symbols faster. 
+
+                               5s are definitely not enough on really low SR when
+                               zigzag has to find the exact frequency first.
+                       */
+               if (sat.symbol_rate > 20000000)
+                       timeout = 5000;
+               else if (sat.symbol_rate > 10000000)
+                       timeout = 10000;
+               else
+                       timeout = 20000;
+               return 0;
+       }
+       case iDVBFrontend::feCable:
+               timeout = 5000;
+               return 0;
+       case iDVBFrontend::feTerrestrial:
+               timeout = 5000;
                return 0;
        default:
                return -1;
                return 0;
        default:
                return -1;
@@ -380,8 +417,12 @@ RESULT eDVBFrontendParameters::getHash(unsigned long &hash) const
 
 DEFINE_REF(eDVBFrontend);
 
 
 DEFINE_REF(eDVBFrontend);
 
+int eDVBFrontend::PriorityOrder=0;
+
 eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok)
 eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok)
-       :m_type(-1), m_fe(fe), m_fd(-1), m_sn(0), m_timeout(0), m_tuneTimer(0)
+       :m_enabled(false), m_type(-1), m_dvbid(fe), m_slotid(fe)
+       ,m_fd(-1), m_need_rotor_workaround(false), m_can_handle_dvbs2(false)
+       ,m_sn(0), m_timeout(0), m_tuneTimer(0)
 #if HAVE_DVB_API_VERSION < 3
        ,m_secfd(-1)
 #endif
 #if HAVE_DVB_API_VERSION < 3
        ,m_secfd(-1)
 #endif
@@ -412,41 +453,26 @@ int eDVBFrontend::openFrontend()
        if (m_sn)
                return -1;  // already opened
 
        if (m_sn)
                return -1;  // already opened
 
-       m_state=0;
+       m_state=stateIdle;
        m_tuning=0;
 
 #if HAVE_DVB_API_VERSION < 3
        m_tuning=0;
 
 #if HAVE_DVB_API_VERSION < 3
-       if (m_secfd < 0)
-       {
-               m_secfd = ::open(m_sec_filename, O_RDWR);
-               if (m_secfd < 0)
-               {
-                       eWarning("failed! (%s) %m", m_sec_filename);
-                       return -1;
-               }
-       }
-       else
-               eWarning("sec %d already opened", m_fe);
        FrontendInfo fe_info;
 #else
        dvb_frontend_info fe_info;
 #endif
        FrontendInfo fe_info;
 #else
        dvb_frontend_info fe_info;
 #endif
-       eDebug("opening frontend %d", m_fe);
+       eDebug("opening frontend %d", m_dvbid);
        if (m_fd < 0)
        {
                m_fd = ::open(m_filename, O_RDWR|O_NONBLOCK);
                if (m_fd < 0)
                {
                        eWarning("failed! (%s) %m", m_filename);
        if (m_fd < 0)
        {
                m_fd = ::open(m_filename, O_RDWR|O_NONBLOCK);
                if (m_fd < 0)
                {
                        eWarning("failed! (%s) %m", m_filename);
-#if HAVE_DVB_API_VERSION < 3
-                       ::close(m_secfd);
-                       m_secfd=-1;
-#endif
                        return -1;
                }
        }
        else
                        return -1;
                }
        }
        else
-               eWarning("frontend %d already opened", m_fe);
+               eWarning("frontend %d already opened", m_dvbid);
        if (m_type == -1)
        {
                if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
        if (m_type == -1)
        {
                if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
@@ -454,10 +480,6 @@ int eDVBFrontend::openFrontend()
                        eWarning("ioctl FE_GET_INFO failed");
                        ::close(m_fd);
                        m_fd = -1;
                        eWarning("ioctl FE_GET_INFO failed");
                        ::close(m_fd);
                        m_fd = -1;
-#if HAVE_DVB_API_VERSION < 3
-                       ::close(m_secfd);
-                       m_secfd=-1;
-#endif
                        return -1;
                }
 
                        return -1;
                }
 
@@ -476,40 +498,59 @@ int eDVBFrontend::openFrontend()
                        eWarning("unknown frontend type.");
                        ::close(m_fd);
                        m_fd = -1;
                        eWarning("unknown frontend type.");
                        ::close(m_fd);
                        m_fd = -1;
-#if HAVE_DVB_API_VERSION < 3
-                       ::close(m_secfd);
-                       m_secfd=-1;
-#endif
                        return -1;
                }
                eDebug("detected %s frontend", "satellite\0cable\0    terrestrial"+fe_info.type*10);
        }
 
                        return -1;
                }
                eDebug("detected %s frontend", "satellite\0cable\0    terrestrial"+fe_info.type*10);
        }
 
+#if HAVE_DVB_API_VERSION < 3
+       if (m_type == iDVBFrontend::feSatellite)
+       {
+                       if (m_secfd < 0)
+                       {
+                               m_secfd = ::open(m_sec_filename, O_RDWR);
+                               if (m_secfd < 0)
+                               {
+                                       eWarning("failed! (%s) %m", m_sec_filename);
+                                       ::close(m_fd);
+                                       m_fd=-1;
+                                       return -1;
+                               }
+                       }
+                       else
+                               eWarning("sec %d already opened", m_dvbid);
+       }
+#endif
+
        setTone(iDVBFrontend::toneOff);
        setVoltage(iDVBFrontend::voltageOff);
 
        setTone(iDVBFrontend::toneOff);
        setVoltage(iDVBFrontend::voltageOff);
 
-       m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read);
+       m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read, false);
        CONNECT(m_sn->activated, eDVBFrontend::feEvent);
 
        return 0;
 }
 
        CONNECT(m_sn->activated, eDVBFrontend::feEvent);
 
        return 0;
 }
 
-int eDVBFrontend::closeFrontend()
+int eDVBFrontend::closeFrontend(bool force)
 {
 {
-       eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)m_data[LINKED_NEXT_PTR];
-       while (linked_fe != (eDVBRegisteredFrontend*)-1)
+       if (!force && m_data[CUR_VOLTAGE] != -1 && m_data[CUR_VOLTAGE] != iDVBFrontend::voltageOff)
        {
        {
-               if (linked_fe->m_inuse)
+               long tmp = m_data[LINKED_NEXT_PTR];
+               while (tmp != -1)
                {
                {
-                       eDebug("dont close frontend %d until the linked frontend %d is still in use",
-                               m_fe, linked_fe->m_frontend->getID());
-                       return -1;
+                       eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)tmp;
+                       if (linked_fe->m_inuse)
+                       {
+                               eDebug("dont close frontend %d until the linked frontend %d in slot %d is still in use",
+                                       m_dvbid, linked_fe->m_frontend->getDVBID(), linked_fe->m_frontend->getSlotID());
+                               return -1;
+                       }
+                       linked_fe->m_frontend->getData(LINKED_NEXT_PTR, tmp);
                }
                }
-               linked_fe->m_frontend->getData(LINKED_NEXT_PTR, (int&)linked_fe);
        }
        if (m_fd >= 0)
        {
        }
        if (m_fd >= 0)
        {
-               eDebug("close frontend %d", m_fe);
+               eDebug("close frontend %d", m_dvbid);
                m_tuneTimer->stop();
                setTone(iDVBFrontend::toneOff);
                setVoltage(iDVBFrontend::voltageOff);
                m_tuneTimer->stop();
                setTone(iDVBFrontend::toneOff);
                setVoltage(iDVBFrontend::voltageOff);
@@ -518,8 +559,7 @@ int eDVBFrontend::closeFrontend()
                if (!::close(m_fd))
                        m_fd=-1;
                else
                if (!::close(m_fd))
                        m_fd=-1;
                else
-                       eWarning("couldnt close frontend %d", m_fe);
-               m_data[CSW] = m_data[UCSW] = m_data[TONEBURST] = -1;
+                       eWarning("couldnt close frontend %d", m_dvbid);
        }
 #if HAVE_DVB_API_VERSION < 3
        if (m_secfd >= 0)
        }
 #if HAVE_DVB_API_VERSION < 3
        if (m_secfd >= 0)
@@ -527,17 +567,19 @@ int eDVBFrontend::closeFrontend()
                if (!::close(m_secfd))
                        m_secfd=-1;
                else
                if (!::close(m_secfd))
                        m_secfd=-1;
                else
-                       eWarning("couldnt close sec %d", m_fe);
+                       eWarning("couldnt close sec %d", m_dvbid);
        }
 #endif
        delete m_sn;
        m_sn=0;
        }
 #endif
        delete m_sn;
        m_sn=0;
+       m_state = stateClosed;
 
        return 0;
 }
 
 eDVBFrontend::~eDVBFrontend()
 {
 
        return 0;
 }
 
 eDVBFrontend::~eDVBFrontend()
 {
+       m_data[LINKED_PREV_PTR] = m_data[LINKED_NEXT_PTR] = -1;
        closeFrontend();
        delete m_timeout;
        delete m_tuneTimer;
        closeFrontend();
        delete m_timeout;
        delete m_tuneTimer;
@@ -545,6 +587,14 @@ eDVBFrontend::~eDVBFrontend()
 
 void eDVBFrontend::feEvent(int w)
 {
 
 void eDVBFrontend::feEvent(int w)
 {
+       eDVBFrontend *sec_fe = this;
+       long tmp = m_data[LINKED_PREV_PTR];
+       while (tmp != -1)
+       {
+               eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)tmp;
+               sec_fe = linked_fe->m_frontend;
+               sec_fe->getData(LINKED_NEXT_PTR, tmp);
+       }
        while (1)
        {
 #if HAVE_DVB_API_VERSION < 3
        while (1)
        {
 #if HAVE_DVB_API_VERSION < 3
@@ -571,7 +621,7 @@ void eDVBFrontend::feEvent(int w)
 #if HAVE_DVB_API_VERSION < 3
                if (event.type == FE_COMPLETION_EV)
 #else
 #if HAVE_DVB_API_VERSION < 3
                if (event.type == FE_COMPLETION_EV)
 #else
-               eDebug("(%d)fe event: status %x, inversion %s", m_fe, event.status, (event.parameters.inversion == INVERSION_ON) ? "on" : "off");
+               eDebug("(%d)fe event: status %x, inversion %s", m_dvbid, event.status, (event.parameters.inversion == INVERSION_ON) ? "on" : "off");
                if (event.status & FE_HAS_LOCK)
 #endif
                {
                if (event.status & FE_HAS_LOCK)
 #endif
                {
@@ -584,7 +634,7 @@ void eDVBFrontend::feEvent(int w)
                        {
                                eDebug("stateLostLock");
                                state = stateLostLock;
                        {
                                eDebug("stateLostLock");
                                state = stateLostLock;
-                               m_data[CSW] = m_data[UCSW] = m_data[TONEBURST] = -1; // reset diseqc
+                               sec_fe->m_data[CSW] = sec_fe->m_data[UCSW] = sec_fe->m_data[TONEBURST] = -1; // reset diseqc
                        }
                }
                if (m_state != state)
                        }
                }
                if (m_state != state)
@@ -605,6 +655,8 @@ void eDVBFrontend::timeout()
        }
 }
 
        }
 }
 
+#define INRANGE(X,Y,Z) (((X<=Y) && (Y<=Z))||((Z<=Y) && (Y<=X)) ? 1 : 0)
+
 int eDVBFrontend::readFrontendData(int type)
 {
        switch(type)
 int eDVBFrontend::readFrontendData(int type)
 {
        switch(type)
@@ -616,14 +668,110 @@ int eDVBFrontend::readFrontendData(int type)
                                eDebug("FE_READ_BER failed (%m)");
                        return ber;
                }
                                eDebug("FE_READ_BER failed (%m)");
                        return ber;
                }
-               case signalPower:
+               case signalQuality:
                {
                        uint16_t snr=0;
                        if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
                                eDebug("FE_READ_SNR failed (%m)");
                        return snr;
                }
                {
                        uint16_t snr=0;
                        if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
                                eDebug("FE_READ_SNR failed (%m)");
                        return snr;
                }
-               case signalQuality:
+               case signalQualitydB: /* this will move into the driver */
+               {
+                       uint16_t snr=0;
+                       if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
+                               eDebug("FE_READ_SNR failed (%m)");
+                       if (!strcmp(m_description, "BCM4501 (internal)"))
+                       {
+                               unsigned int SDS_SNRE = snr << 16;
+
+                               static float SNR_COEFF[6] = {
+                                       100.0 / 4194304.0,
+                                       -7136.0 / 4194304.0,
+                                       197418.0 / 4194304.0,
+                                       -2602183.0 / 4194304.0,
+                                       20377212.0 / 4194304.0,
+                                       -37791203.0 / 4194304.0,
+                               };
+                       
+                               float fval1, fval2, snr_in_db;
+                               int i;
+                               fval1 = 12.44714 - (2.0 * log10(SDS_SNRE / 256.0));
+                               fval2 = pow(10.0, fval1)-1;
+                               fval1 = 10.0 * log10(fval2);
+                       
+                               if (fval1 < 10.0)
+                               {
+                                       fval2 = SNR_COEFF[0];
+                                       for (i=0; i<6; ++i)
+                                       {
+                                               fval2 *= fval1;
+                                               fval2 += SNR_COEFF[i];
+                                       }
+                                       fval1 = fval2;
+                               }
+                               snr_in_db = fval1;
+                       
+                               return (int)(snr_in_db * 100.0);
+                       }
+                       else if (strstr(m_description, "Alps BSBE1 C01A") ||
+                               !strcmp(m_description, "Alps -S(STV0288)"))
+                       {
+                               if (snr == 0)
+                                       return 0;
+                               else if (snr == 0xFFFF) // i think this should not happen
+                                       return 100*100;
+                               else
+                               {
+                                       enum { REALVAL, REGVAL };
+                                       const long CN_lookup[31][2] = {
+                                               {20,8900}, {25,8680}, {30,8420}, {35,8217}, {40,7897},
+                                               {50,7333}, {60,6747}, {70,6162}, {80,5580}, {90,5029},
+                                               {100,4529}, {110,4080}, {120,3685}, {130,3316}, {140,2982},
+                                               {150,2688}, {160,2418}, {170,2188}, {180,1982}, {190,1802},
+                                               {200,1663}, {210,1520}, {220,1400}, {230,1295}, {240,1201},
+                                               {250,1123}, {260,1058}, {270,1004}, {280,957}, {290,920},
+                                               {300,890}
+                                       };
+                                       int add=strchr(m_description, '.') ? 0xA250 : 0xA100;
+                                       long regval = 0xFFFF - ((snr / 3) + add), // revert some dvb api calulations to get the real register value
+                                               Imin=0,
+                                               Imax=30,
+                                               i;
+                                       if(INRANGE(CN_lookup[Imin][REGVAL],regval,CN_lookup[Imax][REGVAL]))
+                                       {
+                                               long val;
+                                               while((Imax-Imin)>1)
+                                               {
+                                                       i=(Imax+Imin)/2;
+                                                       if(INRANGE(CN_lookup[Imin][REGVAL],regval,CN_lookup[i][REGVAL]))
+                                                               Imax = i;
+                                                       else
+                                                               Imin = i;
+                                               }
+                                               return (((regval - CN_lookup[Imin][REGVAL])
+                                                               * (CN_lookup[Imax][REALVAL] - CN_lookup[Imin][REALVAL])
+                                                               / (CN_lookup[Imax][REGVAL] - CN_lookup[Imin][REGVAL]))
+                                                               + CN_lookup[Imin][REALVAL]) * 10;
+                                       }
+                                       return 100;
+                               }
+                               return 0;
+                       }
+                       else if (!strcmp(m_description, "Alps BSBE1 702A") ||  // some frontends with STV0299
+                               !strcmp(m_description, "Alps -S") ||
+                               !strcmp(m_description, "Philips -S") ||
+                               !strcmp(m_description, "LG -S") )
+                       {
+                               float snr_in_db=(snr-39075)/1764.7;
+                               return (int)(snr_in_db * 100.0);
+                       } else if (!strcmp(m_description, "Alps BSBE2"))
+                       {
+                               return (int)((snr >> 7) * 10.0);
+                       } /* else
+                               eDebug("no SNR dB calculation for frontendtype %s yet", m_description); */
+                       return 0x12345678;
+               }
+               case signalPower:
                {
                        uint16_t strength=0;
                        if (ioctl(m_fd, FE_READ_SIGNAL_STRENGTH, &strength) < 0 && errno != ERANGE)
                {
                        uint16_t strength=0;
                        if (ioctl(m_fd, FE_READ_SIGNAL_STRENGTH, &strength) < 0 && errno != ERANGE)
@@ -653,14 +801,14 @@ int eDVBFrontend::readFrontendData(int type)
                        return !!(status&FE_HAS_SYNC);
                }
                case frontendNumber:
                        return !!(status&FE_HAS_SYNC);
                }
                case frontendNumber:
-                       return m_fe;
+                       return m_slotid;
        }
        return 0;
 }
 
        }
        return 0;
 }
 
-void PutToDict(PyObject *dict, const char*key, long value)
+void PutToDict(ePyObject &dict, const char*key, long value)
 {
 {
-       PyObject *item = PyInt_FromLong(value);
+       ePyObject item = PyInt_FromLong(value);
        if (item)
        {
                if (PyDict_SetItemString(dict, key, item))
        if (item)
        {
                if (PyDict_SetItemString(dict, key, item))
@@ -671,9 +819,21 @@ void PutToDict(PyObject *dict, const char*key, long value)
                eDebug("could not create PyObject for %s", key);
 }
 
                eDebug("could not create PyObject for %s", key);
 }
 
-void PutToDict(PyObject *dict, const char*key, const char *value)
+void PutToDict(ePyObject &dict, const char*key, ePyObject item)
+{
+       if (item)
+       {
+               if (PyDict_SetItemString(dict, key, item))
+                       eDebug("put %s to dict failed", key);
+               Py_DECREF(item);
+       }
+       else
+               eDebug("invalid PyObject for %s", key);
+}
+
+void PutToDict(ePyObject &dict, const char*key, const char *value)
 {
 {
-       PyObject *item = PyString_FromString(value);
+       ePyObject item = PyString_FromString(value);
        if (item)
        {
                if (PyDict_SetItemString(dict, key, item))
        if (item)
        {
                if (PyDict_SetItemString(dict, key, item))
@@ -684,12 +844,10 @@ void PutToDict(PyObject *dict, const char*key, const char *value)
                eDebug("could not create PyObject for %s", key);
 }
 
                eDebug("could not create PyObject for %s", key);
 }
 
-void fillDictWithSatelliteData(PyObject *dict, const FRONTENDPARAMETERS &parm, eDVBFrontend *fe)
+void fillDictWithSatelliteData(ePyObject dict, const FRONTENDPARAMETERS &parm, eDVBFrontend *fe)
 {
 {
-       int freq_offset=0;
-       int csw=0;
+       long freq_offset=0;
        const char *tmp=0;
        const char *tmp=0;
-       fe->getData(eDVBFrontend::CSW, csw);
        fe->getData(eDVBFrontend::FREQ_OFFSET, freq_offset);
        int frequency = parm_frequency + freq_offset;
        PutToDict(dict, "frequency", frequency);
        fe->getData(eDVBFrontend::FREQ_OFFSET, freq_offset);
        int frequency = parm_frequency + freq_offset;
        PutToDict(dict, "frequency", frequency);
@@ -756,22 +914,61 @@ void fillDictWithSatelliteData(PyObject *dict, const FRONTENDPARAMETERS &parm, e
                break;
 #endif
        }
                break;
 #endif
        }
+       PutToDict(dict, "fec_inner", tmp);
 #if HAVE_DVB_API_VERSION >=3
        PutToDict(dict, "modulation",
                parm_u_qpsk_fec_inner > FEC_S2_QPSK_9_10 ? "8PSK": "QPSK" );
 #if HAVE_DVB_API_VERSION >=3
        PutToDict(dict, "modulation",
                parm_u_qpsk_fec_inner > FEC_S2_QPSK_9_10 ? "8PSK": "QPSK" );
+       if (parm_u_qpsk_fec_inner > FEC_AUTO)
+       {
+               switch(parm_inversion & 0xc)
+               {
+               default: // unknown rolloff
+               case 0: // 0.35
+                       tmp = "ROLLOFF_0_35";
+                       break;
+               case 4: // 0.25
+                       tmp = "ROLLOFF_0_25";
+                       break;
+               case 8: // 0.20
+                       tmp = "ROLLOFF_0_20";
+                       break;
+               }
+               PutToDict(dict, "rolloff", tmp);
+               if (parm_u_qpsk_fec_inner > FEC_S2_QPSK_9_10)
+               {
+                       switch(parm_inversion & 0x30)
+                       {
+                       case 0: // pilot off
+                               tmp = "PILOT_OFF";
+                               break;
+                       case 0x10: // pilot on
+                               tmp = "PILOT_ON";
+                               break;
+                       case 0x20: // pilot auto
+                               tmp = "PILOT_AUTO";
+                               break;
+                       }
+                       PutToDict(dict, "pilot", tmp);
+               }
+               tmp = "DVB-S2";
+       }
+       else
+               tmp = "DVB-S";
 #else
        PutToDict(dict, "modulation", "QPSK" );
 #else
        PutToDict(dict, "modulation", "QPSK" );
+       tmp = "DVB-S";
 #endif
 #endif
-       PutToDict(dict, "fec_inner", tmp);
-       tmp = parm_u_qpsk_fec_inner > FEC_AUTO ?
-               "DVB-S2" : "DVB-S";
        PutToDict(dict, "system", tmp);
 }
 
        PutToDict(dict, "system", tmp);
 }
 
-void fillDictWithCableData(PyObject *dict, const FRONTENDPARAMETERS &parm)
+void fillDictWithCableData(ePyObject dict, const FRONTENDPARAMETERS &parm)
 {
        const char *tmp=0;
 {
        const char *tmp=0;
+#if HAVE_DVB_API_VERSION < 3
+       PutToDict(dict, "frequency", parm_frequency);
+#else
        PutToDict(dict, "frequency", parm_frequency/1000);
        PutToDict(dict, "frequency", parm_frequency/1000);
+#endif
        PutToDict(dict, "symbol_rate", parm_u_qam_symbol_rate);
        switch(parm_u_qam_fec_inner)
        {
        PutToDict(dict, "symbol_rate", parm_u_qam_symbol_rate);
        switch(parm_u_qam_fec_inner)
        {
@@ -829,7 +1026,7 @@ void fillDictWithCableData(PyObject *dict, const FRONTENDPARAMETERS &parm)
        PutToDict(dict, "modulation", tmp);
 }
 
        PutToDict(dict, "modulation", tmp);
 }
 
-void fillDictWithTerrestrialData(PyObject *dict, const FRONTENDPARAMETERS &parm)
+void fillDictWithTerrestrialData(ePyObject dict, const FRONTENDPARAMETERS &parm)
 {
        const char *tmp=0;
        PutToDict(dict, "frequency", parm_frequency);
 {
        const char *tmp=0;
        PutToDict(dict, "frequency", parm_frequency);
@@ -969,17 +1166,106 @@ void fillDictWithTerrestrialData(PyObject *dict, const FRONTENDPARAMETERS &parm)
        PutToDict(dict, "hierarchy_information", tmp);
 }
 
        PutToDict(dict, "hierarchy_information", tmp);
 }
 
-PyObject *eDVBFrontend::readTransponderData(bool original)
+void eDVBFrontend::getFrontendStatus(ePyObject dest)
 {
 {
-       PyObject *ret=PyDict_New();
+       if (dest && PyDict_Check(dest))
+       {
+               const char *tmp = "UNKNOWN";
+               switch(m_state)
+               {
+                       case stateIdle:
+                               tmp="IDLE";
+                               break;
+                       case stateTuning:
+                               tmp="TUNING";
+                               break;
+                       case stateFailed:
+                               tmp="FAILED";
+                               break;
+                       case stateLock:
+                               tmp="LOCKED";
+                               break;
+                       case stateLostLock:
+                               tmp="LOSTLOCK";
+                               break;
+                       default:
+                               break;
+               }
+               PutToDict(dest, "tuner_state", tmp);
+               PutToDict(dest, "tuner_locked", readFrontendData(locked));
+               PutToDict(dest, "tuner_synced", readFrontendData(synced));
+               PutToDict(dest, "tuner_bit_error_rate", readFrontendData(bitErrorRate));
+               PutToDict(dest, "tuner_signal_quality", readFrontendData(signalQuality));
+               int sigQualitydB = readFrontendData(signalQualitydB);
+               if (sigQualitydB == 0x12345678) // not support yet
+               {
+                       ePyObject obj=Py_None;
+                       Py_INCREF(obj);
+                       PutToDict(dest, "tuner_signal_quality_db", obj);
+               }
+               else
+                       PutToDict(dest, "tuner_signal_quality_db", sigQualitydB);
+               PutToDict(dest, "tuner_signal_power", readFrontendData(signalPower));
+       }
+}
 
 
-       if (ret)
+void eDVBFrontend::getTransponderData(ePyObject dest, bool original)
+{
+       if (m_fd != -1 && dest && PyDict_Check(dest))
        {
        {
-               bool read=m_fd != -1;
-               const char *tmp=0;
+               switch(m_type)
+               {
+                       case feSatellite:
+                       case feCable:
+                       case feTerrestrial:
+                       {
+                               FRONTENDPARAMETERS front;
+                               if (!original && ioctl(m_fd, FE_GET_FRONTEND, &front)<0)
+                                       eDebug("FE_GET_FRONTEND (%m)");
+                               else
+                               {
+                                       const FRONTENDPARAMETERS &parm = original ? this->parm : front;
+                                       const char *tmp = "INVERSION_AUTO";
+                                       switch(parm_inversion)
+                                       {
+                                               case INVERSION_ON:
+                                                       tmp = "INVERSION_ON";
+                                                       break;
+                                               case INVERSION_OFF:
+                                                       tmp = "INVERSION_OFF";
+                                                       break;
+                                               default:
+                                                       break;
+                                       }
+                                       if (tmp)
+                                               PutToDict(dest, "inversion", tmp);
 
 
-               PutToDict(ret, "tuner_number", m_fe);
+                                       switch(m_type)
+                                       {
+                                               case feSatellite:
+                                                       fillDictWithSatelliteData(dest, original?parm:front, this);
+                                                       break;
+                                               case feCable:
+                                                       fillDictWithCableData(dest, original?parm:front);
+                                                       break;
+                                               case feTerrestrial:
+                                                       fillDictWithTerrestrialData(dest, original?parm:front);
+                                                       break;
+                                       }
+                               }
+                       }
+                       default:
+                               break;
+               }
+       }
+}
 
 
+void eDVBFrontend::getFrontendData(ePyObject dest)
+{
+       if (dest && PyDict_Check(dest))
+       {
+               const char *tmp=0;
+               PutToDict(dest, "tuner_number", m_slotid);
                switch(m_type)
                {
                        case feSatellite:
                switch(m_type)
                {
                        case feSatellite:
@@ -993,85 +1279,10 @@ PyObject *eDVBFrontend::readTransponderData(bool original)
                                break;
                        default:
                                tmp = "UNKNOWN";
                                break;
                        default:
                                tmp = "UNKNOWN";
-                               read=false;
                                break;
                }
                                break;
                }
-               PutToDict(ret, "tuner_type", tmp);
-
-               if (read)
-               {
-                       FRONTENDPARAMETERS front;
-
-                       tmp = "UNKNOWN";
-                       switch(m_state)
-                       {
-                               case stateIdle:
-                                       tmp="IDLE";
-                                       break;
-                               case stateTuning:
-                                       tmp="TUNING";
-                                       break;
-                               case stateFailed:
-                                       tmp="FAILED";
-                                       break;
-                               case stateLock:
-                                       tmp="LOCKED";
-                                       break;
-                               case stateLostLock:
-                                       tmp="LOSTLOCK";
-                                       break;
-                               default:
-                                       break;
-                       }
-                       PutToDict(ret, "tuner_state", tmp);
-
-                       PutToDict(ret, "tuner_locked", readFrontendData(locked));
-                       PutToDict(ret, "tuner_synced", readFrontendData(synced));
-                       PutToDict(ret, "tuner_bit_error_rate", readFrontendData(bitErrorRate));
-                       PutToDict(ret, "tuner_signal_power", readFrontendData(signalPower));
-                       PutToDict(ret, "tuner_signal_quality", readFrontendData(signalQuality));
-
-                       if (!original && ioctl(m_fd, FE_GET_FRONTEND, &front)<0)
-                               eDebug("FE_GET_FRONTEND (%m)");
-                       else
-                       {
-                               const FRONTENDPARAMETERS &parm = original ? this->parm : front;
-                               tmp = "INVERSION_AUTO";
-                               switch(parm_inversion)
-                               {
-                                       case INVERSION_ON:
-                                               tmp = "INVERSION_ON";
-                                               break;
-                                       case INVERSION_OFF:
-                                               tmp = "INVERSION_OFF";
-                                               break;
-                                       default:
-                                               break;
-                               }
-                               if (tmp)
-                                       PutToDict(ret, "inversion", tmp);
-
-                               switch(m_type)
-                               {
-                                       case feSatellite:
-                                               fillDictWithSatelliteData(ret, original?parm:front, this);
-                                               break;
-                                       case feCable:
-                                               fillDictWithCableData(ret, original?parm:front);
-                                               break;
-                                       case feTerrestrial:
-                                               fillDictWithTerrestrialData(ret, original?parm:front);
-                                               break;
-                               }
-                       }
-               }
-       }
-       else
-       {
-               Py_INCREF(Py_None);
-               ret = Py_None;
+               PutToDict(dest, "tuner_type", tmp);
        }
        }
-       return ret;
 }
 
 #ifndef FP_IOCTL_GET_ID
 }
 
 #ifndef FP_IOCTL_GET_ID
@@ -1079,22 +1290,35 @@ PyObject *eDVBFrontend::readTransponderData(bool original)
 #endif
 int eDVBFrontend::readInputpower()
 {
 #endif
 int eDVBFrontend::readInputpower()
 {
-       int power=m_fe;  // this is needed for read inputpower from the correct tuner !
-
-       // open front prozessor
-       int fp=::open("/dev/dbox/fp0", O_RDWR);
-       if (fp < 0)
-       {
-               eDebug("couldn't open fp");
-               return -1;
+       int power=m_slotid;  // this is needed for read inputpower from the correct tuner !
+       char proc_name[64];
+       sprintf(proc_name, "/proc/stb/fp/lnb_sense%d", m_slotid);
+       FILE *f=fopen(proc_name, "r");
+       if (f)
+       {
+               if (fscanf(f, "%d", &power) != 1)
+                       eDebug("read %s failed!! (%m)", proc_name);
+               else
+                       eDebug("%s is %d\n", proc_name, power);
+               fclose(f);
        }
        }
-       static bool old_fp = (::ioctl(fp, FP_IOCTL_GET_ID) < 0);
-       if ( ioctl( fp, old_fp ? 9 : 0x100, &power ) < 0 )
+       else
        {
        {
-               eDebug("FP_IOCTL_GET_LNB_CURRENT failed (%m)");
-               return -1;
+               // open front prozessor
+               int fp=::open("/dev/dbox/fp0", O_RDWR);
+               if (fp < 0)
+               {
+                       eDebug("couldn't open fp");
+                       return -1;
+               }
+               static bool old_fp = (::ioctl(fp, FP_IOCTL_GET_ID) < 0);
+               if ( ioctl( fp, old_fp ? 9 : 0x100, &power ) < 0 )
+               {
+                       eDebug("FP_IOCTL_GET_LNB_CURRENT failed (%m)");
+                       return -1;
+               }
+               ::close(fp);
        }
        }
-       ::close(fp);
 
        return power;
 }
 
        return power;
 }
@@ -1122,8 +1346,32 @@ bool eDVBFrontend::setSecSequencePos(int steps)
 void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
 {
        int delay=0;
 void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
 {
        int delay=0;
+       eDVBFrontend *sec_fe = this;
+       eDVBRegisteredFrontend *regFE = 0;
+       long tmp = m_data[LINKED_PREV_PTR];
+       while ( tmp != -1 )
+       {
+               eDVBRegisteredFrontend *prev = (eDVBRegisteredFrontend *)tmp;
+               sec_fe = prev->m_frontend;
+               tmp = prev->m_frontend->m_data[LINKED_PREV_PTR];
+               if (tmp == -1 && sec_fe != this && !prev->m_inuse) {
+                       int state = sec_fe->m_state;
+                       if (state != eDVBFrontend::stateIdle && state != stateClosed)
+                       {
+                               sec_fe->closeFrontend(true);
+                               state = sec_fe->m_state;
+                       }
+                       if (state == eDVBFrontend::stateClosed)
+                       {
+                               regFE = prev;
+                               prev->inc_use();
+                       }
+               }
+       }
+
        if ( m_sec_sequence && m_sec_sequence.current() != m_sec_sequence.end() )
        {
        if ( m_sec_sequence && m_sec_sequence.current() != m_sec_sequence.end() )
        {
+               long *sec_fe_data = sec_fe->m_data;
 //             eDebug("tuneLoop %d\n", m_sec_sequence.current()->cmd);
                switch (m_sec_sequence.current()->cmd)
                {
 //             eDebug("tuneLoop %d\n", m_sec_sequence.current()->cmd);
                switch (m_sec_sequence.current()->cmd)
                {
@@ -1139,13 +1387,13 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                        {
                                int voltage = m_sec_sequence.current()++->voltage;
                                eDebug("[SEC] setVoltage %d", voltage);
                        {
                                int voltage = m_sec_sequence.current()++->voltage;
                                eDebug("[SEC] setVoltage %d", voltage);
-                               setVoltage(voltage);
+                               sec_fe->setVoltage(voltage);
                                break;
                        }
                        case eSecCommand::IF_VOLTAGE_GOTO:
                        {
                                eSecCommand::pair &compare = m_sec_sequence.current()->compare;
                                break;
                        }
                        case eSecCommand::IF_VOLTAGE_GOTO:
                        {
                                eSecCommand::pair &compare = m_sec_sequence.current()->compare;
-                               if ( compare.voltage == m_curVoltage && setSecSequencePos(compare.steps) )
+                               if ( compare.voltage == sec_fe_data[CUR_VOLTAGE] && setSecSequencePos(compare.steps) )
                                        break;
                                ++m_sec_sequence.current();
                                break;
                                        break;
                                ++m_sec_sequence.current();
                                break;
@@ -1153,17 +1401,33 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                        case eSecCommand::IF_NOT_VOLTAGE_GOTO:
                        {
                                eSecCommand::pair &compare = m_sec_sequence.current()->compare;
                        case eSecCommand::IF_NOT_VOLTAGE_GOTO:
                        {
                                eSecCommand::pair &compare = m_sec_sequence.current()->compare;
-                               if ( compare.voltage != m_curVoltage && setSecSequencePos(compare.steps) )
+                               if ( compare.voltage != sec_fe_data[CUR_VOLTAGE] && setSecSequencePos(compare.steps) )
+                                       break;
+                               ++m_sec_sequence.current();
+                               break;
+                       }
+                       case eSecCommand::IF_TONE_GOTO:
+                       {
+                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+                               if ( compare.tone == sec_fe_data[CUR_TONE] && setSecSequencePos(compare.steps) )
+                                       break;
+                               ++m_sec_sequence.current();
+                               break;
+                       }
+                       case eSecCommand::IF_NOT_TONE_GOTO:
+                       {
+                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+                               if ( compare.tone != sec_fe_data[CUR_TONE] && setSecSequencePos(compare.steps) )
                                        break;
                                ++m_sec_sequence.current();
                                break;
                        }
                        case eSecCommand::SET_TONE:
                                eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
                                        break;
                                ++m_sec_sequence.current();
                                break;
                        }
                        case eSecCommand::SET_TONE:
                                eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
-                               setTone(m_sec_sequence.current()++->tone);
+                               sec_fe->setTone(m_sec_sequence.current()++->tone);
                                break;
                        case eSecCommand::SEND_DISEQC:
                                break;
                        case eSecCommand::SEND_DISEQC:
-                               sendDiseqc(m_sec_sequence.current()->diseqc);
+                               sec_fe->sendDiseqc(m_sec_sequence.current()->diseqc);
                                eDebugNoNewLine("[SEC] sendDiseqc: ");
                                for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
                                    eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
                                eDebugNoNewLine("[SEC] sendDiseqc: ");
                                for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
                                    eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
@@ -1172,7 +1436,7 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                break;
                        case eSecCommand::SEND_TONEBURST:
                                eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst);
                                break;
                        case eSecCommand::SEND_TONEBURST:
                                eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst);
-                               sendToneburst(m_sec_sequence.current()++->toneburst);
+                               sec_fe->sendToneburst(m_sec_sequence.current()++->toneburst);
                                break;
                        case eSecCommand::SET_FRONTEND:
                                eDebug("[SEC] setFrontend");
                                break;
                        case eSecCommand::SET_FRONTEND:
                                eDebug("[SEC] setFrontend");
@@ -1180,9 +1444,11 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::START_TUNE_TIMEOUT:
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::START_TUNE_TIMEOUT:
-                               m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent
+                       {
+                               m_timeout->start(m_sec_sequence.current()->timeout, 1);
                                ++m_sec_sequence.current();
                                break;
                                ++m_sec_sequence.current();
                                break;
+                       }
                        case eSecCommand::SET_TIMEOUT:
                                m_timeoutCount = m_sec_sequence.current()++->val;
                                eDebug("[SEC] set timeout %d", m_timeoutCount);
                        case eSecCommand::SET_TIMEOUT:
                                m_timeoutCount = m_sec_sequence.current()++->val;
                                eDebug("[SEC] set timeout %d", m_timeoutCount);
@@ -1191,7 +1457,6 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                if (!m_timeoutCount)
                                {
                                        eDebug("[SEC] rotor timout");
                                if (!m_timeoutCount)
                                {
                                        eDebug("[SEC] rotor timout");
-                                       m_sec->setRotorMoving(false);
                                        setSecSequencePos(m_sec_sequence.current()->steps);
                                }
                                else
                                        setSecSequencePos(m_sec_sequence.current()->steps);
                                }
                                else
@@ -1202,7 +1467,7 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                int idx = m_sec_sequence.current()++->val;
                                if ( idx == 0 || idx == 1 )
                                {
                                int idx = m_sec_sequence.current()++->val;
                                if ( idx == 0 || idx == 1 )
                                {
-                                       m_idleInputpower[idx] = readInputpower();
+                                       m_idleInputpower[idx] = sec_fe->readInputpower();
                                        eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
                                }
                                else
                                        eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
                                }
                                else
@@ -1212,10 +1477,10 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                        case eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO:
                        {
                                eSecCommand::pair &compare = m_sec_sequence.current()->compare;
                        case eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO:
                        {
                                eSecCommand::pair &compare = m_sec_sequence.current()->compare;
-                               int idx = compare.voltage;
+                               int idx = compare.val;
                                if ( idx == 0 || idx == 1 )
                                {
                                if ( idx == 0 || idx == 1 )
                                {
-                                       int idle = readInputpower();
+                                       int idle = sec_fe->readInputpower();
                                        int diff = abs(idle-m_idleInputpower[idx]);
                                        if ( diff > 0)
                                        {
                                        int diff = abs(idle-m_idleInputpower[idx]);
                                        if ( diff > 0)
                                        {
@@ -1229,37 +1494,62 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                        }
                        case eSecCommand::IF_TUNER_LOCKED_GOTO:
                        {
                        }
                        case eSecCommand::IF_TUNER_LOCKED_GOTO:
                        {
+                               int signal = 0;
+                               int isLocked = readFrontendData(locked);
+                               m_idleInputpower[0] = m_idleInputpower[1] = 0;
                                eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
                                eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
-                               if (readFrontendData(locked))
+                               if (isLocked && ((abs((signal = readFrontendData(signalQualitydB)) - cmd.lastSignal) < 50) || !cmd.lastSignal))
                                {
                                {
-                                       eDebug("[SEC] locked step %d ok", cmd.okcount);
+                                       if (cmd.lastSignal)
+                                               eDebug("[SEC] locked step %d ok (%d %d)", cmd.okcount, signal, cmd.lastSignal);
+                                       else
+                                       {
+                                               eDebug("[SEC] locked step %d ok", cmd.okcount);
+                                               cmd.lastSignal = signal;
+                                       }
                                        ++cmd.okcount;
                                        ++cmd.okcount;
-                                       if (cmd.okcount > 12)
+                                       if (cmd.okcount > 4)
                                        {
                                        {
-                                               eDebug("ok > 12 .. goto %d\n",m_sec_sequence.current()->steps);
+                                               eDebug("ok > 4 .. goto %d\n",cmd.steps);
                                                setSecSequencePos(cmd.steps);
                                                setSecSequencePos(cmd.steps);
+                                               m_state = stateLock;
+                                               m_stateChanged(this);
+                                               feEvent(-1);
+                                               m_sn->start();
                                                break;
                                        }
                                }
                                else
                                {
                                                break;
                                        }
                                }
                                else
                                {
-                                       eDebug("[SEC] rotor locked step %d failed", cmd.okcount);
+                                       if (isLocked)
+                                               eDebug("[SEC] rotor locked step %d failed (oldSignal %d, curSignal %d)", cmd.okcount, signal, cmd.lastSignal);
+                                       else
+                                               eDebug("[SEC] rotor locked step %d failed (not locked)", cmd.okcount);
                                        --m_timeoutCount;
                                        if (!m_timeoutCount && m_retryCount > 0)
                                                --m_retryCount;
                                        cmd.okcount=0;
                                        --m_timeoutCount;
                                        if (!m_timeoutCount && m_retryCount > 0)
                                                --m_retryCount;
                                        cmd.okcount=0;
+                                       cmd.lastSignal=0;
                                }
                                ++m_sec_sequence.current();
                                break;
                        }
                        case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
                                }
                                ++m_sec_sequence.current();
                                break;
                        }
                        case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
-                               m_runningInputpower = readInputpower();
+                               m_runningInputpower = sec_fe->readInputpower();
                                eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
                                ++m_sec_sequence.current();
                                break;
                                eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
                                ++m_sec_sequence.current();
                                break;
+                       case eSecCommand::SET_ROTOR_MOVING:
+                               m_sec->setRotorMoving(true);
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::SET_ROTOR_STOPPED:
+                               m_sec->setRotorMoving(false);
+                               ++m_sec_sequence.current();
+                               break;
                        case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
                        {
                        case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
                        {
-                               int idleInputpower = m_idleInputpower[ (m_curVoltage&1) ? 0 : 1];
+                               int idleInputpower = m_idleInputpower[ (sec_fe_data[CUR_VOLTAGE]&1) ? 0 : 1];
                                eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
                                const char *txt = cmd.direction ? "running" : "stopped";
                                eDebug("[SEC] waiting for rotor %s %d, idle %d, delta %d",
                                eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
                                const char *txt = cmd.direction ? "running" : "stopped";
                                eDebug("[SEC] waiting for rotor %s %d, idle %d, delta %d",
@@ -1274,7 +1564,6 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                        eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
                                        if ( cmd.okcount > 6 )
                                        {
                                        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;
                                                eDebug("[SEC] rotor is %s", txt);
                                                if (setSecSequencePos(cmd.steps))
                                                        break;
@@ -1292,20 +1581,35 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                break;
                        }
                        case eSecCommand::IF_ROTORPOS_VALID_GOTO:
                                break;
                        }
                        case eSecCommand::IF_ROTORPOS_VALID_GOTO:
-                               if (m_data[ROTOR_CMD] != -1 && m_data[ROTOR_POS] != -1)
+                               if (sec_fe_data[ROTOR_CMD] != -1 && sec_fe_data[ROTOR_POS] != -1)
                                        setSecSequencePos(m_sec_sequence.current()->steps);
                                else
                                        ++m_sec_sequence.current();
                                break;
                                        setSecSequencePos(m_sec_sequence.current()->steps);
                                else
                                        ++m_sec_sequence.current();
                                break;
+                       case eSecCommand::INVALIDATE_CURRENT_SWITCHPARMS:
+                               eDebug("[SEC] invalidate current switch params");
+                               sec_fe_data[CSW] = -1;
+                               sec_fe_data[UCSW] = -1;
+                               sec_fe_data[TONEBURST] = -1;
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::UPDATE_CURRENT_SWITCHPARMS:
+                               sec_fe_data[CSW] = sec_fe_data[NEW_CSW];
+                               sec_fe_data[UCSW] = sec_fe_data[NEW_UCSW];
+                               sec_fe_data[TONEBURST] = sec_fe_data[NEW_TONEBURST];
+                               eDebug("[SEC] update current switch params");
+                               ++m_sec_sequence.current();
+                               break;
                        case eSecCommand::INVALIDATE_CURRENT_ROTORPARMS:
                        case eSecCommand::INVALIDATE_CURRENT_ROTORPARMS:
-                               m_data[ROTOR_CMD] = m_data[ROTOR_POS] = -1;
                                eDebug("[SEC] invalidate current rotorparams");
                                eDebug("[SEC] invalidate current rotorparams");
+                               sec_fe_data[ROTOR_CMD] = -1;
+                               sec_fe_data[ROTOR_POS] = -1;
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
-                               m_data[ROTOR_CMD] = m_data[NEW_ROTOR_CMD];
-                               m_data[ROTOR_POS] = m_data[NEW_ROTOR_POS];
-                               eDebug("[SEC] update current rotorparams %d %04x %d", m_timeoutCount, m_data[5], m_data[6]);
+                               sec_fe_data[ROTOR_CMD] = sec_fe_data[NEW_ROTOR_CMD];
+                               sec_fe_data[ROTOR_POS] = sec_fe_data[NEW_ROTOR_POS];
+                               eDebug("[SEC] update current rotorparams %d %04lx %ld", m_timeoutCount, sec_fe_data[ROTOR_CMD], sec_fe_data[ROTOR_POS]);
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::SET_ROTOR_DISEQC_RETRYS:
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::SET_ROTOR_DISEQC_RETRYS:
@@ -1323,41 +1627,66 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                break;
                        case eSecCommand::SET_POWER_LIMITING_MODE:
                        {
                                break;
                        case eSecCommand::SET_POWER_LIMITING_MODE:
                        {
-                               int fd = m_fe ?
-                                       ::open("/dev/i2c/1", O_RDWR) :
-                                       ::open("/dev/i2c/0", O_RDWR);
-
-                               unsigned char data[2];
-                               ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
-                               if(::read(fd, data, 1) != 1)
-                                       eDebug("[SEC] error read lnbp (%m)");
-                               if ( m_sec_sequence.current()->mode == eSecCommand::modeStatic )
+                               char proc_name[64];
+                               sprintf(proc_name, "/proc/stb/frontend/%d/static_current_limiting", sec_fe->m_dvbid);
+                               FILE *f=fopen(proc_name, "w");
+                               if (f) // new interface exist?
                                {
                                {
-                                       data[0] |= 0x80;  // enable static current limiting
-                                       eDebug("[SEC] set static current limiting");
+                                       bool slimiting = m_sec_sequence.current()->mode == eSecCommand::modeStatic;
+                                       if (fprintf(f, "%s", slimiting ? "on" : "off") <= 0)
+                                               eDebug("write %s failed!! (%m)", proc_name);
+                                       else
+                                               eDebug("[SEC] set %s current limiting", slimiting ? "static" : "dynamic");
+                                       fclose(f);
                                }
                                }
-                               else
+                               else if (sec_fe->m_need_rotor_workaround)
                                {
                                {
-                                       data[0] &= ~0x80;  // enable dynamic current limiting
-                                       eDebug("[SEC] set dynamic current limiting");
+                                       char dev[16];
+                                       int slotid = sec_fe->m_slotid;
+                                       // FIXMEEEEEE hardcoded i2c devices for dm7025 and dm8000
+                                       if (slotid < 2)
+                                               sprintf(dev, "/dev/i2c/%d", slotid);
+                                       else if (slotid == 2)
+                                               sprintf(dev, "/dev/i2c/2"); // first nim socket on DM8000 use /dev/i2c/2
+                                       else if (slotid == 3)
+                                               sprintf(dev, "/dev/i2c/4"); // second nim socket on DM8000 use /dev/i2c/4
+                                       int fd = ::open(dev, O_RDWR);
+
+                                       unsigned char data[2];
+                                       ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
+                                       if(::read(fd, data, 1) != 1)
+                                               eDebug("[SEC] error read lnbp (%m)");
+                                       if ( m_sec_sequence.current()->mode == eSecCommand::modeStatic )
+                                       {
+                                               data[0] |= 0x80;  // enable static current limiting
+                                               eDebug("[SEC] set static current limiting");
+                                       }
+                                       else
+                                       {
+                                               data[0] &= ~0x80;  // enable dynamic current limiting
+                                               eDebug("[SEC] set dynamic current limiting");
+                                       }
+                                       if(::write(fd, data, 1) != 1)
+                                               eDebug("[SEC] error write lnbp (%m)");
+                                       ::close(fd);
                                }
                                }
-                               if(::write(fd, data, 1) != 1)
-                                       eDebug("[SEC] error write lnbp (%m)");
-                               ::close(fd);
                                ++m_sec_sequence.current();
                                break;
                        }
                        default:
                                ++m_sec_sequence.current();
                                break;
                        }
                        default:
+                               eDebug("[SEC] unhandled sec command %d",
+                                       ++m_sec_sequence.current()->cmd);
                                ++m_sec_sequence.current();
                                ++m_sec_sequence.current();
-                               eDebug("[SEC] unhandled sec command");
                }
                m_tuneTimer->start(delay,true);
        }
                }
                m_tuneTimer->start(delay,true);
        }
+       if (regFE)
+               regFE->dec_use();
 }
 
 void eDVBFrontend::setFrontend()
 {
 }
 
 void eDVBFrontend::setFrontend()
 {
-       eDebug("setting frontend %d", m_fe);
+       eDebug("setting frontend %d", m_dvbid);
        m_sn->start();
        feEvent(-1);
        if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
        m_sn->start();
        feEvent(-1);
        if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
@@ -1375,7 +1704,7 @@ RESULT eDVBFrontend::getFrontendType(int &t)
        return 0;
 }
 
        return 0;
 }
 
-RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm)
+RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm, unsigned int tunetimeout)
 {
        int res;
        if (!m_sec)
 {
        int res;
        if (!m_sec)
@@ -1383,16 +1712,17 @@ RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm)
                eWarning("no SEC module active!");
                return -ENOENT;
        }
                eWarning("no SEC module active!");
                return -ENOENT;
        }
-       res = m_sec->prepare(*this, parm, feparm, 1 << m_fe);
+       res = m_sec->prepare(*this, parm, feparm, 1 << m_slotid, tunetimeout);
        if (!res)
        {
        if (!res)
        {
-               eDebug("prepare_sat System %d Freq %d Pol %d SR %d INV %d FEC %d",
+               eDebug("prepare_sat System %d Freq %d Pol %d SR %d INV %d FEC %d orbpos %d",
                        feparm.system,
                        feparm.frequency,
                        feparm.polarisation,
                        feparm.symbol_rate,
                        feparm.inversion,
                        feparm.system,
                        feparm.frequency,
                        feparm.polarisation,
                        feparm.symbol_rate,
                        feparm.inversion,
-                       feparm.fec);
+                       feparm.fec,
+                       feparm.orbital_position);
                parm_u_qpsk_symbol_rate = feparm.symbol_rate;
                switch (feparm.inversion)
                {
                parm_u_qpsk_symbol_rate = feparm.symbol_rate;
                switch (feparm.inversion)
                {
@@ -1470,9 +1800,12 @@ RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm)
                                        eDebug("no valid fec for DVB-S2 set.. abort !!");
                                        return -EINVAL;
                        }
                                        eDebug("no valid fec for DVB-S2 set.. abort !!");
                                        return -EINVAL;
                        }
-                       if (feparm.modulation == eDVBFrontendParametersSatellite::Modulation::M8PSK)
+                       parm_inversion |= (feparm.rolloff << 2); // Hack.. we use bit 2..3 of inversion param for rolloff
+                       if (feparm.modulation == eDVBFrontendParametersSatellite::Modulation::M8PSK) {
                                parm_u_qpsk_fec_inner = (fe_code_rate_t)((int)parm_u_qpsk_fec_inner+9);
                                // 8PSK fec driver values are decimal 9 bigger
                                parm_u_qpsk_fec_inner = (fe_code_rate_t)((int)parm_u_qpsk_fec_inner+9);
                                // 8PSK fec driver values are decimal 9 bigger
+                               parm_inversion |= (feparm.pilot << 4); // Hack.. we use bit 4..5 of inversion param for pilot
+                       }
                }
 #endif
                // FIXME !!! get frequency range from tuner
                }
 #endif
                // FIXME !!! get frequency range from tuner
@@ -1488,7 +1821,11 @@ RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm)
 
 RESULT eDVBFrontend::prepare_cable(const eDVBFrontendParametersCable &feparm)
 {
 
 RESULT eDVBFrontend::prepare_cable(const eDVBFrontendParametersCable &feparm)
 {
+#if HAVE_DVB_API_VERSION < 3
+       parm_frequency = feparm.frequency;
+#else
        parm_frequency = feparm.frequency * 1000;
        parm_frequency = feparm.frequency * 1000;
+#endif
        parm_u_qam_symbol_rate = feparm.symbol_rate;
        switch (feparm.modulation)
        {
        parm_u_qam_symbol_rate = feparm.symbol_rate;
        switch (feparm.modulation)
        {
@@ -1555,6 +1892,12 @@ RESULT eDVBFrontend::prepare_cable(const eDVBFrontendParametersCable &feparm)
                parm_u_qam_fec_inner = FEC_AUTO;
                break;
        }
                parm_u_qam_fec_inner = FEC_AUTO;
                break;
        }
+       eDebug("tuning to %d khz, sr %d, fec %d, modulation %d, inversion %d",
+               parm_frequency/1000,
+               parm_u_qam_symbol_rate,
+               parm_u_qam_fec_inner,
+               parm_u_qam_modulation,
+               parm_inversion);
        return 0;
 }
 
        return 0;
 }
 
@@ -1707,7 +2050,8 @@ RESULT eDVBFrontend::prepare_terrestrial(const eDVBFrontendParametersTerrestrial
 
 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
 {
 
 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
 {
-       eDebug("(%d)tune", m_fe);
+       unsigned int timeout = 5000;
+       eDebug("(%d)tune", m_dvbid);
 
        m_timeout->stop();
 
 
        m_timeout->stop();
 
@@ -1716,15 +2060,21 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
        if (!m_sn)
        {
                eDebug("no frontend device opened... do not try to tune !!!");
        if (!m_sn)
        {
                eDebug("no frontend device opened... do not try to tune !!!");
-               return -ENODEV;
+               res = -ENODEV;
+               goto tune_error;
        }
 
        if (m_type == -1)
        }
 
        if (m_type == -1)
-               return -ENODEV;
+       {
+               res = -ENODEV;
+               goto tune_error;
+       }
 
        m_sn->stop();
        m_sec_sequence.clear();
 
 
        m_sn->stop();
        m_sec_sequence.clear();
 
+       where.calcLockTimeout(timeout);
+
        switch (m_type)
        {
        case feSatellite:
        switch (m_type)
        {
        case feSatellite:
@@ -1733,23 +2083,30 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                if (where.getDVBS(feparm))
                {
                        eDebug("no dvbs data!");
                if (where.getDVBS(feparm))
                {
                        eDebug("no dvbs data!");
-                       return -EINVAL;
+                       res = -EINVAL;
+                       goto tune_error;
                }
                }
-               res=prepare_sat(feparm);
                m_sec->setRotorMoving(false);
                m_sec->setRotorMoving(false);
+               res=prepare_sat(feparm, timeout);
+               if (res)
+                       goto tune_error;
+
                break;
        }
        case feCable:
        {
                eDVBFrontendParametersCable feparm;
                if (where.getDVBC(feparm))
                break;
        }
        case feCable:
        {
                eDVBFrontendParametersCable feparm;
                if (where.getDVBC(feparm))
-                       return -EINVAL;
-               res=prepare_cable(feparm);
-               if (!res)
                {
                {
-                       m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
-                       m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
+                       res = -EINVAL;
+                       goto tune_error;
                }
                }
+               res=prepare_cable(feparm);
+               if (res)
+                       goto tune_error;
+
+               m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, timeout) );
+               m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
                break;
        }
        case feTerrestrial:
                break;
        }
        case feTerrestrial:
@@ -1758,40 +2115,43 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                if (where.getDVBT(feparm))
                {
                        eDebug("no -T data");
                if (where.getDVBT(feparm))
                {
                        eDebug("no -T data");
-                       return -EINVAL;
+                       res = -EINVAL;
+                       goto tune_error;
                }
                res=prepare_terrestrial(feparm);
                }
                res=prepare_terrestrial(feparm);
-               if (!res)
-               {
-                       std::string enable_5V;
-                       char configStr[255];
-                       snprintf(configStr, 255, "config.Nim%c.terrestrial_5V", 'A'+m_fe);
-                       m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
-                       ePythonConfigQuery::getConfigValue(configStr, enable_5V);
-                       if (enable_5V == "on")
-                               m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
-                       else
-                               m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltageOff) );
-                       m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
-               }
+               if (res)
+                       goto tune_error;
+
+               std::string enable_5V;
+               char configStr[255];
+               snprintf(configStr, 255, "config.Nims.%d.terrestrial_5V", m_slotid);
+               m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, timeout) );
+               ePythonConfigQuery::getConfigValue(configStr, enable_5V);
+               if (enable_5V == "True")
+                       m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
+               else
+                       m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltageOff) );
+               m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
+
                break;
        }
        }
 
                break;
        }
        }
 
-       if (!res)  // prepare ok
-       {
-               m_tuneTimer->start(0,true);
-               m_sec_sequence.current() = m_sec_sequence.begin();
+       m_tuneTimer->start(0,true);
+       m_sec_sequence.current() = m_sec_sequence.begin();
 
 
-               if (m_state != stateTuning)
-               {
-                       m_tuning = 1;
-                       m_state = stateTuning;
-                       m_stateChanged(this);
-               }
+       if (m_state != stateTuning)
+       {
+               m_tuning = 1;
+               m_state = stateTuning;
+               m_stateChanged(this);
        }
 
        return res;
        }
 
        return res;
+
+tune_error:
+       m_tuneTimer->stop();
+       return res;
 }
 
 RESULT eDVBFrontend::connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)
 }
 
 RESULT eDVBFrontend::connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)
@@ -1810,12 +2170,11 @@ RESULT eDVBFrontend::setVoltage(int voltage)
        bool increased=false;
        fe_sec_voltage_t vlt;
 #endif
        bool increased=false;
        fe_sec_voltage_t vlt;
 #endif
-       m_curVoltage=voltage;
+       m_data[CUR_VOLTAGE]=voltage;
        switch (voltage)
        {
        case voltageOff:
        switch (voltage)
        {
        case voltageOff:
-               for (int i=0; i < 3; ++i)  // reset diseqc
-                       m_data[i]=-1;
+               m_data[CSW]=m_data[UCSW]=m_data[TONEBURST]=-1; // reset diseqc
                vlt = SEC_VOLTAGE_OFF;
                break;
        case voltage13_5:
                vlt = SEC_VOLTAGE_OFF;
                break;
        case voltage13_5:
@@ -1865,7 +2224,7 @@ RESULT eDVBFrontend::setTone(int t)
 #else
        fe_sec_tone_mode_t tone;
 #endif
 #else
        fe_sec_tone_mode_t tone;
 #endif
-
+       m_data[CUR_TONE]=t;
        switch (t)
        {
        case toneOn:
        switch (t)
        {
        case toneOn:
@@ -1945,7 +2304,7 @@ RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list)
        return 0;
 }
 
        return 0;
 }
 
-RESULT eDVBFrontend::getData(int num, int &data)
+RESULT eDVBFrontend::getData(int num, long &data)
 {
        if ( num < NUM_DATA_ENTRIES )
        {
 {
        if ( num < NUM_DATA_ENTRIES )
        {
@@ -1955,7 +2314,7 @@ RESULT eDVBFrontend::getData(int num, int &data)
        return -EINVAL;
 }
 
        return -EINVAL;
 }
 
-RESULT eDVBFrontend::setData(int num, int val)
+RESULT eDVBFrontend::setData(int num, long val)
 {
        if ( num < NUM_DATA_ENTRIES )
        {
 {
        if ( num < NUM_DATA_ENTRIES )
        {
@@ -1968,15 +2327,53 @@ RESULT eDVBFrontend::setData(int num, int val)
 int eDVBFrontend::isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)
 {
        int type;
 int eDVBFrontend::isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)
 {
        int type;
-       if (feparm->getSystem(type) || type != m_type)
+       if (feparm->getSystem(type) || type != m_type || !m_enabled)
                return 0;
                return 0;
-
        if (m_type == eDVBFrontend::feSatellite)
        {
                ASSERT(m_sec);
                eDVBFrontendParametersSatellite sat_parm;
        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;
+               int ret = feparm->getDVBS(sat_parm);
+               ASSERT(!ret);
+               if (sat_parm.system == eDVBFrontendParametersSatellite::System::DVB_S2 && !m_can_handle_dvbs2)
+                       return 0;
+               ret = m_sec->canTune(sat_parm, this, 1 << m_slotid);
+               if (ret > 1 && sat_parm.system == eDVBFrontendParametersSatellite::System::DVB_S && m_can_handle_dvbs2)
+                       ret -= 1;
+               return ret;
+       }
+       else if (m_type == eDVBFrontend::feCable)
+               return 2;  // more prio for cable frontends
+       else if (m_type == eDVBFrontend::feTerrestrial)
+               return 1;
+       return 0;
+}
+
+bool eDVBFrontend::setSlotInfo(ePyObject obj)
+{
+       ePyObject Id, Descr, Enabled, IsDVBS2;
+       if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 4)
+               goto arg_error;
+       Id = PyTuple_GET_ITEM(obj, 0);
+       Descr = PyTuple_GET_ITEM(obj, 1);
+       Enabled = PyTuple_GET_ITEM(obj, 2);
+       IsDVBS2 = PyTuple_GET_ITEM(obj, 3);
+       if (!PyInt_Check(Id) || !PyString_Check(Descr) || !PyBool_Check(Enabled) || !PyBool_Check(IsDVBS2))
+               goto arg_error;
+       strcpy(m_description, PyString_AS_STRING(Descr));
+       m_slotid = PyInt_AsLong(Id);
+       m_enabled = Enabled == Py_True;
+       // HACK.. the rotor workaround is neede for all NIMs with LNBP21 voltage regulator...
+       m_need_rotor_workaround = !!strstr(m_description, "Alps BSBE1") ||
+               !!strstr(m_description, "Alps BSBE2") ||
+               !!strstr(m_description, "Alps -S") ||
+               !!strstr(m_description, "BCM4501");
+       m_can_handle_dvbs2 = IsDVBS2 == Py_True;
+       eDebug("setSlotInfo for dvb frontend %d to slotid %d, descr %s, need rotorworkaround %s, enabled %s, DVB-S2 %s",
+               m_dvbid, m_slotid, m_description, m_need_rotor_workaround ? "Yes" : "No", m_enabled ? "Yes" : "No", m_can_handle_dvbs2 ? "Yes" : "No" );
+       return true;
+arg_error:
+       PyErr_SetString(PyExc_StandardError,
+               "eDVBFrontend::setSlotInfo must get a tuple with first param slotid, second param slot description and third param enabled boolean");
+       return false;
 }
 }