mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Allow operation.py to ignore TACAN rules
This commit is contained in:
parent
f63a35b1fa
commit
34ff5fbc6a
@ -229,7 +229,9 @@ class Operation:
|
||||
logging.error(f"TACAN beacon has no channel: {beacon.callsign}")
|
||||
else:
|
||||
cls.tacan_registry.reserve(
|
||||
beacon.tacan_channel, TacanUsage.TransmitReceive
|
||||
beacon.tacan_channel,
|
||||
TacanUsage.TransmitReceive,
|
||||
ignore_rules=True,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
@ -103,7 +103,12 @@ class TacanRegistry:
|
||||
except StopIteration:
|
||||
raise OutOfTacanChannelsError(band)
|
||||
|
||||
def reserve(self, channel: TacanChannel, intended_usage: TacanUsage) -> None:
|
||||
def reserve(
|
||||
self,
|
||||
channel: TacanChannel,
|
||||
intended_usage: TacanUsage,
|
||||
ignore_rules: bool = False,
|
||||
) -> None:
|
||||
"""Reserves the given channel.
|
||||
|
||||
Reserving a channel ensures that it will not be allocated in the future.
|
||||
@ -111,11 +116,13 @@ class TacanRegistry:
|
||||
Args:
|
||||
channel: The channel to reserve.
|
||||
intended_usage: What the caller intends to use the tacan channel for.
|
||||
ignore_rules: Whether to reserve regardless of recommended rules.
|
||||
|
||||
Raises:
|
||||
TacanChannelInUseError: The given channel is already in use.
|
||||
TacanChannelForbiddenError: The given channel is forbidden.
|
||||
"""
|
||||
if not ignore_rules:
|
||||
if channel.number in UNAVAILABLE[intended_usage][channel.band]:
|
||||
raise TacanChannelForbiddenError(channel)
|
||||
if channel in self.allocated_channels:
|
||||
|
||||
@ -24,6 +24,15 @@ def test_allocate_first_few_channels() -> None:
|
||||
assert chan3 == TacanChannel(32, TacanBand.X)
|
||||
|
||||
|
||||
def test_reserve_ignoring_rules() -> None:
|
||||
registry = TacanRegistry()
|
||||
with pytest.raises(TacanChannelForbiddenError):
|
||||
registry.reserve(TacanChannel(16, TacanBand.X), TacanUsage.TransmitReceive)
|
||||
registry.reserve(
|
||||
TacanChannel(16, TacanBand.X), TacanUsage.TransmitReceive, ignore_rules=True
|
||||
)
|
||||
|
||||
|
||||
def test_allocate_different_usages() -> None:
|
||||
"""Make sure unallocated channels for one use don't make channels unavailable for other usage"""
|
||||
registry = TacanRegistry()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user