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 eDVBSatelliteDiseqcParameters &diseqc_ref = lnb_ref.m_diseqc_parameters;
25 eDVBSatelliteParameters &astra1 = lnb_ref.m_satellites[192];
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 = 0;
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 eDVBSatelliteDiseqcParameters &di_param = lnb_param.m_diseqc_parameters;
52 std::map<int, eDVBSatelliteParameters>::iterator sit =
53 lnb_param.m_satellites.find(sat.orbital_position);
54 if ( sit != lnb_param.m_satellites.end())
57 eDVBSatelliteSwitchParameters &sw_param = sit->second.m_switch_parameters;
58 eDVBSatelliteRotorParameters &rotor_param = sit->second.m_rotor_parameters;
60 voltage = iDVBFrontend::voltageOff,
61 tone = iDVBFrontend::toneOff,
62 csw = di_param.m_committed_cmd,
63 ucsw = di_param.m_uncommitted_cmd,
64 toneburst = di_param.m_toneburst_param,
71 frontend.getData(0, lastcsw);
72 frontend.getData(1, lastucsw);
73 frontend.getData(2, lastToneburst);
74 frontend.getData(5, lastRotorCmd);
75 frontend.getData(6, curRotorPos);
77 if ( sat.frequency > lnb_param.m_lof_threshold )
81 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_hi;
83 parm.FREQUENCY = sat.frequency - lnb_param.m_lof_lo;
85 parm.INVERSION = (!sat.inversion) ? INVERSION_ON : INVERSION_OFF;
90 case eDVBFrontendParametersSatellite::FEC::fNone:
91 eDebug("no fec set.. assume auto");
92 case eDVBFrontendParametersSatellite::FEC::fAuto:
93 parm.u.qpsk.FEC_INNER = FEC_AUTO;
95 case eDVBFrontendParametersSatellite::FEC::f1_2:
96 parm.u.qpsk.FEC_INNER = FEC_1_2;
98 case eDVBFrontendParametersSatellite::FEC::f2_3:
99 parm.u.qpsk.FEC_INNER = FEC_2_3;
101 case eDVBFrontendParametersSatellite::FEC::f3_4:
102 parm.u.qpsk.FEC_INNER = FEC_3_4;
104 case eDVBFrontendParametersSatellite::FEC::f5_6:
105 parm.u.qpsk.FEC_INNER = FEC_5_6;
107 case eDVBFrontendParametersSatellite::FEC::f7_8:
108 parm.u.qpsk.FEC_INNER = FEC_7_8;
112 parm.u.qpsk.SYMBOLRATE = sat.symbol_rate;
114 if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_14V
115 || ( sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Vertical
116 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
117 voltage = iDVBFrontend::voltage13;
118 else if ( sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::_18V
119 || ( sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal
120 && sw_param.m_voltage_mode == eDVBSatelliteSwitchParameters::HV ) )
121 voltage = iDVBFrontend::voltage18;
123 if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::ON)
124 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && hi ) )
125 tone = iDVBFrontend::toneOn;
126 else if ( (sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::OFF)
127 || ( sw_param.m_22khz_signal == eDVBSatelliteSwitchParameters::HILO && !hi ) )
128 tone = iDVBFrontend::toneOff;
130 eSecCommandList sec_sequence;
131 bool setVoltage=true;
133 if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0)
135 if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
137 csw = 0xF0 | (csw << 2);
140 if (sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal)
145 (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
146 bool changed_csw = send_csw && csw != lastcsw;
149 (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
150 bool changed_ucsw = send_ucsw && ucsw != lastucsw;
153 (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
154 bool changed_burst = send_burst && toneburst != lastToneburst;
156 bool send_diseqc = changed_ucsw;
158 send_diseqc = changed_burst && (send_ucsw || send_csw);
161 send_diseqc = changed_csw;
162 if ( send_diseqc && di_param.m_use_fast && (csw & 0xF0) && (lastcsw & 0xF0) && ((csw / 4) == (lastcsw / 4)) )
166 if ( send_diseqc || changed_burst )
168 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
169 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
170 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) ); // standard says 15 msek here
183 for ( int i=0; i < di_param.m_repeats; ++i )
186 for ( int i = 0; i < loops;) // fill commands...
188 eDVBDiseqcCommand diseqc;
190 diseqc.data[0] = i ? 0xE1 : 0xE0;
191 diseqc.data[1] = 0x10;
193 if ( !send_csw || (di_param.m_swap_cmds && send_ucsw) )
195 diseqc.data[2] = 0x39;
196 diseqc.data[3] = ucsw;
200 diseqc.data[2] = 0x38;
201 diseqc.data[3] = csw;
203 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
209 if (diseqc.data[2] == 0x38 && send_ucsw)
211 else if (diseqc.data[2] == 0x39 && send_csw)
215 static int delay = (120 - 54) / 2; // standard says 100msek between two repeated commands
216 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
218 diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
219 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
222 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
224 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) );
226 else // delay 120msek when no command is in repeat gap
227 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
230 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) );
232 frontend.setData(0, csw);
233 frontend.setData(1, ucsw);
236 if ( (changed_burst || send_diseqc) && di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO )
238 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
239 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) );
240 frontend.setData(2, di_param.m_toneburst_param);
242 if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
245 bool useGotoXX = false;
247 std::map<int,int,eDVBSatelliteRotorParameters::Orbital_Position_Compare>::iterator it =
248 rotor_param.m_rotor_position_table.find( sat.orbital_position );
250 if (it != rotor_param.m_rotor_position_table.end()) // position for selected sat found ?
252 else // entry not in table found
254 eDebug("Entry for %d,%d° not in Rotor Table found... i try gotoXX°", sat.orbital_position / 10, sat.orbital_position % 10 );
257 int satDir = sat.orbital_position < 0 ?
258 eDVBSatelliteRotorParameters::WEST :
259 eDVBSatelliteRotorParameters::EAST;
261 double SatLon = abs(sat.orbital_position)/10.00,
262 SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
263 SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
265 if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
268 if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
269 SiteLon = 360 - SiteLon;
271 if (satDir == eDVBSatelliteRotorParameters::WEST )
272 SatLon = 360 - SatLon;
274 eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
275 double satHourAngle =
276 calcSatHourangle( SatLon, SiteLat, SiteLon );
277 eDebug("PolarmountHourAngle=%lf", satHourAngle );
279 static int gotoXTable[10] =
280 { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
282 if (SiteLat >= 0) // Northern Hemisphere
284 int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
285 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
287 if (satHourAngle < 180) // the east
292 else // Southern Hemisphere
294 if (satHourAngle < 180) // the east
296 int tmp=(int)round( fabs( satHourAngle ) * 10.0 );
297 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
302 int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 );
303 RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];
307 eDebug("RotorCmd = %04x", RotorCmd);
309 if ( RotorCmd != lastRotorCmd )
311 eDVBDiseqcCommand diseqc;
312 diseqc.data[0] = 0xE0;
313 diseqc.data[1] = 0x31; // positioner
317 diseqc.data[2] = 0x6E; // drive to angular position
318 diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100);
319 diseqc.data[4] = RotorCmd & 0xFF;
324 diseqc.data[2] = 0x6B; // goto stored sat position
325 diseqc.data[3] = RotorCmd;
327 if ( rotor_param.m_inputpower_parameters.m_use )
328 { // use measure rotor input power to detect rotor state
329 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18) ); // always turn with high voltage
330 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50sec after voltage change
331 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER) );
332 sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
333 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 8) ); // 2 seconds rotor start timout
334 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );
335 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
336 eSecCommand::rotor cmd;
337 cmd.direction=1; // check for running rotor
338 cmd.deltaA=rotor_param.m_inputpower_parameters.m_threshold;
341 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
342 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +8 ) );
343 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
344 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 240) ); // 1 minute running timeout
345 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) );
346 sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) );
347 cmd.direction=0; // check for stopped rotor
348 sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) );
349 sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) );
350 sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) );
351 sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) );
352 frontend.setData(3, RotorCmd);
353 frontend.setData(4, sat.orbital_position);
356 eFatal("rotor turning without inputpowermeasure not implemented yet");
363 sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
364 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );
367 sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, tone) );
368 sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 15) );
370 frontend.setSecSequence(sec_sequence);
376 eDebug("not found satellite configuration for orbital position (%d)", sat.orbital_position );