diff --git a/iio_sys_obj.m b/iio_sys_obj.m index 56723c6..f9cb820 100644 --- a/iio_sys_obj.m +++ b/iio_sys_obj.m @@ -92,19 +92,35 @@ classdef iio_sys_obj < matlab.System & matlab.system.mixin.Propagates ... 'mon_ch', []); % Monitoring channels list % Build the configuration/monitoring channels structure - ch_cfg = struct('port_name', '',... % Name of the port to be displayed on the object block - 'port_attr', '',... % Associated device attribute name - 'dev', 0,... % Pointer to the control device - 'ch', 0,... % Pointer to the attributes device channel - 'attr', 0); % Pointer to the device attribute structure + ch_cfg = struct('port_name', '',... % Name of the port to be displayed on the object block + 'port_attr', '',... % Associated device attribute name + 'ctrl_dev_name', '',... % Control device name + 'ctrl_dev', 0); % Pointer to the control device object % Read the object's configuration while(~feof(fp_cfg)) line = fgets(fp_cfg); if(strfind(line,'#')) continue; - end - if(~isempty(strfind(line, 'data_in_device'))) + end + if(~isempty(strfind(line, 'channel'))) + % Get the associated configuration/monitoring channels + idx = strfind(line, '='); + line = line(idx+1:end); + line = strsplit(line, ','); + ch_cfg.port_name = strtrim(line{1}); + ch_cfg.port_attr = strtrim(line{3}); + if(length(line) > 4) + ch_cfg.ctrl_dev_name = strtrim(line{4}); + else + ch_cfg.ctrl_dev_name = 'ctrl_device'; + end + if(strcmp(strtrim(line{2}), 'IN')) + config.cfg_ch = [config.cfg_ch ch_cfg]; + elseif(strcmp(strtrim(line{2}), 'OUT')) + config.mon_ch = [config.mon_ch ch_cfg]; + end + elseif(~isempty(strfind(line, 'data_in_device'))) % Get the associated data input device idx = strfind(line, '='); tmp = line(idx+1:end); @@ -121,19 +137,7 @@ classdef iio_sys_obj < matlab.System & matlab.system.mixin.Propagates ... idx = strfind(line, '='); tmp = line(idx+1:end); tmp = strtrim(tmp); - config.ctrl_device = tmp; - elseif(~isempty(strfind(line, 'channel'))) - % Get the associated configuration/monitoring channels - idx = strfind(line, '='); - line = line(idx+1:end); - line = strsplit(line, ','); - ch_cfg.port_name = strtrim(line{1}); - ch_cfg.port_attr = strtrim(line{3}); - if(strcmp(strtrim(line{2}), 'IN')) - config.cfg_ch = [config.cfg_ch ch_cfg]; - elseif(strcmp(strtrim(line{2}), 'OUT')) - config.mon_ch = [config.mon_ch ch_cfg]; - end + config.ctrl_device = tmp; end end fclose(fp_cfg); @@ -185,15 +189,39 @@ classdef iio_sys_obj < matlab.System & matlab.system.mixin.Propagates ... end % Initialize the libiio control device - [ret, err_msg, msg_log] = init(obj.libiio_ctrl_dev, obj.ip_address, ... - obj.iio_dev_cfg.ctrl_device, '', ... - 0, 0); - fprintf('%s', msg_log); - if(ret < 0) - msgbox(err_msg, 'Error','error'); - return; + if(~isempty(obj.iio_dev_cfg.ctrl_device)) + [ret, err_msg, msg_log] = init(obj.libiio_ctrl_dev, obj.ip_address, ... + obj.iio_dev_cfg.ctrl_device, '', ... + 0, 0); + fprintf('%s', msg_log); + if(ret < 0) + msgbox(err_msg, 'Error','error'); + return; + end end + % Assign the control device for each monitoring channel + for i = 1 : length(obj.iio_dev_cfg.mon_ch) + if(strcmp(obj.iio_dev_cfg.mon_ch(i).ctrl_dev_name, 'data_in_device')) + obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_data_in_dev; + elseif(strcmp(obj.iio_dev_cfg.mon_ch(i).ctrl_dev_name, 'data_out_device')) + obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_data_out_dev; + else + obj.iio_dev_cfg.mon_ch(i).ctrl_dev = obj.libiio_ctrl_dev; + end + end + + % Assign the control device for each configuration channel + for i = 1 : length(obj.iio_dev_cfg.cfg_ch) + if(strcmp(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev_name, 'data_in_device')) + obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_data_in_dev; + elseif(strcmp(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev_name, 'data_out_device')) + obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_data_out_dev; + else + obj.iio_dev_cfg.cfg_ch(i).ctrl_dev = obj.libiio_ctrl_dev; + end + end + % Set the initialization status to success obj.sys_obj_initialized = 1; end @@ -214,8 +242,8 @@ classdef iio_sys_obj < matlab.System & matlab.system.mixin.Propagates ... end % Implement the data transmit flow - writeData(obj.libiio_data_in_dev, varargin); - + writeData(obj.libiio_data_in_dev, varargin); + % Implement the data capture flow [~, data] = readData(obj.libiio_data_out_dev); for i = 1 : obj.out_ch_no @@ -224,7 +252,7 @@ classdef iio_sys_obj < matlab.System & matlab.system.mixin.Propagates ... % Implement the parameters monitoring flow for i = 1 : length(obj.iio_dev_cfg.mon_ch) - [~, val] = readAttributeDouble(obj.libiio_ctrl_dev, obj.iio_dev_cfg.mon_ch(i).port_attr); + [~, val] = readAttributeDouble(obj.iio_dev_cfg.mon_ch(i).ctrl_dev, obj.iio_dev_cfg.mon_ch(i).port_attr); varargout{obj.out_ch_no + i} = val; end @@ -247,7 +275,7 @@ classdef iio_sys_obj < matlab.System & matlab.system.mixin.Propagates ... obj.str_cfg_in(i,j+1) = 0; str = char(obj.str_cfg_in(i,:)); end - writeAttributeString(obj.libiio_ctrl_dev, obj.iio_dev_cfg.cfg_ch(i).port_attr, str); + writeAttributeString(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev, obj.iio_dev_cfg.cfg_ch(i).port_attr, str); end end end diff --git a/libiio_if.m b/libiio_if.m index 1b215a3..8f8f9cd 100644 --- a/libiio_if.m +++ b/libiio_if.m @@ -223,7 +223,7 @@ classdef libiio_if < handle % Enable the DAC buffer output obj.if_initialized = 1; - ret = writeAttributeString(obj, 'out_altvoltage0_TX1_I_F1_raw', '0'); + ret = writeAttributeString(obj, 'altvoltage0*raw', '0'); obj.if_initialized = 0; if(ret < 0) obj.iio_channel = {}; @@ -476,7 +476,7 @@ classdef libiio_if < handle obj.iio_buffer = {}; % Enable the DAC buffer output - ret = writeAttributeString(obj, 'out_altvoltage0_TX1_I_F1_raw', '0'); + ret = writeAttributeString(obj, 'altvoltage0*raw', '0'); if(ret < 0) obj.iio_channel = {}; err_msg = 'Could not enable the DAC buffer output!'; @@ -504,7 +504,7 @@ classdef libiio_if < handle end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% Find an attribute based on the name + %% Find an attribute based on the name. The name can contain wildcard '*' characters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [ret, ch, attr] = findAttribute(obj, attr_name) % Initialize the return values @@ -533,10 +533,20 @@ classdef libiio_if < handle for l = 0 : attr_no - 1 attr = calllib(obj.libname, 'iio_channel_get_attr', ch, l); name = calllib(obj.libname, 'iio_channel_attr_get_filename', ch, attr); - if(strcmp(name, attr_name)) - attr_found = 1; + % The attribute to find can contain wildcard '*' characters, + % search for all the substrings in the attribute name + str_find = strsplit(attr_name, '*'); + attr_found = 1; + for i = 1 : length(str_find) + ret = strfind(name, str_find{i}); + if(isempty(ret)) + attr_found = 0; + break; + end + end + if(attr_found == 1) break; - end + end clear attr; end % Check if the attribute was found