more rotor stuff
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 26 May 2005 10:40:15 +0000 (10:40 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 26 May 2005 10:40:15 +0000 (10:40 +0000)
lib/dvb/frontend.cpp
lib/dvb/frontend.h
lib/dvb/sec.cpp
lib/dvb/sec.h

index 363775925eac3bcf8eff930047c1c2d7d9d7acd2..8a8e591f75fcb5cac7960378f72ebdf692c0f56c 100644 (file)
@@ -363,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;
@@ -371,14 +427,19 @@ 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("sleep %dms\n", 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);
+                               setVoltage(m_sec_sequence.current()++->voltage);
                                eDebug("setVoltage %d", m_sec_sequence.current()->voltage);
                                break;
                        case eSecCommand::SET_TONE:
-                               setTone(m_sec_sequence.current()->tone);
+                               setTone(m_sec_sequence.current()++->tone);
                                eDebug("setTone %d", m_sec_sequence.current()->tone);
                                break;
                        case eSecCommand::SEND_DISEQC:
@@ -387,21 +448,49 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
                                    eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
                                eDebug("");
+                               ++m_sec_sequence.current();
                                break;
                        case eSecCommand::SEND_TONEBURST:
-                               sendToneburst(m_sec_sequence.current()->toneburst);
+                               sendToneburst(m_sec_sequence.current()++->toneburst);
                                eDebug("sendToneburst: %d", m_sec_sequence.current()->toneburst);
                                break;
                        case eSecCommand::SET_FRONTEND:
                                eDebug("setFrontend");
                                setFrontend();
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::MEASURE_IDLE_INPUTPOWER:
+                               m_idleInputpower = readInputpower();
+                               eDebug("idleInputpower is %d", m_idleInputpower);
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
+                               m_runningInputpower = readInputpower();
+                               eDebug("runningInputpower is %d", m_runningInputpower);
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::SET_TIMEOUT:
+                               m_timeoutCount = m_sec_sequence.current()++->val;
+                               eDebug("set timeout %d", m_timeoutCount);
+                               break;
+                       case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
+                               m_data[5] = m_data[3];
+                               m_data[6] = m_data[4];
+                               eDebug("update current rotorparams %d", m_timeoutCount);
+                               ++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_LOCK_GOTO:
-                       case eSecCommand::IF_NOT_LOCK_GOTO:
+                       case eSecCommand::IF_RUNNING_GOTO:
+                       case eSecCommand::IF_STOPPED_GOTO:
                        default:
+                               ++m_sec_sequence.current();
                                eDebug("unhandled sec command");
                }
-               m_sec_sequence.current()++;
                m_tuneTimer->start(delay,true);
        }
 }
index e6beb680265b2446a43f65f7e0f039e1e54467d8..a0ca08ece453afea50069715af335cca15625727 100644 (file)
@@ -53,17 +53,25 @@ class eDVBFrontend: public iDVBFrontend, public Object
 
        eSecCommandList m_sec_sequence;
 
-       int m_data[5]; /* when satellite frontend then
+       int m_data[7]; /* when satellite frontend then
                data[0] = lastcsw -> state of the committed switch
                data[1] = lastucsw -> state of the uncommitted switch
                data[2] = lastToneburst -> current state of toneburst switch
-               data[3] = lastRotorCmd -> last sent rotor cmd
-               data[4] = curRotorPos -> current Rotor Position */
+               data[3] = newRotorCmd -> last sent rotor cmd
+               data[4] = newRotorPos -> current Rotor Position
+               data[5] = curRotorCmd
+               data[6] = curRotorPos */
+
+       int m_idleInputpower;
+       int m_runningInputpower;
+       int m_timeoutCount; // needed for timeout
 
        void feEvent(int);
        void timeout();
        void tuneLoop();  // called by m_tuneTimer
        void setFrontend();
+       int readInputpower();
+       bool setSecSequencePos(int steps);
 public:
        eDVBFrontend(int adap, int fe, int &ok);        
        virtual ~eDVBFrontend();
index edecca902fa12bc779d4d9a8703514cbc6e32cf7..041d1fbcde19c88c65e4b8b212037a524121ded0 100644 (file)
@@ -70,8 +70,8 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                        frontend.getData(0, lastcsw);
                        frontend.getData(1, lastucsw);
                        frontend.getData(2, lastToneburst);
-                       frontend.getData(3, lastRotorCmd);
-                       frontend.getData(4, curRotorPos);
+                       frontend.getData(5, lastRotorCmd);
+                       frontend.getData(6, curRotorPos);
 
                        if ( sat.frequency > lnb_param.m_lof_threshold )
                                hi = 1;
@@ -325,8 +325,23 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                }
                                                if ( rotor_param.m_inputpower_parameters.m_use )
                                                { // use measure rotor input power to detect rotor state
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18) ); // always turn with high voltage
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50sec after voltage change
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 8) );  // 2 seconds rotor start timout
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_RUNNING_GOTO, +3 ) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +8 ) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 240) );  // 1 minute running timeout
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_STOPPED_GOTO, +3 ) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
                                                        frontend.setData(3, RotorCmd);
                                                        frontend.setData(4, sat.orbital_position);
                                                }
index 645f8b152cb6540ff6a988ab10c7713ea6388d56..71fff6a5d2e16380e918b3c239718e77fd902df6 100644 (file)
@@ -9,13 +9,18 @@ class eSecCommand
 {
 public:
        enum {
-               NONE, SLEEP, SET_VOLTAGE, SET_TONE,
-               SEND_DISEQC, SEND_TONEBURST, IF_LOCK_GOTO, IF_NOT_LOCK_GOTO,
-               MEASURE_IDLE_INPUTPOWER, SET_FRONTEND
+               NONE, SLEEP, SET_VOLTAGE, SET_TONE, GOTO,
+               SEND_DISEQC, SEND_TONEBURST, SET_FRONTEND,
+               MEASURE_IDLE_INPUTPOWER, MEASURE_RUNNING_INPUTPOWER,
+               IF_TIMEOUT_GOTO, IF_RUNNING_GOTO, IF_STOPPED_GOTO,
+               UPDATE_CURRENT_ROTORPARAMS, SET_TIMEOUT, 
        };
        int cmd;
        union
        {
+               int val;
+               int steps;
+               int timeout;
                int voltage;
                int tone;
                int toneburst;
@@ -26,7 +31,7 @@ public:
                :cmd(cmd)
        {}
        eSecCommand( int cmd, int val )
-               :cmd(cmd), voltage(val)
+               :cmd(cmd), val(val)
        {}
        eSecCommand( int cmd, eDVBDiseqcCommand diseqc )
                :cmd(cmd), diseqc(diseqc)