1 | function varargout = tango_archiving_config(varargin) |
---|
2 | % TANGO_ARCHIVING_CONFIG M-file for tango_archiving_config.fig |
---|
3 | % TANGO_ARCHIVING_CONFIG, by itself, creates a new TANGO_ARCHIVING_CONFIG or raises the existing |
---|
4 | % singleton*. |
---|
5 | % |
---|
6 | % H = TANGO_ARCHIVING_CONFIG returns the handle to a new TANGO_ARCHIVING_CONFIG or the handle to |
---|
7 | % the existing singleton*. |
---|
8 | % |
---|
9 | % TANGO_ARCHIVING_CONFIG('CALLBACK',hObject,eventData,handles,...) calls the local |
---|
10 | % function named CALLBACK in TANGO_ARCHIVING_CONFIG.M with the given input arguments. |
---|
11 | % |
---|
12 | % TANGO_ARCHIVING_CONFIG('Property','Value',...) creates a new TANGO_ARCHIVING_CONFIG or raises the |
---|
13 | % existing singleton*. Starting from the left, property value pairs are |
---|
14 | % applied to the GUI before tango_archiving_config_OpeningFunction gets called. An |
---|
15 | % unrecognized property name or invalid value makes property application |
---|
16 | % stop. All inputs are passed to tango_archiving_config_OpeningFcn via varargin. |
---|
17 | % |
---|
18 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one |
---|
19 | % instance to run (singleton)". |
---|
20 | % |
---|
21 | % See also: GUIDE, GUIDATA, GUIHANDLES |
---|
22 | |
---|
23 | % Copyright 2002-2003 The MathWorks, Inc. |
---|
24 | |
---|
25 | % Edit the above text to modify the response to help tango_archiving_config |
---|
26 | |
---|
27 | % Last Modified by GUIDE v2.5 07-Apr-2005 09:47:11 |
---|
28 | |
---|
29 | % Begin initialization code - DO NOT EDIT |
---|
30 | gui_Singleton = 1; |
---|
31 | gui_State = struct('gui_Name', mfilename, ... |
---|
32 | 'gui_Singleton', gui_Singleton, ... |
---|
33 | 'gui_OpeningFcn', @tango_archiving_config_OpeningFcn, ... |
---|
34 | 'gui_OutputFcn', @tango_archiving_config_OutputFcn, ... |
---|
35 | 'gui_LayoutFcn', [] , ... |
---|
36 | 'gui_Callback', []); |
---|
37 | if nargin && ischar(varargin{1}) |
---|
38 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
39 | end |
---|
40 | |
---|
41 | if nargout |
---|
42 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
43 | else |
---|
44 | gui_mainfcn(gui_State, varargin{:}); |
---|
45 | end |
---|
46 | % End initialization code - DO NOT EDIT |
---|
47 | |
---|
48 | % |
---|
49 | % Written by Laurent S. Nadolski |
---|
50 | |
---|
51 | |
---|
52 | % --- Executes just before tango_archiving_config is made visible. |
---|
53 | function tango_archiving_config_OpeningFcn(hObject, eventdata, handles, varargin) |
---|
54 | % This function has no output args, see OutputFcn. |
---|
55 | % hObject handle to figure |
---|
56 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
57 | % handles structure with handles and user data (see GUIDATA) |
---|
58 | % varargin command line arguments to tango_archiving_config (see VARARGIN) |
---|
59 | |
---|
60 | % Choose default command line output for tango_archiving_config |
---|
61 | handles.output = hObject; |
---|
62 | |
---|
63 | % Update handles structure |
---|
64 | guidata(hObject, handles); |
---|
65 | |
---|
66 | % UIWAIT makes tango_archiving_config wait for user response (see UIRESUME) |
---|
67 | % uiwait(handles.figure1); |
---|
68 | |
---|
69 | disp('TANGO Archiving Configurator'); |
---|
70 | |
---|
71 | %% Look for archiving manager TANGO name in static Database |
---|
72 | archivingmanager = cell2mat(tango_get_db_property('archivage','archivingmanager')); |
---|
73 | tango_set_timeout(archivingmanager,30000); |
---|
74 | |
---|
75 | setappdata(handles.figure1,'archivingmanager', archivingmanager); |
---|
76 | |
---|
77 | %% Initialize database {HDB} and machine {LT1} |
---|
78 | handles.database='HDB'; |
---|
79 | guidata(hObject, handles); |
---|
80 | |
---|
81 | hdbmenu_Callback(hObject, eventdata, handles); |
---|
82 | uimenu_anneau_Callback(handles.uimenu_LT1, eventdata, handles); |
---|
83 | |
---|
84 | % Update handles structure |
---|
85 | guidata(hObject, handles); |
---|
86 | |
---|
87 | % --- Outputs from this function are returned to the command line. |
---|
88 | function varargout = tango_archiving_config_OutputFcn(hObject, eventdata, handles) |
---|
89 | % varargout cell array for returning output args (see VARARGOUT); |
---|
90 | % hObject handle to figure |
---|
91 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
92 | % handles structure with handles and user data (see GUIDATA) |
---|
93 | |
---|
94 | % Get default command line output from handles structure |
---|
95 | varargout{1} = handles.output; |
---|
96 | |
---|
97 | % --- Executes on selection change in popupmenu_group. |
---|
98 | function popupmenu_group_Callback(hObject, eventdata, handles) |
---|
99 | % hObject handle to popupmenu_group (see GCBO) |
---|
100 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
101 | % handles structure with handles and user data (see GUIDATA) |
---|
102 | |
---|
103 | % Hints: contents = get(hObject,'String') returns popupmenu_group contents as cell array |
---|
104 | % contents{get(hObject,'Value')} returns selected item from popupmenu_group |
---|
105 | |
---|
106 | contents = get(hObject,'String'); |
---|
107 | num = get(hObject,'Value'); |
---|
108 | group = contents{num}; |
---|
109 | |
---|
110 | setappdata(handles.figure1,'group', group); |
---|
111 | |
---|
112 | AO = getappdata(handles.figure1,'AO'); |
---|
113 | |
---|
114 | % Status one devices |
---|
115 | valid = find(AO.(group).Status); |
---|
116 | |
---|
117 | % Update Group list |
---|
118 | set(handles.listbox_group,'String',AO.(group).DeviceName(valid)); |
---|
119 | |
---|
120 | set(handles.popupmenu_command,'BackgroundColor','red'); |
---|
121 | |
---|
122 | % Builds up attribut list for selected group |
---|
123 | attributeList = tango_get_attribute_list(AO.(group).DeviceName{valid(1)}); |
---|
124 | |
---|
125 | num = get(handles.popupmenu_attribute,'Value'); |
---|
126 | if num > length(attributeList) |
---|
127 | num = 1; |
---|
128 | set(handles.popupmenu_attribute,'Value',num); |
---|
129 | end |
---|
130 | set(handles.popupmenu_attribute,'String',attributeList); |
---|
131 | |
---|
132 | popupmenu_attribute_Callback(handles.popupmenu_attribute, eventdata, handles); |
---|
133 | |
---|
134 | %setback selected element and property to first one |
---|
135 | set(handles.listbox_property,'Value',1); |
---|
136 | set(handles.listbox_group,'Value',1); |
---|
137 | |
---|
138 | |
---|
139 | % Update handles structure |
---|
140 | guidata(hObject, handles); |
---|
141 | |
---|
142 | % --- Executes during object creation, after setting all properties. |
---|
143 | function popupmenu_group_CreateFcn(hObject, eventdata, handles) |
---|
144 | % hObject handle to popupmenu_group (see GCBO) |
---|
145 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
146 | % handles empty - handles not created until after all CreateFcns called |
---|
147 | |
---|
148 | % Hint: popupmenu controls usually have a white background on Windows. |
---|
149 | % See ISPC and COMPUTER. |
---|
150 | if ispc |
---|
151 | set(hObject,'BackgroundColor','white'); |
---|
152 | else |
---|
153 | set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); |
---|
154 | end |
---|
155 | |
---|
156 | |
---|
157 | % --- Executes on selection change in popupmenu_attribute. |
---|
158 | function popupmenu_attribute_Callback(hObject, eventdata, handles) |
---|
159 | % hObject handle to popupmenu_attribute (see GCBO) |
---|
160 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
161 | % handles structure with handles and user data (see GUIDATA) |
---|
162 | |
---|
163 | % Hints: contents = get(hObject,'String') returns popupmenu_attribute contents as cell array |
---|
164 | % contents{get(hObject,'Value')} returns selected item from popupmenu_attribute |
---|
165 | |
---|
166 | contents = get(hObject,'String'); |
---|
167 | num = get(hObject,'Value'); |
---|
168 | attribute = contents{num}; |
---|
169 | |
---|
170 | setappdata(handles.figure1,'attribute', attribute); |
---|
171 | |
---|
172 | % --- Executes during object creation, after setting all properties. |
---|
173 | function popupmenu_attribute_CreateFcn(hObject, eventdata, handles) |
---|
174 | % hObject handle to popupmenu_attribute (see GCBO) |
---|
175 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
176 | % handles empty - handles not created until after all CreateFcns called |
---|
177 | |
---|
178 | % Hint: popupmenu controls usually have a white background on Windows. |
---|
179 | % See ISPC and COMPUTER. |
---|
180 | if ispc |
---|
181 | set(hObject,'BackgroundColor','white'); |
---|
182 | else |
---|
183 | set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); |
---|
184 | end |
---|
185 | |
---|
186 | |
---|
187 | % --- Executes on selection change in popupmenu_command. |
---|
188 | function popupmenu_command_Callback(hObject, eventdata, handles) |
---|
189 | % hObject handle to popupmenu_command (see GCBO) |
---|
190 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
191 | % handles structure with handles and user data (see GUIDATA) |
---|
192 | |
---|
193 | % Hints: contents = get(hObject,'String') returns popupmenu_command contents as cell array |
---|
194 | % contents{get(hObject,'Value')} returns selected item from popupmenu_command |
---|
195 | |
---|
196 | %% Set color to Green |
---|
197 | set(handles.popupmenu_command,'BackgroundColor','green'); |
---|
198 | |
---|
199 | contents = get(hObject,'String'); |
---|
200 | num = get(hObject,'Value'); |
---|
201 | command = contents{num}; |
---|
202 | |
---|
203 | setappdata(handles.figure1,'command', command); |
---|
204 | |
---|
205 | group = getappdata(handles.figure1,'group'); |
---|
206 | attribute = getappdata(handles.figure1,'attribute'); |
---|
207 | AO = getappdata(handles.figure1,'AO'); |
---|
208 | |
---|
209 | % Status one devices |
---|
210 | valid = find(AO.(group).Status); |
---|
211 | |
---|
212 | % Construct DeviceName/AttributName list |
---|
213 | %host = getenv('TANGO_HOST'); %% TODO PAS PROPRE mais pour rester conforme avec archiving |
---|
214 | %fullTangoNames = strcat('//',host,'/',AO.(group).DeviceName(valid), '/', attribute); |
---|
215 | fullTangoNames = strcat(AO.(group).DeviceName(valid), '/', attribute); |
---|
216 | archivingmanager = getappdata(handles.figure1,'archivingmanager'); |
---|
217 | |
---|
218 | if (get(handles.checkbox_all,'Value') == 0) |
---|
219 | %% Get selected element |
---|
220 | idx = get(handles.listbox_property,'Value'); |
---|
221 | fullTangoNamesV = fullTangoNames(idx); |
---|
222 | else % All the same |
---|
223 | fullTangoNamesV = fullTangoNames'; |
---|
224 | end |
---|
225 | |
---|
226 | % Select database |
---|
227 | switch handles.database |
---|
228 | case 'HDB' |
---|
229 | command = [command 'Hdb']; |
---|
230 | case 'TDB' |
---|
231 | command = [command 'Tdb']; |
---|
232 | end |
---|
233 | |
---|
234 | % switchyard on commands |
---|
235 | switch command(1:end-3) |
---|
236 | case {'IsArchived'} % check archiving state |
---|
237 | argin = fullTangoNames'; |
---|
238 | list = tango_command_inout2(archivingmanager,command,argin)'; |
---|
239 | set(handles.listbox_property,'String',list); |
---|
240 | |
---|
241 | case {'GetArchivingMode'} % Get archiving mode |
---|
242 | list = []; |
---|
243 | for k = 1:length(fullTangoNames) |
---|
244 | argin = fullTangoNames{k}; |
---|
245 | answer = tango_command_inout2(archivingmanager,command,argin); |
---|
246 | list = [list ; format_output_list(answer)]; |
---|
247 | end |
---|
248 | |
---|
249 | %% Format data for fast print out |
---|
250 | Name = strcat(AO.(group).DeviceName(valid), '/', attribute); |
---|
251 | [n1 n2] = size(list); |
---|
252 | Strcell = cell(n2+1,n1); |
---|
253 | Strcell(end,:) = Name; |
---|
254 | Strcell(1:end-1,:) = num2cell(list'); |
---|
255 | |
---|
256 | %% TODO: location for file, check fopen is OK |
---|
257 | directory = getfamilydata('Directory','Archiving'); |
---|
258 | filename = [directory 'summarymodedata.txt']; |
---|
259 | %filename = tempname; |
---|
260 | [fid message] = fopen(filename,'w'); |
---|
261 | if fid == -1 |
---|
262 | message |
---|
263 | return; |
---|
264 | end |
---|
265 | |
---|
266 | fprintf(fid,['# ',handles.database ' DATABASE: File generated on' ... |
---|
267 | ' %s\n'],datestr(now)); |
---|
268 | fprintf(fid,['# Periodic Mode Absolute Mode ' ... |
---|
269 | ' Relative Mode TANGO attribute Name \n']); |
---|
270 | fprintf(fid,['# T(s) T(s) min max ' ... |
---|
271 | 'T(s) min max \n']); |
---|
272 | fprintf(fid,' %7.1f %7.1f %8.2f %8.2f %7.1f %8.2f %8.2f %s\n',Strcell{:}); |
---|
273 | fclose(fid); |
---|
274 | |
---|
275 | % edit 'modedata.txt' |
---|
276 | if isunix |
---|
277 | system(['nedit ', filename, ' &']); % much faster |
---|
278 | % eval(['edit ' filename]) |
---|
279 | else |
---|
280 | eval(['edit ' filename]) |
---|
281 | end |
---|
282 | |
---|
283 | case {'ArchivingStart'}% Start archiving |
---|
284 | |
---|
285 | %% Selects archiving mode |
---|
286 | mode = archiving_panel_mode(handles.database); |
---|
287 | |
---|
288 | if isstruct(mode) % means not canceled |
---|
289 | %% Build up the argument for sIntermediatetarting archiving |
---|
290 | %% Check for different modes selected by user |
---|
291 | argin = BuildArgin(fullTangoNamesV, mode,handles); |
---|
292 | |
---|
293 | if isnumeric(argin) && argin == -1 |
---|
294 | disp('No Archiving mode selected, does nothing'); |
---|
295 | return; |
---|
296 | end |
---|
297 | |
---|
298 | start_archiving(archivingmanager,command,argin,handles); |
---|
299 | |
---|
300 | %% Force a IsArchived call to check if everything as |
---|
301 | %% expected |
---|
302 | set(handles.popupmenu_command,'Value',1); |
---|
303 | popupmenu_command_Callback(hObject, eventdata, handles); |
---|
304 | end |
---|
305 | |
---|
306 | case {'ArchivingStop'}% Stop archiving |
---|
307 | argin = fullTangoNamesV'; |
---|
308 | error = tango_command_inout2(archivingmanager,command,argin); |
---|
309 | display_archiving_error(error,handles); |
---|
310 | |
---|
311 | set(handles.popupmenu_command,'Value',1); |
---|
312 | popupmenu_command_Callback(hObject, eventdata, handles); |
---|
313 | |
---|
314 | case {'ArchivingModif'}% Get archiving mode |
---|
315 | list = []; % clear list |
---|
316 | % build list |
---|
317 | for k = 1:length(fullTangoNamesV) % length(fullTangoNames) % Get the first one if a list |
---|
318 | argin = fullTangoNamesV{k}; |
---|
319 | answer = tango_command_inout2(archivingmanager,['GetArchivingMode' command(end-2:end)],argin); |
---|
320 | list = [list ; format_output_list(answer)]; |
---|
321 | end |
---|
322 | |
---|
323 | % Selects archiving mode |
---|
324 | % List contains existing archiving modes to be modified |
---|
325 | mode = archiving_panel_mode(handles.database,list); |
---|
326 | |
---|
327 | if isstruct(mode) % means not canceled |
---|
328 | |
---|
329 | %% Build up the argument for starting archiving |
---|
330 | %% Check for different modes selected by user |
---|
331 | argin = BuildArgin(fullTangoNamesV, mode,handles); |
---|
332 | |
---|
333 | start_archiving(archivingmanager,command,argin,handles); |
---|
334 | |
---|
335 | %% Force a IsArchived call to check if everything as |
---|
336 | %% expected |
---|
337 | set(handles.popupmenu_command,'Value',1); |
---|
338 | popupmenu_command_Callback(hObject, eventdata, handles); |
---|
339 | end |
---|
340 | |
---|
341 | otherwise |
---|
342 | disp('Command not implemented') |
---|
343 | end |
---|
344 | |
---|
345 | % Update handles structure |
---|
346 | guidata(handles.figure1, handles); |
---|
347 | |
---|
348 | |
---|
349 | function argin = BuildArgin(fullTangoNames, mode, handles) |
---|
350 | % Build up the argument for starting archiving |
---|
351 | % Check for different modes selected by user |
---|
352 | |
---|
353 | [temp ismodeselected] = findkeyword(mode.selection,'1'); |
---|
354 | if ismodeselected == 0 % no mode selected |
---|
355 | argin = -1; |
---|
356 | return; |
---|
357 | |
---|
358 | elseif ismodeselected == 1 % at least an archiving mode selected |
---|
359 | |
---|
360 | %Load balancing |
---|
361 | |
---|
362 | %% standard header |
---|
363 | % 1. archiver name for load balancing feature |
---|
364 | % 2. group feature true or false (not implemented to the end) |
---|
365 | switch mode.grouped |
---|
366 | case '0' |
---|
367 | header = {'toto', 'false'}; |
---|
368 | case '1' |
---|
369 | % Force to flase since not yet implemented in matlab gui |
---|
370 | header = {'toto', 'false'}; |
---|
371 | % header = {'toto', 'true'}; |
---|
372 | end |
---|
373 | |
---|
374 | %% Not required fields set to default values |
---|
375 | % 1. data type |
---|
376 | % 2. data format |
---|
377 | % 3. writable |
---|
378 | % 4. device in charge |
---|
379 | % 5. Trigger time |
---|
380 | |
---|
381 | header_attribute = { '0', '0', '0', '','NULL'}; |
---|
382 | |
---|
383 | % header length for each attribut |
---|
384 | % depends on the mode selection |
---|
385 | len = 6; |
---|
386 | len_mode = 0; |
---|
387 | |
---|
388 | % number of attributes to archive |
---|
389 | nb = length(fullTangoNames); |
---|
390 | |
---|
391 | % mode parametrization |
---|
392 | mode_P ={}; |
---|
393 | mode_A ={}; |
---|
394 | mode_R ={}; |
---|
395 | mode_string = {}; |
---|
396 | |
---|
397 | if str2double(mode.selection{1}) == 1 %% Periodic mode |
---|
398 | len = len + 3; |
---|
399 | len_mode = len_mode + 2; |
---|
400 | if strcmpi(handles.database,'HDB') |
---|
401 | mode.periodic.period = [mode.periodic.period '000']; % ms |
---|
402 | end |
---|
403 | mode_P = {'MODE_P', mode.periodic.period}; |
---|
404 | end |
---|
405 | |
---|
406 | if str2double(mode.selection{2}) == 1 % Absolute mode |
---|
407 | len = len + 4; |
---|
408 | len_mode = len_mode + 4; |
---|
409 | if strcmpi(handles.database,'HDB') |
---|
410 | mode.absolute.period = [mode.absolute.period '000']; % ms |
---|
411 | end |
---|
412 | mode_A = {'MODE_A', mode.absolute.period,... |
---|
413 | mode.absolute.lowerlimit, mode.absolute.upperlimit}; |
---|
414 | end |
---|
415 | |
---|
416 | if str2double(mode.selection{3}) == 1 %Relative mode |
---|
417 | len = len + 4; |
---|
418 | len_mode = len_mode + 4; |
---|
419 | if strcmpi(handles.database,'HDB') |
---|
420 | mode.relative.period = [mode.relative.period '000']; % ms |
---|
421 | end |
---|
422 | mode_R = {'MODE_R', mode.relative.period,... |
---|
423 | mode.relative.lowerlimit,mode.relative.upperlimit}; |
---|
424 | end |
---|
425 | |
---|
426 | mode_string = {mode_P{:}, mode_R{:}, mode_A{:}}; |
---|
427 | |
---|
428 | switch handles.database %% Select database |
---|
429 | case 'TDB' %% Intermediate DATABASE |
---|
430 | len = len +3; |
---|
431 | len_mode = len_mode + 3; |
---|
432 | mode_string = {mode_string{:}, 'TDB_SPEC', ... |
---|
433 | mode.exportwindow, mode.keepingwindow}; |
---|
434 | case 'HDB' %% Historical DATABASE |
---|
435 | % No extra arguments |
---|
436 | end |
---|
437 | |
---|
438 | argin = header; |
---|
439 | |
---|
440 | % loop over list of attributed to be archived |
---|
441 | for k = 1:nb |
---|
442 | argin = {argin{:}, num2str(len), fullTangoNames{k}, ... |
---|
443 | header_attribute{:}, num2str(len_mode), mode_string{:}}; |
---|
444 | end |
---|
445 | |
---|
446 | end |
---|
447 | |
---|
448 | function start_archiving(archivingmanager,command,argin,handles) |
---|
449 | % START_ARCHIVING - Start or modify an archiving |
---|
450 | % |
---|
451 | % INPUTS |
---|
452 | % archivingmanager - TANGO name of the archiving manager |
---|
453 | % command - start or modify archiving, could be |
---|
454 | % - ArchivingStart |
---|
455 | % - ArchivingModif |
---|
456 | % - ArchivingStartIntermediate |
---|
457 | % - ArchivingModifIntermediate |
---|
458 | % argin - inputs arguments related to command (see archivingmanager doc ) |
---|
459 | % |
---|
460 | error = tango_command_inout2(archivingmanager,command,argin); |
---|
461 | |
---|
462 | display_archiving_error(error,handles); |
---|
463 | |
---|
464 | function display_archiving_error(error,handles) |
---|
465 | %DISPLAY_ARCHIVING_ERROR - Display error reason |
---|
466 | % Errorhandler |
---|
467 | % See archivingmanager documentation for details |
---|
468 | |
---|
469 | switch error |
---|
470 | case 0 |
---|
471 | %% start succeeded |
---|
472 | return; |
---|
473 | case 1 |
---|
474 | disp('All the given attribute already archiving process') |
---|
475 | case 2 |
---|
476 | disp('start failed') |
---|
477 | case 3 |
---|
478 | % stop succeeded |
---|
479 | return; |
---|
480 | case 4 |
---|
481 | disp('All giving attributs are not in archiving process'); |
---|
482 | case 5 |
---|
483 | disp('Stop failed'); |
---|
484 | case 6 |
---|
485 | %% Modif succeeded |
---|
486 | return; |
---|
487 | case 7 |
---|
488 | disp('All given attributes are not in historic archiving'); |
---|
489 | case 8 |
---|
490 | disp('modif failed'); |
---|
491 | case 9 |
---|
492 | disp('No running [H/T]dbArchiver') |
---|
493 | case 10 |
---|
494 | disp('All the attribute do not exist in static DB') |
---|
495 | case 11 |
---|
496 | disp('database not connected') |
---|
497 | case 12 |
---|
498 | disp('device cannot talk to the database') |
---|
499 | otherwise |
---|
500 | disp('Unknown error') |
---|
501 | end |
---|
502 | |
---|
503 | warning(['Error with ', handles.database,' database']); |
---|
504 | |
---|
505 | |
---|
506 | % --- Executes during object creation, after setting all properties. |
---|
507 | function popupmenu_command_CreateFcn(hObject, eventdata, handles) |
---|
508 | % hObject handle to popupmenu_command (see GCBO) |
---|
509 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
510 | % handles empty - handles not created until after all CreateFcns called |
---|
511 | |
---|
512 | % Hint: popupmenu controls usually have a white background on Windows. |
---|
513 | % See ISPC and COMPUTER. |
---|
514 | if ispc |
---|
515 | set(hObject,'BackgroundColor','white'); |
---|
516 | else |
---|
517 | set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); |
---|
518 | end |
---|
519 | |
---|
520 | % --- Executes on selection change in listbox_group. |
---|
521 | function listbox_group_Callback(hObject, eventdata, handles) |
---|
522 | % hObject handle to listbox_group (see GCBO) |
---|
523 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
524 | % handles structure with handles and user data (see GUIDATA) |
---|
525 | |
---|
526 | % Hints: contents = get(hObject,'String') returns listbox_group contents as cell array |
---|
527 | % contents{get(hObject,'Value')} returns selected item from listbox_group |
---|
528 | |
---|
529 | set(handles.listbox_property,'Value',get(hObject,'Value')); |
---|
530 | set(handles.listbox_property,'ListboxTop',get(hObject,'ListboxTop')); |
---|
531 | |
---|
532 | |
---|
533 | % --- Executes during object creation, after setting all properties. |
---|
534 | function listbox_group_CreateFcn(hObject, eventdata, handles) |
---|
535 | % hObject handle to listbox_group (see GCBO) |
---|
536 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
537 | % handles empty - handles not created until after all CreateFcns called |
---|
538 | |
---|
539 | % Hint: listbox controls usually have a white background on Windows. |
---|
540 | % See ISPC and COMPUTER. |
---|
541 | if ispc |
---|
542 | set(hObject,'BackgroundColor','white'); |
---|
543 | else |
---|
544 | set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); |
---|
545 | end |
---|
546 | |
---|
547 | |
---|
548 | % --- Executes on selection change in listbox_property. |
---|
549 | function listbox_property_Callback(hObject, eventdata, handles) |
---|
550 | % hObject handle to listbox_property (see GCBO) |
---|
551 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
552 | % handles structure with handles and user data (see GUIDATA) |
---|
553 | |
---|
554 | % Hints: contents = get(hObject,'String') returns listbox_property contents as cell array |
---|
555 | % contents{get(hObject,'Value')} returns selected item from listbox_property |
---|
556 | |
---|
557 | set(handles.listbox_group,'Value', get(hObject,'Value')); |
---|
558 | set(handles.listbox_group,'ListboxTop', get(hObject,'ListboxTop')); |
---|
559 | |
---|
560 | %set(handles.edit_value,'String',contents{get(hObject,'Value')}); |
---|
561 | |
---|
562 | % --- Executes during object creation, after setting all properties. |
---|
563 | function listbox_property_CreateFcn(hObject, eventdata, handles) |
---|
564 | % hObject handle to listbox_property (see GCBO) |
---|
565 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
566 | % handles empty - handles not created until after all CreateFcns called |
---|
567 | |
---|
568 | % Hint: listbox controls usually have a white background on Windows. |
---|
569 | % See ISPC and COMPUTER. |
---|
570 | if ispc |
---|
571 | set(hObject,'BackgroundColor','white'); |
---|
572 | else |
---|
573 | set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); |
---|
574 | end |
---|
575 | |
---|
576 | |
---|
577 | % --- Executes on button press in checkbox_all. |
---|
578 | function checkbox_all_Callback(hObject, eventdata, handles) |
---|
579 | % hObject handle to checkbox_all (see GCBO) |
---|
580 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
581 | % handles structure with handles and user data (see GUIDATA) |
---|
582 | |
---|
583 | % Hint: get(hObject,'Value') returns toggle state of checkbox_all |
---|
584 | |
---|
585 | function edit_value_Callback(hObject, eventdata, handles) |
---|
586 | % hObject handle to edit_value (see GCBO) |
---|
587 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
588 | % handles structure with handles and user data (see GUIDATA) |
---|
589 | |
---|
590 | % Hints: get(hObject,'String') returns contents of edit_value as text |
---|
591 | % str2double(get(hObject,'String')) returns contents of edit_value as a double |
---|
592 | |
---|
593 | value = get(hObject,'String'); |
---|
594 | |
---|
595 | group = getappdata(handles.figure1,'group'); |
---|
596 | attribute = getappdata(handles.figure1,'attribute'); |
---|
597 | property = getappdata(handles.figure1,'property'); |
---|
598 | AO = getappdata(handles.figure1,'AO'); |
---|
599 | |
---|
600 | %% Status one devices |
---|
601 | valid = find(AO.(group).Status); |
---|
602 | |
---|
603 | if (get(handles.checkbox_all,'Value') == 0) |
---|
604 | %% Get selectedd element |
---|
605 | idx = get(handles.listbox_property,'Value'); |
---|
606 | tango_set_attribute_property(strcat(AO.(group).DeviceName{valid(idx)}, ... |
---|
607 | '/',attribute),property, value) |
---|
608 | else % All the same |
---|
609 | tango_set_attribute_property(strcat(AO.(group).DeviceName(valid), ... |
---|
610 | '/',attribute),property, value) |
---|
611 | end |
---|
612 | %% Status one devices |
---|
613 | valid = find(AO.(group).Status); |
---|
614 | |
---|
615 | %% refresh display |
---|
616 | popupmenu_property_Callback(handles.popupmenu_command,eventdata, handles); |
---|
617 | |
---|
618 | |
---|
619 | % --- Executes during object creation, after setting all properties. |
---|
620 | function edit_value_CreateFcn(hObject, eventdata, handles) |
---|
621 | % hObject handle to edit_value (see GCBO) |
---|
622 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
623 | % handles empty - handles not created until after all CreateFcns called |
---|
624 | |
---|
625 | % Hint: edit controls usually have a white background on Windows. |
---|
626 | % See ISPC and COMPUTER. |
---|
627 | if ispc |
---|
628 | set(hObject,'BackgroundColor','white'); |
---|
629 | else |
---|
630 | set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); |
---|
631 | end |
---|
632 | |
---|
633 | |
---|
634 | % -------------------------------------------------------------------- |
---|
635 | function uimenu_linac_Callback(hObject, eventdata, handles) |
---|
636 | % hObject handle to uimenu_linac (see GCBO) |
---|
637 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
638 | % handles structure with handles and user data (see GUIDATA) |
---|
639 | |
---|
640 | init_uimenu(hObject, eventdata, handles); |
---|
641 | |
---|
642 | % -------------------------------------------------------------------- |
---|
643 | function uimenu_LT1_Callback(hObject, eventdata, handles) |
---|
644 | % hObject handle to uimenu_LT1 (see GCBO) |
---|
645 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
646 | % handles structure with handles and user data (see GUIDATA) |
---|
647 | |
---|
648 | if ~strcmpi(getsubmachinename, 'LT1') |
---|
649 | LT1init; |
---|
650 | end |
---|
651 | handles = init_uimenu(hObject, eventdata, handles); |
---|
652 | % Update handles structure |
---|
653 | guidata(hObject, handles); |
---|
654 | |
---|
655 | %%%-------------------------------------------------------------------- |
---|
656 | function handles = init_uimenu(hObject, eventdata, handles) |
---|
657 | |
---|
658 | setappdata(handles.figure1,'AO', getao); |
---|
659 | |
---|
660 | %% Checked box |
---|
661 | all = findobj(get(hObject,'Parent'),'Type','UImenu'); |
---|
662 | set(all, 'Checked', 'Off'); |
---|
663 | set(hObject, 'Checked', 'On'); |
---|
664 | |
---|
665 | %% Initializes popupmenu w/ first element, first attribute, first property |
---|
666 | listgroup = findmemberof('Archivable'); |
---|
667 | |
---|
668 | set(handles.popupmenu_group,'String',listgroup); |
---|
669 | setappdata(handles.figure1,'group', listgroup{1}); |
---|
670 | |
---|
671 | popupmenu_group_Callback(handles.popupmenu_group, eventdata, handles); |
---|
672 | |
---|
673 | %% Initializes command popup menu w/ list of archivingmanager available |
---|
674 | %% commands |
---|
675 | % res = tango_command_list_query(archivingmanager); |
---|
676 | % listcmd = {res.cmd_name}; |
---|
677 | listcmd = {'IsArchived','GetArchivingMode', 'ArchivingStart', ... |
---|
678 | 'ArchivingStop','ArchivingModif'}; |
---|
679 | set(handles.popupmenu_command,'String',listcmd); |
---|
680 | value = find(strcmp(listcmd,'IsArchived')); |
---|
681 | set(handles.popupmenu_command,'Value',value); |
---|
682 | setappdata(handles.figure1,'command', value); |
---|
683 | |
---|
684 | % -------------------------------------------------------------------- |
---|
685 | function uimenu_booster_Callback(hObject, eventdata, handles) |
---|
686 | % hObject handle to uimenu_booster (see GCBO) |
---|
687 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
688 | % handles structure with handles and user data (see GUIDATA) |
---|
689 | |
---|
690 | if ~strcmpi(getsubmachinename, 'Booster') |
---|
691 | boosterinit |
---|
692 | end |
---|
693 | init_uimenu(hObject, eventdata, handles); |
---|
694 | |
---|
695 | % -------------------------------------------------------------------- |
---|
696 | function uimenu_LT2_Callback(hObject, eventdata, handles) |
---|
697 | % hObject handle to uimenu_LT2 (see GCBO) |
---|
698 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
699 | % handles structure with handles and user data (see GUIDATA) |
---|
700 | |
---|
701 | if ~strcmpi(getsubmachinename, 'LT2') |
---|
702 | LT2init; |
---|
703 | end |
---|
704 | init_uimenu(hObject, eventdata, handles); |
---|
705 | |
---|
706 | % -------------------------------------------------------------------- |
---|
707 | function uimenu_anneau_Callback(hObject, eventdata, handles) |
---|
708 | % hObject handle to uimenu_anneau (see GCBO) |
---|
709 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
710 | % handles structure with handles and user data (see GUIDATA) |
---|
711 | |
---|
712 | if ~strcmpi(getsubmachinename, 'StorageRing') |
---|
713 | soleilinit; |
---|
714 | end |
---|
715 | init_uimenu(hObject, eventdata, handles); |
---|
716 | |
---|
717 | % -------------------------------------------------------------------- |
---|
718 | function Untitled_1_Callback(hObject, eventdata, handles) |
---|
719 | % hObject handle to Untitled_1 (see GCBO) |
---|
720 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
721 | % handles structure with handles and user data (see GUIDATA) |
---|
722 | |
---|
723 | |
---|
724 | % -------------------------------------------------------------------- |
---|
725 | function hdbmenu_Callback(hObject, eventdata, handles) |
---|
726 | % hObject handle to menuhdb (see GCBO) |
---|
727 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
728 | % handles structure with handles and user data (see GUIDATA) |
---|
729 | set(handles.hdbmenu,'checked','On'); |
---|
730 | set(handles.tdbmenu,'checked','Off'); |
---|
731 | handles.database='HDB'; |
---|
732 | set(handles.mainuipanel,'Title','TANGO HDB Configurator', ... |
---|
733 | 'ForegroundColor',[0, 0.5, 0]); |
---|
734 | % Update handles structure |
---|
735 | guidata(hObject, handles); |
---|
736 | |
---|
737 | % -------------------------------------------------------------------- |
---|
738 | function tdbmenu_Callback(hObject, eventdata, handles) |
---|
739 | % hObject handle to tdbmenu (see GCBO) |
---|
740 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
741 | % handles structure with handles and user data (see GUIDATA) |
---|
742 | set(handles.tdbmenu,'checked','On'); |
---|
743 | set(handles.hdbmenu,'checked','Off'); |
---|
744 | handles.database='TDB'; |
---|
745 | set(handles.mainuipanel,'Title','TANGO TDB Configurator','ForegroundColor','b'); |
---|
746 | % Update handles structure |
---|
747 | guidata(hObject, handles); |
---|
748 | |
---|
749 | % -------------------------------------------------------------------- |
---|
750 | function Untitled_2_Callback(hObject, eventdata, handles) |
---|
751 | % hObject handle to Untitled_2 (see GCBO) |
---|
752 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
753 | % handles structure with handles and user data (see GUIDATA) |
---|
754 | |
---|
755 | |
---|
756 | % --- Executes on button press in checkbox_loadbalancing. |
---|
757 | function checkbox_loadbalancing_Callback(hObject, eventdata, handles) |
---|
758 | % hObject handle to checkbox_loadbalancing (see GCBO) |
---|
759 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
760 | % handles structure with handles and user data (see GUIDATA) |
---|
761 | |
---|
762 | % Hint: get(hObject,'Value') returns toggle state of checkbox_loadbalancing |
---|
763 | |
---|
764 | function list = format_output_list(varargin) |
---|
765 | |
---|
766 | cellarray = varargin{:}; |
---|
767 | |
---|
768 | list = zeros(1,7); |
---|
769 | |
---|
770 | % Periodical mode: just get archiving period |
---|
771 | [cellarray index] = findkeyword2(cellarray,'MODE_P'); |
---|
772 | if index ~= 0 |
---|
773 | list(1) = str2double(cellarray(index))/1e3; % seconds |
---|
774 | end |
---|
775 | |
---|
776 | % Absolute mode: just get archiving period and variation limits |
---|
777 | [cellarray index] = findkeyword2(cellarray,'MODE_A'); |
---|
778 | if index ~= 0 |
---|
779 | list(2) = str2double(cellarray(index))/1e3; % seconds |
---|
780 | list(3) = str2double(cellarray(index+1)); % decreasing variation (%) |
---|
781 | list(4) = str2double(cellarray(index+2)); % increasing variation (%) |
---|
782 | end |
---|
783 | |
---|
784 | % Relative mode: just get archiving period and variation limits |
---|
785 | [cellarray index] = findkeyword2(cellarray,'MODE_R'); |
---|
786 | if index ~= 0 |
---|
787 | list(5) = str2double(cellarray(index))/1e3; % seconds |
---|
788 | list(6) = str2double(cellarray(index+1)); % decreasing variation (%) |
---|
789 | list(7) = str2double(cellarray(index+2)); % increasing variation (%) |
---|
790 | end |
---|
791 | |
---|
792 | |
---|
793 | % --- If Enable == 'on', executes on mouse press in 5 pixel border. |
---|
794 | % --- Otherwise, executes on mouse press in 5 pixel border or over listbox_group. |
---|
795 | function listbox_group_ButtonDownFcn(hObject, eventdata, handles) |
---|
796 | % hObject handle to listbox_group (see GCBO) |
---|
797 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
798 | % handles structure with handles and user data (see GUIDATA) |
---|
799 | |
---|
800 | %% TODO: works only if right button pressed |
---|
801 | % do not know how to do for left button |
---|
802 | val = get(handles.listbox_group,'Value'); |
---|
803 | set(handles.listbox_property,'Value',val); |
---|
804 | |
---|
805 | |
---|
806 | % -------------------------------------------------------------------- |
---|
807 | function menu_file_Callback(hObject, eventdata, handles) |
---|
808 | % hObject handle to menu_file (see GCBO) |
---|
809 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
810 | % handles structure with handles and user data (see GUIDATA) |
---|
811 | |
---|
812 | |
---|
813 | % -------------------------------------------------------------------- |
---|
814 | function savemenu_Callback(hObject, eventdata, handles) |
---|
815 | % hObject handle to savemenu (see GCBO) |
---|
816 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
817 | % handles structure with handles and user data (see GUIDATA) |
---|
818 | |
---|
819 | summarymenu_Callback(hObject, eventdata, handles); |
---|
820 | directory = getfamilydata('Directory','Archiving'); |
---|
821 | filename1 = [directory appendtimestamp('config')]; |
---|
822 | filename0 = [directory 'config.dat']; |
---|
823 | copyfile(filename0,filename1); |
---|
824 | |
---|
825 | % -------------------------------------------------------------------- |
---|
826 | function summarymenu_Callback(hObject, eventdata, handles) |
---|
827 | % hObject handle to summarymenu (see GCBO) |
---|
828 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
829 | % handles structure with handles and user data (see GUIDATA) |
---|
830 | |
---|
831 | AO = getappdata(handles.figure1,'AO'); |
---|
832 | archivingmanager = getappdata(handles.figure1,'archivingmanager'); |
---|
833 | |
---|
834 | %grouplist = intersect(findmemberof('Magnet'),findmemberof('Archivable')); |
---|
835 | grouplist = findmemberof('Archivable'); |
---|
836 | |
---|
837 | % get database name |
---|
838 | switch handles.database |
---|
839 | case 'HDB' |
---|
840 | dbName = 'Hdb'; |
---|
841 | case 'TDB' |
---|
842 | dbName = 'Tdb'; |
---|
843 | end |
---|
844 | |
---|
845 | directory = getfamilydata('Directory','Archiving'); |
---|
846 | %filename = [directory appendtimestamp('config')]; |
---|
847 | filename = [directory 'config.dat']; |
---|
848 | fid = fopen(filename,'w'); |
---|
849 | |
---|
850 | fprintf(fid,['# ',handles.database ' DATABASE: File generated on' ... |
---|
851 | ' %s\n'],datestr(now)); |
---|
852 | fprintf(fid,['# Periodic Mode Absolute Mode ' ... |
---|
853 | ' Relative Mode TANGO attribute Name \n']); |
---|
854 | fprintf(fid,['# T(s) T(s) min max ' ... |
---|
855 | 'T(s) min max \n']); |
---|
856 | |
---|
857 | for k1 = 1:length(grouplist), |
---|
858 | % loop of group of devices |
---|
859 | %get attribut list |
---|
860 | % Status one devices |
---|
861 | valid = find(AO.(grouplist{k1}).Status); |
---|
862 | |
---|
863 | for k2 = 1:length(valid) |
---|
864 | % loop over devices |
---|
865 | % Builds up attribut list for selected groups |
---|
866 | attributeList = tango_get_attribute_list(AO.(grouplist{k1}).DeviceName{valid(k2)}); |
---|
867 | for k3 = 1:length(attributeList), |
---|
868 | % loop over attributes |
---|
869 | %check if archived |
---|
870 | try |
---|
871 | argin = strcat(AO.(grouplist{k1}).DeviceName(valid(k2)), '/', attributeList{k3}); |
---|
872 | arstatus = tango_command_inout2(archivingmanager,['IsArchived' dbName], argin); |
---|
873 | catch |
---|
874 | fprintf('Erreur with attribute %s\n Action aborted \n', attributeList{k3}); |
---|
875 | return; |
---|
876 | end |
---|
877 | if arstatus |
---|
878 | %get Archiving modes |
---|
879 | answer = tango_command_inout2(archivingmanager,['GetArchivingMode' dbName], argin{:}); |
---|
880 | list = format_output_list(answer); |
---|
881 | |
---|
882 | %% Format data for fast print out |
---|
883 | % Name = strcat(AO.(groupLIST(k1)).DeviceName(valid(k2)), '/', attributelist{k3}); |
---|
884 | Name = argin; |
---|
885 | [n1 n2] = size(list); |
---|
886 | Strcell = cell(n2+1,n1); |
---|
887 | Strcell(end,:) = Name; |
---|
888 | Strcell(1:end-1,:) = num2cell(list'); |
---|
889 | fprintf(fid,' %7.1f %7.1f %8.2f %8.2f %7.1f %8.2f %8.2f %s\n',Strcell{:}); |
---|
890 | end |
---|
891 | end |
---|
892 | end |
---|
893 | end |
---|
894 | |
---|
895 | fclose(fid); |
---|
896 | |
---|
897 | % show file |
---|
898 | if isunix |
---|
899 | system(['nedit ', filename, ' &']); % much faster |
---|
900 | else |
---|
901 | eval(['edit ' filename]) |
---|
902 | end |
---|
903 | |
---|
904 | |
---|
905 | % -------------------------------------------------------------------- |
---|
906 | function loadmenu_Callback(hObject, eventdata, handles) |
---|
907 | % hObject handle to loadmenu (see GCBO) |
---|
908 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
909 | % handles structure with handles and user data (see GUIDATA) |
---|
910 | |
---|
911 | disp('Not implemented yet') |
---|