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