Beispiel #1
0
		public PDUPTTable(DevicePDUDirection devicePDUDirection, PanelDatabase panelDatabase)
			: base(null, devicePDUDirection.PDUGroupDevice.Device.DottedPresentationNameAndAddress)
		{
			Device = devicePDUDirection.PDUGroupDevice.Device;

			BytesDatabase = new BytesDatabase(Device.DottedPresentationNameAndAddress);
			BytesDatabase.AddByte(Device.AddressOnShleif, "Адрес");
			BytesDatabase.AddByte((Device.ShleifNo - 1), "Шлейф");
			BytesDatabase.AddByte(Device.Parent.IntAddress, "Адрес прибора");
			var deviceCode = FiresecAPI.Models.DriversHelper.GetCodeForDriver(Device.Driver.DriverType);
			BytesDatabase.AddByte(deviceCode, "Тип ИУ");

			var tableBase = panelDatabase.FlashDatabase.LocalZonesTableGroup.Tables.FirstOrDefault(x => x.UID == Device.Zone.UID);
			var localZoneNo = (tableBase as ZoneTable).BinaryZone.LocalNo;
			BytesDatabase.AddShort(localZoneNo, "Номер зоны");
			BytesDatabase.AddByte(devicePDUDirection.Device.IntAddress, "Направление");

			foreach (var tableGroup in panelDatabase.FlashDatabase.DevicesTableGroups)
			{
				tableBase = tableGroup.Tables.FirstOrDefault(x => x.UID == Device.UID);
				if (tableBase != null)
				{
					break;
				}
			}
			var offset = tableBase.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset + 3;
			var offsetBytes = BitConverter.GetBytes(offset);
			for (int i = 0; i < 4; i++)
			{
				BytesDatabase.AddByte(offsetBytes[i], "Смещение");
			}
		}
Beispiel #2
0
		public FlashDatabase(Device parentPanel)
		{
			ParentPanel = parentPanel;
			BytesDatabase = new BytesDatabase();
			BinaryPanel = SystemDatabaseCreator.BinaryConfigurationHelper.BinaryPanels.FirstOrDefault(x => x.ParentPanel == ParentPanel);

			CreateEmptyTable();
            CreateDirections();
			CreateRemoteZones();
			CreateLocalZones();
			CreateAddressListTable();
			CreateDevices();
			CreateLastTable();

			foreach (var table in Tables)
			{
				table.Create();
			}
			foreach (var table in Tables)
			{
				foreach (var byteDescription in table.BytesDatabase.ByteDescriptions)
				{
					byteDescription.TableHeader = table;
				}
			}
			foreach (var table in Tables)
			{
				if (table.BytesDatabase.Name == "Адресный лист")
				{
					var count = BytesDatabase.ByteDescriptions.Count;
					var bytesBefireEnd = 256 - count % 256;
					if (bytesBefireEnd < 32)
					{
						var leftTable = new TableBase(this, "Дополняюшая таблица");
						for (int i = 0; i < bytesBefireEnd; i++)
						{
							leftTable.BytesDatabase.AddByte(0, "Дополняющий байт");
						}
						BytesDatabase.Add(leftTable.BytesDatabase);
					}
				}
				BytesDatabase.Add(table.BytesDatabase);
			}
			BytesDatabase.Order();
			BytesDatabase.ResolveTableReferences();
			BytesDatabase.ResolveReferences();

			var crcBytes = BytesDatabase.GetBytes();
			crcBytes.RemoveRange(0, 256);
			crcBytes.RemoveRange(crcBytes.Count - 36, 36);
			var md5 = MD5.Create();
			var md5Bytes = md5.ComputeHash(crcBytes.ToArray());
			for (int i = 0; i < 16; i++)
			{
				var md5Byte = md5Bytes[i];
				LastTable.BytesDatabase.ByteDescriptions[i + 1].Value = md5Byte;
			}

			CreateRootBytes();
		}
Beispiel #3
0
		public PDUTable(DevicePDUDirection devicePDUDirection, PanelDatabase panelDatabase)
			: base(null, devicePDUDirection.PDUGroupDevice.Device.DottedPresentationNameAndAddress)
		{
			Device = devicePDUDirection.PDUGroupDevice.Device;
			BytesDatabase = new BytesDatabase(Device.DottedPresentationNameAndAddress);
			BytesDatabase.AddByte(Device.AddressOnShleif, "Адрес");
			BytesDatabase.AddByte((Device.ShleifNo - 1), "Шлейф");
			BytesDatabase.AddByte(Device.Parent.IntAddress, "Адрес прибора");
			var deviceCode = FiresecAPI.Models.DriversHelper.GetCodeForDriver(Device.Driver.DriverType);
			BytesDatabase.AddByte(deviceCode, "Тип ИУ");
			var option = 0;
			if (devicePDUDirection.PDUGroupDevice.IsInversion)
				option = 128;
			var anotherCount = devicePDUDirection.Device.Parent.Children.Count(x => x.PDUGroupLogic.Devices.Any(y => y.DeviceUID == Device.UID));
			if (anotherCount > 1)
				option += 64;
			BytesDatabase.AddByte(option, "Опции");
			BytesDatabase.AddByte(devicePDUDirection.Device.IntAddress, "Направление");
			BytesDatabase.AddByte(0, "Пустой байт");

			TableBase tableBase = null;
			foreach (var tableGroup in panelDatabase.FlashDatabase.DevicesTableGroups)
			{
				tableBase = tableGroup.Tables.FirstOrDefault(x => x.UID == Device.UID);
				if (tableBase != null)
				{
					break;
				}
			}
			var offset = tableBase.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset;
			if (Device.Driver.IsZoneLogicDevice)
			{
				offset += 3;
			}
			else
			{
				offset += 2;
			}
			var offsetBytes = BitConverter.GetBytes(offset);
			for (int i = 0; i < 4; i++)
			{
				BytesDatabase.AddByte(offsetBytes[i], "Смещение");
			}

			BytesDatabase.AddByte(devicePDUDirection.PDUGroupDevice.OnDelay, "Задержка на включение");
			BytesDatabase.AddByte(devicePDUDirection.PDUGroupDevice.OffDelay, "Задержка на выключение");
			for (int i = 0; i < 9; i++)
			{
				BytesDatabase.AddByte(255, "ПДУ привязки");
			}
			BytesDatabase.AddByte(0, "ПДУ привязки");
		}
