コード例 #1
0
ファイル: ClauseViewModel.cs プロジェクト: saeednazari/Rubezh
		public ClauseViewModel(ZoneLogicViewModel zoneLogicViewModel, Device device, Clause clause)
		{
			ShowZonesCommand = new RelayCommand(OnShowZones);
			SelectDeviceCommand = new RelayCommand(OnSelectDevice);

			_zoneLogicViewModel = zoneLogicViewModel;
			Device = device;
			Zones = new List<Guid>(
				from zoneUID in clause.ZoneUIDs
				select zoneUID);
			Zones = clause.ZoneUIDs.ToList();
			_selectedState = clause.State;
			SelectedOperation = clause.Operation;

			if (clause.DeviceUIDs == null)
			{
				clause.DeviceUIDs = new List<Guid>();
			}
			SelectedDevices = new List<Device>();
			foreach (var deviceUID in clause.DeviceUIDs)
			{
				var deviceInClause = FiresecManager.Devices.FirstOrDefault(x => x.UID == deviceUID);
				if (deviceInClause != null)
				{
					SelectedDevices.Add(deviceInClause);
				}
			}

			SelectedMROMessageNo = clause.ZoneLogicMROMessageNo;
			SelectedMROMessageType = clause.ZoneLogicMROMessageType;
		}
コード例 #2
0
ファイル: ZoneLogicConverter.cs プロジェクト: hjlfmy/Rubezh
        public static ZoneLogic Convert(expr innerZoneLogic)
        {
            var zoneLogic = new ZoneLogic();

            if (innerZoneLogic != null && innerZoneLogic.clause.IsNotNullOrEmpty())
            {
                foreach (var innerClause in innerZoneLogic.clause)
                {
                    var clause = new Clause();
                    if (innerClause.zone != null)
                    {
                        foreach (var item in innerClause.zone)
                        {
                            if (string.IsNullOrWhiteSpace(item) == false)
                                clause.Zones.Add(int.Parse(item));
                        }
                    }

                    clause.State = (ZoneLogicState)int.Parse(innerClause.state);

                    switch (innerClause.operation)
                    {
                        case "and":
                            clause.Operation = ZoneLogicOperation.All;
                            break;

                        case "or":
                            clause.Operation = ZoneLogicOperation.Any;
                            break;

                        default:
                            clause.Operation = null;
                            break;
                    }

                    switch (innerClause.joinOperator)
                    {
                        case "and":
                            zoneLogic.JoinOperator = ZoneLogicJoinOperator.And;
                            break;

                        case "or":
                            zoneLogic.JoinOperator = ZoneLogicJoinOperator.Or;
                            break;
                    }

                    if (innerClause.device != null)
                        clause.DeviceUID = GuidHelper.ToGuid(innerClause.device[0].UID);

                    zoneLogic.Clauses.Add(clause);
                }
            }

            return zoneLogic;
        }
コード例 #3
0
		void ClearExternalZones(Device device)
		{
			var zoneLogic = new ZoneLogic();
			if (device.ZoneLogic != null)
			{
				foreach (var clause in device.ZoneLogic.Clauses)
				{
					var newClause = new Clause();
					foreach (var zone in clause.Zones)
					{
						if (!HasExternalZone(zone, device))
						{
							newClause.ZoneUIDs.Add(zone.UID);
							newClause.Zones.Add(zone);
						}
					}
					zoneLogic.Clauses.Add(newClause);
				}
			}
			device.ZoneLogic = zoneLogic;
		}
