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