Example #1
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{

    DECL_AND_INIT_DIMSINFO(inputDimsInfo);
    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);
     if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
	 return; /* Parameter mismatch will be reported by Simulink */
     }

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
    /*Input Port 0 */
    ssSetInputPortWidth(S,  0, INPUT_0_WIDTH); /* */
    ssSetInputPortDataType(S, 0, SS_UINT8);
    ssSetInputPortComplexSignal(S,  0, INPUT_0_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/

    /*Input Port 1 */
    ssSetInputPortWidth(S,  1, INPUT_1_WIDTH);
    ssSetInputPortDataType(S, 1, SS_UINT8);
    ssSetInputPortComplexSignal(S, 1, INPUT_1_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 1, INPUT_1_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/

    /*Input Port 2 */
    ssSetInputPortWidth(S,  2, INPUT_2_WIDTH); /* */
    ssSetInputPortDataType(S, 2, SS_UINT8);
    ssSetInputPortComplexSignal(S,  2, INPUT_2_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 2, INPUT_2_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 2, 1); /*direct input signal access*/


    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
    /* Output Port 0 */
    ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
    ssSetOutputPortDataType(S, 0, SS_DOUBLE);
    ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
    /* Output Port 1 */
    ssSetOutputPortWidth(S, 1, OUTPUT_1_WIDTH);
    ssSetOutputPortDataType(S, 1, SS_DOUBLE);
    ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX);

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    ssSetSimulinkVersionGeneratedIn(S, "8.4");

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
                     SS_OPTION_USE_TLC_WITH_ACCELERATOR | 
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}
Example #2
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
*    The sizes information is used by Simulink to determine the S-function
*    block's characteristics (number of inputs, outputs, states, etc.).
*/
static void mdlInitializeSizes(SimStruct *S)
{
   // loop counter
   int idx;

   ssSetNumSFcnParams(S, P_NPARMS);  /* Number of expected parameters */
   // No parameters will be tunable
   for(idx=0; idx<P_NPARMS; idx++){
      ssSetSFcnParamNotTunable(S,idx);
   }

   if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
      /* Return if number of expected != number of actual parameters */
      return;
   }

   // Setup all the CAN datatypes
   CAN_Common_MdlInitSizes(S);
   // Extended frame
   int_T canExDT = ssGetDataTypeId(S,SL_CAN_EXTENDED_FRAME_DTYPE_NAME );
   // Standard frame
   int_T canStDT = ssGetDataTypeId(S,SL_CAN_STANDARD_FRAME_DTYPE_NAME );

   // Setup input port
   ssSetNumInputPorts(S,1);
   ssSetInputPortWidth(S,0,1);
   ssSetInputPortDirectFeedThrough(S,0,true);
   ssSetInputPortDataType(S,0,DYNAMICALLY_TYPED);
   
   // Setup output ports
   ssSetNumOutputPorts(S,4);

   ssSetOutputPortWidth(S,0,1); /* ID */
   ssSetOutputPortDataType(S,0, SS_DOUBLE);
   
   
   ssSetOutputPortWidth(S,1,1); /* Length */
   ssSetOutputPortDataType(S,1, SS_DOUBLE);
 
   ssSetOutputPortWidth(S,2,1); /* Type */
   ssSetOutputPortDataType(S,2, SS_DOUBLE);

   ssSetOutputPortWidth(S,3,1); /* Data */
   ssSetOutputPortDataType(S,3, SS_DOUBLE);
   

   ssSetNumContStates(S, 0);
   ssSetNumDiscStates(S, 0);

   ssSetNumSampleTimes(S, 1);
   
   ssSetNumRWork(S, 0);
   ssSetNumIWork(S, 0);
   ssSetNumPWork(S, 0);
   ssSetNumModes(S, 0);
   ssSetNumNonsampledZCs(S, 0);

   /* use generated code in Accelerator Mode */   
   ssSetOptions(S, SS_OPTION_USE_TLC_WITH_ACCELERATOR);
}
Example #3
0
/*=====================================*
 * Configuration and execution methods *
 *=====================================*/
static void mdlInitializeSizes(SimStruct *S)
{
#ifdef DEBUG
	debug("mdlInitializeSizes entered.\n");
#endif
    ssSetNumSFcnParams(S, NPAR);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
		mdlCheckParameters(S);
        if (ssGetErrorStatus(S) != NULL) return;
    }

    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);

    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, NI);
    ssSetInputPortDirectFeedThrough(S, 0, 1);

    if (!ssSetNumOutputPorts(S, 1)) return;
    ssSetOutputPortWidth(S, 0, NO);

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
#ifdef DEBUG
	debug("mdlInitializeSizes left.\n");
