协助同事分析CAN日志文件,写了一个m脚本文件,帮助定位丢帧问题的发生。
log文件格式
分析代码
close all;clear;clc;%load data from a file
[FileName,PathName,~] = uigetfile('*.trc','Sample Dialog Box');fileID = fopen([PathName FileName]);
disp(FileName);%--------------------------------------------------------------------------
toral_row = 0;while (-1 ~= fgetl(fileID))toral_row = toral_row + 1;
enddisp('The toral_row of the file is: ');
disp(toral_row);%--------------------------------------------------------------------------
fseek(fileID, 0,'bof'); % back to Beginning of file%--------------------------------------------------------------------------
if (toral_row > 11)%--------------------------------------------------------------------------CellData = textscan(fileID,' %d %f32 %s %s %s %d8 %s %s %s %s %s %s %s %s', (toral_row - 11),...'headerlines',11, 'Delimiter', ' ', 'MultipleDelimsAsOne', 1);fclose(fileID);D_Index = CellData{1};D_Time = CellData{2};%----------------------------------------------------------------------D_column = length(D_Index);DeltaTime = zeros(1, D_column);DeltaIndex = zeros(1, D_column);for idx = 1:(D_column - 1)DeltaTime(idx) = D_Time(idx + 1) - D_Time(idx);endfor idx = 1:(D_column - 1)DeltaIndex(idx) = D_Index(idx + 1) - D_Index(idx);end%----------------------------------------------------------------------figure(1);%plot at the same figurehold on;grid on;%Specify Line Marker and Color:rgbcmykwplot(D_Index,'r-'); plot(D_Time,'k-');%titlelegend('Index','Time');title('CAN Tx Processing');hold off%----------------------------------------------------------------------figure(2);%plot at the same figurehold on;grid on;%Specify Line Marker and Color:rgbcmykwplot(DeltaTime,'g-');plot(DeltaIndex,'m-');%titlelegend('\DeltaTime','\DeltaIndex');title('Processing Analyzer');hold off%--------------------------------------------------------------------------
elsefclose(fileID);
end
分析结果
注:仅支持单ID分析,可自行修改根据不同id分析