/// <summary>
        /// Wandelt eine Textdarstellung einer Gruppe von Quellen in eine
        /// Gruppeninstanz um.
        /// </summary>
        /// <returns>Die rekonstruierte Instanz.</returns>
        /// <exception cref="FormatException">Es wurde keine gültige Textdarstellung angegeben.</exception>
        public static T FromString <T>(string text) where T : SourceGroup
        {
            // None
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            // Helper
            T group;

            // Dispatch known types
            if (text.StartsWith("DVB-C"))
            {
                group = CableGroup.Parse(text) as T;
            }
            else if (text.StartsWith("DVB-T"))
            {
                group = TerrestrialGroup.Parse(text) as T;
            }
            else if (text.StartsWith("DVB-S"))
            {
                group = SatelliteGroup.Parse(text) as T;
            }
            else
            {
                group = null;
            }

            // Invalid
            if (null == group)
            {
                throw new FormatException(text);
            }

            // Report
            return(group);
        }
示例#2
0
        /// <summary>
        /// Wählt eine Quellgruppe aus.
        /// </summary>
        /// <param name="group">Díe Daten der Quellgruppe.</param>
        /// <param name="location">Die Wahl des Ursprungs, über den die Quellgruppe empfangen werden kann.</param>
        /// <returns>Gesetzt, wenn es sich um eine DVB-S Quellgruppe handelt.</returns>
        private Channel_S? Tune( SatelliteGroup group, SatelliteLocation location )
        {
            // Not us
            if (location == null)
                return null;
            if (group == null)
                return null;

            // Validate
            if (FrontendType != FrontendType.Satellite)
                throw new DVBException( "Expected " + FrontendType.ToString() + " Channel" );

            // Create channel
            var data =
                new Channel_S
                {
                    Mode = group.UsesS2Modulation ? DVBSMode.DVB_S2 : DVBSMode.DVB_S,
                    Inversion = SpectrumInversion.Auto,
                    SymbolRate = group.SymbolRate,
                    Frequency = group.Frequency,
                };


            // Attach to the DiSEqC setting
            var selector = StandardDiSEqC.FromSourceGroup( group, location );

            // See if the message is different from the last one
            if (!selector.Equals( m_lastMessage ))
            {
                // Remember
                m_lastMessage = selector.Clone();

                // As long as necessary
                for (int nCount = selector.Repeat; nCount-- > 0; Thread.Sleep( 120 ))
                {
                    // Send it
                    DVBException.ThrowOnError( _SendDiSEqCMsg( m_Class.ClassPointer, selector.Request, (byte) selector.Request.Length, selector.Burst ), "Could not send DiSEqC message" );

                    // Set repeat flag
                    if (selector.Request.Length > 0)
                        selector.Request[0] |= 1;
                }
            }

            // Calculated items
            data.b22kHz = (group.Frequency >= location.SwitchFrequency) ? 1 : 0;
            data.LOF = (0 == data.b22kHz) ? location.Frequency1 : location.Frequency2;

            // Power modes
            switch (group.Polarization)
            {
                case Polarizations.Horizontal: data.LNBPower = PowerMode.Horizontal; break;
                case Polarizations.Vertical: data.LNBPower = PowerMode.Vertical; break;
                case Polarizations.NotDefined: data.LNBPower = PowerMode.Off; break;
                default: throw new ArgumentException( group.Polarization.ToString(), "Polarization" );
            }

            // Process
            return data.SetChannel( this, false );
        }
