gusucode.com > vnt工具箱matlab源码程序 > vnt/vntblks/vntmasks/private/privatevntslgetdisplaystring.m
function [dispString, port] = privatevntslgetdisplaystring %PRIVATEVNTSLGETDISPLAYSTRING Return a display string for the Vehicle Network block. % % DISPSTRING = PRIVATEVNTSLGETDISPLAYSTRING returns a display string, % DISPSTRING, for the Vehicle Network Toolbox block. % SS 04-01-08 % Copyright 2008-2014 The MathWorks, Inc. % We are called every time the mask is initialized, % so the current block is always ours. blk = gcb; blkh = gcbh; % Initialize port port = []; % Check if we're in the library. If so, don't display any dynamic info. % g863841: Use the display for all library settings than just canlib. blkDiagExists = false; try blkDiagType = get_param(gcs, 'BlockDiagramType'); blkDiagExists = true; catch e %#ok<NASGU> % Do not do anything. end % Determine the block type. blkType = get_param(blk, 'FunctionName'); if blkDiagExists % 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, then it will. if strcmpi(blkDiagType, 'library') % Display String inside the library switch blkType case 'svntcanconfig' dispString = sprintf('CAN\nConfiguration'); case 'svntcanreceive' dispString = sprintf('CAN\nReceive'); port(1).id = 1; port(1).label = 'f()'; port(2).id = 2; port(2).label = 'CAN Msg'; case 'svntcantransmit' dispString = sprintf('CAN\nTransmit'); port(1).id = 1; port(1).label = 'CAN Msg'; case 'svntcanreplay' dispString = sprintf('CAN\nMessage\nReplay'); case 'svntcanlog' dispString = sprintf('CAN\nMessage\nLog'); end return; end end % Display updated for models. % Set the block handle. allFields = set(blkh); if isfield(allFields, 'BlockHandle') set_param(blk, 'BlockHandle', num2str(gcbh)); end % Query the block for the device name and handle the case where no device % is selected. device = get_param(blk, 'Device'); if strcmpi(device, '(none)') % No devices are available, so don't bother % customizing the display string. dispString = sprintf('No available\nCAN devices'); switch blkType case 'svntcanconfig' case 'svntcanreceive' port(1).id = 1; port(1).label = 'f()'; port(2).id = 2; port(2).label = 'CAN Msg'; case 'svntcantransmit' port(1).id = 1; port(1).label = 'CAN Msg'; end return; end % Extract the vendor and device name out of the "VENDOR DEVNAME (CHANNEL#)" string. 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 = sprintf('%s\n%s', vendorDeviceName, channel); end defaultMaskDisplayString = sprintf('%s\n%s', ... '[str, port] = vntslgate(''privatevntslgetdisplaystring'');', 'disp(str);'); addStr = ''; switch blkType case 'svntcanconfig' % Get Bus speed. busSpeed = get_param(blk, 'BusSpeed'); % Form display string. dispString = sprintf('%s\nBus speed: %s', dispString, busSpeed); case 'svntcanreceive' % @TODO - Add display for receive block. % Get filter status and update string. filterStdIDs = get_param(blk, 'StandardIDs'); filterExtIDs = get_param(blk, 'ExtendedIDs'); if strcmpi(get_param(blk, 'InternalFilterUpdateStatus'), 'on') if strcmpi(get_param(blk, 'StdIDsCombo'), 'Allow only') dispString = sprintf('%s\nStd. IDs: %s', dispString, filterStdIDs); elseif strcmpi(get_param(blk, 'StdIDsCombo'), 'Allow all') dispString = sprintf('%s\nStd. IDs: all', dispString); elseif strcmpi(get_param(blk, 'StdIDsCombo'), 'Block all') dispString = sprintf('%s\nStd. IDs: none', dispString); end if strcmpi(get_param(blk, 'ExtIDsCombo'), 'Allow only') dispString = sprintf('%s\nExt. IDs: %s', dispString, filterExtIDs); elseif strcmpi(get_param(blk, 'ExtIDsCombo'), 'Allow all') dispString = sprintf('%s\nExt. IDs: all', dispString); elseif strcmpi(get_param(blk, 'ExtIDsCombo'), 'Block all') dispString = sprintf('%s\nExt. IDs: none', dispString); end else % Filter settings still from old releases. if strcmpi(get_param(blk, 'EnableStandardIDsFilter'), 'on') dispString = sprintf('%s\nStd. IDs: %s', dispString, filterStdIDs); else dispString = sprintf('%s\nStd. IDs: all', dispString); end if strcmpi(get_param(blk, 'EnableExtendedIDsFilter'), 'on') dispString = sprintf('%s\nExt. IDs: %s', dispString, filterExtIDs); else dispString = sprintf('%s\nExt. IDs: all', dispString); end end addStr = sprintf('\nport_label(''output'',port(1).id,port(1).label);\nport_label(''output'',port(2).id,port(2).label);'); port(1).id = 1; port(1).label = 'f()'; port(2).id = 2; port(2).label = 'CAN Msg'; case 'svntcantransmit' % Set port information. addStr = sprintf('\nport_label(''input'',port(1).id,port(1).label);'); port(1).id = 1; port(1).label = 'CAN Msg'; case 'svntcanreplay' fileName = get_param(blk, 'FileName'); variableName = get_param(blk, 'VariableName'); if strcmpi(get_param(blk, 'ReplayTo'), 'CAN Bus') if strcmpi(get_param(blk, 'Device'), 'Select a device') dispString = 'No device selected'; end fileNameStr = sprintf('File: %s', fileName); fileNameStr = localShortenString(fileNameStr); variableNameStr = sprintf('Variable: %s', variableName); variableNameStr = localShortenString(variableNameStr); dispString = sprintf('%s\n%s\n%s', fileNameStr, variableNameStr, dispString); set(blkh, 'MaskDisplay', defaultMaskDisplayString); return; end % We replay to Simulink. % Build the MaskDisplayString in the block library based on NUMBERPORTS addStr = sprintf('\nport_label(''output'',port(1).id,port(1).label);\nport_label(''output'',port(2).id,port(2).label);'); port(1).id = 1; port(1).label = 'f()'; port(2).id = 2; port(2).label = 'CAN Msg'; fileNameStr = sprintf('File: %s', fileName); fileNameStr = localShortenString(fileNameStr); variableNameStr = sprintf('Variable: %s', variableName); variableNameStr = localShortenString(variableNameStr); dispString = sprintf('%s\n%s', fileNameStr, variableNameStr); case 'svntcanlog' fileName = get_param(blk, 'FileName'); variableName = get_param(blk, 'VariableName'); if strcmpi(get_param(blk, 'LogFrom'), 'CAN Bus') if strcmpi(get_param(blk, 'Device'), 'Select a device') dispString = 'No device selected'; end fileNameStr = sprintf('File: %s', fileName); fileNameStr = localShortenString(fileNameStr); variableNameStr = sprintf('Variable: %s', variableName); variableNameStr = localShortenString(variableNameStr); dispString = sprintf('%s\n%s\n%s', fileNameStr, variableNameStr, dispString); set(blkh, 'MaskDisplay', defaultMaskDisplayString); return; end % We log from input port. % Build the MaskDisplayString in the block library based on NUMBERPORTS addStr = sprintf('\nport_label(''input'',port(1).id,port(1).label);'); port(1).id = 1; port(1).label = 'CAN Msg'; fileNameStr = sprintf('File: %s', fileName); fileNameStr = localShortenString(fileNameStr); variableNameStr = sprintf('Variable: %s', variableName); variableNameStr = localShortenString(variableNameStr); dispString = sprintf('%s\n%s', fileNameStr, variableNameStr); end maskDisplayString = strcat(defaultMaskDisplayString, addStr); set(blkh, 'MaskDisplay', maskDisplayString); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%