target.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Model author: Sam Pieters
  4. Model name: Global inport
  5. Model description:
  6. Test X: Test if global inport works
  7. """
  8. from sccd.runtime.statecharts_core import *
  9. # package "Global inport"
  10. class MainApp(RuntimeClassBase):
  11. def __init__(self, controller):
  12. RuntimeClassBase.__init__(self, controller)
  13. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  14. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  15. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  16. self.semantics.priority = StatechartSemantics.SourceParent
  17. self.semantics.concurrency = StatechartSemantics.Single
  18. # build Statechart structure
  19. self.build_statechart_structure()
  20. # call user defined constructor
  21. MainApp.user_defined_constructor(self)
  22. def user_defined_constructor(self):
  23. pass
  24. def user_defined_destructor(self):
  25. pass
  26. # builds Statechart structure
  27. def build_statechart_structure(self):
  28. # state <root>
  29. self.states[""] = State(0, "", self)
  30. # state /state1
  31. self.states["/state1"] = State(1, "/state1", self)
  32. self.states["/state1"].setEnter(self._state1_enter)
  33. # state /state2
  34. self.states["/state2"] = State(2, "/state2", self)
  35. # add children
  36. self.states[""].addChild(self.states["/state1"])
  37. self.states[""].addChild(self.states["/state2"])
  38. self.states[""].fixTree()
  39. self.states[""].default_state = self.states["/state1"]
  40. # transition /state1
  41. _state1_0 = Transition(self, self.states["/state1"], [self.states["/state2"]])
  42. _state1_0.setAction(self._state1_0_exec)
  43. _state1_0.setTrigger(Event("test", None))
  44. self.states["/state1"].addTransition(_state1_0)
  45. def _state1_enter(self):
  46. self.big_step.outputEvent(Event("generate_input", self.getOutPortName("Output"), []))
  47. def _state1_0_exec(self, parameters):
  48. self.big_step.outputEvent(Event("received", self.getOutPortName("Output"), []))
  49. def initializeStatechart(self):
  50. # enter default state
  51. self.default_targets = self.states["/state1"].getEffectiveTargetStates()
  52. RuntimeClassBase.initializeStatechart(self)
  53. class ObjectManager(ObjectManagerBase):
  54. def __init__(self, controller):
  55. ObjectManagerBase.__init__(self, controller)
  56. def instantiate(self, class_name, construct_params):
  57. if class_name == "MainApp":
  58. instance = MainApp(self.controller)
  59. instance.associations = {}
  60. else:
  61. raise Exception("Cannot instantiate class " + class_name)
  62. return instance
  63. class Controller(ThreadsControllerBase):
  64. def __init__(self, keep_running = None, behind_schedule_callback = None):
  65. if keep_running == None: keep_running = True
  66. if behind_schedule_callback == None: behind_schedule_callback = None
  67. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
  68. self.addInputPort("Input")
  69. self.addOutputPort("Output")
  70. self.object_manager.createInstance("MainApp", [])