public PumpStationCreator(CommonDatabase database, GKPumpStation pumpStation, DatabaseType dataBaseType) { Database = database; PumpStation = pumpStation; DatabaseType = dataBaseType; foreach (var nsDevice in pumpStation.NSDevices) { if (nsDevice.DriverType == GKDriverType.RSR2_Bush_Fire) FirePumpDevices.Add(nsDevice); if (nsDevice.DriverType == GKDriverType.RSR2_Bush_Jokey) JockeyPumpDevices.Add(nsDevice); } }
void WriteEndDescriptor(CommonDatabase commonDatabase) { var endBytes = CreateEndDescriptor((ushort)(commonDatabase.Descriptors.Count + 1)); SendManager.Send(commonDatabase.RootDevice, 5, 17, 0, endBytes, true); }
bool WriteConfigToDevice(CommonDatabase commonDatabase, GKProgressCallback progressCallback, Guid clientUID) { using (var gkLifecycleManager = new GKLifecycleManager(commonDatabase.RootDevice, "Запись дескрипторов")) { for (int descriptorNo = 0; descriptorNo < commonDatabase.Descriptors.Count; descriptorNo++) { var descriptor = commonDatabase.Descriptors[descriptorNo]; gkLifecycleManager.Progress(descriptorNo + 1, commonDatabase.Descriptors.Count); var progressStage = commonDatabase.RootDevice.PresentationName + ": запись " + descriptor.GKBase.PresentationName + " " + "(" + descriptor.GetDescriptorNo() + ")" + " из " + commonDatabase.Descriptors.Count; GKProcessorManager.DoProgress(progressStage, progressCallback, clientUID); var packs = CreateDescriptors(descriptor); foreach (var pack in packs) { for (int i = 0; i < 10; i++) { var sendResult = SendManager.Send(commonDatabase.RootDevice, (ushort)(pack.Count), 17, 0, pack); if (sendResult.HasError) { if (i >= 9) { GKProcessorManager.StopProgress(progressCallback, clientUID); gkLifecycleManager.AddItem("Ошибка"); return false; } } else break; } } } GKProcessorManager.DoProgress(commonDatabase.RootDevice.PresentationName + " Запись завершающего дескриптора", progressCallback, clientUID); WriteEndDescriptor(commonDatabase); return true; } }
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); }
static string SetDeviceParameters(CommonDatabase commonDatabase, BaseDescriptor descriptor, List<byte> parameterBytes) { var device = descriptor.GKBase as GKDevice; if (device != null) { foreach (var property in device.Properties) { var driverProperty = device.Driver.Properties.FirstOrDefault(x => x.Name == property.Name); if (driverProperty != null) { double minValue = driverProperty.Min; double maxValue = driverProperty.Max; double value = property.Value; if (driverProperty.Multiplier != 0) { minValue /= driverProperty.Multiplier; maxValue /= driverProperty.Multiplier; value /= driverProperty.Multiplier; } if (minValue != 0) if (value < minValue) return "Параметр " + driverProperty.Caption + " должен быть больше " + minValue.ToString(); if (maxValue != 0) if (value > maxValue) return "Параметр " + driverProperty.Caption + " должен быть меньше " + maxValue.ToString(); } } } if (descriptor.Parameters.Count > 0) { var rootDevice = commonDatabase.RootDevice; var no = descriptor.GetDescriptorNo(); var bytes = new List<byte>(); bytes.AddRange(BytesHelper.ShortToBytes(no)); bytes.AddRange(parameterBytes); var sendResult = SendManager.Send(rootDevice, (ushort)bytes.Count, 10, 0, bytes); if (sendResult.HasError) return sendResult.Error; } return null; }
bool WriteConfigToDevice(CommonDatabase commonDatabase, GKProgressCallback progressCallback) { foreach (var descriptor in commonDatabase.Descriptors) { if (progressCallback.IsCanceled) return false; var progressStage = commonDatabase.RootDevice.PresentationName + ": запись " + descriptor.XBase.PresentationName + " " + "(" + descriptor.GetDescriptorNo() + ")" + " из " + commonDatabase.Descriptors.Count; GKProcessorManager.DoProgress(progressStage, progressCallback); var packs = CreateDescriptors(descriptor); foreach (var pack in packs) { var packBytesCount = pack.Count; var sendResult = SendManager.Send(commonDatabase.RootDevice, (ushort)(packBytesCount), 17, 0, pack); if (sendResult.HasError) { GKProcessorManager.StopProgress(progressCallback); Trace.WriteLine(progressStage); return false; } } } GKProcessorManager.DoProgress(commonDatabase.RootDevice.PresentationName + " Запись завершающего дескриптора", progressCallback); WriteEndDescriptor(commonDatabase); return true; }
static string SetDeviceParameters(CommonDatabase commonDatabase, BaseDescriptor descriptor, List<byte> parameterBytes) { if (descriptor.Device != null) { foreach (var property in descriptor.Device.Properties) { var driverProperty = descriptor.Device.Driver.Properties.FirstOrDefault(x => x.Name == property.Name); if (driverProperty != null) { if (driverProperty.Min != 0) if (property.Value < driverProperty.Min) return "Парметр " + driverProperty.Caption + " должен быть больше " + driverProperty.Min.ToString(); if (driverProperty.Max != 0) if (property.Value > driverProperty.Max) return "Парметр " + driverProperty.Caption + " должен быть меньше " + driverProperty.Max.ToString(); } } } if (descriptor.Parameters.Count > 0) { var rootDevice = commonDatabase.RootDevice; var no = descriptor.GetDescriptorNo(); var bytes = new List<byte>(); bytes.AddRange(BytesHelper.ShortToBytes(no)); //bytes.AddRange(descriptor.Parameters); bytes.AddRange(parameterBytes); var sendResult = SendManager.Send(rootDevice, (ushort)bytes.Count, 10, 0, bytes); if (sendResult.HasError) return sendResult.Error; } return null; }