Exemple #1
0
        bool _WP.IControllerHostRemote.ProcessMessage(byte[] header, byte[] payload, bool fReply)
        {
            _WP.MessageRaw      raw = new _WP.MessageRaw(); raw.m_header = header; raw.m_payload = payload;
            _WP.MessageBase     bs  = new _WP.MessageBase();
            _WP.IncomingMessage msg = new _WP.IncomingMessage(this, raw, bs);

            bs.m_header = new _WP.Packet();

            new _WP.Converter(this.ParentIControllerRemote.Capabilities).Deserialize(bs.m_header, raw.m_header);

            return(m_owner.ProcessMessage(msg, fReply));
        }
        bool _WP.IControllerHostRemote.ProcessMessage( byte[] header, byte[] payload, bool fReply )
        {
            _WP.MessageRaw      raw = new _WP.MessageRaw (); raw.m_header = header; raw.m_payload = payload;
            _WP.MessageBase     bs  = new _WP.MessageBase();
            _WP.IncomingMessage msg = new _WP.IncomingMessage( this, raw, bs );

            bs.m_header = new _WP.Packet();

            new _WP.Converter( this.ParentIControllerRemote.Capabilities ).Deserialize( bs.m_header, raw.m_header );

            return m_owner.ProcessMessage( msg, fReply );
        }
Exemple #3
0
        internal void InitializeForSend( IController parent, Converter converter, uint cmd, uint flags, object payload )
        {
            Packet header = parent.NewPacket();

            header.m_cmd   = cmd;
            header.m_flags = flags;

            m_parent              = parent;

            m_raw                 = new MessageRaw ();
            m_base                = new MessageBase();
            m_base.m_header       = header;
            m_base.m_payload      = payload;

            if(payload != null)
            {                
                m_raw.m_payload = converter.Serialize( payload );

                m_base.m_header.m_size    = (uint)m_raw.m_payload.Length;
                m_base.m_header.m_crcData = CRC.ComputeCRC( m_raw.m_payload, 0 );
            }
        }
Exemple #4
0
 public IncomingMessage( IController parent, MessageRaw raw, MessageBase messageBase)
 {
     m_parent = parent;
     m_raw    = raw;
     m_base   = messageBase;
 }
Exemple #5
0
            /// <summary>
            /// Essential Rx method. Drives state machine by reading data and processing it. This works in
            /// conjunction with NotificationThreadWorker [Tx].
            /// </summary>
            internal void Process()
            {
                int count;
                int bytesRead;

                try
                {
                    switch(m_state)
                    {
                        case ReceiveState.Initialize:
                            m_rawPos        = 0;

                            m_base          = new MessageBase();
                            m_base.m_header = new Packet();

                            m_raw           = new MessageRaw ();
                            m_raw .m_header = m_parent.CreateConverter().Serialize( m_base.m_header );

                            m_state = ReceiveState.WaitingForHeader;
                            goto case ReceiveState.WaitingForHeader;

                        case ReceiveState.WaitingForHeader:
                            count = m_raw.m_header.Length - m_rawPos;

                            bytesRead = m_parent.Read(m_raw.m_header, m_rawPos, count);
                            m_rawPos += bytesRead;

                            while(m_rawPos > 0)
                            {
                                int flag_Debugger = ValidSignature( m_parent.marker_Debugger );
                                int flag_Packet   = ValidSignature( m_parent.marker_Packet   );
                                
                                if(flag_Debugger == 1 || flag_Packet == 1)
                                {
                                    m_state = ReceiveState.ReadingHeader;
                                    goto case ReceiveState.ReadingHeader;
                                }

                                if(flag_Debugger == 0 || flag_Packet == 0)
                                {
                                    break; // Partial match.
                                }

                                m_parent.App.SpuriousCharacters( m_raw.m_header, 0, 1 );

                                Array.Copy( m_raw.m_header, 1, m_raw.m_header, 0, --m_rawPos );
                            }
                            break;

                        case ReceiveState.ReadingHeader:
                            count = m_raw.m_header.Length - m_rawPos;

                            bytesRead = m_parent.Read(m_raw.m_header, m_rawPos, count);

                            m_rawPos += bytesRead;

                            if (bytesRead != count) break;

                            m_state = ReceiveState.CompleteHeader;
                            goto case ReceiveState.CompleteHeader;

                        case ReceiveState.CompleteHeader:
                            try
                            {
                                m_parent.CreateConverter().Deserialize( m_base.m_header, m_raw.m_header );

                                if(VerifyHeader() == true)
                                {
                                    bool fReply = (m_base.m_header.m_flags & Flags.c_Reply) != 0;

                                    m_base.DumpHeader( "Receiving" );

                                    if(m_base.m_header.m_size != 0)
                                    {
                                        m_raw.m_payload = new byte[m_base.m_header.m_size];
                                        //reuse m_rawPos for position in header to read.
                                        m_rawPos = 0;

                                        m_state = ReceiveState.ReadingPayload;
                                        goto case ReceiveState.ReadingPayload;
                                    }
                                    else
                                    {
                                        m_state = ReceiveState.CompletePayload;
                                        goto case ReceiveState.CompletePayload;
                                    }
                                }
                            }
                            catch(ThreadAbortException)
                            {
                                throw;
                            }
                            catch(Exception e)
                            {
                                Console.WriteLine( "Fault at payload deserialization:\n\n{0}", e.ToString() );
                            }

                            m_state = ReceiveState.Initialize;

                            if((m_base.m_header.m_flags & Flags.c_NonCritical) == 0)
                            {
                                IncomingMessage.ReplyBadPacket( m_parent, Flags.c_BadHeader );
                            }

                            break;

                        case ReceiveState.ReadingPayload:
                            count = m_raw.m_payload.Length - m_rawPos;

                            bytesRead = m_parent.Read(m_raw.m_payload, m_rawPos, count);

                            m_rawPos += bytesRead;

                            if (bytesRead != count) break;

                            m_state = ReceiveState.CompletePayload;
                            goto case ReceiveState.CompletePayload;

                        case ReceiveState.CompletePayload:
                            if(VerifyPayload() == true)
                            {
                                try
                                {
                                    bool fReply = (m_base.m_header.m_flags & Flags.c_Reply) != 0;

                                    if((m_base.m_header.m_flags & Flags.c_NACK) != 0)
                                    {
                                        m_raw.m_payload = null;
                                    }

                                    m_parent.App.ProcessMessage( this.GetCompleteMessage(), fReply );

                                    m_state = ReceiveState.Initialize;
                                    return;
                                }
                                catch(ThreadAbortException)
                                {
                                    throw;
                                }
                                catch(Exception e)
                                {
                                    Console.WriteLine( "Fault at payload deserialization:\n\n{0}", e.ToString() );
                                }
                            }

                            m_state = ReceiveState.Initialize;

                            if((m_base.m_header.m_flags & Flags.c_NonCritical) == 0)
                            {
                                IncomingMessage.ReplyBadPacket( m_parent, Flags.c_BadPayload );
                            }

                            break;             
                    }
                }
                catch
                {
                    m_state = ReceiveState.Initialize;
                    throw;
                }
            }
Exemple #6
0
            /// <summary>
            /// Essential Rx method. Drives state machine by reading data and processing it. This works in
            /// conjunction with NotificationThreadWorker [Tx].
            /// </summary>
            internal void Process()
            {
                int count;
                int bytesRead;

                try
                {
                    switch (m_state)
                    {
                    case ReceiveState.Initialize:
                        m_rawPos = 0;

                        m_base          = new MessageBase();
                        m_base.m_header = new Packet();

                        m_raw          = new MessageRaw();
                        m_raw.m_header = m_parent.CreateConverter().Serialize(m_base.m_header);

                        m_state = ReceiveState.WaitingForHeader;
                        goto case ReceiveState.WaitingForHeader;

                    case ReceiveState.WaitingForHeader:
                        count = m_raw.m_header.Length - m_rawPos;

                        bytesRead = m_parent.Read(m_raw.m_header, m_rawPos, count);
                        m_rawPos += bytesRead;

                        while (m_rawPos > 0)
                        {
                            int flag_Debugger = ValidSignature(m_parent.marker_Debugger);
                            int flag_Packet   = ValidSignature(m_parent.marker_Packet);

                            if (flag_Debugger == 1 || flag_Packet == 1)
                            {
                                m_state = ReceiveState.ReadingHeader;
                                goto case ReceiveState.ReadingHeader;
                            }

                            if (flag_Debugger == 0 || flag_Packet == 0)
                            {
                                break;     // Partial match.
                            }

                            m_parent.App.SpuriousCharacters(m_raw.m_header, 0, 1);

                            Array.Copy(m_raw.m_header, 1, m_raw.m_header, 0, --m_rawPos);
                        }
                        break;

                    case ReceiveState.ReadingHeader:
                        count = m_raw.m_header.Length - m_rawPos;

                        bytesRead = m_parent.Read(m_raw.m_header, m_rawPos, count);

                        m_rawPos += bytesRead;

                        if (bytesRead != count)
                        {
                            break;
                        }

                        m_state = ReceiveState.CompleteHeader;
                        goto case ReceiveState.CompleteHeader;

                    case ReceiveState.CompleteHeader:
                        try
                        {
                            m_parent.CreateConverter().Deserialize(m_base.m_header, m_raw.m_header);

                            if (VerifyHeader() == true)
                            {
                                bool fReply = (m_base.m_header.m_flags & Flags.c_Reply) != 0;

                                m_base.DumpHeader("Receiving");

                                if (m_base.m_header.m_size != 0)
                                {
                                    m_raw.m_payload = new byte[m_base.m_header.m_size];
                                    //reuse m_rawPos for position in header to read.
                                    m_rawPos = 0;

                                    m_state = ReceiveState.ReadingPayload;
                                    goto case ReceiveState.ReadingPayload;
                                }
                                else
                                {
                                    m_state = ReceiveState.CompletePayload;
                                    goto case ReceiveState.CompletePayload;
                                }
                            }
                        }
                        catch (ThreadAbortException)
                        {
                            throw;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Fault at payload deserialization:\n\n{0}", e.ToString());
                        }

                        m_state = ReceiveState.Initialize;

                        if ((m_base.m_header.m_flags & Flags.c_NonCritical) == 0)
                        {
                            IncomingMessage.ReplyBadPacket(m_parent, Flags.c_BadHeader);
                        }

                        break;

                    case ReceiveState.ReadingPayload:
                        count = m_raw.m_payload.Length - m_rawPos;

                        bytesRead = m_parent.Read(m_raw.m_payload, m_rawPos, count);

                        m_rawPos += bytesRead;

                        if (bytesRead != count)
                        {
                            break;
                        }

                        m_state = ReceiveState.CompletePayload;
                        goto case ReceiveState.CompletePayload;

                    case ReceiveState.CompletePayload:
                        if (VerifyPayload() == true)
                        {
                            try
                            {
                                bool fReply = (m_base.m_header.m_flags & Flags.c_Reply) != 0;

                                if ((m_base.m_header.m_flags & Flags.c_NACK) != 0)
                                {
                                    m_raw.m_payload = null;
                                }

                                m_parent.App.ProcessMessage(this.GetCompleteMessage(), fReply);

                                m_state = ReceiveState.Initialize;
                                return;
                            }
                            catch (ThreadAbortException)
                            {
                                throw;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Fault at payload deserialization:\n\n{0}", e.ToString());
                            }
                        }

                        m_state = ReceiveState.Initialize;

                        if ((m_base.m_header.m_flags & Flags.c_NonCritical) == 0)
                        {
                            IncomingMessage.ReplyBadPacket(m_parent, Flags.c_BadPayload);
                        }

                        break;
                    }
                }
                catch
                {
                    m_state = ReceiveState.Initialize;
                    throw;
                }
            }
Exemple #7
0
 public IncomingMessage(IController parent, MessageRaw raw, MessageBase messageBase)
 {
     m_parent = parent;
     m_raw    = raw;
     m_base   = messageBase;
 }