trafficlight.sccd 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. Diagram(name = 'Statechart', author = 'MSDL', description = 'Exported SCCD HUTN'):
  2. Top {
  3. import httplib
  4. import json
  5. method = 'PUT'
  6. host = 'localhost:8124'
  7. uri = '/GET/console?wid=3'
  8. timeout = 5000
  9. }
  10. Inport(name = 'ui')
  11. Class(name = 'MainApp', default = True):
  12. Method highlightState(nodeId) {
  13. headers = \['Content-Type': 'text/plain'\]
  14. data = json->dumps(\['text':'CLIENT_BDAPI :: \["func":"_highlightState","args":\["asid":'+str(nodeId)+',"followCrossFormalismLinks":"*"\]\]'\])
  15. conn = httplib->HTTPConnection(host)
  16. conn->request(method, uri, data, headers)
  17. resp = conn->getresponse()
  18. conn->close()
  19. }
  20. Method unhighlightState(nodeId) {
  21. headers = \['Content-Type': 'text/plain'\]
  22. data = json->dumps(\['text':'CLIENT_BDAPI :: \["func":"_unhighlightState","args":\["asid":'+str(nodeId)+'\]\]'\])
  23. conn = httplib->HTTPConnection(host)
  24. conn->request(method, uri, data, headers)
  25. resp = conn->getresponse()
  26. conn->close()
  27. }
  28. StateMachine:
  29. initial = 'normal'
  30. State('normal'):
  31. Transition(target='../interrupted'):
  32. event = police_interrupt_clicked()
  33. initial = 'red'
  34. State('red'):
  35. OnEnter {
  36. self->setRed()
  37. self->highlightState(5)
  38. }
  39. OnExit {
  40. self->unhighlightState(5)
  41. }
  42. Transition(after=3.0, target='../green')
  43. State('green'):
  44. OnEnter {
  45. self->setGreen()
  46. self->highlightState(6)
  47. }
  48. OnExit {
  49. self->unhighlightState(6)
  50. }
  51. Transition(after=2.0, target='../yellow')
  52. State('yellow'):
  53. OnEnter {
  54. self->setYellow()
  55. self->highlightState(7)
  56. }
  57. OnExit {
  58. self->unhighlightState(7)
  59. }
  60. Transition(after=1.0, target='../red')
  61. State('interrupted'):
  62. Transition(target='../normal'):
  63. event = police_interrupt_clicked()
  64. initial = 'yellow'
  65. State('yellow'):
  66. OnEnter {
  67. self->setYellow()
  68. self->highlightState(14)
  69. }
  70. OnExit {
  71. self->unhighlightState(14)
  72. }
  73. Transition(after=5.0, target='../black')
  74. State('black'):
  75. OnEnter {
  76. self->clear()
  77. self->highlightState(15)
  78. }
  79. OnExit {
  80. self->unhighlightState(15)
  81. }
  82. Transition(after=5.0, target='../yellow')