sweep feature added

This commit is contained in:
Ayzen
2026-10-09 19:45:30 +03:00
parent 62e0430668
commit a1386e2588
8 changed files with 241 additions and 6 deletions
+20 -1
View File
@@ -29,6 +29,7 @@ from .constants import (
CMD_DS1809_CONTROL,
CMD_STATE,
CMD_STM32_DAC_CONTROL,
CMD_SWEEP_CONTROL,
CMD_TEC_MODULATION_CONTROL,
CMD_TRANS_ENABLE,
DEFAULT_SETUP_WORD,
@@ -47,6 +48,9 @@ from .constants import (
SEND_PARAMS_TOTAL_LENGTH,
SHORT_CONTROL_TOTAL_LENGTH,
STM32_DAC_FLAG_ENABLE,
SWEEP_CONTROL_TOTAL_LENGTH,
SWEEP_FLAG_ENABLE,
SWEEP_FLAG_TARGET_STM32_DAC,
TEC_MODULATION_FLAG_CHANNEL_2,
TEC_MODULATION_FLAG_ENABLE,
STATUS_DESCRIPTIONS,
@@ -65,7 +69,7 @@ from .conversions import (
voltage_7v_n_to_v,
)
from .exceptions import CRCError, ProtocolError
from .models import DeviceState, Measurements
from .models import DeviceState, Measurements, SweepSettings, SweepTarget
def _int_to_hex4(value: int) -> str:
@@ -293,6 +297,21 @@ class Protocol:
_ensure_uint(amplitude_code, "amplitude_code", 0, 0xFFFF),
)
@staticmethod
def encode_sweep_control(settings: SweepSettings) -> bytes:
"""Build a laser-2-current or STM32-DAC staircase sweep control packet."""
flags = SWEEP_FLAG_ENABLE if settings.enabled else 0
if settings.target == SweepTarget.STM32_DAC:
flags |= SWEEP_FLAG_TARGET_STM32_DAC
payload = [flags] + [
_ensure_uint(getattr(settings, name), name, 0, 0xFFFF)
for name in ("min_code", "max_code", "step_code", "step_period_us", "pause_ms")
]
packet = _pack_words([CMD_SWEEP_CONTROL, *payload, _payload_checksum(payload)])
if len(packet) != SWEEP_CONTROL_TOTAL_LENGTH:
raise ProtocolError(f"Sweep control length mismatch: {len(packet)} bytes")
return packet
@staticmethod
def encode_ad9102_wave_begin(sample_count: int, pat_period_us: int = 0) -> bytes:
"""Build an AD9102 custom-wave upload BEGIN packet.