void SetFormulaBytes()
        {
            Formula = new FormulaBuilder();

			Formula.AddGetBit(XStateBit.On, MainDelay);
			Formula.AddGetBit(XStateBit.Norm, PumpStation);
			Formula.Add(FormulaOperationType.AND);
			if (PumpStation.AutomaticOffLogic.Clauses.Count > 0)
			{
				Formula.AddClauseFormula(PumpStation.AutomaticOffLogic.Clauses);
				Formula.Add(FormulaOperationType.AND);
			}
			Formula.AddPutBit(XStateBit.SetRegime_Manual, PumpStation);

			if (PumpStation.StartLogic.Clauses.Count > 0)
				Formula.AddClauseFormula(PumpStation.StartLogic.Clauses);
			if (PumpStation.StopLogic.Clauses.Count > 0)
			{
				Formula.AddClauseFormula(PumpStation.StopLogic.Clauses);
				Formula.Add(FormulaOperationType.DUP);
				Formula.AddGetBit(XStateBit.Norm, PumpStation);
				Formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный НС");
				Formula.AddPutBit(XStateBit.TurnOff_InAutomatic, PumpStation);

				Formula.Add(FormulaOperationType.COM);
				Formula.Add(FormulaOperationType.AND);
			}

			Formula.AddGetBit(XStateBit.Norm, PumpStation);
			Formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный НС");
			Formula.AddPutBit(XStateBit.TurnOn_InAutomatic, PumpStation);

            Formula.Add(FormulaOperationType.END);
            FormulaBytes = Formula.GetBytes();
        }
		void CreateMainDelay()
		{
			MainDelay.Name = "Тушение " + PumpStation.PresentationName;
			MainDelay.DelayTime = (ushort)(PumpStation.Hold - 5);
			MainDelay.SetTime = 5;
			MainDelay.DelayRegime = DelayRegime.Off;

			var delayDescriptor = new DelayDescriptor(MainDelay);
			GkDatabase.Descriptors.Add(delayDescriptor);
			UpdateConfigurationHelper.LinkXBases(PumpStation, MainDelay);
			UpdateConfigurationHelper.LinkXBases(MainDelay, PumpStation);

			var formula = new FormulaBuilder();

			formula.AddGetBit(XStateBit.On, PumpStation);
			formula.AddGetBit(XStateBit.Norm, PumpStation);
			formula.Add(FormulaOperationType.AND);
			formula.Add(FormulaOperationType.DUP);
			formula.AddGetBit(XStateBit.TurningOn, MainDelay);
			formula.AddGetBit(XStateBit.On, MainDelay);
			formula.Add(FormulaOperationType.OR);
			formula.Add(FormulaOperationType.COM);
			formula.Add(FormulaOperationType.AND);
			formula.AddPutBit(XStateBit.TurnOn_InAutomatic, MainDelay);
			formula.Add(FormulaOperationType.COM);
			formula.AddPutBit(XStateBit.TurnOff_InAutomatic, MainDelay);

			formula.Add(FormulaOperationType.END);
			delayDescriptor.Formula = formula;
			delayDescriptor.FormulaBytes = formula.GetBytes();
		}
Exemple #3
0
		void SetFormulaBytes()
		{
			Formula = new FormulaBuilder();
			var fire1Count = AddDeviceFire1();
			AddDeviceFire2();

			Formula.Add(FormulaOperationType.CONST, 0, (ushort)Zone.Fire2Count, "Количество устройств для формирования Пожар2");
			Formula.Add(FormulaOperationType.MUL);
			Formula.Add(FormulaOperationType.ADD);
			Formula.Add(FormulaOperationType.DUP);
			Formula.Add(FormulaOperationType.CONST, 0, (ushort)Zone.Fire2Count, "Количество устройств для формирования Пожар2");
			Formula.Add(FormulaOperationType.GE);
			Formula.AddGetBit(XStateBit.Fire2, Zone);
			Formula.Add(FormulaOperationType.OR);
			Formula.AddPutBit(XStateBit.Fire2, Zone);

			Formula.Add(FormulaOperationType.DUP);
			Formula.Add(FormulaOperationType.CONST, 0, (ushort)Zone.Fire1Count, "Количество устройств для формирования Пожар1");
			Formula.Add(FormulaOperationType.GE);
			Formula.AddGetBit(XStateBit.Fire1, Zone);
			Formula.Add(FormulaOperationType.OR);
			Formula.AddPutBit(XStateBit.Fire1, Zone);

			Formula.Add(FormulaOperationType.CONST, 0, 1, "Количество устройств для формирования Внимание");
			Formula.Add(FormulaOperationType.GE);
			Formula.AddPutBit(XStateBit.Attention, Zone);

			Formula.Add(FormulaOperationType.END);
			FormulaBytes = Formula.GetBytes();
		}
		void SetFormulaBytes()
		{
			Formula = new FormulaBuilder();
			if (DatabaseType == DatabaseType.Gk)
			{
				if (Device.Driver.HasLogic)
				{
					if (Device.DeviceLogic.Clauses.Count > 0)
					{
						Formula.AddClauseFormula(Device.DeviceLogic.Clauses);
						AddMro2MFormula();
						if (Device.DeviceLogic.OffClauses == null || Device.DeviceLogic.OffClauses.Count == 0)
						{
							Formula.AddStandardTurning(Device);
						}
						else
						{
							Formula.AddGetBit(XStateBit.Norm, Device);
							Formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный Устройства");
							Formula.AddPutBit(XStateBit.TurnOn_InAutomatic, Device);
						}
					}
					if (Device.DeviceLogic.OffClauses.Count > 0)
					{
						Formula.AddClauseFormula(Device.DeviceLogic.OffClauses);
						Formula.AddGetBit(XStateBit.Norm, Device);
						Formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный Устройства");
						Formula.AddPutBit(XStateBit.TurnOff_InAutomatic, Device);
					}
				}
			}
			Formula.Add(FormulaOperationType.END);
			FormulaBytes = Formula.GetBytes();
		}
