def step(self): """ Perform a step in the simulation. Actual processing is done in a seperate thread. """ if time.time() >= self.next_event: self.next_event = float('inf') getattr(self, "func")()
def preActivityCalculation(self): """ DEFAULT pre-transition activity fetcher. The returned value is passed to the *postActivityCalculation* function :returns: something -- passed to the *postActivityCalculation* """ return time.time()
def postActivityCalculation(self, prevalue): """ DEFAULT post-transition activity fetcher. The returned value will be passed on to the relocator and MUST be an addable (e.g. integer, float, ...) :param prevalue: the value returned from the *preActivityCalculation* method :returns: addable (float, integer, ...) -- passed to the relocator """ return time.time() - prevalue
def wait(self, delay, func): """ Wait for the specified time, or faster if interrupted :param time: time to wait :param func: the function to call """ self.func = func self.next_event = time.time() + delay
def setRealTime(self, subsystem, generator_file, ports, scale, listeners, args=[]): """ Set the use of realtime simulation :param subsystem: defines the subsystem to use :param generator_file: filename to use for generating external inputs :param ports: input port references :param scale: the scale factor for realtime simulation :param listeners: the ports on which we should listen for output :param args: additional arguments for the realtime backend """ self.realtime = True self.threading_backend = ThreadingBackend(subsystem, args) self.rt_zerotime = time.time() async = AsynchronousComboGenerator(generator_file, self.threading_backend) self.asynchronous_generator = async
Set the use of realtime simulation :param subsystem: defines the subsystem to use :param generator_file: filename to use for generating external inputs :param ports: input port references :param scale: the scale factor for realtime simulation :param listeners: the ports on which we should listen for output :param args: additional arguments for the realtime backend """ self.realtime = True self.threading_backend = ThreadingBackend(subsystem, args) self.rt_zerotime = time.time() async = AsynchronousComboGenerator(generator_file, self.threading_backend) self.asynchronous_generator = async self.realtime_starttime = time.time() self.portmap = ports self.model.listeners = listeners self.realtime_scale = scale def gameLoop(self): """ Perform all computations up to the current time. Only applicable for the game loop realtime backend. """ self.threading_backend.step() def realtimeInterrupt(self, string): """ Create an interrupt from other Python code instead of using stdin or the file :param string: the value to inject