Exemplo n.º 1
0
        void Protocol_MessageReceived(object sender, FmdcEventArgs e)
        {
            ConMessage msg = e.Data as ConMessage;

            if (msg != null)
            {
                // We are letting hub take care of incomming messages.
                hubConnection.Protocol.ParseRaw(msg.Bytes, msg.Bytes.Length);
            }
        }
Exemplo n.º 2
0
        public void ParseRaw(byte[] b, int length, IPEndPoint point)
        {
            string raw = Encoding.GetString(b, 0, length);

            if (raw == null)
            {
                return;
            }

            // If raw lenght is 0. Ignore
            if (raw.Length == 0)
            {
                return;
            }

            ConMessage msg = null;

            switch (raw[0])
            {
            case '$':       // Nmdc
                int    pos;
                string cmd = null;
                if ((pos = raw.IndexOf(' ')) != -1)
                {
                    cmd = raw.Substring(0, pos).ToLower();
                }
                else
                {
                    if (raw.Length >= 10)
                    {
                        break;
                    }
                    cmd = raw.ToLower();
                }
                if (cmd == null || cmd.Equals(string.Empty))
                {
                    break;
                }
                switch (cmd)
                {
                case "$sr":
                    msg = new ConMessage(null, b);
                    break;
                }
                break;

            case 'U':       // Adc
                Adc.AdcBaseMessage adc = null;
                if (!(adc = new Adc.RES(null, raw)).IsValid)
                {
                    adc = null;
                }
                if (adc == null && !(adc = new Adc.RES(null, raw)).IsValid)
                {
                    adc = null;
                }
                msg = adc;
                break;
            }
            // Do we support message type?
            if (msg == null)
            {
                return;
            }

            // Plugin handling here
            FmdcEventArgs e = new FmdcEventArgs(Actions.CommandIncomming, msg);

            MessageReceived(this, e);
            if (!e.Handled)
            {
                ActOnInMessage(msg);
            }
        }