fix voltage handling,
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 1 Feb 2006 16:56:58 +0000 (16:56 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 1 Feb 2006 16:56:58 +0000 (16:56 +0000)
fix rotor handling

lib/dvb/frontend.cpp
lib/dvb/frontend.h
lib/dvb/sec.cpp
lib/dvb/sec.h

index c44a312..630c030 100644 (file)
@@ -244,7 +244,6 @@ int eDVBFrontend::openFrontend()
                return -1;  // already opened
 
        m_state=0;
-       m_curVoltage=voltageOff;
        m_tuning=0;
 
 #if HAVE_DVB_API_VERSION < 3
@@ -338,6 +337,7 @@ int eDVBFrontend::closeFrontend()
                setVoltage(iDVBFrontend::voltageOff);
                ::close(m_fd);
                m_fd=-1;
+               m_data[0] = m_data[1] = m_data[2] = -1;
        }
 #if HAVE_DVB_API_VERSION < 3
        if (m_secfd >= 0)
@@ -516,6 +516,22 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                setVoltage(voltage);
                                break;
                        }
+                       case eSecCommand::IF_VOLTAGE_GOTO:
+                       {
+                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+                               if ( compare.voltage == m_curVoltage && setSecSequencePos(compare.steps) )
+                                       break;
+                               ++m_sec_sequence.current();
+                               break;
+                       }
+                       case eSecCommand::IF_NOT_VOLTAGE_GOTO:
+                       {
+                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+                               if ( compare.voltage != m_curVoltage && setSecSequencePos(compare.steps) )
+                                       break;
+                               ++m_sec_sequence.current();
+                               break;
+                       }
                        case eSecCommand::SET_TONE:
                                eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
                                setTone(m_sec_sequence.current()++->tone);
@@ -537,33 +553,10 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                setFrontend();
                                ++m_sec_sequence.current();
                                break;
