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

Allow simulator playback rate to be specified at runtime #39

Merged
merged 9 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ define print_message
@printf "\033[$(1)m$(2)\033[0m\n"
endef

.PHONY: all clean yamcs-up yamcs-down yamcs-simulator yamcs-shell help
.PHONY: all all-10hz clean yamcs-up yamcs-down yamcs-simulator yamcs-simulator-10hz yamcs-shell help

all: clean yamcs-simulator ## run all: clean, yamcs-up (yamcs-down) and yamcs-simulator

all-10hz: clean yamcs-simulator-10hz ## run all: clean, yamcs-up (yamcs-down) and yamcs-simulator

yamcs-up: | yamcs-down ## bring up yamcs system
docker compose up -d

Expand All @@ -30,6 +32,10 @@ yamcs-simulator: yamcs-up ## run yamcs simulator
$(call print_message,36,Connect via http://localhost:8090/ system may take about 50 seconds to startup)
cd .. && $(PYTHON) ./simulator.py

yamcs-simulator-10hz: yamcs-up ## run yamcs simulator at 10hz
$(call print_message,36,Connect via http://localhost:8090/ system may take about 50 seconds to startup)
cd .. && $(PYTHON) ./simulator.py --rate=10

yamcs-shell: ## shell into yamcs container
docker compose up -d && docker compose exec yamcs bash

Expand Down
18 changes: 13 additions & 5 deletions simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from struct import unpack_from
from threading import Thread
from time import sleep

from argparse import ArgumentParser

def send_tm(simulator):
tm_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand All @@ -25,7 +25,7 @@ def send_tm(simulator):
tm_socket.sendto(packet, ('127.0.0.1', 10015))
simulator.tm_counter += 1

sleep(1)
sleep(1 / simulator.rate)


def receive_tc(simulator):
Expand All @@ -39,12 +39,13 @@ def receive_tc(simulator):

class Simulator():

def __init__(self):
def __init__(self, rate):
self.tm_counter = 0
self.tc_counter = 0
self.tm_thread = None
self.tc_thread = None
self.last_tc = None
self.rate = rate

def start(self):
self.tm_thread = Thread(target=send_tm, args=(self,))
Expand All @@ -63,9 +64,16 @@ def print_status(self):


if __name__ == '__main__':
simulator = Simulator()
parser = ArgumentParser()
parser.add_argument("-r", "--rate",
dest="rate",
default=1,
type=int,
help="Playback rate. 1 = 1Hz, 10 = 10Hz, etc.")
args = parser.parse_args()
simulator = Simulator(args.rate)
simulator.start()

sys.stdout.write('Using playback rate of ' + str(args.rate) + 'Hz \r\n');
try:
prev_status = None
while True:
Expand Down
Loading