fix calculation in calculateDifference for cable and terrestrial which should complet...
[enigma2.git] / lib / dvb / frontend.cpp
index 9d4061e..c8434c0 100644 (file)
@@ -1,4 +1,3 @@
-#include <config.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 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
@@ -35,45 +41,10 @@ void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescripto
 {
        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;
-               break;
-       default:
-               fec = FEC::fAuto;
-               break;
-       }
        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;
+       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)
 {
-       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)
@@ -185,7 +195,22 @@ RESULT eDVBFrontendParameters::calculateDifference(const iDVBFrontendParameters
                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:
+               eDVBFrontendParametersTerrestrial oterrestrial;
+               if (parm->getDVBT(oterrestrial))
+                       return -2;
+               
+               diff = abs(terrestrial.frequency - oterrestrial.frequency);
+
+               return 0;
        default:
                return -1;
        }
@@ -245,7 +270,6 @@ int eDVBFrontend::openFrontend()
                return -1;  // already opened
 
        m_state=0;
-       m_curVoltage=voltageOff;
        m_tuning=0;
 
 #if HAVE_DVB_API_VERSION < 3
@@ -339,6 +363,7 @@ int eDVBFrontend::closeFrontend()
                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)
@@ -413,19 +438,12 @@ void eDVBFrontend::feEvent(int w)
 
 void eDVBFrontend::timeout()
 {
-       int state;
+       m_tuning = 0;
        if (m_state == stateTuning)
        {
-               state = stateFailed;
-               eDebug("DVBFrontend: timeout");
-               if (m_state != state)
-               {
-                       m_state = state;
-                       m_stateChanged(this);
-               }
-               m_tuning = 0;
-       } else
-               m_tuning = 0;
+               m_state = stateFailed;
+               m_stateChanged(this);
+       }
 }
 
 int eDVBFrontend::readFrontendData(int type)
@@ -524,6 +542,22 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                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);
@@ -545,33 +579,10 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                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::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)
                                {
@@ -582,35 +593,39 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                else
                                        ++m_sec_sequence.current();
                                break;
-                       case eSecCommand::SET_POWER_LIMITING_MODE:
+                       case eSecCommand::MEASURE_IDLE_INPUTPOWER:
                        {
-                               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 )
+                               int idx = m_sec_sequence.current()++->val;
+                               if ( idx == 0 || idx == 1 )
                                {
-                                       data[0] |= 0x80;  // 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
+                                       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] &= ~0x80;  // 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;
                        }
-                       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:
@@ -640,16 +655,66 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                {
                                        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;
                        }
-                       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;
                        }