-                       case eSecCommand::MEASURE_IDLE_INPUTPOWER:
-                       {
-                               int idx = m_sec_sequence.current()++->val;
-                               if ( idx == 0 || idx == 1 )
-                               {
-                                       m_idleInputpower[idx] = readInputpower();
-                                       eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
-                               }
-                               else
-                                       eDebug("[SEC] idleInputpower measure index(%d) out of bound !!!", idx);
-                               break;
-                       }
-                       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)
                                {
@@ -574,35 +567,39 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                else
                                        ++m_sec_sequence.current();
                                break;
-                       case eSecCommand::SET_POWER_LIMITING_MODE:
+                       case eSecCommand::MEASURE_IDLE_INPUTPOWER:
                        {
-                               int fd = m_fe ?
-                                       ::open("/dev/i2c/1", O_RDWR) :
-                                       ::open("/dev/i2c/0", O_RDWR);
-
-                               unsigned char data[2];
-                               ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
-                               if(::read(fd, data, 1) != 1)
-                                       eDebug("[SEC] error read lnbp (%m)");
-                               if ( m_sec_sequence.current()->mode == eSecCommand::modeStatic )
+                               int idx = m_sec_sequence.current()++->val;
+                               if ( idx == 0 || idx == 1 )
                                {
-                                       data[0] |= 0x80;  // enable static current limiting
-                                       eDebug("[SEC] set static current limiting");
+                                       m_idleInputpower[idx] = readInputpower();
+                                       eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
                                }
                                else
+                                       eDebug("[SEC] idleInputpower measure index(%d) out of bound !!!", idx);
+                               break;
+                       }
+                       case eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO:
+                       {
+                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+                               int idx = compare.voltage;
+                               if ( idx == 0 || idx == 1 )
                                {
-                                       data[0] &= ~0x80;  // enable dynamic current limiting
-                                       eDebug("[SEC] set dynamic current limiting");
+                                       int idle = readInputpower();
+                                       int diff = abs(idle-m_idleInputpower[idx]);
+                                       if ( diff > 0)
+                                       {
+                                               eDebug("measure idle(%d) was not okay.. (%d - %d = %d) retry", idx, m_idleInputpower[idx], idle, diff);
+                                               setSecSequencePos(compare.steps);
+                                               break;
+                                       }
                                }
-                               if(::write(fd, data, 1) != 1)
-                                       eDebug("[SEC] error write lnbp (%m)");
-                               ::close(fd);
                                ++m_sec_sequence.current();
                                break;
                        }
-                       case eSecCommand::IF_IDLE_INPUTPOWER_AVAIL_GOTO:
-                               if (m_idleInputpower[0] && m_idleInputpower[1] && setSecSequencePos(m_sec_sequence.current()->steps))
-                                       break;
+                       case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
+                               m_runningInputpower = readInputpower();
+                               eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
                                ++m_sec_sequence.current();
                                break;
                        case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
@@ -632,16 +629,66 @@ void eDVBFrontend::tuneLoop()  // called by m_tuneTimer
                                {
                                        eDebug("[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();
                                break;
                        }
-                       case eSecCommand::IF_VOLTAGE_GOTO:
+                       case eSecCommand::IF_ROTORPOS_VALID_GOTO:
+                               if (m_data[5] != -1 && m_data[6] != -1)
+                                       setSecSequencePos(m_sec_sequence.current()->steps);
+                               else
+                                       ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::INVALIDATE_CURRENT_ROTORPARMS:
+                               m_data[5] = m_data[6] = -1;
+                               eDebug("[SEC] invalidate current rotorparams");
+                               ++m_sec_sequence.current();
+                               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::SET_ROTOR_DISEQC_RETRYS:
+                               m_retryCount = m_sec_sequence.current()++->val;
+                               eDebug("[SEC] set rotor retries %d", m_retryCount);
+                               break;
+                       case eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO:
+                               if (!m_retryCount)
+                               {
+                                       eDebug("[SEC] no more rotor retrys");
+                                       setSecSequencePos(m_sec_sequence.current()->steps);
+                               }
+                               else
+                                       ++m_sec_sequence.current();
+                               break;
+                       case eSecCommand::SET_POWER_LIMITING_MODE:
                        {
-                               eSecCommand::pair &compare = m_sec_sequence.current()->compare;
-                               if ( compare.voltage == m_curVoltage && setSecSequencePos(compare.steps) )
-                                       break;
+                               int fd = m_fe ?
+                                       ::open("/dev/i2c/1", O_RDWR) :
+                                       ::open("/dev/i2c/0", O_RDWR);
+
+                               unsigned char data[2];
+                               ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
+                               if(::read(fd, data, 1) != 1)
+                                       eDebug("[SEC] error read lnbp (%m)");
+                               if ( m_sec_sequence.current()->mode == eSecCommand::modeStatic )
+                               {
+                                       data[0] |= 0x80;  // enable static current limiting
+                                       eDebug("[SEC] set static current limiting");
+                               }
+                               else
+                               {
+                                       data[0] &= ~0x80;  // enable dynamic current limiting
+                                       eDebug("[SEC] set dynamic current limiting");
+                               }
+                               if(::write(fd, data, 1) != 1)
+                                       eDebug("[SEC] error write lnbp (%m)");
+                               ::close(fd);
                                ++m_sec_sequence.current();
                                break;
                        }
index 8843f6f..2cccf88 100644 (file)
@@ -70,6 +70,7 @@ class eDVBFrontend: public iDVBFrontend, public Object
        int m_idleInputpower[2];  // 13V .. 18V
        int m_runningInputpower;
        int m_timeoutCount; // needed for timeout
+       int m_retryCount; // diseqc retry for rotor
        int m_curVoltage;
 
        void feEvent(int);
index 9095ca6..d504fcb 100644 (file)
@@ -417,93 +417,8 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                eDebug("");
 #endif
 
-                               if ( send_mask )
-                               {
-                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
-                                       eSecCommand::pair compare;
-                                       compare.voltage = voltage;
-                                       compare.steps = +3;
-                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
-                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
-                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
-                               }
-
-                               for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
-                               {
-                                       if ( send_mask & 4 )
-                                       {
-                                               sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
-                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
-                                       }
-
-                                       int loops=0;
-
-                                       if ( send_mask & 1 )
-                                               ++loops;
-                                       if ( send_mask & 2 )
-                                               ++loops;
-
-                                       for ( int i=0; i < di_param.m_repeats; ++i )
-                                               loops *= 2;
-
-                                       for ( int i = 0; i < loops;)  // fill commands...
-                                       {
-                                               eDVBDiseqcCommand diseqc;
-                                               diseqc.len = 4;
-                                               diseqc.data[0] = i ? 0xE1 : 0xE0;
-                                               diseqc.data[1] = 0x10;
-                                               if ( (send_mask & 2) && (di_param.m_command_order & 4) )
-                                               {
-                                                       diseqc.data[2] = 0x39;
-                                                       diseqc.data[3] = ucsw;
-                                               }
-                                               else if ( send_mask & 1 )
-                                               {
-                                                       diseqc.data[2] = 0x38;
-                                                       diseqc.data[3] = csw;
-                                               }
-                                               else
-                                               {
-                                                       diseqc.data[2] = 0x00;
-                                                       diseqc.data[3] = 0x00;
-                                               }
-                                               sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
-
-                                               i++;
-                                               if ( i < loops )
-                                               {
-                                                       int cmd=0;
-                                                       if (diseqc.data[2] == 0x38 && (send_mask & 2))
-                                                               cmd=0x39;
-                                                       else if (diseqc.data[2] == 0x39 && (send_mask & 1))
-                                                               cmd=0x38;
-                                                       if (cmd)
-                                                       {
-                                                               static int delay = (120 - 54) / 2;  // standard says 100msek between two repeated commands
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
-                                                               diseqc.data[2]=cmd;
-                                                               diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
-                                                               ++i;
-                                                               if ( i < loops )
-                                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
-                                                               else
-                                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
-                                                       }
-                                                       else  // delay 120msek when no command is in repeat gap
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
-                                               }
-                                               else
-                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
-                                       }
-
-                                       if ( send_mask & 8 )  // toneburst at end of sequence
-                                       {
-                                               sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
-                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
-                                       }
-                               }
-
+                               int RotorCmd=-1;
+                               bool useGotoXX = false;
                                if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
                                {
                                        if (depend_satpos_mode || linked)
@@ -511,9 +426,6 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                frontend.setData(6, sat.orbital_position);
                                        else
                                        {
-                                               int RotorCmd=0;
-                                               bool useGotoXX = false;
-
                                                if (sw_param.m_rotorPosNum) // we have stored rotor pos?
                                                        RotorCmd=sw_param.m_rotorPosNum;
                                                else  // we must calc gotoxx cmd
@@ -558,7 +470,7 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                                        RotorCmd |= 0xD000;
                                                                }
                                                                else                                    // west
-                                                               {          
+                                                               {
                                                                        int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
                                                                        RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
                                                                        RotorCmd |= 0xE000;
@@ -566,93 +478,218 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA
                                                        }
                                                        eDebug("RotorCmd = %04x", RotorCmd);
                                                }
-                                               if ( RotorCmd != lastRotorCmd )
+                                       }
+                               }
+
+                               if ( send_mask )
+                               {
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
+                                       eSecCommand::pair compare;
+                                       compare.voltage = iDVBFrontend::voltageOff;
+                                       compare.steps = +4;
+                                       // the next is a check if voltage is switched off.. then we first set a voltage :)
+                                       // else we set voltage after all diseqc stuff..
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
+
+                                       if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
+                                               // TODO .. add handling for turning rotor without measure inputpower
+                                               compare.voltage = VOLTAGE(18);
+                                       else
+                                               compare.voltage = voltage;
+
+                                       // voltage already correct ?
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
+                                       compare.steps = +3;
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
+                                       // voltage was disabled..so we wait a longer time .. for normal switches 200ms should be enough
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );
+
+                                       for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
+                                       {
+                                               if ( send_mask & 4 )
+                                               {
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+                                               }
+
+                                               int loops=0;
+
+                                               if ( send_mask & 1 )
+                                                       ++loops;
+                                               if ( send_mask & 2 )
+                                                       ++loops;
+
+                                               for ( int i=0; i < di_param.m_repeats; ++i )
+                                               loops *= 2;
+
+                                               for ( int i = 0; i < loops;)  // fill commands...
                                                {
-                                                       if ( send_mask )
+                                                       eDVBDiseqcCommand diseqc;
+                                                       diseqc.len = 4;
+                                                       diseqc.data[0] = i ? 0xE1 : 0xE0;
+                                                       diseqc.data[1] = 0x10;
+                                                       if ( (send_mask & 2) && (di_param.m_command_order & 4) )
                                                        {
-                                                               // override first voltage change
-                                                               *(++(++sec_sequence.begin()))=eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13));
-                                                               // wait 1 second after first switch diseqc command
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) );
+                                                               diseqc.data[2] = 0x39;
+                                                               diseqc.data[3] = ucsw;
                                                        }
