Exemplo n.º 1
0
        public static byte[] encode(DecodedMessge messge)
        {
            string ans = "";

            switch (messge.type)
            {
            case (msgType.FUNC):
                ans += "fuction";
                break;

            case (msgType.OBJ):
                ans += "object";
                break;

            case (msgType.ALARM):
                ans += "alarm";
                break;
            }
            ans += (char)ETB;
            ans += messge.name;
            ans += (char)ETB;
            foreach (string param in messge.param_list)
            {
                ans += param;
                ans += (char)ETB;
            }
            ans += (char)EOT;

            return(Encoding.ASCII.GetBytes(ans));
        }
Exemplo n.º 2
0
 public static void start()
 {
     while (true)
     {
         byte[]        ans_e = Connection.ConnectionManager.readMessageCon();
         DecodedMessge ans   = Connection.Decoder.decode(ans_e);
         if (ans.type == msgType.ALARM)
         {
             handleAlarm(ans);
         }
         else
         {
             lock (nonAlarmMsg)
             {
                 nonAlarmMsg.Enqueue(ans);
                 waitlock.Set();
             }
         }
     }
 }
Exemplo n.º 3
0
        public static DecodedMessge decode(byte[] msg)
        {
            DecodedMessge ans = new DecodedMessge();

            string        currentPart = "";
            List <string> brokenMsg   = new List <string>();

            foreach (byte b in msg)
            {
                if (Convert.ToChar(b) == ETB)
                {
                    brokenMsg.Add(currentPart);
                    currentPart = "";
                }
                else
                {
                    currentPart += Convert.ToChar(b);
                }
            }
            switch (brokenMsg[0])
            {
            case ("fuction"):
                ans.type = msgType.FUNC;
                break;

            case ("object"):
                ans.type = msgType.OBJ;
                break;

            case ("alarm"):
                ans.type = msgType.ALARM;
                break;
            }
            ans.name       = brokenMsg[1];
            ans.param_list = brokenMsg.GetRange(2, brokenMsg.Count - 2).ToArray();
            return(ans);
        }
Exemplo n.º 4
0
 private static void handleAlarm(DecodedMessge alarm)
 {
     MessageBox.Show(alarm.param_list[0], alarm.name);
 }