@@ -711,123 +776,79 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                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);
-#endif
                break;
        }
        case feCable:
        {
-#if HAVE_DVB_API_VERSION >= 3
                eDVBFrontendParametersCable feparm;
                if (where.getDVBC(feparm))
                        return -EINVAL;
-#if HAVE_DVB_API_VERSION < 3
-               parm.Frequency = feparm.frequency * 1000;
-               parm.u.qam.SymbolRate = feparm.symbol_rate;
-#else
                parm.frequency = feparm.frequency * 1000;
                parm.u.qam.symbol_rate = feparm.symbol_rate;
-#endif
-               fe_modulation_t mod=QAM_AUTO;
                switch (feparm.modulation)
                {
                case eDVBFrontendParametersCable::Modulation::QAM16:
-                       mod = QAM_16;
+                       parm.u.qam.modulation = QAM_16;
                        break;
                case eDVBFrontendParametersCable::Modulation::QAM32:
-                       mod = QAM_32;
+                       parm.u.qam.modulation = QAM_32;
                        break;
                case eDVBFrontendParametersCable::Modulation::QAM64:
-                       mod = QAM_64;
+                       parm.u.qam.modulation = QAM_64;
                        break;
                case eDVBFrontendParametersCable::Modulation::QAM128:
-                       mod = QAM_128;
+                       parm.u.qam.modulation = QAM_128;
                        break;
                case eDVBFrontendParametersCable::Modulation::QAM256:
-                       mod = QAM_256;
-                       break;                  
+                       parm.u.qam.modulation = QAM_256;
+                       break;
+               default:
                case eDVBFrontendParametersCable::Modulation::Auto:
-                       mod = QAM_AUTO;
-                       break;                  
+                       parm.u.qam.modulation = QAM_AUTO;
+                       break;
                }
-#if HAVE_DVB_API_VERSION < 3
-               parm.u.qam.QAM = mod;
-#else
-               parm.u.qam.modulation = mod;
-#endif
                switch (feparm.inversion)
-               {               
+               {
                case eDVBFrontendParametersCable::Inversion::On:
-                       #if HAVE_DVB_API_VERSION < 3
-                       parm.Inversion =
-                       #else
-                       parm.inversion =
-                       #endif
-                               INVERSION_ON;
+                       parm.inversion = INVERSION_ON;
                        break;
                case eDVBFrontendParametersCable::Inversion::Off:
-                       #if HAVE_DVB_API_VERSION < 3
-                       parm.Inversion =
-                       #else
-                       parm.inversion =
-                       #endif
-                               INVERSION_OFF;
+                       parm.inversion = INVERSION_OFF;
                        break;
+               default:
                case eDVBFrontendParametersCable::Inversion::Unknown:
-                       #if HAVE_DVB_API_VERSION < 3
-                       parm.Inversion =
-                       #else
-                       parm.inversion =
-                       #endif
-                               INVERSION_AUTO;
+                       parm.inversion = INVERSION_AUTO;
                        break;
                }
-               
-               fe_code_rate_t fec_inner=FEC_AUTO;
                switch (feparm.fec_inner)
-               {               
+               {
                case eDVBFrontendParametersCable::FEC::fNone:
-                       fec_inner = FEC_NONE;
+                       parm.u.qam.fec_inner = FEC_NONE;
                        break;
                case eDVBFrontendParametersCable::FEC::f1_2:
-                       fec_inner = FEC_1_2;
+                       parm.u.qam.fec_inner = FEC_1_2;
                        break;
                case eDVBFrontendParametersCable::FEC::f2_3:
-                       fec_inner = FEC_2_3;
+                       parm.u.qam.fec_inner = FEC_2_3;
                        break;
                case eDVBFrontendParametersCable::FEC::f3_4:
-                       fec_inner = FEC_3_4;
-                       break;
-               case eDVBFrontendParametersCable::FEC::f4_5:
-                       fec_inner = FEC_4_5;
+                       parm.u.qam.fec_inner = FEC_3_4;
                        break;
                case eDVBFrontendParametersCable::FEC::f5_6:
-                       fec_inner = FEC_5_6;
-                       break;
-               case eDVBFrontendParametersCable::FEC::f6_7:
-                       fec_inner = FEC_6_7;
+                       parm.u.qam.fec_inner = FEC_5_6;
                        break;
                case eDVBFrontendParametersCable::FEC::f7_8:
-                       fec_inner = FEC_7_8;
+                       parm.u.qam.fec_inner = FEC_7_8;
                        break;
                case eDVBFrontendParametersCable::FEC::f8_9:
-                       fec_inner = FEC_8_9;
+                       parm.u.qam.fec_inner = FEC_8_9;
                        break;
+               default:
                case eDVBFrontendParametersCable::FEC::fAuto:
-                       fec_inner = FEC_AUTO;
+                       parm.u.qam.fec_inner = FEC_AUTO;
                        break;
                }
-#if HAVE_DVB_API_VERSION < 3
-               parm.u.qam.FEC_inner = fec_inner;
-#else
-               parm.u.qam.fec_inner = fec_inner;
-#endif
-#else
-               eFatal("Old API not fully supported");
-#endif // old api
                break;
        }
        case feTerrestrial:
@@ -838,54 +859,70 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                        eDebug("no -T data");
                        return -EINVAL;
                }
-#if HAVE_DVB_API_VERSION < 3
-               parm.Frequency = feparm.frequency;
-#else
                parm.frequency = feparm.frequency;
-#endif
 
                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:
-#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:
-#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;
+               default:
                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:
-                       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:
@@ -894,53 +931,65 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
                case eDVBFrontendParametersTerrestrial::Modulation::QAM16:
                        parm.u.ofdm.constellation = QAM_16;
                        break;
+               default:
                case eDVBFrontendParametersTerrestrial::Modulation::Auto:
                        parm.u.ofdm.constellation = QAM_AUTO;
                        break;
                }
-               
                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:
-#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;
+               default:
                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;
                }
-               
-               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_timeout->stop();
        m_sec_sequence.current() = m_sec_sequence.begin();
 
        if (m_state != stateTuning)
@@ -1075,23 +1124,17 @@ RESULT eDVBFrontend::sendToneburst(int burst)
 {
 #if HAVE_DVB_API_VERSION < 3
        secMiniCmd cmd = SEC_MINI_NONE;
-       if ( burst == eDVBSatelliteDiseqcParameters::A )
-               cmd = SEC_MINI_A;
-       else if ( burst == eDVBSatelliteDiseqcParameters::B )
-               cmd = SEC_MINI_B;
-       if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd))
-               return -EINVAL;
 #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;
-       else
-       {
-               eDebug("unknown toneburst!");
+#if HAVE_DVB_API_VERSION < 3
+       if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd))
                return -EINVAL;
-       }
+#else
        if (::ioctl(m_fd, FE_DISEQC_SEND_BURST, cmd))
                return -EINVAL;
 #endif