Files
dynalab-core/test/manual/core.py
T
h3cx 377e6fb323 Added playback mode ready for offline processing
CoreConfig how has a playback mode option which can be set to reprocess
or read.

Setting it to reprocess means that all derived signals are reprocessed
during playback, in this case the PlaybackEngine only plays back the
signals whose source is set to "origin"

Setting it to read means that all derived signals are playedback from
the recorded buffer, this whill be the preferred mode once offline
processing is set up which will allow for more complex data processing
offline once a recording is completed, which would require the read
playback mode as it wouldn't support realtime processing as reprocess
does
2026-09-18 21:27:52 +02:00

66 lines
1.8 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, thread_debug=True)
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()