X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/01921e17fbec0161d4f1578d6648c08e4968f0c4..cae001777c7b32bdb4f6f4199e9f49058946fe9f:/lib/dvb/frontend.cpp diff --git a/lib/dvb/frontend.cpp b/lib/dvb/frontend.cpp index 8a8e591f..b8debd81 100644 --- a/lib/dvb/frontend.cpp +++ b/lib/dvb/frontend.cpp @@ -6,6 +6,10 @@ #include #include +#ifndef I2C_SLAVE_FORCE +#define I2C_SLAVE_FORCE 0x0706 +#endif + #if HAVE_DVB_API_VERSION < 3 #include #include @@ -23,9 +27,9 @@ #include #endif -#include -#include -#include +#include +#include +#include void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescriptor &descriptor) { @@ -204,7 +208,7 @@ RESULT eDVBFrontendParameters::getHash(unsigned long &hash) const 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]; @@ -337,7 +341,12 @@ void eDVBFrontend::feEvent(int w) if (m_tuning) state = stateTuning; else - state = stateFailed; + { + state = stateLostLock; + + if (m_state != stateLostLock) + eDebug("FIXME: we lost lock, so we might have to retune."); + } } if (m_state != state) { @@ -359,6 +368,7 @@ void eDVBFrontend::timeout() m_state = state; m_stateChanged(this); } + m_tuning = 0; } else m_tuning = 0; } @@ -414,7 +424,7 @@ bool eDVBFrontend::setSecSequencePos(int steps) { if (m_sec_sequence.current() != m_sec_sequence.begin() && m_sec_sequence.current() != m_sec_sequence.end()) --m_sec_sequence.current(); - --steps; + ++steps; } return true; } @@ -428,68 +438,144 @@ void eDVBFrontend::tuneLoop() // called by m_tuneTimer { case eSecCommand::SLEEP: delay = m_sec_sequence.current()++->msec; - eDebug("sleep %dms\n", delay); + eDebug("[SEC] sleep %dms", delay); break; case eSecCommand::GOTO: if ( !setSecSequencePos(m_sec_sequence.current()->steps) ) ++m_sec_sequence.current(); break; case eSecCommand::SET_VOLTAGE: - setVoltage(m_sec_sequence.current()++->voltage); - eDebug("setVoltage %d", 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); setTone(m_sec_sequence.current()++->tone); - eDebug("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(""); ++m_sec_sequence.current(); break; case eSecCommand::SEND_TONEBURST: + eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst); sendToneburst(m_sec_sequence.current()++->toneburst); - eDebug("sendToneburst: %d", m_sec_sequence.current()->toneburst); break; case eSecCommand::SET_FRONTEND: - eDebug("setFrontend"); + eDebug("[SEC] setFrontend"); setFrontend(); ++m_sec_sequence.current(); break; case eSecCommand::MEASURE_IDLE_INPUTPOWER: - m_idleInputpower = readInputpower(); - eDebug("idleInputpower is %d", m_idleInputpower); - ++m_sec_sequence.current(); + { + 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("runningInputpower is %d", m_runningInputpower); + eDebug("[SEC] runningInputpower is %d", m_runningInputpower); ++m_sec_sequence.current(); break; case eSecCommand::SET_TIMEOUT: m_timeoutCount = m_sec_sequence.current()++->val; - eDebug("set timeout %d", m_timeoutCount); + 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("update current rotorparams %d", m_timeoutCount); + 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) + { + eDebug("[SEC] rotor timout"); setSecSequencePos(m_sec_sequence.current()->steps); + } else ++m_sec_sequence.current(); break; - case eSecCommand::IF_RUNNING_GOTO: - case eSecCommand::IF_STOPPED_GOTO: + 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 %d, idle %d, delta %d", + txt, + m_runningInputpower, + 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 > 6 ) + { + eDebug("[SEC] rotor is %s", txt); + if (setSecSequencePos(cmd.steps)) + break; + } + } + else + { + eDebug("[SEC] rotor not %s... reset counter.. increase timeout", txt); + --m_timeoutCount; + cmd.okcount=0; + } + ++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("unhandled sec command"); + eDebug("[SEC] unhandled sec command"); } m_tuneTimer->start(delay,true); } @@ -530,8 +616,6 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where) m_sec_sequence.clear(); - eDebug("eDVBFrontend::tune. type: %d", m_type); - switch (m_type) { case feSatellite: @@ -696,6 +780,7 @@ RESULT eDVBFrontend::setVoltage(int voltage) fe_sec_voltage_t vlt; #endif + m_curVoltage=voltage; switch (voltage) { case voltageOff: @@ -805,7 +890,7 @@ RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list) RESULT eDVBFrontend::getData(int num, int &data) { - if ( num < 5 ) + if ( num < 7 ) { data = m_data[num]; return 0; @@ -815,7 +900,7 @@ RESULT eDVBFrontend::getData(int num, int &data) RESULT eDVBFrontend::setData(int num, int val) { - if ( num < 5 ) + if ( num < 7 ) { m_data[num] = val; return 0;