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