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_inversion parm.Inversion
22 #define parm_u_qpsk_symbol_rate parm.u.qpsk.SymbolRate
23 #define parm_u_qpsk_fec_inner parm.u.qpsk.FEC_inner
24 #define parm_u_qam_symbol_rate parm.u.qam.SymbolRate
25 #define parm_u_qam_fec_inner parm.u.qam.FEC_inner
26 #define parm_u_qam_modulation parm.u.qam.QAM
27 #define parm_u_ofdm_bandwidth parm.u.ofdm.bandWidth
28 #define parm_u_ofdm_code_rate_LP parm.u.ofdm.LP_CodeRate
29 #define parm_u_ofdm_code_rate_HP parm.u.ofdm.HP_CodeRate
30 #define parm_u_ofdm_constellation parm.u.ofdm.Constellation
31 #define parm_u_ofdm_transmission_mode parm.u.ofdm.TransmissionMode
32 #define parm_u_ofdm_guard_interval parm.u.ofdm.guardInterval
33 #define parm_u_ofdm_hierarchy_information parm.u.ofdm.HierarchyInformation
35 #include <linux/dvb/frontend.h>
36 #define parm_frequency parm.frequency
37 #define parm_inversion parm.inversion
38 #define parm_u_qpsk_symbol_rate parm.u.qpsk.symbol_rate
39 #define parm_u_qpsk_fec_inner parm.u.qpsk.fec_inner
40 #define parm_u_qam_symbol_rate parm.u.qam.symbol_rate
41 #define parm_u_qam_fec_inner parm.u.qam.fec_inner
42 #define parm_u_qam_modulation parm.u.qam.modulation
43 #define parm_u_ofdm_bandwidth parm.u.ofdm.bandwidth
44 #define parm_u_ofdm_code_rate_LP parm.u.ofdm.code_rate_LP
45 #define parm_u_ofdm_code_rate_HP parm.u.ofdm.code_rate_HP
46 #define parm_u_ofdm_constellation parm.u.ofdm.constellation
47 #define parm_u_ofdm_transmission_mode parm.u.ofdm.transmission_mode
48 #define parm_u_ofdm_guard_interval parm.u.ofdm.guard_interval
49 #define parm_u_ofdm_hierarchy_information parm.u.ofdm.hierarchy_information
52 #include <dvbsi++/satellite_delivery_system_descriptor.h>
53 #include <dvbsi++/cable_delivery_system_descriptor.h>
54 #include <dvbsi++/terrestrial_delivery_system_descriptor.h>
56 void eDVBDiseqcCommand::setCommandString(const char *str)
61 int slen = strlen(str);
64 eDebug("invalid diseqc command string length (not 2 byte aligned)");
67 if (slen > MAX_DISEQC_LENGTH*2)
69 eDebug("invalid diseqc command string length (string is to long)");
73 for (int i=0; i < slen; ++i)
75 unsigned char c = str[i];
78 case '0' ... '9': c-=48; break;
79 case 'a' ... 'f': c-=87; break;
80 case 'A' ... 'F': c-=55; break;
82 eDebug("invalid character in hex string..ignore complete diseqc command !");
96 void eDVBFrontendParametersSatellite::set(const SatelliteDeliverySystemDescriptor &descriptor)
98 frequency = descriptor.getFrequency() * 10;
99 symbol_rate = descriptor.getSymbolRate() * 100;
100 polarisation = descriptor.getPolarization();
101 fec = descriptor.getFecInner();
104 inversion = Inversion::Unknown;
105 orbital_position = ((descriptor.getOrbitalPosition() >> 12) & 0xF) * 1000;
106 orbital_position += ((descriptor.getOrbitalPosition() >> 8) & 0xF) * 100;
107 orbital_position += ((descriptor.getOrbitalPosition() >> 4) & 0xF) * 10;
108 orbital_position += ((descriptor.getOrbitalPosition()) & 0xF);
109 if (orbital_position && (!descriptor.getWestEastFlag()))
110 orbital_position = 3600 - orbital_position;
111 eDebug("SAT freq %d, %s, pos %d, sr %d, fec %d",
113 polarisation ? "hor" : "vert",
118 void eDVBFrontendParametersCable::set(const CableDeliverySystemDescriptor &descriptor)
120 frequency = descriptor.getFrequency() / 10;
121 symbol_rate = descriptor.getSymbolRate() * 100;
122 fec_inner = descriptor.getFecInner();
123 if ( fec_inner == 0xF )
124 fec_inner = FEC::fNone;
125 modulation = descriptor.getModulation();
126 if ( modulation > 0x5 )
127 modulation = Modulation::Auto;
128 inversion = Inversion::Unknown;
129 eDebug("Cable freq %d, mod %d, sr %d, fec %d",
131 modulation, symbol_rate, fec_inner);
134 void eDVBFrontendParametersTerrestrial::set(const TerrestrialDeliverySystemDescriptor &descriptor)
136 frequency = descriptor.getCentreFrequency() * 10;
137 bandwidth = descriptor.getBandwidth();
138 if ( bandwidth > 2 ) // 5Mhz forced to auto
139 bandwidth = Bandwidth::BwAuto;
140 code_rate_HP = descriptor.getCodeRateHpStream();
141 if (code_rate_HP > 4)
142 code_rate_HP = FEC::fAuto;
143 code_rate_LP = descriptor.getCodeRateLpStream();
144 if (code_rate_LP > 4)
145 code_rate_LP = FEC::fAuto;
146 transmission_mode = descriptor.getTransmissionMode();
147 if (transmission_mode > 2)
148 transmission_mode = TransmissionMode::TMAuto;
149 guard_interval = descriptor.getGuardInterval();
150 if (guard_interval > 3)
151 guard_interval = GuardInterval::GI_Auto;
152 hierarchy = descriptor.getHierarchyInformation()&3;
153 modulation = descriptor.getConstellation();
155 modulation = Modulation::Auto;
156 inversion = Inversion::Unknown;
157 eDebug("Terr freq %d, bw %d, cr_hp %d, cr_lp %d, tm_mode %d, guard %d, hierarchy %d, const %d",
158 frequency, bandwidth, code_rate_HP, code_rate_LP, transmission_mode,
159 guard_interval, hierarchy, modulation);
162 eDVBFrontendParameters::eDVBFrontendParameters(): m_type(-1)
166 DEFINE_REF(eDVBFrontendParameters);
168 RESULT eDVBFrontendParameters::getSystem(int &t) const
176 RESULT eDVBFrontendParameters::getDVBS(eDVBFrontendParametersSatellite &p) const
178 if (m_type != iDVBFrontend::feSatellite)
184 RESULT eDVBFrontendParameters::getDVBC(eDVBFrontendParametersCable &p) const
186 if (m_type != iDVBFrontend::feCable)
192 RESULT eDVBFrontendParameters::getDVBT(eDVBFrontendParametersTerrestrial &p) const
194 if (m_type != iDVBFrontend::feTerrestrial)
200 RESULT eDVBFrontendParameters::setDVBS(const eDVBFrontendParametersSatellite &p, bool no_rotor_command_on_tune)
203 sat.no_rotor_command_on_tune = no_rotor_command_on_tune;
204 m_type = iDVBFrontend::feSatellite;
208 RESULT eDVBFrontendParameters::setDVBC(const eDVBFrontendParametersCable &p)
211 m_type = iDVBFrontend::feCable;
215 RESULT eDVBFrontendParameters::setDVBT(const eDVBFrontendParametersTerrestrial &p)
218 m_type = iDVBFrontend::feTerrestrial;
222 RESULT eDVBFrontendParameters::calculateDifference(const iDVBFrontendParameters *parm, int &diff) const
227 if (parm->getSystem(type))
231 diff = 1<<30; // big difference
237 case iDVBFrontend::feSatellite:
239 eDVBFrontendParametersSatellite osat;
240 if (parm->getDVBS(osat))
243 if (sat.orbital_position != osat.orbital_position)
245 else if (sat.polarisation != osat.polarisation)
249 diff = abs(sat.frequency - osat.frequency);
250 diff += abs(sat.symbol_rate - osat.symbol_rate);
254 case iDVBFrontend::feCable:
255 eDVBFrontendParametersCable ocable;
256 if (parm->getDVBC(ocable))
259 if (cable.modulation != ocable.modulation && cable.modulation != eDVBFrontendParametersCable::Modulation::Auto && ocable.modulation != eDVBFrontendParametersCable::Modulation::Auto)
261 else if (cable.inversion != ocable.inversion && cable.inversion != eDVBFrontendParametersCable::Inversion::Unknown && ocable.inversion != eDVBFrontendParametersCable::Inversion::Unknown)
265 diff = abs(cable.frequency - ocable.frequency);
266 diff += abs(cable.symbol_rate - ocable.symbol_rate);
270 case iDVBFrontend::feTerrestrial:
271 eDVBFrontendParametersTerrestrial oterrestrial;
272 if (parm->getDVBT(oterrestrial))
275 diff = abs(terrestrial.frequency - oterrestrial.frequency);
284 RESULT eDVBFrontendParameters::getHash(unsigned long &hash) const
288 case iDVBFrontend::feSatellite:
290 hash = (sat.orbital_position << 16);
291 hash |= ((sat.frequency/1000)&0xFFFF)|((sat.polarisation&1) << 15);
294 case iDVBFrontend::feCable:
295 case iDVBFrontend::feTerrestrial:
301 DEFINE_REF(eDVBFrontend);
303 eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok)
304 :m_type(-1), m_fe(fe), m_fd(-1), m_timeout(0), m_tuneTimer(0)
305 #if HAVE_DVB_API_VERSION < 3
309 #if HAVE_DVB_API_VERSION < 3
310 sprintf(m_filename, "/dev/dvb/card%d/frontend%d", adap, fe);
311 sprintf(m_sec_filename, "/dev/dvb/card%d/sec%d", adap, fe);
313 sprintf(m_filename, "/dev/dvb/adapter%d/frontend%d", adap, fe);
315 m_timeout = new eTimer(eApp);
316 CONNECT(m_timeout->timeout, eDVBFrontend::timeout);
318 m_tuneTimer = new eTimer(eApp);
319 CONNECT(m_tuneTimer->timeout, eDVBFrontend::tuneLoop);
321 int entries = sizeof(m_data) / sizeof(int);
322 for (int i=0; i<entries; ++i)
325 m_idleInputpower[0]=m_idleInputpower[1]=0;
327 ok = !openFrontend();
331 int eDVBFrontend::openFrontend()
334 return -1; // already opened
339 #if HAVE_DVB_API_VERSION < 3
340 m_secfd = ::open(m_sec_filename, O_RDWR);
343 eWarning("failed! (%s) %m", m_sec_filename);
346 FrontendInfo fe_info;
348 dvb_frontend_info fe_info;
350 eDebug("opening frontend %d", m_fe);
351 m_fd = ::open(m_filename, O_RDWR|O_NONBLOCK);
354 eWarning("failed! (%s) %m", m_filename);
355 #if HAVE_DVB_API_VERSION < 3
364 if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
366 eWarning("ioctl FE_GET_INFO failed");
369 #if HAVE_DVB_API_VERSION < 3
376 switch (fe_info.type)
379 m_type = iDVBFrontend::feSatellite;
382 m_type = iDVBFrontend::feCable;
385 m_type = iDVBFrontend::feTerrestrial;
388 eWarning("unknown frontend type.");
391 #if HAVE_DVB_API_VERSION < 3
397 eDebug("detected %s frontend", "satellite\0cable\0 terrestrial"+fe_info.type*10);
400 setTone(iDVBFrontend::toneOff);
401 setVoltage(iDVBFrontend::voltageOff);
403 m_sn = new eSocketNotifier(eApp, m_fd, eSocketNotifier::Read);
404 CONNECT(m_sn->activated, eDVBFrontend::feEvent);
409 int eDVBFrontend::closeFrontend()
411 if (!m_fe && m_data[7] != -1)
413 // try to close the first frontend.. but the second is linked to the first
414 eDVBRegisteredFrontend *linked_fe = (eDVBRegisteredFrontend*)m_data[7];
415 if (linked_fe->m_inuse)
417 eDebug("dont close frontend %d until the linked frontend %d is still in use",
418 m_fe, linked_fe->m_frontend->getID());
424 eDebug("close frontend %d", m_fe);
426 setTone(iDVBFrontend::toneOff);
427 setVoltage(iDVBFrontend::voltageOff);
429 m_sec->setRotorMoving(false);
432 m_data[0] = m_data[1] = m_data[2] = -1;
434 #if HAVE_DVB_API_VERSION < 3
447 eDVBFrontend::~eDVBFrontend()
454 void eDVBFrontend::feEvent(int w)
458 #if HAVE_DVB_API_VERSION < 3
461 dvb_frontend_event event;
465 res = ::ioctl(m_fd, FE_GET_EVENT, &event);
467 if (res && (errno == EAGAIN))
472 eWarning("FE_GET_EVENT failed! %m");
479 #if HAVE_DVB_API_VERSION < 3
480 if (event.type == FE_COMPLETION_EV)
482 eDebug("(%d)fe event: status %x, inversion %s", m_fe, event.status, (event.parameters.inversion == INVERSION_ON) ? "on" : "off");
483 if (event.status & FE_HAS_LOCK)
493 state = stateLostLock;
494 m_data[0] = m_data[1] = m_data[2] = -1; // reset diseqc
497 if (m_state != state)
500 m_stateChanged(this);
505 void eDVBFrontend::timeout()
508 if (m_state == stateTuning)
510 m_state = stateFailed;
511 m_stateChanged(this);
515 int eDVBFrontend::readFrontendData(int type)
522 if (ioctl(m_fd, FE_READ_BER, &ber) < 0 && errno != ERANGE)
523 eDebug("FE_READ_BER failed (%m)");
529 if (ioctl(m_fd, FE_READ_SNR, &snr) < 0 && errno != ERANGE)
530 eDebug("FE_READ_SNR failed (%m)");
536 if (ioctl(m_fd, FE_READ_SIGNAL_STRENGTH, &strength) < 0 && errno != ERANGE)
537 eDebug("FE_READ_SIGNAL_STRENGTH failed (%m)");
542 #if HAVE_DVB_API_VERSION < 3
543 FrontendStatus status=0;
547 if ( ioctl(m_fd, FE_READ_STATUS, &status) < 0 && errno != ERANGE )
548 eDebug("FE_READ_STATUS failed (%m)");
549 return !!(status&FE_HAS_LOCK);
553 #if HAVE_DVB_API_VERSION < 3
554 FrontendStatus status=0;
558 if ( ioctl(m_fd, FE_READ_STATUS, &status) < 0 && errno != ERANGE )
559 eDebug("FE_READ_STATUS failed (%m)");
560 return !!(status&FE_HAS_SYNC);
566 void PutToDict(PyObject *dict, const char*key, long value)
568 PyObject *item = PyInt_FromLong(value);
571 if (PyDict_SetItemString(dict, key, item))
572 eDebug("put %s to dict failed", key);
576 eDebug("could not create PyObject for %s", key);
579 void PutToDict(PyObject *dict, const char*key, const char *value)
581 PyObject *item = PyString_FromString(value);
584 if (PyDict_SetItemString(dict, key, item))
585 eDebug("put %s to dict failed", key);
589 eDebug("could not create PyObject for %s", key);
592 void fillDictWithSatelliteData(PyObject *dict, const FRONTENDPARAMETERS &parm, eDVBFrontend *fe)
598 fe->getData(9, freq_offset);
599 int frequency = parm_frequency + freq_offset;
600 PutToDict(dict, "frequency", frequency);
601 PutToDict(dict, "symbol_rate", parm_u_qpsk_symbol_rate);
603 switch(parm_u_qpsk_fec_inner)
625 PutToDict(dict, "fec_inner", fec);
628 void fillDictWithCableData(PyObject *dict, const FRONTENDPARAMETERS &parm)
631 PutToDict(dict, "frequency", parm_frequency/1000);
632 PutToDict(dict, "symbol_rate", parm_u_qam_symbol_rate);
633 switch(parm_u_qam_fec_inner)
653 #if HAVE_DVB_API_VERSION >= 3
663 PutToDict(dict, "fec_inner", tmp);
664 switch(parm_u_qam_modulation)
686 PutToDict(dict, "modulation", tmp);
689 void fillDictWithTerrestrialData(PyObject *dict, const FRONTENDPARAMETERS &parm)
692 PutToDict(dict, "frequency", parm_frequency);
693 switch (parm_u_ofdm_bandwidth)
695 case BANDWIDTH_8_MHZ:
696 tmp = "BANDWIDTH_8_MHZ";
698 case BANDWIDTH_7_MHZ:
699 tmp = "BANDWIDTH_7_MHZ";
701 case BANDWIDTH_6_MHZ:
702 tmp = "BANDWIDTH_6_MHZ";
706 tmp = "BANDWIDTH_AUTO";
709 PutToDict(dict, "bandwidth", tmp);
710 switch (parm_u_ofdm_code_rate_LP)
732 PutToDict(dict, "code_rate_lp", tmp);
733 switch (parm_u_ofdm_code_rate_HP)
755 PutToDict(dict, "code_rate_hp", tmp);
756 switch (parm_u_ofdm_constellation)
769 PutToDict(dict, "constellation", tmp);
770 switch (parm_u_ofdm_transmission_mode)
772 case TRANSMISSION_MODE_2K:
773 tmp = "TRANSMISSION_MODE_2K";
775 case TRANSMISSION_MODE_8K:
776 tmp = "TRANSMISSION_MODE_8K";
779 case TRANSMISSION_MODE_AUTO:
780 tmp = "TRANSMISSION_MODE_AUTO";
783 PutToDict(dict, "transmission_mode", tmp);
784 switch (parm_u_ofdm_guard_interval)
786 case GUARD_INTERVAL_1_32:
787 tmp = "GUARD_INTERVAL_1_32";
789 case GUARD_INTERVAL_1_16:
790 tmp = "GUARD_INTERVAL_1_16";
792 case GUARD_INTERVAL_1_8:
793 tmp = "GUARD_INTERVAL_1_8";
795 case GUARD_INTERVAL_1_4:
796 tmp = "GUARD_INTERVAL_1_4";
799 case GUARD_INTERVAL_AUTO:
800 tmp = "GUARD_INTERVAL_AUTO";
803 PutToDict(dict, "guard_interval", tmp);
804 switch (parm_u_ofdm_hierarchy_information)
817 tmp = "HIERARCHY_AUTO";
820 PutToDict(dict, "hierarchy_information", tmp);
823 PyObject *eDVBFrontend::readTransponderData(bool original)
825 PyObject *ret=PyDict_New();
829 bool read=m_fd != -1;
832 PutToDict(ret, "tuner_number", m_fe);
850 PutToDict(ret, "tuner_type", tmp);
854 FRONTENDPARAMETERS front;
877 PutToDict(ret, "tuner_state", tmp);
879 PutToDict(ret, "tuner_locked", readFrontendData(Locked));
880 PutToDict(ret, "tuner_synced", readFrontendData(Synced));
881 PutToDict(ret, "tuner_bit_error_rate", readFrontendData(bitErrorRate));
882 PutToDict(ret, "tuner_signal_power", readFrontendData(signalPower));
883 PutToDict(ret, "tuner_signal_quality", readFrontendData(signalQuality));
885 if (!original && ioctl(m_fd, FE_GET_FRONTEND, &front)<0)
886 eDebug("FE_GET_FRONTEND (%m)");
889 tmp = "INVERSION_AUTO";
890 switch(parm_inversion)
893 tmp = "INVERSION_ON";
896 tmp = "INVERSION_OFF";
902 PutToDict(ret, "inversion", tmp);
907 fillDictWithSatelliteData(ret, original?parm:front, this);
910 fillDictWithCableData(ret, original?parm:front);
913 fillDictWithTerrestrialData(ret, original?parm:front);
927 #ifndef FP_IOCTL_GET_ID
928 #define FP_IOCTL_GET_ID 0
930 int eDVBFrontend::readInputpower()
932 int power=m_fe; // this is needed for read inputpower from the correct tuner !
934 // open front prozessor
935 int fp=::open("/dev/dbox/fp0", O_RDWR);
938 eDebug("couldn't open fp");
941 static bool old_fp = (::ioctl(fp, FP_IOCTL_GET_ID) < 0);
942 if ( ioctl( fp, old_fp ? 9 : 0x100, &power ) < 0 )
944 eDebug("FP_IOCTL_GET_LNB_CURRENT failed (%m)");
952 bool eDVBFrontend::setSecSequencePos(int steps)
954 eDebug("set sequence pos %d", steps);
959 if (m_sec_sequence.current() != m_sec_sequence.end())
960 ++m_sec_sequence.current();
965 if (m_sec_sequence.current() != m_sec_sequence.begin() && m_sec_sequence.current() != m_sec_sequence.end())
966 --m_sec_sequence.current();
972 void eDVBFrontend::tuneLoop() // called by m_tuneTimer
975 if ( m_sec_sequence && m_sec_sequence.current() != m_sec_sequence.end() )
977 // eDebug("tuneLoop %d\n", m_sec_sequence.current()->cmd);
978 switch (m_sec_sequence.current()->cmd)
980 case eSecCommand::SLEEP:
981 delay = m_sec_sequence.current()++->msec;
982 eDebug("[SEC] sleep %dms", delay);
984 case eSecCommand::GOTO:
985 if ( !setSecSequencePos(m_sec_sequence.current()->steps) )
986 ++m_sec_sequence.current();
988 case eSecCommand::SET_VOLTAGE:
990 int voltage = m_sec_sequence.current()++->voltage;
991 eDebug("[SEC] setVoltage %d", voltage);
995 case eSecCommand::IF_VOLTAGE_GOTO:
997 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
998 if ( compare.voltage == m_curVoltage && setSecSequencePos(compare.steps) )
1000 ++m_sec_sequence.current();
1003 case eSecCommand::IF_NOT_VOLTAGE_GOTO:
1005 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1006 if ( compare.voltage != m_curVoltage && setSecSequencePos(compare.steps) )
1008 ++m_sec_sequence.current();
1011 case eSecCommand::SET_TONE:
1012 eDebug("[SEC] setTone %d", m_sec_sequence.current()->tone);
1013 setTone(m_sec_sequence.current()++->tone);
1015 case eSecCommand::SEND_DISEQC:
1016 sendDiseqc(m_sec_sequence.current()->diseqc);
1017 eDebugNoNewLine("[SEC] sendDiseqc: ");
1018 for (int i=0; i < m_sec_sequence.current()->diseqc.len; ++i)
1019 eDebugNoNewLine("%02x", m_sec_sequence.current()->diseqc.data[i]);
1021 ++m_sec_sequence.current();
1023 case eSecCommand::SEND_TONEBURST:
1024 eDebug("[SEC] sendToneburst: %d", m_sec_sequence.current()->toneburst);
1025 sendToneburst(m_sec_sequence.current()++->toneburst);
1027 case eSecCommand::SET_FRONTEND:
1028 eDebug("[SEC] setFrontend");
1030 ++m_sec_sequence.current();
1032 case eSecCommand::START_TUNE_TIMEOUT:
1033 m_timeout->start(5000, 1); // 5 sec timeout. TODO: symbolrate dependent
1034 ++m_sec_sequence.current();
1036 case eSecCommand::SET_TIMEOUT:
1037 m_timeoutCount = m_sec_sequence.current()++->val;
1038 eDebug("[SEC] set timeout %d", m_timeoutCount);
1040 case eSecCommand::IF_TIMEOUT_GOTO:
1041 if (!m_timeoutCount)
1043 eDebug("[SEC] rotor timout");
1044 m_sec->setRotorMoving(false);
1045 setSecSequencePos(m_sec_sequence.current()->steps);
1048 ++m_sec_sequence.current();
1050 case eSecCommand::MEASURE_IDLE_INPUTPOWER:
1052 int idx = m_sec_sequence.current()++->val;
1053 if ( idx == 0 || idx == 1 )
1055 m_idleInputpower[idx] = readInputpower();
1056 eDebug("[SEC] idleInputpower[%d] is %d", idx, m_idleInputpower[idx]);
1059 eDebug("[SEC] idleInputpower measure index(%d) out of bound !!!", idx);
1062 case eSecCommand::IF_MEASURE_IDLE_WAS_NOT_OK_GOTO:
1064 eSecCommand::pair &compare = m_sec_sequence.current()->compare;
1065 int idx = compare.voltage;
1066 if ( idx == 0 || idx == 1 )
1068 int idle = readInputpower();
1069 int diff = abs(idle-m_idleInputpower[idx]);
1072 eDebug("measure idle(%d) was not okay.. (%d - %d = %d) retry", idx, m_idleInputpower[idx], idle, diff);
1073 setSecSequencePos(compare.steps);
1077 ++m_sec_sequence.current();
1080 case eSecCommand::IF_TUNER_LOCKED_GOTO:
1082 eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
1083 if (readFrontendData(Locked))
1085 eDebug("[SEC] locked step %d ok", cmd.okcount);
1087 if (cmd.okcount > 12)
1089 eDebug("ok > 12 .. goto %d\n",m_sec_sequence.current()->steps);
1090 setSecSequencePos(cmd.steps);
1096 eDebug("[SEC] rotor locked step %d failed", cmd.okcount);
1098 if (!m_timeoutCount && m_retryCount > 0)
1102 ++m_sec_sequence.current();
1105 case eSecCommand::MEASURE_RUNNING_INPUTPOWER:
1106 m_runningInputpower = readInputpower();
1107 eDebug("[SEC] runningInputpower is %d", m_runningInputpower);
1108 ++m_sec_sequence.current();
1110 case eSecCommand::IF_INPUTPOWER_DELTA_GOTO:
1112 int idleInputpower = m_idleInputpower[ (m_curVoltage&1) ? 0 : 1];
1113 eSecCommand::rotor &cmd = m_sec_sequence.current()->measure;
1114 const char *txt = cmd.direction ? "running" : "stopped";
1115 eDebug("[SEC] waiting for rotor %s %d, idle %d, delta %d",
1117 m_runningInputpower,
1120 if ( (cmd.direction && abs(m_runningInputpower - idleInputpower) >= cmd.deltaA)
1121 || (!cmd.direction && abs(m_runningInputpower - idleInputpower) <= cmd.deltaA) )
1124 eDebug("[SEC] rotor %s step %d ok", txt, cmd.okcount);
1125 if ( cmd.okcount > 6 )
1127 m_sec->setRotorMoving(cmd.direction);
1128 eDebug("[SEC] rotor is %s", txt);
1129 if (setSecSequencePos(cmd.steps))
1135 eDebug("[SEC] rotor not %s... reset counter.. increase timeout", txt);
1137 if (!m_timeoutCount && m_retryCount > 0)
1141 ++m_sec_sequence.current();
1144 case eSecCommand::IF_ROTORPOS_VALID_GOTO:
1145 if (m_data[5] != -1 && m_data[6] != -1)
1146 setSecSequencePos(m_sec_sequence.current()->steps);
1148 ++m_sec_sequence.current();
1150 case eSecCommand::INVALIDATE_CURRENT_ROTORPARMS:
1151 m_data[5] = m_data[6] = -1;
1152 eDebug("[SEC] invalidate current rotorparams");
1153 ++m_sec_sequence.current();
1155 case eSecCommand::UPDATE_CURRENT_ROTORPARAMS:
1156 m_data[5] = m_data[3];
1157 m_data[6] = m_data[4];
1158 eDebug("[SEC] update current rotorparams %d %04x %d", m_timeoutCount, m_data[5], m_data[6]);
1159 ++m_sec_sequence.current();
1161 case eSecCommand::SET_ROTOR_DISEQC_RETRYS:
1162 m_retryCount = m_sec_sequence.current()++->val;
1163 eDebug("[SEC] set rotor retries %d", m_retryCount);
1165 case eSecCommand::IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO:
1168 eDebug("[SEC] no more rotor retrys");
1169 setSecSequencePos(m_sec_sequence.current()->steps);
1172 ++m_sec_sequence.current();
1174 case eSecCommand::SET_POWER_LIMITING_MODE:
1177 ::open("/dev/i2c/1", O_RDWR) :
1178 ::open("/dev/i2c/0", O_RDWR);
1180 unsigned char data[2];
1181 ::ioctl(fd, I2C_SLAVE_FORCE, 0x10 >> 1);
1182 if(::read(fd, data, 1) != 1)
1183 eDebug("[SEC] error read lnbp (%m)");
1184 if ( m_sec_sequence.current()->mode == eSecCommand::modeStatic )
1186 data[0] |= 0x80; // enable static current limiting
1187 eDebug("[SEC] set static current limiting");
1191 data[0] &= ~0x80; // enable dynamic current limiting
1192 eDebug("[SEC] set dynamic current limiting");
1194 if(::write(fd, data, 1) != 1)
1195 eDebug("[SEC] error write lnbp (%m)");
1197 ++m_sec_sequence.current();
1201 ++m_sec_sequence.current();
1202 eDebug("[SEC] unhandled sec command");
1204 m_tuneTimer->start(delay,true);
1208 void eDVBFrontend::setFrontend()
1210 eDebug("setting frontend %d", m_fe);
1213 if (ioctl(m_fd, FE_SET_FRONTEND, &parm) == -1)
1215 perror("FE_SET_FRONTEND failed");
1220 RESULT eDVBFrontend::getFrontendType(int &t)
1228 RESULT eDVBFrontend::prepare_sat(const eDVBFrontendParametersSatellite &feparm)
1233 eWarning("no SEC module active!");
1236 res = m_sec->prepare(*this, parm, feparm, 1 << m_fe);
1239 parm_u_qpsk_symbol_rate = feparm.symbol_rate;
1240 switch (feparm.inversion)
1242 case eDVBFrontendParametersSatellite::Inversion::On:
1243 parm_inversion = INVERSION_ON;
1245 case eDVBFrontendParametersSatellite::Inversion::Off:
1246 parm_inversion = INVERSION_OFF;
1249 case eDVBFrontendParametersSatellite::Inversion::Unknown:
1250 parm_inversion = INVERSION_AUTO;
1256 case eDVBFrontendParametersSatellite::FEC::fNone:
1257 eDebug("no fec set.. assume auto");
1258 case eDVBFrontendParametersSatellite::FEC::fAuto:
1259 parm_u_qpsk_fec_inner = FEC_AUTO;
1261 case eDVBFrontendParametersSatellite::FEC::f1_2:
1262 parm_u_qpsk_fec_inner = FEC_1_2;
1264 case eDVBFrontendParametersSatellite::FEC::f2_3:
1265 parm_u_qpsk_fec_inner = FEC_2_3;
1267 case eDVBFrontendParametersSatellite::FEC::f3_4:
1268 parm_u_qpsk_fec_inner = FEC_3_4;
1270 case eDVBFrontendParametersSatellite::FEC::f5_6:
1271 parm_u_qpsk_fec_inner = FEC_5_6;
1273 case eDVBFrontendParametersSatellite::FEC::f7_8:
1274 parm_u_qpsk_fec_inner = FEC_7_8;
1277 // FIXME !!! get frequency range from tuner
1278 if ( parm_frequency < 900000 || parm_frequency > 2200000 )
1280 eDebug("%d mhz out of tuner range.. dont tune", parm_frequency/1000);
1283 eDebug("tuning to %d mhz", parm_frequency/1000);
1288 RESULT eDVBFrontend::prepare_cable(const eDVBFrontendParametersCable &feparm)
1290 parm_frequency = feparm.frequency * 1000;
1291 parm_u_qam_symbol_rate = feparm.symbol_rate;
1292 switch (feparm.modulation)
1294 case eDVBFrontendParametersCable::Modulation::QAM16:
1295 parm_u_qam_modulation = QAM_16;
1297 case eDVBFrontendParametersCable::Modulation::QAM32:
1298 parm_u_qam_modulation = QAM_32;
1300 case eDVBFrontendParametersCable::Modulation::QAM64:
1301 parm_u_qam_modulation = QAM_64;
1303 case eDVBFrontendParametersCable::Modulation::QAM128:
1304 parm_u_qam_modulation = QAM_128;
1306 case eDVBFrontendParametersCable::Modulation::QAM256:
1307 parm_u_qam_modulation = QAM_256;
1310 case eDVBFrontendParametersCable::Modulation::Auto:
1311 parm_u_qam_modulation = QAM_AUTO;
1314 switch (feparm.inversion)
1316 case eDVBFrontendParametersCable::Inversion::On:
1317 parm_inversion = INVERSION_ON;
1319 case eDVBFrontendParametersCable::Inversion::Off:
1320 parm_inversion = INVERSION_OFF;
1323 case eDVBFrontendParametersCable::Inversion::Unknown:
1324 parm_inversion = INVERSION_AUTO;
1327 switch (feparm.fec_inner)
1329 case eDVBFrontendParametersCable::FEC::fNone:
1330 parm_u_qam_fec_inner = FEC_NONE;
1332 case eDVBFrontendParametersCable::FEC::f1_2:
1333 parm_u_qam_fec_inner = FEC_1_2;
1335 case eDVBFrontendParametersCable::FEC::f2_3:
1336 parm_u_qam_fec_inner = FEC_2_3;
1338 case eDVBFrontendParametersCable::FEC::f3_4:
1339 parm_u_qam_fec_inner = FEC_3_4;
1341 case eDVBFrontendParametersCable::FEC::f5_6:
1342 parm_u_qam_fec_inner = FEC_5_6;
1344 case eDVBFrontendParametersCable::FEC::f7_8:
1345 parm_u_qam_fec_inner = FEC_7_8;
1347 #if HAVE_DVB_API_VERSION >= 3
1348 case eDVBFrontendParametersCable::FEC::f8_9:
1349 parm_u_qam_fec_inner = FEC_8_9;
1353 case eDVBFrontendParametersCable::FEC::fAuto:
1354 parm_u_qam_fec_inner = FEC_AUTO;
1360 RESULT eDVBFrontend::prepare_terrestrial(const eDVBFrontendParametersTerrestrial &feparm)
1362 parm_frequency = feparm.frequency;
1364 switch (feparm.bandwidth)
1366 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw8MHz:
1367 parm_u_ofdm_bandwidth = BANDWIDTH_8_MHZ;
1369 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw7MHz:
1370 parm_u_ofdm_bandwidth = BANDWIDTH_7_MHZ;
1372 case eDVBFrontendParametersTerrestrial::Bandwidth::Bw6MHz:
1373 parm_u_ofdm_bandwidth = BANDWIDTH_6_MHZ;
1376 case eDVBFrontendParametersTerrestrial::Bandwidth::BwAuto:
1377 parm_u_ofdm_bandwidth = BANDWIDTH_AUTO;
1380 switch (feparm.code_rate_LP)
1382 case eDVBFrontendParametersTerrestrial::FEC::f1_2:
1383 parm_u_ofdm_code_rate_LP = FEC_1_2;
1385 case eDVBFrontendParametersTerrestrial::FEC::f2_3:
1386 parm_u_ofdm_code_rate_LP = FEC_2_3;
1388 case eDVBFrontendParametersTerrestrial::FEC::f3_4:
1389 parm_u_ofdm_code_rate_LP = FEC_3_4;
1391 case eDVBFrontendParametersTerrestrial::FEC::f5_6:
1392 parm_u_ofdm_code_rate_LP = FEC_5_6;
1394 case eDVBFrontendParametersTerrestrial::FEC::f7_8:
1395 parm_u_ofdm_code_rate_LP = FEC_7_8;
1398 case eDVBFrontendParametersTerrestrial::FEC::fAuto:
1399 parm_u_ofdm_code_rate_LP = FEC_AUTO;
1402 switch (feparm.code_rate_HP)
1404 case eDVBFrontendParametersTerrestrial::FEC::f1_2:
1405 parm_u_ofdm_code_rate_HP = FEC_1_2;
1407 case eDVBFrontendParametersTerrestrial::FEC::f2_3:
1408 parm_u_ofdm_code_rate_HP = FEC_2_3;
1410 case eDVBFrontendParametersTerrestrial::FEC::f3_4:
1411 parm_u_ofdm_code_rate_HP = FEC_3_4;
1413 case eDVBFrontendParametersTerrestrial::FEC::f5_6:
1414 parm_u_ofdm_code_rate_HP = FEC_5_6;
1416 case eDVBFrontendParametersTerrestrial::FEC::f7_8:
1417 parm_u_ofdm_code_rate_HP = FEC_7_8;
1420 case eDVBFrontendParametersTerrestrial::FEC::fAuto:
1421 parm_u_ofdm_code_rate_HP = FEC_AUTO;
1424 switch (feparm.modulation)
1426 case eDVBFrontendParametersTerrestrial::Modulation::QPSK:
1427 parm_u_ofdm_constellation = QPSK;
1429 case eDVBFrontendParametersTerrestrial::Modulation::QAM16:
1430 parm_u_ofdm_constellation = QAM_16;
1433 case eDVBFrontendParametersTerrestrial::Modulation::Auto:
1434 parm_u_ofdm_constellation = QAM_AUTO;
1437 switch (feparm.transmission_mode)
1439 case eDVBFrontendParametersTerrestrial::TransmissionMode::TM2k:
1440 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_2K;
1442 case eDVBFrontendParametersTerrestrial::TransmissionMode::TM8k:
1443 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_8K;
1446 case eDVBFrontendParametersTerrestrial::TransmissionMode::TMAuto:
1447 parm_u_ofdm_transmission_mode = TRANSMISSION_MODE_AUTO;
1450 switch (feparm.guard_interval)
1452 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_32:
1453 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_32;
1455 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_16:
1456 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_16;
1458 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_8:
1459 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_8;
1461 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_1_4:
1462 parm_u_ofdm_guard_interval = GUARD_INTERVAL_1_4;
1465 case eDVBFrontendParametersTerrestrial::GuardInterval::GI_Auto:
1466 parm_u_ofdm_guard_interval = GUARD_INTERVAL_AUTO;
1469 switch (feparm.hierarchy)
1471 case eDVBFrontendParametersTerrestrial::Hierarchy::H1:
1472 parm_u_ofdm_hierarchy_information = HIERARCHY_1;
1474 case eDVBFrontendParametersTerrestrial::Hierarchy::H2:
1475 parm_u_ofdm_hierarchy_information = HIERARCHY_2;
1477 case eDVBFrontendParametersTerrestrial::Hierarchy::H4:
1478 parm_u_ofdm_hierarchy_information = HIERARCHY_4;
1481 case eDVBFrontendParametersTerrestrial::Hierarchy::HAuto:
1482 parm_u_ofdm_hierarchy_information = HIERARCHY_AUTO;
1488 RESULT eDVBFrontend::tune(const iDVBFrontendParameters &where)
1490 eDebug("(%d)tune", m_fe);
1500 m_sec_sequence.clear();
1506 eDVBFrontendParametersSatellite feparm;
1507 if (where.getDVBS(feparm))
1509 eDebug("no dvbs data!");
1512 res=prepare_sat(feparm);
1513 m_sec->setRotorMoving(false);
1518 eDVBFrontendParametersCable feparm;
1519 if (where.getDVBC(feparm))
1521 res=prepare_cable(feparm);
1524 m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
1525 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
1531 eDVBFrontendParametersTerrestrial feparm;
1532 if (where.getDVBT(feparm))
1534 eDebug("no -T data");
1537 res=prepare_terrestrial(feparm);
1540 m_sec_sequence.push_back( eSecCommand(eSecCommand::START_TUNE_TIMEOUT) );
1541 m_sec_sequence.push_back( eSecCommand(eSecCommand::SET_FRONTEND) );
1547 if (!res) // prepare ok
1549 m_tuneTimer->start(0,true);
1550 m_sec_sequence.current() = m_sec_sequence.begin();
1552 if (m_state != stateTuning)
1555 m_state = stateTuning;
1556 m_stateChanged(this);
1563 RESULT eDVBFrontend::connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)
1565 connection = new eConnection(this, m_stateChanged.connect(stateChange));
1569 RESULT eDVBFrontend::setVoltage(int voltage)
1571 if (m_type != feSatellite)
1573 #if HAVE_DVB_API_VERSION < 3
1576 bool increased=false;
1577 fe_sec_voltage_t vlt;
1579 m_curVoltage=voltage;
1583 for (int i=0; i < 3; ++i) // reset diseqc
1585 vlt = SEC_VOLTAGE_OFF;
1588 #if HAVE_DVB_API_VERSION < 3
1589 vlt = SEC_VOLTAGE_13_5;
1595 vlt = SEC_VOLTAGE_13;
1598 #if HAVE_DVB_API_VERSION < 3
1599 vlt = SEC_VOLTAGE_18_5;
1605 vlt = SEC_VOLTAGE_18;
1610 #if HAVE_DVB_API_VERSION < 3
1611 return ::ioctl(m_secfd, SEC_SET_VOLTAGE, vlt);
1613 if (::ioctl(m_fd, FE_ENABLE_HIGH_LNB_VOLTAGE, increased) < 0)
1614 perror("FE_ENABLE_HIGH_LNB_VOLTAGE");
1615 return ::ioctl(m_fd, FE_SET_VOLTAGE, vlt);
1619 RESULT eDVBFrontend::getState(int &state)
1625 RESULT eDVBFrontend::setTone(int t)
1627 if (m_type != feSatellite)
1629 #if HAVE_DVB_API_VERSION < 3
1632 fe_sec_tone_mode_t tone;
1641 tone = SEC_TONE_OFF;
1646 #if HAVE_DVB_API_VERSION < 3
1647 return ::ioctl(m_secfd, SEC_SET_TONE, tone);
1649 return ::ioctl(m_fd, FE_SET_TONE, tone);
1653 #if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_MASTER_CMD)
1654 #define SEC_DISEQC_SEND_MASTER_CMD _IOW('o', 97, struct secCommand *)
1657 RESULT eDVBFrontend::sendDiseqc(const eDVBDiseqcCommand &diseqc)
1659 #if HAVE_DVB_API_VERSION < 3
1660 struct secCommand cmd;
1661 cmd.type = SEC_CMDTYPE_DISEQC_RAW;
1662 cmd.u.diseqc.cmdtype = diseqc.data[0];
1663 cmd.u.diseqc.addr = diseqc.data[1];
1664 cmd.u.diseqc.cmd = diseqc.data[2];
1665 cmd.u.diseqc.numParams = diseqc.len-3;
1666 memcpy(cmd.u.diseqc.params, diseqc.data+3, diseqc.len-3);
1667 if (::ioctl(m_secfd, SEC_DISEQC_SEND_MASTER_CMD, &cmd))
1669 struct dvb_diseqc_master_cmd cmd;
1670 memcpy(cmd.msg, diseqc.data, diseqc.len);
1671 cmd.msg_len = diseqc.len;
1672 if (::ioctl(m_fd, FE_DISEQC_SEND_MASTER_CMD, &cmd))
1678 #if HAVE_DVB_API_VERSION < 3 && !defined(SEC_DISEQC_SEND_BURST)
1679 #define SEC_DISEQC_SEND_BURST _IO('o', 96)
1681 RESULT eDVBFrontend::sendToneburst(int burst)
1683 #if HAVE_DVB_API_VERSION < 3
1684 secMiniCmd cmd = SEC_MINI_NONE;
1686 fe_sec_mini_cmd_t cmd = SEC_MINI_A;
1688 if ( burst == eDVBSatelliteDiseqcParameters::A )
1690 else if ( burst == eDVBSatelliteDiseqcParameters::B )
1692 #if HAVE_DVB_API_VERSION < 3
1693 if (::ioctl(m_secfd, SEC_DISEQC_SEND_BURST, cmd))
1696 if (::ioctl(m_fd, FE_DISEQC_SEND_BURST, cmd))
1702 RESULT eDVBFrontend::setSEC(iDVBSatelliteEquipmentControl *sec)
1708 RESULT eDVBFrontend::setSecSequence(const eSecCommandList &list)
1710 m_sec_sequence = list;
1714 RESULT eDVBFrontend::getData(int num, int &data)
1716 if ( num < (int)(sizeof(m_data)/sizeof(int)) )
1724 RESULT eDVBFrontend::setData(int num, int val)
1726 if ( num < (int)(sizeof(m_data)/sizeof(int)) )
1734 int eDVBFrontend::isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)
1737 if (feparm->getSystem(type) || type != m_type)
1740 if (m_type == eDVBFrontend::feSatellite)
1743 eDVBFrontendParametersSatellite sat_parm;
1744 ASSERT(!feparm->getDVBS(sat_parm));
1745 return m_sec->canTune(sat_parm, this, 1 << m_fe);