nicer code (api v3 / oldapi)
[enigma2.git] / lib / dvb / sec.cpp
1 #include <config.h>
2 #include <lib/dvb/sec.h>
3 #if HAVE_DVB_API_VERSION < 3
4 #include <ost/frontend.h>
5 #define INVERSION Inversion
6 #define FREQUENCY Frequency
7 #define FEC_INNER FEC_inner
8 #define SYMBOLRATE SymbolRate
9 #else
10 #include <linux/dvb/frontend.h>
11 #define INVERSION inversion
12 #define FREQUENCY frequency
13 #define FEC_INNER fec_inner
14 #define SYMBOLRATE symbol_rate
15 #endif
16 #include <lib/base/eerror.h>
17
18 DEFINE_REF(eDVBSatelliteEquipmentControl);
19
20 eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl()
21 {
22 }
23
24 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat)
25 {
26         int hi;
27         eDebug("(very) ugly and hardcoded eDVBSatelliteEquipmentControl");
28         
29         if (sat.frequency > 11700000)
30                 hi = 1;
31         else
32                 hi = 0;
33         
34         if (hi)
35                 parm.FREQUENCY = sat.frequency - 10600000;
36         else
37                 parm.FREQUENCY = sat.frequency -  9750000;
38         
39 //      frontend.sentDiseqc(...);
40
41         parm.INVERSION = (!sat.inversion) ? INVERSION_ON : INVERSION_OFF;
42
43         switch (sat.fec)
44         {
45 //              case 1:
46 //              case ...:
47         default:
48                 parm.u.qpsk.FEC_INNER = FEC_AUTO;
49                 break;
50         }
51         parm.u.qpsk.SYMBOLRATE = sat.symbol_rate;
52
53         frontend.setVoltage((sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Vertical) ? iDVBFrontend::voltage13 : iDVBFrontend::voltage18);
54
55         eDVBDiseqcCommand diseqc;
56         
57         diseqc.len = 4;
58         diseqc.data[0] = 0xe0;
59         diseqc.data[1] = 0x10;
60         diseqc.data[2] = 0x38;
61         diseqc.data[3] = 0xF0;
62         
63         if (hi)
64                 diseqc.data[3] |= 1;
65                 
66         if (sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal)
67                 diseqc.data[3] |= 2;
68
69         frontend.sendDiseqc(diseqc);
70         frontend.setTone(hi ? iDVBFrontend::toneOn : iDVBFrontend::toneOff);
71
72         return 0;
73 }
74