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