-
Notifications
You must be signed in to change notification settings - Fork 8
/
DSPlatformManagementAPI.m
345 lines (291 loc) · 18.1 KB
/
DSPlatformManagementAPI.m
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
192
193
194
195
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
% DSPlatformManagementAPI.m
% This class is an example how to use the dSPACE Platform Management API,
% provided by the dSPACE Python Extensions 1.8.
%
% Copyright 2015 by dSPACE GmbH
classdef DSPlatformManagementAPI < handle
properties
platformManagement;
end
methods
% Constructs a DSPlatformManagementAPI object.
% Creates an active-x COM server for using the DSPlatformManagement API.
function obj = DSPlatformManagementAPI(varargin)
obj.platformManagement = actxserver('DSPlatformManagementAPI2');
obj.RefreshPlatformConnections();
end
% Refreshes the platform connections of the platform management.
% This is necessary for every platform access to get the current platform configuration.
function RefreshPlatformConnections(obj)
obj.platformManagement.RefreshPlatformConfiguration();
end
% Creating platform connection to a single processor board
%
% boardname is the platform identifier (e. g. 'SCALEXIO', 'ds1007', ...)
% boardtype is the platform type (see 'dSPACE_PlatformManagement_Automation_PlatformType.m')
% connectionType is the platform connection type (see 'dSPACE_PlatformManagement_Automation_InterfaceConnectionType.m')
% portAddress is the port address of the board (e. g. 0 for SCALEXIO, 0x300 for ds1005, ...)
% ipAddresses are the ip addresses of the board (e. g. {'10.0.0.1'}, ...)
function CreatePlatformConnection(obj, boardName, boardType, connectionType, portAddress, ipAddresses)
if (~isempty(strfind(lower(boardName), 'multiprocessor')))
throw(MException('DSPlatformManagementAPI:CreatePlatformConnection', 'Use "CreateMultiprocessorConnection" for a Multiprocessor platform'));
end
try
% check whether the platform is already registered
usedPlatform = GetUsedPlatform(obj, boardName);
if (isempty(usedPlatform))
% platform not found - register it
% create an registration information for the given board type
switch (boardType)
case {dSPACE_PlatformManagement_Automation_PlatformType.SCALEXIO}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.SCALEXIO));
case {dSPACE_PlatformManagement_Automation_PlatformType.DS1005}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.DS1005));
case {dSPACE_PlatformManagement_Automation_PlatformType.DS1006}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.DS1006));
case {dSPACE_PlatformManagement_Automation_PlatformType.DS1007}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.DS1007));
case {dSPACE_PlatformManagement_Automation_PlatformType.DS1103}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.DS1103));
case {dSPACE_PlatformManagement_Automation_PlatformType.DS1104}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.DS1104));
case {dSPACE_PlatformManagement_Automation_PlatformType.MABX}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.MABX));
case {dSPACE_PlatformManagement_Automation_PlatformType.DS1202}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.DS1202));
case {dSPACE_PlatformManagement_Automation_PlatformType.VEOS}
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.VEOS));
otherwise
throw(MException('DSPlatformManagementAPI:CreatePlatformConnection', ['Unsupported board type: ', boardType]));
end
if ( (boardType ~= dSPACE_PlatformManagement_Automation_PlatformType.DS1007) ...
&& (boardType ~= dSPACE_PlatformManagement_Automation_PlatformType.DS1202) ...
&& (boardType ~= dSPACE_PlatformManagement_Automation_PlatformType.SCALEXIO) ...
&& (boardType ~= dSPACE_PlatformManagement_Automation_PlatformType.VEOS))
if (boardType ~= dSPACE_PlatformManagement_Automation_PlatformType.MABX)
registrationInfo.ConnectionType = connectionType;
end
registrationInfo.PortAddress = portAddress;
registrationInfo.NetClient = char(ipAddresses(1));
else
for ipAddress = ipAddresses
childInfo = registrationInfo.RegistrationInfos.Add();
childInfo.IPAddress = char(ipAddress);
end
end
obj.platformManagement.RegisterPlatform(registrationInfo);
end
catch e
rethrow(e);
end
end
% Creating platform connection to a multiprocessor board
%
% boardname is the platform identifier (e. g. 'Multiprocessor', ...)
% boardtype is the subplatform type (see 'dSPACE_PlatformManagement_Automation_PlatformType.m')
% connectionType is the platform connection type (see 'dSPACE_PlatformManagement_Automation_InterfaceConnectionType.m')
% portAddress is the port address of the board (e. g. 0x300 for ds1005, ...)
% ipAddress is the ip address of the board (e. g. '10.0.0.1', ...)
% numMemberApplications is the number of member applications of the multiprocessor system
function CreateMultiprocessorConnection(obj, boardName, boardType, connectionType, portAddress, ipAddress, numMemberApplications)
if (isempty(strfind(lower(boardName), 'multiprocessor')))
throw(MException('DSPlatformManagementAPI:CreatePlatformConnection', 'Use "CreatePlatformConnection" for everything else except Multiprocessor'));
end
try
% check whether the platform is already registered
usedPlatform = GetUsedPlatform(obj, boardName);
if (isempty(usedPlatform))
% platform not found - register it
registrationInfo = obj.platformManagement.CreatePlatformRegistrationInfo(uint32(dSPACE_PlatformManagement_Automation_PlatformType.MultiProcessor));
registrationInfo.ConnectionType = connectionType;
registrationInfo.NetClient = ipAddress;
% register each member
for appIndex = (0:numMemberApplications - 1)
platformInfo = [];
switch (boardType)
case {dSPACE_PlatformManagement_Automation_PlatformType.DS1005}
platformInfo = registrationInfo.Add(uint32(dSPACE_PlatformManagement_Automation_PlatformType.DS1005));
case {dSPACE_PlatformManagement_Automation_PlatformType.DS1006}
platformInfo = registrationInfo.Add(uint32(dSPACE_PlatformManagement_Automation_PlatformType.DS1006));
otherwise
throw(MException('DSPlatformManagementAPI:CreateMultiprocessorConnection', ['Unsupported board type: ', boardType]));
end
% calculate port address with the given start address, e. g. starting at 0x300, next value is 0x310
platformInfo.PortAddress = portAddress + (appIndex * 16);
clear platformInfo;
end
if (registrationInfo.RegisterInfos.Count > 0)
obj.platformManagement.RegisterPlatform(registrationInfo);
end
end
catch e
rethrow(e);
end
end
% Loading an application to a specific platform
%
% sdfFilePath is the path to the application, which will be loaded (e. g. 'C:\test.sdf')
% platformIdentifier is the name of the platform, where the application will be loaded
function LoadApplicationSdfFile(obj, sdfFilePath, platformIdentifier)
try
% check whether the platform is registered
usedPlatform = GetUsedPlatform(obj, platformIdentifier);
if (isempty(usedPlatform))
throw(MException('DSPlatformManagementAPI:LoadApplicationSdfFile', ['Cannot find platform: ', platformIdentifier]));
else
usedPlatform.LoadRealtimeApplication(sdfFilePath);
end
catch e
rethrow(e);
end
end
% Starts the application on the given platform
%
% platformIdenifier is the name of the platform (e. g. 'SCALEXIO', 'ds1005', ...)
function StartApplication(obj, platformIdentifier)
try
% check whether the platform is registered
usedPlatform = GetUsedPlatform(obj, platformIdentifier);
if (isempty(usedPlatform))
throw(MException('DSPlatformManagementAPI:StartApplication', ['Cannot find platform: ', platformIdentifier]));
else
% check whether the system is single- or multiprocessor
if (~isempty(usedPlatform.RealTimeApplication))
if ( obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.DS1007) ...
&& obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.DS1202) ...
&& obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.SCALEXIO) ...
&& obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.VEOS))
% check if the application is already running
if (obj.CompareApplicationState(usedPlatform.RealTimeApplication.State, dSPACE_PlatformManagement_Automation_ApplicationState.Running))
usedPlatform.RealTimeApplication.Start();
end
else
usedPlatform.LoadRealtimeApplication(usedPlatform.RealTimeApplication.FullPath);
end
else
throw(MException('DSPlatformManagementAPI:StartApplication', ['Cannot find real time application on platform: ', platformIdentifier]));
end
end
catch e
rethrow(e);
end
end
% Stops the application on the given platform
%
% platformIdenifier is the name of the platform (e. g. 'SCALEXIO', 'ds1005', ...)
function StopApplication(obj, platformIdentifier)
try
% check whether the platform is registered
usedPlatform = GetUsedPlatform(obj, platformIdentifier);
if (isempty(usedPlatform))
throw(MException('DSPlatformManagementAPI:StartApplication', ['Cannot find platform: ', platformIdentifier]));
else
% check whether the system has a application to stop
% and check for multiprocessor
if (~isempty(usedPlatform.RealTimeApplication))
if ( obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.DS1007) ...
&& obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.DS1202) ...
&& obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.SCALEXIO) ...
&& obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.VEOS))
if (obj.CompareApplicationState(usedPlatform.RealTimeApplication.State, dSPACE_PlatformManagement_Automation_ApplicationState.Stopped))
usedPlatform.RealTimeApplication.Stop();
end
else
usedPlatform.StopRTP();
end
else
throw(MException('DSPlatformManagementAPI:StartApplication', ['Cannot find real time application on platform: ', platformIdentifier]));
end
end
catch e
rethrow(e);
end
end
% Gets the application informations on the given platform
%
% platformIdenifier is the name of the platform (e. g. 'SCALEXIO', 'ds1005', ...)
function applicationInfo = GetApplInfo(obj, platformIdentifier)
applicationInfo = [];
% check whether the platform is registered
usedPlatform = GetUsedPlatform(obj, platformIdentifier);
if (isempty(usedPlatform))
throw(MException('DSPlatformManagementAPI:GetApplInfo', ['Cannot find platform: ', platformIdentifier]));
else
% check for application
if (~isempty(usedPlatform.RealTimeApplication))
applicationInfo = struct('name', usedPlatform.RealTimeApplication.Name, ...
'date', usedPlatform.RealTimeApplication.BuildDateTime, ...
'board', usedPlatform.UniqueName, ...
'type', usedPlatform.Type);
end
end
end
% Gets all platform informations which are currently registered
function boardInfo = GetBoardInfo(obj)
boardInfo = [];
% refresh platform connections to get all current platforms
obj.RefreshPlatformConnections();
% get all registered platforms
platforms = obj.platformManagement.Platforms;
if (platforms.Count ~= 0)
% iterate over platforms and get the board information
for platformIndex = (0:platforms.Count - 1)
platform = platforms.Item(int32(platformIndex));
tempInfos{platformIndex + 1} = struct('name', platform.UniqueName, ...
'type', platform.Type);
end
boardInfo = cell2mat(tempInfos);
end
end
% Checks whether the application is running on the given platform
%
% platformIdenifier is the name of the platform (e. g. 'SCALEXIO', 'ds1005', ...)
function running = IsApplRunning(obj, platformIdentifier)
running = false;
% check whether the platform is registered
usedPlatform = GetUsedPlatform(obj, platformIdentifier);
if (isempty(usedPlatform))
throw(MException('DSPlatformManagementAPI:GetApplInfo', ['Cannot find platform: ', platformIdentifier]));
else
% check for application
if (~isempty(usedPlatform.RealTimeApplication))
running = true;
% check for SCALEXIO, only platform that supports a state to check
if (obj.ComparePlatformType(usedPlatform.Type, dSPACE_PlatformManagement_Automation_PlatformType.SCALEXIO))
if (obj.CompareApplicationState(usedPlatform.RealTimeApplication.State, dSPACE_PlatformManagement_Automation_ApplicationState.Running))
running = true;
else
running = false;
end
end
end
end
end
end
methods (Access = private)
function usedPlatform = GetUsedPlatform(obj, platformIdentifier)
usedPlatform = [];
% refresh interface connections
obj.RefreshPlatformConnections();
% get all registered platforms
platforms = obj.platformManagement.Platforms;
if (platforms.Count ~= 0)
% iterate over platforms
for platformIndex = (0:platforms.Count - 1)
platform = platforms.Item(int32(platformIndex));
% check platform name
if (strcmpi(platform.UniqueName, platformIdentifier))
usedPlatform = platform;
break;
end
end
end
end
function result = ComparePlatformType(obj, apiType, enumType)
result = strcmpi(apiType, ['PlatformType_', char(enumType)]);
end
function result = CompareApplicationState(obj, apiState, enumState)
result = strcmpi(apiState, ['ApplicationState_', char(enumState)]);
end
end
end