Beispiel #4
0
		public BIDatabase(Device device, SystemDatabaseCreator configurationWriterHelper)
		{
			IndicatorItems = new List<IndicatorItem>();

			ConfigurationWriterHelper = configurationWriterHelper;
			ParentPanel = device;
			BytesDatabase = new BytesDatabase();

			Initialize();
			CreateTables();
			CreateRootBytes();

			var crcBytes = BytesDatabase.GetBytes().ToList();
			crcBytes.RemoveRange(0, 0x4000);
			crcBytes.RemoveRange(0, 74);
			var crc16Value = Crc16Helper.ComputeChecksum(crcBytes);
			BytesDatabase.SetShort(Crc16ByteDescription, crc16Value);

			CreateRootBytes();
		}
Beispiel #5
0
		void CreateTables()
		{
			FirstTable = new BytesDatabase();
			for (int i = 0; i < 0x4000; i++)
			{
				FirstTable.AddByte(0);
			}
			FirstTable.AddShort(5, "Версия БД");
			Crc16ByteDescription = FirstTable.AddShort(0, "CRC от ROM части базы", ignoreUnequal: true);
			var lengtByteDescription = FirstTable.AddInt(0, "Размер БД");
			FirstTable.AddShort(IndicatorItems.Count, "Число приборов");
			BytesDatabase.Add(FirstTable);

			BytesDatabase.AddByte(1, "Хэш");
			for (int i = 0; i < 16; i++)
			{
				BytesDatabase.AddByte(0, "Хэш", ignoreUnequal: true);
			}
			for (int i = 0; i < 47; i++)
			{
				BytesDatabase.AddByte(255, "Доп. информация");
			}


            IndicatorItems = IndicatorItems.OrderBy(x => x.ParentPanel.IntAddress).ToList();

			foreach (var indicatorItem in IndicatorItems)
			{
				var panelDatabase = ConfigurationWriterHelper.PanelDatabases.FirstOrDefault(x => x.ParentPanel.UID == indicatorItem.ParentPanel.UID);

				var paneBytesDatabase = new BytesDatabase("Запись прибора");

				paneBytesDatabase.AddByte(indicatorItem.ParentPanel.IntAddress, "Номер прибора");
				for (int i = 0; i < 16; i++)
				{
					var value = panelDatabase.FlashDatabase.LastTable.BytesDatabase.ByteDescriptions[i + 1].Value;
					paneBytesDatabase.AddByte(value, "MD5", ignoreUnequal:true);
				}
				var offset = panelDatabase.FlashDatabase.LastTable.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset;
				var offsetBytes = BitConverter.GetBytes(offset + 1);
				for (int i = 0; i < 3; i++)
				{
					paneBytesDatabase.AddByte(offsetBytes[i], "Смещение MD5");
				}
				paneBytesDatabase.AddShort(indicatorItem.ZoneIndicators.Count, "Количество зон");
				indicatorItem.ZonesReference = paneBytesDatabase.AddReference(new ByteDescription(), "Смещение зон");
				paneBytesDatabase.AddShort(indicatorItem.Devices.Count, "Количество ИУ");
				indicatorItem.DevicesReference = paneBytesDatabase.AddReference(new ByteDescription(), "Смещение ИУ");
				paneBytesDatabase.AddShort(indicatorItem.AM1_T_Devices.Count, "Количество ТМ");
				indicatorItem.AM1_TReference = paneBytesDatabase.AddReference(new ByteDescription(), "Смещение ТМ");
				paneBytesDatabase.AddShort(indicatorItem.PumpStations.Count, "Количество НС");
				indicatorItem.PumpStationReference = paneBytesDatabase.AddReference(new ByteDescription(), "Смещение НС");
				paneBytesDatabase.AddShort(indicatorItem.Pumps.Count, "Количество Насосов");
				indicatorItem.PumpReference = paneBytesDatabase.AddReference(new ByteDescription(), "Смещение Насосов");

				BytesDatabase.Add(paneBytesDatabase);
			}

			foreach (var indicatorItem in IndicatorItems)
			{
				var panelDatabase = ConfigurationWriterHelper.PanelDatabases.FirstOrDefault(x => x.ParentPanel.UID == indicatorItem.ParentPanel.UID);

				var firstFlag = true;
				foreach (var zoneIndicator in indicatorItem.ZoneIndicators)
				{
					var paneBytesDatabase = new BytesDatabase("Зона " + zoneIndicator.Zone.PresentationName);
					var zoneTable = panelDatabase.FlashDatabase.LocalZonesTableGroup.Tables.FirstOrDefault(x => x.UID == zoneIndicator.Zone.UID) as ZoneTable;
					var offset = zoneTable.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset;
					var offsetBytes = BitConverter.GetBytes(offset);
					for (int i = 0; i < 3; i++)
					{
						paneBytesDatabase.AddByte(offsetBytes[i], "Смещение");
					}
					paneBytesDatabase.AddShort(zoneTable.BinaryZone.LocalNo, "Локальный номер");
					var zoneType = 0;
					if (zoneIndicator.Zone.ZoneType == ZoneType.Guard)
						zoneType = 1;
					paneBytesDatabase.AddByte(zoneType, "ID Зоны");
					var deviceNo = (zoneIndicator.IndicatorDevice.Parent.IntAddress - 1) * 50 + zoneIndicator.IndicatorDevice.IntAddress;
					paneBytesDatabase.AddByte(deviceNo, "Номер светодиода");
					BytesDatabase.Add(paneBytesDatabase);

					if (firstFlag)
					{
						indicatorItem.ZonesReference.AddressReference = paneBytesDatabase.ByteDescriptions.FirstOrDefault();
						firstFlag = false;
					}
				}

				firstFlag = true;
				var sortedDevices = indicatorItem.Devices.OrderBy(x => x.Device.IntAddress).ToList();
				foreach (var deviceIndicator in sortedDevices)
				{
					var paneBytesDatabase = new BytesDatabase("Устройство ИУ " + deviceIndicator.Device.DottedPresentationNameAndAddress);

					EffectorDeviceTable effectorDeviceTable = null;
					foreach (var tableGroup in panelDatabase.FlashDatabase.DevicesTableGroups)
					{
						effectorDeviceTable = tableGroup.Tables.FirstOrDefault(x => x.UID == deviceIndicator.Device.UID) as EffectorDeviceTable;
						if (effectorDeviceTable != null)
						{
							break;
						}
					}
					var offset = effectorDeviceTable.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset + 3;
					var offsetBytes = BitConverter.GetBytes(offset);
					for (int i = 0; i < 3; i++)
					{
						paneBytesDatabase.AddByte(offsetBytes[i], "Смещение");
					}
					paneBytesDatabase.AddByte(effectorDeviceTable.Device.AddressOnShleif, "Адрес");
					paneBytesDatabase.AddByte(effectorDeviceTable.Device.ShleifNo - 1, "Шлейф");

					var firstValue = 16 * (int)deviceIndicator.IndicatorDevice.IndicatorLogic.OnColor + (int)deviceIndicator.IndicatorDevice.IndicatorLogic.OffColor;
					var sectondValue = 16 * (int)deviceIndicator.IndicatorDevice.IndicatorLogic.FailureColor + (int)deviceIndicator.IndicatorDevice.IndicatorLogic.ConnectionColor;
					paneBytesDatabase.AddByte(firstValue, "Индикация");
					paneBytesDatabase.AddByte(sectondValue, "Индикация");
					for (int i = 0; i < 14; i++)
					{
						paneBytesDatabase.AddByte(0, "Индикация");
					}

					var deviceCode = FiresecAPI.Models.DriversHelper.GetCodeForDriver(effectorDeviceTable.Device.Driver.DriverType);
					paneBytesDatabase.AddByte(deviceCode, "Тип ИУ");
					var deviceNo = (deviceIndicator.IndicatorDevice.Parent.IntAddress - 1) * 50 + deviceIndicator.IndicatorDevice.IntAddress;
					paneBytesDatabase.AddByte(deviceNo, "Номер светодиода");
					BytesDatabase.Add(paneBytesDatabase);

					if (firstFlag)
					{
						indicatorItem.DevicesReference.AddressReference = paneBytesDatabase.ByteDescriptions.FirstOrDefault();
						firstFlag = false;
					}
				}

				firstFlag = true;
				var sortedAM1_T_Devices = indicatorItem.AM1_T_Devices.OrderBy(x => x.Device.IntAddress).ToList();
				foreach (var deviceIndicator in sortedAM1_T_Devices)
				{
					var paneBytesDatabase = new BytesDatabase("Устройство АМ1-Т " + deviceIndicator.Device.DottedPresentationNameAndAddress);

					SensorDeviceTable sensorDeviceTable = null;
					foreach (var tableGroup in panelDatabase.FlashDatabase.DevicesTableGroups)
					{
						sensorDeviceTable = tableGroup.Tables.FirstOrDefault(x => x.UID == deviceIndicator.Device.UID) as SensorDeviceTable;
						if (sensorDeviceTable != null)
						{
							break;
						}
					}
					var offset = sensorDeviceTable.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset + 2;
					var offsetBytes = BitConverter.GetBytes(offset);
					for (int i = 0; i < 3; i++)
					{
						paneBytesDatabase.AddByte(offsetBytes[i], "Смещение");
					}
					paneBytesDatabase.AddByte(sensorDeviceTable.Device.AddressOnShleif, "Адрес");
					paneBytesDatabase.AddByte(sensorDeviceTable.Device.ShleifNo - 1, "Шлейф");

					var firstValue = 16 * (int)deviceIndicator.IndicatorDevice.IndicatorLogic.OnColor + (int)deviceIndicator.IndicatorDevice.IndicatorLogic.OffColor;
					var sectondValue = 16 * (int)deviceIndicator.IndicatorDevice.IndicatorLogic.FailureColor + (int)deviceIndicator.IndicatorDevice.IndicatorLogic.ConnectionColor;
					paneBytesDatabase.AddByte(firstValue, "Индикация");
					paneBytesDatabase.AddByte(sectondValue, "Индикация");
					for (int i = 0; i < 14; i++)
					{
						paneBytesDatabase.AddByte(0, "Индикация");
					}

					var deviceCode = FiresecAPI.Models.DriversHelper.GetCodeForDriver(sensorDeviceTable.Device.Driver.DriverType);
					paneBytesDatabase.AddByte(deviceCode, "Тип ИУ");
					var deviceNo = (deviceIndicator.IndicatorDevice.Parent.IntAddress - 1) * 50 + deviceIndicator.IndicatorDevice.IntAddress;
					paneBytesDatabase.AddByte(deviceNo, "Номер светодиода");
					BytesDatabase.Add(paneBytesDatabase);

					if (firstFlag)
					{
						indicatorItem.AM1_TReference.AddressReference = paneBytesDatabase.ByteDescriptions.FirstOrDefault();
						firstFlag = false;
					}
				}

				firstFlag = true;
				foreach (var deviceIndicator in indicatorItem.PumpStations)
				{
					var paneBytesDatabase = new BytesDatabase("НС " + deviceIndicator.Device.DottedPresentationNameAndAddress);

					EffectorDeviceTable effectorDeviceTable = null;
					foreach (var tableGroup in panelDatabase.FlashDatabase.DevicesTableGroups)
					{
						effectorDeviceTable = tableGroup.Tables.FirstOrDefault(x => x.UID == deviceIndicator.Device.UID) as EffectorDeviceTable;
						if (effectorDeviceTable != null)
						{
							break;
						}
					}
					var offset = effectorDeviceTable.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset + 3;
					var offsetBytes = BitConverter.GetBytes(offset);
					for (int i = 0; i < 3; i++)
					{
						paneBytesDatabase.AddByte(offsetBytes[i], "Смещение");
					}
					paneBytesDatabase.AddByte(effectorDeviceTable.Device.PumpAddress, "Адрес");

					var deviceNo = (deviceIndicator.IndicatorDevice.Parent.IntAddress - 1) * 50 + deviceIndicator.IndicatorDevice.IntAddress;
					paneBytesDatabase.AddByte(deviceNo, "Номер светодиода");
					BytesDatabase.Add(paneBytesDatabase);

					if (firstFlag)
					{
						indicatorItem.PumpStationReference.AddressReference = paneBytesDatabase.ByteDescriptions.FirstOrDefault();
						firstFlag = false;
					}
				}

				firstFlag = true;
				var sortedPumps = indicatorItem.Pumps.OrderBy(x => x.Device.PumpAddress).ToList();
				foreach (var deviceIndicator in sortedPumps)
				{
					var paneBytesDatabase = new BytesDatabase("Насос " + deviceIndicator.Device.DottedPresentationNameAndAddress);

					EffectorDeviceTable effectorDeviceTable = null;
					foreach (var tableGroup in panelDatabase.FlashDatabase.DevicesTableGroups)
					{
						effectorDeviceTable = tableGroup.Tables.FirstOrDefault(x => x.UID == deviceIndicator.Device.Parent.UID) as EffectorDeviceTable;
						if (effectorDeviceTable != null)
						{
							break;
						}
					}

					var offset = effectorDeviceTable.BytesDatabase.ByteDescriptions.FirstOrDefault(x => x.Description == "Адрес насоса " + deviceIndicator.Device.PumpAddress).Offset + 8;
					var offsetBytes = BitConverter.GetBytes(offset);
					for (int i = 0; i < 3; i++)
					{
						paneBytesDatabase.AddByte(offsetBytes[i], "Смещение");
					}
					paneBytesDatabase.AddByte(deviceIndicator.Device.PumpAddress, "Адрес");
					paneBytesDatabase.AddByte(0, "Шлейф");

					var deviceNo = (deviceIndicator.IndicatorDevice.Parent.IntAddress - 1) * 50 + deviceIndicator.IndicatorDevice.IntAddress;
					paneBytesDatabase.AddByte(deviceNo, "Номер светодиода");
					BytesDatabase.Add(paneBytesDatabase);

					if (firstFlag)
					{
						indicatorItem.PumpReference.AddressReference = paneBytesDatabase.ByteDescriptions.FirstOrDefault();
						firstFlag = false;
					}
				}
			}

			Tables.Add(FirstTable);
			BytesDatabase.SetShort(lengtByteDescription, BytesDatabase.ByteDescriptions.Count - 0x4000 - 74);
		}
Beispiel #6
0
		void AddLocalZonesHeaderPointers()
		{
			var bytesDatabase = new BytesDatabase("Указатель на указатели на локальные зоны");
			bytesDatabase.AddReference(LocalZonesBytesDatabase, "Абсолютный указатель на таблицу");
			bytesDatabase.AddByte(0, "Длина записи в таблице");
			bytesDatabase.AddShort(FlashDatabase.LocalZonesTableGroup.Tables.Count, "Текущее число записей в таблице");
			BytesDatabase.Add(bytesDatabase);
		}
Beispiel #7
0
		public TableBase(FlashDatabase panelDatabase, string name = null)
		{
			PanelDatabase = panelDatabase;
			BytesDatabase = new BytesDatabase(name);
		}
Beispiel #8
0
		void InitializeLocalIUDevices()
		{
			var devicesOnShleifs = DevicesOnShleifHelper.GetLocalForZone(ParentPanel, Zone);
			foreach (var devicesOnShleif in devicesOnShleifs)
			{
				var referenceBytesDatabase = new BytesDatabase("Локальные устройства шлейфа " + devicesOnShleif.ShleifNo.ToString() + " для зоны " + Zone.PresentationName);
				ReferenceBytesDatabase.Add(referenceBytesDatabase);

				foreach (var device in devicesOnShleif.Devices)
				{
					TableBase table = PanelDatabase.Tables.FirstOrDefault(x => x.UID == device.UID);
					referenceBytesDatabase.AddReferenceToTable(table, "Ссылка на локальное устройство " + device.PresentationAddressAndName);
				}
				var byteDescription = referenceBytesDatabase.ByteDescriptions.FirstOrDefault();
				BytesDatabase.AddByte(devicesOnShleif.Devices.Count, "Количество связанных локальных ИУ шлейфа " + devicesOnShleif.ShleifNo.ToString());
				BytesDatabase.AddReference(byteDescription, "Указатель на размещение абсолютного адреса размещения первого в списке связанного локального ИУ шлейфа  " + devicesOnShleif.ShleifNo.ToString());
			}
		}
