Hello @jakaskerl
Sorry for the late reply, here is an example:
device_info = dai.DeviceInfo(device_ip)
pipeline = dai.Pipeline()
# script node
script_node = pipeline.create(dai.node.Script)
script_node.setScript(
"""
import time, datetime
import marshal
while True:
# a timestamp that should represent the actual time corresponding to host-time
clock_now = Clock.now().total_seconds()
datetime_now = datetime.datetime.now().timestamp()
# creating a buffer-object to send the timestamp to host
msg = marshal.dumps({'clock_now': clock_now, 'datetime_now': datetime_now}, 2)
bufs = Buffer(len(msg))
bufs.getData()[:] = msg
# send buffer
node.io['host'].send(bufs)
time.sleep(1)
"""
)
script_xout = pipeline.create(dai.node.XLinkOut)
script_xout.setStreamName("script_out")
script_xout.input.setQueueSize(1)
script_xout.input.setBlocking(False)
script_node.outputs["host"].link(script_xout.input)
with dai.Device(pipeline, device_info) as device:
script_out = device.getOutputQueue("script_out")
while True:
script_msg = script_out.tryGet()
if script_msg is not None:
res = marshal.loads(script_msg.getData())
device_clock_now = datetime.timedelta(seconds=res["clock_now"])
device_datetime_now = datetime.datetime.fromtimestamp(res["datetime_now"])
dai_clock = dai.Clock.now()
actual_time = datetime.datetime.now()
print(f"device_clock_now {device_clock_now}, device_datetime_now {device_datetime_now} \
\ndai_clock {dai_clock}, actual_time {actual_time}")
time.sleep(0.1)
Result:
Expectation:
device clock now, device datetime now and dai clock have at least the same reference point and have milliseconds inbetween eachother
I basically want to know when the given timestamp in the scriptnode is but in actual time (of the host)
Thanks,
werkilan