📄 write_bitfieldhex.m
字号:
function dummy = write_bitfieldhex(nn,index,data)
% Private. Bitfield hexadecimal write.
% Copyright 2002 The MathWorks, Inc.
% $Revision: 1.2 $ $Date: 2002/05/14 19:46:57 $
error(nargchk(2,3,nargin));
if ~ishandle(nn),
error('First Parameter must be a BITFIELD Handle.');
end
if nargin==2,
data = index;
end;
% Is data a valid input
if ~ischar(data) & ~(iscellstr(data) & length(data)==1)
error('DATA must be must be an array of hexidecimal strings ');
end
% Convert from hex to numeric
data = hex2dec(data) * (2^nn.offset); % shift data by the its offset
% Reshape value according to ARRAYORDER property
if strcmp(nn.arrayorder,'row-major'),
data = reshape(permute(data,[2 1]),1,[]);
else
data = reshape(data,1,[]);
end
% Data is numeric format
% Do we have sufficent values ?
nvalues = numel(data);
nvaldef = prod(nn.size);
if nvalues < nvaldef,
% warning('DATA has less elements than specified numeric array, DATA will only be applied to beginning of memory area');
elseif nvalues > nvaldef,
% warning('DATA has more elements than specified numeric array, DATA will be be limited to defined memory area');
data = data(1:nvaldef); % Truncate!
end
% Convert numeric values into array of AUs
% where each column is the the AUs necessary for one numeric value
% The data will be little-endian (swapped later if necessary)
% thus cc.write([1 256]), where storageunitspervalue = 3, represent = 'unsigned', bitsperstorageunit = 8
% fdata =
% 1 0
% 0 1
% 0 0
data = { dec2hex( data ) };
zerostr = '0';
uidata = [];
for i=1:length(data),
mustlen = round( nn.bitsperstorageunit * nn.storageunitspervalue/4 ); % total bits in a value div (4 bits in a character)
needzerochars = mustlen-length(data{i});
if needzerochars > -1
data{i} = [zerostr(ones(1,needzerochars)) data{i}];
else
warning(['Overflow: Saturation was required to fit into the specified numeric range']);
data{i} = data{i}(1+abs(needzerochars):end);
end
newdata = hex2dec( flipud(reshape(data{i},mustlen/nn.storageunitspervalue,[])') )';
uidata = horzcat(uidata, newdata);
end
uidata = uidata';
% Endianness swap (if necessary), Little endian only
if strcmp( nn.endianness,'big') & (nn.storageunitspervalue > 1),
uidata = flipud(uidata);
end
% Call base class (memoryobj) to get unformatted data
memdata = read_memoryobj(nn);
memdata = reshape(double(memdata),nn.storageunitspervalue,[]);
% temp = dec2bin(memdata);
base = dec2bin( bitshift((2^nn.length-1), ...
nn.prepad+nn.offset,nn.prepad+nn.offset+nn.length), nn.wordsize);
baseinv = dec2bin( (2^nn.wordsize-1) - bin2dec(base) );
% base = bin2dec(flipud(reshape( base,[],nn.storageunitspervalue)'));
baseinv = bin2dec(flipud(reshape(baseinv,[],nn.storageunitspervalue)'));
if strcmp( nn.endianness,'big') & (nn.storageunitspervalue > 1),
base = flipud(base);
baseinv = flipud(baseinv);
end
memdata = bitand(memdata,baseinv); % zero out bit field only
uidata = bitor(memdata,uidata);
% Write raw values to memory
if nargin == 2,
write_memoryobj(nn,uidata);
else % timeout % index version - one value only!
write_memoryobj(nn,(index-1).*nn.storageunitspervalue+1,uidata);
end
% [EOF] write_bitfieldhex.m
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -