Main Content

Customize Generated ASAP2 File

You can customize a generated ASAP2 file by using the code generator in either of the following ways:

Customize ASAP2 Fields by Using Base Class

  1. Create an object from the base class.

    obj = coder.asap2.UserCustomizeBase;

  2. Modify the object fields.

    obj.HeaderComment = 'Header comment';
    obj.ModParComment = 'Mod Par comment';
    obj.ModCommonComment = 'Mod Common comment';
    obj.ASAP2FileName = 'File name';
    obj.ByteOrder = 'BYTEORDER MSB_LAST';

  3. Pass the object to the function that generates the ASAP2 file.

    coder.asap2.export(modelName,'CustomizationObject',obj);

Customize ASAP2 Sections by Deriving From Base Class

  1. Derive from the base class coder.asap2.UserCustomizeBase. You can place the derived file anywhere on the MATLAB path.

  2. To edit the Header section, use the writeHeader function.

  3. Use the writeHardwareInterface function to edit the hardware interface section consisting of MOD_PAR and MOD_COMMON fields of the ASAP2 file.

  4. To add text at the beginning of the ASAP2 file, use the writeFileHead function.

  5. To add text at the end of the ASAP2 file, use the writeFileTail function.

    For example, the code for generating a derived class TestASAP2Customization might look like this code:

    classdef TestASAP2Customization < coder.asap2.UserCustomizeBase
        %   Customization class for asap2 file
        methods
            function header = writeHeader(obj)
                header = sprintf(['  /begin HEADER ' 'test Header text'  '\n',...
                    'header test comments from user\n',...
                    '  /end HEADER']);
            end
    
            function hardwareInterface = writeHardwareInterface(obj)
                hardwareInterface = sprintf(['    /begin MOD_PAR "' 'UserDefined' '"\n',...
                    '      test comments from user\n',...
                    '    /end MOD_PAR\n\n',...
                    '    /begin MOD_COMMON "'  'UserDefined MOD_COMMON' '"\n',...
                    '      user defined values for MOD_COMMON\n',...
                    '     ' obj.ByteOrder '\n',...
                    '     /end MOD_COMMON']);
            end
            
            function fileTail = writeFileTail(obj)
                fileTail = sprintf(['/* This File can be used for ' ,...
                    'calibration .*/\n'...
                    '/* EOF ',obj.ASAP2FileName, '*/']);
            end
            
            function fileHeader = writeFileHead(obj)
                fileHeader = sprintf(['/******************************************************************************\n',...
                    ' This is a a2l file which can be used for calibration with INCA or CANAPE\n',...
                    ' ******************************************************************************/'
                    ]);
            end
        end
    end

  6. Create an object from the derived class. For example, the following command creates an object from TestASAP2Customization:

    obj = TestASAP2Customization;

  7. Pass the object to the function that generates the ASAP2 file.

    coder.asap2.export(modelName,'CustomizationObject',obj);

See Also

Related Topics