much better motor turning without possibility of power measurement
authorghost <andreas.monzner@multimedia-labs.de>
Wed, 12 Aug 2009 17:16:03 +0000 (19:16 +0200)
committerghost <andreas.monzner@multimedia-labs.de>
Wed, 12 Aug 2009 17:16:03 +0000 (19:16 +0200)
lib/dvb/frontend.cpp
lib/dvb/frontend.h
lib/dvb/sec.cpp

index e5e83b42cd477fdb0e775a866a0b0ed5cfc148ad..9b64f697c236b9b484fa8ff45135c05d8a238a9d 100644 (file)
@@ -652,12 +652,6 @@ void eDVBFrontend::feEvent(int w)
                if (res && (errno == EAGAIN))
                        break;
 
                if (res && (errno == EAGAIN))
                        break;
 
-               if (res)
-               {
-                       eWarning("FE_GET_EVENT failed! %m");
-                       return;
-               }
-
                if (w < 0)
                        continue;
 
                if (w < 0)
                        continue;
 
@@ -1432,14 +1426,18 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                sec_fe->sendToneburst(m_sec_sequence.current()++->toneburst);
                                break;
                        case eSecCommand::SET_FRONTEND:
                                sec_fe->sendToneburst(m_sec_sequence.current()++->toneburst);
                                break;
                        case eSecCommand::SET_FRONTEND:
-                               eDebugNoSimulate("[SEC] setFrontend");
-                               setFrontend();
-                               ++m_sec_sequence.current();
+                       {
+                               int enableEvents = (m_sec_sequence.current()++)->val;
+                               eDebugNoSimulate("[SEC] setFrontend %d", enableEvents);
+                               setFrontend(enableEvents);
                                break;
                                break;
+                       }
                        case eSecCommand::START_TUNE_TIMEOUT:
                        {
                        case eSecCommand::START_TUNE_TIMEOUT:
                        {
+                               int tuneTimeout = m_sec_sequence.current()->timeout;
+                               eDebugNoSimulate("[SEC] startTuneTimeout %d", tuneTimeout);
                                if (!m_simulate)
                                if (!m_simulate)
-                                       m_timeout->start(m_sec_sequence.current()->timeout, 1);
+                                       m_timeout->start(tuneTimeout, 1);
                                ++m_sec_sequence.current();
                                break;
                        }
                                ++m_sec_sequence.current();
                                break;
                        }
@@ -1497,23 +1495,27 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                int signal = 0;
                                int isLocked = readFrontendData(locked);
                                m_idleInputpower[0] = m_idleInputpower[1] = 0;
                                int signal = 0;
                                int isLocked = readFrontendData(locked);
                                m_idleInputpower[0] = m_idleInputpower[1] = 0;
-                               if (isLocked && ((abs((signal = readFrontendData(signalQualitydB)) - cmd.lastSignal) < 50) || !cmd.lastSignal))
+                               --m_timeoutCount;
+                               if (!m_timeoutCount && m_retryCount > 0)
+                                       --m_retryCount;
+                               if (isLocked && ((abs((signal = readFrontendData(signalQualitydB)) - cmd.lastSignal) < 40) || !cmd.lastSignal))
                                {
                                        if (cmd.lastSignal)
                                                eDebugNoSimulate("[SEC] locked step %d ok (%d %d)", cmd.okcount, signal, cmd.lastSignal);
                                        else
                                        {
                                                eDebugNoSimulate("[SEC] locked step %d ok", cmd.okcount);
                                {
                                        if (cmd.lastSignal)
                                                eDebugNoSimulate("[SEC] locked step %d ok (%d %d)", cmd.okcount, signal, cmd.lastSignal);
                                        else
                                        {
                                                eDebugNoSimulate("[SEC] locked step %d ok", cmd.okcount);
-                                               cmd.lastSignal = signal;
+                                               if (!cmd.okcount)
+                                                       cmd.lastSignal = signal;
                                        }
                                        ++cmd.okcount;
                                        if (cmd.okcount > 4)
                                        {
                                        }
                                        ++cmd.okcount;
                                        if (cmd.okcount > 4)
                                        {
-                                               eDebugNoSimulate("ok > 4 .. goto %d\n",cmd.steps);
+                                               eDebugNoSimulate("ok > 4 .. goto %d\n", cmd.steps);
                                                setSecSequencePos(cmd.steps);
                                                m_state = stateLock;
                                                m_stateChanged(this);
                                                setSecSequencePos(cmd.steps);
                                                m_state = stateLock;
                                                m_stateChanged(this);
-                                               feEvent(-1);
+                                               feEvent(-1); // flush events
                                                m_sn->start();
                                                break;
                                        }
                                                m_sn->start();
                                                break;
                                        }
@@ -1524,9 +1526,6 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                                eDebugNoSimulate("[SEC] rotor locked step %d failed (oldSignal %d, curSignal %d)", cmd.okcount, signal, cmd.lastSignal);
                                        else
                                                eDebugNoSimulate("[SEC] rotor locked step %d failed (not locked)", cmd.okcount);
                                                eDebugNoSimulate("[SEC] rotor locked step %d failed (oldSignal %d, curSignal %d)", cmd.okcount, signal, cmd.lastSignal);
                                        else
                                                eDebugNoSimulate("[SEC] rotor locked step %d failed (not locked)", cmd.okcount);
-                                       --m_timeoutCount;
-                                       if (!m_timeoutCount && m_retryCount > 0)
-                                               --m_retryCount;
                                        cmd.okcount=0;
                                        cmd.lastSignal=0;
                                }
                                        cmd.okcount=0;
                                        cmd.lastSignal=0;
                                }
