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

📄 config.m

📁 simulink real-time workshop for dragon12 development board from
💻 M
字号:
function varargout = config(varargin)
% CONFIG Application M-file for config.fig
%    FIG = CONFIG launch setup GUI.
%    CONFIG('callback_name', ...) invoke the named callback.

% Last Modified by GUIDE v2.0 31-Jul-2001 10:53:57

if nargin == 0  % LAUNCH GUI
    
    % set MATLAB search path...
    cd('..');
    installdir = pwd;
    
    % avoid having to recompile the libraries all the time...
    adjustMarkerFile(installdir);

    % possibly remove previous installations from the MATLAB path
    kk = lower(path);
    kksect  = [1 strfind(kk,';')+1];
    mcfind = strfind(kk, '\mc');
    while(~isempty(mcfind))
        oldinstpath = lower(kk(kksect(max(find(kksect<mcfind(1)))):kksect(min(find(kksect>mcfind(1))))-5));
        binfind = strfind(kk, [oldinstpath '\bin']);
        mcfind  = strfind(kk, [oldinstpath '\mc']);
        if(~isempty(binfind) & ~isempty(mcfind))
            rmpath([oldinstpath '\bin'],[oldinstpath '\mc']);
        end
        mcfind(1) = [];             % in case more path endings '\mc;' were found...
    end
    rehash;
    
    addpath([installdir '/bin'], [installdir '/mc'], '-begin');
    path2rc;                     % save path...
    cd([installdir '/bin']);

    % copy system file 'make_mc9S12.m' to the MATLAB folder '<MATLAB_ROOT>\toolbox\rtw\rtw'
    rtwrtw           = dir([matlabroot '/toolbox/rtw/rtw/make_mc9S12.m']);
    orig_make_mc9S12 = dir([installdir '/bin/make_mc9S12Orig.m']);
    if(~isempty(rtwrtw))
        if(~strcmp(rtwrtw.date,orig_make_mc9S12.date))
            disp(['Copying file ' installdir '/bin/make_mc9S12Orig.m to ' matlabroot '/toolbox/rtw/rtw/make_mc9S12.m']);
            copyfile([installdir '/bin/make_mc9S12Orig.m'], [matlabroot '/toolbox/rtw/rtw/make_mc9S12.m']);
            rehash toolbox;
        end
    else
        disp(['Copying file ' installdir '/bin/make_mc9S12Orig.m to ' matlabroot '/toolbox/rtw/rtw/make_mc9S12.m']);
        copyfile([installdir '/bin/make_mc9S12Orig.m'], [matlabroot '/toolbox/rtw/rtw/make_mc9S12.m']);
        rehash toolbox;
    end

%     % rename original module 'ext_comm.dll' (MathWorks, TCP/IP) to 'ext_comm.org' (if necessary)
%     rtwrtw_backup  = dir([matlabroot '/toolbox/rtw/rtw/ext_comm.org']);
%     if(isempty(rtwrtw_backup))
%         disp(['Renaming file ' installdir '/rtw/ext_mode/ext_comm.dll to ' matlabroot '/toolbox/rtw/rtw/ext_comm.org']);
%         copyfile([matlabroot '/toolbox/rtw/rtw/ext_comm.dll'], [matlabroot '/toolbox/rtw/rtw/ext_comm.org']);
%     end

    % check if the system file 'ext_comm_mc9S12.dll' in folder '<RTmc9S12_ROOT>\bin' is up to date...
    binrtw         = dir([installdir '/bin/ext_comm_mc9S12.dll']);
    orig_ext_comm  = dir([installdir '/rtw/ext_mode/ext_comm.dll']);
    if(~isempty(binrtw))
        if(~strcmp(binrtw.date,orig_ext_comm.date))
            disp(['Copying file ' installdir '/rtw/ext_mode/ext_comm.dll to ' installdir '/bin/ext_comm_mc9S12.dll']);
            copyfile([installdir '/rtw/ext_mode/ext_comm.dll'], [installdir '/bin/ext_comm_mc9S12.dll']);
        end
    else
        disp(['Copying file ' installdir '/rtw/ext_mode/ext_comm.dll to ' installdir '/bin/ext_comm_mc9S12.dll']);
        copyfile([installdir '/rtw/ext_mode/ext_comm.dll'], [installdir '/bin/ext_comm_mc9S12.dll']);
    end

    % adjust help system paths in library file 'mc9S12toolOrig.mdl' and copy it to 'mc9S12tool.mdl'
    libfile      = [installdir '/bin/mc9S12tool.mdl'];
    orig_libfile = [installdir '/bin/mc9S12toolOrig.mdl'];
    

    % load contents of library file
    lhd = fopen(orig_libfile, 'r');
    libf = fscanf(lhd, '%c');
    fclose(lhd);
    
    % substitute token label '|>INSTALLDIR<|' by real path information
    installdir2 = strrep(installdir, '\', '\\');
    libf = strrep(libf, '|>INSTALLDIR<|', installdir2);
    
    % store modified library file
    lhd = fopen(libfile, 'wb');
    fwrite(lhd, libf);
    fclose(lhd);
    disp(['Writing adjusted library file ' libfile]);
    
    
    
    % open GUI
    fig = openfig(mfilename,'reuse');
    
    % Use system color scheme for figure:
    set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));

	% Generate a structure of handles to pass to callbacks, and store it. 
	handles = guihandles(fig);

    % initialise flag: any changes made?
    handles.nochanges = 1;
    % initialise mc9S12TARGET_ROOT (installation folder)
    handles.installdir = installdir;
