Beispiel #1
0
        public static SysInt Parse(byte[] data, int offset)
        {
            if (data == null || data.Length < 0xFF + offset)
            {
                return(null);
            }

            var result = new SysInt();

            DateTime curdate;
            var      dateTimeString = string.Format("{0}.{1}.{2} {3}:00:00",
                                                    ConvertHelper.BinDecToInt(data[offset + 1]), //day
                                                    ConvertHelper.BinDecToInt(data[offset + 2]), //mon
                                                    ConvertHelper.BinDecToInt(data[offset + 3]), //yr
                                                    ConvertHelper.BinDecToInt(data[offset + 0])  //hr
                                                    );

            DateTime.TryParse(dateTimeString, out curdate);
            result.date = curdate;

            result.Trab.Value[0] = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x68, 4), 0);

            for (var sysch = 0; sysch < 4; sysch++)
            {
                result.IntV.Value[sysch] =
                    BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0x08 + sysch * 4, 4), 0) +
                    BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x38 + sysch * 4, 4), 0);
                result.IntM.Value[sysch] =
                    BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0x18 + sysch * 4, 4), 0) +
                    BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x48 + sysch * 4, 4), 0);
                result.IntQ.Value[sysch] =
                    BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0x28 + sysch * 4, 4), 0) +
                    BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x58 + sysch * 4, 4), 0);

                result.Tnar.Value[sysch] = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x6c + sysch * 4, 4), 0);
                //result.Tmin.Value[sysch] = BitConverter.ToInt32(GetReversed(data, offset + 0x7c + sysch * 4, 4), 0);
                //result.Tmax.Value[sysch] = BitConverter.ToInt32(GetReversed(data, offset + 0x8c + sysch * 4, 4), 0);
                //result.Tdt.Value[sysch] = BitConverter.ToInt32(GetReversed(data, offset + 0x9c + sysch * 4, 4), 0);
                //result.Ttn.Value[sysch] = BitConverter.ToInt32(GetReversed(data, offset + 0xac + sysch * 4, 4), 0);

                result.Rshv.Value[sysch] = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0xec + sysch * 4, 4), 0);

                for (int i = 0; i < 3; i++)
                {
                    result.T.Value[sysch * 3 + i] = (double)(BitConverter.ToInt16(ConvertHelper.GetReversed(data, offset + 0xc8 + (sysch * 3 + i) * 2, 2), 0)) / 100;
                    result.P.Value[sysch * 3 + i] = (double)(data[offset + 0xe0 + (sysch * 3 + i)]) / 100;
                }
            }

            return(result);
        }
Beispiel #2
0
        public static T2K Parse(byte[] data, int offset)
        {
            if (data == null || data.Length < 0x2FF + offset)
            {
                return(null);
            }

            var result = new T2K();

            result.Systems = data[offset + 0];
            for (int i = 0; i < 12; i++)
            {
                result.Type_g[i] = (TypeG)data[offset + 0x01 + i];
                result.Type_t[i] = (TypeT)data[offset + 0x0c + i];
            }
            result.Net_num = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x78, 4), 0);
            result.Number  = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x7c, 4), 0);

            for (int i = 0; i < 4; i++)
            {
                result.Diam[i]       = BitConverter.ToInt16(ConvertHelper.GetReversed(data, offset + 0xc4 + i * 2, 2), 0);
                result.G_max[i]      = BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0xcc + i * 4, 4), 0);
                result.G_pcnt_max[i] = data[offset + 0xdc + i];
                result.G_pcnt_min[i] = data[offset + 0xe0 + i];
            }

            for (int i = 0; i < 2; i++)
            {
                result.F_max[i]  = BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0xe4 + i * 4, 4), 0);
                result.Weight[i] = BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0xec + i * 4, 4), 0);//??? 74? EC?
            }

            result.SysInt_copy = SysInt.Parse(data, offset + 0x200);
            for (int i = 0; i < 4; i++)
            {
                result.SysConN[i] = SysCon.Parse(data, offset + 0x600 + i * 0x20);
            }

            return(result);
        }
Beispiel #3
0
        private dynamic ReadArchive(ArchiveType archiveType, TimeSpan d, DateTime start, DateTime end, DateTime currentDt)
        {
            dynamic archive = new ExpandoObject();

            archive.success   = true;
            archive.error     = string.Empty;
            archive.errorcode = DeviceError.NO_ERROR;
            var    allRecs = new List <dynamic>();
            string type    = archiveType == ArchiveType.Hourly ? "Hour" : "Day";

            if (T2k == null)
            {
                archive.error   = "не удалось прочесть память таймера 2к";
                archive.success = false;
                return(archive);
            }

            log($"Чтение {archiveType} архива");

            for (var date = start.Date.AddHours(start.Hour); date <= end; date.Add(d))
            {
                List <dynamic> recs = new List <dynamic>();

                if (cancel())
                {
                    archive.success = false;
                    archive.error   = "опрос отменен";
                    break;
                }

                if (date >= currentDt)
                {
                    log(string.Format("данные за {0:dd.MM.yyyy HH:mm} еще не собраны", date));
                    break;
                }

                log($"Запрос даты {date:HH:mm dd.MM.yyyy}");

                var answer = Send(MakeBaseRequest(0x0d11, new byte[] {
                    (byte)archiveType,
                    archiveType == ArchiveType.Hourly? IntToBCD(date.Hour):(byte)0x00,
                    archiveType != ArchiveType.Monthly? IntToBCD(date.Day):(byte)0x01,
                    IntToBCD(date.Month),
                    IntToBCD(date.Year - 2000)
                }));

                if (!answer.success)
                {
                    return(answer);
                }

                byte[] body = answer.Body as byte[];

                if (body.Length == 3)
                {
                    var num = body[1] << 8 | body[2];
                    if (num == 0xFFFF)
                    {
                        log("запись не обнаружена");
                    }
                    else
                    {
                        log($"номер записи: {num} (0x{num:X4})");
                        //Int64 addr = 0;
                        //var answer0 = SendRequest(0x0f03, new byte[] { 64, (byte)(addr >> 24), (byte)(addr >> 16), (byte)(addr >> 08), (byte)(addr) });
                        //answer = new byte[256];

                        List <byte> bytes = new List <byte>();
                        for (int i = 0; i < 4; i++)
                        {
                            var curanswer = Send(MakeBaseRequest(0x0f03, new byte[] { 64, 0x00, ConvertHelper.ByteHigh(num), ConvertHelper.ByteLow(num) /*answer[1], answer[2]*/, (byte)(i * 0x40) }), 3333, 5);
                            if (!curanswer.success || (curanswer.Body as byte[]).Length != 65)
                            {
                                log("не удалось запросить запись, пропуск");
                                return(curanswer);
                            }
                            bytes.AddRange((curanswer.Body as byte[]).Skip(1));
                        }


                        var sysInt = SysInt.Parse(bytes.ToArray(), 0);

                        if (T2k.Systems < 1 || T2k.Systems > 4)
                        {
                            log($"Некорректное число систем: {T2k.Systems}");
                            answer.error   = "";
                            answer.success = false;
                            return(answer);
                        }

                        recs.Add(MakeDayOrHourRecord(archiveType == ArchiveType.Hourly ? "Hour" : "Day", sysInt.Trab.Parameter, sysInt.Trab.Value[0], sysInt.Trab.MeasuringUnit, sysInt.date));

                        for (int sys = 0; sys < T2k.Systems; sys++)
                        {
                            var systype = T2k.SysConN[sys].sysType;
                            recs.Add(MakeDayOrHourRecord(type, sysInt.IntV.Parameter, sysInt.IntV.Value[sys], sysInt.IntV.MeasuringUnit, sysInt.date));
                            recs.Add(MakeDayOrHourRecord(type, sysInt.IntM.Parameter, sysInt.IntM.Value[sys], sysInt.IntM.MeasuringUnit, sysInt.date));
                            recs.Add(MakeDayOrHourRecord(type, sysInt.IntQ.Parameter, sysInt.IntQ.Value[sys], sysInt.IntQ.MeasuringUnit, sysInt.date));
                            recs.Add(MakeDayOrHourRecord(type, sysInt.Tnar.Parameter, sysInt.Tnar.Value[sys], sysInt.Tnar.MeasuringUnit, sysInt.date));

                            for (int i = 0; i < SysCon.GetChannelsPorT(systype); i++)
                            {
                                recs.Add(MakeDayOrHourRecord(type, sysInt.T.Parameter, sysInt.T.Value[sys * 3 + i], sysInt.T.MeasuringUnit, sysInt.date));
                                recs.Add(MakeDayOrHourRecord(type, sysInt.P.Parameter, sysInt.P.Value[sys * 3 + i], sysInt.P.MeasuringUnit, sysInt.date));
                            }

                            recs.Add(MakeDayOrHourRecord(type, sysInt.Rshv.Parameter, sysInt.Rshv.Value[sys], sysInt.Rshv.MeasuringUnit, sysInt.date));
                        }

                        allRecs.AddRange(recs);
                        records(recs);
                    }
                }
                else
                {
                    log("ответ не получен");
                }
            }

            archive.records = allRecs;
            return(archive);
        }