add stv0299 snr to dB Calculation (thx to adenin for this)
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Tue, 12 Jun 2007 22:37:52 +0000 (22:37 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Tue, 12 Jun 2007 22:37:52 +0000 (22:37 +0000)
fallback to normal SNR when no SNR to dB calculation is available

lib/dvb/frontend.cpp
lib/python/Components/Converter/FrontendInfo.py

index 4df362e..9250764 100644 (file)
@@ -631,36 +631,50 @@ int eDVBFrontend::readFrontendData(int type)
                        uint16_t snr=0;
                        if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
                                eDebug("FE_READ_SNR failed (%m)");
-                       unsigned int SDS_SNRE = snr << 16;
-                       
-                       static float SNR_COEFF[6] = {
-                               100.0 / 4194304.0,
-                               -7136.0 / 4194304.0,
-                               197418.0 / 4194304.0,
-                               -2602183.0 / 4194304.0,
-                               20377212.0 / 4194304.0,
-                               -37791203.0 / 4194304.0,
-                       };
+                       if (!strcmp(m_description, "BCM4501 (internal)"))
+                       {
+                               unsigned int SDS_SNRE = snr << 16;
+
+                               static float SNR_COEFF[6] = {
+                                       100.0 / 4194304.0,
+                                       -7136.0 / 4194304.0,
+                                       197418.0 / 4194304.0,
+                                       -2602183.0 / 4194304.0,
+                                       20377212.0 / 4194304.0,
+                                       -37791203.0 / 4194304.0,
+                               };
                        
-                       float fval1, fval2, snr_in_db;
-                       int i;
-                       fval1 = 12.44714 - (2.0 * log10(SDS_SNRE / 256.0));
-                       fval2 = pow(10.0, fval1)-1;
-                       fval1 = 10.0 * log10(fval2);
+                               float fval1, fval2, snr_in_db;
+                               int i;
+                               fval1 = 12.44714 - (2.0 * log10(SDS_SNRE / 256.0));
+                               fval2 = pow(10.0, fval1)-1;
+                               fval1 = 10.0 * log10(fval2);
                        
-                       if (fval1 < 10.0)
-                       {
-                               fval2 = SNR_COEFF[0];
-                               for (i=0; i<6; ++i)
+                               if (fval1 < 10.0)
                                {
-                                       fval2 *= fval1;
-                                       fval2 += SNR_COEFF[i];
+                                       fval2 = SNR_COEFF[0];
+                                       for (i=0; i<6; ++i)
+                                       {
+                                               fval2 *= fval1;
+                                               fval2 += SNR_COEFF[i];
+                                       }
+                                       fval1 = fval2;
                                }
-                               fval1 = fval2;
-                       }
-                       snr_in_db = fval1;
+                               snr_in_db = fval1;
                        
-                       return (int)(snr_in_db * 100.0);
+                               return (int)(snr_in_db * 100.0);
+                       }
+                       else if (!strcmp(m_description, "Alps BSBE1 702A") ||  // some frontends with STV0299
+                               !strcmp(m_description, "Alps -S") ||
+                               !strcmp(m_description, "Philips -S") ||
+                               !strcmp(m_description, "LG -S") )
+                       {
+                               float snr_in_db=(snr-39075)/1764.7;
+                               return (int)(snr_in_db * 100.0);
+                       }
+                       else
+                               eDebug("no SNR dB caluclation for frontendtype %s yet", m_description);
+                       return 0x12345678;
                }
                case signalQuality:
                {
@@ -710,6 +724,18 @@ void PutToDict(ePyObject &dict, const char*key, long value)
                eDebug("could not create PyObject for %s", key);
 }
 
+void PutToDict(ePyObject &dict, const char*key, ePyObject item)
+{
+       if (item)
+       {
+               if (PyDict_SetItemString(dict, key, item))
+                       eDebug("put %s to dict failed", key);
+               Py_DECREF(item);
+       }
+       else
+               eDebug("invalid PyObject for %s", key);
+}
+
 void PutToDict(ePyObject &dict, const char*key, const char *value)
 {
        ePyObject item = PyString_FromString(value);
@@ -1038,7 +1064,15 @@ void eDVBFrontend::getFrontendStatus(ePyObject dest)
                PutToDict(dest, "tuner_synced", readFrontendData(synced));
                PutToDict(dest, "tuner_bit_error_rate", readFrontendData(bitErrorRate));
                PutToDict(dest, "tuner_signal_power", readFrontendData(signalPower));
-               PutToDict(dest, "tuner_signal_power_db", readFrontendData(signalPowerdB));
+               int sigPowerdB = readFrontendData(signalPowerdB);
+               if (sigPowerdB == 0x12345678) // not support yet
+               {
+                       ePyObject obj=Py_None;
+                       Py_INCREF(obj);
+                       PutToDict(dest, "tuner_signal_power_db", obj);
+               }
+               else
+                       PutToDict(dest, "tuner_signal_power_db", sigPowerdB);
                PutToDict(dest, "tuner_signal_quality", readFrontendData(signalQuality));
        }
 }
index 34d55be..6377d68 100644 (file)
@@ -24,6 +24,7 @@ class FrontendInfo(Converter, object):
        @cached
        def getText(self):
                assert self.type != self.LOCK, "the text output of FrontendInfo cannot be used for lock info"
+               percent = None
                if self.type == self.BER: # as count
                        count = self.source.ber
                        if count is not None:
@@ -35,9 +36,11 @@ class FrontendInfo(Converter, object):
                elif self.type == self.SNR:
                        percent = self.source.snr
                elif self.type == self.SNRdB:
-                       if self.source.snr_db is None:
-                               return "N/A"
-                       return "%3.02f dB" % (self.source.snr_db / 100.0)
+                       if self.source.snr_db is not None:
+                               return "%3.02f dB" % (self.source.snr_db / 100.0)
+                       elif self.source.snr is not None: #fallback to normal SNR...
+                               percent = self.source.snr
+                               return "SNR:%d %%" % (percent * 100 / 65536)
                if percent is None:
                        return "N/A"