Exemple #1
0
        /// <summary>
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (commandInterface == null)
            {
                return(false);
            }

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            DirectShowAPI.Pilot pilot = DsUtils.GetNativePilot(frequency.Pilot);
            reply = commandInterface.put_Pilot(pilot);
            if (reply != 0)
            {
                Logger.Instance.Write("Win7API DVB-S2 handler: Set Pilot command failed error code 0x" + reply.ToString("X"));
            }
            else
            {
                Logger.Instance.Write("Win7API DVB-S2 handler: Set Pilot command succeeded");

                DirectShowAPI.RollOff rollOff = DsUtils.GetNativeRollOff(frequency.RollOff);
                reply = commandInterface.put_RollOff(ref rollOff);
                if (reply != 0)
                {
                    Logger.Instance.Write("Win7API DVB-S2 handler: Set Rolloff command failed error code 0x" + reply.ToString("X"));
                }
                else
                {
                    Logger.Instance.Write("Win7API DVB-S2 handler: Set Rolloff command succeeded");
                }
            }

            return(reply == 0);
        }
Exemple #2
0
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            BurstModulationType modulationType;

            if (lnbNumber == 1)                                                   //for simple diseqc switches (i.e. 22KHz tone burst)
            {
                modulationType = BurstModulationType.TONE_BURST_UNMODULATED;
            }
            else
            {
                modulationType = BurstModulationType.TONE_BURST_MODULATED;        //default to tone_burst_modulated
            }
            bool commandReply = sendCommand(GetCommand(lnbNumber, tuningSpec), modulationType);

            if (!commandReply)
            {
                return(false);
            }

            byte[] commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
            {
                return(true);
            }

            Thread.Sleep(150);

            return(sendCommand(commandBytes, BurstModulationType.TONE_BURST_MODULATED));
        }
Exemple #3
0
        public void Run()
        {
            SatelliteDatabase satelliteDatabase = new SatelliteDatabase();
            satelliteDatabase.Load();

            TVDatabase tvDatabase = new TVDatabase();
            tvDatabase.Load();

            epgDatabase = new EPGDatabase();
            epgDatabase.Load();

            Collection<TuningSpec> tuningCollection = new Collection<TuningSpec>();

            foreach (TVStation tvStation in tvDatabase.StationCollection)
            {
                TuningSpec tuningSpec = findTuningSpec(tuningCollection, tvStation);
                if (tuningSpec == null)
                {
                    TuningSpec newTuningSpec = new TuningSpec();
                    newTuningSpec.Satellite = tvStation.Satellite;
                    newTuningSpec.OriginalNetworkID = tvStation.OriginalNetworkID;
                    newTuningSpec.TransportStreamID = tvStation.TransportStreamID;
                    newTuningSpec.Frequency = tvStation.Frequency;
                    newTuningSpec.SymbolRate = tvStation.SymbolRate;
                    newTuningSpec.Tag = new EPGGraph(satelliteDatabase[tvStation.Satellite], newTuningSpec);
                    tuningCollection.Add(newTuningSpec);
                }
            }

            bool end = false;
            DateTime lastUpdateTime = DateTime.Now;
            TimeSpan interval = new TimeSpan(0, 1, 0);

            while (!end)
            {
                foreach (TuningSpec tuningSpec in tuningCollection)
                {
                    EPGGraph currentGraph = tuningSpec.Tag as EPGGraph;
                    currentGraph.Play();

                    EITController eitController = new EITController();

                    while (!eitController.Finished && !end)
                    {
                        Collection<EITEntry> eitCollection = eitController.ProcessEITSections(currentGraph);
                        updateSchedule(eitCollection);

                        if (lastUpdateTime + interval < DateTime.Now)
                        {
                            epgDatabase.UpdateDatabase();
                            lastUpdateTime = DateTime.Now;
                        }
                    }

                    currentGraph.Stop();
                }

                Thread.Sleep(2000);
            }
        }
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="tuningSpec">A tuning spec instance.</param>
        /// <param name="port">The LNB port (eg AB).</param>
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            if (commandInterface == null)
            {
                return(true);
            }

            int reply = commandInterface.put_EnableDiseqCommands(1);

            if (reply != 0)
            {
                Logger.Instance.Write("DiSEqC enble command failed: error code 0x" + reply.ToString("X"));
            }
            else
            {
                int lnbNumber = GetLnbNumber(port);
                reply = commandInterface.put_DiseqLNBSource(lnbNumber - 1);
                if (reply != 0)
                {
                    Logger.Instance.Write("DiSEqC command failed: error code 0x" + reply.ToString("X"));
                }
            }

            return(reply == 0);
        }
Exemple #5
0
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="tuningSpec">A tuning spec instance.</param>
        /// <param name="port">The Diseqc port ( eg AB).</param>
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            if (!cardCapable)
            {
                return(false);
            }

            switch (port)
            {
            case "AA":
                return(sendRangeCommand(0x00));

            case "AB":
                return(sendRangeCommand(0x01));

            case "BA":
                return(sendRangeCommand(0x0100));

            case "BB":
                return(sendRangeCommand(0x0101));

            case "A":
                return(sendRangeCommand(0x00));

            case "B":
                return(sendRangeCommand(0x01));

            default:
                return(false);
            }
        }
Exemple #6
0
        private bool sendDiseqcCommand(byte disEqcPort, bool isHiBand, TuningSpec tuningSpec)
        {
            //bit 0	(1)	: 0=low band, 1 = hi band
            //bit 1 (2) : 0=vertical, 1 = horizontal
            //bit 3 (4) : 0=satellite position A, 1=satellite position B
            //bit 4 (8) : 0=switch option A, 1=switch option  B
            // LNB    option  position
            // 1        A         A
            // 2        A         B
            // 3        B         A
            // 4        B         B

            bool isHorizontal = ((tuningSpec.NativeSignalPolarization == Polarisation.LinearH) || (tuningSpec.NativeSignalPolarization == Polarisation.CircularL));

            byte command = 0xf0;

            command |= (byte)(isHiBand ? 1 : 0);
            command |= (byte)((isHorizontal) ? 2 : 0);
            command |= (byte)((disEqcPort - 1) << 2);

            byte[] commandBytes = new byte[4];
            commandBytes[0] = 0xe0;
            commandBytes[1] = 0x10;
            commandBytes[2] = 0x38;
            commandBytes[3] = command;

            return(sendCommand(commandBytes));
        }
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IBDA_DigitalDemodulator demodulator = FindDemodulator("GenPix", tunerFilter);

            if (demodulator == null)
            {
                Logger.Instance.Write("GenPix DVB-S2 handler: Demodulator not located");
                return(false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (modulationType)
            {
            case ModulationType.ModQpsk:
                modulationType = ModulationType.Mod8Vsb;
                break;

            case ModulationType.Mod8Psk:
                modulationType = ModulationType.Mod8Vsb;
                break;

            case ModulationType.Mod16Apsk:
                modulationType = ModulationType.Mod16Vsb;
                break;

            case ModulationType.Mod32Apsk:
                modulationType = ModulationType.ModOqpsk;
                break;

            default:
                break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("GenPix DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return(false);
                }
                else
                {
                    Logger.Instance.Write("GenPix DVB-S2 handler: Modulation type changed to " + modulationType);
                }
            }
            else
            {
                Logger.Instance.Write("GenPix DVB-S2 handler: Modulation type not changed");
            }

            return(true);
        }
Exemple #8
0
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            BurstModulationType modulationType;

            if (lnbNumber == 1)                                                   //for simple diseqc switches (i.e. 22KHz tone burst)
            {
                modulationType = BurstModulationType.TONE_BURST_UNMODULATED;
            }
            else
            {
                modulationType = BurstModulationType.TONE_BURST_MODULATED;        //default to tone_burst_modulated
            }
            byte toneDataBurst = 2;

            if (lnbNumber == 1)                                                   // mo tone/data burst is the default
            {
                toneDataBurst = 0;                                                // tone burst for simple A
            }
            else
            {
                if (lnbNumber == 2)
                {
                    toneDataBurst = 1;                                            // data burst for simple B
                }
            }

            byte[] commandBytes = GetCommand(lnbNumber, tuningSpec);

            bool commandReply = sendCommand(commandBytes, modulationType, toneDataBurst);

            if (!commandReply)
            {
                return(false);
            }

            commandReply = sendCommand(commandBytes, modulationType, toneDataBurst);
            if (!commandReply)
            {
                return(false);
            }

            commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
            {
                return(true);
            }

            Thread.Sleep(150);
            commandReply = sendCommand(commandBytes, modulationType, toneDataBurst);
            if (commandReply)
            {
                Thread.Sleep(150);
                commandReply = sendCommand(commandBytes, modulationType, toneDataBurst);
            }

            return(commandReply);
        }
        internal static DVBS2HandlerBase GetDVBS2Handler(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest, Tuner tuner)
        {
            DVBS2HandlerBase dvbs2Handler = getDVBS2Handler(tunerFilter, tuner);
            if (dvbs2Handler == null)
            {
                Logger.Instance.Write("No DVB-S2 handler available - parameters not set");
                return (null);
            }

            Logger.Instance.Write("Created " + dvbs2Handler.Description + " DVB-S2 handler");

            return(dvbs2Handler);
        }