コード例 #4
0
		public static ZoneLogic Convert(DeviceConfiguration deviceConfiguration, expr innerZoneLogic)
		{
			var zoneLogic = new ZoneLogic();

			if (innerZoneLogic != null && innerZoneLogic.clause.IsNotNullOrEmpty())
			{
				foreach (var innerClause in innerZoneLogic.clause)
				{
					var clause = new Clause();
					if (innerClause.zone != null)
					{
						foreach (var item in innerClause.zone)
						{
                            if (string.IsNullOrWhiteSpace(item) == false)
                            {
                                var zoneNo = int.Parse(item);
                                var zone = deviceConfiguration.Zones.FirstOrDefault(x => x.No == zoneNo);
                                if (zone != null)
                                {
                                    clause.ZoneUIDs.Add(zone.UID);
                                }
                            }
						}
					}
					if (innerClause.device != null)
					{
						foreach (var innerDevice in innerClause.device)
						{
							if (innerDevice != null)
							{
								if (!string.IsNullOrEmpty(innerDevice.UID))
								{
									clause.DeviceUIDs.Add(GuidHelper.ToGuid(innerDevice.UID));
								}
							}
						}
					}

					clause.State = (ZoneLogicState)int.Parse(innerClause.state);

					switch (innerClause.operation)
					{
						case "and":
							clause.Operation = ZoneLogicOperation.All;
							break;

						case "or":
							clause.Operation = ZoneLogicOperation.Any;
							break;

						default:
							clause.Operation = null;
							break;
					}

					switch (innerClause.joinOperator)
					{
						case "and":
							zoneLogic.JoinOperator = ZoneLogicJoinOperator.And;
							break;

						case "or":
							zoneLogic.JoinOperator = ZoneLogicJoinOperator.Or;
							break;
					}

					if (!string.IsNullOrEmpty(innerClause.MRO_MessageNo))
					{
						switch (innerClause.MRO_MessageNo)
						{
							case "0":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message1;
								break;

							case "1":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message2;
								break;

							case "2":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message3;
								break;

							case "3":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message4;
								break;

							case "4":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message5;
								break;

							case "5":
								clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message6;
								break;

                            case "6":
                                clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message7;
                                break;

                            case "7":
                                clause.ZoneLogicMROMessageNo = ZoneLogicMROMessageNo.Message8;
                                break;
						}
					}

					if (!string.IsNullOrEmpty(innerClause.MRO_MessageType))
					{
						switch (innerClause.MRO_MessageType)
						{
							case "0":
								clause.ZoneLogicMROMessageType = ZoneLogicMROMessageType.Add;
								break;

							case "1":
								clause.ZoneLogicMROMessageType = ZoneLogicMROMessageType.Remove;
								break;
						}
					}

					zoneLogic.Clauses.Add(clause);
				}
			}

			return zoneLogic;
		}