Exemple #5
0
		public static void AddCodeReaderLogic(FormulaBuilder formula, GKCodeReaderSettingsPart settingsPart, GKDevice device)
		{
			var stateBit = CodeReaderEnterTypeToStateBit(settingsPart.CodeReaderEnterType);
			formula.AddGetBit(stateBit, device);
			formula.Add(FormulaOperationType.BR, 2, 2);
			formula.Add(FormulaOperationType.CONST);
			var gotoFormulaOperation = formula.Add(FormulaOperationType.BR, 0, 0);
			var formulaNo = formula.FormulaOperations.Count;

			var codeIndex = 0;
			foreach (var codeUID in settingsPart.CodeUIDs)
			{
				var code = GKManager.DeviceConfiguration.Codes.FirstOrDefault(x => x.UID == codeUID);
				formula.AddWithGKBase(FormulaOperationType.KOD, 0, device);
				formula.AddWithGKBase(FormulaOperationType.CMPKOD, 1, code);
				if (codeIndex > 0)
				{
					formula.Add(FormulaOperationType.OR);
				}
				codeIndex++;
			}
			if (settingsPart.AccessLevel > 0)
			{
				formula.AddWithGKBase(FormulaOperationType.ACS, (byte)settingsPart.AccessLevel, device);
				if (codeIndex > 0)
				{
					formula.Add(FormulaOperationType.OR);
				}
			}

			gotoFormulaOperation.SecondOperand = (ushort)(formula.FormulaOperations.Count - formulaNo);
		}
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();
			if ((DatabaseType == DatabaseType.Gk && GKBase.IsLogicOnKau) ||
				(DatabaseType == DatabaseType.Kau && !GKBase.IsLogicOnKau))
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}
			if (ExitButton != null)
				Formula.AddGetBit(GKStateBit.Fire1, ExitButton);
			if (EnterDevice != null)
			{
				Formula.AddGetBit(GKStateBit.Attention, EnterDevice);
				Formula.Add(FormulaOperationType.OR);
			}
			Formula.AddGetBit(GKStateBit.On, PimDoor);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddPutBit(GKStateBit.TurnOnNow_InAutomatic, Pim);
			if (EnterButton != null)
			{
				Formula.AddGetBit(GKStateBit.Fire1, EnterButton);
			}
			if (ExitDevice != null)
			{
				Formula.AddGetBit(GKStateBit.Attention, ExitDevice);
				Formula.Add(FormulaOperationType.OR);
			}
			Formula.AddGetBit(GKStateBit.On, PimDoor);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddGetBit(GKStateBit.Off, PimDoor);
			Formula.Add(FormulaOperationType.OR);
			Formula.AddPutBit(GKStateBit.TurnOffNow_InAutomatic, Pim);
			Formula.Add(FormulaOperationType.END);
		}
Exemple #7
0
		/// <summary>
		/// Метод не для IsCardOrCodeReader
		/// </summary>
		public static int AddFireOrFailureLogic(IEnumerable<GKDevice> guardDevices, FormulaBuilder Formula)
		{
			var count = 0;
			foreach (var guardDevice in guardDevices)
			{
				Formula.AddGetBit(GKStateBit.Fire1, guardDevice);
				if (count > 0)
					Formula.Add(FormulaOperationType.OR);
				
				Formula.AddGetBit(GKStateBit.Fire2, guardDevice);
				Formula.Add(FormulaOperationType.OR);
				Formula.AddGetBit(GKStateBit.Failure, guardDevice);
				Formula.Add(FormulaOperationType.OR);

				count++;
			}
			return count;
		}
Exemple #8
0
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();
			if ((DatabaseType == DatabaseType.Gk && GKBase.IsLogicOnKau) || (DatabaseType == DatabaseType.Kau && !GKBase.IsLogicOnKau))
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}

			MPT.LinkToDescriptor(GlobalPim);
			Formula.AddGetBit(GKStateBit.On, GlobalPim);
			Formula.Add(FormulaOperationType.BR, 2, 1);
			Formula.Add(FormulaOperationType.EXIT);

			var mirrorParents = MPT.GetMirrorParents();
			Formula.AddMirrorLogic(MPT, mirrorParents);

			if (MPT.MptLogic.StopClausesGroup.GetObjects().Count > 0)
			{
				Formula.AddClauseFormula(MPT.MptLogic.StopClausesGroup);
				if (MPT.MptLogic.OnClausesGroup.GetObjects().Count > 0)
					Formula.Add(FormulaOperationType.DUP);
				Formula.AddPutBit(GKStateBit.Stop_InManual, MPT);
			}

			if (MPT.MptLogic.OnClausesGroup.GetObjects().Count > 0)
			{
				if (MPT.MptLogic.StopClausesGroup.GetObjects().Count > 0)
					Formula.Add(FormulaOperationType.COM);
				Formula.AddClauseFormula(MPT.MptLogic.OnClausesGroup);
				if (MPT.MptLogic.StopClausesGroup.GetObjects().Count > 0)
					Formula.Add(FormulaOperationType.AND);
				Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, MPT);
				if (MPT.MptLogic.UseOffCounterLogic)
				{
					Formula.AddClauseFormula(MPT.MptLogic.OnClausesGroup);
					Formula.Add(FormulaOperationType.COM);
					Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, MPT);
				}
			}

			if (!MPT.MptLogic.UseOffCounterLogic && MPT.MptLogic.OffClausesGroup.GetObjects().Count > 0)
			{
				Formula.AddClauseFormula(MPT.MptLogic.OffClausesGroup);
				Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, MPT);
			}

			SetRegime(GKMPTDeviceType.HandStart, GKStateBit.TurnOn_InManual);
			SetRegime(GKMPTDeviceType.HandStop, GKStateBit.TurnOff_InManual);
			SetRegime(GKMPTDeviceType.HandAutomaticOn, GKStateBit.SetRegime_Automatic);
			SetRegime(GKMPTDeviceType.HandAutomaticOff, GKStateBit.SetRegime_Manual);

			Formula.Add(FormulaOperationType.END);
		}
		void SetFormulaBytes()
		{
			Formula = new FormulaBuilder();
			if (Direction.InputZones.Count > 0 || Direction.InputDevices.Count > 0)
			{
				var inputObjectsCount = 0;
				foreach (var directionZone in Direction.DirectionZones)
				{
					Formula.AddGetBitOff(directionZone.StateBit, directionZone.Zone);
					if (inputObjectsCount > 0)
					{
						Formula.Add(FormulaOperationType.OR);
					}
					inputObjectsCount++;
				}
				foreach (var directionDevice in Direction.DirectionDevices)
				{
					Formula.AddGetBitOff(directionDevice.StateBit, directionDevice.Device);
					if (inputObjectsCount > 0)
					{
						Formula.Add(FormulaOperationType.OR);
					}
					inputObjectsCount++;
				}

				Formula.Add(FormulaOperationType.DUP);

				Formula.AddGetBit(XStateBit.Norm, Direction);
				Formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный Направления");
				Formula.AddPutBit(XStateBit.TurnOn_InAutomatic, Direction);

				Formula.Add(FormulaOperationType.COM, comment: "Условие Выключения");
				Formula.AddGetBit(XStateBit.Norm, Direction);
				Formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный Направления");
				Formula.AddPutBit(XStateBit.TurnOff_InAutomatic, Direction);
			}
			Formula.Add(FormulaOperationType.END);
			FormulaBytes = Formula.GetBytes();
		}
