4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Anton Gillert <atx@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef HH_SENF_Socket_Protocols_DVB_DVBSocketController_
25 #define HH_SENF_Socket_Protocols_DVB_DVBSocketController_ 1
29 #include <linux/dvb/frontend.h>
30 #include "DVBFrontendHandle.hh"
31 #include "DVBDemuxHandles.hh"
32 #include "DVBConfigParser.hh"
33 #include "../../../Scheduler/Scheduler.hh"
34 #include "../../../Utils/Console/Console.hh"
36 #define MPE_TABLEID 62
40 /** \brief Helperclass for configuration and controlling DVB devices.
42 The DVB API provides two methods for tuning. The first method is
43 synchronous, which means e.g. "tuneTo_sync" will return when the tuning operation on the card
44 succeed, no matter how long it takes. The second (preferred) method is to tune asynchronous.
45 The call "tuneTo" will return immediately and (if a callback was set) call the callback when
46 the tuning operation succeeds. <br>
48 Note that you may have to take draw backs in using this API. This dues to the implementation
49 of the DVB device driver which you or your kernel choose. It has shown that the completeness
50 of implementations vary from driver to driver. This wrapper provides the full Frontend API which
51 is defined by <a href="http://www.linuxtv.org/docs/dvbapi/DVB_Frontend_API.html">Convergence</a>.
52 You have to find out which parts of these functionality are implemented by your preferred
53 device driver by your own.
55 class DVBSocketController : boost::noncopyable
58 senf::console::ScopedDirectory<DVBSocketController> dir;
60 typedef boost::function<void (const struct dvb_frontend_event & )> Callback;
61 ///< Callback which is called when an asynchronous tuning succeeds.
63 DVBSocketController(DVBFrontendHandle frontendHandle_ = DVBFrontendHandle(0,0), DVBDemuxSectionHandle sectionHandle_ = DVBDemuxSectionHandle(0,0), const Callback & cb = NULL);
64 ~DVBSocketController();
66 void tuneToCMD( const std::string & input, const std::string & mode = "async");
67 ///< Tunes a DVB device given by the type of the DVBFrontendHandle
68 /**< Tunes a DVB device by a channel name or complete
69 configuration line. This method was created for use
71 \param[in] input A channel name or a complete
72 configuration line. If a channel name is given
73 it would be searched in the config file.
74 \param[in] mode The mode in which it will tune
76 void tuneTo(const std::string & channel);
77 ///< Tunes a DVB device to a channel
78 /**< Tunes a DVB device to a channel whose parameters
79 are stored in a config file. The method determines
80 the type of DVB device by it self.
81 \param[in] channel A channel name which will be
82 looked up in config file.*/
84 void tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
85 ///< Tunes a DVB-S device
86 /**< Tunes a DVB-S device in asynchronous mode and calls
87 the callback if existing. Needs full configuration */
89 void tuneDVB_T(unsigned int frequency,
90 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
91 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
92 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
93 fe_modulation_t constellation, /* modulation type (see above) */
94 fe_transmit_mode_t transmission_mode,
95 fe_guard_interval_t guard_interval,
96 fe_hierarchy_t hierarchy_information);
97 ///< Tunes a DVB-T device
98 /**< Tunes a DVB-T device in asynchronous mode and calls
99 the callback if existing. Needs full configuration. */
101 void tuneDVB_C(unsigned int frequency,
102 fe_spectral_inversion_t inversion, unsigned int symbol_rate,
103 fe_code_rate_t fec_inner, fe_modulation_t modulation);
104 ///< Tunes a DVB-C device
105 /**< Tunes a DVB-C device in asynchronous mode and calls
106 the callback if existing. Needs full configuration. */
108 dvb_frontend_event tuneTo_sync( const std::string & channel );
109 ///< Tunes a DVB device given by the type of the DVBFrontendHandle
110 /**< Tunes a DVB device, given by the type of the
111 DVBFrontendHandle, by a channel name in synchronous mode
112 \param[in] channel A channel name which will be looked
114 \returns dvb_frontend_event
115 \note The member "dvb_frontend_event.status" should be
116 correct by the most device driver implementations.
117 But "dvb_frontend_event.parameters" maybe not and is
118 definitly not set by: Cinergy T� (2.6.27),
119 Terratec Cinergy DT USB XS Diversity (2.6.27) */
121 dvb_frontend_event tuneDVB_S_sync(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
122 ///< Tunes a DVB-S device
123 /**< Tunes a DVB-S device in synchronous mode. Needs full configuration
124 \returns dvb_frontend_event
125 \note The member "dvb_frontend_event.status" should be
126 correct by the most device driver implementations.
127 But "dvb_frontend_event.parameters" maybe not and is
128 definitly not set by: Cinergy T� (2.6.27),
129 Terratec Cinergy DT USB XS Diversity (2.6.27) */
131 dvb_frontend_event tuneDVB_T_sync(unsigned int frequency,
132 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
133 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
134 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
135 fe_modulation_t constellation, /* modulation type (see above) */
136 fe_transmit_mode_t transmission_mode,
137 fe_guard_interval_t guard_interval,
138 fe_hierarchy_t hierarsourcechy_information);
139 ///< Tunes a DVB-T device
140 /**< Tunes a DVB-T device in synchronous mode. Needs full
142 \returns dvb_frontend_event
143 \note The member "dvb_frontend_event.status" should be
144 correct by the most device driver implementations.
145 But "dvb_frontend_event.parameters" maybe not and is
146 definitly not set by: Cinergy T� (2.6.27),
147 Terratec Cinergy DT USB XS Diversity (2.6.27) */
149 dvb_frontend_event tuneDVB_C_sync(unsigned int frequency,
150 fe_spectral_inversion_t inversion, unsigned int symbol_rate,
151 fe_code_rate_t fec_inner, fe_modulation_t modulation);
152 ///< Tunes a DVB-C device
153 /**< Tunes a DVB-C device in synchronous mode. Needs full configuration
154 \returns dvb_frontend_event
155 \note The member "dvb_frontend_event.status" should be
156 correct by the most device driver implementations.
157 But "dvb_frontend_event.parameters" maybe not and is
158 definitly not set by: Cinergy T� (2.6.27),
159 Terratec Cinergy DT USB XS Diversity (2.6.27) */
161 fe_type_t getType(); ///< Returns the type of the card. The type is defined in frontend.h
163 std::string getTypeString(); ///< Returns the type of the card.
164 /**< Returns the type of the card but human readable e.g.
165 "DVB-S", "DVB-T" or "DVB-C"*/
167 std::string status2String(fe_status_t status);
168 ///< Returns a human readable status information
169 /**< Returns a human readable version of fe_status_t
170 (defined by frontend.h)*/
172 unsigned int bitErrorRate(); ///< Returns the bit error rate
173 /**< \note This function may not be implemented by your
174 specific driver implementation. In this case the
175 output is random. This is true for:
177 Terratec Cinergy DT USB XS Diversity (2.6.27) */
179 unsigned int signalToNoiseRatio(); ///< Returns the signal to noise ratio
180 /**< \note This function may not be implemented by your
181 specific driver implementation. In this case the
182 output is random. This is true for:
184 Terratec Cinergy DT USB XS Diversity (2.6.27) */
186 unsigned int signalStrength(); ///< Returns the signal strength
187 /**< Returns the signal to noise ratio
188 \note This function may not be implemented by your
189 specific driver implementation. In this case the output is
192 void setSectionFilter(unsigned short int pid,
193 u_int8_t filter = MPE_TABLEID,
194 unsigned int flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC,
195 u_int8_t mask = 0xff,
197 unsigned int timeout = 0);
198 ///< Set the section filter
200 void setBufferSize(unsigned long size);
201 ///< Set the size of the circular buffer used for filtered data.
202 /**< The default size is two maximum sized sections, i.e. if
203 this function is not called a buffer size of 2 * 4096
205 \param[in] size Size of circular buffer. */
207 void startFiltering(); ///< Starts filtering
209 void stopFiltering(); ///< Stops filtering
211 std::string getTuneInfo(const std::string & conf ="Ssbuf");
212 ///< Returns a string which shows actual tuning status
213 /**< <br>"S" prints signal strength (in hex)
214 <br>"s" prints singal to noise ration (in hex)
215 <br>"b" prints bit error rate (in hex)
216 <br>"u" prints uncorrected blocks (in hex)
217 <br>"f" prints readable overal status e.g. "Has Lock"<br>
218 These characters can be used to form the output. Be
219 aware, some features may not be supported be your
220 current driver implementation and could end in throwing
223 DVBFrontendHandle frontendHandle;
224 senf::DVBDemuxSectionHandle sectionHandle;
226 DVBConfigParser parser;
228 senf::scheduler::FdEvent event;
230 void readEvent(int i);