コード例 #5
0
		void ParseUIDevicesFlash(ref int pointer, DriverType driverType)
		{
			int rawParametersLength;
			switch (driverType)
			{
				case DriverType.Valve:
					rawParametersLength = 6;
					break;
				case DriverType.MPT:
					rawParametersLength = 15;
					break;
				case DriverType.BUNS:
					rawParametersLength = 0;
					break;
				case DriverType.MDU:
					rawParametersLength = 4;
					break;
				case DriverType.MRO_2:
				case DriverType.MRO:
					rawParametersLength = 3;
					break;
				default:
					rawParametersLength = 2;
					break;
			}

			//var length = DeviceFlash[pointer + 26];
			//CallbackManager.OnLog("Detalization Parameters " + driverType + " " + length);

			var device = new Device
			{
				Driver = ConfigurationManager.Drivers.FirstOrDefault(x => x.DriverType == driverType),
				StateWordBytes = USBManager.CreateBytesArray(DeviceFlash[pointer + 3], DeviceFlash[pointer + 4]),
				StateWordOffset = pointer + 3,
				RawParametersBytes = USBManager.CreateBytesArray(DeviceFlash.GetRange(pointer + 29, rawParametersLength)),
				RawParametersOffset = pointer + 29
			};
			device.IntAddress = driverType == DriverType.Exit ? DeviceFlash[pointer + 1] : DeviceFlash[pointer + 1] + 256 * (DeviceFlash[pointer + 2] + 1);
			device.DriverUID = device.Driver.UID;
			Device groupDevice;
			var parentAddress = 0;
			var config = DeviceFlash[pointer + 31];
			var countInGroup = ((config & 64)>>6) * 4 + ((config & 32)>>5) * 2 + ((config & 16)>>4);
			switch (driverType)
			{
				case DriverType.MPT:
					device.StateWordBytes = USBManager.CreateBytesArray(DeviceFlash[pointer + 31], DeviceFlash[pointer + 32], DeviceFlash[pointer + 33]);
					break;

				case DriverType.MDU:
					device.StateWordBytes = USBManager.CreateBytesArray(DeviceFlash[pointer + 31], DeviceFlash[pointer + 32]);
					config = DeviceFlash[pointer + 33];
					break;

				case DriverType.MRO_2:
					device.StateWordBytes.Add(DeviceFlash[pointer + 31]);
					config = DeviceFlash[pointer + 32];
					parentAddress = DeviceFlash[pointer + 33] + 256 * (DeviceFlash[pointer + 34] + 1);
					break;
			}
			TraceHelper.TraceBytes(device.StateWordBytes, device.PresentationAddressAndName);
			var description = BytesHelper.ExtractString(DeviceFlash, pointer + 6);
			if (driverType != DriverType.MPT)
			{
				var configAndParamSize = DeviceFlash[pointer + 26]; // длина переменной части блока с конфигурацией и сырыми параметрами (1)
				// общая длина записи (2) pointer + 27
				pointer = pointer + configAndParamSize; // конфиг и сырые параметры
				byte clauseJoinOperatorByte = 1;
				var tableDynamicSize = 0; // размер динамической части таблицы
				while (clauseJoinOperatorByte != 0)
				{
					pointer = pointer + tableDynamicSize;
					tableDynamicSize = 0;
					var logicByte = DeviceFlash[pointer + 29];
					//var logic = new BitArray(new byte[] { DeviceFlash[pointer + 29] });
					var zoneLogicOperationByte = logicByte & 3;// Convert.ToInt32(logic[1]) * 2 + Convert.ToInt32(logic[0]);
					var messageNo = (logicByte & 0xF0) >> 4;// Convert.ToInt32(logic[7]) * 8 + Convert.ToInt32(logic[6]) * 4 + Convert.ToInt32(logic[5]) * 2 + Convert.ToInt32(logic[4]);
					var messageType = (logicByte & 8) >> 3;// Convert.ToInt32(logic[3]);
					var eventType = DeviceFlash[pointer + 30]; // Тип события по которому срабатывать в этой группе зон (1)
					clauseJoinOperatorByte = Convert.ToByte(DeviceFlash[pointer + 31] & 3);
					if (clauseJoinOperatorByte == 0x01)
						device.ZoneLogic.JoinOperator = ZoneLogicJoinOperator.And;
					if (clauseJoinOperatorByte == 0x02)
						device.ZoneLogic.JoinOperator = ZoneLogicJoinOperator.Or;
					var zonesCount = BytesHelper.ExtractShort(DeviceFlash, pointer + 32);
					tableDynamicSize += 5;
					var clause = new Clause
					{
						State = GetDeviceConfigHelper.GetEventTypeByCode(eventType),
						Operation = zoneLogicOperationByte == 0x01 ? ZoneLogicOperation.All : ZoneLogicOperation.Any
					};
					if (eventType == 0x0b) // Активация устройства АМ-1Т или МДУ (начиная с 10 версиии базы)
					{
						var deviceCount = zonesCount;
						for (var deviceNo = 0; deviceNo < deviceCount; deviceNo++)
						{
							tableDynamicSize += 3;
							var logicDevice = new Device();
							var localPointer = BytesHelper.ExtractTriple(DeviceFlash, pointer + 34 + deviceNo*3);
							var am1tPointer = BytesHelper.ExtractTriple(DeviceRom, 96);
							var mduPointer = BytesHelper.ExtractTriple(DeviceRom, 120);
							if (localPointer == am1tPointer)
							{
								logicDevice.IntAddress = DeviceFlash[am1tPointer] + 256 * (DeviceFlash[am1tPointer + 1] + 1);
								logicDevice = PanelDevice.Children.FirstOrDefault(x => x.IntAddress == logicDevice.IntAddress);
							}

							if (localPointer == mduPointer)
							{
								logicDevice.IntAddress = DeviceFlash[mduPointer + 1] + 256 * (DeviceFlash[mduPointer + 2] + 1);
								logicDevice = PanelDevice.Children.FirstOrDefault(x => x.IntAddress == logicDevice.IntAddress);
							}
							clause.DeviceUIDs.Add(logicDevice.UID);
						}
					}
					else
					{
						for (var zoneNo = 0; zoneNo < zonesCount; zoneNo++)
						{
							tableDynamicSize += 3;
							var localPointer = BytesHelper.ExtractTriple(DeviceFlash, pointer + 34 + zoneNo * 3);
							// ... здесь инициализируются все зоны учавствующие в логике ... //
							var zone = new Zone();
							if ((localPointer >= outZonesBegin) && (localPointer < outZonesEnd))// зона внешняя
							{
								zone.No = DeviceFlash[localPointer + 6] * 256 + DeviceFlash[localPointer + 7];
								continue;
							}
							zone.No = DeviceFlash[localPointer + 33] * 256 + DeviceFlash[localPointer + 34]; // Глобальный номер зоны
							zone.Name = BytesHelper.ExtractString(DeviceFlash, localPointer + 6);
							zone.DevicesInZoneLogic.Add(device);
							if (Zones.Any(x => x.No == zone.No))
							// Если зона с таким номером уже добавлена, то добавляем её в clauses и продолжаем цикл
							{
								clause.ZoneUIDs.Add(Zones.FirstOrDefault(x => x.No == zone.No).UID);
								continue;
							}

							clause.ZoneUIDs.Add(zone.UID);
							Zones.Add(zone);
							var zonePanelItem = new ZonePanelItem()
							{
								IsRemote = true,
								No = BytesHelper.ExtractShort(DeviceFlash, localPointer + 4),
								PanelDevice = PanelDevice,
								Zone = zone
							};
							zonePanelRelationsInfo.ZonePanelItems.Add(zonePanelItem);
							remoteDeviceConfiguration.Zones.Add(zone);
						}
					}
					if (zoneLogicOperationByte != 0)
						device.ZoneLogic.Clauses.Add(clause);
				}
				pointer = pointer + tableDynamicSize + 29;
			}

			if (driverType == DriverType.MRO_2)
			{
				if (parentAddress > 0x100)
				{
					groupDevice = (PanelDevice.Children.FirstOrDefault(x => x.IntAddress == parentAddress));
					if (groupDevice == null)
					{
						groupDevice = new Device
						{
							Driver = ConfigurationManager.Drivers.FirstOrDefault(x => x.DriverType == DriverType.MRO_2),
							IntAddress = parentAddress
						};
						groupDevice.DriverUID = groupDevice.Driver.UID;
						PanelDevice.Children.Add(groupDevice);
					}
					groupDevice.Children.Add(device);
					return;
				}
			}

			if (driverType == DriverType.RM_1)
			{
				if (countInGroup > 0)
				{
					var localNo = (config & 14) >> 1;
					groupDevice = (PanelDevice.Children.FirstOrDefault(x => x.IntAddress == device.IntAddress - localNo));
					if (groupDevice == null)
					{
						groupDevice = new Device
						{
							IntAddress = device.IntAddress - localNo
						};
						PanelDevice.Children.Add(groupDevice);
					}
					groupDevice.Children.Add(device);
					switch (countInGroup) // смотрим сколько дочерних устройств у группового устройства
					{
						case 2:
							groupDevice.Driver = ConfigurationManager.Drivers.FirstOrDefault(x => x.DriverType == DriverType.RM_2);
							groupDevice.DriverUID = groupDevice.Driver.UID;
							break;
						case 3:
							groupDevice.Driver = ConfigurationManager.Drivers.FirstOrDefault(x => x.DriverType == DriverType.RM_3);
							groupDevice.DriverUID = groupDevice.Driver.UID;
							break;
						case 4:
							groupDevice.Driver = ConfigurationManager.Drivers.FirstOrDefault(x => x.DriverType == DriverType.RM_4);
							groupDevice.DriverUID = groupDevice.Driver.UID;
							break;
						case 5:
							groupDevice.Driver = ConfigurationManager.Drivers.FirstOrDefault(x => x.DriverType == DriverType.RM_5);
							groupDevice.DriverUID = groupDevice.Driver.UID;
							break;
					}
					return;
				}
			}
			if (driverType == DriverType.MPT)
			{
				parentAddress = DeviceFlash[pointer + 35] + (DeviceFlash[pointer + 36] + 1) * 256;
				var startUpDelay = BytesHelper.ExtractShort(DeviceFlash, pointer + 37);
				var zoneNo = BytesHelper.ExtractShort(DeviceFlash, pointer + 39);
				var zonePanelItem = zonePanelRelationsInfo.ZonePanelItems.FirstOrDefault(x => x.No == zoneNo);
				if (zonePanelItem != null)
				{
					device.Zone = zonePanelItem.Zone;
					device.ZoneUID = device.Zone.UID;
				}
				// номер привязанной зоны (2) pointer + 40
				if (parentAddress > 0x100)
				{
					groupDevice = (PanelDevice.Children.FirstOrDefault(x => x.IntAddress == parentAddress));
					if (groupDevice == null) // если такое ГУ ещё не добавлено
					{
						groupDevice = new Device
						{
							Driver = ConfigurationManager.Drivers.FirstOrDefault(x => x.DriverType == DriverType.MPT),
							IntAddress = parentAddress
						};
						groupDevice.DriverUID = groupDevice.Driver.UID;
						PanelDevice.Children.Add(groupDevice);
					}
					groupDevice.Children.Add(device);
					pointer = pointer + 49;
					return;
				}
				pointer = pointer + 49;
			}
			PanelDevice.Children.Add(device);
		}
