Allow operation.py to ignore TACAN rules

This commit is contained in:
Magnus Wolffelt
2021-08-18 00:06:34 +02:00
parent f63a35b1fa
commit 34ff5fbc6a
3 changed files with 22 additions and 4 deletions

View File

@@ -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,13 +116,15 @@ 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 channel.number in UNAVAILABLE[intended_usage][channel.band]:
raise TacanChannelForbiddenError(channel)
if not ignore_rules:
if channel.number in UNAVAILABLE[intended_usage][channel.band]:
raise TacanChannelForbiddenError(channel)
if channel in self.allocated_channels:
raise TacanChannelInUseError(channel)
self.allocated_channels.add(channel)