functionalities
This commit is contained in:
@@ -14,6 +14,7 @@ class CocosimInstance(object):
|
||||
conf_fp = open("modele/config.json")
|
||||
conf = json.load(conf_fp)
|
||||
|
||||
self.pause_simulation = False #pause flag
|
||||
self.conf = conf
|
||||
self.dt = self.conf['circuit']['DT']
|
||||
self.cocosim = None
|
||||
@@ -47,15 +48,19 @@ class CocosimInstance(object):
|
||||
if message == "start":
|
||||
logging.log(logging.INFO, "Starting")
|
||||
self.runner = asyncio.create_task(self.run())
|
||||
|
||||
elif message == "stop":
|
||||
logging.log(logging.INFO, "Stopping")
|
||||
await self.stop()
|
||||
|
||||
elif message == "state":
|
||||
self.state_q.put(self.state.to_json())
|
||||
|
||||
elif message == "quit":
|
||||
logging.log(logging.INFO, "Quitting")
|
||||
await self.stop()
|
||||
self.quit = True
|
||||
|
||||
elif message == "load":
|
||||
logging.log(logging.INFO, "Loading file")
|
||||
try:
|
||||
@@ -63,6 +68,17 @@ class CocosimInstance(object):
|
||||
self.state_q.put("OK")
|
||||
except GraphStructException:
|
||||
self.state_q.put("Error")
|
||||
|
||||
elif message == "pause":
|
||||
but_name = data['args']
|
||||
logging.log(logging.INFO,"Simulation paused {but_name}")
|
||||
self.pause_simulation = True
|
||||
|
||||
elif message == "resume":
|
||||
but_name = data['args']
|
||||
logging.log(logging.INFO,"Simulation resumed {but_name}")
|
||||
self.pause_simulation = False
|
||||
|
||||
elif message == "push":
|
||||
but_name = data['args']
|
||||
logging.log(logging.INFO, f"Push button {but_name}")
|
||||
@@ -103,12 +119,17 @@ class CocosimInstance(object):
|
||||
|
||||
async def run(self):
|
||||
try:
|
||||
while True:
|
||||
self.state.reset_exception()
|
||||
self.cycle()
|
||||
while not self.quit:
|
||||
if not self.pause_simulation:
|
||||
self.state.reset_exception()
|
||||
self.cycle()
|
||||
else:
|
||||
print("Simulation paused. Awaiting resume...")
|
||||
while self.pause_simulation:
|
||||
await asyncio.sleep(1) #wait until the simulation is resumed
|
||||
await asyncio.sleep(self.dt)
|
||||
except:
|
||||
logging.exception("Exception occured in 'cycle'")
|
||||
except Exception as e:
|
||||
logging.exception("Exception occured during simulation run")
|
||||
|
||||
async def stop(self):
|
||||
if self.runner:
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user