Rework radar system
This commit is contained in:
@@ -60,7 +60,7 @@ class CommunicationError(LaserControlError):
|
||||
class PortNotFoundError(CommunicationError):
|
||||
"""Exception raised when serial port cannot be found."""
|
||||
|
||||
def __init__(self, port: str = None):
|
||||
def __init__(self, port: str | None = None):
|
||||
if port:
|
||||
message = f"Serial port '{port}' not found"
|
||||
else:
|
||||
@@ -77,7 +77,7 @@ class PortBusyError(CommunicationError):
|
||||
of silently sharing the bus and corrupting both sides' traffic.
|
||||
"""
|
||||
|
||||
def __init__(self, port: str = None):
|
||||
def __init__(self, port: str | None = None):
|
||||
target = f"'{port}'" if port else "the laser controller port"
|
||||
super().__init__(
|
||||
f"Serial port {target} is busy — another program is already using "
|
||||
@@ -89,7 +89,7 @@ class PortBusyError(CommunicationError):
|
||||
class DeviceNotRespondingError(CommunicationError):
|
||||
"""Exception raised when device doesn't respond to commands."""
|
||||
|
||||
def __init__(self, timeout: float = None):
|
||||
def __init__(self, timeout: float | None = None):
|
||||
if timeout:
|
||||
message = f"Device did not respond within {timeout} seconds"
|
||||
else:
|
||||
@@ -100,7 +100,7 @@ class DeviceNotRespondingError(CommunicationError):
|
||||
class CRCError(CommunicationError):
|
||||
"""Exception raised when CRC check fails."""
|
||||
|
||||
def __init__(self, expected: int = None, received: int = None):
|
||||
def __init__(self, expected: int | None = None, received: int | None = None):
|
||||
if expected is not None and received is not None:
|
||||
message = f"CRC check failed. Expected: 0x{expected:04X}, Received: 0x{received:04X}"
|
||||
else:
|
||||
@@ -113,45 +113,3 @@ class ProtocolError(CommunicationError):
|
||||
|
||||
def __init__(self, message: str):
|
||||
super().__init__(f"Protocol error: {message}")
|
||||
|
||||
|
||||
class DeviceError(LaserControlError):
|
||||
"""Base exception for device-level errors."""
|
||||
pass
|
||||
|
||||
|
||||
class DeviceOverheatingError(DeviceError):
|
||||
"""Exception raised when device reports overheating."""
|
||||
|
||||
def __init__(self, laser_id: int = None, temperature: float = None):
|
||||
if laser_id and temperature:
|
||||
message = f"Laser {laser_id} overheating: {temperature}°C"
|
||||
else:
|
||||
message = "Device overheating detected"
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class PowerSupplyError(DeviceError):
|
||||
"""Exception raised when power supply issues are detected."""
|
||||
|
||||
def __init__(self, rail: str = None, voltage: float = None, expected: float = None):
|
||||
if rail and voltage is not None:
|
||||
if expected:
|
||||
message = f"Power supply {rail}: {voltage}V (expected ~{expected}V)"
|
||||
else:
|
||||
message = f"Power supply {rail}: abnormal voltage {voltage}V"
|
||||
else:
|
||||
message = "Power supply error detected"
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class DeviceStateError(DeviceError):
|
||||
"""Exception raised when device is in an error state."""
|
||||
|
||||
def __init__(self, state_code: int, state_name: str = None):
|
||||
self.state_code = state_code
|
||||
if state_name:
|
||||
message = f"Device error state: {state_name} (0x{state_code:04X})"
|
||||
else:
|
||||
message = f"Device error state: 0x{state_code:04X}"
|
||||
super().__init__(message)
|
||||
Reference in New Issue
Block a user