Exemple #10
0
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            byte disEqcPort = 0;

            switch (port)
            {
            case "A":
                disEqcPort = 1;
                break;

            case "B":
                disEqcPort = 2;
                break;

            case "AA":
                disEqcPort = 1;
                break;

            case "AB":
                disEqcPort = 2;
                break;

            case "BA":
                disEqcPort = 3;
                break;

            case "BB":
                disEqcPort = 4;
                break;
            }

            byte turnon22Khz = 0;
            bool isHiBand    = false;

            if (tuningSpec.Frequency.Frequency >= (((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.LNBSwitchFrequency))
            {
                isHiBand    = true;
                turnon22Khz = 2;
            }
            else
            {
                turnon22Khz = 1;
            }

            Logger.Instance.Write("Twinhan/TechniSat high band: " + isHiBand + " 22Khz: " + turnon22Khz);

            setLnbData(true, turnon22Khz, disEqcPort, ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish);

            return(sendDiseqcCommand(disEqcPort, isHiBand, tuningSpec));
        }
        internal static DVBS2HandlerBase GetDVBS2Handler(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest, Tuner tuner)
        {
            DVBS2HandlerBase dvbs2Handler = getDVBS2Handler(tunerFilter, tuner);

            if (dvbs2Handler == null)
            {
                Logger.Instance.Write("No DVB-S2 handler available - parameters not set");
                return(null);
            }

            Logger.Instance.Write("Created " + dvbs2Handler.Description + " DVB-S2 handler");

            return(dvbs2Handler);
        }
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
                return (true);

            IBDA_DigitalDemodulator demodulator = FindDemodulator("Twinhan/TechniSat", tunerFilter);
            if (demodulator == null)
            {
                Logger.Instance.Write("Twinhan/TechniSat DVB-S2 handler: Demodulator not located");
                return (false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (modulationType)
            {
                case ModulationType.ModQpsk:
                    modulationType = ModulationType.Mod8Vsb;
                    break;
                case ModulationType.Mod8Psk:
                    modulationType = ModulationType.Mod8Vsb;
                    break;
                case ModulationType.Mod16Apsk:
                    modulationType = ModulationType.Mod16Vsb;
                    break;
                case ModulationType.Mod32Apsk:
                    modulationType = ModulationType.ModOqpsk;
                    break;
                default:
                    break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("Twinhan/TechniSat DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return (false);
                }
                else
                    Logger.Instance.Write("Twinhan/TechniSat DVB-S2 handler: Modulation type changed to " + modulationType);
            }
            else
                Logger.Instance.Write("Twinhan/TechniSat DVB-S2 handler: Modulation type not changed");

            return (true);
        }
        internal override bool ClearDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IBDA_DigitalDemodulator demodulator = FindDemodulator("Hauppauge", tunerFilter);

            if (demodulator == null)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Demodulator not located");
                return(false);
            }

            ModulationType modulationType = tuningSpec.NativeModulation;

            reply = demodulator.put_ModulationType(ref modulationType);
            if (reply != 0)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                return(false);
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type set to " + modulationType);
            }

            IntPtr commandBuffer  = Marshal.AllocCoTaskMem(1024);
            IntPtr instanceBuffer = Marshal.AllocCoTaskMem(1024);

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            Marshal.WriteInt32(commandBuffer, (int)DirectShowAPI.Pilot.NotSet);
            reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_PILOT, instanceBuffer, 32, commandBuffer, 4);
            if (reply != 0)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Pilot command failed error code 0x" + reply.ToString("X"));
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Pilot set to off");
            }

            return(reply == 0);
        }
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            bool commandReply = sendCommand(1, GetCommand(lnbNumber, tuningSpec));

            if (!commandReply)
            {
                return(false);
            }

            byte[] commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
            {
                return(true);
            }

            return(sendCommand(2, commandBytes));
        }
        private bool processCommands(string commands, TuningSpec tuningSpec)
        {
            string[] commandStrings = commands.Split(new char[] { ':' });

            foreach (string commandString in commandStrings)
            {
                byte[] command = GetCommand(commandString.Trim());
                bool   reply   = sendCommand(command, tuningSpec.NativeSignalPolarization);
                if (!reply)
                {
                    return(false);
                }

                Thread.Sleep(150);
            }

            return(true);
        }
