From 517cf80dd9b2f713885b2f2f62caf6aa58dabef9 Mon Sep 17 00:00:00 2001 From: Jakub Lev Date: Wed, 20 Sep 2023 00:26:09 +0200 Subject: [PATCH] Dummy record via drivers/replay (#963) * drivers/replay: fix streams registration and add sleep option --- osgar/drivers/replay.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/osgar/drivers/replay.py b/osgar/drivers/replay.py index ed68deafa..601cc8316 100644 --- a/osgar/drivers/replay.py +++ b/osgar/drivers/replay.py @@ -15,6 +15,9 @@ def __init__(self, config, bus): self.filename = config['filename'] self.pins = config['pins'] + self.bus.register(*self.pins.values()) + self.sleep_channel = config.get('sleep_channel') # e.g. ['scan', 0.05] + def start(self): self.input_thread.start() @@ -23,19 +26,25 @@ 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) - for timestamp, channel_index, data_raw in LogReader(self.filename, - only_stream_id=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(): break channel = names[channel_index - 1] 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: + self.bus.sleep(period) print('Replay completed!') def request_stop(self):