Exemple #10
0
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();
			if ((DatabaseType == DatabaseType.Gk && Zone.IsLogicOnKau) || (DatabaseType == DatabaseType.Kau && !Zone.IsLogicOnKau))
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}

			var mirrorParents = Zone.GetMirrorParents();
			Formula.AddMirrorLogic(Zone, mirrorParents);

			var fire1Count = AddDeviceFire1();
			AddDeviceFire2();
			Formula.Add(FormulaOperationType.CONST, 0, (ushort)Zone.Fire2Count, comment:"Количество устройств для формирования Пожар2");
			Formula.Add(FormulaOperationType.MUL);
			Formula.Add(FormulaOperationType.ADD);
			Formula.Add(FormulaOperationType.DUP);
			Formula.Add(FormulaOperationType.CONST, 0, (ushort)Zone.Fire2Count, comment: "Количество устройств для формирования Пожар2");
			Formula.Add(FormulaOperationType.GE);
			Formula.AddGetBit(GKStateBit.Fire2, Zone);
			Formula.Add(FormulaOperationType.OR);
			Formula.AddPutBit(GKStateBit.Fire2, Zone);

			Formula.Add(FormulaOperationType.DUP);
			Formula.Add(FormulaOperationType.CONST, 0, (ushort)Zone.Fire1Count, comment: "Количество устройств для формирования Пожар1");
			Formula.Add(FormulaOperationType.GE);
			Formula.AddGetBit(GKStateBit.Fire1, Zone);
			Formula.Add(FormulaOperationType.OR);
			Formula.AddPutBit(GKStateBit.Fire1, Zone);

			Formula.Add(FormulaOperationType.CONST, 0, 1, comment: "Количество устройств для формирования Внимание");
			Formula.Add(FormulaOperationType.GE);
			Formula.AddPutBit(GKStateBit.Attention, Zone);

			Formula.Add(FormulaOperationType.END);
		}
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();
			if ((DatabaseType == DatabaseType.Gk && GKBase.IsLogicOnKau) || (DatabaseType == DatabaseType.Kau && !GKBase.IsLogicOnKau))
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}

			PumpStation.LinkToDescriptor(GlobalPim);
			Formula.AddGetBit(GKStateBit.On, GlobalPim);
			Formula.Add(FormulaOperationType.BR, 2, 1);
			Formula.Add(FormulaOperationType.EXIT);

			var mirrorParents = PumpStation.GetMirrorParents();
			Formula.AddMirrorLogic(PumpStation, mirrorParents);

			var hasAutomaticOffLogic = PumpStation.AutomaticOffLogic.OnClausesGroup.Clauses.Count + PumpStation.AutomaticOffLogic.OnClausesGroup.ClauseGroups.Count > 0;
			var hasStartLogic = PumpStation.StartLogic.OnClausesGroup.Clauses.Count + PumpStation.StartLogic.OnClausesGroup.ClauseGroups.Count > 0;
			var hasStopLogic = PumpStation.StopLogic.OnClausesGroup.Clauses.Count + PumpStation.StopLogic.OnClausesGroup.ClauseGroups.Count > 0;
			if (hasAutomaticOffLogic)
			{
				Formula.AddClauseFormula(PumpStation.AutomaticOffLogic.OnClausesGroup);
				Formula.AddPutBit(GKStateBit.SetRegime_Manual, PumpStation);
			}

			if (hasStartLogic)
			{
				Formula.AddClauseFormula(PumpStation.StartLogic.OnClausesGroup);

				if (hasStopLogic)
				{
					Formula.AddClauseFormula(PumpStation.StopLogic.OnClausesGroup);
					Formula.Add(FormulaOperationType.COM);
					Formula.Add(FormulaOperationType.AND);
				}

				Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, PumpStation);
			}
			if (hasStopLogic)
			{
				Formula.AddClauseFormula(PumpStation.StopLogic.OnClausesGroup);
				Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, PumpStation);
			}

			Formula.Add(FormulaOperationType.END);
		}
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();
			if ((DatabaseType == DatabaseType.Gk && GKBase.IsLogicOnKau) || (DatabaseType == DatabaseType.Kau && !GKBase.IsLogicOnKau))
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}

			// Фиктивная логика для того, чтобы состояние охранной зоны всегда пересчитывалось, даже когда состояние ПИМ не изменилось
			Formula.AddGetBit(GKStateBit.Test, GuardZone.ChangePim);
			Formula.Add(FormulaOperationType.COM);
			Formula.AddPutBit(GKStateBit.Test, GuardZone.ChangePim);


			AddGuardDevicesLogic(SetAlarmDevices, GKStateBit.Fire1);
			AddGuardDevicesLogic(SetGuardDevices, GKStateBit.TurnOnNow_InAutomatic);
			AddGuardDevicesLogic(ResetGuardDevices, GKStateBit.TurnOffNow_InAutomatic);

			Formula.Add(FormulaOperationType.END);
		}
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();
			if ((DatabaseType == DatabaseType.Gk && GKBase.IsLogicOnKau) || (DatabaseType == DatabaseType.Kau && !GKBase.IsLogicOnKau))
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}

			Formula.AddGetBit(GKStateBit.Attention, PimGuardZone);
			Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Pim);
			Formula.AddGetBit(GKStateBit.Fire1, PimGuardZone);
			Formula.AddGetBit(GKStateBit.Fire2, PimGuardZone);
			Formula.Add(FormulaOperationType.OR);
			Formula.AddPutBit(GKStateBit.TurnOnNow_InAutomatic, Pim);
			Formula.AddGetBit(GKStateBit.Attention, PimGuardZone);
			Formula.AddGetBit(GKStateBit.Fire1, PimGuardZone);
			Formula.Add(FormulaOperationType.OR);
			Formula.AddGetBit(GKStateBit.Fire2, PimGuardZone);
			Formula.Add(FormulaOperationType.OR);
			Formula.Add(FormulaOperationType.COM);
			Formula.AddPutBit(GKStateBit.TurnOffNow_InAutomatic, Pim);
			Formula.Add(FormulaOperationType.END);
		}
		void SetFirePumpDevicesLogic()
		{
			for (int i = 0; i < FirePumpDevices.Count; i++)
			{
				var pumpDevice = FirePumpDevices[i];
				var pumpDescriptor = GkDatabase.Descriptors.FirstOrDefault(x => x.Device != null && x.Device.UID == pumpDevice.UID);
				if (pumpDescriptor != null)
				{
					var formula = new FormulaBuilder();
					AddCountFirePumpDevicesFormula(formula);
					if (i > 0)
					{
						var pumpDelay = PumpDelays.FirstOrDefault(x => x.Device.UID == pumpDevice.UID);
						formula.AddGetBit(XStateBit.On, pumpDelay.Delay);
						formula.Add(FormulaOperationType.AND);
					}

					if (pumpDevice.NSLogic.Clauses.Count > 0)
					{
						formula.AddClauseFormula(pumpDevice.NSLogic.Clauses);
						formula.Add(FormulaOperationType.AND);
					}

					formula.AddGetBit(XStateBit.On, pumpDevice);
					formula.AddGetBit(XStateBit.TurningOn, pumpDevice);
					formula.Add(FormulaOperationType.OR);
					formula.AddGetBit(XStateBit.Failure, pumpDevice);
					formula.Add(FormulaOperationType.OR);
					formula.Add(FormulaOperationType.COM);
					formula.Add(FormulaOperationType.AND, comment: "Запрет на включение, если насос включен и не включается");

					formula.AddGetBit(XStateBit.On, PumpStation);
					formula.Add(FormulaOperationType.AND);

					formula.AddGetBit(XStateBit.Norm, pumpDevice);
					formula.Add(FormulaOperationType.AND);
					formula.AddPutBit(XStateBit.TurnOn_InAutomatic, pumpDevice);

					formula.AddGetBit(XStateBit.Off, PumpStation);
					formula.AddGetBit(XStateBit.Norm, pumpDevice);
					formula.Add(FormulaOperationType.AND);
					formula.AddPutBit(XStateBit.TurnOff_InAutomatic, pumpDevice);

					formula.Add(FormulaOperationType.END);

					pumpDescriptor.Formula = formula;
					pumpDescriptor.FormulaBytes = formula.GetBytes();
				}
			}
		}
		void SetJokeyPumpLogic()
		{
			if (JNPumpDevice != null)
			{
				var jnDescriptor = GkDatabase.Descriptors.FirstOrDefault(x => x.Device != null && x.Device.UID == JNPumpDevice.UID);
				if (jnDescriptor != null)
				{
					var formula = new FormulaBuilder();
					formula.AddGetBit(XStateBit.On, PumpStation);
					formula.AddGetBit(XStateBit.Norm, JNPumpDevice);
					formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный ЖН");
					//formula.AddGetBit(XStateBit.ForbidStart_InAutomatic, JNPumpDevice);
					formula.Add(FormulaOperationType.END);
					jnDescriptor.Formula = formula;
					jnDescriptor.FormulaBytes = formula.GetBytes();
				}
				UpdateConfigurationHelper.LinkXBases(jnDescriptor.XBase, PumpStation);
			}
		}
		void CreatePim()
		{
			Pim = new XPim()
			{
				Name = PumpStation.PresentationName
			};
			Pim.UID = GuidHelper.CreateOn(PumpStation.UID);
			GkDatabase.AddPim(Pim);
			var pimDescriptor = new PimDescriptor(Pim);
			GkDatabase.Descriptors.Add(pimDescriptor);

			var formula = new FormulaBuilder();

			var inputDevices = new List<XBase>();
			inputDevices.AddRange(PumpStation.InputDevices);
			foreach (var nsDevice in PumpStation.NSDevices)
			{
				if (!inputDevices.Contains(nsDevice))
					inputDevices.Add(nsDevice);
			}
			foreach (var inputDevice in inputDevices)
			{
				UpdateConfigurationHelper.LinkXBases(Pim, inputDevice);
			}
			for (int i = 0; i < inputDevices.Count; i++)
			{
				var nsDevice = inputDevices[i];
				formula.AddGetBit(XStateBit.Failure, nsDevice);
				if (i > 0)
				{
					formula.Add(FormulaOperationType.OR);
				}
			}
			formula.AddPutBit(XStateBit.Failure, Pim);

			formula.Add(FormulaOperationType.END);
			pimDescriptor.Formula = formula;
			pimDescriptor.FormulaBytes = formula.GetBytes();
		}
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();
			if ((DatabaseType == DatabaseType.Gk && GKBase.IsLogicOnKau) || (DatabaseType == DatabaseType.Kau && !GKBase.IsLogicOnKau))
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}

			if (LockControlDevice == null || LockControlDeviceExit == null)
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}

			Formula.AddGetBit(GKStateBit.Fire1, LockControlDevice);
			Formula.AddGetBit(GKStateBit.Fire1, LockControlDeviceExit);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddPutBit(GKStateBit.TurnOnNow_InAutomatic, Pim);

			Formula.AddGetBit(GKStateBit.On, Pim);
			Formula.AddGetBit(GKStateBit.Fire1, LockControlDevice);
			Formula.Add(FormulaOperationType.COM);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddGetBit(GKStateBit.Fire2, Pim);
			Formula.Add(FormulaOperationType.COM);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddPutBit(GKStateBit.Fire1, Pim);

			Formula.AddGetBit(GKStateBit.On, Pim);
			Formula.AddGetBit(GKStateBit.Fire1, LockControlDeviceExit);
			Formula.Add(FormulaOperationType.COM);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddGetBit(GKStateBit.Fire1, Pim);
			Formula.Add(FormulaOperationType.COM);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddPutBit(GKStateBit.Fire2, Pim);

			Formula.AddGetBit(GKStateBit.Fire1, Pim);
			Formula.AddGetBit(GKStateBit.Fire1, LockControlDeviceExit);
			Formula.Add(FormulaOperationType.COM);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddGetBit(GKStateBit.Fire2, Pim);
			Formula.AddGetBit(GKStateBit.Fire1, LockControlDevice);
			Formula.Add(FormulaOperationType.COM);
			Formula.Add(FormulaOperationType.AND);
			Formula.Add(FormulaOperationType.OR);
			Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, Pim);

			Formula.AddGetBit(GKStateBit.TurningOff, Pim);
			Formula.AddGetBit(GKStateBit.Off, PimDoor);
			Formula.Add(FormulaOperationType.AND);
			Formula.AddPutBit(GKStateBit.TurnOffNow_InAutomatic, Pim);

			Formula.Add(FormulaOperationType.END);
		}
