X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/7ea97a85b8a5bc5a6f1fb75cb2c6335644b4ebc0..94284f21b07f1756120e8b6f5dd53e485a9ff66d:/lib/dvb/sec.cpp diff --git a/lib/dvb/sec.cpp b/lib/dvb/sec.cpp index 78e5949e..be022a16 100644 --- a/lib/dvb/sec.cpp +++ b/lib/dvb/sec.cpp @@ -1,5 +1,7 @@ #include #include +#include + #if HAVE_DVB_API_VERSION < 3 #define INVERSION Inversion #define FREQUENCY Frequency @@ -23,12 +25,12 @@ eDVBSatelliteEquipmentControl::eDVBSatelliteEquipmentControl() eDVBSatelliteDiseqcParameters &diseqc_ref = astra1.m_diseqc_parameters; eDVBSatelliteSwitchParameters &switch_ref = astra1.m_switch_parameters; - lnb_ref.m_lof_hi = 10607000; + lnb_ref.m_lof_hi = 10600000; lnb_ref.m_lof_lo = 9750000; lnb_ref.m_lof_threshold = 11700000; diseqc_ref.m_diseqc_mode = eDVBSatelliteDiseqcParameters::V1_0; - diseqc_ref.m_commited_cmd = eDVBSatelliteDiseqcParameters::BB; + diseqc_ref.m_committed_cmd = eDVBSatelliteDiseqcParameters::AA; diseqc_ref.m_repeats = 0; diseqc_ref.m_seq_repeat = false; diseqc_ref.m_swap_cmds = false; @@ -50,12 +52,26 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA lnb_param.m_satellites.find(sat.orbital_position); if ( sit != lnb_param.m_satellites.end()) { - int hi=0; - int voltage = iDVBFrontend::voltageOff; - int tone = iDVBFrontend::toneOff; - eDVBSatelliteDiseqcParameters &di_param = sit->second.m_diseqc_parameters; eDVBSatelliteSwitchParameters &sw_param = sit->second.m_switch_parameters; + eDVBSatelliteRotorParameters &rotor_param = sit->second.m_rotor_parameters; + int hi=0, + voltage = iDVBFrontend::voltageOff, + tone = iDVBFrontend::toneOff, + csw = di_param.m_committed_cmd, + ucsw = di_param.m_uncommitted_cmd, + toneburst = di_param.m_toneburst_param, + lastcsw = -1, + lastucsw = -1, + lastToneburst = -1, + lastRotorCmd = -1, + curRotorPos = -1; + + frontend.getData(0, lastcsw); + frontend.getData(1, lastucsw); + frontend.getData(2, lastToneburst); + frontend.getData(5, lastRotorCmd); + frontend.getData(6, curRotorPos); if ( sat.frequency > lnb_param.m_lof_threshold ) hi = 1; @@ -69,11 +85,27 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA switch (sat.fec) { - // case 1: - // case ...: - default: - parm.u.qpsk.FEC_INNER = FEC_AUTO; - break; + default: + case eDVBFrontendParametersSatellite::FEC::fNone: + eDebug("no fec set.. assume auto"); + case eDVBFrontendParametersSatellite::FEC::fAuto: + parm.u.qpsk.FEC_INNER = FEC_AUTO; + break; + case eDVBFrontendParametersSatellite::FEC::f1_2: + parm.u.qpsk.FEC_INNER = FEC_1_2; + break; + case eDVBFrontendParametersSatellite::FEC::f2_3: + parm.u.qpsk.FEC_INNER = FEC_2_3; + break; + case eDVBFrontendParametersSatellite::FEC::f3_4: + parm.u.qpsk.FEC_INNER = FEC_3_4; + break; + case eDVBFrontendParametersSatellite::FEC::f5_6: + parm.u.qpsk.FEC_INNER = FEC_5_6; + break; + case eDVBFrontendParametersSatellite::FEC::f7_8: + parm.u.qpsk.FEC_INNER = FEC_7_8; + break; } parm.u.qpsk.SYMBOLRATE = sat.symbol_rate; @@ -95,47 +127,237 @@ RESULT eDVBSatelliteEquipmentControl::prepare(iDVBFrontend &frontend, FRONTENDPA tone = iDVBFrontend::toneOff; eSecCommandList sec_sequence; + bool setVoltage=true; - if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) - { - eDebug("rotor..."); - } - else if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0) + if (di_param.m_diseqc_mode >= eDVBSatelliteDiseqcParameters::V1_0) { - if ( di_param.m_commited_cmd < eDVBSatelliteDiseqcParameters::SENDNO || - di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO ) + 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) ); sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) ); - sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) ); + sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) ); // standard says 15 msek here + setVoltage=false; } - if ( di_param.m_commited_cmd < eDVBSatelliteDiseqcParameters::SENDNO ) + if ( send_diseqc ) { - eDVBDiseqcCommand diseqc; - diseqc.len = 4; - diseqc.data[0] = 0xe0; - diseqc.data[1] = 0x10; - diseqc.data[2] = 0x38; - diseqc.data[3] = 0xF0 | (di_param.m_commited_cmd << 2); + int loops=0; - if (hi) - diseqc.data[3] |= 1; + if ( send_csw ) + ++loops; + if ( send_ucsw ) + ++loops; - if (sat.polarisation == eDVBFrontendParametersSatellite::Polarisation::Horizontal) - diseqc.data[3] |= 2; + for ( int i=0; i < di_param.m_repeats; ++i ) + loops *= 2; - sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) ); - sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 30) ); - } + 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 || (di_param.m_swap_cmds && send_ucsw) ) + { + 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, 30) ); + } + 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, 30) ); - if ( di_param.m_toneburst_param != eDVBSatelliteDiseqcParameters::NO ) + frontend.setData(0, csw); + frontend.setData(1, ucsw); + } + } + if ( (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, 30) ); + frontend.setData(2, di_param.m_toneburst_param); + } + if ( di_param.m_diseqc_mode == eDVBSatelliteDiseqcParameters::V1_2 ) + { + int RotorCmd=0; + bool useGotoXX = false; + + std::map::iterator it = + rotor_param.m_rotor_position_table.find( sat.orbital_position ); + + if (it != rotor_param.m_rotor_position_table.end()) // position for selected sat found ? + RotorCmd=it->second; + else // entry not in table found + { + 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 ]; + + if (satHourAngle < 180) // the east + RotorCmd |= 0xE000; + else // west + RotorCmd |= 0xD000; + } + else // Southern Hemisphere + { + if (satHourAngle < 180) // the east + { + int tmp=(int)round( fabs( satHourAngle ) * 10.0 ); + RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ]; + RotorCmd |= 0xD000; + } + else // west + { + int tmp=(int)round( fabs( 360 - satHourAngle ) * 10.0 ); + RotorCmd = (tmp/10)*0x10 + gotoXTable[ tmp % 10 ]; + RotorCmd |= 0xE000; + } + } + eDebug("RotorCmd = %04x", RotorCmd); + } + if ( RotorCmd != lastRotorCmd ) + { + eDVBDiseqcCommand diseqc; + diseqc.data[0] = 0xE0; + diseqc.data[1] = 0x31; // positioner + if ( useGotoXX ) + { + diseqc.len = 5; + diseqc.data[2] = 0x6E; // drive to angular position + diseqc.data[3] = ((RotorCmd & 0xFF00) / 0x100); + diseqc.data[4] = RotorCmd & 0xFF; + } + else + { + diseqc.len = 4; + diseqc.data[2] = 0x6B; // goto stored sat position + diseqc.data[3] = RotorCmd; + } + if ( rotor_param.m_inputpower_parameters.m_use ) + { // use measure rotor input power to detect rotor state + sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, iDVBFrontend::voltage18) ); // always turn with high voltage + sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 50) ); // wait 50sec after voltage change + sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_IDLE_INPUTPOWER) ); + sec_sequence.push_back( eSecCommand(eSecCommand::SEND_DISEQC, diseqc) ); + sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 8) ); // 2 seconds rotor start timout + sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); + sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) ); + eSecCommand::rotor cmd; + cmd.direction=1; // check for running rotor + cmd.deltaA=rotor_param.m_inputpower_parameters.m_threshold; + cmd.steps=+3; + cmd.okcount=0; + sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); + sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +8 ) ); + sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); + sec_sequence.push_back( eSecCommand(eSecCommand::SET_TIMEOUT, 240) ); // 1 minute running timeout + sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 250) ); + sec_sequence.push_back( eSecCommand(eSecCommand::MEASURE_RUNNING_INPUTPOWER) ); + cmd.direction=0; // check for stopped rotor + sec_sequence.push_back( eSecCommand(eSecCommand::IF_INPUTPOWER_DELTA_GOTO, cmd ) ); + sec_sequence.push_back( eSecCommand(eSecCommand::IF_TIMEOUT_GOTO, +2 ) ); + sec_sequence.push_back( eSecCommand(eSecCommand::GOTO, -4) ); + sec_sequence.push_back( eSecCommand(eSecCommand::UPDATE_CURRENT_ROTORPARAMS) ); + frontend.setData(3, RotorCmd); + frontend.setData(4, sat.orbital_position); + } + else + eFatal("rotor turning without inputpowermeasure not implemented yet"); + } } } - else + + if ( setVoltage ) { sec_sequence.push_back( eSecCommand(eSecCommand::SET_VOLTAGE, voltage) ); sec_sequence.push_back( eSecCommand(eSecCommand::SLEEP, 10) );