对干扰体系进行了重构,简化了处理流程

This commit is contained in:
Tian jianyong 2025-04-24 22:35:16 +08:00
parent 72d10b948a
commit 2b5b803402
47 changed files with 2347 additions and 2355 deletions

View File

@ -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<LaserCodeMismatchEvent>();
@ -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<LaserCodeMismatchEvent>();
@ -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<LaserCodeMismatchEvent>();

View File

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

View File

@ -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

View File

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

View File

@ -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 - 应用干扰

View File

@ -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 - 应用干扰

View File

@ -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
}
};
// 捕获发布的事件

View File

@ -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 - 应用干扰

View File

@ -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 - 应用干扰

View File

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

View File

@ -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 - 应用干扰

View File

@ -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 - 应用干扰

View File

@ -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 - 应用干扰

View File

@ -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 - 应用干扰

View File

@ -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 - 应用干扰

View File

@ -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
}
};
// 记录初始高度

View File

@ -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

View File

@ -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;
// 子类需要在构造函数中设置支持的干扰类型和阈值
}
/// <summary>
/// 激活制导系统 (基类处理干扰事件订阅)
/// </summary>
public override void Activate()
{
if (!IsActive)
{
IsActive = true;
// 统一订阅 JammingEvent
SimulationManager.SubscribeToEvent<JammingEvent>(HandleJammingEvent);
// 子类应在此方法中调用 base.Activate() 并订阅其他需要的事件
}
// 调用 SimulationElement 的基类 Activate (如果存在)
// base.Activate(); // SimulationElement 似乎没有公开的 Activate
}
/// <summary>
/// 停用制导系统 (基类处理干扰事件取消订阅)
/// </summary>
public override void Deactivate()
{
if (IsActive)
{
IsActive = false;
// 统一取消订阅 JammingEvent
SimulationManager.UnsubscribeFromEvent<JammingEvent>(HandleJammingEvent);
// 子类应在此方法中调用 base.Deactivate() 并取消订阅其他事件
}
HasGuidance = false; // 停用时失去制导
GuidanceAcceleration = Vector3D.Zero;
// 调用 SimulationElement 的基类 Deactivate (如果存在)
// base.Deactivate(); // SimulationElement 似乎没有公开的 Deactivate
}
/// <summary>
/// 更新制导系统的状态和计算结果
/// </summary>
@ -193,6 +229,38 @@ namespace ThreatSource.Guidance
return base.GetStatus() + $"导引头状态: 有制导={HasGuidance}, 被干扰={IsJammed}, 制导加速度={GuidanceAcceleration}";
}
/// <summary>
/// 处理干扰事件
/// </summary>
/// <param name="evt">干扰事件</param>
protected virtual void HandleJammingEvent(JammingEvent evt)
{
if (evt != null)
{
// 在应用干扰前检查是否应该处理此干扰
if (!ShouldHandleJamming(evt.Parameters))
{
// Debug.WriteLine($"[BaseGuidanceSystem] {Id} 忽略干扰事件,类型: {evt.Parameters.Type}");
return;
}
ApplyJamming(evt.Parameters);
}
}
/// <summary>
/// 判断是否应该处理传入的干扰参数(可被子类重写以添加特定检查)
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
protected virtual bool ShouldHandleJamming(JammingParameters parameters)
{
// 基类默认处理所有受支持类型的干扰
// 子类可以重写此方法添加额外检查,如波长/编码匹配
bool supported = SupportedJammingTypes.Contains(parameters.Type);
// if(!supported) Debug.WriteLine($"[BaseGuidanceSystem] {Id} 不支持干扰类型: {parameters.Type}");
return supported;
}
/// <summary>
/// 设置干扰阈值
/// </summary>
@ -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 (因为可能有烟幕)

View File

@ -13,56 +13,45 @@ namespace ThreatSource.Guidance
/// - 红外强度矩阵
/// 用于目标探测和识别
/// </remarks>
public class InfraredImage
/// <remarks>
/// 初始化红外图像的新实例
/// </remarks>
/// <param name="width">图像宽度</param>
/// <param name="height">图像高度</param>
/// <param name="pixelSize">像素物理尺寸</param>
/// <param name="lineOfSight">视线方向</param>
/// <param name="smokeCoverageMask">烟幕覆盖掩码 (可选)</param>
public class InfraredImage(int width, int height, double pixelSize, Vector3D lineOfSight, bool[,]? smokeCoverageMask = null)
{
/// <summary>
/// 图像宽度,单位:像素
/// </summary>
public int Width { get; }
public int Width { get; } = width;
/// <summary>
/// 图像高度,单位:像素
/// </summary>
public int Height { get; }
public int Height { get; } = height;
/// <summary>
/// 像素物理尺寸,单位:弧度/像素
/// </summary>
public double PixelSize { get; }
public double PixelSize { get; } = pixelSize;
/// <summary>
/// 红外强度矩阵单位W/sr
/// </summary>
public double[,] Intensity { get; }
public double[,] Intensity { get; } = new double[height, width];
/// <summary>
/// 图像中心视线方向
/// </summary>
public Vector3D LineOfSight { get; }
public Vector3D LineOfSight { get; } = lineOfSight;
/// <summary>
/// 烟幕覆盖掩码 (true 表示被遮蔽烟幕覆盖)
/// </summary>
public bool[,] SmokeCoverageMask { get; }
/// <summary>
/// 初始化红外图像的新实例
/// </summary>
/// <param name="width">图像宽度</param>
/// <param name="height">图像高度</param>
/// <param name="pixelSize">像素物理尺寸</param>
/// <param name="lineOfSight">视线方向</param>
/// <param name="smokeCoverageMask">烟幕覆盖掩码 (可选)</param>
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];
/// <summary>
/// 设置像素强度值

View File

@ -139,36 +139,6 @@ namespace ThreatSource.Guidance
SwitchToSearchMode(); // 初始化为搜索模式
}
/// <summary>
/// 处理红外干扰事件
/// </summary>
/// <param name="evt">红外干扰事件数据</param>
/// <remarks>
/// 处理过程:
/// - 创建干扰参数
/// - 使用JammableComponent进行干扰判断
/// - 更新系统状态
/// </remarks>
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");
}
/// <summary>
/// 处理系统被干扰的事件
/// </summary>
@ -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<InfraredJammingEvent>(OnInfraredJamming);
// 订阅烟幕事件
SimulationManager.SubscribeToEvent<SmokeScreenEvent>(OnSmokeScreen);
}
/// <summary>
@ -257,8 +224,6 @@ namespace ThreatSource.Guidance
public override void Deactivate()
{
base.Deactivate();
SimulationManager.UnsubscribeFromEvent<InfraredJammingEvent>(OnInfraredJamming);
SimulationManager.UnsubscribeFromEvent<SmokeScreenEvent>(OnSmokeScreen);
lastTargetPosition = null; // Add reset to null
HasTarget = false;
HasGuidance = false;
@ -268,41 +233,6 @@ namespace ThreatSource.Guidance
// lockConfirmationTimer = 0;
}
/// <summary>
/// 处理烟幕事件
/// </summary>
/// <param name="evt">烟幕事件</param>
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);
}
}
}
/// <summary>
/// 更新引导系统的状态和计算结果
/// </summary>

View File

@ -172,7 +172,6 @@ namespace ThreatSource.Guidance
{
base.Activate();
// 在这里订阅事件,确保只订阅一次
SimulationManager.SubscribeToEvent<LaserJammingEvent>(OnLaserJamming);
SimulationManager.SubscribeToEvent<LaserBeamEvent>(OnLaserBeamStart);
SimulationManager.SubscribeToEvent<LaserBeamStopEvent>(OnLaserBeamStop);
}
@ -184,7 +183,6 @@ namespace ThreatSource.Guidance
{
base.Deactivate();
// 取消订阅事件
SimulationManager.UnsubscribeFromEvent<LaserJammingEvent>(OnLaserJamming);
SimulationManager.UnsubscribeFromEvent<LaserBeamEvent>(OnLaserBeamStart);
SimulationManager.UnsubscribeFromEvent<LaserBeamStopEvent>(OnLaserBeamStop);
}
@ -516,29 +514,6 @@ namespace ThreatSource.Guidance
LastGuidanceAcceleration = GuidanceAcceleration;
}
/// <summary>
/// 处理激光干扰事件
/// </summary>
/// <param name="evt">激光干扰事件</param>
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");
}
/// <summary>
/// 处理系统被干扰的事件
/// </summary>
@ -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("激光驾束制导系统受到激光干扰");
}
}
/// <summary>
/// 处理系统干扰被清除的事件
/// </summary>
/// <param name="type">被清除的干扰类型</param>
/// <param name="type">被清除的干扰类型</param>
protected override void HandleJammingCleared(JammingType type)
{
if (type == JammingType.Laser)
{
Debug.WriteLine("激光驾束制导系统干扰已清除");
// 确保基类的处理逻辑被调用
base.HandleJammingCleared(type);
Debug.WriteLine("激光驾束制导系统干扰已清除");
}
}
/// <summary>
/// 判断是否应该处理传入的干扰参数(激光干扰需要额外检查波长)
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
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;
}
/// <summary>
/// 获取制导系统的详细状态信息
/// </summary>