Beispiel #9
0
		public void AddReference(BytesDatabase bytesDatabase, string description = null)
		{
			var byteDescriptions = AddBytes(new List<byte>() { 0, 0, 0 }, description);
			if (bytesDatabase != null)
				byteDescriptions.AddressReference = bytesDatabase.ByteDescriptions.FirstOrDefault();
		}
Beispiel #10
0
		void AddServiceTablePointers()
		{
			var bytesDatabase = new BytesDatabase("Указатель Служебную таблицу");
			bytesDatabase.AddReferenceToTable(FlashDatabase.AddressListTable, "Абсолютный указатель на таблицу");
			bytesDatabase.AddByte(1, "Длина записи в таблице");
			bytesDatabase.AddShort(FlashDatabase.AddressListTable.BytesDatabase.ByteDescriptions.Count, "Текущее число записей в таблице");
			BytesDatabase.Add(bytesDatabase);
		}
Beispiel #11
0
		void AddDirectionsHeadersPointers()
		{
			var bytesDatabase = new BytesDatabase("Указатель на указатели на Направления");
			bytesDatabase.AddReference(DirectionsBytesDatabase, "Абсолютный указатель на таблицу");
			bytesDatabase.AddByte(0, "Длина записи в таблице");
            bytesDatabase.AddShort(DirectionsBytesDatabase.ByteDescriptions.Count / 3, "Текущее число записей в таблице");
			BytesDatabase.Add(bytesDatabase);
		}
