Skip to content

Commit

Permalink
Merge pull request #39 from ozyx/modify-playback-rate
Browse files Browse the repository at this point in the history
Allow simulator playback rate to be specified at runtime
  • Loading branch information
fqqb authored Sep 9, 2024
2 parents 4a44f71 + 8c96601 commit 105a47f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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

0 comments on commit 105a47f

Please sign in to comment.