Commits (1)
MyBool = Simulink.AliasType;
MyBool.BaseType = 'boolean';
MyBool.Description = 'A simple BOOLEAN';
T_Int8 = Simulink.AliasType;
T_Int8.BaseType = 'int8';
T_Int8.Description = 'range is (-128, 127)';
T_UInt32 = Simulink.AliasType;
T_UInt32.BaseType = 'uint32';
T_UInt32.Description = 'range is (0, 4294967295)';
% Values for MyEnum:
MyEnum_value_hello = 0;
MyEnum_value_world = 1;
MyEnum_value_howareyou = 2;
MyEnum = Simulink.AliasType;
MyEnum.BaseType = 'int32';
MyEnum.Description = 'values of ENUMERATED MyEnum';
T_UInt8 = Simulink.AliasType;
T_UInt8.BaseType = 'uint8';
T_UInt8.Description = 'range is (0, 255)';
MyInteger = Simulink.AliasType;
MyInteger.BaseType = 'uint8';
MyInteger.Description = 'range is (0, 255)';
% Values for MySeq-validity:
MySeq_validity_value_valid = 0;
MySeq_validity_value_invalid = 1;
MySeq_validity = Simulink.AliasType;
MySeq_validity.BaseType = 'int32';
MySeq_validity.Description = 'values of ENUMERATED MySeq-validity';
MySeq_elem01=Simulink.BusElement;
MySeq_elem01.name='input_data';
MySeq_elem01.DataType='uint8';
MySeq_elem01.dimensions=1;
MySeq_elem02=Simulink.BusElement;
MySeq_elem02.name='output_data';
MySeq_elem02.DataType='uint8';
MySeq_elem02.dimensions=1;
MySeq_elem03=Simulink.BusElement;
MySeq_elem03.name='validity';
MySeq_elem03.DataType='int32';
MySeq_elem03.dimensions=1;
MySeq = Simulink.Bus;
MySeq.Elements = [MySeq_elem01 MySeq_elem02 MySeq_elem03 ];
MyChoice_elem01=Simulink.BusElement;
MyChoice_elem01.name='choiceIdx';
MyChoice_elem01.DataType='uint8';
MyChoice_elem01.dimensions=1;
MyChoice_elem02=Simulink.BusElement;
MyChoice_elem02.name='a';
MyChoice_elem02.DataType='boolean';
MyChoice_elem02.dimensions=1;
MyChoice_elem03=Simulink.BusElement;
MyChoice_elem03.name='b';
MyChoice_elem03.DataType='MySeq';
MyChoice_elem03.dimensions=1;
MyChoice = Simulink.Bus;
MyChoice.Elements = [MyChoice_elem01 MyChoice_elem02 MyChoice_elem03 ];
MyOctStr_member_data=Simulink.BusElement;
MyOctStr_member_data.name='element_data';
MyOctStr_member_data.DataType='uint8';
MyOctStr_member_data.dimensions=3;
MyOctStr=Simulink.Bus;
MyOctStr.Elements = [MyOctStr_member_data ];
MySeqOf_member_data=Simulink.BusElement;
MySeqOf_member_data.name='element_data';
MySeqOf_member_data.DataType='int32';
MySeqOf_member_data.dimensions=2;
MySeqOf=Simulink.Bus;
MySeqOf.Elements = [MySeqOf_member_data ];
MyGyroVal = Simulink.AliasType;
MyGyroVal.BaseType = 'double';
MyGyroVal.Description = 'range is (-100000.0, 100000.0)';
T_Boolean = Simulink.AliasType;
T_Boolean.BaseType = 'boolean';
T_Boolean.Description = 'A simple BOOLEAN';
MyAccVal = Simulink.AliasType;
MyAccVal.BaseType = 'double';
MyAccVal.Description = 'range is (-16.0, 16.0)';
T_Int32 = Simulink.AliasType;
T_Int32.BaseType = 'int32';
T_Int32.Description = 'range is (-2147483648, 2147483647)';
MyReal = Simulink.AliasType;
MyReal.BaseType = 'double';
MyReal.Description = 'range is (0.0, 1000.0)';
run Simulink_DataView_asn;
inports_positions = zeros(6, 4);
bussel_positions = zeros(6, 4);
outports_positions = zeros(0, 4);
buscre_positions = zeros(0, 4);
if (exist('Get_IMU_Data') == 4),
simulink('open');
load_system('Get_IMU_Data');
open_system('Get_IMU_Data');
inportHan = find_system('Get_IMU_Data','FindAll','on', 'SearchDepth', 1, 'BlockType','Inport');
outportHan = find_system('Get_IMU_Data','FindAll','on', 'SearchDepth', 1, 'BlockType','Outport');
% ---------------------------------------------------------------------------------
% start by removing the Bus Selectors / then lines / finally ports
% ---------------------------------------------------------------------------------
% get the handles of all the lines connected to inports
for i=1:length(inportHan)
inports_positions(i,:) = get_param(inportHan(i),'Position'); % remember Inport's position
line_structsIn(i)=get_param(inportHan(i),'LineHandles'); % get the structures
inLinesHan(i)=line_structsIn(i).Outport; % get the line connected to the block's Outport
if (inLinesHan(i) ~= -1) % if exists
dstBlock = get_param(inLinesHan(i),'DstBlockHandle'); % get the destination block's handle
if (strcmp(get_param(dstBlock,'BlockType'),'BusSelector'))
bussel_positions(i,:) = get_param(dstBlock,'Position'); % remember Bus Selector's position
blockLineStructs = get_param(dstBlock,'LineHandles'); % get the line connected structures
blockLineHandles = blockLineStructs.Outport; % get the line handlers connected to the bus's outports
for j=1:length(blockLineHandles)
if (blockLineHandles(j) ~= -1)
delete(blockLineHandles(j));
end
end
delete_block(dstBlock); % delete it if it is a Bus Selector Block
end
delete(inLinesHan(i)); % delete the respective line
end
delete_block(inportHan(i)); % delete the outdated inport block
end
% now remove the outports
for i=1:length(outportHan)
outports_positions(i,:) = get_param(outportHan(i),'Position'); % remember Outport's position
line_structsOut(i)=get_param(outportHan(i),'LineHandles'); % get the structures
outLinesHan(i)=line_structsOut(i).Inport; % get the line connected to the block's Inport
if (outLinesHan(i) ~= -1) % if exists
srcBlock = get_param(outLinesHan(i),'SrcBlockHandle'); % get the source block's handle
if (strcmp(get_param(srcBlock,'BlockType'),'BusCreator'))
buscre_positions(i,:) = get_param(srcBlock,'Position'); % remember Bus Creator's position
blockLineStructs = get_param(srcBlock,'LineHandles'); % get the line connected structures
blockLineHandles = blockLineStructs.Inport; % get the line handlers connected to the bus's outports
for j=1:length(blockLineHandles)
if (blockLineHandles(j) ~= -1)
delete(blockLineHandles(j));
end
end
delete_block(srcBlock); % delete it if it is a Bus Creator Block
end
delete(outLinesHan(i)); % delete the respective line
end
delete_block(outportHan(i)); % delete the outdated outport block
end
else
simulink('open');
new_system('Get_IMU_Data');
open_system('Get_IMU_Data');
end
add_block('simulink/Sources/In1','Get_IMU_Data/gyro_X');
if inports_positions(1)>0
set_param('Get_IMU_Data/gyro_X','Position', inports_positions(1,:));
else
set_param('Get_IMU_Data/gyro_X','Position',[25 25 55 39]);
end
set_param('Get_IMU_Data/gyro_X','BusOutputAsStruct','on');
set_param('Get_IMU_Data/gyro_X','DataType','Specify via Dialog');
set_param('Get_IMU_Data/gyro_X','OutDataType','MyGyroVal');
add_block('simulink/Sources/In1','Get_IMU_Data/gyro_Y');
if inports_positions(2)>0
set_param('Get_IMU_Data/gyro_Y','Position', inports_positions(2,:));
else
set_param('Get_IMU_Data/gyro_Y','Position',[25 125 55 139]);
end
set_param('Get_IMU_Data/gyro_Y','BusOutputAsStruct','on');
set_param('Get_IMU_Data/gyro_Y','DataType','Specify via Dialog');
set_param('Get_IMU_Data/gyro_Y','OutDataType','MyGyroVal');
add_block('simulink/Sources/In1','Get_IMU_Data/gyro_Z');
if inports_positions(3)>0
set_param('Get_IMU_Data/gyro_Z','Position', inports_positions(3,:));
else
set_param('Get_IMU_Data/gyro_Z','Position',[25 225 55 239]);
end
set_param('Get_IMU_Data/gyro_Z','BusOutputAsStruct','on');
set_param('Get_IMU_Data/gyro_Z','DataType','Specify via Dialog');
set_param('Get_IMU_Data/gyro_Z','OutDataType','MyGyroVal');
add_block('simulink/Sources/In1','Get_IMU_Data/acc_X');
if inports_positions(4)>0
set_param('Get_IMU_Data/acc_X','Position', inports_positions(4,:));
else
set_param('Get_IMU_Data/acc_X','Position',[25 325 55 339]);
end
set_param('Get_IMU_Data/acc_X','BusOutputAsStruct','on');
set_param('Get_IMU_Data/acc_X','DataType','Specify via Dialog');
set_param('Get_IMU_Data/acc_X','OutDataType','MyAccVal');
add_block('simulink/Sources/In1','Get_IMU_Data/acc_Y');
if inports_positions(5)>0
set_param('Get_IMU_Data/acc_Y','Position', inports_positions(5,:));
else
set_param('Get_IMU_Data/acc_Y','Position',[25 425 55 439]);
end
set_param('Get_IMU_Data/acc_Y','BusOutputAsStruct','on');
set_param('Get_IMU_Data/acc_Y','DataType','Specify via Dialog');
set_param('Get_IMU_Data/acc_Y','OutDataType','MyAccVal');
add_block('simulink/Sources/In1','Get_IMU_Data/acc_Z');
if inports_positions(6)>0
set_param('Get_IMU_Data/acc_Z','Position', inports_positions(6,:));
else
set_param('Get_IMU_Data/acc_Z','Position',[25 525 55 539]);
end
set_param('Get_IMU_Data/acc_Z','BusOutputAsStruct','on');
set_param('Get_IMU_Data/acc_Z','DataType','Specify via Dialog');
set_param('Get_IMU_Data/acc_Z','OutDataType','MyAccVal');
set_param('Get_IMU_Data','SaveOutput','off');
set_param('Get_IMU_Data','SignalLogging','off');
set_param('Get_IMU_Data','SaveTime','off')
set_param('Get_IMU_Data','Solver','FixedStepDiscrete');
set_param('Get_IMU_Data','SystemTargetFile','ert.tlc');
set_param('Get_IMU_Data','TemplateMakefile','ert_default_tmf');
set_param('Get_IMU_Data', 'PostCodeGenCommand', 'packNGo(buildInfo);');
set_param('Get_IMU_Data','StrictBusMsg','ErrorLevel1')
save_system('Get_IMU_Data');
close_system('Get_IMU_Data');
simulink('close');
function []=setInputsBusCreator(in_type, in_busCrea)
if(isa(in_type, 'Simulink.Bus'))
s='';
if(length(in_type.Elements)==1);
set_param(in_busCrea, 'Inputs', '1');
else for i=1:length(in_type.Elements)
s=strcat(s,in_type.Elements(i).name);
if i < length(in_type.Elements)
s=strcat(s, ',');
end
end
set_param(in_busCrea, 'Inputs', s);
end
end
function []=setOutputsBusSelector(in_type, in_busSel)
if(isa(in_type, 'Simulink.Bus'))
s='';
for i=1:length(in_type.Elements)
s=strcat(s,in_type.Elements(i).name);
if i < length(in_type.Elements)
s=strcat(s, ',');
end
end
set_param(in_busSel, 'OutputSignals', s);
end