Use Matlab script to realize A2L, ELF file replacement

1. A2L file introduction

A2L file is a kind of car calibration software, using A2L file, it is very convenient to carry out parameter calibration. The A2L file contains data parameters such as the calibration amount and data type specified in the Simulink model; when using INCA for calibration, the A2L file needs to be imported into the workspace.

The generation process of the A2L file is:

After the Simulink completes the model building, the A2L file is generated. At this time, the address of each variable in the A2L file is empty, and the .c and .h files need to be compiled in Tasking to obtain the address information. In actual operation, it is to replace the available part of the original project A2L file with some lines in the newly generated A2L file of simulink.

2. Requirements description

After using the model to generate A2L, use notepad++ to open the generated a2l file, all variable addresses are defaulted to 0x0000, as shown below:

can use

rtw.asap2SetAddress('model.a2l','model.elf')

The statement merges the effective address information in elf into a2l; at the same time, part of the a2l header file generated in matlab needs to be replaced. Every time the model is newly generated, operation replacement needs to be done manually. Therefore, write an m file, automatically perform file replacement operations, and improve productivity.

3. Writing scripts

Design idea

Read the content of two A2L files, and replace the read content in the newly created A2L.

tip:

①The script automatically selects the model.a2l file that needs to delete the first 1174 lines

②The script automatically selects the ADAS.a2l file that needs to keep the first 218 lines

③Generate a new model.a2l file in the matlab working path

④Rename the elf file in the debug folder, and get the new file model.elf in the working path

⑤ Merge A2LConbinewithELF.m function

%file Get_Newfile.m
 ?ta 2022/9/6
%vision V1.1
%************************************************** *************************
% Steps for usage:
% 1. Run the script
% 2. The script automatically selects the model_1Mbps.a2l file that needs to keep the first 1174 lines (valid header file information)
% 3. The script automatically selects the ADAS.a2l file after line 218 that needs to be kept (empty address calibration information)
% 4. Automatically generate a model.a2l file in the matlab working path
% 5. Rename the elf file in the debug folder, and get a new file model.elf in the working path
% 6. Merge A2LConbinewithELF.m function
%************************************************** *************************
fidz=fopen('ADAS.a2l','r + ');
fidx=fopen('model_1Mbps.a2l','r + ');
fidw=fopen('model.a2l','w + ');
%************************************************** *************************
%Clear all the contents of the model.a2l file before running to facilitate subsequent generation
for i=1
    fgetl(fidw)
end
while ~feof(fidw)
    fprintf(fidw,'%s\
','');
end
%************************************************** *************************
 ?l header file replacement
for k=1:1173
    tline1=fgetl(fidx);
    if k>0
        fprintf(fidw,'%s\
',tline1);
    end
end % Get the first 1174 lines of the model_1Mbps.a2l file and fill it into model_new (required header file)
%************************************************** *************************
Copy the file after line 218 of the intermediate version file generated by %matlab
for m=1:218
    fgetl(fidz)
end
while ~feof(fidz)
    tline2 = fgetl(fidz);
    fprintf(fidw,'%s\
',tline2);
end % Get the 218-line follow-up file of the model.a2l file and fill it into modela.a2l (empty address file)
disp('replacement complete');
%************************************************** *************************
% Select the elf file generated by Tasking. Since it is different from the project path, it needs to be selected manually
disp('Select the elf file generated under the tasking debug path');
[filename2, pathname2, FileIndex] = uigetfile({'*.elf', 'All excel file(*.elf)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick an elf file');
if FileIndex == 0 % if 'cancel' is selected
disp('No file selected');
else
file_path = [pathname2 filename2];
end
%Copy the elf file to the working path and name it model.elf
movefile([pathname2 filename2],'model.elf');
fclose(fidx); % close the newly generated file
%************************************************** *************************
% merge A2LConbinewithELF.m function
rtw.asap2SetAddress('model.a2l','model.elf')

The code has been upgraded once to solve the shortcomings:

1. The generated new A2L (model.a2l) file needs to delete the old (model.a2l) from the workspace every time it is updated (if it is not deleted, the previous version model.a2l will be overwritten, when the number of lines in the new version of model.a2l If it is smaller than the old version, the replacement of some lines at the end of the newly generated A2L cannot be completed, resulting in a file error).

Solutions:

pass:

for i=1
fgetl(fidw)endwhile ~feof(fidw)
fprintf(fidw,'%s\
','');
end

statement, first replace all the statements in the model.a2l file with ” empty characters (that is, clear the document).

Remaining disadvantages:

  1. Since the elf file is generated for tasking and saved in the debug path of the tasking project workspace after generation, it needs to be used:

disp('Select the elf file generated under the tasking debug path');
[filename2, pathname2, FileIndex] = uigetfile({'*.elf', 'All excel file(*.elf)'; ...'*.*', 'All Files (*.*)'}, .. .'Pick an elf file');
if FileIndex == 0 % if 'cancel' is selected
disp('No file selected');
else
file_path = [pathname2 filename2];
end

To select the file, you need to move the mouse to select the elf file, which cannot be fully automatic.

File effect

Under initial conditions, the workspace has no .a2l and .elf files:

Run script

At this time, the a2l file and elf file are automatically generated

Don’t worry about the workspace warning, because the elf file I manually selected is one I randomly selected (the elf created for lighting before), not the elf of the ADAS model, so a warning will definitely be reported when the elf and model addresses are merged. Because the corresponding calibration quantity cannot be found.

The generated elf and a2l also meet the requirements. Here, 1174 is used as the replacement demarcation line. (It can be seen that the address of the calibration quantity is still empty at this time, the reason is as above. It does not affect the script function).