fix calculation in calculateDifference for cable and terrestrial which should complet...
[enigma2.git] / lib / dvb / frontend.cpp
index 75824f0..c8434c0 100644 (file)
@@ -1,4 +1,3 @@
-#include <config.h>
 #include <lib/dvb/dvb.h>
 #include <lib/base/eerror.h>
 #include <errno.h>
 #include <lib/dvb/dvb.h>
 #include <lib/base/eerror.h>
 #include <errno.h>
 #define BANDWIDTH_AUTO                 (BandWidth)3
 #define GUARD_INTERVAL_AUTO            (GuardInterval)4
 #define HIERARCHY_AUTO                 (Hierarchy)4
 #define BANDWIDTH_AUTO                 (BandWidth)3
 #define GUARD_INTERVAL_AUTO            (GuardInterval)4
 #define HIERARCHY_AUTO                 (Hierarchy)4
-#define constellation Constellation
-#define guard_interval guardInterval
-#define hierarchy_information HierarchyInformation
-#define code_rate_HP HP_CodeRate
-#define code_rate_LP LP_CodeRate
+#define parm.frequency parm.Frequency
+#define parm.u.qam.symbol_rate parm.u.qam.SymbolRate
+#define parm.u.qam.fec_inner parm.u.qam.FEC_inner
+#define parm.u.qam.modulation parm.u.qam.QAM
+#define parm.u.ofdm.bandwidth parm.u.ofdm.bandWidth
+#define parm.u.ofdm.code_rate_LP parm.u.ofdm.LP_CodeRate
+#define parm.u.ofdm.code_rate_HP parm.u.ofdm.HP_CodeRate
+#define parm.u.ofdm.constellation parm.u.ofdm.Constellation
+#define parm.u.ofdm.transmission_mode parm.u.ofdm.TransmissionMode
+#define parm.u.ofdm.guard_interval parm.u.ofdm.guardInterval
+#define parm.u.ofdm.hierarchy_information parm.u.ofdm.HierarchyInformation
+#define parm.inversion parm.Inversion
 #else
 #include <linux/dvb/frontend.h>
 #endif
 #else
 #include <linux/dvb/frontend.h>
 #endif
@@ -35,45 +41,10 @@ void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescripto
 {
        frequency    = descriptor.getFrequency() * 10;
        symbol_rate  = descriptor.getSymbolRate() * 100;
 {
        frequency    = descriptor.getFrequency() * 10;
        symbol_rate  = descriptor.getSymbolRate() * 100;
-       switch (descriptor.getPolarization())
-       {
-       case 0:
-               polarisation = Polarisation::Horizontal;
-               break;
-       case 1:
-               polarisation = Polarisation::Vertical;
-               break;
-       case 2:
-               polarisation = Polarisation::CircularLeft;
-               break;
-       case 3:
-               polarisation = Polarisation::CircularRight;
-               break;
-       }
-       switch (descriptor.getFecInner())
-       {
-       case 1:
-               fec = FEC::f1_2;
-               break;
-       case 2:
-               fec = FEC::f2_3;
-               break;
-       case 3:
-               fec = FEC::f3_4;
-               break;
-       case 4:
-               fec = FEC::f5_6;
-               break;
-       case 5:
-               fec = FEC::f7_8;
-               break;
-       case 0xF:
+       polarisation = descriptor.getPolarization();
+       fec = descriptor.getFecInner();
+       if ( fec == 0xF )
                fec = FEC::fNone;
                fec = FEC::fNone;
-               break;
-       default:
-               fec = FEC::fAuto;
-               break;
-       }
        inversion = Inversion::Unknown;
        orbital_position  = ((descriptor.getOrbitalPosition() >> 12) & 0xF) * 1000;
        orbital_position += ((descriptor.getOrbitalPosition() >> 8) & 0xF) * 100;
        inversion = Inversion::Unknown;
        orbital_position  = ((descriptor.getOrbitalPosition() >> 12) & 0xF) * 1000;
        orbital_position += ((descriptor.getOrbitalPosition() >> 8) & 0xF) * 100;
@@ -81,16 +52,55 @@ void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescripto
        orbital_position += ((descriptor.getOrbitalPosition()) & 0xF);
        if (orbital_position && (!descriptor.getWestEastFlag()))
                orbital_position = 3600 - orbital_position;
        orbital_position += ((descriptor.getOrbitalPosition()) & 0xF);
        if (orbital_position && (!descriptor.getWestEastFlag()))
                orbital_position = 3600 - orbital_position;
+       eDebug("SAT freq %d, %s, pos %d, sr %d, fec %d",
+               frequency,
+               polarisation ? "hor" : "vert",
+               orbital_position,
+               symbol_rate, fec);
 }
 
 void eDVBFrontendParametersCable::set(const CableDeliverySystemDescriptor &descriptor)
 {
 }
 
 void eDVBFrontendParametersCable::set(const CableDeliverySystemDescriptor &descriptor)
 {
-       eFatal("nyi");
+       frequency = descriptor.getFrequency() / 10;
+       symbol_rate = descriptor.getSymbolRate() * 100;
+       fec_inner = descriptor.getFecInner();
+       if ( fec_inner == 0xF )
+               fec_inner = FEC::fNone;
+       modulation = descriptor.getModulation();
+       if ( modulation > 0x5 )
+               modulation = Modulation::Auto;
+       inversion = Inversion::Unknown;
+       eDebug("Cable freq %d, mod %d, sr %d, fec %d",
+               frequency,
+               modulation, symbol_rate, fec_inner);
 }
 
 }
 
