Example #1
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();
		}
Example #2
0
		void CreateEmptyTable()
		{
			FirstTable = new TableBase(this);
			for (int i = 0; i < 256; i++)
			{
				FirstTable.BytesDatabase.AddByte(0);
			}
			Crc16ByteDescription = FirstTable.BytesDatabase.AddShort(0, "CRC от ROM части базы");
			Tables.Add(FirstTable);
		}
Example #3
0
		void CreateAddressListTable()
		{
			var remotePanels = new HashSet<Device>(BinaryConfigurationHelper.Current.RelationPanels.ToList());
			//if (!BinaryConfigurationHelper.Current.RelationPanels.Any(x => x.IntAddress == ParentPanel.IntAddress))
			//    remotePanels = new HashSet<Device>();

			var addressList = new List<int>();
			for (int i = 0; i < 32; i++)
			{
				addressList.Add(0);
			}

			var nonPanelRemoteDevices = new HashSet<Device>();
			foreach (var device in ConfigurationManager.Devices)
			{
				if (device.Driver.DriverType == DriverType.PDUDirection || device.Driver.DriverType == DriverType.PDU_PTDirection)
				{
					foreach (var pduDevice in device.PDUGroupLogic.Devices)
					{
						if (pduDevice.Device.ParentPanel.UID == ParentPanel.UID)
						{
							nonPanelRemoteDevices.Add(device.ParentPanel);
						}
					}
				}
				if (device.Driver.DriverType == DriverType.IndicationBlock)
				{
					foreach (var pageDevice in device.Children)
					{
						foreach (var indicatorDevice in pageDevice.Children)
						{
							foreach (var zone in indicatorDevice.IndicatorLogic.Zones)
							{
								if (zone.DevicesInZone.Any(x => x.ParentPanel.UID == ParentPanel.UID))
								{
									nonPanelRemoteDevices.Add(indicatorDevice.ParentPanel);
								}
							}
							if (indicatorDevice.IndicatorLogic.Device != null && indicatorDevice.IndicatorLogic.Device.ParentPanel.UID == ParentPanel.UID)
							{
								nonPanelRemoteDevices.Add(device);
							}
						}
					}
				}
			}

			var remotePanelLists = remotePanels.OrderBy(x => x.IntAddress).ToList();

			for (int i = 0; i < remotePanelLists.Count; i++)
			{
				var device = remotePanelLists[i];
				var deviceCode = FiresecAPI.Models.DriversHelper.GetCodeForDriver(device.Driver.DriverType);
				if (device.Driver.DriverType == DriverType.IndicationBlock || device.Driver.DriverType == DriverType.PDUDirection || device.Driver.DriverType == DriverType.PDU_PTDirection)
				{
					if (!nonPanelRemoteDevices.Any(x => x.IntAddress == device.IntAddress))
					{
						continue;
					}
				}
				addressList[i] = deviceCode;
			}

			AddressListTable = new TableBase(this, "Адресный лист");
			foreach (var address in addressList)
			{
				AddressListTable.BytesDatabase.AddByte(address, "", true);
			}
			Tables.Add(AddressListTable);
		}
Example #4
0
		void CreateLastTable()
		{
			LastTable = new TableBase(this, "Последняя таблица");
			LastTable.BytesDatabase.AddByte(9, "Версия MD5");
			for (int i = 0; i < 16; i++)
			{
				LastTable.BytesDatabase.AddByte(0, "MD5", true, true);
			}
			for (int i = 0; i < 19; i++)
			{
				LastTable.BytesDatabase.AddByte(0, "Для нужд базы");
			}
			Tables.Add(LastTable);
		}
Example #5
0
		public ByteDescription AddReferenceToTable(TableBase tableBase, string description = null)
		{
			var byteDescriptions = AddBytes(new List<byte>() { 0, 0, 0 }, description);
			byteDescriptions.TableBaseReference = tableBase;
			return byteDescriptions;
		}