Example #1
0
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="parameters">Scan parameters</param>
        /// <param name="channel">The channel.</param>
        public void SendDiseqCommand(ScanParameters parameters, DVBSChannel channel)
        {
            byte  disEqcPort = (byte)BandTypeConverter.GetAntennaNr(channel);
            Int32 LNBLOFLowBand;
            Int32 LNBLOFHighBand;
            Int32 LNBLOFHiLoSW;

            BandTypeConverter.GetDefaultLnbSetup(parameters, channel.BandType, out LNBLOFLowBand, out LNBLOFHighBand,
                                                 out LNBLOFHiLoSW);
            byte turnon22Khz = BandTypeConverter.IsHiBand(channel, parameters) ? (byte)2 : (byte)1;

            SetLnbData(true, LNBLOFLowBand, LNBLOFHighBand, LNBLOFHiLoSW, turnon22Khz, disEqcPort);
            SendDiseqcCommandTest(parameters, channel);
        }
        /// <summary>
        /// Tunes to channel using custom tune method.
        /// </summary>
        /// <param name="channel">Channel</param>
        /// <param name="Parameters">ScanParameters</param>
        /// <returns>true if successful</returns>
        public bool CustomTune(IChannel channel, ScanParameters Parameters)
        {
            if (!SupportsTuningForChannel(channel))
            {
                return(false);
            }

            DVBSChannel satelliteChannel = channel as DVBSChannel;

            bool hiBand = BandTypeConverter.IsHiBand(satelliteChannel, Parameters);
            int  lof1, lof2, sw;

            BandTypeConverter.GetDefaultLnbSetup(Parameters, satelliteChannel.BandType, out lof1, out lof2, out sw);
            int lnbFrequency;

            if (hiBand)
            {
                lnbFrequency = lof2 * 1000;
            }
            else
            {
                lnbFrequency = lof1 * 1000;
            }

            Log.Log.Debug("TeVii: Start CustomTune F:{0} SR:{1} LOF:{6} P:{2} HI:{3} M:{4} FEC:{5}",
                          (int)satelliteChannel.Frequency,
                          satelliteChannel.SymbolRate * 1000,
                          Translate(satelliteChannel.Polarisation),
                          hiBand,
                          Translate(satelliteChannel.ModulationType),
                          Translate(satelliteChannel.InnerFecRate),
                          lnbFrequency
                          );

            int res = TuneTransponder(m_iDeviceIndex,
                                      (int)satelliteChannel.Frequency,
                                      satelliteChannel.SymbolRate * 1000,
                                      lnbFrequency,
                                      Translate(satelliteChannel.Polarisation),
                                      hiBand ? 1 : 0,
                                      Translate(satelliteChannel.ModulationType),
                                      Translate(satelliteChannel.InnerFecRate)
                                      );

            Log.Log.Debug("TeVii: Send CustomTune: {0}", res);
            return(res == 1);
        }
Example #3
0
        private bool BeforeTune(IChannel channel, ref int subChannelId, out int pmtPid)
        {
            int frequency  = 0;
            int symbolRate = 0;
            int modulation = (int)eModulationTAG.QAM_64;
            int bandWidth  = 0;
            LNBSelectionType lnbSelection = LNBSelectionType.Lnb0;
            const int        lnbKhzTone   = 22;
            const int        fec          = (int)FecType.Fec_Auto;
            int           polarity        = 0;
            SS2DisEqcType disType         = SS2DisEqcType.None;
            int           switchFreq      = 0;

            pmtPid = 0;
            int satelliteIndex = 0;

            Log.Log.WriteFile("ss2:Tune({0})", channel);
            if (_epgGrabbing)
            {
                _epgGrabbing = false;
                if (_epgGrabberCallback != null && _epgGrabbing)
                {
                    _epgGrabberCallback.OnEpgCancelled();
                }
            }
            switch (_cardType)
            {
            case CardType.DvbS:
                DVBSChannel dvbsChannel = channel as DVBSChannel;
                if (dvbsChannel == null)
                {
                    Log.Log.Error("Channel is not a DVBS channel!!! {0}", channel.GetType().ToString());
                    return(false);
                }
                if (CurrentChannel != null)
                {
                    DVBSChannel oldChannels = (DVBSChannel)CurrentChannel;
                    if (oldChannels.Equals(channel))
                    {
                        //@FIX this fails for back-2-back recordings
                        //Log.Log.WriteFile("ss2:already tuned on this channel");
                        //return _mapSubChannels[0];
                    }
                }
                frequency      = (int)dvbsChannel.Frequency;
                symbolRate     = dvbsChannel.SymbolRate;
                satelliteIndex = dvbsChannel.SatelliteIndex;
                bool hiBand = BandTypeConverter.IsHiBand(dvbsChannel, Parameters);
                int  lof1, lof2, sw;
                BandTypeConverter.GetDefaultLnbSetup(Parameters, dvbsChannel.BandType, out lof1, out lof2, out sw);
                int lnbFrequency;
                if (BandTypeConverter.IsHiBand(dvbsChannel, Parameters))
                {
                    lnbFrequency = lof2 * 1000;
                }
                else
                {
                    lnbFrequency = lof1 * 1000;
                }
                //0=horizontal or left, 1=vertical or right
                polarity = 0;
                if (dvbsChannel.Polarisation == Polarisation.LinearV)
                {
                    polarity = 1;
                }
                if (dvbsChannel.Polarisation == Polarisation.CircularR)
                {
                    polarity = 1;
                }
                Log.Log.WriteFile("ss2:  Polarity:{0} {1}", dvbsChannel.Polarisation, polarity);
                lnbSelection = LNBSelectionType.Lnb0;
                if (dvbsChannel.BandType == BandType.Universal)
                {
                    //only set the LNB (22,33,44) Khz tone when we use ku-band and are in hi-band
                    switch (lnbKhzTone)
                    {
                    case 22:
                        lnbSelection = LNBSelectionType.Lnb22kHz;
                        break;
                    }
                    if (hiBand == false)
                    {
                        lnbSelection = LNBSelectionType.Lnb0;
                    }
                }
                switch (dvbsChannel.DisEqc)
                {
                case DisEqcType.None: // none
                    disType = SS2DisEqcType.None;
                    break;

                case DisEqcType.SimpleA: // Simple A
                    disType = SS2DisEqcType.Simple_A;
                    break;

                case DisEqcType.SimpleB: // Simple B
                    disType = SS2DisEqcType.Simple_B;
                    break;

                case DisEqcType.Level1AA: // Level 1 A/A
                    disType = SS2DisEqcType.Level_1_A_A;
                    break;

                case DisEqcType.Level1BA: // Level 1 B/A
                    disType = SS2DisEqcType.Level_1_B_A;
                    break;

                case DisEqcType.Level1AB: // Level 1 A/B
                    disType = SS2DisEqcType.Level_1_A_B;
                    break;

                case DisEqcType.Level1BB: // Level 1 B/B
                    disType = SS2DisEqcType.Level_1_B_B;
                    break;
                }
                switchFreq = lnbFrequency / 1000; //in MHz
                pmtPid     = dvbsChannel.PmtPid;
                break;

            case CardType.DvbT:
                DVBTChannel dvbtChannel = channel as DVBTChannel;
                if (dvbtChannel == null)
                {
                    Log.Log.Error("Channel is not a DVBT channel!!! {0}", channel.GetType().ToString());
                    return(false);
                }
                if (CurrentChannel != null)
                {
                    DVBTChannel oldChannelt = (DVBTChannel)CurrentChannel;
                    if (oldChannelt.Equals(channel))
                    {
                        //@FIX this fails for back-2-back recordings
                        //Log.Log.WriteFile("ss2:already tuned on this channel");
                        //return _mapSubChannels[0];
                    }
                }
                frequency = (int)dvbtChannel.Frequency;
                bandWidth = dvbtChannel.BandWidth;
                pmtPid    = dvbtChannel.PmtPid;
                break;

            case CardType.DvbC:
                DVBCChannel dvbcChannel = channel as DVBCChannel;
                if (dvbcChannel == null)
                {
                    Log.Log.Error("Channel is not a DVBC channel!!! {0}", channel.GetType().ToString());
                    return(false);
                }
                if (CurrentChannel != null)
                {
                    DVBCChannel oldChannelc = (DVBCChannel)CurrentChannel;
                    if (oldChannelc.Equals(channel))
                    {
                        //@FIX this fails for back-2-back recordings
                        //Log.Log.WriteFile("ss2:already tuned on this channel");
                        //return _mapSubChannels[0];
                    }
                }
                frequency  = (int)dvbcChannel.Frequency;
                symbolRate = dvbcChannel.SymbolRate;
                switch (dvbcChannel.ModulationType)
                {
                case ModulationType.Mod16Qam:
                    modulation = (int)eModulationTAG.QAM_16;
                    break;

                case ModulationType.Mod32Qam:
                    modulation = (int)eModulationTAG.QAM_32;
                    break;

                case ModulationType.Mod64Qam:
                    modulation = (int)eModulationTAG.QAM_64;
                    break;

                case ModulationType.Mod128Qam:
                    modulation = (int)eModulationTAG.QAM_128;
                    break;

                case ModulationType.Mod256Qam:
                    modulation = (int)eModulationTAG.QAM_256;
                    break;
                }
                pmtPid = dvbcChannel.PmtPid;
                break;

            case CardType.Atsc:
                ATSCChannel dvbaChannel = channel as ATSCChannel;
                if (dvbaChannel == null)
                {
                    Log.Log.Error("Channel is not a ATSC channel!!! {0}", channel.GetType().ToString());
                    return(false);
                }
                if (CurrentChannel != null)
                {
                    ATSCChannel oldChannela = (ATSCChannel)CurrentChannel;
                    if (oldChannela.Equals(channel))
                    {
                        //@FIX this fails for back-2-back recordings
                        //Log.Log.WriteFile("ss2:already tuned on this channel");
                        //return _mapSubChannels[0];
                    }
                }
                //if modulation = 256QAM assume ATSC QAM for HD5000
                if (dvbaChannel.ModulationType == ModulationType.Mod256Qam)
                {
                    Log.Log.WriteFile("DVBGraphB2C2:  ATSC Channel:{0} Frequency:{1}", dvbaChannel.PhysicalChannel,
                                      dvbaChannel.Frequency);
                    frequency = (int)dvbaChannel.Frequency;
                    pmtPid    = dvbaChannel.PmtPid;
                }
                else
                {
                    Log.Log.WriteFile("DVBGraphSkyStar2:  ATSC Channel:{0}", dvbaChannel.PhysicalChannel);
                    //#DM B2C2 SDK says ATSC is tuned by frequency. Here we work the OTA frequency by channel number#
                    int atscfreq = 0;
                    if (dvbaChannel.PhysicalChannel <= 6)
                    {
                        atscfreq = 45 + (dvbaChannel.PhysicalChannel * 6);
                    }
                    if (dvbaChannel.PhysicalChannel >= 7 && dvbaChannel.PhysicalChannel <= 13)
                    {
                        atscfreq = 177 + ((dvbaChannel.PhysicalChannel - 7) * 6);
                    }
                    if (dvbaChannel.PhysicalChannel >= 14)
                    {
                        atscfreq = 473 + ((dvbaChannel.PhysicalChannel - 14) * 6);
                    }
                    //#DM changed tuning parameter from physical channel to calculated frequency above.
                    frequency = atscfreq;
                    Log.Log.WriteFile("ss2:  ATSC Frequency:{0} MHz", frequency);
                    pmtPid = dvbaChannel.PmtPid;
                }
                break;
            }
            if (_graphState == GraphState.Idle)
            {
                BuildGraph();
            }
            if (_mapSubChannels.ContainsKey(subChannelId) == false)
            {
                subChannelId = GetNewSubChannel(channel);
            }
            _mapSubChannels[subChannelId].CurrentChannel = channel;
            _mapSubChannels[subChannelId].OnBeforeTune();
            if (_interfaceEpgGrabber != null)
            {
                _interfaceEpgGrabber.Reset();
            }
            if (frequency > 13000)
            {
                frequency /= 1000;
            }
            Log.Log.WriteFile("ss2:  Transponder Frequency:{0} MHz", frequency);
            int hr = _interfaceB2C2TunerCtrl.SetFrequency(frequency);

            if (hr != 0)
            {
                Log.Log.Error("ss2:SetFrequencyKHz() failed:0x{0:X}", hr);
                return(false);
            }
            switch (_cardType)
            {
            case CardType.DvbC:
                Log.Log.WriteFile("ss2:  SymbolRate:{0} KS/s", symbolRate);
                hr = _interfaceB2C2TunerCtrl.SetSymbolRate(symbolRate);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetSymbolRate() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Modulation:{0}", ((eModulationTAG)modulation));
                hr = _interfaceB2C2TunerCtrl.SetModulation(modulation);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetModulation() failed:0x{0:X}", hr);
                    return(false);
                }
                break;

            case CardType.DvbT:
                Log.Log.WriteFile("ss2:  GuardInterval:auto");
                hr = _interfaceB2C2TunerCtrl.SetGuardInterval((int)GuardIntervalType.Interval_Auto);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetGuardInterval() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Bandwidth:{0} MHz", bandWidth);
                //hr = _interfaceB2C2TunerCtrl.SetBandwidth((int)dvbtChannel.BandWidth);
                // Set Channel Bandwidth (NOTE: Temporarily use polarity function to avoid having to
                // change SDK interface for SetBandwidth)
                // from Technisat SDK 03/2006
                hr = _interfaceB2C2TunerCtrl.SetPolarity(bandWidth);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetBandwidth() failed:0x{0:X}", hr);
                    return(false);
                }
                break;

            case CardType.DvbS:
                Log.Log.WriteFile("ss2:  SymbolRate:{0} KS/s", symbolRate);
                hr = _interfaceB2C2TunerCtrl.SetSymbolRate(symbolRate);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetSymbolRate() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Fec:{0} {1}", ((FecType)fec), fec);
                hr = _interfaceB2C2TunerCtrl.SetFec(fec);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetFec() failed:0x{0:X}", hr);
                    return(false);
                }
                hr = _interfaceB2C2TunerCtrl.SetPolarity(polarity);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetPolarity() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Lnb:{0}", lnbSelection);
                hr = _interfaceB2C2TunerCtrl.SetLnbKHz((int)lnbSelection);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetLnbKHz() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Diseqc:{0} {1}", disType, disType);
                hr = _interfaceB2C2TunerCtrl.SetDiseqc((int)disType);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetDiseqc() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  LNBFrequency:{0} MHz", switchFreq);
                hr = _interfaceB2C2TunerCtrl.SetLnbFrequency(switchFreq);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetLnbFrequency() failed:0x{0:X}", hr);
                    return(false);
                }
                if (_useDISEqCMotor)
                {
                    if (satelliteIndex > 0)
                    {
                        DisEqcGotoPosition((byte)satelliteIndex);
                    }
                }
                break;
            }
            return(true);
        }
