一、新建枚举类型
形如:
// An highlighted block
typedef enum
{
NM_AllCh = 0, /* Default value */
NM_LinCh,
NM_VehicleCanCh,
NM_InternalCanCh,
NM_ChMax
}
NetWokM_Type;
在matlab中新建的方法:
脚本新建法:
新建脚本
键入如下代码:
classdef NetWokM_Type < Simulink.IntEnumType
enumeration
NM_AllCh (0)
NM_LinCh (1)
NM_VehicleCanCh (2)
NM_InternalCanCh (3)
NM_ChMax (4)
end
end
并将脚本名称改为NetWokM_Type,放在工程目录下。
二、模型示例
三、生成的代码示例
typedef enum {
NM_AllCh = 0, /* Default value */
NM_LinCh,
NM_VehicleCanCh,
NM_InternalCanCh,
NM_ChMax
} NetWokM_Type;
/* Forward declaration for local functions */
static int32_T untit_safe_cast_to_NetWokM_Type(int32_T input);
static int32_T untit_safe_cast_to_NetWokM_Type(int32_T input)
{
int32_T y;
/* Initialize output value to default value for NetWokM_Type (NM_AllCh) */
y = 0;
if ((input >= 0) && (input <= 4)) {
/* Set output value to input value if it is a member of NetWokM_Type */
y = input;
}
return y;
}
MMI_u_Sig_Value = (uint8_T)(untit_safe_cast_to_NetWokM_Type(Sig) <= (int32_T)
NM_InternalCanCh);