예제 #1
0
 public static IEnumerable<XZone> GetGKZones(XDevice device)
 {
     return from zone in DeviceConfiguration.Zones
            where zone.GkDatabaseParent == device.GkDatabaseParent
            orderby zone.No
            select zone;
 }
예제 #2
0
		static void ValidateIPAddress(XDevice device)
		{
			if (!XManager.IsValidIpAddress(device))
			{
				Errors.Add(new DeviceValidationError(device, "Не верно задан IP адрес", ValidationErrorLevel.CannotWrite));
			}
		}
예제 #3
0
		public XDeviceState(XDevice device)
		{
			Device = device;

			if (device.DriverType == XDriverType.System)
				IsInitialState = false;
		}
예제 #4
0
        public void AddDevice(XDevice parentDevice, Device fsDevice)
        {
            var driver = XManager.DriversConfiguration.Drivers.FirstOrDefault(x => x.UID == fsDevice.DriverUID);
            if (driver == null)
            {
                return;
            }
            var shleifNo = ((shleifPairNo - 1) * 2) + (fsDevice.IntAddress >> 8);

            var xDevice = new XDevice()
            {
                UID = fsDevice.UID,
                DriverUID = driver.UID,
                Driver = driver,
                ShleifNo = (byte)shleifNo,
                IntAddress = (byte)(fsDevice.IntAddress & 0xff),
                Description = fsDevice.Description
            };
            XManager.DeviceConfiguration.Devices.Add(xDevice);
            parentDevice.Children.Add(xDevice);
            xDevice.Parent = parentDevice;

            foreach (var fsChildDevice in fsDevice.Children)
            {
                AddDevice(xDevice, fsChildDevice);
            }
        }
예제 #5
0
 public DeviceBinaryObject(XDevice device, DatabaseType databaseType)
 {
     DatabaseType = databaseType;
     ObjectType = ObjectType.Device;
     Device = device;
     Build();
 }
예제 #6
0
        public static void SynchronizeChildern(XDevice xDevice)
        {
            for (int i = xDevice.Children.Count(); i > 0; i--)
            {
                var childDevice = xDevice.Children[i - 1];

                if (xDevice.Driver.Children.Contains(childDevice.Driver.DriverType) == false)
                {
                    xDevice.Children.RemoveAt(i - 1);
                }
            }

            foreach (var autoCreateDriverType in xDevice.Driver.AutoCreateChildren)
            {
                var autoCreateDriver = XManager.DriversConfiguration.Drivers.FirstOrDefault(x => x.DriverType == autoCreateDriverType);
                for (byte i = autoCreateDriver.MinAddress; i <= autoCreateDriver.MaxAddress; i++)
                {
                    var newDevice = new XDevice()
                    {
                        DriverUID = autoCreateDriver.UID,
                        Driver = autoCreateDriver,
                        IntAddress = i
                    };
                    if (xDevice.Children.Any(x => x.Driver.DriverType == newDevice.Driver.DriverType && x.Address == newDevice.Address) == false)
                    {
                        xDevice.Children.Add(newDevice);
                        newDevice.Parent = xDevice;
                    }
                }
            }
        }
예제 #7
0
        public static XDevice CopyDevice(XDevice device, bool fullCopy)
        {
            var newDevice = new XDevice()
            {
                DriverUID = device.DriverUID,
                Driver = device.Driver,
                IntAddress = device.IntAddress,
                Description = device.Description
            };

            if (fullCopy)
            {
                newDevice.UID = device.UID;
            }

            newDevice.Properties = new List<XProperty>();
            foreach (var property in device.Properties)
            {
                newDevice.Properties.Add(new XProperty()
                {
                    Name = property.Name,
                    Value = property.Value
                });
            }

            newDevice.Children = new List<XDevice>();
            foreach (var childDevice in device.Children)
            {
                var newChildDevice = CopyDevice(childDevice, fullCopy);
                newChildDevice.Parent = newDevice;
                newDevice.Children.Add(newChildDevice);
            }

            return newDevice;
        }
