int_T rtwCAPI_GetStateWidth(const rtwCAPI_DimensionMap* dimMap, const uint_T* dimArray, const rtwCAPI_States* states, int_T iState) { int_T mapIdx = rtwCAPI_GetStateDimensionIdx(states, iState); utAssert( rtwCAPI_GetNumDims(dimMap,mapIdx) == 2 ); mapIdx = rtwCAPI_GetDimArrayIndex(dimMap, mapIdx); return (dimArray[mapIdx] * dimArray[mapIdx+1]); }
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
int ZenomMatlab::Xrt_GetSignalInfo(rtwCAPI_ModelMappingInfo* mmi){ const rtwCAPI_Signals* signals; const rtwCAPI_DataTypeMap* dataTypeMap; const rtwCAPI_DimensionMap* dimMap; const uint_T* dimArray; void** dataAddrMap; void* paramAddress; uint_T sigIdx; uint_T nSignals; uint_T addrIdx; uint16_T dataTypeIdx; uint16_T dimIndex; uint16_T fxpMapIdx; uint8_T slDataID; unsigned short isComplex; uint8_T numDims; uint_T dimArrayIdx; rtwCAPI_Orientation orientation; uint_T actualDimensions[10]; uint_T numRows; uint_T numColumns; uint_T rowIdx; uint_T colIdx; const char_T* SigName; const char_T* blockName; const char_T* cDataName; nSignals = rtwCAPI_GetNumSignals(mmi); signals = rtwCAPI_GetSignals(mmi); dataTypeMap = rtwCAPI_GetDataTypeMap(mmi); for(sigIdx=0; sigIdx < nSignals; sigIdx++){ strncpyz(xtsi[sigIdx].blockName, rtwCAPI_GetSignalBlockPath(signals,sigIdx), MAX_NAMES_SIZE); strncpyz(xtsi[sigIdx].signalName, rtwCAPI_GetSignalName(signals,sigIdx), MAX_NAMES_SIZE); dataTypeIdx = rtwCAPI_GetSignalDataTypeIdx(signals, sigIdx); slDataID = rtwCAPI_GetDataTypeSLId(dataTypeMap, dataTypeIdx); xtsi[sigIdx].dataType = slDataID; cDataName = rtwCAPI_GetDataTypeCName(dataTypeMap, dataTypeIdx); xtsi[sigIdx].isComplex = rtwCAPI_GetDataIsComplex(dataTypeMap,dataTypeIdx); } //Get Dimension dimMap = rtwCAPI_GetDimensionMap(mmi); dimArray = rtwCAPI_GetDimensionArray(mmi); if ((dimMap == NULL) || (dimArray == NULL)) exit(EXIT_FAILURE); for(sigIdx=0; sigIdx < nSignals; sigIdx++){ dimIndex = rtwCAPI_GetBlockParameterDimensionIdx(signals, sigIdx); numDims = rtwCAPI_GetNumDims(dimMap, dimIndex); dimArrayIdx = rtwCAPI_GetDimArrayIndex(dimMap, dimIndex); orientation = rtwCAPI_GetOrientation(dimMap, dimIndex); xtsi[sigIdx].dataOrientation = orientation; for(int idx=0; idx < numDims; idx++) { actualDimensions[idx] = dimArray[dimArrayIdx + idx]; } xtsi[sigIdx].numRows = actualDimensions[0]; xtsi[sigIdx].numColumns = actualDimensions[1]; } for(sigIdx=0; sigIdx < nSignals; sigIdx++){ dataAddrMap = rtwCAPI_GetDataAddressMap(mmi); addrIdx = rtwCAPI_GetBlockParameterAddrIdx(signals, sigIdx); paramAddress= (void *) rtwCAPI_GetDataAddress(dataAddrMap, addrIdx); uint_T numPages = 0; if (numDims == 3) numPages = actualDimensions[2]; switch ( xtsi[sigIdx].dataType) { RT_GET_SIG_INFO_IF(SS_DOUBLE, real_T) RT_GET_SIG_INFO_IF(SS_SINGLE, real32_T) RT_GET_SIG_INFO_IF(SS_INT8, int8_T) RT_GET_SIG_INFO_IF(SS_UINT8, uint8_T) RT_GET_SIG_INFO_IF(SS_INT16, int16_T) RT_GET_SIG_INFO_IF(SS_UINT16, uint16_T) RT_GET_SIG_INFO_IF(SS_INT32, int32_T) RT_GET_SIG_INFO_IF(SS_UINT32, uint32_T) RT_GET_SIG_INFO_IF(SS_BOOLEAN, boolean_T) default: {return -1;} }//switch } return 0; }
/* 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; }
/* Abstract: * This function takes in ModelMappingInfo structure modifies the value of * ModelParameter - rtModelParameters[paramIdx] with the newValue. * 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 * newParam - Pointer tot he new value of the parameter */ int_T capi_ModifyModelParameter(rtwCAPI_ModelMappingInfo* capiMap, uint_T paramIdx, void* newParam) { const rtwCAPI_ModelParameters* modelParams; const rtwCAPI_DataTypeMap* dataTypeMap; const rtwCAPI_DimensionMap* dimMap; const uint_T* dimArray; void** dataAddrMap; uint_T addrIdx; uint16_T dataTypeIdx; uint16_T dimIndex; uint8_T slDataID; void* paramAddress; unsigned short isComplex; uint8_T numDims; uint_T dimArrayIdx; rtwCAPI_Orientation orientation; uint_T* actualDimensions; int idx; int_T retVal = 0; /* Get modelParams, an array of rtwCAPI_ModelParameters structure */ modelParams = rtwCAPI_GetModelParameters(capiMap); if (modelParams == NULL) return 0; /* Assert the parameter index is less than total number of parameters */ assert(paramIdx < rtwCAPI_GetNumModelParameters(capiMap)); /* Accessing the data type information from capiMap */ dataTypeMap = rtwCAPI_GetDataTypeMap(capiMap); if (dataTypeMap == NULL) return 0; dataTypeIdx = rtwCAPI_GetModelParameterDataTypeIdx(modelParams, paramIdx); slDataID = rtwCAPI_GetDataTypeSLId(dataTypeMap, dataTypeIdx); isComplex = rtwCAPI_GetDataIsComplex(dataTypeMap, dataTypeIdx); /* Get Dimensions of the Model Parameter */ dimMap = rtwCAPI_GetDimensionMap(capiMap); dimArray = rtwCAPI_GetDimensionArray(capiMap); if ((dimMap == NULL) || (dimArray == NULL)) return 0; dimIndex = rtwCAPI_GetModelParameterDimensionIdx(modelParams, paramIdx); orientation = rtwCAPI_GetOrientation(dimMap, dimIndex); numDims = rtwCAPI_GetNumDims(dimMap, dimIndex); dimArrayIdx = rtwCAPI_GetDimArrayIndex(dimMap, dimIndex); actualDimensions = (uint_T *) malloc(numDims*sizeof(uint_T)); for(idx=0; idx < numDims; idx++) { actualDimensions[idx] = dimArray[dimArrayIdx + idx]; } /* 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 0; retVal = capi_ModifyParameter(paramAddress, newParam, orientation, actualDimensions, numDims, slDataID, isComplex); free(actualDimensions); return retVal; }
/** Function: rtwCAPI_GetSigLogRecordInfo ====================================== * */ const char_T* rtwCAPI_GetSigLogRecordInfo(const rtwCAPI_ModelMappingInfo* mmi, const char_T** sigBlockName, const char_T** sigLabel, int_T* sigWidth, int_T* sigDataType, int_T* logDataType, int_T* sigComplexity, void** sigDataAddr, boolean_T* sigCrossMdlRef, int_T* sigIdx, boolean_T crossingModel, boolean_T rtwLogging) { int_T i; int_T nCMMI; int_T nSignals; const char_T* mmiPath; size_t mmiPathLen; const rtwCAPI_Signals* signals; const rtwCAPI_DimensionMap* dimMap; const uint_T* dimArray; const rtwCAPI_DataTypeMap* dataTypeMap; void** dataAddrMap; const char_T* errstr = NULL; uint8_T isPointer = 0; char* blockPath = NULL; if (mmi == NULL) goto EXIT_POINT; nCMMI = rtwCAPI_GetChildMMIArrayLen(mmi); for (i = 0; i < nCMMI; ++i) { rtwCAPI_ModelMappingInfo* cMMI = rtwCAPI_GetChildMMI(mmi,i); errstr = rtwCAPI_GetSigLogRecordInfo(cMMI, sigBlockName, sigLabel, sigWidth, sigDataType, logDataType, sigComplexity, sigDataAddr, sigCrossMdlRef, sigIdx, true, rtwLogging); if (errstr != NULL) goto EXIT_POINT; } nSignals = rtwCAPI_GetNumSignals(mmi); if (nSignals < 1) goto EXIT_POINT; mmiPath = rtwCAPI_GetFullPath(mmi); mmiPathLen = (mmiPath==NULL)? 0 : strlen(mmiPath); signals = rtwCAPI_GetSignals(mmi); dimMap = rtwCAPI_GetDimensionMap(mmi); dimArray = rtwCAPI_GetDimensionArray(mmi); dataTypeMap = rtwCAPI_GetDataTypeMap(mmi); dataAddrMap = rtwCAPI_GetDataAddressMap(mmi); for (i = 0; i < nSignals; ++i) { uint_T mapIdx; size_t sigPathLen; char* sigPath; /* For RTW logging, skip states that cannot be logged to MAT-File. */ if ((rtwLogging) && (rtwCAPI_CanLogSignalToMATFile(dataTypeMap, signals, i) == false)) continue; /* sigBlockPath = mmiPath + | + BlockPath + '\0' */ /* If crossing a model boundary encode, otherwise do not */ if (crossingModel) { blockPath = rtwCAPI_EncodePath(rtwCAPI_GetSignalBlockPath(signals, i)); if ( (blockPath == NULL) && (rtwCAPI_GetSignalBlockPath(signals, i) != NULL)) { errstr = rtwCAPI_mallocError; goto EXIT_POINT; } } else { const char* constBlockPath = rtwCAPI_GetSignalBlockPath(signals, i); blockPath = (char*)utMalloc((strlen(constBlockPath)+1)*sizeof(char)); (void)strcpy(blockPath, constBlockPath); } utAssert(blockPath != NULL); sigPathLen = ( (mmiPath==NULL) ? strlen(blockPath) + 1 : mmiPathLen + strlen(blockPath) + 2 ); sigPath = (char*)utMalloc(sigPathLen*sizeof(char)); if (sigPath == NULL) { errstr = rtwCAPI_mallocError; goto EXIT_POINT; } if (mmiPath != NULL) { (void)strcpy(sigPath, mmiPath); sigPath[mmiPathLen] = '|'; sigPath[mmiPathLen+1] = '\0'; (void)strcat(sigPath, blockPath); } else { (void)strcpy(sigPath, blockPath); sigPath[sigPathLen-1] = '\0'; } /* need to free for every iteration of the loop, but also have * the free below EXIT_POINT in case of error */ utFree(blockPath); blockPath = NULL; utAssert(sigPath[sigPathLen-1] == '\0'); sigBlockName[*sigIdx] = sigPath; /* caller is responsible for free */ /* Label */ sigLabel[*sigIdx] = rtwCAPI_GetSignalName(signals, i); /* Width */ mapIdx = rtwCAPI_GetSignalDimensionIdx(signals, i); utAssert( rtwCAPI_GetNumDims(dimMap,mapIdx) == 2 ); mapIdx = rtwCAPI_GetDimArrayIndex(dimMap, mapIdx); sigWidth[*sigIdx] = dimArray[mapIdx] * dimArray[mapIdx+1]; /* DataType and logDataType */ mapIdx = rtwCAPI_GetSignalDataTypeIdx(signals, i); sigDataType[*sigIdx] = rtwCAPI_GetDataTypeSLId(dataTypeMap, mapIdx); /* this mimics code in simulink.dll:mapSigDataTypeToLogDataType */ if ( SS_DOUBLE || SS_SINGLE || SS_INT8 || SS_UINT8 || SS_INT16 || SS_UINT16 || SS_INT32 || SS_UINT32 || SS_BOOLEAN ) { logDataType[*sigIdx] = sigDataType[*sigIdx]; } else { logDataType[*sigIdx] = SS_DOUBLE; } /* Complexity */ sigComplexity[*sigIdx] = rtwCAPI_GetDataIsComplex(dataTypeMap, mapIdx); /* Data Access - Pointer or Direct*/ isPointer = ((uint8_T)rtwCAPI_GetDataIsPointer(dataTypeMap, mapIdx)); /* Address */ mapIdx = rtwCAPI_GetSignalAddrIdx(signals, i); rtwCAPI_GetSigAddrFromMap(isPointer, sigComplexity, sigDataType, sigDataAddr, sigIdx, mapIdx, dataAddrMap); /* CrossingModelBoundary */ sigCrossMdlRef[*sigIdx] = crossingModel; ++(*sigIdx); } EXIT_POINT: utFree(blockPath); return(errstr); } /* rtwCAPI_GetSigLogRecordInfo */