%    handles.installdir = longFname2short(installdir);

    % store handles as guidata
    guidata(fig, handles);
    
    % open template makefile and determine current settings
    readtmffields([handles.installdir '\bin\mc9S12.tmf'], fig);

	if nargout > 0
		varargout{1} = fig;
	end

elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK

	try
		if (nargout)
			[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
		else
			feval(varargin{:}); % FEVAL switchyard
		end
	catch
		disp(lasterr);
	end
    
end



% --------------------------------------------------------------------
% CALLBACKS
% --------------------------------------------------------------------


% Cancel pushbutton
% --------------------------------------------------------------------
function varargout = Cancelpushbutton_Callback(h, eventdata, handles, varargin)
cd(handles.installdir)
delete(handles.figure1)
varargout{1} = -1;



% OK pushbutton
% --------------------------------------------------------------------
function varargout = OKpushbutton_Callback(h, eventdata, handles, varargin)
if(~handles.nochanges)
    pos_size = get(handles.figure1,'Position');
    user_response = configexitdlg([pos_size(1)+pos_size(3)/5 pos_size(2)+pos_size(4)/5]);
    switch user_response
    case {'no','cancel'}
        % take no action
    case 'yes'
        % save changes...
        disp(['Saving settings to ' handles.installdir '\bin\mc9S12.tmf'])
        writetmffields([handles.installdir '/bin/mc9S12.tmf'], gcbo);

        % ... and exit
        cd(handles.installdir)
        delete(handles.figure1)
    end
else
    % exit without saving ...
    cd(handles.installdir)
    delete(handles.figure1)
end
    

% compiler text box
% --------------------------------------------------------------------
function varargout = Compileredit_Callback(h, eventdata, handles, varargin)
handles.nochanges = 0;
guidata(gcbo,handles);


% work text box
% --------------------------------------------------------------------
function varargout = Workedit_Callback(h, eventdata, handles, varargin)
handles.nochanges = 0;
guidata(gcbo,handles);


% % work radio button
% % --------------------------------------------------------------------
% function varargout = Workradiobutton_Callback(h, eventdata, handles, varargin)
% handles.nochanges = 0;
% guidata(gcbo,handles);


% compiler push button
% --------------------------------------------------------------------
function varargout = Compilerpushbutton_Callback(h, eventdata, handles, varargin)
pos_size = get(handles.figure1,'Position');
kk = get(handles.Compileredit, 'String');
if(exist(kk))
    cd(kk);
end
user_response = folderdlg([pos_size(1)+pos_size(3)/5 pos_size(2)+pos_size(4)/5]);
if(~strcmp(user_response, 'cancel'))
    handles.nochanges = 0;
    set(handles.Compileredit, 'String', user_response);
%    set(handles.Compileredit, 'String', longFname2short(user_response));
    guidata(gcbo,handles);
end


% work push button
% --------------------------------------------------------------------
function varargout = Workpushbutton_Callback(h, eventdata, handles, varargin)
pos_size = get(handles.figure1,'Position');
kk = get(handles.Workedit, 'String');
if(exist(kk))
    cd(kk);
end
user_response = folderdlg([pos_size(1)+pos_size(3)/5 pos_size(2)+pos_size(4)/5]);
if(~strcmp(user_response, 'cancel'))
    handles.nochanges = 0;
    set(handles.Workedit, 'String', user_response);
%    set(handles.Workedit, 'String', longFname2short(user_response));
    guidata(gcbo,handles);
end



% CloseRequestFcn
% ------------------------------------------------------------
function varargout = figure1_CloseRequestFcn(h, eventdata, handles, varargin)
if(handles.nochanges)
    OKpushbutton_Callback(h,eventdata,handles)                  % exit via 'OK'
else
    Cancelpushbutton_Callback(h,eventdata,handles)              % exit via 'Cancel'
end






% ------------------------------------------------------------
% support functions
% ------------------------------------------------------------

% readtmffields
% ------------------------------------------------------------
function readtmffields(tmffile, fig)

% load template makefile
tmf = textread(tmffile, '%s', 'delimiter', '\n', 'whitespace', ' ');

% read handles structure
handles = guidata(fig);

% determine path variables
for(i= 1:length(tmf))
    
    % filter out 'WORK_DIR_TXT' and change it to new value
    kk = findstr(tmf{i},'WORK_DIR_TXT');
    if(~isempty(kk) &  kk == 1)
        kk = tmf{i};
        kk = kk(findstr(kk,'=')+1:end);                     % filter out specifier
        while(kk(1) == ' ')                                 % remove leading blanks
            kk(1) = [];
        end
        kk = deblank(kk);                                   % remove trailing blanks
%        kk = longFname2short(kk);                           % turn long filename into short filname (8.3) -> cheap fix, doesn't always work 
        set(handles.Worktxt, 'String', kk);
    end
    
end

% not used anymore...
clear tmf;




% writetmffields MATLAB 6 and MATLAB 6.1
% ------------------------------------------------------------
function writetmffields(tmffile, fig)

% read handles structure
handles = guidata(fig);

% load contents of template makefile
whd = fopen(tmffile, 'r');
tmf = fscanf(whd, '%c');
fclose(whd);

% % filter out specifiers...
% % ... begin
% useworktxtdefb = min(findstr(tmf,['USE_WORK_DIR']))+7;
% 
% % ... end
% useworktxtdefe = useworktxtdefb + min(findstr(tmf(useworktxtdefb:end),[char(13) char(10)]));
% 
% % ... adjust begin
% useworktxtdefb = useworktxtdefb + findstr(tmf(useworktxtdefb:useworktxtdefe), '-');
% 
% % ... overread blanks
% while(tmf(useworktxtdefb) == ' ')
%     useworktxtdefb = useworktxtdefb + 1;
% end
% 
% % adjust to selected value
% myRadio = get(handles.radiobutton1, 'Value');
% if(myRadio == 1)
%     tmf(useworktxtdefb:useworktxtdefe) = ['yes' 13 10];
% else
%     tmf(useworktxtdefb:useworktxtdefe) = ['no ' 13 10];
% end

% ... begin
worktxtdefb = min(findstr(tmf,['WORK_DIR_TXT']))+7;

% ... end
worktxtdefe = worktxtdefb + min(findstr(tmf(worktxtdefb:end),[char(13) char(10)]));

% ... adjust begin
worktxtdefb = worktxtdefb + findstr(tmf(worktxtdefb:worktxtdefe), '-');

% ... overread blanks
while(tmf(worktxtdefb) == ' ')
    worktxtdefb = worktxtdefb + 1;
end

% update path variables
newworktxt = get(handles.Workedit, 'String');

% save adjusted file
whd = fopen(tmffile, 'w');
fprintf(whd, '%c', tmf(1:worktxtdefb-1));
fprintf(whd, '%s\r\n', newworktxt);

fprintf(whd, '%c', tmf(worktxtdefe+1:end));

fclose(whd);



% % writetmffields MATLAB 6.1
% % ------------------------------------------------------------
% function writetmffields(tmffile, fig)
% 
% % load template makefile
% tmf = textread(tmffile, '%s', 'delimiter', '\n', 'whitespace', '');
% 
% % read handles structure
% handles = guidata(fig);
% 
% % update path variables
% for(i= 1:length(tmf))
%     % filter out 'mc9S12TARGET_ROOT' and change it to new value
%     kk = findstr(tmf{i},'mc9S12TARGET_ROOT');
%     if(~isempty(kk) &  kk == 1)
%         kk = tmf{i};
%         kk(findstr(kk,'='):end) = [];
%         kk = [kk '= ' handles.installdir];
%         tmf{i} = kk;
%     end
% 
%     % filter out 'COMPILER_ROOT' and change it to new value
%     kk = findstr(tmf{i},'COMPILER_ROOT');
%     if(~isempty(kk) &  kk == 1)
%         kk = tmf{i};
%         kk(findstr(kk,'='):end) = [];
%         kk = [kk '= ' get(handles.Compileredit, 'String')];
%         tmf{i} = kk;
%     end
%     
%     % filter out 'MAKE' and change it to new value
%     kk = findstr(tmf{i},'MAKE');
%     if(~isempty(kk) &  kk == 1)
%         kk = tmf{i};
%         kk(findstr(kk,'='):end) = [];
%         kk = [kk '= ' get(handles.Makeedit, 'String') '\gmake.exe'];
%         tmf{i} = kk;
%     end
% 
%     % filter out 'WORK_ROOT' and change it to new value
%     kk = findstr(tmf{i},'WORK_ROOT');
%     if(~isempty(kk) &  kk == 1)
%         kk = tmf{i};
%         kk(findstr(kk,'='):end) = [];
%         kk = [kk '= ' get(handles.Workedit, 'String')];
%         tmf{i} = kk;
%     end
% end
% 
% 
% % save template makefile
% whd = fopen(tmffile, 'w');
% for(i= 1:length(tmf))
%     fprintf(whd, '%s\n', tmf{i});
% end
% fclose(whd);
% 

⌨️ 快捷键说明

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