#endif
} /* mdlInitializeSizes */
Example #4
0
static void mdlInitializeSizes(SimStruct *S) {
	bool dataPort;

	ssSetNumSFcnParams(S,3);
	if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
		return; /* Parameter mismatch will be reported by Simulink */
	}
	dataPort = PARAM(2)[0];

	if (dataPort) {
		if (!ssSetNumInputPorts(S,2)) return;
		ssSetInputPortWidth(S,1,DYNAMICALLY_SIZED);
		ssSetInputPortDirectFeedThrough(S,1,1);
	} else {
		if (!ssSetNumInputPorts(S,1)) return;
	}
	ssSetInputPortWidth(S,0,1);
	ssSetInputPortDirectFeedThrough(S,0,1);

	ssSetNumContStates(S,0);
	ssSetNumDiscStates(S,0);

	if (!ssSetNumOutputPorts(S,0)) return;

	ssSetInputPortDataType(S, 0, DYNAMICALLY_TYPED);
	ssSetNumSampleTimes(S,1);
	ssSetNumRWork(S,1);
	ssSetNumIWork(S,1);
	ssSetNumPWork(S,2);
	ssSetNumModes(S,0);
	ssSetNumNonsampledZCs(S,0);
	ssSetOptions(S,0);
}
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S) {
    
    ssSetNumSFcnParams(S, 0);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /* Return if number of expected != number of actual parameters */
        return;
    }
    //  printf("URG: 111\n");
    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);
    
    if (!ssSetNumInputPorts(S, 0)) return;
    
    if (!ssSetNumOutputPorts(S, 1)) return;
    ssSetOutputPortWidth(S, 0, 682);
    ssSetOutputPortDataType(S, 0, SS_INT16);
    
    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);
    
    
    /* Specify the sim state compliance to be same as a built-in block */
    //  ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
    
    ssSetOptions(S, 0);
    
    printf("URG: Inicializando driver URG-04LX...\n");
}
Example #6
0
static void mdlInitializeSizes(SimStruct *S) {
    int_T msgType;
    int_T initValLen;

    ssSetNumSFcnParams(S,5);
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        return; /* Parameter mismatch will be reported by Simulink */
    }
    ssSetNumContStates(S,0);
    ssSetNumDiscStates(S,0);

    if (!ssSetNumInputPorts(S,0)) return;

    msgType = (int_T)*mxGetPr(ssGetSFcnParam(S,0));
    switch (msgType) {
    case SUBSCRIBER_TWIST_STAMPED:
    case PUBLISHER_POINT_STAMPED:
        if (!ssSetNumOutputPorts(S,2)) return;
        ssSetOutputPortWidth(S,1,2);
        break;
    default:
        if (!ssSetNumOutputPorts(S,1)) return;
    }

    switch (msgType) {
    case SUBSCRIBER_FLOAT64:
    case SUBSCRIBER_INT32:
    case SUBSCRIBER_BOOL:
    case SUBSCRIBER_TIME:
        ssSetOutputPortWidth(S,0,1);
        break;
    case SUBSCRIBER_FLOAT64ARRAY:
        ssSetOutputPortWidth(S,0,DYNAMICALLY_SIZED);
        break;
    case SUBSCRIBER_TWIST:
    case SUBSCRIBER_TWIST_STAMPED:
        ssSetOutputPortWidth(S,0,6);
        break;
    case PUBLISHER_POINT:
    case PUBLISHER_POINT_STAMPED:
    case PUBLISHER_POSE2D:
        ssSetOutputPortWidth(S,0,3);
        break;
    default:
        ssSetErrorStatus(S, "Unknown message type!");
        return;
    }
    initValLen = mxGetNumberOfElements(ssGetSFcnParam(S,2));
    if (initValLen > 1) {
        ssSetOutputPortWidth(S,0,initValLen);
    }

    ssSetNumSampleTimes(S,1);
    ssSetNumRWork(S,0);
    ssSetNumIWork(S,1);
    ssSetNumPWork(S,2);
    ssSetNumModes(S,0);
    ssSetNumNonsampledZCs(S,0);
    ssSetOptions(S,0);
}
Example #7
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{

    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);
     if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
	 return; /* Parameter mismatch will be reported by Simulink */
     }

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;

    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
    ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
    ssSetOutputPortDataType(S, 0, SS_INT32);
    ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}
Example #8
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
    ssSetNumSFcnParams(S, 0);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        return; /* Parameter mismatch will be reported by Simulink */
    }

    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 2);

    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, 2);
    ssSetInputPortDirectFeedThrough(S, 0, 1);

    if (!ssSetNumOutputPorts(S, 1)) return;
    ssSetOutputPortWidth(S, 0, 2);

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);
    ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
}
Example #9
0
static void mdlInitializeSizes(SimStruct *S)
{
    ssSetNumSFcnParams(S, N_PARAMS);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /* Return if number of expected != number of actual parameters */
        return;
    }

    ssSetNumContStates(S, N_STATES);
    ssSetNumDiscStates(S, 0);

    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, N_INPUTS);
    ssSetInputPortDirectFeedThrough(S, 0, 1);

    if (!ssSetNumOutputPorts(S, 1)) return;
    ssSetOutputPortWidth(S, 0, N_OUTPUTS);

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    ssSetOptions(S, 0);
}
void mdlInitializeSizes(SimStruct *S)
/* ======================================================================== */
{
    /* parameters */
    ssSetNumSFcnParams(S, NUM_PARAMS);
    #if defined(MATLAB_MEX_FILE)
    if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
        mdlCheckParameters(S);
        if (ssGetErrorStatus(S) != NULL) return;
    } else
        return;
    #endif
    ssSetSFcnParamTunable(S, FREQUENCY,   SS_PRM_SIM_ONLY_TUNABLE);
    ssSetSFcnParamTunable(S, BANDWIDTH,   SS_PRM_NOT_TUNABLE);
    ssSetSFcnParamTunable(S, TXVGA_GAIN,  SS_PRM_SIM_ONLY_TUNABLE);

    /* ports */
    ssSetNumSampleTimes(S, 1);
    if (!ssSetNumOutputPorts(S, 0) || !ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED);
    ssSetInputPortComplexSignal(S, 0, COMPLEX_YES);
    ssSetInputPortDataType(S, 0, SS_INT8);
    ssSetInputPortDirectFeedThrough(S, 0, true);
    ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);

    /* work Vectors */
    ssSetNumPWork(S, P_WORK_LENGTH);
    ssSetNumIWork(S, 0);
    ssSetNumRWork(S, NUM_PARAMS);
    ssSetNumModes(S, 0);

    ssSetNumNonsampledZCs(S, 0);
    ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
    ssSetOptions(S, 0);
}
Example #11
0
static void mdlInitializeSizes(SimStruct *S)
{
    int i;
    ssSetNumSFcnParams(S, NPARAMS);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /* Return if number of expected != number of actual parameters */
        return;
    }
    
    for (i = 0; i < NPARAMS; i++)
        ssSetSFcnParamTunable(S, i, 0);
    
    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);
    
    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, 3);
    ssSetInputPortRequiredContiguous(S, 0, true);
    ssSetInputPortDirectFeedThrough(S, 0, 1);
    
    if (!ssSetNumOutputPorts(S, 1)) return;
    ssSetOutputPortWidth(S, 0, 7);
    
    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 2);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);
    
}
static void mdlInitializeSizes(SimStruct *S)
{
  ssSetNumSFcnParams(S, 0);  /* Number of expected parameters */
  if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
    return;
  }

  ssSetNumContStates(S, 2);
  ssSetNumDiscStates(S, 0);

  if (!ssSetNumInputPorts(S, 0)) return;
  if (!ssSetNumOutputPorts(S, 1)) return;
  ssSetOutputPortWidth(S, 0, 2);

  ssSetNumSampleTimes(S, 1);
  ssSetNumRWork(S, 0);
  ssSetNumIWork(S, 0);
  ssSetNumPWork(S, 0);
  ssSetNumModes(S, 0);
  ssSetNumNonsampledZCs(S, 1);

  ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

  ssSetOptions(S, 0);
}
static void mdlInitializeSizes( SimStruct *S )
/* ======================================================================== */
{
	int_T port;

	/* set number of expected parameters and check for a mismatch. */
	ssSetNumSFcnParams( S, NUM_PARAMS );
#if defined(MATLAB_MEX_FILE)
	if ( ssGetNumSFcnParams( S ) == ssGetSFcnParamsCount( S ) )
	{
		mdlCheckParameters( S );
		if ( ssGetErrorStatus( S ) != NULL )
			return;
	}else  {
		return;
	}
#endif

	/* sampling */
	ssSetNumSampleTimes( S, PORT_BASED_SAMPLE_TIMES );

	/* Set number of input ports and tunability */
	ssSetSFcnParamTunable( S, DEVICE_INDEX, SS_PRM_NOT_TUNABLE );

	/* set the resulting number of ports */
	if ( !ssSetNumInputPorts( S, 1 ) )
		return;

	port = 0;
	{
		const Frame_T	inputsFrames	= ( (double) mxGetScalar( ssGetSFcnParam( S, USE_FRAMES ) ) > 0.0) ? FRAME_YES : FRAME_NO;
		double		sample_time	= 1 / mxGetScalar( ssGetSFcnParam( S, SAMPLE_RATE ) );
		const int_T	buf_length	= (int_T) (double) mxGetScalar( ssGetSFcnParam( S, FRAME_LENGTH ) );
		const time_T	period		= (time_T) (sample_time * buf_length);

		ssSetInputPortMatrixDimensions( S, port, buf_length, 1 );
		ssSetInputPortComplexSignal( S, port, COMPLEX_YES );
		ssSetInputPortDataType( S, port, SS_DOUBLE );
		ssSetInputPortFrameData( S, port, inputsFrames );
		ssSetInputPortDirectFeedThrough( S, port, 1 );
		ssSetInputPortSampleTime( S, port, period );
		ssSetInputPortOffsetTime( S, port, 0.0 );
	}

	/* Set number of output ports */
	if ( !ssSetNumOutputPorts( S, 0 ) )
		return;
	/* data port properties */
	/* Prepare work Vectors */
	ssSetNumPWork( S, P_WORK_LENGTH );
	ssSetNumIWork( S, I_WORK_LENGTH );
	ssSetNumRWork( S, R_WORK_LENGTH );
	ssSetNumModes( S, 0 );
	ssSetNumNonsampledZCs( S, 0 );

	/* Specify the sim state compliance to be same as a built-in block */
	ssSetSimStateCompliance( S, USE_DEFAULT_SIM_STATE );

	ssSetOptions( S, 0 );
}
Example #14
0
static void mdlInitializeSizes(SimStruct *S)
{ 
  ssSetNumSFcnParams(S, 4);  /* B,x0,U,P Number of expected parameters */
  if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S))
    return;
  else
  {
    if (CheckPar(S))
      return;
  }

    ssSetNumContStates(S, (int) B(S,"CStates"));
    ssSetNumDiscStates(S, (int) B(S,"DStates"));

    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, (int)  (U(S,"Number")*B(S,"WaterIn")+B(S,"Setpoints")));
    ssSetInputPortDirectFeedThrough(S, 0, (int) B(S,"Direct"));
    ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/

    if (!ssSetNumOutputPorts(S,1)) return;
    ssSetOutputPortWidth(S, 0, (int) (U(S,"Number")*B(S,"WaterOut")+B(S,"Measurements")) );

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE |
                 SS_OPTION_USE_TLC_WITH_ACCELERATOR);
       
}
Example #15
0
 static void mdlSetWorkWidths(SimStruct *S)
 {
     int_T nq = 0;
     if( mxGetNumberOfElements(paramQuaternionIndex) == 2 )
     {
         nq = intval(mxGetPr(paramQuaternionIndex)[1]) - intval(mxGetPr(paramQuaternionIndex)[0]) + 1;
         nq = nq / 4;
     }
     ssSetNumContStates(S, 0);
     ssSetNumDiscStates(S, 0);
     ssSetNumRWork(S, 0);
     ssSetNumIWork(S, 1);
     ssSetNumPWork(S, 1);
     ssSetNumDWork(S, (nq > 0 ? 3 : 2));
     ssSetDWorkWidth(S, 0, ssGetInputPortWidth(S, 0));
     ssSetDWorkWidth(S, 1, ssGetInputPortWidth(S, 0));
     ssSetDWorkDataType(S, 0, SS_DOUBLE);
     ssSetDWorkDataType(S, 1, SS_DOUBLE);
     if( nq )
     {
         ssSetDWorkWidth(S, 2, ssGetInputPortWidth(S, 0));
         ssSetDWorkDataType(S, 2, SS_DOUBLE);
     }
     ssSetNumModes(S, 0);
 }
Example #16
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{

    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);
     if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
	 return; /* Parameter mismatch will be reported by Simulink */
     }

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;

    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
    /* Output Port 0 */
    ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
    ssSetOutputPortDataType(S, 0, SS_SINGLE);
    ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
    /* Output Port 1 */
    ssSetOutputPortWidth(S, 1, OUTPUT_1_WIDTH);
    ssSetOutputPortDataType(S, 1, SS_SINGLE);
    ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX);
    /* Output Port 2 */
    ssSetOutputPortWidth(S, 2, OUTPUT_2_WIDTH);
    ssSetOutputPortDataType(S, 2, SS_SINGLE);
    ssSetOutputPortComplexSignal(S, 2, OUTPUT_2_COMPLEX);
    /* Output Port 3 */
    ssSetOutputPortWidth(S, 3, OUTPUT_3_WIDTH);
    ssSetOutputPortDataType(S, 3, SS_SINGLE);
    ssSetOutputPortComplexSignal(S, 3, OUTPUT_3_COMPLEX);
    /* Output Port 4 */
    ssSetOutputPortWidth(S, 4, OUTPUT_4_WIDTH);
    ssSetOutputPortDataType(S, 4, SS_SINGLE);
    ssSetOutputPortComplexSignal(S, 4, OUTPUT_4_COMPLEX);
    /* Output Port 5 */
    ssSetOutputPortWidth(S, 5, OUTPUT_5_WIDTH);
    ssSetOutputPortDataType(S, 5, SS_SINGLE);
    ssSetOutputPortComplexSignal(S, 5, OUTPUT_5_COMPLEX);
    /* Output Port 6 */
    ssSetOutputPortWidth(S, 6, OUTPUT_6_WIDTH);
    ssSetOutputPortDataType(S, 6, SS_SINGLE);
    ssSetOutputPortComplexSignal(S, 6, OUTPUT_6_COMPLEX);

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    ssSetSimulinkVersionGeneratedIn(S, "8.6");

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
                     SS_OPTION_USE_TLC_WITH_ACCELERATOR | 
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}
Example #17
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{
    slDataTypeAccess *dta = ssGetDataTypeAccess(S);
    int              udtId;

    ssSetNumSFcnParams(S, 0);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /* Return if number of expected != number of actual parameters */
        return;
    }

    /* Obtain an integer datatype ID for the udt (user-defined type) "Data" */
    udtId = ssRegisterDataType(S, "Data");
    if ( udtId == INVALID_DTYPE_ID ) return;

    /* Register the size of the udt */
    if (!ssSetDataTypeSize(S, udtId, sizeof(Data))) return;

    /* Register the zero of the udt */
    if (!ssSetDataTypeZero(S, udtId, &zero)) return;

    /* Register the convert-between datatype function defined above */
    if (!dtaSetConvertBetweenFcn(dta, ssGetPath(S), udtId, &DataCnvBtw)) return;

    /* Register the is-positive datatype function defined above*/
    if (!dtaSetIsPositiveFcn(dta, ssGetPath(S), udtId, &DataIsPos)) return;

    /* Set input-port properties */
    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, 1);
    ssSetInputPortDataType(S, 0, SS_DOUBLE);
    ssSetInputPortDirectFeedThrough(S, 0, 1);

    /* Set output port properties */
    if (!ssSetNumOutputPorts(S, 1)) return;
    ssSetOutputPortDataType(S, 0, udtId);
    ssSetOutputPortWidth(S, 0, 1);

    /* Set miscellaneous properties */
    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);
    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* specify the sim state compliance to be same as a built-in block */
    ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

    ssSetOptions(S,
                 SS_OPTION_WORKS_WITH_CODE_REUSE |
                 SS_OPTION_USE_TLC_WITH_ACCELERATOR |
                 SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME |
                 SS_OPTION_SFUNCTION_INLINED_FOR_RTW);
}
Example #18
0
static void mdlInitializeSizes(SimStruct *S)
{
    int i,nChannels;
    static char msg[256];
    ssSetNumSFcnParams(S, NUMBER_OF_ARGS);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /* Return if number of expected != number of actual parameters */
        sprintf(msg,"Wrong Number of input arguments passed.\n%d arguments are expected\n",NUMBER_OF_ARGS);
        ssSetErrorStatus(S,msg);
        return;
    }

    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);
    
    ssSetNumInputPorts(S, 0);//there is no input 
    //if (!ssSetNumInputPorts(S, 1)) return;
    
    nChannels=(uint_T)mxGetN(CHANNEL_ARG);
   
    //if (!ssSetNumOutputPorts(S, 1)) return;
    ssSetNumOutputPorts(S,nChannels);//set number of outputs ports
    for(i=0;i<nChannels;i++)
    {
        ssSetOutputPortWidth(S, i, 1);//set width of each port to 1    
    }
    
    ssSetInputPortWidth(S, 0, 1);
    ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
    /*
     * Set direct feedthrough flag (1=yes, 0=no).
     * A port has direct feedthrough if the input is used in either
     * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
     */
    ssSetInputPortDirectFeedThrough(S, 0, 1);

   

    ssSetNumSampleTimes(S, 1);//set number of sample time to 1,which means all input ports share same Ts
    
    ssSetNumRWork(S, NO_R_WORKS);//number of float in work vector
    ssSetNumIWork(S, NO_I_WORKS);//number of int in work vector
    ssSetNumPWork(S, 0);//number of pointer in work vector
    
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);//no need for pass-zero check 
    
    ssSetSFcnParamNotTunable(S,0);
    ssSetSFcnParamNotTunable(S,1);
    ssSetSFcnParamNotTunable(S,2);
    ssSetSFcnParamNotTunable(S,3);
    ssSetSFcnParamNotTunable(S,4);
    
    ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE|SS_OPTION_PLACE_ASAP);
    /* Specify the sim state compliance to be same as a built-in block */
    ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
}
Example #19
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
    
    char host[] = "localhost";
	int port = 9002;
    
    trigger = 0;
    /* See sfuntmpl_doc.c for more details on the macros below */

    ssSetNumSFcnParams(S, 1);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /* Return if number of expected != number of actual parameters */
        return;
    }

    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);

    /* This functions receives no inputs, but it could use inputs instead of hard-coded parameters (e.g. port and host) */
    if (!ssSetNumInputPorts(S, 0)) return;
    /*ssSetInputPortWidth(S, 0, 1);*/
    /*ssSetInputPortRequiredContiguous(S, 0, true); /direct input signal access*/
    /*
     * Set direct feedthrough flag (1=yes, 0=no).
     * A port has direct feedthrough if the input is used in either
     * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
     * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
     */
    /*ssSetInputPortDirectFeedThrough(S, 0, 1);*/

    if (!ssSetNumOutputPorts(S, 2)) return;
    ssSetOutputPortWidth(S, 0, PAYLOAD_LEN/2); 
    ssSetOutputPortDataType(S, 0, SS_UINT16);

    ssSetOutputPortWidth(S, 1, 1);



    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
    
        /* Connect to the SerialForwarder server using functions linked in sfsource.o */
    fd = open_sf_source(host, port);
    
        if (fd < 0){
            ssSetErrorStatus(S,"SerialForwarder not running in the specified host and port");
            return;
        }

}
Example #20
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
        int idx;

        int_T canExDT; // Extended extended frame
        int_T canStDT; // Standard frame

        /* See sfuntmpl_doc.c for more details on the macros below */

        ssSetNumSFcnParams(S, P_NPARMS);  /* Number of expected parameters */
        
        if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
                /* Return if number of expected != number of actual parameters */
                return;
        }
                
        // No parameters will be tunable
        for(idx=0; idx<P_NPARMS; idx++){
                ssSetSFcnParamNotTunable(S,idx);
        }

        // Setup all the CAN datatypes
        CAN_Common_MdlInitSizes(S);
        canExDT = ssGetDataTypeId(S,SL_CAN_EXTENDED_FRAME_DTYPE_NAME );
        canStDT = ssGetDataTypeId(S,SL_CAN_STANDARD_FRAME_DTYPE_NAME );

        // One vectorized output port may contain several CAN
        // messages, one frame per signal element
        ssSetNumOutputPorts(S,1);
        ssSetOutputPortWidth(S,0,1);
        if( P_TYPE == CAN_MESSAGE_STANDARD){
                ssSetOutputPortDataType(S,0,canStDT);
        }else if ( P_TYPE == CAN_MESSAGE_EXTENDED ){
                ssSetOutputPortDataType(S,0,canExDT);
        }

        // Multiple input ports. Each input port represents
        // a CAN data frame. These will be vectorized
        // uint8 inputs. The width corressponds to the
        // number of data bytes in the frame
        setInputPorts(S);

        ssSetNumContStates(S, 0);
        ssSetNumDiscStates(S, 0);


        ssSetNumSampleTimes(S, 1);
        ssSetNumRWork(S, 0);
        ssSetNumIWork(S, 0);
        ssSetNumPWork(S, 0);
        ssSetNumModes(S, 0);
        ssSetNumNonsampledZCs(S, 0);
         
        /* use generated code in Accelerator Mode */
        ssSetOptions(S, SS_OPTION_USE_TLC_WITH_ACCELERATOR);
}
Example #21
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{

    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);
     if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
	 return; /* Parameter mismatch will be reported by Simulink */
     }

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;

    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
    /* Output Port 0 */
    outputDimsInfo.width = OUTPUT_0_WIDTH;
    ssSetOutputPortDimensionInfo(S, 0, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,0, OUTPUT_0_WIDTH, OUTPUT_DIMS_0_COL);
    ssSetOutputPortFrameData(S, 0, OUT_0_FRAME_BASED);
    ssSetOutputPortDataType(S, 0, SS_UINT8);
    ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
    /* Output Port 1 */
    outputDimsInfo.width = OUTPUT_1_WIDTH;
    ssSetOutputPortDimensionInfo(S, 1, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,1, OUTPUT_1_WIDTH, OUTPUT_DIMS_1_COL);
    ssSetOutputPortFrameData(S, 1, OUT_1_FRAME_BASED);
    ssSetOutputPortDataType(S, 1, SS_UINT8);
    ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX);
    /* Output Port 2 */
    outputDimsInfo.width = OUTPUT_2_WIDTH;
    ssSetOutputPortDimensionInfo(S, 2, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,2, OUTPUT_2_WIDTH, OUTPUT_DIMS_2_COL);
    ssSetOutputPortFrameData(S, 2, OUT_2_FRAME_BASED);
    ssSetOutputPortDataType(S, 2, SS_UINT8);
    ssSetOutputPortComplexSignal(S, 2, OUTPUT_2_COMPLEX);
    /* Output Port 3 */
    outputDimsInfo.width = OUTPUT_3_WIDTH;
    ssSetOutputPortDimensionInfo(S, 3, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,3, OUTPUT_3_WIDTH, OUTPUT_DIMS_3_COL);
    ssSetOutputPortFrameData(S, 3, OUT_3_FRAME_BASED);
    ssSetOutputPortDataType(S, 3, SS_UINT16);
    ssSetOutputPortComplexSignal(S, 3, OUTPUT_3_COMPLEX);

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}
Example #22
0
static void mdlInitializeSizes(SimStruct *S)
{
    const real_T  *P1  = mxGetData(PARAM_DEF3(S));
    const real_T  *P2  = mxGetData(PARAM_DEF2(S));
    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);  /* Number of expected parameters */
      #if defined(MATLAB_MEX_FILE)
	if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
	  if (ssGetErrorStatus(S) != NULL) {
	    return;
	  }
	 } else {
	   return; /* Parameter mismatch will be reported by Simulink */
	 }
      #endif

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;

    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
    /* Output Port 0 */
    outputDimsInfo.width = *P1;         
    ssSetOutputPortDimensionInfo(S, 0, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,0, *P1, *P2);
    ssSetOutputPortFrameData(S, 0, OUT_0_FRAME_BASED);
    ssSetOutputPortDataType(S, 0, SS_UINT8);
    ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
    /* Output Port 1 */
    outputDimsInfo.width = *P1;
    ssSetOutputPortDimensionInfo(S, 1, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,1, *P1, *P2);
    ssSetOutputPortFrameData(S, 1, OUT_1_FRAME_BASED);
    ssSetOutputPortDataType(S, 1, SS_UINT8);
    ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX);
    /* Output Port 2 */
    outputDimsInfo.width = *P1;
    ssSetOutputPortDimensionInfo(S, 2, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,2, *P1, *P2);
    ssSetOutputPortFrameData(S, 2, OUT_2_FRAME_BASED);
    ssSetOutputPortDataType(S, 2, SS_UINT8);
    ssSetOutputPortComplexSignal(S, 2, OUTPUT_2_COMPLEX);

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
    /* See sfuntmpl_doc.c for more details on the macros below */

    ssSetNumSFcnParams(S, 5);  /* Number of expected parameters */
#if defined(MATLAB_MEX_FILE)
    if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
        mdlCheckParameters(S);
        if (ssGetErrorStatus(S) != NULL) {
            return;
        }
    } else {
        return; /* Parameter mismatch will be reported by Simulink. */
    }
#endif

    int_T nRobots = mxGetNumberOfElements(ssGetSFcnParam(S,2));

    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);

    if (!ssSetNumInputPorts(S, 0)) return;
    //ssSetInputPortWidth(S, 0, 1);
    //ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
    /*
     * Set direct feedthrough flag (1=yes, 0=no).
     * A port has direct feedthrough if the input is used in either
     * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
     * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
     */
    //ssSetInputPortDirectFeedThrough(S, 0, 1);

    if (!ssSetNumOutputPorts(S, 4)) return;

    const int_T nDofs = *((mxChar*)mxGetData(ssGetSFcnParam(S, 4)));

    ssSetOutputPortMatrixDimensions(S, 0, nDofs, nRobots); // position
    ssSetOutputPortMatrixDimensions(S, 1, nDofs, nRobots); // velocity
    ssSetOutputPortMatrixDimensions(S, 2, nDofs, nRobots); // effort
    ssSetOutputPortMatrixDimensions(S, 3, 1, nRobots); // SentTime in s;

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 2); // nRobots, nDofs
    ssSetNumPWork(S, nRobots + 1); //nRobots x GenericSub, AsyncSpinner
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Specify the sim state compliance to be same as a built-in block */
    ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

    ssSetOptions(S, 0);
}
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S) {
	/* See sfuntmpl_doc.c for more details on the macros below */

	ssSetNumSFcnParams(S, 2); /* Number of expected parameters */
#if defined(MATLAB_MEX_FILE)
	if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
		mdlCheckParameters(S);
		if (ssGetErrorStatus(S) != NULL) {
			return;
		}
	} else {
		return; /* Parameter mismatch will be reported by Simulink. */
	}
#endif

	ssSetNumContStates(S, 0);
	ssSetNumDiscStates(S, 0);

	if (!ssSetNumInputPorts(S, 2))
		return;

	ssSetInputPortMatrixDimensions(S, 0, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED); // triangles
	ssSetInputPortDataType(S, 0, SS_UINT32);
	ssSetInputPortMatrixDimensions(S, 1, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED); // vertices

	for (int_T i = 0; i < ssGetNumInputPorts(S); ++i) {
		/*direct input signal access*/
		ssSetInputPortRequiredContiguous(S, i, true);

		/*
		 * Set direct feedthrough flag (1=yes, 0=no).
		 * A port has direct feedthrough if the input is used in either
		 * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
		 * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
		 */
		ssSetInputPortDirectFeedThrough(S, i, 1);
	}

	if (!ssSetNumOutputPorts(S, 0))
		return;

	ssSetNumSampleTimes(S, 1);
	ssSetNumRWork(S, 0);
	ssSetNumIWork(S, 0);
	ssSetNumPWork(S, 2); //GenericPub and frame id
	ssSetNumModes(S, 0);
	ssSetNumNonsampledZCs(S, 0);

	/* Specify the sim state compliance to be same as a built-in block */
	ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

	ssSetOptions(S, 0);
}
Example #25
0
static void mdlInitializeSizes(SimStruct *S)
{
  const mxArray *arg;

  ssSetNumSFcnParams(S, 3);  /* Number of expected parameters */
  if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
    return; /* Parameter mismatch will be reported by Simulink */
  }
  
  if (!ssSetNumInputPorts(S, 0)) return;
  if (!ssSetNumOutputPorts(S, 7)) return;

  RMsys *rmsys = new RMsys;
  rmsys->trigger = 0.0;

  arg = ssGetSFcnParam(S, 0);
  if (mxIsDoubleScalar(arg)) {
    rmsys->networkNbr  = (int)*mxGetPr(arg);
  }
  arg = ssGetSFcnParam(S, 1);
  if (mxIsDoubleScalar(arg)) {
    rmsys->receiver  = (int)*mxGetPr(arg);
  }
  arg = ssGetSFcnParam(S, 2);
  if (mxIsDoubleScalar(arg)) {
    rmsys->outdim  = (int)*mxGetPr(arg);
  }

  /* Output Ports */

  ssSetOutputPortWidth(S, 0, rmsys->outdim);  // data
  ssSetOutputPortWidth(S, 1, 1);              // receiver
  ssSetOutputPortWidth(S, 2, 1);              // length
  ssSetOutputPortWidth(S, 3, 1);              // prio
  ssSetOutputPortWidth(S, 4, 1);              // time stamp
  ssSetOutputPortWidth(S, 5, 1);              // signal power (wireless only)
  ssSetOutputPortWidth(S, 6, 1);              // message id

  ssSetNumContStates(S, 0);
  ssSetNumDiscStates(S, 0);
  
  ssSetNumSampleTimes(S, 1);
    
  ssSetNumRWork(S, 0);
  ssSetNumIWork(S, 0);
  ssSetNumPWork(S, 0); 
  ssSetNumModes(S, 0);
  ssSetNumNonsampledZCs(S, 0);

  ssSetUserData(S, rmsys);
  
  ssSetOptions(S, SS_OPTION_CALL_TERMINATE_ON_EXIT); 
}
Example #26
0
static void mdlInitializeSizes(SimStruct *S)
{
    int_T   status;                                 // for new type definition
    DTypeId COM_HANDLE_id;                          // for new type definition
    HANDLE  handle_aux;                             // for new type definition

//======================================================     new type definition

    COM_HANDLE_id = ssRegisterDataType(S, "COM_HANDLE");
    if(COM_HANDLE_id == INVALID_DTYPE_ID) return;
    status = ssSetDataTypeSize(S, COM_HANDLE_id, sizeof(handle_aux));
    if(status == 0) return;
    status = ssSetDataTypeZero(S, COM_HANDLE_id, &handle_aux);
    if(status == 0) return;

//===============================================================     parameters

    ssSetNumSFcnParams(S, 2);                           // 2 parameters:
                                                        //      - COM port
                                                        //      - baudrate
    //Parameter mismatch will be reported by Simulink
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S))
        return;

//===================================================================     inputs

   if (!ssSetNumInputPorts(S, 0)) return;               // 0 inputs

//==================================================================     outputs

    if (!ssSetNumOutputPorts(S, 1)) return;             // 1 outputs:
                                                        //      - COM handle

//////////////////////////////   com handle   //////////////////////////////
    ssSetOutputPortWidth(S,0,1);                        // input 1 width
    ssSetOutputPortDataType(S, 0, COM_HANDLE_id);       // input 1 datatype


//=============================================================     sample times

    ssSetNumSampleTimes(  S, 1);                // number of sample times

//=============================================================     work vectors

    ssSetNumRWork(S, 0);                        // 0 real work vector elements
    ssSetNumIWork(S, 0);                        // 0 work vector elements
    ssSetNumPWork(S, 1);                        // 1 pwork vector elements:
                                                //      - COM handle
    ssSetNumModes(S, 0);                        // 0  mode work vector elements
    ssSetNumNonsampledZCs(S, 0);                // 0  nonsampled zero crossings
    
}
Example #27
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
    ssSetNumSFcnParams(S, NPARAMS);  /* Number of expected parameters */
#if defined(MATLAB_MEX_FILE)
    if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
        mdlCheckParameters(S);
        if (ssGetErrorStatus(S) != NULL) {
            return;
        }
    } else {
        return; /* Parameter mismatch will be reported by Simulink */
    }
