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