-void eDVBFrontendParametersTerrestrial::set(const TerrestrialDeliverySystemDescriptor  &)
+void eDVBFrontendParametersTerrestrial::set(const TerrestrialDeliverySystemDescriptor &descriptor)
 {
 {
-       eFatal("nyi");
+       frequency = descriptor.getCentreFrequency() * 10;
+       bandwidth = descriptor.getBandwidth();
+       if ( bandwidth > 2 ) // 5Mhz forced to auto
+               bandwidth = Bandwidth::BwAuto;
+       code_rate_HP = descriptor.getCodeRateHpStream();
+       if (code_rate_HP > 4)
+               code_rate_HP = FEC::fAuto;
+       code_rate_LP = descriptor.getCodeRateLpStream();
+       if (code_rate_LP > 4)
+               code_rate_LP = FEC::fAuto;
+       transmission_mode = descriptor.getTransmissionMode();
+       if (transmission_mode > 2)
+               transmission_mode = TransmissionMode::TMAuto;
+       guard_interval = descriptor.getGuardInterval();
+       if (guard_interval > 3)
+               guard_interval = GuardInterval::GI_Auto;
+       hierarchy = descriptor.getHierarchyInformation()&3;
+       modulation = descriptor.getConstellation();
+       if (modulation > 2)
+               modulation = Modulation::Auto;
+       inversion = Inversion::Unknown;
+       eDebug("Terr freq %d, bw %d, cr_hp %d, cr_lp %d, tm_mode %d, guard %d, hierarchy %d, const %d",
+               frequency, bandwidth, code_rate_HP, code_rate_LP, transmission_mode,
+               guard_interval, hierarchy, modulation);
 }
 
 eDVBFrontendParameters::eDVBFrontendParameters(): m_type(-1)
 }
 
 eDVBFrontendParameters::eDVBFrontendParameters(): m_type(-1)
@@ -177,12 +187,30 @@ RESULT eDVBFrontendParameters::calculateDifference(const iDVBFrontendParameters
                        diff = 1<<29;
                else if (sat.polarisation != osat.polarisation)
                        diff = 1<<28;
                        diff = 1<<29;
                else if (sat.polarisation != osat.polarisation)
                        diff = 1<<28;
-               else 
+               else
+               {
                        diff = abs(sat.frequency - osat.frequency);
                        diff = abs(sat.frequency - osat.frequency);
+                       diff += abs(sat.symbol_rate - osat.symbol_rate);
+               }
                return 0;
        }
        case iDVBFrontend::feCable:
                return 0;
        }
        case iDVBFrontend::feCable:
+               eDVBFrontendParametersCable ocable;
+               if (parm->getDVBC(ocable))
+                       return -2;
+               
+               diff = abs(cable.frequency - ocable.frequency);
+               diff += abs(cable.symbol_rate - ocable.symbol_rate);
+               
+               return 0;
        case iDVBFrontend::feTerrestrial:
        case iDVBFrontend::feTerrestrial:
+               eDVBFrontendParametersTerrestrial oterrestrial;
+               if (parm->getDVBT(oterrestrial))
+                       return -2;
+               
+               diff = abs(terrestrial.frequency - oterrestrial.frequency);
+
+               return 0;
        default:
                return -1;
        }
        default:
                return -1;
        }
@@ -195,8 +223,8 @@ RESULT eDVBFrontendParameters::getHash(unsigned long &hash) const
        {
        case iDVBFrontend::feSatellite:
        {
        {
        case iDVBFrontend::feSatellite:
        {
-               hash  = sat.frequency & 0xFFFF;
-               hash |= sat.orbital_position << 16;
+               hash = (sat.orbital_position << 16);
+               hash |= ((sat.frequency/1000)&0xFFFF)|((sat.polarisation&1) << 15);
                return 0;
        }
        case iDVBFrontend::feCable:
                return 0;
        }
        case iDVBFrontend::feCable:
@@ -208,99 +236,153 @@ RESULT eDVBFrontendParameters::getHash(unsigned long &hash) const
 
 DEFINE_REF(eDVBFrontend);
 
 
 DEFINE_REF(eDVBFrontend);
 
-eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok): m_type(-1), m_fe(fe), m_curVoltage(-1)
+eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok)
+       :m_type(-1), m_fe(fe), m_fd(-1), m_timeout(0), m_tuneTimer(0)
+#if HAVE_DVB_API_VERSION < 3
+       ,m_secfd(-1)
+#endif
 {
 #if HAVE_DVB_API_VERSION < 3
 {
 #if HAVE_DVB_API_VERSION < 3
-       char sec_filename[128];
+       sprintf(m_filename, "/dev/dvb/card%d/frontend%d", adap, fe);
+       sprintf(m_sec_filename, "/dev/dvb/card%d/sec%d", adap, fe);
+#else
+       sprintf(m_filename, "/dev/dvb/adapter%d/frontend%d", adap, fe);
 #endif
 #endif
-       char filename[128];
+       m_timeout = new eTimer(eApp);
+       CONNECT(m_timeout->timeout, eDVBFrontend::timeout);
+
+       m_tuneTimer = new eTimer(eApp);
+       CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop);
 
 
-       int result;
+       int entries = sizeof(m_data) / sizeof(int);
+       for (int i=0; i<entries; ++i)
+               m_data[i] = -1;
 
 
-       m_sn = 0;
-       m_timeout = 0;
+       m_idleInputpower[0]=m_idleInputpower[1]=0;
+
+       ok = !openFrontend();
+       closeFrontend();
+}
+
+int eDVBFrontend::openFrontend()
+{
+       if (m_fd >= 0)
+               return -1;  // already opened
+
+       m_state=0;
+       m_tuning=0;
 
 #if HAVE_DVB_API_VERSION < 3
 
 #if HAVE_DVB_API_VERSION < 3
-       sprintf(sec_filename, "/dev/dvb/card%d/sec%d", adap, fe);
-       m_secfd = ::open(sec_filename, O_RDWR);
+       m_secfd = ::open(m_sec_filename, O_RDWR);
        if (m_secfd < 0)
        {
        if (m_secfd < 0)
        {
-               eWarning("failed! (%s) %m", sec_filename);
-               ok = 0;
-               return;
+               eWarning("failed! (%s) %m", m_sec_filename);
+               return -1;
        }
        }
-       else
-               eDebug("m_secfd is %d", m_secfd);
-
        FrontendInfo fe_info;
        FrontendInfo fe_info;
-       sprintf(filename, "/dev/dvb/card%d/frontend%d", adap, fe);
 #else
 #else
-       dvb_frontend_info fe_info;      
-       sprintf(filename, "/dev/dvb/adapter%d/frontend%d", adap, fe);
+       dvb_frontend_info fe_info;
 #endif
 #endif
-       eDebug("opening frontend.");
-       m_fd = ::open(filename, O_RDWR|O_NONBLOCK);
+       eDebug("opening frontend %d", m_fe);
+       m_fd = ::open(m_filename, O_RDWR|O_NONBLOCK);
        if (m_fd < 0)
        {
        if (m_fd < 0)
        {
-               eWarning("failed! (%s) %m", filename);
-               ok = 0;
-               return;
-       }
-
-       result = ::ioctl(m_fd, FE_GET_INFO, &fe_info);
-       
-       if (result < 0) {
-               eWarning("ioctl FE_GET_INFO failed");
-               ::close(m_fd);
-               m_fd = -1;
-               ok = 0;
-               return;
+               eWarning("failed! (%s) %m", m_filename);
+#if HAVE_DVB_API_VERSION < 3
+               ::close(m_secfd);
+               m_secfd=-1;
+#endif
+               return -1;
        }
 
        }
 
-       switch (fe_info.type) 
+       if (m_type == -1)
        {
        {
-       case FE_QPSK:
-               m_type = feSatellite;
-               break;
-       case FE_QAM:
-               m_type = feCable;
-               break;
-       case FE_OFDM:
-               m_type = feTerrestrial;
-               break;
-       default:
-               eWarning("unknown frontend type.");
-               ::close(m_fd);
-               m_fd = -1;
-               ok = 0;
-               return;
+               if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
+               {
+                       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;
+               }
+
+               switch (fe_info.type)
+               {
+               case FE_QPSK:
+                       m_type = iDVBFrontend::feSatellite;
+                       break;
+               case FE_QAM:
+                       m_type = iDVBFrontend::feCable;
+                       break;
+               case FE_OFDM:
+                       m_type = iDVBFrontend::feTerrestrial;
+                       break;
+               default:
+                       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);
        }
        }
-       eDebug("detected %s frontend", "satellite\0cable\0    terrestrial"+fe_info.type*9);
-       ok = 1;
+
+       setTone(iDVBFrontend::toneOff);
+       setVoltage(iDVBFrontend::voltageOff);
 
        m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read);
        CONNECT(m_sn->activated, eDVBFrontend::feEvent);
        m_sn->start();
 
 
        m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read);
        CONNECT(m_sn->activated, eDVBFrontend::feEvent);
        m_sn->start();
 