-                                                       else  // no other diseqc commands before
+                                                       else if ( send_mask & 1 )
                                                        {
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );  // wait 15msec after tone change
-                                                               eSecCommand::pair compare;
-                                                               compare.voltage = voltage;
-                                                               compare.steps = +3;
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec after voltage change
+                                                               diseqc.data[2] = 0x38;
+                                                               diseqc.data[3] = csw;
                                                        }
-
-                                                       eDVBDiseqcCommand diseqc;
-                                                       diseqc.data[0] = 0xE0;
-                                                       diseqc.data[1] = 0x31;          // positioner
-                                                       if ( useGotoXX )
+                                                       else
                                                        {
-                                                               diseqc.len = 5;
-                                                               diseqc.data[2] = 0x6E;  // drive to angular position
-                                                               diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
-                                                               diseqc.data[4] = RotorCmd & 0xFF;
+                                                               diseqc.data[2] = 0x00;
+                                                               diseqc.data[3] = 0x00;
                                                        }
-                                                       else
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
+
+                                                       i++;
+                                                       if ( i < loops )
                                                        {
-                                                               diseqc.len = 4;
-                                                               diseqc.data[2] = 0x6B;  // goto stored sat position
-                                                               diseqc.data[3] = RotorCmd;
-                                                               diseqc.data[4] = 0x00;
+                                                               int cmd=0;
+                                                               if (diseqc.data[2] == 0x38 && (send_mask & 2))
+                                                                       cmd=0x39;
+                                                               else if (diseqc.data[2] == 0x39 && (send_mask & 1))
+                                                                       cmd=0x38;
+                                                               if (cmd)
+                                                               {
+                                                                       static int delay = (120 - 54) / 2;  // standard says 100msek between two repeated commands
+                                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
+                                                                       diseqc.data[2]=cmd;
+                                                                       diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
+                                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
+                                                                       ++i;
+                                                                       if ( i < loops )
+                                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
+                                                                       else
+                                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+                                                               }
+                                                               else  // delay 120msek when no command is in repeat gap
+                                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
                                                        }