View File

@ -184,9 +184,7 @@ namespace ThreatSource.Guidance
SimulationManager.SubscribeToEvent<LaserIlluminationUpdateEvent>(OnLaserIlluminationUpdate);
SimulationManager.SubscribeToEvent<LaserIlluminationStopEvent>(OnLaserIlluminationStop);
// 订阅激光干扰事件
SimulationManager.SubscribeToEvent<LaserJammingEvent>(OnLaserJamming);
// 订阅烟幕事件
SimulationManager.SubscribeToEvent<SmokeScreenEvent>(OnSmokeScreen);
SimulationManager.SubscribeToEvent<JammingEvent>(HandleJammingEvent);
// 订阅诱偏目标照射事件
SimulationManager.SubscribeToEvent<LaserDecoyEvent>(OnLaserDecoy);
@ -209,9 +207,7 @@ namespace ThreatSource.Guidance
SimulationManager.UnsubscribeFromEvent<LaserIlluminationStopEvent>(OnLaserIlluminationStop);
// 取消订阅激光干扰事件
SimulationManager.UnsubscribeFromEvent<LaserJammingEvent>(OnLaserJamming);
// 取消订阅烟幕事件
SimulationManager.UnsubscribeFromEvent<SmokeScreenEvent>(OnSmokeScreen);
SimulationManager.UnsubscribeFromEvent<JammingEvent>(HandleJammingEvent);
// 取消订阅诱偏目标照射事件
SimulationManager.UnsubscribeFromEvent<LaserDecoyEvent>(OnLaserDecoy);
@ -220,39 +216,55 @@ namespace ThreatSource.Guidance
}
/// <summary>
/// 处理激光照射更新事件
/// 处理激光照射更新事件 (恢复编码检查)
/// </summary>
/// <param name="evt">激光照射更新事件</param>
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
/// <param name="evt">激光照射停止事件</param>
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;
}
}
}
/// <summary>
@ -298,123 +317,80 @@ namespace ThreatSource.Guidance
}
}
/// <summary>
/// 处理激光干扰事件
/// </summary>
/// <param name="evt">激光干扰事件</param>
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}");
}
}
/// <summary>
/// 处理烟幕事件
/// </summary>
/// <param name="evt">烟幕事件</param>
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);
}
}
}
/// <summary>
/// 处理系统被干扰的事件
/// </summary>
/// <param name="parameters">干扰参数</param>
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");
}
}
/// <summary>
/// 处理系统干扰被清除的事件
/// </summary>
/// <param name="type">被清除的干扰类型</param>
/// </summary>
/// <param name="type">被清除的干扰类型</param>
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");
}
}
/// <summary>
/// 判断是否应该处理传入的干扰参数(激光干扰需要额外检查波长和编码)
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
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;
}
/// <summary>
@ -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
}
/// <summary>
/// 处理激光照射更新事件
/// 检查激光编码是否匹配
/// </summary>
/// <param name="illuminationEvent">激光照射更新事件</param>
/// <remarks>
/// 处理过程:
/// - 检查编码是否匹配
/// - 如果要求匹配且不匹配,则忽略信号
/// - 如果匹配或不要求匹配,则处理信号
/// - 更新激光照射状态
/// </remarks>
public void ProcessLaserIlluminationUpdateEvent(LaserIlluminationUpdateEvent illuminationEvent)
/// <param name="receivedConfig">接收到的激光编码配置</param>
/// <returns>如果匹配返回true否则返回false</returns>
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;
}
}
/// <summary>
/// 处理激光照射停止事件
/// </summary>
/// <param name="illuminationEvent">激光照射停止事件</param>
/// <remarks>
/// 处理过程:
/// - 停止激光照射状态
/// - 清理相关参数
/// </remarks>
public void ProcessLaserIlluminationStopEvent(LaserIlluminationStopEvent illuminationEvent)
{
LaserIlluminationOn = false;
HasGuidance = false; // 禁用制导
// 调用内部配置的匹配逻辑
return InternalLaserCodeConfig.CheckCodeMatch(receivedConfig);
}
/// <summary>
@ -919,7 +857,7 @@ namespace ThreatSource.Guidance
ReceivedCodeConfig = receivedCodeConfig
};
PublishEvent(mismatchEvent);
PublishEvent(mismatchEvent); // 使用基类的 PublishEvent
}
/// <summary>

View File

@ -215,9 +215,7 @@ namespace ThreatSource.Guidance
{
IsActive = true;
// 在这里订阅事件,确保只订阅一次
SimulationManager.SubscribeToEvent<MillimeterWaveJammingEvent>(OnMillimeterWaveJamming);
// 添加对烟幕事件的订阅
SimulationManager.SubscribeToEvent<SmokeScreenEvent>(OnSmokeScreen);
SimulationManager.SubscribeToEvent<JammingEvent>(HandleJammingEvent);
}
base.Activate();
SwitchToSearchMode();
@ -231,9 +229,7 @@ namespace ThreatSource.Guidance
if (IsActive)
{
IsActive = false;
SimulationManager.UnsubscribeFromEvent<MillimeterWaveJammingEvent>(OnMillimeterWaveJamming);
// 添加取消对烟幕事件的订阅
SimulationManager.UnsubscribeFromEvent<SmokeScreenEvent>(OnSmokeScreen);
SimulationManager.UnsubscribeFromEvent<JammingEvent>(HandleJammingEvent);
}
base.Deactivate();
HasTarget = false;
@ -243,62 +239,6 @@ namespace ThreatSource.Guidance
lastTargetVelocity = null;
}
/// <summary>
/// 处理毫米波干扰事件
/// </summary>
/// <param name="evt">干扰事件参数</param>
/// <remarks>
/// 处理过程:
/// - 更新干扰状态
/// - 记录干扰功率
/// </remarks>
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");
}
/// <summary>
/// 处理烟幕事件,触发干扰应用
/// </summary>
/// <param name="evt">烟幕事件</param>
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);
}
}
}
/// <summary>
/// 处理系统被干扰的事件
/// </summary>
@ -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
/// <param name="type">被清除的干扰类型</param>
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");
}
}
/// <summary>
/// 判断是否应该处理传入的干扰参数(毫米波干扰需要额外检查波长)
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
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;
}
/// <summary>
@ -520,63 +477,69 @@ namespace ThreatSource.Guidance
/// </remarks>
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;
}
}
}

View File

@ -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;
}
/// <summary>
@ -142,8 +143,18 @@ namespace ThreatSource.Indicator
/// <param name="parameters">干扰参数</param>
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");
}
}
/// <summary>
@ -152,42 +163,72 @@ namespace ThreatSource.Indicator
/// <param name="type">被清除的干扰类型</param>
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");
}
}
/// <summary>
/// 激活指示器 (基类实现,子类应重写以添加事件订阅)
/// 激活指示器 (基类统一处理干扰事件订阅)
/// </summary>
public override void Activate()
{
base.Activate();
// 子类需要在此之后调用 base.Activate() 并订阅烟幕事件
if (!IsActive)
{
IsActive = true;
// 统一订阅 JammingEvent
SimulationManager.SubscribeToEvent<JammingEvent>(HandleJammingEvent);
// 子类仍需在此处订阅其他特定事件(如导弹热源事件)
}
base.Activate(); // 调用 SimulationElement 的基类 Activate
// 子类需要在此之后调用 base.Activate() 并订阅烟幕事件 <--- 旧注释,移除或更新
// 现在基类处理通用 JammingEvent子类只需要处理非干扰事件
RecalculateObscurationStatus(); // 激活时检查一次初始遮挡状态
}
/// <summary>
/// 停用指示器 (基类实现,子类应重写以移除事件订阅)
/// 停用指示器 (基类统一处理干扰事件取消订阅)
/// </summary>
public override void Deactivate()
{
// 子类需要在此之前取消订阅烟幕事件
if (IsActive)
{
IsActive = false;
// 统一取消订阅 JammingEvent
SimulationManager.UnsubscribeFromEvent<JammingEvent>(HandleJammingEvent);
// 子类仍需在此处取消订阅其他特定事件
}
// 子类需要在此之前取消订阅烟幕事件 <--- 旧注释,移除或更新
IsTargetObscured = false;
// 重置最后目标状态
_lastKnownTargetPosition = null;
_lastKnownTargetOrientation = null;
base.Deactivate();
base.Deactivate(); // 调用 SimulationElement 的基类 Deactivate
}
/// <summary>
/// 更新指示器状态 (基类只处理电子干扰)
/// 更新指示器状态
/// </summary>
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; // 未被遮挡
}
// --- 新增干扰事件处理逻辑 ---
/// <summary>
/// 统一处理干扰事件
/// </summary>
/// <param name="evt">干扰事件</param>
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);
}
/// <summary>
/// 判断是否应该处理传入的干扰参数(可被子类重写以添加特定检查)
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
protected virtual bool ShouldHandleJamming(JammingParameters parameters)
{
// 基类默认处理所有受支持类型的干扰 (包括烟幕)
// 子类可以重写此方法添加额外检查,如波段匹配
// 注意:烟幕干扰虽然通过这里,但主要效果通过 IsTargetObscured 和 RecalculateObscurationStatus 体现
bool supported = SupportedJammingTypes.Contains(parameters.Type);
// if(!supported) Debug.WriteLine($"[BaseIndicator] {Id} 不支持干扰类型: {parameters.Type}");
return supported;
}
// --- 结束新增干扰事件处理逻辑 ---
}
}

