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