-       m_timeout = new eTimer(eApp);
-       CONNECT(m_timeout->timeout, eDVBFrontend::timeout);
-
-       m_tuneTimer = new eTimer(eApp);
-       CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop);
+       return 0;
+}
 
 
-       memset(m_data, 0xFFFF, sizeof(m_data));
+int eDVBFrontend::closeFrontend()
+{
+       if (!m_fe && m_data[7] != -1)
+       {
+               // try to close the first frontend.. but the second is linked to the first
+               eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)m_data[7];
+               if (linked_fe->m_inuse)
+               {
+                       eDebug("dont close frontend %d until the linked frontend %d is still in use",
+                               m_fe, linked_fe->m_frontend->getID());
+                       return -1;
+               }
+       }
+       if (m_fd >= 0)
+       {
+               eDebug("close frontend %d", m_fe);
+               setTone(iDVBFrontend::toneOff);
+               setVoltage(iDVBFrontend::voltageOff);
+               ::close(m_fd);
+               m_fd=-1;
+               m_data[0] = m_data[1] = m_data[2] = -1;
+       }
+#if HAVE_DVB_API_VERSION < 3
+       if (m_secfd >= 0)
+       {
+               ::close(m_secfd);
+               m_secfd=-1;
+       }
+#endif
+       delete m_sn;
+       m_sn=0;
 
 
-       return;
+       return 0;
 }
 
 eDVBFrontend::~eDVBFrontend()
 {
 }
 
 eDVBFrontend::~eDVBFrontend()
 {
-       if (m_fd >= 0)
-               ::close(m_fd);
-       if (m_sn)
-               delete m_sn;
-       if (m_timeout)
-               delete m_timeout;
+       closeFrontend();
+       delete m_timeout;
+       delete m_tuneTimer;
 }
 
 void eDVBFrontend::feEvent(int w)
 }
 
 void eDVBFrontend::feEvent(int w)