예제 #8
0
		public BaseAUPropertyViewModel(XDriverProperty driverProperty, XDevice device)
		{
			DriverProperty = driverProperty;
			Device = device;

			if (!Device.Properties.Any(x => x.Name == driverProperty.Name))
			{
				Save(driverProperty.Default, false);
			}

			if (Device.DeviceProperties == null)
			{
				Device.DeviceProperties = new List<XProperty>();
			}
			
			var deviceProperty = Device.DeviceProperties.FirstOrDefault(x => x.Name == driverProperty.Name);
			if (deviceProperty != null)
			{
				DeviceAUParameterValue = deviceProperty.Value.ToString();
				//if ((deviceProperty.DriverProperty != null) && (deviceProperty.DriverProperty.DriverPropertyType == XDriverPropertyTypeEnum.EnumType))
					//DeviceAUParameterValue = deviceProperty.DriverProperty.Parameters.FirstOrDefault(x => x.Value == deviceProperty.Value).Name;
			}
			else
				DeviceAUParameterValue = "Неизвестно";

			UpdateDeviceParameterMissmatchType();
		}
		public DeviceExecutableCommandViewModel(XDevice device, XStateBit stateType)
		{
			ExecuteControlCommand = new RelayCommand(OnExecuteControl);
			Device = device;
			StateBit = stateType;
			Name = ((XStateBit)stateType).ToDescription();
			if (Device.DriverType == XDriverType.Valve)
			{
				switch (stateType)
				{
					case XStateBit.TurnOn_InManual:
						Name = "Открыть";
						break;
					case XStateBit.TurnOnNow_InManual:
						Name = "Открыть немедленно";
						break;
					case XStateBit.TurnOff_InManual:
						Name = "Закрыть";
						break;
					case XStateBit.Stop_InManual:
						Name = "Остановить";
						break;
				}
			}
		}
예제 #10
0
		bool GetDescriptorAddresses(XDevice device)
		{
			descriptorAddresses = new List<int>();
			var startaddress = 0x078000;
			while (true)
			{
				byte[] startAddressBytes = BitConverter.GetBytes(startaddress);
				startaddress += 256;

				var data = new List<byte>(startAddressBytes);
				var sendResult = SendManager.Send(device, 4, 31, 256, data);
				if (sendResult.Bytes.Count != 256)
				{
					Error = "Не удалось распознать дескриптор";
					return false;
				}
				for (int i = 0; i < 256 / 4; i++)
				{
					var descriptorAddress = BytesHelper.SubstructInt(sendResult.Bytes, i * 4);
					if (descriptorAddress == -1)
					{
						return true;
					}
					descriptorAddresses.Add(descriptorAddress);
				}
			}
		}
예제 #11
0
		public static void RemoveDevice(XDevice device)
		{
			var parentDevice = device.Parent;
			foreach (var zone in device.Zones)
			{
				zone.Devices.Remove(device);
				zone.OnChanged();
			}
			foreach (var direction in device.Directions)
			{
				direction.InputDevices.Remove(device);
				direction.OutputDevices.Remove(device);
				var directionDevice = direction.DirectionDevices.FirstOrDefault(x => x.Device == device);
				if (directionDevice != null)
				{
					direction.DirectionDevices.Remove(directionDevice);
					direction.InputDevices.Remove(device);
				}

				direction.OnChanged();
			}
			parentDevice.Children.Remove(device);
			Devices.Remove(device);

			if (parentDevice.DriverType == XDriverType.RSR2_KAU_Shleif)
				RebuildRSR2Addresses(parentDevice.Parent);
			device.OnChanged();
		}
예제 #12
0
		public DeviceDescriptor(XDevice device, DatabaseType databaseType)
		{
			DatabaseType = databaseType;
			DescriptorType = DescriptorType.Device;
			Device = device;
			Build();
		}
예제 #13
0
		public static Color GetTankColor(XDevice xdevice)
		{
			Color color = Colors.Black;
			if (xdevice != null)
				color = Colors.LightCyan;
			return color;
		}
예제 #14
0
 public UpdatedDeviceViewModel(XDevice device)
 {
     Device = device;
     Name = device.ShortName;
     Address = device.DottedPresentationAddress;
     ImageSource = device.Driver.ImageSource;
 }
