112 lines
4.0 KiB
Matlab
112 lines
4.0 KiB
Matlab
function inspect_targeted_diagnostics
|
|
% Targeted read-only diagnostics for signal mapping and thermal parameters.
|
|
|
|
rootDir = fileparts(mfilename('fullpath'));
|
|
modelDir = fullfile(rootDir, 'LEM_slx');
|
|
reportFile = fullfile(rootDir, 'analysis_artifacts', 'targeted_diagnostics.txt');
|
|
addpath(modelDir);
|
|
fid = fopen(reportFile, 'w');
|
|
cleanup = onCleanup(@() fclose(fid));
|
|
|
|
models = {'PMLSM', 'PMLSM_ThreeNodeThermal'};
|
|
for k = 1:numel(models)
|
|
model = models{k};
|
|
load_system(fullfile(modelDir, [model '.slx']));
|
|
fprintf(fid, '=== MODEL %s ===\n', model);
|
|
callbackNames = {'PreLoadFcn','PostLoadFcn','InitFcn','StartFcn','StopFcn','CloseFcn'};
|
|
for n = 1:numel(callbackNames)
|
|
fprintf(fid, 'CALLBACK\t%s\t%s\n', callbackNames{n}, ...
|
|
oneLine(get_param(model, callbackNames{n})));
|
|
end
|
|
fprintf(fid, 'DATA_DICTIONARY\t%s\n', get_param(model, 'DataDictionary'));
|
|
|
|
rootBlocks = find_system(model, 'SearchDepth', 1, 'Type', 'Block');
|
|
fprintf(fid, 'ROOT_BLOCKS\n');
|
|
for n = 1:numel(rootBlocks)
|
|
fprintf(fid, '%s\t%s\t%s\n', rootBlocks{n}, ...
|
|
get_param(rootBlocks{n}, 'BlockType'), get_param(rootBlocks{n}, 'MaskType'));
|
|
end
|
|
dumpLines(fid, model);
|
|
|
|
if strcmp(model, 'PMLSM_ThreeNodeThermal')
|
|
ws = get_param(model, 'ModelWorkspace');
|
|
exprBlocks = find_system(model, 'LookUnderMasks', 'all', 'FollowLinks', 'off', ...
|
|
'BlockType', 'Gain');
|
|
fprintf(fid, 'RESOLVED_GAINS\n');
|
|
for n = 1:numel(exprBlocks)
|
|
expr = get_param(exprBlocks{n}, 'Gain');
|
|
fprintf(fid, '%s\t%s\t', exprBlocks{n}, expr);
|
|
try
|
|
fprintf(fid, 'slResolve=%s\t', oneLine(valueText(slResolve(expr, exprBlocks{n}))));
|
|
catch ME
|
|
fprintf(fid, 'slResolve_ERROR=%s\t', oneLine(ME.message));
|
|
end
|
|
try
|
|
fprintf(fid, 'modelWorkspace=%s\n', oneLine(valueText(evalin(ws, expr))));
|
|
catch ME
|
|
fprintf(fid, 'modelWorkspace_ERROR=%s\n', oneLine(ME.message));
|
|
end
|
|
end
|
|
|
|
constants = find_system([model '/Pcu'], 'SearchDepth', 1, 'BlockType', 'Constant');
|
|
fprintf(fid, 'RESOLVED_PCU_CONSTANTS\n');
|
|
for n = 1:numel(constants)
|
|
expr = get_param(constants{n}, 'Value');
|
|
fprintf(fid, '%s\t%s\t', constants{n}, expr);
|
|
try
|
|
fprintf(fid, '%s\n', oneLine(valueText(slResolve(expr, constants{n}))));
|
|
catch ME
|
|
fprintf(fid, 'ERROR=%s\n', oneLine(ME.message));
|
|
end
|
|
end
|
|
end
|
|
close_system(model, 0);
|
|
fprintf(fid, '\n');
|
|
end
|
|
|
|
clear cleanup
|
|
end
|
|
|
|
function dumpLines(fid, system)
|
|
fprintf(fid, 'PORT_MAP\t%s\n', system);
|
|
systems = [{system}; find_system(system, 'LookUnderMasks', 'all', ...
|
|
'FollowLinks', 'off', 'BlockType', 'SubSystem')];
|
|
systems = unique(systems, 'stable');
|
|
for n = 1:numel(systems)
|
|
lines = find_system(systems{n}, 'FindAll', 'on', 'SearchDepth', 1, 'Type', 'Line');
|
|
lines = unique(lines);
|
|
for p = 1:numel(lines)
|
|
srcPort = get_param(lines(p), 'SrcPortHandle');
|
|
dstPorts = get_param(lines(p), 'DstPortHandle');
|
|
if srcPort > 0
|
|
srcBlock = get_param(srcPort, 'Parent');
|
|
srcNumber = get_param(srcPort, 'PortNumber');
|
|
for q = 1:numel(dstPorts)
|
|
if dstPorts(q) > 0
|
|
dstBlock = get_param(dstPorts(q), 'Parent');
|
|
dstNumber = get_param(dstPorts(q), 'PortNumber');
|
|
fprintf(fid, '%s\t%s:%d -> %s:%d\n', systems{n}, ...
|
|
srcBlock, srcNumber, dstBlock, dstNumber);
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function text = valueText(value)
|
|
if ischar(value)
|
|
text = value;
|
|
elseif isstring(value)
|
|
text = strjoin(cellstr(value), ', ');
|
|
elseif isnumeric(value) || islogical(value)
|
|
text = mat2str(value);
|
|
else
|
|
text = ['<' class(value) '>'];
|
|
end
|
|
end
|
|
|
|
function text = oneLine(text)
|
|
text = regexprep(char(text), '[\r\n\t]+', ' ');
|
|
end
|