void SetPropertiesBytes() { var binProperties = new List<BinProperty>(); if (DatabaseType == DatabaseType.Gk && Device.Driver.IsDeviceOnShleif) { return; } foreach (var property in Device.Properties) { var driverProperty = Device.Driver.Properties.FirstOrDefault(x => x.Name == property.Name); if (driverProperty != null && driverProperty.IsAUParameter) { if (driverProperty.IsMPTOrMRORegime) { if (Device.DriverType == XDriverType.MPT) property.Value = Device.IsChildMPTOrMRO() ? (ushort)(2 << 6) : (ushort)(1 << 6); if (Device.DriverType == XDriverType.MRO_2) property.Value = Device.IsChildMPTOrMRO() ? (ushort)1 : (ushort)2; } byte no = driverProperty.No; ushort value = property.Value; if (driverProperty.Mask > 0) { if (driverProperty.DriverPropertyType == XDriverPropertyTypeEnum.BoolType) { if (value > 0) value = (ushort)driverProperty.Mask; } else { value = (ushort)(value & driverProperty.Mask); } } if (driverProperty.IsHieghByte) value = (ushort)(value * 256); if (driverProperty.Multiplier != 0) value = (ushort)(value * driverProperty.Multiplier); if (Device.DriverType == XDriverType.RSR2_KAU && driverProperty.No == 1) { value = (ushort)(256 + value % 256); } var binProperty = binProperties.FirstOrDefault(x => x.No == no); if (binProperty == null) { binProperty = new BinProperty() { No = no }; binProperties.Add(binProperty); } binProperty.Value += value; } } foreach (var binProperty in binProperties) { Parameters.Add(binProperty.No); Parameters.AddRange(BitConverter.GetBytes(binProperty.Value)); Parameters.Add(0); } }
void SetPropertiesBytes() { Parameters = new List<byte>(); var binProperties = new List<BinProperty>(); if (DatabaseType == DatabaseType.Gk && Device.Driver.IsDeviceOnShleif) { return; } if (DatabaseType == DatabaseType.Gk && (Device.DriverType == GKDriverType.GKMirror || (Device.Parent!=null && Device.Parent.DriverType == GKDriverType.GKMirror))) { return; } Device.Properties = (from i in Device.Driver.Properties join o in Device.Properties on i.Name equals o.Name select o).ToList(); foreach (var property in Device.Properties) { var driverProperty = Device.Driver.Properties.FirstOrDefault(x => x.Name == property.Name); if (driverProperty != null && driverProperty.IsAUParameter) { if (driverProperty.CanNotEdit) { if (Device.DriverType == GKDriverType.RSR2_MVP) { if (driverProperty.Name == "Число АУ на АЛС3 МВП") property.Value = (ushort)Device.Children[0].AllChildren.Count(x => x.Driver.IsReal && !x.Driver.IsGroupDevice); if (driverProperty.Name == "Число АУ на АЛС4 МВП") property.Value = (ushort)Device.Children[1].AllChildren.Count(x => x.Driver.IsReal && !x.Driver.IsGroupDevice); } if (Device.DriverType == GKDriverType.RSR2_KDKR) { if (driverProperty.Name == "Число АУ на АЛС3 КД") property.Value = (ushort)Device.Children[13].AllChildren.Count(x => x.Driver.IsReal && !x.Driver.IsGroupDevice); if (driverProperty.Name == "Число АУ на АЛС4 КД") property.Value = (ushort)Device.Children[14].AllChildren.Count(x => x.Driver.IsReal && !x.Driver.IsGroupDevice); } } byte no = driverProperty.No; ushort value = property.Value; if (driverProperty.Mask > 0) { if (driverProperty.DriverPropertyType == GKDriverPropertyTypeEnum.BoolType) { if (value > 0) value = (ushort)driverProperty.Mask; } else { value = (ushort)(value & driverProperty.Mask); } } if (driverProperty.IsHieghByte) value = (ushort)(value * 256); if (Device.DriverType == GKDriverType.RSR2_KAU && driverProperty.No == 1) { value = (ushort)(256 + value % 256); } var binProperty = binProperties.FirstOrDefault(x => x.No == no); if (binProperty == null) { binProperty = new BinProperty() { No = no }; binProperties.Add(binProperty); } binProperty.Value += value; } } foreach (var binProperty in binProperties) { Parameters.Add(binProperty.No); Parameters.AddRange(BitConverter.GetBytes(binProperty.Value)); Parameters.Add(0); } }
List<GKProperty> GetPropertiesFromBytes(List<byte> bytes) { var properties = new List<GKProperty>(); var binProperties = new List<BinProperty>(); for (int i = 0; i < bytes.Count / 4; i++) { byte paramNo = bytes[i * 4]; ushort paramValue = BytesHelper.SubstructShort(bytes, i * 4 + 1); var binProperty = new BinProperty() { No = paramNo, Value = paramValue }; binProperties.Add(binProperty); } var device = GKBaseDescriptor.GKBase as GKDevice; if (device != null) { foreach (var driverProperty in device.Driver.Properties) { if (!driverProperty.IsAUParameter) continue; var binProperty = binProperties.FirstOrDefault(x => x.No == driverProperty.No); if (binProperty != null) { var paramValue = binProperty.Value; if (driverProperty.IsLowByte) { paramValue = (ushort)(paramValue << 8); paramValue = (ushort)(paramValue >> 8); } if (driverProperty.IsHieghByte) { paramValue = (ushort)(paramValue / 256); } if (driverProperty.Mask != 0) { paramValue = (byte)(paramValue & driverProperty.Mask); } var property = device.DeviceProperties.FirstOrDefault(x => x.Name == driverProperty.Name); if (property == null) { var systemProperty = device.Properties.FirstOrDefault(x => x.Name == driverProperty.Name); property = new GKProperty() { DriverProperty = systemProperty.DriverProperty, Name = systemProperty.Name, Value = paramValue, }; device.DeviceProperties.Add(property); } if (property != null) { property.Value = paramValue; property.DriverProperty = driverProperty; if (property.DriverProperty.DriverPropertyType == GKDriverPropertyTypeEnum.BoolType) property.Value = (ushort)(property.Value > 0 ? 1 : 0); properties.Add(property); } } else throw new Exception("Неизвестный номер параметра"); } } if (binProperties.Count >= 3) { if (GKBaseDescriptor.DescriptorType == DescriptorType.Direction || GKBaseDescriptor.DescriptorType == DescriptorType.Delay || GKBaseDescriptor.DescriptorType == DescriptorType.GuardZone || GKBaseDescriptor.DescriptorType == DescriptorType.PumpStation || GKBaseDescriptor.DescriptorType == DescriptorType.Door) { properties.Add(new GKProperty() { Value = binProperties[0].Value }); properties.Add(new GKProperty() { Value = binProperties[1].Value }); properties.Add(new GKProperty() { Value = binProperties[2].Value }); } } if (GKBaseDescriptor.DescriptorType == DescriptorType.Code && binProperties.Count >= 2) { properties.Add(new GKProperty() { Value = binProperties[0].Value }); properties.Add(new GKProperty() { Value = binProperties[1].Value }); } return properties; }
static OperationResult<List<GKProperty>> GetDeviceParameters(CommonDatabase commonDatabase, BaseDescriptor descriptor) { var properties = new List<GKProperty>(); var no = descriptor.GetDescriptorNo(); var sendResult = SendManager.Send(commonDatabase.RootDevice, 2, 9, ushort.MaxValue, BytesHelper.ShortToBytes(no)); if (sendResult.HasError) { return OperationResult<List<GKProperty>>.FromError(sendResult.Error); } var binProperties = new List<BinProperty>(); for (int i = 0; i < sendResult.Bytes.Count / 4; i++) { byte paramNo = sendResult.Bytes[i * 4]; ushort paramValue = BytesHelper.SubstructShort(sendResult.Bytes, i * 4 + 1); var binProperty = new BinProperty() { No = paramNo, Value = paramValue }; binProperties.Add(binProperty); } var device = descriptor.GKBase as GKDevice; if (device != null) { foreach (var driverProperty in device.Driver.Properties) { if (!driverProperty.IsAUParameter) continue; var binProperty = binProperties.FirstOrDefault(x => x.No == driverProperty.No); if (binProperty != null) { var paramValue = binProperty.Value; if (driverProperty.IsLowByte) { paramValue = (ushort)(paramValue << 8); paramValue = (ushort)(paramValue >> 8); } if (driverProperty.IsHieghByte) { paramValue = (ushort)(paramValue / 256); } if (driverProperty.Mask != 0) { paramValue = (byte)(paramValue & driverProperty.Mask); } var property = device.DeviceProperties.FirstOrDefault(x => x.Name == driverProperty.Name); if (property == null) { var systemProperty = device.Properties.FirstOrDefault(x => x.Name == driverProperty.Name); property = new GKProperty() { DriverProperty = systemProperty.DriverProperty, Name = systemProperty.Name, Value = paramValue, }; device.DeviceProperties.Add(property); } if (property != null) { property.Value = paramValue; property.DriverProperty = driverProperty; if (property.DriverProperty.DriverPropertyType == GKDriverPropertyTypeEnum.BoolType) property.Value = (ushort)(property.Value > 0 ? 1 : 0); properties.Add(property); } } else return OperationResult<List<GKProperty>>.FromError("Неизвестный номер параметра"); } } if ((descriptor.DescriptorType == DescriptorType.Direction || descriptor.DescriptorType == DescriptorType.Delay || descriptor.DescriptorType == DescriptorType.GuardZone || descriptor.DescriptorType == DescriptorType.PumpStation) && binProperties.Count >= 3) { properties.Add(new GKProperty() { Value = binProperties[0].Value }); properties.Add(new GKProperty() { Value = binProperties[1].Value }); properties.Add(new GKProperty() { Value = binProperties[2].Value }); } if ((descriptor.DescriptorType == DescriptorType.Code || descriptor.DescriptorType == DescriptorType.Door) && binProperties.Count >= 2) { properties.Add(new GKProperty() { Value = binProperties[0].Value }); properties.Add(new GKProperty() { Value = binProperties[1].Value }); } return new OperationResult<List<GKProperty>>(properties); }