- 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:
- 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);
- break;
- case eSecCommand::SEND_DISEQC:
- sendDiseqc(m_sec_sequence.current()->diseqc);
- 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);
- break;
- case eSecCommand::SET_FRONTEND:
- eDebug("[SEC] setFrontend");
- 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)
- {
+ if (PyDict_SetItemString(dict, key, item))
+ eDebug("put %s to dict failed", key);
+ Py_DECREF(item);
+ }
+ else
+ eDebug("could not create PyObject for %s", key);
+}
+
+void fillDictWithSatelliteData(ePyObject dict, const FRONTENDPARAMETERS &parm, eDVBFrontend *fe)
+{
+ int freq_offset=0;
+ int csw=0;
+ const char *tmp=0;
+ fe->getData(eDVBFrontend::CSW, csw);
+ fe->getData(eDVBFrontend::FREQ_OFFSET, freq_offset);
+ int frequency = parm_frequency + freq_offset;
+ PutToDict(dict, "frequency", frequency);
+ PutToDict(dict, "symbol_rate", parm_u_qpsk_symbol_rate);
+ switch(parm_u_qpsk_fec_inner)
+ {
+ case FEC_1_2:
+ tmp = "FEC_1_2";
+ break;
+ case FEC_2_3:
+ tmp = "FEC_2_3";
+ break;
+ case FEC_3_4:
+ tmp = "FEC_3_4";
+ break;
+ case FEC_5_6:
+ tmp = "FEC_5_6";
+ break;
+ case FEC_7_8:
+ tmp = "FEC_7_8";
+ break;
+ case FEC_NONE:
+ tmp = "FEC_NONE";
+ default:
+ case FEC_AUTO:
+ tmp = "FEC_AUTO";
+ break;
+#if HAVE_DVB_API_VERSION >=3
+ case FEC_S2_8PSK_1_2:
+ case FEC_S2_QPSK_1_2:
+ tmp = "FEC_1_2";
+ break;
+ case FEC_S2_8PSK_2_3:
+ case FEC_S2_QPSK_2_3:
+ tmp = "FEC_2_3";
+ break;
+ case FEC_S2_8PSK_3_4:
+ case FEC_S2_QPSK_3_4:
+ tmp = "FEC_3_4";
+ break;
+ case FEC_S2_8PSK_5_6:
+ case FEC_S2_QPSK_5_6:
+ tmp = "FEC_5_6";
+ break;
+ case FEC_S2_8PSK_7_8:
+ case FEC_S2_QPSK_7_8:
+ tmp = "FEC_7_8";
+ break;
+ case FEC_S2_8PSK_8_9:
+ case FEC_S2_QPSK_8_9:
+ tmp = "FEC_8_9";
+ break;
+ case FEC_S2_8PSK_3_5:
+ case FEC_S2_QPSK_3_5:
+ tmp = "FEC_3_5";
+ break;
+ case FEC_S2_8PSK_4_5:
+ case FEC_S2_QPSK_4_5:
+ tmp = "FEC_4_5";
+ break;
+ case FEC_S2_8PSK_9_10:
+ case FEC_S2_QPSK_9_10:
+ tmp = "FEC_9_10";
+ break;
+#endif
+ }
+#if HAVE_DVB_API_VERSION >=3
+ PutToDict(dict, "modulation",
+ parm_u_qpsk_fec_inner > FEC_S2_QPSK_9_10 ? "8PSK": "QPSK" );
+#else
+ PutToDict(dict, "modulation", "QPSK" );
+#endif
+ PutToDict(dict, "fec_inner", tmp);
+ tmp = parm_u_qpsk_fec_inner > FEC_AUTO ?
+ "DVB-S2" : "DVB-S";
+ PutToDict(dict, "system", tmp);
+}
+
+void fillDictWithCableData(ePyObject dict, const FRONTENDPARAMETERS &parm)
+{
+ const char *tmp=0;
+ PutToDict(dict, "frequency", parm_frequency/1000);
+ PutToDict(dict, "symbol_rate", parm_u_qam_symbol_rate);
+ switch(parm_u_qam_fec_inner)
+ {
+ case FEC_NONE:
+ tmp = "FEC_NONE";
+ break;
+ case FEC_1_2:
+ tmp = "FEC_1_2";
+ break;
+ case FEC_2_3:
+ tmp = "FEC_2_3";
+ break;
+ case FEC_3_4:
+ tmp = "FEC_3_4";
+ break;
+ case FEC_5_6:
+ tmp = "FEC_5_6";
+ break;
+ case FEC_7_8:
+ tmp = "FEC_7_8";
+ break;
+#if HAVE_DVB_API_VERSION >= 3
+ case FEC_8_9:
+ tmp = "FEC_8_9";
+ break;
+#endif
+ default:
+ case FEC_AUTO:
+ tmp = "FEC_AUTO";
+ break;
+ }
+ PutToDict(dict, "fec_inner", tmp);
+ switch(parm_u_qam_modulation)
+ {
+ case QAM_16:
+ tmp = "QAM_16";
+ break;
+ case QAM_32:
+ tmp = "QAM_32";
+ break;
+ case QAM_64:
+ tmp = "QAM_64";
+ break;
+ case QAM_128:
+ tmp = "QAM_128";
+ break;
+ case QAM_256:
+ tmp = "QAM_256";
+ break;
+ default:
+ case QAM_AUTO:
+ tmp = "QAM_AUTO";
+ break;
+ }
+ PutToDict(dict, "modulation", tmp);
+}
+
+void fillDictWithTerrestrialData(ePyObject dict, const FRONTENDPARAMETERS &parm)
+{
+ const char *tmp=0;
+ PutToDict(dict, "frequency", parm_frequency);
+ switch (parm_u_ofdm_bandwidth)
+ {
+ case BANDWIDTH_8_MHZ:
+ tmp = "BANDWIDTH_8_MHZ";
+ break;
+ case BANDWIDTH_7_MHZ:
+ tmp = "BANDWIDTH_7_MHZ";
+ break;
+ case BANDWIDTH_6_MHZ:
+ tmp = "BANDWIDTH_6_MHZ";
+ break;
+ default:
+ case BANDWIDTH_AUTO:
+ tmp = "BANDWIDTH_AUTO";
+ break;
+ }
+ PutToDict(dict, "bandwidth", tmp);
+ switch (parm_u_ofdm_code_rate_LP)
+ {
+ case FEC_1_2:
+ tmp = "FEC_1_2";
+ break;
+ case FEC_2_3:
+ tmp = "FEC_2_3";
+ break;
+ case FEC_3_4:
+ tmp = "FEC_3_4";
+ break;
+ case FEC_5_6:
+ tmp = "FEC_5_6";
+ break;
+ case FEC_7_8:
+ tmp = "FEC_7_8";
+ break;
+ default:
+ case FEC_AUTO:
+ tmp = "FEC_AUTO";
+ break;
+ }
+ PutToDict(dict, "code_rate_lp", tmp);
+ switch (parm_u_ofdm_code_rate_HP)
+ {
+ case FEC_1_2:
+ tmp = "FEC_1_2";
+ break;
+ case FEC_2_3:
+ tmp = "FEC_2_3";
+ break;
+ case FEC_3_4:
+ tmp = "FEC_3_4";
+ break;
+ case FEC_5_6:
+ tmp = "FEC_5_6";
+ break;
+ case FEC_7_8:
+ tmp = "FEC_7_8";
+ break;
+ default:
+ case FEC_AUTO:
+ tmp = "FEC_AUTO";
+ break;
+ }
+ PutToDict(dict, "code_rate_hp", tmp);
+ switch (parm_u_ofdm_constellation)
+ {
+ case QPSK:
+ tmp = "QPSK";
+ break;
+ case QAM_16:
+ tmp = "QAM_16";
+ break;
+ case QAM_64:
+ tmp = "QAM_64";
+ break;
+ default:
+ case QAM_AUTO:
+ tmp = "QAM_AUTO";
+ break;
+ }
+ PutToDict(dict, "constellation", tmp);
+ switch (parm_u_ofdm_transmission_mode)
+ {
+ case TRANSMISSION_MODE_2K:
+ tmp = "TRANSMISSION_MODE_2K";
+ break;
+ case TRANSMISSION_MODE_8K:
+ tmp = "TRANSMISSION_MODE_8K";
+ break;
+ default:
+ case TRANSMISSION_MODE_AUTO:
+ tmp = "TRANSMISSION_MODE_AUTO";
+ break;
+ }
+ PutToDict(dict, "transmission_mode", tmp);
+ switch (parm_u_ofdm_guard_interval)
+ {
+ case GUARD_INTERVAL_1_32:
+ tmp = "GUARD_INTERVAL_1_32";
+ break;
+ case GUARD_INTERVAL_1_16:
+ tmp = "GUARD_INTERVAL_1_16";
+ break;
+ case GUARD_INTERVAL_1_8:
+ tmp = "GUARD_INTERVAL_1_8";
+ break;
+ case GUARD_INTERVAL_1_4:
+ tmp = "GUARD_INTERVAL_1_4";
+ break;
+ default:
+ case GUARD_INTERVAL_AUTO:
+ tmp = "GUARD_INTERVAL_AUTO";
+ break;
+ }
+ PutToDict(dict, "guard_interval", tmp);
+ switch (parm_u_ofdm_hierarchy_information)
+ {
+ case HIERARCHY_NONE:
+ tmp = "HIERARCHY_NONE";
+ break;
+ case HIERARCHY_1:
+ tmp = "HIERARCHY_1";
+ break;
+ case HIERARCHY_2:
+ tmp = "HIERARCHY_2";
+ break;
+ case HIERARCHY_4:
+ tmp = "HIERARCHY_4";
+ break;
+ default:
+ case HIERARCHY_AUTO:
+ tmp = "HIERARCHY_AUTO";
+ break;
+ }
+ PutToDict(dict, "hierarchy_information", tmp);
+}
+
+void eDVBFrontend::getFrontendStatus(ePyObject dest)
+{
+ if (dest && PyDict_Check(dest))
+ {
+ const char *tmp = "UNKNOWN";
+ switch(m_state)
+ {
+ case stateIdle:
+ tmp="IDLE";
+ break;
+ case stateTuning:
+ tmp="TUNING";
+ break;
+ case stateFailed:
+ tmp="FAILED";
+ break;
+ case stateLock:
+ tmp="LOCKED";
+ break;
+ case stateLostLock:
+ tmp="LOSTLOCK";
+ break;
+ default:
+ break;
+ }
+ PutToDict(dest, "tuner_state", tmp);
+ PutToDict(dest, "tuner_locked", readFrontendData(locked));
+ PutToDict(dest, "tuner_synced", readFrontendData(synced));
+ PutToDict(dest, "tuner_bit_error_rate", readFrontendData(bitErrorRate));
+ PutToDict(dest, "tuner_signal_power", readFrontendData(signalPower));
+ int sigPowerdB = readFrontendData(signalPowerdB);
+ if (sigPowerdB == 0x12345678) // not support yet
+ {
+ ePyObject obj=Py_None;
+ Py_INCREF(obj);
+ PutToDict(dest, "tuner_signal_power_db", obj);
+ }
+ else
+ PutToDict(dest, "tuner_signal_power_db", sigPowerdB);
+ PutToDict(dest, "tuner_signal_quality", readFrontendData(signalQuality));
+ }
+}
+
+void eDVBFrontend::getTransponderData(ePyObject dest, bool original)
+{
+ if (m_fd != -1 && dest && PyDict_Check(dest))
+ {
+ switch(m_type)
+ {
+ case feSatellite:
+ case feCable:
+ case feTerrestrial:
+ {
+ FRONTENDPARAMETERS front;
+ if (!original && ioctl(m_fd, FE_GET_FRONTEND, &front)<0)
+ eDebug("FE_GET_FRONTEND (%m)");
+ else
+ {
+ const FRONTENDPARAMETERS &parm = original ? this->parm : front;
+ const char *tmp = "INVERSION_AUTO";
+ switch(parm_inversion)
+ {
+ case INVERSION_ON:
+ tmp = "INVERSION_ON";
+ break;
+ case INVERSION_OFF:
+ tmp = "INVERSION_OFF";
+ break;
+ default:
+ break;
+ }
+ if (tmp)
+ PutToDict(dest, "inversion", tmp);
+
+ switch(m_type)
+ {
+ case feSatellite:
+ fillDictWithSatelliteData(dest, original?parm:front, this);
+ break;
+ case feCable:
+ fillDictWithCableData(dest, original?parm:front);
+ break;
+ case feTerrestrial:
+ fillDictWithTerrestrialData(dest, original?parm:front);
+ break;
+ }
+ }
+ }
+ default:
+ break;
+ }
+ }
+}
+
+void eDVBFrontend::getFrontendData(ePyObject dest)
+{
+ if (dest && PyDict_Check(dest))
+ {
+ const char *tmp=0;
+ PutToDict(dest, "tuner_number", m_dvbid);
+ switch(m_type)
+ {
+ case feSatellite:
+ tmp = "DVB-S";
+ break;
+ case feCable:
+ tmp = "DVB-C";
+ break;
+ case feTerrestrial:
+ tmp = "DVB-T";
+ break;
+ default:
+ tmp = "UNKNOWN";
+ break;
+ }
+ PutToDict(dest, "tuner_type", tmp);
+ }
+}
+
+#ifndef FP_IOCTL_GET_ID
+#define FP_IOCTL_GET_ID 0
+#endif
+int eDVBFrontend::readInputpower()
+{
+ int power=m_slotid; // this is needed for read inputpower from the correct tuner !
+
+ // 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);
+
+ 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::setRotorData(int pos, int cmd)
+{
+ m_data[ROTOR_CMD] = cmd;
+ m_data[ROTOR_POS] = pos;
+ if ( m_data[SATPOS_DEPENDS_PTR] != -1 )
+ {
+ eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) m_data[SATPOS_DEPENDS_PTR];
+ satpos_depends_to_fe->m_frontend->m_data[ROTOR_CMD] = cmd;
+ satpos_depends_to_fe->m_frontend->m_data[ROTOR_POS] = pos;
+ }
+ else
+ {
+ eDVBRegisteredFrontend *next = (eDVBRegisteredFrontend *)m_data[LINKED_NEXT_PTR];
+ while ( (int)next != -1 )
+ {
+ next->m_frontend->m_data[ROTOR_CMD] = cmd;
+ next->m_frontend->m_data[ROTOR_POS] = pos;
+ next = (eDVBRegisteredFrontend *)next->m_frontend->m_data[LINKED_NEXT_PTR];
+ }
+ eDVBRegisteredFrontend *prev = (eDVBRegisteredFrontend *)m_data[LINKED_PREV_PTR];
+ while ( (int)prev != -1 )
+ {
+ prev->m_frontend->m_data[ROTOR_CMD] = cmd;
+ prev->m_frontend->m_data[ROTOR_POS] = pos;
+ prev = (eDVBRegisteredFrontend *)prev->m_frontend->m_data[LINKED_PREV_PTR];
+ }
+ }
+}
+
+void eDVBFrontend::tuneLoop() // called by m_tuneTimer
+{
+ int delay=0;
+ if ( m_sec_sequence && m_sec_sequence.current() != m_sec_sequence.end() )
+ {
+// eDebug("tuneLoop %d\n", m_sec_sequence.current()->cmd);
+ 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:
+ {
+ int voltage = m_sec_sequence.current()++->voltage;
+ eDebug("[SEC] setVoltage %d", voltage);
+ setVoltage(voltage);
+ break;
+ }
+ case eSecCommand::IF_VOLTAGE_GOTO:
+ {
+ eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+ if ( compare.voltage == m_data[CUR_VOLTAGE] && 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_data[CUR_VOLTAGE] && setSecSequencePos(compare.steps) )
+ break;
+ ++m_sec_sequence.current();
+ break;
+ }
+ case eSecCommand::IF_TONE_GOTO:
+ {
+ eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+ if ( compare.tone == m_data[CUR_TONE] && setSecSequencePos(compare.steps) )
+ break;
+ ++m_sec_sequence.current();
+ break;
+ }
+ case eSecCommand::IF_NOT_TONE_GOTO:
+ {
+ eSecCommand::pair &compare = m_sec_sequence.current()->compare;
+ if ( compare.tone != m_data[CUR_TONE] && 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);
+ break;
+ case eSecCommand::SEND_DISEQC:
+ sendDiseqc(m_sec_sequence.current()->diseqc);
+ 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);
+ break;
+ case eSecCommand::SET_FRONTEND:
+ eDebug("[SEC] setFrontend");
+ setFrontend();
+ ++m_sec_sequence.current();
+ break;
+ case eSecCommand::START_TUNE_TIMEOUT:
+ m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent
+ ++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::IF_TIMEOUT_GOTO:
+ if (!m_timeoutCount)
+ {