Beispiel #12
0
		public RomDatabase(FlashDatabase flashDatabase, int startOffset)
		{
			FlashDatabase = flashDatabase;
			BytesDatabase = new BytesDatabase();

			var headBytesDatabase = new BytesDatabase("Заголовок");
			if (FlashDatabase.ParentPanel.Driver.DriverType == DriverType.BUNS || FlashDatabase.ParentPanel.Driver.DriverType == DriverType.USB_BUNS)
			{
				headBytesDatabase.AddString("BUNS", "Сигнатура базы", 4);
			}
			else
			{
				headBytesDatabase.AddString("BASE", "Сигнатура базы", 4);
			}
			headBytesDatabase.AddShort(5, "Версия базы");
			headBytesDatabase.AddReference(FlashDatabase.BytesDatabase.ByteDescriptions.Last(), "Абсолютный указатель на конец базы во внешней энергонезависимой паияти");
			var pointerToLast = headBytesDatabase.AddReference((ByteDescription)null, "Абсолютный указатель на конец блока, записываемого в память кристалла");
			BytesDatabase.Add(headBytesDatabase);

			foreach (var tableGroup in FlashDatabase.DevicesTableGroups)
			{
				var bytesDatabase = new BytesDatabase(tableGroup.Name);
				bytesDatabase.AddReferenceToTable(tableGroup.Tables.FirstOrDefault(), tableGroup.Name);
				bytesDatabase.AddByte(tableGroup.ComputedLength, "Длина записи в таблице");
				bytesDatabase.AddShort(tableGroup.Count, "Текущее число записей в таблице");
				BytesDatabase.Add(bytesDatabase);
			}

			var emptyBytesDatabase = new BytesDatabase();
			for (int i = 0; i < 1542 - BytesDatabase.ByteDescriptions.Count; i++)
			{
				emptyBytesDatabase.AddByte(0);
			}
			BytesDatabase.Add(emptyBytesDatabase);

			CreateLocalZonesHeaders();
			CreateRemoteDevicesHeaders();
			CreateDirectionsHeaders();
			CreateLocalDevicesHeaders();
			AddLocalZonesHeaderPointers();
			AddRemoteZonesHeaders();
			AddRemoteDevicesHeadersPointers();
			AddLocalDevicesHeadersPointers();
			AddServiceTablePointers();
			AddDirectionsHeadersPointers();

            BytesDatabase.Add(DirectionsBytesDatabase);
			BytesDatabase.Add(LocalZonesBytesDatabase);
			BytesDatabase.Add(RemoteDevicesBytesDatabase);
			foreach (var localDevicesBytesDatabase in LocalDevicesBytesDatabase)
			{
				BytesDatabase.Add(localDevicesBytesDatabase);
			}

			pointerToLast.AddressReference = BytesDatabase.ByteDescriptions.LastOrDefault();

			BytesDatabase.Order(startOffset);
			BytesDatabase.ResolveTableReferences();
			foreach (var byteDescription in BytesDatabase.ByteDescriptions)
			{
				if (byteDescription.TableBaseReference != null)
				{
					byteDescription.AddressReference = FlashDatabase.BytesDatabase.ByteDescriptions.FirstOrDefault(x => x.TableHeader != null && x.TableHeader.ReferenceUID == byteDescription.TableBaseReference.ReferenceUID);
				}
			}
			BytesDatabase.ResolveReferences();

			var allBytes = BytesDatabase.GetBytes();
			var crc16Value = Crc16Helper.ComputeChecksum(allBytes);
			FlashDatabase.BytesDatabase.SetShort(FlashDatabase.Crc16ByteDescription, crc16Value);
		}
