gusucode.com > vnt工具箱matlab源码程序 > vnt/vntblks/vntmasks/private/privatecantlstring.m
function dispString = privatecantlstring %PRIVATECANTLSTRING Return a display string for XCP and J1939 CAN TL blocks. % % DISPSTRING = PRIVATECANTLSTRING returns a display string, % DISPSTRING, and port information , PORT, for the XCP/J1939 CAN TL block. % Copyright 2015 The MathWorks, Inc. % We are called every time the mask is initialized, % so the current block is always ours. blk = gcb; blkh = gcbh; % Set dispString to empty. dispString = []; % Check if we're in the library. If so, don't display any dynamic info. parentBlk = get_param(blk, 'Parent'); switch parentBlk case {'vntxcptllib' 'xcplib'} % This check should be done inside the outer level if statement. % Not all blocks have a BlockDiagramType parameter (e.g. subsystems), % but if the parent is canlib or canmsglib, then it will. blkDiagType = get_param(gcs, 'BlockDiagramType'); if strcmpi(blkDiagType, 'library') dispString = sprintf('XCP CAN\nTransport Layer'); return; end case {'vntj1939tllib' 'vntj1939lib' 'j1939vnttllib'} % This check should be done inside the outer level if statement. % Not all blocks have a BlockDiagramType parameter (e.g. subsystems), % but if the parent is canlib or canmsglib, then it will. blkDiagType = get_param(gcs, 'BlockDiagramType'); if strcmpi(blkDiagType, 'library') dispString = sprintf('J1939 CAN\nTransport Layer'); return; end end % Get the reference block. maskType = get(blkh, 'MaskType'); % Get the Config name. configName = get_param(blkh, 'ConfigName'); if strcmpi(configName, 'Select a config name') dispString = sprintf('No config selected'); else dispString = sprintf('%s', configName); end % Extract the vendor and device name out of the "VENDOR DEVNAME (CHANNEL#)" string. device = get_param(blk, 'Device'); spIndex = strfind(device, '('); if ~isempty(spIndex) % Extract devName and Channel. vendorDeviceName = device(1:spIndex(1)-2); % channel = device( spIndex(1)+1:end-1 ); % Shorten vendor/device name if required. Arbitrarily set % to 20 characters. vendorDeviceName = localShortenString(vendorDeviceName); % Shorten channel name if required. channel = localShortenString(channel); % Form the basic display string. dispString = strcat(dispString, '\n', vendorDeviceName, '\n', channel); elseif strcmpi(get_param(blk, 'Device'), 'Select a device') % Form display string. dispString = strcat(dispString, '\n', 'No device selected'); end %% Extract required parameters. objConstructor = get_param(blk, 'ObjConstructor'); busSpeed = get_param(blk, 'BusSpeedStr'); sampleTime = get_param(blk, 'SampleTime'); % Set the underlying library blocks to correct values. %% CAN Configuration block. configBlkName = sprintf('%s/CAN Configuration', blk); set_param(configBlkName, 'BlockHandle', num2str(get_param(configBlkName, 'Handle'))); set_param(configBlkName, 'Device', device); set_param(configBlkName, 'ObjConstructor', objConstructor); set_param(configBlkName, 'BusSpeed', busSpeed); %% CAN Receive block. recBlkName = sprintf('%s/CAN Receive', blk); set_param(recBlkName, 'BlockHandle', num2str(get_param(recBlkName, 'Handle'))); set_param(recBlkName, 'Device', device); set_param(recBlkName, 'ObjConstructor', objConstructor); set_param(recBlkName, 'SampleTime', sampleTime); %% CAN Transmit block transmitBlkName = sprintf('%s/CAN Transmit Subsystem/CAN Transmit', blk); set_param(transmitBlkName, 'BlockHandle', num2str(get_param(transmitBlkName, 'Handle'))); set_param(transmitBlkName, 'Device', device); set_param(transmitBlkName, 'ObjConstructor', objConstructor); %% Transport Layer Transmit block switch maskType case 'XCP CAN Transport Layer' tltxBlkName = sprintf('%s/XCP CAN Transport Layer Transmit', blk); set_param(tltxBlkName, 'SampleTime', sampleTime); case 'J1939 CAN Transport Layer' tltxBlkName = sprintf('%s/J1939 Transport Layer Transmit', blk); tlrxBlkName = sprintf('%s/J1939 Transport Layer Receive Subsystem/J1939 Transport Layer Receive', blk); set_param(tltxBlkName, 'SampleTime', sampleTime); set_param(tltxBlkName, 'TLID', configName); set_param(tlrxBlkName, 'TLID', configName); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function inStr = localShortenString(inStr) % Function that shortens the display string to 17 characters if greater % than 20. % Shorten the string if required. if length(inStr) > 20, inStr = [inStr(1:17) '...']; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%