Exemple #1
0
        private dynamic ParseAbnormal(byte[] bytes)
        {
            dynamic abnormal = new ExpandoObject();

            if (bytes.Length != 8)
            {
                abnormal.success = false;
                abnormal.error   = "тело параметра имеет не верное количество байт (8 байт)";
                return(abnormal);
            }

            if (bytes[0] != 0x10)
            {
                abnormal.success = false;
                abnormal.error   = "отстутствует запись НС";
                return(abnormal);
            }

            try
            {
                int year   = bytes[1];
                int month  = bytes[2];
                int day    = bytes[3];
                int hour   = bytes[4];
                int minute = bytes[5];
                abnormal.date = new DateTime(2000 + year, month, day, hour, minute, 0);
            }
            catch (Exception ex)
            {
                abnormal.success = false;
                abnormal.error   = "ошибка при чтении НС";
                return(abnormal);
            }

            abnormal.code = bytes[6];
            abnormal.flag = bytes[7];
            string situations = "";

            if (Situations.ContainsKey(abnormal.code))
            {
                situations = Situations[abnormal.code];
            }
            else
            {
                situations = "сведения об ошибке отсутствует";
            }

            abnormal.situation = string.Format("(код {0}): {1}, статус: {2}", abnormal.code, situations, abnormal.flag == 1 ? "появилась" : "устранилась");
            abnormal.success   = true;
            return(abnormal);
        }