void CheckDBMissmatch(XBase xBase, DescriptorStateHelper descriptorStateHelper) { bool isMissmatch = false; if (xBase is XDevice) { var device = xBase as XDevice; if (device.Driver.DriverTypeNo != descriptorStateHelper.TypeNo) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_тип_устройства; } ushort physicalAddress = device.IntAddress; if (device.Driver.IsDeviceOnShleif) physicalAddress = (ushort)((device.ShleifNo - 1) * 256 + device.IntAddress); if (device.DriverType != XDriverType.GK && device.DriverType != XDriverType.KAU && device.DriverType != XDriverType.RSR2_KAU && device.Driver.HasAddress && physicalAddress != descriptorStateHelper.PhysicalAddress) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_физический_адрес_устройства; } var nearestDescriptorNo = 0; if (device.KauDatabaseParent != null) nearestDescriptorNo = device.KAUDescriptorNo; else if (device.GkDatabaseParent != null) nearestDescriptorNo = device.GKDescriptorNo; if (nearestDescriptorNo != descriptorStateHelper.AddressOnController) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_адрес_на_контроллере; } } if (xBase is XZone) { if (descriptorStateHelper.TypeNo != 0x100) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_тип_для_зоны; } } if (xBase is XDirection) { if (descriptorStateHelper.TypeNo != 0x106) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_тип_для_направления; } } if (xBase is XPumpStation) { if (descriptorStateHelper.TypeNo != 0x106) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_тип_для_НС; } } if (xBase is XDelay) { if (descriptorStateHelper.TypeNo != 0x101) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_тип_для_Задержки; } } if (xBase is XPim) { if (descriptorStateHelper.TypeNo != 0x107) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_тип_для_ПИМ; } } var stringLength = Math.Min(xBase.PresentationName.Length, 32); var description = xBase.PresentationName.Substring(0, stringLength); if (description.TrimEnd(' ') != descriptorStateHelper.Description) { isMissmatch = true; DBMissmatchDuringMonitoringReason = EventDescription.Не_совпадает_описание_компонента; } xBase.BaseState.IsDBMissmatchDuringMonitoring = isMissmatch; if (isMissmatch) { IsDBMissmatchDuringMonitoring = true; } }
void GetState(XBase xBase, bool delaysOnly = false) { var sendResult = SendManager.Send(xBase.GkDatabaseParent, 2, 12, 68, BytesHelper.ShortToBytes(xBase.GKDescriptorNo)); if (sendResult.HasError || sendResult.Bytes.Count != 68) { ConnectionChanged(false); return; } ConnectionChanged(true); var descriptorStateHelper = new DescriptorStateHelper(); descriptorStateHelper.Parse(sendResult.Bytes, xBase); CheckDBMissmatch(xBase, descriptorStateHelper); xBase.BaseState.LastDateTime = DateTime.Now; if (!delaysOnly) { xBase.BaseState.StateBits = descriptorStateHelper.StateBits; xBase.BaseState.AdditionalStates = descriptorStateHelper.AdditionalStates; } xBase.BaseState.OnDelay = descriptorStateHelper.OnDelay; xBase.BaseState.HoldDelay = descriptorStateHelper.HoldDelay; xBase.BaseState.OffDelay = descriptorStateHelper.OffDelay; }
void CheckDBMissmatch(GKBase gkBase, DescriptorStateHelper descriptorStateHelper) { bool isMissmatch = false; if (gkBase is GKDevice) { var device = gkBase as GKDevice; if (device.Driver.DriverTypeNo != descriptorStateHelper.TypeNo) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_устройства; } ushort physicalAddress = (ushort)device.IntAddress; if (device.Driver.IsDeviceOnShleif) physicalAddress = (ushort)((device.ShleifNo - 1) * 256 + device.IntAddress); if (device.DriverType != GKDriverType.GK && device.DriverType != GKDriverType.RSR2_KAU && device.DriverType != GKDriverType.GKMirror && device.Driver.HasAddress && !device.Driver.HasMirror && device.Driver.IsReal && physicalAddress != descriptorStateHelper.PhysicalAddress) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_физический_адрес_устройства; } var nearestDescriptorNo = 0; if (device.KauDatabaseParent != null) nearestDescriptorNo = device.KAUDescriptorNo; else if (device.GkDatabaseParent != null) nearestDescriptorNo = device.GKDescriptorNo; if (nearestDescriptorNo != descriptorStateHelper.AddressOnController) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_адрес_на_контроллере; } } if (gkBase is GKZone) { if (descriptorStateHelper.TypeNo != 0x100) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_зоны; } } if (gkBase is GKDirection) { if (descriptorStateHelper.TypeNo != 0x106) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_направления; } } if (gkBase is GKPumpStation) { if (descriptorStateHelper.TypeNo != 0x106) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_НС; } } if (gkBase is GKMPT) { if (descriptorStateHelper.TypeNo != 0x106) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_МПТ; } } if (gkBase is GKDelay) { if (descriptorStateHelper.TypeNo != 0x101) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_Задержки; } } if (gkBase is GKPim) { if (descriptorStateHelper.TypeNo != 0x107) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_ПИМ; } } if (gkBase is GKGuardZone) { if (descriptorStateHelper.TypeNo != 0x108) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_охранной_зоны; } } if (gkBase is GKCode) { if (descriptorStateHelper.TypeNo != 0x109) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_кода; } } if (gkBase is GKDoor) { if (descriptorStateHelper.TypeNo != 0x104) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_тип_для_кода; } } var description = gkBase.GetGKDescriptorName(GKManager.DeviceConfiguration.GKNameGenerationType); if (description != descriptorStateHelper.Description) { isMissmatch = true; DBMissmatchDuringMonitoringReason = JournalEventDescriptionType.Не_совпадает_описание_компонента; } gkBase.InternalState.IsDBMissmatchDuringMonitoring = isMissmatch; if (isMissmatch) { IsDBMissmatchDuringMonitoring = true; } }
bool GetDelays(XBase xBase) { SendResult sendResult = null; var expectedBytesCount = 68; if (xBase.KauDatabaseParent != null) { sendResult = SendManager.Send(xBase.KauDatabaseParent, 2, 12, 32, BytesHelper.ShortToBytes(xBase.KAUDescriptorNo)); expectedBytesCount = 32; } else { sendResult = SendManager.Send(xBase.GkDatabaseParent, 2, 12, 68, BytesHelper.ShortToBytes(xBase.GKDescriptorNo)); expectedBytesCount = 68; } if (sendResult.HasError || sendResult.Bytes.Count != expectedBytesCount) { ConnectionChanged(false); return false; } ConnectionChanged(true); var descriptorStateHelper = new DescriptorStateHelper(); descriptorStateHelper.Parse(sendResult.Bytes, xBase); xBase.BaseState.LastDateTime = DateTime.Now; xBase.BaseState.OnDelay = descriptorStateHelper.OnDelay; xBase.BaseState.HoldDelay = descriptorStateHelper.HoldDelay; xBase.BaseState.OffDelay = descriptorStateHelper.OffDelay; return true; }
bool GetDelays(GKBase gkBase) { gkBase.InternalState.LastDateTime = DateTime.Now; SendResult sendResult = null; if (gkBase.KauDatabaseParent != null) { sendResult = SendManager.Send(gkBase.KauDatabaseParent, 2, 12, 32, BytesHelper.ShortToBytes(gkBase.KAUDescriptorNo)); if (sendResult.HasError || sendResult.Bytes.Count != 32) { gkBase.InternalState.ZeroHoldDelayCount = 10; return false; } } else { sendResult = SendManager.Send(gkBase.GkDatabaseParent, 2, 12, 68, BytesHelper.ShortToBytes(gkBase.GKDescriptorNo)); if (sendResult.HasError || sendResult.Bytes.Count != 68) { gkBase.InternalState.ZeroHoldDelayCount = 10; ConnectionChanged(false); return false; } } ConnectionChanged(true); var descriptorStateHelper = new DescriptorStateHelper(); descriptorStateHelper.Parse(sendResult.Bytes, gkBase); gkBase.InternalState.OnDelay = descriptorStateHelper.OnDelay; gkBase.InternalState.HoldDelay = descriptorStateHelper.HoldDelay; gkBase.InternalState.OffDelay = descriptorStateHelper.OffDelay; gkBase.InternalState.RunningTime = descriptorStateHelper.RunningTime; return true; }