|
161 | 161 | % TO DO: should IDEALLY raise error if first line doesn't start with ; (header) |
162 | 162 |
|
163 | 163 | if size(section_text,1) == 1 |
164 | | - % EXIT< no cybernodes has been defined |
| 164 | + % EXIT< no cybernodes have been defined |
165 | 165 | error('ERROR: no cybernodes defined in %s. Did you include the header for this section?', cpaFile) |
166 | 166 | end |
167 | 167 |
|
|
196 | 196 | temp(nsep+1:3) = length(section_text{j}); |
197 | 197 | end |
198 | 198 |
|
199 | | - % get sensors... |
200 | | - sensors = strtrim(section_text{j}(temp(1):temp(2))); |
201 | | - |
202 | | - if ~isempty(sensors) |
203 | | - sensors = regexp(sensors,',','split'); |
204 | | - end |
205 | | - |
206 | | - for k = 1 : numel(sensors) |
207 | | - thisNode.sensors(k) = strtrim(sensors(k)); |
208 | | - end |
| 199 | + % get sensors... |
| 200 | + sensors = section_text{j}(temp(1):temp(2)); |
| 201 | + thisNode.sensors = strsplit(sensors(~isspace(sensors)),','); |
209 | 202 |
|
210 | 203 | % ... actuators... |
211 | | - if temp(2) ~= length(section_text{j}) |
212 | | - actuators = strtrim(section_text{j}(temp(2):end)); |
213 | | - if ~isempty(actuators) |
214 | | - actuators = regexp(actuators,',','split'); |
215 | | - end |
216 | | - |
217 | | - for k = 1 : numel(actuators) |
218 | | - thisNode.actuators(k) = strtrim(actuators(k)); |
219 | | - end |
220 | | - end |
| 204 | + actuators = section_text{j}(temp(2):end); |
| 205 | + thisNode.actuators = strsplit(actuators(~isspace(actuators)),','); |
221 | 206 |
|
222 | 207 | % concatenate |
223 | 208 | cybernodes = cat(1,cybernodes,thisNode); |
|
226 | 211 | end |
227 | 212 |
|
228 | 213 | case 'CYBERLINKS' |
229 | | - warning('THIS WILL BE REMOVED!') |
| 214 | + |
| 215 | + if size(section_text,1) == 1 |
| 216 | + % EXIT< no cyberlinks have been defined |
| 217 | + error('ERROR: no cyberlinks defined in %s. Did you include the header for this section?', cpaFile) |
| 218 | + end |
| 219 | + |
| 220 | + % initialize array of cyberlinks |
| 221 | + cyberlinks = []; |
| 222 | + % loop through all cybernodes |
| 223 | + for j = 2 : size(section_text,1) |
| 224 | + |
| 225 | + % check if comment first... |
| 226 | + temp = strtrim(section_text{j}); |
| 227 | + if temp(1)~= ';' |
| 228 | + % get \t separator positions |
| 229 | + temp = regexp(section_text{j},'\t'); |
| 230 | + nsep = numel(temp); |
| 231 | + if isempty(temp) |
| 232 | + error('Cyberlink string %d in %s file has no details.', j-1, self.cpaFile); |
| 233 | + elseif nsep > 2 |
| 234 | + error('Problem with format of cyberlink string %d in %s file. Check README.md',... |
| 235 | + j-1, self.cpaFile); |
| 236 | + else |
| 237 | + |
| 238 | + % initialize cybernode struct |
| 239 | + thisLink.sender = strtrim(section_text{j}(1:temp(1))); |
| 240 | + thisLink.receiver = strtrim(section_text{j}(temp(1):temp(2))); |
| 241 | + thisLink.signals = strsplit(strtrim(section_text{j}(temp(2):end)),','); |
| 242 | + |
| 243 | + % concatenate |
| 244 | + cyberlinks = cat(1,cyberlinks,thisLink); |
| 245 | + end |
| 246 | + end |
| 247 | + end |
230 | 248 |
|
231 | 249 | case 'CYBERATTACKS' |
232 | 250 | % TO DO: should IDEALLY raise error if first line doesn't start with ; (header) |
|
0 commit comments