Пример #1
0
		public DescriptorViewModel(BaseDescriptor descriptor)
		{
			GKBaseDescriptor = descriptor;
			GKDescriptorNo = descriptor.GKBase.GKDescriptorNo;
			KauDescriptorNo = descriptor.GKBase.KAUDescriptorNo;

			SetAutomaticRegimeCommand = new RelayCommand(OnSetAutomaticRegime);
			SetManualRegimeCommand = new RelayCommand(OnSetManualRegime);
			SetIgnoreRegimeCommand = new RelayCommand(OnSetIgnoreRegime);
			ShowParametersCommand = new RelayCommand(OnShowParameters);
			ShowMeasureCommand = new RelayCommand(OnShowMeasure);
			ShowCardReaderCommand = new RelayCommand(OnShowCardReader);

			InitializeTest();
			InitializeDustiness();
			InitializeController();
			InitializeTypeNo();
			InitializeFire();
			InitializeTurning();
			InitializeLogic();
			InitializeDelays();
			InitializeAll();

			AdditionalShortParameters = new List<ushort>();
			for (int i = 0; i < 10; i++)
			{
				AdditionalShortParameters.Add(0);
			}
		}
Пример #2
0
		public DescriptorViewModel(BaseDescriptor descriptor, DescriptorsViewModel descriptorsViewModel)
		{
			NavigateCommand = new RelayCommand(OnNavigate);
			DescriptorsViewModel = descriptorsViewModel;
			Descriptor = descriptor;
			Description = descriptor.XBase.PresentationName;
			switch (descriptor.DescriptorType)
			{
				case DescriptorType.Device:
					ImageSource = descriptor.Device.Driver.ImageSource;
					break;

				case DescriptorType.Zone:
					ImageSource = "/Controls;component/Images/Zone.png";
					break;

				case DescriptorType.Direction:
					ImageSource = "/Controls;component/Images/Blue_Direction.png";
					break;

				case DescriptorType.PumpStation:
					ImageSource = "/Controls;component/Images/BPumpStation.png";
					break;

				case DescriptorType.Delay:
					ImageSource = "/Controls;component/Images/Delay.png";
					break;

				case DescriptorType.Pim:
					ImageSource = "/Controls;component/Images/Pim.png";
					break;
			}

			IsFormulaInvalid = Descriptor.Formula.CalculateStackLevels();
		}
Пример #3
0
		public BinaryObjectViewModel(BaseDescriptor binaryObject)
		{
			SetAutomaticRegimeCommand = new RelayCommand(OnSetAutomaticRegime);
			SetManualRegimeCommand = new RelayCommand(OnSetManualRegime);
			SetIgnoreRegimeCommand = new RelayCommand(OnSetIgnoreRegime);

			BinaryObject = binaryObject;
			Description = binaryObject.XBase.PresentationName;
			switch (binaryObject.DescriptorType)
			{
				case DescriptorType.Device:
					ImageSource = binaryObject.Device.Driver.ImageSource;
					break;

				case DescriptorType.Zone:
				case DescriptorType.Direction:
					ImageSource = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.System).ImageSource;
					break;
			}

			//Formula = BinaryObject.Formula.GetStringFomula();

			StateBits = new ObservableCollection<StateBitViewModel>();
			StateBits.Add(new StateBitViewModel(this, XStateBit.Norm, true));
			StateBits.Add(new StateBitViewModel(this, XStateBit.Fire1));
			StateBits.Add(new StateBitViewModel(this, XStateBit.Fire2));
			StateBits.Add(new StateBitViewModel(this, XStateBit.On));
		}