Example #4
0
        private bool BeforeTune(ref int subChannelId, IChannel channel)
        {
            DVBSChannel dvbsChannel = channel as DVBSChannel;

            if (dvbsChannel == null)
            {
                Log.Log.WriteFile("Channel is not a DVBS channel!!! {0}", channel.GetType().ToString());
                return(false);
            }

            /*if (CurrentChannel != null)
             * {
             * //@FIX this fails for back-2-back recordings
             * //if (oldChannel.Equals(channel)) return _mapSubChannels[0];
             * }*/
            if (dvbsChannel.SwitchingFrequency < 10)
            {
                dvbsChannel.SwitchingFrequency = 11700000;
            }
            Log.Log.WriteFile("dvbs:  Tune:{0}", channel);
            if (_graphState == GraphState.Idle)
            {
                BuildGraph();
            }
            if (_mapSubChannels.ContainsKey(subChannelId) == false)
            {
                subChannelId = GetNewSubChannel(channel);
            }
            if (useInternalNetworkProvider)
            {
                //set the DisEqC parameters
                if (_conditionalAccess != null)
                {
                    //int hr2 = ((IMediaControl)_graphBuilder).Pause();
                    _diseqCsucceded = _conditionalAccess.SendDiseqcCommand(_parameters, dvbsChannel);
                    //hr2 = ((IMediaControl)_graphBuilder).Run();

                    //move diseqc motor to correct satellite
                    if (dvbsChannel != null && dvbsChannel.SatelliteIndex > 0 && _conditionalAccess.DiSEqCMotor != null)
                    {
                        _conditionalAccess.DiSEqCMotor.GotoPosition((byte)dvbsChannel.SatelliteIndex);
                    }
                }
                return(true);
            }

            if (_previousChannel == null || _previousChannel.IsDifferentTransponder(dvbsChannel))
            {
                //_pmtPid = -1;
                ILocator locator;
                int      lowOsc;
                int      hiOsc;
                int      lnbSwitch;
                BandTypeConverter.GetDefaultLnbSetup(Parameters, dvbsChannel.BandType, out lowOsc, out hiOsc, out lnbSwitch);
                Log.Log.Info("LNB low:{0} hi:{1} switch:{2}", lowOsc, hiOsc, lnbSwitch);
                if (lnbSwitch == 0)
                {
                    lnbSwitch = 18000;
                }
                IDVBSTuningSpace tuningSpace = (IDVBSTuningSpace)_tuningSpace;
                tuningSpace.put_LNBSwitch(lnbSwitch * 1000);
                tuningSpace.put_LowOscillator(lowOsc * 1000);
                tuningSpace.put_HighOscillator(hiOsc * 1000);
                ITuneRequest request;
                _tuningSpace.CreateTuneRequest(out request);
                _tuneRequest = (IDVBTuneRequest)request;
                _tuningSpace.get_DefaultLocator(out locator);
                IDVBSLocator    dvbsLocator = (IDVBSLocator)locator;
                IDVBTuneRequest tuneRequest = (IDVBTuneRequest)_tuneRequest;
                tuneRequest.put_ONID(dvbsChannel.NetworkId);
                tuneRequest.put_SID(dvbsChannel.ServiceId);
                tuneRequest.put_TSID(dvbsChannel.TransportId);
                locator.put_CarrierFrequency((int)dvbsChannel.Frequency);
                dvbsLocator.put_SymbolRate(dvbsChannel.SymbolRate);
                dvbsLocator.put_SignalPolarisation(dvbsChannel.Polarisation);

                // Set DVB-S2 and manufacturer specific tuning parameters here.
                //-------------------------------------------------------------------
                // Important: the original dvbsChannel object *must not* be modified
                // otherwise IsDifferentTransponder() will sometimes returns true
                // when it shouldn't. See mantis 0002979.
                //-------------------------------------------------------------------
                DVBSChannel tuneChannel = new DVBSChannel(dvbsChannel);
                if (_conditionalAccess != null)
                {
                    tuneChannel = _conditionalAccess.SetDVBS2Modulation(_parameters, tuneChannel);
                }
                dvbsLocator.put_Modulation(tuneChannel.ModulationType);
                Log.Log.WriteFile("dvbs:channel modulation is set to {0}", tuneChannel.ModulationType);
                dvbsLocator.put_InnerFECRate(tuneChannel.InnerFecRate);
                Log.Log.WriteFile("dvbs:channel FECRate is set to {0}", tuneChannel.InnerFecRate);
                _tuneRequest.put_Locator(locator);

                //set the DisEqC parameters
                if (_conditionalAccess != null)
                {
                    //int hr2 = ((IMediaControl)_graphBuilder).Pause();
                    _diseqCsucceded = _conditionalAccess.SendDiseqcCommand(_parameters, dvbsChannel);
                    //hr2 = ((IMediaControl)_graphBuilder).Run();

                    //move diseqc motor to correct satellite
                    if (dvbsChannel != null && dvbsChannel.SatelliteIndex > 0 && _conditionalAccess.DiSEqCMotor != null)
                    {
                        _conditionalAccess.DiSEqCMotor.GotoPosition((byte)dvbsChannel.SatelliteIndex);
                    }
                }
            }

            _dvbsChannel = dvbsChannel;
            return(true);
        }