Exemple #18
0
		void AddCountFirePumpDevicesFormula(FormulaBuilder formula)
		{
			var inputPumpsCount = 0;
			foreach (var firePumpDevice in FirePumpDevices)
			{
				formula.AddGetBit(GKStateBit.TurningOn, firePumpDevice);
				formula.AddGetBit(GKStateBit.On, firePumpDevice);
				formula.Add(FormulaOperationType.OR);
				if (inputPumpsCount > 0)
				{
					formula.Add(FormulaOperationType.ADD);
				}
				inputPumpsCount++;
			}
			formula.Add(FormulaOperationType.CONST, 0, (ushort)PumpStation.NSPumpsCount, comment: "Количество основных пожарных насосов");
			formula.Add(FormulaOperationType.LT);
		}
		void CreateDelaysLogic()
		{
			for (int i = 0; i < PumpDelays.Count; i++)
			{
				var pumpDelay = PumpDelays[i];
				var delayDescriptor = GkDatabase.Descriptors.FirstOrDefault(x => x.Delay != null && x.Delay.UID == pumpDelay.Delay.UID);
				var formula = new FormulaBuilder();

				AddCountFirePumpDevicesFormula(formula);
				if (i > 0)
				{
					var prevDelay = PumpDelays[i - 1];
					formula.AddGetBit(XStateBit.On, prevDelay.Delay);
					formula.Add(FormulaOperationType.AND);
				}

				formula.AddGetBit(XStateBit.On, PumpStation);
				formula.Add(FormulaOperationType.AND);

				formula.AddGetBit(XStateBit.Norm, pumpDelay.Delay);
				formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный Задержки");
				formula.AddPutBit(XStateBit.TurnOn_InAutomatic, pumpDelay.Delay);

				formula.AddGetBit(XStateBit.Off, PumpStation);
				formula.AddGetBit(XStateBit.Norm, pumpDelay.Delay);
				formula.Add(FormulaOperationType.AND, comment: "Смешивание с битом Дежурный Задержки");
				formula.AddPutBit(XStateBit.TurnOff_InAutomatic, pumpDelay.Delay);

				formula.Add(FormulaOperationType.END);
				delayDescriptor.Formula = formula;
				delayDescriptor.FormulaBytes = formula.GetBytes();
			}
		}
