4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Thorsten Horstmann <tho@berlios.de>
27 // Anton Gillert <atx@berlios.de>
30 \brief DVBFrontendHandle non-inline non-template implementation */
32 #include "DVBFrontendHandle.hh"
33 //#include "DVBFrontendHandle.ih"
36 #include <boost/format.hpp>
37 #include <sys/socket.h>
38 #include <senf/Utils/Exception.hh>
39 #include <sys/ioctl.h>
42 //#include "DVBFrontendHandle.mpp"
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 // senf::DVBFrontendHandle
50 prefix_ void senf::DVBFrontendSocketProtocol::init_client(unsigned short adapter, unsigned short device, int flags)
53 string devFrontend = str( boost::format("/dev/dvb/adapter%d/frontend%d") % adapter % device);
54 int f = open(devFrontend.c_str(), flags);
56 SENF_THROW_SYSTEM_EXCEPTION("Could not open frontend device of DVB adapter ") << devFrontend << ".";
60 prefix_ unsigned senf::DVBFrontendSocketProtocol::available()
66 prefix_ bool senf::DVBFrontendSocketProtocol::eof()
72 prefix_ void senf::DVBFrontendSocketProtocol::tune(const struct dvb_frontend_parameters & frontend)
76 if (::ioctl(fd(), FE_SET_FRONTEND, &frontend) )
77 SENF_THROW_SYSTEM_EXCEPTION("ioctl FE_SET_FRONTEND failed. Socket should initialized with r/w permissions.");
80 prefix_ void senf::DVBFrontendSocketProtocol::tuneDVB_T(unsigned int frequency,
81 fe_spectral_inversion_t inversion,
82 fe_bandwidth_t bandwidth,
83 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
84 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
85 fe_modulation_t constellation, /* modulation type */
86 fe_transmit_mode_t transmission_mode,
87 fe_guard_interval_t guard_interval,
88 fe_hierarchy_t hierarchy_information
92 struct dvb_ofdm_parameters ofdm; /* DVB-T Parameters */
93 struct dvb_frontend_parameters frontend;
95 ::memset(&frontend, 0, sizeof(struct dvb_frontend_parameters));
96 ::memset(&ofdm, 0, sizeof(struct dvb_ofdm_parameters));
98 ofdm.bandwidth = bandwidth;
99 ofdm.code_rate_HP = code_rate_HP;
100 ofdm.code_rate_LP = code_rate_LP;
101 ofdm.constellation = constellation;
102 ofdm.guard_interval = guard_interval;
103 ofdm.hierarchy_information = hierarchy_information;
105 frontend.frequency = frequency;
106 frontend.inversion = inversion;
107 frontend.u.ofdm = ofdm;
112 prefix_ void senf::DVBFrontendSocketProtocol::tuneDVB_S(unsigned int frequency,
113 fe_spectral_inversion_t inversion,
114 unsigned int symbole_rate, /* symbol rate in Symbols per second */
115 fe_code_rate_t fec_inner /* forward error correction (see above) */
119 struct dvb_qpsk_parameters qpsk; /* DVB-S Parameters*/
120 struct dvb_frontend_parameters frontend;
122 ::memset(&frontend, 0, sizeof(struct dvb_frontend_parameters));
123 ::memset(&qpsk, 0, sizeof(struct dvb_qpsk_parameters));
125 qpsk.symbol_rate = symbole_rate;
126 qpsk.fec_inner = fec_inner;
128 frontend.frequency = frequency;
129 frontend.inversion = inversion;
130 frontend.u.qpsk = qpsk;
135 prefix_ void senf::DVBFrontendSocketProtocol::tuneDVB_C(unsigned int frequency,
136 fe_spectral_inversion_t inversion,
137 unsigned int symbol_rate,
138 fe_code_rate_t fec_inner,
139 fe_modulation_t modulation
143 struct dvb_qam_parameters qam; /* DVB-C Parameters*/
144 struct dvb_frontend_parameters frontend;
146 ::memset(&frontend, 0, sizeof(struct dvb_frontend_parameters));
147 ::memset(&qam, 0, sizeof(struct dvb_qam_parameters));
149 qam.symbol_rate = symbol_rate;
150 qam.fec_inner = fec_inner;
151 qam.modulation = modulation;
154 frontend.frequency = frequency;
155 frontend.inversion = inversion;
156 frontend.u.qam = qam;
160 prefix_ void senf::DVBFrontendSocketProtocol::setNonBlock(bool on)
164 ::fcntl(fd(), F_SETFL, ::fcntl(fd(), F_GETFL) | O_NONBLOCK);
166 ::fcntl(fd(), F_SETFL, ::fcntl(fd(), F_GETFL) & ~O_NONBLOCK);
169 prefix_ dvb_frontend_info senf::DVBFrontendSocketProtocol::getInfo()
172 struct dvb_frontend_info info;
173 ::memset(&info, 0, sizeof(struct dvb_frontend_info));
175 if (::ioctl(fd(), FE_GET_INFO, &info)) {
176 SENF_THROW_SYSTEM_EXCEPTION("Could not read on fildescriptor.");
181 prefix_ dvb_frontend_parameters senf::DVBFrontendSocketProtocol::getFrontendParam() const {
182 struct dvb_frontend_parameters frontend_;
184 ::memset(&frontend_, 0, sizeof(struct dvb_frontend_parameters));
186 if (::ioctl(fd(), FE_GET_FRONTEND, &frontend_)) {
189 SENF_THROW_SYSTEM_EXCEPTION("fd is not a valid open file descriptor.");
192 SENF_THROW_SYSTEM_EXCEPTION( "frontend_ points to invalid address." );
195 SENF_THROW_SYSTEM_EXCEPTION( "Maximum supported symbol rate reached. This call may not be implemented by kernel driver!" );
198 SENF_THROW_SYSTEM_EXCEPTION("Errno: ") << errno;
204 prefix_ dvb_frontend_event senf::DVBFrontendSocketProtocol::getEvent() const{
205 struct dvb_frontend_event ev ;
207 ::memset(&ev, 0, sizeof(struct dvb_frontend_event));
208 std::cerr<<"DVBFrontendSocketProtocol::getEvent\n";
209 if (::ioctl(fd(), FE_GET_EVENT, &ev)) {
212 SENF_THROW_SYSTEM_EXCEPTION("Could not read from frontend device, read-only access to the device is sufficient.");
215 SENF_THROW_SYSTEM_EXCEPTION( "No event pending and device is in nonblocking mode." );
218 // TODO: ignore EINTR. which might be caused by watchdog signals. This is possibly not the solution, but should work
221 SENF_THROW_SYSTEM_EXCEPTION("Errno: ") << errno;
227 prefix_ int16_t senf::DVBFrontendSocketProtocol::signalStrength()
231 if (::ioctl(fd(), FE_READ_SIGNAL_STRENGTH, &strength) < 0)
232 SENF_THROW_SYSTEM_EXCEPTION("Could not get signal strength of DVB adapter.");
236 prefix_ int16_t senf::DVBFrontendSocketProtocol::signalNoiseRatio()
240 if (::ioctl(fd(), FE_READ_SNR, &snr) < 0)
241 SENF_THROW_SYSTEM_EXCEPTION("Could not get signal-to-noise ratio of DVB adapter.");
245 prefix_ uint32_t senf::DVBFrontendSocketProtocol::bitErrorRate()
249 if (::ioctl(fd(), FE_READ_BER, &ber) < 0)
250 SENF_THROW_SYSTEM_EXCEPTION("Could not get bit error rate of DVB adapter.");
254 prefix_ uint32_t senf::DVBFrontendSocketProtocol::uncorrectedBlocks()
257 uint32_t uncorrected_blocks;
258 if (::ioctl(fd(), FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks) < 0)
259 SENF_THROW_SYSTEM_EXCEPTION("Could not get bit error rate of DVB adapter.");
260 return uncorrected_blocks;
264 prefix_ fe_status_t senf::DVBFrontendSocketProtocol::status()
268 if (::ioctl(fd(), FE_READ_STATUS, &status) < 0)
269 SENF_THROW_SYSTEM_EXCEPTION("Could not get bit error rate of DVB adapter.");
274 //-/////////////////////////////////////////////////////////////////////////////////////////////////
276 //#include "DVBFrontendHandle.mpp"
282 // c-file-style: "senf"
283 // indent-tabs-mode: nil
284 // ispell-local-dictionary: "american"
285 // compile-command: "scons -u test"
286 // comment-column: 40