Exemplo n.º 1
0
 public GameParser(IFrameParser frameParser)
 {
     _frameParser = frameParser;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Stops the <see cref="MultiProtocolFrameParser"/>.
        /// </summary>
        public void Stop()
        {
            WaitHandle commandWaitHandle;

            m_enabled = false;
            m_rateCalcTimer.Enabled = false;
            m_configurationFrame = null;

            // Make sure data stream is disabled
            if (!m_skipDisableRealTimeData)
            {
                commandWaitHandle = SendDeviceCommand(DeviceCommand.DisableRealTimeData);

                if ((object)commandWaitHandle != null)
                    commandWaitHandle.WaitOne(1000);
            }

            if ((object)m_dataChannel != null)
            {
                try
                {
                    m_dataChannel.Disconnect();
                }
                catch (Exception ex)
                {
                    OnParsingException(ex, "Failed to properly disconnect data channel: {0}", ex.Message);
                }
                finally
                {
                    m_dataChannel.ConnectionEstablished -= m_dataChannel_ConnectionEstablished;
                    m_dataChannel.ConnectionAttempt -= m_dataChannel_ConnectionAttempt;
                    m_dataChannel.ConnectionException -= m_dataChannel_ConnectionException;
                    m_dataChannel.ConnectionTerminated -= m_dataChannel_ConnectionTerminated;
                    m_dataChannel.ReceiveData -= m_dataChannel_ReceiveData;
                    m_dataChannel.ReceiveDataException -= m_dataChannel_ReceiveDataException;
                    m_dataChannel.SendDataException -= m_dataChannel_SendDataException;
                    m_dataChannel.UnhandledUserException -= m_dataChannel_UnhandledUserException;
                    m_dataChannel.Dispose();
                }

                m_dataChannel = null;
            }

            m_readNextBuffer = null;

            if ((object)m_serverBasedDataChannel != null)
            {
                try
                {
                    m_serverBasedDataChannel.DisconnectAll();
                }
                catch (Exception ex)
                {
                    OnParsingException(ex, "Failed to properly disconnect server based data channel: {0}", ex.Message);
                }
                finally
                {
                    m_serverBasedDataChannel.ClientConnected -= m_serverBasedDataChannel_ClientConnected;
                    m_serverBasedDataChannel.ClientDisconnected -= m_serverBasedDataChannel_ClientDisconnected;
                    m_serverBasedDataChannel.ClientConnectingException -= m_serverBasedDataChannel_ClientConnectingException;
                    m_serverBasedDataChannel.ServerStarted -= m_serverBasedDataChannel_ServerStarted;
                    m_serverBasedDataChannel.ServerStopped -= m_serverBasedDataChannel_ServerStopped;
                    m_serverBasedDataChannel.ReceiveClientData -= m_serverBasedDataChannel_ReceiveClientData;
                    m_serverBasedDataChannel.ReceiveClientDataException -= m_serverBasedDataChannel_ReceiveClientDataException;
                    m_serverBasedDataChannel.SendClientDataException -= m_serverBasedDataChannel_SendClientDataException;
                    m_serverBasedDataChannel.UnhandledUserException -= m_serverBasedDataChannel_UnhandledUserException;
                    m_serverBasedDataChannel.Dispose();
                }

                m_serverBasedDataChannel = null;
            }

            if ((object)m_commandChannel != null)
            {
                try
                {
                    m_commandChannel.Disconnect();
                }
                catch (Exception ex)
                {
                    OnParsingException(ex, "Failed to properly disconnect command channel: {0}", ex.Message);
                }
                finally
                {
                    m_commandChannel.ConnectionEstablished -= m_commandChannel_ConnectionEstablished;
                    m_commandChannel.ConnectionAttempt -= m_commandChannel_ConnectionAttempt;
                    m_commandChannel.ConnectionException -= m_commandChannel_ConnectionException;
                    m_commandChannel.ConnectionTerminated -= m_commandChannel_ConnectionTerminated;
                    m_commandChannel.ReceiveData -= m_commandChannel_ReceiveData;
                    m_commandChannel.ReceiveDataException -= m_commandChannel_ReceiveDataException;
                    m_commandChannel.SendDataException -= m_commandChannel_SendDataException;
                    m_commandChannel.UnhandledUserException -= m_commandChannel_UnhandledUserException;
                    m_commandChannel.Dispose();
                }

                m_commandChannel = null;
            }

            if ((object)m_frameParser != null)
            {
                try
                {
                    m_frameParser.Stop();
                }
                catch (Exception ex)
                {
                    OnParsingException(ex, "Failed to properly stop frame parser: {0}", ex.Message);
                }
                finally
                {
                    m_frameParser.ReceivedCommandFrame -= m_frameParser_ReceivedCommandFrame;
                    m_frameParser.ReceivedConfigurationFrame -= m_frameParser_ReceivedConfigurationFrame;
                    m_frameParser.ReceivedDataFrame -= m_frameParser_ReceivedDataFrame;
                    m_frameParser.ReceivedHeaderFrame -= m_frameParser_ReceivedHeaderFrame;
                    m_frameParser.ReceivedUndeterminedFrame -= m_frameParser_ReceivedUndeterminedFrame;
                    m_frameParser.ReceivedFrameImage -= m_frameParser_ReceivedFrameImage;
                    m_frameParser.ConfigurationChanged -= m_frameParser_ConfigurationChanged;
                    m_frameParser.ParsingException -= m_frameParser_ParsingException;
                    m_frameParser.BufferParsed -= m_frameParser_BufferParsed;

                    if ((object)ReceivedFrameBufferImage != null)
                        m_frameParser.ReceivedFrameBufferImage -= m_frameParser_ReceivedFrameBufferImage;

                    m_frameParser.Dispose();
                }

                m_frameParser = null;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize frame parser.
        /// </summary>
        /// <param name="settings">Key/value pairs dictionary parsed from connection string.</param>
        private void InitializeFrameParser(Dictionary<string, string> settings)
        {
            string setting;

            // Instantiate protocol specific frame parser
            switch (m_phasorProtocol)
            {
                case PhasorProtocol.IEEEC37_118V2:
                case PhasorProtocol.IEEEC37_118V1:
                case PhasorProtocol.IEEEC37_118D6:
                    m_frameParser = new IEEEC37_118.FrameParser(m_checkSumValidationFrameTypes, m_trustHeaderLength, m_phasorProtocol == PhasorProtocol.IEEEC37_118D6 ? DraftRevision.Draft6 : DraftRevision.Draft7);
                    break;
                case PhasorProtocol.IEEE1344:
                    m_frameParser = new IEEE1344.FrameParser(m_checkSumValidationFrameTypes, m_trustHeaderLength);
                    break;
                case PhasorProtocol.IEC61850_90_5:
                    m_frameParser = new IEC61850_90_5.FrameParser(m_checkSumValidationFrameTypes, m_trustHeaderLength);

                    // Check for IEC 61850-90-5 protocol specific parameters in connection string
                    IEC61850_90_5.ConnectionParameters iecParameters = m_connectionParameters as IEC61850_90_5.ConnectionParameters;

                    if ((object)iecParameters != null)
                    {
                        if (settings.TryGetValue("useETRConfiguration", out setting))
                            iecParameters.UseETRConfiguration = setting.ParseBoolean();

                        if (settings.TryGetValue("guessConfiguration", out setting))
                            iecParameters.GuessConfiguration = setting.ParseBoolean();

                        if (settings.TryGetValue("parseRedundantASDUs", out setting))
                            iecParameters.ParseRedundantASDUs = setting.ParseBoolean();

                        if (settings.TryGetValue("ignoreSignatureValidationFailures", out setting))
                            iecParameters.IgnoreSignatureValidationFailures = setting.ParseBoolean();

                        if (settings.TryGetValue("ignoreSampleSizeValidationFailures", out setting))
                            iecParameters.IgnoreSampleSizeValidationFailures = setting.ParseBoolean();
                    }

                    break;
                case PhasorProtocol.BPAPDCstream:
                    m_frameParser = new BPAPDCstream.FrameParser(m_checkSumValidationFrameTypes, m_trustHeaderLength);

                    // Check for BPA PDCstream protocol specific parameters in connection string
                    BPAPDCstream.ConnectionParameters bpaPdcParameters = m_connectionParameters as BPAPDCstream.ConnectionParameters;

                    if ((object)bpaPdcParameters != null)
                    {
                        // INI file name setting is required
                        if (settings.TryGetValue("iniFileName", out setting))
                            bpaPdcParameters.ConfigurationFileName = FilePath.GetAbsolutePath(setting);
                        else if (string.IsNullOrWhiteSpace(bpaPdcParameters.ConfigurationFileName))
                            throw new ArgumentException("BPA PDCstream INI filename setting (e.g., \"inifilename=DEVICE_PDC.ini\") was not found. This setting is required for BPA PDCstream protocol connections - frame parser initialization terminated.");

                        if (settings.TryGetValue("refreshConfigFileOnChange", out setting))
                            bpaPdcParameters.RefreshConfigurationFileOnChange = setting.ParseBoolean();

                        if (settings.TryGetValue("parseWordCountFromByte", out setting))
                            bpaPdcParameters.ParseWordCountFromByte = setting.ParseBoolean();

                        if (settings.TryGetValue("usePhasorDataFileFormat", out setting))
                            bpaPdcParameters.UsePhasorDataFileFormat = setting.ParseBoolean();
                    }
                    break;
                case PhasorProtocol.FNET:
                    m_frameParser = new FNET.FrameParser(m_checkSumValidationFrameTypes, m_trustHeaderLength);

                    // Check for F-NET protocol specific parameters in connection string
                    FNET.ConnectionParameters fnetParameters = m_connectionParameters as FNET.ConnectionParameters;

                    if ((object)fnetParameters != null)
                    {
                        if (settings.TryGetValue("timeOffset", out setting))
                            fnetParameters.TimeOffset = long.Parse(setting);

                        if (settings.TryGetValue("stationName", out setting))
                            fnetParameters.StationName = setting;

                        if (settings.TryGetValue("frameRate", out setting))
                            fnetParameters.FrameRate = ushort.Parse(setting);

                        if (settings.TryGetValue("nominalFrequency", out setting))
                            fnetParameters.NominalFrequency = (LineFrequency)int.Parse(setting);
                    }
                    break;
                case PhasorProtocol.SelFastMessage:
                    m_frameParser = new SelFastMessage.FrameParser(m_checkSumValidationFrameTypes, m_trustHeaderLength);

                    // Check for SEL Fast Message protocol specific parameters in connection string
                    SelFastMessage.ConnectionParameters selParameters = m_connectionParameters as SelFastMessage.ConnectionParameters;

                    if ((object)selParameters != null)
                    {
                        if (settings.TryGetValue("messagePeriod", out setting))
                            selParameters.MessagePeriod = (MessagePeriod)Enum.Parse(typeof(MessagePeriod), setting, true);
                    }
                    break;
                case PhasorProtocol.Macrodyne:
                    m_frameParser = new Macrodyne.FrameParser(m_checkSumValidationFrameTypes, m_trustHeaderLength);

                    // Check for Macrodyne protocol specific parameters in connection string
                    Macrodyne.ConnectionParameters macrodyneParameters = m_connectionParameters as Macrodyne.ConnectionParameters;

                    if ((object)macrodyneParameters != null)
                    {
                        ProtocolVersion protocolVersion;

                        if (settings.TryGetValue("protocolVersion", out setting) && Enum.TryParse(setting, true, out protocolVersion))
                            macrodyneParameters.ProtocolVersion = protocolVersion;

                        // INI file name setting is required for 1690G protocol
                        if (settings.TryGetValue("iniFileName", out setting))
                            macrodyneParameters.ConfigurationFileName = FilePath.GetAbsolutePath(setting);
                        else if (macrodyneParameters.ProtocolVersion == ProtocolVersion.G && string.IsNullOrWhiteSpace(macrodyneParameters.ConfigurationFileName))
                            throw new ArgumentException("Macrodyne INI filename setting (e.g., \"iniFileName=DEVICE_PDC.ini\") was not found. This setting is required for 1690G devices - frame parser initialization terminated.");

                        // Device label setting is required for 1690G protocol
                        if (settings.TryGetValue("deviceLabel", out setting))
                            macrodyneParameters.DeviceLabel = setting;
                        else if (macrodyneParameters.ProtocolVersion == ProtocolVersion.G && string.IsNullOrWhiteSpace(macrodyneParameters.DeviceLabel))
                            throw new ArgumentException("Macrodyne device label setting (e.g., \"deviceLabel=DEVICE1\") was not found. This setting is required for 1690G devices - frame parser initialization terminated.");

                        if (settings.TryGetValue("refreshConfigFileOnChange", out setting))
                            macrodyneParameters.RefreshConfigurationFileOnChange = setting.ParseBoolean();
                    }
                    break;
                default:
                    throw new InvalidOperationException(string.Format("Phasor protocol \"{0}\" is not recognized, failed to initialize frame parser", m_phasorProtocol));
            }

            // Assign frame parser properties
            m_frameParser.ConnectionParameters = m_connectionParameters;

            // Setup event handlers
            m_frameParser.ReceivedCommandFrame += m_frameParser_ReceivedCommandFrame;
            m_frameParser.ReceivedConfigurationFrame += m_frameParser_ReceivedConfigurationFrame;
            m_frameParser.ReceivedDataFrame += m_frameParser_ReceivedDataFrame;
            m_frameParser.ReceivedHeaderFrame += m_frameParser_ReceivedHeaderFrame;
            m_frameParser.ReceivedUndeterminedFrame += m_frameParser_ReceivedUndeterminedFrame;
            m_frameParser.ReceivedFrameImage += m_frameParser_ReceivedFrameImage;
            m_frameParser.ConfigurationChanged += m_frameParser_ConfigurationChanged;
            m_frameParser.ParsingException += m_frameParser_ParsingException;
            m_frameParser.BufferParsed += m_frameParser_BufferParsed;

            // Only attach to this event if consumer needs buffer image (i.e., has attached to our event)
            if ((object)ReceivedFrameBufferImage != null)
                m_frameParser.ReceivedFrameBufferImage += m_frameParser_ReceivedFrameBufferImage;

            // Start parsing engine
            m_frameParser.Start();
        }
Exemplo n.º 4
0
 public BowlingGame()
 {
     rollParser  = new RollParser();
     frameParser = new FrameParser();
     score       = new Score();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Stops the <see cref="MultiProtocolFrameParser"/>.
        /// </summary>
        public virtual void Stop()
        {
            m_enabled = false;
            m_rateCalcTimer.Enabled = false;
            m_lastFrameReceivedTime = 0;
            m_configurationFrame = null;

            // Make sure data stream is disabled
            SendDeviceCommand(DeviceCommand.DisableRealTimeData);

            if (m_dataChannel != null)
            {
                m_dataChannel.Disconnect();
                m_dataChannel.ReceiveDataHandler = null;
                m_dataChannel.ConnectionEstablished -= m_dataChannel_ConnectionEstablished;
                m_dataChannel.ConnectionAttempt -= m_dataChannel_ConnectionAttempt;
                m_dataChannel.ConnectionException -= m_dataChannel_ConnectionException;
                m_dataChannel.ConnectionTerminated -= m_dataChannel_ConnectionTerminated;
                m_dataChannel.Dispose();
            }
            m_dataChannel = null;

            if (m_serverBasedDataChannel != null)
            {
                m_serverBasedDataChannel.DisconnectAll();
                m_serverBasedDataChannel.ReceiveClientDataHandler = null;
                m_serverBasedDataChannel.ClientConnected -= m_serverBasedDataChannel_ClientConnected;
                m_serverBasedDataChannel.ClientDisconnected -= m_serverBasedDataChannel_ClientDisconnected;
                m_serverBasedDataChannel.ServerStarted -= m_serverBasedDataChannel_ServerStarted;
                m_serverBasedDataChannel.ServerStopped -= m_serverBasedDataChannel_ServerStopped;
                m_serverBasedDataChannel.Dispose();
            }
            m_serverBasedDataChannel = null;

            if (m_commandChannel != null)
            {
                m_commandChannel.Disconnect();
                m_commandChannel.ReceiveDataHandler = null;
                m_commandChannel.ConnectionEstablished -= m_commandChannel_ConnectionEstablished;
                m_commandChannel.ConnectionAttempt -= m_commandChannel_ConnectionAttempt;
                m_commandChannel.ConnectionException -= m_commandChannel_ConnectionException;
                m_commandChannel.ConnectionTerminated -= m_commandChannel_ConnectionTerminated;
                m_commandChannel.Dispose();
            }
            m_commandChannel = null;

            if (m_frameParser != null)
            {
                m_frameParser.Stop();
                m_frameParser.ReceivedCommandFrame -= m_frameParser_ReceivedCommandFrame;
                m_frameParser.ReceivedConfigurationFrame -= m_frameParser_ReceivedConfigurationFrame;
                m_frameParser.ReceivedDataFrame -= m_frameParser_ReceivedDataFrame;
                m_frameParser.ReceivedHeaderFrame -= m_frameParser_ReceivedHeaderFrame;
                m_frameParser.ReceivedUndeterminedFrame -= m_frameParser_ReceivedUndeterminedFrame;
                m_frameParser.ReceivedFrameBufferImage -= m_frameParser_ReceivedFrameBufferImage;
                m_frameParser.ConfigurationChanged -= m_frameParser_ConfigurationChanged;
                m_frameParser.ParsingException -= m_frameParser_ParsingException;
                m_frameParser.Dispose();
            }
            m_frameParser = null;

            #if RawDataCapture
            if (m_rawDataCapture != null)
                m_rawDataCapture.Close();
            m_rawDataCapture = null;
            #endif
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize frame parser.
        /// </summary>
        /// <param name="settings">Key/value pairs dictionary parsed from connection string.</param>
        protected virtual void InitializeFrameParser(Dictionary<string, string> settings)
        {
            string setting;

            // Instantiate protocol specific frame parser
            switch (m_phasorProtocol)
            {
                case PhasorProtocol.IeeeC37_118V1:
                    m_frameParser = new IeeeC37_118.FrameParser(IeeeC37_118.DraftRevision.Draft7);
                    break;
                case PhasorProtocol.IeeeC37_118D6:
                    m_frameParser = new IeeeC37_118.FrameParser(IeeeC37_118.DraftRevision.Draft6);
                    break;
                case PhasorProtocol.Ieee1344:
                    m_frameParser = new Ieee1344.FrameParser();
                    break;
                case PhasorProtocol.BpaPdcStream:
                    m_frameParser = new BpaPdcStream.FrameParser();

                    // Check for BPA PDCstream protocol specific parameters in connection string
                    BpaPdcStream.ConnectionParameters bpaPdcParameters = m_connectionParameters as BpaPdcStream.ConnectionParameters;

                    if (bpaPdcParameters != null)
                    {
                        // INI file name setting is required
                        if (settings.TryGetValue("iniFileName", out setting))
                            bpaPdcParameters.ConfigurationFileName = FilePath.GetAbsolutePath(setting);
                        else if (string.IsNullOrEmpty(bpaPdcParameters.ConfigurationFileName))
                            throw new ArgumentException("BPA PDCstream INI filename setting (e.g., \"inifilename=DEVICE_PDC.ini\") was not found. This setting is required for BPA PDCstream protocol connections - frame parser initialization terminated.");

                        if (settings.TryGetValue("refreshConfigFileOnChange", out setting))
                            bpaPdcParameters.RefreshConfigurationFileOnChange = setting.ParseBoolean();

                        if (settings.TryGetValue("parseWordCountFromByte", out setting))
                            bpaPdcParameters.ParseWordCountFromByte = setting.ParseBoolean();
                    }
                    break;
                case PhasorProtocol.FNet:
                    m_frameParser = new FNet.FrameParser();

                    // Check for F-NET protocol specific parameters in connection string
                    FNet.ConnectionParameters fnetParameters = m_connectionParameters as FNet.ConnectionParameters;

                    if (fnetParameters != null)
                    {
                        if (settings.TryGetValue("timeOffset", out setting))
                            fnetParameters.TimeOffset = long.Parse(setting);

                        if (settings.TryGetValue("stationName", out setting))
                            fnetParameters.StationName = setting;

                        if (settings.TryGetValue("frameRate", out setting))
                            fnetParameters.FrameRate = ushort.Parse(setting);

                        if (settings.TryGetValue("nominalFrequency", out setting))
                            fnetParameters.NominalFrequency = (LineFrequency)Enum.Parse(typeof(LineFrequency), setting);
                    }
                    break;
                case PhasorProtocol.SelFastMessage:
                    m_frameParser = new SelFastMessage.FrameParser();

                    // Check for SEL Fast Message protocol specific parameters in connection string
                    SelFastMessage.ConnectionParameters selParameters = m_connectionParameters as SelFastMessage.ConnectionParameters;

                    if (selParameters != null)
                    {
                        if (settings.TryGetValue("messageperiod", out setting))
                            selParameters.MessagePeriod = (SelFastMessage.MessagePeriod)Enum.Parse(typeof(SelFastMessage.MessagePeriod), setting);
                    }
                    break;
                case PhasorProtocol.Macrodyne:
                    m_frameParser = new Macrodyne.FrameParser();
                    break;
                default:
                    throw new InvalidOperationException(string.Format("Phasor protocol \"{0}\" is not recognized, failed to initialize frame parser", m_phasorProtocol));
            }

            // Assign frame parser properties
            m_frameParser.ConnectionParameters = m_connectionParameters;
            m_frameParser.ExecuteParseOnSeparateThread = m_executeParseOnSeparateThread;

            // Setup event handlers
            m_frameParser.ReceivedCommandFrame += m_frameParser_ReceivedCommandFrame;
            m_frameParser.ReceivedConfigurationFrame += m_frameParser_ReceivedConfigurationFrame;
            m_frameParser.ReceivedDataFrame += m_frameParser_ReceivedDataFrame;
            m_frameParser.ReceivedHeaderFrame += m_frameParser_ReceivedHeaderFrame;
            m_frameParser.ReceivedUndeterminedFrame += m_frameParser_ReceivedUndeterminedFrame;
            m_frameParser.ReceivedFrameBufferImage += m_frameParser_ReceivedFrameBufferImage;
            m_frameParser.ConfigurationChanged += m_frameParser_ConfigurationChanged;
            m_frameParser.ParsingException += m_frameParser_ParsingException;
        }