mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fail gracefully when out of radio channels.
Fixes https://github.com/Khopa/dcs_liberation/issues/598 (cherry picked from commit 498af28efb2d0d556c4a7ec8433f846a23716649)
This commit is contained in:
parent
6bb0bdf66e
commit
2288b7f7b2
@ -1,5 +1,6 @@
|
||||
"""Radio frequency types and allocators."""
|
||||
import itertools
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, Iterator, List, Set
|
||||
|
||||
@ -71,12 +72,9 @@ class Radio:
|
||||
self.minimum.hertz, self.maximum.hertz, self.step.hertz
|
||||
))
|
||||
|
||||
|
||||
class OutOfChannelsError(RuntimeError):
|
||||
"""Raised when all channels usable by this radio have been allocated."""
|
||||
|
||||
def __init__(self, radio: Radio) -> None:
|
||||
super().__init__(f"No available channels for {radio}")
|
||||
@property
|
||||
def last_channel(self) -> RadioFrequency:
|
||||
return RadioFrequency(self.maximum.hertz - self.step.hertz)
|
||||
|
||||
|
||||
class ChannelInUseError(RuntimeError):
|
||||
@ -215,7 +213,13 @@ class RadioRegistry:
|
||||
self.reserve(channel)
|
||||
return channel
|
||||
except StopIteration:
|
||||
raise OutOfChannelsError(radio)
|
||||
# In the event of too many channel users, fail gracefully by reusing
|
||||
# the last channel.
|
||||
# https://github.com/Khopa/dcs_liberation/issues/598
|
||||
channel = radio.last_channel
|
||||
logging.warning(
|
||||
f"No more free channels for {radio.name}. Reusing {channel}.")
|
||||
return channel
|
||||
|
||||
def alloc_uhf(self) -> RadioFrequency:
|
||||
"""Allocates a UHF radio channel suitable for inter-flight comms.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user