Skip to content

Commit 105a47f

Browse files
authored
Merge pull request #39 from ozyx/modify-playback-rate
Allow simulator playback rate to be specified at runtime
2 parents 4a44f71 + 8c96601 commit 105a47f

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

docker/Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ define print_message
1515
@printf "\033[$(1)m$(2)\033[0m\n"
1616
endef
1717

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

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

22+
all-10hz: clean yamcs-simulator-10hz ## run all: clean, yamcs-up (yamcs-down) and yamcs-simulator
23+
2224
yamcs-up: | yamcs-down ## bring up yamcs system
2325
docker compose up -d
2426

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

35+
yamcs-simulator-10hz: yamcs-up ## run yamcs simulator at 10hz
36+
$(call print_message,36,Connect via http://localhost:8090/ system may take about 50 seconds to startup)
37+
cd .. && $(PYTHON) ./simulator.py --rate=10
38+
3339
yamcs-shell: ## shell into yamcs container
3440
docker compose up -d && docker compose exec yamcs bash
3541

simulator.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from struct import unpack_from
88
from threading import Thread
99
from time import sleep
10-
10+
from argparse import ArgumentParser
1111

1212
def send_tm(simulator):
1313
tm_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -25,7 +25,7 @@ def send_tm(simulator):
2525
tm_socket.sendto(packet, ('127.0.0.1', 10015))
2626
simulator.tm_counter += 1
2727

28-
sleep(1)
28+
sleep(1 / simulator.rate)
2929

3030

3131
def receive_tc(simulator):
@@ -39,12 +39,13 @@ def receive_tc(simulator):
3939

4040
class Simulator():
4141

42-
def __init__(self):
42+
def __init__(self, rate):
4343
self.tm_counter = 0
4444
self.tc_counter = 0
4545
self.tm_thread = None
4646
self.tc_thread = None
4747
self.last_tc = None
48+
self.rate = rate
4849

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

6465

6566
if __name__ == '__main__':
66-
simulator = Simulator()
67+
parser = ArgumentParser()
68+
parser.add_argument("-r", "--rate",
69+
dest="rate",
70+
default=1,
71+
type=int,
72+
help="Playback rate. 1 = 1Hz, 10 = 10Hz, etc.")
73+
args = parser.parse_args()
74+
simulator = Simulator(args.rate)
6775
simulator.start()
68-
76+
sys.stdout.write('Using playback rate of ' + str(args.rate) + 'Hz \r\n');
6977
try:
7078
prev_status = None
7179
while True:

0 commit comments

Comments
 (0)