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