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