View File

@ -84,22 +84,22 @@ namespace ThreatSource.Indicator
/// <param name="deltaTime">时间步长,单位:秒</param>
/// <remarks>
/// 实现红外测角仪特定的更新逻辑:
/// - 只有在未被电子干扰且目标未被烟幕遮挡时才执行跟踪
/// - 基类 Update 会检查 IsJammed (电子干扰)
/// - UpdateTracking 方法内部会处理 IsTargetObscured (烟幕遮挡)
/// - 更新跟踪状态
/// - 处理目标跟踪
/// </remarks>
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<InfraredGuidanceMissileLightEvent>(OnInfraredGuidanceMissileLight);
SimulationManager.SubscribeToEvent<InfraredGuidanceMissileLightOffEvent>(OnInfraredGuidanceMissileLightOff);
SimulationManager.SubscribeToEvent<InfraredJammingEvent>(OnInfraredJamming);
SimulationManager.SubscribeToEvent<SmokeScreenEvent>(HandleSmokeEvent);
SimulationManager.SubscribeToEvent<SmokeScreenStopEvent>(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<InfraredGuidanceMissileLightEvent>(OnInfraredGuidanceMissileLight);
SimulationManager.SubscribeToEvent<InfraredGuidanceMissileLightOffEvent>(OnInfraredGuidanceMissileLightOff);
// 子类特定的激活逻辑
Debug.WriteLine($"红外测角仪 {Id} 已激活");
}
}
@ -294,71 +295,50 @@ namespace ThreatSource.Indicator
/// </remarks>
public override void Deactivate()
{
if (IsActive)
{
SimulationManager.UnsubscribeFromEvent<SmokeScreenEvent>(HandleSmokeEvent);
SimulationManager.UnsubscribeFromEvent<SmokeScreenStopEvent>(HandleSmokeEvent);
SimulationManager.UnsubscribeFromEvent<InfraredGuidanceMissileLightEvent>(OnInfraredGuidanceMissileLight);
SimulationManager.UnsubscribeFromEvent<InfraredGuidanceMissileLightOffEvent>(OnInfraredGuidanceMissileLightOff);
SimulationManager.UnsubscribeFromEvent<InfraredJammingEvent>(OnInfraredJamming);
Debug.WriteLine($"InfraredTracker {Id} deactivated.");
base.Deactivate();
}
}
/// <summary>
/// 处理红外干扰事件
/// </summary>
/// <param name="evt">红外干扰事件数据</param>
/// <remarks>
/// 处理过程:
/// - 计算干扰效果
/// - 应用干扰状态
/// </remarks>
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<InfraredGuidanceMissileLightEvent>(OnInfraredGuidanceMissileLight);
SimulationManager.UnsubscribeFromEvent<InfraredGuidanceMissileLightOffEvent>(OnInfraredGuidanceMissileLightOff);
// Removed JammingEvent subscriptions for OnInfraredJamming and HandleSmokeEvent
Debug.WriteLine($"红外测角仪 {Id} 已停用");
base.Deactivate(); // Handles IsActive and unsubscribes HandleJammingEvent
}
}
/// <summary>
/// 检查干扰波长是否在测角仪工作波段范围内
/// </summary>
/// <param name="wavelength">波长(微米)</param>
/// <returns>如果波长范围有重叠则返回true</returns>
private static bool IsWavelengthInRange(double wavelength)
{
// 假设红外测角仪的工作波段为3-5μm(中波红外)和8-14μm(长波红外)
// 这里应根据实际的红外测角仪配置来判断
return (wavelength >= 3 && wavelength <= 5) || // 中波红外
(wavelength >= 8 && wavelength <= 14); // 长波红外
}
/// <summary>
/// 处理烟幕更新或停止事件,触发遮挡状态重新计算
/// 判断是否应该处理传入的干扰参数
/// </summary>
private void HandleSmokeEvent(SimulationEvent evt) // Can use base SimulationEvent type
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
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;
}
/// <summary>
@ -422,13 +402,12 @@ namespace ThreatSource.Indicator
/// <param name="parameters">干扰参数</param>
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
/// <param name="type">被清除的干扰类型</param>
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");
}
}
}
}

View File

@ -37,51 +37,9 @@ namespace ThreatSource.Indicator
public double JammingThreshold { get; private set; } = 0.0;
/// <summary>
/// 获取或设置激光功率
/// 激光驾束仪配置
/// </summary>
/// <remarks>
/// 单位:瓦特
/// 影响激光波束的有效作用距离和制导精度
/// </remarks>
public double LaserPower { get; private set; }
/// <summary>
/// 获取或设置激光波长
/// </summary>
/// <remarks>
/// 单位:微米
/// 影响激光波束的波长特性
/// </remarks>
public double LaserWavelength { get; private set; } = 1.06;
/// <summary>
/// 获取或设置激光发散角
/// </summary>
/// <remarks>
/// 单位:毫弧度
/// 影响激光波束的扩散特性和制导精度
/// </remarks>
public double BeamDivergence { get; private set; } = 0.0;
/// <summary>
/// 获取或设置激光编码配置
/// </summary>
/// <remarks>
/// 包含激光信号的编码信息
/// 用于抗干扰和安全识别
/// </remarks>
public LaserCodeConfig LaserCodeConfig { get; set; }
/// <summary>
/// 获取或设置控制场直径
/// </summary>
/// <remarks>
/// 单位:米
/// 定义了激光波束制导场的有效范围
/// </remarks>
public double ControlFieldDiameter { get; private set; }
public readonly LaserBeamRiderConfig config;
/// <summary>
/// 获取或设置激光方向
@ -92,14 +50,6 @@ namespace ThreatSource.Indicator
/// </remarks>
public Vector3D LaserDirection { get; private set; }
/// <summary>
/// 获取或设置最大导引距离
/// </summary>
/// <remarks>
/// 单位:米
/// 超出此距离的导弹将无法接收到有效的制导信号
/// </remarks>
public double MaxGuidanceDistance { get; private set; }
/// <summary>
/// 获取激光束是否开启
@ -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
/// </remarks>
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
/// <param name="deltaTime">时间步长,单位:秒</param>
/// <remarks>
/// 更新过程:
/// - 检查电子干扰和烟幕遮挡状态
/// - 更新激光指向 (仅当未被干扰/遮挡时)
/// - 发布状态更新事件 (仅当未被干扰/遮挡且方向更新时)
/// - 基类 Update 会检查 IsJammed (电子干扰)
/// - 此方法内部检查 IsTargetObscured (烟幕遮挡)
/// - 更新激光指向 (仅当未被遮挡时)
/// - 发布状态更新事件 (仅当未被遮挡且方向更新时)
/// </remarks>
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
/// </summary>
/// <remarks>
/// 激活过程:
/// - 设置激活状态
/// - 订阅干扰事件
/// - 调用基类 Activate (处理 IsActive 和 JammingEvent 订阅)
/// - 开始激光照射
/// - 发布激活事件
/// </remarks>
public override void Activate()
{
if (!IsActive)
{
base.Activate();
SimulationManager.SubscribeToEvent<LaserJammingEvent>(OnLaserJamming);
SimulationManager.SubscribeToEvent<SmokeScreenEvent>(HandleSmokeEvent);
SimulationManager.SubscribeToEvent<SmokeScreenStopEvent>(HandleSmokeEvent);
RecalculateObscurationStatus();
base.Activate(); // Handles IsActive and subscribes HandleJammingEvent
// 子类特定的激活逻辑
Debug.WriteLine($"激光驾束仪 {Id} 已激活");
StartBeamIllumination();
}
@ -235,58 +177,48 @@ namespace ThreatSource.Indicator
/// <remarks>
/// 停用过程:
/// - 停止激光照射
/// - 取消订阅干扰事件
/// - 清理状态
/// - 发布停用事件
/// - 调用基类 Deactivate (处理 IsActive 和 JammingEvent 取消订阅)
/// </remarks>
public override void Deactivate()
{
if (IsActive)
{
// 子类特定的停用逻辑
if (IsBeamOn)
{
StopBeamIllumination();
}
SimulationManager.UnsubscribeFromEvent<LaserJammingEvent>(OnLaserJamming);
SimulationManager.UnsubscribeFromEvent<SmokeScreenEvent>(HandleSmokeEvent);
SimulationManager.UnsubscribeFromEvent<SmokeScreenStopEvent>(HandleSmokeEvent);
Debug.WriteLine($"激光驾束仪 {Id} 已停用");
base.Deactivate();
base.Deactivate(); // Handles IsActive and unsubscribes HandleJammingEvent
}
}
/// <summary>
/// 处理激光干扰事件
/// 判断是否应该处理传入的干扰参数
/// </summary>
/// <param name="evt">激光干扰事件数据</param>
/// <remarks>
/// 处理过程:
/// - 计算干扰效果
/// - 验证干扰条件
/// - 应用干扰参数
/// - 更新驾束仪状态
/// </remarks>
private void OnLaserJamming(LaserJammingEvent evt)
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
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;
}
/// <summary>
@ -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";
}
/// <summary>
@ -423,13 +354,12 @@ namespace ThreatSource.Indicator
/// <param name="parameters">干扰参数</param>
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
/// <param name="type">被清除的干扰类型</param>
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();
}
}
}
/// <summary>
/// 处理烟幕更新或停止事件,触发遮挡状态重新计算
/// </summary>
private void HandleSmokeEvent(SimulationEvent evt) // Can use base SimulationEvent type
{
RecalculateObscurationStatus();
}
}
}

