How can i automatically load a configuration and add custom checks in Model Advisor?

5 visualizzazioni (ultimi 30 giorni)
Hello,
I have one question, I'm loading custom checks in the Model Advisor, see below one simple example. Additionaly, I wanted Model Advisor to preload a configuration and after that to add my Custom checks. But when I load the configuration (MAAB_Checks.mat), Model Advisor doesn't add my mustom checks.
Someone any idea?
MATLAB code
% function sl_customization(cm)
% SL_CUSTOMIZATION - Model Advisor customization
% register custom checks
cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);
% register custom factory group
cm.addModelAdvisorTaskFcn(@defineModelAdvisorTasks);
% register custom tasks.
cm.addModelAdvisorTaskAdvisorFcn(@defineTaskAdvisor);
% register custom process callback
cm.addModelAdvisorProcessFcn(@ModelAdvisorProcessFunction);
% -----------------------------
% defines Model Advisor Checks
% -----------------------------
function defineModelAdvisorChecks
mdladvRoot = ModelAdvisor.Root;
% --- sample check 2
rec = ModelAdvisor.Check('com.mathworks.sample.Check01');
rec.Title = 'Check Compiler Configuration';
rec.TitleTips = 'Example style one callback';
rec.setCallbackFcn(@checkcompilersettings,'None','StyleOne');
% set fix operation
myAction2 = ModelAdvisor.Action;
myAction2.setCallbackFcn(@checkcompilersettingsAction);
myAction2.Name='Fix configuration';
myAction2.Description='Click the button to configure the model';
rec.setAction(myAction2);
mdladvRoot.publish(rec, 'Custom');
% -----------------------------
% defines Model Advisor tasks
% please refer to Model Advisor API document for more details.
% -----------------------------
function defineTaskAdvisor
mdladvRoot = ModelAdvisor.Root;
MAT1 = ModelAdvisor.Task('com.mathworks.sample.TaskSample1');
MAT1.DisplayName='Custom check Compiler Settings';
MAT1.setCheck('com.mathworks.sample.Check01');
mdladvRoot.register(MAT1);
MAG = ModelAdvisor.Group('com.mathworks.sample.GroupSample');
MAG.DisplayName='Custom check configuration';
MAG.addTask(MAT1);
mdladvRoot.publish(MAG); % publish under Root
% -----------------------------
% defines Model Advisor process callback
% please refer to Model Advisor API document for more details.
% -----------------------------
function [checkCellArray taskCellArray] = ModelAdvisorProcessFunction(stage, ~, checkCellArray, taskCellArray)
switch stage
case 'configure'
ModelAdvisor.setConfiguration('..\PrjTools\MAAB_Checks.mat');
case 'process_results'
end
% -----------------------------
% Sample StyleThree callback function,
% please refer to Model Advisor API document for more details.
% -----------------------------
function ResultDescription = checkcompilersettings(system)
ResultDescription = {};
mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system);
% find all blocks inside current system
mdladvObj.setCheckResultStatus(true); % set to pass
avtlsettings{1} = tl_get(bdroot,'codeopt.cleancode');
avtlsettings{2} = tl_get(bdroot,'codeopt.target');
avtlsettings{3} = tl_get(bdroot,'frameopt.simconfig');
mdladvObj.setActionEnable(false);
if avtlsettings{1} ~= 1
ResultDescription{end+1} = ModelAdvisor.Text('Cleancode option not 1 ');
mdladvObj.setCheckResultStatus(false); % set to pass
mdladvObj.setActionEnable(true);
mdladvObj.setCheckErrorSeverity(1);
end
if ~strcmp(avtlsettings{2}, 'Generic TriCore/Task')
ResultDescription{end+1} = ModelAdvisor.Text('wrong compiler ');
mdladvObj.setCheckResultStatus(false); % set to pass
mdladvObj.setActionEnable(true);
mdladvObj.setCheckErrorSeverity(1);
end
if ~strcmp(avtlsettings{3}, 'TBTC/Task')
ResultDescription{end+1} = ModelAdvisor.Text(wrong eval board ');
mdladvObj.setCheckResultStatus(false); % set to pass
mdladvObj.setActionEnable(true);
mdladvObj.setCheckErrorSeverity(1);
end
% -----------------------------
% Sample action callback function for model optimization settings
% please refer to Model Advisor API document for more details.
% -----------------------------
function result = checkcompilersettingsAction(taskobj)
mdladvObj = taskobj.MAObj;
tl_set(bdroot,'codeopt.cleancode',1);
tl_set(bdroot,'codeopt.target','Generic TriCore/Task');
tl_set(bdroot,'frameopt.simconfig','TBTC/Task');
result = ModelAdvisor.Text('Code options set');
mdladvObj.setActionEnable(false);

Risposte (3)

Paraschivu Andreea
Paraschivu Andreea il 8 Feb 2013
Do you know how to do it, or not yet? I'm interested too about this topic

Bastian
Bastian il 11 Feb 2013
unfortunaly no

Alexandre de Langlade
Alexandre de Langlade il 6 Apr 2021
Modificato: Alexandre de Langlade il 6 Apr 2021
If your code is OK, Model Advisor actually adds your check to its list of checks, but you probably don't see it because of your configuration file MAAB_Checks.mat which doesn't contain it yet as it did not exist before.
If you edit that file with Model Advisor Configuration editor so that it includes your new checks, then reload Model Advisor, it should appear.

Categorie

Scopri di più su Run Model Advisor Checks in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by