Beispiel #13
0
		void CreateDirectionsHeaders()
		{
            var maxDirectionNo = 0;
            var localBinaryPanel = BinaryConfigurationHelper.Current.BinaryPanels.FirstOrDefault(x => x.ParentPanel.UID == this.FlashDatabase.ParentPanel.UID);
            if (localBinaryPanel.TempDirections.Count > 0)
            {
                maxDirectionNo = localBinaryPanel.TempDirections.Max(x => x.Id);
            }
            DirectionsBytesDatabase = new BytesDatabase("Направления");
            for (int i = 1; i <= maxDirectionNo; i++)
            {
                var direction = localBinaryPanel.TempDirections.FirstOrDefault(x => x.Id == i);
                if (direction != null)
                {
                    var table = FlashDatabase.DirectionsTableGroup.Tables.FirstOrDefault(x => x.UID == direction.UID);
                    DirectionsBytesDatabase.AddReferenceToTable(table, "Абсолютный адрес размещения Направления");
                }
                else
                {
                    TableBase table = null;
                    DirectionsBytesDatabase.AddReferenceToTable(table, "Пропуск направления");
                }
            }
		}
Beispiel #14
0
		void AddRemoteDevicesHeadersPointers()
		{
			var bytesDatabase = new BytesDatabase("Указатель на указатели на Внешние устройства");
			bytesDatabase.AddReference(RemoteDevicesBytesDatabase, "Абсолютный указатель на таблицу");
			bytesDatabase.AddByte(0, "Длина записи в таблице");
			bytesDatabase.AddShort(0, "Текущее число записей в таблице");
			BytesDatabase.Add(bytesDatabase);
		}
Beispiel #15
0
		void CreateRemoteDevicesHeaders()
		{
			var bytesDatabase = new BytesDatabase("Внешние устройства");
			foreach (var table in FlashDatabase.RemoteDeviceTables)
			{
				bytesDatabase.AddReferenceToTable(table, "Абсолютный адрес размещения внешнего устройства");
			}
			RemoteDevicesBytesDatabase = bytesDatabase;
		}
Beispiel #16
0
		public void Add(BytesDatabase bytesDatabase)
		{
			LastIsBold = !LastIsBold;
			bytesDatabase.IsBold = LastIsBold;

			foreach (var byteDescription in bytesDatabase.ByteDescriptions)
			{
				byteDescription.GroupName = bytesDatabase.Name;
				byteDescription.IsBold = bytesDatabase.IsBold;
			}
			foreach (var byteDescription in bytesDatabase.ByteDescriptions)
			{
				ByteDescriptions.Add(byteDescription);
			}
		}
Beispiel #17
0
		void CreateLocalDevicesHeaders()
		{
			var devicesOnShleifs = DevicesOnShleifHelper.GetLocalForPanelToMax(FlashDatabase.ParentPanel);
			foreach (var devicesOnShleif in devicesOnShleifs)
			{
				var bytesDatabase = new BytesDatabase("Устройства шлейфа " + devicesOnShleif.ShleifNo.ToString());
				foreach (var device in devicesOnShleif.Devices)
				{
					TableBase table = null;
					var tableName = "Пропуск устройства";
					if (device != null)
					{
						table = FlashDatabase.Tables.FirstOrDefault(x => x.UID == device.UID);
						tableName = "Абсолютный адрес размещения устройства " + device.PresentationAddressAndName;
					}
					bytesDatabase.AddReferenceToTable(table, tableName);
				}
				LocalDevicesBytesDatabase.Add(bytesDatabase);
			}
		}
Beispiel #18
0
		void AddLocalDevicesHeadersPointers()
		{
			for (int i = 0; i < 16; i++)
			{
				BytesDatabase shleifBytesDatabase = null;
				if (i < LocalDevicesBytesDatabase.Count)
					shleifBytesDatabase = LocalDevicesBytesDatabase[i];
				var bytesDatabase = new BytesDatabase("Указатель на указатели на локальное устройство шлейфа " + (i + 1).ToString());
				bytesDatabase.AddReference(shleifBytesDatabase, "Абсолютный указатель на таблицу");
				bytesDatabase.AddByte(0, "Длина записи в таблице");
				var count = 0;
				if (shleifBytesDatabase != null)
					count = shleifBytesDatabase.ByteDescriptions.Count / 3;
				bytesDatabase.AddByte(count, "Текущее число записей в таблице");
				BytesDatabase.Add(bytesDatabase);
			}
		}
Beispiel #19
0
		void AddRemoteZonesHeaders()
		{
			var tableBase = FlashDatabase.RemoteZonesTableGroup.Tables.FirstOrDefault();
			if(tableBase == null)
				tableBase = FlashDatabase.LocalZonesTableGroup.Tables.FirstOrDefault();
			var bytesDatabase = new BytesDatabase("Указатели Внешние зоны");
			bytesDatabase.AddReferenceToTable(tableBase, "Абсолютный указатель на таблицу");
			bytesDatabase.AddByte(FlashDatabase.RemoteZonesTableGroup.Length, "Длина записи в таблице");
			bytesDatabase.AddShort(FlashDatabase.RemoteZonesTableGroup.Count, "Текущее число записей в таблице");
			BytesDatabase.Add(bytesDatabase);
		}