示例#3
0
        /// <summary>
        /// Wählt eine Quellgruppe aus.
        /// </summary>
        /// <param name="group">Díe Daten der Quellgruppe.</param>
        /// <param name="location">Die Wahl des Ursprungs, über den die Quellgruppe empfangen werden kann.</param>
        /// <returns>Gesetzt, wenn es sich um eine DVB-S Quellgruppe handelt.</returns>
        private bool SendChannel( SatelliteGroup group, SatelliteLocation location )
        {
            // Not us
            if (location == null)
                return false;
            if (group == null)
                return false;

            // Validate
            if (FrontendType != FrontendType.Satellite)
                throw new DVBException( "Expected " + FrontendType.ToString() + " Channel" );

            // Create channel
            var channel =
                new Channel_S
                {
                    Inversion = SpectrumInversion.Auto,
                    SymbolRate = group.SymbolRate,
                    Frequency = group.Frequency,
                };

            // Attach to the DiSEqC setting
            var selector = StandardDiSEqC.FromSourceGroup( group, location );

            // See if the message is different from the last one
            if (!selector.Equals( m_lastMessage ))
            {
                // Remember
                m_lastMessage = selector.Clone();

                // As long as necessary
                for (int nCount = selector.Repeat; nCount-- > 0; Thread.Sleep( 120 ))
                {
                    // Send it
                    DVBException.ThrowOnError( CDVBFrontend_SendDiSEqCMsg( m_Class.ClassPointer, selector.Request, (byte) selector.Request.Length, selector.Burst ), "Could not send DiSEqC Message" );

                    // Set repeat flag
                    if (selector.Request.Length > 0)
                        selector.Request[0] |= 1;
                }
            }

            // Calculated items
            channel.b22kHz = (group.Frequency >= location.SwitchFrequency) ? 1 : 0;
            channel.LOF = (0 == channel.b22kHz) ? location.Frequency1 : location.Frequency2;

            // Power modes
            switch (group.Polarization)
            {
                case Polarizations.Horizontal: channel.LNBPower = PowerMode.Horizontal; break;
                case Polarizations.Vertical: channel.LNBPower = PowerMode.Vertical; break;
                case Polarizations.NotDefined: channel.LNBPower = PowerMode.Off; break;
                default: throw new ArgumentException( group.Polarization.ToString(), "Polarization" );
            }

            // Process
            CheckChannel( CDVBFrontend_SetChannel( m_Class.ClassPointer, channel, false ) );

            // Check up for synchronisation
            Channel_S val1, val2;

            // Get channel twice
            CheckChannel( CDVBFrontend_GetChannel( m_Class.ClassPointer, out val1 ) );
            CheckChannel( CDVBFrontend_GetChannel( m_Class.ClassPointer, out val2 ) );

            // Did it
            return true;
        }
示例#4
0
        /// <summary>
        /// Versucht, die Textdarstellung einer Gruppe von Quellen in eine
        /// Gruppeninstanz umzuwandeln.
        /// </summary>
        /// <param name="text">Die Textdarstellung, wie über <see cref="ToString"/>
        /// erzeugt.</param>
        /// <param name="group">Die zugehörige Instanz.</param>
        /// <returns>Gesetzt, wenn eine Umwandlung möglich war.</returns>
        public static bool TryParse(string text, out SatelliteGroup group)
        {
            // Reset
            group = null;

            // None
            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            // Split
            string[] parts = text.Split(',');
            if (8 != parts.Length)
            {
                return(false);
            }

            // Modulation type
            bool standardModulation = parts[0].Trim().Equals("DVB-S");

            // Validate other
            if (!standardModulation)
            {
                if (!parts[0].Trim().Equals("DVB-S2"))
                {
                    return(false);
                }
            }

            // Get full
            string orbital = parts[1].Trim();

            // Primary orbital position
            bool west = orbital.EndsWith("W");

            // Validate other
            if (!west)
            {
                if (!orbital.EndsWith("E"))
                {
                    return(false);
                }
            }

            // Cut off
            orbital = orbital.Substring(0, orbital.Length - 1);

            // Test for special notation
            if ((orbital.Length >= 4) && (orbital.Length <= 6))
            {
                if ('.' == orbital[orbital.Length - 3])
                {
                    if ('°' == orbital[orbital.Length - 1])
                    {
                        orbital = ("00" + orbital.Substring(0, orbital.Length - 3) + orbital.Substring(orbital.Length - 2, 1)).Substring(orbital.Length - 4, 4);
                    }
                }
            }

            // Read frequency
            uint frequency;

            if (!uint.TryParse(parts[2].Trim(), out frequency))
            {
                return(false);
            }

            // Polarization
            Polarizations polarisation;

            try
            {
                // Load
                polarisation = (Polarizations)Enum.Parse(typeof(Polarizations), parts[3].Trim());
            }
            catch (FormatException)
            {
                // Not valid
                return(false);
            }

            // Read symbol rate
            uint symbolrate;

            if (!uint.TryParse(parts[4].Trim(), out symbolrate))
            {
                return(false);
            }

            // Error correction
            InnerForwardErrorCorrectionModes correction;

            try
            {
                // Load
                correction = (InnerForwardErrorCorrectionModes)Enum.Parse(typeof(InnerForwardErrorCorrectionModes), parts[5].Trim());
            }
            catch (FormatException)
            {
                // Not valid
                return(false);
            }

            // Modulation
            SatelliteModulations modulation;

            try
            {
                // Load
                modulation = (SatelliteModulations)Enum.Parse(typeof(SatelliteModulations), parts[6].Trim());
            }
            catch (FormatException)
            {
                // Not valid
                return(false);
            }

            // Roll-Off
            S2RollOffs rolloff;

            try
            {
                // Load
                rolloff = (S2RollOffs)Enum.Parse(typeof(S2RollOffs), parts[7].Trim());
            }
            catch (FormatException)
            {
                // Not valid
                return(false);
            }

            // Just create
            group = new SatelliteGroup
            {
                Frequency        = frequency,
                InnerFEC         = correction,
                IsWestPosition   = west,
                Modulation       = modulation,
                OrbitalPosition  = orbital,
                Polarization     = polarisation,
                RollOff          = rolloff,
                SymbolRate       = symbolrate,
                UsesS2Modulation = !standardModulation
            };

            // Did it
            return(true);
        }