Exemple #20
0
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();
			if ((DatabaseType == DatabaseType.Gk && GKBase.IsLogicOnKau) || (DatabaseType == DatabaseType.Kau && !GKBase.IsLogicOnKau))
			{
				Formula.Add(FormulaOperationType.END);
				return;
			}

			var mirrorParents = Device.GetMirrorParents();
			Formula.AddMirrorLogic(Device, mirrorParents);

			if (CreateMPTLogic())
				return;

			if (Device.Driver.HasLogic)
			{
				var hasOn1 = Device.Logic.OnClausesGroup.IsNotEmpty();
				var hasOn2 = Device.Logic.On2ClausesGroup.IsNotEmpty();
				if (hasOn1 && ! hasOn2)
				{
					Formula.AddClauseFormula(Device.Logic.OnClausesGroup);
					Formula.Add(FormulaOperationType.CONST, 0, 0);
					Formula.Add(FormulaOperationType.CONST, 0, 0);
					Formula.Add(FormulaOperationType.CONST, 0, 0);
					Formula.Add(FormulaOperationType.CONST, 0, 0);
					Formula.Add(FormulaOperationType.CONST, 0, 0);
					Formula.AddPutBit(31, Device);
					Formula.AddPutBit(30, Device);
					Formula.AddPutBit(29, Device);
					Formula.AddPutBit(28, Device);
					Formula.AddPutBit(27, Device);
					if (Device.Logic.UseOffCounterLogic)
						Formula.AddStandardTurning(Device);
					else
						Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Device);
				}
				if (!hasOn1 && hasOn2)
				{
					Formula.AddClauseFormula(Device.Logic.On2ClausesGroup);
					Formula.Add(FormulaOperationType.CONST, 0, 1);
					Formula.Add(FormulaOperationType.CONST, 0, 1);
					Formula.Add(FormulaOperationType.CONST, 0, 1);
					Formula.Add(FormulaOperationType.CONST, 0, 1);
					Formula.Add(FormulaOperationType.CONST, 0, 1);
					Formula.AddPutBit(31, Device);
					Formula.AddPutBit(30, Device);
					Formula.AddPutBit(29, Device);
					Formula.AddPutBit(28, Device);
					Formula.AddPutBit(27, Device);
					if (Device.Logic.UseOffCounterLogic)
						Formula.AddStandardTurning(Device);
					else
						Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Device);
				}
				if (hasOn1 && hasOn2)
				{
					Formula.AddClauseFormula(Device.Logic.OnClausesGroup);
					Formula.AddClauseFormula(Device.Logic.On2ClausesGroup);
					Formula.Add(FormulaOperationType.DUP);
					Formula.Add(FormulaOperationType.DUP);
					Formula.Add(FormulaOperationType.DUP);
					Formula.Add(FormulaOperationType.DUP);
					Formula.Add(FormulaOperationType.DUP);
					Formula.AddPutBit(31, Device);
					Formula.AddPutBit(30, Device);
					Formula.AddPutBit(29, Device);
					Formula.AddPutBit(28, Device);
					Formula.AddPutBit(27, Device);
					Formula.Add(FormulaOperationType.OR);
					if (Device.Logic.UseOffCounterLogic)
						Formula.AddStandardTurning(Device);
					else
						Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Device);
				}
				
				if (!Device.Logic.UseOffCounterLogic && Device.Logic.OffClausesGroup.IsNotEmpty())
				{
					Formula.AddClauseFormula(Device.Logic.OffClausesGroup);
					Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, Device);
				}
				if (Device.Logic.OnNowClausesGroup.IsNotEmpty())
				{
					Formula.AddClauseFormula(Device.Logic.OnNowClausesGroup);
					Formula.AddPutBit(GKStateBit.TurnOnNow_InAutomatic, Device);
				}
				if (Device.Logic.OffNowClausesGroup.IsNotEmpty())
				{
					Formula.AddClauseFormula(Device.Logic.OffNowClausesGroup);
					Formula.AddPutBit(GKStateBit.TurnOffNow_InAutomatic, Device);
				}
				if (Device.Logic.StopClausesGroup.IsNotEmpty())
				{
					Formula.AddClauseFormula(Device.Logic.StopClausesGroup);
					Formula.AddPutBit(GKStateBit.Stop_InManual, Device);
				}

				SetICLogic();
			}

			if ((Device.DriverType == GKDriverType.RSR2_GuardDetector || Device.DriverType == GKDriverType.RSR2_GuardDetectorSound || Device.DriverType == GKDriverType.RSR2_HandGuardDetector)
				&& Device.GuardZones != null && Device.GuardZones.Count > 0)
			{
				Formula.AddGetBit(GKStateBit.On, Device.GuardZones.FirstOrDefault());
				Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Device);
				Formula.AddGetBit(GKStateBit.Off, Device.GuardZones.FirstOrDefault());
				Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, Device);
			}

			if (Device.DriverType == GKDriverType.RSR2_MAP4 && Device.Zones.Count > 0)
			{
				int count = 0;
				foreach (var zone in Device.Zones)
				{
					Formula.AddGetBit(GKStateBit.Fire1, zone);
					if (count > 0)
						Formula.Add(FormulaOperationType.OR);
					Formula.AddGetBit(GKStateBit.Fire2, zone);
					Formula.Add(FormulaOperationType.OR);
					Formula.AddGetBit(GKStateBit.Attention, zone);
					Formula.Add(FormulaOperationType.OR);
					count++;
					Device.LinkToDescriptor(zone);
				}
				Formula.AddPutBit(GKStateBit.Reset, Device);
			}

			if (Device.Door != null && (Device.Door.LockDeviceUID == Device.UID || Device.Door.LockDeviceExitUID == Device.UID))
			{
				switch (Device.Door.DoorType)
				{
					case GKDoorType.AirlockBooth:
					case GKDoorType.Turnstile:
						var device = Device.Door.LockDeviceUID == Device.UID ? Device.Door.ExitDevice : Device.Door.EnterDevice;
						var button = Device.Door.LockDeviceUID == Device.UID ? Device.Door.EnterButton : Device.Door.ExitButton;
						if (device != null)
						{
							Formula.AddGetBit(GKStateBit.Attention, device);
							if (button != null)
							{
								Formula.Add(FormulaOperationType.BR, 2, 8);
								Formula.AddGetBit(GKStateBit.Fire1, button);
							}
							Formula.Add(FormulaOperationType.BR, 2, 6);
						}

						Formula.AddGetBit(GKStateBit.On, Device.Door);
						Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Device);
						Formula.AddGetBit(GKStateBit.TurningOff, Device.Door);
						Formula.AddGetBit(GKStateBit.Off, Device.Door);
						Formula.Add(FormulaOperationType.OR);
						Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, Device);
						break;

					case GKDoorType.Barrier:
						if (Device.Door.LockDeviceUID == Device.UID)
						{
							Formula.AddGetBit(GKStateBit.On, Device.Door);
							Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Device);
							Formula.AddGetBit(GKStateBit.Off, Device.Door);
							Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, Device);
						}
						else
						{
							Formula.AddGetBit(GKStateBit.Fire1, Device.Door.LockControlDevice);
							Formula.AddGetBit(GKStateBit.Fire1, Device.Door.LockControlDeviceExit);
							Formula.Add(FormulaOperationType.OR);
							Formula.Add(FormulaOperationType.COM);
							Formula.AddGetBit(GKStateBit.Off, Device.Door);
							Formula.Add(FormulaOperationType.AND);
							Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Device);
							Formula.AddGetBit(GKStateBit.On, Device.Door);
							Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, Device);
						}
						break;

					default:
						Formula.AddGetBit(GKStateBit.On, Device.Door);
						Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Device);
						Formula.AddGetBit(GKStateBit.TurningOff, Device.Door);
						Formula.AddGetBit(GKStateBit.Off, Device.Door);
						Formula.Add(FormulaOperationType.OR);
						Formula.AddPutBit(GKStateBit.TurnOff_InAutomatic, Device);
						break;
				}
				Formula.Add(FormulaOperationType.END);
			}
		}
