4.5.0r6
[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_BLINDSCAN_GOTO,
29                 IF_TUNER_LOCKED_GOTO,
30                 IF_TONE_GOTO, IF_NOT_TONE_GOTO,
31                 START_TUNE_TIMEOUT,
32                 SET_ROTOR_MOVING,
33                 SET_ROTOR_STOPPED,
34                 DELAYED_CLOSE_FRONTEND,
35                 IF_ACQUIRE_SEC_LOCK_GOTO,
36                 CLEAR_SEC_LOCK,
37                 IF_LINKED_IN_USE_GOTO,
38                 UPDATE_OPARM,
39                 SET_TUNER_INPUT
40         };
41         int cmd;
42         struct rotor
43         {
44                 union {
45                         int deltaA;   // difference in mA between running and stopped rotor
46                         int lastSignal;
47                 };
48                 int okcount;  // counter
49                 int steps;    // goto steps
50                 int direction;
51         };
52         struct pair
53         {
54                 union
55                 {
56                         int voltage;
57                         int tone;
58                         int val;
59                 };
60                 int steps;
61         };
62         union
63         {
64                 int val;
65                 int steps;
66                 int timeout;
67                 int voltage;
68                 int tone;
69                 int toneburst;
70                 int msec;
71                 int mode;
72                 rotor measure;
73                 eDVBDiseqcCommand diseqc;
74                 pair compare;
75         };
76         eSecCommand( int cmd )
77                 :cmd(cmd)
78         {}
79         eSecCommand( int cmd, int val )
80                 :cmd(cmd), val(val)
81         {}
82         eSecCommand( int cmd, eDVBDiseqcCommand diseqc )
83                 :cmd(cmd), diseqc(diseqc)
84         {}
85         eSecCommand( int cmd, rotor measure )
86                 :cmd(cmd), measure(measure)
87         {}
88         eSecCommand( int cmd, pair compare )
89                 :cmd(cmd), compare(compare)
90         {}
91         eSecCommand()
92                 :cmd(NONE)
93         {}
94 };
95
96 class eSecCommandList
97 {
98         typedef std::list<eSecCommand> List;
99         List secSequence;
100 public:
101         typedef List::iterator iterator;
102 private:
103         iterator cur;
104 public:
105         eSecCommandList()
106                 :cur(secSequence.end())
107         {
108         }
109         void push_front(const eSecCommand &cmd)
110         {
111                 secSequence.push_front(cmd);
112         }
113         void push_back(const eSecCommand &cmd)
114         {
115                 secSequence.push_back(cmd);
116         }
117         void push_back(eSecCommandList &list)
118         {
119                 secSequence.insert(end(), list.begin(), list.end());
120         }
121         void clear()
122         {
123                 secSequence.clear();
124                 cur=secSequence.end();
125         }
126         inline iterator &current()
127         {
128                 return cur;
129         }
130         inline iterator begin()
131         {
132                 return secSequence.begin();
133         }
134         inline iterator end()
135         {
136                 return secSequence.end();
137         }
138         int size() const
139         {
140                 return secSequence.size();
141         }
142         operator bool() const
143         {
144                 return secSequence.size();
145         }
146         eSecCommandList &operator=(const eSecCommandList &lst)
147         {
148                 secSequence = lst.secSequence;
149                 cur = begin();
150                 return *this;
151         }
152 };
153 #endif
154
155 class eDVBSatelliteDiseqcParameters
156 {
157 #ifdef SWIG
158         eDVBSatelliteDiseqcParameters();
159         ~eDVBSatelliteDiseqcParameters();
160 #endif
161 public:
162         enum { AA=0, AB=1, BA=2, BB=3, SENDNO=4 /* and 0xF0 .. 0xFF*/  };       // DiSEqC Parameter
163         enum t_diseqc_mode { NONE=0, V1_0=1, V1_1=2, V1_2=3, SMATV=4 }; // DiSEqC Mode
164         enum t_toneburst_param { NO=0, A=1, B=2 };
165 #ifndef SWIG
166         __u8 m_committed_cmd;
167         t_diseqc_mode m_diseqc_mode;
168         t_toneburst_param m_toneburst_param;
169
170         __u8 m_repeats; // for cascaded switches
171         bool m_use_fast;        // send no DiSEqC on H/V or Lo/Hi change
172         bool m_seq_repeat;      // send the complete DiSEqC Sequence twice...
173         __u8 m_command_order;
174         /*      diseqc 1.0)
175                         0) commited, toneburst
176                         1) toneburst, committed
177                 diseqc > 1.0)
178                         2) committed, uncommitted, toneburst
179                         3) toneburst, committed, uncommitted
180                         4) uncommitted, committed, toneburst
181                         5) toneburst, uncommitted, committed */
182         __u8 m_uncommitted_cmd; // state of the 4 uncommitted switches..
183 #endif
184 };
185
186 class eDVBSatelliteSwitchParameters
187 {
188 #ifdef SWIG
189         eDVBSatelliteSwitchParameters();
190         ~eDVBSatelliteSwitchParameters();
191 #endif
192 public:
193         enum t_22khz_signal {   HILO=0, ON=1, OFF=2     }; // 22 Khz
194         enum t_voltage_mode     {       HV=0, _14V=1, _18V=2, _0V=3, HV_13=4 }; // 14/18 V
195 #ifndef SWIG
196         t_voltage_mode m_voltage_mode;
197         t_22khz_signal m_22khz_signal;
198         __u8 m_rotorPosNum; // 0 is disable.. then use gotoxx
199 #endif
200 };
201
202 class eDVBSatelliteRotorParameters
203 {
204 #ifdef SWIG
205         eDVBSatelliteRotorParameters();
206         ~eDVBSatelliteRotorParameters();
207 #endif
208 public:
209         enum { NORTH, SOUTH, EAST, WEST };
210         enum { FAST, SLOW };
211 #ifndef SWIG
212         eDVBSatelliteRotorParameters() { setDefaultOptions(); }
213
214         struct eDVBSatelliteRotorInputpowerParameters
215         {
216                 bool m_use;     // can we use rotor inputpower to detect rotor running state ?
217                 __u8 m_delta;   // delta between running and stopped rotor
218                 unsigned int m_turning_speed; // SLOW, FAST, or fast turning epoch
219         };
220         eDVBSatelliteRotorInputpowerParameters m_inputpower_parameters;
221
222         unsigned int m_degree_per_second;
223
224         struct eDVBSatelliteRotorGotoxxParameters
225         {
226                 __u8 m_lo_direction;    // EAST, WEST
227                 __u8 m_la_direction;    // NORT, SOUTH
228                 double m_longitude;     // longitude for gotoXX? function
229                 double m_latitude;      // latitude for gotoXX? function
230         };
231         eDVBSatelliteRotorGotoxxParameters m_gotoxx_parameters;
232
233         void setDefaultOptions() // set default rotor options
234         {
235                 m_inputpower_parameters.m_turning_speed = FAST; // fast turning
236                 m_inputpower_parameters.m_use = true;
237                 m_inputpower_parameters.m_delta = 60;
238                 m_degree_per_second = 5; // 0.5 degree per second for 13V ... + 25% for 18V
239                 m_gotoxx_parameters.m_lo_direction = EAST;
240                 m_gotoxx_parameters.m_la_direction = NORTH;
241                 m_gotoxx_parameters.m_longitude = 0.0;
242                 m_gotoxx_parameters.m_latitude = 0.0;
243         }
244 #endif
245 };
246
247 #ifndef SWIG
248 struct eDVBSatelliteLNBParameters
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
264 #define guard_offset_min -8000
265 #define guard_offset_max 8000
266 #define guard_offset_step 8000
267 #define MAX_SATCR 32
268 #define MAX_LNBNUM 32
269
270         int SatCR_positions;
271         int SatCR_idx;
272         int SatCR_mode;
273         int SatCR_pin;
274         unsigned int SatCRvco;
275         int PowerOnDelay; // some Unicable LNBs need long time to powerup after voltage enable...
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         int TunerInput; /* -1 when unused */
285 };
286 #endif
287
288 class eDVBRegisteredFrontend;
289
290 class eDVBSatelliteEquipmentControl: public iDVBSatelliteEquipmentControl
291 {
292         DECLARE_REF(eDVBSatelliteEquipmentControl);
293 public:
294         enum {
295                 DELAY_AFTER_CONT_TONE_DISABLE_BEFORE_DISEQC=0,  // delay after continuous tone disable before diseqc command
296                 DELAY_AFTER_FINAL_CONT_TONE_CHANGE, // delay after continuous tone change before tune
297                 DELAY_AFTER_FINAL_VOLTAGE_CHANGE, // delay after voltage change at end of complete sequence
298                 DELAY_BETWEEN_DISEQC_REPEATS, // delay between repeated diseqc commands
299                 DELAY_AFTER_LAST_DISEQC_CMD, // delay after last diseqc command
300                 DELAY_AFTER_TONEBURST, // delay after toneburst
301                 DELAY_AFTER_ENABLE_VOLTAGE_BEFORE_SWITCH_CMDS, // delay after enable voltage before transmit toneburst/diseqc
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[512]; // at the moment we have max 2 FBC Tuners.. a 8 channels... max 32 LNB per channel
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_unused; // was m_not_linked_slot_mask
326 #endif
327 #ifdef SWIG
328         eDVBSatelliteEquipmentControl();
329         ~eDVBSatelliteEquipmentControl();
330 #endif
331         static int m_params[MAX_PARAMS];
332 public:
333 #ifndef SWIG
334         eDVBSatelliteEquipmentControl(eSmartPtrList<eDVBRegisteredFrontend> &avail_frontends, eSmartPtrList<eDVBRegisteredFrontend> &avail_simulate_frontends);
335         RESULT prepare(iDVBFrontend &frontend, dvb_frontend_parameters &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id, unsigned int tunetimeout);
336         void prepareClose(iDVBFrontend &frontend, bool typeChanged=false);
337         int canTune(const eDVBFrontendParametersSatellite &feparm, iDVBFrontend *, int frontend_id, int *highest_score_lnb=0);
338         bool currentLNBValid() { return m_lnbidx > -1 && (size_t)m_lnbidx < ARRAY_SIZE(m_lnbs); }
339 #endif
340         static eDVBSatelliteEquipmentControl *getInstance() { return instance; }
341         static void setParam(int param, int value);
342         RESULT clear();
343 /* LNB Specific Parameters */
344         RESULT addLNB();
345         RESULT setLNBSlotMask(int slotmask);
346         RESULT setLNBLOFL(int lofl);
347         RESULT setLNBLOFH(int lofh);
348         RESULT setLNBThreshold(int threshold);
349         RESULT setLNBIncreasedVoltage(bool onoff);
350         RESULT setLNBPrio(int prio);
351         RESULT setLNBNum(int LNBNum);
352         RESULT setLNBTunerInput(int index);
353         RESULT getLNBTunerInput();
354 /* DiSEqC Specific Parameters */
355         RESULT setDiSEqCMode(int diseqcmode);
356         RESULT setToneburst(int toneburst);
357         RESULT setRepeats(int repeats);
358         RESULT setCommittedCommand(int command);
359         RESULT setUncommittedCommand(int command);
360         RESULT setCommandOrder(int order);
361         RESULT setFastDiSEqC(bool onoff);
362         RESULT setSeqRepeat(bool onoff); // send the complete switch sequence twice (without rotor command)
363 /* Rotor Specific Parameters */
364         RESULT setLongitude(float longitude);
365         RESULT setLatitude(float latitude);
366         RESULT setLoDirection(int direction);
367         RESULT setLaDirection(int direction);
368         RESULT setUseInputpower(bool onoff);
369         RESULT setInputpowerDelta(int delta);  // delta between running and stopped rotor
370         RESULT setRotorTurningSpeed(int speed);  // set turning speed..
371         RESULT setDegreePerSecond(int degree); // set motor speed in tenth of degree per second ... used only when inputpower is not used
372 /* Unicable Specific Parameters */
373         RESULT setLNBSatCR(int SatCR_idx);
374         RESULT setLNBSatCRvco(int SatCRvco);
375         RESULT setLNBSatCRpin(int SatCRpin);
376         RESULT setLNBSatCRpositions(int SatCR_positions);
377         RESULT setLNBSatCRmode(int mode);
378         RESULT getLNBSatCR();
379         RESULT getLNBSatCRvco();
380         RESULT getLNBSatCRpin();
381         RESULT getLNBSatCRpositions();
382         RESULT getLNBSatCRmode();
383         RESULT setLNBPowerOnDelay(int ms);
384 /* Satellite Specific Parameters */
385         RESULT addSatellite(int orbital_position);
386         RESULT setVoltageMode(int mode);
387         RESULT setToneMode(int mode);
388         RESULT setRotorPosNum(int rotor_pos_num);
389         RESULT setTunerLinked(int from, int to, int which=3); // bitmask of 1 = normal, 2 = simulate
390         RESULT setTunerDepends(int from, int to);
391         void setSlotNotLinked(int tuner_no); // not used anymore... is a NOP
392
393         intPairList getFrequencyRangeList(int slot_no, int orb_pos);
394         intList getBandCutOffFrequency(int slot_no, int orb_pos);
395         void setRotorMoving(int, bool); // called from the frontend's
396         bool isRotorMoving();
397 };
398
399 #endif