- сделан выбор папки с MCU Wrapper

- добавлен файл для работы с путями
- добавлен файл для работы с компилятором (не доделан)
This commit is contained in:
2025-06-15 10:25:24 +03:00
parent 966ddc3bac
commit 0a2fd71422
6 changed files with 423 additions and 296 deletions

139
McuLib/m/compiler.m Normal file
View File

@@ -0,0 +1,139 @@
classdef compiler
methods(Static)
function compile()
addpath(mcuPath.get('wrapperPath'));
mexing(1);
end
function get_availbe()
addpath(mcuPath.get('wrapperPath'));
mexing(1);
end
function choose()
addpath(mcuPath.get('wrapperPath'));
mexing(1);
end
function updateRunBat()
sources = {
'MCU.c'
'mcu_wrapper.c'
};
% Список заголовочных файлов (.h)
includes = { '.\'
};
periphPath = mcuPath.get('wrapperPath');
% Формируем строки
wrapperSrcText = compiler.createSourcesBat('code_WRAPPER', sources, periphPath);
wrapperIncText = compiler.createIncludesBat('includes_WRAPPER', includes, periphPath);
% Записываем результат
res = compiler.updateRunMexBat(wrapperSrcText, wrapperIncText, ':: WRAPPER BAT'); % Всё прошло успешно
if res == 0
return
end
sources = {
'app_wrapper.c'
'app_init.c'
'app_io.c'
};
% Список заголовочных файлов (.h)
includes = { '.\'
};
periphPath = mcuPath.get('appWrapperPath');
% Формируем строки
wrapperSrcText = compiler.createSourcesBat('code_APP_WRAPPER', sources, periphPath);
wrapperIncText = compiler.createIncludesBat('includes_APP_WRAPPER', includes, periphPath);
% Записываем результат
res = compiler.updateRunMexBat(wrapperSrcText, wrapperIncText, ':: APP WRAPPER BAT'); % Всё прошло успешно
end
function res = updateRunMexBat(srcText, incText, Section)
% Входные параметры:
% srcText - текст для записи set code_...
% incText - текст для записи set includes_...
%
% Возвращает:
% res - 0 при успехе, 1 при ошибке
periphBat = [srcText '\n\n' incText];
batPath = fullfile(mcuPath.get('wrapperPath'), 'run_mex.bat');
res = 1;
try
code = fileread(batPath);
code = regexprep(code, '\r\n?', '\n');
% Записываем строки srcText и incText с переносами строк
code = editCode.insertSection(code, Section, periphBat);
fid = fopen(batPath, 'w', 'n', 'UTF-8');
if fid == -1
error('Не удалось открыть файл для записи');
end
fwrite(fid, code);
fclose(fid);
res = 1;
catch ME
mcuMask.disp(0, '\nОшибка: неудачная запись в файл при записи файла: %s', ME.message);
end
end
function srcText = createSourcesBat(prefix_name, sources, path)
srcList = {};
if nargin >= 2 && iscell(sources)
for i = 1:numel(sources)
fullPath = fullfile(path, sources{i});
srcList{end+1} = strrep(fullPath, '\', '\\');
end
end
% Формируем srcText с переносами строк и ^
srcText = '';
for i = 1:numel(srcList)
if i < numel(srcList)
srcText = [srcText srcList{i} '^' newline ' '];
else
srcText = [srcText srcList{i}];
end
end
% Добавляем префикс
srcText = ['set ' prefix_name '=' srcText];
end
function incText = createIncludesBat(prefix_name, includes, path)
incList = {};
if nargin >= 2 && iscell(includes)
for i = 1:numel(includes)
fullPath = fullfile(path, includes{i});
incList{end+1} = ['-I"' strrep(fullPath, '\', '\\') '"'];
end
end
% Формируем incText с переносами строк и ^
incText = '';
for i = 1:numel(incList)
if i == 1 && numel(incList) ~= 1
incText = [incText incList{i} '^' newline];
elseif i < numel(incList)
incText = [incText ' ' incList{i} '^' newline];
else
incText = [incText ' ' incList{i}];
end
end
% Добавляем префикс
incText = ['set ' prefix_name '=' incText];
end
end
end