Support turbo2.
[vuplus_dvbapp] / 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 #include <lib/dvb/fbc.h>
8
9 #ifndef SWIG
10 class eSecCommand
11 {
12 public:
13         enum { modeStatic, modeDynamic };
14         enum {
15                 NONE, SLEEP, SET_VOLTAGE, SET_TONE, GOTO,
16                 SEND_DISEQC, SEND_TONEBURST, SET_FRONTEND,
17                 SET_TIMEOUT, IF_TIMEOUT_GOTO, 
18                 IF_VOLTAGE_GOTO, IF_NOT_VOLTAGE_GOTO,
19                 SET_POWER_LIMITING_MODE,
20                 SET_ROTOR_DISEQC_RETRYS, IF_NO_MORE_ROTOR_DISEQC_RETRYS_GOTO,
21                 MEASURE_IDLE_INPUTPOWER, MEASURE_RUNNING_INPUTPOWER,
22                 IF_MEASURE_IDLE_WAS_NOT_OK_GOTO, IF_INPUTPOWER_DELTA_GOTO,
23                 UPDATE_CURRENT_ROTORPARAMS, INVALIDATE_CURRENT_ROTORPARMS,
24                 UPDATE_CURRENT_SWITCHPARMS, INVALIDATE_CURRENT_SWITCHPARMS,
25                 IF_ROTORPOS_VALID_GOTO,
26                 IF_TUNER_LOCKED_GOTO,
27                 IF_TONE_GOTO, IF_NOT_TONE_GOTO,
28                 START_TUNE_TIMEOUT,
29                 SET_ROTOR_MOVING,
30                 SET_ROTOR_STOPPED,
31                 DELAYED_CLOSE_FRONTEND
32         };
33         int cmd;
34         struct rotor
35         {
36                 union {
37                         int deltaA;   // difference in mA between running and stopped rotor
38                         int lastSignal;
39                 };
40                 int okcount;  // counter
41                 int steps;    // goto steps
42                 int direction;
43         };
44         struct pair
45         {
46                 union
47                 {
48                         int voltage;
49                         int tone;
50                         int val;
51                 };
52                 int steps;
53         };
54         union
55         {
56                 int val;
57                 int steps;
58                 int timeout;
59                 int voltage;
60                 int tone;
61                 int toneburst;
62                 int msec;
63                 int mode;
64                 rotor measure;
65                 eDVBDiseqcCommand diseqc;
66                 pair compare;
67         };
68         eSecCommand( int cmd )
69                 :cmd(cmd)
70         {}
71         eSecCommand( int cmd, int val )
72                 :cmd(cmd), val(val)
73         {}
74         eSecCommand( int cmd, eDVBDiseqcCommand diseqc )
75                 :cmd(cmd), diseqc(diseqc)
76         {}
77         eSecCommand( int cmd, rotor measure )
78                 :cmd(cmd), measure(measure)
79         {}
80         eSecCommand( int cmd, pair compare )
81                 :cmd(cmd), compare(compare)
82         {}
83         eSecCommand()
84                 :cmd(NONE)
85         {}
86 };
87
88 class eSecCommandList
89 {
90         typedef std::list<eSecCommand> List;
91         List secSequence;
92 public:
93         typedef List::iterator iterator;
94 private:
95         iterator cur;
96 public:
97         eSecCommandList()
98                 :cur(secSequence.end())
99         {
100         }
101         void push_front(const eSecCommand &cmd)
102         {
103                 secSequence.push_front(cmd);
104         }
105         void push_back(const eSecCommand &cmd)
106         {
107                 secSequence.push_back(cmd);
108         }
109         void push_back(eSecCommandList &list)
110         {
111                 secSequence.insert(end(), list.begin(), list.end());
112         }
113         void clear()
114         {
115                 secSequence.clear();
116                 cur=secSequence.end();
117         }
118         inline iterator &current()
119         {
120                 return cur;
121         }
122         inline iterator begin()
123         {
124                 return secSequence.begin();
125         }
126         inline iterator end()
127         {
128                 return secSequence.end();
129         }
130         int size() const
131         {
132                 return secSequence.size();
133         }
134         operator bool() const
135         {
136                 return secSequence.size();
137         }
138         eSecCommandList &operator=(const eSecCommandList &lst)
139         {
140                 secSequence = lst.secSequence;
141                 cur = begin();
142                 return *this;
143         }
144 };
145 #endif
146
147 class eDVBSatelliteDiseqcParameters
148 {
149 #ifdef SWIG
150         eDVBSatelliteDiseqcParameters();
151         ~eDVBSatelliteDiseqcParameters();
152 #endif
153 public:
154         enum { AA=0, AB=1, BA=2, BB=3, SENDNO=4 /* and 0xF0 .. 0xFF*/  };       // DiSEqC Parameter
155         enum t_diseqc_mode { NONE=0, V1_0=1, V1_1=2, V1_2=3, SMATV=4 }; // DiSEqC Mode
156         enum t_toneburst_param { NO=0, A=1, B=2 };
157 #ifndef SWIG
158         __u8 m_committed_cmd;
159         t_diseqc_mode m_diseqc_mode;
160         t_toneburst_param m_toneburst_param;
161
162         __u8 m_repeats; // for cascaded switches
163         bool m_use_fast;        // send no DiSEqC on H/V or Lo/Hi change
164         bool m_seq_repeat;      // send the complete DiSEqC Sequence twice...
165         __u8 m_command_order;
166         /*      diseqc 1.0)
167                         0) commited, toneburst
168                         1) toneburst, committed
169                 diseqc > 1.0)
170                         2) committed, uncommitted, toneburst
171                         3) toneburst, committed, uncommitted
172                         4) uncommitted, committed, toneburst
173                         5) toneburst, uncommitted, committed */
174         __u8 m_uncommitted_cmd; // state of the 4 uncommitted switches..
175 #endif
176 };
177
178 class eDVBSatelliteSwitchParameters
179 {
180 #ifdef SWIG
181         eDVBSatelliteSwitchParameters();
182         ~eDVBSatelliteSwitchParameters();
183 #endif
184 public:
185         enum t_22khz_signal {   HILO=0, ON=1, OFF=2     }; // 22 Khz
186         enum t_voltage_mode     {       HV=0, _14V=1, _18V=2, _0V=3, HV_13=4 }; // 14/18 V
187 #ifndef SWIG
188         t_voltage_mode m_voltage_mode;
189         t_22khz_signal m_22khz_signal;
190         __u8 m_rotorPosNum; // 0 is disable.. then use gotoxx
191 #endif
192 };
193
194 class eDVBSatelliteRotorParameters
195 {
196 #ifdef SWIG
197         eDVBSatelliteRotorParameters();
198         ~eDVBSatelliteRotorParameters();
199 #endif
200 public:
201         enum { NORTH, SOUTH, EAST, WEST };
202         enum { FAST, SLOW };
203 #ifndef SWIG
204         eDVBSatelliteRotorParameters() { setDefaultOptions(); }
205
206         struct eDVBSatelliteRotorInputpowerParameters
207         {
208                 bool m_use;     // can we use rotor inputpower to detect rotor running state ?
209                 __u8 m_delta;   // delta between running and stopped rotor
210                 unsigned int m_turning_speed; // SLOW, FAST, or fast turning epoch
211         };
212         eDVBSatelliteRotorInputpowerParameters m_inputpower_parameters;
213
214         struct eDVBSatelliteRotorGotoxxParameters
215         {
216                 __u8 m_lo_direction;    // EAST, WEST
217                 __u8 m_la_direction;    // NORT, SOUTH
218                 double m_longitude;     // longitude for gotoXX? function
219                 double m_latitude;      // latitude for gotoXX? function
220         };
221         eDVBSatelliteRotorGotoxxParameters m_gotoxx_parameters;
222
223         void setDefaultOptions() // set default rotor options
224         {
225                 m_inputpower_parameters.m_turning_speed = FAST; // fast turning
226                 m_inputpower_parameters.m_use = true;
227                 m_inputpower_parameters.m_delta = 60;
228                 m_gotoxx_parameters.m_lo_direction = EAST;
229                 m_gotoxx_parameters.m_la_direction = NORTH;
230                 m_gotoxx_parameters.m_longitude = 0.0;
231                 m_gotoxx_parameters.m_latitude = 0.0;
232         }
233 #endif
234 };
235
236 class eDVBSatelliteLNBParameters
237 {
238 #ifdef SWIG
239         eDVBSatelliteLNBParameters();
240         ~eDVBSatelliteLNBParameters();
241 #endif
242 public:
243         enum t_12V_relais_state { OFF=0, ON };
244 #ifndef SWIG
245         t_12V_relais_state m_12V_relais_state;  // 12V relais output on/off
246
247         int m_slot_mask; // useable by slot ( 1 | 2 | 4...)
248
249         unsigned int m_lof_hi,  // for 2 band universal lnb 10600 Mhz (high band offset frequency)
250                                 m_lof_lo,       // for 2 band universal lnb  9750 Mhz (low band offset frequency)
251                                 m_lof_threshold;        // for 2 band universal lnb 11750 Mhz (band switch frequency)
252
253         bool m_increased_voltage; // use increased voltage ( 14/18V )
254
255         std::map<int, eDVBSatelliteSwitchParameters> m_satellites;
256         eDVBSatelliteDiseqcParameters m_diseqc_parameters;
257         eDVBSatelliteRotorParameters m_rotor_parameters;
258
259         int m_prio; // to override automatic tuner management ... -1 is Auto
260 #endif
261 public:
262 #define guard_offset_min -8000
263 #define guard_offset_max 8000
264 #define guard_offset_step 8000
265 #define MAX_SATCR 32
266 #define MAX_LNBNUM 64
267
268         int SatCR_positions;
269         int SatCR_idx;
270         int SatCR_format;
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 prepareTurnOffSatCR(iDVBFrontend &frontend); // used for unicable
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 setLNBSatCRformat(int SatCR_format);     //DiSEqc or JESS (or ...)
364         RESULT setLNBSatCR(int SatCR_idx);
365         RESULT setLNBSatCRvco(int SatCRvco);
366         RESULT setLNBSatCRpositions(int SatCR_positions);
367         RESULT getLNBSatCRformat();     //DiSEqc or JESS (or ...)
368         RESULT getLNBSatCR();
369         RESULT getLNBSatCRvco();
370         RESULT getLNBSatCRpositions();
371 /* Satellite Specific Parameters */
372         RESULT addSatellite(int orbital_position);
373         RESULT setVoltageMode(int mode);
374         RESULT setToneMode(int mode);
375         RESULT setRotorPosNum(int rotor_pos_num);
376 /* Tuner Specific Parameters */
377         RESULT setTunerLinked(int from, int to);
378         RESULT setTunerDepends(int from, int to);
379         void setSlotNotLinked(int tuner_no);
380
381         void setRotorMoving(int, bool); // called from the frontend's
382         bool isRotorMoving();
383         bool canMeasureInputPower() { return m_canMeasureInputPower; }
384
385         friend class eFBCTunerManager;
386 };
387
388 #endif