コード例 #6
0
		protected override bool Save()
		{
			var zoneLogic = new ZoneLogic();
			zoneLogic.JoinOperator = JoinOperator;

			foreach (var clauseViewModel in Clauses)
			{
				switch (clauseViewModel.SelectedState)
				{
					case ZoneLogicState.AM1TOn:
					case ZoneLogicState.ShuzOn:
						if (clauseViewModel.SelectedDevices.Count > 0)
						{
							var clause = new Clause()
							{
								State = clauseViewModel.SelectedState,
								Operation = clauseViewModel.SelectedOperation,
							};
							foreach (var device in clauseViewModel.SelectedDevices)
							{
								clause.DeviceUIDs.Add(device.UID);
								clause.Devices.Add(device);
							}

							zoneLogic.Clauses.Add(clause);
						}
						break;

					case ZoneLogicState.Failure:
					case ZoneLogicState.DoubleFire:
						{
							var clause = new Clause()
							{
								State = clauseViewModel.SelectedState,
							};
							zoneLogic.Clauses.Add(clause);
						}
						break;

					default:
						if (clauseViewModel.Zones.Count > 0)
						{
							var clause = new Clause()
							{
								State = clauseViewModel.SelectedState,
								Operation = clauseViewModel.SelectedOperation,
								ZoneUIDs = clauseViewModel.Zones,
								ZoneLogicMROMessageNo = clauseViewModel.SelectedMROMessageNo,
								ZoneLogicMROMessageType = clauseViewModel.SelectedMROMessageType
							};
							zoneLogic.Clauses.Add(clause);
						}
						break;
				}
			}
			FiresecManager.FiresecConfiguration.SetDeviceZoneLogic(_device, zoneLogic);
			return base.Save();
		}
