Tour codedesigner generation » History » Version 9

Txinto Vaz, 08/05/2018 12:24 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 9 Txinto Vaz
{{wiki_book_thumbnail(/attachments/download/21,700)}}
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 4 Txinto Vaz
void CuF2_LowBeamLights(  );
26 2 Txinto Vaz
27 2 Txinto Vaz
>>> DEFINITION CODE PREVIEW: 
28 2 Txinto Vaz
29 4 Txinto Vaz
void CuF2_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 4 Txinto Vaz
            if( statusCar>=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 4 Txinto Vaz
            if( statusCar<=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 1 Txinto Vaz
}
93 3 Txinto Vaz
</code></pre>
94 3 Txinto Vaz
95 3 Txinto Vaz
And this is same FSM implemented using ELSEIF generator.
96 3 Txinto Vaz
97 3 Txinto Vaz
<pre><code class="C">
98 3 Txinto Vaz
>>> DECLARATION CODE PREVIEW: 
99 3 Txinto Vaz
100 1 Txinto Vaz
/* State IDs */
101 3 Txinto Vaz
#define ID_INIT 0
102 3 Txinto Vaz
#define ID_OFF 1
103 1 Txinto Vaz
#define ID_ON 2
104 3 Txinto Vaz
105 4 Txinto Vaz
void CuF2_LowBeamLights(  );
106 3 Txinto Vaz
107 3 Txinto Vaz
>>> DEFINITION CODE PREVIEW: 
108 3 Txinto Vaz
109 4 Txinto Vaz
void CuF2_LowBeamLights(  )
110 3 Txinto Vaz
{
111 3 Txinto Vaz
    /* set initial state */
112 3 Txinto Vaz
    static STATE_T state = ID_INIT;
113 3 Txinto Vaz
114 3 Txinto Vaz
    /* State ID: ID_INIT */
115 3 Txinto Vaz
    if( state==ID_INIT )
116 3 Txinto Vaz
    {
117 3 Txinto Vaz
        /* Transition ID: ID_INITTOOFF */
118 3 Txinto Vaz
        /* Actions: */
119 3 Txinto Vaz
        /* ['<global>::lowBeamLightsOff' begin] */
120 3 Txinto Vaz
        OUT_LOWBEAM_LAMP_L = FALSE;
121 3 Txinto Vaz
        OUT_LOWBEAM_LAMP_R = FALSE;
122 1 Txinto Vaz
        canLowBeam=CAN_LOW_BEAM_OFF;
123 3 Txinto Vaz
        /* ['<global>::lowBeamLightsOff' end] */
124 3 Txinto Vaz
        state = ID_OFF;
125 3 Txinto Vaz
    }
126 3 Txinto Vaz
    /* State ID: ID_OFF */
127 3 Txinto Vaz
    else if( state==ID_OFF )
128 3 Txinto Vaz
    {
129 4 Txinto Vaz
        if( statusCar>=3 && IN_LEV_LOWBEAM_LAMP==TRUE )
130 3 Txinto Vaz
        {
131 3 Txinto Vaz
            /* Transition ID: ID_OFFTOON */
132 3 Txinto Vaz
            /* Actions: */
133 3 Txinto Vaz
            /* ['<global>::lowBeamLightsOn' begin] */
134 3 Txinto Vaz
            OUT_LOWBEAM_LAMP_L = TRUE;
135 3 Txinto Vaz
            OUT_LOWBEAM_LAMP_R = TRUE;
136 1 Txinto Vaz
            canLowBeam=CAN_LOW_BEAM_ON;
137 3 Txinto Vaz
            /* ['<global>::lowBeamLightsOn' end] */
138 3 Txinto Vaz
            state = ID_ON;
139 3 Txinto Vaz
        }
140 3 Txinto Vaz
    }
141 3 Txinto Vaz
    /* State ID: ID_ON */
142 3 Txinto Vaz
    else if( state==ID_ON )
143 3 Txinto Vaz
    {
144 4 Txinto Vaz
        if( statusCar<=2 ||
145 3 Txinto Vaz
IN_LEV_LOWBEAM_LAMP==FALSE ||
146 3 Txinto Vaz
(IN_LEV_HIGHBEAM_LAMP == TRUE && OUT_HIGHBEAM_LAMP_L==TRUE && OUT_HIGHBEAM_LAMP_R==TRUE) ||
147 3 Txinto Vaz
diagPsOvervolt == TRUE ||
148 3 Txinto Vaz
diagPsUndervolt == TRUE ||
149 3 Txinto Vaz
diagPsOvercurrent == TRUE ||
150 3 Txinto Vaz
LOWBEAM_LAMP_L_DGN ||
151 3 Txinto Vaz
LOWBEAM_LAMP_R_DGN
152 3 Txinto Vaz
 )
153 3 Txinto Vaz
        {
154 3 Txinto Vaz
            /* Transition ID: ID_ONTOOFF */
155 3 Txinto Vaz
            /* Actions: */
156 3 Txinto Vaz
            /* ['<global>::lowBeamLightsOff' begin] */
157 3 Txinto Vaz
            OUT_LOWBEAM_LAMP_L = FALSE;
158 3 Txinto Vaz
            OUT_LOWBEAM_LAMP_R = FALSE;
159 3 Txinto Vaz
            canLowBeam=CAN_LOW_BEAM_OFF;
160 3 Txinto Vaz
            /* ['<global>::lowBeamLightsOff' end] */
161 3 Txinto Vaz
            state = ID_OFF;
162 3 Txinto Vaz
        }
163 3 Txinto Vaz
    }
164 3 Txinto Vaz
165 3 Txinto Vaz
    return state;
166 3 Txinto Vaz
}
167 2 Txinto Vaz
</code></pre>