Exemple #16
0
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="tuningSpec">A tuning spec instance.</param>
        /// <param name="port">The LNB port (eg AB).</param>
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            if (!cardCapable)
            {
                return(true);
            }

            int lnbNumber = GetLnbNumber(port);

            if (lnbNumber != -1)
            {
                return(processPort(lnbNumber, tuningSpec));
            }
            else
            {
                return(processCommands(port));
            }
        }
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            bool commandReply = sendCommand(GetCommand(lnbNumber, tuningSpec), tuningSpec.NativeSignalPolarization);

            if (!commandReply)
            {
                return(false);
            }

            byte[] commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
            {
                return(true);
            }

            Thread.Sleep(150);

            return(sendCommand(commandBytes, tuningSpec.NativeSignalPolarization));
        }
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="tuningSpec">A tuning spec instance.</param>
        /// <param name="port">The LNB port (eg AB).</param>
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            if (commandInterface == null)
            {
                return(true);
            }

            disableDiseqcCommands(tunerFilter);

            int lnbNumber = GetLnbNumber(port);

            if (lnbNumber != -1)
            {
                return(processPort(lnbNumber, tuningSpec));
            }
            else
            {
                return(processCommands(port));
            }
        }
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            bool commandReply = sendCommand(GetCommand(lnbNumber, tuningSpec), false);

            if (!commandReply)
            {
                CloseDevice(deviceNumber);
                return(false);
            }

            byte[] commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
            {
                CloseDevice(deviceNumber);
                return(true);
            }

            Thread.Sleep(150);

            return(sendCommand(commandBytes, true));
        }
        protected byte[] GetSecondCommand(int lnbNumber, TuningSpec tuningSpec)
        {
            byte[] commandBytes = new byte[4] {
                0xe0, 0x10, 0x39, 0x00
            };

            if (lnbNumber < 21 || lnbNumber > 36)
            {
                return(null);
            }
            else
            {
                if (lnbNumber >= 21 && lnbNumber <= 24)
                {
                    commandBytes[3] = 0;
                }
                else
                {
                    if (lnbNumber >= 25 && lnbNumber <= 28)
                    {
                        commandBytes[3] = 1;
                    }
                    else
                    {
                        if (lnbNumber >= 29 && lnbNumber <= 32)
                        {
                            commandBytes[3] = 2;
                        }
                        else
                        {
                            commandBytes[3] = 3;
                        }
                    }
                }
            }

            return(commandBytes);
        }
        internal static SwitchReply ProcessDisEqcSwitch(TuningSpec tuningSpec, Tuner tunerSpec, IBaseFilter tunerFilter)
        {
            DiseqcHandlerBase diseqcHandler = getDiseqcHandler(tunerSpec, tunerFilter);

            if (diseqcHandler == null)
            {
                Logger.Instance.Write("No DiSEqC handler available - switch request ignored");
                return(SwitchReply.NoHandler);
            }

            Logger.Instance.Write("Created " + diseqcHandler.Description + " DiSEqC handler");

            bool reply = diseqcHandler.SendDiseqcCommand(tuningSpec, ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.DiseqcSwitch);

            if (reply)
            {
                return(SwitchReply.OK);
            }
            else
            {
                return(SwitchReply.Failed);
            }
        }
        internal override bool ClearDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
                return (true);

            IBDA_DigitalDemodulator demodulator = FindDemodulator("Hauppauge", tunerFilter);
            if (demodulator == null)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Demodulator not located");
                return (false);
            }

            ModulationType modulationType = tuningSpec.NativeModulation;
            reply = demodulator.put_ModulationType(ref modulationType);
            if (reply != 0)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                return (false);
            }
            else
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type set to " + modulationType);

            IntPtr commandBuffer = Marshal.AllocCoTaskMem(1024);
            IntPtr instanceBuffer = Marshal.AllocCoTaskMem(1024);

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            Marshal.WriteInt32(commandBuffer, (int)DirectShowAPI.Pilot.NotSet);
            reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_PILOT, instanceBuffer, 32, commandBuffer, 4);
            if (reply != 0)
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Pilot command failed error code 0x" + reply.ToString("X"));
            else
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Pilot set to off");

            return (reply == 0);
        }
 internal abstract bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest);
        protected byte[] GetCommand(int lnbNumber, TuningSpec tuningSpec)
        {
            byte[] commandBytes = new byte[4] {
                0xe0, 0x10, 0x00, 0x00
            };

            if (lnbNumber < 5)
            {
                commandBytes[2] = 0x38;
                commandBytes[3] = 0xf0;

                //bit 0	(1)	: 0=low band, 1 = hi band
                //bit 1 (2) : 0=vertical, 1 = horizontal
                //bit 3 (4) : 0=satellite position A, 1=satellite position B
                //bit 4 (8) : 0=switch option A, 1=switch option  B
                // LNB    option  position
                // 1        A         A
                // 2        A         B
                // 3        B         A
                // 4        B         B

                bool hiBand       = (tuningSpec.Frequency.Frequency > ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.LNBSwitchFrequency);
                bool isHorizontal = ((tuningSpec.NativeSignalPolarization == Polarisation.LinearH) || (tuningSpec.NativeSignalPolarization == Polarisation.CircularL));

                commandBytes[3] |= (byte)(hiBand ? 1 : 0);
                commandBytes[3] |= (byte)((isHorizontal) ? 2 : 0);
                commandBytes[3] |= (byte)((lnbNumber - 1) << 2);
            }
            else
            {
                if (lnbNumber < 21)
                {
                    commandBytes[2] = 0x39;
                    commandBytes[3] = (byte)(lnbNumber - 5);
                }
                else
                {
                    commandBytes[2] = 0x38;
                    commandBytes[3] = 0xf0;

                    bool hiBand       = (tuningSpec.Frequency.Frequency > ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.LNBSwitchFrequency);
                    bool isHorizontal = ((tuningSpec.NativeSignalPolarization == Polarisation.LinearH) || (tuningSpec.NativeSignalPolarization == Polarisation.CircularL));

                    commandBytes[3] |= (byte)(hiBand ? 1 : 0);
                    commandBytes[3] |= (byte)((isHorizontal) ? 2 : 0);

                    if (lnbNumber >= 21 && lnbNumber <= 24)
                    {
                        commandBytes[3] |= (byte)((lnbNumber - 21) << 2);
                    }
                    else
                    {
                        if (lnbNumber >= 25 && lnbNumber <= 28)
                        {
                            commandBytes[3] |= (byte)((lnbNumber - 25) << 2);
                        }
                        else
                        {
                            if (lnbNumber >= 29 && lnbNumber <= 32)
                            {
                                commandBytes[3] |= (byte)((lnbNumber - 29) << 2);
                            }
                            else
                            {
                                commandBytes[3] |= (byte)((lnbNumber - 33) << 2);
                            }
                        }
                    }
                }
            }

            return(commandBytes);
        }
        private bool sendDiseqcCommand(byte disEqcPort, bool isHiBand, TuningSpec tuningSpec)
        {
            //bit 0	(1)	: 0=low band, 1 = hi band
            //bit 1 (2) : 0=vertical, 1 = horizontal
            //bit 3 (4) : 0=satellite position A, 1=satellite position B
            //bit 4 (8) : 0=switch option A, 1=switch option  B
            // LNB    option  position
            // 1        A         A
            // 2        A         B
            // 3        B         A
            // 4        B         B

            bool isHorizontal = ((tuningSpec.NativeSignalPolarization == Polarisation.LinearH) || (tuningSpec.NativeSignalPolarization == Polarisation.CircularL));

            byte command = 0xf0;
            command |= (byte)(isHiBand ? 1 : 0);
            command |= (byte)((isHorizontal) ? 2 : 0);
            command |= (byte)((disEqcPort - 1) << 2);

            byte[] commandBytes = new byte[4];
            commandBytes[0] = 0xe0;
            commandBytes[1] = 0x10;
            commandBytes[2] = 0x38;
            commandBytes[3] = command;

            return(sendCommand(commandBytes));
        }
        private static bool tuneFrequency(TuningFrequency frequency)
        {
            Logger.Instance.Write("Tuning to frequency " + frequency.Frequency + " on " + frequency.TunerType);

            TuningSpec tuningSpec;
            TunerNodeType tunerNodeType;
            int frequencyRetries = 0;

            if (frequency.TunerType == TunerType.Satellite)
            {
                tuningSpec = new TuningSpec(Satellite.CurrentSatellite, (SatelliteFrequency)frequency);
                tunerNodeType = TunerNodeType.Satellite;
            }
            else if (frequency.TunerType == TunerType.Terrestrial)
            {
                tuningSpec = new TuningSpec((TerrestrialFrequency)frequency);
                tunerNodeType = TunerNodeType.Terrestrial;
            }
            else
            {
                tuningSpec = new TuningSpec((CableFrequency)frequency);
                tunerNodeType = TunerNodeType.Cable;
            }

            bool finished = false;

            while (!finished)
            {
                graph = BDAGraph.FindTuner(RunParameters.SelectedTuner, tunerNodeType, tuningSpec);
                if (graph == null)
                {
                    Logger.Instance.Write("Tuner not available");
                    return (false);
                }

                TimeSpan timeout = new TimeSpan();
                bool done = false;
                bool locked = false;

                if (RunParameters.Options.Contains("NOSIGLOCK"))
                {
                    Logger.Instance.Write("Option NOSIGLOCK: No lock check, wait 5 seconds instead");
                    locked = true;
                    Thread.Sleep(5000);
                }
                else
                {
                    while (!done)
                    {
                        if (cancelGraph)
                        {
                            graph.Dispose();
                            return (false);
                        }

                        locked = graph.SignalLocked;
                        if (!locked)
                        {
                            int signalQuality = graph.SignalQuality;
                            if (signalQuality > 0)
                            {
                                Logger.Instance.Write("Signal not locked but signal quality > 0");
                                locked = true;
                                done = true;
                            }
                            else
                            {
                                Logger.Instance.Write("Signal not locked and signal quality not > 0");
                                Thread.Sleep(1000);
                                timeout = timeout.Add(new TimeSpan(0, 0, 1));
                                done = (timeout.TotalSeconds == RunParameters.LockTimeout.TotalSeconds);
                            }
                        }
                        else
                            done = true;
                    }
                }

                if (!locked)
                {
                    Logger.Instance.Write("Failed to acquire signal");
                    graph.Dispose();

                    if (frequencyRetries == 1)
                        return (false);
                    else
                    {
                        frequencyRetries++;
                        Logger.Instance.Write("Retrying frequency");
                    }
                }
                else
                {
                    finished = true;
                    Logger.Instance.Write("Signal acquired: lock is " + graph.SignalLocked + " quality is " + graph.SignalQuality + " strength is " + graph.SignalStrength);
                }
            }

            return (true);
        }
        private void doDump(object sender, DoWorkEventArgs e)
        {
            finalSize = -1;

            DumpParameters dumpParameters = e.Argument as DumpParameters;

            TunerNodeType tunerNodeType;
            TuningSpec tuningSpec;

            SatelliteFrequency satelliteFrequency = dumpParameters.ScanningFrequency as SatelliteFrequency;
            if (satelliteFrequency != null)
            {
                tunerNodeType = TunerNodeType.Satellite;
                tuningSpec = new TuningSpec((Satellite)satelliteFrequency.Provider, satelliteFrequency);
            }
            else
            {
                TerrestrialFrequency terrestrialFrequency = dumpParameters.ScanningFrequency as TerrestrialFrequency;
                if (terrestrialFrequency != null)
                {
                    tunerNodeType = TunerNodeType.Terrestrial;
                    tuningSpec = new TuningSpec(terrestrialFrequency);
                }
                else
                {
                    CableFrequency cableFrequency = dumpParameters.ScanningFrequency as CableFrequency;
                    if (cableFrequency != null)
                    {
                        tunerNodeType = TunerNodeType.Cable;
                        tuningSpec = new TuningSpec(cableFrequency);
                    }
                    else
                    {
                        AtscFrequency atscFrequency = dumpParameters.ScanningFrequency as AtscFrequency;
                        if (atscFrequency != null)
                        {
                            if (atscFrequency.TunerType == TunerType.ATSC)
                                tunerNodeType = TunerNodeType.ATSC;
                            else
                                tunerNodeType = TunerNodeType.Cable;
                            tuningSpec = new TuningSpec(atscFrequency);
                        }
                        else
                        {
                            ClearQamFrequency clearQamFrequency = dumpParameters.ScanningFrequency as ClearQamFrequency;
                            if (clearQamFrequency != null)
                            {
                                tunerNodeType = TunerNodeType.Cable;
                                tuningSpec = new TuningSpec(clearQamFrequency);
                            }
                            else
                            {
                                ISDBSatelliteFrequency isdbSatelliteFrequency = dumpParameters.ScanningFrequency as ISDBSatelliteFrequency;
                                if (isdbSatelliteFrequency != null)
                                {
                                    tunerNodeType = TunerNodeType.ISDBS;
                                    tuningSpec = new TuningSpec((Satellite)satelliteFrequency.Provider, isdbSatelliteFrequency);
                                }
                                else
                                {
                                    ISDBTerrestrialFrequency isdbTerrestrialFrequency = dumpParameters.ScanningFrequency as ISDBTerrestrialFrequency;
                                    if (isdbTerrestrialFrequency != null)
                                    {
                                        tunerNodeType = TunerNodeType.ISDBT;
                                        tuningSpec = new TuningSpec(isdbTerrestrialFrequency);
                                    }
                                    else
                                        throw (new InvalidOperationException("Tuning frequency not recognized"));
                                }
                            }
                        }
                    }
                }
            }

            Tuner currentTuner = null;
            bool finished = false;

            while (!finished)
            {
                if ((sender as BackgroundWorker).CancellationPending)
                {
                    Logger.Instance.Write("Scan abandoned by user");
                    e.Cancel = true;
                    resetEvent.Set();
                    return;
                }

                BDAGraph graph = BDAGraph.FindTuner(dumpParameters.Tuners,
                    tunerNodeType, tuningSpec, currentTuner, dumpParameters.RepeatDiseqc, dumpParameters.SwitchAfterPlay, dumpParameters.FileName);
                if (graph == null)
                {
                    Logger.Instance.Write("<e> No tuner able to tune frequency " + dumpParameters.ScanningFrequency.ToString());

                    frequencySelectionControl.Invoke(new ShowMessage(showMessage), "No tuner able to tune frequency " + dumpParameters.ScanningFrequency.ToString(),
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    finished = true;
                }
                else
                {
                    string tuneReply = checkTuning(graph, dumpParameters, sender as BackgroundWorker);

                    if ((sender as BackgroundWorker).CancellationPending)
                    {
                        Logger.Instance.Write("Scan abandoned by user");
                        graph.Dispose();
                        e.Cancel = true;
                        resetEvent.Set();
                        return;
                    }

                    if (tuneReply == null)
                    {
                        try
                        {
                            getData(graph, dumpParameters, sender as BackgroundWorker);

                        }
                        catch (IOException ex)
                        {
                            Logger.Instance.Write("<e> Failed to create dump file");
                            Logger.Instance.Write("<e> " + ex.Message);
                            frequencySelectionControl.Invoke(new ShowMessage(showMessage), "Failed to create dump file." +
                                Environment.NewLine + Environment.NewLine + ex.Message,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        graph.Dispose();

                        finished = true;
                    }
                    else
                    {
                        Logger.Instance.Write("Failed to tune frequency " + dumpParameters.ScanningFrequency.ToString());
                        graph.Dispose();
                        currentTuner = graph.Tuner;
                    }
                }
            }
            e.Cancel = true;
            resetEvent.Set();
        }
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            bool commandReply = sendCommand(GetCommand(lnbNumber, tuningSpec), tuningSpec.NativeSignalPolarization);
            if (!commandReply)
                return (false);

            byte[] commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
                return (true);

            Thread.Sleep(150);

            return (sendCommand(commandBytes, tuningSpec.NativeSignalPolarization));
        }
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IBDA_DigitalDemodulator demodulator = FindDemodulator("Hauppauge", tunerFilter);

            if (demodulator == null)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Demodulator not located");
                return(false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (tuningSpec.Modulation)
            {
            case Modulation.QPSK:
                BinaryConvolutionCodeRate codeRate;
                reply = demodulator.get_InnerFECRate(out codeRate);
                if (reply != 0)
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Get FEC rate failed error code 0x" + reply.ToString("X"));
                    return(false);
                }

                if (codeRate == BinaryConvolutionCodeRate.Rate9_10)
                {
                    modulationType = ModulationType.Mod32Qam;
                }
                else
                {
                    if (codeRate == BinaryConvolutionCodeRate.Rate8_9)
                    {
                        modulationType = ModulationType.Mod16Qam;
                    }
                    else
                    {
                        modulationType = ModulationType.ModBpsk;
                    }
                }
                break;

            case Modulation.PSK8:
                modulationType = ModulationType.ModNbc8Psk;
                break;

            default:
                break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return(false);
                }
                else
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type changed to " + modulationType);
                }
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type not changed");
            }

            IntPtr commandBuffer  = Marshal.AllocCoTaskMem(1024);
            IntPtr instanceBuffer = Marshal.AllocCoTaskMem(1024);

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            string setting;

            if (frequency.SymbolRate != 30000)
            {
                Marshal.WriteInt32(commandBuffer, (int)DsUtils.GetNativePilot(frequency.Pilot));
                setting = frequency.Pilot.ToString();
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Setting pilot to off for symbol rate of 30000");
                Marshal.WriteInt32(commandBuffer, (int)DirectShowAPI.Pilot.Off);
                setting = "Off";
            }
            reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_PILOT, instanceBuffer, 32, commandBuffer, 4);
            if (reply != 0)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Pilot command failed error code 0x" + reply.ToString("X"));
                return(false);
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Pilot set to " + setting);

                Marshal.WriteInt32(commandBuffer, (int)DsUtils.GetNativeRollOff(frequency.RollOff));
                reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_ROLL_OFF, instanceBuffer, 32, commandBuffer, 4);
                if (reply != 0)
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Rolloff command failed error code 0x" + reply.ToString("X"));
                    return(false);
                }
                else
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Rolloff set to " + frequency.RollOff);
                }
            }

            return(true);
        }
Exemple #30
0
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
                return (true);

            IntPtr commandBuffer = Marshal.AllocCoTaskMem(commandBufferLength);

            for (int index = 0; index < commandBufferLength; ++index)
                Marshal.WriteByte(commandBuffer, index, 0x00);

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            switch (frequency.RollOff)
            {
                case DomainObjects.RollOff.RollOff20:
                    Marshal.WriteInt32(commandBuffer, 0, 0);
                    break;
                case DomainObjects.RollOff.RollOff25:
                    Marshal.WriteInt32(commandBuffer, 0, 1);
                    break;
                case DomainObjects.RollOff.RollOff35:
                    Marshal.WriteInt32(commandBuffer, 0, 2);
                    break;
                default:
                    Marshal.WriteInt32(commandBuffer, 0, 0xff);
                    break;
            }

            switch (frequency.Pilot)
            {
                case DomainObjects.Pilot.Off:
                    Marshal.WriteInt32(commandBuffer, 4, 0);
                    break;
                case DomainObjects.Pilot.On:
                    Marshal.WriteInt32(commandBuffer, 4, 1);
                    break;
                default:
                    Marshal.WriteInt32(commandBuffer, 4, 1);
                    break;
            }

            Marshal.WriteInt32(commandBuffer, 8, 2);            // 0 = auto 1 = DVB-S 2 = DVB-S2
            Marshal.WriteInt32(commandBuffer, 12, (int)tuningSpec.NativeFECRate);
            Marshal.WriteInt32(commandBuffer, 16, (int)ModulationType.ModBpsk);            //

            StringBuilder commandString = new StringBuilder("TBS DVB-S2 handler: sending command 0x");
            byte[] commandBytes = new byte[20];
            for (int index = 0; index < 20; ++index)
            {
                int commandByte = Marshal.ReadByte(commandBuffer, index);
                if (commandByte < 0x10)
                    commandString.Append("0" + commandByte.ToString("X"));
                else
                    commandString.Append(commandByte.ToString("X"));
            }
            Logger.Instance.Write(commandString.ToString());

            string getSet;

            if (useGet)
            {
                int bytesReturned;
                reply = propertySet.Get(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_NBC_PARAMS, commandBuffer, commandBufferLength, commandBuffer, commandBufferLength, out bytesReturned);
                getSet = "Get";
            }
            else
            {
                reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_NBC_PARAMS, commandBuffer, commandBufferLength, commandBuffer, commandBufferLength);
                getSet = "Set";
            }

            if (reply != 0)
                Logger.Instance.Write("TBS DVB-S2 handler: " + getSet + " command failed error code 0x" + reply.ToString("X"));
            else
                Logger.Instance.Write("TBS DVB-S2 handler: " + getSet + " command succeeded");

            return (reply == 0);
        }
        protected byte[] GetCommand(int lnbNumber, TuningSpec tuningSpec)
        {
            byte[] commandBytes = new byte[4] { 0xe0, 0x10, 0x00, 0x00 };

            if (lnbNumber < 5)
            {
                commandBytes[2] = 0x38;
                commandBytes[3] = 0xf0;

                //bit 0	(1)	: 0=low band, 1 = hi band
                //bit 1 (2) : 0=vertical, 1 = horizontal
                //bit 3 (4) : 0=satellite position A, 1=satellite position B
                //bit 4 (8) : 0=switch option A, 1=switch option  B
                // LNB    option  position
                // 1        A         A
                // 2        A         B
                // 3        B         A
                // 4        B         B

                bool hiBand = (tuningSpec.Frequency.Frequency > ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.LNBSwitchFrequency);
                bool isHorizontal = ((tuningSpec.NativeSignalPolarization == Polarisation.LinearH) || (tuningSpec.NativeSignalPolarization == Polarisation.CircularL));

                commandBytes[3] |= (byte)(hiBand ? 1 : 0);
                commandBytes[3] |= (byte)((isHorizontal) ? 2 : 0);
                commandBytes[3] |= (byte)((lnbNumber - 1) << 2);
            }
            else
            {
                if (lnbNumber < 21)
                {
                    commandBytes[2] = 0x39;
                    commandBytes[3] = (byte)(lnbNumber - 5);
                }
                else
                {
                    commandBytes[2] = 0x38;
                    commandBytes[3] = 0xf0;

                    bool hiBand = (tuningSpec.Frequency.Frequency > ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.LNBSwitchFrequency);
                    bool isHorizontal = ((tuningSpec.NativeSignalPolarization == Polarisation.LinearH) || (tuningSpec.NativeSignalPolarization == Polarisation.CircularL));

                    commandBytes[3] |= (byte)(hiBand ? 1 : 0);
                    commandBytes[3] |= (byte)((isHorizontal) ? 2 : 0);

                    if (lnbNumber >= 21 && lnbNumber <= 24)
                        commandBytes[3] |= (byte)((lnbNumber - 21) << 2);
                    else
                    {
                        if (lnbNumber >= 25 && lnbNumber <= 28)
                            commandBytes[3] |= (byte)((lnbNumber - 25) << 2);
                        else
                        {
                            if (lnbNumber >= 29 && lnbNumber <= 32)
                                commandBytes[3] |= (byte)((lnbNumber - 29) << 2);
                            else
                                commandBytes[3] |= (byte)((lnbNumber - 33) << 2);
                        }
                    }
                }
            }

            return (commandBytes);
        }
Exemple #32
0
        private static BDAGraph checkTunerAvailability(Tuner tuner, TuningSpec tuningSpec, bool repeatDiseqc, bool switchAfterPlay, string dumpFileName)
        {
            if (!RunParameters.Instance.DebugIDs.Contains("USEDVBLINK"))
            {
                if (tuner.Name.ToUpperInvariant().StartsWith("DVBLINK"))
                    return (null);
            }

            BDAGraph graph = new BDAGraph("BDA", tuningSpec, tuner, dumpFileName);
            graph.LogFilters();

            if (tuningSpec.Frequency.TunerType == TunerType.Satellite && ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.DiseqcSwitch != null)
                return (checkDiseqcAvailability(graph, tuner, tuningSpec, repeatDiseqc, switchAfterPlay));
            else
            {
                if (graph.Play())
                    return (graph);
                else
                {
                    Logger.Instance.Write("Tuner in use - ignored: " + tuner.Name);
                    graph.Dispose();
                    return (null);
                }
            }
        }
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="tuningSpec">A tuning spec instance.</param>
        /// <param name="port">The LNB port (eg AB).</param>        
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            if (!cardCapable)
                return (true);

            int lnbNumber = GetLnbNumber(port);
            if (lnbNumber != -1)
                return (processPort(lnbNumber, tuningSpec));
            else
                return (processCommands(port));
        }
        protected byte[] GetSecondCommand(int lnbNumber, TuningSpec tuningSpec)
        {
            byte[] commandBytes = new byte[4] { 0xe0, 0x10, 0x39, 0x00 };

            if (lnbNumber < 21 || lnbNumber > 36)
                return(null);
            else
            {
                if (lnbNumber >= 21 && lnbNumber <= 24)
                    commandBytes[3] = 0;
                else
                {
                    if (lnbNumber >= 25 && lnbNumber <= 28)
                        commandBytes[3] = 1;
                    else
                    {
                        if (lnbNumber >= 29 && lnbNumber <= 32)
                            commandBytes[3] = 2;
                        else
                            commandBytes[3] = 3;
                    }
                }
            }

            return (commandBytes);
        }
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
                return (true);

            IBDA_DigitalDemodulator demodulator = FindDemodulator("DigitalEverywhere", tunerFilter);
            if (demodulator == null)
            {
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Demodulator not located");
                return (false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (tuningSpec.Modulation)
            {
                case Modulation.QPSK:
                    modulationType = ModulationType.ModNbcQpsk;
                    break;
                case Modulation.PSK8:
                    modulationType = ModulationType.ModNbc8Psk;
                    break;
                default:
                    break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return (false);
                }
                else
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Modulation type changed to " + modulationType);
            }
            else
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Modulation type not changed");

            BinaryConvolutionCodeRate oldCodeRate;
            reply = demodulator.get_InnerFECRate(out oldCodeRate);
            if (reply != 0)
            {
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Get FEC Rate failed error code 0x" + reply.ToString("X"));
                return (false);
            }

            SatelliteFrequency satelliteFrequency = tuningSpec.Frequency as SatelliteFrequency;

            BinaryConvolutionCodeRate newCodeRate = oldCodeRate;

            if (satelliteFrequency.Pilot == DomainObjects.Pilot.Off)
                newCodeRate+= 64;
            else
            {
                if (satelliteFrequency.Pilot == DomainObjects.Pilot.On)
                    newCodeRate+= 128;
            }

            switch (satelliteFrequency.RollOff)
            {
                case DomainObjects.RollOff.RollOff20:
                    newCodeRate += 16;
                    break;
                case DomainObjects.RollOff.RollOff25:
                    newCodeRate += 32;
                    break;
                case DomainObjects.RollOff.RollOff35:
                    newCodeRate += 48;
                    break;
                default:
                    break;
            }

            if (oldCodeRate != newCodeRate)
            {
                reply = demodulator.put_InnerFECRate(newCodeRate);
                if (reply != 0)
                {
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Set FEC Rate failed error code 0x" + reply.ToString("X"));
                    return (false);
                }

                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: FEC Rate changed from " + oldCodeRate + " to " + newCodeRate);
            }

            return (true);
        }
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="tuningSpec">A tuning spec instance.</param>
        /// <param name="port">The Diseqc port ( eg AB).</param>        
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            if (!cardCapable)
                return (false);

            switch (port)
            {
                case "AA":
                    return(sendRangeCommand(0x00));
                case "AB":
                    return(sendRangeCommand(0x01));
                case "BA":
                    return(sendRangeCommand(0x0100));
                case "BB":
                    return(sendRangeCommand(0x0101));
                case "A":
                    return(sendRangeCommand(0x00));
                case "B":
                    return(sendRangeCommand(0x01));
                default:
                    return (false);
            }
        }
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
                return (true);

            IBDA_DigitalDemodulator demodulator = FindDemodulator("Hauppauge", tunerFilter);
            if (demodulator == null)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Demodulator not located");
                return (false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (tuningSpec.Modulation)
            {
                case Modulation.QPSK:
                    BinaryConvolutionCodeRate codeRate;
                    reply = demodulator.get_InnerFECRate(out codeRate);
                    if (reply != 0)
                    {
                        Logger.Instance.Write("Hauppauge DVB-S2 handler: Get FEC rate failed error code 0x" + reply.ToString("X"));
                        return (false);
                    }

                    if (codeRate == BinaryConvolutionCodeRate.Rate9_10)
                        modulationType = ModulationType.Mod32Qam;
                    else
                    {
                        if (codeRate == BinaryConvolutionCodeRate.Rate8_9)
                            modulationType = ModulationType.Mod16Qam;
                        else
                            modulationType = ModulationType.ModBpsk;
                    }
                    break;
                case Modulation.PSK8:
                    modulationType = ModulationType.ModNbc8Psk;
                    break;
                default:
                    break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return (false);
                }
                else
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type changed to " + modulationType);
            }
            else
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Modulation type not changed");

            IntPtr commandBuffer = Marshal.AllocCoTaskMem(1024);
            IntPtr instanceBuffer = Marshal.AllocCoTaskMem(1024);

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            string setting;

            if (frequency.SymbolRate != 30000)
            {
                Marshal.WriteInt32(commandBuffer, (int)DsUtils.GetNativePilot(frequency.Pilot));
                setting = frequency.Pilot.ToString();
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Setting pilot to off for symbol rate of 30000");
                Marshal.WriteInt32(commandBuffer, (int)DirectShowAPI.Pilot.Off);
                setting = "Off";
            }
            reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_PILOT, instanceBuffer, 32, commandBuffer, 4);
            if (reply != 0)
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Pilot command failed error code 0x" + reply.ToString("X"));
                return (false);
            }
            else
            {
                Logger.Instance.Write("Hauppauge DVB-S2 handler: Pilot set to " + setting);

                Marshal.WriteInt32(commandBuffer, (int)DsUtils.GetNativeRollOff(frequency.RollOff));
                reply = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_ROLL_OFF, instanceBuffer, 32, commandBuffer, 4);
                if (reply != 0)
                {
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Set Rolloff command failed error code 0x" + reply.ToString("X"));
                    return (false);
                }
                else
                    Logger.Instance.Write("Hauppauge DVB-S2 handler: Rolloff set to " + frequency.RollOff);
            }

            return (true);
        }
        /// <summary>
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (commandInterface == null)
                return (false);

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            DirectShowAPI.Pilot pilot = DsUtils.GetNativePilot(frequency.Pilot);
            reply = commandInterface.put_Pilot(pilot);
            if (reply != 0)
                Logger.Instance.Write("Win7API DVB-S2 handler: Set Pilot command failed error code 0x" + reply.ToString("X"));
            else
            {
                Logger.Instance.Write("Win7API DVB-S2 handler: Set Pilot command succeeded");

                DirectShowAPI.RollOff rollOff = DsUtils.GetNativeRollOff(frequency.RollOff);
                reply = commandInterface.put_RollOff(ref rollOff);
                if (reply != 0)
                    Logger.Instance.Write("Win7API DVB-S2 handler: Set Rolloff command failed error code 0x" + reply.ToString("X"));
                else
                    Logger.Instance.Write("Win7API DVB-S2 handler: Set Rolloff command succeeded");
            }

            return (reply == 0);
        }
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            byte disEqcPort = 0;

            switch (port)
            {
                case "A":
                    disEqcPort = 1;
                    break;
                case "B":
                    disEqcPort = 2;
                    break;
                case "AA":
                    disEqcPort = 1;
                    break;
                case "AB":
                    disEqcPort = 2;
                    break;
                case "BA":
                    disEqcPort = 3;
                    break;
                case "BB":
                    disEqcPort = 4;
                    break;
            }

            byte turnon22Khz = 0;
            bool isHiBand = false;

            if (tuningSpec.Frequency.Frequency >= (((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.LNBSwitchFrequency))
            {
                isHiBand = true;
                turnon22Khz = 2;

            }
            else
                turnon22Khz = 1;

            Logger.Instance.Write("Twinhan/TechniSat high band: " + isHiBand + " 22Khz: " + turnon22Khz);

            setLnbData(true, turnon22Khz, disEqcPort, ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish);

            return(sendDiseqcCommand(disEqcPort, isHiBand, tuningSpec));
        }
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            BurstModulationType modulationType;
            if (lnbNumber == 1)                                                   //for simple diseqc switches (i.e. 22KHz tone burst)
                modulationType = BurstModulationType.TONE_BURST_UNMODULATED;
            else
                modulationType = BurstModulationType.TONE_BURST_MODULATED;        //default to tone_burst_modulated

            bool commandReply = sendCommand(GetCommand(lnbNumber, tuningSpec), modulationType);
            if (!commandReply)
                return (false);

            byte[] commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
                return (true);

            Thread.Sleep(150);

            return(sendCommand(commandBytes, BurstModulationType.TONE_BURST_MODULATED));
        }
        private bool processCommands(string commands, TuningSpec tuningSpec)
        {
            string[] commandStrings = commands.Split(new char[] { ':' });

            foreach (string commandString in commandStrings)
            {
                byte[] command = GetCommand(commandString.Trim());
                bool reply = sendCommand(command, tuningSpec.NativeSignalPolarization);
                if (!reply)
                    return (false);

                Thread.Sleep(150);
            }

            return (true);
        }
