-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed export model information script issue with masked subsystems.
- Loading branch information
1 parent
480f519
commit 5c1597a
Showing
1 changed file
with
84 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,46 @@ | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% | ||
% Authors: Hamza Bourbouh, Anastasia Mavridou <[email protected]>, Andreas Katis <[email protected]> | ||
% Notices: | ||
% | ||
% Copyright @ 2020 United States Government as represented by the | ||
% Administrator of the National Aeronautics and Space Administration. All | ||
% Rights Reserved. | ||
% | ||
% Disclaimers | ||
% | ||
% No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY | ||
% WARRANTY OF ANY KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, | ||
% BUT NOT LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM | ||
% TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS | ||
% FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT | ||
% THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT | ||
% DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE. THIS | ||
% AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN ENDORSEMENT BY | ||
% GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS, RESULTING | ||
% DESIGNS, HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS RESULTING | ||
% FROM USE OF THE SUBJECT SOFTWARE. FURTHER, GOVERNMENT AGENCY DISCLAIMS | ||
% ALL WARRANTIES AND LIABILITIES REGARDING THIRD-PARTY SOFTWARE, IF PRESENT | ||
% IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT "AS IS." | ||
% | ||
% Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS | ||
% AGAINST THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, | ||
% AS WELL AS ANY PRIOR RECIPIENT. IF RECIPIENT'S USE OF THE SUBJECT | ||
% SOFTWARE RESULTS IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES OR | ||
% LOSSES ARISING FROM SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED | ||
% ON, OR RESULTING FROM, RECIPIENT'S USE OF THE SUBJECT SOFTWARE, RECIPIENT | ||
% SHALL INDEMNIFY AND HOLD HARMLESS THE UNITED STATES GOVERNMENT, ITS | ||
% CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT, TO THE | ||
% EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER | ||
% SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT. | ||
% | ||
% Notice: The accuracy and quality of the results of running CoCoSim | ||
% directly corresponds to the quality and accuracy of the model and the | ||
% requirements given as inputs to CoCoSim. If the models and requirements | ||
% are incorrectly captured or incorrectly input into CoCoSim, the results | ||
% cannot be relied upon to generate or error check software being developed. | ||
% Simply stated, the results of CoCoSim are only as good as | ||
% the inputs given to CoCoSim. | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% // ***************************************************************************** | ||
% // Notices: | ||
% // | ||
% // Copyright � 2019 United States Government as represented by the Administrator | ||
% // of the National Aeronautics and Space Administration. All Rights Reserved. | ||
% // | ||
% // Disclaimers | ||
% // | ||
% // No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF | ||
% // ANY KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED | ||
% // TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, | ||
% // ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, | ||
% // OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL BE | ||
% // ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED, WILL CONFORM TO | ||
% // THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN | ||
% // ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS, | ||
% // RESULTING DESIGNS, HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS | ||
% // RESULTING FROM USE OF THE SUBJECT SOFTWARE. FURTHER, GOVERNMENT AGENCY | ||
% // DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING THIRD-PARTY SOFTWARE, IF | ||
% // PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT ''AS IS.'' | ||
% // | ||
% // Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST | ||
% // THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS | ||
% // ANY PRIOR RECIPIENT. IF RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS IN | ||
% // ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES OR LOSSES ARISING FROM SUCH USE, | ||
% // INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING FROM, RECIPIENT'S | ||
% // USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD HARMLESS THE | ||
% // UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY | ||
% // PRIOR RECIPIENT, TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY FOR | ||
% // ANY SUCH MATTER SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS | ||
% // AGREEMENT. | ||
% // ***************************************************************************** | ||
|
||
% If you want to use this on a model with CoCoSim contracts, start CoCoSim first. | ||
|
||
|
||
function [ir_struct, json_model] = fret_IR( model_full_path, output_dir ) | ||
|
||
%% Initialisation | ||
|
||
df_export = true; | ||
|
||
load_system(model_full_path) | ||
load_system(model_full_path); | ||
[parent, file_name, ~] = fileparts(model_full_path); | ||
%% Construction of the internal representation | ||
ir_struct = {}; | ||
|
@@ -72,7 +63,8 @@ | |
end | ||
|
||
try | ||
ir_struct = fret_subsystems_struct(file_name, ir_struct); | ||
systemChoice = chooseSubsystem(file_name); | ||
ir_struct = fret_subsystems_struct(systemChoice, ir_struct); | ||
catch | ||
Cmd = [file_name, '([], [], [], ''term'');']; | ||
eval(Cmd); | ||
|
@@ -102,7 +94,7 @@ | |
output_dir = parent; | ||
end | ||
if df_export | ||
file_json = [file_name '_forFRET.json']; | ||
file_json = [get_param(systemChoice, 'Name') '_forFRET.json']; | ||
% Open or create the file | ||
file_path = fullfile(output_dir, file_json); | ||
fid = fopen(file_path, 'w'); | ||
|
@@ -112,19 +104,62 @@ | |
end | ||
end | ||
|
||
function [choice] = chooseSubsystem(file_name) | ||
|
||
%% Find all non-mask (Sub)systems and prompt user to select target as root. | ||
|
||
content = find_system(file_name, 'LookUnderMasks', 'all', 'FollowLinks', 'on','BlockType','SubSystem'); | ||
|
||
promptList="\n\nList of Subsystems:\n------------------------\n\n"; | ||
numOfSubSystems = numel(content); | ||
count=1; | ||
for i=1:numOfSubSystems | ||
if isempty(Simulink.Mask.get(content{i})) | ||
promptList = strcat(promptList, int2str(count), ': ', content{i}, '\n'); | ||
count = count+1; | ||
end | ||
end | ||
|
||
indexChoice = input(strcat(promptList, "\n------------------------\n\n", sprintf('Select subsystem from the list above (index value) [default: 1]: '))); | ||
if isempty(indexChoice) | ||
indexChoice = 1; | ||
end | ||
while ~ (isfinite(indexChoice) & indexChoice == floor(indexChoice) & indexChoice >=1 & indexChoice <= numOfSubSystems) | ||
indexChoice = input('Incorrect value entered. Please provide an option from the list using the corresponding integer index value [default: 1]: '); | ||
end | ||
|
||
choice = content{indexChoice}; | ||
end | ||
|
||
function ir_struct = fret_subsystems_struct( block_path, ir_struct ) | ||
blockTypesFret = {'Inport', 'Outport'}; | ||
content = find_system(block_path, 'LookUnderMasks', 'all', 'FollowLinks', 'on'); | ||
|
||
%Andreas: Removing recursive option as it is not currently needed. | ||
%Ask user if they want to recursively retrieve all the information, starting with the selected (Sub)system as root. | ||
% recursiveChoice = upper(input('Apply recursively? Y/N [default: N]: ','s')); | ||
% if isempty(recursiveChoice) | ||
% recursiveChoice = 'N'; | ||
% end | ||
|
||
% if ~ (recursiveChoice == 'Y' | recursiveChoice == 'N') | ||
% recursiveChoice = 'N'; | ||
% end | ||
|
||
% if recursiveChoice == 'Y' | ||
% content = find_system(block_path, 'LookUnderMasks', 'all', 'FollowLinks', 'on'); | ||
% else | ||
|
||
content = find_system(block_path, 'SearchDepth', 1, 'LookUnderMasks', 'all'); | ||
|
||
% IR of all blocks contained in the subsystem or block_diagram | ||
for i=1:numel(content) | ||
try | ||
blkType = get_param(content{i}, 'BlockType'); | ||
isParentNotMask = isempty(Simulink.Mask.get(get_param(content{i}, 'Parent'))); | ||
catch | ||
continue; | ||
end | ||
if ismember(blkType, blockTypesFret) | ||
if ismember(blkType, blockTypesFret) & isParentNotMask | ||
ir_struct{end+1} = fret_common_struct(content{i}); | ||
end | ||
|
||
|