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