Exemple #42
0
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IntPtr commandBuffer = Marshal.AllocCoTaskMem(commandBufferLength);

            for (int index = 0; index < commandBufferLength; ++index)
            {
                Marshal.WriteByte(commandBuffer, index, 0x00);
            }

            SatelliteFrequency frequency = tuningSpec.Frequency as SatelliteFrequency;

            switch (frequency.RollOff)
            {
            case DomainObjects.RollOff.RollOff20:
                Marshal.WriteInt32(commandBuffer, 0, 0);
                break;

            case DomainObjects.RollOff.RollOff25:
                Marshal.WriteInt32(commandBuffer, 0, 1);
                break;

            case DomainObjects.RollOff.RollOff35:
                Marshal.WriteInt32(commandBuffer, 0, 2);
                break;

            default:
                Marshal.WriteInt32(commandBuffer, 0, 0xff);
                break;
            }

            switch (frequency.Pilot)
            {
            case DomainObjects.Pilot.Off:
                Marshal.WriteInt32(commandBuffer, 4, 0);
                break;

            case DomainObjects.Pilot.On:
                Marshal.WriteInt32(commandBuffer, 4, 1);
                break;

            default:
                Marshal.WriteInt32(commandBuffer, 4, 1);
                break;
            }

            Marshal.WriteInt32(commandBuffer, 8, 2);                            // 0 = auto 1 = DVB-S 2 = DVB-S2
            Marshal.WriteInt32(commandBuffer, 12, (int)tuningSpec.NativeFECRate);
            Marshal.WriteInt32(commandBuffer, 16, (int)ModulationType.ModBpsk); //

            StringBuilder commandString = new StringBuilder("TBS DVB-S2 handler: sending command 0x");

            byte[] commandBytes = new byte[20];
            for (int index = 0; index < 20; ++index)
            {
                int commandByte = Marshal.ReadByte(commandBuffer, index);
                if (commandByte < 0x10)
                {
                    commandString.Append("0" + commandByte.ToString("X"));
                }
                else
                {
                    commandString.Append(commandByte.ToString("X"));
                }
            }
            Logger.Instance.Write(commandString.ToString());

            string getSet;

            if (useGet)
            {
                int bytesReturned;
                reply  = propertySet.Get(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_NBC_PARAMS, commandBuffer, commandBufferLength, commandBuffer, commandBufferLength, out bytesReturned);
                getSet = "Get";
            }
            else
            {
                reply  = propertySet.Set(bdaTunerExtensionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_NBC_PARAMS, commandBuffer, commandBufferLength, commandBuffer, commandBufferLength);
                getSet = "Set";
            }

            if (reply != 0)
            {
                Logger.Instance.Write("TBS DVB-S2 handler: " + getSet + " command failed error code 0x" + reply.ToString("X"));
            }
            else
            {
                Logger.Instance.Write("TBS DVB-S2 handler: " + getSet + " command succeeded");
            }

            return(reply == 0);
        }
 internal abstract bool SendDiseqcCommand(TuningSpec tuningSpec, string port);
