1 #include <lib/dvb/dvb.h>
2 #include <lib/base/eerror.h>
8 #ifndef I2C_SLAVE_FORCE
9 #define I2C_SLAVE_FORCE 0x0706
12 #if HAVE_DVB_API_VERSION < 3
13 #include <ost/frontend.h>
15 #define QAM_AUTO (Modulation)6
16 #define TRANSMISSION_MODE_AUTO (TransmitMode)2
17 #define BANDWIDTH_AUTO (BandWidth)3
18 #define GUARD_INTERVAL_AUTO (GuardInterval)4
19 #define HIERARCHY_AUTO (Hierarchy)4
20 #define parm.frequency parm.Frequency
21 #define parm.u.qam.symbol_rate parm.u.qam.SymbolRate
22 #define parm.u.qam.fec_inner parm.u.qam.FEC_inner
23 #define parm.u.qam.modulation parm.u.qam.QAM
24 #define parm.u.ofdm.bandwidth parm.u.ofdm.bandWidth
25 #define parm.u.ofdm.code_rate_LP parm.u.ofdm.LP_CodeRate
26 #define parm.u.ofdm.code_rate_HP parm.u.ofdm.HP_CodeRate
27 #define parm.u.ofdm.constellation parm.u.ofdm.Constellation
28 #define parm.u.ofdm.transmission_mode parm.u.ofdm.TransmissionMode
29 #define parm.u.ofdm.guard_interval parm.u.ofdm.guardInterval
30 #define parm.u.ofdm.hierarchy_information parm.u.ofdm.HierarchyInformation
31 #define parm.inversion parm.Inversion
33 #include <linux/dvb/frontend.h>
36 #include <dvbsi++/satellite_delivery_system_descriptor.h>
37 #include <dvbsi++/cable_delivery_system_descriptor.h>
38 #include <dvbsi++/terrestrial_delivery_system_descriptor.h>
40 void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescriptor &descriptor)
42 frequency = descriptor.getFrequency() * 10;
43 symbol_rate = descriptor.getSymbolRate() * 100;
44 polarisation = descriptor.getPolarization();
45 fec = descriptor.getFecInner();
48 inversion = Inversion::Unknown;
49 orbital_position = ((descriptor.getOrbitalPosition() >> 12) & 0xF) * 1000;
50 orbital_position += ((descriptor.getOrbitalPosition() >> 8) & 0xF) * 100;
51 orbital_position += ((descriptor.getOrbitalPosition() >> 4) & 0xF) * 10;
52 orbital_position += ((descriptor.getOrbitalPosition()) & 0xF);
53 if (orbital_position && (!descriptor.getWestEastFlag()))
54 orbital_position = 3600 - orbital_position;
57 void eDVBFrontendParametersCable::set(const CableDeliverySystemDescriptor &descriptor)
59 frequency = descriptor.getFrequency() * 10;
60 symbol_rate = descriptor.getSymbolRate() * 100;
61 fec_inner = descriptor.getFecInner();
62 if ( fec_inner == 0xF )
63 fec_inner = FEC::fNone;
64 modulation = descriptor.getModulation();
65 if ( modulation > 0x5 )
66 modulation = Modulation::Auto;
67 inversion = Inversion::Unknown;
70 void eDVBFrontendParametersTerrestrial::set(const TerrestrialDeliverySystemDescriptor &descriptor)
72 frequency = descriptor.getCentreFrequency() * 10;
73 bandwidth = descriptor.getBandwidth();
74 if ( bandwidth > 2 ) // 5Mhz forced to auto
75 bandwidth = Bandwidth::BwAuto;
76 code_rate_HP = descriptor.getCodeRateHpStream();
78 code_rate_HP = FEC::fAuto;
79 code_rate_LP = descriptor.getCodeRateLpStream();
81 code_rate_LP = FEC::fAuto;
82 transmission_mode = descriptor.getTransmissionMode();
83 if (transmission_mode > 2)
84 transmission_mode = TransmissionMode::TMAuto;
85 guard_interval = descriptor.getGuardInterval();
86 if (guard_interval > 3)
87 guard_interval = GuardInterval::GI_Auto;
88 hierarchy = descriptor.getHierarchyInformation()&3;
89 modulation = descriptor.getConstellation();
91 modulation = Modulation::Auto;
92 inversion = Inversion::Unknown;
95 eDVBFrontendParameters::eDVBFrontendParameters(): m_type(-1)
99 DEFINE_REF(eDVBFrontendParameters);
101 RESULT eDVBFrontendParameters::getSystem(int &t) const
109 RESULT eDVBFrontendParameters::getDVBS(eDVBFrontendParametersSatellite &p) const
111 if (m_type != iDVBFrontend::feSatellite)
117 RESULT eDVBFrontendParameters::getDVBC(eDVBFrontendParametersCable &p) const
119 if (m_type != iDVBFrontend::feCable)
125 RESULT eDVBFrontendParameters::getDVBT(eDVBFrontendParametersTerrestrial &p) const
127 if (m_type != iDVBFrontend::feTerrestrial)
133 RESULT eDVBFrontendParameters::setDVBS(const eDVBFrontendParametersSatellite &p)
136 m_type = iDVBFrontend::feSatellite;
140 RESULT eDVBFrontendParameters::setDVBC(const eDVBFrontendParametersCable &p)
143 m_type = iDVBFrontend::feCable;
147 RESULT eDVBFrontendParameters::setDVBT(const eDVBFrontendParametersTerrestrial &p)
150 m_type = iDVBFrontend::feTerrestrial;
154 RESULT eDVBFrontendParameters::calculateDifference(const iDVBFrontendParameters *parm, int &diff) const
159 if (parm->getSystem(type))
163 diff = 1<<30; // big difference
169 case iDVBFrontend::feSatellite:
171 eDVBFrontendParametersSatellite osat;
172 if (parm->getDVBS(osat))
175 if (sat.orbital_position != osat.orbital_position)
177 else if (sat.polarisation != osat.polarisation)
181 diff = abs(sat.frequency - osat.frequency);
182 diff += abs(sat.symbol_rate - osat.symbol_rate);
186 case iDVBFrontend::feCable:
187 case iDVBFrontend::feTerrestrial:
194 RESULT eDVBFrontendParameters::getHash(unsigned long &hash) const
198 case iDVBFrontend::feSatellite:
200 hash = (sat.orbital_position << 16);
201 hash |= ((sat.frequency/1000)&0xFFFF)|((sat.polarisation&1) << 15);
204 case iDVBFrontend::feCable:
205 case iDVBFrontend::feTerrestrial:
211 DEFINE_REF(eDVBFrontend);
213 eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok)
214 :m_type(-1), m_fe(fe), m_fd(-1), m_timeout(0), m_tuneTimer(0)
215 #if HAVE_DVB_API_VERSION < 3
219 #if HAVE_DVB_API_VERSION < 3
220 sprintf(m_filename, "/dev/dvb/card%d/frontend%d", adap, fe);
221 sprintf(m_sec_filename, "/dev/dvb/card%d/sec%d", adap, fe);
223 sprintf(m_filename, "/dev/dvb/adapter%d/frontend%d", adap, fe);
225 m_timeout = new eTimer(eApp);
226 CONNECT(m_timeout->timeout, eDVBFrontend::timeout);
228 m_tuneTimer = new eTimer(eApp);
229 CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop);
231 int entries = sizeof(m_data) / sizeof(int);
232 for (int i=0; i<entries; ++i)
235 m_idleInputpower[0]=m_idleInputpower[1]=0;
237 ok = !openFrontend();
241 int eDVBFrontend::openFrontend()
244 return -1; // already opened
249 #if HAVE_DVB_API_VERSION < 3
250 m_secfd = ::open(m_sec_filename, O_RDWR);
253 eWarning("failed! (%s) %m", m_sec_filename);
256 FrontendInfo fe_info;
258 dvb_frontend_info fe_info;
260 eDebug("opening frontend %d", m_fe);
261 m_fd = ::open(m_filename, O_RDWR|O_NONBLOCK);
264 eWarning("failed! (%s) %m", m_filename);
265 #if HAVE_DVB_API_VERSION < 3
274 if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
276 eWarning("ioctl FE_GET_INFO failed");
279 #if HAVE_DVB_API_VERSION < 3
286 switch (fe_info.type)
289 m_type = iDVBFrontend::feSatellite;
292 m_type = iDVBFrontend::feCable;
295 m_type = iDVBFrontend::feTerrestrial;
298 eWarning("unknown frontend type.");
301 #if HAVE_DVB_API_VERSION < 3
307 eDebug("detected %s frontend", "satellite\0cable\0 terrestrial"+fe_info.type*10);
310 setTone(iDVBFrontend::toneOff);
311 setVoltage(iDVBFrontend::voltageOff);
313 m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read);
314 CONNECT(m_sn->activated, eDVBFrontend::feEvent);
320 int eDVBFrontend::closeFrontend()
322 if (!m_fe && m_data[7] != -1)
324 // try to close the first frontend.. but the second is linked to the first
325 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)m_data[7];
326 if (linked_fe->m_inuse)
328 eDebug("dont close frontend %d until the linked frontend %d is still in use",
329 m_fe, linked_fe->m_frontend->getID());
335 eDebug("close frontend %d", m_fe);
336 setTone(iDVBFrontend::toneOff);
337 setVoltage(iDVBFrontend::voltageOff);
340 m_data[0] = m_data[1] = m_data[2] = -1;
342 #if HAVE_DVB_API_VERSION < 3
355 eDVBFrontend::~eDVBFrontend()
362 void eDVBFrontend::feEvent(int w)
366 #if HAVE_DVB_API_VERSION < 3
369 dvb_frontend_event event;
373 res = ::ioctl(m_fd, FE_GET_EVENT, &event);
375 if (res && (errno == EAGAIN))
380 eWarning("FE_GET_EVENT failed! %m");
387 #if HAVE_DVB_API_VERSION < 3
388 if (event.type == FE_COMPLETION_EV)
390 eDebug("(%d)fe event: status %x, inversion %s", m_fe, event.status, (event.parameters.inversion == INVERSION_ON) ? "on" : "off");
391 if (event.status & FE_HAS_LOCK)
401 state = stateLostLock;
402 m_data[0] = m_data[1] = m_data[2] = -1; // reset diseqc
405 if (m_state != state)
408 m_stateChanged(this);
413 void eDVBFrontend::timeout()
416 if (m_state == stateTuning)
418 m_state = stateFailed;
419 m_stateChanged(this);
423 int eDVBFrontend::readFrontendData(int type)
430 if (ioctl(m_fd, FE_READ_BER, &ber) < 0 && errno != ERANGE)
431 eDebug("FE_READ_BER failed (%m)");
437 if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
438 eDebug("FE_READ_SNR failed (%m)");
444 if (ioctl(m_fd, FE_READ_SIGNAL_STRENGTH, &strength) < 0 && errno != ERANGE)
445 eDebug("FE_READ_SIGNAL_STRENGTH failed (%m)");
452 #ifndef FP_IOCTL_GET_ID
453 #define FP_IOCTL_GET_ID 0
455 int eDVBFrontend::readInputpower()
457 int power=m_fe; // this is needed for read inputpower from the correct tuner !
459 // open front prozessor
460 int fp=::open("/dev/dbox/fp0", O_RDWR);
463 eDebug("couldn't open fp");
466 static bool old_fp = (::ioctl(fp, FP_IOCTL_GET_ID) < 0);
467 if ( ioctl( fp, old_fp ? 9 : 0x100, &power ) < 0 )
469 eDebug("FP_IOCTL_GET_LNB_CURRENT failed (%m)");
477 bool eDVBFrontend::setSecSequencePos(int steps)
479 eDebug("set sequence pos %d", steps);
484 if (m_sec_sequence.current() != m_sec_sequence.end())
485 ++m_sec_sequence.current();
490 if (m_sec_sequence.current() != m_sec_sequence.begin() && m_sec_sequence.current() != m_sec_sequence.end())
491 --m_sec_sequence.current();
497 void eDVBFrontend::tuneLoop() // called by m_tuneTimer
500 if ( m_sec_sequence && m_sec_sequence.current() != m_sec_sequence.end() )
502 switch (m_sec_sequence.current()->cmd)
504 case eSecCommand::SLEEP:
505 delay = m_sec_sequence.current()++->msec;
506 eDebug("[SEC] sleep %dms", delay);
508 case eSecCommand::GOTO:
509 if ( !setSecSequencePos(m_sec_sequence.current()->steps) )
510 ++m_sec_sequence.current();
512 case eSecCommand::SET_VOLTAGE:
514 int voltage = m_sec_sequence.current()++->voltage;
515 eDebug("[SEC] setVoltage %d", voltage);
519 case eSecCommand::IF_VOLTAGE_GOTO:
521 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
522 if ( compare.voltage == m_curVoltage && setSecSequencePos(compare.steps) )
524 ++m_sec_sequence.current();
527 case eSecCommand::IF_NOT_VOLTAGE_GOTO:
529 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
530 if ( compare.voltage != m_curVoltage && setSecSequencePos(compare.steps) )
532 ++m_sec_sequence.current();
535 case eSecCommand::SET_TONE:
536 eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
537 setTone(m_sec_sequence.current()++->tone);
539 case eSecCommand::SEND_DISEQC:
540 sendDiseqc(m_sec_sequence.current()->diseqc);
541 eDebugNoNewLine("[SEC] sendDiseqc: ");
542 for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
543 eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
545 ++m_sec_sequence.current();
547 case eSecCommand::SEND_TONEBURST:
548 eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst);
549 sendToneburst(m_sec_sequence.current()++->toneburst);
551 case eSecCommand::SET_FRONTEND:
552 eDebug("[SEC] setFrontend");
554 ++m_sec_sequence.current();
556 case eSecCommand::SET_TIMEOUT:
557 m_timeoutCount = m_sec_sequence.current()++->val;
558 eDebug("[SEC] set timeout %d", m_timeoutCount);
560 case eSecCommand::IF_TIMEOUT_GOTO:
563 eDebug("[SEC] rotor timout");
564 m_sec->setRotorMoving(false);
565 setSecSequencePos(m_sec_sequence.current()->steps);
568 ++m_sec_sequence.current();
570 case eSecCommand::MEASURE_IDLE_INPUTPOWER:
572 int idx = m_sec_sequence.current()++->val;
573 if ( idx == 0 || idx == 1 )
575 m_idleInputpower[idx] = readInputpower();
576 eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
579 eDebug("[SEC] idleInputpower measure index(%d) out of bound !!!", idx);
582 case eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO:
584 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
585 int idx = compare.voltage;
586 if ( idx == 0 || idx == 1 )
588 int idle = readInputpower();
589 int diff = abs(idle-m_idleInputpower[idx]);
592 eDebug("measure idle(%d) was not okay.. (%d - %d = %d) retry", idx, m_idleInputpower[idx], idle, diff);
593 setSecSequencePos(compare.steps);
597 ++m_sec_sequence.current();
600 case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
601 m_runningInputpower = readInputpower();
602 eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
603 ++m_sec_sequence.current();
605 case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
607 int idleInputpower = m_idleInputpower[ (m_curVoltage&1) ? 0 : 1];
608 eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
609 const char *txt = cmd.direction ? "running" : "stopped";
610 eDebug("[SEC] waiting for rotor %s %d, idle %d, delta %d",
615 if ( (cmd.direction && abs(m_runningInputpower - idleInputpower) >= cmd.deltaA)
616 || (!cmd.direction && abs(m_runningInputpower - idleInputpower) <= cmd.deltaA) )
619 eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
620 if ( cmd.okcount > 6 )
622 m_sec->setRotorMoving(cmd.direction);
623 eDebug("[SEC] rotor is %s", txt);
624 if (setSecSequencePos(cmd.steps))
630 eDebug("[SEC] rotor not %s... reset counter.. increase timeout", txt);
632 if (!m_timeoutCount && m_retryCount > 0)
636 ++m_sec_sequence.current();
639 case eSecCommand::IF_ROTORPOS_VALID_GOTO:
640 if (m_data[5] != -1 && m_data[6] != -1)
641 setSecSequencePos(m_sec_sequence.current()->steps);
643 ++m_sec_sequence.current();
645 case eSecCommand::INVALIDATE_CURRENT_ROTORPARMS:
646 m_data[5] = m_data[6] = -1;
647 eDebug("[SEC] invalidate current rotorparams");
648 ++m_sec_sequence.current();
650 case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
651 m_data[5] = m_data[3];
652 m_data[6] = m_data[4];
653 eDebug("[SEC] update current rotorparams %d %04x %d", m_timeoutCount, m_data[5], m_data[6]);
654 ++m_sec_sequence.current();
656 case eSecCommand::SET_ROTOR_DISEQC_RETRYS:
657 m_retryCount = m_sec_sequence.current()++->val;
658 eDebug("[SEC] set rotor retries %d", m_retryCount);
660 case eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO:
663 eDebug("[SEC] no more rotor retrys");
664 setSecSequencePos(m_sec_sequence.current()->steps);
667 ++m_sec_sequence.current();
669 case eSecCommand::SET_POWER_LIMITING_MODE:
672 ::open("/dev/i2c/1", O_RDWR) :
673 ::open("/dev/i2c/0", O_RDWR);
675 unsigned char data[2];
676 ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
677 if(::read(fd, data, 1) != 1)
678 eDebug("[SEC] error read lnbp (%m)");
679 if ( m_sec_sequence.current()->mode == eSecCommand::modeStatic )
681 data[0] |= 0x80; // enable static current limiting
682 eDebug("[SEC] set static current limiting");
686 data[0] &= ~0x80; // enable dynamic current limiting
687 eDebug("[SEC] set dynamic current limiting");
689 if(::write(fd, data, 1) != 1)
690 eDebug("[SEC] error write lnbp (%m)");
692 ++m_sec_sequence.current();
696 ++m_sec_sequence.current();
697 eDebug("[SEC] unhandled sec command");
699 m_tuneTimer->start(delay,true);
703 void eDVBFrontend::setFrontend()
705 eDebug("setting frontend %d", m_fe);
706 if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
708 perror("FE_SET_FRONTEND failed");
711 m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent
714 RESULT eDVBFrontend::getFrontendType(int &t)
722 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
724 eDebug("(%d)tune", m_fe);
731 m_sec_sequence.clear();
738 eDVBFrontendParametersSatellite feparm;
739 if (where.getDVBS(feparm))
741 eDebug("no dvbs data!");
746 eWarning("no SEC module active!");
750 res = m_sec->prepare(*this, parm, feparm, 1 << m_fe);
753 eDebug("tuning to %d mhz", parm.frequency/1000);
758 eDVBFrontendParametersCable feparm;
759 if (where.getDVBC(feparm))
761 parm.frequency = feparm.frequency * 1000;
762 parm.u.qam.symbol_rate = feparm.symbol_rate;
763 switch (feparm.modulation)
765 case eDVBFrontendParametersCable::Modulation::QAM16:
766 parm.u.qam.modulation = QAM_16;
768 case eDVBFrontendParametersCable::Modulation::QAM32:
769 parm.u.qam.modulation = QAM_32;
771 case eDVBFrontendParametersCable::Modulation::QAM64:
772 parm.u.qam.modulation = QAM_64;
774 case eDVBFrontendParametersCable::Modulation::QAM128:
775 parm.u.qam.modulation = QAM_128;
777 case eDVBFrontendParametersCable::Modulation::QAM256:
778 parm.u.qam.modulation = QAM_256;
781 case eDVBFrontendParametersCable::Modulation::Auto:
782 parm.u.qam.modulation = QAM_AUTO;
785 switch (feparm.inversion)
787 case eDVBFrontendParametersCable::Inversion::On:
788 parm.inversion = INVERSION_ON;
790 case eDVBFrontendParametersCable::Inversion::Off:
791 parm.inversion = INVERSION_OFF;
794 case eDVBFrontendParametersCable::Inversion::Unknown:
795 parm.inversion = INVERSION_AUTO;
798 switch (feparm.fec_inner)
800 case eDVBFrontendParametersCable::FEC::fNone:
801 parm.u.qam.fec_inner = FEC_NONE;
803 case eDVBFrontendParametersCable::FEC::f1_2:
804 parm.u.qam.fec_inner = FEC_1_2;
806 case eDVBFrontendParametersCable::FEC::f2_3:
807 parm.u.qam.fec_inner = FEC_2_3;
809 case eDVBFrontendParametersCable::FEC::f3_4:
810 parm.u.qam.fec_inner = FEC_3_4;
812 case eDVBFrontendParametersCable::FEC::f5_6:
813 parm.u.qam.fec_inner = FEC_5_6;
815 case eDVBFrontendParametersCable::FEC::f7_8:
816 parm.u.qam.fec_inner = FEC_7_8;
818 case eDVBFrontendParametersCable::FEC::f8_9:
819 parm.u.qam.fec_inner = FEC_8_9;
822 case eDVBFrontendParametersCable::FEC::fAuto:
823 parm.u.qam.fec_inner = FEC_AUTO;
830 eDVBFrontendParametersTerrestrial feparm;
831 if (where.getDVBT(feparm))
833 eDebug("no -T data");
836 parm.frequency = feparm.frequency;
838 switch (feparm.bandwidth)
840 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz:
841 parm.u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
843 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw7MHz:
844 parm.u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
846 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw6MHz:
847 parm.u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
850 case eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto:
851 parm.u.ofdm.bandwidth = BANDWIDTH_AUTO;
854 switch (feparm.code_rate_LP)
856 case eDVBFrontendParametersCable::FEC::f1_2:
857 parm.u.ofdm.code_rate_LP = FEC_1_2;
859 case eDVBFrontendParametersCable::FEC::f2_3:
860 parm.u.ofdm.code_rate_LP = FEC_2_3;
862 case eDVBFrontendParametersCable::FEC::f3_4:
863 parm.u.ofdm.code_rate_LP = FEC_3_4;
865 case eDVBFrontendParametersCable::FEC::f5_6:
866 parm.u.ofdm.code_rate_LP = FEC_5_6;
868 case eDVBFrontendParametersCable::FEC::f7_8:
869 parm.u.ofdm.code_rate_LP = FEC_7_8;
872 case eDVBFrontendParametersCable::FEC::fAuto:
873 case eDVBFrontendParametersCable::FEC::fNone:
874 parm.u.ofdm.code_rate_LP = FEC_AUTO;
877 switch (feparm.code_rate_HP)
879 case eDVBFrontendParametersCable::FEC::f1_2:
880 parm.u.ofdm.code_rate_HP = FEC_1_2;
882 case eDVBFrontendParametersCable::FEC::f2_3:
883 parm.u.ofdm.code_rate_HP = FEC_2_3;
885 case eDVBFrontendParametersCable::FEC::f3_4:
886 parm.u.ofdm.code_rate_HP = FEC_3_4;
888 case eDVBFrontendParametersCable::FEC::f5_6:
889 parm.u.ofdm.code_rate_HP = FEC_5_6;
891 case eDVBFrontendParametersCable::FEC::f7_8:
892 parm.u.ofdm.code_rate_HP = FEC_7_8;
895 case eDVBFrontendParametersCable::FEC::fAuto:
896 case eDVBFrontendParametersCable::FEC::fNone:
897 parm.u.ofdm.code_rate_HP = FEC_AUTO;
900 switch (feparm.modulation)
902 case eDVBFrontendParametersTerrestrial::Modulation::QPSK:
903 parm.u.ofdm.constellation = QPSK;
905 case eDVBFrontendParametersTerrestrial::Modulation::QAM16:
906 parm.u.ofdm.constellation = QAM_16;
909 case eDVBFrontendParametersTerrestrial::Modulation::Auto:
910 parm.u.ofdm.constellation = QAM_AUTO;
913 switch (feparm.transmission_mode)
915 case eDVBFrontendParametersTerrestrial::TransmissionMode::TM2k:
916 parm.u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
918 case eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k:
919 parm.u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
922 case eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto:
923 parm.u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
926 switch (feparm.guard_interval)
928 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_32:
929 parm.u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
931 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_16:
932 parm.u.ofdm.guard_interval = GUARD_INTERVAL_1_16;
934 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_8:
935 parm.u.ofdm.guard_interval = GUARD_INTERVAL_1_8;
937 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_4:
938 parm.u.ofdm.guard_interval = GUARD_INTERVAL_1_4;
941 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_Auto:
942 parm.u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
945 switch (feparm.hierarchy)
947 case eDVBFrontendParametersTerrestrial::Hierarchy::H1:
948 parm.u.ofdm.hierarchy_information = HIERARCHY_1;
950 case eDVBFrontendParametersTerrestrial::Hierarchy::H2:
951 parm.u.ofdm.hierarchy_information = HIERARCHY_2;
953 case eDVBFrontendParametersTerrestrial::Hierarchy::H4:
954 parm.u.ofdm.hierarchy_information = HIERARCHY_4;
957 case eDVBFrontendParametersTerrestrial::Hierarchy::HAuto:
958 parm.u.ofdm.hierarchy_information = HIERARCHY_AUTO;
964 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
965 m_tuneTimer->start(0,true);
967 m_sec_sequence.current() = m_sec_sequence.begin();
969 if (m_state != stateTuning)
972 m_state = stateTuning;
973 m_stateChanged(this);
979 RESULT eDVBFrontend::connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)
981 connection = new eConnection(this, m_stateChanged.connect(stateChange));
985 RESULT eDVBFrontend::setVoltage(int voltage)
987 if (m_type != feSatellite)
989 #if HAVE_DVB_API_VERSION < 3
992 bool increased=false;
993 fe_sec_voltage_t vlt;
995 m_curVoltage=voltage;
999 for (int i=0; i < 3; ++i) // reset diseqc
1001 vlt = SEC_VOLTAGE_OFF;
1004 #if HAVE_DVB_API_VERSION < 3
1005 vlt = SEC_VOLTAGE_13_5;
1011 vlt = SEC_VOLTAGE_13;
1014 #if HAVE_DVB_API_VERSION < 3
1015 vlt = SEC_VOLTAGE_18_5;
1021 vlt = SEC_VOLTAGE_18;
1026 #if HAVE_DVB_API_VERSION < 3
1027 return ::ioctl(m_secfd, SEC_SET_VOLTAGE, vlt);
1029 if (::ioctl(m_fd, FE_ENABLE_HIGH_LNB_VOLTAGE, increased) < 0)
1030 perror("FE_ENABLE_HIGH_LNB_VOLTAGE");
1031 return ::ioctl(m_fd, FE_SET_VOLTAGE, vlt);
1035 RESULT eDVBFrontend::getState(int &state)
1041 RESULT eDVBFrontend::setTone(int t)
1043 if (m_type != feSatellite)
1045 #if HAVE_DVB_API_VERSION < 3
1048 fe_sec_tone_mode_t tone;
1057 tone = SEC_TONE_OFF;
1062 #if HAVE_DVB_API_VERSION < 3
1063 return ::ioctl(m_secfd, SEC_SET_TONE, tone);
1065 return ::ioctl(m_fd, FE_SET_TONE, tone);
1069 #if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_MASTER_CMD)
1070 #define SEC_DISEQC_SEND_MASTER_CMD _IOW('o', 97, struct secCommand *)
1073 RESULT eDVBFrontend::sendDiseqc(const eDVBDiseqcCommand &diseqc)
1075 #if HAVE_DVB_API_VERSION < 3
1076 struct secCommand cmd;
1077 cmd.type = SEC_CMDTYPE_DISEQC_RAW;
1078 cmd.u.diseqc.cmdtype = diseqc.data[0];
1079 cmd.u.diseqc.addr = diseqc.data[1];
1080 cmd.u.diseqc.cmd = diseqc.data[2];
1081 cmd.u.diseqc.numParams = diseqc.len-3;
1082 memcpy(cmd.u.diseqc.params, diseqc.data+3, diseqc.len-3);
1083 if (::ioctl(m_secfd, SEC_DISEQC_SEND_MASTER_CMD, &cmd))
1085 struct dvb_diseqc_master_cmd cmd;
1086 memcpy(cmd.msg, diseqc.data, diseqc.len);
1087 cmd.msg_len = diseqc.len;
1088 if (::ioctl(m_fd, FE_DISEQC_SEND_MASTER_CMD, &cmd))
1094 #if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_BURST)
1095 #define SEC_DISEQC_SEND_BURST _IO('o', 96)
1097 RESULT eDVBFrontend::sendToneburst(int burst)
1099 #if HAVE_DVB_API_VERSION < 3
1100 secMiniCmd cmd = SEC_MINI_NONE;
1102 fe_sec_mini_cmd_t cmd = SEC_MINI_A;
1104 if ( burst == eDVBSatelliteDiseqcParameters::A )
1106 else if ( burst == eDVBSatelliteDiseqcParameters::B )
1108 #if HAVE_DVB_API_VERSION < 3
1109 if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd))
1112 if (::ioctl(m_fd, FE_DISEQC_SEND_BURST, cmd))
1118 RESULT eDVBFrontend::setSEC(iDVBSatelliteEquipmentControl *sec)
1124 RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list)
1126 m_sec_sequence = list;
1130 RESULT eDVBFrontend::getData(int num, int &data)
1132 if ( num < (int)(sizeof(m_data)/sizeof(int)) )
1140 RESULT eDVBFrontend::setData(int num, int val)
1142 if ( num < (int)(sizeof(m_data)/sizeof(int)) )
1150 int eDVBFrontend::isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)
1153 if (feparm->getSystem(type) || type != m_type)
1156 if (m_type == eDVBFrontend::feSatellite)
1159 eDVBFrontendParametersSatellite sat_parm;
1160 ASSERT(!feparm->getDVBS(sat_parm));
1161 return m_sec->canTune(sat_parm, this, 1 << m_fe);