Previous chapter: Source Code

Chapter 7.b. from book 'A Tour on uCANca'

CodeDesigner RAD generation

CodeDesigner RAD is a fantastic open-source tool to edit FSM

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.

CodeDesigner RAD has also a very beautiful, efficient and powerful GUI.

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

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.

/attachments/download/21

And this is an example of ANSI C source code generated by CodeDesigner RAD on this machine (using LOOPCASE generator):

>>> DECLARATION CODE PREVIEW: 

/* State IDs */
#define ID_INIT 0
#define ID_OFF 1
#define ID_ON 2

void CuF2_LowBeamLights(  );

>>> DEFINITION CODE PREVIEW: 

void CuF2_LowBeamLights(  )
{
    /* set initial state */
    static STATE_T state = ID_INIT;

    switch( state )
    {
        /* State ID: ID_INIT */
        case ID_INIT:
        {
            /* Transition ID: ID_INITTOOFF */
            /* Actions: */
            /* ['<global>::lowBeamLightsOff' begin] */
            OUT_LOWBEAM_LAMP_L = FALSE;
            OUT_LOWBEAM_LAMP_R = FALSE;
            canLowBeam=CAN_LOW_BEAM_OFF;
            /* ['<global>::lowBeamLightsOff' end] */
            state = ID_OFF;
            break;
        }
        /* State ID: ID_OFF */
        case ID_OFF:
        {
            if( statusCar>=3 && IN_LEV_LOWBEAM_LAMP==TRUE )
            {
                /* Transition ID: ID_OFFTOON */
                /* Actions: */
                /* ['<global>::lowBeamLightsOn' begin] */
                OUT_LOWBEAM_LAMP_L = TRUE;
                OUT_LOWBEAM_LAMP_R = TRUE;
                canLowBeam=CAN_LOW_BEAM_ON;
                /* ['<global>::lowBeamLightsOn' end] */
                state = ID_ON;
            }
            break;
        }
        /* State ID: ID_ON */
        case ID_ON:
        {
            if( statusCar<=2 ||
IN_LEV_LOWBEAM_LAMP==FALSE ||
(IN_LEV_HIGHBEAM_LAMP == TRUE && OUT_HIGHBEAM_LAMP_L==TRUE && OUT_HIGHBEAM_LAMP_R==TRUE) ||
diagPsOvervolt == TRUE ||
diagPsUndervolt == TRUE ||
diagPsOvercurrent == TRUE ||
LOWBEAM_LAMP_L_DGN ||
LOWBEAM_LAMP_R_DGN
 )
            {
                /* Transition ID: ID_ONTOOFF */
                /* Actions: */
                /* ['<global>::lowBeamLightsOff' begin] */
                OUT_LOWBEAM_LAMP_L = FALSE;
                OUT_LOWBEAM_LAMP_R = FALSE;
                canLowBeam=CAN_LOW_BEAM_OFF;
                /* ['<global>::lowBeamLightsOff' end] */
                state = ID_OFF;
            }
            break;
        }
    }

    return state;
}

And this is same FSM implemented using ELSEIF generator.

>>> DECLARATION CODE PREVIEW: 

/* State IDs */
#define ID_INIT 0
#define ID_OFF 1
#define ID_ON 2

void CuF2_LowBeamLights(  );

>>> DEFINITION CODE PREVIEW: 

void CuF2_LowBeamLights(  )
{
    /* set initial state */
    static STATE_T state = ID_INIT;

    /* State ID: ID_INIT */
    if( state==ID_INIT )
    {
        /* Transition ID: ID_INITTOOFF */
        /* Actions: */
        /* ['<global>::lowBeamLightsOff' begin] */
        OUT_LOWBEAM_LAMP_L = FALSE;
        OUT_LOWBEAM_LAMP_R = FALSE;
        canLowBeam=CAN_LOW_BEAM_OFF;
        /* ['<global>::lowBeamLightsOff' end] */
        state = ID_OFF;
    }
    /* State ID: ID_OFF */
    else if( state==ID_OFF )
    {
        if( statusCar>=3 && IN_LEV_LOWBEAM_LAMP==TRUE )
        {
            /* Transition ID: ID_OFFTOON */
            /* Actions: */
            /* ['<global>::lowBeamLightsOn' begin] */
            OUT_LOWBEAM_LAMP_L = TRUE;
            OUT_LOWBEAM_LAMP_R = TRUE;
            canLowBeam=CAN_LOW_BEAM_ON;
            /* ['<global>::lowBeamLightsOn' end] */
            state = ID_ON;
        }
    }
    /* State ID: ID_ON */
    else if( state==ID_ON )
    {
        if( statusCar<=2 ||
IN_LEV_LOWBEAM_LAMP==FALSE ||
(IN_LEV_HIGHBEAM_LAMP == TRUE && OUT_HIGHBEAM_LAMP_L==TRUE && OUT_HIGHBEAM_LAMP_R==TRUE) ||
diagPsOvervolt == TRUE ||
diagPsUndervolt == TRUE ||
diagPsOvercurrent == TRUE ||
LOWBEAM_LAMP_L_DGN ||
LOWBEAM_LAMP_R_DGN
 )
        {
            /* Transition ID: ID_ONTOOFF */
            /* Actions: */
            /* ['<global>::lowBeamLightsOff' begin] */
            OUT_LOWBEAM_LAMP_L = FALSE;
            OUT_LOWBEAM_LAMP_R = FALSE;
            canLowBeam=CAN_LOW_BEAM_OFF;
            /* ['<global>::lowBeamLightsOff' end] */
            state = ID_OFF;
        }
    }

    return state;
}

Next chapter Scilab/XCos project skeletons

See this page on wiki: CodeDesigner RAD projects