#endif

    {
        int iParam = 0;
        int nParam = ssGetNumSFcnParams(S);

        for ( iParam = 0; iParam < nParam; iParam++ )
        {
            ssSetSFcnParamTunable( S, iParam, SS_PRM_SIM_ONLY_TUNABLE );
        }
    }

    ssSetNumContStates(S, NSTATES);
    ssSetNumDiscStates(S, 0);

    if (!ssSetNumInputPorts(S, NINPUTS)) return;
    ssSetInputPortWidth(S, 0, 1);
    ssSetInputPortDirectFeedThrough(S, 0, TRUE);
    ssSetInputPortWidth(S, 1, 1);
    ssSetInputPortDirectFeedThrough(S, 1, TRUE);
    ssSetInputPortWidth(S, 2, 1);
    ssSetInputPortDirectFeedThrough(S, 2, TRUE);

    if (!ssSetNumOutputPorts(S, NOUTPUTS)) return;
    //ssSetOutputPortWidth(S, 0, NOUTPUTS);
    {
        ssSetOutputPortWidth(S, 0, 1);
    }
    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);
    ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
}
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
    /* See sfuntmpl_doc.c for more details on the macros below */

    ssSetNumSFcnParams(S, 1);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /* Return if number of expected != number of actual parameters */
        return;
    }

    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);

    if (!ssSetNumInputPorts(S, 3)) return;
    ssSetInputPortWidth(S, 0, 1);
    ssSetInputPortWidth(S, 1, 1);
    ssSetInputPortWidth(S, 2, 1);
    ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
    ssSetInputPortRequiredContiguous(S, 1, true); /*direct input signal access*/
    ssSetInputPortRequiredContiguous(S, 2, true); /*direct input signal access*/
    /*
     * Set direct feedthrough flag (1=yes, 0=no).
     * A port has direct feedthrough if the input is used in either
     * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
     * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
     */
    ssSetInputPortDirectFeedThrough(S, 0, 1);
    ssSetInputPortDirectFeedThrough(S, 1, 1);
    ssSetInputPortDirectFeedThrough(S, 2, 1);

    if (!ssSetNumOutputPorts(S, 5)) return;
    ssSetOutputPortWidth(S, 0, 1);
    ssSetOutputPortWidth(S, 1, 1);
    ssSetOutputPortWidth(S, 2, 1);
    ssSetOutputPortWidth(S, 3, 1);
    ssSetOutputPortWidth(S, 4, 1);
    
    

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Specify the sim state compliance to be same as a built-in block */
    ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

    ssSetOptions(S, 0);
}
Example #29
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{

    DECL_AND_INIT_DIMSINFO(inputDimsInfo);
    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);
     if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
	 return; /* Parameter mismatch will be reported by Simulink */
     }

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
    /*Input Port 0 */
    inputDimsInfo.width = INPUT_0_WIDTH;
    ssSetInputPortDimensionInfo(S,  0, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 0, INPUT_0_WIDTH, INPUT_DIMS_0_COL);
    ssSetInputPortFrameData(S,  0, IN_0_FRAME_BASED);

    ssSetInputPortDataType(S, 0, SS_SINGLE);
    ssSetInputPortComplexSignal(S,  0, INPUT_0_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/

    /*Input Port 1 */
    inputDimsInfo.width = INPUT_1_WIDTH;
    ssSetInputPortDimensionInfo(S,  1, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 1, INPUT_1_WIDTH, INPUT_DIMS_1_COL);
    ssSetInputPortFrameData(S,  1, IN_1_FRAME_BASED);

    ssSetInputPortDataType(S, 1, SS_INT32);
    ssSetInputPortComplexSignal(S,  1, INPUT_1_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 1, INPUT_1_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/


    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}
Example #30
0
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{
    slDataTypeAccess *dta = ssGetDataTypeAccess(S);
    int              udtId;

    ssSetNumSFcnParams(S, 0);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /* Return if number of expected != number of actual parameters */
        return;
    }

    /* Obtain an integer datatype ID for the udt (user-defined type) "Data" */
    udtId = ssRegisterDataType(S, "Data");
    if ( udtId == INVALID_DTYPE_ID ) return;

    /* Register the size of the udt */
    if (!ssSetDataTypeSize(S, udtId, sizeof(Data))) return;

    /* Register the zero of the udt */
    if (!ssSetDataTypeZero(S, udtId, &zero)) return;

    /* Set input-port properties */
    if (!ssSetNumInputPorts(S, 1)) return;
    ssSetInputPortWidth(S, 0, 1);
    ssSetInputPortDataType(S, 0, SS_DOUBLE);
    ssSetInputPortDirectFeedThrough(S, 0, 1);

    /* Set output port properties */
    if (!ssSetNumOutputPorts(S, 1)) return;
    ssSetOutputPortDataType(S, 0, udtId);
    ssSetOutputPortWidth(S, 0, 1);

    /* Set miscellaneous properties */
    ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);
    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

    /* specify the sim state compliance to be same as a built-in block */
    ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);

    ssSetOptions(S,
                 SS_OPTION_WORKS_WITH_CODE_REUSE);
}