Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy record via drivers/replay #963

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading