forked from analogdevicesinc/ToolboxCommon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttribute.m
151 lines (138 loc) · 6.59 KB
/
Attribute.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
classdef (Abstract) Attribute < adi.common.RegisterReadWrite & ...
adi.common.DebugAttribute & adi.common.DeviceAttribute
% Attribute IIO attribute function calls
methods (Hidden)
function setAttributeLongLong(obj,id,attr,value,isOutput,tol,phydev)
if nargin < 7
phydev = getDev(obj, obj.phyDevName);
end
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
status = iio_channel_attr_write_longlong(obj,chanPtr,attr,value);
cstatus(obj,status,['Attribute write failed for : ' attr ' with value ' num2str(value)]);
% Check
[status, rValue] = iio_channel_attr_read_longlong(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
if nargin<6
tol = sqrt(eps);
end
if abs(value - rValue) > tol
status = -1;
cstatus(obj,status,['Attribute ' attr ' return value ' num2str(rValue) ', expected ' num2str(value)]);
end
end
function setAttributeDouble(obj,id,attr,value,isOutput,tol,phydev)
if nargin < 7
phydev = getDev(obj, obj.phyDevName);
end
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
status = iio_channel_attr_write_double(obj,chanPtr,attr,value);
cstatus(obj,status,['Attribute write failed for : ' attr ' with value ' num2str(value)]);
% Check
[status, rValue] = iio_channel_attr_read_double(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
if nargin<6
tol = sqrt(eps);
end
if abs(value - rValue) > tol
status = -1;
cstatus(obj,status,['Attribute ' attr ' return value ' num2str(rValue) ', expected ' num2str(value)]);
end
end
function rValue = getAttributeLongLong(obj,id,attr,isOutput,phydev)
if nargin < 5
phydev = getDev(obj, obj.phyDevName);
end
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
[status, rValue] = iio_channel_attr_read_longlong(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
end
function rValue = getAttributeDouble(obj,id,attr,isOutput,phydev)
if nargin < 5
phydev = getDev(obj, obj.phyDevName);
end
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
[status, rValue] = iio_channel_attr_read_double(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
end
function setAttributeBool(obj,id,attr,value,isOutput,phydev)
if nargin < 6
phydev = getDev(obj, obj.phyDevName);
end
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
status = iio_channel_attr_write_bool(obj,chanPtr,attr,value);
cstatus(obj,status,['Attribute write failed for : ' attr]);
% Check
[status, rValue] = iio_channel_attr_read_bool(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
if value ~= rValue
status = -1;
cstatus(obj,status,['Attribute ' attr ' return value ' num2str(rValue) ', expected ' num2str(value)]);
end
end
function rValue = getAttributeBool(obj,id,attr,isOutput,phydev)
if nargin < 5
phydev = getDev(obj, obj.phyDevName);
end
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
[status, rValue] = iio_channel_attr_read_bool(obj,chanPtr,attr);
cstatus(obj,status,['Error reading attribute: ' attr]);
end
function setAttributeRAW(obj,id,attr,value,isOutput,phydev)
if nargin < 6
phydev = getDev(obj, obj.phyDevName);
end
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
bytes = iio_channel_attr_write(obj,chanPtr,attr,value);
if bytes <= 0
status = -1;
cstatus(obj,status,['Attribute write failed for : ' attr ' with value ' value]);
end
end
function rValue = getAttributeRAW(obj,id,attr,isOutput,phydev)
if nargin < 5
phydev = getDev(obj, obj.phyDevName);
end
chanPtr = iio_device_find_channel(obj,phydev,id,isOutput);%FIXME (INVERSION)
status = cPtrCheck(obj,chanPtr);
cstatus(obj,status,['Channel: ' id ' not found']);
[bytes, rValue] = iio_channel_attr_read(obj,chanPtr,attr,1024);
if bytes <= 0
status = -1;
cstatus(obj,status,['Attribute read failed for : ' attr]);
end
end
function setDeviceAttributeRAW(obj,attr,value,phydev)
if nargin < 4
phydev = getDev(obj, obj.phyDevName);
end
bytes = iio_device_attr_write(obj,phydev,attr,value);
if bytes <= 0
status = -1;
cstatus(obj,status,['Attribute write failed for : ' attr ' with value ' value]);
end
end
function rValue = getDeviceAttributeRAW(obj,attr,len,phydev)
if nargin < 4
phydev = getDev(obj, obj.phyDevName);
end
[status, rValue] = iio_device_attr_read(obj,phydev,attr,len);
if status == 0
cstatus(obj,-1,['Error reading attribute: ' attr]);
end
end
end
end