Beispiel #20
0
		void InitializeRemoteIUDevices()
		{
			var devices = DevicesOnShleifHelper.GetRemoteForZone(ParentPanel, Zone);
			devices = devices.OrderBy(x => x.IntAddress).ToList();
			BytesDatabase.AddByte(devices.Count, "Количество связанных внешних ИУ");

			var referenceBytesDatabase = new BytesDatabase("Внешние устройства" + " для зоны " + Zone.PresentationName);
			ReferenceBytesDatabase.Add(referenceBytesDatabase);

			foreach (var device in devices)
			{
				TableBase table = PanelDatabase.Tables.FirstOrDefault(x => x.UID == device.UID);
				referenceBytesDatabase.AddReferenceToTable(table, "Ссылка на внешнее устройство " + device.DottedPresentationAddressAndName);
			}

			var byteDescription = referenceBytesDatabase.ByteDescriptions.FirstOrDefault();
			BytesDatabase.AddReference(byteDescription, "Указатель на размещение абсолютного адреса размещения первого в списке связанного внешнего ИУ");
		}
Beispiel #21
0
		void CreateTables()
		{
			FirstTable = new BytesDatabase();
			for (int i = 0; i < 0x4000; i++)
			{
				FirstTable.AddByte(0);
			}
			FirstTable.AddShort(4, "Версия БД");
			Crc16ByteDescription = FirstTable.AddShort(0, "CRC от ROM части базы", ignoreUnequal: true);
			var lengtByteDescription = FirstTable.AddInt(0, "Размер БД");
			FirstTable.AddShort(PDUItems.Count, "Количество приборов");

			var devicesCount = 0;
			foreach (var pduItem in PDUItems)
			{
				devicesCount += pduItem.DevicePDUDirections.Count;
			}
			FirstTable.AddShort(devicesCount, "Количество ИУ");

			FirstTable.AddByte(1, "Хэш");
			for (int i = 0; i < 16; i++)
			{
				FirstTable.AddByte(0, "Хэш", ignoreUnequal: true);
			}
			for (int i = 0; i < 47; i++)
			{
				FirstTable.AddByte(255, "Доп. информация");
			}

			BytesDatabase.Add(FirstTable);

			foreach (var pduItem in PDUItems)
			{
				var panelDatabase = ConfigurationWriterHelper.PanelDatabases.FirstOrDefault(x => x.ParentPanel.UID == pduItem.ParentPanel.UID);

				var paneBytesDatabase = new BytesDatabase("Прибор " + pduItem.ParentPanel.DottedPresentationNameAndAddress);

				paneBytesDatabase.AddByte(pduItem.ParentPanel.IntAddress, "Номер прибора");
				for (int i = 0; i < 16; i++)
				{
					var value = panelDatabase.FlashDatabase.LastTable.BytesDatabase.ByteDescriptions[i + 1].Value;
					paneBytesDatabase.AddByte(value, "MD5", ignoreUnequal: true);
				}
				var offset = panelDatabase.FlashDatabase.LastTable.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset;
				var offsetBytes = BitConverter.GetBytes(offset + 1);
				for (int i = 0; i < 4; i++)
				{
					paneBytesDatabase.AddByte(offsetBytes[i], "Смещение MD5");
				}

				var deviceCode = FiresecAPI.Models.DriversHelper.GetCodeForDriver(pduItem.ParentPanel.Driver.DriverType);
				paneBytesDatabase.AddByte(deviceCode, "Тип прибора");

				BytesDatabase.Add(paneBytesDatabase);
			}

			var emptyBytesDatabase = new BytesDatabase("Пусто");
			var emptyBytesCount = 0x42CC-BytesDatabase.ByteDescriptions.Count + 64;
			for (int i = 0; i < emptyBytesCount; i++)
			{
				emptyBytesDatabase.AddByte(255, "Пустой байт");
			}
			//emptyBytesDatabase.AddByte(0, "Пустой байт");
			BytesDatabase.Add(emptyBytesDatabase);

			var pduTables = new List<PDUTable>();
			foreach (var pduItem in PDUItems)
			{
				var panelDatabase = ConfigurationWriterHelper.PanelDatabases.FirstOrDefault(x => x.ParentPanel.UID == pduItem.ParentPanel.UID);

				foreach (var devicePDUDirection in pduItem.DevicePDUDirections)
				{
					var pduTable = new PDUTable(devicePDUDirection, panelDatabase);
					pduTables.Add(pduTable);
				}
			}

			pduTables = pduTables.OrderBy(x => x.Device.IntAddress * 256 + x.Device.ParentPanel.IntAddress).ToList();
			foreach (var pduTable in pduTables)
			{
				BytesDatabase.Add(pduTable.BytesDatabase);
			}

			Tables.Add(FirstTable);
			BytesDatabase.SetShort(lengtByteDescription, BytesDatabase.ByteDescriptions.Count - 0x4000 - 12 - 64);
		}
