Skip to content

Commit 14f6c16

Browse files
author
au650680
committed
replay functionality added as example
1 parent 7c34e4e commit 14f6c16

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

record/replay.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
RECORDINGS_DIR = "record/mqtt_recordings"
1616
FILE_NAME = "recording_beam_reduced.jsonl"
1717

18-
REPLAY_SPEED = 1 # Multiplier for replay speed
18+
REPLAY_SPEED = 10 # Multiplier for replay speed
1919

2020
BUSY_WAIT_THRESHOLD = 10/1000 # Threshold in seconds for busy waiting (10 ms)
2121
KEEP_UP_TIME = -1 # If delay time (remaining) is lower than this time, warn the user that the replay speed is two fast.
@@ -75,7 +75,7 @@ def publish_massage(publish_client: MQTTClient, PublishTopics: Dict[str,str], qo
7575
except KeyboardInterrupt:
7676
raise RuntimeError("Replay interrupted by user.")
7777

78-
def replay_mqtt_messages(loop: int = 1) -> None:
78+
def replay_mqtt_messages(config_path: str, loop: int = 1) -> None:
7979
"""
8080
Replay data using jsonl file
8181
@@ -84,7 +84,7 @@ def replay_mqtt_messages(loop: int = 1) -> None:
8484
Returns:
8585
None
8686
"""
87-
config = load_config(CONFIG_PATH)
87+
config = load_config(config_path)
8888
MQTT_config = config["MQTT"]
8989
publish_client = setup_publish_client(MQTT_config)
9090
try:
@@ -173,4 +173,4 @@ def replay_mqtt_messages(loop: int = 1) -> None:
173173
print("[DONE].")
174174

175175
if __name__ == "__main__":
176-
replay_mqtt_messages(loop=LOOPS) # Times to loop
176+
replay_mqtt_messages(CONFIG_PATH, loop=LOOPS) # Times to loop

src/examples/example.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
run_model_update_remote_sysid,
2525
run_live_model_update_remote_clustering
2626
)
27+
from examples.run_replay import replay_mqtt
2728

2829
@click.group()
2930
@click.option('--config', default="config/production.json", help="Path to config file")
@@ -42,6 +43,11 @@ def accelerometers(ctx):
4243
def align_readings(ctx):
4344
align_acceleration_readings(ctx.obj["CONFIG"])
4445

46+
@cli.command()
47+
@click.pass_context
48+
def replay(ctx):
49+
replay_mqtt(ctx.obj["CONFIG"])
50+
4551
@cli.command()
4652
@click.pass_context
4753
def sysid_and_print(ctx):

src/examples/run_replay.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from record import replay
2+
3+
def replay_mqtt(config_path):
4+
replay.replay_mqtt_messages(config_path)

0 commit comments

Comments
 (0)