@@ -331,7 +413,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("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
                {
                if (event.status & FE_HAS_LOCK)
 #endif
                {
@@ -343,9 +425,7 @@ void eDVBFrontend::feEvent(int w)
                        else
                        {
                                state = stateLostLock;
                        else
                        {
                                state = stateLostLock;
-
-                               if (m_state != stateLostLock)
-                                       eDebug("FIXME: we lost lock, so we might have to retune.");
+                               m_data[0] = m_data[1] = m_data[2] = -1; // reset diseqc
                        }
                }
                if (m_state != state)
                        }
                }
                if (m_state != state)
@@ -358,19 +438,41 @@ void eDVBFrontend::feEvent(int w)
 
 void eDVBFrontend::timeout()
 {
 
 void eDVBFrontend::timeout()
 {
-       int state;
+       m_tuning = 0;
        if (m_state == stateTuning)
        {
        if (m_state == stateTuning)
        {
-               state = stateFailed;
-               eDebug("DVBFrontend: timeout");
-               if (m_state != state)
+               m_state = stateFailed;
+               m_stateChanged(this);
+       }
+}
+
+int eDVBFrontend::readFrontendData(int type)
+{
+       switch(type)
+       {
+               case bitErrorRate:
                {
                {
-                       m_state = state;
-                       m_stateChanged(this);
+                       uint32_t ber=0;
+                       if (ioctl(m_fd, FE_READ_BER, &ber) < 0 && errno != ERANGE)
+                               eDebug("FE_READ_BER failed (%m)");
+                       return ber;
+               }
+               case signalPower:
+               {
+                       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:
+               {
+                       uint16_t strength=0;
+                       if (ioctl(m_fd, FE_READ_SIGNAL_STRENGTH, &strength) < 0 && errno != ERANGE)
+                               eDebug("FE_READ_SIGNAL_STRENGTH failed (%m)");
+                       return strength;
                }
                }
-               m_tuning = 0;
-       } else
-               m_tuning = 0;
+       }
+       return 0;
 }
 
 #ifndef FP_IOCTL_GET_ID
 }
 
 #ifndef FP_IOCTL_GET_ID
@@ -378,34 +480,23 @@ void eDVBFrontend::timeout()
 #endif
 int eDVBFrontend::readInputpower()
 {
 #endif
 int eDVBFrontend::readInputpower()
 {
-       int power=0;
-//     if ( eSystemInfo::getInstance()->canMeasureLNBCurrent() )
+       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)
        {
        {
-//             switch ( eSystemInfo::getInstance()->getHwType() )
-               {
-//                     case eSystemInfo::DM7000:
-//                     case eSystemInfo::DM7020:
-                       {
-                               // 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);
-//                             break;
-                       }
-//                     default:
-//                             eDebug("Inputpower read for platform %d not yet implemented", eSystemInfo::getInstance()->getHwType());
-               }
+               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);
+
        return power;
 }
 
        return power;
 }
 
@@ -445,10 +536,28 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                        ++m_sec_sequence.current();
                                break;
                        case eSecCommand::SET_VOLTAGE:
                                        ++m_sec_sequence.current();
                                break;
                        case eSecCommand::SET_VOLTAGE:
+                       {
                                int voltage = m_sec_sequence.current()++->voltage;
                                eDebug("[SEC] setVoltage %d", voltage);
                                setVoltage(voltage);
                                break;
                                int voltage = m_sec_sequence.current()++->voltage;
                                eDebug("[SEC] setVoltage %d", voltage);
                                setVoltage(voltage);
                                break;
+                       }
+                       case eSecCommand::IF_VOLTAGE_GOTO:
+                       {
+                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+                               if ( compare.voltage == m_curVoltage && setSecSequencePos(compare.steps) )
+                                       break;
+                               ++m_sec_sequence.current();
+                               break;
+                       }
+                       case eSecCommand::IF_NOT_VOLTAGE_GOTO:
+                       {
+                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+                               if ( compare.voltage != m_curVoltage && setSecSequencePos(compare.steps) )
+                                       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);
                        case eSecCommand::SET_TONE:
                                eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
                                setTone(m_sec_sequence.current()++->tone);
@@ -470,73 +579,58 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                setFrontend();
                                ++m_sec_sequence.current();
                                break;
                                setFrontend();
                                ++m_sec_sequence.current();
                                break;
-                       case eSecCommand::MEASURE_IDLE_INPUTPOWER:
-                       {
-                               int idx = m_sec_sequence.current()++->val;
-                               if ( idx == 0 || idx == 1 )
-                               {
-                                       m_idleInputpower[idx] = readInputpower();
-                                       eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
-                               }
-                               else
-                                       eDebug("[SEC] idleInputpower measure index(%d) out of bound !!!", idx);
-                               break;
-                       }
-                       case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
-                               m_runningInputpower = readInputpower();
-                               eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
-                               ++m_sec_sequence.current();
-                               break;
                        case eSecCommand::SET_TIMEOUT:
                                m_timeoutCount = m_sec_sequence.current()++->val;
                                eDebug("[SEC] set timeout %d", m_timeoutCount);
                                break;
                        case eSecCommand::SET_TIMEOUT:
                                m_timeoutCount = m_sec_sequence.current()++->val;
                                eDebug("[SEC] set timeout %d", m_timeoutCount);
                                break;
-                       case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
-                               m_data[5] = m_data[3];
-                               m_data[6] = m_data[4];
-                               eDebug("[SEC] update current rotorparams %d %04x %d", m_timeoutCount, m_data[5], m_data[6]);
-                               ++m_sec_sequence.current();
-                               break;
                        case eSecCommand::IF_TIMEOUT_GOTO:
                                if (!m_timeoutCount)
                                {
                                        eDebug("[SEC] rotor timout");
                        case eSecCommand::IF_TIMEOUT_GOTO:
                                if (!m_timeoutCount)
                                {
                                        eDebug("[SEC] rotor timout");
+                                       m_sec->setRotorMoving(false);
                                        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::SET_POWER_LIMITING_MODE:
+                       case eSecCommand::MEASURE_IDLE_INPUTPOWER:
                        {
                        {
-                               int fd=::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 )
+                               int idx = m_sec_sequence.current()++->val;
+                               if ( idx == 0 || idx == 1 )
                                {
                                {
-                                       data[0] |= 0x90;  // enable static current limiting
-                                       eDebug("[SEC] set static current limiting");
+                                       m_idleInputpower[idx] = readInputpower();
+                                       eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
                                }
                                else
                                }
                                else
+                                       eDebug("[SEC] idleInputpower measure index(%d) out of bound !!!", idx);
+                               break;
+                       }
+                       case eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO:
+                       {
+                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+                               int idx = compare.voltage;
+                               if ( idx == 0 || idx == 1 )
                                {
                                {
-                                       data[0] &= ~0x90;  // enable dynamic current limiting
-                                       eDebug("[SEC] set dynamic current limiting");
+                                       int idle = readInputpower();
+                                       int diff = abs(idle-m_idleInputpower[idx]);
+                                       if ( diff > 0)
+                                       {
+                                               eDebug("measure idle(%d) was not okay.. (%d - %d = %d) retry", idx, m_idleInputpower[idx], idle, diff);
+                                               setSecSequencePos(compare.steps);
+                                               break;
+                                       }
                                }
                                }
-                               if(::write(fd, data, 1) != 1)
-                                       eDebug("[SEC] error write lnbp (%m)");
-                               ::close(fd);
                                ++m_sec_sequence.current();
                                break;
                        }
                                ++m_sec_sequence.current();
                                break;
                        }
-                       case eSecCommand::IF_IDLE_INPUTPOWER_AVAIL_GOTO:
-                               if (m_idleInputpower[0] && m_idleInputpower[1] && setSecSequencePos(m_sec_sequence.current()->steps))
-                                       break;
+                       case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
+                               m_runningInputpower = readInputpower();
+                               eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
                        {
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
                        {
-                               int idleInputpower = m_idleInputpower[m_curVoltage == iDVBFrontend::voltage13 ? 0 : 1];
+                               int idleInputpower = m_idleInputpower[ (m_curVoltage&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",
@@ -551,6 +645,7 @@ 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;
@@ -560,16 +655,66 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                {
                                        eDebug("[SEC] rotor not %s... reset counter.. increase timeout", txt);
                                        --m_timeoutCount;
                                {
                                        eDebug("[SEC] rotor not %s... reset counter.. increase timeout", txt);
                                        --m_timeoutCount;
+                                       if (!m_timeoutCount && m_retryCount > 0)
+                                               --m_retryCount;
                                        cmd.okcount=0;
                                }
                                ++m_sec_sequence.current();
                                break;
                        }
                                        cmd.okcount=0;
                                }
                                ++m_sec_sequence.current();
                                break;
                        }
-                       case eSecCommand::IF_VOLTAGE_GOTO:
+                       case eSecCommand::IF_ROTORPOS_VALID_GOTO:
+                               if (m_data[5] != -1 && m_data[6] != -1)
+                                       setSecSequencePos(m_sec_sequence.current()->steps);
+                               else
+                                       ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::INVALIDATE_CURRENT_ROTORPARMS:
+                               m_data[5] = m_data[6] = -1;
+                               eDebug("[SEC] invalidate current rotorparams");
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
+                               m_data[5] = m_data[3];
+                               m_data[6] = m_data[4];
+                               eDebug("[SEC] update current rotorparams %d %04x %d", m_timeoutCount, m_data[5], m_data[6]);
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::SET_ROTOR_DISEQC_RETRYS:
+                               m_retryCount = m_sec_sequence.current()++->val;
+                               eDebug("[SEC] set rotor retries %d", m_retryCount);
+                               break;
+                       case eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO:
+                               if (!m_retryCount)
+                               {
+                                       eDebug("[SEC] no more rotor retrys");
+                                       setSecSequencePos(m_sec_sequence.current()->steps);
+                               }
+                               else
+                                       ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::SET_POWER_LIMITING_MODE:
                        {
                        {
-                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
-                               if ( compare.voltage == m_curVoltage && setSecSequencePos(compare.steps) )
-                                       break;
+                               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 )
+                               {
+                                       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);
                                ++m_sec_sequence.current();
                                break;
                        }
                                ++m_sec_sequence.current();
                                break;
                        }
@@ -583,19 +728,12 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
 
 void eDVBFrontend::setFrontend()
 {
 
 void eDVBFrontend::setFrontend()
 {
-       eDebug("setting frontend..\n");
+       eDebug("setting frontend %d", m_fe);
        if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
        {
                perror("FE_SET_FRONTEND failed");
                return;
        }
        if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
        {
                perror("FE_SET_FRONTEND failed");
                return;
        }
-
-       if (m_state != stateTuning)
-       {
-               m_tuning = 1;
-               m_state = stateTuning;
-               m_stateChanged(this);
-       }
        m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent
 }
 
        m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent
 }
 
@@ -609,6 +747,8 @@ RESULT eDVBFrontend::getFrontendType(int &t)
 
 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
 {
 
 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
 {
+       eDebug("(%d)tune", m_fe);
+
        if (m_type == -1)
                return -ENODEV;
 
        if (m_type == -1)
                return -ENODEV;
 
@@ -636,11 +776,7 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                res = m_sec->prepare(*this, parm, feparm, 1 << m_fe);
                if (res)
                        return res;
                res = m_sec->prepare(*this, parm, feparm, 1 << m_fe);
                if (res)
                        return res;
-#if HAVE_DVB_API_VERSION < 3
-               eDebug("tuning to %d mhz", parm.Frequency/1000);
-#else
                eDebug("tuning to %d mhz", parm.frequency/1000);
                eDebug("tuning to %d mhz", parm.frequency/1000);
-#endif
                break;
        }
        case feCable:
                break;
        }
        case feCable:
@@ -648,14 +784,8 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                eDVBFrontendParametersCable feparm;
                if (where.getDVBC(feparm))
                        return -EINVAL;
                eDVBFrontendParametersCable feparm;
                if (where.getDVBC(feparm))
                        return -EINVAL;
-#if HAVE_DVB_API_VERSION < 3
-               parm.Frequency = feparm.frequency;
-#else
-               parm.frequency = feparm.frequency;
-#endif
-
+               parm.frequency = feparm.frequency * 1000;
                parm.u.qam.symbol_rate = feparm.symbol_rate;
                parm.u.qam.symbol_rate = feparm.symbol_rate;
-
                switch (feparm.modulation)
                {
                case eDVBFrontendParametersCable::Modulation::QAM16:
                switch (feparm.modulation)
                {
                case eDVBFrontendParametersCable::Modulation::QAM16:
@@ -672,40 +802,27 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                        break;
                case eDVBFrontendParametersCable::Modulation::QAM256:
                        parm.u.qam.modulation = QAM_256;
                        break;
                case eDVBFrontendParametersCable::Modulation::QAM256:
                        parm.u.qam.modulation = QAM_256;
-                       break;                  
+                       break;
+               default:
                case eDVBFrontendParametersCable::Modulation::Auto:
                        parm.u.qam.modulation = QAM_AUTO;
                case eDVBFrontendParametersCable::Modulation::Auto:
                        parm.u.qam.modulation = QAM_AUTO;
-                       break;                  
+                       break;
                }
                }
-               switch (feparm.modulation)
-               {               
+               switch (feparm.inversion)
+               {
                case eDVBFrontendParametersCable::Inversion::On:
                case eDVBFrontendParametersCable::Inversion::On:
-                       #if HAVE_DVB_API_VERSION < 3
-                       parm.Inversion =
-                       #else
-                       parm.inversion =
-                       #endif
-                               INVERSION_ON;
+                       parm.inversion = INVERSION_ON;
                        break;
                case eDVBFrontendParametersCable::Inversion::Off:
                        break;
                case eDVBFrontendParametersCable::Inversion::Off:
-                       #if HAVE_DVB_API_VERSION < 3
-                       parm.Inversion =
-                       #else
-                       parm.inversion =
-                       #endif
-                               INVERSION_OFF;
+                       parm.inversion = INVERSION_OFF;
                        break;
                        break;
+               default:
                case eDVBFrontendParametersCable::Inversion::Unknown:
                case eDVBFrontendParametersCable::Inversion::Unknown:
-                       #if HAVE_DVB_API_VERSION < 3
-                       parm.Inversion =
-                       #else
-                       parm.inversion =
-                       #endif
-                               INVERSION_AUTO;
-                       break;                                          
+                       parm.inversion = INVERSION_AUTO;
+                       break;
                }
                switch (feparm.fec_inner)
                }
                switch (feparm.fec_inner)
-               {               
+               {
                case eDVBFrontendParametersCable::FEC::fNone:
                        parm.u.qam.fec_inner = FEC_NONE;
                        break;
                case eDVBFrontendParametersCable::FEC::fNone:
                        parm.u.qam.fec_inner = FEC_NONE;
                        break;
@@ -718,21 +835,16 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                case eDVBFrontendParametersCable::FEC::f3_4:
                        parm.u.qam.fec_inner = FEC_3_4;
                        break;
                case eDVBFrontendParametersCable::FEC::f3_4:
                        parm.u.qam.fec_inner = FEC_3_4;
                        break;
-               case eDVBFrontendParametersCable::FEC::f4_5:
-                       parm.u.qam.fec_inner = FEC_4_5;
-                       break;
                case eDVBFrontendParametersCable::FEC::f5_6:
                        parm.u.qam.fec_inner = FEC_5_6;
                        break;
                case eDVBFrontendParametersCable::FEC::f5_6:
                        parm.u.qam.fec_inner = FEC_5_6;
                        break;
-               case eDVBFrontendParametersCable::FEC::f6_7:
-                       parm.u.qam.fec_inner = FEC_6_7;
-                       break;
                case eDVBFrontendParametersCable::FEC::f7_8:
                        parm.u.qam.fec_inner = FEC_7_8;
                        break;
                case eDVBFrontendParametersCable::FEC::f8_9:
                        parm.u.qam.fec_inner = FEC_8_9;
                        break;
                case eDVBFrontendParametersCable::FEC::f7_8:
                        parm.u.qam.fec_inner = FEC_7_8;
                        break;
                case eDVBFrontendParametersCable::FEC::f8_9:
                        parm.u.qam.fec_inner = FEC_8_9;
                        break;
+               default:
                case eDVBFrontendParametersCable::FEC::fAuto:
                        parm.u.qam.fec_inner = FEC_AUTO;
                        break;
                case eDVBFrontendParametersCable::FEC::fAuto:
                        parm.u.qam.fec_inner = FEC_AUTO;
                        break;
@@ -747,54 +859,70 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                        eDebug("no -T data");
                        return -EINVAL;
                }
                        eDebug("no -T data");
                        return -EINVAL;
                }
-#if HAVE_DVB_API_VERSION < 3
-               parm.Frequency = feparm.frequency;
-#else
                parm.frequency = feparm.frequency;
                parm.frequency = feparm.frequency;
-#endif
 
                switch (feparm.bandwidth)
                {
                case eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz:
 
                switch (feparm.bandwidth)
                {
                case eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz:
-#if HAVE_DVB_API_VERSION < 3
-                       parm.u.ofdm.bandWidth =
-#else
-                       parm.u.ofdm.bandwidth =
-#endif
-                               BANDWIDTH_8_MHZ;
+                       parm.u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
                        break;
                case eDVBFrontendParametersTerrestrial::Bandwidth::Bw7MHz:
                        break;
                case eDVBFrontendParametersTerrestrial::Bandwidth::Bw7MHz:
-#if HAVE_DVB_API_VERSION < 3
-                       parm.u.ofdm.bandWidth =
-#else
-                       parm.u.ofdm.bandwidth =
-#endif
-                               BANDWIDTH_7_MHZ;
+                       parm.u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
                        break;
                case eDVBFrontendParametersTerrestrial::Bandwidth::Bw6MHz:
                        break;
                case eDVBFrontendParametersTerrestrial::Bandwidth::Bw6MHz:
-#if HAVE_DVB_API_VERSION < 3
-                       parm.u.ofdm.bandWidth =
-#else
-                       parm.u.ofdm.bandwidth =
-#endif
-                               BANDWIDTH_6_MHZ;
+                       parm.u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
                        break;
                        break;
+               default:
                case eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto:
                case eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto:
-#if HAVE_DVB_API_VERSION < 3
-                       parm.u.ofdm.bandWidth =
-#else
-                       parm.u.ofdm.bandwidth =
-#endif
-                               BANDWIDTH_AUTO;
+                       parm.u.ofdm.bandwidth = BANDWIDTH_AUTO;
+                       break;
+               }
+               switch (feparm.code_rate_LP)
+               {
+               case eDVBFrontendParametersCable::FEC::f1_2:
+                       parm.u.ofdm.code_rate_LP = FEC_1_2;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f2_3:
+                       parm.u.ofdm.code_rate_LP = FEC_2_3;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f3_4:
+                       parm.u.ofdm.code_rate_LP = FEC_3_4;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f5_6:
+                       parm.u.ofdm.code_rate_LP = FEC_5_6;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f7_8:
+                       parm.u.ofdm.code_rate_LP = FEC_7_8;
                        break;
                default:
                        break;
                default:
-                       eWarning("invalid OFDM bandwith");
-                       return -EINVAL;
+               case eDVBFrontendParametersCable::FEC::fAuto:
+               case eDVBFrontendParametersCable::FEC::fNone:
+                       parm.u.ofdm.code_rate_LP = FEC_AUTO;
+                       break;
+               }
+               switch (feparm.code_rate_HP)
+               {
+               case eDVBFrontendParametersCable::FEC::f1_2:
+                       parm.u.ofdm.code_rate_HP = FEC_1_2;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f2_3:
+                       parm.u.ofdm.code_rate_HP = FEC_2_3;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f3_4:
+                       parm.u.ofdm.code_rate_HP = FEC_3_4;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f5_6:
+                       parm.u.ofdm.code_rate_HP = FEC_5_6;
+                       break;
+               case eDVBFrontendParametersCable::FEC::f7_8:
+                       parm.u.ofdm.code_rate_HP = FEC_7_8;
+                       break;
+               default:
+               case eDVBFrontendParametersCable::FEC::fAuto:
+               case eDVBFrontendParametersCable::FEC::fNone:
+                       parm.u.ofdm.code_rate_HP = FEC_AUTO;
+                       break;
                }
                }
-               
-               parm.u.ofdm.code_rate_HP = FEC_AUTO;
-               parm.u.ofdm.code_rate_LP = FEC_AUTO;
-               
                switch (feparm.modulation)
                {
                case eDVBFrontendParametersTerrestrial::Modulation::QPSK:
                switch (feparm.modulation)
                {
                case eDVBFrontendParametersTerrestrial::Modulation::QPSK:
@@ -803,55 +931,74 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                case eDVBFrontendParametersTerrestrial::Modulation::QAM16:
                        parm.u.ofdm.constellation = QAM_16;
                        break;
                case eDVBFrontendParametersTerrestrial::Modulation::QAM16:
                        parm.u.ofdm.constellation = QAM_16;
                        break;
+               default:
                case eDVBFrontendParametersTerrestrial::Modulation::Auto:
                        parm.u.ofdm.constellation = QAM_AUTO;
                        break;
                }
                case eDVBFrontendParametersTerrestrial::Modulation::Auto:
                        parm.u.ofdm.constellation = QAM_AUTO;
                        break;
                }
-               
                switch (feparm.transmission_mode)
                {
                case eDVBFrontendParametersTerrestrial::TransmissionMode::TM2k:
                switch (feparm.transmission_mode)
                {
                case eDVBFrontendParametersTerrestrial::TransmissionMode::TM2k:
-#if HAVE_DVB_API_VERSION < 3
-                       parm.u.ofdm.TransmissionMode =
-#else
-                       parm.u.ofdm.transmission_mode =
-#endif
-                               TRANSMISSION_MODE_2K;
+                       parm.u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
                        break;
                case eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k:
                        break;
                case eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k:
-#if HAVE_DVB_API_VERSION < 3
-                       parm.u.ofdm.TransmissionMode =
-#else
-                       parm.u.ofdm.transmission_mode =
-#endif
-                               TRANSMISSION_MODE_8K;
+                       parm.u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
                        break;
                        break;
+               default:
                case eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto:
                case eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto:
-#if HAVE_DVB_API_VERSION < 3
-                       parm.u.ofdm.TransmissionMode =
-#else
-                       parm.u.ofdm.transmission_mode =
-#endif
-                               TRANSMISSION_MODE_AUTO;
+                       parm.u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
                        break;
                }
                        break;
                }
-               
-               parm.u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
-               parm.u.ofdm.hierarchy_information = HIERARCHY_AUTO;
-#if HAVE_DVB_API_VERSION < 3
-               parm.Inversion =
-#else
-               parm.inversion =
-#endif
-                       INVERSION_AUTO;
-               break;
+               switch (feparm.guard_interval)
+               {
+                       case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_32:
+                               parm.u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
+                               break;
+                       case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_16:
+                               parm.u.ofdm.guard_interval = GUARD_INTERVAL_1_16;
+                               break;
+                       case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_8:
+                               parm.u.ofdm.guard_interval = GUARD_INTERVAL_1_8;
+                               break;
+                       case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_4:
+                               parm.u.ofdm.guard_interval = GUARD_INTERVAL_1_4;
+                               break;
+                       default:
+                       case eDVBFrontendParametersTerrestrial::GuardInterval::GI_Auto:
+                               parm.u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
+                               break;
+               }
+               switch (feparm.hierarchy)
+               {
+                       case eDVBFrontendParametersTerrestrial::Hierarchy::H1:
+                               parm.u.ofdm.hierarchy_information = HIERARCHY_1;
+                               break;
+                       case eDVBFrontendParametersTerrestrial::Hierarchy::H2:
+                               parm.u.ofdm.hierarchy_information = HIERARCHY_2;
+                               break;
+                       case eDVBFrontendParametersTerrestrial::Hierarchy::H4:
+                               parm.u.ofdm.hierarchy_information = HIERARCHY_4;
+                               break;
+                       default:
+                       case eDVBFrontendParametersTerrestrial::Hierarchy::HAuto:
+                               parm.u.ofdm.hierarchy_information = HIERARCHY_AUTO;
+                               break;
+               }
        }
        }
 
        m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
        m_tuneTimer->start(0,true);
        }
        }
 
        m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
        m_tuneTimer->start(0,true);
