<< mdaqBlock C/C++ code integration mdaqBlockBuild >>

MicroDAQ toolbox >> MicroDAQ toolbox > C/C++ code integration > mdaqBlockAdd

mdaqBlockAdd

Generates MicroDAQ block from provided block structure

Description

This function generates MicroDAQ block. The generated block will be avaliable in MicroDAQ User Xcos palette after Scilab restart. Function generates necessery macros and C source file which needs to be modified by adding custom user C code. Generated C source file contains three function which are executed during block initialization (init() funciton), computation(inout() function)and termination(end() function). Generated code contains pointers to block input and outputs. Block inputs are named with 'u' and input port number e.g u3 - third block input. Block outputs are named with 'y' and output port number. Code generated by mdaqBlockAdd() function also contains block parameter pointers with same names as defined in MicroDAQ block structure.

The mdaqBlockAdd() function generates three files - macros containing block code and simulation macro which can be modified to use block in simulation mode without running code on MicroDAQ. The C source file is compiled and linked with userlib.lib library which contains all precompiled MicroDAQ block C code. During code generation userlib.lib is linked with generated code which results DSP applications with custom functionality introduced by new MicroDAQ block.

Calling Sequence

mdaqBlockAdd(block);

Arguments

Examples

// call mdaqBlock to initialize block structure describing new MicroDAQ block		
block = mdaqBlock();
block.name = "test"; // set block name 
block.param_name = [ "param1" "param2" "param3" ]; // set block parameters
block.param_size = [ 1 2 4 ]; // set block parameters sizes
block.param_def_val(1) = 1;  // assign default values to defined block parameters according to block.param_size
block.param_def_val(2) = [ 2; 3 ]; 
block.param_def_val(3) = [ 4; 5; 6; 7 ]; 
block.use_sim_script = %F;

// define block inputs (four inputs: input 1 - vec size 1, input 2 - vec size 2, input 3 - vec size 4, input 4 - vec size 1)
block.in = [1 2 4 1];

// define block outputs (two outputs both with vector size 1)
block.out = [1 1];

// create block - generate block code and corresponding C source file
mdaqBlockAdd(block);

Obtaining generated file paths

// get user block generated C source file path 
mdaqToolboxPath() + "src\c\userlib"

// get user block generated macros file path
mdaqToolboxPath() + "macros\user_blocks"

Generated C code

/* Generated with MicroDAQ toolbox ver: 1.0. */
#include "scicos_block4.h"

extern double get_scicos_time( void );

/* This function will executed once at the beginning of model execution */
static void init(scicos_block *block)
{
    /* Block parameters */
    double *params = GetRparPtrs(block);

    /* param size = 1 */
    double param1 = params[0];
    int param2_size = 2;
    double *param2 = &params[1];
    int param3_size = 4;
    double *param3 = &params[3];

    /* Add block init code here */
}

/* This function will be executed on every model step */
static void inout(scicos_block *block)
{
    /* Block parameters */
    double *params = GetRparPtrs(block);
    /* param size = 1 */
    double param1 = params[0];
    int param2_size = 2;
    double *param2 = &params[1];
    int param3_size = 4;
    double *param3 = &params[3];

    /* Block input ports */
    double *u1 = GetRealInPortPtrs(block,1);
    int u1_size = GetInPortRows(block,1);    /* u1_size = 1 */

    double *u2 = GetRealInPortPtrs(block,2);
    int u2_size = GetInPortRows(block,2);    /* u2_size = 1 */

    /* Block output ports */
    double *y1 = GetRealOutPortPtrs(block,1);
    int y1_size = GetOutPortRows(block,1);    /* y1_size = 1 */

    /* Add block code here (executed every model step) */

}

/* This function will be executed once at the end of model execution (only in Ext mode) */
static void end(scicos_block *block)
{
    /* Prameters */
    double *params = GetRparPtrs(block);

    /* param size = 1 */
    double param1 = params[0];
    int param2_size = 2;
    double *param2 = &params[1];
    int param3_size = 4;
    double *param3 = &params[3];

    /* Add block end code here */
}

void mdaq_test(scicos_block *block,int flag)
{
    if (flag == 1){            /* set output */
        inout(block);
    }
    else if (flag == 5){       /* termination */
        end(block);
    }
    else if (flag == 4){       /* initialisation */
        init(block);
    }
}

See Also


Report an issue
<< mdaqBlock C/C++ code integration mdaqBlockBuild >>