Changed API of DVBDemuxSectionHandle !
[senf.git] / Socket / Protocols / DVB / DVBFrontendHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief DVBFrontendHandle public header */
25
26 #ifndef HH_SENF_Socket_Protocols_DVB_DVBFrontendHandle_
27 #define HH_SENF_Socket_Protocols_DVB_DVBFrontendHandle_ 1
28
29 // Custom includes
30 #include <boost/cstdint.hpp>
31 #include <boost/bind.hpp>
32 #include <boost/function.hpp>
33 #include <linux/dvb/frontend.h>
34 #include "../../../Socket/FramingPolicy.hh"
35 #include "../../../Socket/CommunicationPolicy.hh"
36 #include "../../../Socket/ReadWritePolicy.hh"
37 #include "../../../Socket/ProtocolClientSocketHandle.hh"
38 #include "../../../Socket/SocketProtocol.hh"
39 #include <fcntl.h>
40 //#include "DVBFrontendHandle.mpp"
41 ///////////////////////////////hh.p////////////////////////////////////////
42
43 namespace senf {
44
45     /// \addtogroup concrete_protocol_group
46     /// @{
47
48     typedef MakeSocketPolicy<
49         NoAddressingPolicy,
50         DatagramFramingPolicy,
51         UnconnectedCommunicationPolicy,
52         NotReadablePolicy,
53         NotWriteablePolicy
54 >    ::policy DVBFrontend_Policy; ///< Socket Policy for DVBFrontendSocketProtocol
55         
56
57     /** \brief SocketProtocol for the dvb frontend device
58
59         The DVB frontend device controls the tuner and DVB demodulator hardware.
60         ATTENTION!
61         Some calls are not supported by real life drivers, known issues:
62         
63         Cinergy T² getParameter is not supported
64         Cinergy T² in getEvent fe_status_t will be set but dvb_frontend_parameters will be stay untouched
65         Cinergy DT XS bitErrorRate is not supported
66         
67         This dues to the lack of driver implementation. There could be restrictions also for other DVB devices!
68      */
69     
70     class DVBFrontendSocketProtocol
71         : public ConcreteSocketProtocol<DVBFrontend_Policy, DVBFrontendSocketProtocol>
72     {
73     private: 
74         void tune(const struct dvb_frontend_parameters & frontend) const;
75     public:
76         ///////////////////////////////////////////////////////////////////////////
77         // internal interface
78
79         ///\name Constructors
80         ///@{
81         void init_client(unsigned short adapter = 0, unsigned short device = 0, int flags = (O_RDWR | O_NONBLOCK) ) const;
82                                         ///< Opens the specified frontend device in read-only mode.
83                                         /**< \note This member is implicitly called from the
84                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
85                                              constructor */
86
87         ///@}
88         void setNonBlock(bool on = true) const;
89        
90         void tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate) const;
91                                                                         ///< Tunes a DVB-S device
92                                                                         /**< Tunes a DVB-S device. Needs full configuration */
93         void tuneDVB_T(unsigned int frequency, 
94                 fe_spectral_inversion_t inversion,
95                 fe_bandwidth_t bandwidth, 
96                 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
97                 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
98                 fe_modulation_t constellation, /* modulation type (see above) */
99                 fe_transmit_mode_t transmission_mode, 
100                 fe_guard_interval_t guard_interval,
101                 fe_hierarchy_t hierarchy_information
102                 ) const;                                                ///< Tunes a DVB-T device
103                                                                         /**< Tunes a DVB-T device. Needs full configuration */
104         void tuneDVB_C(unsigned int frequency, 
105                 fe_spectral_inversion_t inversion,
106                 unsigned int symbol_rate,
107                 fe_code_rate_t fec_inner,
108                 fe_modulation_t modulation
109                 ) const;        
110                                                                         ///< Tunes a DVB-C device
111                                                                         /**< Tunes a DVB-C device. Needs full configuration */
112         dvb_frontend_info getInfo() const;                              ///< Returns information struct.
113                                                                         /**< Returns information struct, which contains information 
114                                                                              about the device which is associated with the current frontend.*/
115         struct dvb_frontend_parameters getFrontendParam() const;        ///< Returns dvb_frontend_parameters struct.
116                                                                         /**< Returns dvb_frontend_parameters struct, which contains the actual 
117                                                                              configuration of the device.*/
118         ///\name Abstract Interface Implementation
119         ///@{
120         
121         dvb_frontend_event getEvent() const;
122         
123
124         unsigned available() const;     ///< Returns always <tt>0</tt>
125                                         /**< Returns always <tt>0</tt>, since the DVB frontend
126                                              socket is not readable. */
127         bool eof() const;               ///< Returns always <tt>false</tt>
128                                         /**< Returns always <tt>false</tt>, since the DVB frontend
129                                              socket does not support the notion of EOF. */
130
131         ///@}
132
133         int16_t signalStrength() const; ///< Returns current signal strength
134                                         /**< Returns the signal strength value for the signal
135                                              currently received by the front-end. For this method,
136                                              read-only access to the device is sufficient.*/
137
138         int16_t signalNoiseRatio() const;
139                                         ///< Returns current signal-to-noise ratio
140                                         /**< Returns the signal-to-noise ratio for the signal
141                                              currently received by the front-end. For this method,
142                                              read-only access to the device is sufficient. */
143
144         uint32_t bitErrorRate() const;  ///< Returns the current bit error rate for the signal
145                                         /**< Returns the bit error rate for the signal currently
146                                              received/demodulated by the front-end. For this method,
147                                              read-only access to the device is sufficient. */
148         uint32_t uncorrectedBlocks() const; ///< Returns the number of uncorrected blocks 
149                                             /**< Returns the number of uncorrected blocks 
150                                              * detected by the device driver during its lifetime.
151                                              *  For meaningful measurements, the increment in block 
152                                              * count during a specific time interval should be calculated. 
153                                              * For this command, read-only access to the device is sufficient.
154                                              *  Note that the counter will wrap to zero after its maximum count 
155                                              * has been reached.*/
156         
157         fe_status_t status() const;         ///< This ioctl call returns status information about the front-end.
158                                             /**< This ioctl call returns status information about the 
159                                              * front-end. This call only requires read-only access 
160                                              * to the device.*/
161                
162     };
163
164     typedef ProtocolClientSocketHandle<DVBFrontendSocketProtocol> DVBFrontendHandle;
165
166     ///@}
167 }
168
169
170 ///////////////////////////////hh.e////////////////////////////////////////
171 //#include "DVBFrontendHandle.cci"
172 //#include "DVBFrontendHandle.ct"
173 //#include "DVBFrontendHandle.cti"
174 #endif
175
176
177 // Local Variables:
178 // mode: c++
179 // fill-column: 100
180 // c-file-style: "senf"
181 // indent-tabs-mode: nil
182 // ispell-local-dictionary: "american"
183 // compile-command: "scons -u test"
184 // comment-column: 40
185 // End: