예제 #1
0
 public BankModel(byte[] bytes)
 {
     using (var memoryStream = new MemoryStream(bytes))
     {
         using (var binaryReader = new SBinaryReader(memoryStream))
         {
             Name = binaryReader.ReadString(10);
             DateTime temp;
             if (DateTime.TryParse(binaryReader.ReadString(10), out temp))
             {
                 Date = temp;
             }
             else
             {
                 Date = DateTime.Now;
             }
             Place = binaryReader.ReadString(10);
             Maker = binaryReader.ReadString(10);
             Model = binaryReader.ReadString(10);
             Capa  = binaryReader.ReadString(10);
             Memo  = binaryReader.ReadString(10);
             Alarm = new AlarmModel(binaryReader.ReadBytes(8));
         }
     }
 }
예제 #2
0
 public IBexInfoModel(byte[] bytes)
 {
     using (var memoryStream = new MemoryStream(bytes))
     {
         using (var binaryReader = new SBinaryReader(memoryStream))
         {
             binaryReader.ReadBytes(4);
             Code = binaryReader.ReadByte();
             binaryReader.ReadByte();
             ZeroBaseDCV                = LittleEndian.ToInt32(binaryReader.ReadBytes(4));
             ImpedanceStandard          = LittleEndian.ToUint16(binaryReader.ReadBytes(2));
             CableImpedance             = LittleEndian.ToInt32(binaryReader.ReadBytes(4));
             InternalStateAndcorrection = binaryReader.ReadBytes(11);
             CurrentBankNumber          = binaryReader.ReadByte();
             CurrentCellNumber          = LittleEndian.ToUint16(binaryReader.ReadBytes(2));
             BacklightTime              = binaryReader.ReadByte();
             PowerConstant              = binaryReader.ReadByte();
             Contrast        = binaryReader.ReadByte();
             Temperature     = binaryReader.ReadByte();
             Buzzer          = binaryReader.ReadByte();
             Mode            = binaryReader.ReadByte();
             SelectedAlarm   = binaryReader.ReadByte();
             InterCorrection = binaryReader.ReadBytes(5);
             CurrentAlram    = new AlarmModel(binaryReader.ReadBytes(8));
             binaryReader.ReadBytes(10);
             AlarmGroups = new ObservableCollection <AlarmGroupModel>();
             var alarmGroup1 = new AlarmGroupModel();
             var alarmGroup2 = new AlarmGroupModel();
             var alarmGroup3 = new AlarmGroupModel();
             var alarmGroup4 = new AlarmGroupModel();
             alarmGroup1.Alarms = new ObservableCollection <AlarmModel>();
             alarmGroup2.Alarms = new ObservableCollection <AlarmModel>();
             alarmGroup3.Alarms = new ObservableCollection <AlarmModel>();
             alarmGroup4.Alarms = new ObservableCollection <AlarmModel>();
             AlarmGroups.Add(alarmGroup1);
             AlarmGroups.Add(alarmGroup2);
             AlarmGroups.Add(alarmGroup3);
             AlarmGroups.Add(alarmGroup4);
             for (int i = 0; i < 4; i++)
             {
                 AlarmGroups[i].Name = binaryReader.ReadString(10);
             }
             for (int i = 0; i < 4; i++)
             {
                 var alarmGroup = AlarmGroups[i];
                 for (int j = 0; j < 20; j++)
                 {
                     var alarmName = binaryReader.ReadString(10);
                     var alarm     = new AlarmModel(binaryReader.ReadBytes(8))
                     {
                         Name = alarmName
                     };
                     binaryReader.ReadBytes(2);
                     alarmGroup.Alarms.Add(alarm);
                 }
             }
         }
     }
 }
예제 #3
0
        public CellModel(byte[] bytes, AlarmModel alarm)
        {
            using (var memoryStream = new MemoryStream(bytes))
            {
                using (var binaryReader = new BinaryReader(memoryStream))
                {
                    bool ExistFF(byte[] source)
                    {
                        foreach (var item in source)
                        {
                            if (item != 0xff)
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }

                    var impedanceByte = new byte[4];
                    var b             = binaryReader.ReadBytes(3);
                    if (ExistFF(b))
                    {
                        Impedance = null;
                    }
                    else
                    {
                        b.CopyTo(impedanceByte, 0);
                        Impedance = Math.Round(LittleEndian.ToUInt32(impedanceByte) / 10000.0, 3);
                    }

                    var voltageByte = binaryReader.ReadBytes(2);
                    if (ExistFF(voltageByte))
                    {
                        Voltage = null;
                    }
                    else
                    {
                        Voltage = Math.Round(LittleEndian.ToUint16(voltageByte) / 1000.0, 2);
                    }
                    var temperatureByte = binaryReader.ReadByte();
                    if (temperatureByte >= 0xC7)
                    {
                        Temperature = null;
                    }
                    else
                    {
                        Temperature = Math.Round(temperatureByte / 2.0 - 20.0, 1);
                    }

                    if (alarm != null)
                    {
                        if (Impedance.HasValue && alarm.ImpedanceStandard != 0)
                        {
                            ImpedancePercentage = Impedance.Value / alarm.ImpedanceStandard * 100;
                            ImpedancePercentage = Math.Round(ImpedancePercentage.Value, 2);
                            if (ImpedancePercentage > alarm.ImpedanceFail)
                            {
                                ImpedanceAlarm = Definitions.Alarm.Status.Fail;
                            }
                            else if (ImpedancePercentage > alarm.ImpedanceAlarm)
                            {
                                ImpedanceAlarm = Definitions.Alarm.Status.Waring;
                            }
                            else
                            {
                                ImpedanceAlarm = Definitions.Alarm.Status.Normal;
                            }
                        }
                        else
                        {
                            ImpedanceAlarm = Definitions.Alarm.Status.Normal;
                        }

                        if (Voltage.HasValue)
                        {
                            if (Voltage.Value >= alarm.OverVoltage || Voltage.Value <= alarm.UnderVoltage)
                            {
                                VoltageAlarm = Definitions.Alarm.Status.Fail;
                            }
                            else
                            {
                                VoltageAlarm = Definitions.Alarm.Status.Normal;
                            }
                        }
                        else
                        {
                            VoltageAlarm = Definitions.Alarm.Status.Normal;
                        }


                        if (Temperature.HasValue)
                        {
                            if (Temperature.Value >= alarm.Temperature)
                            {
                                TemperatureAlarm = Definitions.Alarm.Status.Fail;
                            }
                            else
                            {
                                TemperatureAlarm = Definitions.Alarm.Status.Normal;
                            }
                        }
                        else
                        {
                            TemperatureAlarm = Definitions.Alarm.Status.Normal;
                        }
                    }
                }
            }
        }