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