Files
dynalab-core/test/manual/core.py
T
h3cx 207a91811e Moved derive unit API to DLUnit
Derived units now use a DLUnit class similar to a DLPak to be easily
stored and loaded, the public API has been updated to either take a
DLUnit object or a Path where it reads the DLUnit from a *.dlunit file

The .dlunit file is a ZIP compressed archive containing two files, a
manifest.json which stores the units uuid, its input signals and its
output signal, and unit.py which is the python code for the unit, the
same rules apply (one python function with a specifically structured
signature) as when a string was passed in the old API

Errors have been added to have a DLUnitError similar to the DLPakError
as the DLUnit class is heavily inspired from the DLPak architecutre

Logging may still be primitive, this will be covered in the next AI
logging sweep to homogenize and clean up the logging aspect of things
2026-09-15 17:13:27 +02:00

66 lines
1.7 KiB
Python

import logging
from pathlib import Path
from time import sleep
from uuid import UUID, uuid4
from rich.logging import RichHandler
from dynalab_core import Core
from dynalab_core.config import CoreConfig
from dynalab_core.dlunit import DLUnit
from dynalab_core.protocols.packets.handshake import SignalDescriptor
logging.basicConfig(
level=logging.DEBUG,
format="%(name)s %(message)s",
datefmt="%H:%M:%S",
handlers=[RichHandler(rich_tracebacks=True, show_path=False)],
force=True,
)
log = logging.getLogger(__name__)
processing_str = Path(
"/home/hector/projects/Exergie/dynalab-core/test/manual/process.py"
).read_text(encoding="utf-8")
signal_id_1: UUID = UUID("3f32cea3-d872-4c16-a0a2-54b57171aeb2")
signal_id_2: UUID = UUID("6578ac37-99d1-410c-b3f7-d049339919b2")
config = CoreConfig(port=8765)
log.info("Configured manual core on %s", config.bind_str())
dl_core = Core(config)
dl_core.start()
dl_unit = DLUnit()
dl_unit.set_manifest(
uuid4(),
[
SignalDescriptor(
id=signal_id_1, name="Dummy signal 1", type="number", timeout_ms=5000
),
SignalDescriptor(
id=signal_id_2, name="Dummy signal 2", type="number", timeout_ms=5000
),
],
SignalDescriptor(id=uuid4(), name="Dummy sum", type="number", timeout_ms=5000),
)
dl_unit.set_data(processing_str)
unit_id = dl_core.bind_derive_unit(dl_unit)
# for i in range(10):
# dl_core.wait(1)
# values = dl_core.get_all_live_values()
# log.debug(f"Core values: {values}")
#
# dl_core.set_mode("playback")
try:
while True:
dl_core.wait(1)
values = dl_core.get_all_live_values()
log.debug(f"Core values: {values}")
except KeyboardInterrupt:
log.info("Received keyboard interrupt")
dl_core.stop()