Skip to content
Snippets Groups Projects
Commit 025899b3 authored by David Hammer's avatar David Hammer
Browse files

Start sketching changes based on dev meeting

parent 7a2231e7
No related branches found
No related tags found
1 merge request!53Train picker arbiter kernel
...@@ -10,6 +10,7 @@ from karabo.bound import ( ...@@ -10,6 +10,7 @@ from karabo.bound import (
KARABO_CLASSINFO, KARABO_CLASSINFO,
NDARRAY_ELEMENT, NDARRAY_ELEMENT,
NODE_ELEMENT, NODE_ELEMENT,
OUTPUT_CHANNEL,
OVERWRITE_ELEMENT, OVERWRITE_ELEMENT,
SLOT_ELEMENT, SLOT_ELEMENT,
STRING_ELEMENT, STRING_ELEMENT,
...@@ -50,6 +51,23 @@ class PickyBoi(PythonDevice): ...@@ -50,6 +51,23 @@ class PickyBoi(PythonDevice):
.reconfigurable() .reconfigurable()
.commit(), .commit(),
UINT64_ELEMENT(expected)
.key("numTrainToCatch")
.assignmentOptional()
.defaultValue(1)
.reconfigurable()
.commit(),
STRING_ELEMENT(expected)
.key("ppuDevice")
.assignmentOptional()
.defaultValue("")
.commit(),
SLOT_ELEMENT(expected)
.key("watchPpu")
.commit(),
SLOT_ELEMENT(expected) SLOT_ELEMENT(expected)
.key("resetCapturedSchema") .key("resetCapturedSchema")
.commit(), .commit(),
...@@ -63,7 +81,7 @@ class PickyBoi(PythonDevice): ...@@ -63,7 +81,7 @@ class PickyBoi(PythonDevice):
super().__init__(config) super().__init__(config)
self.registerInitialFunction(self._initialization) self.registerInitialFunction(self._initialization)
self._schema_is_set = False self._schema_is_set = False
self._previous_train_seen = 0 self._previous_tid = 0
self._just_capture_next = False self._just_capture_next = False
self.KARABO_SLOT(self.resetCapturedSchema) self.KARABO_SLOT(self.resetCapturedSchema)
self.KARABO_SLOT(self.captureNextTrain) self.KARABO_SLOT(self.captureNextTrain)
...@@ -74,37 +92,51 @@ class PickyBoi(PythonDevice): ...@@ -74,37 +92,51 @@ class PickyBoi(PythonDevice):
def captureNextTrain(self): def captureNextTrain(self):
self._just_capture_next = True self._just_capture_next = True
def watchPpu(self):
ppu_device_id = self.get("ppuDevice")
client = self.remote()
conf = client.getConfiguration(ppu_device_id)
self.handlePpuDeviceConfiguration(conf)
client.registerDeviceMonitor(ppu_device_id, self.handlePpuDeviceConfiguration)
def handlePpuDeviceConfiguration(self, conf):
...
# TODO
self._set_new_target_tid(new_target_tid)
self.set("nextTrainToCatch", new_target_tid)
def _initialization(self): def _initialization(self):
self.KARABO_ON_DATA("input", self.input_handler) self.KARABO_ON_DATA("input", self.input_handler)
def input_handler(self, data, meta): def input_handler(self, data, meta):
state = self.get("state")
current = Timestamp.fromHashAttributes(
meta.getAttributes("timestamp")
).getTrainId()
if self._just_capture_next:
self.set("nextTrainToCatch", current)
self._just_capture_next = False
target = self.get("nextTrainToCatch")
if not self._schema_is_set: if not self._schema_is_set:
self.updateState(State.ROTATING) self.updateState(State.ROTATING)
schema_update = Schema() schema_update = Schema()
( (
NODE_ELEMENT(schema_update) OUTPUT_CHANNEL(schema_update)
.key("captured") .key("output")
.commit() .dataSchema(hash_to_schema(data))
.commit(),
) )
hash_to_schema(data, schema_update, "captured.")
self.updateSchema(schema_update) self.updateSchema(schema_update)
self._schema_is_set = True self._schema_is_set = True
if target > current: # TODO: handle multiple (consecutive) trains picked
state = self.get("state")
current_tid = Timestamp.fromHashAttributes(
meta.getAttributes("timestamp")
).getTrainId()
if self._just_capture_next:
self.set("nextTrainToCatch", current_tid)
self._just_capture_next = False
target_tid = self.get("nextTrainToCatch")
if target_tid > current_tid:
if state is not State.MONITORING: if state is not State.MONITORING:
self.updateState(State.MONITORING) self.updateState(State.MONITORING)
elif target < current: elif target_tid < current_tid:
if self._previous_train_seen < target: if self._previous_tid < target_tid and state is not State.ERROR:
self.log.ERROR(f"Missed target train of {target} :(") self.log.ERROR(f"Missed target train of {target_tid} :(")
self.updateState(State.ERROR) self.updateState(State.ERROR)
else: else:
if state is not State.PASSIVE: if state is not State.PASSIVE:
...@@ -112,12 +144,33 @@ class PickyBoi(PythonDevice): ...@@ -112,12 +144,33 @@ class PickyBoi(PythonDevice):
else: else:
self.updateState(State.FILLING) self.updateState(State.FILLING)
self.log.INFO(f"Got target train {target} now :D") self.log.INFO(f"Got target train {target} now :D")
new_hash = Hash() # TODO: copy train ID on metadata
for path in data.getPaths(): self.writeChannel("output", data)
new_hash[f"captured.{path}"] = data[path]
self.set(new_hash)
self.updateState(State.DISENGAGED) self.updateState(State.DISENGAGED)
self._previous_train_seen = current self._previous_tid = current
def _set_new_target_tid(self, new_target_tid):
# assumes nextTrainToCatch gets set *after* this function
current_target_tid = self.get("nextTrainToCatch")
if self._previous_tid >= new_target_tid:
self.log.INFO(
f"Moved target train to {new_target_tid} even though last seen was "
f"{self._previous_tid} - will not be able to retroactively catch this."
)
self.updateState(State.ERROR)
else:
if current_target_tid < new_target_tid:
self.log.INFO(
f"Moved target train from {current_target_tid} to {new_target_tid}"
f"even though last seen was {self._previous_tid} "
f"effectively skipping {current_target_tid}"
)
self.updateState(State.MONITORING)
def preReconfigure(self, config):
super().preReconfigure(config)
if config.has("nextTrainToCatch"):
self._set_new_target_tid(config["nextTrainToCatch"])
def hash_to_schema(h, root=None, prefix=""): def hash_to_schema(h, root=None, prefix=""):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment