主要内容

add

将元素添加到 ASAP2 文件

自 R2022b 起

    说明

    add(descObj,object) 将新自定义 ASAP2 元素对象添加到 ECU 描述对象 descObj 中,以便生成具有新元素的 ASAP2 文件。

    示例

    示例

    全部折叠

    在 ASAP2 文件中添加、更新、过滤、查找和删除 ECU 描述。

    打开并编译示例模型

    打开示例模型 ASAP2Demo

    open_system("ASAP2Demo");

    编译模型。

    slbuild("ASAP2Demo");
    ### Searching for referenced models in model 'ASAP2Demo'.
    ### Total of 2 models to build.
    ### Starting serial code generation build.
    ### Successfully updated the model reference code generation target for: ASAP2DemoModelRef
    ### Starting build procedure for: ASAP2Demo
    codeInterfacePackaging: Nonreusable function
    codeInterfacePackaging: NonReusable
    ### Successful completion of build procedure for: ASAP2Demo
    
    Build Summary
    
    Model reference code generation targets:
    
    Model              Build Reason                                 Status                        Build Duration
    ============================================================================================================
    ASAP2DemoModelRef  Target (ASAP2DemoModelRef.c) did not exist.  Code generated and compiled.  0h 0m 9.4574s 
    
    Top model targets:
    
    Model      Build Reason                                         Status                        Build Duration
    ============================================================================================================
    ASAP2Demo  Information cache folder or artifacts were missing.  Code generated and compiled.  0h 0m 20.325s 
    
    2 of 2 models built (0 models already up to date)
    Build duration: 0h 0m 31.393s
    

    为模型创建 ECU 描述对象。

    descObj = coder.asap2.getEcuDescriptions("ASAP2Demo");

    获取描述对象中可用计算方法的列表。

    find(descObj,"CompuMethod")
    ans = 1×10 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 = 1×3 string
        "ASAP2DemoModelRef_CM_int16_rpm"    "ASAP2Demo_CM_double_rpm"    "ASAP2Demo_CM_single_rpm"
    
    

    创建和添加自定义计算方法

    要向 ASAP2 文件添加新计算方法,请创建一个自定义计算方法。

    CompuMethod_1 = coder.asap2.CompuMethod;
    CompuMethod_1.Name = 'CompuMethod_1';
    CompuMethod_1.ConversionType = 'LINEAR';
    CompuMethod_1.Coefficients = [2 3];
    CompuMethod_1.LongIdentifier = 'longIdentifierTest';
    CompuMethod_1.Format = '%2.3';
    CompuMethod_1.Units = 's';

    将该自定义计算方法添加到 ECU 描述对象中。

    add(descObj,CompuMethod_1);

    获取新添加的计算方法的属性。

    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: [1×1 struct]
             CustomData: ""
    
    

    要修改计算方法的属性,请使用 set 函数。将计算方法的 ConversionType 字段更新为 TAB_VERB,并定义 CompuVTabValues。

    set(descObj,"CompuMethod","CompuMethod_1",ConversionType="TAB_VERB");
    set(descObj,"CompuMethod","CompuMethod_1",CompuVTabValues = struct('Literals',["false" "true"],'Values',[0 1]));

    获取属性以查看修改后的字段。

    modifiedprop = get(descObj,"CompuMethod","CompuMethod_1")
    modifiedprop = 
      CompuMethod with properties:
    
                   Name: 'CompuMethod_1'
         LongIdentifier: 'longIdentifierTest'
                 Format: '%2.3'
                  Units: 's'
           Coefficients: [2 3]
         ConversionType: "TAB_VERB"
        CompuVTabValues: [1×1 struct]
             CustomData: ""
    
    
    modifiedprop.CompuVTabValues
    ans = struct with fields:
        Literals: ["false"    "true"]
          Values: [0 1]
    
    

    使用更新后的 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: [1×1 struct]
                 SymbolLink: [1×1 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: [1×1 struct]
          EcuAddressComment: ""
        EcuAddressExtension: []
          CalibrationAccess: 'NoCalibration'
          DisplayIdentifier: ""
                     Format: ""
                    BitMask: []
                 Dimensions: []
                     Export: 1
                   MaskData: [1×1 struct]
                 MaxRefresh: [1×1 struct]
                 SymbolLink: [1×1 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.getEcuDescriptions 函数创建的信息对象,包含给定模型的 ASAP2 属性。

    示例: descObj = coder.asap2.getEcuDescriptions(<modelName>)

    创建一个表示 ASAP2 元素(例如特性、测量值、轴点、函数或 Compu 方法)的对象。将该对象添加到现有信息对象并将其导出到 ASAP2 文件。

    示例: CompuMethod_CM1 = coder.asap2.CompuMethod; add(descObj,CompuMethod_CM1); coder.asap2.export(<modelName>, CustomEcuDescriptions=descObj)

    版本历史记录

    在 R2022b 中推出