TrafficLightWaitingStatemachine.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. /**
  2. Copyright (c) 2012-2015 committers of YAKINDU and others.
  3. All rights reserved. This program and the accompanying materials
  4. are made available under the terms of the Eclipse Public License v1.0
  5. which accompanies this distribution, and is available at
  6. http://www.eclipse.org/legal/epl-v10.html
  7. Contributors:
  8. committers of YAKINDU - initial API and implementation
  9. �*/
  10. package traffic.light.trafficlightwaiting;
  11. import traffic.light.ITimer;
  12. public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStatemachine {
  13. protected class SCITrafficLightImpl implements SCITrafficLight {
  14. private boolean red;
  15. public boolean getRed() {
  16. return red;
  17. }
  18. public void setRed(boolean value) {
  19. this.red = value;
  20. }
  21. private boolean yellow;
  22. public boolean getYellow() {
  23. return yellow;
  24. }
  25. public void setYellow(boolean value) {
  26. this.yellow = value;
  27. }
  28. private boolean green;
  29. public boolean getGreen() {
  30. return green;
  31. }
  32. public void setGreen(boolean value) {
  33. this.green = value;
  34. }
  35. }
  36. protected SCITrafficLightImpl sCITrafficLight;
  37. protected class SCIPedestrianImpl implements SCIPedestrian {
  38. private boolean request;
  39. public boolean getRequest() {
  40. return request;
  41. }
  42. public void setRequest(boolean value) {
  43. this.request = value;
  44. }
  45. private boolean red;
  46. public boolean getRed() {
  47. return red;
  48. }
  49. public void setRed(boolean value) {
  50. this.red = value;
  51. }
  52. private boolean green;
  53. public boolean getGreen() {
  54. return green;
  55. }
  56. public void setGreen(boolean value) {
  57. this.green = value;
  58. }
  59. }
  60. protected SCIPedestrianImpl sCIPedestrian;
  61. protected class SCInterfaceImpl implements SCInterface {
  62. private boolean pedestrianRequest;
  63. public void raisePedestrianRequest() {
  64. pedestrianRequest = true;
  65. }
  66. private boolean onOff;
  67. public void raiseOnOff() {
  68. onOff = true;
  69. }
  70. protected void clearEvents() {
  71. pedestrianRequest = false;
  72. onOff = false;
  73. }
  74. }
  75. protected SCInterfaceImpl sCInterface;
  76. private boolean initialized = false;
  77. public enum State {
  78. main_region_on, main_region_on_r1_StreetGreen, main_region_on_r1_PedWaiting, main_region_on_r1_PedWaiting_r1_waitOn, main_region_on_r1_PedWaiting_r1_waitOff, main_region_on_r1_StreetAttention, main_region_on_r1_StreetRed, main_region_on_r1_PedestrianGreen, main_region_on_r1_PedestrianRed, main_region_on_r1_StreetPrepare, main_region_off, main_region_off_r1_YellowOn, main_region_off_r1_YellowOff, $NullState$
  79. };
  80. private final State[] stateVector = new State[1];
  81. private int nextStateIndex;
  82. private ITimer timer;
  83. private final boolean[] timeEvents = new boolean[10];
  84. public TrafficLightWaitingStatemachine() {
  85. sCITrafficLight = new SCITrafficLightImpl();
  86. sCIPedestrian = new SCIPedestrianImpl();
  87. sCInterface = new SCInterfaceImpl();
  88. }
  89. public void init() {
  90. this.initialized = true;
  91. if (timer == null) {
  92. throw new IllegalStateException("timer not set.");
  93. }
  94. for (int i = 0; i < 1; i++) {
  95. stateVector[i] = State.$NullState$;
  96. }
  97. clearEvents();
  98. clearOutEvents();
  99. sCITrafficLight.setRed(false);
  100. sCITrafficLight.setYellow(false);
  101. sCITrafficLight.setGreen(false);
  102. sCIPedestrian.setRequest(false);
  103. sCIPedestrian.setRed(false);
  104. sCIPedestrian.setGreen(false);
  105. }
  106. public void enter() {
  107. if (!initialized)
  108. throw new IllegalStateException(
  109. "The statemachine needs to be initialized first by calling the init() function.");
  110. if (timer == null) {
  111. throw new IllegalStateException("timer not set.");
  112. }
  113. enterSequence_main_region_default();
  114. }
  115. public void exit() {
  116. exitSequence_main_region();
  117. }
  118. /**
  119. * @see IStatemachine#isActive()
  120. */
  121. public boolean isActive() {
  122. return stateVector[0] != State.$NullState$;
  123. }
  124. /**
  125. * Always returns 'false' since this state machine can never become final.
  126. *
  127. * @see IStatemachine#isFinal()
  128. */
  129. public boolean isFinal() {
  130. return false;
  131. }
  132. /**
  133. * This method resets the incoming events (time events included).
  134. */
  135. protected void clearEvents() {
  136. sCInterface.clearEvents();
  137. for (int i = 0; i < timeEvents.length; i++) {
  138. timeEvents[i] = false;
  139. }
  140. }
  141. /**
  142. * This method resets the outgoing events.
  143. */
  144. protected void clearOutEvents() {
  145. }
  146. /**
  147. * Returns true if the given state is currently active otherwise false.
  148. */
  149. public boolean isStateActive(State state) {
  150. switch (state) {
  151. case main_region_on :
  152. return stateVector[0].ordinal() >= State.main_region_on.ordinal()
  153. && stateVector[0].ordinal() <= State.main_region_on_r1_StreetPrepare.ordinal();
  154. case main_region_on_r1_StreetGreen :
  155. return stateVector[0] == State.main_region_on_r1_StreetGreen;
  156. case main_region_on_r1_PedWaiting :
  157. return stateVector[0].ordinal() >= State.main_region_on_r1_PedWaiting.ordinal()
  158. && stateVector[0].ordinal() <= State.main_region_on_r1_PedWaiting_r1_waitOff.ordinal();
  159. case main_region_on_r1_PedWaiting_r1_waitOn :
  160. return stateVector[0] == State.main_region_on_r1_PedWaiting_r1_waitOn;
  161. case main_region_on_r1_PedWaiting_r1_waitOff :
  162. return stateVector[0] == State.main_region_on_r1_PedWaiting_r1_waitOff;
  163. case main_region_on_r1_StreetAttention :
  164. return stateVector[0] == State.main_region_on_r1_StreetAttention;
  165. case main_region_on_r1_StreetRed :
  166. return stateVector[0] == State.main_region_on_r1_StreetRed;
  167. case main_region_on_r1_PedestrianGreen :
  168. return stateVector[0] == State.main_region_on_r1_PedestrianGreen;
  169. case main_region_on_r1_PedestrianRed :
  170. return stateVector[0] == State.main_region_on_r1_PedestrianRed;
  171. case main_region_on_r1_StreetPrepare :
  172. return stateVector[0] == State.main_region_on_r1_StreetPrepare;
  173. case main_region_off :
  174. return stateVector[0].ordinal() >= State.main_region_off.ordinal()
  175. && stateVector[0].ordinal() <= State.main_region_off_r1_YellowOff.ordinal();
  176. case main_region_off_r1_YellowOn :
  177. return stateVector[0] == State.main_region_off_r1_YellowOn;
  178. case main_region_off_r1_YellowOff :
  179. return stateVector[0] == State.main_region_off_r1_YellowOff;
  180. default :
  181. return false;
  182. }
  183. }
  184. /**
  185. * Set the {@link ITimer} for the state machine. It must be set
  186. * externally on a timed state machine before a run cycle can be correct
  187. * executed.
  188. *
  189. * @param timer
  190. */
  191. public void setTimer(ITimer timer) {
  192. this.timer = timer;
  193. }
  194. /**
  195. * Returns the currently used timer.
  196. *
  197. * @return {@link ITimer}
  198. */
  199. public ITimer getTimer() {
  200. return timer;
  201. }
  202. public void timeElapsed(int eventID) {
  203. timeEvents[eventID] = true;
  204. }
  205. public SCITrafficLight getSCITrafficLight() {
  206. return sCITrafficLight;
  207. }
  208. public SCIPedestrian getSCIPedestrian() {
  209. return sCIPedestrian;
  210. }
  211. public SCInterface getSCInterface() {
  212. return sCInterface;
  213. }
  214. public void raisePedestrianRequest() {
  215. sCInterface.raisePedestrianRequest();
  216. }
  217. public void raiseOnOff() {
  218. sCInterface.raiseOnOff();
  219. }
  220. private boolean check_main_region_on_tr0_tr0() {
  221. return sCInterface.onOff;
  222. }
  223. private boolean check_main_region_on_r1_StreetGreen_tr0_tr0() {
  224. return sCInterface.pedestrianRequest;
  225. }
  226. private boolean check_main_region_on_r1_PedWaiting_tr0_tr0() {
  227. return timeEvents[0];
  228. }
  229. private boolean check_main_region_on_r1_PedWaiting_r1_waitOn_tr0_tr0() {
  230. return timeEvents[1];
  231. }
  232. private boolean check_main_region_on_r1_PedWaiting_r1_waitOff_tr0_tr0() {
  233. return timeEvents[2];
  234. }
  235. private boolean check_main_region_on_r1_StreetAttention_tr0_tr0() {
  236. return timeEvents[3];
  237. }
  238. private boolean check_main_region_on_r1_StreetRed_tr0_tr0() {
  239. return timeEvents[4];
  240. }
  241. private boolean check_main_region_on_r1_PedestrianGreen_tr0_tr0() {
  242. return timeEvents[5];
  243. }
  244. private boolean check_main_region_on_r1_PedestrianRed_tr0_tr0() {
  245. return timeEvents[6];
  246. }
  247. private boolean check_main_region_on_r1_StreetPrepare_tr0_tr0() {
  248. return timeEvents[7];
  249. }
  250. private boolean check_main_region_off_tr0_tr0() {
  251. return sCInterface.onOff;
  252. }
  253. private boolean check_main_region_off_r1_YellowOn_tr0_tr0() {
  254. return timeEvents[8];
  255. }
  256. private boolean check_main_region_off_r1_YellowOff_tr0_tr0() {
  257. return timeEvents[9];
  258. }
  259. private void effect_main_region_on_tr0() {
  260. exitSequence_main_region_on();
  261. enterSequence_main_region_off_default();
  262. }
  263. private void effect_main_region_on_r1_StreetGreen_tr0() {
  264. exitSequence_main_region_on_r1_StreetGreen();
  265. enterSequence_main_region_on_r1_PedWaiting_default();
  266. }
  267. private void effect_main_region_on_r1_PedWaiting_tr0() {
  268. exitSequence_main_region_on_r1_PedWaiting();
  269. enterSequence_main_region_on_r1_StreetAttention_default();
  270. }
  271. private void effect_main_region_on_r1_PedWaiting_r1_waitOn_tr0() {
  272. exitSequence_main_region_on_r1_PedWaiting_r1_waitOn();
  273. enterSequence_main_region_on_r1_PedWaiting_r1_waitOff_default();
  274. }
  275. private void effect_main_region_on_r1_PedWaiting_r1_waitOff_tr0() {
  276. exitSequence_main_region_on_r1_PedWaiting_r1_waitOff();
  277. enterSequence_main_region_on_r1_PedWaiting_r1_waitOn_default();
  278. }
  279. private void effect_main_region_on_r1_StreetAttention_tr0() {
  280. exitSequence_main_region_on_r1_StreetAttention();
  281. enterSequence_main_region_on_r1_StreetRed_default();
  282. }
  283. private void effect_main_region_on_r1_StreetRed_tr0() {
  284. exitSequence_main_region_on_r1_StreetRed();
  285. enterSequence_main_region_on_r1_PedestrianGreen_default();
  286. }
  287. private void effect_main_region_on_r1_PedestrianGreen_tr0() {
  288. exitSequence_main_region_on_r1_PedestrianGreen();
  289. enterSequence_main_region_on_r1_PedestrianRed_default();
  290. }
  291. private void effect_main_region_on_r1_PedestrianRed_tr0() {
  292. exitSequence_main_region_on_r1_PedestrianRed();
  293. enterSequence_main_region_on_r1_StreetPrepare_default();
  294. }
  295. private void effect_main_region_on_r1_StreetPrepare_tr0() {
  296. exitSequence_main_region_on_r1_StreetPrepare();
  297. enterSequence_main_region_on_r1_StreetGreen_default();
  298. }
  299. private void effect_main_region_off_tr0() {
  300. exitSequence_main_region_off();
  301. enterSequence_main_region_on_default();
  302. }
  303. private void effect_main_region_off_r1_YellowOn_tr0() {
  304. exitSequence_main_region_off_r1_YellowOn();
  305. enterSequence_main_region_off_r1_YellowOff_default();
  306. }
  307. private void effect_main_region_off_r1_YellowOff_tr0() {
  308. exitSequence_main_region_off_r1_YellowOff();
  309. enterSequence_main_region_off_r1_YellowOn_default();
  310. }
  311. /* Entry action for state 'StreetGreen'. */
  312. private void entryAction_main_region_on_r1_StreetGreen() {
  313. sCITrafficLight.setRed(false);
  314. sCITrafficLight.setYellow(false);
  315. sCITrafficLight.setGreen(true);
  316. sCIPedestrian.setRed(true);
  317. sCIPedestrian.setGreen(false);
  318. sCIPedestrian.setRequest(false);
  319. }
  320. /* Entry action for state 'PedWaiting'. */
  321. private void entryAction_main_region_on_r1_PedWaiting() {
  322. timer.setTimer(this, 0, 7 * 1000, false);
  323. }
  324. /* Entry action for state 'waitOn'. */
  325. private void entryAction_main_region_on_r1_PedWaiting_r1_waitOn() {
  326. timer.setTimer(this, 1, 500, false);
  327. sCIPedestrian.setRequest(true);
  328. }
  329. /* Entry action for state 'waitOff'. */
  330. private void entryAction_main_region_on_r1_PedWaiting_r1_waitOff() {
  331. timer.setTimer(this, 2, 500, false);
  332. sCIPedestrian.setRequest(false);
  333. }
  334. /* Entry action for state 'StreetAttention'. */
  335. private void entryAction_main_region_on_r1_StreetAttention() {
  336. timer.setTimer(this, 3, 2 * 1000, false);
  337. sCITrafficLight.setRed(false);
  338. sCITrafficLight.setYellow(true);
  339. sCITrafficLight.setGreen(false);
  340. }
  341. /* Entry action for state 'StreetRed'. */
  342. private void entryAction_main_region_on_r1_StreetRed() {
  343. timer.setTimer(this, 4, 2 * 1000, false);
  344. sCITrafficLight.setRed(true);
  345. sCITrafficLight.setYellow(false);
  346. sCITrafficLight.setGreen(false);
  347. }
  348. /* Entry action for state 'PedestrianGreen'. */
  349. private void entryAction_main_region_on_r1_PedestrianGreen() {
  350. timer.setTimer(this, 5, 7 * 1000, false);
  351. sCIPedestrian.setRed(false);
  352. sCIPedestrian.setGreen(true);
  353. }
  354. /* Entry action for state 'PedestrianRed'. */
  355. private void entryAction_main_region_on_r1_PedestrianRed() {
  356. timer.setTimer(this, 6, 5 * 1000, false);
  357. sCIPedestrian.setRed(true);
  358. sCIPedestrian.setGreen(false);
  359. }
  360. /* Entry action for state 'StreetPrepare'. */
  361. private void entryAction_main_region_on_r1_StreetPrepare() {
  362. timer.setTimer(this, 7, 2 * 1000, false);
  363. sCITrafficLight.setRed(true);
  364. sCITrafficLight.setYellow(true);
  365. sCITrafficLight.setGreen(false);
  366. }
  367. /* Entry action for state 'off'. */
  368. private void entryAction_main_region_off() {
  369. sCITrafficLight.setRed(false);
  370. sCITrafficLight.setGreen(false);
  371. sCITrafficLight.setYellow(false);
  372. sCIPedestrian.setRed(false);
  373. sCIPedestrian.setGreen(false);
  374. }
  375. /* Entry action for state 'YellowOn'. */
  376. private void entryAction_main_region_off_r1_YellowOn() {
  377. timer.setTimer(this, 8, 500, false);
  378. sCITrafficLight.setYellow(true);
  379. sCIPedestrian.setRequest(true);
  380. }
  381. /* Entry action for state 'YellowOff'. */
  382. private void entryAction_main_region_off_r1_YellowOff() {
  383. timer.setTimer(this, 9, 500, false);
  384. sCITrafficLight.setYellow(false);
  385. sCIPedestrian.setRequest(false);
  386. }
  387. /* Exit action for state 'PedWaiting'. */
  388. private void exitAction_main_region_on_r1_PedWaiting() {
  389. timer.unsetTimer(this, 0);
  390. sCIPedestrian.setRequest(false);
  391. }
  392. /* Exit action for state 'waitOn'. */
  393. private void exitAction_main_region_on_r1_PedWaiting_r1_waitOn() {
  394. timer.unsetTimer(this, 1);
  395. }
  396. /* Exit action for state 'waitOff'. */
  397. private void exitAction_main_region_on_r1_PedWaiting_r1_waitOff() {
  398. timer.unsetTimer(this, 2);
  399. }
  400. /* Exit action for state 'StreetAttention'. */
  401. private void exitAction_main_region_on_r1_StreetAttention() {
  402. timer.unsetTimer(this, 3);
  403. }
  404. /* Exit action for state 'StreetRed'. */
  405. private void exitAction_main_region_on_r1_StreetRed() {
  406. timer.unsetTimer(this, 4);
  407. }
  408. /* Exit action for state 'PedestrianGreen'. */
  409. private void exitAction_main_region_on_r1_PedestrianGreen() {
  410. timer.unsetTimer(this, 5);
  411. }
  412. /* Exit action for state 'PedestrianRed'. */
  413. private void exitAction_main_region_on_r1_PedestrianRed() {
  414. timer.unsetTimer(this, 6);
  415. }
  416. /* Exit action for state 'StreetPrepare'. */
  417. private void exitAction_main_region_on_r1_StreetPrepare() {
  418. timer.unsetTimer(this, 7);
  419. }
  420. /* Exit action for state 'YellowOn'. */
  421. private void exitAction_main_region_off_r1_YellowOn() {
  422. timer.unsetTimer(this, 8);
  423. }
  424. /* Exit action for state 'YellowOff'. */
  425. private void exitAction_main_region_off_r1_YellowOff() {
  426. timer.unsetTimer(this, 9);
  427. }
  428. /* 'default' enter sequence for state on */
  429. private void enterSequence_main_region_on_default() {
  430. enterSequence_main_region_on_r1_default();
  431. }
  432. /* 'default' enter sequence for state StreetGreen */
  433. private void enterSequence_main_region_on_r1_StreetGreen_default() {
  434. entryAction_main_region_on_r1_StreetGreen();
  435. nextStateIndex = 0;
  436. stateVector[0] = State.main_region_on_r1_StreetGreen;
  437. }
  438. /* 'default' enter sequence for state PedWaiting */
  439. private void enterSequence_main_region_on_r1_PedWaiting_default() {
  440. entryAction_main_region_on_r1_PedWaiting();
  441. enterSequence_main_region_on_r1_PedWaiting_r1_default();
  442. }
  443. /* 'default' enter sequence for state waitOn */
  444. private void enterSequence_main_region_on_r1_PedWaiting_r1_waitOn_default() {
  445. entryAction_main_region_on_r1_PedWaiting_r1_waitOn();
  446. nextStateIndex = 0;
  447. stateVector[0] = State.main_region_on_r1_PedWaiting_r1_waitOn;
  448. }
  449. /* 'default' enter sequence for state waitOff */
  450. private void enterSequence_main_region_on_r1_PedWaiting_r1_waitOff_default() {
  451. entryAction_main_region_on_r1_PedWaiting_r1_waitOff();
  452. nextStateIndex = 0;
  453. stateVector[0] = State.main_region_on_r1_PedWaiting_r1_waitOff;
  454. }
  455. /* 'default' enter sequence for state StreetAttention */
  456. private void enterSequence_main_region_on_r1_StreetAttention_default() {
  457. entryAction_main_region_on_r1_StreetAttention();
  458. nextStateIndex = 0;
  459. stateVector[0] = State.main_region_on_r1_StreetAttention;
  460. }
  461. /* 'default' enter sequence for state StreetRed */
  462. private void enterSequence_main_region_on_r1_StreetRed_default() {
  463. entryAction_main_region_on_r1_StreetRed();
  464. nextStateIndex = 0;
  465. stateVector[0] = State.main_region_on_r1_StreetRed;
  466. }
  467. /* 'default' enter sequence for state PedestrianGreen */
  468. private void enterSequence_main_region_on_r1_PedestrianGreen_default() {
  469. entryAction_main_region_on_r1_PedestrianGreen();
  470. nextStateIndex = 0;
  471. stateVector[0] = State.main_region_on_r1_PedestrianGreen;
  472. }
  473. /* 'default' enter sequence for state PedestrianRed */
  474. private void enterSequence_main_region_on_r1_PedestrianRed_default() {
  475. entryAction_main_region_on_r1_PedestrianRed();
  476. nextStateIndex = 0;
  477. stateVector[0] = State.main_region_on_r1_PedestrianRed;
  478. }
  479. /* 'default' enter sequence for state StreetPrepare */
  480. private void enterSequence_main_region_on_r1_StreetPrepare_default() {
  481. entryAction_main_region_on_r1_StreetPrepare();
  482. nextStateIndex = 0;
  483. stateVector[0] = State.main_region_on_r1_StreetPrepare;
  484. }
  485. /* 'default' enter sequence for state off */
  486. private void enterSequence_main_region_off_default() {
  487. entryAction_main_region_off();
  488. enterSequence_main_region_off_r1_default();
  489. }
  490. /* 'default' enter sequence for state YellowOn */
  491. private void enterSequence_main_region_off_r1_YellowOn_default() {
  492. entryAction_main_region_off_r1_YellowOn();
  493. nextStateIndex = 0;
  494. stateVector[0] = State.main_region_off_r1_YellowOn;
  495. }
  496. /* 'default' enter sequence for state YellowOff */
  497. private void enterSequence_main_region_off_r1_YellowOff_default() {
  498. entryAction_main_region_off_r1_YellowOff();
  499. nextStateIndex = 0;
  500. stateVector[0] = State.main_region_off_r1_YellowOff;
  501. }
  502. /* 'default' enter sequence for region main region */
  503. private void enterSequence_main_region_default() {
  504. react_main_region__entry_Default();
  505. }
  506. /* 'default' enter sequence for region r1 */
  507. private void enterSequence_main_region_on_r1_default() {
  508. react_main_region_on_r1__entry_Default();
  509. }
  510. /* 'default' enter sequence for region r1 */
  511. private void enterSequence_main_region_on_r1_PedWaiting_r1_default() {
  512. react_main_region_on_r1_PedWaiting_r1__entry_Default();
  513. }
  514. /* 'default' enter sequence for region r1 */
  515. private void enterSequence_main_region_off_r1_default() {
  516. react_main_region_off_r1__entry_Default();
  517. }
  518. /* Default exit sequence for state on */
  519. private void exitSequence_main_region_on() {
  520. exitSequence_main_region_on_r1();
  521. }
  522. /* Default exit sequence for state StreetGreen */
  523. private void exitSequence_main_region_on_r1_StreetGreen() {
  524. nextStateIndex = 0;
  525. stateVector[0] = State.$NullState$;
  526. }
  527. /* Default exit sequence for state PedWaiting */
  528. private void exitSequence_main_region_on_r1_PedWaiting() {
  529. exitSequence_main_region_on_r1_PedWaiting_r1();
  530. exitAction_main_region_on_r1_PedWaiting();
  531. }
  532. /* Default exit sequence for state waitOn */
  533. private void exitSequence_main_region_on_r1_PedWaiting_r1_waitOn() {
  534. nextStateIndex = 0;
  535. stateVector[0] = State.$NullState$;
  536. exitAction_main_region_on_r1_PedWaiting_r1_waitOn();
  537. }
  538. /* Default exit sequence for state waitOff */
  539. private void exitSequence_main_region_on_r1_PedWaiting_r1_waitOff() {
  540. nextStateIndex = 0;
  541. stateVector[0] = State.$NullState$;
  542. exitAction_main_region_on_r1_PedWaiting_r1_waitOff();
  543. }
  544. /* Default exit sequence for state StreetAttention */
  545. private void exitSequence_main_region_on_r1_StreetAttention() {
  546. nextStateIndex = 0;
  547. stateVector[0] = State.$NullState$;
  548. exitAction_main_region_on_r1_StreetAttention();
  549. }
  550. /* Default exit sequence for state StreetRed */
  551. private void exitSequence_main_region_on_r1_StreetRed() {
  552. nextStateIndex = 0;
  553. stateVector[0] = State.$NullState$;
  554. exitAction_main_region_on_r1_StreetRed();
  555. }
  556. /* Default exit sequence for state PedestrianGreen */
  557. private void exitSequence_main_region_on_r1_PedestrianGreen() {
  558. nextStateIndex = 0;
  559. stateVector[0] = State.$NullState$;
  560. exitAction_main_region_on_r1_PedestrianGreen();
  561. }
  562. /* Default exit sequence for state PedestrianRed */
  563. private void exitSequence_main_region_on_r1_PedestrianRed() {
  564. nextStateIndex = 0;
  565. stateVector[0] = State.$NullState$;
  566. exitAction_main_region_on_r1_PedestrianRed();
  567. }
  568. /* Default exit sequence for state StreetPrepare */
  569. private void exitSequence_main_region_on_r1_StreetPrepare() {
  570. nextStateIndex = 0;
  571. stateVector[0] = State.$NullState$;
  572. exitAction_main_region_on_r1_StreetPrepare();
  573. }
  574. /* Default exit sequence for state off */
  575. private void exitSequence_main_region_off() {
  576. exitSequence_main_region_off_r1();
  577. }
  578. /* Default exit sequence for state YellowOn */
  579. private void exitSequence_main_region_off_r1_YellowOn() {
  580. nextStateIndex = 0;
  581. stateVector[0] = State.$NullState$;
  582. exitAction_main_region_off_r1_YellowOn();
  583. }
  584. /* Default exit sequence for state YellowOff */
  585. private void exitSequence_main_region_off_r1_YellowOff() {
  586. nextStateIndex = 0;
  587. stateVector[0] = State.$NullState$;
  588. exitAction_main_region_off_r1_YellowOff();
  589. }
  590. /* Default exit sequence for region main region */
  591. private void exitSequence_main_region() {
  592. switch (stateVector[0]) {
  593. case main_region_on_r1_StreetGreen :
  594. exitSequence_main_region_on_r1_StreetGreen();
  595. break;
  596. case main_region_on_r1_PedWaiting_r1_waitOn :
  597. exitSequence_main_region_on_r1_PedWaiting_r1_waitOn();
  598. exitAction_main_region_on_r1_PedWaiting();
  599. break;
  600. case main_region_on_r1_PedWaiting_r1_waitOff :
  601. exitSequence_main_region_on_r1_PedWaiting_r1_waitOff();
  602. exitAction_main_region_on_r1_PedWaiting();
  603. break;
  604. case main_region_on_r1_StreetAttention :
  605. exitSequence_main_region_on_r1_StreetAttention();
  606. break;
  607. case main_region_on_r1_StreetRed :
  608. exitSequence_main_region_on_r1_StreetRed();
  609. break;
  610. case main_region_on_r1_PedestrianGreen :
  611. exitSequence_main_region_on_r1_PedestrianGreen();
  612. break;
  613. case main_region_on_r1_PedestrianRed :
  614. exitSequence_main_region_on_r1_PedestrianRed();
  615. break;
  616. case main_region_on_r1_StreetPrepare :
  617. exitSequence_main_region_on_r1_StreetPrepare();
  618. break;
  619. case main_region_off_r1_YellowOn :
  620. exitSequence_main_region_off_r1_YellowOn();
  621. break;
  622. case main_region_off_r1_YellowOff :
  623. exitSequence_main_region_off_r1_YellowOff();
  624. break;
  625. default :
  626. break;
  627. }
  628. }
  629. /* Default exit sequence for region r1 */
  630. private void exitSequence_main_region_on_r1() {
  631. switch (stateVector[0]) {
  632. case main_region_on_r1_StreetGreen :
  633. exitSequence_main_region_on_r1_StreetGreen();
  634. break;
  635. case main_region_on_r1_PedWaiting_r1_waitOn :
  636. exitSequence_main_region_on_r1_PedWaiting_r1_waitOn();
  637. exitAction_main_region_on_r1_PedWaiting();
  638. break;
  639. case main_region_on_r1_PedWaiting_r1_waitOff :
  640. exitSequence_main_region_on_r1_PedWaiting_r1_waitOff();
  641. exitAction_main_region_on_r1_PedWaiting();
  642. break;
  643. case main_region_on_r1_StreetAttention :
  644. exitSequence_main_region_on_r1_StreetAttention();
  645. break;
  646. case main_region_on_r1_StreetRed :
  647. exitSequence_main_region_on_r1_StreetRed();
  648. break;
  649. case main_region_on_r1_PedestrianGreen :
  650. exitSequence_main_region_on_r1_PedestrianGreen();
  651. break;
  652. case main_region_on_r1_PedestrianRed :
  653. exitSequence_main_region_on_r1_PedestrianRed();
  654. break;
  655. case main_region_on_r1_StreetPrepare :
  656. exitSequence_main_region_on_r1_StreetPrepare();
  657. break;
  658. default :
  659. break;
  660. }
  661. }
  662. /* Default exit sequence for region r1 */
  663. private void exitSequence_main_region_on_r1_PedWaiting_r1() {
  664. switch (stateVector[0]) {
  665. case main_region_on_r1_PedWaiting_r1_waitOn :
  666. exitSequence_main_region_on_r1_PedWaiting_r1_waitOn();
  667. break;
  668. case main_region_on_r1_PedWaiting_r1_waitOff :
  669. exitSequence_main_region_on_r1_PedWaiting_r1_waitOff();
  670. break;
  671. default :
  672. break;
  673. }
  674. }
  675. /* Default exit sequence for region r1 */
  676. private void exitSequence_main_region_off_r1() {
  677. switch (stateVector[0]) {
  678. case main_region_off_r1_YellowOn :
  679. exitSequence_main_region_off_r1_YellowOn();
  680. break;
  681. case main_region_off_r1_YellowOff :
  682. exitSequence_main_region_off_r1_YellowOff();
  683. break;
  684. default :
  685. break;
  686. }
  687. }
  688. /* The reactions of state StreetGreen. */
  689. private void react_main_region_on_r1_StreetGreen() {
  690. if (check_main_region_on_tr0_tr0()) {
  691. effect_main_region_on_tr0();
  692. } else {
  693. if (check_main_region_on_r1_StreetGreen_tr0_tr0()) {
  694. effect_main_region_on_r1_StreetGreen_tr0();
  695. }
  696. }
  697. }
  698. /* The reactions of state waitOn. */
  699. private void react_main_region_on_r1_PedWaiting_r1_waitOn() {
  700. if (check_main_region_on_tr0_tr0()) {
  701. effect_main_region_on_tr0();
  702. } else {
  703. if (check_main_region_on_r1_PedWaiting_tr0_tr0()) {
  704. effect_main_region_on_r1_PedWaiting_tr0();
  705. } else {
  706. if (check_main_region_on_r1_PedWaiting_r1_waitOn_tr0_tr0()) {
  707. effect_main_region_on_r1_PedWaiting_r1_waitOn_tr0();
  708. }
  709. }
  710. }
  711. }
  712. /* The reactions of state waitOff. */
  713. private void react_main_region_on_r1_PedWaiting_r1_waitOff() {
  714. if (check_main_region_on_tr0_tr0()) {
  715. effect_main_region_on_tr0();
  716. } else {
  717. if (check_main_region_on_r1_PedWaiting_tr0_tr0()) {
  718. effect_main_region_on_r1_PedWaiting_tr0();
  719. } else {
  720. if (check_main_region_on_r1_PedWaiting_r1_waitOff_tr0_tr0()) {
  721. effect_main_region_on_r1_PedWaiting_r1_waitOff_tr0();
  722. }
  723. }
  724. }
  725. }
  726. /* The reactions of state StreetAttention. */
  727. private void react_main_region_on_r1_StreetAttention() {
  728. if (check_main_region_on_tr0_tr0()) {
  729. effect_main_region_on_tr0();
  730. } else {
  731. if (check_main_region_on_r1_StreetAttention_tr0_tr0()) {
  732. effect_main_region_on_r1_StreetAttention_tr0();
  733. }
  734. }
  735. }
  736. /* The reactions of state StreetRed. */
  737. private void react_main_region_on_r1_StreetRed() {
  738. if (check_main_region_on_tr0_tr0()) {
  739. effect_main_region_on_tr0();
  740. } else {
  741. if (check_main_region_on_r1_StreetRed_tr0_tr0()) {
  742. effect_main_region_on_r1_StreetRed_tr0();
  743. }
  744. }
  745. }
  746. /* The reactions of state PedestrianGreen. */
  747. private void react_main_region_on_r1_PedestrianGreen() {
  748. if (check_main_region_on_tr0_tr0()) {
  749. effect_main_region_on_tr0();
  750. } else {
  751. if (check_main_region_on_r1_PedestrianGreen_tr0_tr0()) {
  752. effect_main_region_on_r1_PedestrianGreen_tr0();
  753. }
  754. }
  755. }
  756. /* The reactions of state PedestrianRed. */
  757. private void react_main_region_on_r1_PedestrianRed() {
  758. if (check_main_region_on_tr0_tr0()) {
  759. effect_main_region_on_tr0();
  760. } else {
  761. if (check_main_region_on_r1_PedestrianRed_tr0_tr0()) {
  762. effect_main_region_on_r1_PedestrianRed_tr0();
  763. }
  764. }
  765. }
  766. /* The reactions of state StreetPrepare. */
  767. private void react_main_region_on_r1_StreetPrepare() {
  768. if (check_main_region_on_tr0_tr0()) {
  769. effect_main_region_on_tr0();
  770. } else {
  771. if (check_main_region_on_r1_StreetPrepare_tr0_tr0()) {
  772. effect_main_region_on_r1_StreetPrepare_tr0();
  773. }
  774. }
  775. }
  776. /* The reactions of state YellowOn. */
  777. private void react_main_region_off_r1_YellowOn() {
  778. if (check_main_region_off_tr0_tr0()) {
  779. effect_main_region_off_tr0();
  780. } else {
  781. if (check_main_region_off_r1_YellowOn_tr0_tr0()) {
  782. effect_main_region_off_r1_YellowOn_tr0();
  783. }
  784. }
  785. }
  786. /* The reactions of state YellowOff. */
  787. private void react_main_region_off_r1_YellowOff() {
  788. if (check_main_region_off_tr0_tr0()) {
  789. effect_main_region_off_tr0();
  790. } else {
  791. if (check_main_region_off_r1_YellowOff_tr0_tr0()) {
  792. effect_main_region_off_r1_YellowOff_tr0();
  793. }
  794. }
  795. }
  796. /* Default react sequence for initial entry */
  797. private void react_main_region__entry_Default() {
  798. enterSequence_main_region_on_default();
  799. }
  800. /* Default react sequence for initial entry */
  801. private void react_main_region_on_r1_PedWaiting_r1__entry_Default() {
  802. enterSequence_main_region_on_r1_PedWaiting_r1_waitOn_default();
  803. }
  804. /* Default react sequence for initial entry */
  805. private void react_main_region_on_r1__entry_Default() {
  806. enterSequence_main_region_on_r1_StreetGreen_default();
  807. }
  808. /* Default react sequence for initial entry */
  809. private void react_main_region_off_r1__entry_Default() {
  810. enterSequence_main_region_off_r1_YellowOn_default();
  811. }
  812. public void runCycle() {
  813. if (!initialized)
  814. throw new IllegalStateException(
  815. "The statemachine needs to be initialized first by calling the init() function.");
  816. clearOutEvents();
  817. for (nextStateIndex = 0; nextStateIndex < stateVector.length; nextStateIndex++) {
  818. switch (stateVector[nextStateIndex]) {
  819. case main_region_on_r1_StreetGreen :
  820. react_main_region_on_r1_StreetGreen();
  821. break;
  822. case main_region_on_r1_PedWaiting_r1_waitOn :
  823. react_main_region_on_r1_PedWaiting_r1_waitOn();
  824. break;
  825. case main_region_on_r1_PedWaiting_r1_waitOff :
  826. react_main_region_on_r1_PedWaiting_r1_waitOff();
  827. break;
  828. case main_region_on_r1_StreetAttention :
  829. react_main_region_on_r1_StreetAttention();
  830. break;
  831. case main_region_on_r1_StreetRed :
  832. react_main_region_on_r1_StreetRed();
  833. break;
  834. case main_region_on_r1_PedestrianGreen :
  835. react_main_region_on_r1_PedestrianGreen();
  836. break;
  837. case main_region_on_r1_PedestrianRed :
  838. react_main_region_on_r1_PedestrianRed();
  839. break;
  840. case main_region_on_r1_StreetPrepare :
  841. react_main_region_on_r1_StreetPrepare();
  842. break;
  843. case main_region_off_r1_YellowOn :
  844. react_main_region_off_r1_YellowOn();
  845. break;
  846. case main_region_off_r1_YellowOff :
  847. react_main_region_off_r1_YellowOff();
  848. break;
  849. default :
  850. // $NullState$
  851. }
  852. }
  853. clearEvents();
  854. }
  855. }