예제 #15
0
        public PropertiesViewModel(XDevice xDevice)
        {
            XDevice = xDevice;
            StringProperties = new List<StringPropertyViewModel>();
            ShortProperties = new List<ShortPropertyViewModel>();
            BoolProperties = new List<BoolPropertyViewModel>();
            EnumProperties = new List<EnumPropertyViewModel>();

            if (xDevice != null)
                foreach (var driverProperty in xDevice.Driver.Properties)
                {
                    switch (driverProperty.DriverPropertyType)
                    {
                        case XDriverPropertyTypeEnum.EnumType:
                            EnumProperties.Add(new EnumPropertyViewModel(driverProperty, xDevice));
                            break;

                        case XDriverPropertyTypeEnum.StringType:
                            StringProperties.Add(new StringPropertyViewModel(driverProperty, xDevice));
                            break;

                        case XDriverPropertyTypeEnum.IntType:
                            ShortProperties.Add(new ShortPropertyViewModel(driverProperty, xDevice));
                            break;

                        case XDriverPropertyTypeEnum.BoolType:
                            BoolProperties.Add(new BoolPropertyViewModel(driverProperty, xDevice));
                            break;
                    }
                }
        }
예제 #16
0
		public ObjectsListViewModel (XDevice device, XDeviceConfiguration deviceConfiguration)
		{
			deviceConfiguration.Update();
			Objects = new List<ObjectViewModel>();

			foreach (var childDevice in deviceConfiguration.Devices)
			{
				var objectViewModel = new ObjectViewModel(childDevice);
				var parent = childDevice.AllParents.FirstOrDefault(x => x.ShortName == device.ShortName && x.Address == device.Address);
				if (parent != null && childDevice.IsRealDevice)
					Objects.Add(objectViewModel);
			}
			if (deviceConfiguration.Zones != null)
				foreach (var zone in deviceConfiguration.Zones.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(zone);
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.Directions != null)
				foreach (var direction in deviceConfiguration.Directions.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(direction) { ObjectType = ObjectType.Direction };
					Objects.Add(objectViewModel);
				}
			if (deviceConfiguration.PumpStations != null)
				foreach (var pumpStation in deviceConfiguration.PumpStations.Where(x => x.GkDatabaseParent != null && x.GkDatabaseParent.Address == device.Address))
				{
					var objectViewModel = new ObjectViewModel(pumpStation) { ObjectType = ObjectType.PumpStation };
					Objects.Add(objectViewModel);
				}
		}
예제 #17
0
		bool GetDescriptorInfo(XDevice kauDevice, int descriptorAdderss)
		{
			var descriptorAdderssesBytes = new List<byte>(BitConverter.GetBytes(descriptorAdderss));
			var data = new List<byte>(descriptorAdderssesBytes);
			var sendResult = SendManager.Send(kauDevice, 4, 31, 256, data);
			var bytes = sendResult.Bytes;
			if (bytes.Count != 256)
			{
				Error = "Длина дескриптора не соответствует нужному значению";
				return false;
			}
			var deviceType = BytesHelper.SubstructShort(bytes, 0);
			var address = BytesHelper.SubstructShort(bytes, 2);
			int shleifNo = (byte)(address / 256 + 1);
			var device = new XDevice();
			device.Driver = XManager.Drivers.FirstOrDefault(x => x.DriverTypeNo == deviceType);
			if ((1 <= shleifNo && shleifNo <= 8) && (address != 0))
			{
				device.DriverUID = device.Driver.UID;
				var shleif = KauDevice.Children.FirstOrDefault(x => (x.DriverType == XDriverType.KAU_Shleif || x.DriverType == XDriverType.RSR2_KAU_Shleif) && x.IntAddress == shleifNo);
				shleif.Children.Add(device);
				device.IntAddress = (byte)(address % 256);
				return true;
			}
			device.Driver = XManager.Drivers.FirstOrDefault(x => x.DriverType == XDriverType.KAUIndicator);
			device.DriverUID = device.Driver.UID;
			device.IntAddress = 1;
			KauDevice.Children.Add(device);
			return true;
		}
예제 #18
0
		public void AddDevice(Device fsDevice, XDevice kauDevice, byte shleifNo)
		{
			var driver = XManager.Drivers.FirstOrDefault(x => x.UID == fsDevice.DriverUID);
			if (driver == null)
			{
				return;
			}

			var device = new XDevice()
			{
				UID = fsDevice.UID,
				DriverUID = driver.UID,
				Driver = driver,
				IntAddress = (byte)(fsDevice.IntAddress & 0xff),
				Description = fsDevice.Description
			};
			XManager.DeviceConfiguration.Devices.Add(device);
			var shleifDevice = kauDevice.Children.FirstOrDefault(x => x.ShleifNo == shleifNo);
			if (shleifDevice != null)
			{
				shleifDevice.Children.Add(device);
				device.Parent = shleifDevice;
			}

			foreach (var fsChildDevice in fsDevice.Children)
			{
				AddDevice(fsChildDevice, device, shleifNo);
			}
		}