View File

@ -45,27 +45,6 @@ namespace ThreatSource.Indicator
/// 控制激光发射状态
/// </remarks>
public bool IsIlluminationOn { get; private set; } = false;
/// <summary>
/// 获取或设置激光功率,单位:瓦特
/// </summary>
/// <remarks>
/// 定义了激光照射的能量强度
/// 默认功率为20瓦特
/// 影响照射距离和制导效果
/// </remarks>
public double LaserPower { get; set; } = 20;
/// <summary>
/// 获取或设置激光发散角,单位:弧度
/// </summary>
/// <remarks>
/// 定义了激光束的扩展角度
/// 默认发散角为0.5毫弧度
/// 影响照射面积和能量密度
/// </remarks>
public double LaserDivergenceAngle { get; private set; } = 0.5e-3;
/// <summary>
/// 获取或设置激光编码配置
@ -74,16 +53,7 @@ namespace ThreatSource.Indicator
/// 包含激光信号的编码信息
/// 用于抗干扰和安全识别
/// </remarks>
public LaserCodeConfig LaserCodeConfig { get; set; }
/// <summary>
/// 获取或设置工作波长,单位:微米
/// </summary>
/// <remarks>
/// 指示器工作所需的工作波长
/// 用于波长范围匹配检查
/// </remarks>
public double LaserWavelength { get; private set; } = 1.06;
public readonly LaserDesignatorConfig config;
/// <summary>
/// 初始化激光指示器的新实例
@ -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
/// <param name="deltaTime">时间步长,单位:秒</param>
/// <remarks>
/// 更新过程:
/// - 检查激活状态
/// - 检查电子干扰和烟幕遮挡状态
/// - 更新照射状态
/// - 更新指示器朝向 (仅当未被干扰/遮挡时)
/// - 发布状态事件 (仅当未被干扰/遮挡且照射开启时)
/// - 基类 Update 会检查 IsJammed (电子干扰)
/// - 此方法内部检查 IsTargetObscured (烟幕遮挡)
/// - 更新指示器朝向 (仅当未被遮挡时)
/// - 发布状态事件 (仅当未被遮挡且照射开启时)
/// </remarks>
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
}
}
/// <summary>
/// 处理激光干扰事件
/// </summary>
/// <param name="evt">激光干扰事件数据</param>
/// <remarks>
/// 处理过程:
/// - 验证目标ID
/// - 计算干扰效果
/// - 更新干扰状态
/// - 处理工作模式
/// </remarks>
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}");
}
}
/// <summary>
/// 处理指示器被干扰的事件
/// </summary>
/// <param name="parameters">干扰参数</param>
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
/// <param name="type">被清除的干扰类型</param>
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
/// </summary>
/// <remarks>
/// 激活过程:
/// - 设置激活状态
/// - 清除干扰状态
/// - 调用基类 Activate (处理 IsActive 和 JammingEvent 订阅)
/// - 开始激光照射
/// - 订阅相关事件
/// - 调用基类激活
/// </remarks>
public override void Activate()
{
if (!IsActive)
{
base.Activate(); // Call base Activate first
// Subscribe to Laser Jamming
SimulationManager.SubscribeToEvent<LaserJammingEvent>(OnLaserJamming);
// Subscribe to Smoke Events
SimulationManager.SubscribeToEvent<SmokeScreenEvent>(HandleSmokeEvent);
SimulationManager.SubscribeToEvent<SmokeScreenStopEvent>(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
/// </summary>
/// <remarks>
/// 停用过程:
/// - 清除激活状态
/// - 停止激光照射
/// - 取消事件订阅
/// - 清理工作状态
/// - 调用基类停用
/// - 调用基类 Deactivate (处理 IsActive 和 JammingEvent 取消订阅)
/// </remarks>
public override void Deactivate()
{
if (IsActive)
{
// Stop illumination first if active
StopLaserIllumination();
// Unsubscribe from events
SimulationManager.UnsubscribeFromEvent<LaserJammingEvent>(OnLaserJamming);
SimulationManager.UnsubscribeFromEvent<SmokeScreenEvent>(HandleSmokeEvent);
SimulationManager.UnsubscribeFromEvent<SmokeScreenStopEvent>(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
/// </remarks>
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
}
/// <summary>
/// 处理烟幕更新或停止事件,触发遮挡状态重新计算
/// 判断是否应该处理传入的干扰参数
/// </summary>
private void HandleSmokeEvent(SimulationEvent evt) // Can use base SimulationEvent type
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
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;
}
/// <summary>
@ -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";
}
}
}

View File

@ -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
{
/// <summary>
@ -18,203 +22,19 @@ namespace ThreatSource.Jammable
public class JammableComponent : IJammable
{
/// <summary>
/// 干扰处理器接口,用于处理实际的干扰逻辑
/// 内部干扰处理器实例,管理干扰状态和持续时间
/// </summary>
protected interface IJammingProcessor
{
/// <summary>
/// 获取当前是否处于被干扰状态
/// </summary>
bool IsJammed { get; }
/// <summary>
/// 设置干扰阈值
/// </summary>
/// <param name="type">干扰类型</param>
/// <param name="threshold">阈值值(单位:瓦特)</param>
void SetJammingThreshold(JammingType type, double threshold);
/// <summary>
/// 处理干扰
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>干扰是否生效</returns>
bool HandleJamming(JammingParameters parameters);
/// <summary>
/// 清除干扰
/// </summary>
void ClearJamming();
/// <summary>
/// 更新干扰状态
/// </summary>
/// <param name="deltaTime">时间步长,单位:秒</param>
void Update(double deltaTime);
}
private readonly JammingHandler _jammingHandler;
/// <summary>
/// 干扰处理器实现使用通用的JammingHandler并增强其功能
/// 干扰阈值字典
/// </summary>
protected class JammingProcessor : IJammingProcessor
{
private readonly JammingHandler _jammingHandler;
private readonly Dictionary<JammingType, double> _jammingThresholds = new Dictionary<JammingType, double>();
private readonly JammableComponent _owner;
/// <summary>
/// 获取当前是否处于被干扰状态
/// </summary>
public bool IsJammed => _jammingHandler.IsJammed;
/// <summary>
/// 初始化干扰处理器实例
/// </summary>
/// <param name="owner">所属的可干扰组件</param>
public JammingProcessor(JammableComponent owner)
{
_owner = owner;
_jammingHandler = new JammingHandlerAdapter(this);
}
/// <summary>
/// 设置干扰阈值
/// </summary>
/// <param name="type">干扰类型</param>
/// <param name="threshold">阈值值(单位:瓦特)</param>
public void SetJammingThreshold(JammingType type, double threshold)
{
_jammingThresholds[type] = threshold;
}
/// <summary>
/// 判断干扰是否有效(是否超过阈值)
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果干扰有效返回true否则返回false</returns>
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;
}
/// <summary>
/// 处理干扰
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>干扰是否生效</returns>
public bool HandleJamming(JammingParameters parameters)
{
// 只有当干扰有效时才处理
if (IsJammingEffective(parameters))
{
_jammingHandler.HandleJamming(parameters);
return true;
}
return false;
}
/// <summary>
/// 清除干扰
/// </summary>
public void ClearJamming()
{
_jammingHandler.ClearJamming();
}
/// <summary>
/// 更新干扰状态
/// </summary>
/// <param name="deltaTime">时间步长,单位:秒</param>
public void Update(double deltaTime)
{
_jammingHandler.Update(deltaTime);
}
/// <summary>
/// JammingHandler适配器类用于连接JammingHandler和JammingProcessor
/// </summary>
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);
}
}
}
/// <summary>
/// 干扰处理器实例
/// </summary>
protected readonly IJammingProcessor _jammingProcessor;
private readonly Dictionary<JammingType, double> _jammingThresholds = new Dictionary<JammingType, double>();
/// <summary>
/// 支持的干扰类型列表
/// </summary>
protected readonly List<JammingType> _supportedJammingTypes = new List<JammingType>();
private readonly List<JammingType> _supportedJammingTypes = new List<JammingType>();
/// <summary>
/// 位置提供委托,用于获取设备当前位置
@ -222,14 +42,14 @@ namespace ThreatSource.Jammable
private readonly Func<Vector3D> _positionProvider;
/// <summary>
/// 干扰应用事件委托
/// 当干扰被应用时触发
/// </summary>
private readonly Action<JammingParameters> _onJammingApplied;
public event Action<JammingParameters>? JammingApplied;
/// <summary>
/// 干扰清除事件委托
/// 当干扰被清除时触发
/// </summary>
private readonly Action<JammingType> _onJammingCleared;
public event Action<JammingType>? JammingCleared;
/// <summary>
/// 获取设备支持的干扰类型
@ -239,23 +59,20 @@ namespace ThreatSource.Jammable
/// <summary>
/// 获取设备当前是否处于被干扰状态
/// </summary>
public bool IsJammed => _jammingProcessor.IsJammed;
public bool IsJammed => _jammingHandler.IsJammed;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="positionProvider">位置提供委托</param>
/// <param name="onJammingApplied">干扰应用事件处理委托</param>
/// <param name="onJammingCleared">干扰清除事件处理委托</param>
public JammableComponent(
Func<Vector3D> positionProvider,
Action<JammingParameters> onJammingApplied,
Action<JammingType> onJammingCleared)
public JammableComponent(Func<Vector3D> 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;
}
/// <summary>
@ -264,7 +81,7 @@ namespace ThreatSource.Jammable
/// <param name="deltaTime">时间步长,单位:秒</param>
public void UpdateJammingStatus(double deltaTime)
{
_jammingProcessor.Update(deltaTime);
_jammingHandler.Update(deltaTime);
}
/// <summary>
@ -274,7 +91,7 @@ namespace ThreatSource.Jammable
/// <param name="threshold">阈值值(单位:瓦特)</param>
public void SetJammingThreshold(JammingType type, double threshold)
{
_jammingProcessor.SetJammingThreshold(type, threshold);
_jammingThresholds[type] = threshold;
}
/// <summary>
@ -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}");
}
}
/// <summary>
/// 清除干扰
/// </summary>
/// <param name="type">要清除的干扰类型</param>
/// <param name="type">要清除的干扰类型 (Note: JammingHandler clears all current jamming regardless of type)</param>
public void ClearJamming(JammingType type)
{
// 这里简化处理,直接清除当前干扰
_jammingProcessor.ClearJamming();
_jammingHandler.ClearJamming();
}
/// <summary>
/// 当干扰被应用时调用
/// 判断干扰是否有效(是否超过阈值和物理条件)
/// </summary>
/// <param name="parameters">干扰参数</param>
protected void OnJammingApplied(JammingParameters parameters)
/// <returns>如果干扰有效返回true否则返回false</returns>
public bool IsJammingEffective(JammingParameters parameters)
{
_onJammingApplied(parameters);
}
/// <summary>
/// 当干扰被清除时调用
/// </summary>
/// <param name="type">被清除的干扰类型</param>
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;
}
/// <summary>
@ -341,36 +220,35 @@ namespace ThreatSource.Jammable
/// </summary>
/// <param name="jammingResistanceThreshold">配置中的干扰抗性阈值,单位:瓦特</param>
/// <param name="supportedTypes">支持的干扰类型,默认为所有类型</param>
public void LoadJammingConfigFromThreshold(double jammingResistanceThreshold,
public void LoadJammingConfigFromThreshold(double jammingResistanceThreshold,
IEnumerable<JammingType>? supportedTypes = null)
{
// 如果未指定支持的干扰类型,则默认支持所有类型
if (supportedTypes == null)
IEnumerable<JammingType> typesToSupport = supportedTypes ?? Enum.GetValues(typeof(JammingType)).Cast<JammingType>();
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);
}
}
/// <summary>
/// 判断干扰是否有效
/// 处理内部 JammingHandler 的 JammingApplied 事件
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果干扰有效返回true否则返回false</returns>
public bool IsJammingEffective(JammingParameters parameters)
private void HandleInternalJammingApplied(JammingParameters parameters)
{
return ((JammingProcessor)_jammingProcessor).IsJammingEffective(parameters);
JammingApplied?.Invoke(parameters);
}
/// <summary>
/// 处理内部 JammingHandler 的 JammingCleared 事件
/// </summary>
private void HandleInternalJammingCleared(JammingParameters? parameters)
{
// 触发公共事件,如果可用,则提供类型
if (parameters != null)
{
JammingCleared?.Invoke(parameters.Type);
}
}
}
}

