its better to set tone and set voltage before closing the frontend fd :)
[enigma2.git] / lib / dvb / sec.h
1 #ifndef __dvb_sec_h
2 #define __dvb_sec_h
3
4 #include <config.h>
5 #include <lib/dvb/idvb.h>
6 #include <list>
7
8 #ifndef SWIG
9 class eSecCommand
10 {
11 public:
12         enum { modeStatic, modeDynamic };
13         enum {
14                 NONE, SLEEP, SET_VOLTAGE, SET_TONE, GOTO,
15                 SEND_DISEQC, SEND_TONEBURST, SET_FRONTEND,
16                 MEASURE_IDLE_INPUTPOWER, MEASURE_RUNNING_INPUTPOWER,
17                 IF_TIMEOUT_GOTO, IF_INPUTPOWER_DELTA_GOTO,
18                 UPDATE_CURRENT_ROTORPARAMS, SET_TIMEOUT,
19                 IF_IDLE_INPUTPOWER_AVAIL_GOTO, SET_POWER_LIMITING_MODE,
20                 IF_VOLTAGE_GOTO
21         };
22         int cmd;
23         struct rotor
24         {
25                 int deltaA;   // difference in mA between running and stopped rotor
26                 int okcount;  // counter
27                 int steps;    // goto steps
28                 int direction;
29         };
30         struct pair
31         {
32                 int voltage;
33                 int steps;
34         };
35         union
36         {
37                 int val;
38                 int steps;
39                 int timeout;
40                 int voltage;
41                 int tone;
42                 int toneburst;
43                 int msec;
44                 int mode;
45                 rotor measure;
46                 eDVBDiseqcCommand diseqc;
47                 pair compare;
48         };
49         eSecCommand( int cmd )
50                 :cmd(cmd)
51         {}
52         eSecCommand( int cmd, int val )
53                 :cmd(cmd), val(val)
54         {}
55         eSecCommand( int cmd, eDVBDiseqcCommand diseqc )
56                 :cmd(cmd), diseqc(diseqc)
57         {}
58         eSecCommand( int cmd, rotor measure )
59                 :cmd(cmd), measure(measure)
60         {}
61         eSecCommand( int cmd, pair compare )
62                 :cmd(cmd), compare(compare)
63         {}
64         eSecCommand()
65                 :cmd(NONE)
66         {}
67 };
68
69 class eSecCommandList
70 {
71         std::list<eSecCommand> secSequence;
72         std::list<eSecCommand>::iterator cur;
73 public:
74         eSecCommandList()
75                 :cur(secSequence.end())
76         {
77         }
78         void push_front(const eSecCommand &cmd)
79         {
80                 secSequence.push_front(cmd);
81         }
82         void push_back(const eSecCommand &cmd)
83         {
84                 secSequence.push_back(cmd);
85         }
86         void clear()
87         {
88                 secSequence.clear();
89                 cur=secSequence.end();
90         }
91         inline std::list<eSecCommand>::iterator &current()
92         {
93                 return cur;
94         }
95         inline std::list<eSecCommand>::iterator begin()
96         {
97                 return secSequence.begin();
98         }
99         inline std::list<eSecCommand>::iterator end()
100         {
101                 return secSequence.end();
102         }
103         int size() const
104         {
105                 return secSequence.size();
106         }
107         operator bool() const
108         {
109                 return secSequence.size();
110         }
111 };
112 #endif
113
114 class eDVBSatelliteDiseqcParameters
115 {
116 #ifdef SWIG
117         eDVBSatelliteDiseqcParameters();
118         ~eDVBSatelliteDiseqcParameters();
119 #endif
120 public:
121         enum { AA=0, AB=1, BA=2, BB=3, SENDNO=4 /* and 0xF0 .. 0xFF*/  };       // DiSEqC Parameter
122         enum t_diseqc_mode { NONE=0, V1_0=1, V1_1=2, V1_2=3, SMATV=4 }; // DiSEqC Mode
123         enum t_toneburst_param { NO=0, A=1, B=2 };
124 #ifndef SWIG
125         __u8 m_committed_cmd;
126         t_diseqc_mode m_diseqc_mode;
127         t_toneburst_param m_toneburst_param;
128
129         __u8 m_repeats; // for cascaded switches
130         bool m_use_fast;        // send no DiSEqC on H/V or Lo/Hi change
131         bool m_seq_repeat;      // send the complete DiSEqC Sequence twice...
132         __u8 m_command_order;
133         /*      diseqc 1.0)
134                         0) commited, toneburst
135                         1) toneburst, committed
136                 diseqc > 1.0)
137                         2) committed, uncommitted, toneburst
138                         3) toneburst, committed, uncommitted
139                         4) uncommitted, committed, toneburst
140                         5) toneburst, uncommitted, committed */
141         __u8 m_uncommitted_cmd; // state of the 4 uncommitted switches..
142 #endif
143 };
144
145 class eDVBSatelliteSwitchParameters
146 {
147 #ifdef SWIG
148         eDVBSatelliteSwitchParameters();
149         ~eDVBSatelliteSwitchParameters();
150 #endif
151 public:
152         enum t_22khz_signal {   HILO=0, ON=1, OFF=2     }; // 22 Khz
153         enum t_voltage_mode     {       HV=0, _14V=1, _18V=2, _0V=3 }; // 14/18 V
154 #ifndef SWIG
155         t_voltage_mode m_voltage_mode;
156         t_22khz_signal m_22khz_signal;
157         __u8 m_rotorPosNum; // 0 is disable.. then use gotoxx
158 #endif
159 };
160
161 class eDVBSatelliteRotorParameters
162 {
163 #ifdef SWIG
164         eDVBSatelliteRotorParameters();
165         ~eDVBSatelliteRotorParameters();
166 #endif
167 public:
168         enum { NORTH, SOUTH, EAST, WEST };
169 #ifndef SWIG
170         eDVBSatelliteRotorParameters() { setDefaultOptions(); }
171
172         struct eDVBSatelliteRotorInputpowerParameters
173         {
174                 bool m_use;     // can we use rotor inputpower to detect rotor running state ?
175                 __u8 m_delta;   // delta between running and stopped rotor
176         };
177         eDVBSatelliteRotorInputpowerParameters m_inputpower_parameters;
178
179         struct eDVBSatelliteRotorGotoxxParameters
180         {
181                 __u8 m_lo_direction;    // EAST, WEST
182                 __u8 m_la_direction;    // NORT, SOUTH
183                 double m_longitude;     // longitude for gotoXX? function
184                 double m_latitude;      // latitude for gotoXX? function
185         };
186         eDVBSatelliteRotorGotoxxParameters m_gotoxx_parameters;
187
188         void setDefaultOptions() // set default rotor options
189         {
190                 m_inputpower_parameters.m_use = true;
191                 m_inputpower_parameters.m_delta = 60;
192                 m_gotoxx_parameters.m_lo_direction = EAST;
193                 m_gotoxx_parameters.m_la_direction = NORTH;
194                 m_gotoxx_parameters.m_longitude = 0.0;
195                 m_gotoxx_parameters.m_latitude = 0.0;
196         }
197 #endif
198 };
199
200 class eDVBSatelliteLNBParameters
201 {
202 #ifdef SWIG
203         eDVBSatelliteLNBParameters();
204         ~eDVBSatelliteLNBParameters();
205 #endif
206 public:
207         enum t_12V_relais_state { OFF=0, ON };
208 #ifndef SWIG
209         t_12V_relais_state m_12V_relais_state;  // 12V relais output on/off
210
211         __u8 tuner_mask; // useable by tuner ( 1 | 2 | 4...)
212
213         unsigned int m_lof_hi,  // for 2 band universal lnb 10600 Mhz (high band offset frequency)
214                                 m_lof_lo,       // for 2 band universal lnb  9750 Mhz (low band offset frequency)
215                                 m_lof_threshold;        // for 2 band universal lnb 11750 Mhz (band switch frequency)
216
217         bool m_increased_voltage; // use increased voltage ( 14/18V )
218
219         std::map<int, eDVBSatelliteSwitchParameters> m_satellites;
220         eDVBSatelliteDiseqcParameters m_diseqc_parameters;
221         eDVBSatelliteRotorParameters m_rotor_parameters;
222 #endif
223 };
224
225 class eDVBRegisteredFrontend;
226
227 class eDVBSatelliteEquipmentControl: public iDVBSatelliteEquipmentControl
228 {
229 #ifndef SWIG
230         static eDVBSatelliteEquipmentControl *instance;
231         eDVBSatelliteLNBParameters m_lnbs[128]; // i think its enough
232         int m_lnbidx; // current index for set parameters
233         std::map<int, eDVBSatelliteSwitchParameters>::iterator m_curSat;
234         eSmartPtrList<eDVBRegisteredFrontend> &m_avail_frontends;
235         bool m_rotorMoving;
236 #endif
237 #ifdef SWIG
238         eDVBSatelliteEquipmentControl();
239         ~eDVBSatelliteEquipmentControl();
240 #endif
241 public:
242 #ifndef SWIG
243         eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBRegisteredFrontend> &avail_frontends);
244         DECLARE_REF(eDVBSatelliteEquipmentControl);
245         RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat, int frontend_id);
246         int canTune(const eDVBFrontendParametersSatellite &feparm, iDVBFrontend *, int frontend_id);
247         bool currentLNBValid() { return m_lnbidx > -1 && m_lnbidx < (int)(sizeof(m_lnbs) / sizeof(eDVBSatelliteLNBParameters)); }
248 #endif
249         static eDVBSatelliteEquipmentControl *getInstance() { return instance; }
250         RESULT clear();
251 /* LNB Specific Parameters */
252         RESULT addLNB();
253         RESULT setLNBTunerMask(int tunermask);
254         RESULT setLNBLOFL(int lofl);
255         RESULT setLNBLOFH(int lofh);
256         RESULT setLNBThreshold(int threshold);
257         RESULT setLNBIncreasedVoltage(bool onoff);
258 /* DiSEqC Specific Parameters */
259         RESULT setDiSEqCMode(int diseqcmode);
260         RESULT setToneburst(int toneburst);
261         RESULT setRepeats(int repeats);
262         RESULT setCommittedCommand(int command);
263         RESULT setUncommittedCommand(int command);
264         RESULT setCommandOrder(int order);
265         RESULT setFastDiSEqC(bool onoff);
266         RESULT setSeqRepeat(bool onoff); // send the complete switch sequence twice (without rotor command)
267 /* Rotor Specific Parameters */
268         RESULT setLongitude(float longitude);
269         RESULT setLatitude(float latitude);
270         RESULT setLoDirection(int direction);
271         RESULT setLaDirection(int direction);
272         RESULT setUseInputpower(bool onoff);
273         RESULT setInputpowerDelta(int delta);  // delta between running and stopped rotor
274 /* Satellite Specific Parameters */
275         RESULT addSatellite(int orbital_position);
276         RESULT setVoltageMode(int mode);
277         RESULT setToneMode(int mode);
278         RESULT setRotorPosNum(int rotor_pos_num);
279 /* Tuner Specific Parameters */
280         RESULT setTunerLinked(int from, int to);
281
282         void setRotorMoving(bool); // called from the frontend's
283         bool isRotorMoving();
284 };
285
286 #endif