Files
sil/SIL/otherFiles/find_param_val_wrapper.c
T
2020-10-22 10:50:04 +08:00

232 lines
6.0 KiB
C

/*
* Include Files
*
*/
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef WITH_CAPI
#include "builtin_typeid_types.h"
#include "param_pre.h"
#include "param_mgr.h"
#include <stdio.h>
#else
#include <string.h>
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1
#define y_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef WITH_CAPI
void scan_params(void)
{
const rtwCAPI_ModelMappingStaticInfo* sm;
unsigned int m;
rtwCAPI_ModelParameters const *prm;
rtwCAPI_DataTypeMap const *dtm;
rtwCAPI_DimensionMap const *dmm;
uint_T const *dam;
rtwCAPI_ModelMappingInfo *MMI;
void** da;
unsigned int i;
const char * name;
int idx;
uint16_t dti;
uint16_t dmi;
uint8_t ss;
uint_T dai;
uint8_t nd;
uint_T n;
uint16_t j;
size_t s1,s2;
int k;
char idx_buff[8];
param_prop prop;
static int is_init=0;
if (is_init)
{
return;
}
is_init = 1;
sm = ap_GetCAPIStaticMap_fcn();
if (sm)
{
prop.getter_ptr = NULL;
prop.setter_ptr = NULL;
//n = rtwCAPI_GetNumBlockParametersFromStaticMap(sm);
m = rtwCAPI_GetNumModelParametersFromStaticMap(sm);
prm = rtwCAPI_GetModelParametersFromStaticMap(sm);
dtm = rtwCAPI_GetDataTypeMapFromStaticMap(sm);
dmm = rtwCAPI_GetDimensionMapFromStaticMap(sm);
dam = rtwCAPI_GetDimensionArrayFromStaticMap(sm);
MMI = &(rtmGetDataMapInfo(ap_M_ptr).mmi);
da = rtwCAPI_GetDataAddressMap(MMI);
for (i = 0;i<m; ++i)
{
name = rtwCAPI_GetModelParameterName(prm, i);
idx = rtwCAPI_GetModelParameterAddrIdx(prm, i);
dti = rtwCAPI_GetModelParameterDataTypeIdx(prm, i);
dmi = rtwCAPI_GetModelParameterDimensionIdx(prm, i);
ss = rtwCAPI_GetDataTypeSLId(dtm, dti);
dai = rtwCAPI_GetDimArrayIndex(dmm, dmi);
nd = rtwCAPI_GetNumDims(dmm, dmi);
n = 1;
for (j=0u;j<nd;++j)
{
n *= dam[dai+j];
}
for (j=0;j<n;++j)
{
switch (ss)
{
case SS_DOUBLE:
{
prop.val_ptr.d = &((double *)da[idx])[j];
prop.typ = PARAM_TYPE_REAL64;
}
break;
case SS_INT8:
case SS_BOOLEAN:
{
prop.val_ptr.b = &((int8_t *)da[idx])[j];
prop.typ = PARAM_TYPE_INT8;
}
break;
case SS_INT16:
{
prop.val_ptr.h = &((int16_t *)da[idx])[j];
prop.typ = PARAM_TYPE_INT16;
}
break;
case SS_INT32:
{
prop.val_ptr.i = &((int32_t *)da[idx])[j];
prop.typ = PARAM_TYPE_INT32;
}
break;
case SS_UINT8:
{
prop.val_ptr.B = &((uint8_t *)da[idx])[j];
prop.typ = PARAM_TYPE_UINT8;
}
break;
case SS_UINT16:
{
prop.val_ptr.H = &((uint16_t *)da[idx])[j];
prop.typ = PARAM_TYPE_UINT16;
}
break;
case SS_UINT32:
{
prop.val_ptr.I = &((uint32_t *)da[idx])[j];
prop.typ = PARAM_TYPE_UINT32;
}
break;
default:
{
prop.val_ptr.s = &((float *)da[idx])[j];
prop.typ = PARAM_TYPE_REAL32;
}
break;
}
strncpy(prop.name, name, 16);
if (j > 0)
{
sprintf(idx_buff, "(%d)", j);
s2 = strlen(idx_buff);
s1 = strlen(prop.name);
if (s1+s2 >= 16)
{
for (k=0;k<s2;++k)
{
prop.name[16-s2+k] = idx_buff[k];
}
}
else
{
for (k=0;k<s2;++k)
{
prop.name[s1+k] = idx_buff[k];
}
prop.name[s1+k] = '\0';
}
}
if (prop.typ != PARAM_TYPE_REAL64)
param_mgr_regist(&prop);
}
}
}
}
#endif
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Start function
*
*/
void find_param_val_Start_wrapper(void)
{
/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef WITH_CAPI
scan_params();
#endif
/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Output function
*
*/
void find_param_val_Outputs_wrapper(const uint16_T *idx,
uint8_T *name,
uint8_T *value,
uint8_T *type,
uint16_T *count,
uint16_T *index)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef WITH_CAPI
count[0] = param_get_count();
index[0] = idx[0];
param_prop * p = param_get_by_idx(idx[0]);
if (p)
{
strncpy(name, p->name, 16);
type[0] = p->typ;
param_get_value(p, value);
}
else
{
strcpy((char *)name, "outrange");
float val = 0.0;
memcpy(value, &val, 4);
type[0] = 9u;
}
#else
strcpy((char *)name, "unkown");
float val = 0.0;
memcpy(value, &val, 4);
type[0] = 9u;
count[0] = 1;
index[0] = 0u;
#endif
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}