Beispiel #22
0
		void CreateTables()
		{
			FirstTable = new BytesDatabase();
			for (int i = 0; i < 0x4000; i++)
			{
				FirstTable.AddByte(0);
			}
			FirstTable.AddShort(1, "Версия БД");
			Crc16ByteDescription = FirstTable.AddShort(0, "CRC от ROM части базы", ignoreUnequal: true);
			var lengtByteDescription = FirstTable.AddInt(0, "Размер БД");
			FirstTable.AddShort(PDUItems.Count, "Количество приборов");

			var devicesCount = 0;
			foreach (var pduItem in PDUItems)
			{
				pduItem.DevicePDUDirections = pduItem.DevicePDUDirections.OrderBy(x => x.Device.IntAddress).ToList();
				devicesCount += pduItem.DevicePDUDirections.Count;
			}
			FirstTable.AddShort(devicesCount, "Количество направлений");
			BytesDatabase.Add(FirstTable);

			BytesDatabase.AddByte(1, "Хэш");
			for (int i = 0; i < 16; i++)
			{
				BytesDatabase.AddByte(0, "Хэш", ignoreUnequal: true);
			}
			for (int i = 0; i < 47; i++)
			{
				BytesDatabase.AddByte(255, "Доп. информация");
			}

			var emptyBytesDatabase1 = new BytesDatabase("Пусто");
			var emptyBytesCount1 = 0x404C - BytesDatabase.ByteDescriptions.Count;
			for (int i = 0; i < emptyBytesCount1; i++)
			{
				emptyBytesDatabase1.AddByte(255, "Пустой байт 1");
			}
			BytesDatabase.Add(emptyBytesDatabase1);

			foreach (var pduItem in PDUItems)
			{
				var panelDatabase = ConfigurationWriterHelper.PanelDatabases.FirstOrDefault(x => x.ParentPanel.UID == pduItem.ParentPanel.UID);
				var paneBytesDatabase = new BytesDatabase("Прибор " + pduItem.ParentPanel.DottedPresentationNameAndAddress);

				paneBytesDatabase.AddByte(pduItem.ParentPanel.IntAddress, "Номер прибора");
				for (int i = 0; i < 16; i++)
				{
					var value = panelDatabase.FlashDatabase.LastTable.BytesDatabase.ByteDescriptions[i + 1].Value;
					paneBytesDatabase.AddByte(value, "MD5", ignoreUnequal: true);
				}
				var offset = panelDatabase.FlashDatabase.LastTable.BytesDatabase.ByteDescriptions.FirstOrDefault().Offset;
				var offsetBytes = BitConverter.GetBytes(offset + 1);
				for (int i = 0; i < 4; i++)
				{
					paneBytesDatabase.AddByte(offsetBytes[i], "Смещение MD5");
				}

				var deviceCode = FiresecAPI.Models.DriversHelper.GetCodeForDriver(pduItem.ParentPanel.Driver.DriverType);
				paneBytesDatabase.AddByte(deviceCode, "Тип прибора");

				BytesDatabase.Add(paneBytesDatabase);
			}

			var emptyBytesDatabase2 = new BytesDatabase("Пусто");
			var emptyBytesCount2 = 0x430C-BytesDatabase.ByteDescriptions.Count;
			for (int i = 0; i < emptyBytesCount2; i++)
			{
				emptyBytesDatabase2.AddByte(255, "Пустой байт 2");
			}
			BytesDatabase.Add(emptyBytesDatabase2);


			var pduPTTables = new List<PDUPTTable>();
			foreach (var pduItem in PDUItems)
			{
				var panelDatabase = ConfigurationWriterHelper.PanelDatabases.FirstOrDefault(x => x.ParentPanel.UID == pduItem.ParentPanel.UID);
				foreach (var devicePDUDirection in pduItem.DevicePDUDirections)
				{
					var pduTable = new PDUPTTable(devicePDUDirection, panelDatabase);
					pduPTTables.Add(pduTable);
					devicePDUDirection.ReferenceToByteDescriptions = pduTable.BytesDatabase.ByteDescriptions.FirstOrDefault();
				}
			}


			foreach (var pduItem in PDUItems)
			{
				foreach (var devicePDUDirection in pduItem.DevicePDUDirections)
				{
					var mptDevice = devicePDUDirection.PDUGroupDevice.Device;
					var paneBytesDatabase = new BytesDatabase("Направление " + devicePDUDirection.Device.DottedPresentationNameAndAddress);
					paneBytesDatabase.AddByte(devicePDUDirection.Device.IntAddress, "Номер направления");
					paneBytesDatabase.AddShort(0, "Задержка запуска");
					var uiCount = 1 + mptDevice.Children.Count;
					paneBytesDatabase.AddByte(uiCount, "Количество ИУ");
					var offsetByteDescription = paneBytesDatabase.AddInt(0, "Смещение");
					offsetByteDescription.AddressReference = devicePDUDirection.ReferenceToByteDescriptions;
					BytesDatabase.Add(paneBytesDatabase);
				}
			}

			var emptyBytesDatabase3 = new BytesDatabase("Пусто");
			var emptyBytesCount3 = 0x4334 - BytesDatabase.ByteDescriptions.Count;
			for (int i = 0; i < emptyBytesCount3; i++)
			{
				emptyBytesDatabase3.AddByte(255, "Пустой байт 3");
			}
			BytesDatabase.Add(emptyBytesDatabase3);

			//pduPTTables = pduPTTables.OrderBy(x => x.Device.IntAddress * 256 + x.Device.ParentPanel.IntAddress).ToList();
			foreach (var pduTable in pduPTTables)
			{
				BytesDatabase.Add(pduTable.BytesDatabase);
			}

			Tables.Add(FirstTable);
			BytesDatabase.SetShort(lengtByteDescription, BytesDatabase.ByteDescriptions.Count - 0x404C);
		}
Beispiel #23
0
		void CreateLocalZonesHeaders()
		{
			var bytesDatabase = new BytesDatabase("Локальные зоны");
			foreach (var table in FlashDatabase.LocalZonesTableGroup.Tables)
			{
				bytesDatabase.AddReferenceToTable(table, "Абсолютный адрес размещения локальной зоны " + (table as ZoneTable).Zone.PresentationName);
			}
			LocalZonesBytesDatabase = bytesDatabase;
		}