+                                                       else
+                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+                                               }
+
+                                               if ( send_mask & 8 )  // toneburst at end of sequence
+                                               {
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
+                                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+                                               }
+                                       }
+                               }
+
+                               if ( RotorCmd != -1 && RotorCmd != lastRotorCmd )
+                               {
+                                       eSecCommand::pair compare;
+                                       compare.voltage = iDVBFrontend::voltageOff;
+                                       compare.steps = +4;
+                                       // the next is a check if voltage is switched off.. then we first set a voltage :)
+                                       // else we set voltage after all diseqc stuff..
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::IF_NOT_VOLTAGE_GOTO, compare) );
+
+                                       // TODO .. add handling for turning rotor without measure inputpower
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
+                                       // voltage was disabled..so we wait a longer time ..
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
+                                       sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +4) );  // no need to send stop rotor cmd
+
+                                       eDVBDiseqcCommand diseqc;
+                                       if ( !send_mask )  // no switch changed.. so we send first the rotor stop command
+                                       {
+                                               diseqc.len = 3;
+                                               diseqc.data[0] = 0xE0;
+                                               diseqc.data[1] = 0x31;  // positioner
+                                               diseqc.data[2] = 0x60;  // stop
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_ROTORPOS_VALID_GOTO, +3) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
+                                               // wait 300msec after send rotor stop cmd
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 300) );
+                                       }
+                                       else
+                                       {
+                                               // wait 500msec after switching to rotor
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 500) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +2) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, +1) );
+                                       }
 