コード例 #7
0
		void OnAdd()
		{
			var clause = new Clause()
			{
				Operation = ZoneLogicOperation.All,
				State = ZoneLogicState.Fire
			};
			var clauseViewModel = new ClauseViewModel(this, _device, clause);
			Clauses.Add(clauseViewModel);
			UpdateJoinOperatorVisibility();
		}
コード例 #8
0
ファイル: ZoneLogicViewModel.cs プロジェクト: hjlfmy/Rubezh
        protected override bool Save()
        {
            var zoneLogic = new ZoneLogic();
            zoneLogic.JoinOperator = JoinOperator;

            foreach (var clauseViewModel in Clauses)
            {
                switch (clauseViewModel.SelectedState)
                {
                    case ZoneLogicState.AM1TOn:
                        if (clauseViewModel.SelectedDevice != null)
                        {
                            var clause = new Clause()
                            {
                                State = clauseViewModel.SelectedState,
                                Operation = clauseViewModel.SelectedOperation,
                                DeviceUID = clauseViewModel.SelectedDevice.UID,
                                Device = clauseViewModel.SelectedDevice
                            };
                            zoneLogic.Clauses.Add(clause);
                        }
                        break;

                    case ZoneLogicState.Failure:
                        {
                            var clause = new Clause()
                            {
                                State = clauseViewModel.SelectedState,
                            };
                            zoneLogic.Clauses.Add(clause);
                        }
                        break;

                    default:
                        if (clauseViewModel.Zones.Count > 0)
                        {
                            var clause = new Clause()
                            {
                                State = clauseViewModel.SelectedState,
                                Operation = clauseViewModel.SelectedOperation,
                                Zones = clauseViewModel.Zones
                            };
                            zoneLogic.Clauses.Add(clause);
                        }
                        break;
                }
            }
            _device.ZoneLogic = zoneLogic;
            return base.Save();
        }