00_rapid_py.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Mon Aug 08 09:49:26 2016
  4. Model author: Herr Joeri Exelmans
  5. Model name: rapid
  6. Model description:
  7. After event with a very small timeout.
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. # package "rapid"
  11. class c(RuntimeClassBase):
  12. def __init__(self, controller):
  13. RuntimeClassBase.__init__(self, controller)
  14. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  15. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  16. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  17. self.semantics.priority = StatechartSemantics.SourceParent
  18. self.semantics.concurrency = StatechartSemantics.Single
  19. # build Statechart structure
  20. self.build_statechart_structure()
  21. # user defined attributes
  22. self.i = None
  23. # call user defined constructor
  24. c.user_defined_constructor(self)
  25. def user_defined_constructor(self):
  26. self.i = 0
  27. def user_defined_destructor(self):
  28. pass
  29. # builds Statechart structure
  30. def build_statechart_structure(self):
  31. # state <root>
  32. self.states[""] = State(0, self)
  33. # state /a
  34. self.states["/a"] = State(1, self)
  35. self.states["/a"].setEnter(self._a_enter)
  36. self.states["/a"].setExit(self._a_exit)
  37. # add children
  38. self.states[""].addChild(self.states["/a"])
  39. self.states[""].fixTree()
  40. self.states[""].default_state = self.states["/a"]
  41. # transition /a
  42. _a_0 = Transition(self, self.states["/a"], [self.states["/a"]])
  43. _a_0.setAction(self._a_0_exec)
  44. _a_0.setTrigger(Event("_0after"))
  45. _a_0.setGuard(self._a_0_guard)
  46. self.states["/a"].addTransition(_a_0)
  47. def _a_enter(self):
  48. self.addTimer(0, 1e-10)
  49. self.big_step.outputEvent(Event("entered_a", "out", []))
  50. def _a_exit(self):
  51. self.removeTimer(0)
  52. def _a_0_exec(self, parameters):
  53. self.i += 1
  54. def _a_0_guard(self, parameters):
  55. return self.i < 2
  56. def initializeStatechart(self):
  57. # enter default state
  58. states = self.states["/a"].getEffectiveTargetStates()
  59. self.updateConfiguration(states)
  60. for state in states:
  61. if state.enter:
  62. state.enter()
  63. class ObjectManager(ObjectManagerBase):
  64. def __init__(self, controller):
  65. ObjectManagerBase.__init__(self, controller)
  66. def instantiate(self, class_name, construct_params):
  67. if class_name == "c":
  68. instance = c(self.controller)
  69. instance.associations = {}
  70. else:
  71. raise Exception("Cannot instantiate class " + class_name)
  72. return instance
  73. class Controller(ThreadsControllerBase):
  74. def __init__(self, keep_running = None):
  75. if keep_running == None: keep_running = True
  76. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
  77. self.addInputPort("in")
  78. self.addOutputPort("out")
  79. self.object_manager.createInstance("c", [])
  80. class InputEvent:
  81. def __init__(self, name, port, parameters, time_offset):
  82. self.name = name
  83. self.port = port
  84. self.parameters = parameters
  85. self.time_offset = time_offset
  86. class Test:
  87. def __init__(self):
  88. pass
  89. input_events = []
  90. expected_events = [[Event("entered_a", "out", [])], [Event("entered_a", "out", [])], [Event("entered_a", "out", [])]]