Newer
Older
classdef SCDclass_node < SCDclass_component
% Wrapper class containing algos
properties (SetAccess = private)
nodenr
active = false; % not active by default
hasrfm = true; % all nodes have rfm
haswavegen
hasadc
hasethercat
ncpu % number of CPUs
cputype
timing = struct('t_start',-4.5,'t_stop',3,'dt',1e-4);
thperiod
buildcfg
initscdbeforecomp
cpuactive
wrappers % info about thread wrappers contained in this node
end
properties
type = 'node';
end
methods
name = sprintf('SCD_rtc_%02d',nodenr);
obj.nodenr = nodenr;
obj.name = name;
obj.algos = [];
obj.ddname = [name,'.sldd'];
obj.mdlname = [name,'.slx'];
function obj = addwrapper(obj,wrapperObj,cpunr,varalgo,isactive)
% by default, activate CPU when adding a wrapper
if nargin==4, isactive=true; end
assert(isa(wrapperObj,'SCDclass_wrapper'));
for ii=1:numel(obj.wrappers)
assert(~isequal(wrapperObj,obj.wrappers{ii}.wrapperobj),...
'wrapper %s is already present in node %d thread %d',...
obj.wrappers{ii}.wrapperobj.name,obj.nodenr,cpunr)
end
mywrapper.wrapperobj = wrapperObj;
obj.wrappers{cpunr} = mywrapper;
obj.cpuactive(cpunr) = isactive;
function node = defaultnodeconfig(node,nodenr)
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
% [general part]
switch nodenr
case 1
node.ncpu = 1;
node.type = 'std1cpu2015a';
node.timing.t_start = -4.5;
node.timing.t_stop = 3;
node.timing.dt = 1e-4;
node.thperiod = 1.0000e-03;
node.buildcfg.conffile{1} = 'standard';
node.buildcfg.initscdbeforecomp = false;
node.haswavegen = true;
node.hasethercat = false;
node.hasadc = true;
case 2
node.ncpu = 6;
node.type = 'std1cpu2015a';
node.timing.t_start = -4.5;
node.timing.t_stop = 3;
node.timing.dt = 1e-4;
node.thperiod = [1.0000e-03 1.0000e-03 1.0000e-03 1.0000e-03 1.0e-3 1.0e-3];
node.buildcfg.conffile = cell(node.ncpu,1);
node.buildcfg.conffile{1} = 'standard';
node.buildcfg.conffile{2} = 'standard';
node.buildcfg.conffile{3} = 'standard';
node.buildcfg.conffile{4} = 'standard';
node.buildcfg.conffile{5} = 'standard';
node.buildcfg.conffile{6} = 'standard';
node.buildcfg.initscdbeforecomp = false;
node.haswavegen = true;
node.hasadc = true;
node.hasethercat = true;
case 3
node.ncpu = 4;
node.type = '4cpus2015a';
node.timing.t_start = -2.0;
node.timing.t_stop = 2.75;
node.timing.dt = 1e-3;
node.thperiod = [1.0000e-03 1.0000e-03 1.0000e-03 1.0000e-03];
node.buildcfg.conffile = cell(node.ncpu,1);
node.buildcfg.conffile{1} = 'standard';
node.buildcfg.conffile{2} = 'standard';
node.buildcfg.conffile{3} = 'standard';
node.buildcfg.conffile{4} = 'standard';
node.buildcfg.initscdbeforecomp = [0 0 0 0];
node.haswavegen = true;
node.hasadc = false;
node.hasethercat = false;
case 4
node.ncpu = 4;
node.type = 'std1cpu2015a';
node.timing.t_start = -4.5;
node.timing.t_stop = 3;
node.timing.dt = 1e-4;
node.thperiod = 1.0000e-04;
node.buildcfg.conffile{1} = 'standard';
node.buildcfg.initscdbeforecomp = false;
node.haswavegen = true;
node.hasadc = false;
node.hasethercat = false;
case 5
node.ncpu = 1;
node.type = 'std1cpu2015a';
node.timing.t_start = -4.5;
node.timing.t_stop = 3;
node.timing.dt = 1e-4;
node.thperiod = 1.0000e-04;
node.buildcfg.conffile{1} = 'standard';
node.buildcfg.initscdbeforecomp = false;
node.haswavegen = true;
node.hasadc = false;
node.hasethercat = false;
case 6
node.ncpu = 4;
node.type = '4cpus2015a';
node.timing.t_start = 0.0;
node.timing.t_stop = 2.75;
node.timing.dt = 1e-3;
node.thperiod = [1.0000e-03 1.0000e-03 1.0000e-03 1.0000e-03];
node.buildcfg.conffile = cell(node.ncpu,1);
node.buildcfg.conffile{1} = 'standard';
node.buildcfg.conffile{2} = 'standard';
node.buildcfg.conffile{3} = 'standard';
node.buildcfg.conffile{4} = 'standard';
node.buildcfg.initscdbeforecomp = [0 0 0 0];
node.haswavegen = true;
node.hasadc = false;
node.hasethercat = false;
case 7
node.ncpu = 4;
node.type = '4cpus2015a';
node.timing.t_start = -0.5;
node.timing.t_stop = 2.5;
node.timing.dt = 1e-3;
node.thperiod = [1.0000e-03 1.0000e-03 1.0000e-03 1.0000e-03];
node.buildcfg.conffile = cell(node.ncpu,1);
node.buildcfg.conffile{1} = 'standard';
node.buildcfg.conffile{2} = 'standard';
node.buildcfg.conffile{3} = 'standard';
node.buildcfg.conffile{4} = 'standard';
node.buildcfg.initscdbeforecomp = [0 0 0 0];
node.haswavegen = true;
node.hasadc = true;
node.hasethercat = false;
case 8
node.ncpu = 1;
node.type = '4cpus2015a';
node.timing.t_start = -0.5;
node.timing.t_stop = 2.5;
node.timing.dt = 1e-3;
node.thperiod = [1.0000e-03 1.0000e-03 1.0000e-03 1.0000e-03];
node.buildcfg.conffile = cell(node.ncpu,1);
node.buildcfg.conffile{1} = 'standard';
node.buildcfg.conffile{2} = 'standard';
node.buildcfg.conffile{3} = 'standard';
node.buildcfg.conffile{4} = 'standard';
node.buildcfg.initscdbeforecomp = [0 0 0 0];
node.haswavegen = true;
node.hasadc = true;
node.hasethercat = false;
end
node.cpuactive = zeros(1,node.ncpu);
% add template node wrappers
for icpu=1:node.ncpu
wrappername = sprintf('SCDwrap_template%02d%02d',nodenr,icpu);
mywrapper = SCDclass_wrapper(wrappername);
varalgo = 1; % template value
node = node.addwrapper(mywrapper,icpu,varalgo,false);
function obj = setactive(obj,value)
assert(islogical(value),'value must be boolean')
obj.active = value;
end
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
function linknodedd(obj,node)
% link node data dictionary to main expcode object data dicationary
assert(isa(node,'SCDclass_node'),'node must be an SCDclass_node object')
ddObj = Simulink.data.dictionary.open(obj.ddname);
prefix = 'SCD_rtc';
% already linked sources
prevsources = ddObj.DataSources;
prevsources_nodes = prevsources(startsWith(prevsources,prefix));
% make algo data dictionary list list
reqsources = node.ddname;
% removing unnecessary ones
for ii=1:numel(prevsources_nodes)
mysource = prevsources_nodes{ii};
if ~contains(reqsources,mysource)
obj.printlog('Removing algorithm data source %s from %s',mysource,obj.ddname);
ddObj.removeDataSource(prevsources_nodes{ii})
end
end
% add new ones not yet present
mysource = reqsources;
assert(startsWith(mysource,prefix),...
'attempting to add algo dd: %s that does not start with ''%s''-aborting',prefix,mysource);
if contains(prevsources,mysource)
obj.printlog('Not adding node data source %s - already exists',mysource);
else
obj.printlog('Adding node data source %s to %s',mysource,obj.ddname);
ddObj.addDataSource(mysource);
end
end
function updatetemplatetp(obj)
% update wrapper algos
for ii=1:numel(obj.wrappers)
obj.wrappers{ii}.wrapperobj.updatetemplatetp;
end
% update node algos
for ii=1:numel(obj.algos)
if ~isempty(obj.algos(ii))
obj.algos(ii).updatetemplatetp;
end
end
end
function printinfo(obj)
% print wrapper and algo info
fprintf('\nNode%02d, CPUs:%02d, nodename:%s\n',...
obj.nodenr,obj.ncpu,obj.name)
for wrapper = obj.wrappers
fprintf(' CPU %d wrapper: ',wrapper{:}.cpunr);
wrapper{:}.wrapperobj.printinfo;
end
if ~isempty(obj.algos)
fprintf(' Node Algos:\n')
for ii=1:numel(obj.algos)
algo = obj.algos(ii);
fprintf('%s',algo.getname);
end
end
fprintf('\n');
end