Esempio n. 1
0
		static void InitializeAddresses(Device device, int shleifNo)
		{
			Addresses = new List<DeviceAddress>();

			if (device.Driver.IsChildAddressReservedRange)
			{
				for (int i = 1; i < device.GetReservedCount(); i++)
				{
					Addresses.Add(new DeviceAddress(device.IntAddress + i));
				}
			}
			else
			{
				for (int i = 1; i < 256; i++)
				{
					Addresses.Add(new DeviceAddress(shleifNo * 256 + i));
				}
			}
			if (device.Driver.DriverType == DriverType.MRK_30)
			{
				Addresses = new List<DeviceAddress>();
				for (int i = device.IntAddress % 256; i <= Math.Min(256, device.IntAddress % 256 + 30); i++)
				{
					Addresses.Add(new DeviceAddress(shleifNo * 256 + i));
				}
			}
		}
Esempio n. 2
0
        public static int GetMinAddress(Driver driver, Device parentDevice)
        {
            if (driver.UseParentAddressSystem)
            {
                if (driver.DriverType == DriverType.MPT)
                {
                    while (parentDevice.Driver.UseParentAddressSystem)
                    {
                        parentDevice = parentDevice.Parent;
                    }
                }
                else
                {
                    parentDevice = parentDevice.Parent;
                }
            }

            int maxAddress = 0;

            if (driver.IsRangeEnabled)
            {
                maxAddress = driver.MinAddress;
            }
            else
            {
                if (parentDevice.Driver.ShleifCount > 0)
                    maxAddress = 257;

                if (parentDevice.Driver.IsChildAddressReservedRange)
                {
                    maxAddress = parentDevice.IntAddress;
                }
            }

            foreach (var child in FiresecManager.FiresecConfiguration.GetAllChildrenForDevice(parentDevice))
            {
                if (child.Driver.IsAutoCreate)
                    continue;

                if (driver.IsRangeEnabled)
                {
                    if ((child.IntAddress < driver.MinAddress) || (child.IntAddress > driver.MaxAddress))
                        continue;
                }

                if (parentDevice.Driver.IsChildAddressReservedRange)
                {
                    int reservedCount = parentDevice.GetReservedCount();

                    if ((child.IntAddress < parentDevice.IntAddress) && (child.IntAddress > parentDevice.IntAddress + reservedCount - 1))
                        continue;
                }

                if (child.Driver.AutoChildCount > 0)
                {
                    if (child.IntAddress + child.Driver.AutoChildCount - 1 > maxAddress)
                        maxAddress = child.IntAddress + child.Driver.AutoChildCount - 1;
                }
                else
                {
                    if (child.IntAddress > maxAddress)
                        maxAddress = child.IntAddress;
                }

                if (child.Driver.DriverType == DriverType.MRK_30)
                {
                    maxAddress = child.IntAddress + child.GetReservedCount();
                }
            }

            if (parentDevice.Driver.DriverType == DriverType.MRK_30)
                maxAddress = parentDevice.IntAddress;

            if (driver.IsRangeEnabled)
            {
                if (parentDevice.Children.Count > 0)
                    if (maxAddress + 1 <= driver.MaxAddress)
                        maxAddress = maxAddress + 1;
            }
            else
            {
                if (parentDevice.Driver.IsChildAddressReservedRange)
                {
                    int reservedCount = driver.ChildAddressReserveRangeCount;
                    if (parentDevice.Driver.DriverType == DriverType.MRK_30)
                    {
                        reservedCount = 30;

                        var reservedCountProperty = parentDevice.Properties.FirstOrDefault(x => x.Name == "MRK30ChildCount");
                        if (reservedCountProperty != null)
                        {
                            reservedCount = int.Parse(reservedCountProperty.Value);
                        }
                    }

                    if (parentDevice.Children.Count > 0)
                        if (maxAddress + 1 <= parentDevice.IntAddress + reservedCount - 1)
                            maxAddress = maxAddress + 1;
                }
                else
                {
                    if (parentDevice.Children.Where(x=>x.Driver.IsAutoCreate == false).ToList().Count > 0)
                        if (((maxAddress + 1) % 256) != 0)
                            maxAddress = maxAddress + 1;
                }
            }

            return maxAddress;
        }
Esempio n. 3
0
		void ValidateMRK30(Device device)
		{
			if (device.Driver.DriverType == DriverType.MRK_30)
			{
				var reservedCount = device.GetReservedCount();
				if (reservedCount < 1 || reservedCount > 30)
					Errors.Add(new DeviceValidationError(device, string.Format("Количество подключаемых устройств должно быть в диапазоне 1 - 30: {0}", device.PresentationAddress), ValidationErrorLevel.CannotWrite));

				int minChildAddress = device.IntAddress + 1;
				int maxChildAddress = device.IntAddress + reservedCount;
				if (maxChildAddress / 256 != minChildAddress / 256)
					maxChildAddress = maxChildAddress - maxChildAddress % 256;

				foreach (var childDevice in device.Parent.Children)
				{
					if (childDevice.IntAddress >= minChildAddress && childDevice.IntAddress <= maxChildAddress)
					{
						if (childDevice.Parent.UID != device.UID)
							Errors.Add(new DeviceValidationError(childDevice, string.Format("Устройство находится в зарезервированном диапазоне адресов МРК-30: {0}", device.PresentationAddress), ValidationErrorLevel.CannotWrite));
					}
				}

				foreach (var childDevice in device.Children)
				{
					if (childDevice.IntAddress < minChildAddress || childDevice.IntAddress > maxChildAddress)
					{
						Errors.Add(new DeviceValidationError(childDevice, string.Format("Устройство находится за пределами диапазона адресов МРК-30: {0}", device.PresentationAddress), ValidationErrorLevel.CannotWrite));
					}
				}
			}
		}