View File

@ -1,11 +1,12 @@
using ThreatSource.Jammer;
using System; // Added for Action delegate
namespace ThreatSource.Jammable
{
/// <summary>
/// 干扰处理基类
/// </summary>
public abstract class JammingHandler
public class JammingHandler
{
/// <summary>
/// 是否处于被干扰状态
@ -22,6 +23,16 @@ namespace ThreatSource.Jammable
/// </summary>
private double _elapsedTime;
/// <summary>
/// 当干扰被应用时触发
/// </summary>
public event Action<JammingParameters>? JammingApplied;
/// <summary>
/// 当干扰被清除时触发
/// </summary>
public event Action<JammingParameters>? JammingCleared;
/// <summary>
/// 更新干扰状态
/// </summary>
@ -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);
}
/// <summary>
@ -62,20 +73,29 @@ namespace ThreatSource.Jammable
_elapsedTime = 0;
var oldJamming = CurrentJamming;
CurrentJamming = null;
OnJammingCleared(oldJamming);
OnJammingCleared(oldJamming);
}
}
/// <summary>
/// 当干扰被应用时调用
/// 当干扰被应用时调用(内部辅助方法,触发事件)
/// </summary>
/// <param name="parameters">干扰参数</param>
protected abstract void OnJammingApplied(JammingParameters parameters);
protected virtual void OnJammingApplied(JammingParameters parameters)
{
JammingApplied?.Invoke(parameters);
}
/// <summary>
/// 当干扰被清除时调用
/// 当干扰被清除时调用(内部辅助方法,触发事件)
/// </summary>
/// <param name="parameters">被清除的干扰参数</param>
protected abstract void OnJammingCleared(JammingParameters? parameters);
protected virtual void OnJammingCleared(JammingParameters? parameters)
{
if (parameters != null)
{
JammingCleared?.Invoke(parameters);
}
}
}
}

View File

@ -18,7 +18,7 @@ namespace ThreatSource.Jammer
/// <summary>
/// 当前干扰参数
/// </summary>
protected JammingParameters? CurrentParameters { get; private set; }
protected JammingParameters? CurrentParameters { get; set; }
/// <summary>
/// 干扰器类型
@ -53,6 +53,30 @@ namespace ThreatSource.Jammer
IsJamming = false;
}
/// <summary>
/// 激活干扰器
/// </summary>
public override void Activate()
{
IsActive = true;
if (!IsJamming && CurrentParameters != null)
{
StartJamming(CurrentParameters);
}
}
/// <summary>
/// 禁用干扰器
/// </summary>
public override void Deactivate()
{
IsActive = false;
if (IsJamming)
{
StopJamming();
}
}
/// <summary>
/// 获取干扰器的当前运行状态
/// </summary>
@ -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
/// <summary>
/// 发布干扰开始事件
/// </summary>
protected abstract void PublishJammingStartedEvent(JammingParameters parameters);
protected void PublishJammingEvent(JammingParameters parameters)
{
var jammingEvent = new JammingEvent
{
SenderId = Id,
Parameters = parameters
};
SimulationManager.PublishEvent(jammingEvent);
}
/// <summary>
/// 发布干扰更新事件
/// 创建干扰参数
/// </summary>
protected abstract void PublishJammingUpdateEvent(JammingParameters parameters);
/// <returns>干扰参数</returns>
protected abstract JammingParameters CreateJammingParameters();
/// <summary>
/// 发布干扰结束事件
/// </summary>
protected abstract void PublishJammingStoppedEvent(JammingParameters parameters);
protected void PublishJammingStoppedEvent(JammingParameters parameters)
{
var stoppedEvent = new JammingStoppedEvent
{
SenderId = Id,
Parameters = parameters
};
SimulationManager.PublishEvent(stoppedEvent);
}
/// <summary>
/// 获取干扰器状态信息

View File

@ -0,0 +1,60 @@
using System.Collections.Generic;
using System.Linq;
using ThreatSource.Simulation;
using ThreatSource.Utils;
namespace ThreatSource.Jammer
{
/// <summary>
/// 红外干扰器实现
/// </summary>
public class InfraredJammer : BaseJammer
{
/// <summary>
/// 红外干扰器配置
/// </summary>
public readonly InfraredJammerConfig config;
/// <summary>
/// 干扰器类型
/// </summary>
protected override JammerType Type => JammerType.Infrared;
/// <summary>
/// 支持的干扰类型
/// </summary>
public override IEnumerable<JammingType> SupportedJammingTypes => [JammingType.Infrared];
/// <summary>
/// 初始化红外干扰器的新实例
/// </summary>
/// <param name="id">干扰器ID</param>
/// <param name="config">红外干扰器配置</param>
/// <param name="motionParameters">初始运动参数</param>
/// <param name="manager">仿真管理器实例</param>
public InfraredJammer(string id, InfraredJammerConfig config, MotionParameters motionParameters, ISimulationManager manager)
: base(id, motionParameters, manager)
{
this.config = config;
}
/// <summary>
/// 创建干扰参数
/// </summary>
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
};
}
}
}

View File

