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 "DVBProtocolWrapper.hh"
34 #include <senf/Scheduler/Scheduler.hh>
35 #include <senf/Utils/Console/Console.hh>
37 #define MPE_TABLEID 62
41 /** \brief Helperclass for configuration and controlling DVB devices.
43 The DVB API provides two methods for tuning. The first method is
44 synchronous, which means e.g. "tuneTo_sync" will return when the tuning operation on the card
45 succeed, no matter how long it takes. The second (preferred) method is to tune asynchronous.
46 The call "tuneTo" will return immediately and (if a callback was set) call the callback when
47 the tuning operation succeeds. <br>
49 Note that you may have to take draw backs in using this API. This dues to the implementation
50 of the DVB device driver which you or your kernel choose. It has shown that the completeness
51 of implementations vary from driver to driver. This wrapper provides the full Frontend API which
52 is defined by <a href="http://www.linuxtv.org/docs/dvbapi/DVB_Frontend_API.html">Convergence</a>.
53 You have to find out which parts of these functionality are implemented by your preferred
54 device driver by your own.
59 class DVBSocketController : boost::noncopyable
63 senf::console::ScopedDirectory<DVBSocketController> dir;
65 typedef boost::function<void (const struct dvb_frontend_event & )> Callback;
66 ///< Callback which is called when an asynchronous tuning succeeds.
68 DVBSocketController(DVBFrontendHandle frontendHandle_ = DVBFrontendHandle(0,0), const Callback & cb = NULL);
69 ~DVBSocketController();
71 senf::DVBDemuxSectionHandle createDVBDemuxSectionHandle( int adapternumber=0, int demuxnumber=0, bool addToConsole=false );
72 senf::DVBDemuxPESHandle createDVBDemuxPESHandle( int adapternumber=0, int demuxnumber=0, bool addToConsole=false );
74 void addToConsole(senf::DVBDemuxSectionHandle sh);
75 ///< Adds an DVBDemuxSectionHandle to the console
76 /**< Allocates the functionality of DVBDemuxSectionProtocol into the folder
77 of the DVBSocketController. If the protocol is closed, or all handles are
78 discarded the console support will automatically removed.
79 \param[in] handle of a protocol*/
80 void addToConsole(senf::DVBDemuxPESHandle sh);
81 ///< Adds an DVBDemuxPESHandle to the console
82 /**< Allocates the functionality of DVBDemuxPESProtocol into the folder
83 of the DVBSocketController. If the protocol is closed, or all handles are
84 discarded the console support will automatically removed.
85 \param[in] handle of a protocol*/
87 void tuneToCMD( const std::string & input, const std::string & mode = "async");
88 ///< Tunes a DVB device given by the type of the DVBFrontendHandle
89 /**< Tunes a DVB device by a channel name or complete
90 configuration line. This method was created for use
92 \param[in] input A channel name or a complete
93 configuration line. If a channel name is given
94 it would be searched in the config file.
95 \param[in] mode The mode in which it will tune
97 void tuneTo(const std::string & channel);
98 ///< Tunes a DVB device to a channel
99 /**< Tunes a DVB device to a channel whose parameters
100 are stored in a config file. The method determines
101 the type of DVB device by it self.
102 \param[in] channel A channel name which will be
103 looked up in config file.*/
105 void tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
106 ///< Tunes a DVB-S device
107 /**< Tunes a DVB-S device in asynchronous mode and calls
108 the callback if existing. Needs full configuration */
110 void tuneDVB_T(unsigned int frequency,
111 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
112 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
113 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
114 fe_modulation_t constellation, /* modulation type (see above) */
115 fe_transmit_mode_t transmission_mode,
116 fe_guard_interval_t guard_interval,
117 fe_hierarchy_t hierarchy_information);
118 ///< Tunes a DVB-T device
119 /**< Tunes a DVB-T device in asynchronous mode and calls
120 the callback if existing. Needs full configuration. */
122 void tuneDVB_C(unsigned int frequency,
123 fe_spectral_inversion_t inversion, unsigned int symbol_rate,
124 fe_code_rate_t fec_inner, fe_modulation_t modulation);
125 ///< Tunes a DVB-C device
126 /**< Tunes a DVB-C device in asynchronous mode and calls
127 the callback if existing. Needs full configuration. */
129 dvb_frontend_event tuneTo_sync( const std::string & channel );
130 ///< Tunes a DVB device given by the type of the DVBFrontendHandle
131 /**< Tunes a DVB device, given by the type of the
132 DVBFrontendHandle, by a channel name in synchronous mode
133 \param[in] channel A channel name which will be looked
135 \returns dvb_frontend_event
136 \note The member "dvb_frontend_event.status" should be
137 correct by the most device driver implementations.
138 But "dvb_frontend_event.parameters" maybe not and is
139 definitly not set by: Cinergy T� (2.6.27),
140 Terratec Cinergy DT USB XS Diversity (2.6.27) */
142 dvb_frontend_event tuneDVB_S_sync(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
143 ///< Tunes a DVB-S device
144 /**< Tunes a DVB-S device in synchronous mode. Needs full configuration
145 \returns dvb_frontend_event
146 \note The member "dvb_frontend_event.status" should be
147 correct by the most device driver implementations.
148 But "dvb_frontend_event.parameters" maybe not and is
149 definitly not set by: Cinergy T� (2.6.27),
150 Terratec Cinergy DT USB XS Diversity (2.6.27) */
152 dvb_frontend_event tuneDVB_T_sync(unsigned int frequency,
153 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
154 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
155 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
156 fe_modulation_t constellation, /* modulation type (see above) */
157 fe_transmit_mode_t transmission_mode,
158 fe_guard_interval_t guard_interval,
159 fe_hierarchy_t hierarsourcechy_information);
160 ///< Tunes a DVB-T device
161 /**< Tunes a DVB-T device in synchronous mode. Needs full
163 \returns dvb_frontend_event
164 \note The member "dvb_frontend_event.status" should be
165 correct by the most device driver implementations.
166 But "dvb_frontend_event.parameters" maybe not and is
167 definitly not set by: Cinergy T� (2.6.27),
168 Terratec Cinergy DT USB XS Diversity (2.6.27) */
170 dvb_frontend_event tuneDVB_C_sync(unsigned int frequency,
171 fe_spectral_inversion_t inversion, unsigned int symbol_rate,
172 fe_code_rate_t fec_inner, fe_modulation_t modulation);
173 ///< Tunes a DVB-C device
174 /**< Tunes a DVB-C device in synchronous mode. Needs full configuration
175 \returns dvb_frontend_event
176 \note The member "dvb_frontend_event.status" should be
177 correct by the most device driver implementations.
178 But "dvb_frontend_event.parameters" maybe not and is
179 definitly not set by: Cinergy T� (2.6.27),
180 Terratec Cinergy DT USB XS Diversity (2.6.27) */
182 fe_type_t getType(); ///< Returns the type of the card. The type is defined in frontend.h
184 std::string getTypeString(); ///< Returns the type of the card.
185 /**< Returns the type of the card but human readable e.g.
186 "DVB-S", "DVB-T" or "DVB-C"*/
188 std::string status2String(fe_status_t status);
189 ///< Returns a human readable status information
190 /**< Returns a human readable version of fe_status_t
191 (defined by frontend.h)*/
193 unsigned int bitErrorRate(); ///< Returns the bit error rate
194 /**< \note This function may not be implemented by your
195 specific driver implementation. In this case the
196 output is random. This is true for:
198 Terratec Cinergy DT USB XS Diversity (2.6.27) */
200 unsigned int signalToNoiseRatio(); ///< Returns the signal to noise ratio
201 /**< \note This function may not be implemented by your
202 specific driver implementation. In this case the
203 output is random. This is true for:
205 Terratec Cinergy DT USB XS Diversity (2.6.27) */
207 unsigned int signalStrength(); ///< Returns the signal strength
208 /**< Returns the signal to noise ratio
209 \note This function may not be implemented by your
210 specific driver implementation. In this case the output is
213 std::string getTuneInfo(const std::string & conf ="Ssbuf");
214 ///< Returns a string which shows actual tuning status
215 /**< <br>"S" prints signal strength (in hex)
216 <br>"s" prints singal to noise ration (in hex)
217 <br>"b" prints bit error rate (in hex)
218 <br>"u" prints uncorrected blocks (in hex)
219 <br>"f" prints readable overal status e.g. "Has Lock"<br>
220 These characters can be used to form the output. Be
221 aware, some features may not be supported be your
222 current driver implementation and could end in throwing
225 DVBFrontendHandle frontendHandle;
227 DVBConfigParser parser;
229 static unsigned int controllerNr;
230 unsigned int sectionNr;
232 senf::scheduler::FdEvent event;
233 void readEvent(int i);