-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSOLUS_Autocal_Parameters.m
130 lines (125 loc) · 4.3 KB
/
SOLUS_Autocal_Parameters.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
classdef SOLUS_Autocal_Parameters
% SOLUS_Autocal_Parameters
%
% Author(s): Alessandro RUGGERI
% Revision: 1.0
% Date: 20/11/2019
%
% Copyright 2019 Micro Photon Devices
%
% Usage:
% ap = SOLUS_Autocal_Parameters(); initialize and fill all the parameters with 0
% ap = SOLUS_Autocal_Parameters(ld_struct); initialize and fill with data from the struct.
% ap = SOLUS_Autocal_Parameters(goal, meas_time, steps, start_pos);
% initialize and fill data with given parameters.
%
% Rev 1.0-20/11/2019: first issue
properties
goal=uint32(0);
meas_time=uint16(0);
steps=uint16(0);
start_pos=uint16(0);
end
methods
% constructor / inizializator
function obj = SOLUS_Autocal_Parameters(goal__struct, meas_time, steps, start_pos)
if nargin ~= 0 && nargin ~= 1 && nargin ~= 4
error('SOLUS_Autocal_Parameters must be called with 0, 1 or 4 arguments');
end
if nargin == 1
obj=obj.fromStruct(en1__struct);
elseif nargin == 4
obj.goal=goal__struct;
obj.meas_time=meas_time;
obj.steps=steps;
obj.start_pos=start_pos;
end
end
function ok=eq(obj1, obj2)
ok=true;
if size(obj1)==size(obj2)
for k=1:numel(obj1)
ok=ok && obj1(k).goal==obj2(k).goal;
ok=ok && obj1(k).meas_time==obj2(k).meas_time;
ok=ok && obj1(k).steps==obj2(k).steps;
ok=ok && obj1(k).start_pos==obj2(k).start_pos;
end
else
ok=false;
end
end
% convert class to struct
function LD_str = toStruct(obj)
LD_str=struct('goal', obj.goal, ...
'meas_time', uint16(obj.meas_time/100e-6),...
'steps', obj.steps, 'start_pos', obj.start_pos);
end
%% convert from struct
function obj = fromStruct(obj, str)
% convert struct to class
if isa(str,'struct')
fields={'goal', 'meas_time', 'steps', 'start_pos'};
ok=true;
for k=1:length(fields)
if ~isfield(str,fields{k})
ok=false;
break;
end
end
if ok
obj.goal=str.goal;
obj.meas_time=str.meas_time;
obj.steps=str.steps;
obj.start_pos=str.start_pos;
else
error('Input argument of SOLUS_Autocal_Parameters does not contains all the expected fields');
end
else
error('Input argument of SOLUS_Autocal_Parameters must be a struct');
end
end
% below functions to validate input parameters size
% and convert to the desired type
function obj = set.goal(obj,val)
if isscalar(val)
obj.goal=uint32(val);
else
SOLUS_Autocal_Parameters.printError(1);
end
end
function obj = set.meas_time(obj,val)
if isscalar(val)
obj.meas_time=uint16(val/100e-6);
else
SOLUS_Autocal_Parameters.printError(1);
end
end
function val = get.meas_time(obj)
val=double(obj.meas_time)*100e-6;
end
function obj = set.steps(obj,val)
if isscalar(val)
obj.steps=uint16(val);
else
SOLUS_Autocal_Parameters.printError(1);
end
end
function obj = set.start_pos(obj,val)
if isscalar(val)
obj.start_pos=uint16(val);
else
SOLUS_Autocal_Parameters.printError(1);
end
end
end
methods(Static)
function printError(size)
if size==1
str='A number is required';
else
str=['A vector with ' num2str(size) ' elements is required'];
end
error('SOLUS_Autocal_Parameters:badSize',str);
end
end
end