⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbc_rfcomms_server.m

📁 simulink real-time workshop for dragon12 development board from
💻 M
📖 第 1 页 / 共 2 页
字号:
function [buf_sizestr, RXTXmodestr, RFchannelstr, clientstr, serverAddressstr, clientAddressstr, channelstr, data_type_str, sampletime_str] = ...
          mbc_rfComms_server(sampletime, RXTXmode, RFchannel, numClient, serverAddress, clientAddress, channel, buf_size, data_type, format, outformat)

MAX_RFCOM_CHANNELS = 127;
MAX_RFCOM_USERCHANNELS = 10;    % 10 channels per client (-> abs. max. 50)
MAX_BUF_SIZE = 32;

% inactivate link to library...
if(~strcmp(get_param(gcb, 'LinkStatus'), 'inactive'))
	set_param(gcb,'LinkStatus','inactive')
end


% check server address
if( (strcmp(serverAddress(1:2), '0x') == 1) & (length(serverAddress) == 10) )
    
    % general format is ok
    if(~any(setdiff(serverAddress(3:end), ['0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'b' 'c' 'd' 'e' 'f' 'A' 'B' 'C' 'D' 'E' 'F'])))

        % accept server address
        serverAddressstr = serverAddress;
        
    else
        
        % found illegal characters
    	fprintf ('rfComms_server: Inadmissible server address (not a hexadecimal number).\n');
        
    end
        
else
    
    % overall format not correct
   	fprintf ('rfComms_server: Inadmissible server address (length, might not start with ''0x''.\n');
    
end
    
% check client address
if( (strcmp(clientAddress(1:2), '0x') == 1) & (length(clientAddress) == 10) )
    
    % general format is ok
    if(~any(setdiff(clientAddress(3:end), ['0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'b' 'c' 'd' 'e' 'f' 'A' 'B' 'C' 'D' 'E' 'F'])))

        % accept client address
        clientAddressstr = clientAddress;
        
    else
        
        % found illegal characters
    	fprintf ('rfComms_server: Inadmissible client address (not a hexadecimal number).\n');
        
    end
        
else
    
    % overall format not correct
   	fprintf ('rfComms_server: Inadmissible client address (length, might not start with ''0x''.\n');
    
end


% assemble clientflagmask
MC9S12RFCommsBlocks = find_system(gcs, 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'Tag', 'MC9S12target_RFCOMMS');
myClients = [];
for(i = 1:length(MC9S12RFCommsBlocks))
    
    % only check 'server' blocks
    if(~isempty(findstr(MC9S12RFCommsBlocks{i}, 'rfComms_Server')))
        
        % get current settings
        ll = get_param(MC9S12RFCommsBlocks{i}, 'RTWData');
        myClients = [myClients str2num(ll.numClient)];
        
    end
    
end
myClients = unique(myClients);
myNumClients = length(myClients);

% assemble mask
clientmasks = [ 2, 4, 8, 16, 32 ];
clientmask = 0;
for(i = 1:myNumClients)
    clientmask = clientmask + clientmasks(myClients(i));
end
clientmaskstr = num2str(clientmask);

% adjust 'clientflagmask'
for(i = 1:length(MC9S12RFCommsBlocks))
    
    % only check 'server' blocks
    if(~isempty(findstr(MC9S12RFCommsBlocks{i}, 'rfComms_Server')))
        
        % get current settings
        ll = get_param(MC9S12RFCommsBlocks{i}, 'RTWData');
        ll.clientflagmask = clientmaskstr;
        
        % write adjusted settings back
        set_param(MC9S12RFCommsBlocks{i}, 'RTWData', ll);
        
    end
    
end


% Check the sample time:
if ((sampletime < 0) & (sampletime ~= -1))
   fprintf ('RFComms_server: Inadmissible sample time !\n');
   sampletime_str = 'invalid';
else
   if(sampletime == -1)
      sampletime_str = 'inherited';
   else
      if(sampletime == 0)
         sampletime_str = 'continuous';
      else
         sampletime_str = [num2str(sampletime) ' s'];
      end
   end
end


% Check channel number
if ((channel < 0) | (channel > MAX_RFCOM_USERCHANNELS))
   channelstr = '???';
   fprintf ('RFComms_server: Inadmissible user channel number !\n');
else
   channelstr = num2str (channel);
end


% Check RFchannel number
if ((RFchannel < 0) | (RFchannel > MAX_RFCOM_CHANNELS))
   RFchannelstr = '???';
   fprintf ('RFComms_server: Inadmissible RF channel number !\n');
else
   RFchannelstr = num2str (RFchannel);
end


% Check the number of inputs and adapt the underlying Simulink block to it:
if (buf_size < 1) | (buf_size > MAX_BUF_SIZE)
   fprintf ('RFComms_server: Inadmissible buffer size!\n');
   buf_sizestr = '???'
else
   buf_sizestr = num2str (buf_size);
end


% set RXTXmode string
RXTXmodelabels = {'RX', 'TX'};
RXTXmodestr = RXTXmodelabels{RXTXmode};


% display cosmetics... assemble 'clientstr'
clientstr = ['Client: ' num2str(numClient)];


% set data conversion type according to the block parameter 'data_type'
myBlocks = find_system(gcb, 'LookUnderMasks', 'all');
DTC = [];for(i = 1:length(myBlocks)), DTC = [DTC ~isempty(findstr(myBlocks{i},'Data Type Conversion'))]; end, DTC = find(DTC);

% define data_types as text
data_sz_str={'single', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'boolean'};

% get data_type_string
data_type_str = data_sz_str{data_type};


% telegram format (raw / formatted)
formatstr = num2str(format);

if(format == 1)
    
    if (strcmp(RXTXmodestr, 'TX') == 1)
        
        set_param(gcb, 'MaskVisibilities', {'on', 'on', 'on', 'on', 'on', 'on', 'off', 'on', 'off', 'on', 'off' });
        % set_param(gcb, 'MaskEnables', {'on', 'on', 'on', 'on', 'on', 'on', 'off', 'on', 'off', 'on', 'off' });

        % adjust mask
        kk = get_param(gcb, 'MaskPrompts');
        kk{4} = 'Client to transmit to';
        set_param(gcb, 'MaskPrompts', kk);
        
    else
        
        set_param(gcb, 'MaskVisibilities', {'on', 'on', 'on', 'on', 'on', 'on', 'off', 'on', 'off', 'on', 'on' });
        % set_param(gcb, 'MaskEnables', {'on', 'on', 'on', 'on', 'on', 'on', 'off', 'on', 'off', 'on', 'on' });
        
        % adjust mask
        kk = get_param(gcb, 'MaskPrompts');
        kk{4} = 'Client to receive from';
        set_param(gcb, 'MaskPrompts', kk);
        
    end

    channelstr = '-';
    data_type_str = 'uint8';
    
else

    if (strcmp(RXTXmodestr, 'TX') == 1)
        
        set_param(gcb, 'MaskVisibilities', {'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'off' });
        % set_param(gcb, 'MaskEnables', {'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'off' });

        % adjust mask
        kk = get_param(gcb, 'MaskPrompts');
        kk{4} = 'Client to transmit to';
        set_param(gcb, 'MaskPrompts', kk);
        
    else
        
        set_param(gcb, 'MaskVisibilities', {'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on' });
        % set_param(gcb, 'MaskEnables', {'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on', 'on' });
        
        % adjust mask
        kk = get_param(gcb, 'MaskPrompts');
        kk{4} = 'Client to receive from';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -