Example #1
0
 public wtMessage(WTMESSAGES MSG, string src, string dst, string data, string extra)
 {
     Msg         = MSG;
     Src         = src;
     Dst         = dst;
     Data        = data;
     Extra       = extra;
     Checksum    = 0;
     HasChecksum = false;
 }
Example #2
0
 public wtMessage(byte[] bytes)
 {
     Msg         = WTMESSAGES.NONE;
     Src         = "";
     Dst         = "";
     Data        = "";
     Extra       = "";
     Checksum    = 0;
     HasChecksum = false;
     this.FromBytes(bytes);
 }
Example #3
0
        public void FromBytes(byte[] bytes)
        {
            // convert bytes coded in UTF8 to text
            string text = Encoding.ASCII.GetString(bytes);
            string msg  = text.Substring(0, text.IndexOf(": "));

            try
            {
                Msg = (WTMESSAGES)Enum.Parse(typeof(WTMESSAGES), msg);
            }
            catch
            {
                Msg = WTMESSAGES.UNKNOWN;
            }
            text = text.Remove(0, text.IndexOf(": ") + 2);
            Src  = text.Substring(0, text.IndexOf(" ")).Replace("\"", "");
            text = text.Remove(0, text.IndexOf(" ") + 1);
            Dst  = text.Substring(0, text.IndexOf(" ")).Replace("\"", "");
            text = text.Remove(0, text.IndexOf(" ") + 1);
            // Clean up the message --> scrub last byte
            text = text.Substring(0, text.Length - 1).Replace("\"", "");
            // convert bytes coded in UTF8 to text
            Data = text.Substring(0, text.Length);
            // get checksum
            Checksum = (byte)(bytes[bytes.Length - 1] | 0x80);
            byte sum = 0;

            for (int i = 0; i < bytes.Length - 1; i++)
            {
                sum += bytes[i];
            }
            sum = (byte)(sum | 0x80);
            if (Checksum == sum)
            {
                HasChecksum = true;
            }
            else
            {
                HasChecksum = false;
            }
        }