Exemple #21
0
		public override void BuildFormula()
		{
			Formula = new FormulaBuilder();

			var hasOpenRegimeLogic = Door.OpenRegimeLogic.OnClausesGroup.IsNotEmpty();
			if (hasOpenRegimeLogic)
			{
				Formula.AddClauseFormula(Door.OpenRegimeLogic.OnClausesGroup);
				Formula.Add(FormulaOperationType.BR, 1, 7);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.AddPutBit(GKStateBit.SetRegime_Manual, Door);
				Formula.AddPutBit(GKStateBit.TurnOn_InAutomatic, Door);
				Formula.AddPutBit(GKStateBit.TurnOn_InManual, Door);
				Formula.Add(FormulaOperationType.EXIT);
			}

			var hasCloseRegimeLogic = Door.CloseRegimeLogic.OnClausesGroup.IsNotEmpty();
			if (hasCloseRegimeLogic)
			{
				Formula.AddClauseFormula(Door.CloseRegimeLogic.OnClausesGroup);
				Formula.Add(FormulaOperationType.BR, 1, 7);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.AddPutBit(GKStateBit.SetRegime_Manual, Door);
				Formula.AddPutBit(GKStateBit.TurnOffNow_InAutomatic, Door);
				Formula.AddPutBit(GKStateBit.TurnOffNow_InManual, Door);
				Formula.Add(FormulaOperationType.EXIT);
			}

			var hasNormRegimeLogic = Door.NormRegimeLogic.OnClausesGroup.IsNotEmpty();
			if (hasNormRegimeLogic)
			{
				Formula.AddClauseFormula(Door.NormRegimeLogic.OnClausesGroup);
				Formula.AddGetBit(GKStateBit.Norm, Door);
				Formula.Add(FormulaOperationType.COM);
				Formula.Add(FormulaOperationType.AND);
				Formula.Add(FormulaOperationType.BR, 1, 7);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.Add(FormulaOperationType.CONST, 0, 1);
				Formula.AddPutBit(GKStateBit.SetRegime_Automatic, Door);
				Formula.AddPutBit(GKStateBit.TurnOffNow_InAutomatic, Door);
				Formula.AddPutBit(GKStateBit.TurnOffNow_InManual, Door);
				Formula.Add(FormulaOperationType.EXIT);
			}

			switch (Door.DoorType)
			{
				case GKDoorType.OneWay:
				case GKDoorType.TwoWay:
				case GKDoorType.Turnstile:
					SetFormulaDoor();
					break;
				case GKDoorType.Barrier:
					SetFormulaBarrier();
					break;
				case GKDoorType.AirlockBooth:
					SetFormulaAirlockBooth();
					break;
			}

			Formula.Add(FormulaOperationType.END);
		}