Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/modify-playback-rate'
Browse files Browse the repository at this point in the history
  • Loading branch information
ozyx committed Aug 7, 2024
2 parents 7b4dc1b + f5a1536 commit 8c96601
Showing 1 changed file with 13 additions and 5 deletions.
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 8c96601

Please sign in to comment.