Added derive units to core
Derive units are now available in the core and has their relevant input values routed and outputs are looped back into the core router Fixed the dlpak manifest which had no signal descriptors
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
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.protocols.packets.handshake import SignalDescriptor
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
@@ -14,13 +18,39 @@ logging.basicConfig(
|
||||
)
|
||||
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_core.start_recording()
|
||||
|
||||
for i in range(2):
|
||||
dl_core.wait(1)
|
||||
values = dl_core.get_all_live_values()
|
||||
log.debug(f"Core values: {values}")
|
||||
|
||||
unit_id = dl_core.bind_derive_unit(
|
||||
processing_str,
|
||||
[
|
||||
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),
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
while True:
|
||||
dl_core.wait(1)
|
||||
|
||||
+19
-10
@@ -52,7 +52,8 @@ logging.basicConfig(
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
signal_id: UUID = uuid4()
|
||||
signal_id_1: UUID = UUID("3f32cea3-d872-4c16-a0a2-54b57171aeb2")
|
||||
signal_id_2: UUID = UUID("6578ac37-99d1-410c-b3f7-d049339919b2")
|
||||
|
||||
|
||||
def monotonic_ms() -> int:
|
||||
@@ -117,13 +118,18 @@ def value_sender_thread(
|
||||
next_send_time += period
|
||||
|
||||
message = ValueBatch(values=[])
|
||||
for i in range(10):
|
||||
value = ValueDescriptor(
|
||||
signal_id=signal_id,
|
||||
value=2.0,
|
||||
timestamp=monotonic_ns(),
|
||||
)
|
||||
message.values.append(value)
|
||||
value1 = ValueDescriptor(
|
||||
signal_id=signal_id_1,
|
||||
value=2.0,
|
||||
timestamp=monotonic_ns(),
|
||||
)
|
||||
value2 = ValueDescriptor(
|
||||
signal_id=signal_id_2,
|
||||
value=1.0,
|
||||
timestamp=monotonic_ns(),
|
||||
)
|
||||
message.values.append(value1)
|
||||
message.values.append(value2)
|
||||
|
||||
future = asyncio.run_coroutine_threadsafe(
|
||||
send_message(
|
||||
@@ -205,8 +211,11 @@ async def perform_handshake(
|
||||
connector_version=CONNECTOR_VERSION.get_version(),
|
||||
signals=[
|
||||
SignalDescriptor(
|
||||
id=signal_id, name="Dummy signal", type="number", timeout_ms=5000
|
||||
)
|
||||
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
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
from dynalab_core.protocols.packets.data import ValueDescriptor
|
||||
from dynalab_core.protocols.packets.handshake import SignalDescriptor
|
||||
|
||||
|
||||
def process(
|
||||
a: ValueDescriptor, b: ValueDescriptor, r: SignalDescriptor
|
||||
) -> ValueDescriptor:
|
||||
val = ValueDescriptor(
|
||||
signal_id=r.id, value=a.value * b.value, timestamp=a.timestamp
|
||||
)
|
||||
return val
|
||||
Reference in New Issue
Block a user