From 2b5b8034025e1b56986ad18a4e87a87e78ac4347 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Thu, 24 Apr 2025 22:35:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E5=B9=B2=E6=89=B0=E4=BD=93=E7=B3=BB?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BA=86=E9=87=8D=E6=9E=84=EF=BC=8C=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E4=BA=86=E5=A4=84=E7=90=86=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LaserSemiActiveGuidanceSystemCodeTests.cs | 14 +- .../src/Indicator/LaserBeamRiderTests.cs | 6 +- .../src/Indicator/LaserDesignatorCodeTests.cs | 12 +- .../src/Indicator/LaserDesignatorTests.cs | 25 +- .../Jamming/InfraredDetectorJammingTests.cs | 114 +++--- .../InfraredImagingGuidanceJammingTests.cs | 106 +++-- .../Jamming/InfraredTrackerJammingTests.cs | 142 ++++--- .../LaserBeamRiderGuidanceJammingTests.cs | 110 ++++-- .../src/Jamming/LaserBeamRiderJammingTests.cs | 97 +++-- .../Jamming/LaserDesignatorJammingTests.cs | 176 +++++---- .../Jamming/LaserRangefinderJammingTests.cs | 110 +++--- .../LaserSemiActiveGuidanceJammingTests.cs | 114 ++++-- .../MillimeterWaveAltimeterJammingTests.cs | 128 +++--- .../MillimeterWaveGuidanceJammingTests.cs | 110 ++++-- .../MillimeterWaveRadiometerJammingTests.cs | 130 ++++--- ...erminalSensitiveSubmunitionJammingTests.cs | 19 +- .../LaserSemiActiveGuidedMissileCodeTests.cs | 6 +- .../src/Guidance/BaseGuidanceSystem.cs | 86 ++++- ThreatSource/src/Guidance/InfraredImage.cs | 41 +- .../Guidance/InfraredImagingGuidanceSystem.cs | 74 +--- .../Guidance/LaserBeamRiderGuidanceSystem.cs | 64 ++- .../Guidance/LaserSemiActiveGuidanceSystem.cs | 302 ++++++--------- .../Guidance/MillimeterWaveGuidanceSystem.cs | 263 ++++++------- ThreatSource/src/Indicator/BaseIndicator.cs | 113 +++++- ThreatSource/src/Indicator/InfraredTracker.cs | 148 ++++--- ThreatSource/src/Indicator/LaserBeamRider.cs | 187 +++------ ThreatSource/src/Indicator/LaserDesignator.cs | 184 ++++----- .../src/Jammable/JammableComponent.cs | 364 ++++++------------ ThreatSource/src/Jammable/JammingHandler.cs | 36 +- ThreatSource/src/Jammer/BaseJammer.cs | 53 ++- ThreatSource/src/Jammer/InfraredJammer.cs | 60 +++ ThreatSource/src/Jammer/JammingParameters.cs | 9 +- ThreatSource/src/Jammer/LaserDecoy.cs | 160 +------- ThreatSource/src/Jammer/LaserJammer.cs | 59 +++ .../src/Jammer/MillimeterWaveJammer.cs | 61 +++ ThreatSource/src/Jammer/SmokeGrenade.cs | 55 +-- .../src/MIssile/LaserBeamRiderMissile.cs | 2 +- ThreatSource/src/Sensor/InfraredDetector.cs | 135 +++---- ThreatSource/src/Sensor/LaserRangefinder.cs | 80 ++-- .../src/Sensor/MillimeterWaveAltimeter.cs | 102 +++-- .../src/Sensor/MillimeterWaveRadiometer.cs | 82 ++-- ThreatSource/src/Sensor/Sensor.cs | 69 +++- .../src/Simulation/SimulationConfig.cs | 150 +++++--- .../src/Simulation/SimulationEvents.cs | 289 +++----------- docs/project/theory.md | 9 + tools/ComprehensiveMissileSimulator.cs | 38 +- tools/Program.cs | 8 +- 47 files changed, 2347 insertions(+), 2355 deletions(-) create mode 100644 ThreatSource/src/Jammer/InfraredJammer.cs create mode 100644 ThreatSource/src/Jammer/LaserJammer.cs create mode 100644 ThreatSource/src/Jammer/MillimeterWaveJammer.cs diff --git a/ThreatSource.Tests/src/Guidance/LaserSemiActiveGuidanceSystemCodeTests.cs b/ThreatSource.Tests/src/Guidance/LaserSemiActiveGuidanceSystemCodeTests.cs index e5b1571..b8fb6b5 100644 --- a/ThreatSource.Tests/src/Guidance/LaserSemiActiveGuidanceSystemCodeTests.cs +++ b/ThreatSource.Tests/src/Guidance/LaserSemiActiveGuidanceSystemCodeTests.cs @@ -75,12 +75,14 @@ namespace ThreatSource.Tests.Guidance public void ProcessLaserIlluminationEvent_WithMismatchingCode_PublishesMismatchEvent() { // Arrange + _guidanceSystem.Activate(); // Ensure the system is subscribed to events _guidanceSystem.SetExpectedLaserCode(LaserCodeType.PRF, 1234); var illuminationEvent = new LaserIlluminationUpdateEvent { LaserDesignatorId = "laser1", TargetId = "target1", + SpotPosition = new Vector3D(0, 0, 0), LaserCodeConfig = new LaserCodeConfig { IsCodeEnabled = true, @@ -93,7 +95,8 @@ namespace ThreatSource.Tests.Guidance }; // Act - _guidanceSystem.ProcessLaserIlluminationUpdateEvent(illuminationEvent); + // _guidanceSystem.ProcessLaserIlluminationUpdateEvent(illuminationEvent); // Don't call directly + _simulationManager.PublishEvent(illuminationEvent); // Publish event instead // Assert var mismatchEvents = _testAdapter.GetPublishedEvents(); @@ -114,12 +117,14 @@ namespace ThreatSource.Tests.Guidance public void ProcessLaserIlluminationEvent_WithDifferentCodeType_PublishesMismatchEvent() { // Arrange + _guidanceSystem.Activate(); // Ensure the system is subscribed to events _guidanceSystem.SetExpectedLaserCode(LaserCodeType.PRF, 1234); var illuminationEvent = new LaserIlluminationUpdateEvent { LaserDesignatorId = "laser1", TargetId = "target1", + SpotPosition = new Vector3D(0, 0, 0), LaserCodeConfig = new LaserCodeConfig { IsCodeEnabled = true, @@ -132,7 +137,8 @@ namespace ThreatSource.Tests.Guidance }; // Act - _guidanceSystem.ProcessLaserIlluminationUpdateEvent(illuminationEvent); + // _guidanceSystem.ProcessLaserIlluminationUpdateEvent(illuminationEvent); // Don't call directly + _simulationManager.PublishEvent(illuminationEvent); // Publish event instead // Assert var mismatchEvents = _testAdapter.GetPublishedEvents(); @@ -153,6 +159,7 @@ namespace ThreatSource.Tests.Guidance public void ProcessLaserIlluminationEvent_WithCodeDisabled_IgnoresCode() { // Arrange + _guidanceSystem.Activate(); // Ensure the system is subscribed to events _guidanceSystem.SetExpectedLaserCode(LaserCodeType.PRF, 1234); var illuminationEvent = new LaserIlluminationUpdateEvent @@ -171,7 +178,8 @@ namespace ThreatSource.Tests.Guidance }; // Act - _guidanceSystem.ProcessLaserIlluminationUpdateEvent(illuminationEvent); + // _guidanceSystem.ProcessLaserIlluminationUpdateEvent(illuminationEvent); // Don't call directly + _simulationManager.PublishEvent(illuminationEvent); // Publish event instead // Assert - No mismatch events should be published var mismatchEvents = _testAdapter.GetPublishedEvents(); diff --git a/ThreatSource.Tests/src/Indicator/LaserBeamRiderTests.cs b/ThreatSource.Tests/src/Indicator/LaserBeamRiderTests.cs index 885289d..9412986 100644 --- a/ThreatSource.Tests/src/Indicator/LaserBeamRiderTests.cs +++ b/ThreatSource.Tests/src/Indicator/LaserBeamRiderTests.cs @@ -69,9 +69,9 @@ namespace ThreatSource.Tests.Indicator Assert.Equal("beamRider1", _laserBeamRider.Id); Assert.Equal("missile1", _laserBeamRider.MissileId); Assert.Equal("target1", _laserBeamRider.TargetId); - Assert.Equal(1000, _laserBeamRider.LaserPower); - Assert.Equal(5.0, _laserBeamRider.ControlFieldDiameter); - Assert.Equal(5000, _laserBeamRider.MaxGuidanceDistance); + Assert.Equal(1000, _laserBeamRider.config.LaserPower); + Assert.Equal(5.0, _laserBeamRider.config.ControlFieldDiameter); + Assert.Equal(5000, _laserBeamRider.config.MaxGuidanceDistance); Assert.False(_laserBeamRider.IsActive); Assert.False(_laserBeamRider.IsBeamOn); } diff --git a/ThreatSource.Tests/src/Indicator/LaserDesignatorCodeTests.cs b/ThreatSource.Tests/src/Indicator/LaserDesignatorCodeTests.cs index 8eaa347..3626bfb 100644 --- a/ThreatSource.Tests/src/Indicator/LaserDesignatorCodeTests.cs +++ b/ThreatSource.Tests/src/Indicator/LaserDesignatorCodeTests.cs @@ -70,7 +70,7 @@ namespace ThreatSource.Tests.Indicator _laserDesignator.Activate(); // Act - _laserDesignator.LaserCodeConfig = new LaserCodeConfig + _laserDesignator.config.LaserCodeConfig = new LaserCodeConfig { IsCodeEnabled = true, Code = new LaserCode @@ -97,7 +97,7 @@ namespace ThreatSource.Tests.Indicator { // Arrange _laserDesignator.Activate(); - _laserDesignator.LaserCodeConfig = new LaserCodeConfig + _laserDesignator.config.LaserCodeConfig = new LaserCodeConfig { IsCodeEnabled = true, Code = new LaserCode @@ -129,7 +129,7 @@ namespace ThreatSource.Tests.Indicator { // Arrange _laserDesignator.Activate(); - _laserDesignator.LaserCodeConfig = new LaserCodeConfig + _laserDesignator.config.LaserCodeConfig = new LaserCodeConfig { IsCodeEnabled = true, Code = new LaserCode @@ -140,7 +140,7 @@ namespace ThreatSource.Tests.Indicator }; // Act - Disable code - _laserDesignator.LaserCodeConfig.IsCodeEnabled = false; + _laserDesignator.config.LaserCodeConfig.IsCodeEnabled = false; _laserDesignator.Update(0.1); // Assert - Code should be disabled @@ -151,7 +151,7 @@ namespace ThreatSource.Tests.Indicator Assert.False(lastEventAfterDisable.LaserCodeConfig.IsCodeEnabled); // Act - Enable code again - _laserDesignator.LaserCodeConfig.IsCodeEnabled = true; + _laserDesignator.config.LaserCodeConfig.IsCodeEnabled = true; _laserDesignator.Update(0.1); // Assert - Code should be enabled @@ -166,7 +166,7 @@ namespace ThreatSource.Tests.Indicator public void LaserIlluminationEvents_IncludeCodeInformation() { // Arrange - _laserDesignator.LaserCodeConfig = new LaserCodeConfig + _laserDesignator.config.LaserCodeConfig = new LaserCodeConfig { IsCodeEnabled = true, Code = new LaserCode diff --git a/ThreatSource.Tests/src/Indicator/LaserDesignatorTests.cs b/ThreatSource.Tests/src/Indicator/LaserDesignatorTests.cs index cb021d7..4b088a5 100644 --- a/ThreatSource.Tests/src/Indicator/LaserDesignatorTests.cs +++ b/ThreatSource.Tests/src/Indicator/LaserDesignatorTests.cs @@ -71,8 +71,8 @@ namespace ThreatSource.Tests.Indicator Assert.Equal("laser1", _laserDesignator.Id); Assert.Equal("target1", _laserDesignator.TargetId); Assert.Equal("missile1", _laserDesignator.MissileId); - Assert.Equal(1000, _laserDesignator.LaserPower); - Assert.Equal(0.001, _laserDesignator.LaserDivergenceAngle); + Assert.Equal(1000, _laserDesignator.config.LaserPower); + Assert.Equal(0.001, _laserDesignator.config.LaserDivergenceAngle); Assert.False(_laserDesignator.IsActive); Assert.False(_laserDesignator.IsIlluminationOn); Assert.False(_laserDesignator.IsJammed); @@ -110,15 +110,20 @@ namespace ThreatSource.Tests.Indicator _laserDesignator.Activate(); // Act - _simulationManager.PublishEvent(new LaserJammingEvent + _simulationManager.PublishEvent(new JammingEvent { - JammingPower = jammingPower, - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - SenderId = "jammer1" + Parameters = new JammingParameters + { + JammerId = "jammer1", + Power = jammingPower, + Wavelength = 1.06, + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Laser, + Duration = null + } }); _laserDesignator.Update(0.1); diff --git a/ThreatSource.Tests/src/Jamming/InfraredDetectorJammingTests.cs b/ThreatSource.Tests/src/Jamming/InfraredDetectorJammingTests.cs index 543da0c..61f2b16 100644 --- a/ThreatSource.Tests/src/Jamming/InfraredDetectorJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/InfraredDetectorJammingTests.cs @@ -71,15 +71,19 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 4, - JammingSourcePosition = new Vector3D(10, 10, 0), // 更靠近探测器,且角度更小 - JammingDirection = new Vector3D(0, 1, 0), // 45度角指向探测器 - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 4, + SourcePosition = new Vector3D(10, 10, 0), // 更靠近探测器,且角度更小 + Direction = new Vector3D(0, 1, 0), // 45度角指向探测器 + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Infrared + } }; // Act @@ -95,14 +99,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建角度范围外的干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 4, - JammingSourcePosition = new Vector3D(0, 150, 0), // 位于上方 - JammingDirection = new Vector3D(0, 0, 1), // 指向前方,不是指向探测器 - JammingAngleRange = 0.1, // 很小的角度范围 - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 4, + SourcePosition = new Vector3D(0, 150, 0), // 位于上方 + Direction = new Vector3D(0, 0, 1), // 指向前方,不是指向探测器 + AngleRange = 0.1, // 很小的角度范围 + Mode = JammingMode.Noise, + Type = JammingType.Infrared + } }; // Act @@ -118,14 +126,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建低功率干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10.0, // 低于阈值 - Wavelength = 4, - JammingSourcePosition = new Vector3D(50, 100, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10.0, // 低于阈值 + Wavelength = 4, + SourcePosition = new Vector3D(50, 100, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Infrared + } }; // Act @@ -141,15 +153,19 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建有限时间的干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 4, - JammingSourcePosition = new Vector3D(10, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 4, + SourcePosition = new Vector3D(10, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5, + Type = JammingType.Infrared + } }; // Act - 应用干扰 @@ -174,15 +190,19 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建持续干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 4, - JammingSourcePosition = new Vector3D(10, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 4, + SourcePosition = new Vector3D(10, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Infrared + } }; // Act - 应用干扰 @@ -226,14 +246,18 @@ namespace ThreatSource.Tests.Jamming var initialData = (InfraredSensorData)_infraredDetector.GetSensorData(); // 创建干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 4, - JammingSourcePosition = new Vector3D(50, 100, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 4, + SourcePosition = new Vector3D(50, 100, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Infrared + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/InfraredImagingGuidanceJammingTests.cs b/ThreatSource.Tests/src/Jamming/InfraredImagingGuidanceJammingTests.cs index 99a3e80..2c37cc4 100644 --- a/ThreatSource.Tests/src/Jamming/InfraredImagingGuidanceJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/InfraredImagingGuidanceJammingTests.cs @@ -99,17 +99,21 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 修改为2000瓦特,与激光指示器一致 - JammingSourcePosition = new Vector3D(50, 0, 0), // 修改为50米,与激光指示器一致 - JammingDirection = new Vector3D(1, 0, 0), // 修改为(1,0,0),指向设备的方向 - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, // 修改为2000瓦特,与激光指示器一致 + SourcePosition = new Vector3D(50, 0, 0), // 修改为50米,与激光指示器一致 + Direction = new Vector3D(1, 0, 0), // 修改为(1,0,0),指向设备的方向 + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Infrared + } }; - System.Diagnostics.Debug.WriteLine($"创建干扰事件 - 功率: {jammingEvent.JammingPower}W, 位置: {jammingEvent.JammingSourcePosition}, 方向: {jammingEvent.JammingDirection}, 角度范围: {jammingEvent.JammingAngleRange * 180 / Math.PI}度"); + System.Diagnostics.Debug.WriteLine($"创建干扰事件 - 功率: {jammingEvent.Parameters.Power}W, 位置: {jammingEvent.Parameters.SourcePosition}, 方向: {jammingEvent.Parameters.Direction}, 角度范围: {jammingEvent.Parameters.AngleRange * 180 / Math.PI}度"); // Act _simulationManager.PublishEvent(jammingEvent); @@ -136,13 +140,17 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建角度范围外的干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, // 保持不变 - JammingSourcePosition = new Vector3D(0, 50, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = 0.1, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, // 保持不变 + SourcePosition = new Vector3D(0, 50, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = 0.1, + Mode = JammingMode.Noise, + Type = JammingType.Infrared + } }; // Act @@ -168,13 +176,17 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建低功率干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10, // 保持不变 - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10, // 保持不变 + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Infrared + } }; // Act @@ -200,14 +212,18 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建有限时间的干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 修改为2000瓦特,与激光指示器一致 - JammingSourcePosition = new Vector3D(50, 0, 0), // 修改为50米,与激光指示器一致 - JammingDirection = new Vector3D(1, 0, 0), // 修改为(1,0,0),指向设备的方向 - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 + Parameters = new JammingParameters + { + Power = 2000, // 修改为2000瓦特,与激光指示器一致 + SourcePosition = new Vector3D(50, 0, 0), // 修改为50米,与激光指示器一致 + Direction = new Vector3D(1, 0, 0), // 修改为(1,0,0),指向设备的方向 + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5, + Type = JammingType.Infrared + } }; // Act - 应用干扰 @@ -243,14 +259,18 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建持续干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 修改为2000瓦特,与激光指示器一致 - JammingSourcePosition = new Vector3D(50, 0, 0), // 修改为50米,与激光指示器一致 - JammingDirection = new Vector3D(1, 0, 0), // 修改为(1,0,0),指向设备的方向 - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, // 修改为2000瓦特,与激光指示器一致 + SourcePosition = new Vector3D(50, 0, 0), // 修改为50米,与激光指示器一致 + Direction = new Vector3D(1, 0, 0), // 修改为(1,0,0),指向设备的方向 + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Infrared + } }; // Act - 应用干扰 @@ -283,14 +303,18 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 修改为2000瓦特,与激光指示器一致 - JammingSourcePosition = new Vector3D(50, 0, 0), // 修改为50米,与激光指示器一致 - JammingDirection = new Vector3D(1, 0, 0), // 修改为(1,0,0),指向设备的方向 - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, // 修改为2000瓦特,与激光指示器一致 + SourcePosition = new Vector3D(50, 0, 0), // 修改为50米,与激光指示器一致 + Direction = new Vector3D(1, 0, 0), // 修改为(1,0,0),指向设备的方向 + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Infrared + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/InfraredTrackerJammingTests.cs b/ThreatSource.Tests/src/Jamming/InfraredTrackerJammingTests.cs index f44c6ad..1abcc64 100644 --- a/ThreatSource.Tests/src/Jamming/InfraredTrackerJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/InfraredTrackerJammingTests.cs @@ -61,15 +61,18 @@ namespace ThreatSource.Tests.Jamming _infraredTracker.Activate(); // 创建干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 1000, // 高于阈值 - Wavelength = 4, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), // 指向跟踪器 - JammingAngleRange = Math.PI / 4, // 45度角 - JammingMode = JammingMode.Noise, - Duration = null // 持续干扰 + Parameters = new JammingParameters + { + Power = 1000, // 高于阈值 + Wavelength = 4, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), // 指向跟踪器 + AngleRange = Math.PI / 4, // 45度角 + Mode = JammingMode.Noise, + Duration = null // 持续干扰 + } }; // Act @@ -89,14 +92,17 @@ namespace ThreatSource.Tests.Jamming _infraredTracker.Activate(); // 创建角度范围外的干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 1000, - Wavelength = 4, - JammingSourcePosition = new Vector3D(0, 50, 0), // 位于上方 - JammingDirection = new Vector3D(0, 0, 1), // 指向前方,不是指向跟踪器 - JammingAngleRange = 0.1, // 很小的角度范围 - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 1000, + Wavelength = 4, + SourcePosition = new Vector3D(0, 50, 0), // 位于上方 + Direction = new Vector3D(0, 0, 1), // 指向前方,不是指向跟踪器 + AngleRange = 0.1, // 很小的角度范围 + Mode = JammingMode.Noise + } }; // Act @@ -116,14 +122,17 @@ namespace ThreatSource.Tests.Jamming _infraredTracker.Activate(); // 创建低功率干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10, // 低于阈值 - Wavelength = 4, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10, // 低于阈值 + Wavelength = 4, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise + } }; // Act @@ -141,14 +150,17 @@ namespace ThreatSource.Tests.Jamming _infraredTracker.Activate(); // 创建错误波长的干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 1000, - Wavelength = 6, // 不在3-5μm或8-14μm范围 - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 1000, + Wavelength = 6, // 不在3-5μm或8-14μm范围 + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise + } }; // Act @@ -166,14 +178,17 @@ namespace ThreatSource.Tests.Jamming _infraredTracker.Activate(); // 创建干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 1000, - Wavelength = 4, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 1000, + Wavelength = 4, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise + } }; // Act @@ -191,15 +206,18 @@ namespace ThreatSource.Tests.Jamming _infraredTracker.Activate(); // 创建有限时间的干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 1000, - Wavelength = 4, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 // 0.5秒后过期 + Parameters = new JammingParameters + { + Power = 1000, + Wavelength = 4, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5 // 0.5秒后过期 + } }; // Act - 应用干扰 @@ -229,15 +247,18 @@ namespace ThreatSource.Tests.Jamming _infraredTracker.Activate(); // 创建持续干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 1000, - Wavelength = 4, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null // 持续干扰 + Parameters = new JammingParameters + { + Power = 1000, + Wavelength = 4, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null // 持续干扰 + } }; // Act - 应用干扰 @@ -265,14 +286,17 @@ namespace ThreatSource.Tests.Jamming _infraredTracker.Activate(); // 创建干扰事件 - var jammingEvent = new InfraredJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 1000, - Wavelength = 4, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 1000, + Wavelength = 4, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise + } }; // 捕获发布的事件 diff --git a/ThreatSource.Tests/src/Jamming/LaserBeamRiderGuidanceJammingTests.cs b/ThreatSource.Tests/src/Jamming/LaserBeamRiderGuidanceJammingTests.cs index 8d65f74..5a340cd 100644 --- a/ThreatSource.Tests/src/Jamming/LaserBeamRiderGuidanceJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/LaserBeamRiderGuidanceJammingTests.cs @@ -117,17 +117,22 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 2000瓦特 - JammingSourcePosition = new Vector3D(50, 0, 0), // 50米 - JammingDirection = new Vector3D(1, 0, 0), // 指向设备的方向 - JammingAngleRange = Math.PI / 4, // 45度 - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, // 2000瓦特 + SourcePosition = new Vector3D(50, 0, 0), // 50米 + Direction = new Vector3D(1, 0, 0), // 指向设备的方向 + AngleRange = Math.PI / 4, // 45度 + Mode = JammingMode.Noise, + Duration = null, + Wavelength = 1.06, + Type = JammingType.Laser + } }; - System.Diagnostics.Debug.WriteLine($"创建干扰事件 - 功率: {jammingEvent.JammingPower}W, 位置: {jammingEvent.JammingSourcePosition}, 方向: {jammingEvent.JammingDirection}, 角度范围: {jammingEvent.JammingAngleRange * 180 / Math.PI}度"); + System.Diagnostics.Debug.WriteLine($"创建干扰事件 - 功率: {jammingEvent.Parameters.Power}W, 位置: {jammingEvent.Parameters.SourcePosition}, 方向: {jammingEvent.Parameters.Direction}, 角度范围: {jammingEvent.Parameters.AngleRange * 180 / Math.PI}度"); // Act _simulationManager.PublishEvent(jammingEvent); @@ -161,13 +166,17 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建角度范围外的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, // 500瓦特 - JammingSourcePosition = new Vector3D(0, 50, 0), // 从Y轴方向 - JammingDirection = new Vector3D(1, 0, 0), // 指向X轴方向 - JammingAngleRange = 0.1, // 约5.7度 - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, // 500瓦特 + SourcePosition = new Vector3D(0, 50, 0), // 从Y轴方向 + Direction = new Vector3D(1, 0, 0), // 指向X轴方向 + AngleRange = 0.1, // 约5.7度 + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act @@ -200,13 +209,17 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建低功率干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10, // 10瓦特 - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, // 45度 - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10, // 10瓦特 + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, // 45度 + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act @@ -239,14 +252,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建有限时间的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 2000瓦特 - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, // 45度 - JammingMode = JammingMode.Noise, - Duration = 0.5 // 0.5秒 + Parameters = new JammingParameters + { + Power = 2000, // 2000瓦特 + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, // 45度 + Mode = JammingMode.Noise, + Duration = 0.5, // 0.5秒 + Wavelength = 1.06, + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -289,14 +307,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建持续干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 2000瓦特 - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, // 45度 - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, // 2000瓦特 + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, // 45度 + Mode = JammingMode.Noise, + Duration = null, + Wavelength = 1.06, + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -336,14 +359,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 2000瓦特 - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, // 45度 - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, // 2000瓦特 + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, // 45度 + Mode = JammingMode.Noise, + Duration = null, + Wavelength = 1.06, + Type = JammingType.Laser + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/LaserBeamRiderJammingTests.cs b/ThreatSource.Tests/src/Jamming/LaserBeamRiderJammingTests.cs index 00b7c74..18d711e 100644 --- a/ThreatSource.Tests/src/Jamming/LaserBeamRiderJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/LaserBeamRiderJammingTests.cs @@ -79,15 +79,18 @@ namespace ThreatSource.Tests.Jamming _laserBeamRider.Activate(); // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 高功率干扰 - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), // 指向激光驾束仪 - JammingAngleRange = Math.PI / 4, // 45度角 - JammingMode = JammingMode.Noise, - Duration = null // 持续干扰 + Parameters = new JammingParameters + { + Power = 2000, // 高功率干扰 + Wavelength = 1.06, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), // 指向激光驾束仪 + AngleRange = Math.PI / 4, // 45度角 + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act @@ -111,14 +114,19 @@ namespace ThreatSource.Tests.Jamming Assert.IsTrue(beamOnBeforeJamming, "激光束应该在干扰前处于开启状态"); // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 高功率干扰 - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 2000, // 高功率干扰 + Wavelength = 1.06, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; // 捕获发布的事件 @@ -154,15 +162,19 @@ namespace ThreatSource.Tests.Jamming _laserBeamRider.Activate(); // 创建有限时间的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 高功率干扰 - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 // 0.5秒后过期 + Parameters = new JammingParameters + { + Power = 2000, // 高功率干扰 + Wavelength = 1.06, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5, // 0.5秒后过期 + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -192,15 +204,19 @@ namespace ThreatSource.Tests.Jamming _laserBeamRider.Activate(); // 创建持续干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 高功率干扰 - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null // 持续干扰 + Parameters = new JammingParameters + { + Power = 2000, // 高功率干扰 + Wavelength = 1.06, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, // 持续干扰 + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -227,14 +243,19 @@ namespace ThreatSource.Tests.Jamming Assert.IsTrue(_laserBeamRider.IsActive, "激光驾束仪应该处于激活状态"); // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, // 高功率干扰 - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 2000, // 高功率干扰 + Wavelength = 1.06, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Duration = null, + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/LaserDesignatorJammingTests.cs b/ThreatSource.Tests/src/Jamming/LaserDesignatorJammingTests.cs index 5914ac9..e4969c9 100644 --- a/ThreatSource.Tests/src/Jamming/LaserDesignatorJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/LaserDesignatorJammingTests.cs @@ -78,15 +78,19 @@ namespace ThreatSource.Tests.Jamming _laserDesignator.Activate(); // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - Wavelength = 1.06, // 匹配波长1.06μm - JammingSourcePosition = new Vector3D(5, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + Wavelength = 1.06, // 匹配波长1.06μm + SourcePosition = new Vector3D(5, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; // Act @@ -106,14 +110,19 @@ namespace ThreatSource.Tests.Jamming _laserDesignator.Activate(); // 创建角度范围外的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, // 角度范围外的干扰 - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(0, 50, 0), // 位于上方 - JammingDirection = new Vector3D(0, 0, 1), // 指向前方,不是指向指示器 - JammingAngleRange = 0.1, // 很小的角度范围 - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, // 角度范围外的干扰 + Wavelength = 1.06, + SourcePosition = new Vector3D(0, 50, 0), // 位于上方 + Direction = new Vector3D(0, 0, 1), // 指向前方,不是指向指示器 + AngleRange = 0.1, // 很小的角度范围 + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; // Act @@ -133,14 +142,19 @@ namespace ThreatSource.Tests.Jamming _laserDesignator.Activate(); // 创建低功率干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10, // 低功率干扰 - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10, // 低功率干扰 + Wavelength = 1.06, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; // Act @@ -158,14 +172,19 @@ namespace ThreatSource.Tests.Jamming _laserDesignator.Activate(); // 创建错误波长的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, // 波长不匹配的干扰 - Wavelength = 2.5, // 不在1.0-1.1μm范围 - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, // 波长不匹配的干扰 + Wavelength = 2.5, // 不在1.0-1.1μm范围 + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; // Act @@ -183,15 +202,19 @@ namespace ThreatSource.Tests.Jamming _laserDesignator.Activate(); // 创建有限时间的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 1.06, // 匹配波长1.06μm - JammingSourcePosition = new Vector3D(5, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 1.06, // 匹配波长1.06μm + SourcePosition = new Vector3D(5, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5, + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -219,15 +242,19 @@ namespace ThreatSource.Tests.Jamming _laserDesignator.Activate(); // 创建持续干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 1.06, // 匹配波长1.06μm - JammingSourcePosition = new Vector3D(5, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 1.06, // 匹配波长1.06μm + SourcePosition = new Vector3D(5, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -255,14 +282,19 @@ namespace ThreatSource.Tests.Jamming bool illuminationBeforeJamming = _laserDesignator.IsIlluminationOn; // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 1.06, // 匹配波长1.06μm - JammingSourcePosition = new Vector3D(5, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 1.06, // 匹配波长1.06μm + SourcePosition = new Vector3D(5, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; // 捕获发布的事件 @@ -286,15 +318,19 @@ namespace ThreatSource.Tests.Jamming _laserDesignator.Activate(); // 测试1:波长匹配的情况 - var matchingJammingEvent = new LaserJammingEvent + var matchingJammingEvent = new JammingEvent { - JammingPower = 2000, - Wavelength = 1.06, // 匹配波长1.06μm - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + Wavelength = 1.06, // 匹配波长1.06μm + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; _simulationManager.PublishEvent(matchingJammingEvent); @@ -307,15 +343,19 @@ namespace ThreatSource.Tests.Jamming _laserDesignator.Update(0.1); // 测试2:波长不匹配的情况 - var nonMatchingJammingEvent = new LaserJammingEvent + var nonMatchingJammingEvent = new JammingEvent { - JammingPower = 2000, - Wavelength = 1.56, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + Wavelength = 1.56, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser + } }; _simulationManager.PublishEvent(nonMatchingJammingEvent); diff --git a/ThreatSource.Tests/src/Jamming/LaserRangefinderJammingTests.cs b/ThreatSource.Tests/src/Jamming/LaserRangefinderJammingTests.cs index 55d7046..7bf982b 100644 --- a/ThreatSource.Tests/src/Jamming/LaserRangefinderJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/LaserRangefinderJammingTests.cs @@ -71,14 +71,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 1.06, + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act @@ -94,14 +98,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建角度范围外的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(0, 150, 0), // 位于上方 - JammingDirection = new Vector3D(0, 0, 1), // 指向前方,不是指向测距仪 - JammingAngleRange = 0.1, // 很小的角度范围 - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 1.06, + SourcePosition = new Vector3D(0, 150, 0), // 位于上方 + Direction = new Vector3D(0, 0, 1), // 指向前方,不是指向测距仪 + AngleRange = 0.1, // 很小的角度范围 + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act @@ -117,14 +125,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建低功率干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10.0, // 低于阈值 - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10.0, // 低于阈值 + Wavelength = 1.06, + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act @@ -140,15 +152,19 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建有限时间的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 1.06, + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5, + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -173,14 +189,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建持续干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 1.06, + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -208,14 +228,18 @@ namespace ThreatSource.Tests.Jamming double initialDistance = initialData.Distance; // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 1.06, - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 1.06, + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Laser + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/LaserSemiActiveGuidanceJammingTests.cs b/ThreatSource.Tests/src/Jamming/LaserSemiActiveGuidanceJammingTests.cs index ae227d7..95b7817 100644 --- a/ThreatSource.Tests/src/Jamming/LaserSemiActiveGuidanceJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/LaserSemiActiveGuidanceJammingTests.cs @@ -107,17 +107,22 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Wavelength = 1.06, + Type = JammingType.Laser + } }; - System.Diagnostics.Debug.WriteLine($"创建干扰事件 - 功率: {jammingEvent.JammingPower}W, 位置: {jammingEvent.JammingSourcePosition}, 方向: {jammingEvent.JammingDirection}, 角度范围: {jammingEvent.JammingAngleRange * 180 / Math.PI}度"); + System.Diagnostics.Debug.WriteLine($"创建干扰事件 - 功率: {jammingEvent.Parameters.Power}W, 位置: {jammingEvent.Parameters.SourcePosition}, 方向: {jammingEvent.Parameters.Direction}, 角度范围: {jammingEvent.Parameters.AngleRange * 180 / Math.PI}度"); // Act _simulationManager.PublishEvent(jammingEvent); @@ -144,13 +149,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建角度范围外的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - JammingSourcePosition = new Vector3D(0, 50, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = 0.1, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + SourcePosition = new Vector3D(0, 50, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = 0.1, + Mode = JammingMode.Noise, + Type = JammingType.Laser, + Wavelength = 1.06, + Duration = null + } }; // Act @@ -176,13 +187,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建低功率干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.Laser, + Wavelength = 1.06, + Duration = null + } }; // Act @@ -208,14 +225,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建有限时间的干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 + Parameters = new JammingParameters + { + Power = 2000, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5, + Type = JammingType.Laser, + Wavelength = 1.06 + } }; // Act - 应用干扰 @@ -251,14 +273,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建持续干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Wavelength = 1.06, + Type = JammingType.Laser + } }; // Act - 应用干扰 @@ -291,14 +318,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建干扰事件 - var jammingEvent = new LaserJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Type = JammingType.Laser, + Wavelength = 1.06 + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/MillimeterWaveAltimeterJammingTests.cs b/ThreatSource.Tests/src/Jamming/MillimeterWaveAltimeterJammingTests.cs index fe802e8..551019e 100644 --- a/ThreatSource.Tests/src/Jamming/MillimeterWaveAltimeterJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/MillimeterWaveAltimeterJammingTests.cs @@ -71,14 +71,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 3.0, - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 6, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 3.0, + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 6, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act @@ -94,14 +98,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建角度范围外的干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 3.0, - JammingSourcePosition = new Vector3D(0, 150, 0), // 位于上方 - JammingDirection = new Vector3D(0, 0, 1), // 指向前方,不是指向测高雷达 - JammingAngleRange = 0.1, // 很小的角度范围 - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 3.0, + SourcePosition = new Vector3D(0, 150, 0), // 位于上方 + Direction = new Vector3D(0, 0, 1), // 指向前方,不是指向测高雷达 + AngleRange = 0.1, // 很小的角度范围 + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act @@ -117,14 +125,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建低功率干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10.0, // 低于阈值 - Wavelength = 3.0, - JammingSourcePosition = new Vector3D(50, 100, 0), - JammingDirection = new Vector3D(-1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10.0, // 低于阈值 + Wavelength = 3.0, + SourcePosition = new Vector3D(50, 100, 0), + Direction = new Vector3D(-1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act @@ -140,14 +152,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建不同波段的干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 8.0, // 与测高雷达波段不匹配 - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 8.0, // 与测高雷达波段不匹配 + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act @@ -163,15 +179,19 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建有限时间的干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 3.0, // 设置为3mm波段的波长 - JammingSourcePosition = new Vector3D(0, 120, 0), - JammingDirection = new Vector3D(0, -1, 0), - JammingAngleRange = Math.PI / 6, - JammingMode = JammingMode.Noise, - Duration = 0.5 // 0.5秒后过期 + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 3.0, // 设置为3mm波段的波长 + SourcePosition = new Vector3D(0, 120, 0), + Direction = new Vector3D(0, -1, 0), + AngleRange = Math.PI / 6, + Mode = JammingMode.Noise, + Duration = 0.5, // 0.5秒后过期 + Type = JammingType.MillimeterWave + } }; // Act - 应用干扰 @@ -196,14 +216,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建持续干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 3.0, // 设置为3mm波段的波长 - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 6, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 3.0, // 设置为3mm波段的波长 + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 6, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act - 应用干扰 @@ -231,14 +255,18 @@ namespace ThreatSource.Tests.Jamming double initialAltitude = initialData.Altitude; // 创建干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 3.0, - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 6, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 3.0, + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 6, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/MillimeterWaveGuidanceJammingTests.cs b/ThreatSource.Tests/src/Jamming/MillimeterWaveGuidanceJammingTests.cs index e71d8a2..7ee563f 100644 --- a/ThreatSource.Tests/src/Jamming/MillimeterWaveGuidanceJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/MillimeterWaveGuidanceJammingTests.cs @@ -105,17 +105,22 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Wavelength = 3.19, + Type = JammingType.MillimeterWave + } }; - System.Diagnostics.Debug.WriteLine($"创建干扰事件 - 功率: {jammingEvent.JammingPower}W, 位置: {jammingEvent.JammingSourcePosition}, 方向: {jammingEvent.JammingDirection}, 角度范围: {jammingEvent.JammingAngleRange * 180 / Math.PI}度"); + System.Diagnostics.Debug.WriteLine($"创建干扰事件 - 功率: {jammingEvent.Parameters.Power}W, 位置: {jammingEvent.Parameters.SourcePosition}, 方向: {jammingEvent.Parameters.Direction}, 角度范围: {jammingEvent.Parameters.AngleRange * 180 / Math.PI}度"); // Act _simulationManager.PublishEvent(jammingEvent); @@ -142,13 +147,18 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建角度范围外的干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - JammingSourcePosition = new Vector3D(0, 50, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = 0.1, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + SourcePosition = new Vector3D(0, 50, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = 0.1, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave, + Wavelength = 3.19 + } }; // Act @@ -174,13 +184,16 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建低功率干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise + } }; // Act @@ -206,14 +219,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建有限时间的干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 + Parameters = new JammingParameters + { + Power = 2000, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5, + Type = JammingType.MillimeterWave, + Wavelength = 3.19 + } }; // Act - 应用干扰 @@ -249,14 +267,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建持续干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Wavelength = 3.19, + Type = JammingType.MillimeterWave + } }; // Act - 应用干扰 @@ -289,14 +312,19 @@ namespace ThreatSource.Tests.Jamming _guidanceSystem.Update(0.1, initialPosition, initialVelocity); // 创建干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 2000, - JammingSourcePosition = new Vector3D(50, 0, 0), - JammingDirection = new Vector3D(1, 0, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = null + Parameters = new JammingParameters + { + Power = 2000, + SourcePosition = new Vector3D(50, 0, 0), + Direction = new Vector3D(1, 0, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = null, + Wavelength = 3.19, + Type = JammingType.MillimeterWave + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/MillimeterWaveRadiometerJammingTests.cs b/ThreatSource.Tests/src/Jamming/MillimeterWaveRadiometerJammingTests.cs index e14751a..133f2e1 100644 --- a/ThreatSource.Tests/src/Jamming/MillimeterWaveRadiometerJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/MillimeterWaveRadiometerJammingTests.cs @@ -70,15 +70,19 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, // 高于阈值 - Wavelength = 3.0, - JammingSourcePosition = new Vector3D(10, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, // 45度角 - JammingMode = JammingMode.Noise, - Duration = null // 持续干扰 + Parameters = new JammingParameters + { + Power = 500.0, // 高于阈值 + Wavelength = 3.0, + SourcePosition = new Vector3D(10, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, // 45度角 + Mode = JammingMode.Noise, + Duration = null, // 持续干扰 + Type = JammingType.MillimeterWave + } }; // Act @@ -94,14 +98,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建角度范围外的干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 3.0, - JammingSourcePosition = new Vector3D(0, 150, 0), // 位于上方 - JammingDirection = new Vector3D(0, 1, 0), // 指向上方,与辐射计方向完全相反 - JammingAngleRange = 0.01, // 极小的角度范围 - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 3.0, + SourcePosition = new Vector3D(0, 150, 0), // 位于上方 + Direction = new Vector3D(0, 1, 0), // 指向上方,与辐射计方向完全相反 + AngleRange = 0.01, // 极小的角度范围 + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act @@ -117,14 +125,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建低功率干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 10.0, // 低于阈值 - Wavelength = 3.0, - JammingSourcePosition = new Vector3D(10, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 10.0, // 低于阈值 + Wavelength = 3.0, + SourcePosition = new Vector3D(10, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act @@ -140,14 +152,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建不同波段的干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500.0, - Wavelength = 8.0, // 与辐射计波段不匹配 - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 8.0, // 与辐射计波段不匹配 + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act @@ -163,15 +179,19 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建有限时间的干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 3.0, // 3mm波段 - JammingSourcePosition = new Vector3D(10, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise, - Duration = 0.5 + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 3.0, // 3mm波段 + SourcePosition = new Vector3D(10, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Duration = 0.5, + Type = JammingType.MillimeterWave + } }; // Act - 应用干扰 @@ -196,14 +216,18 @@ namespace ThreatSource.Tests.Jamming { // Arrange // 创建持续干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 3.0, // 3mm波段 - JammingSourcePosition = new Vector3D(10, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 3.0, // 3mm波段 + SourcePosition = new Vector3D(10, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act - 应用干扰 @@ -247,14 +271,18 @@ namespace ThreatSource.Tests.Jamming var initialData = (RadiometerSensorData)_radiometer.GetSensorData(); // 创建干扰事件 - var jammingEvent = new MillimeterWaveJammingEvent + var jammingEvent = new JammingEvent { - JammingPower = 500, - Wavelength = 3.0, // 3mm波段 - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI / 4, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500, + Wavelength = 3.0, // 3mm波段 + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI / 4, + Mode = JammingMode.Noise, + Type = JammingType.MillimeterWave + } }; // Act - 应用干扰 diff --git a/ThreatSource.Tests/src/Jamming/TerminalSensitiveSubmunitionJammingTests.cs b/ThreatSource.Tests/src/Jamming/TerminalSensitiveSubmunitionJammingTests.cs index 09eae51..775ffbf 100644 --- a/ThreatSource.Tests/src/Jamming/TerminalSensitiveSubmunitionJammingTests.cs +++ b/ThreatSource.Tests/src/Jamming/TerminalSensitiveSubmunitionJammingTests.cs @@ -390,14 +390,19 @@ namespace ThreatSource.Tests.Jamming altimeter.Activate(); // 激活测高仪 // 创建毫米波干扰参数 - var millimeterWaveJamming = new MillimeterWaveJammingEvent + var millimeterWaveJamming = new JammingEvent { - JammingPower = 500.0, - Wavelength = 8.0, // 设置为3mm波段的波长 - JammingSourcePosition = new Vector3D(0, 10, 0), - JammingDirection = new Vector3D(0, 1, 0), - JammingAngleRange = Math.PI/2, - JammingMode = JammingMode.Noise + Parameters = new JammingParameters + { + Power = 500.0, + Wavelength = 8.0, // 设置为3mm波段的波长 + SourcePosition = new Vector3D(0, 10, 0), + Direction = new Vector3D(0, 1, 0), + AngleRange = Math.PI/2, + Mode = JammingMode.Noise, + Duration = 10, + Type = JammingType.MillimeterWave + } }; // 记录初始高度 diff --git a/ThreatSource.Tests/src/Missile/LaserSemiActiveGuidedMissileCodeTests.cs b/ThreatSource.Tests/src/Missile/LaserSemiActiveGuidedMissileCodeTests.cs index 1c808d1..7d1c6ea 100644 --- a/ThreatSource.Tests/src/Missile/LaserSemiActiveGuidedMissileCodeTests.cs +++ b/ThreatSource.Tests/src/Missile/LaserSemiActiveGuidedMissileCodeTests.cs @@ -48,7 +48,7 @@ namespace ThreatSource.Tests.Missile // 创建并注册模拟的激光指示器,位置在导弹后方100米处 _laserDesignator = new MockLaserDesignator("laser1", _simulationManager); _laserDesignator.Position = new Vector3D(-100, 0, 0); - _laserDesignator.LaserPower = 100; // 设置足够高的激光功率 + _laserDesignator.config.LaserPower = 100; // 设置足够高的激光功率 _testAdapter.AddTestEntity("laser1", _laserDesignator); // 创建并注册模拟的目标,位置在导弹前方1000米处 @@ -236,7 +236,7 @@ namespace ThreatSource.Tests.Missile // 设置激光指示器和目标位置,确保在视场角内 _laserDesignator.Position = new Vector3D(-100, 0, 0); _target.Position = new Vector3D(1000, 0, 0); - _laserDesignator.LaserPower = 100; // 设置足够高的激光功率 + _laserDesignator.config.LaserPower = 100; // 设置足够高的激光功率 // Act - Send illumination with disabled code var illuminationEvent = new LaserIlluminationUpdateEvent @@ -278,7 +278,7 @@ namespace ThreatSource.Tests.Missile // 设置激光指示器和目标位置,确保在视场角内 _laserDesignator.Position = new Vector3D(-100, 0, 0); _target.Position = new Vector3D(1000, 0, 0); - _laserDesignator.LaserPower = 100; // 设置足够高的激光功率 + _laserDesignator.config.LaserPower = 100; // 设置足够高的激光功率 // First enable guidance with matching code var startEvent = new LaserIlluminationUpdateEvent diff --git a/ThreatSource/src/Guidance/BaseGuidanceSystem.cs b/ThreatSource/src/Guidance/BaseGuidanceSystem.cs index 1816f9d..91fd80e 100644 --- a/ThreatSource/src/Guidance/BaseGuidanceSystem.cs +++ b/ThreatSource/src/Guidance/BaseGuidanceSystem.cs @@ -114,14 +114,50 @@ namespace ThreatSource.Guidance // 初始化干扰处理组件 _jammingComponent = new JammableComponent( - positionProvider: () => base.Position, - onJammingApplied: HandleJammingApplied, - onJammingCleared: HandleJammingCleared + positionProvider: () => base.Position ); + // Subscribe to the events instead + _jammingComponent.JammingApplied += HandleJammingApplied; + _jammingComponent.JammingCleared += HandleJammingCleared; + // 子类需要在构造函数中设置支持的干扰类型和阈值 } + /// + /// 激活制导系统 (基类处理干扰事件订阅) + /// + public override void Activate() + { + if (!IsActive) + { + IsActive = true; + // 统一订阅 JammingEvent + SimulationManager.SubscribeToEvent(HandleJammingEvent); + // 子类应在此方法中调用 base.Activate() 并订阅其他需要的事件 + } + // 调用 SimulationElement 的基类 Activate (如果存在) + // base.Activate(); // SimulationElement 似乎没有公开的 Activate + } + + /// + /// 停用制导系统 (基类处理干扰事件取消订阅) + /// + public override void Deactivate() + { + if (IsActive) + { + IsActive = false; + // 统一取消订阅 JammingEvent + SimulationManager.UnsubscribeFromEvent(HandleJammingEvent); + // 子类应在此方法中调用 base.Deactivate() 并取消订阅其他事件 + } + HasGuidance = false; // 停用时失去制导 + GuidanceAcceleration = Vector3D.Zero; + // 调用 SimulationElement 的基类 Deactivate (如果存在) + // base.Deactivate(); // SimulationElement 似乎没有公开的 Deactivate + } + /// /// 更新制导系统的状态和计算结果 /// @@ -193,6 +229,38 @@ namespace ThreatSource.Guidance return base.GetStatus() + $"导引头状态: 有制导={HasGuidance}, 被干扰={IsJammed}, 制导加速度={GuidanceAcceleration}"; } + /// + /// 处理干扰事件 + /// + /// 干扰事件 + protected virtual void HandleJammingEvent(JammingEvent evt) + { + if (evt != null) + { + // 在应用干扰前检查是否应该处理此干扰 + if (!ShouldHandleJamming(evt.Parameters)) + { + // Debug.WriteLine($"[BaseGuidanceSystem] {Id} 忽略干扰事件,类型: {evt.Parameters.Type}"); + return; + } + ApplyJamming(evt.Parameters); + } + } + + /// + /// 判断是否应该处理传入的干扰参数(可被子类重写以添加特定检查) + /// + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected virtual bool ShouldHandleJamming(JammingParameters parameters) + { + // 基类默认处理所有受支持类型的干扰 + // 子类可以重写此方法添加额外检查,如波长/编码匹配 + bool supported = SupportedJammingTypes.Contains(parameters.Type); + // if(!supported) Debug.WriteLine($"[BaseGuidanceSystem] {Id} 不支持干扰类型: {parameters.Type}"); + return supported; + } + /// /// 设置干扰阈值 /// @@ -241,8 +309,8 @@ namespace ThreatSource.Guidance // 默认:非烟幕干扰是硬干扰 if (parameters.Type != JammingType.SmokeScreen) { - this.IsHardJammed = true; - this.HasGuidance = false; // 硬干扰立即停止制导 + IsHardJammed = true; + HasGuidance = false; // 硬干扰立即停止制导 Trace.WriteLine($"[{this.GetType().Name}] 硬干扰已应用: {parameters.Type}"); } } @@ -259,16 +327,16 @@ namespace ThreatSource.Guidance // 尝试清除硬干扰标志。如果还有其他硬干扰,组件状态可能仍反映, // 或者后续 ApplyJamming 会再次设置 IsHardJammed。 // 简化处理:清除任何硬干扰时都清除标志。 - this.IsHardJammed = false; + IsHardJammed = false; Trace.WriteLine($"[{this.GetType().Name}] 硬干扰已清除: {type}"); } // 子类需要重写此方法来处理 SmokeScreen 清除。 // 检查整体干扰状态 - if (!this._jammingComponent.IsJammed) + if (!_jammingComponent.IsJammed) { - this.IsHardJammed = false; // 确保清除 - this.HasGuidance = true; // 恢复制导 + IsHardJammed = false; // 确保清除 + HasGuidance = true; // 恢复制导 Trace.WriteLine($"[{this.GetType().Name}] 所有干扰已清除。"); } // 如果 _jammingComponent 仍然 IsJammed (因为可能有烟幕), diff --git a/ThreatSource/src/Guidance/InfraredImage.cs b/ThreatSource/src/Guidance/InfraredImage.cs index 7a35893..e48e42e 100644 --- a/ThreatSource/src/Guidance/InfraredImage.cs +++ b/ThreatSource/src/Guidance/InfraredImage.cs @@ -13,56 +13,45 @@ namespace ThreatSource.Guidance /// - 红外强度矩阵 /// 用于目标探测和识别 /// - public class InfraredImage + /// + /// 初始化红外图像的新实例 + /// + /// 图像宽度 + /// 图像高度 + /// 像素物理尺寸 + /// 视线方向 + /// 烟幕覆盖掩码 (可选) + public class InfraredImage(int width, int height, double pixelSize, Vector3D lineOfSight, bool[,]? smokeCoverageMask = null) { /// /// 图像宽度,单位:像素 /// - public int Width { get; } + public int Width { get; } = width; /// /// 图像高度,单位:像素 /// - public int Height { get; } + public int Height { get; } = height; /// /// 像素物理尺寸,单位:弧度/像素 /// - public double PixelSize { get; } + public double PixelSize { get; } = pixelSize; /// /// 红外强度矩阵,单位:W/sr /// - public double[,] Intensity { get; } + public double[,] Intensity { get; } = new double[height, width]; /// /// 图像中心视线方向 /// - public Vector3D LineOfSight { get; } + public Vector3D LineOfSight { get; } = lineOfSight; /// /// 烟幕覆盖掩码 (true 表示被遮蔽烟幕覆盖) /// - public bool[,] SmokeCoverageMask { get; } - - /// - /// 初始化红外图像的新实例 - /// - /// 图像宽度 - /// 图像高度 - /// 像素物理尺寸 - /// 视线方向 - /// 烟幕覆盖掩码 (可选) - public InfraredImage(int width, int height, double pixelSize, Vector3D lineOfSight, bool[,] smokeCoverageMask = null) - { - Width = width; - Height = height; - PixelSize = pixelSize; - LineOfSight = lineOfSight; - Intensity = new double[height, width]; - - SmokeCoverageMask = smokeCoverageMask ?? new bool[height, width]; - } + public bool[,] SmokeCoverageMask { get; } = smokeCoverageMask ?? new bool[height, width]; /// /// 设置像素强度值 diff --git a/ThreatSource/src/Guidance/InfraredImagingGuidanceSystem.cs b/ThreatSource/src/Guidance/InfraredImagingGuidanceSystem.cs index dfd1ebf..dd6b121 100644 --- a/ThreatSource/src/Guidance/InfraredImagingGuidanceSystem.cs +++ b/ThreatSource/src/Guidance/InfraredImagingGuidanceSystem.cs @@ -139,36 +139,6 @@ namespace ThreatSource.Guidance SwitchToSearchMode(); // 初始化为搜索模式 } - /// - /// 处理红外干扰事件 - /// - /// 红外干扰事件数据 - /// - /// 处理过程: - /// - 创建干扰参数 - /// - 使用JammableComponent进行干扰判断 - /// - 更新系统状态 - /// - private void OnInfraredJamming(InfraredJammingEvent evt) - { - if (evt == null) return; - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.Infrared, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 使用JammableComponent进行干扰判断 - ApplyJamming(parameters); - Debug.WriteLine($"红外引导系统干扰状态 - IsJammed: {IsJammed}, 干扰功率: {evt.JammingPower}W, 抗性阈值: {config.JammingResistanceThreshold}W"); - } - /// /// 处理系统被干扰的事件 /// @@ -186,6 +156,8 @@ namespace ThreatSource.Guidance { SwitchToSearchMode(); } + // 调用基类处理硬干扰状态 + base.HandleJammingApplied(parameters); } else if (parameters.Type == JammingType.SmokeScreen) { @@ -244,11 +216,6 @@ namespace ThreatSource.Guidance public override void Activate() { base.Activate(); - // 在这里订阅事件,确保只订阅一次 - SimulationManager.SubscribeToEvent(OnInfraredJamming); - - // 订阅烟幕事件 - SimulationManager.SubscribeToEvent(OnSmokeScreen); } /// @@ -257,8 +224,6 @@ namespace ThreatSource.Guidance public override void Deactivate() { base.Deactivate(); - SimulationManager.UnsubscribeFromEvent(OnInfraredJamming); - SimulationManager.UnsubscribeFromEvent(OnSmokeScreen); lastTargetPosition = null; // Add reset to null HasTarget = false; HasGuidance = false; @@ -268,41 +233,6 @@ namespace ThreatSource.Guidance // lockConfirmationTimer = 0; } - /// - /// 处理烟幕事件 - /// - /// 烟幕事件 - private void OnSmokeScreen(SmokeScreenEvent evt) - { - if (evt != null && evt.SmokeGrenadeId != null) - { - // 获取烟幕弹的配置 - if (SimulationManager.GetEntityById(evt.SmokeGrenadeId) is SmokeGrenade smokeGrenade) - { - var config = smokeGrenade.config; - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.SmokeScreen, - JammerId = smokeGrenade.Id, - SourcePosition = smokeGrenade.Position, - Direction = smokeGrenade.Orientation.ToVector(), - AngleRange = config.SmokeType == SmokeScreenType.Wall ? Math.PI : Math.PI * 2, // 墙状烟幕为半球形覆盖,云状为全方位 - SmokeConcentration = config.Concentration, - SmokeType = config.SmokeType, - SmokeThickness = config.Thickness, - Duration = config.Duration, - Mode = JammingMode.Obscuration - }; - - // 使用JammableComponent进行干扰判断 - ApplyJamming(parameters); - } - } - } - - - /// /// 更新引导系统的状态和计算结果 /// diff --git a/ThreatSource/src/Guidance/LaserBeamRiderGuidanceSystem.cs b/ThreatSource/src/Guidance/LaserBeamRiderGuidanceSystem.cs index d855b16..b44690b 100644 --- a/ThreatSource/src/Guidance/LaserBeamRiderGuidanceSystem.cs +++ b/ThreatSource/src/Guidance/LaserBeamRiderGuidanceSystem.cs @@ -172,7 +172,6 @@ namespace ThreatSource.Guidance { base.Activate(); // 在这里订阅事件,确保只订阅一次 - SimulationManager.SubscribeToEvent(OnLaserJamming); SimulationManager.SubscribeToEvent(OnLaserBeamStart); SimulationManager.SubscribeToEvent(OnLaserBeamStop); } @@ -184,7 +183,6 @@ namespace ThreatSource.Guidance { base.Deactivate(); // 取消订阅事件 - SimulationManager.UnsubscribeFromEvent(OnLaserJamming); SimulationManager.UnsubscribeFromEvent(OnLaserBeamStart); SimulationManager.UnsubscribeFromEvent(OnLaserBeamStop); } @@ -516,29 +514,6 @@ namespace ThreatSource.Guidance LastGuidanceAcceleration = GuidanceAcceleration; } - /// - /// 处理激光干扰事件 - /// - /// 激光干扰事件 - private void OnLaserJamming(LaserJammingEvent evt) - { - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.Laser, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 使用JammableComponent进行干扰判断 - ApplyJamming(parameters); - Debug.WriteLine($"激光驾束制导系统干扰状态 - IsJammed: {IsJammed}, 干扰功率: {evt.JammingPower}W, 抗性阈值: {config.JammingResistanceThreshold}W"); - } - /// /// 处理系统被干扰的事件 /// @@ -547,33 +522,48 @@ namespace ThreatSource.Guidance { if (parameters.Type == JammingType.Laser) { - Debug.WriteLine($"激光驾束制导系统受到激光干扰,功率:{parameters.Power}瓦特"); - // 确保基类的处理逻辑被调用,设置HasGuidance = false base.HandleJammingApplied(parameters); - - // 在强干扰下切换到搜索模式 - if (LaserIlluminationOn) - { - LaserIlluminationOn = false; - HasGuidance = false; - } + Debug.WriteLine("激光驾束制导系统受到激光干扰"); } } /// /// 处理系统干扰被清除的事件 /// - /// 被清除的干扰类型 + /// 被清除的干扰类型 protected override void HandleJammingCleared(JammingType type) { if (type == JammingType.Laser) { - Debug.WriteLine("激光驾束制导系统干扰已清除"); - // 确保基类的处理逻辑被调用 base.HandleJammingCleared(type); + Debug.WriteLine("激光驾束制导系统干扰已清除"); } } + /// + /// 判断是否应该处理传入的干扰参数(激光干扰需要额外检查波长) + /// + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) + { + if (!base.ShouldHandleJamming(parameters)) + { + return false; + } + + if (parameters.Type == JammingType.Laser) + { + if (Math.Abs((parameters.Wavelength ?? 0) - config.LaserWavelength) > 1e-6) + { + Debug.WriteLine($"[LASER_BEAM_RIDER] {Id} 忽略激光干扰:波长 {parameters.Wavelength}um 与期望波长 {config.LaserWavelength}um 不匹配。", "Jamming"); + return false; + } + } + + return true; + } + /// /// 获取制导系统的详细状态信息 /// diff --git a/ThreatSource/src/Guidance/LaserSemiActiveGuidanceSystem.cs b/ThreatSource/src/Guidance/LaserSemiActiveGuidanceSystem.cs index 7d9135e..f3bacfd 100644 --- a/ThreatSource/src/Guidance/LaserSemiActiveGuidanceSystem.cs +++ b/ThreatSource/src/Guidance/LaserSemiActiveGuidanceSystem.cs @@ -184,9 +184,7 @@ namespace ThreatSource.Guidance SimulationManager.SubscribeToEvent(OnLaserIlluminationUpdate); SimulationManager.SubscribeToEvent(OnLaserIlluminationStop); // 订阅激光干扰事件 - SimulationManager.SubscribeToEvent(OnLaserJamming); - // 订阅烟幕事件 - SimulationManager.SubscribeToEvent(OnSmokeScreen); + SimulationManager.SubscribeToEvent(HandleJammingEvent); // 订阅诱偏目标照射事件 SimulationManager.SubscribeToEvent(OnLaserDecoy); @@ -209,9 +207,7 @@ namespace ThreatSource.Guidance SimulationManager.UnsubscribeFromEvent(OnLaserIlluminationStop); // 取消订阅激光干扰事件 - SimulationManager.UnsubscribeFromEvent(OnLaserJamming); - // 取消订阅烟幕事件 - SimulationManager.UnsubscribeFromEvent(OnSmokeScreen); + SimulationManager.UnsubscribeFromEvent(HandleJammingEvent); // 取消订阅诱偏目标照射事件 SimulationManager.UnsubscribeFromEvent(OnLaserDecoy); @@ -220,39 +216,55 @@ namespace ThreatSource.Guidance } /// - /// 处理激光照射更新事件 + /// 处理激光照射更新事件 (恢复编码检查) /// /// 激光照射更新事件 private void OnLaserIlluminationUpdate(LaserIlluminationUpdateEvent evt) - { - if (evt?.LaserDesignatorId != null && evt?.TargetId != null && evt?.SpotPosition != null) + { + if (evt?.LaserDesignatorId == null || evt?.TargetId == null || evt?.SpotPosition == null) { - Console.WriteLine($"处理激光照射更新事件: 激光指示器ID: {evt.LaserDesignatorId}, 目标ID: {evt.TargetId}, 光斑位置: {evt.SpotPosition}"); - try - { - LaserDesignator laserDesignator = SimulationManager.GetEntityById(evt.LaserDesignatorId) as LaserDesignator ?? throw new Exception("激光指示器不存在"); - SimulationElement target = SimulationManager.GetEntityById(evt.TargetId) as SimulationElement ?? throw new Exception("目标不存在"); - - int existingIndex = laserTargets.FindIndex(t => t.Target.Id == target.Id); - if (existingIndex != -1) - { - // 如果存在,先移除旧条目 - laserTargets.RemoveAt(existingIndex); - } - // 添加新条目(包含最新信息) - laserTargets.Add((target, evt.SpotPosition, laserDesignator)); + Console.WriteLine("接收到无效的激光照射更新事件"); + return; + } - // 处理激光照射更新事件 - ProcessLaserIlluminationUpdateEvent(evt); - } - catch (Exception ex) + // 1. 检查编码 (如果需要) + if (InternalLaserCodeConfig != null && InternalLaserCodeConfig.IsCodeMatchRequired) + { + if (!CheckLaserCode(evt.LaserCodeConfig)) // 使用辅助方法检查编码 { - Trace.WriteLine($"处理激光照射更新事件时出错: {ex.Message}"); + PublishCodeMismatchEvent(evt.LaserDesignatorId, evt.LaserCodeConfig); + Console.WriteLine($"[LASER_SEMI_ACTIVE] {Id} 接收到编码不匹配的激光照射事件,忽略。预期: {InternalLaserCodeConfig}, 收到: {evt.LaserCodeConfig}"); + // 编码不匹配,不处理此事件,也不设置 LaserIlluminationOn + return; } + Console.WriteLine($"[LASER_SEMI_ACTIVE] {Id} 激光编码匹配。"); } else { - Trace.WriteLine("警告:激光照射更新事件缺少必要参数"); + Console.WriteLine($"[LASER_SEMI_ACTIVE] {Id} 未配置编码检查或不要求匹配。"); + } + + // 2. 编码匹配或无需检查,处理事件 + Console.WriteLine($"[LASER_SEMI_ACTIVE] 处理激光照射更新事件: 指示器ID: {evt.LaserDesignatorId}, 目标ID: {evt.TargetId}"); + try + { + LaserDesignator laserDesignator = SimulationManager.GetEntityById(evt.LaserDesignatorId) as LaserDesignator ?? throw new Exception("激光指示器不存在"); + SimulationElement target = SimulationManager.GetEntityById(evt.TargetId) as SimulationElement ?? throw new Exception("目标不存在"); + + int existingIndex = laserTargets.FindIndex(t => t.Target.Id == target.Id); + if (existingIndex != -1) + { + laserTargets.RemoveAt(existingIndex); + } + laserTargets.Add((target, evt.SpotPosition, laserDesignator)); + + // 只要收到有效事件就认为照射开启 (有效性由后续SNR判断) + LaserIlluminationOn = true; + // HasGuidance 的设置由 Update 方法根据 SNR 和其他条件决定 + } + catch (Exception ex) + { + Console.WriteLine($"处理激光照射更新事件时出错: {ex.Message}"); } } @@ -262,10 +274,17 @@ namespace ThreatSource.Guidance /// 激光照射停止事件 private void OnLaserIlluminationStop(LaserIlluminationStopEvent evt) { - LaserIlluminationOn = false; - HasGuidance = false; // 禁用制导 - PreviousGuidanceAcceleration = Vector3D.Zero; // 重置历史加速度 - TargetPosition = null; + if (evt?.TargetId != null) + { + // 移除特定目标 + laserTargets.RemoveAll(t => t.Target.Id == evt.TargetId); + // 如果没有其他照射目标,则关闭照射状态 + if (!laserTargets.Any()) + { + LaserIlluminationOn = false; + HasGuidance = false; + } + } } /// @@ -298,123 +317,80 @@ namespace ThreatSource.Guidance } } - /// - /// 处理激光干扰事件 - /// - /// 激光干扰事件 - private void OnLaserJamming(LaserJammingEvent evt) - { - if (evt == null) return; - - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.Laser, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 使用JammableComponent进行干扰判断 - ApplyJamming(parameters); - - // 如果被硬干扰,切换到搜索模式 - if (IsHardJammed) - { - // 清除目标信息 - TargetPosition = null; - LaserIlluminationOn = false; - // 记录干扰信息 - Trace.WriteLine($"激光半主动制导系统被硬干扰 - 功率: {evt.JammingPower}W, 位置: {evt.JammingSourcePosition}, 方向: {evt.JammingDirection}"); - } - } - - /// - /// 处理烟幕事件 - /// - /// 烟幕事件 - private void OnSmokeScreen(SmokeScreenEvent evt) - { - if (evt != null && evt.SmokeGrenadeId != null) - { - // 获取烟幕弹的配置 - if (SimulationManager.GetEntityById(evt.SmokeGrenadeId) is SmokeGrenade smokeGrenade) - { - var config = smokeGrenade.config; - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.SmokeScreen, - JammerId = smokeGrenade.Id, - SourcePosition = smokeGrenade.Position, - Direction = smokeGrenade.Orientation.ToVector(), - AngleRange = config.SmokeType == SmokeScreenType.Wall ? Math.PI : Math.PI * 2, // 墙状烟幕为半球形覆盖,云状为全方位 - SmokeConcentration = config.Concentration, - SmokeType = config.SmokeType, - SmokeThickness = config.Thickness, - Duration = config.Duration, - Mode = JammingMode.Obscuration - }; - - // 使用JammableComponent进行干扰判断 - ApplyJamming(parameters); - } - } - } - /// /// 处理系统被干扰的事件 /// /// 干扰参数 protected override void HandleJammingApplied(JammingParameters parameters) { - base.HandleJammingApplied(parameters); + base.HandleJammingApplied(parameters); // Calls base logic (IsHardJammed, HasGuidance) if (parameters.Type == JammingType.Laser) - { - // 在硬干扰下切换到搜索模式 - if (LaserIlluminationOn) - { - LaserIlluminationOn = false; - PreviousGuidanceAcceleration = Vector3D.Zero; // 重置历史加速度 - } + { + Debug.WriteLine($"[LASER_SEMI_ACTIVE] 受到激光干扰。", "Jamming"); + // 基类已将 HasGuidance 设为 false + TargetPosition = null; // 丢失目标位置 + LaserIlluminationOn = false; // 无法确认照射状态 + // 不需要再次设置 HasGuidance = false } else if (parameters.Type == JammingType.SmokeScreen) { - if (SimulationManager.GetEntityById(parameters.JammerId) is SmokeGrenade smokeGrenade) - { - // 检查目标位置是否有效,并且激光照射是否开启 (烟幕只影响接收到的信号) - if (TargetPosition != null && LaserIlluminationOn) - { - // 计算烟幕衰减 (1.0 表示无衰减) - SmokeAttenuation = smokeGrenade.GetSmokeTransmittanceOnLine(Position, TargetPosition, config.LaserWavelength); - Console.WriteLine($"[烟幕干扰应用 Laser] 视线透过率/衰减系数: {SmokeAttenuation:F3}"); - } - else - { - // 目标无效或激光未照射,暂不计算特定视线衰减 - SmokeAttenuation = 1.0; - Console.WriteLine("[烟幕干扰应用 Laser] 目标位置无效或激光未照射,暂不计算烟幕衰减。"); - } - } - else - { - // 未找到烟幕弹,假定无衰减 - SmokeAttenuation = 1.0; - } + // 计算并应用烟幕衰减 + SmokeAttenuation = CalculateSmokeAttenuation(parameters); + Debug.WriteLine($"[LASER_SEMI_ACTIVE] 烟幕干扰应用,衰减因子: {SmokeAttenuation:P2}", "Jamming"); } } /// /// 处理系统干扰被清除的事件 - /// - /// 被清除的干扰类型 + /// + /// 被清除的干扰类型 protected override void HandleJammingCleared(JammingType type) { - base.HandleJammingCleared(type); + base.HandleJammingCleared(type); // Calls base logic (IsHardJammed, maybe HasGuidance = true) + + if (type == JammingType.Laser) + { + Debug.WriteLine($"[LASER_SEMI_ACTIVE] 激光干扰已清除。", "Jamming"); + // 不需要设置 HasGuidance = true, 基类可能已处理 + // 激光照射状态 LaserIlluminationOn 会在收到下一个有效 Update 事件时恢复 + } + else if (type == JammingType.SmokeScreen) + { + SmokeAttenuation = 1.0; // 重置烟幕衰减 + Debug.WriteLine($"[LASER_SEMI_ACTIVE] 烟幕干扰已清除。", "Jamming"); + } + } + + /// + /// 判断是否应该处理传入的干扰参数(激光干扰需要额外检查波长和编码) + /// + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) + { + // 首先调用基类检查是否支持该干扰类型 + if (!base.ShouldHandleJamming(parameters)) + { + return false; + } + + // 对激光干扰添加波长检查 + if (parameters.Type == JammingType.Laser) + { + // 1. 检查波长 + if (Math.Abs((parameters.Wavelength ?? 0) - config.LaserWavelength) > 1e-6) + { + Debug.WriteLine($"[LASER_SEMI_ACTIVE] {Id} 忽略激光干扰:波长 {parameters.Wavelength}um 与期望波长 {config.LaserWavelength}um 不匹配。", "Jamming"); + return false; + } + + // 2. 移除干扰事件中的编码检查: JammingParameters 不包含 LaserCode. + // 编码检查已移至 OnLaserIlluminationUpdate + } + + // 如果是支持的非激光干扰 (例如烟幕) 或通过了激光检查,则返回 true + return true; } /// @@ -490,13 +466,13 @@ namespace ThreatSource.Guidance if (target.Target is LaserDecoy decoy) { // 计算接收功率 - receivedPower = CalculateReceivedPower(target.Source.Position, target.SpotPosition, decoy.DecoyPower, decoy.DecoyLaserDivergenceAngle); + receivedPower = CalculateReceivedPower(target.Source.Position, target.SpotPosition, decoy.config.DecoyPower, decoy.config.DecoyLaserDivergenceAngle); Console.WriteLine($"处理激光信号: 诱偏目标接收功率={receivedPower:E}W, 诱偏目标ID: {target.Target.Id}, 诱偏目标位置: {target.SpotPosition}"); } else if (target.Source is LaserDesignator laserDesignator) { // 计算接收功率 - receivedPower = CalculateReceivedPower(target.Source.Position, target.SpotPosition, laserDesignator.LaserPower, laserDesignator.LaserDivergenceAngle); + receivedPower = CalculateReceivedPower(target.Source.Position, target.SpotPosition, laserDesignator.config.LaserPower, laserDesignator.config.LaserDivergenceAngle); Console.WriteLine($"处理激光信号: 真实目标接收功率={receivedPower:E}W, 真实目标ID: {target.Target.Id}, 真实目标位置: {target.SpotPosition}"); } @@ -845,57 +821,19 @@ namespace ThreatSource.Guidance } /// - /// 处理激光照射更新事件 + /// 检查激光编码是否匹配 /// - /// 激光照射更新事件 - /// - /// 处理过程: - /// - 检查编码是否匹配 - /// - 如果要求匹配且不匹配,则忽略信号 - /// - 如果匹配或不要求匹配,则处理信号 - /// - 更新激光照射状态 - /// - public void ProcessLaserIlluminationUpdateEvent(LaserIlluminationUpdateEvent illuminationEvent) + /// 接收到的激光编码配置 + /// 如果匹配返回true,否则返回false + private bool CheckLaserCode(LaserCodeConfig? receivedConfig) { - if (illuminationEvent.LaserCodeConfig != null) + // 如果内部配置为空,或接收到的配置为空,或内部配置不需要检查,则视为匹配(或忽略) + if (InternalLaserCodeConfig == null || receivedConfig == null || !InternalLaserCodeConfig.IsCodeMatchRequired) { - // 只有在编码启用的情况下才进行编码匹配检查 - if (illuminationEvent.LaserCodeConfig.IsCodeEnabled) - { - bool codeMatched = InternalLaserCodeConfig?.CheckCodeMatch(illuminationEvent.LaserCodeConfig) ?? false; - - if (!codeMatched) - { - // 发布编码不匹配事件 - PublishCodeMismatchEvent(illuminationEvent.LaserDesignatorId, illuminationEvent.LaserCodeConfig); - Trace.WriteLine("激光半主动制导系统接收到不匹配的激光编码,忽略信号"); - HasGuidance = false; // 禁用制导 - LaserIlluminationOn = false; // 禁用激光照射状态,确保四象限探测器不处理信号 - // 重置四象限探测器状态 - quadrantDetector.ProcessLaserSignal(0, new Vector2D(0, 0)); - PreviousGuidanceAcceleration = Vector3D.Zero; // 重置历史加速度 - return; - } - } - - // 更新激光照射状态 - LaserIlluminationOn = true; + return true; } - } - - /// - /// 处理激光照射停止事件 - /// - /// 激光照射停止事件 - /// - /// 处理过程: - /// - 停止激光照射状态 - /// - 清理相关参数 - /// - public void ProcessLaserIlluminationStopEvent(LaserIlluminationStopEvent illuminationEvent) - { - LaserIlluminationOn = false; - HasGuidance = false; // 禁用制导 + // 调用内部配置的匹配逻辑 + return InternalLaserCodeConfig.CheckCodeMatch(receivedConfig); } /// @@ -919,7 +857,7 @@ namespace ThreatSource.Guidance ReceivedCodeConfig = receivedCodeConfig }; - PublishEvent(mismatchEvent); + PublishEvent(mismatchEvent); // 使用基类的 PublishEvent } /// diff --git a/ThreatSource/src/Guidance/MillimeterWaveGuidanceSystem.cs b/ThreatSource/src/Guidance/MillimeterWaveGuidanceSystem.cs index d426e03..7c3bbcb 100644 --- a/ThreatSource/src/Guidance/MillimeterWaveGuidanceSystem.cs +++ b/ThreatSource/src/Guidance/MillimeterWaveGuidanceSystem.cs @@ -215,9 +215,7 @@ namespace ThreatSource.Guidance { IsActive = true; // 在这里订阅事件,确保只订阅一次 - SimulationManager.SubscribeToEvent(OnMillimeterWaveJamming); - // 添加对烟幕事件的订阅 - SimulationManager.SubscribeToEvent(OnSmokeScreen); + SimulationManager.SubscribeToEvent(HandleJammingEvent); } base.Activate(); SwitchToSearchMode(); @@ -231,9 +229,7 @@ namespace ThreatSource.Guidance if (IsActive) { IsActive = false; - SimulationManager.UnsubscribeFromEvent(OnMillimeterWaveJamming); - // 添加取消对烟幕事件的订阅 - SimulationManager.UnsubscribeFromEvent(OnSmokeScreen); + SimulationManager.UnsubscribeFromEvent(HandleJammingEvent); } base.Deactivate(); HasTarget = false; @@ -243,62 +239,6 @@ namespace ThreatSource.Guidance lastTargetVelocity = null; } - /// - /// 处理毫米波干扰事件 - /// - /// 干扰事件参数 - /// - /// 处理过程: - /// - 更新干扰状态 - /// - 记录干扰功率 - /// - private void OnMillimeterWaveJamming(MillimeterWaveJammingEvent evt) - { - if (evt == null) return; - - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.MillimeterWave, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 使用JammableComponent进行干扰判断 - ApplyJamming(parameters); - Debug.WriteLine($"毫米波导引头系统干扰状态 - IsJammed: {IsJammed}, 干扰功率: {evt.JammingPower}W, 抗性阈值: {config.JammingResistanceThreshold}W"); - } - - /// - /// 处理烟幕事件,触发干扰应用 - /// - /// 烟幕事件 - private void OnSmokeScreen(SmokeScreenEvent evt) - { - if (evt != null && evt.SmokeGrenadeId != null) - { - // 获取烟幕弹实例以创建干扰参数 - if (SimulationManager.GetEntityById(evt.SmokeGrenadeId) is SmokeGrenade smokeGrenade) - { - var parameters = new JammingParameters - { - Type = JammingType.SmokeScreen, - JammerId = smokeGrenade.Id, - SourcePosition = smokeGrenade.Position, - Direction = smokeGrenade.Orientation.ToVector(), - Mode = JammingMode.Obscuration // 表明是遮蔽干扰 - // JammableComponent可能需要其他烟幕属性,如果需要则从smokeGrenade.CurrentParameters获取 - }; - // 应用干扰效果,这将调用HandleJammingApplied - ApplyJamming(parameters); - } - } - } - /// /// 处理系统被干扰的事件 /// @@ -308,42 +248,27 @@ namespace ThreatSource.Guidance // 1. 让基类处理通用硬干扰逻辑 (如果不是SmokeScreen, 会设置 IsHardJammed 和 HasGuidance = false) base.HandleJammingApplied(parameters); - // 2. 处理特定于毫米波的硬干扰响应 + // 2. 处理毫米波干扰特定逻辑 if (parameters.Type == JammingType.MillimeterWave) - { - Debug.WriteLine($"毫米波导引头系统受到毫米波干扰,功率:{parameters.Power}瓦特"); - // 在硬干扰下切换到搜索模式 (即使基类已设置HasGuidance=false, 仍可切换模式) - if (currentMode != WorkMode.Search) - { - SwitchToSearchMode(); - } + { + isJammed = true; // 使用局部变量,与基类 IsJammed 分开? 还是统一? **统一使用基类的 IsJammed** + // isJammed = _jammingComponent.IsJammed; // Correct way to get status + jammingPower = parameters.Power; // 记录干扰功率 + Debug.WriteLine($"[MMW_GUIDANCE] 受到毫米波干扰,功率:{jammingPower} W。切换到搜索模式。", "Jamming"); + // 干扰时切换到搜索模式 + if (currentMode != WorkMode.Search) + { + SwitchToSearchMode(); + } + // 基类已经设置 HasGuidance = false } - // 3. 处理烟幕干扰 (计算透过率,不直接影响 IsHardJammed 或 HasGuidance) + // 3. 处理烟幕干扰特定逻辑 else if (parameters.Type == JammingType.SmokeScreen) { - if (SimulationManager.GetEntityById(parameters.JammerId) is SmokeGrenade smokeGrenade) - { - // Check lastTargetPosition != null before using it - if (lastTargetPosition != null) - { - // 计算波长 - double wavelength = 3e8 / config.WaveFrequency; - // 计算视线透过率 - _currentSmokeTransmittance = smokeGrenade.GetSmokeTransmittanceOnLine(Position, lastTargetPosition, wavelength); - Debug.WriteLine($"[烟幕干扰应用 MMW] 视线透过率: {_currentSmokeTransmittance:F3}"); - } - else - { - // 目标尚未有效跟踪,无法计算特定视线衰减,假定无衰减 - _currentSmokeTransmittance = 1.0; - Debug.WriteLine("[烟幕干扰应用 MMW] 目标位置无效,暂不计算烟幕衰减。"); - } - } - else - { - // 未找到烟幕弹,假定无衰减 - _currentSmokeTransmittance = 1.0; - } + // 计算烟幕透过率 + // TODO: 实现基于 JammingParameters 中烟幕属性 (浓度、厚度等) 的真实透过率计算。 + _currentSmokeTransmittance = 1.0; // 暂时设置为无遮挡 + Debug.WriteLine($"[MMW_GUIDANCE] 烟幕干扰应用,(临时) 透过率: {_currentSmokeTransmittance:P2}", "Jamming"); } } @@ -353,21 +278,53 @@ namespace ThreatSource.Guidance /// 被清除的干扰类型 protected override void HandleJammingCleared(JammingType type) { - // 1. 处理特定于烟幕的清除逻辑 - if (type == JammingType.SmokeScreen) + base.HandleJammingCleared(type); // 调用基类处理 IsHardJammed 和 HasGuidance + + if (type == JammingType.MillimeterWave) { - _currentSmokeTransmittance = 1.0; // 重置透过率 - Debug.WriteLine("[烟幕干扰清除 MMW]"); + isJammed = false; // 重置局部变量? **统一使用基类的 IsJammed** + // isJammed = _jammingComponent.IsJammed; // Correct way to get status + jammingPower = 0; // 重置干扰功率 + Debug.WriteLine($"[MMW_GUIDANCE] 毫米波干扰已清除。", "Jamming"); + // 干扰清除后是否需要切换模式?取决于当前是否有目标。Update 会处理。 } - else if (type == JammingType.MillimeterWave) + else if (type == JammingType.SmokeScreen) { - Debug.WriteLine("毫米波导引头系统干扰被清除"); - // 毫米波硬干扰清除的具体行为由基类处理 + _currentSmokeTransmittance = 1.0; // 重置烟幕透过率 + Debug.WriteLine($"[MMW_GUIDANCE] 烟幕干扰已清除。", "Jamming"); + } + } + + /// + /// 判断是否应该处理传入的干扰参数(毫米波干扰需要额外检查波长) + /// + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) + { + // 首先调用基类检查是否支持该干扰类型 + if (!base.ShouldHandleJamming(parameters)) + { + return false; + } + + // 对毫米波干扰添加波长检查 + if (parameters.Type == JammingType.MillimeterWave) + { + // 检查波长是否与工作波长匹配 (单位: 毫米 mm) + // 计算配置波长 (单位: mm), 直接使用光速值 3e8 m/s + const double speedOfLight = 3e8; + double configWavelength = speedOfLight / config.WaveFrequency * 1000.0; // m/s / Hz * 1000 = mm + + if (Math.Abs((parameters.Wavelength ?? 0) - configWavelength) > 1e-1) // 允许 0.1mm 偏差 + { + Debug.WriteLine($"[MMW_GUIDANCE] {Id} 忽略毫米波干扰:干扰波长 {parameters.Wavelength}mm 与系统工作波长 {configWavelength:F2}mm (频率 {config.WaveFrequency/1e9:F1}GHz) 不匹配。", "Jamming"); + return false; + } } - // 2. 最后调用基类方法处理通用清除逻辑 - // 基类会检查是否所有干扰都已清除,并相应地更新 IsHardJammed 和 HasGuidance - base.HandleJammingCleared(type); + // 如果是支持的非毫米波干扰 (例如烟幕) 或通过了毫米波检查,则返回 true + return true; } /// @@ -520,63 +477,69 @@ namespace ThreatSource.Guidance /// public override void Update(double deltaTime, Vector3D missilePosition, Vector3D missileVelocity) { + base.Update(deltaTime, missilePosition, missileVelocity); // 更新基类状态和干扰状态 + + // 在执行核心逻辑前检查干扰状态 + if (IsJammed) // 使用基类的 IsJammed 状态 + { + // 如果被干扰,确保处于搜索模式并且没有制导 + if (currentMode != WorkMode.Search) + { + SwitchToSearchMode(); + } + HasGuidance = false; + GuidanceAcceleration = Vector3D.Zero; + // Debug.WriteLine($"[MMW_GUIDANCE] {Id} 处于干扰状态,跳过制导计算。", "Jamming"); + return; // 不执行后续逻辑 + } + // 更新扫描参数 UpdateConicalScan(deltaTime); - base.Update(deltaTime, missilePosition, missileVelocity); - - if (!IsHardJammed) + if (TryDetectAndTrackTarget(missilePosition, missileVelocity, deltaTime, out Vector3D currentTargetPosition)) { - if (TryDetectAndTrackTarget(missilePosition, missileVelocity, deltaTime, out Vector3D currentTargetPosition)) + targetLostTimer = 0; + Vector3D? currentTargetVelocity = null; + if (lastTargetPosition != null && deltaTime > 0) { - targetLostTimer = 0; - Vector3D? currentTargetVelocity = null; - if (lastTargetPosition != null && deltaTime > 0) - { - currentTargetVelocity = (currentTargetPosition - lastTargetPosition) / deltaTime; - } - - lastTargetPosition = currentTargetPosition; - lastTargetVelocity = currentTargetVelocity; - - GuidanceAcceleration = MotionAlgorithm.CalculateProportionalNavigation( - ProportionalNavigationCoefficient, - missilePosition, - missileVelocity, - currentTargetPosition, - currentTargetVelocity ?? Vector3D.Zero - ); - - if (GuidanceAcceleration.Magnitude() > MaxAcceleration) - { - GuidanceAcceleration = GuidanceAcceleration.Normalize() * MaxAcceleration; - } - - Console.WriteLine($"制导加速度: {GuidanceAcceleration}"); - HasGuidance = true; + currentTargetVelocity = (currentTargetPosition - lastTargetPosition) / deltaTime; } - else + + lastTargetPosition = currentTargetPosition; + lastTargetVelocity = currentTargetVelocity; + + GuidanceAcceleration = MotionAlgorithm.CalculateProportionalNavigation( + ProportionalNavigationCoefficient, + missilePosition, + missileVelocity, + currentTargetPosition, + currentTargetVelocity ?? Vector3D.Zero + ); + + if (GuidanceAcceleration.Magnitude() > MaxAcceleration) { - if (currentMode != WorkMode.Search) - { - targetLostTimer += deltaTime; - if (targetLostTimer >= config.TargetLostTolerance) - { - HasGuidance = false; - Trace.WriteLine($"目标丢失 {targetLostTimer:F3}秒,切换回搜索模式"); - SwitchToSearchMode(); - } - } - else - { - HasGuidance = false; - } + GuidanceAcceleration = GuidanceAcceleration.Normalize() * MaxAcceleration; } + + Console.WriteLine($"制导加速度: {GuidanceAcceleration}"); + HasGuidance = true; } else { - HasGuidance = false; - GuidanceAcceleration = Vector3D.Zero; + if (currentMode != WorkMode.Search) + { + targetLostTimer += deltaTime; + if (targetLostTimer >= config.TargetLostTolerance) + { + HasGuidance = false; + Trace.WriteLine($"目标丢失 {targetLostTimer:F3}秒,切换回搜索模式"); + SwitchToSearchMode(); + } + } + else + { + HasGuidance = false; + } } } diff --git a/ThreatSource/src/Indicator/BaseIndicator.cs b/ThreatSource/src/Indicator/BaseIndicator.cs index 9113f0d..f7d5841 100644 --- a/ThreatSource/src/Indicator/BaseIndicator.cs +++ b/ThreatSource/src/Indicator/BaseIndicator.cs @@ -88,10 +88,11 @@ namespace ThreatSource.Indicator : base(id, motionParameters, manager) { _jammingComponent = new JammableComponent( - positionProvider: () => base.Position, - onJammingApplied: HandleJammingApplied, - onJammingCleared: HandleJammingCleared + positionProvider: () => base.Position ); + + _jammingComponent.JammingApplied += HandleJammingApplied; + _jammingComponent.JammingCleared += HandleJammingCleared; } /// @@ -142,8 +143,18 @@ namespace ThreatSource.Indicator /// 干扰参数 protected virtual void HandleJammingApplied(JammingParameters parameters) { - // 子类可以重写此方法以实现特定的干扰响应 - Console.WriteLine($"指示器受到{parameters.Type}类型干扰,功率:{parameters.Power}W"); + // 如果是烟幕干扰,重新计算遮挡状态 + if (parameters.Type == JammingType.SmokeScreen) + { + RecalculateObscurationStatus(); + Debug.WriteLine($"[BaseIndicator] 烟幕状态更新,IsTargetObscured: {IsTargetObscured}", "Jamming"); + } + else // 其他干扰类型打印通用消息 + { + // 子类可以重写此方法以实现特定的干扰响应 + Debug.WriteLine($"[BaseIndicator] {this.GetType().Name} {Id} 受到 {parameters.Type} 类型干扰,功率:{parameters.Power}W", "Jamming"); + } + } /// @@ -152,42 +163,72 @@ namespace ThreatSource.Indicator /// 被清除的干扰类型 protected virtual void HandleJammingCleared(JammingType type) { - // 子类可以重写此方法以实现干扰清除后的特定行为 - Console.WriteLine($"指示器{type}类型干扰已清除"); + // 如果是烟幕干扰,重新计算遮挡状态 + if (type == JammingType.SmokeScreen) + { + RecalculateObscurationStatus(); + Debug.WriteLine($"[BaseIndicator] 烟幕状态更新,IsTargetObscured: {IsTargetObscured}", "Jamming"); + } + else // 其他干扰类型打印通用消息 + { + // 子类可以重写此方法以实现干扰清除后的特定行为 + Debug.WriteLine($"[BaseIndicator] {this.GetType().Name} {Id} {type} 类型干扰已清除", "Jamming"); + } } /// - /// 激活指示器 (基类实现,子类应重写以添加事件订阅) + /// 激活指示器 (基类统一处理干扰事件订阅) /// public override void Activate() { - base.Activate(); - // 子类需要在此之后调用 base.Activate() 并订阅烟幕事件 + if (!IsActive) + { + IsActive = true; + // 统一订阅 JammingEvent + SimulationManager.SubscribeToEvent(HandleJammingEvent); + // 子类仍需在此处订阅其他特定事件(如导弹热源事件) + } + base.Activate(); // 调用 SimulationElement 的基类 Activate + // 子类需要在此之后调用 base.Activate() 并订阅烟幕事件 <--- 旧注释,移除或更新 + // 现在基类处理通用 JammingEvent,子类只需要处理非干扰事件 + RecalculateObscurationStatus(); // 激活时检查一次初始遮挡状态 } /// - /// 停用指示器 (基类实现,子类应重写以移除事件订阅) + /// 停用指示器 (基类统一处理干扰事件取消订阅) /// public override void Deactivate() { - // 子类需要在此之前取消订阅烟幕事件 + if (IsActive) + { + IsActive = false; + // 统一取消订阅 JammingEvent + SimulationManager.UnsubscribeFromEvent(HandleJammingEvent); + // 子类仍需在此处取消订阅其他特定事件 + } + // 子类需要在此之前取消订阅烟幕事件 <--- 旧注释,移除或更新 IsTargetObscured = false; // 重置最后目标状态 _lastKnownTargetPosition = null; _lastKnownTargetOrientation = null; - base.Deactivate(); + base.Deactivate(); // 调用 SimulationElement 的基类 Deactivate } /// - /// 更新指示器状态 (基类只处理电子干扰) + /// 更新指示器状态 /// - public override void Update(double deltaTime) + public override void Update(double deltaTime) { - _jammingComponent.UpdateJammingStatus(deltaTime); + _jammingComponent.UpdateJammingStatus(deltaTime); // 更新干扰状态(包括持续时间等) if (IsActive) { - UpdateIndicator(deltaTime); + // 只有未被电子干扰时才更新指示器特定功能 + // 烟幕遮挡 (IsTargetObscured) 在 UpdateIndicator 内部处理 + if (!IsJammed) + { + UpdateIndicator(deltaTime); + } } } @@ -321,5 +362,43 @@ namespace ThreatSource.Indicator // 6. 如果遍历完所有烟幕都没有达到遮挡阈值 return false; // 未被遮挡 } + + // --- 新增干扰事件处理逻辑 --- + + /// + /// 统一处理干扰事件 + /// + /// 干扰事件 + protected virtual void HandleJammingEvent(JammingEvent evt) + { + if (evt == null) return; + + // 在应用干扰前检查是否应该处理此干扰 + if (!ShouldHandleJamming(evt.Parameters)) + { + // Debug.WriteLine($"[BaseIndicator] {Id} 忽略干扰事件,类型: {evt.Parameters.Type}"); + return; + } + + // 如果应该处理,则应用干扰 + ApplyJamming(evt.Parameters); + } + + /// + /// 判断是否应该处理传入的干扰参数(可被子类重写以添加特定检查) + /// + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected virtual bool ShouldHandleJamming(JammingParameters parameters) + { + // 基类默认处理所有受支持类型的干扰 (包括烟幕) + // 子类可以重写此方法添加额外检查,如波段匹配 + // 注意:烟幕干扰虽然通过这里,但主要效果通过 IsTargetObscured 和 RecalculateObscurationStatus 体现 + bool supported = SupportedJammingTypes.Contains(parameters.Type); + // if(!supported) Debug.WriteLine($"[BaseIndicator] {Id} 不支持干扰类型: {parameters.Type}"); + return supported; + } + + // --- 结束新增干扰事件处理逻辑 --- } } \ No newline at end of file diff --git a/ThreatSource/src/Indicator/InfraredTracker.cs b/ThreatSource/src/Indicator/InfraredTracker.cs index 757b29a..41da9ad 100644 --- a/ThreatSource/src/Indicator/InfraredTracker.cs +++ b/ThreatSource/src/Indicator/InfraredTracker.cs @@ -84,22 +84,22 @@ namespace ThreatSource.Indicator /// 时间步长,单位:秒 /// /// 实现红外测角仪特定的更新逻辑: - /// - 只有在未被电子干扰且目标未被烟幕遮挡时才执行跟踪 + /// - 基类 Update 会检查 IsJammed (电子干扰) + /// - UpdateTracking 方法内部会处理 IsTargetObscured (烟幕遮挡) /// - 更新跟踪状态 - /// - 处理目标跟踪 /// protected override void UpdateIndicator(double deltaTime) { - // 检查红外干扰 - if (IsJammed) - { - // 干扰完全停止跟踪 - StopTracking(); - Console.WriteLine($"InfraredTracker {Id} 受到红外干扰,停止跟踪。"); - return; - } + // 基类 Update 已经检查了 IsJammed + // if (IsJammed) + // { + // StopTracking(); // Logic moved to HandleJammingApplied + // Console.WriteLine($"InfraredTracker {Id} 受到红外干扰,停止跟踪。"); + // return; + // } // 无论是否被遮挡,都尝试更新跟踪状态 + // IsTargetObscured is handled within UpdateTracking UpdateTracking(); } @@ -272,14 +272,15 @@ namespace ThreatSource.Indicator { if (!IsActive) { - base.Activate(); - SimulationManager.SubscribeToEvent(OnInfraredGuidanceMissileLight); - SimulationManager.SubscribeToEvent(OnInfraredGuidanceMissileLightOff); - SimulationManager.SubscribeToEvent(OnInfraredJamming); - SimulationManager.SubscribeToEvent(HandleSmokeEvent); - SimulationManager.SubscribeToEvent(HandleSmokeEvent); - RecalculateObscurationStatus(); - Debug.WriteLine($"InfraredTracker {Id} activated."); + base.Activate(); // Handles IsActive and subscribes HandleJammingEvent + // Removed JammingEvent subscriptions for OnInfraredJamming and HandleSmokeEvent + + // Subscribe to missile-specific events (KEEP THESE) + SimulationManager.SubscribeToEvent(OnInfraredGuidanceMissileLight); + SimulationManager.SubscribeToEvent(OnInfraredGuidanceMissileLightOff); + + // 子类特定的激活逻辑 + Debug.WriteLine($"红外测角仪 {Id} 已激活"); } } @@ -294,71 +295,50 @@ namespace ThreatSource.Indicator /// public override void Deactivate() { - if (IsActive) - { - SimulationManager.UnsubscribeFromEvent(HandleSmokeEvent); - SimulationManager.UnsubscribeFromEvent(HandleSmokeEvent); - SimulationManager.UnsubscribeFromEvent(OnInfraredGuidanceMissileLight); - SimulationManager.UnsubscribeFromEvent(OnInfraredGuidanceMissileLightOff); - SimulationManager.UnsubscribeFromEvent(OnInfraredJamming); - Debug.WriteLine($"InfraredTracker {Id} deactivated."); - base.Deactivate(); - } - } - - /// - /// 处理红外干扰事件 - /// - /// 红外干扰事件数据 - /// - /// 处理过程: - /// - 计算干扰效果 - /// - 应用干扰状态 - /// - private void OnInfraredJamming(InfraredJammingEvent evt) - { - // 创建干扰参数 - var parameters = new JammingParameters + if (IsActive) { - Type = JammingType.Infrared, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 检查波长匹配(红外特定逻辑) - bool isWavelengthInRange = IsWavelengthInRange(evt.Wavelength); - - // 使用JammableComponent进行干扰判断 - if (isWavelengthInRange) - { - ApplyJamming(parameters); - Debug.WriteLine($"干扰状态 - IsJammed: {IsJammed}"); + // 子类特定的停用逻辑 + StopTracking(); // 停止跟踪 + + // Unsubscribe from missile-specific events (KEEP THESE) + SimulationManager.UnsubscribeFromEvent(OnInfraredGuidanceMissileLight); + SimulationManager.UnsubscribeFromEvent(OnInfraredGuidanceMissileLightOff); + + // Removed JammingEvent subscriptions for OnInfraredJamming and HandleSmokeEvent + Debug.WriteLine($"红外测角仪 {Id} 已停用"); + base.Deactivate(); // Handles IsActive and unsubscribes HandleJammingEvent } } - - /// - /// 检查干扰波长是否在测角仪工作波段范围内 - /// - /// 波长(微米) - /// 如果波长范围有重叠则返回true - private static bool IsWavelengthInRange(double wavelength) - { - // 假设红外测角仪的工作波段为3-5μm(中波红外)和8-14μm(长波红外) - // 这里应根据实际的红外测角仪配置来判断 - return (wavelength >= 3 && wavelength <= 5) || // 中波红外 - (wavelength >= 8 && wavelength <= 14); // 长波红外 - } /// - /// 处理烟幕更新或停止事件,触发遮挡状态重新计算 + /// 判断是否应该处理传入的干扰参数 /// - private void HandleSmokeEvent(SimulationEvent evt) // Can use base SimulationEvent type + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) { - RecalculateObscurationStatus(); + // 首先调用基类检查是否支持该干扰类型 (包括 SmokeScreen) + if (!base.ShouldHandleJamming(parameters)) + { + return false; + } + + // 对红外干扰添加波长检查 + if (parameters.Type == JammingType.Infrared) + { + double wavelength = parameters.Wavelength ?? 0; + // 检查波长是否在中波红外 (3-5 微米) 或长波红外 (8-12 微米) 范围内 + bool isCompatible = (wavelength >= 3 && wavelength <= 5) || (wavelength >= 8 && wavelength <= 12); + + if (!isCompatible) + { + Debug.WriteLine($"[InfraredTracker] {Id} 忽略红外干扰:波长 {wavelength}um 不在兼容范围 (3-5um 或 8-12um) 内。", "Jamming"); + return false; + } + } + + // 如果是支持的非红外干扰 (例如烟幕) 或通过了红外波长检查,则返回 true + return true; } /// @@ -422,13 +402,12 @@ namespace ThreatSource.Indicator /// 干扰参数 protected override void HandleJammingApplied(JammingParameters parameters) { - // 记录干扰信息 - Debug.WriteLine($"红外测角仪受到干扰,功率:{parameters.Power}瓦特,类型:{parameters.Type}"); + base.HandleJammingApplied(parameters); // Calls RecalculateObscurationStatus for smoke - // 如果是红外干扰,则停止跟踪 + // 添加子类特定响应:如果是红外干扰,停止跟踪 if (parameters.Type == JammingType.Infrared) { - // 停止跟踪功能 + Debug.WriteLine($"[InfraredTracker] {Id} 受到红外干扰,停止跟踪。", "Jamming"); StopTracking(); } } @@ -439,8 +418,13 @@ namespace ThreatSource.Indicator /// 被清除的干扰类型 protected override void HandleJammingCleared(JammingType type) { - Debug.WriteLine("红外测角仪干扰已清除"); - // 不需要特殊的恢复操作,因为tracker会在Update中自动恢复跟踪能力 + base.HandleJammingCleared(type); // Calls RecalculateObscurationStatus for smoke + + // 红外干扰清除后,不需要特殊操作,UpdateIndicator 会重新评估跟踪状态 + if (type == JammingType.Infrared) + { + Debug.WriteLine($"[InfraredTracker] {Id} 红外干扰已清除。", "Jamming"); + } } } } diff --git a/ThreatSource/src/Indicator/LaserBeamRider.cs b/ThreatSource/src/Indicator/LaserBeamRider.cs index 89a017d..a54d522 100644 --- a/ThreatSource/src/Indicator/LaserBeamRider.cs +++ b/ThreatSource/src/Indicator/LaserBeamRider.cs @@ -37,51 +37,9 @@ namespace ThreatSource.Indicator public double JammingThreshold { get; private set; } = 0.0; /// - /// 获取或设置激光功率 + /// 激光驾束仪配置 /// - /// - /// 单位:瓦特 - /// 影响激光波束的有效作用距离和制导精度 - /// - public double LaserPower { get; private set; } - - - /// - /// 获取或设置激光波长 - /// - /// - /// 单位:微米 - /// 影响激光波束的波长特性 - /// - public double LaserWavelength { get; private set; } = 1.06; - - - /// - /// 获取或设置激光发散角 - /// - /// - /// 单位:毫弧度 - /// 影响激光波束的扩散特性和制导精度 - /// - public double BeamDivergence { get; private set; } = 0.0; - - /// - /// 获取或设置激光编码配置 - /// - /// - /// 包含激光信号的编码信息 - /// 用于抗干扰和安全识别 - /// - public LaserCodeConfig LaserCodeConfig { get; set; } - - /// - /// 获取或设置控制场直径 - /// - /// - /// 单位:米 - /// 定义了激光波束制导场的有效范围 - /// - public double ControlFieldDiameter { get; private set; } + public readonly LaserBeamRiderConfig config; /// /// 获取或设置激光方向 @@ -92,14 +50,6 @@ namespace ThreatSource.Indicator /// public Vector3D LaserDirection { get; private set; } - /// - /// 获取或设置最大导引距离 - /// - /// - /// 单位:米 - /// 超出此距离的导弹将无法接收到有效的制导信号 - /// - public double MaxGuidanceDistance { get; private set; } /// /// 获取激光束是否开启 @@ -129,16 +79,11 @@ namespace ThreatSource.Indicator public LaserBeamRider(string id, string targetId, string missileId, LaserBeamRiderConfig config, MotionParameters motionParameters, ISimulationManager simulationManager) : base(id, motionParameters, simulationManager) { - LaserPower = config.LaserPower; - LaserWavelength = config.LaserWavelength; - ControlFieldDiameter = config.ControlFieldDiameter; - LaserDirection = Vector3D.Zero; - MaxGuidanceDistance = config.MaxGuidanceDistance; - IsActive = false; // 初始状态为非激活 + this.config = config; + LaserDirection = Orientation.ToVector(); IsBeamOn = false; MissileId = missileId; TargetId = targetId; - LaserCodeConfig = config.LaserCodeConfig; JammingThreshold = config.JammingResistanceThreshold; // 设置干扰阈值并添加支持的干扰类型 @@ -156,9 +101,9 @@ namespace ThreatSource.Indicator /// public void AddCodeParameter(string key, object value) { - if (LaserCodeConfig != null) + if (config.LaserCodeConfig != null) { - LaserCodeConfig.Code.Parameters[key] = value; + config.LaserCodeConfig.Code.Parameters[key] = value; } } @@ -168,18 +113,19 @@ namespace ThreatSource.Indicator /// 时间步长,单位:秒 /// /// 更新过程: - /// - 检查电子干扰和烟幕遮挡状态 - /// - 更新激光指向 (仅当未被干扰/遮挡时) - /// - 发布状态更新事件 (仅当未被干扰/遮挡且方向更新时) + /// - 基类 Update 会检查 IsJammed (电子干扰) + /// - 此方法内部检查 IsTargetObscured (烟幕遮挡) + /// - 更新激光指向 (仅当未被遮挡时) + /// - 发布状态更新事件 (仅当未被遮挡且方向更新时) /// protected override void UpdateIndicator(double deltaTime) { - // 检查激光干扰 - if (IsJammed) - { - StopBeamIllumination(); - return; - } + // 基类 Update 已经检查了 IsJammed + // if (IsJammed) + // { + // StopBeamIllumination(); // This logic moved to HandleJammingApplied + // return; + // } if (IsBeamOn) { @@ -210,20 +156,16 @@ namespace ThreatSource.Indicator /// /// /// 激活过程: - /// - 设置激活状态 - /// - 订阅干扰事件 + /// - 调用基类 Activate (处理 IsActive 和 JammingEvent 订阅) /// - 开始激光照射 - /// - 发布激活事件 /// public override void Activate() { if (!IsActive) { - base.Activate(); - SimulationManager.SubscribeToEvent(OnLaserJamming); - SimulationManager.SubscribeToEvent(HandleSmokeEvent); - SimulationManager.SubscribeToEvent(HandleSmokeEvent); - RecalculateObscurationStatus(); + base.Activate(); // Handles IsActive and subscribes HandleJammingEvent + + // 子类特定的激活逻辑 Debug.WriteLine($"激光驾束仪 {Id} 已激活"); StartBeamIllumination(); } @@ -235,58 +177,48 @@ namespace ThreatSource.Indicator /// /// 停用过程: /// - 停止激光照射 - /// - 取消订阅干扰事件 - /// - 清理状态 - /// - 发布停用事件 + /// - 调用基类 Deactivate (处理 IsActive 和 JammingEvent 取消订阅) /// public override void Deactivate() { if (IsActive) { + // 子类特定的停用逻辑 if (IsBeamOn) { StopBeamIllumination(); } - SimulationManager.UnsubscribeFromEvent(OnLaserJamming); - SimulationManager.UnsubscribeFromEvent(HandleSmokeEvent); - SimulationManager.UnsubscribeFromEvent(HandleSmokeEvent); Debug.WriteLine($"激光驾束仪 {Id} 已停用"); - base.Deactivate(); + base.Deactivate(); // Handles IsActive and unsubscribes HandleJammingEvent } } /// - /// 处理激光干扰事件 + /// 判断是否应该处理传入的干扰参数 /// - /// 激光干扰事件数据 - /// - /// 处理过程: - /// - 计算干扰效果 - /// - 验证干扰条件 - /// - 应用干扰参数 - /// - 更新驾束仪状态 - /// - private void OnLaserJamming(LaserJammingEvent evt) + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) { - // 创建干扰参数 - var parameters = new JammingParameters + // 首先调用基类检查是否支持该干扰类型 (包括 SmokeScreen) + if (!base.ShouldHandleJamming(parameters)) { - Type = JammingType.Laser, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 使用JammableComponent进行干扰判断 - // 检查波长匹配(激光特定逻辑) - if (evt.Wavelength == LaserWavelength) - { - ApplyJamming(parameters); - Debug.WriteLine($"干扰状态 - IsJammed: {IsJammed}"); + return false; } + + // 对激光干扰添加波长检查 + if (parameters.Type == JammingType.Laser) + { + // 检查波长匹配 (单位: 微米) + if (Math.Abs((parameters.Wavelength ?? 0) - config.LaserWavelength) > 1e-6) // 使用配置的波长 + { + Debug.WriteLine($"[LaserBeamRider] {Id} 忽略激光干扰:波长 {parameters.Wavelength}um 与工作波长 {config.LaserWavelength}um 不匹配。", "Jamming"); + return false; + } + } + + // 如果是支持的非激光干扰 (例如烟幕) 或通过了激光波长检查,则返回 true + return true; } /// @@ -411,10 +343,9 @@ namespace ThreatSource.Indicator $" 激活状态: {(IsActive ? "激活" : "未激活")}\n" + $" 激光束状态: {(IsBeamOn ? "开启" : "关闭")}\n" + $" 干扰/遮挡状态: {jammingStatusString}\n" + - $" 激光功率: {LaserPower} W\n" + - $" 发散角: {BeamDivergence} rad\n" + - $" 控制场直径: {ControlFieldDiameter} m\n" + - $" 最大导引距离: {MaxGuidanceDistance} m\n"; + $" 激光功率: {config.LaserPower} W\n" + + $" 激光波长: {config.LaserWavelength} μm\n" + + $" 控制场直径: {config.ControlFieldDiameter} m\n"; } /// @@ -423,13 +354,12 @@ namespace ThreatSource.Indicator /// 干扰参数 protected override void HandleJammingApplied(JammingParameters parameters) { - // 记录干扰信息 - Debug.WriteLine($"激光驾束仪受到干扰,功率:{parameters.Power}瓦特,类型:{parameters.Type}"); + base.HandleJammingApplied(parameters); // Calls RecalculateObscurationStatus for smoke - // 如果是激光干扰,则停止激光束照射 + // 添加子类特定响应:如果是激光干扰,停止光束 if (parameters.Type == JammingType.Laser) { - // 在干扰期间停止激光束照射 + Debug.WriteLine($"[LaserBeamRider] {Id} 受到激光干扰,停止光束。", "Jamming"); StopBeamIllumination(); } } @@ -440,24 +370,17 @@ namespace ThreatSource.Indicator /// 被清除的干扰类型 protected override void HandleJammingCleared(JammingType type) { + base.HandleJammingCleared(type); // Calls RecalculateObscurationStatus for smoke + + // 添加子类特定响应:如果是激光干扰清除,并且设备仍激活,尝试启动光束 if (type == JammingType.Laser) { - Debug.WriteLine("激光驾束仪干扰已清除"); - - // 在驾束仪仍然处于激活状态时,恢复激光束照射 - if (IsActive) + Debug.WriteLine($"[LaserBeamRider] {Id} 激光干扰已清除。", "Jamming"); + if (IsActive && !IsJammed) // Check IsJammed in case other jams exist { StartBeamIllumination(); } } } - - /// - /// 处理烟幕更新或停止事件,触发遮挡状态重新计算 - /// - private void HandleSmokeEvent(SimulationEvent evt) // Can use base SimulationEvent type - { - RecalculateObscurationStatus(); - } } } diff --git a/ThreatSource/src/Indicator/LaserDesignator.cs b/ThreatSource/src/Indicator/LaserDesignator.cs index 3159d99..017f343 100644 --- a/ThreatSource/src/Indicator/LaserDesignator.cs +++ b/ThreatSource/src/Indicator/LaserDesignator.cs @@ -45,27 +45,6 @@ namespace ThreatSource.Indicator /// 控制激光发射状态 /// public bool IsIlluminationOn { get; private set; } = false; - - - /// - /// 获取或设置激光功率,单位:瓦特 - /// - /// - /// 定义了激光照射的能量强度 - /// 默认功率为20瓦特 - /// 影响照射距离和制导效果 - /// - public double LaserPower { get; set; } = 20; - - /// - /// 获取或设置激光发散角,单位:弧度 - /// - /// - /// 定义了激光束的扩展角度 - /// 默认发散角为0.5毫弧度 - /// 影响照射面积和能量密度 - /// - public double LaserDivergenceAngle { get; private set; } = 0.5e-3; /// /// 获取或设置激光编码配置 @@ -74,16 +53,7 @@ namespace ThreatSource.Indicator /// 包含激光信号的编码信息 /// 用于抗干扰和安全识别 /// - public LaserCodeConfig LaserCodeConfig { get; set; } - - /// - /// 获取或设置工作波长,单位:微米 - /// - /// - /// 指示器工作所需的工作波长 - /// 用于波长范围匹配检查 - /// - public double LaserWavelength { get; private set; } = 1.06; + public readonly LaserDesignatorConfig config; /// /// 初始化激光指示器的新实例 @@ -108,11 +78,8 @@ namespace ThreatSource.Indicator MissileId = missileId; IsActive = false; IsIlluminationOn = false; - LaserPower = config.LaserPower; - LaserDivergenceAngle = config.LaserDivergenceAngle; - LaserCodeConfig = config.LaserCodeConfig; + this.config = config; JammingThreshold = config.JammingResistanceThreshold; - LaserWavelength = config.LaserWavelength; // 设置干扰阈值并添加支持的干扰类型 InitializeJamming(JammingThreshold, SupportedJammingTypes); @@ -124,19 +91,18 @@ namespace ThreatSource.Indicator /// 时间步长,单位:秒 /// /// 更新过程: - /// - 检查激活状态 - /// - 检查电子干扰和烟幕遮挡状态 - /// - 更新照射状态 - /// - 更新指示器朝向 (仅当未被干扰/遮挡时) - /// - 发布状态事件 (仅当未被干扰/遮挡且照射开启时) + /// - 基类 Update 会检查 IsJammed (电子干扰) + /// - 此方法内部检查 IsTargetObscured (烟幕遮挡) + /// - 更新指示器朝向 (仅当未被遮挡时) + /// - 发布状态事件 (仅当未被遮挡且照射开启时) /// protected override void UpdateIndicator(double deltaTime) { - // 检查激光干扰 - if (IsJammed ) - { - return; - } + // 基类 Update 已经检查了 IsJammed + // if (IsJammed ) + // { + // return; // Specific response (stopping illumination) moved to HandleJammingApplied + // } if (!IsTargetObscured) { @@ -208,50 +174,18 @@ namespace ThreatSource.Indicator } } - /// - /// 处理激光干扰事件 - /// - /// 激光干扰事件数据 - /// - /// 处理过程: - /// - 验证目标ID - /// - 计算干扰效果 - /// - 更新干扰状态 - /// - 处理工作模式 - /// - private void OnLaserJamming(LaserJammingEvent evt) - { - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.Laser, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 使用JammableComponent进行干扰判断 - // 检查波长匹配(激光特定逻辑) - if (evt.Wavelength == LaserWavelength) - { - ApplyJamming(parameters); - Debug.WriteLine($"干扰状态 - IsJammed: {IsJammed}"); - } - } - /// /// 处理指示器被干扰的事件 /// /// 干扰参数 protected override void HandleJammingApplied(JammingParameters parameters) { + base.HandleJammingApplied(parameters); // Calls RecalculateObscurationStatus for smoke + // 实现激光指示器的干扰效果 if (parameters.Type == JammingType.Laser) { - Debug.WriteLine($"激光指示器受到激光干扰,功率:{parameters.Power}瓦特"); + Debug.WriteLine($"[LaserDesignator] {Id} 受到激光干扰,停止照射。", "Jamming"); // 停止激光照射 StopLaserIllumination(); } @@ -263,11 +197,17 @@ namespace ThreatSource.Indicator /// 被清除的干扰类型 protected override void HandleJammingCleared(JammingType type) { - Debug.WriteLine("激光指示器干扰已清除"); - // 如果设备仍处于激活状态,恢复激光照射 - if (IsActive) + base.HandleJammingCleared(type); // Calls RecalculateObscurationStatus for smoke + + // 添加子类特定响应:如果是激光干扰清除,并且设备仍激活,尝试启动照射 + if (type == JammingType.Laser) { - StartLaserIllumination(); + Debug.WriteLine($"[LaserDesignator] {Id} 激光干扰已清除。", "Jamming"); + // 如果设备仍处于激活状态,并且没有其他干扰,恢复激光照射 + if (IsActive && !IsJammed) + { + StartLaserIllumination(); + } } } @@ -276,25 +216,19 @@ namespace ThreatSource.Indicator /// /// /// 激活过程: - /// - 设置激活状态 - /// - 清除干扰状态 + /// - 调用基类 Activate (处理 IsActive 和 JammingEvent 订阅) /// - 开始激光照射 - /// - 订阅相关事件 - /// - 调用基类激活 /// public override void Activate() { if (!IsActive) { - base.Activate(); // Call base Activate first - // Subscribe to Laser Jamming - SimulationManager.SubscribeToEvent(OnLaserJamming); - // Subscribe to Smoke Events - SimulationManager.SubscribeToEvent(HandleSmokeEvent); - SimulationManager.SubscribeToEvent(HandleSmokeEvent); - RecalculateObscurationStatus(); // Initial check - Debug.WriteLine($"激光指示器 {Id} 已激活."); - StartLaserIllumination(); // Start illumination after setup + base.Activate(); // Handles IsActive and subscribes HandleJammingEvent + // Removed JammingEvent subscriptions for OnLaserJamming and HandleSmokeEvent + + // 子类特定的激活逻辑 + Debug.WriteLine($"激光指示器 {Id} 已激活"); + StartLaserIllumination(); } } @@ -303,24 +237,18 @@ namespace ThreatSource.Indicator /// /// /// 停用过程: - /// - 清除激活状态 /// - 停止激光照射 - /// - 取消事件订阅 - /// - 清理工作状态 - /// - 调用基类停用 + /// - 调用基类 Deactivate (处理 IsActive 和 JammingEvent 取消订阅) /// public override void Deactivate() { if (IsActive) { - // Stop illumination first if active - StopLaserIllumination(); - // Unsubscribe from events - SimulationManager.UnsubscribeFromEvent(OnLaserJamming); - SimulationManager.UnsubscribeFromEvent(HandleSmokeEvent); - SimulationManager.UnsubscribeFromEvent(HandleSmokeEvent); - Debug.WriteLine($"激光指示器 {Id} 已停用."); - base.Deactivate(); // Call base Deactivate last + // 子类特定的停用逻辑 + StopLaserIllumination(); + // Removed JammingEvent subscriptions for OnLaserJamming and HandleSmokeEvent + Debug.WriteLine($"激光指示器 {Id} 已停用"); + base.Deactivate(); // Handles IsActive and unsubscribes HandleJammingEvent } } @@ -335,9 +263,9 @@ namespace ThreatSource.Indicator /// public void AddCodeParameter(string key, object value) { - if (LaserCodeConfig != null) + if (config.LaserCodeConfig != null) { - LaserCodeConfig.Code.Parameters[key] = value; + config.LaserCodeConfig.Code.Parameters[key] = value; } } @@ -362,9 +290,9 @@ namespace ThreatSource.Indicator }; // 添加编码信息 - if (LaserCodeConfig != null) + if (config.LaserCodeConfig != null) { - illuminationEvent.LaserCodeConfig = LaserCodeConfig; + illuminationEvent.LaserCodeConfig = config.LaserCodeConfig; } PublishEvent(illuminationEvent); @@ -387,11 +315,31 @@ namespace ThreatSource.Indicator } /// - /// 处理烟幕更新或停止事件,触发遮挡状态重新计算 + /// 判断是否应该处理传入的干扰参数 /// - private void HandleSmokeEvent(SimulationEvent evt) // Can use base SimulationEvent type + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) { - RecalculateObscurationStatus(); + // 首先调用基类检查是否支持该干扰类型 (包括 SmokeScreen) + if (!base.ShouldHandleJamming(parameters)) + { + return false; + } + + // 对激光干扰添加波长检查 + if (parameters.Type == JammingType.Laser) + { + // 检查波长匹配 (单位: 微米) + if (Math.Abs((parameters.Wavelength ?? 0) - config.LaserWavelength) > 1e-6) // 使用配置的波长 + { + Debug.WriteLine($"[LaserDesignator] {Id} 忽略激光干扰:波长 {parameters.Wavelength}um 与工作波长 {config.LaserWavelength}um 不匹配。", "Jamming"); + return false; + } + } + + // 如果是支持的非激光干扰 (例如烟幕) 或通过了激光波长检查,则返回 true + return true; } /// @@ -448,8 +396,8 @@ namespace ThreatSource.Indicator $" 激活状态: {(IsActive ? "激活" : "未激活")}\n" + $" 照射状态: {(IsIlluminationOn ? "正在照射" : "未照射")}\n" + $" 干扰/遮挡状态: {jammingStatusString}\n" + - $" 编码状态: {(LaserCodeConfig != null ? "启用" : "禁用")}\n" + - $" 激光功率: {LaserPower:E} W"; + $" 编码状态: {(config.LaserCodeConfig != null ? "启用" : "禁用")}\n" + + $" 激光功率: {config.LaserPower:E} W"; } } } diff --git a/ThreatSource/src/Jammable/JammableComponent.cs b/ThreatSource/src/Jammable/JammableComponent.cs index b1f1a20..f48c898 100644 --- a/ThreatSource/src/Jammable/JammableComponent.cs +++ b/ThreatSource/src/Jammable/JammableComponent.cs @@ -1,6 +1,10 @@ using ThreatSource.Jammer; using System.Diagnostics; using ThreatSource.Utils; +using System; +using System.Collections.Generic; +using System.Linq; + namespace ThreatSource.Jammable { /// @@ -18,203 +22,19 @@ namespace ThreatSource.Jammable public class JammableComponent : IJammable { /// - /// 干扰处理器接口,用于处理实际的干扰逻辑 + /// 内部干扰处理器实例,管理干扰状态和持续时间 /// - protected interface IJammingProcessor - { - /// - /// 获取当前是否处于被干扰状态 - /// - bool IsJammed { get; } - - /// - /// 设置干扰阈值 - /// - /// 干扰类型 - /// 阈值值(单位:瓦特) - void SetJammingThreshold(JammingType type, double threshold); - - /// - /// 处理干扰 - /// - /// 干扰参数 - /// 干扰是否生效 - bool HandleJamming(JammingParameters parameters); - - /// - /// 清除干扰 - /// - void ClearJamming(); - - /// - /// 更新干扰状态 - /// - /// 时间步长,单位:秒 - void Update(double deltaTime); - } + private readonly JammingHandler _jammingHandler; /// - /// 干扰处理器实现,使用通用的JammingHandler并增强其功能 + /// 干扰阈值字典 /// - protected class JammingProcessor : IJammingProcessor - { - private readonly JammingHandler _jammingHandler; - private readonly Dictionary _jammingThresholds = new Dictionary(); - private readonly JammableComponent _owner; - - /// - /// 获取当前是否处于被干扰状态 - /// - public bool IsJammed => _jammingHandler.IsJammed; - - /// - /// 初始化干扰处理器实例 - /// - /// 所属的可干扰组件 - public JammingProcessor(JammableComponent owner) - { - _owner = owner; - _jammingHandler = new JammingHandlerAdapter(this); - } - - /// - /// 设置干扰阈值 - /// - /// 干扰类型 - /// 阈值值(单位:瓦特) - public void SetJammingThreshold(JammingType type, double threshold) - { - _jammingThresholds[type] = threshold; - } - - /// - /// 判断干扰是否有效(是否超过阈值) - /// - /// 干扰参数 - /// 如果干扰有效返回true,否则返回false - public bool IsJammingEffective(JammingParameters parameters) - { - - // 检查是否支持该干扰类型 - if (!_jammingThresholds.TryGetValue(parameters.Type, out double threshold)) - { - return false; // 不支持的干扰类型 - } - // 烟幕干扰总是有效 - if(parameters.Type == JammingType.SmokeScreen) return true; - - // 处理普通干扰 - // 计算干扰源与设备之间的矢量 - Vector3D devicePosition = _owner._positionProvider(); - Vector3D relativePosition = devicePosition - parameters.SourcePosition; // 从干扰源指向设备 - double distance = relativePosition.Magnitude(); - - Debug.WriteLine($"干扰计算 - 设备位置: {devicePosition}, 干扰源位置: {parameters.SourcePosition}"); - Debug.WriteLine($"干扰计算 - 相对位置: {relativePosition}, 距离: {distance:F2}m"); - - if (distance <= 0) - { - distance = 0.1; // 避免除零错误,设置最小距离 - } - - // 使用球面扩散模型计算接收功率 - // P_received = P_transmitted / (4πd²) - double receivedPower = parameters.Power / (4 * Math.PI * distance * distance); - - Debug.WriteLine($"干扰计算 - 发射功率: {parameters.Power}W, 接收功率: {receivedPower:E6}W, 阈值: {threshold:E6}W"); - - // 计算角度因素(如果干扰波束有方向性) - if (parameters.AngleRange > 0 && distance > 1) - { - // 计算干扰方向与干扰源到设备方向的夹角 - Vector3D jammingToDevice = relativePosition.Normalize(); - double dotProduct = Vector3D.DotProduct(parameters.Direction.Normalize(), jammingToDevice); - double angle = Math.Acos(Math.Clamp(dotProduct, -1.0, 1.0)); - - Debug.WriteLine($"干扰计算 - 干扰方向: {parameters.Direction}, 到设备方向: {jammingToDevice}"); - Debug.WriteLine($"干扰计算 - 点积: {dotProduct:F2}, 夹角: {angle * 180 / Math.PI:F2}°, 波束范围: {parameters.AngleRange * 180 / Math.PI:F2}°"); - - // 如果夹角超出干扰波束范围,降低接收功率 - if (angle > parameters.AngleRange / 2) - { - // 简化模型:角度衰减,超出波束范围接收功率迅速降低 - receivedPower *= 0.01; // 更严格的衰减以确保干扰无效 - Debug.WriteLine($"干扰计算 - 超出波束范围,功率衰减: {receivedPower:F2}W"); - } - } - - // 比较接收功率与阈值 - bool isEffective = receivedPower >= threshold; - Debug.WriteLine($"干扰计算 - 最终结果: {(isEffective ? "有效" : "无效")}"); - return isEffective; - } - - /// - /// 处理干扰 - /// - /// 干扰参数 - /// 干扰是否生效 - public bool HandleJamming(JammingParameters parameters) - { - // 只有当干扰有效时才处理 - if (IsJammingEffective(parameters)) - { - _jammingHandler.HandleJamming(parameters); - return true; - } - return false; - } - - /// - /// 清除干扰 - /// - public void ClearJamming() - { - _jammingHandler.ClearJamming(); - } - - /// - /// 更新干扰状态 - /// - /// 时间步长,单位:秒 - public void Update(double deltaTime) - { - _jammingHandler.Update(deltaTime); - } - - /// - /// JammingHandler适配器类,用于连接JammingHandler和JammingProcessor - /// - private class JammingHandlerAdapter : JammingHandler - { - private readonly JammingProcessor _processor; - - public JammingHandlerAdapter(JammingProcessor processor) - { - _processor = processor; - } - - protected override void OnJammingApplied(JammingParameters parameters) - { - _processor._owner.OnJammingApplied(parameters); - } - - protected override void OnJammingCleared(JammingParameters? parameters) - { - _processor._owner.OnJammingCleared(parameters?.Type ?? JammingType.RadioFrequency); - } - } - } - - /// - /// 干扰处理器实例 - /// - protected readonly IJammingProcessor _jammingProcessor; + private readonly Dictionary _jammingThresholds = new Dictionary(); /// /// 支持的干扰类型列表 /// - protected readonly List _supportedJammingTypes = new List(); + private readonly List _supportedJammingTypes = new List(); /// /// 位置提供委托,用于获取设备当前位置 @@ -222,14 +42,14 @@ namespace ThreatSource.Jammable private readonly Func _positionProvider; /// - /// 干扰应用事件委托 + /// 当干扰被应用时触发 /// - private readonly Action _onJammingApplied; + public event Action? JammingApplied; /// - /// 干扰清除事件委托 + /// 当干扰被清除时触发 /// - private readonly Action _onJammingCleared; + public event Action? JammingCleared; /// /// 获取设备支持的干扰类型 @@ -239,23 +59,20 @@ namespace ThreatSource.Jammable /// /// 获取设备当前是否处于被干扰状态 /// - public bool IsJammed => _jammingProcessor.IsJammed; + public bool IsJammed => _jammingHandler.IsJammed; /// /// 构造函数 /// /// 位置提供委托 - /// 干扰应用事件处理委托 - /// 干扰清除事件处理委托 - public JammableComponent( - Func positionProvider, - Action onJammingApplied, - Action onJammingCleared) + public JammableComponent(Func positionProvider) { _positionProvider = positionProvider ?? throw new ArgumentNullException(nameof(positionProvider)); - _onJammingApplied = onJammingApplied ?? throw new ArgumentNullException(nameof(onJammingApplied)); - _onJammingCleared = onJammingCleared ?? throw new ArgumentNullException(nameof(onJammingCleared)); - _jammingProcessor = new JammingProcessor(this); + _jammingHandler = new JammingHandler(); + + // Subscribe to internal handler events to trigger own public events + _jammingHandler.JammingApplied += HandleInternalJammingApplied; + _jammingHandler.JammingCleared += HandleInternalJammingCleared; } /// @@ -264,7 +81,7 @@ namespace ThreatSource.Jammable /// 时间步长,单位:秒 public void UpdateJammingStatus(double deltaTime) { - _jammingProcessor.Update(deltaTime); + _jammingHandler.Update(deltaTime); } /// @@ -274,7 +91,7 @@ namespace ThreatSource.Jammable /// 阈值值(单位:瓦特) public void SetJammingThreshold(JammingType type, double threshold) { - _jammingProcessor.SetJammingThreshold(type, threshold); + _jammingThresholds[type] = threshold; } /// @@ -300,40 +117,102 @@ namespace ThreatSource.Jammable // 检查是否支持该类型的干扰 if (_supportedJammingTypes.Contains(parameters.Type)) { - _jammingProcessor.HandleJamming(parameters); + if (IsJammingEffective(parameters)) + { + _jammingHandler.HandleJamming(parameters); + } } else { - Console.WriteLine($"[可干扰组件] 不支持的干扰类型: {parameters.Type}"); + Console.WriteLine($"[JammableComponent] Unsupported jamming type: {parameters.Type}"); } } /// /// 清除干扰 /// - /// 要清除的干扰类型 + /// 要清除的干扰类型 (Note: JammingHandler clears all current jamming regardless of type) public void ClearJamming(JammingType type) { - // 这里简化处理,直接清除当前干扰 - _jammingProcessor.ClearJamming(); + _jammingHandler.ClearJamming(); } /// - /// 当干扰被应用时调用 + /// 判断干扰是否有效(是否超过阈值和物理条件) /// /// 干扰参数 - protected void OnJammingApplied(JammingParameters parameters) + /// 如果干扰有效返回true,否则返回false + public bool IsJammingEffective(JammingParameters parameters) { - _onJammingApplied(parameters); - } - - /// - /// 当干扰被清除时调用 - /// - /// 被清除的干扰类型 - protected void OnJammingCleared(JammingType type) - { - _onJammingCleared(type); + // 检查是否支持该干扰类型且定义了阈值 + if (!_jammingThresholds.TryGetValue(parameters.Type, out double threshold)) + { + // 也检查 _supportedJammingTypes 以保持一致性?如果 AddSupported 确保两者都存在,则冗余。 + if(!_supportedJammingTypes.Contains(parameters.Type)) + { + Debug.WriteLine($"[干扰有效性检查] 不支持干扰类型 {parameters.Type}。"); + return false; // 不支持的类型 + } + // 如果支持但不知何故没有阈值?默认为无效还是抛出异常? + Debug.WriteLine($"[干扰有效性检查] 支持的类型 {parameters.Type} 未找到阈值。假设无效。"); + return false; + } + + // 烟幕干扰总是有效,如果支持的话 + if (parameters.Type == JammingType.SmokeScreen) + { + Debug.WriteLine($"[干扰有效性检查] 烟幕干扰有效。"); + return true; + } + + // 基于功率、距离、角度等计算有效性 + Vector3D devicePosition = _positionProvider(); + Vector3D relativePosition = devicePosition - parameters.SourcePosition; // 从干扰源指向设备的矢量 + double distance = relativePosition.Magnitude(); + + Debug.WriteLine($"干扰计算 - 设备位置: {devicePosition}, 干扰源位置: {parameters.SourcePosition}"); + Debug.WriteLine($"干扰计算 - 相对位置: {relativePosition}, 距离: {distance:F2}m"); + + // 恢复原始逻辑:避免除零错误 + if (distance <= 0) + { + distance = 0.1; // 设置最小距离 + Debug.WriteLine($"干扰计算 - 调整近零距离为 {distance}m"); + } + + // 球面扩散损耗模型: P_received = P_transmitted / (4 * pi * d^2) + double receivedPower = parameters.Power / (4 * Math.PI * distance * distance); + + Debug.WriteLine($"干扰计算 - 发射功率: {parameters.Power}W, 接收功率: {receivedPower:E6}W, 阈值: {threshold:E6}W"); + + // 如果干扰源有方向性,则考虑角度因素 (恢复原始逻辑:仅在距离 > 1 时检查) + if (parameters.AngleRange > 0 && distance > 1) + { + // 恢复原始逻辑:直接计算方向和角度 + Vector3D jammerDirection = parameters.Direction.Normalize(); + Vector3D jammerToDeviceDirection = relativePosition.Normalize(); + + // 直接进行计算,不预先检查 IsZero + double dotProduct = Vector3D.DotProduct(jammerDirection, jammerToDeviceDirection); + // 钳制点积以避免 Acos 的参数超出 [-1, 1] 范围 + double angle = Math.Acos(Math.Clamp(dotProduct, -1.0, 1.0)); // 干扰波束方向与到设备方向之间的夹角 + + Debug.WriteLine($"干扰计算 - 干扰器方向: {jammerDirection}, 到设备方向: {jammerToDeviceDirection}"); + Debug.WriteLine($"干扰计算 - 点积: {dotProduct:F2}, 夹角: {angle * 180 / Math.PI:F2} 度, 波束范围: {parameters.AngleRange * 180 / Math.PI:F2} 度"); + + // 如果到设备的角度超出了干扰器波束半角,则降低有效性 (恢复原始逻辑) + if (angle > parameters.AngleRange / 2) + { + // 简化模型:如果超出波束范围,则大幅降低接收功率 + receivedPower *= 0.01; // 衰减因子 (与之前嵌套类中的逻辑一致) + Debug.WriteLine($"干扰计算 - 超出波束角度。衰减后接收功率: {receivedPower:E6}W"); + } + } + + // 将接收功率与该干扰类型的阈值进行比较 + bool isEffective = receivedPower >= threshold; + Debug.WriteLine($"干扰计算 - 最终结果: {(isEffective ? "有效" : "无效")}"); + return isEffective; } /// @@ -341,36 +220,35 @@ namespace ThreatSource.Jammable /// /// 配置中的干扰抗性阈值,单位:瓦特 /// 支持的干扰类型,默认为所有类型 - public void LoadJammingConfigFromThreshold(double jammingResistanceThreshold, + public void LoadJammingConfigFromThreshold(double jammingResistanceThreshold, IEnumerable? supportedTypes = null) { - // 如果未指定支持的干扰类型,则默认支持所有类型 - if (supportedTypes == null) + IEnumerable typesToSupport = supportedTypes ?? Enum.GetValues(typeof(JammingType)).Cast(); + + foreach (JammingType jammingType in typesToSupport) { - // 添加所有干扰类型 - foreach (JammingType jammingType in Enum.GetValues(typeof(JammingType))) - { - AddSupportedJammingType(jammingType, jammingResistanceThreshold); - } - } - else - { - // 添加指定的干扰类型 - foreach (JammingType jammingType in supportedTypes) - { - AddSupportedJammingType(jammingType, jammingResistanceThreshold); - } + AddSupportedJammingType(jammingType, jammingResistanceThreshold); } } /// - /// 判断干扰是否有效 + /// 处理内部 JammingHandler 的 JammingApplied 事件 /// - /// 干扰参数 - /// 如果干扰有效返回true,否则返回false - public bool IsJammingEffective(JammingParameters parameters) + private void HandleInternalJammingApplied(JammingParameters parameters) { - return ((JammingProcessor)_jammingProcessor).IsJammingEffective(parameters); + JammingApplied?.Invoke(parameters); + } + + /// + /// 处理内部 JammingHandler 的 JammingCleared 事件 + /// + private void HandleInternalJammingCleared(JammingParameters? parameters) + { + // 触发公共事件,如果可用,则提供类型 + if (parameters != null) + { + JammingCleared?.Invoke(parameters.Type); + } } } } \ No newline at end of file diff --git a/ThreatSource/src/Jammable/JammingHandler.cs b/ThreatSource/src/Jammable/JammingHandler.cs index aeb6b73..68387f1 100644 --- a/ThreatSource/src/Jammable/JammingHandler.cs +++ b/ThreatSource/src/Jammable/JammingHandler.cs @@ -1,11 +1,12 @@ using ThreatSource.Jammer; +using System; // Added for Action delegate namespace ThreatSource.Jammable { /// /// 干扰处理基类 /// - public abstract class JammingHandler + public class JammingHandler { /// /// 是否处于被干扰状态 @@ -22,6 +23,16 @@ namespace ThreatSource.Jammable /// private double _elapsedTime; + /// + /// 当干扰被应用时触发 + /// + public event Action? JammingApplied; + + /// + /// 当干扰被清除时触发 + /// + public event Action? JammingCleared; + /// /// 更新干扰状态 /// @@ -32,7 +43,7 @@ namespace ThreatSource.Jammable { _elapsedTime += deltaTime; // 检查是否超时 - if (_elapsedTime >= CurrentJamming.Duration) + if (_elapsedTime >= CurrentJamming.Duration.Value) { ClearJamming(); } @@ -48,7 +59,7 @@ namespace ThreatSource.Jammable _elapsedTime = 0; IsJammed = true; CurrentJamming = parameters; - OnJammingApplied(parameters); + OnJammingApplied(parameters); } /// @@ -62,20 +73,29 @@ namespace ThreatSource.Jammable _elapsedTime = 0; var oldJamming = CurrentJamming; CurrentJamming = null; - OnJammingCleared(oldJamming); + OnJammingCleared(oldJamming); } } /// - /// 当干扰被应用时调用 + /// 当干扰被应用时调用(内部辅助方法,触发事件) /// /// 干扰参数 - protected abstract void OnJammingApplied(JammingParameters parameters); + protected virtual void OnJammingApplied(JammingParameters parameters) + { + JammingApplied?.Invoke(parameters); + } /// - /// 当干扰被清除时调用 + /// 当干扰被清除时调用(内部辅助方法,触发事件) /// /// 被清除的干扰参数 - protected abstract void OnJammingCleared(JammingParameters? parameters); + protected virtual void OnJammingCleared(JammingParameters? parameters) + { + if (parameters != null) + { + JammingCleared?.Invoke(parameters); + } + } } } \ No newline at end of file diff --git a/ThreatSource/src/Jammer/BaseJammer.cs b/ThreatSource/src/Jammer/BaseJammer.cs index 9bbaa4b..6c67d1d 100644 --- a/ThreatSource/src/Jammer/BaseJammer.cs +++ b/ThreatSource/src/Jammer/BaseJammer.cs @@ -18,7 +18,7 @@ namespace ThreatSource.Jammer /// /// 当前干扰参数 /// - protected JammingParameters? CurrentParameters { get; private set; } + protected JammingParameters? CurrentParameters { get; set; } /// /// 干扰器类型 @@ -53,6 +53,30 @@ namespace ThreatSource.Jammer IsJamming = false; } + /// + /// 激活干扰器 + /// + public override void Activate() + { + IsActive = true; + if (!IsJamming && CurrentParameters != null) + { + StartJamming(CurrentParameters); + } + } + + /// + /// 禁用干扰器 + /// + public override void Deactivate() + { + IsActive = false; + if (IsJamming) + { + StopJamming(); + } + } + /// /// 获取干扰器的当前运行状态 /// @@ -93,7 +117,7 @@ namespace ThreatSource.Jammer IsJamming = true; // 发布干扰开始事件 - PublishJammingStartedEvent(parameters); + PublishJammingEvent(parameters); Console.WriteLine($"干扰器 {Id} 开始 {parameters.Type} 类型的干扰,功率:{parameters.Power}W"); } @@ -162,17 +186,34 @@ namespace ThreatSource.Jammer /// /// 发布干扰开始事件 /// - protected abstract void PublishJammingStartedEvent(JammingParameters parameters); + protected void PublishJammingEvent(JammingParameters parameters) + { + var jammingEvent = new JammingEvent + { + SenderId = Id, + Parameters = parameters + }; + SimulationManager.PublishEvent(jammingEvent); + } /// - /// 发布干扰更新事件 + /// 创建干扰参数 /// - protected abstract void PublishJammingUpdateEvent(JammingParameters parameters); + /// 干扰参数 + protected abstract JammingParameters CreateJammingParameters(); /// /// 发布干扰结束事件 /// - protected abstract void PublishJammingStoppedEvent(JammingParameters parameters); + protected void PublishJammingStoppedEvent(JammingParameters parameters) + { + var stoppedEvent = new JammingStoppedEvent + { + SenderId = Id, + Parameters = parameters + }; + SimulationManager.PublishEvent(stoppedEvent); + } /// /// 获取干扰器状态信息 diff --git a/ThreatSource/src/Jammer/InfraredJammer.cs b/ThreatSource/src/Jammer/InfraredJammer.cs new file mode 100644 index 0000000..7589791 --- /dev/null +++ b/ThreatSource/src/Jammer/InfraredJammer.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.Linq; +using ThreatSource.Simulation; +using ThreatSource.Utils; + +namespace ThreatSource.Jammer +{ + /// + /// 红外干扰器实现 + /// + public class InfraredJammer : BaseJammer + { + /// + /// 红外干扰器配置 + /// + public readonly InfraredJammerConfig config; + + /// + /// 干扰器类型 + /// + protected override JammerType Type => JammerType.Infrared; + + /// + /// 支持的干扰类型 + /// + public override IEnumerable SupportedJammingTypes => [JammingType.Infrared]; + + /// + /// 初始化红外干扰器的新实例 + /// + /// 干扰器ID + /// 红外干扰器配置 + /// 初始运动参数 + /// 仿真管理器实例 + public InfraredJammer(string id, InfraredJammerConfig config, MotionParameters motionParameters, ISimulationManager manager) + : base(id, motionParameters, manager) + { + this.config = config; + } + + /// + /// 创建干扰参数 + /// + protected override JammingParameters CreateJammingParameters() + { + return new JammingParameters + { + Type = JammingType.Infrared, + JammerId = Id, + Power = config.Power, + Wavelength = config.Wavelength, + Direction = Orientation.ToVector(), + SourcePosition = Position, + AngleRange = config.AngleRange, + Mode = config.Mode, + Duration = config.Duration + }; + } + } +} \ No newline at end of file diff --git a/ThreatSource/src/Jammer/JammingParameters.cs b/ThreatSource/src/Jammer/JammingParameters.cs index 7895bc5..152ab6d 100644 --- a/ThreatSource/src/Jammer/JammingParameters.cs +++ b/ThreatSource/src/Jammer/JammingParameters.cs @@ -17,6 +17,11 @@ namespace ThreatSource.Jammer /// public string JammerId { get; set; } = ""; + /// + /// 干扰目标ID + /// + public string? TargetId { get; set; } + /// /// 干扰功率,单位:瓦特 /// @@ -42,9 +47,9 @@ namespace ThreatSource.Jammer public double AngleRange { get; set; } /// - /// 干扰频率,单位:赫兹 + /// 干扰波长,单位:微米 /// - public double Frequency { get; set; } + public double? Wavelength { get; set; } /// /// 持续时间,单位:秒,null表示持续干扰 diff --git a/ThreatSource/src/Jammer/LaserDecoy.cs b/ThreatSource/src/Jammer/LaserDecoy.cs index 4fdeb04..fbe4fef 100644 --- a/ThreatSource/src/Jammer/LaserDecoy.cs +++ b/ThreatSource/src/Jammer/LaserDecoy.cs @@ -27,40 +27,10 @@ namespace ThreatSource.Jammer public readonly LaserDecoyConfig config; /// - /// 获取或设置诱偏源ID + /// 干扰源ID /// - public string SourceId { get; set; } + private readonly string SourceId; - /// - /// 获取或设置诱偏源功率,单位:瓦特 - /// - public double DecoyPower { get; set; } - - /// - /// 获取或设置诱偏激光发散角,单位:弧度 - /// - public double DecoyLaserDivergenceAngle { get; set; } - - /// - /// 获取或设置反射系数 - /// - public double ReflectionCoefficient { get; set; } - - /// - /// 获取或设置生命周期,单位:秒 - /// - public double LifeTime { get; set; } - - /// - /// 获取创建时间 - /// - public DateTime CreationTime { get; private set; } - - /// - /// 获取或设置有效反射面积,单位:平方米 - /// - public double ReflectiveArea { get; set; } - /// /// 初始化激光诱偏目标的新实例 /// @@ -74,19 +44,12 @@ namespace ThreatSource.Jammer { this.config = config; SourceId = sourceId; - DecoyPower = config.DecoyPower; - DecoyLaserDivergenceAngle = config.DecoyLaserDivergenceAngle; - ReflectionCoefficient = config.ReflectionCoefficient; - ReflectiveArea = config.ReflectiveArea; - LifeTime = config.LifeTime; - - CreationTime = DateTime.Now; } /// /// 创建烟幕干扰参数 /// - private JammingParameters CreateJammingParameters() + protected override JammingParameters CreateJammingParameters() { SimulationElement source = SimulationManager.GetEntityById(SourceId) as SimulationElement ?? throw new Exception("诱偏源不存在"); Vector3D sourcePosition = source.Position; @@ -94,128 +57,27 @@ namespace ThreatSource.Jammer return new JammingParameters { Type = JammingType.Decoy, - Power = DecoyPower, + JammerId = Id, + Power = config.DecoyPower, + Wavelength = config.DecoyWavelength, SourcePosition = sourcePosition, Direction = Orientation.ToVector(), DecoyPosition = Position, - AngleRange = DecoyLaserDivergenceAngle, - Duration = LifeTime, - ReflectiveArea = ReflectiveArea, - ReflectionCoefficient = ReflectionCoefficient, + AngleRange = config.DecoyLaserDivergenceAngle, + Duration = config.LifeTime, + ReflectiveArea = config.ReflectiveArea, + ReflectionCoefficient = config.ReflectionCoefficient, StartTime = DateTime.UtcNow }; } - /// - /// 检查诱偏目标是否仍然活跃 - /// - /// 如果目标仍然活跃返回true,否则返回false - public bool IsDecoyActive() - { - return (DateTime.Now - CreationTime).TotalSeconds < LifeTime; - } - - /// - /// 激活激光诱偏目标 - /// - public override void Activate() - { - IsActive = true; - if (!IsJamming) - { - var parameters = CreateJammingParameters(); - StartJamming(parameters); - } - } - - /// - /// 禁用激光诱偏目标 - /// - public override void Deactivate() - { - IsActive = false; - if (IsJamming) - { - StopJamming(); - } - } - - /// - /// 更新诱偏目标状态 - /// - /// 时间步长,单位:秒 - public override void Update(double deltaTime) - { - base.Update(deltaTime); - // 如果生命周期结束,从仿真中移除 - if (!IsDecoyActive()) - { - Deactivate(); - } - } - - /// - /// 更新干扰状态 - /// - /// - protected override void UpdateJamming(double deltaTime) - { - if (IsJamming) - { - PublishJammingUpdateEvent(CreateJammingParameters()); - } - } - - /// - /// 发布干扰开始事件 - /// - protected override void PublishJammingStartedEvent(JammingParameters parameters) - { - PublishLaserDecoyEvent(); - } - - /// - /// 发布干扰更新事件 - /// - protected override void PublishJammingUpdateEvent(JammingParameters parameters) - { - PublishLaserDecoyEvent(); - } - - /// - /// 发布干扰停止事件 - /// - protected override void PublishJammingStoppedEvent(JammingParameters parameters) - { - PublishLaserDecoyStopEvent(); - } - - private void PublishLaserDecoyEvent() - { - var evt = new LaserDecoyEvent - { - LaserDecoyId = Id, - SourceId = SourceId - }; - PublishEvent(evt); - } - - private void PublishLaserDecoyStopEvent() - { - var evt = new LaserDecoyStopEvent - { - LaserDecoyId = Id - }; - PublishEvent(evt); - } - /// /// 获取激光诱偏目标状态 /// /// 激光诱偏目标状态 public override string GetStatus() { - return base.GetStatus() + $"诱饵位置: {Position}, 源 ID: {SourceId}, 诱偏功率: {DecoyPower}, 诱偏激光发散角: {DecoyLaserDivergenceAngle}, 反射系数: {ReflectionCoefficient}, 有效反射面积: {ReflectiveArea}, 生命周期: {LifeTime}\n"; + return base.GetStatus() + $"诱饵位置: {Position}, 源 ID: {SourceId}, 诱偏功率: {config.DecoyPower}, 诱偏激光发散角: {config.DecoyLaserDivergenceAngle}, 反射系数: {config.ReflectionCoefficient}, 有效反射面积: {config.ReflectiveArea}, 生命周期: {config.LifeTime}\n"; } } } \ No newline at end of file diff --git a/ThreatSource/src/Jammer/LaserJammer.cs b/ThreatSource/src/Jammer/LaserJammer.cs new file mode 100644 index 0000000..cee34aa --- /dev/null +++ b/ThreatSource/src/Jammer/LaserJammer.cs @@ -0,0 +1,59 @@ +using System.Collections.Generic; +using System.Linq; +using ThreatSource.Simulation; +using ThreatSource.Utils; // Assuming JammingParameters is here or in Jammer namespace + +namespace ThreatSource.Jammer +{ + /// + /// 激光干扰器实现 + /// + public class LaserJammer : BaseJammer + { + /// + /// 干扰器类型 + /// + protected override JammerType Type => JammerType.Laser; + + /// + /// 支持的干扰类型 + /// + public override IEnumerable SupportedJammingTypes => [JammingType.Laser]; + + /// + /// 激光干扰器配置 + /// + public readonly LaserJammerConfig config; + + /// + /// 初始化激光干扰器的新实例 + /// + /// 干扰器ID + /// 激光干扰器配置 + /// 初始运动参数 + /// 仿真管理器实例 + public LaserJammer(string id, LaserJammerConfig config, MotionParameters motionParameters, ISimulationManager manager) + : base(id, motionParameters, manager) + { + this.config = config; + } + + /// + /// 创建干扰参数 + /// + protected override JammingParameters CreateJammingParameters() + { + return new JammingParameters + { + Type = JammingType.Laser, + JammerId = Id, + Power = config.Power, + Wavelength = config.Wavelength, + Direction = Orientation.ToVector(), + SourcePosition = Position, + Mode = config.Mode, + Duration = config.Duration + }; + } + } +} \ No newline at end of file diff --git a/ThreatSource/src/Jammer/MillimeterWaveJammer.cs b/ThreatSource/src/Jammer/MillimeterWaveJammer.cs new file mode 100644 index 0000000..aba88ed --- /dev/null +++ b/ThreatSource/src/Jammer/MillimeterWaveJammer.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Linq; +using ThreatSource.Simulation; +using ThreatSource.Utils; + +namespace ThreatSource.Jammer +{ + /// + /// 毫米波干扰器实现 + /// + public class MillimeterWaveJammer : BaseJammer + { + /// + /// 干扰器类型 + /// + protected override JammerType Type => JammerType.MillimeterWave; + + /// + /// 支持的干扰类型 + /// + public override IEnumerable SupportedJammingTypes => [JammingType.MillimeterWave]; + + /// + /// 毫米波干扰器配置 + /// + public readonly MillimeterWaveJammerConfig config; + + /// + /// 初始化毫米波干扰器的新实例 + /// + /// 干扰器ID + /// 毫米波干扰器配置 + /// 初始运动参数 + /// 仿真管理器实例 + public MillimeterWaveJammer(string id, MillimeterWaveJammerConfig config, MotionParameters motionParameters, ISimulationManager manager) + : base(id, motionParameters, manager) + { + this.config = config; + } + + /// + /// 创建干扰参数 + /// + protected override JammingParameters CreateJammingParameters() + { + return new JammingParameters + { + Type = JammingType.MillimeterWave, + JammerId = Id, + Power = config.Power, + Wavelength = config.Wavelength, + Direction = Orientation.ToVector(), + SourcePosition = Position, + Mode = config.Mode, + Duration = config.Duration + }; + } + + // 可在此处重写 UpdateJamming(double deltaTime) 以实现毫米波干扰的特定效果更新逻辑 + } +} \ No newline at end of file diff --git a/ThreatSource/src/Jammer/SmokeGrenade.cs b/ThreatSource/src/Jammer/SmokeGrenade.cs index c6e1f37..6c257c5 100644 --- a/ThreatSource/src/Jammer/SmokeGrenade.cs +++ b/ThreatSource/src/Jammer/SmokeGrenade.cs @@ -74,7 +74,7 @@ namespace ThreatSource.Jammer /// /// 创建烟幕干扰参数 /// - private JammingParameters CreateJammingParameters() + protected override JammingParameters CreateJammingParameters() { return new JammingParameters { @@ -145,7 +145,7 @@ namespace ThreatSource.Jammer CurrentParameters.SmokeDiameter = null; } // 发布烟幕状态更新事件 - PublishSmokeEvent(); + PublishJammingEvent(CurrentParameters); // 检查是否需要停止烟幕效果 if (_elapsedTime >= config.Duration || @@ -155,57 +155,6 @@ namespace ThreatSource.Jammer } } } - - /// - /// 发布干扰开始事件 - /// - protected override void PublishJammingStartedEvent(JammingParameters parameters) - { - PublishSmokeEvent(); - } - - /// - /// 发布干扰更新事件 - /// - protected override void PublishJammingUpdateEvent(JammingParameters parameters) - { - PublishSmokeEvent(); - } - - /// - /// 发布干扰结束事件 - /// - protected override void PublishJammingStoppedEvent(JammingParameters parameters) - { - PublishSmokeStopEvent(); - } - - /// - /// 发布烟幕事件 - /// - private void PublishSmokeEvent() - { - if (CurrentParameters == null) return; - - var evt = new SmokeScreenEvent - { - SmokeGrenadeId = Id - }; - - PublishEvent(evt); - } - - /// - /// 发布烟幕停止事件 - /// - private void PublishSmokeStopEvent() - { - var evt = new SmokeScreenStopEvent - { - SmokeGrenadeId = Id - }; - PublishEvent(evt); - } /// /// 计算观察者到目标的视线穿过烟雾的透射率 diff --git a/ThreatSource/src/MIssile/LaserBeamRiderMissile.cs b/ThreatSource/src/MIssile/LaserBeamRiderMissile.cs index 473fdb2..0d9a999 100644 --- a/ThreatSource/src/MIssile/LaserBeamRiderMissile.cs +++ b/ThreatSource/src/MIssile/LaserBeamRiderMissile.cs @@ -101,7 +101,7 @@ namespace ThreatSource.Missile if (evt?.LaserBeamRiderId != null) { LaserBeamRider laserBeamRider = SimulationManager.GetEntityById(evt.LaserBeamRiderId) as LaserBeamRider ?? throw new Exception("激光驾束仪不存在"); - guidanceSystem?.UpdateLaserBeamRider(laserBeamRider.Position, laserBeamRider.LaserDirection, laserBeamRider.LaserPower); + guidanceSystem?.UpdateLaserBeamRider(laserBeamRider.Position, laserBeamRider.LaserDirection, laserBeamRider.config.LaserPower); } } diff --git a/ThreatSource/src/Sensor/InfraredDetector.cs b/ThreatSource/src/Sensor/InfraredDetector.cs index 0d69604..09d84ca 100644 --- a/ThreatSource/src/Sensor/InfraredDetector.cs +++ b/ThreatSource/src/Sensor/InfraredDetector.cs @@ -106,77 +106,6 @@ namespace ThreatSource.Sensor InitializeJamming(config.JammingResistanceThreshold, [JammingType.Infrared]); } - /// - /// 激活红外探测器 - /// - /// - /// 激活红外探测器,设置传感器数据为活动状态 - /// - public override void Activate() - { - base.Activate(); - SimulationManager.SubscribeToEvent(OnInfraredJamming); - } - - /// - /// 停用红外探测器 - /// - /// - /// 停用红外探测器,取消事件订阅 - /// - public override void Deactivate() - { - base.Deactivate(); - SimulationManager.UnsubscribeFromEvent(OnInfraredJamming); - } - - /// - /// 处理红外干扰事件 - /// - /// 红外干扰事件数据 - private void OnInfraredJamming(InfraredJammingEvent evt) - { - // 检查波长匹配(红外特定逻辑) - bool isWavelengthCompatible = IsWavelengthCompatible(evt.Wavelength); - - if (!isWavelengthCompatible) - { - System.Diagnostics.Debug.WriteLine($"红外干扰波长 {evt.Wavelength}um 与红外探测器波段 {Band} 不匹配,忽略干扰"); - return; - } - - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.Infrared, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - ApplyJamming(parameters); - Debug.WriteLine($"干扰状态 - IsJammed: {IsJammed}"); - } - - /// - /// 检查干扰波长是否与红外探测器波段匹配 - /// - /// 干扰波长(微米) - /// 如果波长匹配返回true,否则返回false - private bool IsWavelengthCompatible(double wavelength) - { - // 根据红外探测器的波段确定能接收的波长范围 - return Band switch - { - InfraredBand.Long => wavelength >= 8 && wavelength <= 14,// 远红外波段(约8-14微米) - InfraredBand.Medium => wavelength >= 3 && wavelength <= 6,// 中红外波段(约3-6微米) - _ => false,// 未知波段,默认不匹配 - }; - } - /// /// 更新红外探测器的工作状态 /// @@ -247,16 +176,64 @@ namespace ThreatSource.Sensor return sensorData; } + /// + /// 判断是否应该处理传入的干扰参数 + /// + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) + { + // 首先调用基类检查是否支持该干扰类型 + if (!base.ShouldHandleJamming(parameters)) + { + return false; + } + + // 检查干扰类型是否为红外 + if (parameters.Type == JammingType.Infrared) + { + // 检查波长是否与工作波段匹配 (单位: 微米) + if (!IsWavelengthCompatible(parameters.Wavelength ?? 0)) + { + Debug.WriteLine($"[InfraredDetector] 忽略干扰:波长 {parameters.Wavelength}um 与工作波段 {Band} 不匹配。", "Jamming"); + return false; + } + } + + // 如果所有检查通过,则处理此干扰 + return true; + } + + /// + /// 检查干扰波长是否与红外探测器波段匹配 + /// + /// 干扰波长(微米) + /// 如果波长匹配返回true,否则返回false + private bool IsWavelengthCompatible(double wavelength) + { + // 根据红外探测器的波段确定能接收的波长范围 + return Band switch + { + InfraredBand.Long => wavelength >= 8 && wavelength <= 12,// 远红外波段(约8-12微米) + InfraredBand.Medium => wavelength >= 3 && wavelength <= 5,// 中红外波段(约3-5微米) + _ => false,// 未知波段,默认不匹配 + }; + } + /// /// 处理红外干扰应用 /// protected override void HandleJammingApplied(JammingParameters parameters) { base.HandleJammingApplied(parameters); + // 基类 JammableComponent 和 Sensor 已经处理了 IsJammed 状态 + // 这里只处理探测器特定的响应 if (parameters.Type == JammingType.Infrared) { - Debug.WriteLine($"红外探测器受到干扰,功率:{parameters.Power}瓦特"); + // 不需要再次检查波长,因为 ShouldHandleJamming 已经做过 + Debug.WriteLine($"[InfraredDetector] 红外探测器受到有效干扰,功率:{parameters.Power}瓦特", "Jamming"); sensorData.IsValid = false; + // IsTargetDetected 会在下一次 UpdateSensor 时根据干扰状态决定,这里不直接修改 } } @@ -266,10 +243,20 @@ namespace ThreatSource.Sensor protected override void HandleJammingCleared(JammingType type) { base.HandleJammingCleared(type); + // 基类 JammableComponent 和 Sensor 已经处理了 IsJammed 状态 + // 这里只处理探测器特定的响应 if (type == JammingType.Infrared) { - Debug.WriteLine("红外探测器干扰已清除"); - sensorData.IsValid = true; + Debug.WriteLine("[InfraredDetector] 红外探测器干扰已清除", "Jamming"); + // 只有在整体未被干扰时才恢复有效状态 + if (!IsJammed) + { + sensorData.IsValid = true; + } + else + { + sensorData.IsValid = false; // 如果仍被干扰,保持无效 + } } } } diff --git a/ThreatSource/src/Sensor/LaserRangefinder.cs b/ThreatSource/src/Sensor/LaserRangefinder.cs index c527552..28321e6 100644 --- a/ThreatSource/src/Sensor/LaserRangefinder.cs +++ b/ThreatSource/src/Sensor/LaserRangefinder.cs @@ -157,51 +157,31 @@ namespace ThreatSource.Sensor } /// - /// 激活激光测距仪 + /// 判断是否应该处理传入的干扰参数 /// - public override void Activate() + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) { - base.Activate(); - SimulationManager.SubscribeToEvent(OnLaserJamming); - } - - /// - /// 停用激光测距仪 - /// - public override void Deactivate() - { - base.Deactivate(); - SimulationManager.UnsubscribeFromEvent(OnLaserJamming); - } - - /// - /// 处理激光干扰事件 - /// - /// 激光干扰事件数据 - private void OnLaserJamming(LaserJammingEvent evt) - { - // 检查波长匹配(激光特定逻辑) - bool isWavelengthCompatible = IsWavelengthCompatible(evt.Wavelength); - - if (!isWavelengthCompatible) + // 首先调用基类检查是否支持该干扰类型 + if (!base.ShouldHandleJamming(parameters)) { - Debug.WriteLine($"激光干扰波长 {evt.Wavelength}um 与激光测距仪波段 {Wavelength}um 不匹配,忽略干扰"); - return; + return false; } - // 创建干扰参数 - var parameters = new JammingParameters + // 检查干扰类型是否为激光 + if (parameters.Type == JammingType.Laser) { - Type = JammingType.Laser, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; + // 检查波长是否与工作波长匹配 (单位: 微米) + if (!IsWavelengthCompatible(parameters.Wavelength ?? 0)) + { + Debug.WriteLine($"[LaserRangefinder] 忽略干扰:波长 {parameters.Wavelength}um 与工作波长 {Wavelength}um 不匹配。", "Jamming"); + return false; + } + } - ApplyJamming(parameters); + // 如果所有检查通过,则处理此干扰 + return true; } /// @@ -222,9 +202,12 @@ namespace ThreatSource.Sensor protected override void HandleJammingApplied(JammingParameters parameters) { base.HandleJammingApplied(parameters); + // 基类 JammableComponent 和 Sensor 已经处理了 IsJammed 状态 + // 这里只处理测距仪特定的响应 if (parameters.Type == JammingType.Laser) - { - Debug.WriteLine($"激光测距仪受到干扰,功率:{parameters.Power}瓦特"); + { + // 不需要再次检查波长,因为 ShouldHandleJamming 已经做过 + Debug.WriteLine($"[LaserRangefinder] 激光测距仪受到有效干扰,功率:{parameters.Power}瓦特", "Jamming"); sensorData.IsValid = false; sensorData.Distance = 0; // 在干扰状态下将距离设置为0 } @@ -236,11 +219,22 @@ namespace ThreatSource.Sensor protected override void HandleJammingCleared(JammingType type) { base.HandleJammingCleared(type); + // 基类 JammableComponent 和 Sensor 已经处理了 IsJammed 状态 + // 这里只处理测距仪特定的响应 if (type == JammingType.Laser) { - Debug.WriteLine("激光测距仪干扰已清除"); - sensorData.IsValid = true; - sensorData.Distance = currentDistance; + Debug.WriteLine("[LaserRangefinder] 激光测距仪干扰已清除", "Jamming"); + // 只有在整体未被干扰时才恢复有效状态 + if (!IsJammed) + { + sensorData.IsValid = true; + sensorData.Distance = currentDistance; // 恢复上次测量的距离 + } + else + { + sensorData.IsValid = false; // 如果仍被干扰,保持无效 + sensorData.Distance = 0; + } } } diff --git a/ThreatSource/src/Sensor/MillimeterWaveAltimeter.cs b/ThreatSource/src/Sensor/MillimeterWaveAltimeter.cs index f11c13c..3b98d83 100644 --- a/ThreatSource/src/Sensor/MillimeterWaveAltimeter.cs +++ b/ThreatSource/src/Sensor/MillimeterWaveAltimeter.cs @@ -110,6 +110,34 @@ namespace ThreatSource.Sensor InitializeJamming(config.JammingResistanceThreshold, [JammingType.MillimeterWave]); } + /// + /// 判断是否应该处理传入的干扰参数 + /// + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) + { + // 首先调用基类检查是否支持该干扰类型 + if (!base.ShouldHandleJamming(parameters)) + { + return false; + } + + // 检查干扰类型是否为毫米波 + if (parameters.Type == JammingType.MillimeterWave) + { + // 检查波长是否与工作波段匹配 + if (!IsWavelengthCompatible(parameters.Wavelength ?? 0)) + { + Debug.WriteLine($"[MillimeterWaveAltimeter] 忽略干扰:波长 {parameters.Wavelength}mm 与波段 {Band} 不匹配。", "Jamming"); + return false; + } + } + + // 如果所有检查通过,则处理此干扰 + return true; + } + /// /// 更新毫米波测高雷达的工作状态 /// @@ -156,54 +184,6 @@ namespace ThreatSource.Sensor return sensorData; } - /// - /// 激活毫米波测高雷达 - /// - public override void Activate() - { - base.Activate(); - SimulationManager.SubscribeToEvent(OnMillimeterWaveJamming); - } - - /// - /// 停用毫米波测高雷达 - /// - public override void Deactivate() - { - base.Deactivate(); - SimulationManager.UnsubscribeFromEvent(OnMillimeterWaveJamming); - } - - /// - /// 处理毫米波干扰事件 - /// - private void OnMillimeterWaveJamming(MillimeterWaveJammingEvent evt) - { - // 检查波长匹配性 - bool isWavelengthCompatible = IsWavelengthCompatible(evt.Wavelength); - - if (!isWavelengthCompatible) - { - System.Diagnostics.Debug.WriteLine($"毫米波干扰波长 {evt.Wavelength}mm 与测高雷达波段 {Band} 不匹配,忽略干扰"); - return; - } - - // 创建干扰参数 - var parameters = new JammingParameters - { - Type = JammingType.MillimeterWave, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 应用干扰 - ApplyJamming(parameters); - } - /// /// 检查干扰波长是否与测高雷达波段匹配 /// @@ -226,11 +206,14 @@ namespace ThreatSource.Sensor protected override void HandleJammingApplied(JammingParameters parameters) { base.HandleJammingApplied(parameters); + // 基类 JammableComponent 和 Sensor 已经处理了 IsJammed 状态 + // 这里只处理测高雷达特定的响应 if (parameters.Type == JammingType.MillimeterWave) { - Debug.WriteLine($"毫米波测高雷达受到干扰,功率:{parameters.Power}瓦特"); - sensorData.IsValid = false; - sensorData.Altitude = 0; // 被干扰时将高度值设为0 + // 不需要再次检查波长,因为 ShouldHandleJamming 已经做过 + Debug.WriteLine($"[MillimeterWaveAltimeter] 毫米波测高雷达受到有效干扰,功率:{parameters.Power}瓦特", "Jamming"); + sensorData.IsValid = false; + sensorData.Altitude = 0; // 被干扰时将高度值设为0 } } @@ -240,11 +223,22 @@ namespace ThreatSource.Sensor protected override void HandleJammingCleared(JammingType type) { base.HandleJammingCleared(type); + // 基类 JammableComponent 和 Sensor 已经处理了 IsJammed 状态 + // 这里只处理测高雷达特定的响应 if (type == JammingType.MillimeterWave) { - Debug.WriteLine("毫米波测高雷达干扰已清除"); - sensorData.IsValid = true; - sensorData.Altitude = currentAltitude; // 恢复正常的高度测量值 + Debug.WriteLine("[MillimeterWaveAltimeter] 毫米波测高雷达干扰已清除", "Jamming"); + // 只有在整体未被干扰时才恢复有效状态 + if (!IsJammed) + { + sensorData.IsValid = true; + sensorData.Altitude = currentAltitude; // 恢复正常的高度测量值 + } + else + { + // 如果仍有其他干扰(理论上不可能,因为只支持MMW),保持无效 + sensorData.IsValid = false; + } } } } diff --git a/ThreatSource/src/Sensor/MillimeterWaveRadiometer.cs b/ThreatSource/src/Sensor/MillimeterWaveRadiometer.cs index 8e612ed..3d58cb1 100644 --- a/ThreatSource/src/Sensor/MillimeterWaveRadiometer.cs +++ b/ThreatSource/src/Sensor/MillimeterWaveRadiometer.cs @@ -216,51 +216,31 @@ namespace ThreatSource.Sensor } /// - /// 激活毫米波辐射计 + /// 判断是否应该处理传入的干扰参数 /// - public override void Activate() + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected override bool ShouldHandleJamming(JammingParameters parameters) { - base.Activate(); - SimulationManager.SubscribeToEvent(OnMillimeterWaveJamming); - } - - /// - /// 停用毫米波辐射计 - /// - public override void Deactivate() - { - base.Deactivate(); - SimulationManager.UnsubscribeFromEvent(OnMillimeterWaveJamming); - } - - /// - /// 处理毫米波干扰事件 - /// - private void OnMillimeterWaveJamming(MillimeterWaveJammingEvent evt) - { - // 检查波长匹配性 - bool isWavelengthCompatible = IsWavelengthCompatible(evt.Wavelength); - - if (!isWavelengthCompatible) + // 首先调用基类检查是否支持该干扰类型 + if (!base.ShouldHandleJamming(parameters)) { - System.Diagnostics.Debug.WriteLine($"毫米波干扰波长 {evt.Wavelength}mm 与辐射计波段 {Band} 不匹配,忽略干扰"); - return; + return false; } - - // 创建干扰参数 - var parameters = new JammingParameters + + // 检查干扰类型是否为毫米波 + if (parameters.Type == JammingType.MillimeterWave) { - Type = JammingType.MillimeterWave, - Power = evt.JammingPower, - Direction = evt.JammingDirection, - SourcePosition = evt.JammingSourcePosition, - AngleRange = evt.JammingAngleRange, - Mode = evt.JammingMode, - Duration = evt.Duration - }; - - // 应用干扰 - ApplyJamming(parameters); + // 检查波长是否与工作波段匹配 + if (!IsWavelengthCompatible(parameters.Wavelength ?? 0)) + { + Debug.WriteLine($"[MillimeterWaveRadiometer] 忽略干扰:波长 {parameters.Wavelength}mm 与波段 {Band} 不匹配。", "Jamming"); + return false; + } + } + + // 如果所有检查通过,则处理此干扰 + return true; } /// @@ -285,11 +265,14 @@ namespace ThreatSource.Sensor protected override void HandleJammingApplied(JammingParameters parameters) { base.HandleJammingApplied(parameters); + // 基类 JammableComponent 和 Sensor 已经处理了 IsJammed 状态 + // 这里只处理辐射计特定的响应 if (parameters.Type == JammingType.MillimeterWave) { - Debug.WriteLine($"毫米波辐射计受到干扰,功率:{parameters.Power}瓦特"); + // 不需要再次检查波长,因为 ShouldHandleJamming 已经做过 + Debug.WriteLine($"[MillimeterWaveRadiometer] 毫米波辐射计受到有效干扰,功率:{parameters.Power}瓦特", "Jamming"); sensorData.IsValid = false; - sensorData.IsTargetDetected = false; + sensorData.IsTargetDetected = false; // 干扰时无法探测目标 } } @@ -299,10 +282,21 @@ namespace ThreatSource.Sensor protected override void HandleJammingCleared(JammingType type) { base.HandleJammingCleared(type); + // 基类 JammableComponent 和 Sensor 已经处理了 IsJammed 状态 + // 这里只处理辐射计特定的响应 if (type == JammingType.MillimeterWave) { - Debug.WriteLine("毫米波辐射计干扰已清除"); - sensorData.IsValid = true; + Debug.WriteLine("[MillimeterWaveRadiometer] 毫米波辐射计干扰已清除", "Jamming"); + // 只有在整体未被干扰时才恢复有效状态 + if (!IsJammed) + { + sensorData.IsValid = true; + // 不需要重置 IsTargetDetected,UpdateSensor 会处理 + } + else + { + sensorData.IsValid = false; // 如果仍被干扰,保持无效 + } } } } diff --git a/ThreatSource/src/Sensor/Sensor.cs b/ThreatSource/src/Sensor/Sensor.cs index 06813b4..325d6e1 100644 --- a/ThreatSource/src/Sensor/Sensor.cs +++ b/ThreatSource/src/Sensor/Sensor.cs @@ -81,10 +81,12 @@ namespace ThreatSource.Sensor // 初始化干扰处理组件 _jammingComponent = new JammableComponent( - positionProvider: () => Position, - onJammingApplied: HandleJammingApplied, - onJammingCleared: HandleJammingCleared + positionProvider: () => Position ); + + // Subscribe to the events instead + _jammingComponent.JammingApplied += HandleJammingApplied; + _jammingComponent.JammingCleared += HandleJammingCleared; } /// @@ -171,6 +173,37 @@ namespace ThreatSource.Sensor // 子类中实现具体的传感器更新逻辑 } + /// + /// 统一处理干扰事件 + /// + /// 干扰事件 + protected virtual void HandleJammingEvent(JammingEvent evt) + { + if (evt == null) return; + + // 在应用干扰前检查是否应该处理此干扰 + if (!ShouldHandleJamming(evt.Parameters)) + { + // 可选择记录日志:Debug.WriteLine($"传感器 {Id} 忽略干扰事件,类型: {evt.Parameters.Type}"); + return; + } + + // 如果应该处理,则应用干扰 + ApplyJamming(evt.Parameters); + } + + /// + /// 判断是否应该处理传入的干扰参数(可被子类重写以添加特定检查) + /// + /// 干扰参数 + /// 如果应该处理则返回 true,否则返回 false + protected virtual bool ShouldHandleJamming(JammingParameters parameters) + { + // 基类默认处理所有受支持类型的干扰 + // 子类可以重写此方法添加额外检查,如波段匹配 + return SupportedJammingTypes.Contains(parameters.Type); + } + /// /// 应用干扰 /// @@ -209,5 +242,35 @@ namespace ThreatSource.Sensor /// - 确保数据有效性 /// public abstract SensorData GetSensorData(); + + /// + /// 激活传感器 + /// + public override void Activate() + { + if (!IsActive) + { + IsActive = true; + // 统一订阅 HandleJammingEvent + SimulationManager.SubscribeToEvent(HandleJammingEvent); + // 移除可能存在的旧订阅(如果子类之前有单独订阅) + } + base.Activate(); + } + + /// + /// 停用传感器 + /// + public override void Deactivate() + { + if (IsActive) + { + IsActive = false; + // 统一取消订阅 HandleJammingEvent + SimulationManager.UnsubscribeFromEvent(HandleJammingEvent); + // 移除可能存在的旧取消订阅 + } + base.Deactivate(); + } } } diff --git a/ThreatSource/src/Simulation/SimulationConfig.cs b/ThreatSource/src/Simulation/SimulationConfig.cs index 720c25d..2990f62 100644 --- a/ThreatSource/src/Simulation/SimulationConfig.cs +++ b/ThreatSource/src/Simulation/SimulationConfig.cs @@ -415,32 +415,6 @@ namespace ThreatSource.Simulation public double WavelengthMax { get; set; } = 0; } - /// - /// 激光干扰器配置类 - /// - public class LaserJammerConfig - { - /// - /// 最大干扰冷却时间(秒) - /// - public double MaxJammingCooldown { get; set; } = 5.0; - - /// - /// 最大干扰功率(瓦特) - /// - public double MaxJammingPower { get; set; } = 10000.0; - - /// - /// 初始干扰功率(瓦特) - /// - public double InitialJammingPower { get; set; } = 4000.0; - - /// - /// 功率增加速率(瓦特/秒) - /// - public double PowerIncreaseRate { get; set; } = 2000.0; - } - /// /// 红外测角仪配置类 /// @@ -476,32 +450,6 @@ namespace ThreatSource.Simulation public double JammingResistanceThreshold { get; set; } = 50; } - /// - /// 毫米波干扰器配置类 - /// - public class MillimeterWaveJammerConfig - { - /// - /// 最大干扰功率(瓦特) - /// - public double MaxJammingPower { get; set; } = 1000; - - /// - /// 初始干扰功率(瓦特) - /// - public double InitialJammingPower { get; set; } = 400; - - /// - /// 功率增长率(瓦特/秒) - /// - public double PowerIncreaseRate { get; set; } = 200; - - /// - /// 最大冷却时间(秒) - /// - public double MaxJammingCooldown { get; set; } = 5; - } - /// /// 红外指令导引系统配置类 /// @@ -1737,6 +1685,99 @@ namespace ThreatSource.Simulation } } +/// + /// 红外干扰器配置类 + /// + public class InfraredJammerConfig + { + /// + /// 干扰功率,单位:瓦特 + /// + public double Power { get; set; } = 1000; + + /// + /// 干扰波长,单位:微米 + /// + public double Wavelength { get; set; } = 5; + + /// + /// 干扰角度范围,单位:度 + /// + public double AngleRange { get; set; } = 10; + + /// + /// 干扰模式 + /// + public JammingMode Mode { get; set; } = JammingMode.Noise; + + /// + /// 持续时间,单位:秒 + /// + public double Duration { get; set; } = 10; + } + + /// + /// 毫米波干扰器配置类 + /// + public class MillimeterWaveJammerConfig + { + /// + /// 干扰功率,单位:瓦特 + /// + public double Power { get; set; } = 1000; + + /// + /// 干扰波长,单位:微米 + /// + public double Wavelength { get; set; } = 3e3; + + /// + /// 干扰角度范围,单位:度 + /// + public double AngleRange { get; set; } = 10; + + /// + /// 干扰模式 + /// + public JammingMode Mode { get; set; } = JammingMode.Noise; + + /// + /// 持续时间,单位:秒 + /// + public double Duration { get; set; } = 10; + } + + /// + /// 激光干扰器配置类 + /// + public class LaserJammerConfig + { + /// + /// 干扰功率,单位:瓦特 + /// + public double Power { get; set; } = 1000; + + /// + /// 干扰波长,单位:微米 + /// + public double Wavelength { get; set; } = 1.06; + + /// + /// 干扰角度范围,单位:度 + /// + public double AngleRange { get; set; } = 10; + + /// + /// 干扰模式 + /// + public JammingMode Mode { get; set; } = JammingMode.Noise; + + /// + /// 持续时间,单位:秒 + /// + public double Duration { get; set; } = 10; + } + /// /// 激光诱偏目标配置类 /// @@ -1747,6 +1788,11 @@ namespace ThreatSource.Simulation /// public double DecoyPower { get; set; } = 0; + /// + /// 诱偏激光波长,单位:微米 + /// + public double DecoyWavelength { get; set; } = 1.06; + /// /// 诱偏激光发散角,单位:度 /// diff --git a/ThreatSource/src/Simulation/SimulationEvents.cs b/ThreatSource/src/Simulation/SimulationEvents.cs index 5413f09..127152d 100644 --- a/ThreatSource/src/Simulation/SimulationEvents.cs +++ b/ThreatSource/src/Simulation/SimulationEvents.cs @@ -115,80 +115,6 @@ namespace ThreatSource.Simulation public string? TargetId { get; set; } } - /// - /// 激光干扰事件,表示对激光制导系统的干扰 - /// - /// - /// 用于模拟激光干扰效果 - /// 包含干扰功率信息 - /// - public class LaserJammingEvent : SimulationEvent - { - /// - /// 获取或设置干扰功率值 - /// - /// - /// 单位:瓦特 - /// 表示干扰源的输出功率 - /// - public double JammingPower { get; set; } - - /// - /// 获取或设置波长 - /// - /// - /// 单位:微米 - /// 干扰激光的波长 - /// - public double Wavelength { get; set; } = 1.06; - - /// - /// 获取或设置干扰源位置 - /// - /// - /// 干扰设备在三维空间中的位置 - /// 用于计算干扰效果衰减 - /// - public Vector3D JammingSourcePosition { get; set; } = Vector3D.Zero; - - /// - /// 获取或设置干扰方向 - /// - /// - /// 干扰波束的主方向向量 - /// 单位向量 - /// - public Vector3D JammingDirection { get; set; } = Vector3D.UnitX; - - /// - /// 获取或设置干扰角度范围 - /// - /// - /// 单位:弧度 - /// 定义了干扰波束的发散角度 - /// 影响干扰的覆盖范围 - /// - public double JammingAngleRange { get; set; } = 0.1; // 激光干扰角度范围默认更小 - - /// - /// 获取或设置干扰模式 - /// - /// - /// 定义干扰的工作模式 - /// 影响干扰的效果类型 - /// - public JammingMode JammingMode { get; set; } = JammingMode.Noise; - - /// - /// 获取或设置干扰持续时间 - /// - /// - /// 单位:秒 - /// null表示持续干扰,直到显式清除 - /// - public double? Duration { get; set; } - } - /// /// 实体销毁事件,表示仿真实体被销毁 /// @@ -518,133 +444,6 @@ namespace ThreatSource.Simulation /// public string? TargetId { get; set; } } - - /// - /// 红外干扰事件 - /// - public class InfraredJammingEvent : SimulationEvent - { - /// - /// 干扰功率(瓦特) - /// - public double JammingPower { get; set; } - - /// - /// 波长(微米) - /// - public double Wavelength { get; set; } - - /// - /// 干扰源位置 - /// - /// - /// 干扰设备在三维空间中的位置 - /// 用于计算干扰效果衰减 - /// - public Vector3D JammingSourcePosition { get; set; } = Vector3D.Zero; - - /// - /// 干扰方向 - /// - /// - /// 干扰波束的主方向向量 - /// 单位向量 - /// - public Vector3D JammingDirection { get; set; } = Vector3D.UnitX; - - /// - /// 干扰角度范围(弧度) - /// - /// - /// 定义了干扰波束的发散角度 - /// 影响干扰的覆盖范围 - /// - public double JammingAngleRange { get; set; } = 0.5; - - /// - /// 干扰模式 - /// - /// - /// 定义干扰的工作模式 - /// 影响干扰的效果类型 - /// - public JammingMode JammingMode { get; set; } = JammingMode.Noise; - - /// - /// 干扰持续时间(秒) - /// - /// - /// null表示持续干扰,直到显式清除 - /// - public double? Duration { get; set; } - } - /// - /// 毫米波干扰事件,表示对毫米波雷达的干扰 - /// - /// - /// 用于模拟对毫米波制导系统的干扰 - /// 包含干扰功率信息 - /// - public class MillimeterWaveJammingEvent : SimulationEvent - { - /// - /// 获取或设置干扰功率值 - /// - /// - /// 单位:瓦特 - /// 表示毫米波干扰源的输出功率 - /// - public double JammingPower { get; set; } - - /// - /// 波长(微米) - /// - public double Wavelength { get; set; } - - /// - /// 干扰源位置 - /// - /// - /// 干扰设备在三维空间中的位置 - /// 用于计算干扰效果衰减 - /// - public Vector3D JammingSourcePosition { get; set; } = Vector3D.Zero; - - /// - /// 干扰方向 - /// - /// - /// 干扰波束的主方向向量 - /// 单位向量 - /// - public Vector3D JammingDirection { get; set; } = Vector3D.UnitX; - - /// - /// 干扰角度范围(弧度) - /// - /// - /// 定义了干扰波束的发散角度 - /// 影响干扰的覆盖范围 - /// - public double JammingAngleRange { get; set; } = 0.5; - - /// - /// 干扰模式 - /// - /// - /// 定义干扰的工作模式 - /// 影响干扰的效果类型 - /// - public JammingMode JammingMode { get; set; } = JammingMode.Noise; - - /// - /// 干扰持续时间(秒) - /// - /// - /// null表示持续干扰,直到显式清除 - /// - public double? Duration { get; set; } - } /// /// 激光编码不匹配事件,表示导弹接收到与期望不符的激光编码 @@ -688,43 +487,6 @@ namespace ThreatSource.Simulation public LaserCodeConfig? ReceivedCodeConfig { get; set; } } - - /// - /// 烟幕事件,表示烟幕的生成和扩散 - /// - /// - /// 用于模拟烟幕生成和影响 - /// 触发时机:烟幕弹爆炸或烟幕状态更新时 - /// - public class SmokeScreenEvent : SimulationEvent - { - /// - /// 获取或设置烟幕弹ID - /// - /// - /// 标识生成烟幕的烟幕弹 - /// - public string? SmokeGrenadeId { get; set; } - } - - /// - /// 烟幕停止事件,表示烟幕状态的停止 - /// - /// - /// 用于模拟烟幕状态的停止 - /// 触发时机:烟幕停止时 - /// - public class SmokeScreenStopEvent : SimulationEvent - { - /// - /// 获取或设置烟幕弹ID - /// - /// - /// 标识停止的烟幕弹 - /// - public string? SmokeGrenadeId { get; set; } - } - /// /// 激光诱偏目标事件,表示激光诱偏目标被照射 @@ -769,6 +531,53 @@ namespace ThreatSource.Simulation /// public string? LaserDecoyId { get; set; } } - - + + // --- General Jamming Events --- + + /// + /// 通用干扰事件,表示干扰器正在发射干扰信号 + /// + /// + /// 由干扰器 (IJammer 实现) 发布,表示其正在发射具有指定参数的干扰信号。 + /// 在干扰开始或参数更新时发布。 + /// SenderId 为干扰器ID。 + /// + public class JammingEvent : SimulationEvent + { + /// + /// 获取或设置当前的干扰参数 + /// + /// + /// 包含了干扰类型、功率、位置、方向、模式、持续时间等详细信息 + /// + public required JammingParameters Parameters { get; set; } + + /// + /// 获取当前干扰类型 (方便快速访问) + /// + public JammingType CurrentJammingType => Parameters.Type; + } + + /// + /// 通用干扰停止事件,表示干扰器停止发射 + /// + /// + /// 由干扰器 (IJammer 实现) 发布,通知系统其干扰已停止发射。 + /// SenderId 为干扰器ID。 + /// + public class JammingStoppedEvent : SimulationEvent + { + /// + /// 获取或设置停止前的干扰参数 + /// + /// + /// 包含了停止前有效的干扰类型、功率、位置、方向、模式、持续时间等信息。 + /// + public required JammingParameters Parameters { get; set; } + + /// + /// 获取已停止的干扰类型 (方便快速访问) + /// + public JammingType StoppedJammingType => Parameters.Type; + } } diff --git a/docs/project/theory.md b/docs/project/theory.md index 99e3848..c480ea8 100644 --- a/docs/project/theory.md +++ b/docs/project/theory.md @@ -260,3 +260,12 @@ P_r \propto \rho \cdot A_{target} - Tank: `{ AR: 2.9, Size: 1.0, IP: 0.8, TG: 0.7 }` - APC: `{ AR: 2.1, Size: 0.7, IP: 0.7, TG: 0.6 }` - Helicopter: `{ AR: 4.8, Size: 1.4, IP: 0.8, TG: 0.2 }` + + +红外大气窗口 +3~5um 中波 +8~12um 长波 + + + + diff --git a/tools/ComprehensiveMissileSimulator.cs b/tools/ComprehensiveMissileSimulator.cs index c90980c..9d70a68 100644 --- a/tools/ComprehensiveMissileSimulator.cs +++ b/tools/ComprehensiveMissileSimulator.cs @@ -158,8 +158,14 @@ namespace ThreatSource.Tools.MissileSimulation Console.WriteLine($"注册烟幕弹 {smokeGrenadeId}"); } + var motionParametersTop = new MotionParameters + { + Position = new Vector3D(0, 20, 0), + Orientation = Orientation.FromVector(Vector3D.UnitX), + InitialSpeed = 0.0 + }; smokeGrenadeId = "SG_3"; - smokeGrenade = _threatSourceFactory.CreateJammer(smokeGrenadeId, "top", motionParameters, "Tank_1"); + smokeGrenade = _threatSourceFactory.CreateJammer(smokeGrenadeId, "top", motionParametersTop, "Tank_1"); if (smokeGrenade != null) { simulationManager.RegisterEntity(smokeGrenadeId, smokeGrenade); @@ -407,7 +413,7 @@ namespace ThreatSource.Tools.MissileSimulation /// /// 应用干扰 /// - public void ApplyJamming(JammingType type, double power, double duration, Vector3D position) + public void ApplyJamming(JammingType type, string category, double power, double duration, Vector3D position) { var jammingParams = new JammingParameters { @@ -420,9 +426,31 @@ namespace ThreatSource.Tools.MissileSimulation switch (type) { + case JammingType.Laser: + + break; + case JammingType.Infrared: + + break; + case JammingType.MillimeterWave: + + break; case JammingType.SmokeScreen: - jammingParams.JammerId = "SG_2"; - jammers["SG_2"].Activate(); + if (category == "水平烟幕弹") + { + jammingParams.JammerId = "SG_1"; + jammers["SG_1"].Activate(); + } + else if (category == "红外烟幕弹") + { + jammingParams.JammerId = "SG_2"; + jammers["SG_2"].Activate(); + } + else if (category == "顶部烟幕弹") + { + jammingParams.JammerId = "SG_3"; + jammers["SG_3"].Activate(); + } break; case JammingType.Decoy: jammingParams.JammerId = "LDY_1"; @@ -460,7 +488,7 @@ namespace ThreatSource.Tools.MissileSimulation /// /// 清除干扰 /// - public void ClearJamming(JammingType type) + public void ClearJamming(JammingType type, string category) { var jammingParams = new JammingParameters { diff --git a/tools/Program.cs b/tools/Program.cs index bfe3e95..7e5c672 100644 --- a/tools/Program.cs +++ b/tools/Program.cs @@ -174,7 +174,9 @@ namespace ThreatSource.Tools.MissileSimulation (JammingType.Infrared, "红外干扰"), (JammingType.MillimeterWave, "毫米波干扰"), (JammingType.Laser, "激光干扰"), - (JammingType.SmokeScreen, "烟幕弹"), + (JammingType.SmokeScreen, "水平烟幕弹"), + (JammingType.SmokeScreen, "红外烟幕弹"), + (JammingType.SmokeScreen, "顶部烟幕弹"), (JammingType.Decoy, "假目标干扰") }; @@ -202,9 +204,9 @@ namespace ThreatSource.Tools.MissileSimulation { jammingStatus[choice - 1] = !jammingStatus[choice - 1]; if (jammingStatus[choice - 1]) - simulator.ApplyJamming(jammingTypes[choice - 1].Item1, 100, 5, new Vector3D(0, 0, 0)); + simulator.ApplyJamming(jammingTypes[choice - 1].Item1, jammingTypes[choice - 1].Item2, 100, 5, new Vector3D(0, 0, 0)); else - simulator.ClearJamming(jammingTypes[choice - 1].Item1); + simulator.ClearJamming(jammingTypes[choice - 1].Item1, jammingTypes[choice - 1].Item2); continue; } }