+ if ( di_param.m_committed_cmd < eDVBSatelliteDiseqcParameters::SENDNO )
+ {
+ csw = 0xF0 | (csw << 2);
+ if (hi)
+ csw |= 1;
+ if (sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal)
+ csw |= 2;
+ }
+
+ bool send_csw =
+ (di_param.m_committed_cmd != eDVBSatelliteDiseqcParameters::SENDNO);
+ bool changed_csw = send_csw && csw != lastcsw;
+
+ bool send_ucsw =
+ (di_param.m_uncommitted_cmd && di_param.m_diseqc_mode > eDVBSatelliteDiseqcParameters::V1_0);
+ bool changed_ucsw = send_ucsw && ucsw != lastucsw;
+
+ bool send_burst =
+ (di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO);
+ bool changed_burst = send_burst && toneburst != lastToneburst;
+
+ bool send_diseqc = changed_ucsw;
+ if (!send_diseqc)
+ send_diseqc = changed_burst && (send_ucsw || send_csw);
+ if (!send_diseqc)
+ {
+ send_diseqc = changed_csw;
+ if ( send_diseqc && di_param.m_use_fast && (csw & 0xF0) && (lastcsw & 0xF0) && ((csw / 4) == (lastcsw / 4)) )
+ send_diseqc = false;
+ }
+
+ if ( send_diseqc || changed_burst )
+ {
+ sec_sequence.push_back( eSecCommand(eSecCommand::SET_TONE, iDVBFrontend::toneOff) );
+ eSecCommand::pair compare;
+ compare.voltage = voltage;
+ compare.steps = +3;
+ sec_sequence.push_back( eSecCommand(eSecCommand::IF_VOLTAGE_GOTO, compare) ); // voltage already correct ?
+ sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) );
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+ }
+
+ for (int seq_repeat = 0; seq_repeat < (di_param.m_seq_repeat?2:1); ++seq_repeat)
+ {
+ if ( di_param.m_command_order & 1 && // toneburst at begin of sequence
+ changed_burst && di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO )
+ {
+ sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+ frontend.setData(2, di_param.m_toneburst_param);
+ }
+
+ if ( send_diseqc )
+ {
+ int loops=0;
+
+ if ( send_csw )
+ ++loops;
+ if ( send_ucsw )
+ ++loops;
+
+ for ( int i=0; i < di_param.m_repeats; ++i )
+ loops *= 2;
+
+ for ( int i = 0; i < loops;) // fill commands...
+ {
+ eDVBDiseqcCommand diseqc;
+ diseqc.len = 4;
+ diseqc.data[0] = i ? 0xE1 : 0xE0;
+ diseqc.data[1] = 0x10;
+
+ if ( !send_csw || (send_ucsw && (di_param.m_command_order & 4) ) )
+ {
+ diseqc.data[2] = 0x39;
+ diseqc.data[3] = ucsw;
+ }
+ else
+ {
+ diseqc.data[2] = 0x38;
+ diseqc.data[3] = csw;
+ }
+ sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
+
+ i++;
+ if ( i < loops )
+ {
+ int cmd=0;
+ if (diseqc.data[2] == 0x38 && send_ucsw)
+ cmd=0x39;
+ else if (diseqc.data[2] == 0x39 && send_csw)
+ cmd=0x38;
+ if (cmd)
+ {
+ static int delay = (120 - 54) / 2; // standard says 100msek between two repeated commands
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay) );
+ diseqc.data[2]=cmd;
+ diseqc.data[3]=(cmd==0x38) ? csw : ucsw;
+ sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) );
+ ++i;
+ if ( i < loops )
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, delay ) );
+ else
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+ }
+ else // delay 120msek when no command is in repeat gap
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 120) );
+ }
+ else
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+
+ frontend.setData(0, csw);
+ frontend.setData(1, ucsw);
+ }
+ }
+
+ if ( !(di_param.m_command_order & 1) && // toneburst at end of sequence
+ (changed_burst || send_diseqc) && di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO )
+ {
+ sec_sequence.push_back( eSecCommand(eSecCommand::SEND_TONEBURST, di_param.m_toneburst_param) );
+ sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) );
+ frontend.setData(2, di_param.m_toneburst_param);
+ }
+ }
+
+ if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 )
+ {
+ int RotorCmd=0;
+ bool useGotoXX = false;
+
+ if (sw_param.m_rotorPosNum) // we have stored rotor pos?
+ RotorCmd=sw_param.m_rotorPosNum;
+ else // we must calc gotoxx cmd
+ {
+ eDebug("Entry for %d,%d° not in Rotor Table found... i try gotoXX°", sat.orbital_position / 10, sat.orbital_position % 10 );
+ useGotoXX = true;
+
+ int satDir = sat.orbital_position < 0 ?
+ eDVBSatelliteRotorParameters::WEST :
+ eDVBSatelliteRotorParameters::EAST;
+
+ double SatLon = abs(sat.orbital_position)/10.00,
+ SiteLat = rotor_param.m_gotoxx_parameters.m_latitude,
+ SiteLon = rotor_param.m_gotoxx_parameters.m_longitude;
+
+ if ( rotor_param.m_gotoxx_parameters.m_la_direction == eDVBSatelliteRotorParameters::SOUTH )
+ SiteLat = -SiteLat;
+
+ if ( rotor_param.m_gotoxx_parameters.m_lo_direction == eDVBSatelliteRotorParameters::WEST )
+ SiteLon = 360 - SiteLon;
+
+ if (satDir == eDVBSatelliteRotorParameters::WEST )
+ SatLon = 360 - SatLon;
+
+ eDebug("siteLatitude = %lf, siteLongitude = %lf, %lf degrees", SiteLat, SiteLon, SatLon );
+ double satHourAngle =
+ calcSatHourangle( SatLon, SiteLat, SiteLon );
+ eDebug("PolarmountHourAngle=%lf", satHourAngle );
+
+ static int gotoXTable[10] =
+ { 0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E };
+
+ if (SiteLat >= 0) // Northern Hemisphere
+ {
+ int tmp=(int)round( fabs( 180 - satHourAngle ) * 10.0 );
+ RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ];