Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public static SysCon Parse(byte[] data, int offset)
        {
            if (data == null || data.Length < 0x19 + offset)
            {
                return(null);
            }

            var result = new SysCon();

            result.sysType = (SysType)data[offset + 0x00];
            for (int i = 0; i < 4; i++)
            {
                result.Gprog[i] = data[offset + 0x01 + i];
                result.Gchan[i] = data[offset + 0x05 + i];
                result.Tprog[i] = data[offset + 0x09 + i];
                result.Tchan[i] = data[offset + 0x0d + i];
                result.Pprog[i] = data[offset + 0x11 + i];
                result.Pchan[i] = data[offset + 0x15 + i];
            }

            return(result);
        }
Ejemplo n.º 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);
        }