tester.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  3. Date: Fri Oct 06 16:24:33 2017
  4. Model author: Yentl Van Tendeloo
  5. Model name: Testing
  6. Model description:
  7. Testing
  8. """
  9. from sccd.runtime.statecharts_core import *
  10. import time
  11. # package "Testing"
  12. class Testing(RuntimeClassBase):
  13. def __init__(self, controller):
  14. RuntimeClassBase.__init__(self, controller)
  15. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  16. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  17. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  18. self.semantics.priority = StatechartSemantics.SourceParent
  19. self.semantics.concurrency = StatechartSemantics.Single
  20. # build Statechart structure
  21. self.build_statechart_structure()
  22. # call user defined constructor
  23. Testing.user_defined_constructor(self)
  24. def user_defined_constructor(self):
  25. pass
  26. def user_defined_destructor(self):
  27. pass
  28. # builds Statechart structure
  29. def build_statechart_structure(self):
  30. # state <root>
  31. self.states[""] = State(0, "", self)
  32. # state /A
  33. self.states["/A"] = State(1, "/A", self)
  34. self.states["/A"].setEnter(self._A_enter)
  35. self.states["/A"].setExit(self._A_exit)
  36. # add children
  37. self.states[""].addChild(self.states["/A"])
  38. self.states[""].fixTree()
  39. self.states[""].default_state = self.states["/A"]
  40. # transition /A
  41. _A_0 = Transition(self, self.states["/A"], [self.states["/A"]])
  42. _A_0.setAction(self._A_0_exec)
  43. _A_0.setTrigger(Event("_0after"))
  44. self.states["/A"].addTransition(_A_0)
  45. def _A_enter(self):
  46. self.addTimer(0, 0.01)
  47. def _A_exit(self):
  48. self.removeTimer(0)
  49. def _A_0_exec(self, parameters):
  50. print(time.time())
  51. def initializeStatechart(self):
  52. # enter default state
  53. self.default_targets = self.states["/A"].getEffectiveTargetStates()
  54. RuntimeClassBase.initializeStatechart(self)
  55. class ObjectManager(ObjectManagerBase):
  56. def __init__(self, controller):
  57. ObjectManagerBase.__init__(self, controller)
  58. def instantiate(self, class_name, construct_params):
  59. if class_name == "Testing":
  60. instance = Testing(self.controller)
  61. instance.associations = {}
  62. else:
  63. raise Exception("Cannot instantiate class " + class_name)
  64. return instance
  65. class Controller(EventLoopControllerBase):
  66. def __init__(self, event_loop_callbacks, finished_callback = None, behind_schedule_callback = None):
  67. if finished_callback == None: finished_callback = None
  68. if behind_schedule_callback == None: behind_schedule_callback = None
  69. EventLoopControllerBase.__init__(self, ObjectManager(self), event_loop_callbacks, finished_callback, behind_schedule_callback)
  70. self.addInputPort("input")
  71. self.object_manager.createInstance("Testing", [])