Esempio n. 1
0
		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();
		}
Esempio n. 2
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);
			}
		}