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 eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok)
386 :m_type(-1), m_fe(fe), m_fd(-1), m_sn(0), m_timeout(0), m_tuneTimer(0)
387 #if HAVE_DVB_API_VERSION < 3
391 #if HAVE_DVB_API_VERSION < 3
392 sprintf(m_filename, "/dev/dvb/card%d/frontend%d", adap, fe);
393 sprintf(m_sec_filename, "/dev/dvb/card%d/sec%d", adap, fe);
395 sprintf(m_filename, "/dev/dvb/adapter%d/frontend%d", adap, fe);
397 m_timeout = new eTimer(eApp);
398 CONNECT(m_timeout->timeout, eDVBFrontend::timeout);
400 m_tuneTimer = new eTimer(eApp);
401 CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop);
403 for (int i=0; i<eDVBFrontend::NUM_DATA_ENTRIES; ++i)
406 m_idleInputpower[0]=m_idleInputpower[1]=0;
408 ok = !openFrontend();
412 int eDVBFrontend::openFrontend()
415 return -1; // already opened
420 #if HAVE_DVB_API_VERSION < 3
423 m_secfd = ::open(m_sec_filename, O_RDWR);
426 eWarning("failed! (%s) %m", m_sec_filename);
431 eWarning("sec %d already opened", m_fe);
432 FrontendInfo fe_info;
434 dvb_frontend_info fe_info;
436 eDebug("opening frontend %d", m_fe);
439 m_fd = ::open(m_filename, O_RDWR|O_NONBLOCK);
442 eWarning("failed! (%s) %m", m_filename);
443 #if HAVE_DVB_API_VERSION < 3
451 eWarning("frontend %d already opened", m_fe);
454 if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
456 eWarning("ioctl FE_GET_INFO failed");
459 #if HAVE_DVB_API_VERSION < 3
466 switch (fe_info.type)
469 m_type = iDVBFrontend::feSatellite;
472 m_type = iDVBFrontend::feCable;
475 m_type = iDVBFrontend::feTerrestrial;
478 eWarning("unknown frontend type.");
481 #if HAVE_DVB_API_VERSION < 3
487 eDebug("detected %s frontend", "satellite\0cable\0 terrestrial"+fe_info.type*10);
490 setTone(iDVBFrontend::toneOff);
491 setVoltage(iDVBFrontend::voltageOff);
493 m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read);
494 CONNECT(m_sn->activated, eDVBFrontend::feEvent);
499 int eDVBFrontend::closeFrontend()
501 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)m_data[LINKED_NEXT_PTR];
502 while (linked_fe != (eDVBRegisteredFrontend*)-1)
504 if (linked_fe->m_inuse)
506 eDebug("dont close frontend %d until the linked frontend %d is still in use",
507 m_fe, linked_fe->m_frontend->getID());
510 linked_fe->m_frontend->getData(LINKED_NEXT_PTR, (int&)linked_fe);
514 eDebug("close frontend %d", m_fe);
516 setTone(iDVBFrontend::toneOff);
517 setVoltage(iDVBFrontend::voltageOff);
519 m_sec->setRotorMoving(false);
523 eWarning("couldnt close frontend %d", m_fe);
524 m_data[CSW] = m_data[UCSW] = m_data[TONEBURST] = -1;
526 #if HAVE_DVB_API_VERSION < 3
529 if (!::close(m_secfd))
532 eWarning("couldnt close sec %d", m_fe);
541 eDVBFrontend::~eDVBFrontend()
548 void eDVBFrontend::feEvent(int w)
552 #if HAVE_DVB_API_VERSION < 3
555 dvb_frontend_event event;
559 res = ::ioctl(m_fd, FE_GET_EVENT, &event);
561 if (res && (errno == EAGAIN))
566 eWarning("FE_GET_EVENT failed! %m");
573 #if HAVE_DVB_API_VERSION < 3
574 if (event.type == FE_COMPLETION_EV)
576 eDebug("(%d)fe event: status %x, inversion %s", m_fe, event.status, (event.parameters.inversion == INVERSION_ON) ? "on" : "off");
577 if (event.status & FE_HAS_LOCK)
587 eDebug("stateLostLock");
588 state = stateLostLock;
589 m_data[CSW] = m_data[UCSW] = m_data[TONEBURST] = -1; // reset diseqc
592 if (m_state != state)
595 m_stateChanged(this);
600 void eDVBFrontend::timeout()
603 if (m_state == stateTuning)
605 m_state = stateFailed;
606 m_stateChanged(this);
610 int eDVBFrontend::readFrontendData(int type)
617 if (ioctl(m_fd, FE_READ_BER, &ber) < 0 && errno != ERANGE)
618 eDebug("FE_READ_BER failed (%m)");
624 if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
625 eDebug("FE_READ_SNR failed (%m)");
631 if (ioctl(m_fd, FE_READ_SIGNAL_STRENGTH, &strength) < 0 && errno != ERANGE)
632 eDebug("FE_READ_SIGNAL_STRENGTH failed (%m)");
637 #if HAVE_DVB_API_VERSION < 3
638 FrontendStatus status=0;
642 if ( ioctl(m_fd, FE_READ_STATUS, &status) < 0 && errno != ERANGE )
643 eDebug("FE_READ_STATUS failed (%m)");
644 return !!(status&FE_HAS_LOCK);
648 #if HAVE_DVB_API_VERSION < 3
649 FrontendStatus status=0;
653 if ( ioctl(m_fd, FE_READ_STATUS, &status) < 0 && errno != ERANGE )
654 eDebug("FE_READ_STATUS failed (%m)");
655 return !!(status&FE_HAS_SYNC);
663 void PutToDict(ePyObject &dict, const char*key, long value)
665 ePyObject item = PyInt_FromLong(value);
668 if (PyDict_SetItemString(dict, key, item))
669 eDebug("put %s to dict failed", key);
673 eDebug("could not create PyObject for %s", key);
676 void PutToDict(ePyObject &dict, const char*key, const char *value)
678 ePyObject item = PyString_FromString(value);
681 if (PyDict_SetItemString(dict, key, item))
682 eDebug("put %s to dict failed", key);
686 eDebug("could not create PyObject for %s", key);
689 void fillDictWithSatelliteData(ePyObject dict, const FRONTENDPARAMETERS &parm, eDVBFrontend *fe)
694 fe->getData(eDVBFrontend::CSW, csw);
695 fe->getData(eDVBFrontend::FREQ_OFFSET, freq_offset);
696 int frequency = parm_frequency + freq_offset;
697 PutToDict(dict, "frequency", frequency);
698 PutToDict(dict, "symbol_rate", parm_u_qpsk_symbol_rate);
699 switch(parm_u_qpsk_fec_inner)
722 #if HAVE_DVB_API_VERSION >=3
723 case FEC_S2_8PSK_1_2:
724 case FEC_S2_QPSK_1_2:
727 case FEC_S2_8PSK_2_3:
728 case FEC_S2_QPSK_2_3:
731 case FEC_S2_8PSK_3_4:
732 case FEC_S2_QPSK_3_4:
735 case FEC_S2_8PSK_5_6:
736 case FEC_S2_QPSK_5_6:
739 case FEC_S2_8PSK_7_8:
740 case FEC_S2_QPSK_7_8:
743 case FEC_S2_8PSK_8_9:
744 case FEC_S2_QPSK_8_9:
747 case FEC_S2_8PSK_3_5:
748 case FEC_S2_QPSK_3_5:
751 case FEC_S2_8PSK_4_5:
752 case FEC_S2_QPSK_4_5:
755 case FEC_S2_8PSK_9_10:
756 case FEC_S2_QPSK_9_10:
761 #if HAVE_DVB_API_VERSION >=3
762 PutToDict(dict, "modulation",
763 parm_u_qpsk_fec_inner > FEC_S2_QPSK_9_10 ? "8PSK": "QPSK" );
765 PutToDict(dict, "modulation", "QPSK" );
767 PutToDict(dict, "fec_inner", tmp);
768 tmp = parm_u_qpsk_fec_inner > FEC_AUTO ?
770 PutToDict(dict, "system", tmp);
773 void fillDictWithCableData(ePyObject dict, const FRONTENDPARAMETERS &parm)
776 PutToDict(dict, "frequency", parm_frequency/1000);
777 PutToDict(dict, "symbol_rate", parm_u_qam_symbol_rate);
778 switch(parm_u_qam_fec_inner)
798 #if HAVE_DVB_API_VERSION >= 3
808 PutToDict(dict, "fec_inner", tmp);
809 switch(parm_u_qam_modulation)
831 PutToDict(dict, "modulation", tmp);
834 void fillDictWithTerrestrialData(ePyObject dict, const FRONTENDPARAMETERS &parm)
837 PutToDict(dict, "frequency", parm_frequency);
838 switch (parm_u_ofdm_bandwidth)
840 case BANDWIDTH_8_MHZ:
841 tmp = "BANDWIDTH_8_MHZ";
843 case BANDWIDTH_7_MHZ:
844 tmp = "BANDWIDTH_7_MHZ";
846 case BANDWIDTH_6_MHZ:
847 tmp = "BANDWIDTH_6_MHZ";
851 tmp = "BANDWIDTH_AUTO";
854 PutToDict(dict, "bandwidth", tmp);
855 switch (parm_u_ofdm_code_rate_LP)
877 PutToDict(dict, "code_rate_lp", tmp);
878 switch (parm_u_ofdm_code_rate_HP)
900 PutToDict(dict, "code_rate_hp", tmp);
901 switch (parm_u_ofdm_constellation)
917 PutToDict(dict, "constellation", tmp);
918 switch (parm_u_ofdm_transmission_mode)
920 case TRANSMISSION_MODE_2K:
921 tmp = "TRANSMISSION_MODE_2K";
923 case TRANSMISSION_MODE_8K:
924 tmp = "TRANSMISSION_MODE_8K";
927 case TRANSMISSION_MODE_AUTO:
928 tmp = "TRANSMISSION_MODE_AUTO";
931 PutToDict(dict, "transmission_mode", tmp);
932 switch (parm_u_ofdm_guard_interval)
934 case GUARD_INTERVAL_1_32:
935 tmp = "GUARD_INTERVAL_1_32";
937 case GUARD_INTERVAL_1_16:
938 tmp = "GUARD_INTERVAL_1_16";
940 case GUARD_INTERVAL_1_8:
941 tmp = "GUARD_INTERVAL_1_8";
943 case GUARD_INTERVAL_1_4:
944 tmp = "GUARD_INTERVAL_1_4";
947 case GUARD_INTERVAL_AUTO:
948 tmp = "GUARD_INTERVAL_AUTO";
951 PutToDict(dict, "guard_interval", tmp);
952 switch (parm_u_ofdm_hierarchy_information)
955 tmp = "HIERARCHY_NONE";
968 tmp = "HIERARCHY_AUTO";
971 PutToDict(dict, "hierarchy_information", tmp);
974 PyObject *eDVBFrontend::readTransponderData(bool original)
976 ePyObject ret=PyDict_New();
980 bool read=m_fd != -1;
983 PutToDict(ret, "tuner_number", m_fe);
1001 PutToDict(ret, "tuner_type", tmp);
1005 FRONTENDPARAMETERS front;
1028 PutToDict(ret, "tuner_state", tmp);
1030 PutToDict(ret, "tuner_locked", readFrontendData(locked));
1031 PutToDict(ret, "tuner_synced", readFrontendData(synced));
1032 PutToDict(ret, "tuner_bit_error_rate", readFrontendData(bitErrorRate));
1033 PutToDict(ret, "tuner_signal_power", readFrontendData(signalPower));
1034 PutToDict(ret, "tuner_signal_quality", readFrontendData(signalQuality));
1036 if (!original && ioctl(m_fd, FE_GET_FRONTEND, &front)<0)
1037 eDebug("FE_GET_FRONTEND (%m)");
1040 const FRONTENDPARAMETERS &parm = original ? this->parm : front;
1041 tmp = "INVERSION_AUTO";
1042 switch(parm_inversion)
1045 tmp = "INVERSION_ON";
1048 tmp = "INVERSION_OFF";
1054 PutToDict(ret, "inversion", tmp);
1059 fillDictWithSatelliteData(ret, original?parm:front, this);
1062 fillDictWithCableData(ret, original?parm:front);
1065 fillDictWithTerrestrialData(ret, original?parm:front);
1077 #ifndef FP_IOCTL_GET_ID
1078 #define FP_IOCTL_GET_ID 0
1080 int eDVBFrontend::readInputpower()
1082 int power=m_fe; // this is needed for read inputpower from the correct tuner !
1084 // open front prozessor
1085 int fp=::open("/dev/dbox/fp0", O_RDWR);
1088 eDebug("couldn't open fp");
1091 static bool old_fp = (::ioctl(fp, FP_IOCTL_GET_ID) < 0);
1092 if ( ioctl( fp, old_fp ? 9 : 0x100, &power ) < 0 )
1094 eDebug("FP_IOCTL_GET_LNB_CURRENT failed (%m)");
1102 bool eDVBFrontend::setSecSequencePos(int steps)
1104 eDebug("set sequence pos %d", steps);
1109 if (m_sec_sequence.current() != m_sec_sequence.end())
1110 ++m_sec_sequence.current();
1115 if (m_sec_sequence.current() != m_sec_sequence.begin() && m_sec_sequence.current() != m_sec_sequence.end())
1116 --m_sec_sequence.current();
1122 void eDVBFrontend::tuneLoop() // called by m_tuneTimer
1125 if ( m_sec_sequence && m_sec_sequence.current() != m_sec_sequence.end() )
1127 // eDebug("tuneLoop %d\n", m_sec_sequence.current()->cmd);
1128 switch (m_sec_sequence.current()->cmd)
1130 case eSecCommand::SLEEP:
1131 delay = m_sec_sequence.current()++->msec;
1132 eDebug("[SEC] sleep %dms", delay);
1134 case eSecCommand::GOTO:
1135 if ( !setSecSequencePos(m_sec_sequence.current()->steps) )
1136 ++m_sec_sequence.current();
1138 case eSecCommand::SET_VOLTAGE:
1140 int voltage = m_sec_sequence.current()++->voltage;
1141 eDebug("[SEC] setVoltage %d", voltage);
1142 setVoltage(voltage);
1145 case eSecCommand::IF_VOLTAGE_GOTO:
1147 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1148 if ( compare.voltage == m_data[CUR_VOLTAGE] && setSecSequencePos(compare.steps) )
1150 ++m_sec_sequence.current();
1153 case eSecCommand::IF_NOT_VOLTAGE_GOTO:
1155 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1156 if ( compare.voltage != m_data[CUR_VOLTAGE] && setSecSequencePos(compare.steps) )
1158 ++m_sec_sequence.current();
1161 case eSecCommand::IF_TONE_GOTO:
1163 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1164 if ( compare.tone == m_data[CUR_TONE] && setSecSequencePos(compare.steps) )
1166 ++m_sec_sequence.current();
1169 case eSecCommand::IF_NOT_TONE_GOTO:
1171 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1172 if ( compare.tone != m_data[CUR_TONE] && setSecSequencePos(compare.steps) )
1174 ++m_sec_sequence.current();
1177 case eSecCommand::SET_TONE:
1178 eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
1179 setTone(m_sec_sequence.current()++->tone);
1181 case eSecCommand::SEND_DISEQC:
1182 sendDiseqc(m_sec_sequence.current()->diseqc);
1183 eDebugNoNewLine("[SEC] sendDiseqc: ");
1184 for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
1185 eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
1187 ++m_sec_sequence.current();
1189 case eSecCommand::SEND_TONEBURST:
1190 eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst);
1191 sendToneburst(m_sec_sequence.current()++->toneburst);
1193 case eSecCommand::SET_FRONTEND:
1194 eDebug("[SEC] setFrontend");
1196 ++m_sec_sequence.current();
1198 case eSecCommand::START_TUNE_TIMEOUT:
1199 m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent
1200 ++m_sec_sequence.current();
1202 case eSecCommand::SET_TIMEOUT:
1203 m_timeoutCount = m_sec_sequence.current()++->val;
1204 eDebug("[SEC] set timeout %d", m_timeoutCount);
1206 case eSecCommand::IF_TIMEOUT_GOTO:
1207 if (!m_timeoutCount)
1209 eDebug("[SEC] rotor timout");
1210 m_sec->setRotorMoving(false);
1211 setSecSequencePos(m_sec_sequence.current()->steps);
1214 ++m_sec_sequence.current();
1216 case eSecCommand::MEASURE_IDLE_INPUTPOWER:
1218 int idx = m_sec_sequence.current()++->val;
1219 if ( idx == 0 || idx == 1 )
1221 m_idleInputpower[idx] = readInputpower();
1222 eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
1225 eDebug("[SEC] idleInputpower measure index(%d) out of bound !!!", idx);
1228 case eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO:
1230 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1231 int idx = compare.val;
1232 if ( idx == 0 || idx == 1 )
1234 int idle = readInputpower();
1235 int diff = abs(idle-m_idleInputpower[idx]);
1238 eDebug("measure idle(%d) was not okay.. (%d - %d = %d) retry", idx, m_idleInputpower[idx], idle, diff);
1239 setSecSequencePos(compare.steps);
1243 ++m_sec_sequence.current();
1246 case eSecCommand::IF_TUNER_LOCKED_GOTO:
1248 eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
1249 if (readFrontendData(locked))
1251 eDebug("[SEC] locked step %d ok", cmd.okcount);
1253 if (cmd.okcount > 12)
1255 eDebug("ok > 12 .. goto %d\n",m_sec_sequence.current()->steps);
1256 setSecSequencePos(cmd.steps);
1262 eDebug("[SEC] rotor locked step %d failed", cmd.okcount);
1264 if (!m_timeoutCount && m_retryCount > 0)
1268 ++m_sec_sequence.current();
1271 case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
1272 m_runningInputpower = readInputpower();
1273 eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
1274 ++m_sec_sequence.current();
1276 case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
1278 int idleInputpower = m_idleInputpower[ (m_data[CUR_VOLTAGE]&1) ? 0 : 1];
1279 eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
1280 const char *txt = cmd.direction ? "running" : "stopped";
1281 eDebug("[SEC] waiting for rotor %s %d, idle %d, delta %d",
1283 m_runningInputpower,
1286 if ( (cmd.direction && abs(m_runningInputpower - idleInputpower) >= cmd.deltaA)
1287 || (!cmd.direction && abs(m_runningInputpower - idleInputpower) <= cmd.deltaA) )
1290 eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
1291 if ( cmd.okcount > 6 )
1293 m_sec->setRotorMoving(cmd.direction);
1294 eDebug("[SEC] rotor is %s", txt);
1295 if (setSecSequencePos(cmd.steps))
1301 eDebug("[SEC] rotor not %s... reset counter.. increase timeout", txt);
1303 if (!m_timeoutCount && m_retryCount > 0)
1307 ++m_sec_sequence.current();
1310 case eSecCommand::IF_ROTORPOS_VALID_GOTO:
1311 if (m_data[ROTOR_CMD] != -1 && m_data[ROTOR_POS] != -1)
1312 setSecSequencePos(m_sec_sequence.current()->steps);
1314 ++m_sec_sequence.current();
1316 case eSecCommand::INVALIDATE_CURRENT_ROTORPARMS:
1317 m_data[ROTOR_CMD] = m_data[ROTOR_POS] = -1;
1318 eDebug("[SEC] invalidate current rotorparams");
1319 ++m_sec_sequence.current();
1321 case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
1322 m_data[ROTOR_CMD] = m_data[NEW_ROTOR_CMD];
1323 m_data[ROTOR_POS] = m_data[NEW_ROTOR_POS];
1324 eDebug("[SEC] update current rotorparams %d %04x %d", m_timeoutCount, m_data[5], m_data[6]);
1325 ++m_sec_sequence.current();
1327 case eSecCommand::SET_ROTOR_DISEQC_RETRYS:
1328 m_retryCount = m_sec_sequence.current()++->val;
1329 eDebug("[SEC] set rotor retries %d", m_retryCount);
1331 case eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO:
1334 eDebug("[SEC] no more rotor retrys");
1335 setSecSequencePos(m_sec_sequence.current()->steps);
1338 ++m_sec_sequence.current();
1340 case eSecCommand::SET_POWER_LIMITING_MODE:
1343 ::open("/dev/i2c/1", O_RDWR) :
1344 ::open("/dev/i2c/0", O_RDWR);
1346 unsigned char data[2];
1347 ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
1348 if(::read(fd, data, 1) != 1)
1349 eDebug("[SEC] error read lnbp (%m)");
1350 if ( m_sec_sequence.current()->mode == eSecCommand::modeStatic )
1352 data[0] |= 0x80; // enable static current limiting
1353 eDebug("[SEC] set static current limiting");
1357 data[0] &= ~0x80; // enable dynamic current limiting
1358 eDebug("[SEC] set dynamic current limiting");
1360 if(::write(fd, data, 1) != 1)
1361 eDebug("[SEC] error write lnbp (%m)");
1363 ++m_sec_sequence.current();
1367 eDebug("[SEC] unhandled sec command %d",
1368 ++m_sec_sequence.current()->cmd);
1369 ++m_sec_sequence.current();
1371 m_tuneTimer->start(delay,true);
1375 void eDVBFrontend::setFrontend()
1377 eDebug("setting frontend %d", m_fe);
1380 if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
1382 perror("FE_SET_FRONTEND failed");
1387 RESULT eDVBFrontend::getFrontendType(int &t)
1395 RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm)
1400 eWarning("no SEC module active!");
1403 res = m_sec->prepare(*this, parm, feparm, 1 << m_fe);
1406 eDebug("prepare_sat System %d Freq %d Pol %d SR %d INV %d FEC %d orbpos %d",
1409 feparm.polarisation,
1413 feparm.orbital_position);
1414 parm_u_qpsk_symbol_rate = feparm.symbol_rate;
1415 switch (feparm.inversion)
1417 case eDVBFrontendParametersSatellite::Inversion::On:
1418 parm_inversion = INVERSION_ON;
1420 case eDVBFrontendParametersSatellite::Inversion::Off:
1421 parm_inversion = INVERSION_OFF;
1424 case eDVBFrontendParametersSatellite::Inversion::Unknown:
1425 parm_inversion = INVERSION_AUTO;
1428 if (feparm.system == eDVBFrontendParametersSatellite::System::DVB_S)
1431 case eDVBFrontendParametersSatellite::FEC::fNone:
1432 parm_u_qpsk_fec_inner = FEC_NONE;
1434 case eDVBFrontendParametersSatellite::FEC::f1_2:
1435 parm_u_qpsk_fec_inner = FEC_1_2;
1437 case eDVBFrontendParametersSatellite::FEC::f2_3:
1438 parm_u_qpsk_fec_inner = FEC_2_3;
1440 case eDVBFrontendParametersSatellite::FEC::f3_4:
1441 parm_u_qpsk_fec_inner = FEC_3_4;
1443 case eDVBFrontendParametersSatellite::FEC::f5_6:
1444 parm_u_qpsk_fec_inner = FEC_5_6;
1446 case eDVBFrontendParametersSatellite::FEC::f7_8:
1447 parm_u_qpsk_fec_inner = FEC_7_8;
1450 eDebug("no valid fec for DVB-S set.. assume auto");
1451 case eDVBFrontendParametersSatellite::FEC::fAuto:
1452 parm_u_qpsk_fec_inner = FEC_AUTO;
1455 #if HAVE_DVB_API_VERSION >= 3
1460 case eDVBFrontendParametersSatellite::FEC::f1_2:
1461 parm_u_qpsk_fec_inner = FEC_S2_QPSK_1_2;
1463 case eDVBFrontendParametersSatellite::FEC::f2_3:
1464 parm_u_qpsk_fec_inner = FEC_S2_QPSK_2_3;
1466 case eDVBFrontendParametersSatellite::FEC::f3_4:
1467 parm_u_qpsk_fec_inner = FEC_S2_QPSK_3_4;
1469 case eDVBFrontendParametersSatellite::FEC::f3_5:
1470 parm_u_qpsk_fec_inner = FEC_S2_QPSK_3_5;
1472 case eDVBFrontendParametersSatellite::FEC::f4_5:
1473 parm_u_qpsk_fec_inner = FEC_S2_QPSK_4_5;
1475 case eDVBFrontendParametersSatellite::FEC::f5_6:
1476 parm_u_qpsk_fec_inner = FEC_S2_QPSK_5_6;
1478 case eDVBFrontendParametersSatellite::FEC::f7_8:
1479 parm_u_qpsk_fec_inner = FEC_S2_QPSK_7_8;
1481 case eDVBFrontendParametersSatellite::FEC::f8_9:
1482 parm_u_qpsk_fec_inner = FEC_S2_QPSK_8_9;
1484 case eDVBFrontendParametersSatellite::FEC::f9_10:
1485 parm_u_qpsk_fec_inner = FEC_S2_QPSK_9_10;
1488 eDebug("no valid fec for DVB-S2 set.. abort !!");
1491 if (feparm.modulation == eDVBFrontendParametersSatellite::Modulation::M8PSK)
1492 parm_u_qpsk_fec_inner = (fe_code_rate_t)((int)parm_u_qpsk_fec_inner+9);
1493 // 8PSK fec driver values are decimal 9 bigger
1496 // FIXME !!! get frequency range from tuner
1497 if ( parm_frequency < 900000 || parm_frequency > 2200000 )
1499 eDebug("%d mhz out of tuner range.. dont tune", parm_frequency/1000);
1502 eDebug("tuning to %d mhz", parm_frequency/1000);
1507 RESULT eDVBFrontend::prepare_cable(const eDVBFrontendParametersCable &feparm)
1509 parm_frequency = feparm.frequency * 1000;
1510 parm_u_qam_symbol_rate = feparm.symbol_rate;
1511 switch (feparm.modulation)
1513 case eDVBFrontendParametersCable::Modulation::QAM16:
1514 parm_u_qam_modulation = QAM_16;
1516 case eDVBFrontendParametersCable::Modulation::QAM32:
1517 parm_u_qam_modulation = QAM_32;
1519 case eDVBFrontendParametersCable::Modulation::QAM64:
1520 parm_u_qam_modulation = QAM_64;
1522 case eDVBFrontendParametersCable::Modulation::QAM128:
1523 parm_u_qam_modulation = QAM_128;
1525 case eDVBFrontendParametersCable::Modulation::QAM256:
1526 parm_u_qam_modulation = QAM_256;
1529 case eDVBFrontendParametersCable::Modulation::Auto:
1530 parm_u_qam_modulation = QAM_AUTO;
1533 switch (feparm.inversion)
1535 case eDVBFrontendParametersCable::Inversion::On:
1536 parm_inversion = INVERSION_ON;
1538 case eDVBFrontendParametersCable::Inversion::Off:
1539 parm_inversion = INVERSION_OFF;
1542 case eDVBFrontendParametersCable::Inversion::Unknown:
1543 parm_inversion = INVERSION_AUTO;
1546 switch (feparm.fec_inner)
1548 case eDVBFrontendParametersCable::FEC::fNone:
1549 parm_u_qam_fec_inner = FEC_NONE;
1551 case eDVBFrontendParametersCable::FEC::f1_2:
1552 parm_u_qam_fec_inner = FEC_1_2;
1554 case eDVBFrontendParametersCable::FEC::f2_3:
1555 parm_u_qam_fec_inner = FEC_2_3;
1557 case eDVBFrontendParametersCable::FEC::f3_4:
1558 parm_u_qam_fec_inner = FEC_3_4;
1560 case eDVBFrontendParametersCable::FEC::f5_6:
1561 parm_u_qam_fec_inner = FEC_5_6;
1563 case eDVBFrontendParametersCable::FEC::f7_8:
1564 parm_u_qam_fec_inner = FEC_7_8;
1566 #if HAVE_DVB_API_VERSION >= 3
1567 case eDVBFrontendParametersCable::FEC::f8_9:
1568 parm_u_qam_fec_inner = FEC_8_9;
1572 case eDVBFrontendParametersCable::FEC::fAuto:
1573 parm_u_qam_fec_inner = FEC_AUTO;
1576 eDebug("tuning to %d khz, sr %d, fec %d, modulation %d, inversion %d",
1577 parm_frequency/1000,
1578 parm_u_qam_symbol_rate,
1579 parm_u_qam_fec_inner,
1580 parm_u_qam_modulation,
1585 RESULT eDVBFrontend::prepare_terrestrial(const eDVBFrontendParametersTerrestrial &feparm)
1587 parm_frequency = feparm.frequency;
1589 switch (feparm.bandwidth)
1591 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz:
1592 parm_u_ofdm_bandwidth = BANDWIDTH_8_MHZ;
1594 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw7MHz:
1595 parm_u_ofdm_bandwidth = BANDWIDTH_7_MHZ;
1597 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw6MHz:
1598 parm_u_ofdm_bandwidth = BANDWIDTH_6_MHZ;
1601 case eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto:
1602 parm_u_ofdm_bandwidth = BANDWIDTH_AUTO;
1605 switch (feparm.code_rate_LP)
1607 case eDVBFrontendParametersTerrestrial::FEC::f1_2:
1608 parm_u_ofdm_code_rate_LP = FEC_1_2;
1610 case eDVBFrontendParametersTerrestrial::FEC::f2_3:
1611 parm_u_ofdm_code_rate_LP = FEC_2_3;
1613 case eDVBFrontendParametersTerrestrial::FEC::f3_4:
1614 parm_u_ofdm_code_rate_LP = FEC_3_4;
1616 case eDVBFrontendParametersTerrestrial::FEC::f5_6:
1617 parm_u_ofdm_code_rate_LP = FEC_5_6;
1619 case eDVBFrontendParametersTerrestrial::FEC::f7_8:
1620 parm_u_ofdm_code_rate_LP = FEC_7_8;
1623 case eDVBFrontendParametersTerrestrial::FEC::fAuto:
1624 parm_u_ofdm_code_rate_LP = FEC_AUTO;
1627 switch (feparm.code_rate_HP)
1629 case eDVBFrontendParametersTerrestrial::FEC::f1_2:
1630 parm_u_ofdm_code_rate_HP = FEC_1_2;
1632 case eDVBFrontendParametersTerrestrial::FEC::f2_3:
1633 parm_u_ofdm_code_rate_HP = FEC_2_3;
1635 case eDVBFrontendParametersTerrestrial::FEC::f3_4:
1636 parm_u_ofdm_code_rate_HP = FEC_3_4;
1638 case eDVBFrontendParametersTerrestrial::FEC::f5_6:
1639 parm_u_ofdm_code_rate_HP = FEC_5_6;
1641 case eDVBFrontendParametersTerrestrial::FEC::f7_8:
1642 parm_u_ofdm_code_rate_HP = FEC_7_8;
1645 case eDVBFrontendParametersTerrestrial::FEC::fAuto:
1646 parm_u_ofdm_code_rate_HP = FEC_AUTO;
1649 switch (feparm.modulation)
1651 case eDVBFrontendParametersTerrestrial::Modulation::QPSK:
1652 parm_u_ofdm_constellation = QPSK;
1654 case eDVBFrontendParametersTerrestrial::Modulation::QAM16:
1655 parm_u_ofdm_constellation = QAM_16;
1657 case eDVBFrontendParametersTerrestrial::Modulation::QAM64:
1658 parm_u_ofdm_constellation = QAM_64;
1661 case eDVBFrontendParametersTerrestrial::Modulation::Auto:
1662 parm_u_ofdm_constellation = QAM_AUTO;
1665 switch (feparm.transmission_mode)
1667 case eDVBFrontendParametersTerrestrial::TransmissionMode::TM2k:
1668 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_2K;
1670 case eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k:
1671 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_8K;
1674 case eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto:
1675 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_AUTO;
1678 switch (feparm.guard_interval)
1680 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_32:
1681 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_32;
1683 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_16:
1684 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_16;
1686 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_8:
1687 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_8;
1689 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_4:
1690 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_4;
1693 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_Auto:
1694 parm_u_ofdm_guard_interval = GUARD_INTERVAL_AUTO;
1697 switch (feparm.hierarchy)
1699 case eDVBFrontendParametersTerrestrial::Hierarchy::HNone:
1700 parm_u_ofdm_hierarchy_information = HIERARCHY_NONE;
1702 case eDVBFrontendParametersTerrestrial::Hierarchy::H1:
1703 parm_u_ofdm_hierarchy_information = HIERARCHY_1;
1705 case eDVBFrontendParametersTerrestrial::Hierarchy::H2:
1706 parm_u_ofdm_hierarchy_information = HIERARCHY_2;
1708 case eDVBFrontendParametersTerrestrial::Hierarchy::H4:
1709 parm_u_ofdm_hierarchy_information = HIERARCHY_4;
1712 case eDVBFrontendParametersTerrestrial::Hierarchy::HAuto:
1713 parm_u_ofdm_hierarchy_information = HIERARCHY_AUTO;
1716 switch (feparm.inversion)
1718 case eDVBFrontendParametersTerrestrial::Inversion::On:
1719 parm_inversion = INVERSION_ON;
1721 case eDVBFrontendParametersTerrestrial::Inversion::Off:
1722 parm_inversion = INVERSION_OFF;
1725 case eDVBFrontendParametersTerrestrial::Inversion::Unknown:
1726 parm_inversion = INVERSION_AUTO;
1732 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
1734 eDebug("(%d)tune", m_fe);
1742 eDebug("no frontend device opened... do not try to tune !!!");
1754 m_sec_sequence.clear();
1760 eDVBFrontendParametersSatellite feparm;
1761 if (where.getDVBS(feparm))
1763 eDebug("no dvbs data!");
1767 m_sec->setRotorMoving(false);
1768 res=prepare_sat(feparm);
1776 eDVBFrontendParametersCable feparm;
1777 if (where.getDVBC(feparm))
1782 res=prepare_cable(feparm);
1786 m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
1787 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
1792 eDVBFrontendParametersTerrestrial feparm;
1793 if (where.getDVBT(feparm))
1795 eDebug("no -T data");
1799 res=prepare_terrestrial(feparm);
1803 std::string enable_5V;
1804 char configStr[255];
1805 snprintf(configStr, 255, "config.Nims.%d.terrestrial_5V", m_fe);
1806 m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
1807 ePythonConfigQuery::getConfigValue(configStr, enable_5V);
1808 if (enable_5V == "True")
1809 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage13) );
1811 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltageOff) );
1812 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
1818 m_tuneTimer->start(0,true);
1819 m_sec_sequence.current() = m_sec_sequence.begin();
1821 if (m_state != stateTuning)
1824 m_state = stateTuning;
1825 m_stateChanged(this);
1831 m_tuneTimer->stop();
1835 RESULT eDVBFrontend::connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)
1837 connection = new eConnection(this, m_stateChanged.connect(stateChange));
1841 RESULT eDVBFrontend::setVoltage(int voltage)
1843 if (m_type == feCable)
1845 #if HAVE_DVB_API_VERSION < 3
1848 bool increased=false;
1849 fe_sec_voltage_t vlt;
1851 m_data[CUR_VOLTAGE]=voltage;
1855 for (int i=0; i < 3; ++i) // reset diseqc
1857 vlt = SEC_VOLTAGE_OFF;
1860 #if HAVE_DVB_API_VERSION < 3
1861 vlt = SEC_VOLTAGE_13_5;
1867 vlt = SEC_VOLTAGE_13;
1870 #if HAVE_DVB_API_VERSION < 3
1871 vlt = SEC_VOLTAGE_18_5;
1877 vlt = SEC_VOLTAGE_18;
1882 #if HAVE_DVB_API_VERSION < 3
1883 return ::ioctl(m_secfd, SEC_SET_VOLTAGE, vlt);
1885 if (m_type == feSatellite && ::ioctl(m_fd, FE_ENABLE_HIGH_LNB_VOLTAGE, increased) < 0)
1886 perror("FE_ENABLE_HIGH_LNB_VOLTAGE");
1887 return ::ioctl(m_fd, FE_SET_VOLTAGE, vlt);
1891 RESULT eDVBFrontend::getState(int &state)
1897 RESULT eDVBFrontend::setTone(int t)
1899 if (m_type != feSatellite)
1901 #if HAVE_DVB_API_VERSION < 3
1904 fe_sec_tone_mode_t tone;
1913 tone = SEC_TONE_OFF;
1918 #if HAVE_DVB_API_VERSION < 3
1919 return ::ioctl(m_secfd, SEC_SET_TONE, tone);
1921 return ::ioctl(m_fd, FE_SET_TONE, tone);
1925 #if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_MASTER_CMD)
1926 #define SEC_DISEQC_SEND_MASTER_CMD _IOW('o', 97, struct secCommand *)
1929 RESULT eDVBFrontend::sendDiseqc(const eDVBDiseqcCommand &diseqc)
1931 #if HAVE_DVB_API_VERSION < 3
1932 struct secCommand cmd;
1933 cmd.type = SEC_CMDTYPE_DISEQC_RAW;
1934 cmd.u.diseqc.cmdtype = diseqc.data[0];
1935 cmd.u.diseqc.addr = diseqc.data[1];
1936 cmd.u.diseqc.cmd = diseqc.data[2];
1937 cmd.u.diseqc.numParams = diseqc.len-3;
1938 memcpy(cmd.u.diseqc.params, diseqc.data+3, diseqc.len-3);
1939 if (::ioctl(m_secfd, SEC_DISEQC_SEND_MASTER_CMD, &cmd))
1941 struct dvb_diseqc_master_cmd cmd;
1942 memcpy(cmd.msg, diseqc.data, diseqc.len);
1943 cmd.msg_len = diseqc.len;
1944 if (::ioctl(m_fd, FE_DISEQC_SEND_MASTER_CMD, &cmd))
1950 #if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_BURST)
1951 #define SEC_DISEQC_SEND_BURST _IO('o', 96)
1953 RESULT eDVBFrontend::sendToneburst(int burst)
1955 #if HAVE_DVB_API_VERSION < 3
1956 secMiniCmd cmd = SEC_MINI_NONE;
1958 fe_sec_mini_cmd_t cmd = SEC_MINI_A;
1960 if ( burst == eDVBSatelliteDiseqcParameters::A )
1962 else if ( burst == eDVBSatelliteDiseqcParameters::B )
1964 #if HAVE_DVB_API_VERSION < 3
1965 if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd))
1968 if (::ioctl(m_fd, FE_DISEQC_SEND_BURST, cmd))
1974 RESULT eDVBFrontend::setSEC(iDVBSatelliteEquipmentControl *sec)
1980 RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list)
1982 m_sec_sequence = list;
1986 RESULT eDVBFrontend::getData(int num, int &data)
1988 if ( num < NUM_DATA_ENTRIES )
1996 RESULT eDVBFrontend::setData(int num, int val)
1998 if ( num < NUM_DATA_ENTRIES )
2006 int eDVBFrontend::isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)
2009 if (feparm->getSystem(type) || type != m_type)
2012 if (m_type == eDVBFrontend::feSatellite)
2015 eDVBFrontendParametersSatellite sat_parm;
2016 int ret = feparm->getDVBS(sat_parm);
2018 return m_sec->canTune(sat_parm, this, 1 << m_fe);
2020 else if (m_type == eDVBFrontend::feCable)
2021 return 2; // more prio for cable frontends