Tour codedesigner generation » History » Version 3
Txinto Vaz, 12/19/2013 05:05 AM
1 | 1 | Txinto Vaz | h1. CodeDesigner RAD generation |
---|---|---|---|
2 | 1 | Txinto Vaz | |
3 | 1 | Txinto Vaz | "CodeDesigner RAD":www.codedesigner.org is a fantastic open-source tool to edit "FSM":http://en.wikipedia.org/wiki/Finite-state_machine |
4 | 1 | Txinto Vaz | |
5 | 1 | Txinto Vaz | It has the ability to automatically generate source code that implements these state machine. With uCANca you can automatically genertate a CodeDesigner RAD project containing all the FSM of the project. This allows uCANca to de-couple of FSM source code generation, encouraging people to improve CodeDesigner RAD catalog of code generator rather than duplicating this ability in uCANca. |
6 | 1 | Txinto Vaz | |
7 | 1 | Txinto Vaz | CodeDesigner RAD has also a very beautiful, efficient and powerful GUI. |
8 | 1 | Txinto Vaz | |
9 | 1 | Txinto Vaz | You can export the CodeDesigner RAD project by clicking on "CodeDesigner state machines" link on project details page: http://ucanca.gatatac.org/projects/1-electric-car/gen_code.cdp |
10 | 1 | Txinto Vaz | |
11 | 1 | Txinto Vaz | If you download and install CodeDesigner RAD in you computer, you will be able to edit this file. At the beginning all the state machine states are collapsed, but after some cosmetic handling your project is similar to this screenshot. |
12 | 1 | Txinto Vaz | |
13 | 1 | Txinto Vaz | !CodeDesignerScreenshot1.png! |
14 | 2 | Txinto Vaz | |
15 | 3 | Txinto Vaz | And this is an example of ANSI C source code generated by CodeDesigner RAD on this machine (using LOOPCASE generator): |
16 | 2 | Txinto Vaz | |
17 | 2 | Txinto Vaz | <pre><code class="C"> |
18 | 2 | Txinto Vaz | >>> DECLARATION CODE PREVIEW: |
19 | 2 | Txinto Vaz | |
20 | 2 | Txinto Vaz | /* State IDs */ |
21 | 2 | Txinto Vaz | #define ID_INIT 0 |
22 | 2 | Txinto Vaz | #define ID_OFF 1 |
23 | 2 | Txinto Vaz | #define ID_ON 2 |
24 | 2 | Txinto Vaz | |
25 | 2 | Txinto Vaz | void BcmF2_LowBeamLights( ); |
26 | 2 | Txinto Vaz | |
27 | 2 | Txinto Vaz | >>> DEFINITION CODE PREVIEW: |
28 | 2 | Txinto Vaz | |
29 | 2 | Txinto Vaz | void BcmF2_LowBeamLights( ) |
30 | 2 | Txinto Vaz | { |
31 | 2 | Txinto Vaz | /* set initial state */ |
32 | 2 | Txinto Vaz | static STATE_T state = ID_INIT; |
33 | 2 | Txinto Vaz | |
34 | 2 | Txinto Vaz | switch( state ) |
35 | 2 | Txinto Vaz | { |
36 | 2 | Txinto Vaz | /* State ID: ID_INIT */ |
37 | 2 | Txinto Vaz | case ID_INIT: |
38 | 2 | Txinto Vaz | { |
39 | 2 | Txinto Vaz | /* Transition ID: ID_INITTOOFF */ |
40 | 2 | Txinto Vaz | /* Actions: */ |
41 | 2 | Txinto Vaz | /* ['<global>::lowBeamLightsOff' begin] */ |
42 | 2 | Txinto Vaz | OUT_LOWBEAM_LAMP_L = FALSE; |
43 | 2 | Txinto Vaz | OUT_LOWBEAM_LAMP_R = FALSE; |
44 | 2 | Txinto Vaz | canLowBeam=CAN_LOW_BEAM_OFF; |
45 | 2 | Txinto Vaz | /* ['<global>::lowBeamLightsOff' end] */ |
46 | 2 | Txinto Vaz | state = ID_OFF; |
47 | 2 | Txinto Vaz | break; |
48 | 2 | Txinto Vaz | } |
49 | 2 | Txinto Vaz | /* State ID: ID_OFF */ |
50 | 2 | Txinto Vaz | case ID_OFF: |
51 | 2 | Txinto Vaz | { |
52 | 2 | Txinto Vaz | if( statusBCM>=3 && IN_LEV_LOWBEAM_LAMP==TRUE ) |
53 | 2 | Txinto Vaz | { |
54 | 2 | Txinto Vaz | /* Transition ID: ID_OFFTOON */ |
55 | 2 | Txinto Vaz | /* Actions: */ |
56 | 2 | Txinto Vaz | /* ['<global>::lowBeamLightsOn' begin] */ |
57 | 2 | Txinto Vaz | OUT_LOWBEAM_LAMP_L = TRUE; |
58 | 2 | Txinto Vaz | OUT_LOWBEAM_LAMP_R = TRUE; |
59 | 2 | Txinto Vaz | canLowBeam=CAN_LOW_BEAM_ON; |
60 | 2 | Txinto Vaz | /* ['<global>::lowBeamLightsOn' end] */ |
61 | 2 | Txinto Vaz | state = ID_ON; |
62 | 2 | Txinto Vaz | } |
63 | 2 | Txinto Vaz | break; |
64 | 2 | Txinto Vaz | } |
65 | 2 | Txinto Vaz | /* State ID: ID_ON */ |
66 | 2 | Txinto Vaz | case ID_ON: |
67 | 2 | Txinto Vaz | { |
68 | 2 | Txinto Vaz | if( statusBCM<=2 || |
69 | 2 | Txinto Vaz | IN_LEV_LOWBEAM_LAMP==FALSE || |
70 | 2 | Txinto Vaz | (IN_LEV_HIGHBEAM_LAMP == TRUE && OUT_HIGHBEAM_LAMP_L==TRUE && OUT_HIGHBEAM_LAMP_R==TRUE) || |
71 | 2 | Txinto Vaz | diagPsOvervolt == TRUE || |
72 | 2 | Txinto Vaz | diagPsUndervolt == TRUE || |
73 | 2 | Txinto Vaz | diagPsOvercurrent == TRUE || |
74 | 2 | Txinto Vaz | LOWBEAM_LAMP_L_DGN || |
75 | 2 | Txinto Vaz | LOWBEAM_LAMP_R_DGN |
76 | 2 | Txinto Vaz | ) |
77 | 2 | Txinto Vaz | { |
78 | 2 | Txinto Vaz | /* Transition ID: ID_ONTOOFF */ |
79 | 2 | Txinto Vaz | /* Actions: */ |
80 | 2 | Txinto Vaz | /* ['<global>::lowBeamLightsOff' begin] */ |
81 | 2 | Txinto Vaz | OUT_LOWBEAM_LAMP_L = FALSE; |
82 | 2 | Txinto Vaz | OUT_LOWBEAM_LAMP_R = FALSE; |
83 | 2 | Txinto Vaz | canLowBeam=CAN_LOW_BEAM_OFF; |
84 | 2 | Txinto Vaz | /* ['<global>::lowBeamLightsOff' end] */ |
85 | 2 | Txinto Vaz | state = ID_OFF; |
86 | 2 | Txinto Vaz | } |
87 | 2 | Txinto Vaz | break; |
88 | 2 | Txinto Vaz | } |
89 | 2 | Txinto Vaz | } |
90 | 2 | Txinto Vaz | |
91 | 2 | Txinto Vaz | return state; |
92 | 2 | Txinto Vaz | } |
93 | 1 | Txinto Vaz | |
94 | 3 | Txinto Vaz | </code></pre> |
95 | 3 | Txinto Vaz | |
96 | 3 | Txinto Vaz | And this is same FSM implemented using ELSEIF generator. |
97 | 3 | Txinto Vaz | |
98 | 3 | Txinto Vaz | <pre><code class="C"> |
99 | 3 | Txinto Vaz | >>> DECLARATION CODE PREVIEW: |
100 | 3 | Txinto Vaz | |
101 | 3 | Txinto Vaz | /* State IDs */ |
102 | 3 | Txinto Vaz | #define ID_INIT 0 |
103 | 3 | Txinto Vaz | #define ID_OFF 1 |
104 | 3 | Txinto Vaz | #define ID_ON 2 |
105 | 3 | Txinto Vaz | |
106 | 3 | Txinto Vaz | void BcmF2_LowBeamLights( ); |
107 | 3 | Txinto Vaz | |
108 | 3 | Txinto Vaz | >>> DEFINITION CODE PREVIEW: |
109 | 3 | Txinto Vaz | |
110 | 3 | Txinto Vaz | void BcmF2_LowBeamLights( ) |
111 | 3 | Txinto Vaz | { |
112 | 3 | Txinto Vaz | /* set initial state */ |
113 | 3 | Txinto Vaz | static STATE_T state = ID_INIT; |
114 | 3 | Txinto Vaz | |
115 | 3 | Txinto Vaz | /* State ID: ID_INIT */ |
116 | 3 | Txinto Vaz | if( state==ID_INIT ) |
117 | 3 | Txinto Vaz | { |
118 | 3 | Txinto Vaz | /* Transition ID: ID_INITTOOFF */ |
119 | 3 | Txinto Vaz | /* Actions: */ |
120 | 3 | Txinto Vaz | /* ['<global>::lowBeamLightsOff' begin] */ |
121 | 3 | Txinto Vaz | OUT_LOWBEAM_LAMP_L = FALSE; |
122 | 3 | Txinto Vaz | OUT_LOWBEAM_LAMP_R = FALSE; |
123 | 3 | Txinto Vaz | canLowBeam=CAN_LOW_BEAM_OFF; |
124 | 3 | Txinto Vaz | /* ['<global>::lowBeamLightsOff' end] */ |
125 | 3 | Txinto Vaz | state = ID_OFF; |
126 | 3 | Txinto Vaz | } |
127 | 3 | Txinto Vaz | /* State ID: ID_OFF */ |
128 | 3 | Txinto Vaz | else if( state==ID_OFF ) |
129 | 3 | Txinto Vaz | { |
130 | 3 | Txinto Vaz | if( statusBCM>=3 && IN_LEV_LOWBEAM_LAMP==TRUE ) |
131 | 3 | Txinto Vaz | { |
132 | 3 | Txinto Vaz | /* Transition ID: ID_OFFTOON */ |
133 | 3 | Txinto Vaz | /* Actions: */ |
134 | 3 | Txinto Vaz | /* ['<global>::lowBeamLightsOn' begin] */ |
135 | 3 | Txinto Vaz | OUT_LOWBEAM_LAMP_L = TRUE; |
136 | 3 | Txinto Vaz | OUT_LOWBEAM_LAMP_R = TRUE; |
137 | 3 | Txinto Vaz | canLowBeam=CAN_LOW_BEAM_ON; |
138 | 3 | Txinto Vaz | /* ['<global>::lowBeamLightsOn' end] */ |
139 | 3 | Txinto Vaz | state = ID_ON; |
140 | 3 | Txinto Vaz | } |
141 | 3 | Txinto Vaz | } |
142 | 3 | Txinto Vaz | /* State ID: ID_ON */ |
143 | 3 | Txinto Vaz | else if( state==ID_ON ) |
144 | 3 | Txinto Vaz | { |
145 | 3 | Txinto Vaz | if( statusBCM<=2 || |
146 | 3 | Txinto Vaz | IN_LEV_LOWBEAM_LAMP==FALSE || |
147 | 3 | Txinto Vaz | (IN_LEV_HIGHBEAM_LAMP == TRUE && OUT_HIGHBEAM_LAMP_L==TRUE && OUT_HIGHBEAM_LAMP_R==TRUE) || |
148 | 3 | Txinto Vaz | diagPsOvervolt == TRUE || |
149 | 3 | Txinto Vaz | diagPsUndervolt == TRUE || |
150 | 3 | Txinto Vaz | diagPsOvercurrent == TRUE || |
151 | 3 | Txinto Vaz | LOWBEAM_LAMP_L_DGN || |
152 | 3 | Txinto Vaz | LOWBEAM_LAMP_R_DGN |
153 | 3 | Txinto Vaz | ) |
154 | 3 | Txinto Vaz | { |
155 | 3 | Txinto Vaz | /* Transition ID: ID_ONTOOFF */ |
156 | 3 | Txinto Vaz | /* Actions: */ |
157 | 3 | Txinto Vaz | /* ['<global>::lowBeamLightsOff' begin] */ |
158 | 3 | Txinto Vaz | OUT_LOWBEAM_LAMP_L = FALSE; |
159 | 3 | Txinto Vaz | OUT_LOWBEAM_LAMP_R = FALSE; |
160 | 3 | Txinto Vaz | canLowBeam=CAN_LOW_BEAM_OFF; |
161 | 3 | Txinto Vaz | /* ['<global>::lowBeamLightsOff' end] */ |
162 | 3 | Txinto Vaz | state = ID_OFF; |
163 | 3 | Txinto Vaz | } |
164 | 3 | Txinto Vaz | } |
165 | 3 | Txinto Vaz | |
166 | 3 | Txinto Vaz | return state; |
167 | 3 | Txinto Vaz | } |
168 | 2 | Txinto Vaz | </code></pre> |