예제 #19
0
		public void WriteFileToGK(XDevice gkDevice)
		{
			var bytesList = new List<byte>();
			var gkFileInfo = new GKFileInfo();
			gkFileInfo.Initialize(XManager.DeviceConfiguration, gkDevice);
			bytesList.AddRange(gkFileInfo.InfoBlock);
			var sendResult = SendManager.Send(gkDevice, 0, 21, 0);
			if (sendResult.HasError)
				{ Error = "Невозможно начать процедуру записи "; return; }
            bytesList.AddRange(gkFileInfo.FileBytes);
			var progressCallback = GKProcessorManager.StartProgress("Запись файла в " + gkDevice.PresentationName, null, bytesList.Count / 256, true, GKProgressClientType.Administrator);
			for (var i = 0; i < bytesList.Count; i += 256)
			{
				if (progressCallback.IsCanceled)
					{ Error = "Операция отменена"; return; }
				GKProcessorManager.DoProgress("Запись блока данных " + i + 1, progressCallback);
				var bytesBlock = BitConverter.GetBytes((uint)(i / 256 + 1)).ToList();
				bytesBlock.AddRange(bytesList.GetRange(i, Math.Min(256, bytesList.Count - i)));
				sendResult = SendManager.Send(gkDevice, (ushort)bytesBlock.Count(), 22, 0, bytesBlock);
				if (sendResult.HasError)
				{
					Error = "Невозможно записать блок данных " + i;
					break;
				}
			}
			var endBlock = BitConverter.GetBytes((uint) (bytesList.Count()/256 + 1)).ToList();
			sendResult = SendManager.Send(gkDevice, 0, 22, 0, endBlock);
			if (sendResult.HasError)
				{ Error = "Невозможно завершить запись файла "; }
		}
예제 #20
0
		public static string GetDeviceInfo(XDevice device)
		{
			try
			{
				var stringBuilder = new StringBuilder();
				var result1 = SendManager.Send(device, 0, 1, 1);
				if (!result1.HasError)
				{
					byte softvareVersion = result1.Bytes[0];
					if (softvareVersion > 127)
						stringBuilder.AppendLine("Режим: Технологический");
					else
						stringBuilder.AppendLine("Режим: Рабочий");
					softvareVersion = (byte)(softvareVersion << 1);
					softvareVersion = (byte)(softvareVersion >> 1);
					stringBuilder.AppendLine("Версия ПО: " + softvareVersion.ToString());
				}
				var result2 = SendManager.Send(device, 0, 2, 8);
				if (!result2.HasError)
				{
					var serialNo = (ushort)BytesHelper.SubstructInt(result2.Bytes, 0);
					stringBuilder.AppendLine("Серийный номер: " + serialNo.ToString());

					var hardvareVervion = (ushort)BytesHelper.SubstructInt(result2.Bytes, 4);
					stringBuilder.AppendLine("Аппаратный номер: " + hardvareVervion.ToString());
				}
				return stringBuilder.ToString();
			}
			catch (Exception e)
			{
				Logger.Error(e, "DeviceBytesHelper.ShowInfoCommand");
			}
			return null;
		}
		public ConfigurationCompareViewModel(XDeviceConfiguration localConfiguration, XDeviceConfiguration remoteConfiguration, XDevice device, bool configFromFile)
		{
			Title = "Сравнение конфигураций " + device.PresentationName;
			ConfigFromFile = configFromFile;
			ChangeCommand = new RelayCommand(OnChange);
			NextDifferenceCommand = new RelayCommand(OnNextDifference, CanNextDifference);
			PreviousDifferenceCommand = new RelayCommand(OnPreviousDifference, CanPreviousDifference);

			LocalConfiguration = localConfiguration;
			RemoteConfiguration = remoteConfiguration;
			RemoteConfiguration.Update();
			UpdateConfigurationHelper.Update(RemoteConfiguration);

			LocalDevice = localConfiguration.Devices.FirstOrDefault(x => x.DriverType == device.DriverType && x.Address == device.Address);
			RemoteDevice = remoteConfiguration.Devices.FirstOrDefault(x => x.DriverType == device.DriverType && x.Address == device.Address);
		    if (RemoteDevice == null)
		    {
		        Error = "ГК в удаленной конфигурации имеет невалидный IP адрес";
                return;
		    }
		    LocalObjectsViewModel = new ObjectsListViewModel(LocalDevice, localConfiguration);
			RemoteObjectsViewModel = new ObjectsListViewModel(RemoteDevice, remoteConfiguration);
			CompareObjectLists();
			InitializeMismatchedIndexes();
		}
