improove motor turning without power measure
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Mon, 4 Aug 2008 23:24:10 +0000 (23:24 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Mon, 4 Aug 2008 23:24:10 +0000 (23:24 +0000)
lib/dvb/frontend.cpp
lib/dvb/sec.cpp
lib/dvb/sec.h

index 79c9ad0bccbc9556b3c4ab0ad53aca06292a4979..2d38dc25473415c7911132a0ceade2a0c083fb0e 100644 (file)
@@ -586,6 +586,14 @@ eDVBFrontend::~eDVBFrontend()
 
 void eDVBFrontend::feEvent(int w)
 {
 
 void eDVBFrontend::feEvent(int w)
 {
+       eDVBFrontend *sec_fe = this;
+       long tmp = m_data[LINKED_PREV_PTR];
+       while (tmp != -1)
+       {
+               eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)tmp;
+               sec_fe = linked_fe->m_frontend;
+               sec_fe->getData(LINKED_NEXT_PTR, tmp);
+       }
        while (1)
        {
 #if HAVE_DVB_API_VERSION < 3
        while (1)
        {
 #if HAVE_DVB_API_VERSION < 3
@@ -623,22 +631,12 @@ void eDVBFrontend::feEvent(int w)
                                state = stateTuning;
                        else
                        {
                                state = stateTuning;
                        else
                        {
-                               eDVBFrontend *sec_fe = this;
-                               long tmp = m_data[LINKED_PREV_PTR];
-
                                eDebug("stateLostLock");
                                state = stateLostLock;
                                eDebug("stateLostLock");
                                state = stateLostLock;
-
-                               while (tmp != -1)
-                               {
-                                       eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)tmp;
-                                       sec_fe = linked_fe->m_frontend;
-                                       sec_fe->getData(LINKED_NEXT_PTR, tmp);
-                               }
                                sec_fe->m_data[CSW] = sec_fe->m_data[UCSW] = sec_fe->m_data[TONEBURST] = -1; // reset diseqc
                        }
                }
                                sec_fe->m_data[CSW] = sec_fe->m_data[UCSW] = sec_fe->m_data[TONEBURST] = -1; // reset diseqc
                        }
                }
-               if (m_state != state)
+               if (m_state != state && ((m_idleInputpower[0] && m_idleInputpower[1]) || (sec_fe->m_data[ROTOR_POS] == sec_fe->m_data[NEW_ROTOR_POS])))
                {
                        m_state = state;
                        m_stateChanged(this);
                {
                        m_state = state;
                        m_stateChanged(this);
@@ -1457,7 +1455,6 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                if (!m_timeoutCount)
                                {
                                        eDebug("[SEC] rotor timout");
                                if (!m_timeoutCount)
                                {
                                        eDebug("[SEC] rotor timout");
-                                       m_sec->setRotorMoving(false);
                                        setSecSequencePos(m_sec_sequence.current()->steps);
                                }
                                else
                                        setSecSequencePos(m_sec_sequence.current()->steps);
                                }
                                else
@@ -1495,25 +1492,40 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                        }
                        case eSecCommand::IF_TUNER_LOCKED_GOTO:
                        {
                        }
                        case eSecCommand::IF_TUNER_LOCKED_GOTO:
                        {
+                               int signal = 0;
+                               int isLocked = readFrontendData(locked);
+                               m_idleInputpower[0] = m_idleInputpower[1] = 0;
                                eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
                                eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
-                               if (readFrontendData(locked))
+                               if (isLocked && ((abs((signal = readFrontendData(signalQualitydB)) - cmd.lastSignal) < 50) || !cmd.lastSignal))
                                {
                                {
-                                       eDebug("[SEC] locked step %d ok", cmd.okcount);
+                                       if (cmd.lastSignal)
+                                               eDebug("[SEC] locked step %d ok (%d %d)", cmd.okcount, signal, cmd.lastSignal);
+                                       else
+                                       {
+                                               eDebug("[SEC] locked step %d ok", cmd.okcount);
+                                               cmd.lastSignal = signal;
+                                       }
                                        ++cmd.okcount;
                                        ++cmd.okcount;
-                                       if (cmd.okcount > 12)
+                                       if (cmd.okcount > 4)
                                        {
                                        {
-                                               eDebug("ok > 12 .. goto %d\n",m_sec_sequence.current()->steps);
+                                               eDebug("ok > 4 .. goto %d\n",cmd.steps);
                                                setSecSequencePos(cmd.steps);
                                                setSecSequencePos(cmd.steps);
+                                               m_state = stateLock;
+                                               m_stateChanged(this);
                                                break;
                                        }
                                }
                                else
                                {
                                                break;
                                        }
                                }
                                else
                                {
-                                       eDebug("[SEC] rotor locked step %d failed", cmd.okcount);
+                                       if (isLocked)
+                                               eDebug("[SEC] rotor locked step %d failed (oldSignal %d, curSignal %d)", cmd.okcount, signal, cmd.lastSignal);
+                                       else
+                                               eDebug("[SEC] rotor locked step %d failed (not locked)", cmd.okcount);
                                        --m_timeoutCount;
                                        if (!m_timeoutCount && m_retryCount > 0)
                                                --m_retryCount;
                                        cmd.okcount=0;
                                        --m_timeoutCount;
                                        if (!m_timeoutCount && m_retryCount > 0)
                                                --m_retryCount;
                                        cmd.okcount=0;
+                                       cmd.lastSignal=0;
                                }
                                ++m_sec_sequence.current();
                                break;
                                }
                                ++m_sec_sequence.current();
                                break;
@@ -1523,6 +1535,14 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
                                ++m_sec_sequence.current();
                                break;
                                eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
                                ++m_sec_sequence.current();
                                break;
+                       case eSecCommand::SET_ROTOR_MOVING:
+                               m_sec->setRotorMoving(true);
+                               ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::SET_ROTOR_STOPPED:
+                               m_sec->setRotorMoving(false);
+                               ++m_sec_sequence.current();
+                               break;
                        case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
                        {
                                int idleInputpower = m_idleInputpower[ (sec_fe_data[CUR_VOLTAGE]&1) ? 0 : 1];
                        case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
                        {
                                int idleInputpower = m_idleInputpower[ (sec_fe_data[CUR_VOLTAGE]&1) ? 0 : 1];
@@ -1540,7 +1560,6 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                        eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
                                        if ( cmd.okcount > 6 )
                                        {
                                        eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
                                        if ( cmd.okcount > 6 )
                                        {
-                                               m_sec->setRotorMoving(cmd.direction);
                                                eDebug("[SEC] rotor is %s", txt);
                                                if (setSecSequencePos(cmd.steps))
                                                        break;
                                                eDebug("[SEC] rotor is %s", txt);
                                                if (setSecSequencePos(cmd.steps))
                                                        break;
index 3d8084c84d2f0d3a0bf8624fa326393560bc421b..dccffaf21a8b31e0cf5cb1d7621606a3c505e7db 100644 (file)
@@ -730,9 +730,10 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );  // check if rotor has started
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) );  // timeout .. we assume now the rotor is already at the correct position
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );  // goto loop start
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );  // check if rotor has started
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) );  // timeout .. we assume now the rotor is already at the correct position
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );  // goto loop start
-                                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO, turn_fast ? 9 : 8 ) );  // timeout .. we assume now the rotor is already at the correct position  
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO, turn_fast ? 10 : 9 ) );  // timeout .. we assume now the rotor is already at the correct position 
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) );  // goto loop start
 ////////////////////
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -8) );  // goto loop start
 ////////////////////
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
                                                        if (turn_fast)
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*20) );  // 2 minutes running timeout
                                                        if (turn_fast)
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*20) );  // 2 minutes running timeout
@@ -747,6 +748,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
 /////////////////////
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
 /////////////////////
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
                                                }
                                                else
                                                {  // use normal turning mode
                                                }
                                                else
                                                {  // use normal turning mode
@@ -762,6 +764,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
 
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
 
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_MOVING) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
 
                                                        compare.voltage = voltage;
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
 
                                                        compare.voltage = voltage;
