X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/967664233fc4ce992405a0e86e0c6cd594dfba57..894d8e0be915db6a8ee6454cbd01f95b5f6abad9:/lib/dvb/frontend.cpp diff --git a/lib/dvb/frontend.cpp b/lib/dvb/frontend.cpp index 5eb61077..d4704a9d 100644 --- a/lib/dvb/frontend.cpp +++ b/lib/dvb/frontend.cpp @@ -9,6 +9,16 @@ #if HAVE_DVB_API_VERSION < 3 #include #include +#define QAM_AUTO (Modulation)6 +#define TRANSMISSION_MODE_AUTO (TransmitMode)2 +#define BANDWIDTH_AUTO (BandWidth)3 +#define GUARD_INTERVAL_AUTO (GuardInterval)4 +#define HIERARCHY_AUTO (Hierarchy)4 +#define constellation Constellation +#define guard_interval guardInterval +#define hierarchy_information HierarchyInformation +#define code_rate_HP HP_CodeRate +#define code_rate_LP LP_CodeRate #else #include #endif @@ -261,16 +271,21 @@ eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok): m_type(-1) ok = 0; return; } - eDebug("detected %s frontend", "satellite\0cable\0 terrestrial"+feSatellite*9); + eDebug("detected %s frontend", "satellite\0cable\0 terrestrial"+fe_info.type*9); ok = 1; m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read); CONNECT(m_sn->activated, eDVBFrontend::feEvent); m_sn->start(); - + m_timeout = new eTimer(eApp); CONNECT(m_timeout->timeout, eDVBFrontend::timeout); - + + m_tuneTimer = new eTimer(eApp); + CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop); + + memset(m_data, 0xFFFF, sizeof(m_data)); + return; } @@ -348,6 +363,185 @@ void eDVBFrontend::timeout() m_tuning = 0; } +#ifndef FP_IOCTL_GET_ID +#define FP_IOCTL_GET_ID 0 +#endif +int eDVBFrontend::readInputpower() +{ + int power=0; +// if ( eSystemInfo::getInstance()->canMeasureLNBCurrent() ) + { +// switch ( eSystemInfo::getInstance()->getHwType() ) + { +// case eSystemInfo::DM7000: +// case eSystemInfo::DM7020: + { + // open front prozessor + int fp=::open("/dev/dbox/fp0", O_RDWR); + if (fp < 0) + { + eDebug("couldn't open fp"); + return -1; + } + static bool old_fp = (::ioctl(fp, FP_IOCTL_GET_ID) < 0); + if ( ioctl( fp, old_fp ? 9 : 0x100, &power ) < 0 ) + { + eDebug("FP_IOCTL_GET_LNB_CURRENT failed (%m)"); + return -1; + } + ::close(fp); +// break; + } +// default: +// eDebug("Inputpower read for platform %d not yet implemented", eSystemInfo::getInstance()->getHwType()); + } + } + return power; +} + +bool eDVBFrontend::setSecSequencePos(int steps) +{ + eDebug("set sequence pos %d", steps); + if (!steps) + return false; + while( steps > 0 ) + { + if (m_sec_sequence.current() != m_sec_sequence.end()) + ++m_sec_sequence.current(); + --steps; + } + while( steps < 0 ) + { + if (m_sec_sequence.current() != m_sec_sequence.begin() && m_sec_sequence.current() != m_sec_sequence.end()) + --m_sec_sequence.current(); + ++steps; + } + return true; +} + +void eDVBFrontend::tuneLoop() // called by m_tuneTimer +{ + int delay=0; + if ( m_sec_sequence && m_sec_sequence.current() != m_sec_sequence.end() ) + { + switch (m_sec_sequence.current()->cmd) + { + case eSecCommand::SLEEP: + delay = m_sec_sequence.current()++->msec; + 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: + eDebug("[SEC] setVoltage %d", m_sec_sequence.current()->voltage); + setVoltage(m_sec_sequence.current()++->voltage); + break; + case eSecCommand::SET_TONE: + eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone); + setTone(m_sec_sequence.current()++->tone); + break; + case eSecCommand::SEND_DISEQC: + sendDiseqc(m_sec_sequence.current()->diseqc); + eDebugNoNewLine("sendDiseqc: "); + for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i) + eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]); + eDebug("[SEC] "); + ++m_sec_sequence.current(); + break; + case eSecCommand::SEND_TONEBURST: + eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst); + sendToneburst(m_sec_sequence.current()++->toneburst); + break; + case eSecCommand::SET_FRONTEND: + eDebug("[SEC] setFrontend"); + setFrontend(); + ++m_sec_sequence.current(); + break; + case eSecCommand::MEASURE_IDLE_INPUTPOWER: + m_idleInputpower = readInputpower(); + eDebug("[SEC] idleInputpower is %d", m_idleInputpower); + ++m_sec_sequence.current(); + 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) + setSecSequencePos(m_sec_sequence.current()->steps); + else + ++m_sec_sequence.current(); + break; + case eSecCommand::IF_INPUTPOWER_DELTA_GOTO: + { + 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", + txt, + m_runningInputpower, + m_idleInputpower, + cmd.deltaA); + if ( (cmd.direction && abs(m_runningInputpower - m_idleInputpower) >= cmd.deltaA) + || (!cmd.direction && abs(m_runningInputpower - m_idleInputpower) <= cmd.deltaA) ) + { + ++cmd.okcount; + eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount); + if ( cmd.okcount > 1 ) + { + 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; + } + default: + ++m_sec_sequence.current(); + eDebug("[SEC] unhandled sec command"); + } + m_tuneTimer->start(delay,true); + } +} + +void eDVBFrontend::setFrontend() +{ + eDebug("setting frontend..\n"); + if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1) + { + perror("FE_SET_FRONTEND failed"); + return; + } + + if (m_state != stateTuning) + { + m_tuning = 1; + m_state = stateTuning; + m_stateChanged(this); + } + m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent +} + RESULT eDVBFrontend::getFrontendType(int &t) { if (m_type == -1) @@ -361,14 +555,12 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where) if (m_type == -1) return -ENODEV; -#if HAVE_DVB_API_VERSION < 3 - FrontendParameters parm; -#else - dvb_frontend_parameters parm; -#endif - feEvent(-1); - + + m_sec_sequence.clear(); + + eDebug("eDVBFrontend::tune. type: %d", m_type); + switch (m_type) { case feSatellite: @@ -407,25 +599,114 @@ RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where) { eDVBFrontendParametersTerrestrial feparm; if (where.getDVBT(feparm)) + { + eDebug("no -T data"); return -EINVAL; - eFatal("terrestrial tuning nyi"); - } - } - - if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1) - { - perror("FE_SET_FRONTEND failed"); - return errno; + } +#if HAVE_DVB_API_VERSION < 3 + parm.Frequency = feparm.frequency; +#else + parm.frequency = feparm.frequency; +#endif + + switch (feparm.bandwidth) + { + case eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz: +#if HAVE_DVB_API_VERSION < 3 + parm.u.ofdm.bandWidth = +#else + parm.u.ofdm.bandwidth = +#endif + BANDWIDTH_8_MHZ; + break; + case eDVBFrontendParametersTerrestrial::Bandwidth::Bw7MHz: +#if HAVE_DVB_API_VERSION < 3 + parm.u.ofdm.bandWidth = +#else + parm.u.ofdm.bandwidth = +#endif + BANDWIDTH_7_MHZ; + break; + case eDVBFrontendParametersTerrestrial::Bandwidth::Bw6MHz: +#if HAVE_DVB_API_VERSION < 3 + parm.u.ofdm.bandWidth = +#else + parm.u.ofdm.bandwidth = +#endif + BANDWIDTH_6_MHZ; + break; + case eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto: +#if HAVE_DVB_API_VERSION < 3 + parm.u.ofdm.bandWidth = +#else + parm.u.ofdm.bandwidth = +#endif + BANDWIDTH_AUTO; + break; + default: + eWarning("invalid OFDM bandwith"); + return -EINVAL; + } + + parm.u.ofdm.code_rate_HP = FEC_AUTO; + parm.u.ofdm.code_rate_LP = FEC_AUTO; + + switch (feparm.modulation) + { + case eDVBFrontendParametersTerrestrial::Modulation::QPSK: + parm.u.ofdm.constellation = QPSK; + break; + case eDVBFrontendParametersTerrestrial::Modulation::QAM16: + parm.u.ofdm.constellation = QAM_16; + break; + case eDVBFrontendParametersTerrestrial::Modulation::Auto: + parm.u.ofdm.constellation = QAM_AUTO; + break; + } + + switch (feparm.transmission_mode) + { + case eDVBFrontendParametersTerrestrial::TransmissionMode::TM2k: +#if HAVE_DVB_API_VERSION < 3 + parm.u.ofdm.TransmissionMode = +#else + parm.u.ofdm.transmission_mode = +#endif + TRANSMISSION_MODE_2K; + break; + case eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k: +#if HAVE_DVB_API_VERSION < 3 + parm.u.ofdm.TransmissionMode = +#else + parm.u.ofdm.transmission_mode = +#endif + TRANSMISSION_MODE_8K; + break; + case eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto: +#if HAVE_DVB_API_VERSION < 3 + parm.u.ofdm.TransmissionMode = +#else + parm.u.ofdm.transmission_mode = +#endif + TRANSMISSION_MODE_AUTO; + break; + } + + parm.u.ofdm.guard_interval = GUARD_INTERVAL_AUTO; + parm.u.ofdm.hierarchy_information = HIERARCHY_AUTO; +#if HAVE_DVB_API_VERSION < 3 + parm.Inversion = +#else + parm.inversion = +#endif + INVERSION_AUTO; + break; } - - if (m_state != stateTuning) - { - m_tuning = 1; - m_state = stateTuning; - m_stateChanged(this); } - - m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent + + m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) ); + m_tuneTimer->start(0,true); + m_sec_sequence.current() = m_sec_sequence.begin(); return 0; } @@ -497,53 +778,45 @@ RESULT eDVBFrontend::setTone(int t) #endif } +#if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_MASTER_CMD) + #define SEC_DISEQC_SEND_MASTER_CMD _IOW('o', 97, struct secCommand *) +#endif + RESULT eDVBFrontend::sendDiseqc(const eDVBDiseqcCommand &diseqc) { #if HAVE_DVB_API_VERSION < 3 - secCmdSequence seq; - secCommand cmd; - + struct secCommand cmd; cmd.type = SEC_CMDTYPE_DISEQC_RAW; cmd.u.diseqc.cmdtype = diseqc.data[0]; - eDebug("cmdtype is %02x", diseqc.data[0]); cmd.u.diseqc.addr = diseqc.data[1]; - eDebug("cmdaddr is %02x", diseqc.data[1]); cmd.u.diseqc.cmd = diseqc.data[2]; - eDebug("cmd is %02x", diseqc.data[2]); cmd.u.diseqc.numParams = diseqc.len-3; - eDebug("numparams %d", diseqc.len-3); - memcpy(cmd.u.diseqc.params, diseqc.data+3, diseqc.len-3); - for (int i=0; i < diseqc.len-3; ++i ) - eDebugNoNewLine("%02x ", diseqc.data[3+i]); - eDebug(""); - - seq.continuousTone = SEC_TONE_OFF; - seq.voltage = SEC_VOLTAGE_13; - seq.miniCommand = SEC_MINI_NONE; - seq.commands=&cmd; - seq.numCommands=1; - - - if ( ioctl(m_secfd, SEC_SEND_SEQUENCE, &seq) < 0 ) - { - eDebug("SEC_SEND_SEQUENCE failed ( %m )"); - return -EINVAL; - } - return 0; + if (::ioctl(m_secfd, SEC_DISEQC_SEND_MASTER_CMD, &cmd)) #else struct dvb_diseqc_master_cmd cmd; - if (::ioctl(m_fd, FE_SET_TONE, SEC_TONE_OFF)) - return -EINVAL; - usleep(15 * 1000); memcpy(cmd.msg, diseqc.data, diseqc.len); cmd.msg_len = diseqc.len; - if (::ioctl(m_fd, FE_DISEQC_SEND_MASTER_CMD, &cmd)) +#endif + return -EINVAL; + return 0; +} + +#if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_BURST) + #define SEC_DISEQC_SEND_BURST _IO('o', 96) +#endif +RESULT eDVBFrontend::sendToneburst(int burst) +{ +#if HAVE_DVB_API_VERSION < 3 + secMiniCmd cmd = SEC_MINI_NONE; + if ( burst == eDVBSatelliteDiseqcParameters::A ) + cmd = SEC_MINI_A; + else if ( burst == eDVBSatelliteDiseqcParameters::B ) + cmd = SEC_MINI_B; + if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd)) return -EINVAL; - usleep(15 * 1000); #endif - eDebug("diseqc ok"); return 0; } @@ -552,3 +825,30 @@ RESULT eDVBFrontend::setSEC(iDVBSatelliteEquipmentControl *sec) m_sec = sec; return 0; } + +RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list) +{ + m_sec_sequence = list; + return 0; +} + +RESULT eDVBFrontend::getData(int num, int &data) +{ + if ( num < 7 ) + { + data = m_data[num]; + return 0; + } + return -EINVAL; +} + +RESULT eDVBFrontend::setData(int num, int val) +{ + if ( num < 7 ) + { + m_data[num] = val; + return 0; + } + return -EINVAL; +} +