DEFINE_REF(eDVBFrontend);
-eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok): m_type(-1)
+eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok): m_type(-1), m_curVoltage(-1)
{
#if HAVE_DVB_API_VERSION < 3
char sec_filename[128];
++m_sec_sequence.current();
break;
case eSecCommand::SET_VOLTAGE:
- eDebug("[SEC] setVoltage %d", m_sec_sequence.current()->voltage);
- setVoltage(m_sec_sequence.current()++->voltage);
+ int voltage = m_sec_sequence.current()++->voltage;
+ eDebug("[SEC] setVoltage %d", voltage);
+ setVoltage(voltage);
break;
case eSecCommand::SET_TONE:
eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
break;
case eSecCommand::SEND_DISEQC:
sendDiseqc(m_sec_sequence.current()->diseqc);
- eDebugNoNewLine("sendDiseqc: ");
+ eDebugNoNewLine("[SEC] sendDiseqc: ");
for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
- eDebug("[SEC] ");
+ eDebug("");
++m_sec_sequence.current();
break;
case eSecCommand::SEND_TONEBURST:
++m_sec_sequence.current();
break;
case eSecCommand::MEASURE_IDLE_INPUTPOWER:
- m_idleInputpower = readInputpower();
- eDebug("[SEC] idleInputpower is %d", m_idleInputpower);
- ++m_sec_sequence.current();
+ {
+ 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);
break;
case eSecCommand::IF_TIMEOUT_GOTO:
if (!m_timeoutCount)
+ {
+ eDebug("[SEC] rotor timout");
setSecSequencePos(m_sec_sequence.current()->steps);
+ }
else
++m_sec_sequence.current();
break;
+ case eSecCommand::SET_POWER_LIMITING_MODE:
+ {
+ int fd=::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] |= 0x90; // enable static current limiting
+ eDebug("[SEC] set static current limiting");
+ }
+ else
+ {
+ data[0] &= ~0x90; // 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;
+ }
+ case eSecCommand::IF_IDLE_INPUTPOWER_AVAIL_GOTO:
+ if (m_idleInputpower[0] && m_idleInputpower[1] && setSecSequencePos(m_sec_sequence.current()->steps))
+ break;
+ ++m_sec_sequence.current();
+ break;
case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
{
+ int idleInputpower = m_idleInputpower[m_curVoltage == iDVBFrontend::voltage13 ? 0 : 1];
eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
const char *txt = cmd.direction ? "running" : "stopped";
- eDebug("[SEC] waiting for rotor %s", txt);
- eDebug("[SEC] %s %d, idle %d, delta %d",
+ eDebug("[SEC] waiting for rotor %s %d, idle %d, delta %d",
txt,
m_runningInputpower,
- m_idleInputpower,
+ idleInputpower,
cmd.deltaA);
- if ( (cmd.direction && abs(m_runningInputpower - m_idleInputpower) >= cmd.deltaA)
- || (!cmd.direction && abs(m_runningInputpower - m_idleInputpower) <= cmd.deltaA) )
+ if ( (cmd.direction && abs(m_runningInputpower - idleInputpower) >= cmd.deltaA)
+ || (!cmd.direction && abs(m_runningInputpower - idleInputpower) <= cmd.deltaA) )
{
++cmd.okcount;
eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
- if ( cmd.okcount > 1 )
+ if ( cmd.okcount > 6 )
{
eDebug("[SEC] rotor is %s", txt);
if (setSecSequencePos(cmd.steps))
++m_sec_sequence.current();
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;
+ }
default:
++m_sec_sequence.current();
eDebug("[SEC] unhandled sec command");
fe_sec_voltage_t vlt;
#endif
+ m_curVoltage=voltage;
switch (voltage)
{
case voltageOff:
tone = iDVBFrontend::toneOff;
eSecCommandList sec_sequence;
- bool setVoltage=true;
if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
{
if ( send_diseqc || changed_burst )
{
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, 30) ); // standard says 15 msek here
- setVoltage=false;
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
}
if ( send_diseqc )
}
if ( RotorCmd != lastRotorCmd )
{
+ if ( changed_burst || send_diseqc )
+ {
+ // override first voltage change
+ *(++(++sec_sequence.begin()))=eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13);
+ // wait 1 second after first switch diseqc command
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 1000) );
+ }
+ else // no other diseqc commands before
+ {
+ sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) ); // wait 50msec after voltage 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, iDVBFrontend::voltage13) );
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec after voltage change
+ }
+
eDVBDiseqcCommand diseqc;
diseqc.data[0] = 0xE0;
diseqc.data[1] = 0x31; // positioner
diseqc.data[2] = 0x6B; // goto stored sat position
diseqc.data[3] = RotorCmd;
}
+
if ( rotor_param.m_inputpower_parameters.m_use )
{ // use measure rotor input power to detect rotor state
- sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18) ); // always turn with high voltage
- sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50sec after voltage change
- sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER) );
+ eSecCommand::rotor cmd;
+// 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, iDVBFrontend::voltage18) );
+ 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, iDVBFrontend::voltage13) ); // back to lower voltage
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50msec
+////////////////////////////
+ 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, 8) ); // 2 seconds rotor start timout
- sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );
+ 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) );
- eSecCommand::rotor cmd;
cmd.direction=1; // check for running rotor
cmd.deltaA=rotor_param.m_inputpower_parameters.m_threshold;
cmd.steps=+3;
cmd.okcount=0;
- sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
- sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +8 ) );
- sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
- sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 240) ); // 1 minute running timeout
- sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );
+ sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); // check if rotor has started
+ sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +11 ) ); // timeout ?
+ sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // goto loop start
+////////////////////
+ sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 2400) ); // 2 minutes running timeout
+ sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18) );
+ sec_sequence.push_back( eSecCommand(eSecCommand::SET_POWER_LIMITING_MODE, eSecCommand::modeDynamic) );
+// 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, +2 ) );
- sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
+ sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +3 ) ); // timeout ?
+ sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); // running loop start
+/////////////////////
sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
frontend.setData(3, RotorCmd);
frontend.setData(4, sat.orbital_position);
}
}
- if ( setVoltage )
- {
- sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
- sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
- }
+ 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, 10) );
sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );