physdev path start with /, like in hotplug. add dvd drive into devicedb. fix scanner...
[enigma2.git] / lib / dvb / frontend.cpp
index a74e65cab4d9979ec4275e17b3efab0ebd7bbd1d..aae7bbc2d58f239d66459c83c417476f0367a8c2 100644 (file)
@@ -587,6 +587,10 @@ int eDVBFrontend::closeFrontend(bool force)
        if (m_fd >= 0)
        {
                eDebugNoSimulate("close frontend %d", m_dvbid);
+               if (m_data[SATCR] != -1)
+               {
+                       turnOffSatCR(m_data[SATCR]);
+               }
                setTone(iDVBFrontend::toneOff);
                setVoltage(iDVBFrontend::voltageOff);
                m_tuneTimer->stop();
@@ -695,6 +699,12 @@ void eDVBFrontend::timeout()
 
 #define INRANGE(X,Y,Z) (((X<=Y) && (Y<=Z))||((Z<=Y) && (Y<=X)) ? 1 : 0)
 
+/* unsigned 32 bit division */
+static inline uint32_t fe_udiv(uint32_t a, uint32_t b)
+{
+       return (a + b / 2) / b;
+}
+
 int eDVBFrontend::readFrontendData(int type)
 {
        switch(type)
@@ -710,23 +720,16 @@ int eDVBFrontend::readFrontendData(int type)
                        return ber;
                }
                case signalQuality:
-               {
-                       uint16_t snr=0;
-                       if (!m_simulate)
-                       {
-                               if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
-                                       eDebug("FE_READ_SNR failed (%m)");
-                       }
-                       return snr;
-               }
                case signalQualitydB: /* this will move into the driver */
                {
+                       int sat_max = 1600; // for stv0288 / bsbe2
+                       int ret = 0x12345678;
                        uint16_t snr=0;
                        if (m_simulate)
                                return 0;
                        if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
                                eDebug("FE_READ_SNR failed (%m)");
-                       if (!strcmp(m_description, "BCM4501 (internal)"))
+                       else if (!strcmp(m_description, "BCM4501 (internal)"))
                        {
                                float SDS_SNRE = snr << 16;
                                float snr_in_db;
@@ -781,15 +784,16 @@ int eDVBFrontend::readFrontendData(int type)
                                        snr_in_db = fval1;
                                }
 #endif
-                               return (int)(snr_in_db * 100.0);
+                               sat_max = 1750;
+                               ret = (int)(snr_in_db * 100);
                        }
                        else if (strstr(m_description, "Alps BSBE1 C01A") ||
                                !strcmp(m_description, "Alps -S(STV0288)"))
                        {
                                if (snr == 0)
-                                       return 0;
+                                       ret = 0;
                                else if (snr == 0xFFFF) // i think this should not happen
-                                       return 100*100;
+                                       ret = 100*100;
                                else
                                {
                                        enum { REALVAL, REGVAL };
@@ -817,28 +821,60 @@ int eDVBFrontend::readFrontendData(int type)
                                                        else
                                                                Imin = i;
                                                }
-                                               return (((regval - CN_lookup[Imin][REGVAL])
+                                               ret = (((regval - CN_lookup[Imin][REGVAL])
                                                                * (CN_lookup[Imax][REALVAL] - CN_lookup[Imin][REALVAL])
                                                                / (CN_lookup[Imax][REGVAL] - CN_lookup[Imin][REGVAL]))
                                                                + CN_lookup[Imin][REALVAL]) * 10;
                                        }
-                                       return 100;
+                                       else
+                                               ret = 100;
                                }
-                               return 0;
                        }
                        else if (!strcmp(m_description, "Alps BSBE1 702A") ||  // some frontends with STV0299
                                !strcmp(m_description, "Alps -S") ||
                                !strcmp(m_description, "Philips -S") ||
                                !strcmp(m_description, "LG -S") )
                        {
-                               float snr_in_db=(snr-39075)/1764.7;
-                               return (int)(snr_in_db * 100.0);
+                               sat_max = 1500;
+                               ret = (int)((snr-39075)/17.647);
                        } else if (!strcmp(m_description, "Alps BSBE2"))
                        {
-                               return (int)((snr >> 7) * 10.0);
-                       } /* else
+                               ret = (int)((snr >> 7) * 10);
+                       } else if (!strcmp(m_description, "Philips CU1216Mk3"))
+                       {
+                               int mse = (~snr) & 0xFF;
+                               switch (parm_u_qam_modulation) {
+                               case QAM_16: ret = fe_udiv(1950000, (32 * mse) + 138) + 1000; break;
+                               case QAM_32: ret = fe_udiv(2150000, (40 * mse) + 500) + 1350; break;
+                               case QAM_64: ret = fe_udiv(2100000, (40 * mse) + 500) + 1250; break;
+                               case QAM_128: ret = fe_udiv(1850000, (38 * mse) + 400) + 1380; break;
+                               case QAM_256: ret = fe_udiv(1800000, (100 * mse) + 40) + 2030; break;
+                               default: break;
+                               }
+                       } else if (!strcmp(m_description, "Philips TU1216"))
+                       {
+                               snr = 0xFF - (snr & 0xFF);
+                               if (snr != 0)
+                                       ret = 10 * (int)(-100 * (log10(snr) - log10(255)));
+                       }
+
+                       if (type == signalQuality)
+                       {
+                               if (ret == 0x12345678) // no snr db calculation avail.. return untouched snr value..
+                                       return snr;
+                               switch(m_type)
+                               {
+                                       case feSatellite:
+                                               return ret >= sat_max ? 65536 : ret * 65536 / sat_max;
+                                       case feCable: // we assume a max of 42db here
+                                               return ret >= 4200 ? 65536 : ret * 65536 / 4200;
+                                       case feTerrestrial: // we assume a max of 24db here
+                                               return ret >= 2400 ? 65536 : ret * 65536 / 2400;
+                               }
+                       }
+/* else
                                eDebug("no SNR dB calculation for frontendtype %s yet", m_description); */
-                       return 0x12345678;
+                       return ret;
                }
                case signalPower:
                {
@@ -1827,6 +1863,20 @@ RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm,
        res = m_sec->prepare(*this, parm, feparm, 1 << m_slotid, tunetimeout);
        if (!res)
        {
+#if HAVE_DVB_API_VERSION >= 3
+               eDebugNoSimulate("prepare_sat System %d Freq %d Pol %d SR %d INV %d FEC %d orbpos %d system %d modulation %d pilot %d, rolloff %d",
+                       feparm.system,
+                       feparm.frequency,
+                       feparm.polarisation,
+                       feparm.symbol_rate,
+                       feparm.inversion,
+                       feparm.fec,
+                       feparm.orbital_position,
+                       feparm.system,
+                       feparm.modulation,
+                       feparm.pilot,
+                       feparm.rolloff);
+#else
                eDebugNoSimulate("prepare_sat System %d Freq %d Pol %d SR %d INV %d FEC %d orbpos %d",
                        feparm.system,
                        feparm.frequency,
@@ -1835,6 +1885,7 @@ RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm,
                        feparm.inversion,
                        feparm.fec,
                        feparm.orbital_position);
+#endif
                parm_u_qpsk_symbol_rate = feparm.symbol_rate;
                switch (feparm.inversion)
                {
@@ -2505,3 +2556,42 @@ arg_error:
                "eDVBFrontend::setSlotInfo must get a tuple with first param slotid, second param slot description and third param enabled boolean");
        return false;
 }
+
+RESULT eDVBFrontend::turnOffSatCR(int satcr)
+{
+       eSecCommandList sec_sequence;
+       // check if voltage is disabled
+       eSecCommand::pair compare;
+       compare.steps = +9;     //nothing to do
+       compare.voltage = iDVBFrontend::voltageOff;
+       sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
+       sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
+       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50 ) );
+
+       sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18_5) );
+       sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
+       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );
+
+       eDVBDiseqcCommand diseqc;
+       memset(diseqc.data, 0, MAX_DISEQC_LENGTH);
+       diseqc.len = 5;
+       diseqc.data[0] = 0xE0;
+       diseqc.data[1] = 0x10;
+       diseqc.data[2] = 0x5A;
+       diseqc.data[3] = satcr << 5;
+       diseqc.data[4] = 0x00;
+
+       sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
+       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50+20+14*diseqc.len) );
+       sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
+       setSecSequence(sec_sequence);
+       return 0;
+}
+
+RESULT eDVBFrontend::ScanSatCR()
+{
+       setFrontend();
+       usleep(20000);
+       setTone(iDVBFrontend::toneOff);
+       return 0;
+}