Пример #4
0
		public DescriptorViewModel(BaseDescriptor descriptor, DescriptorsViewModel descriptorsViewModel)
		{
			NavigateCommand = new RelayCommand(OnNavigate);
			DescriptorsViewModel = descriptorsViewModel;
			Descriptor = descriptor;
			PresentationName = descriptor.GKBase.PresentationName;
			Description = descriptor.GKBase.Description;
			switch (descriptor.DescriptorType)
			{
				case DescriptorType.Device:
					var device = descriptor.GKBase as GKDevice;
					if (device != null)
					{
						ImageSource = device.Driver.ImageSource;
					}
					break;

				case DescriptorType.Zone:
					ImageSource = "/Controls;component/Images/Zone.png";
					break;

				case DescriptorType.Direction:
					ImageSource = "/Controls;component/Images/Blue_Direction.png";
					break;

				case DescriptorType.PumpStation:
					ImageSource = "/Controls;component/Images/BPumpStation.png";
					break;

				case DescriptorType.MPT:
					ImageSource = "/Controls;component/Images/BMPT.png";
					break;

				case DescriptorType.Delay:
					ImageSource = "/Controls;component/Images/Delay.png";
					break;

				case DescriptorType.Pim:
					ImageSource = "/Controls;component/Images/Pim.png";
					break;

				case DescriptorType.GuardZone:
					ImageSource = "/Controls;component/Images/GuardZone.png";
					break;

				case DescriptorType.Code:
					ImageSource = "/Controls;component/Images/Code.png";
					break;

				case DescriptorType.Door:
					ImageSource = "/Controls;component/Images/Door.png";
					break;
			}

			IsFormulaInvalid = !Descriptor.Formula.CheckStackOverflow();
		}
Пример #5
0
		public DescriptorError(BaseDescriptor baseDescriptor, string error)
		{
			BaseDescriptor = baseDescriptor;
			Error = error;
		}
Пример #6
0
		public void SetKauDescriptor(BaseDescriptor kauBaseDescriptor)
		{
			KauBaseDescriptor = kauBaseDescriptor;
			InitializeLogic();
		}
Пример #7
0
		void ChangeJournalOnDevice(BaseDescriptor descriptor, JournalItem journalItem)
		{
			if (descriptor.Device != null)
			{
				var device = descriptor.Device;
				if (device.DriverType == XDriverType.AM1_T)
				{
					if (journalItem.Name == "Сработка-2")
					{
						var property = device.Properties.FirstOrDefault(x => x.Name == "OnMessage");
						if (property != null)
						{
							journalItem.Description = property.StringValue;
						}
					}
					if (journalItem.Name == "Норма")
					{
						var property = device.Properties.FirstOrDefault(x => x.Name == "NormMessage");
						if (property != null)
						{
							journalItem.Description = property.StringValue;
						}
					}
				}
				if (device.DriverType == XDriverType.Valve)
				{
					switch (journalItem.Name)
					{
						case "Включено":
							journalItem.Name = "Открыто";
							break;

						case "Выключено":
							journalItem.Name = "Закрыто";
							break;

						case "Включается":
							journalItem.Name = "Открывается";
							break;

						case "Выключается":
							journalItem.Name = "Закрывается";
							break;
					}
				}
			}
		}
Пример #8
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;
		}
Пример #9
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);
		}
Пример #10
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;
		}
Пример #11
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();
		}
Пример #12
0
		public DescriptorLogicItem(FormulaOperation formulaOperation, DescriptorsViewModel descriptorsViewModel, BaseDescriptor descriptor)
		{
			FormulaOperation = formulaOperation;
			DescriptorsViewModel = descriptorsViewModel;
			FirstOperand = FormulaOperation.FirstOperand.ToString();
			FirstOperandByte = FormulaOperation.FirstOperand;
			SecondOperand = FormulaOperation.SecondOperand.ToString();
			Descriptor = descriptor;

			switch (FormulaOperation.FormulaOperationType)
			{
				case FormulaOperationType.ADD:
				case FormulaOperationType.AND:
				case FormulaOperationType.COM:
				case FormulaOperationType.DUP:
				case FormulaOperationType.END:
				case FormulaOperationType.EQ:
				case FormulaOperationType.GE:
				case FormulaOperationType.GT:
				case FormulaOperationType.LE:
				case FormulaOperationType.LT:
				case FormulaOperationType.MUL:
				case FormulaOperationType.NE:
				case FormulaOperationType.NEG:
				case FormulaOperationType.OR:
				case FormulaOperationType.SUB:
				case FormulaOperationType.XOR:
				case FormulaOperationType.EXIT:
				case FormulaOperationType.PUTP:
					FirstOperand = "";
					SecondOperand = "";
					break;

				case FormulaOperationType.CONST:
				case FormulaOperationType.TSTP:
					FirstOperand = "";
					break;

				case FormulaOperationType.PUTMEMB:
				case FormulaOperationType.GETMEMB:
					FirstOperand = "";
					var descriptorViewModel = DescriptorsViewModel.Descriptors.FirstOrDefault(x => ((x.Descriptor.DatabaseType == GKProcessor.DatabaseType.Gk && x.Descriptor.GKBase.GKDescriptorNo == FormulaOperation.SecondOperand) || (x.Descriptor.DatabaseType == GKProcessor.DatabaseType.Kau && x.Descriptor.GKBase.KAUDescriptorNo == FormulaOperation.SecondOperand)));
					if (descriptorViewModel != null)
					{
						DescriptorIcon = descriptorViewModel.ImageSource;
						SecondOperand = descriptorViewModel.Descriptor.GKBase.PresentationName;
					}
					else
					{
						SecondOperand = "<Не найдено в конфигурации>";
						Error = "Отсутствует ссылка на объект логики";
					}
					break;

				case FormulaOperationType.BR:
					break;

				case FormulaOperationType.GETWORD:
				case FormulaOperationType.PUTWORD:
					FirstOperand = FormulaOperation.FirstOperand == 1 ? "старшее слово" : "младшее слово";
					descriptorViewModel = DescriptorsViewModel.Descriptors.FirstOrDefault(x => ((x.Descriptor.DatabaseType == GKProcessor.DatabaseType.Gk && x.Descriptor.GKBase.GKDescriptorNo == FormulaOperation.SecondOperand) || (x.Descriptor.DatabaseType == GKProcessor.DatabaseType.Kau && x.Descriptor.GKBase.KAUDescriptorNo == FormulaOperation.SecondOperand)));
					if (descriptorViewModel != null)
					{
						DescriptorIcon = descriptorViewModel.ImageSource;
						SecondOperand = descriptorViewModel.Descriptor.GKBase.PresentationName;
					}
					else
					{
						SecondOperand = "<Не найдено в конфигурации>";
						Error = "Отсутствует ссылка на объект логики";
					}
					break;

				default:
					IsBold = true;

					var stateTypeToIconConverter = new XStateTypeToIconConverter();
					StateIcon = (string)stateTypeToIconConverter.Convert((GKStateBit)FormulaOperation.FirstOperand, null, null, null);

					var stateTypeToStringConverter = new EnumToDescriptionConverter();
					FirstOperand = (string)stateTypeToStringConverter.Convert((GKStateBit)FormulaOperation.FirstOperand, null, null, null);

					descriptorViewModel = DescriptorsViewModel.Descriptors.FirstOrDefault(x => ((x.Descriptor.DatabaseType == GKProcessor.DatabaseType.Gk && x.Descriptor.GKBase.GKDescriptorNo == FormulaOperation.SecondOperand) || (x.Descriptor.DatabaseType == GKProcessor.DatabaseType.Kau && x.Descriptor.GKBase.KAUDescriptorNo == FormulaOperation.SecondOperand)));
					if (descriptorViewModel != null)
					{
						DescriptorIcon = descriptorViewModel.ImageSource;
						SecondOperand = descriptorViewModel.Descriptor.GKBase.PresentationName;
					}
					else
					{
						SecondOperand = "<Не найдено в конфигурации>";
						Error = "Отсутствует ссылка на объект логики";
					}
					break;
			}

			if (FormulaOperation.FormulaOperationType == FormulaOperationType.KOD)
			{
				StateIcon = null;
				FirstOperand = "";
			}
			if (FormulaOperation.FormulaOperationType == FormulaOperationType.CMPKOD)
			{
				StateIcon = null;
				if (FormulaOperation.FirstOperand == 1)
					FirstOperand = "Если равно";
				if (FormulaOperation.FirstOperand == 2)
					FirstOperand = "Если не равно";
			}
			if (FormulaOperation.FormulaOperationType == FormulaOperationType.ACS)
			{
				FirstOperand = FormulaOperation.FirstOperand.ToString();
			}
			if (FormulaOperation.FormulaOperationType == FormulaOperationType.ACSP)
			{
				FirstOperand = FormulaOperation.FirstOperand.ToString();
			}
			if (FormulaOperation.FormulaOperationType == FormulaOperationType.BR)
			{
				StateIcon = null;
				DescriptorIcon = null;
				switch(FormulaOperation.FirstOperand)
				{
					case 0:
						FirstOperand = "Безусловный переход";
						break;

					case 1:
						FirstOperand = "Переход, если в стеке 0";
						break;

					case 2:
						FirstOperand = "Переход, если в стеке не 0";
						break;
				}
				SecondOperand = FormulaOperation.SecondOperand.ToString();
			}
		}
Пример #13
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;
		}