Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
classdef SCDclass_mdspar < matlab.mixin.Heterogeneous
% Superclass for MDS+ parameters
% the superclass matlab.mixin.Heterogeneous allows
% bilding of lists of mixed kind parameters in the
% expcode configuration (and later in C++ code)
% For all subclasses, by default all NaN values are converted to 0
properties (Access = protected)
mdsserver % The MDS+ server hosting the parameter
mdstree % The MDS+ Tree hosting the parameter
tdiexprmodel % TDI expression to retrieve data when invoked with -1 shot
tdiexprshot % TDI expression to retrieve data when invoked with a give shotno, if empty the -1 is used
tdiexprused % TDI expression actually used
modelparam % Full expansion of the model target parameter (modeltpstruct+modeltargetpar)
modeltpstruct % target tunable parameter structure, if left empty it will be filled once binding to an algorithm
modeltargetpar % Model parameter w/o tunable parameters structure
value % value of the parameter
datadictionary % data dictionary hosting the parameter, if empty base workspace
modelname % name of the Simulink model using the parameter
getcommand % full command for getting the value (callable by matlab eval)
classname % class name for logging
assignvar % actualizedata specific
assignstring % actualizedata specific
denanstring % actualizedata specific
caststring % actualizedata specific
end
properties
verbose % Verbosity of the class
end
methods
function obj=SCDclass_mdspar(srctdimodel,destparam,varargin)
% MDS source and model destination constructor
p=inputParser;
addRequired(p,'srctdimodel',@(x) ischar(x));
addRequired(p,'destparam',@(x) ischar(x));
addParameter(p,'srcsrv','tcvdata',@(x) ischar(x));
addParameter(p,'srctree','tcv_shot',@(x) ischar(x));
addParameter(p,'srctdishot','',@(x) ischar(x));
addParameter(p,'modelname','',@(x) ischar(x));
addParameter(p,'datadictname','',@(x) ischar(x));
addParameter(p,'modeltpstruct','',@(x) ischar(x)); % desttp ?
parse(p,srctdimodel,destparam,varargin{:}{:});
obj.mdsserver=p.Results.srcsrv;
obj.mdstree=p.Results.srctree;
obj.tdiexprmodel=p.Results.srctdimodel;
if isempty(p.Results.srctdishot)
obj.tdiexprshot=p.Results.srctdimodel;
else
obj.tdiexprshot=p.Results.srctdishot;
end
obj.modeltargetpar=p.Results.destparam;
obj.modelname=p.Results.modelname;
obj.datadictionary=p.Results.datadictname;
obj.modeltpstruct=p.Results.modeltpstruct;
obj.verbose=1;
end
end
% Not abstract methods common to all child classes
methods
function mdsconnect(obj, shot)
mdsconnect(obj.mdsserver);
s=mdsopen(obj.mdstree, shot);
str=sprintf('SCDclass_mdsparam (%s), failed opening MDS+ tree', obj.modelparam);
assert(s==shot, str);
end
function obj=preactualizecommon(obj, shot)
% Opening the tree
obj.mdsconnect(shot);
% Checking if data can be retrieved, updating get command
[obj, obj.value]=obj.getdata(shot);
pointspos=strfind(obj.modelparam,'.');
baseparam=obj.modelparam(1:pointspos(1)-1);
structparam=obj.modelparam(pointspos(1):end);
obj.assignvar=sprintf('%s.Value%s',baseparam,structparam);
obj.assignstring=sprintf('%s=%s;',obj.assignvar,obj.getcommand);
obj.denanstring=sprintf('%s(isnan(%s))=0;',obj.assignvar,obj.assignvar);
obj.caststring=sprintf('%s=%s;',obj.assignvar,obj.assignvar);
end
function obj=postactualizecommon(obj, shot)
if obj.verbose==1
fprintf('Actualizing parameter: ''%s'' <- ''%s'' (%s, shot %d)\n', obj.modelparam, obj.tdiexprused, obj.classname, shot);
end
evalin('base', obj.assignstring);
evalin('base', obj.denanstring);
evalin('base', obj.caststring);
end
function [obj,value]=getdatacommon(obj, shot)
obj=obj.actualizegetcmd('mdsvalue(''%s'')', shot);
value=eval(obj.getcommand);
str=sprintf('MDS+ error for parameter %s: %s', obj.modelparam, value);
assert(isnumeric(value), str);
end
function obj=actualizegetcmd(obj, cmdstring, shot)
if(shot==-1)
obj.getcommand=sprintf(cmdstring, obj.tdiexprmodel);
obj.tdiexprused=obj.tdiexprmodel;
else
obj.getcommand=sprintf(cmdstring, obj.tdiexprshot);
obj.tdiexprused=obj.tdiexprshot;
end
obj.modelparam=[obj.modeltpstruct '.' obj.modeltargetpar];
end
function printinfocommon(obj)
fprintf('%s (class %s):\n', obj.modelparam, obj.classname);
fprintf(' Simulink model: ''%s'', data dictionary: ''%s''\n', obj.modelname, obj.datadictionary);
fprintf(' MDS+ source server: ''%s'', Tree: ''%s''\n', obj.mdsserver, obj.mdstree);
fprintf(' MDS+ TDI expressions, model: ''%s''', obj.tdiexprmodel);
if(strcmp(obj.tdiexprmodel, obj.tdiexprshot))
fprintf(', shot: same.\n');
else
fprintf(', shot: ''%s''\n', obj.tdiexprshot);
end
end
function out = gettargetparam(obj)
out = obj.modelparam;
end
function obj = setparamstructure(obj, structname)
%obj.modelparam = [structname '.' obj.modelparam];
if(isempty(obj.modeltpstruct))
obj.modeltpstruct = structname;
end
obj.modelparam=[obj.modeltpstruct '.' obj.modeltargetpar];
end
function obj = setmodelname(obj, modelname)
if(isempty(obj.modelname))
obj.modelname = modelname;
end
end
function obj = setdatadictionary(obj, ddname)
if(isempty(obj.datadictionary))
obj.datadictionary = ddname;
end
end
function entrystring = genMARTe2entrycommon(obj, shot)
obj.mdsconnect(shot);
[obj,~]=obj.getdata(shot);
%entrystring = ['+' obj.modeltargetpar ' = { Class=' obj.classname ' Path=' obj.tdiexprused ' }'];
entrystring = ['+' obj.modeltargetpar ' = { Class=' obj.classname ' Path=' obj.tdiexprused];
end
end
% Abstract method actually implemented by child classes
methods (Abstract)
% Gets data from MDS+ and actualizes it on the model,
% Connects to MDS+ and opens the tree, to be
% improved via container class of this class
actualizedata(obj, shot)
% Gets data from mds, mds connection is assumed already estabilished
% and tree opened
[obj, value] = getdata(obj, shot)
% Generate C++ code
%gencode(obj)
% Generate MARTe2 configuration entry
entrystring = genMARTe2entry(obj, shot)
% Prints the parameter info summary
printinfo(obj)
end
end