@ -17,6 +17,11 @@ namespace ThreatSource.Jammer
/// </summary>
public string JammerId { get; set; } = "";
/// <summary>
/// 干扰目标ID
/// </summary>
public string? TargetId { get; set; }
/// <summary>
/// 干扰功率,单位:瓦特
/// </summary>
@ -42,9 +47,9 @@ namespace ThreatSource.Jammer
public double AngleRange { get; set; }
/// <summary>
/// 干扰频率,单位:赫兹
/// 干扰波长,单位:微米
/// </summary>
public double Frequency { get; set; }
public double? Wavelength { get; set; }
/// <summary>
/// 持续时间单位null表示持续干扰

View File

@ -27,40 +27,10 @@ namespace ThreatSource.Jammer
public readonly LaserDecoyConfig config;
/// <summary>
/// 获取或设置诱偏源ID
/// 干扰源ID
/// </summary>
public string SourceId { get; set; }
private readonly string SourceId;
/// <summary>
/// 获取或设置诱偏源功率,单位:瓦特
/// </summary>
public double DecoyPower { get; set; }
/// <summary>
/// 获取或设置诱偏激光发散角,单位:弧度
/// </summary>
public double DecoyLaserDivergenceAngle { get; set; }
/// <summary>
/// 获取或设置反射系数
/// </summary>
public double ReflectionCoefficient { get; set; }
/// <summary>
/// 获取或设置生命周期,单位:秒
/// </summary>
public double LifeTime { get; set; }
/// <summary>
/// 获取创建时间
/// </summary>
public DateTime CreationTime { get; private set; }
/// <summary>
/// 获取或设置有效反射面积,单位:平方米
/// </summary>
public double ReflectiveArea { get; set; }
/// <summary>
/// 初始化激光诱偏目标的新实例
/// </summary>
@ -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;
}
/// <summary>
/// 创建烟幕干扰参数
/// </summary>
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
};
}
/// <summary>
/// 检查诱偏目标是否仍然活跃
/// </summary>
/// <returns>如果目标仍然活跃返回true否则返回false</returns>
public bool IsDecoyActive()
{
return (DateTime.Now - CreationTime).TotalSeconds < LifeTime;
}
/// <summary>
/// 激活激光诱偏目标
/// </summary>
public override void Activate()
{
IsActive = true;
if (!IsJamming)
{
var parameters = CreateJammingParameters();
StartJamming(parameters);
}
}
/// <summary>
/// 禁用激光诱偏目标
/// </summary>
public override void Deactivate()
{
IsActive = false;
if (IsJamming)
{
StopJamming();
}
}
/// <summary>
/// 更新诱偏目标状态
/// </summary>
/// <param name="deltaTime">时间步长,单位:秒</param>
public override void Update(double deltaTime)
{
base.Update(deltaTime);
// 如果生命周期结束,从仿真中移除
if (!IsDecoyActive())
{
Deactivate();
}
}
/// <summary>
/// 更新干扰状态
/// </summary>
/// <param name="deltaTime"></param>
protected override void UpdateJamming(double deltaTime)
{
if (IsJamming)
{
PublishJammingUpdateEvent(CreateJammingParameters());
}
}
/// <summary>
/// 发布干扰开始事件
/// </summary>
protected override void PublishJammingStartedEvent(JammingParameters parameters)
{
PublishLaserDecoyEvent();
}
/// <summary>
/// 发布干扰更新事件
/// </summary>
protected override void PublishJammingUpdateEvent(JammingParameters parameters)
{
PublishLaserDecoyEvent();
}
/// <summary>
/// 发布干扰停止事件
/// </summary>
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);
}
/// <summary>
/// 获取激光诱偏目标状态
/// </summary>
/// <returns>激光诱偏目标状态</returns>
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";
}
}
}

View File

@ -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
{
/// <summary>
/// 激光干扰器实现
/// </summary>
public class LaserJammer : BaseJammer
{
/// <summary>
/// 干扰器类型
/// </summary>
protected override JammerType Type => JammerType.Laser;
/// <summary>
/// 支持的干扰类型
/// </summary>
public override IEnumerable<JammingType> SupportedJammingTypes => [JammingType.Laser];
/// <summary>
/// 激光干扰器配置
/// </summary>
public readonly LaserJammerConfig config;
/// <summary>
/// 初始化激光干扰器的新实例
/// </summary>
/// <param name="id">干扰器ID</param>
/// <param name="config">激光干扰器配置</param>
/// <param name="motionParameters">初始运动参数</param>
/// <param name="manager">仿真管理器实例</param>
public LaserJammer(string id, LaserJammerConfig config, MotionParameters motionParameters, ISimulationManager manager)
: base(id, motionParameters, manager)
{
this.config = config;
}
/// <summary>
/// 创建干扰参数
/// </summary>
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
};
}
}
}

View File

@ -0,0 +1,61 @@
using System.Collections.Generic;
using System.Linq;
using ThreatSource.Simulation;
using ThreatSource.Utils;
namespace ThreatSource.Jammer
{
/// <summary>
/// 毫米波干扰器实现
/// </summary>
public class MillimeterWaveJammer : BaseJammer
{
/// <summary>
/// 干扰器类型
/// </summary>
protected override JammerType Type => JammerType.MillimeterWave;
/// <summary>
/// 支持的干扰类型
/// </summary>
public override IEnumerable<JammingType> SupportedJammingTypes => [JammingType.MillimeterWave];
/// <summary>
/// 毫米波干扰器配置
/// </summary>
public readonly MillimeterWaveJammerConfig config;
/// <summary>
/// 初始化毫米波干扰器的新实例
/// </summary>
/// <param name="id">干扰器ID</param>
/// <param name="config">毫米波干扰器配置</param>
/// <param name="motionParameters">初始运动参数</param>
/// <param name="manager">仿真管理器实例</param>
public MillimeterWaveJammer(string id, MillimeterWaveJammerConfig config, MotionParameters motionParameters, ISimulationManager manager)
: base(id, motionParameters, manager)
{
this.config = config;
}
/// <summary>
/// 创建干扰参数
/// </summary>
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) 以实现毫米波干扰的特定效果更新逻辑
}
}

View File

@ -74,7 +74,7 @@ namespace ThreatSource.Jammer
/// <summary>
/// 创建烟幕干扰参数
/// </summary>
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
}
}
}
/// <summary>
/// 发布干扰开始事件
/// </summary>
protected override void PublishJammingStartedEvent(JammingParameters parameters)
{
PublishSmokeEvent();
}
/// <summary>
/// 发布干扰更新事件
/// </summary>
protected override void PublishJammingUpdateEvent(JammingParameters parameters)
{
PublishSmokeEvent();
}
/// <summary>
/// 发布干扰结束事件
/// </summary>
protected override void PublishJammingStoppedEvent(JammingParameters parameters)
{
PublishSmokeStopEvent();
}
/// <summary>
/// 发布烟幕事件
/// </summary>
private void PublishSmokeEvent()
{
if (CurrentParameters == null) return;
var evt = new SmokeScreenEvent
{
SmokeGrenadeId = Id
};
PublishEvent(evt);
}
/// <summary>
/// 发布烟幕停止事件
/// </summary>
private void PublishSmokeStopEvent()
{
var evt = new SmokeScreenStopEvent
{
SmokeGrenadeId = Id
};
PublishEvent(evt);
}
/// <summary>
/// 计算观察者到目标的视线穿过烟雾的透射率

View File

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

View File

@ -106,77 +106,6 @@ namespace ThreatSource.Sensor
InitializeJamming(config.JammingResistanceThreshold, [JammingType.Infrared]);
}
/// <summary>
/// 激活红外探测器
/// </summary>
/// <remarks>
/// 激活红外探测器,设置传感器数据为活动状态
/// </remarks>
public override void Activate()
{
base.Activate();
SimulationManager.SubscribeToEvent<InfraredJammingEvent>(OnInfraredJamming);
}
/// <summary>
/// 停用红外探测器
/// </summary>
/// <remarks>
/// 停用红外探测器,取消事件订阅
/// </remarks>
public override void Deactivate()
{
base.Deactivate();
SimulationManager.UnsubscribeFromEvent<InfraredJammingEvent>(OnInfraredJamming);
}
/// <summary>
/// 处理红外干扰事件
/// </summary>
/// <param name="evt">红外干扰事件数据</param>
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}");
}
/// <summary>
/// 检查干扰波长是否与红外探测器波段匹配
/// </summary>
/// <param name="wavelength">干扰波长(微米)</param>
/// <returns>如果波长匹配返回true否则返回false</returns>
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,// 未知波段,默认不匹配
};
}
/// <summary>
/// 更新红外探测器的工作状态
/// </summary>
@ -247,16 +176,64 @@ namespace ThreatSource.Sensor
return sensorData;
}
/// <summary>
/// 判断是否应该处理传入的干扰参数
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
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;
}
/// <summary>
/// 检查干扰波长是否与红外探测器波段匹配
/// </summary>
/// <param name="wavelength">干扰波长(微米)</param>
/// <returns>如果波长匹配返回true否则返回false</returns>
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,// 未知波段,默认不匹配
};
}
/// <summary>
/// 处理红外干扰应用
/// </summary>
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; // 如果仍被干扰,保持无效
}
}
}
}

View File

@ -157,51 +157,31 @@ namespace ThreatSource.Sensor
}
/// <summary>
/// 激活激光测距仪
/// 判断是否应该处理传入的干扰参数
/// </summary>
public override void Activate()
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
protected override bool ShouldHandleJamming(JammingParameters parameters)
{
base.Activate();
SimulationManager.SubscribeToEvent<LaserJammingEvent>(OnLaserJamming);
}
/// <summary>
/// 停用激光测距仪
/// </summary>
public override void Deactivate()
{
base.Deactivate();
SimulationManager.UnsubscribeFromEvent<LaserJammingEvent>(OnLaserJamming);
}
/// <summary>
/// 处理激光干扰事件
/// </summary>
/// <param name="evt">激光干扰事件数据</param>
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;
}
/// <summary>
@ -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;
}
}
}

View File

@ -110,6 +110,34 @@ namespace ThreatSource.Sensor
InitializeJamming(config.JammingResistanceThreshold, [JammingType.MillimeterWave]);
}
/// <summary>
/// 判断是否应该处理传入的干扰参数
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
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;
}
/// <summary>
/// 更新毫米波测高雷达的工作状态
/// </summary>
@ -156,54 +184,6 @@ namespace ThreatSource.Sensor
return sensorData;
}
/// <summary>
/// 激活毫米波测高雷达
/// </summary>
public override void Activate()
{
base.Activate();
SimulationManager.SubscribeToEvent<MillimeterWaveJammingEvent>(OnMillimeterWaveJamming);
}
/// <summary>
/// 停用毫米波测高雷达
/// </summary>
public override void Deactivate()
{
base.Deactivate();
SimulationManager.UnsubscribeFromEvent<MillimeterWaveJammingEvent>(OnMillimeterWaveJamming);
}
/// <summary>
/// 处理毫米波干扰事件
/// </summary>
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);
}
/// <summary>
/// 检查干扰波长是否与测高雷达波段匹配
/// </summary>
@ -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;
}
}
}
}

View File

@ -216,51 +216,31 @@ namespace ThreatSource.Sensor
}
/// <summary>
/// 激活毫米波辐射计
/// 判断是否应该处理传入的干扰参数
/// </summary>
public override void Activate()
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
protected override bool ShouldHandleJamming(JammingParameters parameters)
{
base.Activate();
SimulationManager.SubscribeToEvent<MillimeterWaveJammingEvent>(OnMillimeterWaveJamming);
}
/// <summary>
/// 停用毫米波辐射计
/// </summary>
public override void Deactivate()
{
base.Deactivate();
SimulationManager.UnsubscribeFromEvent<MillimeterWaveJammingEvent>(OnMillimeterWaveJamming);
}
/// <summary>
/// 处理毫米波干扰事件
/// </summary>
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;
}
/// <summary>
@ -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;
// 不需要重置 IsTargetDetectedUpdateSensor 会处理
}
else
{
sensorData.IsValid = false; // 如果仍被干扰,保持无效
}
}
}
}

View File

@ -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;
}
/// <summary>
@ -171,6 +173,37 @@ namespace ThreatSource.Sensor
// 子类中实现具体的传感器更新逻辑
}
/// <summary>
/// 统一处理干扰事件
/// </summary>
/// <param name="evt">干扰事件</param>
protected virtual void HandleJammingEvent(JammingEvent evt)
{
if (evt == null) return;
// 在应用干扰前检查是否应该处理此干扰
if (!ShouldHandleJamming(evt.Parameters))
{
// 可选择记录日志Debug.WriteLine($"传感器 {Id} 忽略干扰事件,类型: {evt.Parameters.Type}");
return;
}
// 如果应该处理,则应用干扰
ApplyJamming(evt.Parameters);
}
/// <summary>
/// 判断是否应该处理传入的干扰参数(可被子类重写以添加特定检查)
/// </summary>
/// <param name="parameters">干扰参数</param>
/// <returns>如果应该处理则返回 true否则返回 false</returns>
protected virtual bool ShouldHandleJamming(JammingParameters parameters)
{
// 基类默认处理所有受支持类型的干扰
// 子类可以重写此方法添加额外检查,如波段匹配
return SupportedJammingTypes.Contains(parameters.Type);
}
/// <summary>
/// 应用干扰
/// </summary>
@ -209,5 +242,35 @@ namespace ThreatSource.Sensor
/// - 确保数据有效性
/// </remarks>
public abstract SensorData GetSensorData();
/// <summary>
/// 激活传感器
/// </summary>
public override void Activate()
{
if (!IsActive)
{
IsActive = true;
// 统一订阅 HandleJammingEvent
SimulationManager.SubscribeToEvent<JammingEvent>(HandleJammingEvent);
// 移除可能存在的旧订阅(如果子类之前有单独订阅)
}
base.Activate();
}
/// <summary>
/// 停用传感器
/// </summary>
public override void Deactivate()
{
if (IsActive)
{
IsActive = false;
// 统一取消订阅 HandleJammingEvent
SimulationManager.UnsubscribeFromEvent<JammingEvent>(HandleJammingEvent);
// 移除可能存在的旧取消订阅
}
base.Deactivate();
}
}
}

View File

@ -415,32 +415,6 @@ namespace ThreatSource.Simulation
public double WavelengthMax { get; set; } = 0;
}
/// <summary>
/// 激光干扰器配置类
/// </summary>
public class LaserJammerConfig
{
/// <summary>
/// 最大干扰冷却时间(秒)
/// </summary>
public double MaxJammingCooldown { get; set; } = 5.0;
/// <summary>
/// 最大干扰功率(瓦特)
/// </summary>
public double MaxJammingPower { get; set; } = 10000.0;
/// <summary>
/// 初始干扰功率(瓦特)
/// </summary>
public double InitialJammingPower { get; set; } = 4000.0;
/// <summary>
/// 功率增加速率(瓦特/秒)
/// </summary>
public double PowerIncreaseRate { get; set; } = 2000.0;
}
/// <summary>
/// 红外测角仪配置类
/// </summary>
@ -476,32 +450,6 @@ namespace ThreatSource.Simulation
public double JammingResistanceThreshold { get; set; } = 50;
}
/// <summary>
/// 毫米波干扰器配置类
/// </summary>
public class MillimeterWaveJammerConfig
{
/// <summary>
/// 最大干扰功率(瓦特)
/// </summary>
public double MaxJammingPower { get; set; } = 1000;
/// <summary>
/// 初始干扰功率(瓦特)
/// </summary>
public double InitialJammingPower { get; set; } = 400;
/// <summary>
/// 功率增长率(瓦特/秒)
/// </summary>
public double PowerIncreaseRate { get; set; } = 200;
/// <summary>
/// 最大冷却时间(秒)
/// </summary>
public double MaxJammingCooldown { get; set; } = 5;
}
/// <summary>
/// 红外指令导引系统配置类
/// </summary>
@ -1737,6 +1685,99 @@ namespace ThreatSource.Simulation
}
}
/// <summary>
/// 红外干扰器配置类
/// </summary>
public class InfraredJammerConfig
{
/// <summary>
/// 干扰功率,单位:瓦特
/// </summary>
public double Power { get; set; } = 1000;
/// <summary>
/// 干扰波长,单位:微米
/// </summary>
public double Wavelength { get; set; } = 5;
/// <summary>
/// 干扰角度范围,单位:度
/// </summary>
public double AngleRange { get; set; } = 10;
/// <summary>
/// 干扰模式
/// </summary>
public JammingMode Mode { get; set; } = JammingMode.Noise;
/// <summary>
/// 持续时间,单位:秒
/// </summary>
public double Duration { get; set; } = 10;
}
/// <summary>
/// 毫米波干扰器配置类
/// </summary>
public class MillimeterWaveJammerConfig
{
/// <summary>
/// 干扰功率,单位:瓦特
/// </summary>
public double Power { get; set; } = 1000;
/// <summary>
/// 干扰波长,单位:微米
/// </summary>
public double Wavelength { get; set; } = 3e3;
/// <summary>
/// 干扰角度范围,单位:度
/// </summary>
public double AngleRange { get; set; } = 10;
/// <summary>
/// 干扰模式
/// </summary>
public JammingMode Mode { get; set; } = JammingMode.Noise;
/// <summary>
/// 持续时间,单位:秒
/// </summary>
public double Duration { get; set; } = 10;
}
/// <summary>
/// 激光干扰器配置类
/// </summary>
public class LaserJammerConfig
{
/// <summary>
/// 干扰功率,单位:瓦特
/// </summary>
public double Power { get; set; } = 1000;
/// <summary>
/// 干扰波长,单位:微米
/// </summary>
public double Wavelength { get; set; } = 1.06;
/// <summary>
/// 干扰角度范围,单位:度
/// </summary>
public double AngleRange { get; set; } = 10;
/// <summary>
/// 干扰模式
/// </summary>
public JammingMode Mode { get; set; } = JammingMode.Noise;
/// <summary>
/// 持续时间,单位:秒
/// </summary>
public double Duration { get; set; } = 10;
}
/// <summary>
/// 激光诱偏目标配置类
/// </summary>
@ -1747,6 +1788,11 @@ namespace ThreatSource.Simulation
/// </summary>
public double DecoyPower { get; set; } = 0;
/// <summary>
/// 诱偏激光波长,单位:微米
/// </summary>
public double DecoyWavelength { get; set; } = 1.06;
/// <summary>
/// 诱偏激光发散角,单位:度
/// </summary>