示例#5
0
        /// <summary>
        /// Vergleicht diese Quellgruppe (Transponder) mit einer anderen.
        /// </summary>
        /// <param name="group">Die andere Quellgruppe.</param>
        /// <param name="legacy">Gesetzt, wenn ein partieller Vergleich erfolgen soll.</param>
        /// <returns>Gesetzt, wenn die Gruppen identisch sind.</returns>
        protected override bool OnCompare(SourceGroup group, bool legacy)
        {
            // Change type
            SatelliteGroup other = (SatelliteGroup)group;

            // Most groups can be uniquely identified by the frequency
            if (legacy)
            {
                // Allow shift by 5 MHz
                if (Math.Abs((long)Frequency - (long)other.Frequency) > 5000)
                {
                    return(false);
                }
            }
            else
            {
                // Exact match
                if (Frequency != other.Frequency)
                {
                    return(false);
                }
            }

            // In rare cases both polarisations are needed
            if (Polarization != other.Polarization)
            {
                return(false);
            }

            // Location in the sky
            if (!legacy)
            {
                // All of it
                if (IsWestPosition != other.IsWestPosition)
                {
                    return(false);
                }
                if (!Equals((null == OrbitalPosition) ? string.Empty : OrbitalPosition, (null == other.OrbitalPosition) ? string.Empty : other.OrbitalPosition))
                {
                    return(false);
                }
            }

            // The rest is more or less for completeness
            if (UsesS2Modulation != other.UsesS2Modulation)
            {
                return(false);
            }

            // See if we should include the modulation
            if (!legacy)
            {
                // All of it
                if (SymbolRate != other.SymbolRate)
                {
                    return(false);
                }
                if (Modulation != other.Modulation)
                {
                    return(false);
                }
                if (RollOff != other.RollOff)
                {
                    return(false);
                }
                if (InnerFEC != other.InnerFEC)
                {
                    return(false);
                }
            }

            // Same
            return(true);
        }