-                                                       if ( rotor_param.m_inputpower_parameters.m_use )
-                                                       { // use measure rotor input power to detect rotor state
-                                                               eSecCommand::rotor cmd;
+                                       diseqc.data[0] = 0xE0;
+                                       diseqc.data[1] = 0x31;          // positioner
+                                       if ( useGotoXX )
+                                       {
+                                               diseqc.len = 5;
+                                               diseqc.data[2] = 0x6E;  // drive to angular position
+                                               diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
+                                               diseqc.data[4] = RotorCmd & 0xFF;
+                                       }
+                                       else
+                                       {
+                                               diseqc.len = 4;
+                                               diseqc.data[2] = 0x6B;  // goto stored sat position
+                                               diseqc.data[3] = RotorCmd;
+                                               diseqc.data[4] = 0x00;
+                                       }
+
+                                       if ( rotor_param.m_inputpower_parameters.m_use )
+                                       { // use measure rotor input power to detect rotor state
+                                               eSecCommand::rotor cmd;
+                                               eSecCommand::pair compare;
+                                               compare.voltage = VOLTAGE(18);
+                                               compare.steps = +2;
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, compare.voltage) );
 // measure idle power values
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_IDLE_INPUTPOWER_AVAIL_GOTO, +8) ); // already measured?
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec after voltage change
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 100) );  // wait 100msec before measure
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) ); // back to lower voltage
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );  // wait 200msec after voltage change
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 1) );
+                                               compare.voltage = 1;
+                                               compare.steps = -2;
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(13)) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 200) );  // wait 200msec before measure
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER, 0) );
+                                               compare.voltage = 0;
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, compare) );
 ////////////////////////////
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec after voltage change
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) );  // 2 seconds rotor start timout
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeStatic) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_ROTOR_DISEQC_RETRYS, 2) );  // 2 retries
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::INVALIDATE_CURRENT_ROTORPARMS) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 40) );  // 2 seconds rotor start timout
 // rotor start loop
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // 50msec delay
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
-                                                               cmd.direction=1;  // check for running rotor
-                                                               cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
-                                                               cmd.steps=+3;
-                                                               cmd.okcount=0;
-                                                               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, +9 ) );  // 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::SLEEP, 50) );  // 50msec delay
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
+                                               cmd.direction=1;  // check for running rotor
+                                               cmd.deltaA=rotor_param.m_inputpower_parameters.m_delta;
+                                               cmd.steps=+5;
+                                               cmd.okcount=0;
+                                               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, +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::SET_TIMEOUT, 2400) );  // 2 minutes running timeout
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) );  // 2 minutes running timeout
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, VOLTAGE(18)) );
 // rotor running loop
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
-                                                               cmd.direction=0;  // check for stopped rotor
-                                                               cmd.steps=+3;
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );  // timeout ? this should never happen
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );  // running loop start
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );  // wait 50msec
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
+                                               cmd.direction=0;  // check for stopped rotor
+                                               cmd.steps=+3;
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) );  // timeout ? this should never happen
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );  // running loop start
 /////////////////////
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
-                                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
-                                                               frontend.setData(3, RotorCmd);
-                                                               frontend.setData(4, sat.orbital_position);
-                                                       }
-                                                       else
-                                                               eFatal("rotor turning without inputpowermeasure not implemented yet");
-                                               }
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
+                                               sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
+                                               frontend.setData(3, RotorCmd);
+                                               frontend.setData(4, sat.orbital_position);
                                        }
+                                       else
+                                               eFatal("rotor turning without inputpowermeasure not implemented yet");
                                }
                        }
                        else
index 18bc2b3..ac18f3c 100644 (file)
@@ -12,11 +12,14 @@ public:
        enum {
                NONE, SLEEP, SET_VOLTAGE, SET_TONE, GOTO,
                SEND_DISEQC, SEND_TONEBURST, SET_FRONTEND,
-               MEASURE_IDLE_INPUTPOWER, MEASURE_RUNNING_INPUTPOWER,
-               IF_TIMEOUT_GOTO, IF_INPUTPOWER_DELTA_GOTO,
-               UPDATE_CURRENT_ROTORPARAMS, SET_TIMEOUT,
-               IF_IDLE_INPUTPOWER_AVAIL_GOTO, SET_POWER_LIMITING_MODE,
-               IF_VOLTAGE_GOTO
+               SET_TIMEOUT, IF_TIMEOUT_GOTO, 
+               IF_VOLTAGE_GOTO, IF_NOT_VOLTAGE_GOTO,
+               SET_POWER_LIMITING_MODE,
+               SET_ROTOR_DISEQC_RETRYS, IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO,
+               MEASURE_IDLE_INPUTPOWER, MEASURE_RUNNING_INPUTPOWER,
+               IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, IF_INPUTPOWER_DELTA_GOTO,
+               UPDATE_CURRENT_ROTORPARAMS, INVALIDATE_CURRENT_ROTORPARMS,
+               IF_ROTORPOS_VALID_GOTO
        };
        int cmd;
        struct rotor
@@ -67,8 +70,12 @@ public:
 
 class eSecCommandList
 {
-       std::list<eSecCommand> secSequence;
-       std::list<eSecCommand>::iterator cur;
+       typedef std::list<eSecCommand> List;
+       List secSequence;
+public:
+       typedef List::iterator iterator;
+private:
+       iterator cur;
 public:
        eSecCommandList()
                :cur(secSequence.end())
@@ -87,15 +94,15 @@ public:
                secSequence.clear();
                cur=secSequence.end();
        }
-       inline std::list<eSecCommand>::iterator &current()
+       inline iterator &current()
        {
                return cur;
        }
-       inline std::list<eSecCommand>::iterator begin()
+       inline iterator begin()
        {
                return secSequence.begin();
        }
-       inline std::list<eSecCommand>::iterator end()
+       inline iterator end()
        {
                return secSequence.end();
        }