@@ -787,6 +790,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) );  // goto loop start
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -3) );  // goto loop start
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
                                                        sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_STOPPED) );
                                                }
                                                sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
                                                sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
                                                }
                                                sec_fe->setData(eDVBFrontend::NEW_ROTOR_CMD, RotorCmd);
                                                sec_fe->setData(eDVBFrontend::NEW_ROTOR_POS, sat.orbital_position);
index 2f30e7817f3e2df4df770d675718a436c63f6701..35213b39e1e65ea986f62e090efa0811e0b842d9 100644 (file)
@@ -23,12 +23,17 @@ public:
                IF_ROTORPOS_VALID_GOTO,
                IF_TUNER_LOCKED_GOTO,
                IF_TONE_GOTO, IF_NOT_TONE_GOTO,
                IF_ROTORPOS_VALID_GOTO,
                IF_TUNER_LOCKED_GOTO,
                IF_TONE_GOTO, IF_NOT_TONE_GOTO,
-               START_TUNE_TIMEOUT
+               START_TUNE_TIMEOUT,
+               SET_ROTOR_MOVING,
+               SET_ROTOR_STOPPED
        };
        int cmd;
        struct rotor
        {
        };
        int cmd;
        struct rotor
        {
-               int deltaA;   // difference in mA between running and stopped rotor
+               union {
+                       int deltaA;   // difference in mA between running and stopped rotor
+                       int lastSignal;
+               };
                int okcount;  // counter
                int steps;    // goto steps
                int direction;
                int okcount;  // counter
                int steps;    // goto steps
                int direction;