示例#6
0
        /// <summary>
        /// Erzeugt die Beschreibung einer Quellgruppe aus einer SI Beschreibung eines
        /// NIT Eintrags.
        /// </summary>
        /// <param name="descriptor">Die Daten zur Quellgruppe.</param>
        /// <returns>Die Quellgruppe.</returns>
        private static SatelliteGroup ToGroup(this EPG.Descriptors.SatelliteDelivery descriptor)
        {
            // Create core
            var group = new SatelliteGroup
            {
                Frequency       = descriptor.Frequency,
                IsWestPosition  = descriptor.West,
                OrbitalPosition = descriptor.OrbitalPosition.ToString("0000"),
                SymbolRate      = descriptor.SymbolRate * 1000
            };

            // DVB-S2 modulation
            group.UsesS2Modulation = (0 != (0x04 & descriptor.Modulation));

            // Roll-Off if using DVB-S2
            if (group.UsesS2Modulation)
            {
                switch (0x18 & descriptor.Modulation)
                {
                case 0x00: group.RollOff = S2RollOffs.Alpha35; break;

                case 0x08: group.RollOff = S2RollOffs.Alpha25; break;

                case 0x10: group.RollOff = S2RollOffs.Alpha20; break;

                case 0x18: group.RollOff = S2RollOffs.Reserved; break;
                }
            }

            // Modulation
            switch (0x03 & descriptor.Modulation)
            {
            case 0: group.Modulation = SatelliteModulations.Auto; break;

            case 1: group.Modulation = SatelliteModulations.QPSK; break;

            case 2: group.Modulation = SatelliteModulations.PSK8; break;

            case 3: group.Modulation = SatelliteModulations.QAM16; break;
            }

            // Polarisation
            switch (descriptor.Polarization)
            {
            case EPG.Polarizations.Horizontal: group.Polarization = Polarizations.Horizontal; break;

            case EPG.Polarizations.Vertical: group.Polarization = Polarizations.Vertical; break;

            case EPG.Polarizations.Left: group.Polarization = Polarizations.Left; break;

            case EPG.Polarizations.Right: group.Polarization = Polarizations.Right; break;
            }

            // Error correction
            switch (descriptor.InnerFEC)
            {
            case EPG.InnerFECs.NotDefined: group.InnerFEC = InnerForwardErrorCorrectionModes.NotDefined; break;

            case EPG.InnerFECs.Conv1_2: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv1_2; break;

            case EPG.InnerFECs.Conv2_3: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv2_3; break;

            case EPG.InnerFECs.Conv3_4: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv3_4; break;

            case EPG.InnerFECs.Conv5_6: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv5_6; break;

            case EPG.InnerFECs.Conv7_8: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv7_8; break;

            case EPG.InnerFECs.Conv8_9: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv8_9; break;

            case EPG.InnerFECs.Reserved0111: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv3_5; break;

            case EPG.InnerFECs.Reserved1000: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv4_5; break;

            case EPG.InnerFECs.Reserved1001: group.InnerFEC = InnerForwardErrorCorrectionModes.Conv9_10; break;

            case EPG.InnerFECs.Reserved1010: group.InnerFEC = InnerForwardErrorCorrectionModes.Reserved1010; break;

            case EPG.InnerFECs.Reserved1011: group.InnerFEC = InnerForwardErrorCorrectionModes.Reserved1011; break;

            case EPG.InnerFECs.Reserved1100: group.InnerFEC = InnerForwardErrorCorrectionModes.Reserved1100; break;

            case EPG.InnerFECs.Reserved1101: group.InnerFEC = InnerForwardErrorCorrectionModes.Reserved1101; break;

            case EPG.InnerFECs.Reserved1110: group.InnerFEC = InnerForwardErrorCorrectionModes.Reserved1110; break;

            case EPG.InnerFECs.NoConv: group.InnerFEC = InnerForwardErrorCorrectionModes.NoConv; break;
            }

            // Report
            return(group);
        }
        /// <summary>
        /// Versucht, die Textdarstellung einer Gruppe von Quellen in eine
        /// Gruppeninstanz umzuwandeln.
        /// </summary>
        /// <param name="text">Die Textdarstellung, wie über <see cref="ToString"/>
        /// erzeugt.</param>
        /// <param name="group">Die zugehörige Instanz.</param>
        /// <returns>Gesetzt, wenn eine Umwandlung möglich war.</returns>
        public static bool TryParse( string text, out SatelliteGroup group )
        {
            // Reset
            group = null;

            // None
            if (string.IsNullOrEmpty( text ))
                return false;

            // Split
            string[] parts = text.Split( ',' );
            if (8 != parts.Length)
                return false;

            // Modulation type
            bool standardModulation = parts[0].Trim().Equals( "DVB-S" );

            // Validate other
            if (!standardModulation)
                if (!parts[0].Trim().Equals( "DVB-S2" ))
                    return false;

            // Get full
            string orbital = parts[1].Trim();

            // Primary orbital position
            bool west = orbital.EndsWith( "W" );

            // Validate other
            if (!west)
                if (!orbital.EndsWith( "E" ))
                    return false;

            // Cut off
            orbital = orbital.Substring( 0, orbital.Length - 1 );

            // Test for special notation
            if ((orbital.Length >= 4) && (orbital.Length <= 6))
                if ('.' == orbital[orbital.Length - 3])
                    if ('°' == orbital[orbital.Length - 1])
                        orbital = ("00" + orbital.Substring( 0, orbital.Length - 3 ) + orbital.Substring( orbital.Length - 2, 1 )).Substring( orbital.Length - 4, 4 );

            // Read frequency
            uint frequency;
            if (!uint.TryParse( parts[2].Trim(), out frequency ))
                return false;

            // Polarization
            Polarizations polarisation;
            try
            {
                // Load
                polarisation = (Polarizations) Enum.Parse( typeof( Polarizations ), parts[3].Trim() );
            }
            catch (FormatException)
            {
                // Not valid
                return false;
            }

            // Read symbol rate
            uint symbolrate;
            if (!uint.TryParse( parts[4].Trim(), out symbolrate ))
                return false;

            // Error correction
            InnerForwardErrorCorrectionModes correction;
            try
            {
                // Load
                correction = (InnerForwardErrorCorrectionModes) Enum.Parse( typeof( InnerForwardErrorCorrectionModes ), parts[5].Trim() );
            }
            catch (FormatException)
            {
                // Not valid
                return false;
            }

            // Modulation
            SatelliteModulations modulation;
            try
            {
                // Load
                modulation = (SatelliteModulations) Enum.Parse( typeof( SatelliteModulations ), parts[6].Trim() );
            }
            catch (FormatException)
            {
                // Not valid
                return false;
            }

            // Roll-Off
            S2RollOffs rolloff;
            try
            {
                // Load
                rolloff = (S2RollOffs) Enum.Parse( typeof( S2RollOffs ), parts[7].Trim() );
            }
            catch (FormatException)
            {
                // Not valid
                return false;
            }

            // Just create
            group = new SatelliteGroup
                {
                    Frequency = frequency,
                    InnerFEC = correction,
                    IsWestPosition = west,
                    Modulation = modulation,
                    OrbitalPosition = orbital,
                    Polarization = polarisation,
                    RollOff = rolloff,
                    SymbolRate = symbolrate,
                    UsesS2Modulation = !standardModulation
                };

            // Did it
            return true;
        }