From fc2c9bfb84bdf9c3a7f25852ef7012e7d15928da Mon Sep 17 00:00:00 2001 From: tajgr Date: Thu, 7 Sep 2023 22:15:53 +0200 Subject: [PATCH 1/3] drivers/replay: fix streams registration and add sleep option --- osgar/drivers/replay.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/osgar/drivers/replay.py b/osgar/drivers/replay.py index ed68deafa..adbfb1293 100644 --- a/osgar/drivers/replay.py +++ b/osgar/drivers/replay.py @@ -3,6 +3,7 @@ """ from threading import Thread +import time from osgar.logger import LogReader, lookup_stream_names from osgar.lib.serialize import deserialize @@ -15,6 +16,10 @@ def __init__(self, config, bus): self.filename = config['filename'] self.pins = config['pins'] + for channel in self.pins.values(): + self.bus.register(channel) + self.sleep_channel = config.get('sleep_channel') # e.g. ['scan', 0.05] + def start(self): self.input_thread.start() @@ -23,10 +28,14 @@ def join(self, timeout=None): self.input_thread.join(timeout=timeout) def run_input(self): + sleeping_channel = None + period = 0 names = lookup_stream_names(self.filename) print(names) ids = [i + 1 for i, name in enumerate(names) if name in self.pins] print(ids) + if self.sleep_channel: + sleeping_channel, period = self.sleep_channel for timestamp, channel_index, data_raw in LogReader(self.filename, only_stream_id=ids): if not self.bus.is_alive(): @@ -35,7 +44,10 @@ def run_input(self): assert channel in self.pins data = deserialize(data_raw) # TODO reuse timestamp - self.bus.publish(self.pins[channel], data) + sub_channel = self.pins[channel] + self.bus.publish(sub_channel, data) + if sub_channel == sleeping_channel: + time.sleep(period) print('Replay completed!') def request_stop(self): From 402d759037d10934d0e554d9ad9e4501e3989794 Mon Sep 17 00:00:00 2001 From: tajgr Date: Thu, 7 Sep 2023 22:34:35 +0200 Subject: [PATCH 2/3] drivers/replay: replace time.sleep by bus.sleep --- osgar/drivers/replay.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osgar/drivers/replay.py b/osgar/drivers/replay.py index adbfb1293..a977fac09 100644 --- a/osgar/drivers/replay.py +++ b/osgar/drivers/replay.py @@ -3,7 +3,6 @@ """ from threading import Thread -import time from osgar.logger import LogReader, lookup_stream_names from osgar.lib.serialize import deserialize @@ -47,7 +46,7 @@ def run_input(self): sub_channel = self.pins[channel] self.bus.publish(sub_channel, data) if sub_channel == sleeping_channel: - time.sleep(period) + self.bus.sleep(period) print('Replay completed!') def request_stop(self): From 091102489dad8c2a2ea8b5c86383126805001551 Mon Sep 17 00:00:00 2001 From: tajgr Date: Tue, 12 Sep 2023 21:39:27 +0200 Subject: [PATCH 3/3] drivers/replay.py: improves stream registration --- osgar/drivers/replay.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osgar/drivers/replay.py b/osgar/drivers/replay.py index a977fac09..601cc8316 100644 --- a/osgar/drivers/replay.py +++ b/osgar/drivers/replay.py @@ -15,8 +15,7 @@ def __init__(self, config, bus): self.filename = config['filename'] self.pins = config['pins'] - for channel in self.pins.values(): - self.bus.register(channel) + self.bus.register(*self.pins.values()) self.sleep_channel = config.get('sleep_channel') # e.g. ['scan', 0.05] @@ -35,8 +34,7 @@ def run_input(self): print(ids) if self.sleep_channel: sleeping_channel, period = self.sleep_channel - for timestamp, channel_index, data_raw in LogReader(self.filename, - only_stream_id=ids): + for timestamp, channel_index, data_raw in LogReader(self.filename, only_stream_id=ids): if not self.bus.is_alive(): break channel = names[channel_index - 1]