2 #include <lib/dvb/sec.h>
3 #include <lib/dvb/rotor_calc.h>
5 #if HAVE_DVB_API_VERSION < 3
6 #define INVERSION Inversion
7 #define FREQUENCY Frequency
8 #define FEC_INNER FEC_inner
9 #define SYMBOLRATE SymbolRate
11 #define INVERSION inversion
12 #define FREQUENCY frequency
13 #define FEC_INNER fec_inner
14 #define SYMBOLRATE symbol_rate
16 #include <lib/base/eerror.h>
18 DEFINE_REF(eDVBSatelliteEquipmentControl);
20 eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl()
22 m_lnblist.push_back(eDVBSatelliteLNBParameters());
23 eDVBSatelliteLNBParameters &lnb_ref = m_lnblist.front();
24 eDVBSatelliteParameters &astra1 = lnb_ref.m_satellites[192];
25 eDVBSatelliteDiseqcParameters &diseqc_ref = astra1.m_diseqc_parameters;
26 eDVBSatelliteSwitchParameters &switch_ref = astra1.m_switch_parameters;
28 lnb_ref.m_lof_hi = 10600000;
29 lnb_ref.m_lof_lo = 9750000;
30 lnb_ref.m_lof_threshold = 11700000;
32 diseqc_ref.m_diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0;
33 diseqc_ref.m_committed_cmd = eDVBSatelliteDiseqcParameters::AA;
34 diseqc_ref.m_repeats = 0;
35 diseqc_ref.m_seq_repeat = false;
36 diseqc_ref.m_swap_cmds = false;
37 diseqc_ref.m_toneburst_param = eDVBSatelliteDiseqcParameters::NO;
38 diseqc_ref.m_uncommitted_cmd = 0;
39 diseqc_ref.m_use_fast = 1;
41 switch_ref.m_22khz_signal = eDVBSatelliteSwitchParameters::HILO;
42 switch_ref.m_voltage_mode = eDVBSatelliteSwitchParameters::HV;
45 RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat)
47 std::list<eDVBSatelliteLNBParameters>::iterator it = m_lnblist.begin();
48 for (;it != m_lnblist.end(); ++it )
50 eDVBSatelliteLNBParameters &lnb_param = *it;
51 std::map<int, eDVBSatelliteParameters>::iterator sit =
52 lnb_param.m_satellites.find(sat.orbital_position);
53 if ( sit != lnb_param.m_satellites.end())
55 eDVBSatelliteDiseqcParameters &di_param = sit->second.m_diseqc_parameters;
56 eDVBSatelliteSwitchParameters &sw_param = sit->second.m_switch_parameters;
57 eDVBSatelliteRotorParameters &rotor_param = sit->second.m_rotor_parameters;
59 voltage = iDVBFrontend::voltageOff,
60 tone = iDVBFrontend::toneOff,
61 csw = di_param.m_committed_cmd,
62 ucsw = di_param.m_uncommitted_cmd,
63 toneburst = di_param.m_toneburst_param,
70 frontend.getData(0, lastcsw);
71 frontend.getData(1, lastucsw);
72 frontend.getData(2, lastToneburst);
73 frontend.getData(3, lastRotorCmd);
74 frontend.getData(4, curRotorPos);
76 if ( sat.frequency > lnb_param.m_lof_threshold )
80 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
82 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
84 parm.INVERSION = (!sat.inversion) ? INVERSION_ON : INVERSION_OFF;
89 case eDVBFrontendParametersSatellite::FEC::fNone:
90 eDebug("no fec set.. assume auto");
91 case eDVBFrontendParametersSatellite::FEC::fAuto:
92 parm.u.qpsk.FEC_INNER = FEC_AUTO;
94 case eDVBFrontendParametersSatellite::FEC::f1_2:
95 parm.u.qpsk.FEC_INNER = FEC_1_2;
97 case eDVBFrontendParametersSatellite::FEC::f2_3:
98 parm.u.qpsk.FEC_INNER = FEC_2_3;
100 case eDVBFrontendParametersSatellite::FEC::f3_4:
101 parm.u.qpsk.FEC_INNER = FEC_3_4;
103 case eDVBFrontendParametersSatellite::FEC::f5_6:
104 parm.u.qpsk.FEC_INNER = FEC_5_6;
106 case eDVBFrontendParametersSatellite::FEC::f7_8:
107 parm.u.qpsk.FEC_INNER = FEC_7_8;
111 parm.u.qpsk.SYMBOLRATE = sat.symbol_rate;
113 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
114 || ( sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Vertical
115 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
116 voltage = iDVBFrontend::voltage13;
117 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
118 || ( sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal
119 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
120 voltage = iDVBFrontend::voltage18;
122 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
123 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && hi ) )
124 tone = iDVBFrontend::toneOn;
125 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
126 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !hi ) )
127 tone = iDVBFrontend::toneOff;
129 eSecCommandList sec_sequence;
131 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
133 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
135 csw = 0xF0 | (csw << 2);
138 if (sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal)
143 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
144 bool changed_csw = send_csw && csw != lastcsw;
147 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
148 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
151 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
152 bool changed_burst = send_burst && toneburst != lastToneburst;
154 bool send_diseqc = changed_ucsw;
156 send_diseqc = changed_burst && (send_ucsw || send_csw);
159 send_diseqc = changed_csw;
160 if ( send_diseqc && di_param.m_use_fast && (csw & 0xF0) && (lastcsw & 0xF0) && ((csw / 4) == (lastcsw / 4)) )
164 if ( send_diseqc || changed_burst )
166 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
167 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
168 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) ); // standard says 15 msek here
180 for ( int i=0; i < di_param.m_repeats; ++i )
183 for ( int i = 0; i < loops;) // fill commands...
185 eDVBDiseqcCommand diseqc;
187 diseqc.data[0] = i ? 0xE1 : 0xE0;
188 diseqc.data[1] = 0x10;
190 if ( !send_csw || (di_param.m_swap_cmds && send_ucsw) )
192 diseqc.data[2] = 0x39;
193 diseqc.data[3] = ucsw;
197 diseqc.data[2] = 0x38;
198 diseqc.data[3] = csw;
200 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
206 if (diseqc.data[2] == 0x38 && send_ucsw)
208 else if (diseqc.data[2] == 0x39 && send_csw)
212 static int delay = (120 - 54) / 2; // standard says 100msek between two repeated commands
213 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
215 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
216 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
219 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
221 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) );
223 else // delay 120msek when no command is in repeat gap
224 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
227 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) );
229 frontend.setData(0, csw);
230 frontend.setData(1, ucsw);
233 if ( (changed_burst || send_diseqc) && di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO )
235 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
236 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) );
237 frontend.setData(2, di_param.m_toneburst_param);
239 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
242 bool useGotoXX = false;
244 std::map<int,int,eDVBSatelliteRotorParameters::Orbital_Position_Compare>::iterator it =
245 rotor_param.m_rotor_position_table.find( sat.orbital_position );
247 if (it != rotor_param.m_rotor_position_table.end()) // position for selected sat found ?
249 else // entry not in table found
251 eDebug("Entry for %d,%d° not in Rotor Table found... i try gotoXX°", sat.orbital_position / 10, sat.orbital_position % 10 );
254 int satDir = sat.orbital_position < 0 ?
255 eDVBSatelliteRotorParameters::WEST :
256 eDVBSatelliteRotorParameters::EAST;
258 double SatLon = abs(sat.orbital_position)/10.00,
259 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
260 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
262 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
265 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
266 SiteLon = 360 - SiteLon;
268 if (satDir == eDVBSatelliteRotorParameters::WEST )
269 SatLon = 360 - SatLon;
271 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
272 double satHourAngle =
273 calcSatHourangle( SatLon, SiteLat, SiteLon );
274 eDebug("PolarmountHourAngle=%lf", satHourAngle );
276 static int gotoXTable[10] =
277 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
279 if (SiteLat >= 0) // Northern Hemisphere
281 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
282 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
284 if (satHourAngle < 180) // the east
289 else // Southern Hemisphere
291 if (satHourAngle < 180) // the east
293 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
294 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
299 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
300 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
304 eDebug("RotorCmd = %04x", RotorCmd);
306 if ( RotorCmd != lastRotorCmd )
308 eDVBDiseqcCommand diseqc;
309 diseqc.data[0] = 0xE0;
310 diseqc.data[1] = 0x31; // positioner
314 diseqc.data[2] = 0x6E; // drive to angular position
315 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
316 diseqc.data[4] = RotorCmd & 0xFF;
321 diseqc.data[2] = 0x6B; // goto stored sat position
322 diseqc.data[3] = RotorCmd;
324 if ( rotor_param.m_inputpower_parameters.m_use )
325 { // use measure rotor input power to detect rotor state
326 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER) );
327 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
328 frontend.setData(3, RotorCmd);
329 frontend.setData(4, sat.orbital_position);
332 eFatal("rotor turning without inputpowermeasure not implemented yet");
338 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
339 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
342 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
343 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
345 frontend.setSecSequence(sec_sequence);
351 eDebug("not found satellite configuration for orbital position (%d)", sat.orbital_position );