0b06afc609096f7b057dec37f5cd86aa9f170e86
[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 class eSecCommand
9 {
10 public:
11         enum { modeStatic, modeDynamic };
12         enum {
13                 NONE, SLEEP, SET_VOLTAGE, SET_TONE, GOTO,
14                 SEND_DISEQC, SEND_TONEBURST, SET_FRONTEND,
15                 MEASURE_IDLE_INPUTPOWER, MEASURE_RUNNING_INPUTPOWER,
16                 IF_TIMEOUT_GOTO, IF_INPUTPOWER_DELTA_GOTO,
17                 UPDATE_CURRENT_ROTORPARAMS, SET_TIMEOUT,
18                 IF_IDLE_INPUTPOWER_AVAIL_GOTO, SET_POWER_LIMITING_MODE,
19                 IF_VOLTAGE_GOTO
20         };
21         int cmd;
22         struct rotor
23         {
24                 int deltaA;   // difference in mA between running and stopped rotor
25                 int okcount;  // counter
26                 int steps;    // goto steps
27                 int direction;
28         };
29         struct pair
30         {
31                 int voltage;
32                 int steps;
33         };
34         union
35         {
36                 int val;
37                 int steps;
38                 int timeout;
39                 int voltage;
40                 int tone;
41                 int toneburst;
42                 int msec;
43                 int mode;
44                 rotor measure;
45                 eDVBDiseqcCommand diseqc;
46                 pair compare;
47         };
48         eSecCommand( int cmd )
49                 :cmd(cmd)
50         {}
51         eSecCommand( int cmd, int val )
52                 :cmd(cmd), val(val)
53         {}
54         eSecCommand( int cmd, eDVBDiseqcCommand diseqc )
55                 :cmd(cmd), diseqc(diseqc)
56         {}
57         eSecCommand( int cmd, rotor measure )
58                 :cmd(cmd), measure(measure)
59         {}
60         eSecCommand( int cmd, pair compare )
61                 :cmd(cmd), compare(compare)
62         {}
63         eSecCommand()
64                 :cmd(NONE)
65         {}
66 };
67
68 class eSecCommandList
69 {
70         std::list<eSecCommand> secSequence;
71         std::list<eSecCommand>::iterator cur;
72 public:
73         eSecCommandList()
74                 :cur(secSequence.end())
75         {
76         }
77         void push_front(const eSecCommand &cmd)
78         {
79                 secSequence.push_front(cmd);
80         }
81         void push_back(const eSecCommand &cmd)
82         {
83                 secSequence.push_back(cmd);
84         }
85         void clear()
86         {
87                 secSequence.clear();
88                 cur=secSequence.end();
89         }
90         inline std::list<eSecCommand>::iterator &current()
91         {
92                 return cur;
93         }
94         inline std::list<eSecCommand>::iterator begin()
95         {
96                 return secSequence.begin();
97         }
98         inline std::list<eSecCommand>::iterator end()
99         {
100                 return secSequence.end();
101         }
102         int size() const
103         {
104                 return secSequence.size();
105         }
106         operator bool() const
107         {
108                 return secSequence.size();
109         }
110 };
111
112 class eDVBSatelliteDiseqcParameters
113 {
114 public:
115         enum { AA=0, AB=1, BA=2, BB=3, SENDNO=4 /* and 0xF0 .. 0xFF*/  };       // DiSEqC Parameter
116         int m_committed_cmd;
117
118         enum t_diseqc_mode { NONE=0, V1_0=1, V1_1=2, V1_2=3, SMATV=4 }; // DiSEqC Mode
119         t_diseqc_mode m_diseqc_mode;
120
121         enum t_toneburst_param { NO=0, A=1, B=2 };
122         t_toneburst_param m_toneburst_param;
123
124         int m_repeats;  // for cascaded switches
125         bool m_use_fast;        // send no DiSEqC on H/V or Lo/Hi change
126         bool m_seq_repeat;      // send the complete DiSEqC Sequence twice...
127         bool m_swap_cmds;       // swaps the committed & uncommitted cmd
128         int m_uncommitted_cmd;  // state of the 4 uncommitted switches..
129 };
130
131 class eDVBSatelliteSwitchParameters
132 {
133 public:
134         enum t_22khz_signal {   HILO=0, ON=1, OFF=2     }; // 22 Khz
135         enum t_voltage_mode     {       HV=0, _14V=1, _18V=2, _0V=3 }; // 14/18 V
136         t_voltage_mode m_voltage_mode;
137         t_22khz_signal m_22khz_signal;
138 };
139
140 class eDVBSatelliteRotorParameters
141 {
142 public:
143         enum { NORTH, SOUTH, EAST, WEST };
144
145         struct eDVBSatelliteRotorInputpowerParameters
146         {
147                 bool m_use;     // can we use rotor inputpower to detect rotor running state ?
148                 int m_threshold;        // threshold between running and stopped rotor
149         };
150         eDVBSatelliteRotorInputpowerParameters m_inputpower_parameters;
151
152         struct eDVBSatelliteRotorGotoxxParameters
153         {
154                 bool m_can_use; // rotor support gotoXX cmd ?
155                 int m_lo_direction;     // EAST, WEST
156                 int m_la_direction;     // NORT, SOUTH
157                 double m_longitude;     // longitude for gotoXX° function
158                 double m_latitude;      // latitude for gotoXX° function
159         };
160         eDVBSatelliteRotorGotoxxParameters m_gotoxx_parameters;
161
162         struct Orbital_Position_Compare
163         {
164                 inline bool operator()(const int &i1, const int &i2) const
165                 {
166                         return abs(i1-i2) < 6 ? false: i1 < i2;
167                 }
168         };
169         std::map< int, int, Orbital_Position_Compare > m_rotor_position_table;
170         /* mapping orbitalposition <-> number stored in rotor */
171
172         void setDefaultOptions() // set default rotor options
173         {
174                 m_inputpower_parameters.m_use = true;
175                 m_inputpower_parameters.m_threshold = 60;
176                 m_gotoxx_parameters.m_can_use = true;
177                 m_gotoxx_parameters.m_lo_direction = EAST;
178                 m_gotoxx_parameters.m_la_direction = NORTH;
179                 m_gotoxx_parameters.m_longitude = 0.0;
180                 m_gotoxx_parameters.m_latitude = 0.0;
181         }
182 };
183
184 class eDVBSatelliteLNBParameters
185 {
186 public:
187         enum t_12V_relais_state { OFF=0, ON };
188         t_12V_relais_state m_12V_relais_state;  // 12V relais output on/off
189
190         unsigned int m_lof_hi,  // for 2 band universal lnb 10600 Mhz (high band offset frequency)
191                                 m_lof_lo,       // for 2 band universal lnb  9750 Mhz (low band offset frequency)
192                                 m_lof_threshold;        // for 2 band universal lnb 11750 Mhz (band switch frequency)
193
194         bool m_increased_voltage; // use increased voltage ( 14/18V )
195
196         std::map<int, eDVBSatelliteSwitchParameters> m_satellites;
197         eDVBSatelliteDiseqcParameters m_diseqc_parameters;
198         eDVBSatelliteRotorParameters m_rotor_parameters;
199 };
200
201 class eDVBSatelliteEquipmentControl: public iDVBSatelliteEquipmentControl
202 {
203         std::list<eDVBSatelliteLNBParameters> m_lnblist;
204 public:
205         DECLARE_REF(eDVBSatelliteEquipmentControl);
206         eDVBSatelliteEquipmentControl();
207         RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat);
208 };
209
210 #endif