-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure_rti_connext_dds.m
194 lines (163 loc) · 7.54 KB
/
configure_rti_connext_dds.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) 2021 Copyright, Real-Time Innovations, Inc. (RTI) All rights reserved. %
% %
% RTI grants Licensee a license to use, modify, compile, and create %
% derivative works of the software solely for use with RTI Connext DDS. %
% Licensee may redistribute copies of the software provided that all such %
% copies are subject to this license. %
% The software is provided "as is", with no warranty of any type, including %
% any warranty for fitness for any purpose. RTI is under no obligation to %
% maintain or support the software. RTI shall not be liable for any %
% incidental or consequential damages arising out of the use or inability to %
% use the software. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function configure_rti_connext_dds()
% CONFIGURE_RTI_CONNEXT_DDS configures all necessary stuff to use
% RTI Connext DDS with MATLAB/Simulink.
% configure_rti_connext_dds() configures RTI Connext DDS
add_configure_nddshome_startup();
configure_nddshome();
% NDDSHOME is set in configure_nddshome() to a supported version
connextVersion = "6.1.2";
connextPath = string(getenv("NDDSHOME"));
shortcutName = append("RTI Launcher ", connextVersion);
create_rti_launcher_shortcut(shortcutName, connextPath, connextVersion);
move_license_file(connextPath)
end
function move_license_file(connextPath)
% MOVE_LICENSE_FILE move the license file from its corresponding
% dependency to RTI Connext DDS dependency
% move_license_file() move the corresponding RTI Connext DDS license
licensePath = rticonnextdds_simulink_ddsblockset.getInstallationLocation(...
"RTI Connext DDS - License");
outputLicenseFilePath = append(connextPath, "/rti_license.dat");
if isfile(outputLicenseFilePath)
warning(['The license file <%s> already exists. Therefore, ',...
'a new license file won''t be copied.\n'],...
outputLicenseFilePath);
else
% There is not license, so it gets copied
licenseFilePath = append(licensePath, "/rti_license.dat");
if isfile(licenseFilePath)
movefile(licenseFilePath,connextPath);
else
warning('No license file under <%s>.\n', licenseFilePath);
end
end
end
function add_configure_nddshome_startup()
% ADD_CONFIGURE_NDDSHOME_STARTUP add if needed the configuration of
% NDDSHME environment variable to the user's startup file.
% add_configure_nddshome_startup() add if needed the configuration of
% NDDSHOME to the startup file
startupFile = fullfile(userpath, 'startup.m');
% Check whether NDDSHOME is already configured
startupText = "";
if isfile(startupFile)
f = fopen(startupFile, 'rt');
if f == -1
error("Error opening <%s> file.", startupFile);
end
startupText = convertCharsToStrings(fread(f, '*char'));
fclose(f);
end
% If NDDSHOME is not configured in the startup script, add it
if ~contains(startupText, "configure_nddshome")
textToAdd = sprintf([
'\n%% Configure NDDSHOME to use RTI Connext for DDS Blockset \n',...
'if exist("configure_nddshome", "file") == 2\n',...
' configure_nddshome();\n',...
'end\n']);
f = fopen(startupFile, 'at');
if f == -1
error("Error opening <%s> file.\n", startupFile);
end
fprintf(f, '%s', textToAdd);
fclose(f);
end
end
function create_rti_launcher_shortcut(shortcutName, connextPath, version)
% CREATE_RTI_LAUNCHER_SHORTCUT Creates a desktop shortcut to
% RTI Launcher independently of the OS.
% create_rti_launcher_shortcut(shortcutName, connextPath, "6.0.1")
% Creates a shortcut called shortcutName, pointing to connextPath
% for the RTI Connext DDS version 6.0.1
if ~exist(connextPath, "dir")
error(['Error creating RTI Launcher shortcut, ',...
'the folder <%s> doesn''t exist.\n'], connextPath);
end
if ismac
create_rti_launcher_shortcut_mac(shortcutName, connextPath);
elseif isunix
create_rti_launcher_shortcut_linux(shortcutName, connextPath, version);
elseif ispc
create_rti_launcher_shortcut_win(shortcutName, connextPath);
else
error("Unsupported OS.");
end
end
function create_rti_launcher_shortcut_win(shortcutName, connextPath)
% CREATE_RTI_LAUNCHER_SHORTCUT_WIN Creates a desktop shortcut to
% RTI Launcher for Windows.
% create_rti_launcher_shortcut(shortcutName, connextPath)
% Creates a shortcut called shortcutName, pointing to connextPath
% Run create_connext_shortcut script to create a desktop shortcut
toolboxPath = regexprep(...
mfilename('fullpath'),...
'(.+)\\configure_rti_connext_dds',...
'$1\\');
system(append(...
'"', toolboxPath, 'bin\create_rti_launcher_shortcut.bat" ',...
'"', shortcutName, '" ',...
'"', connextPath, '"'));
end
function create_rti_launcher_shortcut_linux(shortcutName, connextPath, version)
% CREATE_RTI_LAUNCHER_SHORTCUT_LINUX Creates a desktop shortcut to
% RTI Launcher for Linux.
% create_rti_launcher_shortcut(shortcutName, connextPath, "6.0.1")
% Creates a shortcut called shortcutName, pointing to connextPath
% for the RTI Connext DDS version 6.0.1
% Create the .desktop file
unixShortcut = sprintf([ ...
'[Desktop Entry]\n',...
'Version=%s\n',...
'Name=RTI Launcher\n',...
'GenericName=RTI Launcher\n',...
'Exec="%s/bin/rtilauncher" %%f\n',...
'Terminal=false\n',...
'Hidden=false\n',...
'Icon=%s/resource/app/app_support/launcher/icons/RTI_Launcher_Dock-Icon_256x256.png\n',...
'Type=Application\n',...
'Categories=Development\n',...
'MimeType=application/rti-package\n\n',...
'Name[en_US]=%s'],...
version,... %version
connextPath,... %exec
connextPath,... %icon
shortcutName); %Name[en_US]
launcherPath = append(connextPath, "/rtilauncher.desktop");
f = fopen(launcherPath , 'wt');
if f == -1
error("Error opening <%s> file.\n", launcherPath);
end
fprintf(f, '%s', unixShortcut);
fclose(f);
launcherPath = strrep(launcherPath, ' ', '\ ');
shortcutDesktopName = strrep(append(shortcutName, ".desktop"), ' ', '\ ');
system(append("cp ", launcherPath, " ~/Desktop/", shortcutDesktopName));
% make the shortcut a trusted application
system(append('gio set ~/Desktop/', shortcutDesktopName, ' "metadata::trusted" yes'));
end
function create_rti_launcher_shortcut_mac(shortcutName, connextPath)
% CREATE_RTI_LAUNCHER_SHORTCUT_MAC Creates a desktop shortcut to
% RTI Launcher for MacOS.
% create_rti_launcher_shortcut(shortcutName, connextPath)
% Creates a shortcut called shortcutName
% escape spaces
connextPath = strrep(connextPath, ' ', '\ ');
shortcutName = strrep(shortcutName, ' ', '\ ');
% if the file doesn't exist
if ~isfile(append('~/Desktop/', shortcutName))
system(append("ln -s ", connextPath, "/RTI\ Launcher.app ~/Desktop/", shortcutName));
end
end