@@ -1558,6 +1557,9 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                }
                                int idleInputpower = m_idleInputpower[ (sec_fe_data[CUR_VOLTAGE]&1) ? 0 : 1];
                                const char *txt = cmd.direction ? "running" : "stopped";
                                }
                                int idleInputpower = m_idleInputpower[ (sec_fe_data[CUR_VOLTAGE]&1) ? 0 : 1];
                                const char *txt = cmd.direction ? "running" : "stopped";
+                               --m_timeoutCount;
+                               if (!m_timeoutCount && m_retryCount > 0)
+                                       --m_retryCount;
                                eDebugNoSimulate("[SEC] waiting for rotor %s %d, idle %d, delta %d",
                                        txt,
                                        m_runningInputpower,
                                eDebugNoSimulate("[SEC] waiting for rotor %s %d, idle %d, delta %d",
                                        txt,
                                        m_runningInputpower,
@@ -1578,9 +1580,6 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                else
                                {
                                        eDebugNoSimulate("[SEC] rotor not %s... reset counter.. increase timeout", txt);
                                else
                                {
                                        eDebugNoSimulate("[SEC] rotor not %s... reset counter.. increase timeout", txt);
-                                       --m_timeoutCount;
-                                       if (!m_timeoutCount && m_retryCount > 0)
-                                               --m_retryCount;
                                        cmd.okcount=0;
                                }
                                ++m_sec_sequence.current();
                                        cmd.okcount=0;
                                }
                                ++m_sec_sequence.current();
@@ -1696,13 +1695,14 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                tuneLoop();
 }
 
                tuneLoop();
 }
 
-void eDVBFrontend::setFrontend()
+void eDVBFrontend::setFrontend(bool recvEvents)
 {
        if (!m_simulate)
        {
                eDebug("setting frontend %d", m_dvbid);
 {
        if (!m_simulate)
        {
                eDebug("setting frontend %d", m_dvbid);
-               m_sn->start();
-               feEvent(-1);
+               if (recvEvents)
+                       m_sn->start();
+               feEvent(-1); // flush events
                if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
                {
                        perror("FE_SET_FRONTEND failed");
                if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
                {
                        perror("FE_SET_FRONTEND failed");
index b6e3b6a4299d734e7271604e206438cea0acd8fc..e1556bd99fccd5e655397b88c0aacc37f7ba47ad 100644 (file)
@@ -105,7 +105,7 @@ private:
        void feEvent(int);
        void timeout();
        void tuneLoop();  // called by m_tuneTimer
        void feEvent(int);
        void timeout();
        void tuneLoop();  // called by m_tuneTimer
-       void setFrontend();
+       void setFrontend(bool recvEvents=true);
        bool setSecSequencePos(int steps);
        static int PriorityOrder;
 public:
        bool setSecSequencePos(int steps);
        static int PriorityOrder;
 public:
index 83092d8e8e5309f72f06626fd9ead9a45c7eabb3..71c8a19cfd10a3ed5874a13c8a4a46ecae79e667 100644 (file)
@@ -754,6 +754,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                }
                                                if(lnb_param.SatCR_idx == -1)
                                                {
                                                }
                                                if(lnb_param.SatCR_idx == -1)
                                                {
+                                                       int mrt = m_params[MOTOR_RUNNING_TIMEOUT]; // in seconds!
                                                        if ( rotor_param.m_inputpower_parameters.m_use )
                                                        { // use measure rotor input power to detect rotor state
                                                                bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed);
                                                        if ( rotor_param.m_inputpower_parameters.m_use )
                                                        { // use measure rotor input power to detect rotor state
                                                                bool turn_fast = need_turn_fast(rotor_param.m_inputpower_parameters.m_turning_speed);
@@ -800,7 +801,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                                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_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
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*20) );  // mrt is in seconds... our SLEEP time is 50ms.. so * 20
        // rotor running loop
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
        // rotor running loop
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
@@ -815,6 +816,17 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                        }
                                                        else
                                                        {  // use normal turning mode
                                                        }
                                                        else
                                                        {  // use normal turning mode
+                                                               if (curRotorPos != -1)
+                                                               {               
+                                                                       mrt = abs(curRotorPos - sat.orbital_position);
+                                                                       if (mrt > 1800)
+                                                                               mrt = 3600 - mrt;
+                                                                       if (mrt % 10)
+                                                                               mrt += 10; // round a little bit
+                                                                       mrt *= 2000;  // (we assume a very slow rotor with just 0.5 degree per second here)
+                                                                       mrt /= 10000;
+                                                                       mrt += 3; // a little bit overhead
+                                                               }
                                                                doSetVoltageToneFrontend=false;
                                                                doSetFrontend=false;
                                                                eSecCommand::rotor cmd;
                                                                doSetVoltageToneFrontend=false;
                                                                doSetFrontend=false;
                                                                eSecCommand::rotor cmd;
@@ -828,37 +840,40 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                                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) );
                                                                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) );
-       
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) ); // sleep one second before change voltage or tone
+
                                                                compare.voltage = voltage;
                                                                compare.steps = +3;
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) );  // wait 2 second before set high voltage
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
                                                                compare.voltage = voltage;
                                                                compare.steps = +3;
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // correct final voltage?
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 2000) );  // wait 2 second before set high voltage
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
-       
+
                                                                compare.tone = tone;
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
                                                                compare.tone = tone;
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_TONE_GOTO, compare) );
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, m_params[DELAY_AFTER_FINAL_CONT_TONE_CHANGE]) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 0) );
        
                                                                cmd.direction=1;  // check for running rotor
                                                                cmd.deltaA=0;
        
                                                                cmd.direction=1;  // check for running rotor
                                                                cmd.deltaA=0;
-                                                               cmd.steps=+3;
+                                                               cmd.steps = +3;
                                                                cmd.okcount=0;
                                                                cmd.okcount=0;
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, m_params[MOTOR_RUNNING_TIMEOUT]*4) );  // 2 minutes running timeout
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, mrt*4) );  // mrt is in seconds... our SLEEP time is 250ms.. so * 4
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );  // 250msec delay
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );  // 250msec delay
                                                                sec_sequence.push_back( eSecCommand(eSecCommand::IF_TUNER_LOCKED_GOTO, cmd ) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); 
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +5 ) );
                                                                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_ROTOR_STOPPED) );
                                                                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_ROTOR_STOPPED) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +3) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +4) );
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -5) );
                                                        }
                                                        }
+                                                       eDebug("set rotor timeout to %d seconds", mrt);
+                                                       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);
                                        }
                                }
                        }
                                        }
                                }
                        }
@@ -919,7 +934,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                        if (doSetFrontend)
                        {
                                sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
                        if (doSetFrontend)
                        {
                                sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT, tunetimeout) );
-                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
+                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND, 1) );
                        }
 
                        sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
                        }
 
                        sec_sequence.push_front( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );