int_T ZenomMatlab::Xrt_GetParameterInfo(void *rtw_mpi){ rtwCAPI_ModelMappingInfo* capiMap; const rtwCAPI_BlockParameters* blockParams; const rtwCAPI_DataTypeMap* dataTypeMap; const rtwCAPI_DimensionMap* dimMap; const rtwCAPI_FixPtMap* fxpMap; const uint_T* dimArray; void** dataAddrMap; void* paramAddress; uint_T paramIdx; capiMap= (rtwCAPI_ModelMappingInfo *)rtw_mpi; const char_T* paramName; const char_T* blockName; uint_T addrIdx; uint16_T dataTypeIdx; uint16_T dimIndex; uint16_T fxpMapIdx; uint8_T slDataID; const char_T* cDataName; unsigned short isComplex; uint8_T numDims; uint_T dimArrayIdx; rtwCAPI_Orientation orientation; uint_T actualDimensions[10]; uint_T numRows; uint_T numColumns; int idx; real_T slope = 1.0; real_T bias = 0.0; unsigned short modParamFlag = 0; uint_T rowIdx; uint_T colIdx; uint_T pageIdx; uint_T nBlockParams; nBlockParams=rtwCAPI_GetNumBlockParameters(capiMap); /******************** GET Model Name **************************/ for(paramIdx=0;paramIdx<nBlockParams;paramIdx++) strncpyz(xrtpi[paramIdx].modelName, STR(MODEL), MAX_NAMES_SIZE); /**************************************************************/ /* Assert the parameter index is less than total number of parameters */ for(paramIdx=0;paramIdx<nBlockParams;paramIdx++) assert(paramIdx < rtwCAPI_GetNumBlockParameters(capiMap)); /* Get blockParams, an array of rtwCAPI_ModelParameters structure */ blockParams = rtwCAPI_GetBlockParameters(capiMap); if (blockParams == NULL) exit(EXIT_FAILURE); /********************GET Block Name**********************************************************/ for(paramIdx=0;paramIdx<nBlockParams;paramIdx++) strncpyz(xrtpi[paramIdx].blockName,rtwCAPI_GetBlockParameterBlockPath(blockParams,paramIdx), MAX_NAMES_SIZE); /********************************************************************************************/ /***********************Get Parameters Names*****************************************************/ for(paramIdx=0;paramIdx<nBlockParams;paramIdx++) { strncpyz(xrtpi[paramIdx].paramName,rtwCAPI_GetBlockParameterName(blockParams, paramIdx), MAX_NAMES_SIZE); strncpyz(xrtpi[paramIdx].blockName,rtwCAPI_GetBlockParameterBlockPath(blockParams, paramIdx), MAX_NAMES_SIZE); } /**********************************************************************************************/ /* Get Data Type attributes of the Model Parameter */ /* Accessing the data type information from capiMap is a 3 step process * * 1) Get the dataTypeMap Array from capiMap. * * 2) Get the index into the above array, dataTypeIdx, from ModelParameter* * structure. The index will point to a rtwCAPI_DataTypeMap structure.* * 3) From the structure, get the member values of the structure, namely * * o Simulink Data ID, can be one of the enumerated value * * SS_DOUBLE, SS_SINGLE, SS_INT8, SS_UINT8, SS_INT16, SS_UINT16* * , SS_INT32, SS_UINT32, SS_BOOLEAN * * o Complexity * * o Data Size * * For complete structure see matlabroot/rtw/c/src/rtw_capi.h */ dataTypeMap = rtwCAPI_GetDataTypeMap(capiMap); if (dataTypeMap == NULL) exit(EXIT_FAILURE); for(paramIdx=0;paramIdx<nBlockParams;paramIdx++){ dataTypeIdx = rtwCAPI_GetBlockParameterDataTypeIdx(blockParams, paramIdx); slDataID = rtwCAPI_GetDataTypeSLId(dataTypeMap, dataTypeIdx); /*************GET DATA TYPEs*************************************************/ xrtpi[paramIdx].dataType=slDataID; /***************************************************************************/ cDataName = rtwCAPI_GetDataTypeCName(dataTypeMap,dataTypeIdx); xrtpi[paramIdx].isComplex = rtwCAPI_GetDataIsComplex(dataTypeMap,dataTypeIdx);} /* Get Dimensions of the Model Parameter */ /* Accessing the dimension from capiMap is a 4 step process * * 1) Get the dimMap array, an array of CAPI_DimensionMap struct * * 2) Get the dimArray array, an array of all the dimensions in the Map * * 3) Get the index into the dimMap array (dimIdx) from ModelParameter * * structure. the index will point to rtwCAPI_Dimension structure * * 4) From the rtwCAPI_Dimension structure, get the following information* * o orientation (scalar | vector | matrix) * * o Number of dimensions (numDims) * * o index into the dimArray (dimArrayIdx) * * 5) Using numDims and the dimArrayIdx, get the actual dimensions from * * the dimArray * * uint_T ActualDims[numDims] = {dimArray[dimArrayIdx], * * dimArray[dimArrayIdx+1], * * ... * * dimArray[dimArrayIdx+(numDims-1)]} * * For e.g, scalar and 2-D parameters will have numDims = 2, So * * uint_T ActualDims[2] = {dimArray[dimArrayIdx], * * dimArray[dimArrayIdx +1]} */ //uint8_T nDims = rtwCAPI_GetNumDims(dimMap, dimIdx); // uint_T dIndex = rtwCAPI_GetDimArrayIndex(dimMap, dimIdx); //uint_T addrIdx = rtwCAPI_GetSignalAddrIdx(bioSig,sigIdx);xrt_HostInterfaceTask // uint16_T dTypeIdx = rtwCAPI_GetSignalDataTypeIdx(bioSig,sigIdx); // uint16_T dimIdx = rtwCAPI_GetSignalDimensionIdx(bioSig,sigIdx); dimMap = rtwCAPI_GetDimensionMap(capiMap); dimArray = rtwCAPI_GetDimensionArray(capiMap); if ((dimMap == NULL) || (dimArray == NULL)) exit(EXIT_FAILURE); for(paramIdx=0;paramIdx<nBlockParams;paramIdx++) { dimIndex = rtwCAPI_GetBlockParameterDimensionIdx(blockParams, paramIdx); numDims = rtwCAPI_GetNumDims(dimMap, dimIndex); //actualDimensions=(uint_T *) calloc(numDims, sizeof(uint_T)); dimArrayIdx = rtwCAPI_GetDimArrayIndex(dimMap, dimIndex); orientation = rtwCAPI_GetOrientation(dimMap, dimIndex); /******************************* GET ORIENTATIONs******************************/ xrtpi[paramIdx].dataOrientation=orientation; for(idx=0; idx < numDims; idx++) { actualDimensions[idx] = dimArray[dimArrayIdx + idx]; //printf("actdim::%d\n",actualDimensions[idx]); } xrtpi[paramIdx].numRows=actualDimensions[0]; xrtpi[paramIdx].numColumns=actualDimensions[1]; //free(actualDimensions); //printf("orient::%d,%d\n",xrtpi[paramIdx].dataOrientation,paramIdx); // printf(" t param numRows,cols::%d %d\n",xrtpi[paramIdx].numRows,xrtpi[paramIdx].numColumns); } /*****************************************************************************/ /* Get fixed-point information of the parameter */ fxpMap = rtwCAPI_GetFixPtMap(capiMap); if (fxpMap == NULL) exit(EXIT_FAILURE); fxpMapIdx = rtwCAPI_GetBlockParameterFixPtIdx(blockParams, paramIdx); if(fxpMapIdx > 0) { /* Only Fixed-point parameters have fxpMapIdx > 0 */ real_T fracslope = rtwCAPI_GetFxpFracSlope(fxpMap,fxpMapIdx); int8_T expt = rtwCAPI_GetFxpExponent(fxpMap,fxpMapIdx); /* slope = fractional slope * 2^exponent * fractional slope is also called Slope Adjustment Factor. * Type "help fixdt" in MATLAB command window for more information * on fixed point data types */ slope = fracslope*pow(2.0,expt); bias = rtwCAPI_GetFxpBias(fxpMap,fxpMapIdx); } for(paramIdx=0;paramIdx<nBlockParams;paramIdx++) { /* Get the address to this paxeno_Starrameter */ dataAddrMap = rtwCAPI_GetDataAddressMap(capiMap); addrIdx = rtwCAPI_GetBlockParameterAddrIdx(blockParams,paramIdx); paramAddress= (void *) rtwCAPI_GetDataAddress(dataAddrMap,addrIdx); uint_T numPages = 0; if (numDims == 3) numPages = actualDimensions[2]; switch ( xrtpi[paramIdx].dataType) { RT_GET_PARAM_INFO_IF(SS_DOUBLE, real_T) RT_GET_PARAM_INFO_IF(SS_SINGLE, real32_T) RT_GET_PARAM_INFO_IF(SS_INT8, int8_T) RT_GET_PARAM_INFO_IF(SS_UINT8, uint8_T) RT_GET_PARAM_INFO_IF(SS_INT16, int16_T) RT_GET_PARAM_INFO_IF(SS_UINT16, uint16_T) RT_GET_PARAM_INFO_IF(SS_INT32, int32_T) RT_GET_PARAM_INFO_IF(SS_UINT32, uint32_T) RT_GET_PARAM_INFO_IF(SS_BOOLEAN, boolean_T) default: return -1; }//switch }//for //free(actualDimensions); return 0; }//END
/* Abstract: * This function takes in ModelMappingInfo structure prints the value of * ModelParameter - rtModelParameters[paramIdx] to STDOUT * capiMap - Pointer to the ModelMappingInfo structure in Real-Time model. * Map of all C-API arrays and structures. * paramIdx - Index of the Parameter in the rtModelParameters array * generated by RTW in <MODEL>_capi.c */ void capi_PrintModelParameter(rtwCAPI_ModelMappingInfo* capiMap, uint_T paramIdx) { const rtwCAPI_ModelParameters* modelParams; const rtwCAPI_DataTypeMap* dataTypeMap; const rtwCAPI_DimensionMap* dimMap; const rtwCAPI_FixPtMap* fxpMap; const uint_T* dimArray; void** dataAddrMap; const char_T* paramName; uint_T addrIdx; uint16_T dataTypeIdx; uint16_T dimIndex; uint16_T fxpMapIdx; uint8_T slDataID; void* paramAddress; const char_T* cDataName; unsigned short isComplex; uint8_T numDims; uint_T dimArrayIdx; rtwCAPI_Orientation orientation; uint_T* actualDimensions; int idx; real_T slope = 1.0; real_T bias = 0.0; unsigned short modParamFlag = 0; /* Assert the parameter index is less than total number of parameters */ assert(paramIdx < rtwCAPI_GetNumModelParameters(capiMap)); /* Get modelParams, an array of rtwCAPI_ModelParameters structure */ modelParams = rtwCAPI_GetModelParameters(capiMap); if (modelParams == NULL) return; /* Get Parameter Name */ paramName = rtwCAPI_GetModelParameterName(modelParams, paramIdx); /* Get Data Type attributes of the Model Parameter */ /* Accessing the data type information from capiMap is a 3 step process * * 1) Get the dataTypeMap Array from capiMap. * * 2) Get the index into the above array, dataTypeIdx, from ModelParameter* * structure. The index will point to a rtwCAPI_DataTypeMap structure.* * 3) From the structure, get the member values of the structure, namely * * o Simulink Data ID, can be one of the enumerated value * * SS_DOUBLE, SS_SINGLE, SS_INT8, SS_UINT8, SS_INT16, SS_UINT16* * , SS_INT32, SS_UINT32, SS_BOOLEAN * * o Complexity * * o Data Size * * For complete structure see matlabroot/rtw/c/src/rtw_capi.h */ dataTypeMap = rtwCAPI_GetDataTypeMap(capiMap); if (dataTypeMap == NULL) return; dataTypeIdx = rtwCAPI_GetModelParameterDataTypeIdx(modelParams, paramIdx); slDataID = rtwCAPI_GetDataTypeSLId(dataTypeMap, dataTypeIdx); cDataName = rtwCAPI_GetDataTypeCName(dataTypeMap,dataTypeIdx); isComplex = rtwCAPI_GetDataIsComplex(dataTypeMap,dataTypeIdx); /* Get Dimensions of the Model Parameter */ /* Accessing the dimension from capiMap is a 4 step process * * 1) Get the dimMap array, an array of CAPI_DimensionMap struct * * 2) Get the dimArray array, an array of all the dimensions in the Map * * 3) Get the index into the dimMap array (dimIdx) from ModelParameter * * structure. the index will point to rtwCAPI_Dimension structure * * 4) From the rtwCAPI_Dimension structure, get the following information* * o orientation (scalar | vector | matrix) * * o Number of dimensions (numDims) * * o index into the dimArray (dimArrayIdx) * * 5) Using numDims and the dimArrayIdx, get the actual dimensions from * * the dimArray * * uint_T ActualDims[numDims] = {dimArray[dimArrayIdx], * * dimArray[dimArrayIdx+1], * * ... * * dimArray[dimArrayIdx+(numDims-1)]} * * For e.g, scalar and 2-D parameters will have numDims = 2, So * * uint_T ActualDims[2] = {dimArray[dimArrayIdx], * * dimArray[dimArrayIdx +1]} */ dimMap = rtwCAPI_GetDimensionMap(capiMap); dimArray = rtwCAPI_GetDimensionArray(capiMap); if ((dimMap == NULL) || (dimArray == NULL)) return; dimIndex = rtwCAPI_GetModelParameterDimensionIdx(modelParams, paramIdx); numDims = rtwCAPI_GetNumDims(dimMap, dimIndex); dimArrayIdx = rtwCAPI_GetDimArrayIndex(dimMap, dimIndex); orientation = rtwCAPI_GetOrientation(dimMap, dimIndex); actualDimensions = (uint_T *) malloc(numDims*sizeof(uint_T)); for(idx=0; idx < numDims; idx++) { actualDimensions[idx] = dimArray[dimArrayIdx + idx]; } /* Get fixed-point information of the parameter */ fxpMap = rtwCAPI_GetFixPtMap(capiMap); if (fxpMap == NULL) return; fxpMapIdx = rtwCAPI_GetModelParameterFixPtIdx(modelParams, paramIdx); if(fxpMapIdx > 0) { /* Only Fixed-point parameters have fxpMapIdx > 0 */ real_T fracslope = rtwCAPI_GetFxpFracSlope(fxpMap,fxpMapIdx); int8_T expt = rtwCAPI_GetFxpExponent(fxpMap,fxpMapIdx); /* slope = fractional slope * 2^exponent * fractional slope is also called Slope Adjustment Factor. * Type "help fixdt" in MATLAB command window for more information * on fixed point data types */ slope = fracslope*pow(2.0,expt); bias = rtwCAPI_GetFxpBias(fxpMap,fxpMapIdx); } /* Get the address to this parameter */ dataAddrMap = rtwCAPI_GetDataAddressMap(capiMap); addrIdx = rtwCAPI_GetModelParameterAddrIdx(modelParams,paramIdx); paramAddress= (void *) rtwCAPI_GetDataAddress(dataAddrMap,addrIdx); if (paramAddress == NULL) return; /* Print the parameter value */ capi_PrintParameter(paramName, paramAddress, slDataID, isComplex, actualDimensions, numDims, slope, bias); /* Modify parameter with itself */ /* modParamflag is used as a flag to indicate whether you want to modify * the parameter after you print the value. Set flag to 1 to modify */ if(modParamFlag && capi_ModifyParameter(paramAddress, paramAddress, orientation, actualDimensions, numDims, slDataID, isComplex)) { printf("Parameter modified with itself\n"); } free(actualDimensions); return; }