自定义 ASAP2 文件
在 ASAP2 文件中添加、更新、过滤、查找和删除 ECU 描述。
打开并编译示例模型
打开示例模型 ASAP2Demo
open_system("ASAP2Demo");
编译模型。
rtwbuild("ASAP2Demo");
### Searching for referenced models in model 'ASAP2Demo'. ### Found 1 model references to update. ### Starting serial model reference code generation build. ### Successfully updated the model reference code generation target for: ASAP2DemoModelRef ### Starting build procedure for: ASAP2Demo ### Successful completion of build procedure for: ASAP2Demo Build Summary Code generation targets built: Model Action Rebuild Reason ====================================================================================== ASAP2DemoModelRef Code generated and compiled. ASAP2DemoModelRef.c does not exist. Top model targets built: Model Action Rebuild Reason =========================================================================================== ASAP2Demo Code generated and compiled. Code generation information file does not exist. 2 of 2 models built (0 models already up to date) Build duration: 0h 0m 23.37s
为模型创建 ECU 描述对象。
descObj = coder.asap2.getEcuDescriptions("ASAP2Demo");
获取描述对象中可用计算方法的列表。
find(descObj,"CompuMethod")
ans = 1x10 string
"ASAP2DemoModelRef_CM_double" "ASAP2DemoModelRef_CM_int16_rpm" "ASAP2Demo_CM_double" "ASAP2Demo_CM_double_m_per__s_2_" "ASAP2Demo_CM_double_rpm" "ASAP2Demo_CM_int32" "ASAP2Demo_CM_single" "ASAP2Demo_CM_single_m_per__s_2_" "ASAP2Demo_CM_single_rpm" "ASAP2Demo_CM_uint8"
过滤计算方法,并获取以 rpm 为单位的计算方法列表。
find(descObj,"CompuMethod",Units='rpm')
ans = 1x3 string
"ASAP2DemoModelRef_CM_int16_rpm" "ASAP2Demo_CM_double_rpm" "ASAP2Demo_CM_single_rpm"
创建和添加自定义计算方法
要向 ASAP2 文件添加新计算方法,请创建一个自定义计算方法。
CompuMethod_CM1 = coder.asap2.CompuMethod; CompuMethod_CM1.Name = 'CompuMethod_1'; CompuMethod_CM1.ConversionType = 'LINEAR'; CompuMethod_CM1.Coefficients = [2 3]; CompuMethod_CM1.LongIdentifier = 'longIdentifierTest'; CompuMethod_CM1.Format = '%2.3'; CompuMethod_CM1.Units = 's';
将该自定义计算方法添加到 ECU 描述对象中。
add(descObj,CompuMethod_CM1);
获取新添加的计算方法的属性。
get(descObj,"CompuMethod","CompuMethod_1")
ans = CompuMethod with properties: Name: 'CompuMethod_1' LongIdentifier: 'longIdentifierTest' Format: '%2.3' Units: 's' Coefficients: [2 3] ConversionType: 'LINEAR' CompuVTabValues: [1x1 struct] CustomData: ""
要修改计算方法的属性,请使用 set 函数。更新计算方法的 LongIdentifier 字段。
set(descObj,"CompuMethod","CompuMethod_1",LongIdentifier="longIdentifierCM1")
使用更新后的 ECU 描述对象生成 ASAP2 文件,并确认 ASAP2 文件包含计算方法 CompuMethod_1。
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
删除计算方法
从描述对象中删除新添加的计算方法。
delete(descObj,"CompuMethod","CompuMethod_1");
创建和添加自定义特征
要向 ASAP2 文件添加新特征,请创建一个自定义特征。
Parameter_1 = coder.asap2.Characteristic; Parameter_1.Name = 'Custom_parameter1'; Parameter_1.LongIdentifier = 'longIdentifierParam'; Parameter_1.UpperLimit = 255; Parameter_1.LowerLimit = 0;
将该自定义特征添加到 ECU 描述对象中。
add(descObj,Parameter_1);
获取新添加的特征的属性。
get(descObj,"Characteristic","Custom_parameter1")
ans = Characteristic with properties: Name: 'Custom_parameter1' LongIdentifier: 'longIdentifierParam' Type: 'VALUE' EcuAddress: '0x0000' CompuMethodName: 'NO_COMPU_METHOD' LowerLimit: 0 UpperLimit: 255 EcuAddressComment: "" EcuAddressExtension: [] CalibrationAccess: 'Calibration' DisplayIdentifier: "" Format: "" BitMask: [] AxisInfo: [] RecordLayout: "" Dimensions: [] Export: 1 MaxRefresh: [1x1 struct] SymbolLink: [1x1 struct] CustomData: ""
要修改特征的属性,请使用 set 函数。更新特征的 UpperLimit 字段。
set(descObj,"Characteristic","Custom_parameter1",UpperLimit=128)
使用更新后的 ECU 描述对象生成 ASAP2 文件,并确认 ASAP2 文件包含特征 Custom_parameter1。
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
从描述对象中删除新添加的特征。
delete(descObj,"Characteristic","Custom_parameter1");
创建和添加自定义测量
要向 ASAP2 文件添加新测量,请创建一个自定义测量。
Signal_1 = coder.asap2.Measurement; Signal_1.Name = 'Custom_signal1'; Signal_1.LongIdentifier = 'longIdentifierSignal'; Signal_1.UpperLimit = 255; Signal_1.LowerLimit = 0;
将该自定义测量添加到 ECU 描述对象中。
add(descObj,Signal_1);
获取新添加的测量的属性。
get(descObj,"Measurement","Custom_signal1")
ans = Measurement with properties: Name: 'Custom_signal1' LongIdentifier: 'longIdentifierSignal' DataType: 'UBYTE' EcuAddress: '0x0000' CompuMethodName: "" LowerLimit: 0 UpperLimit: 255 Raster: [1x1 struct] EcuAddressComment: "" EcuAddressExtension: [] CalibrationAccess: 'NoCalibration' DisplayIdentifier: "" Format: "" BitMask: [] Dimensions: [] Export: 1 MaskData: [1x1 struct] MaxRefresh: [1x1 struct] SymbolLink: [1x1 struct] CustomData: ""
要修改测量的属性,请使用 set 函数。更新测量的 CalibrationAccess 字段。
set(descObj,"Measurement","Custom_signal1",CalibrationAccess='Calibration')
使用更新后的 ECU 描述对象生成 ASAP2 文件,并确认 ASAP2 文件包含名为 Custom_signal1 的测量。
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
从描述对象中删除新添加的测量。
delete(descObj,"Measurement","Custom_signal1");
创建和添加查找表参数
添加一个查找表参数。
LUT_Parameter = coder.asap2.Characteristic; LUT_Parameter.Name = "custom_lookup_table"; LUT_Parameter.Type = "MAP";
创建轴信息并将其添加到参数中。
axis_data = coder.asap2.AxisInfo; axis_data(1).Name = 'BP3'; axis_data(2).Name = 'Bp4'; axis_data(1).CompuMethodName = 'ASAP2Demo_CM_double'; axis_data(2).CompuMethodName = 'ASAP2Demo_CM_double'; axis_data(1).MaxAxisPoints = '3'; axis_data(2).MaxAxisPoints = '3'; axis_data(1).AxisType = 'STD_AXIS'; axis_data(2).AxisType = 'STD_AXIS'; LUT_Parameter.AxisInfo = axis_data;
将查找表参数添加到描述对象。
add(descObj,LUT_Parameter)
使用更新后的 ECU 描述对象生成 ASAP2 文件,并确认 ASAP2 文件包含查找表参数 custom_lookup_table。
coder.asap2.export("ASAP2Demo",CustomEcuDescriptions=descObj);
Following Characteristics or Measurements with unsupported data types are not exported in ASAP2 file. "ASAP2Demo_DW.ASAP2DemoModelRef_InstanceData"
另请参阅
coder.asap2.export
| coder.asap2.UserCustomizeBase
相关主题
- Customize Generated ASAP2 File
- Customize Using Base Files (Embedded Coder)