removed testcode
[enigma2.git] / lib / dvb / frontend.cpp
index cdbf8a58f4cfebbc6a760def4d387888bf584e43..d4704a9d0305347ff01835bc0841b02458ce02f8 100644 (file)
@@ -284,6 +284,8 @@ eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok): m_type(-1)
        m_tuneTimer = new eTimer(eApp);
        CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop);
 
+       memset(m_data, 0xFFFF, sizeof(m_data));
+
        return;
 }
 
@@ -361,6 +363,62 @@ void eDVBFrontend::timeout()
                m_tuning = 0;
 }
 
+#ifndef FP_IOCTL_GET_ID
+#define FP_IOCTL_GET_ID 0
+#endif
+int eDVBFrontend::readInputpower()
+{
+       int power=0;
+//     if ( eSystemInfo::getInstance()->canMeasureLNBCurrent() )
+       {
+//             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());
+               }
+       }
+       return power;
+}
+
+bool eDVBFrontend::setSecSequencePos(int steps)
+{
+       eDebug("set sequence pos %d", steps);
+       if (!steps)
+               return false;
+       while( steps > 0 )
+       {
+               if (m_sec_sequence.current() != m_sec_sequence.end())
+                       ++m_sec_sequence.current();
+               --steps;
+       }
+       while( steps < 0 )
+       {
+               if (m_sec_sequence.current() != m_sec_sequence.begin() && m_sec_sequence.current() != m_sec_sequence.end())
+                       --m_sec_sequence.current();
+               ++steps;
+       }
+       return true;
+}
+
 void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
 {
        int delay=0;
@@ -369,29 +427,99 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                switch (m_sec_sequence.current()->cmd)
                {
                        case eSecCommand::SLEEP:
-                               delay = m_sec_sequence.current()->msec;
+                               delay = m_sec_sequence.current()++->msec;
+                               eDebug("[SEC] sleep %dms", delay);
+                               break;
+                       case eSecCommand::GOTO:
+                               if ( !setSecSequencePos(m_sec_sequence.current()->steps) )
+                                       ++m_sec_sequence.current();
                                break;
                        case eSecCommand::SET_VOLTAGE:
-                               setVoltage(m_sec_sequence.current()->voltage);
+                               eDebug("[SEC] setVoltage %d", m_sec_sequence.current()->voltage);
+                               setVoltage(m_sec_sequence.current()++->voltage);
                                break;
                        case eSecCommand::SET_TONE:
-                               setTone(m_sec_sequence.current()->tone);
+                               eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
+                               setTone(m_sec_sequence.current()++->tone);
                                break;
                        case eSecCommand::SEND_DISEQC:
                                sendDiseqc(m_sec_sequence.current()->diseqc);
+                               eDebugNoNewLine("sendDiseqc: ");
+                               for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
+                                   eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
+                               eDebug("[SEC] ");
+                               ++m_sec_sequence.current();
                                break;
                        case eSecCommand::SEND_TONEBURST:
-                               sendToneburst(m_sec_sequence.current()->toneburst);
+                               eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst);
+                               sendToneburst(m_sec_sequence.current()++->toneburst);
                                break;
                        case eSecCommand::SET_FRONTEND:
+                               eDebug("[SEC] setFrontend");
                                setFrontend();
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::MEASURE_IDLE_INPUTPOWER:
+                               m_idleInputpower = readInputpower();
+                               eDebug("[SEC] idleInputpower is %d", m_idleInputpower);
+                               ++m_sec_sequence.current();
                                break;
-                       case eSecCommand::IF_LOCK_GOTO:
-                       case eSecCommand::IF_NOT_LOCK_GOTO:
+                       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)
+                                       setSecSequencePos(m_sec_sequence.current()->steps);
+                               else
+                                       ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
+                       {
+                               eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
+                               const char *txt = cmd.direction ? "running" : "stopped";
+                               eDebug("[SEC] waiting for rotor %s", txt);
+                               eDebug("[SEC] %s %d, idle %d, delta %d",
+                                       txt,
+                                       m_runningInputpower,
+                                       m_idleInputpower,
+                                       cmd.deltaA);
+                               if ( (cmd.direction && abs(m_runningInputpower - m_idleInputpower) >= cmd.deltaA)
+                                       || (!cmd.direction && abs(m_runningInputpower - m_idleInputpower) <= cmd.deltaA) )
+                               {
+                                       ++cmd.okcount;
+                                       eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
+                                       if ( cmd.okcount > 1 )
+                                       {
+                                               eDebug("[SEC] rotor is %s", txt);
+                                               if (setSecSequencePos(cmd.steps))
+                                                       break;
+                                       }
+                               }
+                               else
+                               {
+                                       eDebug("[SEC] rotor not %s... reset counter.. increase timeout", txt);
+                                       --m_timeoutCount;
+                                       cmd.okcount=0;
+                               }
+                               ++m_sec_sequence.current();
+                               break;
+                       }
                        default:
-                               eDebug("unhandled sec command");
+                               ++m_sec_sequence.current();
+                               eDebug("[SEC] unhandled sec command");
                }
-               m_sec_sequence.current()++;
                m_tuneTimer->start(delay,true);
        }
 }
@@ -576,7 +704,7 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
        }
        }
 
-       m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 0) );
+       m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
        m_tuneTimer->start(0,true);
        m_sec_sequence.current() = m_sec_sequence.begin();
 
@@ -703,3 +831,24 @@ RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list)
        m_sec_sequence = list;
        return 0;
 }
+
+RESULT eDVBFrontend::getData(int num, int &data)
+{
+       if ( num < 7 )
+       {
+               data = m_data[num];
+               return 0;
+       }
+       return -EINVAL;
+}
+
+RESULT eDVBFrontend::setData(int num, int val)
+{
+       if ( num < 7 )
+       {
+               m_data[num] = val;
+               return 0;
+       }
+       return -EINVAL;
+}
+