123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- """
- Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
- Date: Wed Apr 4 23:27:30 2018
- Model author: Lucas Heer
- Model name: ALC_IO
- Model description:
- I/O Statechart for passing data to ALC
- """
- from sccd.runtime.statecharts_core import *
- # package "ALC_IO"
- class ALC_IO(RuntimeClassBase):
- def __init__(self, controller):
- RuntimeClassBase.__init__(self, controller)
-
- self.semantics.big_step_maximality = StatechartSemantics.TakeMany
- self.semantics.internal_event_lifeline = StatechartSemantics.Queue
- self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
- self.semantics.priority = StatechartSemantics.SourceParent
- self.semantics.concurrency = StatechartSemantics.Single
-
- # build Statechart structure
- self.build_statechart_structure()
-
- # call user defined constructor
- ALC_IO.user_defined_constructor(self)
-
- def user_defined_constructor(self):
- pass
-
- def user_defined_destructor(self):
- pass
-
-
- # builds Statechart structure
- def build_statechart_structure(self):
-
- # state <root>
- self.states[""] = State(0, "", self)
-
- # state /init
- self.states["/init"] = State(1, "/init", self)
-
- # state /finished
- self.states["/finished"] = State(2, "/finished", self)
-
- # add children
- self.states[""].addChild(self.states["/init"])
- self.states[""].addChild(self.states["/finished"])
- self.states[""].fixTree()
- self.states[""].default_state = self.states["/init"]
-
- # transition /init
- _init_0 = Transition(self, self.states["/init"], [self.states["/init"]])
- _init_0.setAction(self._init_0_exec)
- _init_0.setTrigger(Event("input", "inp"))
- self.states["/init"].addTransition(_init_0)
- _init_1 = Transition(self, self.states["/init"], [self.states["/finished"]])
- _init_1.setTrigger(Event("terminate", "inp"))
- self.states["/init"].addTransition(_init_1)
- _init_2 = Transition(self, self.states["/init"], [self.states["/init"]])
- _init_2.setAction(self._init_2_exec)
- _init_2.setTrigger(Event("data_inp", "datap"))
- self.states["/init"].addTransition(_init_2)
-
- def _init_0_exec(self, parameters):
- value = parameters[0]
- print(value)
-
- def _init_2_exec(self, parameters):
- value = parameters[0]
- print("SC: Got data {}".format(value))
- self.big_step.outputEvent(Event("output", "outp", [value]))
-
- def initializeStatechart(self):
- # enter default state
- self.default_targets = self.states["/init"].getEffectiveTargetStates()
- RuntimeClassBase.initializeStatechart(self)
- class ObjectManager(ObjectManagerBase):
- def __init__(self, controller):
- ObjectManagerBase.__init__(self, controller)
-
- def instantiate(self, class_name, construct_params):
- if class_name == "ALC_IO":
- instance = ALC_IO(self.controller)
- instance.associations = {}
- else:
- raise Exception("Cannot instantiate class " + class_name)
- return instance
- class Controller(ThreadsControllerBase):
- def __init__(self, keep_running = None, behind_schedule_callback = None):
- if keep_running == None: keep_running = True
- if behind_schedule_callback == None: behind_schedule_callback = None
- ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
- self.addInputPort("datap")
- self.addInputPort("inp")
- self.addOutputPort("outp")
- self.object_manager.createInstance("ALC_IO", [])
|