1 #include <lib/dvb/dvb.h>
2 #include <lib/base/eerror.h>
3 #include <lib/base/nconfig.h> // access to python config
9 #ifndef I2C_SLAVE_FORCE
10 #define I2C_SLAVE_FORCE 0x0706
13 #if HAVE_DVB_API_VERSION < 3
14 #include <ost/frontend.h>
16 #define QAM_AUTO (Modulation)6
17 #define TRANSMISSION_MODE_AUTO (TransmitMode)2
18 #define BANDWIDTH_AUTO (BandWidth)3
19 #define GUARD_INTERVAL_AUTO (GuardInterval)4
20 #define HIERARCHY_AUTO (Hierarchy)4
21 #define parm_frequency parm.Frequency
22 #define parm_inversion parm.Inversion
23 #define parm_u_qpsk_symbol_rate parm.u.qpsk.SymbolRate
24 #define parm_u_qpsk_fec_inner parm.u.qpsk.FEC_inner
25 #define parm_u_qam_symbol_rate parm.u.qam.SymbolRate
26 #define parm_u_qam_fec_inner parm.u.qam.FEC_inner
27 #define parm_u_qam_modulation parm.u.qam.QAM
28 #define parm_u_ofdm_bandwidth parm.u.ofdm.bandWidth
29 #define parm_u_ofdm_code_rate_LP parm.u.ofdm.LP_CodeRate
30 #define parm_u_ofdm_code_rate_HP parm.u.ofdm.HP_CodeRate
31 #define parm_u_ofdm_constellation parm.u.ofdm.Constellation
32 #define parm_u_ofdm_transmission_mode parm.u.ofdm.TransmissionMode
33 #define parm_u_ofdm_guard_interval parm.u.ofdm.guardInterval
34 #define parm_u_ofdm_hierarchy_information parm.u.ofdm.HierarchyInformation
36 #include <linux/dvb/frontend.h>
37 #define parm_frequency parm.frequency
38 #define parm_inversion parm.inversion
39 #define parm_u_qpsk_symbol_rate parm.u.qpsk.symbol_rate
40 #define parm_u_qpsk_fec_inner parm.u.qpsk.fec_inner
41 #define parm_u_qam_symbol_rate parm.u.qam.symbol_rate
42 #define parm_u_qam_fec_inner parm.u.qam.fec_inner
43 #define parm_u_qam_modulation parm.u.qam.modulation
44 #define parm_u_ofdm_bandwidth parm.u.ofdm.bandwidth
45 #define parm_u_ofdm_code_rate_LP parm.u.ofdm.code_rate_LP
46 #define parm_u_ofdm_code_rate_HP parm.u.ofdm.code_rate_HP
47 #define parm_u_ofdm_constellation parm.u.ofdm.constellation
48 #define parm_u_ofdm_transmission_mode parm.u.ofdm.transmission_mode
49 #define parm_u_ofdm_guard_interval parm.u.ofdm.guard_interval
50 #define parm_u_ofdm_hierarchy_information parm.u.ofdm.hierarchy_information
52 #warning "FEC_9_10 already exist in dvb api ... it seems it is now ready for DVB-S2"
54 #define FEC_S2_QPSK_1_2 (fe_code_rate_t)(FEC_AUTO+1)
55 #define FEC_S2_QPSK_2_3 (fe_code_rate_t)(FEC_S2_QPSK_1_2+1)
56 #define FEC_S2_QPSK_3_4 (fe_code_rate_t)(FEC_S2_QPSK_2_3+1)
57 #define FEC_S2_QPSK_5_6 (fe_code_rate_t)(FEC_S2_QPSK_3_4+1)
58 #define FEC_S2_QPSK_7_8 (fe_code_rate_t)(FEC_S2_QPSK_5_6+1)
59 #define FEC_S2_QPSK_8_9 (fe_code_rate_t)(FEC_S2_QPSK_7_8+1)
60 #define FEC_S2_QPSK_3_5 (fe_code_rate_t)(FEC_S2_QPSK_8_9+1)
61 #define FEC_S2_QPSK_4_5 (fe_code_rate_t)(FEC_S2_QPSK_3_5+1)
62 #define FEC_S2_QPSK_9_10 (fe_code_rate_t)(FEC_S2_QPSK_4_5+1)
63 #define FEC_S2_8PSK_1_2 (fe_code_rate_t)(FEC_S2_QPSK_9_10+1)
64 #define FEC_S2_8PSK_2_3 (fe_code_rate_t)(FEC_S2_8PSK_1_2+1)
65 #define FEC_S2_8PSK_3_4 (fe_code_rate_t)(FEC_S2_8PSK_2_3+1)
66 #define FEC_S2_8PSK_5_6 (fe_code_rate_t)(FEC_S2_8PSK_3_4+1)
67 #define FEC_S2_8PSK_7_8 (fe_code_rate_t)(FEC_S2_8PSK_5_6+1)
68 #define FEC_S2_8PSK_8_9 (fe_code_rate_t)(FEC_S2_8PSK_7_8+1)
69 #define FEC_S2_8PSK_3_5 (fe_code_rate_t)(FEC_S2_8PSK_8_9+1)
70 #define FEC_S2_8PSK_4_5 (fe_code_rate_t)(FEC_S2_8PSK_3_5+1)
71 #define FEC_S2_8PSK_9_10 (fe_code_rate_t)(FEC_S2_8PSK_4_5+1)
75 #include <dvbsi++/satellite_delivery_system_descriptor.h>
76 #include <dvbsi++/cable_delivery_system_descriptor.h>
77 #include <dvbsi++/terrestrial_delivery_system_descriptor.h>
79 void eDVBDiseqcCommand::setCommandString(const char *str)
84 int slen = strlen(str);
87 eDebug("invalid diseqc command string length (not 2 byte aligned)");
90 if (slen > MAX_DISEQC_LENGTH*2)
92 eDebug("invalid diseqc command string length (string is to long)");
96 for (int i=0; i < slen; ++i)
98 unsigned char c = str[i];
101 case '0' ... '9': c-=48; break;
102 case 'a' ... 'f': c-=87; break;
103 case 'A' ... 'F': c-=55; break;
105 eDebug("invalid character in hex string..ignore complete diseqc command !");
119 void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescriptor &descriptor)
121 frequency = descriptor.getFrequency() * 10;
122 symbol_rate = descriptor.getSymbolRate() * 100;
123 polarisation = descriptor.getPolarization();
124 fec = descriptor.getFecInner();
125 if ( fec != FEC::fNone && fec > FEC::f9_10 )
127 inversion = Inversion::Unknown;
128 orbital_position = ((descriptor.getOrbitalPosition() >> 12) & 0xF) * 1000;
129 orbital_position += ((descriptor.getOrbitalPosition() >> 8) & 0xF) * 100;
130 orbital_position += ((descriptor.getOrbitalPosition() >> 4) & 0xF) * 10;
131 orbital_position += ((descriptor.getOrbitalPosition()) & 0xF);
132 if (orbital_position && (!descriptor.getWestEastFlag()))
133 orbital_position = 3600 - orbital_position;
134 system = descriptor.getModulationSystem();
135 modulation = descriptor.getModulation();
136 if (system == System::DVB_S && modulation == Modulation::M8PSK)
138 eDebug("satellite_delivery_descriptor non valid modulation type.. force QPSK");
141 roll_off = descriptor.getRollOff();
142 if (system == System::DVB_S2)
144 eDebug("SAT DVB-S2 freq %d, %s, pos %d, sr %d, fec %d, modulation %d, roll_off %d",
146 polarisation ? "hor" : "vert",
154 eDebug("SAT DVB-S freq %d, %s, pos %d, sr %d, fec %d",
156 polarisation ? "hor" : "vert",
162 void eDVBFrontendParametersCable::set(const CableDeliverySystemDescriptor &descriptor)
164 frequency = descriptor.getFrequency() / 10;
165 symbol_rate = descriptor.getSymbolRate() * 100;
166 fec_inner = descriptor.getFecInner();
167 if ( fec_inner == 0xF )
168 fec_inner = FEC::fNone;
169 modulation = descriptor.getModulation();
170 if ( modulation > 0x5 )
171 modulation = Modulation::Auto;
172 inversion = Inversion::Unknown;
173 eDebug("Cable freq %d, mod %d, sr %d, fec %d",
175 modulation, symbol_rate, fec_inner);
178 void eDVBFrontendParametersTerrestrial::set(const TerrestrialDeliverySystemDescriptor &descriptor)
180 frequency = descriptor.getCentreFrequency() * 10;
181 bandwidth = descriptor.getBandwidth();
182 if ( bandwidth > 2 ) // 5Mhz forced to auto
183 bandwidth = Bandwidth::BwAuto;
184 code_rate_HP = descriptor.getCodeRateHpStream();
185 if (code_rate_HP > 4)
186 code_rate_HP = FEC::fAuto;
187 code_rate_LP = descriptor.getCodeRateLpStream();
188 if (code_rate_LP > 4)
189 code_rate_LP = FEC::fAuto;
190 transmission_mode = descriptor.getTransmissionMode();
191 if (transmission_mode > 1) // TM4k forced to auto
192 transmission_mode = TransmissionMode::TMAuto;
193 guard_interval = descriptor.getGuardInterval();
194 if (guard_interval > 3)
195 guard_interval = GuardInterval::GI_Auto;
196 hierarchy = descriptor.getHierarchyInformation()&3;
197 modulation = descriptor.getConstellation();
199 modulation = Modulation::Auto;
200 inversion = Inversion::Unknown;
201 eDebug("Terr freq %d, bw %d, cr_hp %d, cr_lp %d, tm_mode %d, guard %d, hierarchy %d, const %d",
202 frequency, bandwidth, code_rate_HP, code_rate_LP, transmission_mode,
203 guard_interval, hierarchy, modulation);
206 eDVBFrontendParameters::eDVBFrontendParameters(): m_type(-1)
210 DEFINE_REF(eDVBFrontendParameters);
212 RESULT eDVBFrontendParameters::getSystem(int &t) const
220 RESULT eDVBFrontendParameters::getDVBS(eDVBFrontendParametersSatellite &p) const
222 if (m_type != iDVBFrontend::feSatellite)
228 RESULT eDVBFrontendParameters::getDVBC(eDVBFrontendParametersCable &p) const
230 if (m_type != iDVBFrontend::feCable)
236 RESULT eDVBFrontendParameters::getDVBT(eDVBFrontendParametersTerrestrial &p) const
238 if (m_type != iDVBFrontend::feTerrestrial)
244 RESULT eDVBFrontendParameters::setDVBS(const eDVBFrontendParametersSatellite &p, bool no_rotor_command_on_tune)
247 sat.no_rotor_command_on_tune = no_rotor_command_on_tune;
248 m_type = iDVBFrontend::feSatellite;
252 RESULT eDVBFrontendParameters::setDVBC(const eDVBFrontendParametersCable &p)
255 m_type = iDVBFrontend::feCable;
259 RESULT eDVBFrontendParameters::setDVBT(const eDVBFrontendParametersTerrestrial &p)
262 m_type = iDVBFrontend::feTerrestrial;
266 RESULT eDVBFrontendParameters::calculateDifference(const iDVBFrontendParameters *parm, int &diff, bool exact) const
271 if (parm->getSystem(type))
275 diff = 1<<30; // big difference
281 case iDVBFrontend::feSatellite:
283 eDVBFrontendParametersSatellite osat;
284 if (parm->getDVBS(osat))
287 if (sat.orbital_position != osat.orbital_position)
289 else if (sat.polarisation != osat.polarisation)
291 else if (exact && sat.fec != osat.fec && sat.fec != eDVBFrontendParametersSatellite::FEC::fAuto && osat.fec != eDVBFrontendParametersSatellite::FEC::fAuto)
293 else if (exact && sat.modulation != osat.modulation && sat.modulation != eDVBFrontendParametersSatellite::Modulation::Auto && osat.modulation != eDVBFrontendParametersSatellite::Modulation::Auto)
297 diff = abs(sat.frequency - osat.frequency);
298 diff += abs(sat.symbol_rate - osat.symbol_rate);
302 case iDVBFrontend::feCable:
303 eDVBFrontendParametersCable ocable;
304 if (parm->getDVBC(ocable))
307 if (exact && cable.modulation != ocable.modulation
308 && cable.modulation != eDVBFrontendParametersCable::Modulation::Auto
309 && ocable.modulation != eDVBFrontendParametersCable::Modulation::Auto)
311 else if (exact && cable.fec_inner != ocable.fec_inner && cable.fec_inner != eDVBFrontendParametersCable::FEC::fAuto && ocable.fec_inner != eDVBFrontendParametersCable::FEC::fAuto)
315 diff = abs(cable.frequency - ocable.frequency);
316 diff += abs(cable.symbol_rate - ocable.symbol_rate);
319 case iDVBFrontend::feTerrestrial:
320 eDVBFrontendParametersTerrestrial oterrestrial;
321 if (parm->getDVBT(oterrestrial))
325 if (exact && oterrestrial.bandwidth != terrestrial.bandwidth &&
326 oterrestrial.bandwidth != eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto &&
327 terrestrial.bandwidth != eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto)
329 else if (exact && oterrestrial.modulation != terrestrial.modulation &&
330 oterrestrial.modulation != eDVBFrontendParametersTerrestrial::Modulation::Auto &&
331 terrestrial.modulation != eDVBFrontendParametersTerrestrial::Modulation::Auto)
333 else if (exact && oterrestrial.transmission_mode != terrestrial.transmission_mode &&
334 oterrestrial.transmission_mode != eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto &&
335 terrestrial.transmission_mode != eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto)
337 else if (exact && oterrestrial.guard_interval != terrestrial.guard_interval &&
338 oterrestrial.guard_interval != eDVBFrontendParametersTerrestrial::GuardInterval::GI_Auto &&
339 terrestrial.guard_interval != eDVBFrontendParametersTerrestrial::GuardInterval::GI_Auto)
341 else if (exact && oterrestrial.hierarchy != terrestrial.hierarchy &&
342 oterrestrial.hierarchy != eDVBFrontendParametersTerrestrial::Hierarchy::HAuto &&
343 terrestrial.hierarchy != eDVBFrontendParametersTerrestrial::Hierarchy::HAuto)
345 else if (exact && oterrestrial.code_rate_LP != terrestrial.code_rate_LP &&
346 oterrestrial.code_rate_LP != eDVBFrontendParametersTerrestrial::FEC::fAuto &&
347 terrestrial.code_rate_LP != eDVBFrontendParametersTerrestrial::FEC::fAuto)
349 else if (exact && oterrestrial.code_rate_HP != terrestrial.code_rate_HP &&
350 oterrestrial.code_rate_HP != eDVBFrontendParametersTerrestrial::FEC::fAuto &&
351 terrestrial.code_rate_HP != eDVBFrontendParametersTerrestrial::FEC::fAuto)
354 diff = abs(terrestrial.frequency - oterrestrial.frequency);
362 RESULT eDVBFrontendParameters::getHash(unsigned long &hash) const
366 case iDVBFrontend::feSatellite:
368 hash = (sat.orbital_position << 16);
369 hash |= ((sat.frequency/1000)&0xFFFF)|((sat.polarisation&1) << 15);
372 case iDVBFrontend::feCable:
375 case iDVBFrontend::feTerrestrial:
383 DEFINE_REF(eDVBFrontend);
385 int eDVBFrontend::PriorityOrder=0;
387 eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok)
388 :m_enabled(false), m_type(-1), m_dvbid(fe), m_slotid(fe)
389 ,m_fd(-1), m_need_rotor_workaround(false), m_sn(0), m_timeout(0), m_tuneTimer(0)
390 #if HAVE_DVB_API_VERSION < 3
394 #if HAVE_DVB_API_VERSION < 3
395 sprintf(m_filename, "/dev/dvb/card%d/frontend%d", adap, fe);
396 sprintf(m_sec_filename, "/dev/dvb/card%d/sec%d", adap, fe);
398 sprintf(m_filename, "/dev/dvb/adapter%d/frontend%d", adap, fe);
400 m_timeout = new eTimer(eApp);
401 CONNECT(m_timeout->timeout, eDVBFrontend::timeout);
403 m_tuneTimer = new eTimer(eApp);
404 CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop);
406 for (int i=0; i<eDVBFrontend::NUM_DATA_ENTRIES; ++i)
409 m_idleInputpower[0]=m_idleInputpower[1]=0;
411 ok = !openFrontend();
415 int eDVBFrontend::openFrontend()
418 return -1; // already opened
423 #if HAVE_DVB_API_VERSION < 3
424 FrontendInfo fe_info;
426 dvb_frontend_info fe_info;
428 eDebug("opening frontend %d", m_dvbid);
431 m_fd = ::open(m_filename, O_RDWR|O_NONBLOCK);
434 eWarning("failed! (%s) %m", m_filename);
439 eWarning("frontend %d already opened", m_dvbid);
442 if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
444 eWarning("ioctl FE_GET_INFO failed");
450 switch (fe_info.type)
453 m_type = iDVBFrontend::feSatellite;
456 m_type = iDVBFrontend::feCable;
459 m_type = iDVBFrontend::feTerrestrial;
462 eWarning("unknown frontend type.");
467 eDebug("detected %s frontend", "satellite\0cable\0 terrestrial"+fe_info.type*10);
470 #if HAVE_DVB_API_VERSION < 3
471 if (m_type == iDVBFrontend::feSatellite)
475 m_secfd = ::open(m_sec_filename, O_RDWR);
478 eWarning("failed! (%s) %m", m_sec_filename);
485 eWarning("sec %d already opened", m_dvbid);
489 setTone(iDVBFrontend::toneOff);
490 setVoltage(iDVBFrontend::voltageOff);
492 m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read);
493 CONNECT(m_sn->activated, eDVBFrontend::feEvent);
498 int eDVBFrontend::closeFrontend()
500 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)m_data[LINKED_NEXT_PTR];
501 while (linked_fe != (eDVBRegisteredFrontend*)-1)
503 if (linked_fe->m_inuse)
505 eDebug("dont close frontend %d until the linked frontend %d in slot %d is still in use",
506 m_dvbid, linked_fe->m_frontend->getDVBID(), linked_fe->m_frontend->getSlotID());
509 linked_fe->m_frontend->getData(LINKED_NEXT_PTR, (long&)linked_fe);
513 eDebug("close frontend %d", m_dvbid);
515 setTone(iDVBFrontend::toneOff);
516 setVoltage(iDVBFrontend::voltageOff);
518 m_sec->setRotorMoving(false);
522 eWarning("couldnt close frontend %d", m_dvbid);
523 m_data[CSW] = m_data[UCSW] = m_data[TONEBURST] = -1;
525 #if HAVE_DVB_API_VERSION < 3
528 if (!::close(m_secfd))
531 eWarning("couldnt close sec %d", m_dvbid);
540 eDVBFrontend::~eDVBFrontend()
547 void eDVBFrontend::feEvent(int w)
551 #if HAVE_DVB_API_VERSION < 3
554 dvb_frontend_event event;
558 res = ::ioctl(m_fd, FE_GET_EVENT, &event);
560 if (res && (errno == EAGAIN))
565 eWarning("FE_GET_EVENT failed! %m");
572 #if HAVE_DVB_API_VERSION < 3
573 if (event.type == FE_COMPLETION_EV)
575 eDebug("(%d)fe event: status %x, inversion %s", m_dvbid, event.status, (event.parameters.inversion == INVERSION_ON) ? "on" : "off");
576 if (event.status & FE_HAS_LOCK)
586 eDebug("stateLostLock");
587 state = stateLostLock;
588 m_data[CSW] = m_data[UCSW] = m_data[TONEBURST] = -1; // reset diseqc
591 if (m_state != state)
594 m_stateChanged(this);
599 void eDVBFrontend::timeout()
602 if (m_state == stateTuning)
604 m_state = stateFailed;
605 m_stateChanged(this);
609 int eDVBFrontend::readFrontendData(int type)
616 if (ioctl(m_fd, FE_READ_BER, &ber) < 0 && errno != ERANGE)
617 eDebug("FE_READ_BER failed (%m)");
623 if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
624 eDebug("FE_READ_SNR failed (%m)");
627 case signalQualitydB: /* this will move into the driver */
630 if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
631 eDebug("FE_READ_SNR failed (%m)");
632 if (!strcmp(m_description, "BCM4501 (internal)"))
634 unsigned int SDS_SNRE = snr << 16;
636 static float SNR_COEFF[6] = {
639 197418.0 / 4194304.0,
640 -2602183.0 / 4194304.0,
641 20377212.0 / 4194304.0,
642 -37791203.0 / 4194304.0,
645 float fval1, fval2, snr_in_db;
647 fval1 = 12.44714 - (2.0 * log10(SDS_SNRE / 256.0));
648 fval2 = pow(10.0, fval1)-1;
649 fval1 = 10.0 * log10(fval2);
653 fval2 = SNR_COEFF[0];
657 fval2 += SNR_COEFF[i];
663 return (int)(snr_in_db * 100.0);
665 else if (!strcmp(m_description, "Alps BSBE1 702A") || // some frontends with STV0299
666 !strcmp(m_description, "Alps -S") ||
667 !strcmp(m_description, "Philips -S") ||
668 !strcmp(m_description, "LG -S") )
670 float snr_in_db=(snr-39075)/1764.7;
671 return (int)(snr_in_db * 100.0);
672 } else if (!strcmp(m_description, "Alps BSBE2"))
674 return (int)((snr >> 7) * 10.0);
676 eDebug("no SNR dB calculation for frontendtype %s yet", m_description); */
682 if (ioctl(m_fd, FE_READ_SIGNAL_STRENGTH, &strength) < 0 && errno != ERANGE)
683 eDebug("FE_READ_SIGNAL_STRENGTH failed (%m)");
688 #if HAVE_DVB_API_VERSION < 3
689 FrontendStatus status=0;
693 if ( ioctl(m_fd, FE_READ_STATUS, &status) < 0 && errno != ERANGE )
694 eDebug("FE_READ_STATUS failed (%m)");
695 return !!(status&FE_HAS_LOCK);
699 #if HAVE_DVB_API_VERSION < 3
700 FrontendStatus status=0;
704 if ( ioctl(m_fd, FE_READ_STATUS, &status) < 0 && errno != ERANGE )
705 eDebug("FE_READ_STATUS failed (%m)");
706 return !!(status&FE_HAS_SYNC);
714 void PutToDict(ePyObject &dict, const char*key, long value)
716 ePyObject item = PyInt_FromLong(value);
719 if (PyDict_SetItemString(dict, key, item))
720 eDebug("put %s to dict failed", key);
724 eDebug("could not create PyObject for %s", key);
727 void PutToDict(ePyObject &dict, const char*key, ePyObject item)
731 if (PyDict_SetItemString(dict, key, item))
732 eDebug("put %s to dict failed", key);
736 eDebug("invalid PyObject for %s", key);
739 void PutToDict(ePyObject &dict, const char*key, const char *value)
741 ePyObject item = PyString_FromString(value);
744 if (PyDict_SetItemString(dict, key, item))
745 eDebug("put %s to dict failed", key);
749 eDebug("could not create PyObject for %s", key);
752 void fillDictWithSatelliteData(ePyObject dict, const FRONTENDPARAMETERS &parm, eDVBFrontend *fe)
757 fe->getData(eDVBFrontend::CSW, csw);
758 fe->getData(eDVBFrontend::FREQ_OFFSET, freq_offset);
759 int frequency = parm_frequency + freq_offset;
760 PutToDict(dict, "frequency", frequency);
761 PutToDict(dict, "symbol_rate", parm_u_qpsk_symbol_rate);
762 switch(parm_u_qpsk_fec_inner)
785 #if HAVE_DVB_API_VERSION >=3
786 case FEC_S2_8PSK_1_2:
787 case FEC_S2_QPSK_1_2:
790 case FEC_S2_8PSK_2_3:
791 case FEC_S2_QPSK_2_3:
794 case FEC_S2_8PSK_3_4:
795 case FEC_S2_QPSK_3_4:
798 case FEC_S2_8PSK_5_6:
799 case FEC_S2_QPSK_5_6:
802 case FEC_S2_8PSK_7_8:
803 case FEC_S2_QPSK_7_8:
806 case FEC_S2_8PSK_8_9:
807 case FEC_S2_QPSK_8_9:
810 case FEC_S2_8PSK_3_5:
811 case FEC_S2_QPSK_3_5:
814 case FEC_S2_8PSK_4_5:
815 case FEC_S2_QPSK_4_5:
818 case FEC_S2_8PSK_9_10:
819 case FEC_S2_QPSK_9_10:
824 #if HAVE_DVB_API_VERSION >=3
825 PutToDict(dict, "modulation",
826 parm_u_qpsk_fec_inner > FEC_S2_QPSK_9_10 ? "8PSK": "QPSK" );
828 PutToDict(dict, "modulation", "QPSK" );
830 PutToDict(dict, "fec_inner", tmp);
831 tmp = parm_u_qpsk_fec_inner > FEC_AUTO ?
833 PutToDict(dict, "system", tmp);
836 void fillDictWithCableData(ePyObject dict, const FRONTENDPARAMETERS &parm)
839 PutToDict(dict, "frequency", parm_frequency/1000);
840 PutToDict(dict, "symbol_rate", parm_u_qam_symbol_rate);
841 switch(parm_u_qam_fec_inner)
861 #if HAVE_DVB_API_VERSION >= 3
871 PutToDict(dict, "fec_inner", tmp);
872 switch(parm_u_qam_modulation)
894 PutToDict(dict, "modulation", tmp);
897 void fillDictWithTerrestrialData(ePyObject dict, const FRONTENDPARAMETERS &parm)
900 PutToDict(dict, "frequency", parm_frequency);
901 switch (parm_u_ofdm_bandwidth)
903 case BANDWIDTH_8_MHZ:
904 tmp = "BANDWIDTH_8_MHZ";
906 case BANDWIDTH_7_MHZ:
907 tmp = "BANDWIDTH_7_MHZ";
909 case BANDWIDTH_6_MHZ:
910 tmp = "BANDWIDTH_6_MHZ";
914 tmp = "BANDWIDTH_AUTO";
917 PutToDict(dict, "bandwidth", tmp);
918 switch (parm_u_ofdm_code_rate_LP)
940 PutToDict(dict, "code_rate_lp", tmp);
941 switch (parm_u_ofdm_code_rate_HP)
963 PutToDict(dict, "code_rate_hp", tmp);
964 switch (parm_u_ofdm_constellation)
980 PutToDict(dict, "constellation", tmp);
981 switch (parm_u_ofdm_transmission_mode)
983 case TRANSMISSION_MODE_2K:
984 tmp = "TRANSMISSION_MODE_2K";
986 case TRANSMISSION_MODE_8K:
987 tmp = "TRANSMISSION_MODE_8K";
990 case TRANSMISSION_MODE_AUTO:
991 tmp = "TRANSMISSION_MODE_AUTO";
994 PutToDict(dict, "transmission_mode", tmp);
995 switch (parm_u_ofdm_guard_interval)
997 case GUARD_INTERVAL_1_32:
998 tmp = "GUARD_INTERVAL_1_32";
1000 case GUARD_INTERVAL_1_16:
1001 tmp = "GUARD_INTERVAL_1_16";
1003 case GUARD_INTERVAL_1_8:
1004 tmp = "GUARD_INTERVAL_1_8";
1006 case GUARD_INTERVAL_1_4:
1007 tmp = "GUARD_INTERVAL_1_4";
1010 case GUARD_INTERVAL_AUTO:
1011 tmp = "GUARD_INTERVAL_AUTO";
1014 PutToDict(dict, "guard_interval", tmp);
1015 switch (parm_u_ofdm_hierarchy_information)
1017 case HIERARCHY_NONE:
1018 tmp = "HIERARCHY_NONE";
1021 tmp = "HIERARCHY_1";
1024 tmp = "HIERARCHY_2";
1027 tmp = "HIERARCHY_4";
1030 case HIERARCHY_AUTO:
1031 tmp = "HIERARCHY_AUTO";
1034 PutToDict(dict, "hierarchy_information", tmp);
1037 void eDVBFrontend::getFrontendStatus(ePyObject dest)
1039 if (dest && PyDict_Check(dest))
1041 const char *tmp = "UNKNOWN";
1062 PutToDict(dest, "tuner_state", tmp);
1063 PutToDict(dest, "tuner_locked", readFrontendData(locked));
1064 PutToDict(dest, "tuner_synced", readFrontendData(synced));
1065 PutToDict(dest, "tuner_bit_error_rate", readFrontendData(bitErrorRate));
1066 PutToDict(dest, "tuner_signal_quality", readFrontendData(signalQuality));
1067 int sigQualitydB = readFrontendData(signalQualitydB);
1068 if (sigQualitydB == 0x12345678) // not support yet
1070 ePyObject obj=Py_None;
1072 PutToDict(dest, "tuner_signal_quality_db", obj);
1075 PutToDict(dest, "tuner_signal_quality_db", sigQualitydB);
1076 PutToDict(dest, "tuner_signal_power", readFrontendData(signalPower));
1080 void eDVBFrontend::getTransponderData(ePyObject dest, bool original)
1082 if (m_fd != -1 && dest && PyDict_Check(dest))
1090 FRONTENDPARAMETERS front;
1091 if (!original && ioctl(m_fd, FE_GET_FRONTEND, &front)<0)
1092 eDebug("FE_GET_FRONTEND (%m)");
1095 const FRONTENDPARAMETERS &parm = original ? this->parm : front;
1096 const char *tmp = "INVERSION_AUTO";
1097 switch(parm_inversion)
1100 tmp = "INVERSION_ON";
1103 tmp = "INVERSION_OFF";
1109 PutToDict(dest, "inversion", tmp);
1114 fillDictWithSatelliteData(dest, original?parm:front, this);
1117 fillDictWithCableData(dest, original?parm:front);
1120 fillDictWithTerrestrialData(dest, original?parm:front);
1131 void eDVBFrontend::getFrontendData(ePyObject dest)
1133 if (dest && PyDict_Check(dest))
1136 PutToDict(dest, "tuner_number", m_dvbid);
1152 PutToDict(dest, "tuner_type", tmp);
1156 #ifndef FP_IOCTL_GET_ID
1157 #define FP_IOCTL_GET_ID 0
1159 int eDVBFrontend::readInputpower()
1161 int power=m_slotid; // this is needed for read inputpower from the correct tuner !
1163 sprintf(proc_name, "/proc/stb/fp/lnb_sense%d", m_slotid);
1164 FILE *f=fopen(proc_name, "r");
1167 if (fscanf(f, "%08x", &power) != 1)
1168 eDebug("read %s failed!! (%m)", proc_name);
1170 eDebug("%s is %d\n", proc_name, power);
1175 // open front prozessor
1176 int fp=::open("/dev/dbox/fp0", O_RDWR);
1179 eDebug("couldn't open fp");
1182 static bool old_fp = (::ioctl(fp, FP_IOCTL_GET_ID) < 0);
1183 if ( ioctl( fp, old_fp ? 9 : 0x100, &power ) < 0 )
1185 eDebug("FP_IOCTL_GET_LNB_CURRENT failed (%m)");
1194 bool eDVBFrontend::setSecSequencePos(int steps)
1196 eDebug("set sequence pos %d", steps);
1201 if (m_sec_sequence.current() != m_sec_sequence.end())
1202 ++m_sec_sequence.current();
1207 if (m_sec_sequence.current() != m_sec_sequence.begin() && m_sec_sequence.current() != m_sec_sequence.end())
1208 --m_sec_sequence.current();
1214 void eDVBFrontend::setRotorData(int pos, int cmd)
1216 m_data[ROTOR_CMD] = cmd;
1217 m_data[ROTOR_POS] = pos;
1218 if ( m_data[SATPOS_DEPENDS_PTR] != -1 )
1220 eDVBRegisteredFrontend *satpos_depends_to_fe = (eDVBRegisteredFrontend*) m_data[SATPOS_DEPENDS_PTR];
1221 satpos_depends_to_fe->m_frontend->m_data[ROTOR_CMD] = cmd;
1222 satpos_depends_to_fe->m_frontend->m_data[ROTOR_POS] = pos;
1226 eDVBRegisteredFrontend *next = (eDVBRegisteredFrontend *)m_data[LINKED_NEXT_PTR];
1227 while ( (long)next != -1 )
1229 next->m_frontend->m_data[ROTOR_CMD] = cmd;
1230 next->m_frontend->m_data[ROTOR_POS] = pos;
1231 next = (eDVBRegisteredFrontend *)next->m_frontend->m_data[LINKED_NEXT_PTR];
1233 eDVBRegisteredFrontend *prev = (eDVBRegisteredFrontend *)m_data[LINKED_PREV_PTR];
1234 while ( (long)prev != -1 )
1236 prev->m_frontend->m_data[ROTOR_CMD] = cmd;
1237 prev->m_frontend->m_data[ROTOR_POS] = pos;
1238 prev = (eDVBRegisteredFrontend *)prev->m_frontend->m_data[LINKED_PREV_PTR];
1243 void eDVBFrontend::tuneLoop() // called by m_tuneTimer
1246 if ( m_sec_sequence && m_sec_sequence.current() != m_sec_sequence.end() )
1248 // eDebug("tuneLoop %d\n", m_sec_sequence.current()->cmd);
1249 switch (m_sec_sequence.current()->cmd)
1251 case eSecCommand::SLEEP:
1252 delay = m_sec_sequence.current()++->msec;
1253 eDebug("[SEC] sleep %dms", delay);
1255 case eSecCommand::GOTO:
1256 if ( !setSecSequencePos(m_sec_sequence.current()->steps) )
1257 ++m_sec_sequence.current();
1259 case eSecCommand::SET_VOLTAGE:
1261 int voltage = m_sec_sequence.current()++->voltage;
1262 eDebug("[SEC] setVoltage %d", voltage);
1263 setVoltage(voltage);
1266 case eSecCommand::IF_VOLTAGE_GOTO:
1268 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1269 if ( compare.voltage == m_data[CUR_VOLTAGE] && setSecSequencePos(compare.steps) )
1271 ++m_sec_sequence.current();
1274 case eSecCommand::IF_NOT_VOLTAGE_GOTO:
1276 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1277 if ( compare.voltage != m_data[CUR_VOLTAGE] && setSecSequencePos(compare.steps) )
1279 ++m_sec_sequence.current();
1282 case eSecCommand::IF_TONE_GOTO:
1284 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1285 if ( compare.tone == m_data[CUR_TONE] && setSecSequencePos(compare.steps) )
1287 ++m_sec_sequence.current();
1290 case eSecCommand::IF_NOT_TONE_GOTO:
1292 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1293 if ( compare.tone != m_data[CUR_TONE] && setSecSequencePos(compare.steps) )
1295 ++m_sec_sequence.current();
1298 case eSecCommand::SET_TONE:
1299 eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
1300 setTone(m_sec_sequence.current()++->tone);
1302 case eSecCommand::SEND_DISEQC:
1303 sendDiseqc(m_sec_sequence.current()->diseqc);
1304 eDebugNoNewLine("[SEC] sendDiseqc: ");
1305 for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
1306 eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
1308 ++m_sec_sequence.current();
1310 case eSecCommand::SEND_TONEBURST:
1311 eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst);
1312 sendToneburst(m_sec_sequence.current()++->toneburst);
1314 case eSecCommand::SET_FRONTEND:
1315 eDebug("[SEC] setFrontend");
1317 ++m_sec_sequence.current();
1319 case eSecCommand::START_TUNE_TIMEOUT:
1320 m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent
1321 ++m_sec_sequence.current();
1323 case eSecCommand::SET_TIMEOUT:
1324 m_timeoutCount = m_sec_sequence.current()++->val;
1325 eDebug("[SEC] set timeout %d", m_timeoutCount);
1327 case eSecCommand::IF_TIMEOUT_GOTO:
1328 if (!m_timeoutCount)
1330 eDebug("[SEC] rotor timout");
1331 m_sec->setRotorMoving(false);
1332 setSecSequencePos(m_sec_sequence.current()->steps);
1335 ++m_sec_sequence.current();
1337 case eSecCommand::MEASURE_IDLE_INPUTPOWER:
1339 int idx = m_sec_sequence.current()++->val;
1340 if ( idx == 0 || idx == 1 )
1342 m_idleInputpower[idx] = readInputpower();
1343 eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
1346 eDebug("[SEC] idleInputpower measure index(%d) out of bound !!!", idx);
1349 case eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO:
1351 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1352 int idx = compare.val;
1353 if ( idx == 0 || idx == 1 )
1355 int idle = readInputpower();
1356 int diff = abs(idle-m_idleInputpower[idx]);
1359 eDebug("measure idle(%d) was not okay.. (%d - %d = %d) retry", idx, m_idleInputpower[idx], idle, diff);
1360 setSecSequencePos(compare.steps);
1364 ++m_sec_sequence.current();
1367 case eSecCommand::IF_TUNER_LOCKED_GOTO:
1369 eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
1370 if (readFrontendData(locked))
1372 eDebug("[SEC] locked step %d ok", cmd.okcount);
1374 if (cmd.okcount > 12)
1376 eDebug("ok > 12 .. goto %d\n",m_sec_sequence.current()->steps);
1377 setSecSequencePos(cmd.steps);
1383 eDebug("[SEC] rotor locked step %d failed", cmd.okcount);
1385 if (!m_timeoutCount && m_retryCount > 0)
1389 ++m_sec_sequence.current();
1392 case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
1393 m_runningInputpower = readInputpower();
1394 eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
1395 ++m_sec_sequence.current();
1397 case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
1399 int idleInputpower = m_idleInputpower[ (m_data[CUR_VOLTAGE]&1) ? 0 : 1];
1400 eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
1401 const char *txt = cmd.direction ? "running" : "stopped";
1402 eDebug("[SEC] waiting for rotor %s %d, idle %d, delta %d",
1404 m_runningInputpower,
1407 if ( (cmd.direction && abs(m_runningInputpower - idleInputpower) >= cmd.deltaA)
1408 || (!cmd.direction && abs(m_runningInputpower - idleInputpower) <= cmd.deltaA) )
1411 eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
1412 if ( cmd.okcount > 6 )
1414 m_sec->setRotorMoving(cmd.direction);
1415 eDebug("[SEC] rotor is %s", txt);
1416 if (setSecSequencePos(cmd.steps))
1422 eDebug("[SEC] rotor not %s... reset counter.. increase timeout", txt);
1424 if (!m_timeoutCount && m_retryCount > 0)
1428 ++m_sec_sequence.current();
1431 case eSecCommand::IF_ROTORPOS_VALID_GOTO:
1432 if (m_data[ROTOR_CMD] != -1 && m_data[ROTOR_POS] != -1)
1433 setSecSequencePos(m_sec_sequence.current()->steps);
1435 ++m_sec_sequence.current();
1437 case eSecCommand::INVALIDATE_CURRENT_ROTORPARMS:
1438 eDebug("[SEC] invalidate current rotorparams");
1439 setRotorData(-1,-1);
1440 ++m_sec_sequence.current();
1442 case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
1443 setRotorData(m_data[NEW_ROTOR_POS], m_data[NEW_ROTOR_CMD]);
1444 eDebug("[SEC] update current rotorparams %d %04lx %ld", m_timeoutCount, m_data[ROTOR_CMD], m_data[ROTOR_POS]);
1445 ++m_sec_sequence.current();
1447 case eSecCommand::SET_ROTOR_DISEQC_RETRYS:
1448 m_retryCount = m_sec_sequence.current()++->val;
1449 eDebug("[SEC] set rotor retries %d", m_retryCount);
1451 case eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO:
1454 eDebug("[SEC] no more rotor retrys");
1455 setSecSequencePos(m_sec_sequence.current()->steps);
1458 ++m_sec_sequence.current();
1460 case eSecCommand::SET_POWER_LIMITING_MODE:
1462 if (m_need_rotor_workaround)
1466 // FIXMEEEEEE hardcoded i2c devices for dm7025 and dm8000
1468 sprintf(dev, "/dev/i2c/%d", m_slotid);
1469 else if (m_slotid == 2)
1470 sprintf(dev, "/dev/i2c/2"); // first nim socket on DM8000 use /dev/i2c/2
1471 else if (m_slotid == 3)
1472 sprintf(dev, "/dev/i2c/4"); // second nim socket on DM8000 use /dev/i2c/4
1473 int fd = ::open(dev, O_RDWR);
1475 unsigned char data[2];
1476 ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
1477 if(::read(fd, data, 1) != 1)
1478 eDebug("[SEC] error read lnbp (%m)");
1479 if ( m_sec_sequence.current()->mode == eSecCommand::modeStatic )
1481 data[0] |= 0x80; // enable static current limiting
1482 eDebug("[SEC] set static current limiting");
1486 data[0] &= ~0x80; // enable dynamic current limiting
1487 eDebug("[SEC] set dynamic current limiting");
1489 if(::write(fd, data, 1) != 1)
1490 eDebug("[SEC] error write lnbp (%m)");
1493 ++m_sec_sequence.current();
1497 eDebug("[SEC] unhandled sec command %d",
1498 ++m_sec_sequence.current()->cmd);
1499 ++m_sec_sequence.current();
1501 m_tuneTimer->start(delay,true);
1505 void eDVBFrontend::setFrontend()
1507 eDebug("setting frontend %d", m_dvbid);
1510 if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
1512 perror("FE_SET_FRONTEND failed");
1517 RESULT eDVBFrontend::getFrontendType(int &t)
1525 RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm)
1530 eWarning("no SEC module active!");
1533 res = m_sec->prepare(*this, parm, feparm, 1 << m_slotid);
1536 eDebug("prepare_sat System %d Freq %d Pol %d SR %d INV %d FEC %d orbpos %d",
1539 feparm.polarisation,
1543 feparm.orbital_position);
1544 parm_u_qpsk_symbol_rate = feparm.symbol_rate;
1545 switch (feparm.inversion)
1547 case eDVBFrontendParametersSatellite::Inversion::On:
1548 parm_inversion = INVERSION_ON;
1550 case eDVBFrontendParametersSatellite::Inversion::Off:
1551 parm_inversion = INVERSION_OFF;
1554 case eDVBFrontendParametersSatellite::Inversion::Unknown:
1555 parm_inversion = INVERSION_AUTO;
1558 if (feparm.system == eDVBFrontendParametersSatellite::System::DVB_S)
1561 case eDVBFrontendParametersSatellite::FEC::fNone:
1562 parm_u_qpsk_fec_inner = FEC_NONE;
1564 case eDVBFrontendParametersSatellite::FEC::f1_2:
1565 parm_u_qpsk_fec_inner = FEC_1_2;
1567 case eDVBFrontendParametersSatellite::FEC::f2_3:
1568 parm_u_qpsk_fec_inner = FEC_2_3;
1570 case eDVBFrontendParametersSatellite::FEC::f3_4:
1571 parm_u_qpsk_fec_inner = FEC_3_4;
1573 case eDVBFrontendParametersSatellite::FEC::f5_6:
1574 parm_u_qpsk_fec_inner = FEC_5_6;
1576 case eDVBFrontendParametersSatellite::FEC::f7_8:
1577 parm_u_qpsk_fec_inner = FEC_7_8;
1580 eDebug("no valid fec for DVB-S set.. assume auto");
1581 case eDVBFrontendParametersSatellite::FEC::fAuto:
1582 parm_u_qpsk_fec_inner = FEC_AUTO;
1585 #if HAVE_DVB_API_VERSION >= 3
1590 case eDVBFrontendParametersSatellite::FEC::f1_2:
1591 parm_u_qpsk_fec_inner = FEC_S2_QPSK_1_2;
1593 case eDVBFrontendParametersSatellite::FEC::f2_3:
1594 parm_u_qpsk_fec_inner = FEC_S2_QPSK_2_3;
1596 case eDVBFrontendParametersSatellite::FEC::f3_4:
1597 parm_u_qpsk_fec_inner = FEC_S2_QPSK_3_4;
1599 case eDVBFrontendParametersSatellite::FEC::f3_5:
1600 parm_u_qpsk_fec_inner = FEC_S2_QPSK_3_5;
1602 case eDVBFrontendParametersSatellite::FEC::f4_5:
1603 parm_u_qpsk_fec_inner = FEC_S2_QPSK_4_5;
1605 case eDVBFrontendParametersSatellite::FEC::f5_6:
1606 parm_u_qpsk_fec_inner = FEC_S2_QPSK_5_6;
1608 case eDVBFrontendParametersSatellite::FEC::f7_8:
1609 parm_u_qpsk_fec_inner = FEC_S2_QPSK_7_8;
1611 case eDVBFrontendParametersSatellite::FEC::f8_9:
1612 parm_u_qpsk_fec_inner = FEC_S2_QPSK_8_9;
1614 case eDVBFrontendParametersSatellite::FEC::f9_10:
1615 parm_u_qpsk_fec_inner = FEC_S2_QPSK_9_10;
1618 eDebug("no valid fec for DVB-S2 set.. abort !!");
1621 if (feparm.modulation == eDVBFrontendParametersSatellite::Modulation::M8PSK)
1622 parm_u_qpsk_fec_inner = (fe_code_rate_t)((int)parm_u_qpsk_fec_inner+9);
1623 // 8PSK fec driver values are decimal 9 bigger
1626 // FIXME !!! get frequency range from tuner
1627 if ( parm_frequency < 900000 || parm_frequency > 2200000 )
1629 eDebug("%d mhz out of tuner range.. dont tune", parm_frequency/1000);
1632 eDebug("tuning to %d mhz", parm_frequency/1000);
1637 RESULT eDVBFrontend::prepare_cable(const eDVBFrontendParametersCable &feparm)
1639 parm_frequency = feparm.frequency * 1000;
1640 parm_u_qam_symbol_rate = feparm.symbol_rate;
1641 switch (feparm.modulation)
1643 case eDVBFrontendParametersCable::Modulation::QAM16:
1644 parm_u_qam_modulation = QAM_16;
1646 case eDVBFrontendParametersCable::Modulation::QAM32:
1647 parm_u_qam_modulation = QAM_32;
1649 case eDVBFrontendParametersCable::Modulation::QAM64:
1650 parm_u_qam_modulation = QAM_64;
1652 case eDVBFrontendParametersCable::Modulation::QAM128:
1653 parm_u_qam_modulation = QAM_128;
1655 case eDVBFrontendParametersCable::Modulation::QAM256:
1656 parm_u_qam_modulation = QAM_256;
1659 case eDVBFrontendParametersCable::Modulation::Auto:
1660 parm_u_qam_modulation = QAM_AUTO;
1663 switch (feparm.inversion)
1665 case eDVBFrontendParametersCable::Inversion::On:
1666 parm_inversion = INVERSION_ON;
1668 case eDVBFrontendParametersCable::Inversion::Off:
1669 parm_inversion = INVERSION_OFF;
1672 case eDVBFrontendParametersCable::Inversion::Unknown:
1673 parm_inversion = INVERSION_AUTO;
1676 switch (feparm.fec_inner)
1678 case eDVBFrontendParametersCable::FEC::fNone:
1679 parm_u_qam_fec_inner = FEC_NONE;
1681 case eDVBFrontendParametersCable::FEC::f1_2:
1682 parm_u_qam_fec_inner = FEC_1_2;
1684 case eDVBFrontendParametersCable::FEC::f2_3:
1685 parm_u_qam_fec_inner = FEC_2_3;
1687 case eDVBFrontendParametersCable::FEC::f3_4:
1688 parm_u_qam_fec_inner = FEC_3_4;
1690 case eDVBFrontendParametersCable::FEC::f5_6:
1691 parm_u_qam_fec_inner = FEC_5_6;
1693 case eDVBFrontendParametersCable::FEC::f7_8:
1694 parm_u_qam_fec_inner = FEC_7_8;
1696 #if HAVE_DVB_API_VERSION >= 3
1697 case eDVBFrontendParametersCable::FEC::f8_9:
1698 parm_u_qam_fec_inner = FEC_8_9;
1702 case eDVBFrontendParametersCable::FEC::fAuto:
1703 parm_u_qam_fec_inner = FEC_AUTO;
1706 eDebug("tuning to %d khz, sr %d, fec %d, modulation %d, inversion %d",
1707 parm_frequency/1000,
1708 parm_u_qam_symbol_rate,
1709 parm_u_qam_fec_inner,
1710 parm_u_qam_modulation,
1715 RESULT eDVBFrontend::prepare_terrestrial(const eDVBFrontendParametersTerrestrial &feparm)
1717 parm_frequency = feparm.frequency;
1719 switch (feparm.bandwidth)
1721 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz:
1722 parm_u_ofdm_bandwidth = BANDWIDTH_8_MHZ;
1724 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw7MHz:
1725 parm_u_ofdm_bandwidth = BANDWIDTH_7_MHZ;
1727 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw6MHz:
1728 parm_u_ofdm_bandwidth = BANDWIDTH_6_MHZ;
1731 case eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto:
1732 parm_u_ofdm_bandwidth = BANDWIDTH_AUTO;
1735 switch (feparm.code_rate_LP)
1737 case eDVBFrontendParametersTerrestrial::FEC::f1_2:
1738 parm_u_ofdm_code_rate_LP = FEC_1_2;
1740 case eDVBFrontendParametersTerrestrial::FEC::f2_3:
1741 parm_u_ofdm_code_rate_LP = FEC_2_3;
1743 case eDVBFrontendParametersTerrestrial::FEC::f3_4:
1744 parm_u_ofdm_code_rate_LP = FEC_3_4;
1746 case eDVBFrontendParametersTerrestrial::FEC::f5_6:
1747 parm_u_ofdm_code_rate_LP = FEC_5_6;
1749 case eDVBFrontendParametersTerrestrial::FEC::f7_8:
1750 parm_u_ofdm_code_rate_LP = FEC_7_8;
1753 case eDVBFrontendParametersTerrestrial::FEC::fAuto:
1754 parm_u_ofdm_code_rate_LP = FEC_AUTO;
1757 switch (feparm.code_rate_HP)
1759 case eDVBFrontendParametersTerrestrial::FEC::f1_2:
1760 parm_u_ofdm_code_rate_HP = FEC_1_2;
1762 case eDVBFrontendParametersTerrestrial::FEC::f2_3:
1763 parm_u_ofdm_code_rate_HP = FEC_2_3;
1765 case eDVBFrontendParametersTerrestrial::FEC::f3_4:
1766 parm_u_ofdm_code_rate_HP = FEC_3_4;
1768 case eDVBFrontendParametersTerrestrial::FEC::f5_6:
1769 parm_u_ofdm_code_rate_HP = FEC_5_6;
1771 case eDVBFrontendParametersTerrestrial::FEC::f7_8:
1772 parm_u_ofdm_code_rate_HP = FEC_7_8;
1775 case eDVBFrontendParametersTerrestrial::FEC::fAuto:
1776 parm_u_ofdm_code_rate_HP = FEC_AUTO;
1779 switch (feparm.modulation)
1781 case eDVBFrontendParametersTerrestrial::Modulation::QPSK:
1782 parm_u_ofdm_constellation = QPSK;
1784 case eDVBFrontendParametersTerrestrial::Modulation::QAM16:
1785 parm_u_ofdm_constellation = QAM_16;
1787 case eDVBFrontendParametersTerrestrial::Modulation::QAM64:
1788 parm_u_ofdm_constellation = QAM_64;
1791 case eDVBFrontendParametersTerrestrial::Modulation::Auto:
1792 parm_u_ofdm_constellation = QAM_AUTO;
1795 switch (feparm.transmission_mode)
1797 case eDVBFrontendParametersTerrestrial::TransmissionMode::TM2k:
1798 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_2K;
1800 case eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k:
1801 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_8K;
1804 case eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto:
1805 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_AUTO;
1808 switch (feparm.guard_interval)
1810 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_32:
1811 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_32;
1813 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_16:
1814 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_16;
1816 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_8:
1817 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_8;
1819 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_4:
1820 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_4;
1823 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_Auto:
1824 parm_u_ofdm_guard_interval = GUARD_INTERVAL_AUTO;
1827 switch (feparm.hierarchy)
1829 case eDVBFrontendParametersTerrestrial::Hierarchy::HNone:
1830 parm_u_ofdm_hierarchy_information = HIERARCHY_NONE;
1832 case eDVBFrontendParametersTerrestrial::Hierarchy::H1:
1833 parm_u_ofdm_hierarchy_information = HIERARCHY_1;
1835 case eDVBFrontendParametersTerrestrial::Hierarchy::H2:
1836 parm_u_ofdm_hierarchy_information = HIERARCHY_2;
1838 case eDVBFrontendParametersTerrestrial::Hierarchy::H4:
1839 parm_u_ofdm_hierarchy_information = HIERARCHY_4;
1842 case eDVBFrontendParametersTerrestrial::Hierarchy::HAuto:
1843 parm_u_ofdm_hierarchy_information = HIERARCHY_AUTO;
1846 switch (feparm.inversion)
1848 case eDVBFrontendParametersTerrestrial::Inversion::On:
1849 parm_inversion = INVERSION_ON;
1851 case eDVBFrontendParametersTerrestrial::Inversion::Off:
1852 parm_inversion = INVERSION_OFF;
1855 case eDVBFrontendParametersTerrestrial::Inversion::Unknown:
1856 parm_inversion = INVERSION_AUTO;
1862 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
1864 eDebug("(%d)tune", m_dvbid);
1872 eDebug("no frontend device opened... do not try to tune !!!");
1884 m_sec_sequence.clear();
1890 eDVBFrontendParametersSatellite feparm;
1891 if (where.getDVBS(feparm))
1893 eDebug("no dvbs data!");
1897 m_sec->setRotorMoving(false);
1898 res=prepare_sat(feparm);
1906 eDVBFrontendParametersCable feparm;
1907 if (where.getDVBC(feparm))
1912 res=prepare_cable(feparm);
1916 m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
1917 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
1922 eDVBFrontendParametersTerrestrial feparm;
1923 if (where.getDVBT(feparm))
1925 eDebug("no -T data");
1929 res=prepare_terrestrial(feparm);
1933 std::string enable_5V;
1934 char configStr[255];
1935 snprintf(configStr, 255, "config.Nims.%d.terrestrial_5V", m_slotid);
1936 m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
1937 ePythonConfigQuery::getConfigValue(configStr, enable_5V);
1938 if (enable_5V == "True")
1939 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1941 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltageOff) );
1942 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
1948 m_tuneTimer->start(0,true);
1949 m_sec_sequence.current() = m_sec_sequence.begin();
1951 if (m_state != stateTuning)
1954 m_state = stateTuning;
1955 m_stateChanged(this);
1961 m_tuneTimer->stop();
1965 RESULT eDVBFrontend::connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)
1967 connection = new eConnection(this, m_stateChanged.connect(stateChange));
1971 RESULT eDVBFrontend::setVoltage(int voltage)
1973 if (m_type == feCable)
1975 #if HAVE_DVB_API_VERSION < 3
1978 bool increased=false;
1979 fe_sec_voltage_t vlt;
1981 m_data[CUR_VOLTAGE]=voltage;
1985 for (int i=0; i < 3; ++i) // reset diseqc
1987 vlt = SEC_VOLTAGE_OFF;
1990 #if HAVE_DVB_API_VERSION < 3
1991 vlt = SEC_VOLTAGE_13_5;
1997 vlt = SEC_VOLTAGE_13;
2000 #if HAVE_DVB_API_VERSION < 3
2001 vlt = SEC_VOLTAGE_18_5;
2007 vlt = SEC_VOLTAGE_18;
2012 #if HAVE_DVB_API_VERSION < 3
2013 return ::ioctl(m_secfd, SEC_SET_VOLTAGE, vlt);
2015 if (m_type == feSatellite && ::ioctl(m_fd, FE_ENABLE_HIGH_LNB_VOLTAGE, increased) < 0)
2016 perror("FE_ENABLE_HIGH_LNB_VOLTAGE");
2017 return ::ioctl(m_fd, FE_SET_VOLTAGE, vlt);
2021 RESULT eDVBFrontend::getState(int &state)
2027 RESULT eDVBFrontend::setTone(int t)
2029 if (m_type != feSatellite)
2031 #if HAVE_DVB_API_VERSION < 3
2034 fe_sec_tone_mode_t tone;
2043 tone = SEC_TONE_OFF;
2048 #if HAVE_DVB_API_VERSION < 3
2049 return ::ioctl(m_secfd, SEC_SET_TONE, tone);
2051 return ::ioctl(m_fd, FE_SET_TONE, tone);
2055 #if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_MASTER_CMD)
2056 #define SEC_DISEQC_SEND_MASTER_CMD _IOW('o', 97, struct secCommand *)
2059 RESULT eDVBFrontend::sendDiseqc(const eDVBDiseqcCommand &diseqc)
2061 #if HAVE_DVB_API_VERSION < 3
2062 struct secCommand cmd;
2063 cmd.type = SEC_CMDTYPE_DISEQC_RAW;
2064 cmd.u.diseqc.cmdtype = diseqc.data[0];
2065 cmd.u.diseqc.addr = diseqc.data[1];
2066 cmd.u.diseqc.cmd = diseqc.data[2];
2067 cmd.u.diseqc.numParams = diseqc.len-3;
2068 memcpy(cmd.u.diseqc.params, diseqc.data+3, diseqc.len-3);
2069 if (::ioctl(m_secfd, SEC_DISEQC_SEND_MASTER_CMD, &cmd))
2071 struct dvb_diseqc_master_cmd cmd;
2072 memcpy(cmd.msg, diseqc.data, diseqc.len);
2073 cmd.msg_len = diseqc.len;
2074 if (::ioctl(m_fd, FE_DISEQC_SEND_MASTER_CMD, &cmd))
2080 #if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_BURST)
2081 #define SEC_DISEQC_SEND_BURST _IO('o', 96)
2083 RESULT eDVBFrontend::sendToneburst(int burst)
2085 #if HAVE_DVB_API_VERSION < 3
2086 secMiniCmd cmd = SEC_MINI_NONE;
2088 fe_sec_mini_cmd_t cmd = SEC_MINI_A;
2090 if ( burst == eDVBSatelliteDiseqcParameters::A )
2092 else if ( burst == eDVBSatelliteDiseqcParameters::B )
2094 #if HAVE_DVB_API_VERSION < 3
2095 if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd))
2098 if (::ioctl(m_fd, FE_DISEQC_SEND_BURST, cmd))
2104 RESULT eDVBFrontend::setSEC(iDVBSatelliteEquipmentControl *sec)
2110 RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list)
2112 m_sec_sequence = list;
2116 RESULT eDVBFrontend::getData(int num, long &data)
2118 if ( num < NUM_DATA_ENTRIES )
2126 RESULT eDVBFrontend::setData(int num, long val)
2128 if ( num < NUM_DATA_ENTRIES )
2136 int eDVBFrontend::isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)
2139 if (feparm->getSystem(type) || type != m_type || !m_enabled)
2142 if (m_type == eDVBFrontend::feSatellite)
2145 eDVBFrontendParametersSatellite sat_parm;
2146 int ret = feparm->getDVBS(sat_parm);
2148 return m_sec->canTune(sat_parm, this, 1 << m_slotid);
2150 else if (m_type == eDVBFrontend::feCable)
2151 return 2; // more prio for cable frontends
2155 bool eDVBFrontend::setSlotInfo(ePyObject obj)
2157 ePyObject Id, Descr, Enabled;
2158 if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3)
2160 Id = PyTuple_GET_ITEM(obj, 0);
2161 Descr = PyTuple_GET_ITEM(obj, 1);
2162 Enabled = PyTuple_GET_ITEM(obj, 2);
2163 if (!PyInt_Check(Id) || !PyString_Check(Descr) || !PyBool_Check(Enabled))
2165 strcpy(m_description, PyString_AS_STRING(Descr));
2166 m_slotid = PyInt_AsLong(Id);
2167 m_enabled = Enabled == Py_True;
2168 // HACK.. the rotor workaround is neede for all NIMs with LNBP21 voltage regulator...
2169 m_need_rotor_workaround = !!strstr(m_description, "Alps BSBE1") ||
2170 !!strstr(m_description, "Alps BSBE2") ||
2171 !!strstr(m_description, "Alps -S");
2172 eDebug("setSlotInfo for dvb frontend %d to slotid %d, descr %s, need rotorworkaround %s, enabled %s",
2173 m_dvbid, m_slotid, m_description, m_need_rotor_workaround ? "Yes" : "No", m_enabled ? "Yes" : "No" );
2176 PyErr_SetString(PyExc_StandardError,
2177 "eDVBFrontend::setSlotInfo must get a tuple with first param slotid, second param slot description and third param enabled boolean");