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); }
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); }
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); }