Files

34 lines
1.5 KiB
Python

"""Physical limits checked before command encoding or any board reset."""
import math
from .constants import (
TEMP_MIN_C, TEMP_MAX_C, CURRENT_MIN_MA, CURRENT_MAX_MA,
CURRENT_STEP_MIN_MA, CURRENT_STEP_MAX_MA,
TIME_STEP_MIN_US, TIME_STEP_MAX_US, DELAY_TIME_MIN_MS, DELAY_TIME_MAX_MS,
)
from .exceptions import ValidationError
def _range(value: float, name: str, low: float, high: float) -> None:
if not isinstance(value, (int, float)) or not math.isfinite(value) or not low <= value <= high:
raise ValidationError(f"{name} must be a finite number in [{low}, {high}], got {value!r}")
def validate_manual(temp1: float, temp2: float, current1: float, current2: float) -> None:
for name, value in (("temp1", temp1), ("temp2", temp2)):
_range(value, name, TEMP_MIN_C, TEMP_MAX_C)
for name, value in (("current1", current1), ("current2", current2)):
_range(value, name, CURRENT_MIN_MA, CURRENT_MAX_MA)
def validate_variation(min_value: float, max_value: float, step: float,
time_step: int, delay_time: int) -> None:
for name, value in (("min_value", min_value), ("max_value", max_value)):
_range(value, name, CURRENT_MIN_MA, CURRENT_MAX_MA)
if min_value >= max_value:
raise ValidationError("min_value must be less than max_value")
_range(step, "step", CURRENT_STEP_MIN_MA, CURRENT_STEP_MAX_MA)
_range(time_step, "time_step (us)", TIME_STEP_MIN_US, TIME_STEP_MAX_US)
_range(delay_time, "delay_time (ms)", DELAY_TIME_MIN_MS, DELAY_TIME_MAX_MS)