diff --git a/bindings/matlab/test/codegen/iioContextGetChannelInfo.m b/bindings/matlab/test/codegen/iioContextGetChannelInfo.m new file mode 100644 index 000000000..1fc26624a --- /dev/null +++ b/bindings/matlab/test/codegen/iioContextGetChannelInfo.m @@ -0,0 +1,64 @@ +function [PhyDevName, ChnId, ChnType, ModType, IsOutput, ... + IsScanElement, AttrsCount, AttrNameGet, AttrNameFind] = ... + iioContextGetChannelInfo(uri, phyDevName, ... + chnName, isOutput, AttrIndex) + + assert(isa(uri,'char') && all(size(uri) <= [1,20])); + assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,50])); + assert(isa(chnName,'char') && all(size(chnName) <= [1,50])); + assert(isa(isOutput,'logical') && all(size(isOutput) <= [1,1])); + assert(isa(AttrIndex,'uint16') && all(size(AttrIndex) <= [1,1])); + + % Get Context + iioCtxPtr = adi.libiio.context.iio_create_context(uri); + status = -int32(iioCtxPtr==coder.opaque('struct iio_context*', 'NULL')); + if status ~= 0 + PhyDevName = uint8('xyz'); + ChnId = uint8('abc'); + ChnType = uint8('IIO_XYZ'); + ModType = uint8('IIO_MOD_ABC'); + IsOutput = true; + IsScanElement = true; + AttrsCount = 0; + AttrNameGet = uint8('pqr'); + AttrNameFind = uint8('pqr'); + return; + end + + % Get PhyDev Pointer + iioPhyDevPtr = adi.libiio.context.iio_context_find_device(iioCtxPtr, phyDevName); + + % Get Channel Pointer + iioPhyDevChnPtr = adi.libiio.device.iio_device_find_channel(iioPhyDevPtr, chnName, isOutput); + + % Get PhyDev Name Associated with the Channel Pointer + iioPhyDevPtrFromChnPtr = adi.libiio.channel.iio_channel_get_device(iioPhyDevChnPtr); + PhyDevName = adi.libiio.device.iio_device_get_name(iioPhyDevPtrFromChnPtr); + + % Get Channel Id Associated with the Channel Pointer + ChnId = adi.libiio.channel.iio_channel_get_id(iioPhyDevChnPtr); + + % Get Channel Type Associated with the Channel Pointer + ChnType = adi.libiio.channel.iio_channel_get_type(iioPhyDevChnPtr); + + % Get Modifier Type Associated with the Channel Pointer + ModType = adi.libiio.channel.iio_channel_get_modifier(iioPhyDevChnPtr); + + % Is Channel Associated with the Channel Pointer an Output Channel? + IsOutput = adi.libiio.channel.iio_channel_is_output(iioPhyDevChnPtr); + + % Is Channel Associated with the Channel Pointer a Scan Element? + IsScanElement = adi.libiio.channel.iio_channel_is_scan_element(iioPhyDevChnPtr); + + % Get Channel Attributes Count Associated with the Channel Pointer + AttrsCount = adi.libiio.channel.iio_channel_get_attrs_count(iioPhyDevChnPtr); + + AttrPtrGet = adi.libiio.channel.iio_channel_get_attr(iioPhyDevChnPtr, AttrIndex); + AttrNameGet = adi.libiio.attribute.iio_attr_get_name(AttrPtrGet); + + AttrPtrFind = adi.libiio.channel.iio_channel_find_attr(iioPhyDevChnPtr, AttrNameGet); + AttrNameFind = adi.libiio.attribute.iio_attr_get_name(AttrPtrFind); + + % Destroy Context + adi.libiio.context.iio_context_destroy(iioCtxPtr); +end \ No newline at end of file diff --git a/bindings/matlab/test/codegen/iioContextGetDeviceInfo.m b/bindings/matlab/test/codegen/iioContextGetDeviceInfo.m new file mode 100644 index 000000000..cda2d204b --- /dev/null +++ b/bindings/matlab/test/codegen/iioContextGetDeviceInfo.m @@ -0,0 +1,27 @@ +function [PhyDevName, DevId] = ... + iioContextGetDeviceInfo(uri, phyDevName) + + assert(isa(uri,'char') && all(size(uri) <= [1,20])); + assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,50])); + + % Get Context + iioCtxPtr = adi.libiio.context.iio_create_context(uri); + status = -int32(iioCtxPtr==coder.opaque('struct iio_context*', 'NULL')); + if status ~= 0 + PhyDevName = uint8('xyz'); + DevId = uint8('abc'); + return; + end + + % Get PhyDev Pointer + iioPhyDevPtr = adi.libiio.context.iio_context_find_device(iioCtxPtr, phyDevName); + + % Get PhyDev Name + PhyDevName = adi.libiio.device.iio_device_get_name(iioPhyDevPtr); + + % Get Device Id Associated with the PhyDev Pointer + DevId = adi.libiio.device.iio_device_get_id(iioPhyDevPtr); + + % Destroy Context + adi.libiio.context.iio_context_destroy(iioCtxPtr); +end \ No newline at end of file diff --git a/bindings/matlab/test/codegen/iioReadChannelAttributeBool.m b/bindings/matlab/test/codegen/iioReadChannelAttributeBool.m new file mode 100644 index 000000000..cee95b5ea --- /dev/null +++ b/bindings/matlab/test/codegen/iioReadChannelAttributeBool.m @@ -0,0 +1,45 @@ +function [status, chnDataFormatPtr, ... + attrName, value] = iioReadChannelAttributeBool(... + uri, ... + phyDevName, ... + chnName, ... + isOutput, ... + chnAttrName) + + assert(isa(uri,'char') && all(size(uri) <= [1,20])); + assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,50])); + assert(isa(chnName,'char') && all(size(chnName) <= [1,50])); + assert(isa(isOutput,'logical') && all(size(isOutput) <= [1,1])); + assert(isa(chnAttrName,'char') && all(size(chnAttrName) <= [1,50])); + + % Get Context + iioCtxPtr = adi.libiio.context.iio_create_context(uri); + status = -int32(iioCtxPtr==coder.opaque('struct iio_context*', 'NULL')); + if status ~= 0 + chnDataFormatPtr = libpointer; + attrName = char(zeros(1,1,'uint8')); + value = bool(0); + return; + end + + % Get PhyDev Pointer + iioPhyDevPtr = adi.libiio.context.iio_context_find_device(iioCtxPtr, phyDevName); + + % Get Channel Pointer + iioPhyDevChnPtr = adi.libiio.device.iio_device_find_channel(iioPhyDevPtr, chnName, isOutput); + + % Get Channel Pointer + chnDataFormatPtr = adi.libiio.lowlevel.iio_channel_get_data_format(iioPhyDevChnPtr); + + % Get Channel Attribute Pointer + iioPhyDevChnAttrPtr = adi.libiio.channel.iio_channel_find_attr(iioPhyDevChnPtr, chnAttrName); + + % get Attribute Name + attrName = adi.libiio.attribute.iio_attr_get_name(iioPhyDevChnAttrPtr); + + % Read Attribute + [status, value] = adi.libiio.attribute.iio_attr_read_bool(iioPhyDevChnAttrPtr); + + % Destroy Context + adi.libiio.context.iio_context_destroy(iioCtxPtr); +end \ No newline at end of file diff --git a/bindings/matlab/test/codegen/iioReadChannelAttributeLonglong.m b/bindings/matlab/test/codegen/iioReadChannelAttributeLonglong.m index 0347048c6..c68574167 100644 --- a/bindings/matlab/test/codegen/iioReadChannelAttributeLonglong.m +++ b/bindings/matlab/test/codegen/iioReadChannelAttributeLonglong.m @@ -6,10 +6,10 @@ chnAttrName) assert(isa(uri,'char') && all(size(uri) <= [1,20])); - assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,20])); - assert(isa(chnName,'char') && all(size(chnName) <= [1,20])); + assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,50])); + assert(isa(chnName,'char') && all(size(chnName) <= [1,50])); assert(isa(isOutput,'logical') && all(size(isOutput) <= [1,1])); - assert(isa(chnAttrName,'char') && all(size(chnAttrName) <= [1,20])); + assert(isa(chnAttrName,'char') && all(size(chnAttrName) <= [1,50])); % Get Context iioCtxPtr = adi.libiio.context.iio_create_context(uri); diff --git a/bindings/matlab/test/codegen/iioReadDeviceAttributeLonglong.m b/bindings/matlab/test/codegen/iioReadDeviceAttributeLonglong.m index 4f5a3971c..7e2865c9f 100644 --- a/bindings/matlab/test/codegen/iioReadDeviceAttributeLonglong.m +++ b/bindings/matlab/test/codegen/iioReadDeviceAttributeLonglong.m @@ -1,7 +1,7 @@ function [status, attrName, value] = iioReadDeviceAttributeLonglong(uri, phyDevName, devAttrName) assert(isa(uri,'char') && all(size(uri) <= [1,20])); - assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,20])); - assert(isa(devAttrName,'char') && all(size(devAttrName) <= [1,20])); + assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,50])); + assert(isa(devAttrName,'char') && all(size(devAttrName) <= [1,50])); % Get Context iioCtxPtr = adi.libiio.context.iio_create_context(uri); diff --git a/bindings/matlab/test/codegen/iioWriteChannelAttributeBool.m b/bindings/matlab/test/codegen/iioWriteChannelAttributeBool.m new file mode 100644 index 000000000..918c659c8 --- /dev/null +++ b/bindings/matlab/test/codegen/iioWriteChannelAttributeBool.m @@ -0,0 +1,36 @@ +function status = iioWriteChannelAttributeBool(uri, ... + phyDevName, ... + chnName, ... + isOutput, ... + chnAttrName, ... + value) + + assert(isa(uri,'char') && all(size(uri) <= [1,20])); + assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,50])); + assert(isa(chnName,'char') && all(size(chnName) <= [1,50])); + assert(isa(isOutput,'logical') && all(size(isOutput) <= [1,1])); + assert(isa(chnAttrName,'char') && all(size(chnAttrName) <= [1,50])); + assert(isa(value,'logical') && isreal(value) && all(size(value) == [1,1])); + + % Get Context + iioCtxPtr = adi.libiio.context.iio_create_context(uri); + status = -int32(iioCtxPtr==coder.opaque('struct iio_context*', 'NULL')); + if status ~= 0 + return; + end + + % Get PhyDev Pointer + iioPhyDevPtr = adi.libiio.context.iio_context_find_device(iioCtxPtr, phyDevName); + + % Get Channel Pointer + iioPhyDevChnPtr = adi.libiio.device.iio_device_find_channel(iioPhyDevPtr, chnName, isOutput); + + % Get Channel Attribute Pointer + iioPhyDevChnAttrPtr = adi.libiio.channel.iio_channel_find_attr(iioPhyDevChnPtr, chnAttrName); + + % Write Attribute + status = adi.libiio.attribute.iio_attr_write_bool(iioPhyDevChnAttrPtr, value); + + % Destroy Context + adi.libiio.context.iio_context_destroy(iioCtxPtr); +end \ No newline at end of file diff --git a/bindings/matlab/test/codegen/iioWriteChannelAttributeLonglong.m b/bindings/matlab/test/codegen/iioWriteChannelAttributeLonglong.m index 020d8a428..361850588 100644 --- a/bindings/matlab/test/codegen/iioWriteChannelAttributeLonglong.m +++ b/bindings/matlab/test/codegen/iioWriteChannelAttributeLonglong.m @@ -6,10 +6,10 @@ value) assert(isa(uri,'char') && all(size(uri) <= [1,20])); - assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,20])); - assert(isa(chnName,'char') && all(size(chnName) <= [1,20])); + assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,50])); + assert(isa(chnName,'char') && all(size(chnName) <= [1,50])); assert(isa(isOutput,'logical') && all(size(isOutput) <= [1,1])); - assert(isa(chnAttrName,'char') && all(size(chnAttrName) <= [1,20])); + assert(isa(chnAttrName,'char') && all(size(chnAttrName) <= [1,50])); assert(isa(value,'int64') && isreal(value) && all(size(value) == [1,1])); % Get Context diff --git a/bindings/matlab/test/codegen/iioWriteDeviceAttributeLonglong.m b/bindings/matlab/test/codegen/iioWriteDeviceAttributeLonglong.m index 7ffd7ef2f..e2c02246e 100644 --- a/bindings/matlab/test/codegen/iioWriteDeviceAttributeLonglong.m +++ b/bindings/matlab/test/codegen/iioWriteDeviceAttributeLonglong.m @@ -1,7 +1,7 @@ function status = iioWriteDeviceAttributeLonglong(uri, phyDevName, devAttrName, value) assert(isa(uri,'char') && all(size(uri) <= [1,20])); - assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,20])); - assert(isa(devAttrName,'char') && all(size(devAttrName) <= [1,20])); + assert(isa(phyDevName,'char') && all(size(phyDevName) <= [1,50])); + assert(isa(devAttrName,'char') && all(size(devAttrName) <= [1,50])); assert(isa(value,'int64') && isreal(value) && all(size(value) == [1,1])); % Get Context diff --git a/bindings/matlab/test/testChannelAttributes.m b/bindings/matlab/test/testChannelAttributes.m index ae2d5c7b7..f4c705083 100644 --- a/bindings/matlab/test/testChannelAttributes.m +++ b/bindings/matlab/test/testChannelAttributes.m @@ -3,7 +3,8 @@ uri = {'ip:pluto.local'} phyDev = {'ad9361-phy'} chnParamsLongLong = {'altvoltage0', true, 'frequency', int64(1900000000)} - chnParamsDouble = {'voltage0', true, 'hardwaregain', double(-12.5)} + chnParamsDouble = {'voltage0', true, 'hardwaregain', double(-12.5), uint16(1), 'IIO_VOLTAGE', 'IIO_NO_MOD'} + chnParamsLogical = {'voltage0', false, 'quadrature_tracking_en', logical(false)} end methods(Test) @@ -51,8 +52,40 @@ function testPlutoChannelAttributes(testCase) assert(status==0); assert(result==OrigValue); - % Unload Library - adi.libiio.helpers.unloadLibIIO(); + %% Logical + % Read from Channel Attribute + [status, chnDataFormatPtr, attrName, result] = iioReadChannelAttributeBool(testCase.uri{1}, testCase.phyDev{1}, testCase.chnParamsLogical{1}, testCase.chnParamsLogical{2}, testCase.chnParamsLogical{3}); + assert(~chnDataFormatPtr.isNull); + assert(strcmp(attrName, testCase.chnParamsLogical{3})); + assert(status==0); + OrigValue = result; + + % Write to Channel Attribute and Verify Value is Written + status = iioWriteChannelAttributeBool(testCase.uri{1}, testCase.phyDev{1}, testCase.chnParamsLogical{1}, testCase.chnParamsLogical{2}, testCase.chnParamsLogical{3}, testCase.chnParamsLogical{4}); + assert(status==0); + [status, ~, ~, result] = iioReadChannelAttributeBool(testCase.uri{1}, testCase.phyDev{1}, testCase.chnParamsLogical{1}, testCase.chnParamsLogical{2}, testCase.chnParamsLogical{3}); + assert(status==0); + assert(result==testCase.chnParamsLogical{4}); + + % Write Original Value to Channel Attribute and Verify Value is Written + status = iioWriteChannelAttributeBool(testCase.uri{1}, testCase.phyDev{1}, testCase.chnParamsLogical{1}, testCase.chnParamsLogical{2}, testCase.chnParamsLogical{3}, OrigValue); + assert(status==0); + [status, ~, ~, result] = iioReadChannelAttributeBool(testCase.uri{1}, testCase.phyDev{1}, testCase.chnParamsLogical{1}, testCase.chnParamsLogical{2}, testCase.chnParamsLogical{3}); + assert(status==0); + assert(result==OrigValue); + + [PhyDevName, ChnId, ChnType, ModType, IsOutput, IsScanElement, AttrsCount, AttrNameGet, AttrNameFind] = ... + iioContextGetChannelInfo(testCase.uri{1}, testCase.phyDev{1}, testCase.chnParamsDouble{1}, ... + testCase.chnParamsDouble{2}, testCase.chnParamsDouble{5}); + assert(strcmp(PhyDevName, testCase.phyDev{1})); + assert(strcmp(ChnId, testCase.chnParamsDouble{1})); + assert(strcmp(ChnType, testCase.chnParamsDouble{6})); + assert(strcmp(ModType, testCase.chnParamsDouble{7})); + assert(IsOutput==testCase.chnParamsDouble{2}); + assert(~IsScanElement); + assert(AttrsCount==10); + assert(strcmp(AttrNameGet, testCase.chnParamsDouble{3})); + assert(strcmp(AttrNameFind, testCase.chnParamsDouble{3})); end end end \ No newline at end of file diff --git a/bindings/matlab/test/testDeviceAttributes.m b/bindings/matlab/test/testDeviceAttributes.m index 68528a2cb..d9228a4ae 100644 --- a/bindings/matlab/test/testDeviceAttributes.m +++ b/bindings/matlab/test/testDeviceAttributes.m @@ -52,6 +52,10 @@ function testPlutoDeviceAttributes(testCase) % assert(status==0); % assert(result==OrigValue); + [PhyDevName, DevId] = ... + iioContextGetDeviceInfo(testCase.uri{1}, testCase.phyDev{1}); + assert(strcmp(PhyDevName, testCase.phyDev{1})); + % Unload Library adi.libiio.helpers.unloadLibIIO(); end