Skip to content

Commit

Permalink
Dummy record via drivers/replay (#963)
Browse files Browse the repository at this point in the history
* drivers/replay: fix streams registration and add sleep option
  • Loading branch information
tajgr authored Sep 19, 2023
1 parent cc214a5 commit 517cf80
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions osgar/drivers/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down

0 comments on commit 517cf80

Please sign in to comment.