示例#1
0
		List<List<byte>> CreateDescriptors(BaseDescriptor descriptor)
		{
			var objectNo = (ushort)(descriptor.GetDescriptorNo());

			var packs = new List<List<byte>>();
			for (int packNo = 0; packNo <= descriptor.AllBytes.Count / 256; packNo++)
			{
				int packLenght = Math.Min(256, descriptor.AllBytes.Count - packNo * 256);
				var packBytes = descriptor.AllBytes.Skip(packNo * 256).Take(packLenght).ToList();

				if (packBytes.Count > 0)
				{
					var resultBytes = new List<byte>();
					ushort descriptorNo = (ushort)(descriptor.GetDescriptorNo());
					resultBytes.AddRange(BytesHelper.ShortToBytes(descriptorNo));
					resultBytes.Add((byte)(packNo + 1));
					resultBytes.AddRange(packBytes);
					packs.Add(resultBytes);
				}
			}
			return packs;
		}
示例#2
0
		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);
		}
示例#3
0
		void AddJournalItem(BaseDescriptor baseDescriptor, byte code, byte eventDescription, byte eventYesNo, int objectState)
		{
			var imitatorJournalItem = new ImitatorJournalItem();
			imitatorJournalItem.DateTime = DateTime.Now;
			imitatorJournalItem.GkNo = JournalHelper.ImitatorJournalItemCollection.ImitatorJournalItems.Count + 1;
			imitatorJournalItem.GkObjectNo = baseDescriptor.GetDescriptorNo();

			imitatorJournalItem.Source = 2;
			imitatorJournalItem.Code = code;
			imitatorJournalItem.EventDescription = eventDescription;
			imitatorJournalItem.EventYesNo = eventYesNo;

			imitatorJournalItem.ObjectNo = 0;
			imitatorJournalItem.ObjectDeviceType = 0;
			imitatorJournalItem.ObjectDeviceAddress = 0;
			imitatorJournalItem.ObjectFactoryNo = 0;
			imitatorJournalItem.ObjectState = objectState;

			if (baseDescriptor.Device != null)
			{
				imitatorJournalItem.ObjectDeviceType = (short)baseDescriptor.Device.Driver.DriverTypeNo;
				imitatorJournalItem.ObjectDeviceAddress = (short)((baseDescriptor.Device.ShleifNo - 1) * 256 + baseDescriptor.Device.IntAddress);
			}

			JournalHelper.ImitatorJournalItemCollection.ImitatorJournalItems.Add(imitatorJournalItem);
			JournalHelper.Save();
		}
示例#4
0
		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;
		}
示例#5
0
		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;
		}