예제 #22
0
		public static SendResult Send(XDevice device, ushort length, byte command, ushort inputLenght, List<byte> data = null, bool hasAnswer = true, bool sleepInsteadOfRecieve = false, int receiveTimeout = 2000)
		{
			lock (locker)
			{
				if ((device == null) || (device.Driver == null))
				{
					return new SendResult("Неизвестное устройство");
				}

				byte whom = 0;

				switch (device.DriverType)
				{
					case XDriverType.GK:
						whom = 2;
						break;

					case XDriverType.KAU:
					case XDriverType.RSR2_KAU:
						whom = 4;
						var modeProperty = device.Properties.FirstOrDefault(x => x.Name == "Mode");
						if (modeProperty != null)
						{
							switch (modeProperty.Value)
							{
								case 0:
									whom = 4;
									break;

								case 1:
									whom = 5;
									break;

								default:
									throw new Exception("Неизвестный тип линии");
							}
						}
						break;

					default:
						throw new Exception("Команду можно отправлять только в ГК или в КАУ");
				}
				var bytes = new List<byte>();
				bytes.Add(whom);
				bytes.Add((byte)device.IntAddress);
				bytes.AddRange(ToBytes(length));
				bytes.Add(command);
				if (data != null)
					bytes.AddRange(data);

				string ipAddress = XManager.GetIpAddress(device);
				if (string.IsNullOrEmpty(ipAddress))
				{
					return new SendResult("Не задан адрес ГК");
				}
				var resultBytes = SendBytes(ipAddress, bytes, inputLenght, hasAnswer, sleepInsteadOfRecieve, receiveTimeout);
				return resultBytes;
			}
		}
예제 #23
0
		void AddDevice(XDevice device)
		{
			if (!Devices.Contains(device))
			{
				device.GKDescriptorNo = NextDescriptorNo;
				Devices.Add(device);
			}
		}
예제 #24
0
        public virtual void AddDevice(XDevice device)
        {
            if (Devices.Contains(device))
                return;

            device.SetDatabaseNo(DatabaseType, NextChildNo);
            Devices.Add(device);
        }
예제 #25
0
		public void Update(XDevice device, string fileName, string userName)
		{
			var firmWareBytes = HexFileToBytesList(fileName);
			Update(device, firmWareBytes, userName);
			GKProcessorManager.StopProgress(ProgressCallback);
			if (Error != null)
				ErrorList.Add(Error);
		}
예제 #26
0
		public static void ShowDevice(XDevice device, Plan plan)
		{
			var element = plan == null ? null : plan.ElementXDevices.FirstOrDefault(item => item.XDeviceUID == device.UID);
			if (plan == null || element == null)
				ShowDevice(device);
			else
				ServiceFactory.Events.GetEvent<NavigateToPlanElementEvent>().Publish(new NavigateToPlanElementEventArgs(plan.UID, element.UID));
		}
예제 #27
0
		public BoolPropertyViewModel(XDriverProperty driverProperty, XDevice device)
			: base(driverProperty, device)
		{
			var property = device.Properties.FirstOrDefault(x => x.Name == driverProperty.Name);
			if (property != null)
				_isChecked = property.Value > 0;
			else
				_isChecked = (driverProperty.Default == (ushort)1) ? true : false;
		}
예제 #28
0
		public ObjectViewModel(XDevice device)
		{
			Device = device;
			Name = device.ShortName;
			Address = device.DottedPresentationAddress;
			PresentationZone = device.IsNotUsed ? "" : XManager.GetPresentationZone(Device);
			ImageSource = "/Controls;component/GKIcons/" + device.DriverType + ".png";
			ObjectType = ObjectType.Device;
		}
		public StringAUPropertyViewModel(XDriverProperty driverProperty, XDevice device)
			: base(driverProperty, device)
		{
			var property = device.Properties.FirstOrDefault(x => x.Name == driverProperty.Name);
			if (property != null)
				_text = Convert.ToString(property.Value);
			else
				_text = Convert.ToString(driverProperty.Default);
		}
예제 #30
0
 static void AddChild(XDevice device)
 {
     if (!device.Driver.IsGroupDevice)
         AllDevices.Add(device);
     foreach (var child in device.Children)
     {
         AddChild(child);
     }
 }