/* Function: mdlCheckParameters ============================================= * Abstract: * Validate our parameters to verify they are okay. */ static void mdlCheckParameters(SimStruct *S) { unsigned int i; if ( !mxIsChar(paramHostName) || (mxGetNumberOfElements(paramHostName) < 1) || (mxGetNumberOfElements(paramHostName) > 100) ) { ssSetErrorStatus(S, "The Host Name parameter must be a nonempty string with max. 100 elements."); return; } if ( (!IS_PARAM_DOUBLE(paramImageSizeXYN)) || (mxGetNumberOfElements(paramImageSizeXYN) < 2) || (mxGetNumberOfElements(paramImageSizeXYN) > 3) ) { ssSetErrorStatus(S, "The image size must have two elements [X Y] or three elements [X Y frames]."); return; } else { for( i=0; i<mxGetNumberOfElements(paramImageSizeXYN); i++ ) { if( intval(mxGetPr(paramImageSizeXYN)[i]) <= 0 ) { ssSetErrorStatus(S, "The image dimensions have to be positive integers."); return; } } } if ( (!IS_PARAM_DOUBLE(paramPixelFormat)) || (mxGetNumberOfElements(paramPixelFormat) != 1) ) { ssSetErrorStatus(S, "Pixel format must be a scalar"); return; } else if (intval(mxGetPr(paramPixelFormat)[0]) != 1 && intval(mxGetPr(paramPixelFormat)[0]) != 5) { ssSetErrorStatus(S, "Pixel format must be Mono8(1) or Rgb24(5)"); return; } if ( (!IS_PARAM_DOUBLE(paramTimeout)) || (mxGetNumberOfElements(paramTimeout) != 1) ) { ssSetErrorStatus(S, "Timeout must be a scalar"); return; } else if (mxGetPr(paramTimeout)[0] < 0) { ssSetErrorStatus(S, "Timeout must be non-negative"); return; } if ( (!IS_PARAM_DOUBLE(paramSampleTime)) || (mxGetNumberOfElements(paramSampleTime) != 1) ) { ssSetErrorStatus(S, "Wrong sample time."); return; } if ( !((mxGetPr(paramSampleTime)[0] == -1) || (mxGetPr(paramSampleTime)[0] > 0)) ) { ssSetErrorStatus(S, "The sample time must be inherited (-1) or discrete (a positive number)."); return; } }
/* Function: mdlCheckParameters ============================================= * Abstract: * Validate our parameters to verify they are okay. */ static void mdlCheckParameters(SimStruct *S) { int paramIndex = 0; bool validParam = false; /* All parameters must match the S-function Builder Dialog */ { const mxArray *pVal0 = ssGetSFcnParam(S,0); if (!IS_PARAM_DOUBLE(pVal0)) { validParam = true; paramIndex = 0; goto EXIT_POINT; } } { const mxArray *pVal1 = ssGetSFcnParam(S,1); if (!IS_PARAM_DOUBLE(pVal1)) { validParam = true; paramIndex = 1; goto EXIT_POINT; } } { const mxArray *pVal2 = ssGetSFcnParam(S,2); if (!IS_PARAM_DOUBLE(pVal2)) { validParam = true; paramIndex = 2; goto EXIT_POINT; } } { const mxArray *pVal3 = ssGetSFcnParam(S,3); if (!IS_PARAM_DOUBLE(pVal3)) { validParam = true; paramIndex = 3; goto EXIT_POINT; } } EXIT_POINT: if (validParam) { char parameterErrorMsg[1024]; sprintf(parameterErrorMsg, "The data type and or complexity of parameter %d does not match the " "information specified in the S-function Builder dialog. " "For non-double parameters you will need to cast them using int8, int16, " "int32, uint8, uint16, uint32 or boolean.", paramIndex + 1); ssSetErrorStatus(S,parameterErrorMsg); } return; }
/* Function: mdlCheckParameters ============================================= * Abstract: * Validate our parameters to verify they are okay. */ static void mdlCheckParameters(SimStruct *S) { /* Check 1st parameter: A-Matrix */ { if ( mxGetN(A_PARAM(S)) != NSTATES || !IS_PARAM_DOUBLE(A_PARAM(S)) ) { ssSetErrorStatus(S,"1st parameter to S-function " "\"A-Matrix\" must be square and double"); return; } } /* Check 2nd parameter: B-Matrix */ { if (mxGetM(B_PARAM(S)) != NSTATES || !IS_PARAM_DOUBLE(B_PARAM(S)) ) { ssSetErrorStatus(S,"2nd parameter to S-function " "\"B-Matrix\" is not dimensioned " "correctly"); return; } } /* Check 3rd parameter: C-Matrix */ { if (mxGetN(C_PARAM(S)) != NSTATES || !IS_PARAM_DOUBLE(C_PARAM(S)) ) { ssSetErrorStatus(S,"3rd parameter to S-function " "\"C-Matrix\" is not dimensioned " "correctly"); return; } } /* Check 4th parameter: D-Matrix */ { if (mxGetM(D_PARAM(S)) != NOUTPUTS || mxGetN(D_PARAM(S)) != NINPUTS || !IS_PARAM_DOUBLE(D_PARAM(S)) ) { ssSetErrorStatus(S,"4th parameter to S-function " "\"D-Matrix\" is not dimensioned " "correctly"); return; } } /* Check 5th parameter: X0 */ { if ( ((mxGetM(X0_PARAM(S)) != 0) && (mxGetM(X0_PARAM(S)) != NSTATES)) || !OK_EMPTY_DOUBLE_PARAM(X0_PARAM(S)) ) { ssSetErrorStatus(S,"5th parameter to S-function " "\"X0-Matrix\" is not dimensioned " "correctly"); return; } } }
/* Function: mdlCheckParameters ============================================= * Abstract: * Validate our parameters to verify they are okay. */ static void mdlCheckParameters(SimStruct *S) { #define PrmNumPos 46 int paramIndex = 0; bool validParam = false; char paramVector[] ={'1'}; static char parameterErrorMsg[] ="The data type and/or complexity of parameter does not match the information " "specified in the S-function Builder dialog. For non-double parameters you will need to cast them using int8, int16," "int32, uint8, uint16, uint32 or boolean."; /* All parameters must match the S-function Builder Dialog */ { const mxArray *pVal0 = ssGetSFcnParam(S,0); if (!IS_PARAM_DOUBLE(pVal0)) { validParam = true; paramIndex = 0; goto EXIT_POINT; } } EXIT_POINT: if (validParam) { parameterErrorMsg[PrmNumPos] = paramVector[paramIndex]; ssSetErrorStatus(S,parameterErrorMsg); } return; }
/* Function: mdlCheckParameters ============================================= * Abstract: * Validate our parameters to verify they are okay. */ static void mdlCheckParameters(SimStruct *S) { /* Check 1st parameter: MAGICNUM-Matrix */ { if ( mxGetNumberOfElements(MAGICNUM_PARAM(S)) != NMAGICNUM || !IS_PARAM_DOUBLE(MAGICNUM_PARAM(S)) ) { ssSetErrorStatus(S,"1st parameter to S-function " "\"A-Matrix\" must be square and double"); return; } } /* Check 2nd parameter: X0 */ { if ( ((mxGetNumberOfElements(X0_PARAM(S)) != 0) && (mxGetNumberOfElements(X0_PARAM(S)) != NSTATES)) || !OK_EMPTY_DOUBLE_PARAM(X0_PARAM(S)) ) { ssSetErrorStatus(S,"2nd parameter to S-function " "\"X0-Matrix\" is not dimensioned " "correctly"); return; } } }
/* Function: mdlCheckParameters ============================================= * Abstract: * Validate our parameters to verify they are okay. */ static void mdlCheckParameters(SimStruct *S) { int_T param; for( param=0; param<NPARAMS; param++ ) { if ( (param != 11) && (param != 12) ) if ( !IS_PARAM_DOUBLE(ssGetSFcnParam(S, param)) && (mxGetNumberOfElements(ssGetSFcnParam(S, param)) < 1) ) { ssSetErrorStatus(S, "Parameter is not a double."); return; } } if( (mxGetNumberOfElements(paramQuaternionIndex) != 0) && (mxGetNumberOfElements(paramQuaternionIndex) != 2) ) { ssSetErrorStatus(S, "The quaternion index must be defined by two numbers."); return; } if( mxGetNumberOfElements(paramQuaternionIndex) == 2 ) { if( !IS_PARAM_DOUBLE(paramQuaternionIndex) ) { ssSetErrorStatus(S, "The quaternion index must be defined by of type double."); return; } if( (intval(mxGetPr(paramQuaternionIndex)[0]) < 1) || (intval(mxGetPr(paramQuaternionIndex)[0]) > intval(mxGetPr(paramQuaternionIndex)[1])) ) { ssSetErrorStatus(S, "The quaternion index interval is not defined properly."); return; } param = intval(mxGetPr(paramQuaternionIndex)[1]) - intval(mxGetPr(paramQuaternionIndex)[0]) + 1; if( param != (param/4)*4 ) { ssSetErrorStatus(S, "The quaternion index interval must have a length multiple of 4."); return; } } if( (mxGetNumberOfElements(paramOmegaDotIndex) != 0) && (mxGetNumberOfElements(paramOmegaDotIndex) != 2) ) { ssSetErrorStatus(S, "The omega_dot index must be defined by two numbers."); return; } if( mxGetNumberOfElements(paramOmegaDotIndex) == 2 ) { if( !IS_PARAM_DOUBLE(paramOmegaDotIndex) ) { ssSetErrorStatus(S, "The omega_dot index must be defined by of type double."); return; } if( (intval(mxGetPr(paramOmegaDotIndex)[0]) < 1) || (intval(mxGetPr(paramOmegaDotIndex)[0]) > intval(mxGetPr(paramOmegaDotIndex)[1])) ) { ssSetErrorStatus(S, "The omega_dot index interval is not defined properly."); return; } param = intval(mxGetPr(paramOmegaDotIndex)[1]) - intval(mxGetPr(paramOmegaDotIndex)[0]) + 1; if( param != (param/3)*3 ) { ssSetErrorStatus(S, "The omega_dot index interval must have a length multiple of 3."); return; } } if ( !((mxGetPr(paramSampleTime)[0] == -1) || (mxGetPr(paramSampleTime)[0] > 0)) ) { ssSetErrorStatus(S, "The sample time must be inherited (-1) or discrete (a positive number)."); return; } }