View File

@ -115,80 +115,6 @@ namespace ThreatSource.Simulation
public string? TargetId { get; set; }
}
/// <summary>
/// 激光干扰事件,表示对激光制导系统的干扰
/// </summary>
/// <remarks>
/// 用于模拟激光干扰效果
/// 包含干扰功率信息
/// </remarks>
public class LaserJammingEvent : SimulationEvent
{
/// <summary>
/// 获取或设置干扰功率值
/// </summary>
/// <remarks>
/// 单位:瓦特
/// 表示干扰源的输出功率
/// </remarks>
public double JammingPower { get; set; }
/// <summary>
/// 获取或设置波长
/// </summary>
/// <remarks>
/// 单位:微米
/// 干扰激光的波长
/// </remarks>
public double Wavelength { get; set; } = 1.06;
/// <summary>
/// 获取或设置干扰源位置
/// </summary>
/// <remarks>
/// 干扰设备在三维空间中的位置
/// 用于计算干扰效果衰减
/// </remarks>
public Vector3D JammingSourcePosition { get; set; } = Vector3D.Zero;
/// <summary>
/// 获取或设置干扰方向
/// </summary>
/// <remarks>
/// 干扰波束的主方向向量
/// 单位向量
/// </remarks>
public Vector3D JammingDirection { get; set; } = Vector3D.UnitX;
/// <summary>
/// 获取或设置干扰角度范围
/// </summary>
/// <remarks>
/// 单位:弧度
/// 定义了干扰波束的发散角度
/// 影响干扰的覆盖范围
/// </remarks>
public double JammingAngleRange { get; set; } = 0.1; // 激光干扰角度范围默认更小
/// <summary>
/// 获取或设置干扰模式
/// </summary>
/// <remarks>
/// 定义干扰的工作模式
/// 影响干扰的效果类型
/// </remarks>
public JammingMode JammingMode { get; set; } = JammingMode.Noise;
/// <summary>
/// 获取或设置干扰持续时间
/// </summary>
/// <remarks>
/// 单位:秒
/// null表示持续干扰直到显式清除
/// </remarks>
public double? Duration { get; set; }
}
/// <summary>
/// 实体销毁事件,表示仿真实体被销毁
/// </summary>
@ -518,133 +444,6 @@ namespace ThreatSource.Simulation
/// </summary>
public string? TargetId { get; set; }
}
/// <summary>
/// 红外干扰事件
/// </summary>
public class InfraredJammingEvent : SimulationEvent
{
/// <summary>
/// 干扰功率(瓦特)
/// </summary>
public double JammingPower { get; set; }
/// <summary>
/// 波长(微米)
/// </summary>
public double Wavelength { get; set; }
/// <summary>
/// 干扰源位置
/// </summary>
/// <remarks>
/// 干扰设备在三维空间中的位置
/// 用于计算干扰效果衰减
/// </remarks>
public Vector3D JammingSourcePosition { get; set; } = Vector3D.Zero;
/// <summary>
/// 干扰方向
/// </summary>
/// <remarks>
/// 干扰波束的主方向向量
/// 单位向量
/// </remarks>
public Vector3D JammingDirection { get; set; } = Vector3D.UnitX;
/// <summary>
/// 干扰角度范围(弧度)
/// </summary>
/// <remarks>
/// 定义了干扰波束的发散角度
/// 影响干扰的覆盖范围
/// </remarks>
public double JammingAngleRange { get; set; } = 0.5;
/// <summary>
/// 干扰模式
/// </summary>
/// <remarks>
/// 定义干扰的工作模式
/// 影响干扰的效果类型
/// </remarks>
public JammingMode JammingMode { get; set; } = JammingMode.Noise;
/// <summary>
/// 干扰持续时间(秒)
/// </summary>
/// <remarks>
/// null表示持续干扰直到显式清除
/// </remarks>
public double? Duration { get; set; }
}
/// <summary>
/// 毫米波干扰事件,表示对毫米波雷达的干扰
/// </summary>
/// <remarks>
/// 用于模拟对毫米波制导系统的干扰
/// 包含干扰功率信息
/// </remarks>
public class MillimeterWaveJammingEvent : SimulationEvent
{
/// <summary>
/// 获取或设置干扰功率值
/// </summary>
/// <remarks>
/// 单位:瓦特
/// 表示毫米波干扰源的输出功率
/// </remarks>
public double JammingPower { get; set; }
/// <summary>
/// 波长(微米)
/// </summary>
public double Wavelength { get; set; }
/// <summary>
/// 干扰源位置
/// </summary>
/// <remarks>
/// 干扰设备在三维空间中的位置
/// 用于计算干扰效果衰减
/// </remarks>
public Vector3D JammingSourcePosition { get; set; } = Vector3D.Zero;
/// <summary>
/// 干扰方向
/// </summary>
/// <remarks>
/// 干扰波束的主方向向量
/// 单位向量
/// </remarks>
public Vector3D JammingDirection { get; set; } = Vector3D.UnitX;
/// <summary>
/// 干扰角度范围(弧度)
/// </summary>
/// <remarks>
/// 定义了干扰波束的发散角度
/// 影响干扰的覆盖范围
/// </remarks>
public double JammingAngleRange { get; set; } = 0.5;
/// <summary>
/// 干扰模式
/// </summary>
/// <remarks>
/// 定义干扰的工作模式
/// 影响干扰的效果类型
/// </remarks>
public JammingMode JammingMode { get; set; } = JammingMode.Noise;
/// <summary>
/// 干扰持续时间(秒)
/// </summary>
/// <remarks>
/// null表示持续干扰直到显式清除
/// </remarks>
public double? Duration { get; set; }
}
/// <summary>
/// 激光编码不匹配事件,表示导弹接收到与期望不符的激光编码
@ -688,43 +487,6 @@ namespace ThreatSource.Simulation
public LaserCodeConfig? ReceivedCodeConfig { get; set; }
}
/// <summary>
/// 烟幕事件,表示烟幕的生成和扩散
/// </summary>
/// <remarks>
/// 用于模拟烟幕生成和影响
/// 触发时机:烟幕弹爆炸或烟幕状态更新时
/// </remarks>
public class SmokeScreenEvent : SimulationEvent
{
/// <summary>
/// 获取或设置烟幕弹ID
/// </summary>
/// <remarks>
/// 标识生成烟幕的烟幕弹
/// </remarks>
public string? SmokeGrenadeId { get; set; }
}
/// <summary>
/// 烟幕停止事件,表示烟幕状态的停止
/// </summary>
/// <remarks>
/// 用于模拟烟幕状态的停止
/// 触发时机:烟幕停止时
/// </remarks>
public class SmokeScreenStopEvent : SimulationEvent
{
/// <summary>
/// 获取或设置烟幕弹ID
/// </summary>
/// <remarks>
/// 标识停止的烟幕弹
/// </remarks>
public string? SmokeGrenadeId { get; set; }
}
/// <summary>
/// 激光诱偏目标事件,表示激光诱偏目标被照射
@ -769,6 +531,53 @@ namespace ThreatSource.Simulation
/// </remarks>
public string? LaserDecoyId { get; set; }
}
// --- General Jamming Events ---
/// <summary>
/// 通用干扰事件,表示干扰器正在发射干扰信号
/// </summary>
/// <remarks>
/// 由干扰器 (IJammer 实现) 发布,表示其正在发射具有指定参数的干扰信号。
/// 在干扰开始或参数更新时发布。
/// SenderId 为干扰器ID。
/// </remarks>
public class JammingEvent : SimulationEvent
{
/// <summary>
/// 获取或设置当前的干扰参数
/// </summary>
/// <remarks>
/// 包含了干扰类型、功率、位置、方向、模式、持续时间等详细信息
/// </remarks>
public required JammingParameters Parameters { get; set; }
/// <summary>
/// 获取当前干扰类型 (方便快速访问)
/// </summary>
public JammingType CurrentJammingType => Parameters.Type;
}
/// <summary>
/// 通用干扰停止事件,表示干扰器停止发射
/// </summary>
/// <remarks>
/// 由干扰器 (IJammer 实现) 发布,通知系统其干扰已停止发射。
/// SenderId 为干扰器ID。
/// </remarks>
public class JammingStoppedEvent : SimulationEvent
{
/// <summary>
/// 获取或设置停止前的干扰参数
/// </summary>
/// <remarks>
/// 包含了停止前有效的干扰类型、功率、位置、方向、模式、持续时间等信息。
/// </remarks>
public required JammingParameters Parameters { get; set; }
/// <summary>
/// 获取已停止的干扰类型 (方便快速访问)
/// </summary>
public JammingType StoppedJammingType => Parameters.Type;
}
}

View File

@ -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 长波

View File

@ -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
/// <summary>
/// 应用干扰
/// </summary>
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
/// <summary>
/// 清除干扰
/// </summary>
public void ClearJamming(JammingType type)
public void ClearJamming(JammingType type, string category)
{
var jammingParams = new JammingParameters
{

View File

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