Exemple #44
0
        internal override bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
        {
            if (!dvbs2Capable)
            {
                return(true);
            }

            IBDA_DigitalDemodulator demodulator = FindDemodulator("DigitalEverywhere", tunerFilter);

            if (demodulator == null)
            {
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Demodulator not located");
                return(false);
            }

            ModulationType modulationType = ModulationType.ModNotSet;

            switch (tuningSpec.Modulation)
            {
            case Modulation.QPSK:
                modulationType = ModulationType.ModNbcQpsk;
                break;

            case Modulation.PSK8:
                modulationType = ModulationType.ModNbc8Psk;
                break;

            default:
                break;
            }

            if (modulationType != ModulationType.ModNotSet)
            {
                reply = demodulator.put_ModulationType(ref modulationType);
                if (reply != 0)
                {
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Set Modulation Type failed error code 0x" + reply.ToString("X"));
                    return(false);
                }
                else
                {
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Modulation type changed to " + modulationType);
                }
            }
            else
            {
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Modulation type not changed");
            }

            BinaryConvolutionCodeRate oldCodeRate;

            reply = demodulator.get_InnerFECRate(out oldCodeRate);
            if (reply != 0)
            {
                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Get FEC Rate failed error code 0x" + reply.ToString("X"));
                return(false);
            }

            SatelliteFrequency satelliteFrequency = tuningSpec.Frequency as SatelliteFrequency;

            BinaryConvolutionCodeRate newCodeRate = oldCodeRate;

            if (satelliteFrequency.Pilot == DomainObjects.Pilot.Off)
            {
                newCodeRate += 64;
            }
            else
            {
                if (satelliteFrequency.Pilot == DomainObjects.Pilot.On)
                {
                    newCodeRate += 128;
                }
            }

            switch (satelliteFrequency.RollOff)
            {
            case DomainObjects.RollOff.RollOff20:
                newCodeRate += 16;
                break;

            case DomainObjects.RollOff.RollOff25:
                newCodeRate += 32;
                break;

            case DomainObjects.RollOff.RollOff35:
                newCodeRate += 48;
                break;

            default:
                break;
            }

            if (oldCodeRate != newCodeRate)
            {
                reply = demodulator.put_InnerFECRate(newCodeRate);
                if (reply != 0)
                {
                    Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: Set FEC Rate failed error code 0x" + reply.ToString("X"));
                    return(false);
                }

                Logger.Instance.Write("DigitalEverywhere DVB-S2 handler: FEC Rate changed from " + oldCodeRate + " to " + newCodeRate);
            }

            return(true);
        }
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="tuningSpec">A tuning spec instance.</param>
        /// <param name="port">The LNB port (eg AB).</param>        
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            if (commandInterface == null)
                return (true);

            int reply = commandInterface.put_EnableDiseqCommands(1);
            if (reply != 0)
                Logger.Instance.Write("DiSEqC enble command failed: error code 0x" + reply.ToString("X"));
            else
            {
                int lnbNumber = GetLnbNumber(port);
                reply = commandInterface.put_DiseqLNBSource(lnbNumber - 1);
                if (reply != 0)
                    Logger.Instance.Write("DiSEqC command failed: error code 0x" + reply.ToString("X"));
            }

            return (reply == 0);
        }
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            bool commandReply = sendCommand(GetCommand(lnbNumber, tuningSpec), false);
            if (!commandReply)
            {
                CloseDevice(deviceNumber);
                return (false);
            }

            byte[] commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
            {
                CloseDevice(deviceNumber);
                return (true);
            }

            Thread.Sleep(150);

            return (sendCommand(commandBytes, true));
        }