+       m_timeout->stop();
        m_sec_sequence.current() = m_sec_sequence.begin();
 
        m_sec_sequence.current() = m_sec_sequence.begin();
 
+       if (m_state != stateTuning)
+       {
+               m_tuning = 1;
+               m_state = stateTuning;
+               m_stateChanged(this);
+       }
+
        return 0;
 }
 
        return 0;
 }
 
@@ -863,21 +1010,39 @@ RESULT eDVBFrontend::connectStateChange(const Slot1<void,iDVBFrontend*> &stateCh
 
 RESULT eDVBFrontend::setVoltage(int voltage)
 {
 
 RESULT eDVBFrontend::setVoltage(int voltage)
 {
+       if (m_type != feSatellite)
+               return -1;
 #if HAVE_DVB_API_VERSION < 3
        secVoltage vlt;
 #else
 #if HAVE_DVB_API_VERSION < 3
        secVoltage vlt;
 #else
+       bool increased=false;
        fe_sec_voltage_t vlt;
 #endif
        fe_sec_voltage_t vlt;
 #endif
-
        m_curVoltage=voltage;
        switch (voltage)
        {
        case voltageOff:
        m_curVoltage=voltage;
        switch (voltage)
        {
        case voltageOff:
+               for (int i=0; i < 3; ++i)  // reset diseqc
+                       m_data[i]=-1;
                vlt = SEC_VOLTAGE_OFF;
                break;
                vlt = SEC_VOLTAGE_OFF;
                break;
+       case voltage13_5:
+#if HAVE_DVB_API_VERSION < 3
+               vlt = SEC_VOLTAGE_13_5;
+               break;
+#else
+               increased = true;
+#endif
        case voltage13:
                vlt = SEC_VOLTAGE_13;
                break;
        case voltage13:
                vlt = SEC_VOLTAGE_13;
                break;
+       case voltage18_5:
+#if HAVE_DVB_API_VERSION < 3
+               vlt = SEC_VOLTAGE_18_5;
+               break;
+#else
+               increased = true;
+#endif
        case voltage18:
                vlt = SEC_VOLTAGE_18;
                break;
        case voltage18:
                vlt = SEC_VOLTAGE_18;
                break;
@@ -887,6 +1052,8 @@ RESULT eDVBFrontend::setVoltage(int voltage)
 #if HAVE_DVB_API_VERSION < 3
        return ::ioctl(m_secfd, SEC_SET_VOLTAGE, vlt);
 #else
 #if HAVE_DVB_API_VERSION < 3
        return ::ioctl(m_secfd, SEC_SET_VOLTAGE, vlt);
 #else
+       if (::ioctl(m_fd, FE_ENABLE_HIGH_LNB_VOLTAGE, increased) < 0)
+               perror("FE_ENABLE_HIGH_LNB_VOLTAGE");
        return ::ioctl(m_fd, FE_SET_VOLTAGE, vlt);
 #endif
 }
        return ::ioctl(m_fd, FE_SET_VOLTAGE, vlt);
 #endif
 }
@@ -899,6 +1066,8 @@ RESULT eDVBFrontend::getState(int &state)
 
 RESULT eDVBFrontend::setTone(int t)
 {
 
 RESULT eDVBFrontend::setTone(int t)
 {
+       if (m_type != feSatellite)
+               return -1;
 #if HAVE_DVB_API_VERSION < 3
        secToneMode_t tone;
 #else
 #if HAVE_DVB_API_VERSION < 3
        secToneMode_t tone;
 #else
@@ -955,12 +1124,19 @@ RESULT eDVBFrontend::sendToneburst(int burst)
 {
 #if HAVE_DVB_API_VERSION < 3
        secMiniCmd cmd = SEC_MINI_NONE;
 {
 #if HAVE_DVB_API_VERSION < 3
        secMiniCmd cmd = SEC_MINI_NONE;
+#else
+       fe_sec_mini_cmd_t cmd = SEC_MINI_A;
+#endif
        if ( burst == eDVBSatelliteDiseqcParameters::A )
                cmd = SEC_MINI_A;
        else if ( burst == eDVBSatelliteDiseqcParameters::B )
                cmd = SEC_MINI_B;
        if ( burst == eDVBSatelliteDiseqcParameters::A )
                cmd = SEC_MINI_A;
        else if ( burst == eDVBSatelliteDiseqcParameters::B )
                cmd = SEC_MINI_B;
+#if HAVE_DVB_API_VERSION < 3
        if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd))
                return -EINVAL;
        if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd))
                return -EINVAL;
+#else
+       if (::ioctl(m_fd, FE_DISEQC_SEND_BURST, cmd))
+               return -EINVAL;
 #endif
        return 0;
 }
 #endif
        return 0;
 }
@@ -979,7 +1155,7 @@ RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list)
 
 RESULT eDVBFrontend::getData(int num, int &data)
 {
 
 RESULT eDVBFrontend::getData(int num, int &data)
 {
-       if ( num < 7 )
+       if ( num < (int)(sizeof(m_data)/sizeof(int)) )
        {
                data = m_data[num];
                return 0;
        {
                data = m_data[num];
                return 0;
@@ -989,7 +1165,7 @@ RESULT eDVBFrontend::getData(int num, int &data)
 
 RESULT eDVBFrontend::setData(int num, int val)
 {
 
 RESULT eDVBFrontend::setData(int num, int val)
 {
-       if ( num < 7 )
+       if ( num < (int)(sizeof(m_data)/sizeof(int)) )
        {
                m_data[num] = val;
                return 0;
        {
                m_data[num] = val;
                return 0;
@@ -999,14 +1175,16 @@ RESULT eDVBFrontend::setData(int num, int val)
 
 int eDVBFrontend::isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)
 {
 
 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, 1 << m_fe);
+       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;
 }
 }