Exemple #47
0
        /// <summary>
        /// Sends the diseq command.
        /// </summary>
        /// <param name="tuningSpec">A tuning spec instance.</param>
        /// <param name="port">The LNB port (eg AB).</param>        
        internal override bool SendDiseqcCommand(TuningSpec tuningSpec, string port)
        {
            if (commandInterface == null)
                return (true);

            disableDiseqcCommands(tunerFilter);

            int lnbNumber = GetLnbNumber(port);
            if (lnbNumber != -1)
                return(processPort(lnbNumber, tuningSpec));
            else
                return(processCommands(port));
        }
        internal static SwitchReply ProcessDisEqcSwitch(TuningSpec tuningSpec, Tuner tunerSpec, IBaseFilter tunerFilter)
        {
            DiseqcHandlerBase diseqcHandler = getDiseqcHandler(tunerSpec, tunerFilter);
            if (diseqcHandler == null)
            {
                Logger.Instance.Write("No DiSEqC handler available - switch request ignored");
                return (SwitchReply.NoHandler);
            }

            Logger.Instance.Write("Created " + diseqcHandler.Description + " DiSEqC handler");

            bool reply = diseqcHandler.SendDiseqcCommand(tuningSpec, ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.DiseqcSwitch);
            if (reply)
                return (SwitchReply.OK);
            else
                return (SwitchReply.Failed);
        }
Exemple #49
0
        private bool processPort(int lnbNumber,TuningSpec tuningSpec)
        {
            bool commandReply = sendCommand(1, GetCommand(lnbNumber, tuningSpec));
            if (!commandReply)
                return (false);

            byte[] commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
                return (true);

            return (sendCommand(2, commandBytes));
        }
 internal abstract bool SendDiseqcCommand(TuningSpec tuningSpec, string port);
 internal virtual bool ClearDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
 {
     Logger.Instance.Write("No DVB-S2 processing required");
     return(true);
 }
        private bool processPort(int lnbNumber, TuningSpec tuningSpec)
        {
            BurstModulationType modulationType;
            if (lnbNumber == 1)                                                   //for simple diseqc switches (i.e. 22KHz tone burst)
                modulationType = BurstModulationType.TONE_BURST_UNMODULATED;
            else
                modulationType = BurstModulationType.TONE_BURST_MODULATED;        //default to tone_burst_modulated

            byte toneDataBurst = 2;
            if (lnbNumber == 1)                                                   // mo tone/data burst is the default
                toneDataBurst = 0;                                                // tone burst for simple A
            else
            {
                if (lnbNumber == 2)
                    toneDataBurst = 1;                                            // data burst for simple B
            }

            byte[] commandBytes = GetCommand(lnbNumber, tuningSpec);

            bool commandReply = sendCommand(commandBytes, modulationType, toneDataBurst);
            if (!commandReply)
                return (false);

            commandReply = sendCommand(commandBytes, modulationType, toneDataBurst);
            if (!commandReply)
                return (false);

            commandBytes = GetSecondCommand(lnbNumber, tuningSpec);
            if (commandBytes == null)
                return (true);

            Thread.Sleep(150);
            commandReply = sendCommand(commandBytes, modulationType, toneDataBurst);
            if (commandReply)
            {
                Thread.Sleep(150);
                commandReply = sendCommand(commandBytes, modulationType, toneDataBurst);
            }

            return (commandReply);
        }
 internal virtual bool ClearDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest)
 {
     Logger.Instance.Write("No DVB-S2 processing required");
     return (true);
 }
 internal abstract bool SetDVBS2Parameters(TuningSpec tuningSpec, IBaseFilter tunerFilter, ITuneRequest tuneRequest);
Exemple #55
0
        private static BDAGraph checkDiseqcAvailability(BDAGraph graph, Tuner tuner, TuningSpec tuningSpec, bool repeatDiseqc, bool switchAfterPlay)
        {
            if (RunParameters.Instance.Options.Contains("USESAFEDISEQC"))
            {
                Logger.Instance.Write("Processing using safe DiSEqC switching method");

                if (!graph.Play())
                {
                    Logger.Instance.Write("Tuner in use - ignored: " + tuner.Name);
                    graph.Dispose();
                    return (null);
                }

                graph.Dispose();
                graph = new BDAGraph("BDA", tuningSpec, tuner);
            }
            else
                Logger.Instance.Write("Processing using unsafe DiSEqC switching method");

            SwitchReply switchReply = SwitchReply.NotSet;

            if (!switchAfterPlay)
            {
                Logger.Instance.Write("Processing Diseqc command before running graph");
                switchReply = DiseqcHandlerBase.ProcessDisEqcSwitch(tuningSpec, tuner, graph.tunerFilter);
                Thread.Sleep(500);
            }

            if (!graph.Play())
            {
                Logger.Instance.Write("Tuner in use - ignored: " + tuner.Name);
                graph.Dispose();
                return (null);
            }

            if (switchReply == SwitchReply.Failed && repeatDiseqc)
            {
                Logger.Instance.Write("Repeating DiSEqC command due to initial failure");
                switchReply = DiseqcHandlerBase.ProcessDisEqcSwitch(tuningSpec, tuner, graph.tunerFilter);
            }
            else
            {
                if (switchAfterPlay)
                {
                    Logger.Instance.Write("Processing Diseqc command after running graph");
                    switchReply = DiseqcHandlerBase.ProcessDisEqcSwitch(tuningSpec, tuner, graph.tunerFilter);
                }
            }

            return (graph);
        }