├── .gitignore ├── .travis.yml ├── AUTHORS ├── Guidelines.md ├── LICENSE ├── README.md ├── libs ├── ObserverBlock.mdl └── cocosimLibs.slx ├── pre-commit.cmd ├── pre-commit.sh ├── sanity ├── README ├── pre_release_script.m └── sanity_check.py ├── sl_customization.m ├── src ├── add_cocospec.m ├── backEnd │ ├── jkind.m │ ├── kind2.m │ ├── lustrec.m │ ├── rust.m │ ├── seahorn.m │ ├── solver_result.m │ ├── templates │ │ ├── ann.html │ │ ├── annot.html │ │ ├── complex_arith_int.lus │ │ ├── complex_arith_real.lus │ │ ├── footer.html │ │ ├── header.html │ │ ├── launch_sim_embedded_annotation.m │ │ ├── launch_simulation.m │ │ ├── list_item.html │ │ ├── list_item_mat_code.html │ │ ├── list_title.html │ │ ├── materialize.css │ │ ├── plotting.m │ │ ├── title.html │ │ └── title2.html │ └── zustre.m ├── cocoSim.m ├── cocosim_menu.m ├── cocosim_pp.m ├── config.m ├── frontEnd │ ├── app_sprintf.m │ ├── blocks2lustre.m │ ├── blocks_dt_conversions.m │ ├── blocks_interconnection.m │ ├── blocks_interconnection_complet.m │ ├── clean_inter.m │ ├── flatten_subsystems.m │ ├── get_model_blocks_ports_dts.m │ ├── list_var_action.m │ ├── list_var_entree.m │ ├── list_var_input.m │ ├── list_var_outport.m │ ├── list_var_sortie.m │ ├── lookuptable.m │ ├── mk_internalRep.m │ ├── num_block.m │ ├── preprocess_model.m │ ├── realornot.m │ ├── ss2subsyst.m │ ├── transfo_entier_real.m │ ├── write_code.m │ └── ztransform.m ├── gui │ ├── add_property.m │ ├── cocosim_window.m │ ├── unsupported_blocks_gui.m │ └── validate_window.m ├── log4m.m ├── middleEnd │ ├── CoCoSpec.m │ ├── Parallel_states_call.m │ ├── add_node_param.m │ ├── add_unchanged_variables.m │ ├── add_variables.m │ ├── chart2lus.m │ ├── chart_and_function_code.m │ ├── construct_node_header.m │ ├── convert_cocospec.m │ ├── extern_nodes_header.m │ ├── math_functions.m │ ├── temporal_operators.m │ ├── transition_code.m │ ├── update_variables.m │ ├── write_3x3_Matrix.m │ ├── write_SignalConversion.m │ ├── write_Transition_actions.m │ ├── write_abs.m │ ├── write_action.m │ ├── write_assignment.m │ ├── write_bias.m │ ├── write_bitwise.m │ ├── write_busassignment.m │ ├── write_buscreator.m │ ├── write_buses.m │ ├── write_busselector.m │ ├── write_compareto.m │ ├── write_concatenate.m │ ├── write_constant.m │ ├── write_constantes.m │ ├── write_crossproduct.m │ ├── write_datatypeconversion.m │ ├── write_delay.m │ ├── write_demux.m │ ├── write_detect.m │ ├── write_discreteintegrator.m │ ├── write_dotproduct.m │ ├── write_dss.m │ ├── write_enableport.m │ ├── write_entree_sorties.m │ ├── write_extern_functions.m │ ├── write_extern_s_function.m │ ├── write_foriterator.m │ ├── write_fromworkspace.m │ ├── write_function_block.m │ ├── write_gain.m │ ├── write_global_node.m │ ├── write_goto_from.m │ ├── write_ifelseif.m │ ├── write_logic.m │ ├── write_lookupnddirect.m │ ├── write_math_fun.m │ ├── write_matlab_function_node.m │ ├── write_memory.m │ ├── write_merge.m │ ├── write_minmax.m │ ├── write_multiportswitch.m │ ├── write_mux.m │ ├── write_outport.m │ ├── write_polyval.m │ ├── write_product.m │ ├── write_property.m │ ├── write_relationaloperator.m │ ├── write_reshape.m │ ├── write_s_function.m │ ├── write_saturation.m │ ├── write_saturation_dynamic.m │ ├── write_selector.m │ ├── write_sf_Matlab_function_node.m │ ├── write_signalspecification.m │ ├── write_signum.m │ ├── write_state_actions.m │ ├── write_state_node.m │ ├── write_subsystem.m │ ├── write_sum.m │ ├── write_switch.m │ ├── write_switchcase.m │ ├── write_triggerport.m │ ├── write_trigo.m │ ├── write_unitdelay.m │ └── write_zero_pole.m ├── pp │ ├── README │ ├── default_constants.m │ ├── doc │ │ └── pp_doc.tex │ ├── lib │ │ ├── blocks │ │ │ ├── chart_process.m │ │ │ ├── clock_process.m │ │ │ ├── constant_process.m │ │ │ ├── deadzone_dynamic_process.m │ │ │ ├── deadzone_process.m │ │ │ ├── discrete_integrator_process.m │ │ │ ├── discrete_state_space_process.m │ │ │ ├── from_workspace_process.m │ │ │ ├── function_process.m │ │ │ ├── gain_process.m │ │ │ ├── goto_process.m │ │ │ ├── integrator_process.m │ │ │ ├── lookuptable_nD_process.m │ │ │ ├── lookuptable_process.m │ │ │ ├── math_process.m │ │ │ ├── product_process.m │ │ │ ├── pulsegenerator_process.m │ │ │ ├── rate_transition_process.m │ │ │ ├── replace_variables.m │ │ │ ├── saturation_dynamic_process.m │ │ │ ├── saturation_process.m │ │ │ ├── selector_process.m │ │ │ ├── signalbuilder_process.m │ │ │ ├── to_workspace_process.m │ │ │ ├── transfer_function_process.m │ │ │ └── zero_pole_process.m │ │ ├── common │ │ │ ├── datatable_process.m │ │ │ ├── gal_lib.slx │ │ │ ├── goto_block_process.m │ │ │ ├── pos.m │ │ │ ├── remove_line_tags.m │ │ │ ├── replace_one_block.m │ │ │ ├── state_matrix_process.m │ │ │ └── verification_template.slx │ │ └── math │ │ │ ├── expr_parser.py │ │ │ ├── expression_process.m │ │ │ └── parse_math.m │ └── pp.m ├── unsupported_blocks.m ├── utils │ ├── BusUtils.m │ ├── Constants.m │ ├── Utils.m │ ├── XML_Trace.m │ ├── cprintf.m │ ├── display_msg.m │ ├── func2node.py │ ├── generate-tables.py │ ├── get_full_name.m │ ├── log4m.m │ ├── messagetype.m │ ├── parse_json.m │ ├── sT2fT.m │ ├── setdiff_struct.m │ ├── sort_by_order.m │ ├── split_transition.m │ ├── to_XML.m │ └── traceability_annotation.m ├── validate_model.m └── view_cocospec.m ├── start_cocosim.m └── test ├── Fcn ├── Fcn.slx ├── Fcn2.slx └── Fcn3.slx ├── StateFlow ├── test_all.m ├── tests_with_properties │ ├── Arrays1V2.mdl │ ├── MicrowaveCex.slx │ ├── MicrowaveV2.mdl │ └── set_up_parameters.m └── tests_without_properties │ ├── BSCU.slx │ ├── BSCU_Active_State.mdl │ ├── BSCU_Brake_Mode.mdl │ ├── BSCU_Brake_cmd.mdl │ ├── BSCU_Duration.mdl │ ├── CruiseState.mdl │ ├── DA1.mdl │ ├── DockingApproachExample_Ext.mdl │ ├── GPCA_Alarm.mdl │ ├── GPCA_CONFIG.mdl │ ├── GPCA_INFUSION_MGR.mdl │ ├── GPCA_Logging.mdl │ ├── GPCA_System_Monitor.mdl │ ├── GPCA_Top_Level_Mode.mdl │ ├── MicrowaveModified.mdl │ └── set_up_parameters.m ├── cocospec ├── AltitudeControl_Demo.slx └── cocospec_3.slx ├── compilation └── simple.mdl └── properties ├── AltitudeControl_Demo.slx ├── assertion.mdl ├── assumption.slx ├── safe_1.mdl ├── safe_math_functions.slx ├── two_property.mdl └── unsafe_1.mdl /.gitignore: -------------------------------------------------------------------------------- 1 | src/config.m 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Lead developer: 2 | Temesghen Kahsai : teme DOT Kahsai AT sv DOT cmu DOT com (NASA AMES / CMU) 3 | 4 | Contributors: 5 | Hamza BOURBOUH : bourbouhh AT gmail DOT com 6 | Arnaud Dieumegard : arnaud DOT dieumegard AT gmail DOT com 7 | Thomas LOQUEN : Thomas DOT Loquen AT onera DOT fr (ONERA) 8 | Claire PAGETTI : Claire DOT Pagetti AT onera DOT fr (ONERA) 9 | Eric NOULARD : Eric DOT Noulard AT onera DOT fr (ONERA) 10 | -------------------------------------------------------------------------------- /Guidelines.md: -------------------------------------------------------------------------------- 1 | How to be sure your model is well supported by our tool: 2 | 3 | * Make sure all Simulink blocks has the same `Sample Time` 4 | * Blocks names should start with a character or underscore 5 | 6 | 7 | 8 | 9 | Some constraints for some specific blocks: 10 | 11 | ### Discrete-Time Integrator 12 | 13 | * We support only `Forward Euler method` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | CoCoSim Automated Analysis Framework 2 | Copyright (c) 2016 Carnegie Mellon University. 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following acknowledgments and 11 | disclaimers. 12 | 13 | 2. Redistributions in binary form must reproduce the 14 | above copyright notice, this list of conditions and the following 15 | acknowledgments and disclaimers in the documentation and/or other 16 | materials provided with the distribution. 17 | 18 | 3. Products derived from this software may not include “Carnegie 19 | Mellon University,” in the name of such derived product, 20 | nor shall “Carnegie Mellon University,” be used to 21 | endorse or promote products derived from this software without prior 22 | written permission. 23 | 24 | 25 | ACKNOWLEDGMENTS AND DISCLAIMERS: 26 | 27 | Copyright 2016 Carnegie Mellon University 28 | 29 | This material is based upon work funded and supported by 30 | NASA NRA Contract No. NNX14AI09G and NSF Award No. 1422705. 31 | 32 | Any opinions, findings and conclusions or recommendations expressed in 33 | this material are those of the author(s) and do not necessarily 34 | reflect the views of NASA nor NSF. 35 | 36 | 37 | NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY MATERIAL 38 | IS FURNISHED ON AN “AS-IS” BASIS. CARNEGIE MELLON 39 | UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR 40 | IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF 41 | FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS 42 | OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT 43 | MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, 44 | TRADEMARK, OR COPYRIGHT INFRINGEMENT. 45 | 46 | 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/coco-team/cocoSim.svg?branch=master)](https://travis-ci.org/coco-team/cocoSim) 2 | 3 | # CoCoSim 4 | 5 | CoCoSim is an automated analysis and code generation framework for 6 | Simulink and Stateflow models. Specifically, CoCoSim can be used to 7 | verify automatically user-supplied safety requirements. Moreover, 8 | CoCoSim can be used to generate C and/or Rust code. CoCoSim uses 9 | Lustre as its intermediate language. CoCoSim is currently under 10 | development. We welcome any feedback and bug report. 11 | 12 | [![ScreenCast of CoCoSim](http://i.imgur.com/itLte0X.png)](https://youtu.be/dcs8GOeFI9c) 13 | 14 | ## CoCoSim ToolBox 15 | 16 | The CoCoSim toolbox contains linux and osx binariers for the backend solvers. 17 | Download the [CoCoSim ToolBox](https://github.com/coco-team/cocoSim/releases) 18 | 19 | 20 | 21 | ## Installation 22 | 23 | CoCoSim can be installed and used as follows: 24 | 25 | ### Dependencies 26 | 27 | * MATLAB(c) version **R2014b** or newer 28 | * [Zustre](https://github.com/lememta/zustre) 29 | * (Optional) [JKind](https://github.com/agacek/jkind) -- Best for Windows OS users 30 | * (Optional) [Kind2](http://kind2-mc.github.io/kind2/) 31 | * Python2.7 32 | 33 | ### Configuration 34 | 35 | * Place the different solvers (Zustre, Kind2, JKind) under ```cocosim/tools/verifiers/```. 36 | * Set the configuration for the backend solvers in `src/config.m`: 37 | * `ZUSTRE`: Path to [Zustre](https://github.com/coco-team/zustre) binary. 38 | * `KIND2`: Path to [Kind2](https://github.com/kind2-mc/kind2) binary. 39 | * `LUSTREC`: Path to [LustreC](https://github.com/coco-team/lustrec) binary. 40 | * `Z3`: Path to Z3 binary. If you install Zustre, Z3 can be found in `ZUSTRE_PATH/build/run/bin/z3`. 41 | * `JKIND`: Path to [JKind](https://github.com/agacek/jkind). 42 | 43 | 44 | ### Launching 45 | 46 | + Launch Matlab(c) 47 | + Navigate to `cocosim/` 48 | + Just run the file ```start_cocosim``` 49 | + Make sure to have one of the backround solvers installed (e.g. Zustre, Kind2 and or JKind) 50 | + You can now open your Simulink model, e.g. ```open test/properties/safe_1.mdl``` 51 | 52 | ## # Example 53 | 54 | 1. To test a safe property: `open test/properties/safe_1.mdl` 55 | 2. Under the `Tools` menu choose `Verify with ...` and then `Zustre` (or JKind if you are under Windows OS). 56 | 3. To test an unsafe property (which also provide a counterexample): 57 | `open test/properties/unsafe_1.mdl` 58 | 59 | More information about CoCoSim can be found [here](https://github.com/coco-team/cocoSim/wiki/CoCoSim) 60 | 61 | ## Waffle 62 | [![Stories in Ready](https://badge.waffle.io/coco-team/cocoSim.png?label=ready&title=Ready)](https://waffle.io/coco-team/cocoSim) 63 | [![Throughput Graph](https://graphs.waffle.io/coco-team/cocoSim/throughput.svg)](https://waffle.io/coco-team/cocoSim/metrics/throughput) 64 | 65 | ## Developers 66 | 67 | * Lead Developer: [Temesghen Kahsai](http://www.lememta.info/) 68 | 69 | * Current Contributors: Hamza Bourbouh (SGT - USA), Pierre-Loic 70 | Garoche (Onera - France), Claire Pagetti (Onera - France), Eric 71 | Noulard (Onera - France), Thomas Loquen (Onera - France), Xavier 72 | Thirioux (ENSEEIHT - France) 73 | 74 | * Past Contributors: Arnaud Dieumegard (Fabruary - August 2015) 75 | 76 | 77 | ## Acknowledgments and Disclaimers 78 | 79 | CoCoSim is partially funded by: 80 | 81 | * NASA NRA NNX14AI09G 82 | * NSF award 1136008 83 | 84 | Any opinions, findings and conclusions or recommendations expressed in 85 | this material are those of the author(s) do not necessarily 86 | reflect the views of NASA and NSF. 87 | -------------------------------------------------------------------------------- /libs/cocosimLibs.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/libs/cocosimLibs.slx -------------------------------------------------------------------------------- /pre-commit.cmd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # this hook is in SCM so that it can be shared 3 | # to install it, create a symbolic link in the projects .git/hooks folder 4 | # 5 | # i.e. - from the .git/hooks directory, run 6 | # $ ln -s ../../git-hooks/pre-commit.sh pre-commit 7 | # 8 | # to skip the tests, run with the --no-verify argument 9 | # i.e. - $ 'git commit --no-verify' 10 | 11 | echo "CoCoSim Pre Commit checks ... (you better have run the regression tests)" 12 | # stash any unstaged changes 13 | git stash -q --keep-index 14 | 15 | # check for results of regression te 16 | python sanity/sanity_check.py 17 | 18 | # store the last exit code in a variable 19 | RESULT=$? 20 | 21 | echo $RESULT 22 | 23 | # unstash the unstashed changes 24 | git stash pop -q 25 | 26 | # return the './gradlew test' exit code 27 | exit $RESULT 28 | -------------------------------------------------------------------------------- /pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # this hook is in SCM so that it can be shared 3 | # to install it, create a symbolic link in the projects .git/hooks folder 4 | # 5 | # i.e. - from the .git/hooks directory, run 6 | # $ ln -s ../../pre-commit.sh pre-commit 7 | # 8 | # to skip the tests, run with the --no-verify argument 9 | # i.e. - $ 'git commit --no-verify' 10 | 11 | echo "CoCoSim Pre Commit checks ..." 12 | # stash any unstaged changes 13 | git stash -q --keep-index 14 | 15 | # check for results of regression te 16 | python sanity/sanity_check.py 17 | 18 | # store the last exit code in a variable 19 | RESULT=$? 20 | 21 | 22 | # unstash the unstashed changes 23 | git stash pop -q 24 | 25 | # return the './gradlew test' exit code 26 | exit $RESULT 27 | -------------------------------------------------------------------------------- /sanity/README: -------------------------------------------------------------------------------- 1 | This directory will contain one file reporting the result of regression testing 2 | -------------------------------------------------------------------------------- /sanity/pre_release_script.m: -------------------------------------------------------------------------------- 1 | function pre_release_script(folder_Path, version) 2 | 3 | if nargin==0 4 | [file_path, ~, ~] = fileparts(mfilename('fullpath')); 5 | folder_Path = fileparts(file_path); 6 | end 7 | if nargin < 2 8 | version = 'R2014a'; 9 | end 10 | mdl_models = dir(fullfile(folder_Path,'**/*.mdl')); 11 | slx_models = dir(fullfile(folder_Path,'**/*.slx')); 12 | models = [mdl_models; slx_models]; 13 | 14 | 15 | for i=1:numel(models) 16 | m = models(i); 17 | 18 | full_path = fullfile(folder_Path, m.name); 19 | try 20 | info = Simulink.MDLInfo(full_path); 21 | if str2double(info.SimulinkVersion) > 8.3 22 | fprintf('saving model %s in %s format\n', m.name, version); 23 | load_system(full_path); 24 | [path, base_name, ext] = fileparts(full_path); 25 | get_param(base_name,'Modelversionformat') 26 | target_filename = fullfile(path, strcat(base_name, '_tmp',ext)); 27 | 28 | Simulink.exportToVersion(base_name,target_filename,version); 29 | close_system(full_path,1); 30 | delete(full_path); 31 | copyfile(target_filename, full_path); 32 | delete(target_filename); 33 | delete(strcat(full_path,'.r20*')); 34 | display('Done'); 35 | end 36 | catch ME 37 | dsplay(ME.getReport()) 38 | continue; 39 | end 40 | 41 | end 42 | bdclose('all') 43 | end -------------------------------------------------------------------------------- /sanity/sanity_check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import glob 5 | #import time 6 | from os import path 7 | #from datetime import datetime, timedelta 8 | 9 | current_path = os.path.dirname(os.path.abspath(__file__)) 10 | 11 | print("Runing regression testing....") 12 | cocosim_path = os.path.abspath(os.path.join(current_path, os.pardir)) 13 | cocoTeam_path = os.path.abspath(os.path.join(cocosim_path, os.pardir)) 14 | regression_runner_path = os.path.abspath(os.path.join(cocoTeam_path, "regression-test/scripts")) 15 | add_path = "addpath('"+regression_runner_path+"')" 16 | bashCommand = "matlab -nodisplay -r \"try, "+add_path+"; test_all; bdclose('all'); catch e, disp(getReport(e)), exit(7); end, exit()\"" 17 | return_val = os.system(bashCommand) 18 | 19 | if return_val == 0: 20 | 21 | print("Checking for regression testing result ....") 22 | 23 | all_reg = glob.glob(current_path + os.sep + 'not_valid_models*') 24 | 25 | if len(all_reg) > 0: 26 | for reg in all_reg: 27 | print(":( You need to fix these models") 28 | with open(reg, 'r') as fin: 29 | print fin.read() 30 | exit(1) 31 | else: 32 | print(":) Good Job!!! All models are valid") 33 | exit(0) 34 | 35 | else: 36 | print(":( You need to check your regression tests:") 37 | print("1. Checkout https://github.com/coco-team/regression-test in the same folder as cocoSim") 38 | print("2. Configure scripts/test_all.m") 39 | exit(1) 40 | -------------------------------------------------------------------------------- /src/backEnd/lustrec.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | function lustrec(lustre_file_name) 8 | 9 | [path file ext] = fileparts(lustre_file_name); 10 | config; 11 | new_dir = [path '/' file '_cgen']; 12 | if ~exist(new_dir, 'dir') 13 | mkdir(new_dir); 14 | end 15 | if exist(LUSTREC,'file') 16 | date_value = datestr(now, 'ddmmyyyyHHMMSS'); 17 | command = sprintf('%s -I %s -d %s %s', LUSTREC, include_dir, new_dir, lustre_file_name); 18 | [status, lustrec_out] = system(command); 19 | if isempty(strfind(lustrec_out, '.. done')) 20 | display_msg('Error Generating C code', Constants.ERROR, 'C Generation', ''); 21 | else 22 | msg = ['C code is generated in : ' new_dir] ; 23 | display_msg(msg, Constants.RESULT, 'C Generation', ''); 24 | end 25 | else 26 | msg = 'Running C: Impossible to find LustreC'; 27 | display_msg(msg, Constants.ERROR, 'C Generation', ''); 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /src/backEnd/rust.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | function rust(lustre_file_name) 8 | 9 | [path file ext] = fileparts(lustre_file_name); 10 | config; 11 | new_dir = [path '_rust']; 12 | if ~exist(new_dir, 'dir') 13 | mkdir(new_dir); 14 | end 15 | if exist(KIND2,'file') 16 | date_value = datestr(now, 'ddmmyyyyHHMMSS'); 17 | command = sprintf('%s --compile true --z3_bin %s --output_dir %s --check_implem false %s', KIND2, Z3, new_dir, lustre_file_name); 18 | display_msg(['KIND2_COMMAND ' command], Constants.DEBUG, 'write_code', ''); 19 | [status, rust_out] = system(command); 20 | if isempty(strfind(rust_out, 'Success')) 21 | display_msg('Error Generating Rust code', Constants.ERROR, 'Rust Generation', ''); 22 | display_msg(rust_out, Constants.ERROR, 'Rust Generation', ''); 23 | else 24 | msg = ['Rust code is generated in : ' new_dir] ; 25 | display_msg(msg, Constants.INFO, 'Rust', ''); 26 | end 27 | else 28 | msg = 'Running Kind2: Impossible to find Kind2'; 29 | display_msg(msg, Constants.ERROR, 'Rust', ''); 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /src/backEnd/seahorn.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | function [smt_out_file] = seahorn(c_file_name) 8 | 9 | [path file ext] = fileparts(c_file_name); 10 | config; 11 | entry_function = file; 12 | display_msg(['Entry Function: ' entry_function], Constants.INFO, 'SEAHORN', ''); 13 | smt_out_file = fullfile(path, strcat(entry_function,'.smt2')); 14 | if exist(SEAHORN,'file') 15 | date_value = datestr(now, 'ddmmyyyyHHMMSS'); 16 | command = sprintf('%s smt -O0 --horn-no-verif --horn-stats --entry=%s -o %s %s', SEAHORN, entry_function, smt_out_file, c_file_name); 17 | 18 | [status, seahorn_out] = system(command); 19 | if isempty(strfind(seahorn_out, 'BRUNCH STATS END')) 20 | display_msg('Error Generating HORN Clause', Constants.ERROR, 'SEAHORN', ''); 21 | display_msg(seahorn_out, Constants.ERROR, 'SEAHORN', ''); 22 | else 23 | if exist(smt_out_file, 'file') 24 | msg = ['HORN Clauses are generated in : ' smt_out_file] ; 25 | display_msg(msg, Constants.RESULT, 'SEAHORN', ''); 26 | else 27 | display_msg('Error Generating HORN Clause', Constants.ERROR, 'SEAHORN', ''); 28 | display_msg(seahorn_out, Constants.ERROR, 'SEAHORN', ''); 29 | end 30 | end 31 | else 32 | msg = 'Running SEAHORN: Impossible to find SEAHORN'; 33 | display_msg(msg, Constants.ERROR, 'SeaHorn', ''); 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /src/backEnd/solver_result.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | % Parse the XML output of Solver and return the status of the result (SAFE, CEX, UNKNOWN) 7 | function [answer, cex] = solver_result(solver, xml_result, property_node_name, property_file_base_name) 8 | answer = ''; 9 | cex = ''; 10 | prop_file_name = [property_file_base_name '_' property_node_name '.xml']; 11 | fid = fopen(prop_file_name, 'w'); 12 | fprintf(fid, xml_result); 13 | fclose(fid); 14 | s = dir(prop_file_name); 15 | if s.bytes ~= 0 16 | xml_doc = xmlread(prop_file_name); 17 | xml_properties = xml_doc.getElementsByTagName('Property'); 18 | % logs = xml_doc.getElementsByTagName('Log'); 19 | % for idx=0:(logs.getLength-1) 20 | % log = logs.item(idx); 21 | % end 22 | for idx=0:(xml_properties.getLength-1) 23 | prop = xml_properties.item(idx); 24 | answer = prop.getElementsByTagName('Answer').item(0).getTextContent; 25 | 26 | if strcmp(solver, 'KIND2') || strcmp(solver, 'JKIND') 27 | if strcmp(answer, 'valid') 28 | answer = 'SAFE'; 29 | elseif strcmp(answer, 'falsifiable') 30 | answer = 'CEX'; 31 | else 32 | answer = 'UNKNOWN'; 33 | end 34 | end 35 | 36 | msg = [solver ' result for property node [' property_node_name ']: ' char(answer)]; 37 | display_msg(msg, Constants.RESULT, 'Property checking', ''); 38 | if strcmp(answer, 'CEX') || strcmp(answer, 'falsifiable') 39 | if strcmp(solver, 'JKIND') 40 | xml_cex = xml_doc.getElementsByTagName('Counterexample'); 41 | else 42 | xml_cex = xml_doc.getElementsByTagName('CounterExample'); 43 | end 44 | if xml_cex.getLength > 0 45 | cex = xml_cex; 46 | else 47 | msg = [solver ': FAILURE to get counter example: ']; 48 | msg = [msg property_node_name '\n']; 49 | display_msg(msg, Constants.WARNING, 'Property Checking', ''); 50 | end 51 | end 52 | end 53 | end 54 | end 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/backEnd/templates/ann.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 |

8 | Counter example for property_assert_test/observer

9 | 10 |

11 | Inputs:

12 |
  • 13 | In1 = [[0; 0; 0]];
  • 14 |
  • 15 | In2 = [[0; 0; 0]];
  • 16 |
  • 17 | In3 = [[0; 1/2; -1]];
  • 18 |
  • 19 | In4 = [[15 16 17;18 19 20]];
  • 20 |

    21 | Outputs:

    22 | 23 |
  • 24 | Out1 = [[1; 1/2; 2]];
  • 25 |
  • 26 | Out2 = [[0 0 0;0 0 0]];
  • 27 | 28 | -------------------------------------------------------------------------------- /src/backEnd/templates/annot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    5 | Counter example for [observer_full_name]

    6 |

    7 |

    8 | Inputs:

    9 |
  • 10 | [inport_name] = [[inport_values]];
  • 11 |

    12 |

    13 | Outputs:

    14 |
  • 15 | [outport_name] = [[outport_value]];
  • 16 | 17 | -------------------------------------------------------------------------------- /src/backEnd/templates/complex_arith_int.lus: -------------------------------------------------------------------------------- 1 | node complex_mult_int(x: complex_int; y: complex_int) 2 | returns (z: complex_int) 3 | let 4 | z.r = x.r * y.r - x.i * y.i; 5 | z.i = x.r * y.i + x.i * y.r; 6 | tel 7 | 8 | node complex_inv_int(x: complex_int) 9 | returns (z: complex_int) 10 | let 11 | z.r = x.r / (x.r * x.r - x.i * x.i); 12 | z.i = x.i / (x.r * x.r - x.i * x.i); 13 | tel 14 | 15 | node complex_sum_int(x: complex_int; y: complex_int) 16 | returns (z: complex_int) 17 | let 18 | z.r = x.r + y.r; 19 | z.i = x.i + y.i; 20 | tel 21 | -------------------------------------------------------------------------------- /src/backEnd/templates/complex_arith_real.lus: -------------------------------------------------------------------------------- 1 | node complex_mult_real(x: complex_real; y: complex_real) 2 | returns (z: complex_real) 3 | let 4 | z.r = x.r * y.r - x.i * y.i; 5 | z.i = x.r * y.i + x.i * y.r; 6 | tel 7 | 8 | node complex_inv_real(x: complex_real) 9 | returns (z: complex_real) 10 | let 11 | z.r = x.r / (x.r * x.r - x.i * x.i); 12 | z.i = x.i / (x.r * x.r - x.i * x.i); 13 | tel 14 | 15 | node complex_sum_real(x: complex_real; y: complex_real) 16 | returns (z: complex_real) 17 | let 18 | z.r = x.r + y.r; 19 | z.i = x.i + y.i; 20 | tel 21 | -------------------------------------------------------------------------------- /src/backEnd/templates/footer.html: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/backEnd/templates/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/backEnd/templates/launch_sim_embedded_annotation.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | model = find_system(gcs); 7 | configSet = copy(getActiveConfigSet(model{1})); 8 | 9 | configSet_name = ['Configuration_' model{1}]; 10 | set_param(configSet, 'Name', configSet_name); 11 | set_param(configSet, 'Solver', 'FixedStepDiscrete'); 12 | set_param(configSet, 'FixedStep', '1.0'); 13 | set_param(configSet, 'SaveState', 'on'); 14 | set_param(configSet, 'StateSaveName', 'xout'); 15 | set_param(configSet, 'OutputSaveName', 'yout'); 16 | set_param(configSet, 'StartTime', '0.0'); 17 | set_param(configSet, 'StopTime', '0.0'); 18 | set_param(configSet, 'SaveFormat', 'Structure'); 19 | set_param(configSet, 'SaveOutput', 'on'); 20 | set_param(configSet, 'SaveTime', 'on'); 21 | 22 | In1.time = [0]; 23 | In1.signals.values = [0 0 0]; 24 | In1.signals.dimensions = 3; 25 | assignin('base', 'In1', In1); 26 | 27 | In2.time = [0]; 28 | In2.signals.values = [0 0 0]; 29 | In2.signals.dimensions = 3; 30 | assignin('base', 'In2', In2); 31 | 32 | In3.time = [0]; 33 | In3.signals.values = [0 -1 1/2]; 34 | In3.signals.dimensions = 3; 35 | assignin('base', 'In3', In3); 36 | 37 | In4.time = [0]; 38 | In4.signals.values = [15 16 17; 18 19 20]; 39 | In4.signals.dimensions = [2 3]; 40 | assignin('base', 'In4', In4); 41 | 42 | set_param(configSet, 'ExtMode', 'on'); 43 | set_param(configSet, 'LoadExternalInput', 'on'); 44 | set_param(configSet, 'ExternalInput', 'In1 In2 In3 In4'); 45 | attachConfigSet(model{1}, configSet, true); 46 | setActiveConfigSet(model{1}, configSet_name); 47 | 48 | outStruct = sim(model{1}, configSet); 49 | for idx=1:numel(outStruct.get('yout').signals) 50 | disp(['Output: ' outStruct.get('yout').signals(idx).blockName]); 51 | disp(outStruct.get('yout').signals(idx).values); 52 | end 53 | -------------------------------------------------------------------------------- /src/backEnd/templates/launch_simulation.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | function outStruct = simModel(model) 6 | 7 | sys = load_system(model); 8 | configSet = getConfigSet(sys, 'DevConfig'); 9 | 10 | configSet.Solver = 'FixedStepDiscrete'; 11 | configSet.FixedStep = '1.0'; 12 | configSet.StateSaveName = 'xout'; 13 | configSet.OutputSaveName = 'yout'; 14 | configSet.StartTime = '0.0'; 15 | configSet.StopTime = '2.0'; 16 | configSet.SaveFormat = 'Structure'; 17 | configSet.SaveOutput = 'on'; 18 | configSet.SaveTime = 'on'; 19 | configSet.LoadExternalInput = 'on'; 20 | configSet.ExternalInput = 'In1'; 21 | 22 | In1.time = [0:2]; 23 | In1.signals.values = [-1; -2; -3]; 24 | In1.signals.dimensions = 1; 25 | assignin('base', 'In1', In1); 26 | 27 | outStruct = sim(model, configSet); 28 | for idx=1:numel(outStruct.get('yout').signals) 29 | disp(['Output: ' outStruct.get('yout').signals(idx).blockName]); 30 | disp(outStruct.get('yout').signals(idx).values); 31 | end 32 | 33 | end -------------------------------------------------------------------------------- /src/backEnd/templates/list_item.html: -------------------------------------------------------------------------------- 1 |
    [Item]
    2 | -------------------------------------------------------------------------------- /src/backEnd/templates/list_item_mat_code.html: -------------------------------------------------------------------------------- 1 |
    [Item]
    2 | -------------------------------------------------------------------------------- /src/backEnd/templates/list_title.html: -------------------------------------------------------------------------------- 1 |
    2 |
    3 |
    4 |

    [Title]:

    5 | [List_Content] 6 |
    7 |
    8 |
    9 | -------------------------------------------------------------------------------- /src/backEnd/templates/plotting.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function plotting(name, in ) 7 | %PLOTTING Summary of this function goes here 8 | % Detailed explanation goes here 9 | 10 | fig = findobj('Type', 'Figure', 'name', name); 11 | n_prev = 0; 12 | if numel(fig) == 0 13 | fig = figure('name', name, 'NumberTitle', 'off'); 14 | else 15 | figure(fig); 16 | axes = findall(fig, 'type', 'axes'); 17 | prev_stairs = findall(axes(1), 'type', 'stair'); 18 | n_prev = numel(prev_stairs); 19 | end 20 | 21 | cm = jet(500); 22 | step = .083; 23 | 24 | nb_io = 0; 25 | for idx_in=1:numel(in) 26 | nb_io = nb_io + numel(in{idx_in}.signals); 27 | end 28 | 29 | last_time = in{1}.time(end) + 1; 30 | time_values = [in{1}.time last_time]; 31 | 32 | cpt = 1; 33 | for idx_in=1:numel(in) 34 | for idx_sig=1:numel(in{idx_in}.signals) 35 | subplot(nb_io, 1, cpt); 36 | color_f = ((cpt -1)/nb_io) + (n_prev * step); 37 | if color_f > 1 38 | integ = floor(color_f); 39 | color_f = color_f - integ; 40 | end 41 | colorID = max(1, sum(color_f > [0:1/length(cm(:,1)):1])); 42 | color = cm(colorID, :); 43 | if numel(in{idx_in}.signals(idx_sig).values) ~= numel(time_values) 44 | last_value = in{idx_in}.signals(idx_sig).values(end); 45 | signal_values = [in{idx_in}.signals(idx_sig).values ; last_value]; 46 | else 47 | signal_values = in{idx_in}.signals(idx_sig).values; 48 | end 49 | if n_prev == 0 50 | leg = in{idx_in}.signals(idx_sig).var_name; 51 | else 52 | leg = [in{idx_in}.signals(idx_sig).var_name '_' num2str(n_prev + 1)]; 53 | end 54 | stairs(time_values, signal_values, 'LineStyle', '-', 'LineWidth', 2, 'Color', color, 'DisplayName', leg); 55 | legend('off'); 56 | l = legend('show'); 57 | set(l, 'Interpreter', 'none'); 58 | xbounds = xlim(); 59 | ylabel(in{idx_in}.signals(idx_sig).var_name, 'FontSize', 8); 60 | set(gca, 'xtick', xbounds(1):1:xbounds(2)); 61 | hold on; 62 | cpt = cpt + 1; 63 | end 64 | end 65 | xlabel('time', 'FontSize', 8); 66 | end 67 | 68 | -------------------------------------------------------------------------------- /src/backEnd/templates/title.html: -------------------------------------------------------------------------------- 1 |
    2 | 7 |
    8 | -------------------------------------------------------------------------------- /src/backEnd/templates/title2.html: -------------------------------------------------------------------------------- 1 |
    2 | 7 |
    8 | -------------------------------------------------------------------------------- /src/config.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | % Configuration file for the backend solvers 8 | if ~exist('solvers_path', 'var') 9 | [file_path, ~, ~] = fileparts(mfilename('fullpath')); 10 | cocosim_path = fileparts(file_path); 11 | if ismac 12 | solvers_path = fullfile(cocosim_path, 'tools/verifiers/osx/bin/'); 13 | JKIND =fullfile(cocosim_path,'tools/verifiers/jkind/jkind'); 14 | Z3Library_path = fullfile(cocosim_path, 'tools/verifiers/osx/lib/libz3.so'); 15 | include_dir = fullfile(cocosim_path, 'tools/verifiers/osx/include/lustrec'); 16 | elseif isunix 17 | solvers_path = fullfile(cocosim_path, 'tools/verifiers/linux/bin/'); 18 | JKIND =fullfile(cocosim_path,'tools/verifiers/jkind/jkind'); 19 | Z3Library_path = fullfile(cocosim_path, 'tools/verifiers/linux/lib/libz3.so'); 20 | include_dir = fullfile(cocosim_path, 'tools/verifiers/linux/include/lustrec'); 21 | elseif ispc 22 | % warndlg('Only JKind can be used', 'CoCoSim backend configuration') 23 | solvers_path = fullfile(cocosim_path, 'tools\verifiers\'); 24 | JKIND =fullfile(solvers_path,'jkind\jkind.bat'); 25 | Z3Library_path = fullfile(cocosim_path, 'tools\verifiers\Z3\bin\libz3.dll'); 26 | else 27 | errordlg('OS not supported yet','CoCoSim backend configuration'); 28 | end 29 | OldLibPath = getenv('LD_LIBRARY_PATH'); 30 | if isempty(strfind(OldLibPath,'libz3.so')) || ~isempty(strfind(OldLibPath,'::')) 31 | setenv('LD_LIBRARY_PATH',Z3Library_path); 32 | %to keep the old LD_LIBRARY_PATH use the following (it does not work) 33 | %setenv('LD_LIBRARY_PATH',[getenv('LD_LIBRARY_PATH') Z3Library_path ':']); 34 | end 35 | end 36 | if ~ispc 37 | LUSTREC = fullfile(solvers_path,'lustrec'); 38 | LUCTREC_INCLUDE_DIR = include_dir; 39 | end 40 | ZUSTRE = fullfile(solvers_path,'zustre'); 41 | Z3 = fullfile(solvers_path,'z3'); 42 | KIND2 = fullfile(solvers_path,'kind2'); 43 | SEAHORN = 'PATH'; 44 | cocosim_version = 'v0.1'; 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/frontEnd/app_sprintf.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [out_str] = app_sprintf(str, formatSpec, varargin) 7 | tmp = sprintf(formatSpec, varargin{:}); 8 | out_str = [str tmp]; 9 | end 10 | -------------------------------------------------------------------------------- /src/frontEnd/blocks_interconnection_complet.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | % TODO: Add summary of the function with parameters 7 | 8 | function [myblk blks] = blocks_interconnection_complet(name, mat_files, default_Ts, myblk, blks, nbmax, ref) 9 | 10 | [inter_blk1 blks1] = blocks_interconnection(name, mat_files, default_Ts, ref); 11 | 12 | nbmax = nbmax + 1; 13 | 14 | % Update the sample time value on the blocks 15 | for idx_block=1:numel(blks1) 16 | try 17 | if strcmp(inter_blk1{idx_block}.sample_time, '-1') 18 | inter_blk1{idx_block}.sample_time = num2str(default_Ts); 19 | end 20 | catch 21 | inter_blk1{idx_block}.sample_time = num2str(default_Ts); 22 | end 23 | end 24 | 25 | size_myblk = numel(myblk); 26 | myblk{size_myblk + 1} = inter_blk1; 27 | blks{size_myblk + 1} = blks1; 28 | 29 | % Is it even possible to have nbmax == 0 ? 30 | if nbmax == 0 31 | kinit = 1; 32 | else 33 | kinit = 2; 34 | end 35 | 36 | for idx_sub=kinit:numel(blks1) 37 | if strcmp(inter_blk1{idx_sub}.type, 'SubSystem') 38 | 39 | print_node = true; 40 | % Do not print masked blocks but print the Observers 41 | if strcmp(get_param(blks1{idx_sub}, 'Mask'), 'on') 42 | if strcmp(inter_blk1{idx_sub}.mask_type, 'Observer') 43 | print_node = true; 44 | elseif strcmp(inter_blk1{idx_sub}.mask_type, '') 45 | print_node = true; 46 | else 47 | print_node = false; 48 | end 49 | end 50 | 51 | if print_node 52 | lesprename = inter_blk1{idx_sub}.prename; 53 | lespostname = inter_blk1{idx_sub}.postname; 54 | lerythme = inter_blk1{idx_sub}.sample_time; 55 | lenumero = numel(myblk); 56 | 57 | [myblk blks] = blocks_interconnection_complet(inter_blk1{idx_sub}.origin_name, mat_files, lerythme, myblk, blks, nbmax, ''); 58 | 59 | idx_new_sub = lenumero + 1; 60 | myblk{idx_new_sub}{1}.prename = lesprename; 61 | myblk{idx_new_sub}{1}.postname = lespostname; 62 | end 63 | end 64 | end 65 | 66 | end 67 | -------------------------------------------------------------------------------- /src/frontEnd/clean_inter.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function inter_blk_clean=clean_inter(inter_blk, first_blk, nblk) 7 | 8 | inter_blk_clean = inter_blk; 9 | 10 | for k1=first_blk:nblk 11 | if (inter_blk{k1}.num_input ~= 0 && inter_blk{k1}.num_output ~= 0) && ~strcmp(inter_blk{k1}.type,'Merge') 12 | %recherche du dernier bloc pre (forcement celui de l'action port donc 13 | %relie au if) 14 | numel_pre = numel(inter_blk{k1}.prename); 15 | 16 | num_pre = num_block(inter_blk,inter_blk{k1}.prename{numel_pre}{1}); 17 | %verification si c'est un if 18 | if strcmp(inter_blk{num_pre}.type,'If') 19 | %alors on enleve ses infos 20 | inter_blk_clean{k1}.srcport(numel_pre)=[]; 21 | inter_blk_clean{k1}.pre(numel_pre)=[]; 22 | inter_blk_clean{k1}.prename(numel_pre)=''; 23 | inter_blk_clean{k1}.srcport_size(numel_pre)=[]; 24 | inter_blk_clean{k1}.num_input=inter_blk{k1}.num_input-1; 25 | end 26 | end 27 | 28 | end 29 | -------------------------------------------------------------------------------- /src/frontEnd/get_model_blocks_ports_dts.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ports_dts]=get_model_blocks_ports_dts(mdl_path) 7 | %model_name = get_model_name(mdl_path); 8 | 9 | [pathstr,model_name,ext] = fileparts(mdl_path); 10 | % Compile model to get runtime informations 11 | eval([model_name,'([],[],[],''compile'');']); 12 | 13 | block_paths = find_system(model_name, 'Type', 'Block'); 14 | ports_dts = []; 15 | for i=1:numel(block_paths) 16 | block = block_paths{i}; 17 | block_handle = get_param(block, 'handle'); 18 | block_ports_dts = get_param(block_handle, 'CompiledPortDataTypes'); 19 | 20 | ports_dts = [ports_dts, struct('block',block, 'ports_dt', block_ports_dts)]; 21 | end 22 | 23 | % root_system = find_system(mdl_name, 'SearchDepth', '0'); 24 | % root_system_handle = get_param(root_system, 'handle'); 25 | % root_system_handle = root_system_handle{1, 1}; 26 | % 27 | % ioports = find_system(root_system_handle, 'SearchDepth',1, 'regexp', 'on', 'blocktype', 'port'); 28 | % port = find_system(ioports(1), 'FindAll', 'On', 'Type', 'port'); 29 | % port_parent = get_param(port, 'Parent'); 30 | % 31 | % parent = get_param(port_parent, 'handle'); 32 | % 33 | % block_dts = get_param(parent, 'CompiledPortDataTypes'); 34 | 35 | % Terminate model compilation 36 | eval([model_name,'([],[],[],''term'');']); 37 | end 38 | -------------------------------------------------------------------------------- /src/frontEnd/list_var_action.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [lo] = list_var_action(unbloc, inter_blk, type) 7 | 8 | if strcmp(type, 'Action') 9 | for idx=1:numel(unbloc.action) 10 | preceding_block_full_name = regexp(unbloc.actionname{idx}, '/', 'split'); 11 | pre_block_level = Utils.get_pre_block_level(unbloc.actionname{idx}, inter_blk); 12 | preceding_block_name = Utils.concat_delim(preceding_block_full_name{1}(end - pre_block_level : end), '_'); 13 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.action_dim, 1); 14 | dim = dim_r * dim_c; 15 | for idx_dim=1:dim 16 | lo{idx_dim} = [preceding_block_name '_' num2str(unbloc.actionport(idx) + 1) '_' num2str(idx_dim)]; 17 | end 18 | end 19 | elseif strcmp(type, 'Trigger') 20 | for idx=1:numel(unbloc.trigger) 21 | preceding_block_full_name = regexp(unbloc.triggername{idx}, '/', 'split'); 22 | pre_block_level = Utils.get_pre_block_level(unbloc.triggername{idx}, inter_blk); 23 | preceding_block_name = Utils.concat_delim(preceding_block_full_name{1}(end - pre_block_level : end), '_'); 24 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.trigger_dim, 1); 25 | dim = dim_r * dim_c; 26 | for idx_dim=1:dim 27 | lo{idx_dim} = [preceding_block_name '_' num2str(unbloc.triggerport(idx) + 1) '_' num2str(idx_dim)]; 28 | end 29 | end 30 | elseif strcmp(type, 'Enable') 31 | for idx=1:numel(unbloc.enable) 32 | preceding_block_full_name = regexp(unbloc.enablename{idx}, '/', 'split'); 33 | pre_block_level = Utils.get_pre_block_level(unbloc.enablename{idx}, inter_blk); 34 | preceding_block_name = Utils.concat_delim(preceding_block_full_name{1}(end - pre_block_level : end), '_'); 35 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.enable_dim, 1); 36 | dim = dim_r * dim_c; 37 | for idx_dim=1:dim 38 | lo{idx_dim} = [preceding_block_name '_' num2str(unbloc.enableport(idx) + 1) '_' num2str(idx_dim)]; 39 | end 40 | end 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /src/frontEnd/list_var_input.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [list_out_final] = list_var_sortie_prelude(inter_blk, xml_trace, block_type) 7 | 8 | % Writing outputs declarations 9 | block_full_name = regexp(inter_blk.name, '/', 'split'); 10 | if inter_blk.name_level >= numel(block_full_name{1}) 11 | block_name = Utils.concat_delim(block_full_name{1}, '_'); 12 | else 13 | block_name = Utils.concat_delim(block_full_name{1}(end - inter_blk.name_level : end), '_'); 14 | end 15 | list_out = ''; 16 | for idx_output=1:inter_blk.num_output 17 | list_out_var = ''; 18 | if Constants.is_action_block(inter_blk.type) 19 | output_dt = 'bool'; 20 | else 21 | output_dt = Utils.get_lustre_dt(inter_blk.outports_dt{idx_output}); 22 | end 23 | [is_bus bus] = BusUtils.is_bus(inter_blk.outports_dt{idx_output}); 24 | if is_bus && strcmp(inter_blk.type, 'Inport') && strcmp(get_param(inter_blk.annotation, 'BusOutputAsStruct'), 'off') 25 | str_out = ''; 26 | cpt_elem_dim = 1; 27 | for idx_elem=1:numel(bus.Elements) 28 | elem = bus.Elements(idx_elem); 29 | elem_dt = Utils.get_lustre_dt(elem.DataType); 30 | if numel(elem.Dimensions) == 1 31 | dims = elem.Dimensions; 32 | else 33 | dims = elem.Dimensions(1) * elem.Dimensions(2); 34 | end 35 | for idx_dim=1:dims 36 | list_out_var{cpt_elem_dim} = [block_name '_' num2str(idx_output) '_' num2str(cpt_elem_dim)]; 37 | list_out{cpt_elem_dim} = [list_out_var{cpt_elem_dim} ' : ' elem_dt]; 38 | cpt_elem_dim = cpt_elem_dim+1; 39 | end 40 | end 41 | list_out_final{idx_output} = Utils.concat_delim(list_out, '; '); 42 | else 43 | if inter_blk.out_cpx_sig(idx_output) 44 | output_dt = ['complex_' output_dt]; 45 | end 46 | for idx_dim_out=1:inter_blk.dstport_size(idx_output) 47 | list_out_var{idx_dim_out} = [block_name '_' num2str(idx_output) '_' num2str(idx_dim_out)]; 48 | list_out{idx_dim_out} = [list_out_var{idx_dim_out} ' : ' output_dt]; 49 | end 50 | list_out_final{idx_output} = Utils.concat_delim(list_out, '; '); 51 | end 52 | % Create traceability information node 53 | if exist('xml_trace', 'var') 54 | if strcmp(block_type, 'Inport') 55 | for idx=1:numel(list_out) 56 | xml_trace.add_Input(list_out_var{idx}, inter_blk.origin_name, idx_output, idx); 57 | end 58 | elseif strcmp(block_type, 'Variable') 59 | for idx=1:numel(list_out) 60 | xml_trace.add_Variable(list_out_var{idx}, inter_blk.origin_name, idx_output, idx, false); 61 | end 62 | end 63 | end 64 | 65 | clear list_out list_out_var 66 | end 67 | 68 | end 69 | -------------------------------------------------------------------------------- /src/frontEnd/list_var_outport.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function li_index = list_var_outport(block_outport) 7 | 8 | dim_outport= block_outport.srcport_size; 9 | block_full_name = regexp(block_outport.name, '/', 'split'); 10 | block_name = Utils.concat_delim(block_full_name{1}(end - block_outport.name_level : end), '_'); 11 | for k2=1:dim_outport 12 | li_index{k2} = [block_name '_' block_outport.portnumber '_' num2str(k2) '_']; 13 | %li_index{k2} = ['out' block_outport.portnumber '_' num2str(k2) '_']; 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /src/frontEnd/list_var_sortie.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [list_out] = list_var_sortie(unbloc) 7 | 8 | block_full_name = regexp(unbloc.name, '/', 'split'); 9 | if unbloc.name_level >= numel(block_full_name{1}) 10 | block_name = Utils.concat_delim(block_full_name{1}, '_'); 11 | else 12 | block_name = Utils.concat_delim(block_full_name{1}(end - unbloc.name_level : end), '_'); 13 | end 14 | 15 | dims = unbloc.outports_dim; 16 | num_pred = 0; 17 | idx_dim = 1; 18 | 19 | for k1=1:unbloc.num_output 20 | [is_bus, ~] = BusUtils.is_bus(unbloc.outports_dt{k1}); 21 | if is_bus 22 | for idx=1:unbloc.dstport_size(k1) 23 | list_out{num_pred + 1} = [block_name '_' num2str(k1) '_' num2str(idx)]; 24 | num_pred = num_pred + 1; 25 | idx_dim = idx_dim + 1; 26 | end 27 | else 28 | if dims(idx_dim) == -2 29 | % Here we have a virtual bus, the shape of dims is: 30 | % [-2 {nb_bus_fields}] 31 | nb_bus_fields = dims(idx_dim + 1); 32 | cpt = 0; 33 | for idx=1:nb_bus_fields 34 | [dim_r, dim_c] = Utils.get_port_dims_simple(dims((idx_dim+2:numel(dims))), 1); 35 | for idx_row=1:dim_r 36 | for idx_col=1:dim_c 37 | in_out_idx = idx_col + ((idx_row-1) * dim_c); 38 | list_out{num_pred + in_out_idx} = [block_name '_' num2str(k1) '_' num2str(cpt + 1)]; 39 | cpt = cpt + 1; 40 | end 41 | end 42 | num_pred = num_pred + (dim_r * dim_c); 43 | [nb_dims, ~] = Utils.get_port_dims(dims((idx_dim+2:numel(dims))), 1); 44 | idx_dim = idx_dim + nb_dims + 1; 45 | end 46 | %correction of the old code (Hamza) 47 | idx_dim = idx_dim+2; 48 | else 49 | % This is a normal output 50 | [dim_r, dim_c] = Utils.get_port_dims_simple(dims((idx_dim:numel(dims))), 1); 51 | for idx_row=1:dim_r 52 | for idx_col=1:dim_c 53 | in_out_idx = idx_col + ((idx_row-1) * dim_c); 54 | list_out{num_pred + in_out_idx} = [block_name '_' num2str(k1) '_' num2str(in_out_idx)]; 55 | end 56 | end 57 | num_pred = num_pred + (dim_r * dim_c); 58 | [nb_dims, ~] = Utils.get_port_dims(dims((idx_dim:numel(dims))), 1); 59 | idx_dim = idx_dim + nb_dims + 1; 60 | end 61 | end 62 | end 63 | 64 | end 65 | -------------------------------------------------------------------------------- /src/frontEnd/num_block.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | % TODO: Make it more efficient (transform for loop as while loop) 7 | function [num]=num_block(blks, block_name) 8 | num=-1; 9 | for k1= 1:numel(blks) 10 | 11 | % tmp=regexp(blks{k1}.name,'/','split'); 12 | % name=tmp{1}{2}; 13 | if strcmp(blks{k1}.name, block_name) 14 | num=k1; 15 | end 16 | end 17 | 18 | end 19 | -------------------------------------------------------------------------------- /src/frontEnd/realornot.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | 8 | function [out]=realornot(x) 9 | 10 | if round(x) == x 11 | out=1; 12 | else 13 | out=0; 14 | end -------------------------------------------------------------------------------- /src/frontEnd/transfo_entier_real.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function newstr= transfo_entier_real(str_final) 7 | 8 | [a b]=regexp(str_final, '[\W]', 'split'); 9 | 10 | newstr=str_final; 11 | nb_traite=0; 12 | for k=1:numel(a) 13 | [c d ] =regexp(a{k}, '[\D]', 'split'); 14 | 15 | if(numel(c)==1 && nb_traite==0) 16 | 17 | if(~strcmp(c{1},'')) 18 | if(k>1 && ~ strcmp(str_final(b(k-1)),'.')) 19 | if(k< numel(a) && (~ strcmp(str_final(b(k)),'.'))) 20 | pat=num2str(str2num(c{1}),'%10.10f'); 21 | avant=str_final(1:b(k-1)); 22 | apres=str_final(b(k):end); 23 | newstr=strcat(avant,pat,apres); 24 | str_final=transfo_entier_real(newstr); 25 | nb_traite=1; 26 | newstr=str_final; 27 | elseif (k==numel(a)) 28 | pat=num2str(str2num(c{1}),'%10.10f'); 29 | avant=str_final(1:b(k-1)); 30 | str_final=strcat(avant,pat); 31 | newstr=str_final; 32 | nb_traite=1; 33 | 34 | end 35 | else if(k==1) 36 | if(k< numel(a) && (~ strcmp(str_final(b(k)),'.'))) 37 | pat=num2str(str2num(c{1}),'%10.10f'); 38 | avant=''; 39 | apres=str_final(b(k):end); 40 | newstr=strcat(avant,pat,apres); 41 | str_final=transfo_entier_real(newstr); 42 | newstr=str_final; 43 | nb_traite=1; 44 | end 45 | end 46 | end 47 | end 48 | end 49 | end -------------------------------------------------------------------------------- /src/frontEnd/ztransform.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | % This function implement Tim Wang's algorithm description as provided in the NASA 2013 Summer report by Dieumegard, Feron, Garoche, Kahsai, Wang, Tailliar 7 | 8 | function [new_block] = ztransform(container, block_name) 9 | init_block = strcat(container, '/', block_name); 10 | 11 | % Obtaining z-expression parameters 12 | denum = eval(get_param(init_block, 'Denominator')); 13 | num = eval(get_param(init_block, 'Numerator')); 14 | % Computing state space representation 15 | [A,B,C,D] = tf2ss(num,denum); 16 | 17 | new_block = ss2subsyst(container, block_name, A, B, C, D); 18 | -------------------------------------------------------------------------------- /src/middleEnd/CoCoSpec.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | 7 | classdef CoCoSpec 8 | methods (Static = true) 9 | function [contract]= get_cocospec(cocospec_file) 10 | contract = []; 11 | cs_id = fopen(cocospec_file, 'r'); 12 | line = fgets(cs_id); 13 | is_cs = 'no'; 14 | while ischar(line) 15 | if regexp(line, '^%{') 16 | is_cs = 'yes'; 17 | elseif regexp(line, '^%}') 18 | is_cs = 'no'; 19 | else 20 | if strcmp(is_cs, 'yes') 21 | if regexp(line, '^%{') 22 | [con, remain] = strtok(line, '%{'); 23 | contract=[contract;{con}]; 24 | elseif regexp(line, '^%}') 25 | [con, remain] = strtok(line, '%}'); 26 | contract=[contract;{con}]; 27 | else 28 | contract=[contract;{line}]; 29 | end 30 | end 31 | end 32 | % if regexp(line, '^%') 33 | % r = strrep(line,'%',''); 34 | % if regexp(r, '^ contract') 35 | % 36 | % [contract, remain] = strtok(r, ' contract'); 37 | % spec_names=[spec_names;{contract}]; 38 | % end 39 | % spec = app_sprintf(spec, '%s', r); 40 | % end 41 | line = fgets(cs_id); 42 | end 43 | fclose(cs_id); 44 | end 45 | 46 | function [spec] = multi_line(line) 47 | spec = line; 48 | end 49 | end 50 | end 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/middleEnd/Parallel_states_call.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [action_code, variables_struct, node_struct] = Parallel_states_call(state, token, variables_struct, node_struct, global_nodes_struct) 7 | action_code = ''; 8 | variables = ''; 9 | states = sort_by_order(state.findShallow('State')); 10 | n = numel(states); 11 | if n>=1 12 | for i=1:n 13 | if strcmp(token,'ex') 14 | k=n-i+1; 15 | else 16 | k=i; 17 | end 18 | name = [get_full_name(states(k)), '_', token]; 19 | index = find(strcmp({global_nodes_struct.Name},name)); 20 | if ~isempty(index) 21 | node_struct2 = global_nodes_struct(index); 22 | node_param = node_struct2.Parameters; 23 | params = add_node_param(node_param, variables_struct, token, false); 24 | right_expression = [name, params ';' ]; 25 | 26 | output_struct = node_struct2.Outputs; 27 | for j=1:numel(output_struct) 28 | o = output_struct(j); 29 | index = find(strcmp({variables_struct.Name},o.Name)); 30 | if ~isempty(index) 31 | variables_struct(index).index = variables_struct(index).index+1; 32 | variables_struct(index).used = 1; 33 | else 34 | warning('abnormal behavior %s does not exist in variables structure',char(o.Name)) 35 | end 36 | end 37 | [~, left_variables] = add_variables(output_struct,0,variables_struct); 38 | action_code = [action_code '\n\t' left_variables ' \n\t= ' right_expression '\n']; 39 | 40 | %add parameters and outputs of this state to node_struct of 41 | %its parent 42 | node_struct.Parameters = [node_struct.Parameters, setdiff_struct( node_param, node_struct.Parameters)]; 43 | node_struct.Outputs = [node_struct.Outputs, setdiff_struct( output_struct, node_struct.Outputs)]; 44 | else 45 | warning('Warning: %s does not exist before',char(name)) 46 | action_code = [action_code '\n\t Warning: ' char(name), ' does not exist before' '\n']; 47 | end 48 | 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /src/middleEnd/add_node_param.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function param = add_node_param(extern_nodes_header_param, variables_struct, token, isInner) 7 | 8 | param_i = cell(numel(extern_nodes_header_param),1); 9 | param = ''; 10 | for i=1:numel(extern_nodes_header_param) 11 | if strcmp(extern_nodes_header_param(i).Type, 'Output') || strcmp(extern_nodes_header_param(i).Type, 'Local') || strcmp(extern_nodes_header_param(i).Type, 'ID') 12 | data_index = find(strcmp({variables_struct.Name},{extern_nodes_header_param(i).Name})); 13 | if ~isempty(data_index) 14 | if variables_struct(data_index).used 15 | index = variables_struct(data_index).index; 16 | else 17 | index = 1; 18 | end 19 | else 20 | error('abnormal behavior %s does not exist in variables structure',extern_nodes_header_param(i).Name) 21 | end 22 | param_i{i} = strcat(extern_nodes_header_param(i).Name,'_',num2str(index)); 23 | else 24 | param_i{i} = extern_nodes_header_param(i).Name; 25 | end 26 | end 27 | if ~isempty(param_i) 28 | param = Utils.concat_delim(param_i,', '); 29 | end 30 | 31 | 32 | if strcmp(token,'en') || strcmp(token,'ex') 33 | if isInner 34 | inner = 'true'; 35 | else 36 | inner = 'false'; 37 | end 38 | param = ['(' param ', ' inner ')']; 39 | else 40 | param = ['(' param ')']; 41 | end 42 | 43 | end -------------------------------------------------------------------------------- /src/middleEnd/add_unchanged_variables.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [action_code, variables] = add_unchanged_variables(extern_nodes_header_return, variables_struct) 7 | 8 | [~, outputs] = add_variables(extern_nodes_header_return,false,variables_struct, true); 9 | [variables, right_vars] = add_variables(extern_nodes_header_return,false,variables_struct); 10 | 11 | if ~strcmp(variables,'') 12 | variables = ['var ', variables]; 13 | end 14 | action_code = [outputs ' \n\t= ' right_vars ';\n\t' ]; 15 | end -------------------------------------------------------------------------------- /src/middleEnd/add_variables.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [variables, outputs] = add_variables(extern_nodes_header_return, firstAction, variables_struct, isOutput, global_node,variables_struct_old) 7 | if ~exist('global_node','var') 8 | global_node = false; 9 | end 10 | if ~exist('isOutput','var') 11 | isOutput = false; 12 | end 13 | to_start_from = true; 14 | if ~exist('variables_struct_old','var') 15 | variables_struct_old = variables_struct; 16 | to_start_from = false; 17 | end 18 | variables = ''; 19 | outputs = ''; 20 | output_i = {}; 21 | for i=1:numel(extern_nodes_header_return) 22 | data_index = find(strcmp({variables_struct.Name},{extern_nodes_header_return(i).Name})); 23 | if ~isempty(data_index) 24 | real_index = variables_struct(data_index).index; 25 | if variables_struct(data_index).used 26 | index = variables_struct(data_index).index; 27 | else 28 | index = 1; 29 | end 30 | else 31 | error('abnormal behavior %s does not exist in variables structure',extern_nodes_header_return(i).Name) 32 | end 33 | if firstAction 34 | output_i{i} = strcat(extern_nodes_header_return(i).Name,'_1'); 35 | elseif isOutput 36 | output_i{i} = extern_nodes_header_return(i).Name; 37 | else 38 | output_i{i} = strcat(extern_nodes_header_return(i).Name,'_',num2str(index)); 39 | end 40 | vars = {}; 41 | if global_node 42 | start = 1; 43 | elseif to_start_from 44 | start = variables_struct_old(data_index).index + 1; 45 | else 46 | start = 2; 47 | end 48 | for j=start:real_index 49 | vars{j-start+1} = strcat(extern_nodes_header_return(i).Name,'_',num2str(j)); 50 | end 51 | if ~isempty(vars) 52 | variables = [variables, '\t' Utils.concat_delim(vars,', '), ':', extern_nodes_header_return(i).DataType, ';\n']; 53 | end 54 | end 55 | if ~isempty(output_i) 56 | outputs = strcat('(',Utils.concat_delim(output_i,', '),')'); 57 | end 58 | 59 | end -------------------------------------------------------------------------------- /src/middleEnd/chart2lus.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ nodes_string,external_nodes,nb_actions, nb_nodes] = chart2lus( chart, Debug, xml_trace, file_name ) 7 | nodes_string = ''; 8 | external_nodes = []; 9 | 10 | %these two variables are just for statistics goals. 11 | nb_nodes = 0; 12 | nb_actions = 0; 13 | transitions_fcts = []; 14 | data_fcts = []; 15 | %this is a structure array that contains the following fields for every 16 | %generated node in Lustre file : 17 | % Name : the name of the node in Lustre file 18 | % Parameters : a structure containing informations about node parameters, 19 | % the name, dataType and type of parameter (output, input, ...) 20 | % Outputs : The same as Parameters, has informations about node outputs. 21 | global_nodes_struct = struct('Parameters',[],'Outputs',[],'Name',[]); 22 | 23 | %TODO : 24 | %We can have a problem if a function call another function, but this second 25 | %function that is called by the first is not generated yet. So we should 26 | %make sure that functions are generated with the right order. It has 27 | %never happened but it could be. 28 | % To do it we should 29 | functions = chart.find('-isa','Stateflow.Function'); 30 | for i=1:numel(functions) 31 | if Debug 32 | fprintf('Start generating code for function : %s in chart : %s\n',functions(i).Name, chart.Name); 33 | end 34 | [nodes_string_i,... 35 | external_nodes_i, ... 36 | global_nodes_struct, ... 37 | nb_actions_i, ... 38 | nb_nodes_i] = chart_and_function_code(functions(i),global_nodes_struct, true,[],[], Debug, xml_trace,file_name); 39 | nodes_string = [nodes_string nodes_string_i '\n']; 40 | external_nodes = [external_nodes, external_nodes_i]; 41 | nb_actions = nb_actions + nb_actions_i; 42 | nb_nodes = nb_nodes + nb_nodes_i; 43 | transitions_fcts = [transitions_fcts; functions(i).find('-isa', 'Stateflow.Transition')]; 44 | data_fcts = [data_fcts; functions(i).find('-isa', 'Stateflow.Data')]; 45 | 46 | end 47 | 48 | 49 | if Debug 50 | fprintf('Start generating code for chart : %s\n',get_full_name(chart)); 51 | end 52 | [nodes_string_i,... 53 | external_nodes_i, ... 54 | ~, ... 55 | nb_actions_i, ... 56 | nb_nodes_i] = chart_and_function_code(chart, global_nodes_struct, false,transitions_fcts ,data_fcts, Debug, xml_trace,file_name); 57 | nodes_string = [nodes_string nodes_string_i '\n']; 58 | external_nodes = [external_nodes, external_nodes_i]; 59 | nb_actions = nb_actions + nb_actions_i; 60 | nb_nodes = nb_nodes + nb_nodes_i; 61 | 62 | 63 | end 64 | 65 | -------------------------------------------------------------------------------- /src/middleEnd/construct_node_header.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [extern_nodes_header_param, extern_nodes_header_return] = construct_node_header(extern_nodes_header_param_struct,extern_nodes_header_return_struct, token, xml_trace) 7 | variables_param = {}; 8 | variables_return = {}; 9 | n = numel(extern_nodes_header_param_struct); 10 | if n>=1 && exist('xml_trace', 'var') && ~isempty(find(strcmp({extern_nodes_header_param_struct.Type},'Input'),1)) 11 | xml_trace.create_Inputs_Element(); 12 | end 13 | for i=1:n 14 | par = extern_nodes_header_param_struct(i); 15 | if strcmp(par.Type, 'Output') || strcmp(par.Type, 'Local') || strcmp(par.Type, 'ID') 16 | variables_param{i} = strcat(par.Name,'_1:',par.DataType); 17 | else 18 | variables_param{i} = strcat(par.Name,':',par.DataType); 19 | end 20 | if exist('xml_trace', 'var') && strcmp(par.Type, 'Input') 21 | xml_trace.add_Input(par.Name, par.Name, 1, 1); 22 | end 23 | end 24 | n = numel(extern_nodes_header_return_struct); 25 | if n>=1 && exist('xml_trace', 'var') && ~isempty(find(strcmp({extern_nodes_header_return_struct.Type},'Output'),1)) 26 | xml_trace.create_Outputs_Element(); 27 | end 28 | for i=1:n 29 | par = extern_nodes_header_return_struct(i); 30 | variables_return{i} = strcat(par.Name,':',par.DataType); 31 | if exist('xml_trace', 'var') && strcmp(par.Type, 'Output') 32 | xml_trace.add_Output(par.Name, par.Name, 1, 1); 33 | end 34 | end 35 | 36 | if ~isempty(variables_param) 37 | extern_nodes_header_param = Utils.concat_delim(variables_param,';\n\t'); 38 | else 39 | extern_nodes_header_param = 'noInput :bool'; 40 | end 41 | if ~isempty(variables_return) 42 | extern_nodes_header_return = Utils.concat_delim(variables_return,';\n\t'); 43 | else 44 | extern_nodes_header_return = ' '; 45 | end 46 | if strcmp(token,'en') || strcmp(token,'ex') 47 | extern_nodes_header_param = [extern_nodes_header_param, ';\n\tisInner:bool']; 48 | end 49 | 50 | end -------------------------------------------------------------------------------- /src/middleEnd/math_functions.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ fun_code ] = math_functions( fun ) 7 | %MATH_FUNCTIONS Summary of this function goes here 8 | % Detailed explanation goes here 9 | 10 | fun_code = ''; 11 | 12 | if strcmp(fun.Name, 'min') && strcmp(fun.Type, 'int*int') 13 | fun_code = 'node min(x,y:int) \n returns (z:int) \nlet \n\t z=if x= zero then Input_1_1 else - Input_1_1; 16 | % Output_1_2 = if Input_1_2 >= zero then Input_1_2 else - Input_1_2; 17 | % 18 | %%% Input is complex 19 | % Example provided for a 2 elements vector 20 | % 21 | % Output_1_1 = sqrt((Input_1_1.r * Input_1_1.r) + (Input_1_1.i * Input_1_1.i)); 22 | % Output_1_2 = sqrt((Input_1_2.r * Input_1_2.r) + (Input_1_2.i * Input_1_2.i)); 23 | % 24 | %% Code 25 | % 26 | function [output_string ext_fun] = write_abs(unbloc, inter_blk) 27 | 28 | output_string = ''; 29 | ext_fun = ''; 30 | 31 | [list_out] = list_var_sortie(unbloc); 32 | [list_in] = list_var_entree(unbloc, inter_blk); 33 | 34 | dt = Utils.get_lustre_dt(unbloc.inports_dt{1}); 35 | if strcmp(dt, 'real') 36 | zero = '0.0'; 37 | else 38 | zero = '0'; 39 | end 40 | 41 | if unbloc.in_cpx_sig(1) 42 | for idx_dim=1:unbloc.dstport_size 43 | sqrt_str = sprintf('(%s.r * %s.r) + (%s.i * %s.i)', list_in{idx_dim}, list_in{idx_dim}, list_in{idx_dim}, list_in{idx_dim}); 44 | output_string = app_sprintf(output_string, '\t%s = sqrt(%s);\n', list_out{idx_dim}, sqrt_str); 45 | end 46 | ext_fun{1} = sprintf('sqrt %s', unbloc.outports_dt{1}); 47 | else 48 | for idx_dim=1:unbloc.dstport_size 49 | if_cond = [list_in{idx_dim} ' >= ' zero]; 50 | then_branch = list_in{idx_dim}; 51 | else_branch = ['-' list_in{idx_dim}]; 52 | output_string = app_sprintf(output_string, '\t%s = if %s then %s else %s;\n', list_out{idx_dim}, if_cond, then_branch, else_branch); 53 | end 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /src/middleEnd/write_bias.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Bias block 7 | % 8 | % Adds a bias to the input value. The bias value is provided in the bias 9 | % parameter. 10 | % 11 | %% Generation scheme 12 | % 13 | %%% Output is real (both Input and bias are real) 14 | % Example provided for Input and bias as 2 dimentional vectors 15 | % 16 | % Output_1_1 = Input_1_1 + bias_1; 17 | % Output_1_2 = Input_1_2 + bias_2; 18 | % 19 | %%% Output is complex (either or both Input and bias are complex) 20 | % Example provided for Input and bias as 2 dimentional vectors 21 | % 22 | % Output_1_1.r = Input_1_1.r + bias_1.r; 23 | % Output_1_1.i = Input_1_1.i + bias_1.i; 24 | % Output_1_2.r = Input_1_2.r + bias_2.r; 25 | % Output_1_2.i = Input_1_2.i + bias_2.i; 26 | % 27 | %% Code 28 | % 29 | function [output_string] = write_bias(unbloc, bias, inter_blk) 30 | 31 | output_string = ''; 32 | 33 | [list_out] = list_var_sortie(unbloc); 34 | [list_in] = list_var_entree(unbloc, inter_blk); 35 | [list_const] = Utils.list_cst(bias, unbloc.outports_dt{1}); 36 | 37 | if numel(list_const) ~= numel(list_out) 38 | val = list_const{1}; 39 | for idx=1:numel(list_out) 40 | list_const{idx} = val; 41 | end 42 | end 43 | 44 | if numel(list_in) ~= numel(list_out) 45 | val = list_in{1}; 46 | for idx=1:numel(list_out) 47 | list_in{idx} = val; 48 | end 49 | end 50 | 51 | dt = Utils.get_lustre_dt(unbloc.outports_dt{1}); 52 | if unbloc.out_cpx_sig(1) 53 | for idx=1:numel(list_out) 54 | const_real = evalin('base', sprintf('real(%s);', list_const{idx})); 55 | const_imag = evalin('base', sprintf('imag(%s);', list_const{idx})); 56 | if strcmp(dt, 'real') 57 | if unbloc.in_cpx_sig(1) 58 | output_string = app_sprintf(output_string, '\t%s.r = %s.r + %10.10f;\n', char(list_out{idx}), list_in{idx}, const_real); 59 | output_string = app_sprintf(output_string, '\t%s.i = %s.i + %10.10f;\n', char(list_out{idx}), list_in{idx}, const_imag); 60 | else 61 | output_string = app_sprintf(output_string, '\t%s.r = %s + %10.10f;\n', char(list_out{idx}), list_in{idx}, const_real); 62 | output_string = app_sprintf(output_string, '\t%s.i = %10.10f;\n', char(list_out{idx}), const_imag); 63 | end 64 | else 65 | if unbloc.in_cpx_sig(1) 66 | output_string = app_sprintf(output_string, '\t%s.r = %s.r + %d;\n', char(list_out{idx}), list_in{idx}, const_real); 67 | output_string = app_sprintf(output_string, '\t%s.i = %s.i + %d;\n', char(list_out{idx}), list_in{idx}, const_imag); 68 | else 69 | output_string = app_sprintf(output_string, '\t%s.r = %s + %d;\n', char(list_out{idx}), list_in{idx}, const_real); 70 | output_string = app_sprintf(output_string, '\t%s.i = %d;\n', char(list_out{idx}), const_imag); 71 | end 72 | end 73 | end 74 | else 75 | for idx=1:numel(list_out) 76 | output_string = app_sprintf(output_string, '\t%s = %s + %s;\n', char(list_out{idx}), list_in{idx}, list_const{idx}); 77 | end 78 | end 79 | 80 | end 81 | -------------------------------------------------------------------------------- /src/middleEnd/write_buscreator.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% BusCreator block 7 | % 8 | % Creates a bus from a set of input values. 9 | % 10 | %% Generation scheme 11 | % Every example is provided for 2 elements as input of respective data types scalar, vector of 2 elements and scalar. 12 | % The output is a bus of the corresponding structure (we will use f1, f2 13 | % and f3 as the three fields of this created bus). 14 | % 15 | %%% Output is a non_virtual bus 16 | % 17 | % Output_1_1.f1 = Input_1_1; 18 | % Output_1_1.f2_1 = Input_2_1; 19 | % Output_1_1.f2_2 = Input_2_2; 20 | % Output_1_1.f3 = Input_3_1; 21 | % 22 | %%% Output is a virtual bus 23 | % 24 | % Output_1_1 = Input_1_1; 25 | % Output_1_2 = Input_2_1; 26 | % Output_1_3 = Input_2_2; 27 | % Output_1_4 = Input_3_1; 28 | % 29 | %% Code 30 | % 31 | function [output_string] = write_buscreator(unbloc, inter_blk, non_virtual) 32 | 33 | output_string = ''; 34 | 35 | [list_out] = list_var_sortie(unbloc); 36 | [list_in] = list_var_entree(unbloc, inter_blk); 37 | 38 | non_virtual = strcmp(non_virtual, 'on'); 39 | [is_bus bus] = BusUtils.is_bus(unbloc.outports_dt{1}); 40 | is_virtual = ~is_bus; 41 | 42 | if non_virtual 43 | nb_assigned = 0; 44 | for idx_elem=1:numel(bus.Elements) 45 | elem = bus.Elements(idx_elem); 46 | field_name = elem.Name; 47 | if numel(elem.Dimensions) == 1 48 | for idx_dim=1:elem.Dimensions 49 | output_string = app_sprintf(output_string, '\t%s.%s_%d = %s;\n', list_out{1}, field_name, idx_dim, list_in{idx_dim + nb_assigned}); 50 | end 51 | nb_assigned = nb_assigned + elem.Dimensions; 52 | else 53 | for idx_r=1:elem.Dimensions(1) 54 | for idx_c=1:elem.Dimensions(2) 55 | idx = idx_c + (idx_r-1) * elem.Dimensions(2); 56 | output_string = app_sprintf(output_string, '\t%s.%s_%d = %s;\n', list_out{1}, field_name, idx, list_in{idx + nb_assigned}); 57 | end 58 | end 59 | nb_assigned = nb_assigned + (elem.Dimensions(1) * elem.Dimensions(2)); 60 | end 61 | end 62 | else 63 | for idx_out=1:numel(list_out) 64 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_out}, list_in{idx_out}); 65 | end 66 | end 67 | 68 | end 69 | -------------------------------------------------------------------------------- /src/middleEnd/write_buses.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Outputs the lustre string representation for the bus provided as input. 7 | function [bus_decl] = write_buses(bus_struct) 8 | 9 | bus_decl = ''; 10 | for idx=1:numel(bus_struct) 11 | bus = bus_struct(idx); 12 | name = bus.name; 13 | struct_str = sprintf('type %s = struct { ', name); 14 | fields = {}; 15 | for idx_elem=1:numel(bus.Elements) 16 | elem = bus.Elements(idx_elem); 17 | elem_fields = {}; 18 | dt = Utils.get_lustre_dt(elem.DataType); 19 | if numel(elem.Dimensions) == 1 20 | for idx_dim=1:elem.Dimensions 21 | elem_fields{idx_dim} = sprintf('%s_%d: %s', elem.Name, idx_dim, dt); 22 | end 23 | elseif numel(elem.Dimensions) == 2 24 | for idx_r=1:elem.Dimensions(1) 25 | for idx_c=1:elem.Dimensions(2) 26 | index = idx_c + elem.Dimensions(2) * (idx_r-1); 27 | elem_fields{index} = sprintf('%s_%d: %s', elem.Name, index, dt); 28 | end 29 | end 30 | else 31 | disp('error'); 32 | end 33 | fields{idx_elem} = Utils.concat_delim(elem_fields, '; '); 34 | end 35 | fields_str = Utils.concat_delim(fields, '; '); 36 | bus_decl = [bus_decl struct_str fields_str '};\n']; 37 | end 38 | 39 | end 40 | -------------------------------------------------------------------------------- /src/middleEnd/write_constant.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Constant block 7 | % 8 | % Assigns a value to its output according to the Constant parameter 9 | % (kvalue). 10 | % 11 | %% Generation scheme 12 | % We take the example of a 3 elements vector for the value of the constant parameter 13 | % 14 | %%% If constant is a real value 15 | % 16 | % Output_1_1 = Kvalue{1}; 17 | % Output_1_2 = Kvalue{2}; 18 | % Output_1_3 = Kvalue{3}; 19 | % 20 | %%% If constant is a complex value 21 | % 22 | % Output_1_1 = complex_dt{ r = real(Kvalue{1}); i = imag(Kvalue{1})}; 23 | % Output_1_2 = complex_dt{ r = real(Kvalue{2}); i = imag(Kvalue{2})}; 24 | % Output_1_3 = complex_dt{ r = real(Kvalue{3}); i = imag(Kvalue{3})}; 25 | % 26 | %%% If constant is a bus value 27 | % We take the example here of a bus value for a bus having two fields (f1, 28 | % f2) of respective data type scalar and vector of 2 elements). 29 | % 30 | % Output_1_1.f1_1 = Kvalue.f1; 31 | % Output_1_1.f2_1 = Kvalue.f2{1}; 32 | % Output_1_1.f2_2 = Kvalue.f2{2}; 33 | % 34 | %% Code 35 | % 36 | function [output_string, var_str] = write_constant(nom_lustre_file, unbloc, inter_blk, Kvalue) 37 | 38 | output_string = ''; 39 | var_str = ''; 40 | [list_out] = list_var_sortie(unbloc); 41 | 42 | [is_bus bus] = BusUtils.is_bus(unbloc.outports_dt{1}); 43 | if is_bus 44 | [list_const, list_fields] = BusUtils.list_cst(Kvalue, bus); 45 | else 46 | [list_const] = Utils.list_cst(Kvalue, unbloc.outports_dt{1}); 47 | end 48 | 49 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.outports_dim, 1); 50 | 51 | if is_bus 52 | for idx=1:numel(list_const) 53 | output_string = app_sprintf(output_string, '\t%s.%s = %s;\n', list_out{1}, list_fields{idx}, list_const{idx}); 54 | end 55 | else 56 | if numel(list_const) == 1 && unbloc.dstport_size ~= 1 57 | value = list_const{1, 1}; 58 | for idx_row=1:dim_r 59 | for idx_col=1:dim_c 60 | value_idx = idx_col + ((idx_row-1) * dim_c); 61 | list_const{value_idx} = value; 62 | end 63 | end 64 | end 65 | 66 | if unbloc.out_cpx_sig(1) 67 | % Complex constant 68 | dt = Utils.get_lustre_dt(unbloc.outports_dt{1}); 69 | for idx_row=1:dim_r 70 | for idx_col=1:dim_c 71 | in_out_idx = idx_col + ((idx_row-1) * dim_c); 72 | real_part = evalin('base', sprintf('real(%s);', num2str(list_const{in_out_idx}))); 73 | imag_part = evalin('base', sprintf('imag(%s);', num2str(list_const{in_out_idx}))); 74 | if strcmp(dt, 'real') 75 | output_string = [output_string sprintf('\t%s.r = %10.10f;\n', list_out{in_out_idx}, real_part)]; 76 | output_string = [output_string sprintf('\t%s.i = %10.10f;\n', list_out{in_out_idx}, imag_part)]; 77 | else 78 | output_string = [output_string sprintf('\t%s.r = %s;\n', list_out{in_out_idx}, num2str(real_part))]; 79 | output_string = [output_string sprintf('\t%s.i = %s;\n', list_out{in_out_idx}, num2str(imag_part))]; 80 | end 81 | end 82 | end 83 | else 84 | % Numerical constant 85 | for idx_row=1:dim_r 86 | for idx_col=1:dim_c 87 | in_out_idx = idx_col + ((idx_row-1) * dim_c); 88 | output_string = [output_string sprintf('\t%s = %s;\n', list_out{in_out_idx}, list_const{in_out_idx})]; 89 | end 90 | end 91 | end 92 | end 93 | blk_type = get_param(unbloc.post{1}, 'BlockType'); 94 | if strcmp(blk_type,'Merge') 95 | annotation = regexprep(num2str(unbloc.post{1}),'\.','_'); 96 | name = strcat('Merge_',annotation,'_input',num2str(unbloc.dstport{1}),'_hasChanged'); 97 | var_str = [var_str '\t' name ': bool;\n']; 98 | output_string = app_sprintf(output_string, '\t%s = true;\n', name); 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /src/middleEnd/write_constantes.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Write constants declaration 7 | % 8 | % Writes the definition for constants values according to the declarations contained in the provided .m and .mat files as input of the tool. 9 | % 10 | % This code is not anymore used in the cocoSim tool as constants values are 11 | % resolved and printed directly on the generated code. 12 | % 13 | function [output_string] = write_constantes(const_files) 14 | 15 | output_string = ''; 16 | 17 | if numel(const_files) > 0 18 | output_string = app_sprintf(output_string, '-- Constants declarations\n'); 19 | end 20 | 21 | % Load all intialisation values and constants 22 | for i=1:numel(const_files) 23 | output_string = app_sprintf(output_string, '-- \tconstants file: %s\n', const_files{i}); 24 | vars = load(const_files{i}); 25 | field_names = fieldnames(vars); 26 | for j=1:numel(field_names) 27 | if strcmp(class(vars.(field_names{j})), 'Simulink.Bus') 28 | % TODO: implement Bus management 29 | elseif strcmp(class(vars.(field_names{j})), 'struct') 30 | % TODO: Add support for deeply embedded structures 31 | struct_name = field_names{j}; 32 | struct_fields = fieldnames(vars.(field_names{j})); 33 | for idx_struct=1:numel(struct_fields) 34 | struct_field_name = [struct_name '_' struct_fields{idx_struct}]; 35 | output_string = app_sprintf(output_string, 'const %s = %10.10f;\n', struct_field_name, vars.(field_names{j}).(struct_fields{idx_struct})); 36 | end 37 | else 38 | output_string = app_sprintf(output_string, 'const %s = %10.10f;\n', field_names{j}, vars.(field_names{j})); 39 | end 40 | end 41 | end 42 | 43 | output_string = app_sprintf(output_string, '\n'); 44 | 45 | end 46 | 47 | function bus_printing(vars) 48 | % Print differently a bus object and a classical constant 49 | if strcmp(class(vars.(field_names{j})), 'Simulink.Bus') 50 | bus = vars.(field_names{j}); 51 | for idx_bus=1:numel(bus.Elements) 52 | bus_elem_dt = bus.Element(idx_bus).DataType; 53 | const_string = 'const %s = '; 54 | if strcmp(bus_elem_dt, 'double') || strcmp(bus_elem_dt, 'single') 55 | const_string = [const_string '%10.10f;\n']; 56 | elseif strncmp(bus_elem_dt, 'int', 3) || strncmp(bus_elem_dt, 'uint', 4) 57 | const_string = [const_string '%d;\n']; 58 | else 59 | const_string = [const_string '%s;\n']; 60 | end 61 | end 62 | end 63 | end 64 | 65 | -------------------------------------------------------------------------------- /src/middleEnd/write_datatypeconversion.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% DataTypeConversion block 7 | % 8 | % Converts the input signal to a certain data type specified in a 9 | % parameter. 10 | % 11 | %% Generation scheme 12 | % The actual conversion of the value is done in the printing of the Input 13 | % variables (the call to list_var_entree) which is based on the work done 14 | % in the blocks_dt_conversion function. 15 | % 16 | %% Conversion from int to real 17 | % 18 | % Output = int_to_real(Input); 19 | % 20 | %% Conversion from real to int 21 | % The conversion is done according to the RndMeth parameter value of the 22 | % block. A node is generated to do the conversion (dummy node). 23 | % 24 | % Output = conv_fun(Input); 25 | % 26 | %% Conversion from int to bool 27 | % 28 | % Output = if Input = 0 then false else true; 29 | % 30 | %% Conversion from real to bool 31 | % 32 | % Output = if Input = 0.0 then false else true; 33 | % 34 | %% Conversion from bool to real 35 | % 36 | % Output = if Input then 1.0 else 0.0; 37 | % 38 | %% Conversion from bool to int 39 | % 40 | % Output = if Input then 1 else 0; 41 | % 42 | %% Code 43 | % 44 | function [output_string] = write_datatypeconversion(unbloc, inter_blk) 45 | 46 | output_string = ''; 47 | 48 | [list_out] = list_var_sortie(unbloc); 49 | [list_in] = list_var_entree(unbloc, inter_blk); 50 | 51 | for idx_dim=1:unbloc.dstport_size 52 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, list_in{idx_dim}); 53 | end 54 | 55 | end 56 | -------------------------------------------------------------------------------- /src/middleEnd/write_delay.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Delay block 7 | % 8 | % This blocks outputs its input values delayed by n unit of time. 9 | % 10 | %% Generation scheme n==1 11 | % We take here the example of a 2 elements vector output of the block 12 | % 13 | %%% If the output is complex 14 | % 15 | % Output_1_1 = complex_real/int{ r = real(init{1}); i = imag(init{1})} -> pre Input_1_1; 16 | % Output_1_2 = complex_real/int{ r = real(init{2}); i = imag(init{2})} -> pre Input_1_2; 17 | % 18 | % If the output is real 19 | % 20 | % Output_1_1 = init{1} -> pre Input_1_1; 21 | % Output_1_2 = init{2} -> pre Input_1_2; 22 | % 23 | %% Code 24 | % 25 | function [output_string] = write_delay(unbloc, init, delay_length, inter_blk) 26 | 27 | output_string = ''; 28 | 29 | [list_out] = list_var_sortie(unbloc); 30 | [list_in] = list_var_entree(unbloc, inter_blk); 31 | 32 | [is_bus bus] = BusUtils.is_bus(unbloc.outports_dt{1}); 33 | if is_bus 34 | [list_ic, list_fields] = BusUtils.list_cst(init, bus); 35 | else 36 | [list_ic] = Utils.list_cst(init, unbloc.outports_dt{1}); 37 | end 38 | 39 | [out_dim_r out_dim_c] = Utils.get_port_dims_simple(unbloc.outports_dim, 1); 40 | 41 | [ic_dim_r ic_dim_c] = size(list_ic); 42 | 43 | [is_reset reset_var_name] = Utils.is_reset(inter_blk); 44 | 45 | % Expand IC if necessary 46 | if numel(list_ic) < numel(list_out) 47 | value = list_ic{1}; 48 | for idx_out=1:numel(list_out) 49 | new_ic{idx_out} = value; 50 | end 51 | list_ic = new_ic; 52 | end 53 | 54 | % Expand inputs if necessary 55 | if numel(list_in) < numel(list_out) 56 | value = list_in{1}; 57 | for idx_out=1:numel(list_out) 58 | new_in{idx_out} = value; 59 | end 60 | list_in = new_in; 61 | end 62 | 63 | out_dt = Utils.get_lustre_dt(unbloc.outports_dt{1}); 64 | 65 | pre = ''; 66 | for i=1:str2num(delay_length) 67 | pre = [pre ' pre']; 68 | end 69 | if is_bus 70 | for idx=1:numel(list_ic) 71 | assign_str = sprintf('%s -> %s %s.%s', list_ic{idx},pre, list_in{1}, list_fields{idx}); 72 | reset_cond = ''; 73 | if is_reset 74 | reset_cond = sprintf('if %s then %s else ', reset_var_name, list_ic{idx}); 75 | end 76 | output_string = app_sprintf(output_string, '\t%s.%s = %s%s;\n', list_out{1}, list_fields{idx}, reset_cond, assign_str); 77 | end 78 | else 79 | for idx_out=1:numel(list_out) 80 | if unbloc.out_cpx_sig(1) 81 | ic_cpx = Utils.get_complex_def_str(list_ic{idx_out}, out_dt); 82 | assign_str = sprintf('%s -> %s %s', ic_cpx,pre, list_in{idx_out}); 83 | else 84 | assign_str = sprintf('%s -> %s %s', list_ic{idx_out}, pre, list_in{idx_out}); 85 | end 86 | reset_cond = ''; 87 | if is_reset 88 | reset_cond = sprintf('if %s then %s else ', reset_var_name, list_ic{idx_out}); 89 | end 90 | output_string = app_sprintf(output_string, '\t%s = %s%s;\n', list_out{idx_out}, reset_cond, assign_str); 91 | end 92 | end 93 | 94 | end 95 | -------------------------------------------------------------------------------- /src/middleEnd/write_demux.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Demux block 7 | % 8 | % Splits a multi dimentional Input to multiple Outputs 9 | % 10 | %% Generation scheme 11 | % We take the example of a 3 elements vector provided as input of the 12 | % block. The Output is parametrized in the block to have 2 outputs, the 13 | % first that is a scalar and the second that is a 2 elements vector. 14 | % 15 | %%% We directly assign the Input values to the Outputs values. The correction of the assignment is actually ensured by the variables names generation functions. 16 | % 17 | % Output_1_1 = Input_1_1; 18 | % Output_2_1 = Input_1_2; 19 | % Output_2_2 = Input_1_3; 20 | % 21 | %% Code 22 | % 23 | function [output_string] = write_demux(nom_lustre_file, unbloc, inter_blk) 24 | 25 | output_string = ''; 26 | 27 | [list_out] = list_var_sortie(unbloc); 28 | [list_in] = list_var_entree(unbloc,inter_blk); 29 | 30 | for k1=1:numel(list_out) 31 | output_string = [output_string sprintf('\t%s = %s ;\n', list_out{k1}, list_in{k1})]; 32 | end 33 | 34 | end 35 | -------------------------------------------------------------------------------- /src/middleEnd/write_enableport.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Enable block 7 | % 8 | % The Enable block equips the surrounding subsytem with an enable port. It 9 | % the block has no output (the parameter ShowOutputPort is disabled) then 10 | % nothing is printed for this block. Else it provides the value of the 11 | % surrounding SubSystem enable port. 12 | % 13 | %% Generation scheme 14 | % 15 | % Output = Value of the enable input of the surrounding node; 16 | % 17 | %% Code 18 | % 19 | function [output_string] = write_enableport(unbloc, inter_blk) 20 | 21 | output_string = ''; 22 | 23 | [list_out] = list_var_sortie(unbloc); 24 | 25 | out_dt = Utils.get_lustre_dt(unbloc.outports_dt); 26 | 27 | name_cell = regexp(unbloc.name{1}, '/', 'split'); 28 | name = Utils.concat_delim(name_cell, '_'); 29 | for idx_dim=1:numel(list_out) 30 | str_val{idx_dim} = sprintf('%s_1_%d', name, idx_dim); 31 | end 32 | 33 | for idx_dim=1:numel(list_out) 34 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, str_val{idx_dim}); 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /src/middleEnd/write_entree_sorties.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Outputs the declaration for a new node based on the parameters 7 | % 8 | % unbloc: The block structure object of the block to be printed as a node 9 | % list_out: the list of output variables to be used as outputs of the new node 10 | % list_in: the list of input variables to be used as inputs of the new node 11 | % nom: the name of the new node 12 | % extern: a boolean stating whether or not the node should be printed as an external node 13 | % 14 | % This function is from the original version of the tool and is not used in 15 | % this version. 16 | % 17 | function [output_string] = write_entree_sorties(nom_lustre_file, unbloc, list_out, list_in, nom, extern) 18 | 19 | output_string = ''; 20 | 21 | if(nom) 22 | node_name = nommage(unbloc.name{1}); 23 | else 24 | node_name = nommage_simple(unbloc.name{1}); 25 | end 26 | 27 | if extern 28 | output_string = 'extern '; 29 | end 30 | 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | tampon = ''; 33 | if ~isempty(list_in) 34 | cpt_input_vars = 1; 35 | for idx_input=1:unbloc.num_input 36 | for idx_dim_in=1:unbloc.srcport_size(idx_input) 37 | in_dt = Utils.get_lustre_dt(unbloc.inports_dt{idx_input}); 38 | tampon{cpt_input_vars} = [list_in{cpt_input_vars} ': ' in_dt]; 39 | cpt_input_vars = cpt_input_vars + 1; 40 | end 41 | end 42 | in_decl = Utils.concat_delim(tampon, '; '); 43 | output_string = app_sprintf(output_string, '%s %s (%s)', 'node', node_name, in_decl); 44 | else 45 | output_string = app_sprintf(output_string, '%s %s ()', 'node', node_name); 46 | end 47 | 48 | tampon = ''; 49 | cpt_output_vars = 1; 50 | for idx_output=1:unbloc.num_output 51 | for idx_dim_out=1:unbloc.dstport_size(idx_output) 52 | out_dt = Utils.get_lustre_dt(unbloc.outports_dt{idx_output}); 53 | tampon{cpt_output_vars} = [list_out{cpt_output_vars} ': ' out_dt]; 54 | cpt_output_vars = cpt_output_vars + 1; 55 | end 56 | end 57 | 58 | out_decl = Utils.concat_delim(tampon, '; '); 59 | output_string = app_sprintf(output_string, '\nreturns (%s)\n', out_decl); 60 | 61 | end 62 | 63 | function out = nommage_simple(nomsim) 64 | [a b]=regexp (nomsim, '/', 'split'); 65 | out = a{end}; 66 | end 67 | -------------------------------------------------------------------------------- /src/middleEnd/write_foriterator.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% ForIterator block 7 | % 8 | % ForIterator block provides the value for the iterator at the Iteration 9 | % step. This value is used only if the show_iter_port parameter is set to 10 | % 'on', nothing is generated in the other case. 11 | % The next iteration value can either be provided by an internal rule or provided from an 12 | % external source. 13 | % 14 | %% Generation scheme 15 | % 16 | %%% Iteration value provided by iteration rule. 17 | % In this case, the iteration value is provided as an input of the enclosing subsystem. 18 | % 19 | % Output_1_1 = iter_variable; 20 | % 21 | %%% Iteration value provided from an external source. 22 | % The init value depends on the index_mode parameter (one-based or zero-based). 23 | % 24 | % Output_1_1 = init -> pre(Input_1_1); 25 | % 26 | %% Code 27 | % 28 | function [output_string] = write_foriterator(unbloc, inter_blk, ext_incr, show_iter_port, iter_dt, index_mode) 29 | 30 | output_string = ''; 31 | 32 | % Only retrieve the variables names if necessary 33 | if strcmp(show_iter_port, 'on') 34 | [list_out] = list_var_sortie(unbloc); 35 | iter_dt = Utils.get_lustre_dt(iter_dt); 36 | if strcmp(index_mode, 'One-based') 37 | if strcmp(iter_dt, 'int') 38 | state = '1'; 39 | else 40 | state = '1.0'; 41 | end 42 | else 43 | if strcmp(iter_dt, 'int') 44 | state = '0'; 45 | else 46 | state = '0.0'; 47 | end 48 | end 49 | 50 | if strcmp(ext_incr, 'on') 51 | [list_in] = list_var_entree(unbloc, inter_blk); 52 | for idx=1:numel(list_out) 53 | output_string = app_sprintf(output_string, '\t%s = %s -> pre(%s);\n', list_out{idx}, state, list_in{idx}); 54 | end 55 | else 56 | [res var_iter] = Utils.needs_for_iter_var(inter_blk); 57 | for idx=1:numel(list_out) 58 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx}, var_iter); 59 | end 60 | end 61 | end 62 | 63 | end 64 | 65 | -------------------------------------------------------------------------------- /src/middleEnd/write_fromworkspace.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% FromWorkspace block 7 | % 8 | % Generates data from the values contained in a workspace variable. 9 | % This backend does not yet support bus values. 10 | % 11 | %% Generation scheme 12 | % We take the example of a two elements vector output of the block. 13 | % Values for the output are in variable: value 14 | % 15 | %%% Outputs the values contained in the variable 16 | % 17 | % Output_1_1 = value{t1}(1) -> value{t2}(1) -> ...; 18 | % Output_1_2 = value{t1}(2) -> value{t2}(2) -> ...; 19 | % 20 | %% Code 21 | % 22 | function [output_string] = write_fromworkspace(unbloc, inter_blk, data) 23 | 24 | output_string = ''; 25 | 26 | [list_out] = list_var_sortie(unbloc); 27 | %[list_const] = Utils.list_cst(K, unbloc.outports_dt{1}); 28 | [list_in] = list_var_entree(unbloc, inter_blk); 29 | 30 | classifier = class(data); 31 | if strcmp(classifier, 'timeseries') 32 | value.time = data.Time; 33 | [nb_r nb_c] = size(data.Data); 34 | for idx_r=1:nb_r 35 | value.values{idx_r} = data.Data(idx_r,:); 36 | end 37 | elseif strcmp(classifier, 'struct') 38 | [nb_r nb_c] = size(data.signals.values); 39 | for idx_r=1:nb_r 40 | value.values{idx_r} = data.signals.values(idx_r,:); 41 | end 42 | value.time = transpose(data.time); 43 | else 44 | [nb_r nb_c] = size(data); 45 | data = sort(data, 1); 46 | for idx=1:nb_r 47 | value.time(idx) = data(idx,1); 48 | value.values{idx} = data(idx,2:end); 49 | end 50 | end 51 | 52 | dt = Utils.get_lustre_dt(unbloc.outports_dt{1}); 53 | is_complex = unbloc.out_cpx_sig(1); 54 | 55 | for idx_dim=1:numel(list_out) 56 | lhs_str = ''; 57 | for idx_time=1:numel(value.time)-1; 58 | if is_complex 59 | cpx_val = Utils.get_complex_def_str(num2str(value.values{idx_time}(idx_dim)), dt); 60 | lhs_str = app_sprintf(lhs_str, '%s -> ', cpx_val); 61 | else 62 | if strcmp(dt, 'real') 63 | lhs_str = app_sprintf(lhs_str, '%10.10f -> ', value.values{idx_time}(idx_dim)); 64 | else 65 | lhs_str = app_sprintf(lhs_str, '%d -> ', value.values{idx_time}(idx_dim)); 66 | end 67 | end 68 | end 69 | if is_complex 70 | cpx_val = Utils.get_complex_def_str(num2str(value.values{end}(idx_dim)), dt); 71 | lhs_str = app_sprintf(lhs_str, '%s', cpx_val); 72 | else 73 | if strcmp(dt, 'real') 74 | lhs_str = app_sprintf(lhs_str, '%10.10f', value.values{end}(idx_dim)); 75 | else 76 | lhs_str = app_sprintf(lhs_str, '%d', value.values{end}(idx_dim)); 77 | end 78 | end 79 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, lhs_str); 80 | end 81 | end 82 | 83 | -------------------------------------------------------------------------------- /src/middleEnd/write_goto_from.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Goto/From blocks 7 | % 8 | % Same backend file for both Goto and From blocks. Goto/From blocks are 9 | % identified by their unique goto_tag parameter. 10 | % For the Goto block, generates a new variable for each element of the 11 | % Input of the Goto block. For the From block, set eh output of the block 12 | % to the values of the corresponding Goto block. 13 | % 14 | %% Generation scheme 15 | % We take the example of a vector signal of 3 elements with goto_tag = 'A' 16 | % 17 | %%% Goto 18 | % 19 | % Goto_A_1 = Input_1_1; 20 | % Goto_A_2 = Input_1_2; 21 | % Goto_A_3 = Input_1_3; 22 | % 23 | %%% From 24 | % 25 | % Output_1_1 = Goto_A_1; 26 | % Output_1_2 = Goto_A_2; 27 | % Output_1_3 = Goto_A_3; 28 | % 29 | %% Code 30 | % 31 | function [output_string add_vars] = write_goto_from(unbloc, inter_blk, goto_tag, xml_trace) 32 | 33 | output_string = ''; 34 | add_vars = ''; 35 | 36 | if strcmp(unbloc.type, 'Goto') 37 | [list_in] = list_var_entree(unbloc, inter_blk); 38 | add_vars = '\t'; 39 | in_dt = Utils.get_lustre_dt(unbloc.inports_dt{1}); 40 | for idx_dim=1:unbloc.srcport_size 41 | var_name = sprintf('Goto_%s_%s', goto_tag, num2str(idx_dim)); 42 | output_string = app_sprintf(output_string, '\t%s = %s;\n', var_name, list_in{idx_dim}); 43 | add_vars = [add_vars var_name]; 44 | if idx_dim == unbloc.srcport_size 45 | add_vars = [add_vars ': ' in_dt ';\n']; 46 | else 47 | add_vars = [add_vars ', ']; 48 | end 49 | 50 | % Add traceability for additional variables 51 | xml_trace.add_Variable(var_name, unbloc.origin_name, 1, idx_dim, true); 52 | end 53 | else 54 | [list_out] = list_var_sortie(unbloc); 55 | for idx_dim=1:unbloc.dstport_size 56 | var_name = sprintf('Goto_%s_%s', goto_tag, num2str(idx_dim)); 57 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, var_name); 58 | end 59 | end 60 | 61 | end 62 | -------------------------------------------------------------------------------- /src/middleEnd/write_matlab_function_node.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Matlab Function block 7 | % 8 | % Outputs a node containing the link to the .m file containing the MAtlab 9 | % Function code. 10 | % 11 | %% Generation scheme 12 | % 13 | %%% The function has 2 inputs, the first is a 3 elements vector of doubles, the second 14 | % is a 3 elements row matrix of integers. The output is a 2 elements 15 | % vector of reals. 16 | % 17 | % node BlockName_MatlabFunctionName (in1: real^1^3; in2: int^3) 18 | % returns (out: real^1^2) 19 | % let 20 | % --!MATLAB_Code: 'BlockName_MatlabFunctionName.m' 21 | % tel 22 | % 23 | %% Code 24 | % 25 | function [header] = write_matlab_function_node(block, main_blk, inter_blk, fun_name, chart, xml_trace) 26 | 27 | header = ''; 28 | 29 | % Get parent subsystem 30 | full_name = regexp(block.origin_name, '/', 'split'); 31 | if numel(full_name{1}(1:end-1)) == 1 32 | idx_parent_subsystem = 1; 33 | parent_subsystem = main_blk{idx_parent_subsystem}; 34 | parent_node_name = full_name{1}{1}; 35 | else 36 | idx_parent_subsystem = get_subsys_index(main_blk, Utils.concat_delim(full_name{1}(1:end-1), '/')); 37 | parent_subsystem = main_blk{idx_parent_subsystem}; 38 | full_parent_name = regexp(parent_subsystem{1}.name, '/', 'split'); 39 | parent_node_name = Utils.concat_delim(full_parent_name{1}, '_'); 40 | end 41 | 42 | % Prepare node header 43 | blk_path_elems = regexp(block.name{1}, '/', 'split'); 44 | node_call_name = Utils.concat_delim(blk_path_elems, '_'); 45 | 46 | header = sprintf('node %s_%s (', node_call_name, fun_name); 47 | 48 | xml_trace_node = xml_trace.create_Node_Element(block.origin_name, node_call_name); 49 | 50 | inputs = {}; 51 | % Get inputs 52 | for idx_in=1:numel(block.pre) 53 | in_name = char(chart.Inputs(idx_in).Name); 54 | in_dt = Utils.get_lustre_dt(block.inports_dt{idx_in}); 55 | [dim_r dim_c] = Utils.get_port_dims_simple(block.inports_dim, idx_in); 56 | if block.in_cpx_sig(idx_in) 57 | in_dt = ['complex_' in_dt]; 58 | end 59 | if dim_r == 1 && dim_c == 1 60 | dt_str = in_dt; 61 | elseif dim_r == 1 62 | dt_str = sprintf('%s^%d', in_dt, dim_c); 63 | elseif dim_c == 1 64 | dt_str = sprintf('%s^1^%d', in_dt, dim_r); 65 | else 66 | dt_str = sprintf('%s^%d^%d', in_dt, dim_c, dim_r); 67 | end 68 | inputs{idx_in} = [in_name ' : ' dt_str]; 69 | end 70 | 71 | inputs_string = Utils.concat_delim(inputs, '; '); 72 | header = app_sprintf(header, '%s;)\nreturns (', inputs_string); 73 | 74 | outputs = {}; 75 | % Get outputs 76 | for idx_out=1:numel(block.post) 77 | out_name = char(chart.Outputs(idx_out).Name); 78 | out_dt = Utils.get_lustre_dt(block.outports_dt{idx_out}); 79 | [dim_r dim_c] = Utils.get_port_dims_simple(block.outports_dim, idx_out); 80 | if block.out_cpx_sig(idx_out) 81 | out_dt = ['complex_' out_dt]; 82 | end 83 | if dim_r == 1 && dim_c == 1 84 | dt_str = out_dt; 85 | elseif dim_r == 1 86 | dt_str = sprintf('%s^%d', out_dt, dim_c); 87 | elseif dim_c == 1 88 | dt_str = sprintf('%s^1^%d', out_dt, dim_r); 89 | else 90 | dt_str = sprintf('%s^%d^%d', out_dt, dim_c, dim_r); 91 | end 92 | outputs{idx_out} = [out_name ' : ' dt_str]; 93 | end 94 | 95 | outputs_string = Utils.concat_delim(outputs, '; '); 96 | header = app_sprintf(header, '%s)\n', outputs_string); 97 | 98 | header = app_sprintf(header, 'let\n'); 99 | 100 | comment_string = sprintf('\t--!MATLAB_Code ''%s_%s.m''', node_call_name, fun_name); 101 | 102 | header = app_sprintf(header, '%s\ntel\n\n', comment_string); 103 | 104 | 105 | end 106 | 107 | -------------------------------------------------------------------------------- /src/middleEnd/write_memory.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Memory block 7 | % 8 | % This block output the previous value of the input. The initial value for 9 | % the block output is set according tot he init parameter. 10 | % 11 | %% Generation scheme 12 | % 13 | %%% The input is a 3 elements vector 14 | % 15 | % Output_1_1 = init{1} -> pre Input_1_1; 16 | % Output_1_2 = init{2} -> pre Input_1_2; 17 | % Output_1_3 = init{3} -> pre Input_1_3; 18 | % 19 | %% Code 20 | % 21 | function [output_string] = write_memory(unbloc, init, inter_blk) 22 | 23 | output_string = ''; 24 | 25 | [list_out] = list_var_sortie(unbloc); 26 | [list_in] = list_var_entree(unbloc, inter_blk); 27 | 28 | [is_bus bus] = BusUtils.is_bus(unbloc.outports_dt{1}); 29 | if is_bus 30 | [list_ic, list_fields] = BusUtils.list_cst(init, bus); 31 | else 32 | [list_ic] = Utils.list_cst(init, unbloc.outports_dt{1}); 33 | end 34 | 35 | if unbloc.out_cpx_sig(1) 36 | % The output is complex so both input and init should be complex too 37 | dt = Utils.get_lustre_dt(unbloc.outports_dt{1}); 38 | for idx=1:numel(list_ic) 39 | list_ic{idx} = Utils.get_complex_def_str(list_ic{idx}, dt); 40 | end 41 | end 42 | 43 | [out_dim_r out_dim_c] = Utils.get_port_dims_simple(unbloc.outports_dim, 1); 44 | 45 | [ic_dim_r ic_dim_c] = size(list_ic); 46 | 47 | [is_reset reset_var_name] = Utils.is_reset(inter_blk); 48 | 49 | % Expand IC if necessary 50 | if numel(list_ic) < numel(list_out) 51 | value = list_ic{1}; 52 | for idx_out=1:numel(list_out) 53 | new_ic{idx_out} = value; 54 | end 55 | list_ic = new_ic; 56 | end 57 | 58 | % Expand inputs if necessary 59 | if numel(list_in) < numel(list_out) 60 | value = list_in{1}; 61 | for idx_out=1:numel(list_out) 62 | new_in{idx_out} = value; 63 | end 64 | list_in = new_in; 65 | end 66 | 67 | if is_bus 68 | for idx=1:numel(list_ic) 69 | assign_str = sprintf('%s -> pre %s.%s', list_ic{idx}, list_in{1}, list_fields{idx}); 70 | reset_cond = ''; 71 | if is_reset 72 | reset_cond = sprintf('if %s then %s else ', reset_var_name, list_ic{idx}); 73 | end 74 | output_string = app_sprintf(output_string, '\t%s.%s = %s%s;\n', list_out{1}, list_fields{idx}, reset_cond, assign_str); 75 | end 76 | else 77 | for idx_out=1:numel(list_out) 78 | assign_str = sprintf('%s -> pre %s', list_ic{idx_out}, list_in{idx_out}); 79 | reset_cond = ''; 80 | if is_reset 81 | reset_cond = sprintf('if %s then %s else ', reset_var_name, list_ic{idx_out}); 82 | end 83 | output_string = app_sprintf(output_string, '\t%s = %s%s;\n', list_out{idx_out}, reset_cond, assign_str); 84 | end 85 | end 86 | 87 | end 88 | -------------------------------------------------------------------------------- /src/middleEnd/write_merge.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Merge block 7 | % 8 | % Merge the inputs values to the output. Merging is done according ot the 9 | % last refreshed input value. 10 | % 11 | %% Generation scheme 12 | % Example taken for a 3 elements vector for all inputs. 13 | % 14 | % Output_1_1 = Input_1_1; 15 | % Output_1_2 = Input_1_2; 16 | % Output_1_3 = Input_1_3; 17 | % 18 | %% Code 19 | % 20 | function [output_string] =write_merge(unbloc, inter_blk) 21 | 22 | output_string = ''; 23 | % unbloc 24 | [list_out] = list_var_sortie(unbloc); 25 | [list_in] = list_var_entree(unbloc,inter_blk); 26 | numel_out = numel(list_out); 27 | numel_in = numel(list_in); 28 | right_exp = ''; 29 | annotation = regexprep(num2str(unbloc.annotation),'\.','_'); 30 | for ind_in=1:numel_out:numel_in 31 | %this version has the problem if an input change its value but it still 32 | %equal to previous value. 33 | % condition={}; 34 | % for k=1:numel_out 35 | % condition{k} = ['(' char(list_in(ind_in+k-1)) ' <> pre ' char(list_in(ind_in+k-1)) ')']; 36 | % end 37 | % condition_str = ['(' Utils.concat_delim(condition, ' or ') ')']; 38 | 39 | %this version rely on creating local variables, that save who changed. 40 | if numel_out==1 41 | ind_src = ind_in-1; 42 | else 43 | ind_src = (ind_in-mod(ind_in, numel_out))/numel_out; 44 | end 45 | condition_str = strcat('Merge_',annotation,'_input',num2str(ind_src),'_hasChanged'); 46 | 47 | inputs = ['(' Utils.concat_delim(list_in(ind_in:ind_in+numel_out-1), ', ') ')']; 48 | right_exp = app_sprintf(right_exp,'\tif %s then %s else\n', condition_str,inputs); 49 | end 50 | 51 | if numel_out > 1 52 | list_def_out = ['(pre ' Utils.concat_delim(list_out, ', pre ') ')']; 53 | left_exp = ['(' Utils.concat_delim(list_out, ', ') ')']; 54 | else 55 | list_def_out = ['pre ' list_out{1}]; 56 | left_exp = list_out{1}; 57 | end 58 | output_string = app_sprintf(output_string,'\t%s = %s \t%s;\n', left_exp,right_exp,list_def_out); 59 | end 60 | -------------------------------------------------------------------------------- /src/middleEnd/write_mux.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Mux block 7 | % 8 | % The mux block is grouping the values on its input as values on its 9 | % output. The backend only consist in assigning the values of the output to 10 | % the values of the inputs. The whole muxing is handled in the generation 11 | % of the names of the variables. 12 | % 13 | %% Code 14 | % 15 | function [output_string] = write_mux(unbloc, inter_blk) 16 | 17 | output_string = ''; 18 | 19 | [list_out] = list_var_sortie(unbloc); 20 | [list_in] = list_var_entree(unbloc,inter_blk); 21 | 22 | for k1 = 1:numel(list_out) 23 | output_string = app_sprintf(output_string,'\t%s = %s ;\n',list_out{k1}, list_in{k1}); 24 | end 25 | 26 | end 27 | 28 | -------------------------------------------------------------------------------- /src/middleEnd/write_outport.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Outport block 7 | % 8 | % The outport block is output value of the computation in a block. 9 | % This backend is very simple but may need to be improved as Outport block 10 | % may be latched and thus may contain a memory. 11 | % 12 | %% Code 13 | % 14 | function [output_string] = write_outport(nom_lustre_file, unbloc, inter_blk) 15 | 16 | output_string = ''; 17 | 18 | [list_in] = list_var_entree(unbloc, inter_blk); 19 | list_out = ''; 20 | 21 | block_full_name = regexp(unbloc.name{1}, '/', 'split'); 22 | block_name = Utils.concat_delim(block_full_name(end - unbloc.name_level : end), '_'); 23 | for idx_dim_in=1:unbloc.srcport_size 24 | %list_out{idx_dim_in} = ['out' num2str(unbloc.portnumber) '_' num2str(idx_dim_in) '_']; 25 | list_out{idx_dim_in} = [block_name '_' num2str(unbloc.portnumber) '_' num2str(idx_dim_in)]; 26 | %if strcmp(inter_blk{1}.type, 'SubSystem') 27 | % [a b] = regexp(inter_blk{1}.name{1}, '/', 'split'); 28 | % list_out{idx_dim_in} = [list_out{idx_dim_in} a{end}]; 29 | %else 30 | % [model_path, embedding_node_name, ext] = fileparts(nom_lustre_file); 31 | % list_out{idx_dim_in} = [list_out{idx_dim_in} embedding_node_name]; 32 | %end 33 | %list_out{idx_dim_in} = [list_out{idx_dim_in} '_' embedding_node_name]; 34 | end 35 | 36 | for idx_dim_in=1:unbloc.srcport_size 37 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim_in}, list_in{idx_dim_in}); 38 | end 39 | 40 | end 41 | -------------------------------------------------------------------------------- /src/middleEnd/write_polyval.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Polyval block 7 | % 8 | % Computes the result of the use of the input values as the variable of a 9 | % polynome. The polynome coeficients are provided in the coefs parameter. 10 | % The computation is done on each element of the input. 11 | % 12 | %% Generation scheme 13 | % We take the example of an input as a 3 elements vector. The coefs 14 | % parameter is equal to [3 0 .5 8]. If x is the input value then the 15 | % polynome is: 3*u*u*u + 0.5*u + 8 16 | % 17 | % Output_1_1 = 3 * Input_1_1 * Input_1_1 * Input_1_1 + 0.5 * Input_1_1 + 8.0; 18 | % Output_1_2 = 3 * Input_1_2 * Input_1_2 * Input_1_2 + 0.5 * Input_1_2 + 8.0; 19 | % Output_1_3 = 3 * Input_1_3 * Input_1_3 * Input_1_3 + 0.5 * Input_1_3 + 8.0; 20 | % 21 | %% Code 22 | % 23 | function [output_string] = write_polyval(unbloc, inter_blk, coefs) 24 | 25 | output_string = ''; 26 | 27 | [list_out] = list_var_sortie(unbloc); 28 | [list_in] = list_var_entree(unbloc, inter_blk); 29 | 30 | for idx_out=1:numel(list_out) 31 | mul_str = ''; 32 | for idx_coef=1:numel(coefs) 33 | if coefs(idx_coef) ~= 0 34 | mul_str = sprintf('%s (%.10f', mul_str, coefs(idx_coef)); 35 | for idx_mul=1:numel(coefs)-idx_coef 36 | mul_str = [mul_str ' * ' list_in{idx_out}]; 37 | end 38 | if idx_coef ~= numel(coefs) 39 | mul_str = [mul_str ') +']; 40 | else 41 | mul_str = [mul_str ')']; 42 | end 43 | end 44 | end 45 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_out}, mul_str); 46 | end 47 | 48 | end 49 | -------------------------------------------------------------------------------- /src/middleEnd/write_relationaloperator.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Relational Operator block 7 | % 8 | % Applies the relational operation specified in the operator parameter to 9 | % the inputs of the block. If the comparison is done between complex values 10 | % then only == and ~= operators are allowed and we compare separately the 11 | % real and imaginary parts. 12 | % 13 | %% Generation scheme 14 | % We take the example of scalar values comparisons 15 | % 16 | %%% If the inputs are real and operator is ~= 17 | % 18 | % Output_1_1 = not (Input_1_1 = Input_2_1); 19 | % 20 | %%% If the inputs are real, op is ==, <=, <, >, >= 21 | % 22 | % Output_1_1 = Input_1_1 op Input_2_1; 23 | % 24 | %%% If the inputs are complex and operator is ~= 25 | % 26 | % Output_1_1 = not (Input_1_1.r = Input_2_1.r) and not (Input_1_1.i = Input_2_1.i); 27 | % 28 | %%% If the inputs are real and operator is == 29 | % 30 | % Output_1_1 = (Input_1_1.r = Input_2_1.r) and (Input_1_1.i = Input_2_1.i); 31 | % 32 | %% Code 33 | % 34 | function [output_string] = write_relationaloperator(unbloc, operator, inter_blk) 35 | 36 | output_string = ''; 37 | 38 | [list_out] = list_var_sortie(unbloc); 39 | [list_in] = list_var_entree(unbloc, inter_blk); 40 | 41 | % Expand inputs if necessary 42 | list_in = Utils.expand_all_inputs(unbloc, list_in); 43 | 44 | not_op = strcmp(operator, '~='); 45 | if strcmp(operator, '==') || strcmp(operator, '~=') 46 | operator = '='; 47 | end 48 | 49 | is_complex = false; 50 | if unbloc.in_cpx_sig(1) || unbloc.in_cpx_sig(2) 51 | is_complex = true; 52 | dt = Utils.get_lustre_dt(unbloc.conversion{1}); 53 | % Convert the real input value to complex if necessary 54 | if ~unbloc.in_cpx_sig(1) 55 | for idx=1:numel(list_out) 56 | list_in{idx} = Utils.real_to_complex_str(list_in{idx}, dt); 57 | end 58 | elseif ~unbloc.in_cpx_sig(2) 59 | for idx=1:numel(list_out) 60 | list_in{numel(list_in)/2 + idx} = Utils.real_to_complex_str(list_in{numel(list_in)/2 + idx}, dt); 61 | end 62 | end 63 | end 64 | 65 | dim = unbloc.dstport_size(1); 66 | for idx_out=1:numel(list_out) 67 | output_string = app_sprintf(output_string,'\t%s = ', list_out{idx_out}); 68 | if is_complex 69 | if not_op 70 | output_string = app_sprintf(output_string, 'not(%s.r %s %s.r) and not(%s.i %s %s.i);\n', list_in{idx_out}, operator, list_in{idx_out + dim}, list_in{idx_out}, operator, list_in{idx_out + dim}); 71 | else 72 | output_string = app_sprintf(output_string, '(%s.r %s %s.r) and (%s.r %s %s.r) ;\n', list_in{idx_out}, operator, list_in{idx_out + dim}, list_in{idx_out}, operator, list_in{idx_out + dim}); 73 | end 74 | else 75 | if not_op 76 | output_string = app_sprintf(output_string, 'not(%s %s %s);\n', list_in{idx_out}, operator, list_in{idx_out + dim}); 77 | else 78 | output_string = app_sprintf(output_string, '%s %s %s;\n', list_in{idx_out}, operator, list_in{idx_out + dim}); 79 | end 80 | end 81 | end 82 | 83 | end 84 | -------------------------------------------------------------------------------- /src/middleEnd/write_reshape.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Reshape block 7 | % 8 | % Reshape the input signal according to the 'Output Dimentionality' 9 | % parameter or according to a second optional input dimensions. 10 | % The conversion is done along the first dimension. 11 | % 12 | %% Generation scheme 13 | % We take the example of a 2x3 matrix: [1 2 3; 4 5 6] 14 | % It is converted as a 3x2 matrix ('Custom' value of the 'Output 15 | % Dimentionality' parameter set to [3 2]) 16 | % The result is [1 5; 4 3; 2 6] as teh conversion is done by browsing the 17 | % input value each column at a time. 18 | % 19 | % Output_1_1 = Input_1_1 ; 20 | % Output_1_3 = Input_1_4 ; 21 | % Output_1_5 = Input_1_2 ; 22 | % Output_1_2 = Input_1_5 ; 23 | % Output_1_4 = Input_1_3 ; 24 | % Output_1_6 = Input_1_6 ; 25 | % 26 | %% Code 27 | % 28 | function [output_string] = write_reshape(unbloc, inter_blk) 29 | 30 | output_string = ''; 31 | 32 | [list_out] = list_var_sortie(unbloc); 33 | [list_in] = list_var_entree(unbloc,inter_blk); 34 | 35 | [in_dim_r in_dim_c] = Utils.get_port_dims_simple(unbloc.inports_dim, 1); 36 | [out_dim_r out_dim_c] = Utils.get_port_dims_simple(unbloc.outports_dim, 1); 37 | 38 | cpt = 1; 39 | for idx_c=1:in_dim_c 40 | for idx_r=1:in_dim_r 41 | idx_in = ((idx_r - 1) * in_dim_c) + idx_c; 42 | reorder_list_in{cpt} = list_in{idx_in}; 43 | cpt = cpt + 1; 44 | end 45 | end 46 | 47 | cpt = 1; 48 | for idx_c=1:out_dim_c 49 | for idx_r=1:out_dim_r 50 | idx_out = ((idx_r - 1) * out_dim_c) + idx_c; 51 | output_string = app_sprintf(output_string,'\t%s = %s ;\n', list_out{idx_out}, reorder_list_in{cpt}); 52 | cpt = cpt + 1; 53 | end 54 | end 55 | 56 | end 57 | 58 | -------------------------------------------------------------------------------- /src/middleEnd/write_s_function.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% S-Function block 7 | % 8 | % Generates a call to the node containig the definition (link to the m 9 | % file) for the S-Function. Adds additional parameters to the call if some 10 | % parameters are to be used in the Function. 11 | % 12 | %% Generation scheme 13 | % We take the example of a S-Function having two scalar inputs, one scalar 14 | % parameter and outputing two scalar values. 15 | % 16 | % (Output_1_1, Output_2_1) = function_name(Input_1_1, Input_2_1, param_1_value); 17 | % 18 | %% Code 19 | % 20 | function [output_string] = write_s_function(unbloc, function_name, parameters, inter_blk) 21 | 22 | output_string = ''; 23 | 24 | [list_out] = list_var_sortie(unbloc); 25 | [list_in] = list_var_entree(unbloc, inter_blk); 26 | 27 | block_full_name = regexp(unbloc.name{1}, '/', 'split'); 28 | node_name = block_full_name{end}; 29 | 30 | % Format list_in and list_out as string 31 | list_in = Utils.concat_delim(list_in, ', '); 32 | list_out = Utils.concat_delim(list_out, ', '); 33 | 34 | if numel(list_out) > 1 35 | list_out = ['(' list_out ')']; 36 | end 37 | 38 | 39 | % if ~strcmp(parameters, '') 40 | % parameters_strings = regexp(parameters, ',', 'split'); 41 | % for param_idx=1:numel(parameters_strings) 42 | % param_string_value = parameters_strings{param_idx}; 43 | % matched_value = Utils.convert_literal_value(param_string_value); 44 | % list_in = strcat(list_in, ',', {' '}, matched_value); 45 | % end 46 | % else 47 | % list_in = {''}; 48 | % end 49 | 50 | 51 | block_name = Utils.naming(unbloc.name{1}); 52 | output_string = app_sprintf(output_string, '\t%s = %s(%s);\n', list_out, block_name, list_in); 53 | end 54 | -------------------------------------------------------------------------------- /src/middleEnd/write_saturation_dynamic.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% SaturationDynamic block 7 | % 8 | % Saturate the value of the second input according to the values provided in the 9 | % first and third inputs. 10 | % If the saturation boundaries are provided as scalar values, they are expanded to 11 | % match the size of Input_2. 12 | % 13 | %% Generation scheme 14 | % 15 | %%% 2 elements vector input 16 | % 17 | % Output_1_1 = if Input_1_1 >= Input_1_1 then Input_1_1 else if Input_1_1 <= Input_3_1 then Input_3_1 else Input_1_1; 18 | % Output_1_2 = if Input_1_2 >= Input_1_2 then Input_1_2 else if Input_1_2 <= Input_3_2 then Input_3_2 else Input_1_2; 19 | % 20 | %% Code 21 | % 22 | function [output_string] = write_saturation_dynamic(unbloc, inter_blk, outMin, outMax) 23 | 24 | output_string = ''; 25 | 26 | [list_out] = list_var_sortie(unbloc); 27 | [list_in] = list_var_entree(unbloc,inter_blk); 28 | 29 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.outports_dim, 1); 30 | 31 | % Expand inputs if necessary 32 | list_in = Utils.expand_all_inputs_according_output(unbloc, list_in, 1); 33 | 34 | if numel(outMin) ~= 0 35 | [list_cstMin] = Utils.list_cst(outMin, unbloc.inports_dt{2}); 36 | if numel(list_cstMin) == 1 && unbloc.dstport_size ~= 1 37 | value = list_cstMin{1, 1}; 38 | for idx_row=1:dim_r 39 | for idx_column=1:dim_c 40 | list_cstMin{idx_row, idx_column} = value; 41 | end 42 | end 43 | end 44 | end 45 | 46 | if numel(outMax) ~= 0 47 | [list_cstMax] = Utils.list_cst(outMax, unbloc.inports_dt{2}); 48 | if numel(list_cstMax) == 1 && unbloc.dstport_size ~= 1 49 | value = list_cstMax{1, 1}; 50 | for idx_row=1:dim_r 51 | for idx_column=1:dim_c 52 | list_cstMax{idx_row, idx_column} = value; 53 | end 54 | end 55 | end 56 | end 57 | 58 | nb_elem = dim_r * dim_c; 59 | 60 | for idx_row=1:dim_r 61 | for idx_col=1:dim_c 62 | in_out_idx = idx_col + ((idx_row-1) * dim_c); 63 | if numel(outMax) == 0 64 | output_string = [output_string sprintf('\t%s = if %s > %s then %s\n', list_out{in_out_idx}, list_in{in_out_idx + nb_elem}, list_in{in_out_idx}, list_in{in_out_idx})]; 65 | else 66 | output_string = [output_string sprintf('\t%s = if %s > %s then\n', list_out{in_out_idx}, list_in{in_out_idx + nb_elem}, list_in{in_out_idx})]; 67 | output_string = [output_string sprintf('\t\t\t if %s > %s then %s\n', list_in{in_out_idx}, list_cstMax{idx_row, idx_col}, list_cstMax{idx_row, idx_col})]; 68 | output_string = [output_string sprintf('\t\t\t else %s\n', list_in{in_out_idx})]; 69 | end 70 | 71 | if numel(outMin) == 0 72 | output_string = [output_string sprintf('\t\telse if %s < %s then %s\n', list_in{in_out_idx + nb_elem}, list_in{in_out_idx + (nb_elem*2)}, list_in{in_out_idx + (nb_elem*2)})]; 73 | else 74 | output_string = [output_string sprintf('\t\telse if %s < %s then\n', list_in{in_out_idx + nb_elem}, list_in{in_out_idx + (nb_elem*2)})]; 75 | output_string = [output_string sprintf('\t\t\tif %s < %s then %s\n', list_in{in_out_idx + (nb_elem*2)}, list_cstMin{idx_row, idx_col}, list_cstMin{idx_row, idx_col})]; 76 | output_string = [output_string sprintf('\t\t\telse %s\n', list_in{in_out_idx + (nb_elem*2)})]; 77 | end 78 | 79 | output_string = [output_string sprintf('\t\telse %s;\n', list_in{in_out_idx + nb_elem})]; 80 | end 81 | end 82 | 83 | end 84 | -------------------------------------------------------------------------------- /src/middleEnd/write_sf_Matlab_function_node.m: -------------------------------------------------------------------------------- 1 | function [node_string,external_nodes,global_nodes_struct] = write_sf_Matlab_function_node(chart,data,matlab_function, variables_struct, global_nodes_struct) 2 | %generate Matlab function inside a Stateflow chart 3 | external_nodes = []; 4 | code = matlab_function.Script; 5 | expression = '(\.{3}|/\*(\s*\w*\W*\s*)*\*/)'; 6 | replace = ''; 7 | code = regexprep(code,expression,replace); 8 | 9 | [node_string, ext_nodes, node_struct] = write_actions(chart,data, matlab_function, code,variables_struct, global_nodes_struct); 10 | external_nodes = [external_nodes, ext_nodes]; 11 | global_nodes_struct = [global_nodes_struct, node_struct]; 12 | 13 | end 14 | 15 | function [node_string, external_nodes, node_struct] = write_actions(chart,data, matlab_function, actions, variables_struct, global_nodes_struct) 16 | external_nodes = []; 17 | comment = ''; 18 | actions_code=''; 19 | variables = ''; 20 | 21 | node_struct.Parameters = struct('Name',[],'DataType',[],'Type',[]); 22 | node_struct.Parameters= node_struct.Parameters(~cellfun(@isempty,{node_struct.Parameters.Name})); 23 | node_struct.Outputs = struct('Name',[],'DataType',[],'Type',[]); 24 | node_struct.Outputs= node_struct.Outputs(~cellfun(@isempty,{node_struct.Outputs.Name})); 25 | node_struct.Name = char(matlab_function.Name); 26 | 27 | expr = '(;|\n)'; 28 | action_Array = regexp(actions, expr, 'split'); 29 | action_Array = action_Array(~strcmp(action_Array,'')); 30 | action_Array = action_Array(~strcmp(action_Array,' ')); 31 | n = numel(action_Array); 32 | 33 | if n==0 34 | [action_code, variables] =add_unchanged_variables(node_struct.Outputs, variables_struct); 35 | actions_code = [actions_code '\n\n\t' action_code]; 36 | else 37 | for i=2:n 38 | [action_code, ext_nodes, variables_struct, node_struct] = write_action(chart,data, action_Array{i}, 'MFunction', false, variables_struct , node_struct, global_nodes_struct); 39 | actions_code = [actions_code '\n\n\t' action_code]; 40 | external_nodes = [external_nodes, ext_nodes]; 41 | end 42 | [action_code, variables] =add_unchanged_variables(node_struct.Outputs, variables_struct); 43 | actions_code = [actions_code '\n\n\t' action_code]; 44 | end 45 | 46 | 47 | outputs = node_struct.Outputs; 48 | inputs = node_struct.Parameters; 49 | [extern_nodes_header_param, extern_nodes_header_return] = construct_node_header(inputs,outputs, 'MFunction'); 50 | 51 | header = ['node ' char(node_struct.Name) '(' char(extern_nodes_header_param) ')\n\n' 'returns (' char(extern_nodes_header_return) ');\n']; 52 | node_string = [ '\n\n' comment header '\n\n' variables '\n\n' 'let\n\n' actions_code '\n\ntel\n\n']; 53 | end 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/middleEnd/write_signalspecification.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% SignalSpecification block 7 | % 8 | % This block is used to ensure that an input signal has the correct type. 9 | % It is then used for debug purposes and has no impact on the generated 10 | % code. We thus encode it as a signal. 11 | % 12 | %% Generation scheme 13 | % 14 | %%% 15 | % 16 | % Output = Input; 17 | % 18 | %% Code 19 | % 20 | function [output_string] = write_signalspecification(unbloc, inter_blk) 21 | 22 | output_string = ''; 23 | 24 | [list_out] = list_var_sortie(unbloc); 25 | [list_in] = list_var_entree(unbloc, inter_blk); 26 | 27 | for idx_dim=1:numel(list_out) 28 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, list_in{idx_dim}); 29 | end 30 | 31 | end 32 | -------------------------------------------------------------------------------- /src/middleEnd/write_signum.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Signum block 7 | % 8 | % For real values provides the output -1, 0, 1, if the input is negative, 9 | % null or positive. 10 | % For complex values computes the values of Input / abs(Input). 11 | % 12 | %% Generation scheme 13 | % 14 | %%% Input is real 15 | % Example provided for a 2 elements vector 16 | % 17 | % Output_1_1 = if Input_1_1 = zero then zero else if Input_1_1 < zero then -one else one; 18 | % Output_1_2 = if Input_1_2 = zero then zero else if Input_1_2 < zero then -one else one; 19 | % 20 | %%% Input is complex 21 | % Example provided for a 2 elements vector 22 | % 23 | % Output_1_1.r = Input_1_1.r / sqrt((Input_1_1.r * Input_1_1.r) + (Input_1_1.i * Input_1_1.i)); 24 | % Output_1_1.i = Input_1_1.i / sqrt((Input_1_1.r * Input_1_1.r) + (Input_1_1.i * Input_1_1.i)); 25 | % Output_1_2.r = Input_1_2.r / sqrt((Input_1_2.r * Input_1_2.r) + (Input_1_2.i * Input_1_2.i)); 26 | % Output_1_2.i = Input_1_2.i / sqrt((Input_1_2.r * Input_1_2.r) + (Input_1_2.i * Input_1_2.i)); 27 | % 28 | %% Code 29 | % 30 | function [output_string ext_funs] = write_signum(unbloc, inter_blk) 31 | 32 | output_string = ''; 33 | ext_funs = ''; 34 | 35 | [list_out] = list_var_sortie(unbloc); 36 | [list_in] = list_var_entree(unbloc, inter_blk); 37 | 38 | dt = Utils.get_lustre_dt(unbloc.inports_dt{1}); 39 | if ~unbloc.in_cpx_sig(1) 40 | if strcmp(dt, 'real') 41 | zero = '0.0'; 42 | one = '1.0'; 43 | else 44 | zero = '0'; 45 | one = '1'; 46 | end 47 | for idx=1:numel(list_out) 48 | output_string = app_sprintf(output_string, '\t%s = if %s = %s then %s else if %s < %s then -%s else %s;\n', list_out{idx}, list_in{idx}, zero, zero, list_in{idx}, zero, one, one); 49 | end 50 | else 51 | for idx=1:numel(list_out) 52 | sqrt_val = sprintf('%s.r * %s.r + %s.i * %s.i', list_in{idx}, list_in{idx}, list_in{idx}, list_in{idx}); 53 | output_string = app_sprintf(output_string, '\t%s.r = %s.r / sqrt(%s);\n', list_out{idx}, list_in{idx}, sqrt_val); 54 | end 55 | ext_funs{1} = ['sqrt ' dt]; 56 | end 57 | 58 | end 59 | -------------------------------------------------------------------------------- /src/middleEnd/write_switchcase.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% SwitchCase block 7 | % 8 | % This block activates the computation of the subsystem connected to its 9 | % outputs according to conditions specified in the cond parameter. The 10 | % values are integer values and the input of the SwitchCase block is tested 11 | % against the cond values to define the output to be activated. 12 | % 13 | %% Generation scheme 14 | % 15 | %%% SwitchCase with default value and cond set to: {1,[2,5]} 16 | % In this block configuration if the input is equal to 1 then the first 17 | % output is set to true, if the input is equal to 2 or 5 then the second 18 | % output is set to true else the thrid output is set to true. 19 | % 20 | % (Output_1_1, Output_2_1, Output_3_1) = if Input_1_1 = 1 then (true, false, false) else if Input_1_1 = 2 then (false, true, false) else if Input_1_1 = 5 then (false, true, false) else (false, false, true); 21 | % 22 | % then for each subsystem with an action input connected to the Switch case 23 | % block, we generate the following code template: 24 | % 25 | % SubSystemOutput_1_1 = if Output_1_1 then switch_case_test_SwitchCaseActionSubsystem(SubSystemInput_1_1) else SubSystemInput_1_1; 26 | % 27 | %% Code 28 | % 29 | function [output_string] = write_switchcase(unbloc, inter_blk, cond, default_case) 30 | 31 | output_string = ''; 32 | 33 | [list_out] = list_var_sortie(unbloc); 34 | [list_in] = list_var_entree(unbloc, inter_blk); 35 | 36 | if strcmp(default_case, 'on') 37 | default_case = true; 38 | else 39 | default_case = false; 40 | end 41 | 42 | if numel(list_out) == 1 43 | out_str = list_out{1}; 44 | else 45 | out_str = ['(' Utils.concat_delim(list_out, ', ') ')']; 46 | end 47 | 48 | cpt_out_cond = 1; 49 | out_res = {}; 50 | out_cond = {}; 51 | 52 | for idx=1:numel(cond) 53 | for idx_inner=1:numel(cond{idx}) 54 | cells = num2cell(ones(numel(list_out),1) * 0); 55 | cells{idx} = 1; 56 | cells = cellfun(@(x) Utils.num2logic(x), cells, 'UniformOutput', false); 57 | if numel(cells) == 1 && ~default_case 58 | out_res{cpt_out_cond} = cells{1}; 59 | else 60 | out_res{cpt_out_cond} = ['(' Utils.concat_delim(cells, ', ') ')']; 61 | end 62 | out_cond{cpt_out_cond} = [list_in{1} ' = ' num2str(fix(cond{idx}(idx_inner)))]; 63 | cpt_out_cond = cpt_out_cond + 1; 64 | end 65 | end 66 | 67 | if default_case 68 | cells = num2cell(ones(numel(list_out),1) * 0); 69 | cells{end} = 1; 70 | cells = cellfun(@(x) Utils.num2logic(x), cells, 'UniformOutput', false); 71 | if numel(cells) == 1 72 | out_res{cpt_out_cond} = cells{1}; 73 | else 74 | out_res{cpt_out_cond} = ['(' Utils.concat_delim(cells, ', ') ')']; 75 | end 76 | else 77 | cells = num2cell(ones(numel(list_out),1) * 0); 78 | cells = cellfun(@(x) Utils.num2logic(x), cells, 'UniformOutput', false); 79 | if numel(cells) == 1 80 | out_res{cpt_out_cond} = cells{1}; 81 | else 82 | out_res{cpt_out_cond} = ['(' Utils.concat_delim(cells, ', ') ')']; 83 | end 84 | end 85 | 86 | assign_str = ''; 87 | for idx=1:cpt_out_cond-1 88 | assign_str = app_sprintf(assign_str, 'if %s then %s else ', out_cond{idx}, out_res{idx}); 89 | end 90 | 91 | assign_str = [assign_str out_res{cpt_out_cond}]; 92 | 93 | output_string = sprintf('\t%s = %s;\n', out_str, assign_str); 94 | 95 | end 96 | -------------------------------------------------------------------------------- /src/middleEnd/write_triggerport.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% TriggerPort block 7 | % 8 | % Outputs a value according to the type of trigger function applied in the 9 | % block. If the trigger is a rising the outputs 1, if falling outputs -1 if 10 | % either outputs -1 or 1 according to the dynamic behavior of the trigger. 11 | % 12 | %% Generation scheme 13 | % We take the example of a simple scalar input for the TriggerPort block, 14 | % the same value is assigned to all outputs. 15 | % 16 | %%% If rising 17 | % 18 | % Output_1_1 = one; 19 | % 20 | %%% If falling 21 | % 22 | % Output_1_1 = -one; 23 | % 24 | %%% If either 25 | % 26 | %%% + If the trigger port on the enclosing subsystem is real or int 27 | % 28 | % Output_1_1 = if triggerfullblockname_pre_1_1 > triggerfullblockname_1_1 then -one else one; 29 | % 30 | %%% + If the trigger port on the enclosing subsystem is boolean 31 | % 32 | % Output_1_1 = if triggerfullblockname_pre_1_1 and not(triggerfullblockname_1_1) then -one else one; 33 | % 34 | %% Code 35 | % 36 | function [output_string] = write_triggerport(unbloc, inter_blk, trigger_type) 37 | 38 | output_string = ''; 39 | 40 | [list_out] = list_var_sortie(unbloc); 41 | 42 | out_dt = Utils.get_lustre_dt(unbloc.outports_dt); 43 | 44 | if strcmp(out_dt, 'real') 45 | str_val_post = '.0'; 46 | else 47 | str_val_post = ''; 48 | end 49 | 50 | if strcmp(trigger_type, 'rising') 51 | for idx_dim=1:numel(list_out) 52 | str_val{idx_dim} = ['1' str_val_post]; 53 | end 54 | elseif strcmp(trigger_type, 'falling') 55 | for idx_dim=1:numel(list_out) 56 | str_val{idx_dim} = ['-1' str_val_post]; 57 | end 58 | elseif strcmp(trigger_type, 'either') 59 | name_cell = regexp(unbloc.name{1}, '/', 'split'); 60 | name = Utils.concat_delim(name_cell, '_'); 61 | trigger_input_dt = Utils.get_lustre_dt(inter_blk{1}.trigger_dt{1}); 62 | for idx_dim=1:numel(list_out) 63 | if strcmp(trigger_input_dt, 'bool') 64 | str_val{idx_dim} = sprintf('if %s_pre_1_%d and not(%s_1_%d) then -1%s else 1%s', name, idx_dim, name, idx_dim, str_val_post, str_val_post); 65 | else 66 | str_val{idx_dim} = sprintf('if %s_pre_1_%d > %s_1_%d then -1%s else 1%s', name, idx_dim, name, idx_dim, str_val_post, str_val_post); 67 | end 68 | end 69 | end 70 | 71 | for idx_dim=1:numel(list_out) 72 | output_string = app_sprintf(output_string, '\t%s = %s;\n', list_out{idx_dim}, str_val{idx_dim}); 73 | end 74 | 75 | end 76 | -------------------------------------------------------------------------------- /src/middleEnd/write_trigo.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Trigonometric block 7 | % 8 | % Prints a call to a node to compute the value of the trigonometric 9 | % function. The function name is contained in the op_trigo parameter. 10 | % 11 | %% Generation scheme 12 | % 13 | %%% If the output is real and op_trigo is 'sincos' 14 | % 15 | % Output_1_1 = sin(Input_1); 16 | % Output_2_1 = cos(Input_1); 17 | % 18 | %%% If the output is real 19 | % 20 | % Output_1_1 = op_trigo(Input_1_1); 21 | % 22 | %%% If the output is complex and op_trigo is 'cos + jsin' 23 | % 24 | % Output_1_1 = complex_real{ r = cos(Input_1_1); i = sin(Input_1_1)}; 25 | % 26 | %%% If the output is complex and op_trigo is 'sincos' 27 | % 28 | % Output_1_1 = sin_complex(Input_1); 29 | % Output_2_1 = cos_complex(Input_1); 30 | % 31 | %%% If the output is complex 32 | % 33 | % Output_1_1 = op_trigo_complex(Input_1_1); 34 | % 35 | %% Code 36 | % 37 | function [output_string extern_funs] = write_trigo(nom_lustre_file, unbloc, op_trigo, inter_blk) 38 | 39 | output_string = ''; 40 | extern_funs = ''; 41 | 42 | [list_out] = list_var_sortie(unbloc); 43 | [list_in] = list_var_entree(unbloc, inter_blk); 44 | 45 | % Expand if necessary 46 | if strcmp(op_trigo, 'atan2') 47 | list_in = Utils.expand_all_inputs(unbloc, list_in); 48 | end 49 | 50 | dim = unbloc.dstport_size(1); 51 | 52 | if ~unbloc.out_cpx_sig(1) 53 | if strcmp(op_trigo, 'atan2') 54 | for idx_dim=1:numel(list_out) 55 | in_str = [list_in{idx_dim} ', ' list_in{idx_dim + dim}]; 56 | output_string = app_sprintf(output_string,'\t%s = z%s(%s);\n', list_out{idx_dim}, op_trigo, in_str); 57 | end 58 | extern_funs{1} = [op_trigo ' real']; 59 | elseif strcmp(op_trigo, 'sincos') 60 | for idx_dim=1:numel(list_in) 61 | output_string = app_sprintf(output_string,'\t%s = zsin(%s);\n', list_out{idx_dim}, list_in{idx_dim}); 62 | output_string = app_sprintf(output_string,'\t%s = zcos(%s);\n', list_out{idx_dim + dim}, list_in{idx_dim}); 63 | end 64 | extern_funs{1} = 'cos real'; 65 | extern_funs{2} = 'sin real'; 66 | else 67 | for idx_dim=1:numel(list_out) 68 | output_string = app_sprintf(output_string,'\t%s = z%s(%s);\n', list_out{idx_dim}, op_trigo, list_in{idx_dim}); 69 | end 70 | extern_funs{1} = [op_trigo ' real']; 71 | end 72 | else 73 | if strcmp(op_trigo, 'cos + jsin') 74 | for idx_dim=1:numel(list_in) 75 | output_string = app_sprintf(output_string,'\t%s = complex_real{ r = zcos(%s); i = zsin(%s)};\n', list_out{idx_dim}, list_in{idx_dim}, list_in{idx_dim}); 76 | end 77 | extern_funs{1} = 'cos real'; 78 | extern_funs{2} = 'sin real'; 79 | elseif strcmp(op_trigo, 'sincos') 80 | for idx_dim=1:numel(list_in) 81 | output_string = app_sprintf(output_string,'\t%s = sin_complex(%s);\n', list_out{idx_dim}, list_in{idx_dim}); 82 | output_string = app_sprintf(output_string,'\t%s = cos_complex(%s);\n', list_out{idx_dim + dim}, list_in{idx_dim}); 83 | end 84 | extern_funs{1} = 'cos complex'; 85 | extern_funs{2} = 'sin complex'; 86 | else 87 | for idx_dim=1:numel(list_in) 88 | output_string = app_sprintf(output_string,'\t%s = %s_complex(%s);\n', list_out{idx_dim}, op_trigo, list_in{idx_dim}); 89 | end 90 | extern_funs{1} = [op_trigo ' complex']; 91 | end 92 | end 93 | 94 | end 95 | -------------------------------------------------------------------------------- /src/middleEnd/write_unitdelay.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% UnitDelay block 7 | % 8 | % This blocks outputs its input values delayed by one unit of time. 9 | % 10 | %% Generation scheme 11 | % We take here the example of a 2 elements vector output of the block 12 | % 13 | %%% If the output is complex 14 | % 15 | % Output_1_1 = complex_real/int{ r = real(init{1}); i = imag(init{1})} -> pre Input_1_1; 16 | % Output_1_2 = complex_real/int{ r = real(init{2}); i = imag(init{2})} -> pre Input_1_2; 17 | % 18 | % If the output is real 19 | % 20 | % Output_1_1 = init{1} -> pre Input_1_1; 21 | % Output_1_2 = init{2} -> pre Input_1_2; 22 | % 23 | %% Code 24 | % 25 | function [output_string] = write_unitdelay(unbloc, init, Ts, inter_blk) 26 | 27 | output_string = ''; 28 | 29 | [list_out] = list_var_sortie(unbloc); 30 | [list_in] = list_var_entree(unbloc, inter_blk); 31 | 32 | [is_bus bus] = BusUtils.is_bus(unbloc.outports_dt{1}); 33 | if is_bus 34 | [list_ic, list_fields] = BusUtils.list_cst(init, bus); 35 | else 36 | [list_ic] = Utils.list_cst(init, unbloc.outports_dt{1}); 37 | end 38 | 39 | [out_dim_r out_dim_c] = Utils.get_port_dims_simple(unbloc.outports_dim, 1); 40 | 41 | [ic_dim_r ic_dim_c] = size(list_ic); 42 | 43 | [is_reset reset_var_name] = Utils.is_reset(inter_blk); 44 | 45 | % Expand IC if necessary 46 | if numel(list_ic) < numel(list_out) 47 | value = list_ic{1}; 48 | for idx_out=1:numel(list_out) 49 | new_ic{idx_out} = value; 50 | end 51 | list_ic = new_ic; 52 | end 53 | 54 | % Expand inputs if necessary 55 | if numel(list_in) < numel(list_out) 56 | value = list_in{1}; 57 | for idx_out=1:numel(list_out) 58 | new_in{idx_out} = value; 59 | end 60 | list_in = new_in; 61 | end 62 | 63 | out_dt = Utils.get_lustre_dt(unbloc.outports_dt{1}); 64 | 65 | if is_bus 66 | for idx=1:numel(list_ic) 67 | assign_str = sprintf('%s -> pre %s.%s', list_ic{idx}, list_in{1}, list_fields{idx}); 68 | reset_cond = ''; 69 | if is_reset 70 | reset_cond = sprintf('if %s then %s else ', reset_var_name, list_ic{idx}); 71 | end 72 | output_string = app_sprintf(output_string, '\t%s.%s = %s%s;\n', list_out{1}, list_fields{idx}, reset_cond, assign_str); 73 | end 74 | else 75 | for idx_out=1:numel(list_out) 76 | if unbloc.out_cpx_sig(1) 77 | ic_cpx = Utils.get_complex_def_str(list_ic{idx_out}, out_dt); 78 | assign_str = sprintf('%s -> pre %s', ic_cpx, list_in{idx_out}); 79 | else 80 | assign_str = sprintf('%s -> pre %s', list_ic{idx_out}, list_in{idx_out}); 81 | end 82 | reset_cond = ''; 83 | if is_reset 84 | reset_cond = sprintf('if %s then %s else ', reset_var_name, list_ic{idx_out}); 85 | end 86 | output_string = app_sprintf(output_string, '\t%s = %s%s;\n', list_out{idx_out}, reset_cond, assign_str); 87 | end 88 | end 89 | 90 | end 91 | -------------------------------------------------------------------------------- /src/middleEnd/write_zero_pole.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% ZeroPole block 7 | % 8 | % Prints the computation for the Zero-Pole block as described in 9 | % http://www.mathworks.com/help/simulink/slref/zeropole.html 10 | % 11 | %% Generation scheme 12 | % For a 2 elements input vector, gain as a 2 elements vector, zero as a 2 elements vector and poles a 3 elements vector. 13 | % 14 | % Output_1_1 = Gain{1} * ((Input_1_1 * zero{1})*(Input_1_1 * zero{2}))/((Input_1_1 * poles{1})*(Input_1_1 * poles{2})*(Input_1_1 * poles{3})); 15 | % Output_1_2 = Gain{2} * ((Input_1_2 * zero{2})*(Input_1_2 * zero{2}))/((Input_1_2 * poles{1})*(Input_1_2 * poles{2})*(Input_1_2 * poles{3})); 16 | % 17 | %% Code 18 | % 19 | function [output_string] = write_zero_pole(unbloc, inter_blk, zero, poles, gain) 20 | 21 | output_string = ''; 22 | 23 | [list_out] = list_var_sortie(unbloc); 24 | [list_in] = list_var_entree(unbloc, inter_blk); 25 | 26 | [list_zeros] = Utils.list_cst(zero, unbloc.inports_dt{1}); 27 | [list_poles] = Utils.list_cst(poles, unbloc.inports_dt{1}); 28 | [list_gain] = Utils.list_cst(gain, unbloc.inports_dt{1}); 29 | 30 | [r_z c_z] = size(zero); 31 | [r_p c_p] = size(poles); 32 | [r_g c_g] = size(gain); 33 | 34 | [dim_r dim_c] = Utils.get_port_dims_simple(unbloc.outports_dim, 1); 35 | 36 | for idx_row=1:dim_r 37 | numerator = ''; 38 | for idx_zero=1:c_z 39 | idx = idx_row + ((idx_zero-1) * r_z); 40 | numerator = [numerator '(' list_in{idx_row} ' - ' list_zeros{idx} ')']; 41 | if idx_zero ~= c_z 42 | numerator = [numerator ' * ']; 43 | end 44 | end 45 | 46 | denom = ''; 47 | if r_p == 1 48 | nb_poles = c_p; 49 | else 50 | nb_poles = r_p; 51 | end 52 | for idx_poles=1:nb_poles 53 | denom = [denom '(' list_in{idx_row} ' - ' list_poles{idx_poles} ')']; 54 | if idx_poles ~= nb_poles 55 | denom = [denom ' * ']; 56 | end 57 | end 58 | 59 | val = [list_gain{idx_row} ' * (' numerator ' / ' denom ')']; 60 | output_string = [output_string sprintf('\t%s = %s;\n', list_out{idx_row}, val)]; 61 | 62 | end 63 | 64 | end 65 | -------------------------------------------------------------------------------- /src/pp/README: -------------------------------------------------------------------------------- 1 | ------------------------ 2 | Pre-Processor (PP) for cocoSim 3 | ------------------------ 4 | 5 | 6 | ------------------------ 7 | REQUIREMENTS 8 | ------------------------ 9 | - Matlab r2014b or newer 10 | - Simulink 11 | - Python 12 | 13 | ------------------------ 14 | INSTRUCTIONS 15 | ------------------------ 16 | To use PP which converts a Simulink model into a CoCoSim-friendly one, 17 | open Matlab and add the folder where the script pp.m is to the Matlab 18 | path (usually add 'pp' using the right click and the option 19 | 'Add to path' then 'Selected Folders and subfolders'). 20 | Then go to the folder where is located the Simulink model you want to 21 | process (using cd or the Matlab browser) and type the following command : 22 | pp('filename') 23 | 24 | If the Simulink model needs the definition of constants in order to run, 25 | you have to give a .m file containing these values to PP with 26 | the command : 27 | pp('filename','constant_filename') 28 | 29 | You have to give the complete name of the files, including the extension 30 | as follow : 31 | pp('model.slx') or 32 | pp('model.slx','model_constants.m') 33 | 34 | PP will create : 35 | - modelname_p.slx or .mdl file which contains the CoCoSim-friendly model in 36 | the same file format as the model processed. 37 | - modelname_pp.mdl file which contains the CoCoSim-friendly model in the 38 | Matlab r2008b compatible file format, which is supported by CoCoSim. 39 | 40 | ------------------------ 41 | OPTIONS 42 | ------------------------ 43 | You can call PP with the 'verif' option which will create some 44 | simulink models containing every block processed and the block generated by 45 | PP side by side. Those models are stored in the "Verification" 46 | folder. The command is : 47 | pp('model.slx','model_constants.m','verif') or 48 | pp('model.slx','','verif') if no constant file is required 49 | 50 | ------------------------ 51 | DETAILS 52 | ------------------------ 53 | PP needs to compile the model during its execution, if it lacks 54 | values of certain parameters for example, be aware that the preprocessing 55 | will fail. 56 | 57 | Matlab r2014b is required because of its python capabilities. 58 | If you want to use PP in an older version of Matlab, you can, but any 59 | call of the Python parser script will fail and you will get error messages 60 | in the console each time this python script is called. 61 | That means that blocks needing parsing to be processed (fcn, gain and 62 | constants with calculation for example) won't be processed, nevertheless 63 | all other blocks will be processed normally. -------------------------------------------------------------------------------- /src/pp/default_constants.m: -------------------------------------------------------------------------------- 1 | % This file contains the default values of different sample times that will 2 | % be used during the execution of Pre-GAL. The user can modify these values 3 | % before executing Pre-GAL and they will be used. 4 | sample = -1; 5 | integrator_sample = -1; 6 | clock_sample = -1; 7 | signal_builder_sample = -1; -------------------------------------------------------------------------------- /src/pp/lib/blocks/chart_process.m: -------------------------------------------------------------------------------- 1 | function [ ] = chart_process( model ) 2 | %CHART_PROCESS change all charts to use Strong data typing with Simulink 3 | %I/O 4 | 5 | 6 | rt = sfroot; 7 | m = rt.find('-isa','Stateflow.Machine','Name',model); 8 | chartArr = m.find('-isa','Stateflow.Chart'); 9 | if not(isempty(chartArr)) 10 | display_msg('Processing Charts...', Constants.INFO, 'chart_process', ''); 11 | for i=1:numel(chartArr) 12 | chart = chartArr(i); 13 | display_msg(chart.Name, Constants.INFO, 'chart_process', ''); 14 | chart.StrongDataTypingWithSimulink = 1; 15 | end 16 | display_msg('Done\n\n', Constants.INFO, 'chart_process', ''); 17 | end 18 | 19 | end 20 | 21 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/clock_process.m: -------------------------------------------------------------------------------- 1 | function [] = clock_process(model) 2 | % CLOCK_PROCESS Searches for clock blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Clock blocks 7 | clock_list = find_system(model,'BlockType','Clock'); 8 | if not(isempty(clock_list)) 9 | display_msg('Processing Clock blocks...', Constants.INFO, 'clock_process', ''); 10 | for i=1:length(clock_list) 11 | display_msg(clock_list{i}, Constants.INFO, 'clock_process', ''); 12 | replace_one_block(clock_list{i},'gal_lib/clock'); 13 | % TODO : get the model sample time 14 | try 15 | clock_sample = Utils.get_BlockDiagram_SampleTime(file_name); 16 | if clock_sample==0 || isnan(clock_sample) || clock_sample==Inf 17 | clock_sample = 1; 18 | end 19 | catch 20 | clock_sample = Constants.clock_sample; 21 | end 22 | set_param(strcat(clock_list{i},'/Sample'),'Gain', num2str(clock_sample)); 23 | end 24 | display_msg('Done\n\n', Constants.INFO, 'clock_process', ''); 25 | end 26 | end 27 | 28 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/constant_process.m: -------------------------------------------------------------------------------- 1 | function [] = constant_process(model) 2 | % CONSTANT_PROCESS Searches for constant blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Constant blocks 7 | constant_list = find_system(model,'BlockType','Constant'); 8 | if not(isempty(constant_list)) 9 | display_msg('Processing Constant blocks...', Constants.INFO, 'constant_process', ''); 10 | for i=1:length(constant_list) 11 | display_msg(constant_list{i}, Constants.INFO, 'constant_process', ''); 12 | constant_block_process(constant_list{i}); 13 | end 14 | display_msg('Done\n\n', Constants.INFO, 'constant_process', ''); 15 | end 16 | end 17 | 18 | function err = constant_block_process(init_block) 19 | % CONSTANT_BLOCK_PROCESS analyses the value of a constant block and if 20 | % it this value needs to be calculated, it converts the calculation into 21 | % blocks, then replaces the initial block by its equivalent. 22 | % The function returns : 23 | % 0 if the function has been completed without any error. 24 | % 1 if an error occured during the execution of the function. 25 | % This can happen if a parse error occured or a function is not handled, 26 | % then the details of the error are dispayed in the command line. 27 | 28 | err = 0; 29 | 30 | value = get_param(init_block,'Value'); 31 | % Obtaining a tree from the matlab expression 32 | try 33 | tree = parse_math(value); 34 | catch 35 | try 36 | value = evalin('base',value); 37 | tree = parse_math(value); 38 | set_param(init_block,'Value',tree) 39 | catch error 40 | 41 | msg = sprintf('%s%s%s\n%s\n',... 42 | 'error occured while parsing the expression : "',value,... 43 | '" of block :',init_block); 44 | display_msg(msg, Constants.DEBUG, 'constant_process', ''); 45 | if not(strcmp('Python:BadMatlabVersion',error.identifier)) 46 | msg = sprintf('the block will be processed manually\n'); 47 | display_msg(msg, Constants.DEBUG, 'constant_process', ''); 48 | end 49 | err = 1; 50 | tree = 'err'; % To go threw the next if test 51 | end 52 | end 53 | 54 | % If the value contains a complex expression and needs processing 55 | if isa(tree,'cell') 56 | new_block = strcat(init_block,'_p'); 57 | % Creating a block from the expression 58 | success = expression_process(value,new_block); 59 | if not(success) 60 | msg = sprintf('The block %s will be handled manually\n',init_block); 61 | display_msg(msg, Constants.DEBUG, 'constant_process', ''); 62 | else 63 | display_msg(init_block, Constants.INFO, 'constant_process', ''); 64 | replace_one_block(init_block,new_block); 65 | delete_block(new_block); 66 | end 67 | end 68 | 69 | end 70 | 71 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/deadzone_dynamic_process.m: -------------------------------------------------------------------------------- 1 | function [] = deadzone_dynamic_process(model) 2 | % DEADZONE_DYNAMIC_PROCESS Searches for deadzone dynamic blocks and 3 | % replaces them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Dead Zone Dynamic blocks 7 | deadzone_dyn_list = find_system(model,'MaskType','Dead Zone Dynamic'); 8 | if not(isempty(deadzone_dyn_list)) 9 | display_msg('Processing Dead Zone Dynamic blocks...', Constants.INFO, 'deadzone_dynamic_process', ''); 10 | for i=1:length(deadzone_dyn_list) 11 | display_msg(deadzone_dyn_list{i}, Constants.INFO, 'deadzone_dynamic_process', ''); 12 | replace_one_block(deadzone_dyn_list{i},'gal_lib/deadzone_dyn'); 13 | end 14 | display_msg('Done\n\n', Constants.INFO, 'deadzone_dynamic_process', ''); 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/deadzone_process.m: -------------------------------------------------------------------------------- 1 | function [] = deadzone_process(model) 2 | % DEADZONE_PROCESS Searches for deadzone blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Deadzone blocks 7 | deadzone_list = find_system(model,'BlockType','DeadZone'); 8 | if not(isempty(deadzone_list)) 9 | display_msg('Processing Deadzone blocks...', Constants.INFO, 'deadzone_process', ''); 10 | for i=1:length(deadzone_list) 11 | display_msg(deadzone_list{i}, Constants.INFO, 'deadzone_process', ''); 12 | lower_value = get_param(deadzone_list{i},'LowerValue'); 13 | upper_value = get_param(deadzone_list{i},'UpperValue'); 14 | replace_one_block(deadzone_list{i},'gal_lib/deadzone'); 15 | set_param(strcat(deadzone_list{i},'/lower_value'),... 16 | 'Value',lower_value); 17 | set_param(strcat(deadzone_list{i},'/upper_value'),... 18 | 'Value',upper_value); 19 | end 20 | display_msg('Done\n\n', Constants.INFO, 'deadzone_process', ''); 21 | end 22 | end 23 | 24 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/discrete_state_space_process.m: -------------------------------------------------------------------------------- 1 | function [] = discrete_state_space_process(model) 2 | % DISCRETE_STATE_SPACE_PROCESS Searches for discrete state space blocks 3 | % and replaces them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Discrete State Space blocks 7 | dss_list = find_system(model,'BlockType','DiscreteStateSpace'); 8 | if not(isempty(dss_list)) 9 | % Apply the z-transform to the discrete state space block 10 | display_msg('Processing Discrete State Space blocks...', Constants.INFO, 'discrete_state_space_process', ''); 11 | for i=1:length(dss_list) 12 | display_msg(dss_list{i}, Constants.INFO, 'discrete_state_space_process', ''); 13 | new_block_name = discrete_state_space_block_process(dss_list{i}); 14 | replace_one_block(dss_list{i},new_block_name); 15 | delete_block(new_block_name) 16 | end 17 | display_msg('Done\n\n', Constants.INFO, 'discrete_state_space_process', ''); 18 | end 19 | end 20 | 21 | function [new_block] = discrete_state_space_block_process(init_block) 22 | % DISCRETE_STATE_SPACE_BLOCK_PROCESS Operates the ztransform over the 23 | % specified block. 24 | % init_block is a sting containing the name of 25 | % the block to process. 26 | 27 | % Obtaining the matrices defining the system 28 | A = evalin('base',get_param(init_block,'A')); 29 | B = evalin('base',get_param(init_block,'B')); 30 | C = evalin('base',get_param(init_block,'C')); 31 | D = evalin('base',get_param(init_block,'D')); 32 | IC = evalin('base',get_param(init_block,'X0')); 33 | sample_time = get_param(init_block,'SampleTime'); 34 | 35 | % Obtaining the number of inputs and output of the system 36 | sizeB = size(B); 37 | m = sizeB(2); 38 | sizeC = size(C); 39 | l = sizeC(1); 40 | 41 | new_block = strcat(init_block,'_p'); 42 | 43 | if (m==1)&&(l==1) 44 | % If the block have a single input and a single output 45 | state_matrix_process(A,B,C,D,IC,new_block,sample_time); 46 | else 47 | % Handle a block with multiple inputs or outputs 48 | add_block('gal_lib/multi_in_out',new_block); 49 | dss = state_matrix_process(A,B,C,D,IC,... 50 | strcat(new_block,'/DSS'),sample_time); 51 | name = get_param(dss,'Name'); 52 | replace_one_block(strcat(new_block,'/multi_block'),dss); 53 | delete_block(dss); 54 | set_param(strcat(new_block,'/multi_block'),'Name',name); 55 | ports = get_param(strcat(new_block,'/',name),'Ports'); 56 | nb_inputs = ports(1); 57 | nb_outputs = ports(2); 58 | set_param(strcat(new_block,'/Mux'),'Inputs',num2str(nb_outputs)); 59 | set_param(strcat(new_block,'/Demux'),'Outputs',num2str(nb_inputs)); 60 | for i=1:nb_inputs 61 | add_line(new_block,strcat('Demux/',num2str(i)),... 62 | strcat(name,'/',num2str(i))); 63 | end 64 | for i=1:nb_outputs 65 | add_line(new_block,strcat(name,'/',num2str(i)),... 66 | strcat('Mux/',num2str(i))); 67 | end 68 | end 69 | 70 | end 71 | 72 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/from_workspace_process.m: -------------------------------------------------------------------------------- 1 | function [] = from_workspace_process(model) 2 | % FROM_WORKSPACE_PROCESS Searches for From Workspace blocks and replaces 3 | % them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | Xinit = -1; 7 | 8 | % Processing From Workspace blocks 9 | from_workspace_list = find_system(model,'BlockType','FromWorkspace'); 10 | if not(isempty(from_workspace_list)) 11 | display_msg('Processing From Workspace blocks...', Constants.INFO, 'from_workspace_process', ''); 12 | for i=1:length(from_workspace_list) 13 | display_msg(from_workspace_list{i}, Constants.INFO, 'from_workspace_process', ''); 14 | tag = get_param(from_workspace_list{i},'VariableName'); 15 | 16 | parent = get_param(from_workspace_list{i},'Parent'); 17 | if strcmp(parent,model) 18 | replace_one_block(from_workspace_list{i},'built-in/Inport'); 19 | set_param(from_workspace_list{i},'Name',tag); 20 | else 21 | % Create a goto/from pattern that will be replaced after 22 | replace_one_block(from_workspace_list{i},'built-in/From'); 23 | set_param(from_workspace_list{i},'GotoTag',tag); 24 | set_param(from_workspace_list{i},'TagVisibility','global'); 25 | goto_block = strcat(model,'/tag_',tag); 26 | add_block('built-in/Goto',goto_block,... 27 | 'Position',pos(Xinit,i,'h',15)); 28 | set_param(goto_block,'GotoTag',tag); 29 | set_param(goto_block,'TagVisibility','global'); 30 | add_block('built-in/Inport',strcat(model,'/',tag),... 31 | 'Position',pos(Xinit-1,i,'h',15)); 32 | add_line(model,strcat(tag,'/1'),... 33 | strcat('tag_',tag,'/1')); 34 | % Replace the goto/from pattern 35 | goto_block_process(model,goto_block); 36 | end 37 | end 38 | display_msg('Done\n\n', Constants.INFO, 'from_workspace_process', ''); 39 | end 40 | end 41 | 42 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/function_process.m: -------------------------------------------------------------------------------- 1 | function [success] = function_process(model) 2 | % FUNCTION_PROCESS Searches for function blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Function blocks 7 | function_list = find_system(model,'BlockType','Fcn'); 8 | if not(isempty(function_list)) 9 | display_msg('Processing Function blocks...', Constants.INFO, 'function_process', ''); 10 | % Obtaining the input sizes 11 | % Compile the model before requesting a compiled argument 12 | command = strcat(model,'([],[],[],''compile'');'); 13 | try 14 | eval(command); 15 | catch err 16 | fprintf(2,'%s\n%s\n%s\n%s\n\n',... 17 | 'An error occured while compiling the model.',... 18 | 'This kind of error generally occur when parameters',... 19 | 'can''t be resolved because they are not specified in',... 20 | 'the constant file initially provided to the process.'); 21 | 22 | % Provide the initial error trace 23 | rethrow(err) 24 | end 25 | 26 | % Request arguments and store them 27 | input_size_list = cell.empty(length(function_list),0); 28 | for i=1:length(function_list) 29 | display_msg(function_list{i}, Constants.INFO, 'function_process', ''); 30 | cports = get_param(function_list{i},'CompiledPortDimensions'); 31 | input_size_list{i} = cports.Inport(2); 32 | end 33 | 34 | % Then exit the compiling state 35 | command = strcat(model,'([],[],[],''term'');'); 36 | eval(command); 37 | 38 | % Process blocks 39 | for i=1:length(function_list) 40 | display_msg(function_list{i}, Constants.INFO, 'function_process', ''); 41 | [new_block_name,success] = function_block_process(... 42 | function_list{i},model,input_size_list{i}); 43 | if success 44 | replace_one_block(function_list{i},new_block_name); 45 | delete_block(new_block_name) 46 | else 47 | fprintf(2,'%s%s%s\n%s\n','The block ',function_list{i},... 48 | ' is not handled,',' it should be replaced manually'); 49 | end 50 | end 51 | display_msg('Done\n\n', Constants.INFO, 'function_process', ''); 52 | end 53 | 54 | end 55 | 56 | function [new_block,success] = function_block_process(init_block,model,input_size) 57 | % FUNCTION_BLOCK_PROCESS Changes the init_block block into a 58 | % GAL-friendly block. 59 | % init_block is a string containing the name of the block to process 60 | % return the name of the generated block 61 | % return success = 0 if the process fails 62 | 63 | new_block = strcat(init_block,'_p'); 64 | % Get the mathematical expression to process 65 | expression = get_param(init_block,'Expr'); 66 | 67 | % Get the block representing the expression 68 | success = expression_process(expression,new_block,input_size); 69 | 70 | if not(success) 71 | new_block = init_block; 72 | end 73 | end 74 | 75 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/gain_process.m: -------------------------------------------------------------------------------- 1 | function [] = gain_process(model) 2 | % GAIN_PROCESS Searches for gain blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Gain blocks 7 | gain_list = find_system(model,'BlockType','Gain'); 8 | if not(isempty(gain_list)) 9 | display_msg('Processing Gains blocks...', Constants.INFO, 'gain_process', ''); 10 | for i=1:length(gain_list) 11 | gain_block_process(gain_list{i}); 12 | end 13 | display_msg('Done\n\n', Constants.INFO, 'gain_process', ''); 14 | end 15 | end 16 | 17 | function err = gain_block_process(init_block) 18 | % GAIN_BLOCK_PROCESS analyses the value of a gain block and if it this 19 | % value needs to be calculated, it converts the calculation into blocks, 20 | % then replaces the block by its equivalent. 21 | % The function returns : 22 | % 0 if the function has been completed without any error. 23 | % 1 if an error occured during the execution of the function. 24 | % This can happen if a parse error occured or a function is not handled, 25 | % then the details of the error are dispayed in the command line. 26 | 27 | err = 0; 28 | 29 | gain = get_param(init_block,'Gain'); 30 | % Obtaining a tree from the matlab expression 31 | try 32 | tree = parse_math(gain); 33 | catch error 34 | msg = sprintf('%s%s%s\n%s\n',... 35 | 'error occured while parsing the expression : "',gain,... 36 | '" of block :',init_block); 37 | display_msg(msg, Constants.ERROR, 'gain_process', ''); 38 | if not(strcmp('Python:BadMatlabVersion',error.identifier)) 39 | display_msg('the block must be processed manually\n', Constants.ERROR, 'gain_process', ''); 40 | end 41 | err = 1; 42 | tree = 'err'; % To go threw the next if test 43 | display_msg(error.message, Constants.ERROR, 'gain_process', ''); 44 | end 45 | 46 | % If the gain contains a complex expression and needs processing 47 | if isa(tree,'cell') 48 | new_block = strcat(init_block,'_p'); 49 | % Creating a block from the expression 50 | % The variable 'u' is added to represent the input 51 | gain = strcat('u*(',gain,')'); 52 | success = expression_process(gain,new_block); 53 | if not(success) 54 | msg = sprintf('The block %s has to be handled manually\n',init_block); 55 | display_msg(msg, Constants.ERROR, 'gain_process', ''); 56 | else 57 | display_msg('init_block', Constants.INFO, 'gain_process', ''); 58 | replace_one_block(init_block,new_block); 59 | delete_block(new_block); 60 | end 61 | end 62 | 63 | end -------------------------------------------------------------------------------- /src/pp/lib/blocks/goto_process.m: -------------------------------------------------------------------------------- 1 | function [] = goto_process(model) 2 | % GOTO_PROCESS Searches for goto/from pattern and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | goto_list = find_system(model,'BlockType','Goto'); 6 | if not(isempty(goto_list)) 7 | display_msg('Processing Goto/From blocks...', Constants.INFO, 'goto_process', ''); 8 | for i=1:length(goto_list) 9 | display_msg(goto_list{i}, Constants.INFO, 'goto_process', ''); 10 | goto_block_process(model,goto_list{i}); 11 | end 12 | display_msg('Done\n\n', Constants.INFO, 'goto_process', ''); 13 | end 14 | end 15 | 16 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/integrator_process.m: -------------------------------------------------------------------------------- 1 | function [] = integrator_process(model) 2 | % INTEGRATOR_PROCESS Searches for integrator blocks and replaces them by a 3 | % discrete one. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Integrator blocks 7 | intr_list = find_system(model,'BlockType','Integrator'); 8 | if not(isempty(intr_list)) 9 | display_msg('Processing Integrator blocks...', Constants.INFO, 'integrator_process', ''); 10 | for i=1:length(intr_list) 11 | display_msg(intr_list{i}, Constants.INFO, 'integrator_process', ''); 12 | ICS = get_param(intr_list{i},'InitialConditionSource'); 13 | ER = get_param(intr_list{i},'ExternalReset'); 14 | % Handle internal/external initial value 15 | if strcmp(ICS,'internal') 16 | x0 = get_param(intr_list{i},'InitialCondition'); 17 | switch ER 18 | case 'none' 19 | replace_one_block(intr_list{i},'gal_lib/integrator'); 20 | set_param(intr_list{i},'InitialCondition',x0); 21 | otherwise 22 | replace_one_block(intr_list{i},'gal_lib/integrator_reset'); 23 | set_param(intr_list{i},'InitialCondition',x0); 24 | set_param(intr_list{i},'ExternalReset',ER); 25 | end 26 | else 27 | switch ER 28 | case 'none' 29 | replace_one_block(intr_list{i},'gal_lib/integrator_ic'); 30 | otherwise 31 | replace_one_block(intr_list{i},'gal_lib/integrator_reset_ic'); 32 | set_param(intr_list{i},'ExternalReset',ER); 33 | end 34 | end 35 | end 36 | display_msg('Done\n\n', Constants.INFO, 'integrator_process', ''); 37 | end 38 | end 39 | 40 | 41 | function [] = integrator_process_old_version(model) 42 | % INTEGRATOR_PROCESS Searches for integrator blocks and replaces them by a 43 | % GAL-friendly equivalent. 44 | % model is a string containing the name of the model to search in 45 | 46 | % Processing Integrator blocks 47 | intr_list = find_system(model,'BlockType','Integrator'); 48 | if not(isempty(intr_list)) 49 | display_msg('Processing Integrator blocks...', Constants.INFO, 'integrator_process', ''); 50 | for i=1:length(intr_list) 51 | display_msg(intr_list{i}, Constants.INFO, 'integrator_process', ''); 52 | ICS = get_param(intr_list{i},'InitialConditionSource'); 53 | ER = get_param(intr_list{i},'ExternalReset'); 54 | % Handle internal/external initial value 55 | if strcmp(ICS,'internal') 56 | x0 = get_param(intr_list{i},'InitialCondition'); 57 | switch ER 58 | case 'none' 59 | replace_one_block(intr_list{i},'gal_lib/integrator'); 60 | set_param(strcat(intr_list{i},'/UnitDelay'),... 61 | 'InitialCondition',x0); 62 | case 'level' 63 | replace_one_block(intr_list{i},'gal_lib/integrator_reset'); 64 | set_param(strcat(intr_list{i},'/Init'),'Value',x0); 65 | end 66 | else 67 | switch ER 68 | case 'none' 69 | replace_one_block(intr_list{i},'gal_lib/integrator_ic'); 70 | case 'level' 71 | replace_one_block(intr_list{i},'gal_lib/integrator_reset_ic'); 72 | end 73 | end 74 | end 75 | fprintf('Done\n\n'); 76 | end 77 | end 78 | 79 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/lookuptable_nD_process.m: -------------------------------------------------------------------------------- 1 | function [] = lookuptable_nD_process(model) 2 | % LOOKUPTABLE_ND_PROCESS Searches for lookuptable blocks and replaces them 3 | % by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Lookup table n_D blocks 7 | lookup_nD_list = find_system(model,'BlockType','Lookup_n-D'); 8 | if not(isempty(lookup_nD_list)) 9 | display_msg('Processing Lookup table n-D blocks...', Constants.INFO,... 10 | 'lookuptable_nD_process', ''); 11 | for i=1:length(lookup_nD_list) 12 | display_msg(lookup_nD_list{i}, Constants.INFO, ... 13 | 'lookuptable_nD_process', ''); 14 | new_block_name = lookuptable_nD_block_process(lookup_nD_list{i}); 15 | replace_one_block(lookup_nD_list{i},new_block_name); 16 | delete_block(new_block_name) 17 | end 18 | display_msg('Done\n\n', Constants.INFO, 'lookuptable_nD_process', ''); 19 | end 20 | end 21 | 22 | function [new_block] = lookuptable_nD_block_process(init_block) 23 | % LOOKUPTABLE_ND_BLOCK_PROCESS Changes the lookup table into a 24 | % GAL-friendly block. 25 | % init_block is a sting containing the name of 26 | % the block to process. 27 | % ONLY HANDLE 1D LOOKUP TABLES FOR NOW 28 | 29 | % Obtaining tables 30 | if eval(get_param(init_block, 'NumberOfTableDimensions')) > 1 31 | display_msg('Only 1D lookup table', Constants.ERROR, ... 32 | 'lookuptable_nD_process', ''); 33 | error('Only 1D lookup table'); 34 | end 35 | 36 | indexes = eval(get_param(init_block, 'BreakpointsForDimension1')); 37 | datatable = eval(get_param(init_block, 'Table')); 38 | 39 | if size(indexes) ~= size(datatable) 40 | if size(indexes) ~= size(datatable') 41 | display_msg('Incompatible dimension for indexes and data',... 42 | Constants.ERROR, 'lookuptable_nD_process', ''); 43 | error('Incompatible dimension for indexes and data'); 44 | else 45 | % We have to transpose one of them 46 | if size(indexes,1) > 1 47 | indexes= indexes'; 48 | else 49 | datatable=datatable'; 50 | end 51 | end 52 | end 53 | 54 | new_block = strcat(init_block,'_p'); 55 | datatable_process(indexes,datatable,new_block); 56 | 57 | end 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/lookuptable_process.m: -------------------------------------------------------------------------------- 1 | function [] = lookuptable_process(model) 2 | % LOOKUPTABLE_PROCESS Searches for lookuptable blocks and replaces them 3 | % by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Lookup table blocks 7 | lookup_list = find_system(model,'BlockType','Lookup'); 8 | if not(isempty(lookup_list)) 9 | display_msg('Processing Lookup table blocks...', Constants.INFO, 'lookuptable_process', ''); 10 | for i=1:length(lookup_list) 11 | display_msg(lookup_list{i}, Constants.INFO, 'lookuptable_process', ''); 12 | new_block_name = lookuptable_block_process(lookup_list{i}); 13 | replace_one_block(lookup_list{i},new_block_name); 14 | delete_block(new_block_name) 15 | end 16 | display_msg('Done\n\n', Constants.INFO, 'lookuptable_process', ''); 17 | end 18 | end 19 | 20 | function [new_block] = lookuptable_block_process(init_block) 21 | % LOOKUPTABLE_BLOCK_PROCESS Changes the lookup table into a 22 | % GAL-friendly block. 23 | % init_block is a sting containing the name of 24 | % the block to process. 25 | 26 | % Obtaining tables 27 | try 28 | indexes = eval(get_param(init_block, 'InputValues')); 29 | catch 30 | indexes = evalin('base',get_param(init_block, 'InputValues')); 31 | end 32 | try 33 | datatable = eval(get_param(init_block, 'Table')); 34 | catch 35 | datatable = evalin('base',get_param(init_block, 'Table')); 36 | end 37 | new_block = strcat(init_block,'_p'); 38 | datatable_process(indexes,datatable,new_block); 39 | 40 | end -------------------------------------------------------------------------------- /src/pp/lib/blocks/math_process.m: -------------------------------------------------------------------------------- 1 | function [] = math_process(model) 2 | % MATH_PROCESS Searches for Math blocks with unsupported functions 3 | % and replaces them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Math unsupported blocks 7 | math_list = find_system(model,'BlockType','Math'); 8 | if not(isempty(math_list)) 9 | display_msg('Processing Math blocks...', Constants.INFO, ... 10 | 'math_process', ''); 11 | for i=1:length(math_list) 12 | func = get_param(math_list{i},'Operator'); 13 | switch func 14 | case 'magnitude^2' 15 | disp(math_list{i}) 16 | display_msg(math_list{i}, Constants.INFO,... 17 | 'math_process', ''); 18 | new_block = strcat(math_list{i},'_p'); 19 | expression_process('u^2',new_block,1); 20 | replace_one_block(math_list{i},new_block); 21 | delete_block(new_block); 22 | %otherwise 23 | % The function is natively supported by GAL : nothing to 24 | % do. 25 | end 26 | end 27 | display_msg('Done\n\n', Constants.INFO, 'math_process', ''); 28 | end 29 | end 30 | 31 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/product_process.m: -------------------------------------------------------------------------------- 1 | function [] = product_process(model) 2 | % product_process Searches for product blocks and try to check dimensions 3 | % of its inports, if there are scalars, we change them to matrix with the 4 | % size of the product output 5 | % model is a string containing the name of the model to search in 6 | 7 | % Processing Product blocks 8 | product_list = find_system(model,'BlockType','Product'); 9 | if not(isempty(product_list)) 10 | display_msg('Processing Product blocks...', Constants.INFO, 'product_block_process', ''); 11 | for i=1:length(product_list) 12 | multiplication = get_param(product_list{i}, 'Multiplication'); 13 | if strcmp(multiplication, 'Element-wise(.*)') 14 | product_block_process(model, product_list{i}); 15 | end 16 | end 17 | display_msg('Done\n\n', Constants.INFO, 'product_block_process', ''); 18 | end 19 | end 20 | 21 | function product_block_process(model, init_block) 22 | % product_block_process try to look for scalars that are multiplying with 23 | % matrix and try to change them to the right dimension. 24 | % that make the translation to lustre more easy 25 | 26 | tmp=regexp(char(init_block),'/','split'); 27 | block_name = tmp{end}; 28 | 29 | warning off; 30 | code_on=sprintf('%s([], [], [], ''compile'')', model); 31 | eval(code_on); 32 | 33 | port_widths = get_param(init_block, 'CompiledPortWidths'); 34 | port_handles = get_param(init_block, 'PortHandles'); 35 | output_dim = get_param(port_handles.Outport(1),'CompiledPortDimensions'); 36 | 37 | code_off = sprintf('%s([], [], [], ''term'')', model); 38 | eval(code_off); 39 | warning on; 40 | 41 | if port_widths.Outport(1) > 1 && numel(output_dim)>=2 42 | str = {}; 43 | for i=2:numel(output_dim) 44 | str{i-1} = num2str(output_dim(i)); 45 | end 46 | if output_dim(1)==1 47 | I = strcat('ones(',Utils.concat_delim(str,', ') ,',1)'); 48 | else 49 | I = strcat('ones(',Utils.concat_delim(str,', ') ,')'); 50 | end 51 | for idx=1:numel(port_widths.Inport) 52 | if port_widths.Inport(idx) == 1 53 | pos = get_param(port_handles.Inport(idx),'Position'); 54 | gain_name = strcat(get_param(init_block, 'Parent'),'/',block_name,'_dimension',num2str(idx)); 55 | add_block('simulink/Math Operations/Gain',... 56 | gain_name,... 57 | 'Gain',I,... 58 | 'Position',[(pos(1)-25) (pos(2)-10) (pos(1)-5) (pos(2)+5)]); 59 | DstBlkH = get_param(gain_name, 'PortHandles'); 60 | l = get_param(port_handles.Inport(idx),'line'); 61 | SrcPortHandle = get_param(l ,'SrcPortHandle'); 62 | delete_line(l) 63 | add_line(get_param(init_block, 'Parent'), SrcPortHandle, DstBlkH.Inport(1), 'autorouting', 'on'); 64 | add_line(get_param(init_block, 'Parent'), DstBlkH.Outport(1), port_handles.Inport(idx), 'autorouting', 'on'); 65 | end 66 | end 67 | end 68 | 69 | end -------------------------------------------------------------------------------- /src/pp/lib/blocks/rate_transition_process.m: -------------------------------------------------------------------------------- 1 | function [] = rate_transition_process(model) 2 | % RATE_TRANSITION_PROCESS Searches for Rate Transition blocks and replaces 3 | % them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | % THIS VERSION OF THE PROCESS ONLY HANDLE THE INITIAL CONDITION OF THE 6 | % BLOCK AND DOESN'T HAS THE BEHAVIOUR OF THE INITIAL BLOCK 7 | 8 | % Processing Rate Transition blocks 9 | rt_list = find_system(model,'BlockType','RateTransition'); 10 | if not(isempty(rt_list)) 11 | disp('Processing Rate Transition blocks...') 12 | display_msg('Processing Rate Transition blocks...', Constants.INFO, ... 13 | 'rate_transition_process', ''); 14 | for i=1:length(rt_list) 15 | display_msg(rt_list{i}, Constants.INFO, 'rate_transition_process', ''); 16 | sample = get_param(rt_list{i},'OutPortSampleTime'); 17 | X0 = get_param(rt_list{i},'X0'); 18 | replace_one_block(rt_list{i},'gal_lib/rate_transition'); 19 | set_param(strcat(rt_list{i},'/UnitDelay'),'SampleTime',sample); 20 | set_param(strcat(rt_list{i},'/Sum'),'SampleTime',sample); 21 | set_param(strcat(rt_list{i},'/Init'),'Value',X0); 22 | end 23 | display_msg('Done\n\n', Constants.INFO, 'rate_transition_process', ''); 24 | end 25 | end 26 | 27 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/replace_variables.m: -------------------------------------------------------------------------------- 1 | function [] = replace_variables(model) 2 | % NAME2VALUE Replaces scalar variables refered by their name to their 3 | % actual value available in the 'base' workspace. 4 | % The values have to be loaded to the 'base' workspace first using the 5 | % command evalin('base',...) for example. 6 | 7 | % Replacing variables in gains 8 | block_parameter_replace(model,'Gain','Gain'); 9 | 10 | % Replacing variables in constants 11 | block_parameter_replace(model,'Constant','Value'); 12 | 13 | % Replacing variables in Unit Delays 14 | block_parameter_replace(model,'UnitDelay','InitialCondition'); 15 | block_parameter_replace(model,'UnitDelay','SampleTime'); 16 | 17 | end 18 | 19 | function [] = block_parameter_replace(model,type,param_name) 20 | % BLOCK_PARAMETER_REPLACE Searches for 'type' blocks and replaces their 21 | % 'param_name', which is often a variable, by their value when they are 22 | % scalar variables. 23 | % model is a string containing the name of the model to search in 24 | % type is the type of block to search the param in 25 | % param_name is the parameter to be replaced by its actual value 26 | 27 | % Processing blocks 28 | block_list = find_system(model,'BlockType',type); 29 | if not(isempty(block_list)) 30 | display_msg(['Replacing variables in ' type ' blocks...'], Constants.INFO, 'replace_variables', ''); 31 | for i=1:length(block_list) 32 | variable = get_param(block_list{i},param_name); 33 | % get the actual value from the 'base' workspace 34 | if strcmp(variable,'true') || strcmp(variable,'true') 35 | value = variable; 36 | else 37 | value = evalin('base',variable); 38 | end 39 | % check if the variable is a scalar 40 | command = strcat('length(',variable,');'); 41 | issimple = evalin('base',command); 42 | if issimple == 1 43 | display_msg(block_list{i}, Constants.INFO, 'replace_variables', ''); 44 | set_param(block_list{i},param_name,num2str(value)); 45 | end 46 | end 47 | display_msg('Done\n\n', Constants.INFO, 'replace_variables', ''); 48 | end 49 | end 50 | 51 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/saturation_dynamic_process.m: -------------------------------------------------------------------------------- 1 | function [] = saturation_dynamic_process(model) 2 | % SATURATION_DYNAMIC_PROCESS Searches for saturation_dynamic blocks and 3 | % replaces them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Saturation Dynamic blocks 7 | sat_dyn_list = find_system(model,'MaskType','Saturation Dynamic'); 8 | if not(isempty(sat_dyn_list)) 9 | display_msg('Processing Saturation Dynamic blocks...', Constants.INFO, ... 10 | 'saturation_dynamic_process', ''); 11 | for i=1:length(sat_dyn_list) 12 | display_msg(sat_dyn_list{i}, Constants.INFO, ... 13 | 'saturation_dynamic_process', ''); 14 | replace_one_block(sat_dyn_list{i},'gal_lib/saturation_dyn'); 15 | end 16 | display_msg('Done\n\n', Constants.INFO, ... 17 | 'saturation_dynamic_process', ''); 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/saturation_process.m: -------------------------------------------------------------------------------- 1 | function [] = saturation_process(model) 2 | % SATURATION_PROCESS Searches for saturation blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Saturation blocks 7 | saturation_list = find_system(model,'BlockType','Saturate'); 8 | if not(isempty(saturation_list)) 9 | disp('Processing Saturation blocks...') 10 | display_msg('Processing Saturation blocks...', Constants.INFO,... 11 | 'saturation_process', ''); 12 | for i=1:length(saturation_list) 13 | display_msg(saturation_list{i}, Constants.INFO, ... 14 | 'saturation_process', ''); 15 | lower_limit = get_param(saturation_list{i},'LowerLimit'); 16 | upper_limit = get_param(saturation_list{i},'UpperLimit'); 17 | replace_one_block(saturation_list{i},'gal_lib/saturation'); 18 | set_param(strcat(saturation_list{i},'/lower_limit'),... 19 | 'Value',lower_limit); 20 | set_param(strcat(saturation_list{i},'/upper_limit'),... 21 | 'Value',upper_limit); 22 | end 23 | display_msg('Done\n\n', Constants.INFO, 'saturation_process', ''); 24 | end 25 | end 26 | 27 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/selector_process.m: -------------------------------------------------------------------------------- 1 | function [] = selector_process(model) 2 | % SELECTOR_PROCESS Searches for selector blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing selector blocks 7 | selector_list = find_system(model,'BlockType','Selector'); 8 | if not(isempty(selector_list)) 9 | display_msg('Processing Selector blocks...', Constants.INFO,... 10 | 'selector_process', ''); 11 | for i=1:length(selector_list) 12 | display_msg(selector_list{i}, Constants.INFO,... 13 | 'selector_process', ''); 14 | [new_block_name, err] = selector_block_process(selector_list{i}); 15 | if ~err 16 | replace_one_block(selector_list{i},new_block_name); 17 | delete_block(new_block_name) 18 | end 19 | 20 | end 21 | display_msg('Done\n\n', Constants.INFO, 'selector_process', ''); 22 | end 23 | end 24 | 25 | function [new_block, err] = selector_block_process(init_block) 26 | % SELECTOR_BLOCK_PROCESS Changes the init_block block into a 27 | % GAL-friendly block. 28 | % init_block is a string containing the name of the block to process 29 | 30 | new_block = strcat(init_block,'_p'); 31 | err= 0; 32 | % Check that the input is only a verctor 33 | nb_dimensions = str2num(get_param(init_block,'NumberOfDimensions')); 34 | if (nb_dimensions ~= 1) 35 | msg = sprintf('%s%s%s\n%s\n','The block "',init_block,... 36 | '" is not supported because the ',... 37 | 'number of input dimensions is not 1\n'); 38 | display_msg(msg, Constants.WARNING, 'selector_process', ''); 39 | err = 1; 40 | else 41 | add_block('gal_lib/multi_in_out',new_block); 42 | delete_block(strcat(new_block,'/multi_block')); 43 | % Get the reference for indexes 44 | index_mode = get_param(init_block,'IndexMode'); 45 | if strcmp(index_mode,'Zero-based') 46 | idx = 1; 47 | else 48 | idx = 0; 49 | end 50 | 51 | input_size = get_param(init_block,'InputPortWidth'); 52 | set_param(strcat(new_block,'/Demux'),'Outputs',num2str(input_size)); 53 | 54 | index_option = get_param(init_block,'IndexOptionArray'); 55 | 56 | switch index_option{1} % index_option is a cell array 57 | case 'Index vector (dialog)' 58 | out = get_param(init_block,'IndexParamArray'); 59 | out = str2num(out{1}); % out is a cell array containing a string 60 | if length(out) == 1 61 | % Avoid vector output when the ouput is a scalar 62 | delete_block(strcat(new_block,'/Mux')); 63 | line_handle = get_param(strcat(new_block,'/Out'),'LineHandles'); 64 | delete_line(line_handle.Inport); 65 | add_line(new_block,... 66 | strcat('Demux/',num2str(out+idx)),'Out/1'); 67 | else 68 | set_param(strcat(new_block,'/Mux'),... 69 | 'Inputs',num2str(length(out))); 70 | for i=1:length(out) 71 | add_line(new_block,strcat('Demux/',num2str(out(i)+idx)),... 72 | strcat('Mux/',num2str(i))); 73 | end 74 | end 75 | otherwise 76 | msg = sprintf('The option "%s" in block "%s" is not handled\n',... 77 | index_option{1},init_block); 78 | display_msg(msg, Constants.WARNING, 'selector_process', ''); 79 | err = 1; 80 | delete_block(new_block) 81 | end 82 | end 83 | end 84 | 85 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/signalbuilder_process.m: -------------------------------------------------------------------------------- 1 | function [] = signalbuilder_process(model) 2 | % SIGNALBUILDER_PROCESS Searches for signal builder blocks and replaces 3 | % them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Signal Builder blocks 7 | 8 | signal_list = find_system(model,'MaskType','Sigbuilder block'); 9 | try 10 | signal_builder_sample = Utils.get_BlockDiagram_SampleTime(model); 11 | if signal_builder_sample==0 || isnan(signal_builder_sample) || signal_builder_sample==Inf 12 | signal_builder_sample = 1; 13 | end 14 | catch 15 | signal_builder_sample = Constants.signal_builder_sample; 16 | end 17 | if not(isempty(signal_list)) 18 | display_msg('Processing Signal Builder blocks...', Constants.INFO, 'signalbuilder_process', ''); 19 | for i=1:length(signal_list) 20 | display_msg(signal_list{i}, Constants.INFO, 'signalbuilder_process', ''); 21 | new_block_name = signalbuilder_block_process(signal_list{i}, signal_builder_sample); 22 | replace_one_block(signal_list{i},new_block_name); 23 | delete_block(new_block_name); 24 | end 25 | display_msg('Done\n\n', Constants.INFO, 'signalbuilder_process', ''); 26 | end 27 | end 28 | 29 | function [new_block] = signalbuilder_block_process(init_block, signal_builder_sample) 30 | % SIGNAL_BUILDER_BLOCK_PROCESS Changes the signal builder block into a 31 | % GAL-friendly block. 32 | % init_block is a sting containing the name of 33 | % the block to process. 34 | 35 | % Obtaining tables 36 | [time,data,signames] = signalbuilder(init_block); 37 | sig_nb = length(signames); 38 | if sig_nb == 1 39 | time = {time}; 40 | data = {data}; 41 | end 42 | 43 | new_block = strcat(init_block,'_p'); 44 | add_block('built-in/SubSystem',new_block); 45 | % Add an input in order to GAL to convert the block to a node 46 | % add_block('built-in/Inport',strcat(new_block,'/GAL_in'),... 47 | % 'Position',pos(0,0)); 48 | 49 | for i = 1:sig_nb 50 | sig = strcat(new_block,'/',signames{i}); 51 | sig_gen = strcat(sig,'_gen'); 52 | add_block('gal_lib/signal',sig_gen,... 53 | 'Position',pos(4,i,'w',80)); 54 | set_param(strcat(sig_gen,'/Sample'),'Gain', num2str(signal_builder_sample)); 55 | add_block('built-in/Outport',sig,'Position',pos(7,i)); 56 | add_line(new_block,strcat(signames{i},'_gen/1'),... 57 | strcat(signames{i},'/1')); 58 | 59 | tmp_block = strcat(sig_gen,'/tmp_block'); 60 | datatable_process(time{i},data{i},tmp_block); 61 | replace_one_block(strcat(sig_gen,'/signal_generator'),tmp_block); 62 | delete_block(tmp_block); 63 | end 64 | 65 | end -------------------------------------------------------------------------------- /src/pp/lib/blocks/to_workspace_process.m: -------------------------------------------------------------------------------- 1 | function [] = to_workspace_process(model) 2 | % TO_WORKSPACE_PROCESS Searches for To Workspace blocks and replaces them 3 | % by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | Xinit = 30; 7 | 8 | % Processing To Workspace blocks 9 | to_workspace_list = find_system(model,'BlockType','ToWorkspace'); 10 | if not(isempty(to_workspace_list)) 11 | display_msg('Processing To Workspace blocks...', Constants.INFO,... 12 | 'to_workspace_process', ''); 13 | for i=1:length(to_workspace_list) 14 | display_msg(to_workspace_list{i}, Constants.INFO, ... 15 | 'to_workspace_process', ''); 16 | tag = get_param(to_workspace_list{i},'VariableName'); 17 | 18 | parent = get_param(to_workspace_list{i},'Parent'); 19 | if strcmp(parent,model) 20 | replace_one_block(to_workspace_list{i},'built-in/Outport'); 21 | set_param(to_workspace_list{i},'Name',tag); 22 | else 23 | % Create a goto/from pattern that will be replaced after 24 | replace_one_block(to_workspace_list{i},'built-in/Goto'); 25 | set_param(to_workspace_list{i},'GotoTag',tag); 26 | set_param(to_workspace_list{i},'TagVisibility','global'); 27 | from_block = strcat(model,'/tag_',tag); 28 | add_block('built-in/From',from_block,... 29 | 'Position',pos(Xinit,i,'h',15)); 30 | set_param(from_block,'GotoTag',tag); 31 | set_param(from_block,'TagVisibility','global'); 32 | add_block('built-in/Outport',strcat(model,'/',tag),... 33 | 'Position',pos(Xinit+1,i,'h',15)); 34 | add_line(model,strcat('tag_',tag,'/1'),... 35 | strcat(tag,'/1')); 36 | % Replace the goto/from pattern 37 | goto_block_process(model,to_workspace_list{i}); 38 | end 39 | end 40 | display_msg('Done\n\n', Constants.INFO, 'to_workspace_process', ''); 41 | end 42 | end 43 | 44 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/transfer_function_process.m: -------------------------------------------------------------------------------- 1 | function [] = transfer_function_process(model) 2 | % TRANSFER_FCN_PROCESS Searches for transfer function blocks and replaces 3 | % them by a GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing Transfer Functions blocks 7 | transfer_function_list = find_system(model,'BlockType','TransferFcn'); 8 | if not(isempty(transfer_function_list)) 9 | % Apply the z-transform to the function block 10 | display_msg('Processing Transfer Functions blocks...', Constants.INFO,... 11 | 'transfer_function_process', ''); 12 | for i=1:length(transfer_function_list) 13 | display_msg(transfer_function_list{i}, Constants.INFO, 'transfer_function_process', ''); 14 | new_block_name = transfer_fcn_block_process(transfer_function_list{i}); 15 | replace_one_block(transfer_function_list{i},new_block_name); 16 | delete_block(new_block_name) 17 | end 18 | display_msg('Done\n\n', Constants.INFO, 'transfer_function_process', ''); 19 | end 20 | end 21 | 22 | function [new_block] = transfer_fcn_block_process(init_block) 23 | % TRANSFER_FCN_BLOCK_PROCESS Operates the ztransform over the specified 24 | % block. 25 | % init_block is a sting containing the name of 26 | % the block to process. 27 | 28 | % Obtaining z-expression parameters 29 | denum = get_param(init_block, 'Denominator'); 30 | denum = evalin('base',denum); 31 | num = get_param(init_block, 'Numerator'); 32 | num = evalin('base',num); 33 | %change from s domaine to z domaine 34 | try 35 | Hc = tf(num, denum); 36 | Hd = c2d(Hc,1);% we suppose sample time is 1 37 | num_d = Hd.Numerator{:}; 38 | denum_d = Hd.Denominator{:}; 39 | catch 40 | num_d = num; 41 | denum_d = denum; 42 | end 43 | % Computing state space representation 44 | [A,B,C,D]=tf2ss(num_d,denum_d); 45 | 46 | % Generating null Initial Conditions 47 | sizeA=size(A); 48 | n = sizeA(1); 49 | IC = zeros(1,n); 50 | 51 | % Generate the new_block 52 | new_block = strcat(init_block,'_p'); 53 | state_matrix_process(A,B,C,D,IC,new_block); 54 | end 55 | 56 | -------------------------------------------------------------------------------- /src/pp/lib/blocks/zero_pole_process.m: -------------------------------------------------------------------------------- 1 | function [] = zero_pole_process(model) 2 | % ZERO_POLE_PROCESS Searches for zero-pole blocks and replaces them by a 3 | % GAL-friendly equivalent. 4 | % model is a string containing the name of the model to search in 5 | 6 | % Processing ZeroPole defined transfer functions blocks 7 | zero_pole_list = find_system(model,'BlockType','ZeroPole'); 8 | if not(isempty(zero_pole_list)) 9 | % Apply the z-transform to the zero-pole block 10 | display_msg('Processing ZeroPole defined transfer function blocks...',... 11 | Constants.INFO, 'zero_pole_process', ''); 12 | for i=1:length(zero_pole_list) 13 | display_msg(zero_pole_list{i}, Constants.INFO, ... 14 | 'zero_pole_process', ''); 15 | new_block_name = zero_pole_block_process(zero_pole_list{i}); 16 | replace_one_block(zero_pole_list{i},new_block_name); 17 | delete_block(new_block_name) 18 | end 19 | display_msg('Done\n\n', Constants.INFO, 'zero_pole_process', ''); 20 | end 21 | end 22 | 23 | function [new_block] = zero_pole_block_process(init_block) 24 | % ZERO_POLE_BLOCK_PROCESS Operates the ztransform over the specified block. 25 | % init_block is a sting containing the name of 26 | % the block to process. 27 | 28 | % Obtaining z-expression parameters 29 | zeros1 = eval(get_param(init_block, 'Zeros')); 30 | poles = eval(get_param(init_block, 'Poles')); 31 | gain = eval(get_param(init_block, 'Gain')); 32 | % Computing state space representation 33 | [A,B,C,D]=zp2ss(zeros1,poles,gain); 34 | 35 | % Generating null Initial Conditions 36 | sizeA=size(A); 37 | n = sizeA(1); 38 | IC = zeros(1,n); 39 | 40 | % Generate the new_block 41 | new_block = strcat(init_block,'_p'); 42 | state_matrix_process(A,B,C,D,IC,new_block); 43 | end 44 | 45 | -------------------------------------------------------------------------------- /src/pp/lib/common/gal_lib.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/src/pp/lib/common/gal_lib.slx -------------------------------------------------------------------------------- /src/pp/lib/common/pos.m: -------------------------------------------------------------------------------- 1 | function [position] = pos(offset_x, offset_y,varargin) 2 | % Generate a position array 3 | x = 30; 4 | y = 30; 5 | w = 30; 6 | h = 30; 7 | offset = 60; 8 | if nargin>2 9 | for i=1:2:(nargin-2) 10 | switch varargin{i} 11 | case 'w' 12 | % width specified 13 | w = varargin{i+1}; 14 | case 'h' 15 | % height specified 16 | h = varargin{i+1}; 17 | otherwise 18 | throw(MException(Pos:Options,'Wrong option')) 19 | end 20 | end 21 | end 22 | position = [x+offset*offset_x y+offset*offset_y x+offset*offset_x+w y+offset*offset_y+h]; 23 | end -------------------------------------------------------------------------------- /src/pp/lib/common/remove_line_tags.m: -------------------------------------------------------------------------------- 1 | function [] = remove_line_tags(file_name, tags) 2 | % REMOVE_TAGS searches for each component of tags in the provided file 3 | % and suppress the ENTIRE LINE where the tag is located. 4 | 5 | if strcmp(class(tags),'char') 6 | expr = tags; 7 | else 8 | expr = tags{1}; 9 | for i=2:length(tags) 10 | expr = strcat(expr,'|',tags{i}); 11 | end 12 | end 13 | system(['LANG=C && sed -Ei '''' "/' expr '/d" "' file_name '"']); 14 | 15 | end 16 | 17 | -------------------------------------------------------------------------------- /src/pp/lib/common/replace_one_block.m: -------------------------------------------------------------------------------- 1 | function [] = replace_one_block(block,new_block,varargin) 2 | % REPLACE_ONE_BLOCK replaces block by the new block. 3 | % Full path must be provided. 4 | % If the global variable 'verif' is true, this function also creates a 5 | % slx model with both the block and the new_block for verification 6 | % purposes. 7 | % Options : 'verif_off' bypasses the value of the verif global variable 8 | 9 | % Determine wether verification model should be generated 10 | verif = false; 11 | if nargin > 2 12 | if not(strcmp(varargin{1},'verif_off')) 13 | verif = true; 14 | end 15 | else 16 | verif = evalin('base','verif'); 17 | end 18 | 19 | % Create the verification model if necessary 20 | try 21 | if verif 22 | newline = sprintf('\n'); 23 | fname = get_param(block,'Name'); 24 | fname = strrep(fname,newline,'_'); 25 | fname = strrep(fname,'-','_'); 26 | fname = strrep(fname,' ','_'); 27 | fname = strrep(fname,'.','_'); 28 | verif_file = strcat('Verification/',fname,'_verif.slx'); 29 | verif_model = strcat(fname,'_verif'); 30 | if exist('Verification','dir') && exist(verif_file,'file') 31 | % If the file doesn't exist, we generate a new one 32 | [script_path, ~, ~] = fileparts(mfilename('fullpath')); 33 | verif_template = fullfile(script_path, 'verification_template.slx'); 34 | copyfile(verif_template,verif_file); 35 | disp('A verification file has been created'); 36 | end 37 | load_system(verif_model); 38 | replace_one_block(strcat(verif_model,'/original'),... 39 | block,'verif_off'); 40 | replace_one_block(strcat(verif_model,'/generated'),... 41 | new_block,'verif_off'); 42 | save_system(verif_model); 43 | close_system(verif_model); 44 | end 45 | catch ME 46 | display_msg(ME.message, Constants.ERROR, 'simplifier', ''); 47 | display_msg(ME.getReport(), Constants.DEBUG, 'simplifier', ''); 48 | end 49 | % Replace the block by the new_block 50 | Orient=get_param(block,'orientation'); 51 | Size=get_param(block,'position'); 52 | delete_block(block); 53 | add_block(new_block,block, ... 54 | 'MakeNameUnique', 'on', ... 55 | 'Orientation',Orient, ... 56 | 'Position',Size); 57 | end 58 | 59 | -------------------------------------------------------------------------------- /src/pp/lib/common/verification_template.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/src/pp/lib/common/verification_template.slx -------------------------------------------------------------------------------- /src/pp/lib/math/parse_math.m: -------------------------------------------------------------------------------- 1 | function tree = parse_math(expr) 2 | % PARSE_MATH return a cell array representing the mathematical expression. 3 | % This function requires Matlab R2014b featuring the python module to 4 | % work properly. 5 | 6 | % Handle error concerning the Matlab version running 7 | 8 | try 9 | % Add the folder where "expr_parser" python module is into python path 10 | libpy_path = which('expr_parser.py'); 11 | libpy_path = strrep(libpy_path,'/expr_parser.py',''); 12 | if count(py.sys.path,libpy_path) == 0 13 | insert(py.sys.path,int32(0),libpy_path) 14 | end 15 | catch 16 | throw(MException('Python:BadMatlabVersion',... 17 | '%s\n%s\n%s%s\n%s\n%s%s%s%s',... 18 | 'Error while using Python capabilities of Matlab,',... 19 | 'Those Python capabilities require Matlab r2014b or higher.',... 20 | 'If you have Matlab r2014b and this message is displayed ',... 21 | 'you should check that :',... 22 | '- Python is installed on your computer',... 23 | '- the matlab command "pyversion" displays the actual ',... 24 | '"library" and "home" paths. Otherwise use the ',... 25 | 'command "pyversion(python/executable/absolute/path)" to ',... 26 | 'update these paths.')); 27 | end 28 | 29 | % Transform the expression into a python string 30 | pyexpr = py.str(expr); 31 | % Call the python parser with the python string in argument 32 | pytree = py.expr_parser.parse(pyexpr); 33 | % The python parser returns a python tuple representing the expression if 34 | % this one is 'complex' wich means at least one calculation. 35 | if isa(pytree,'py.tuple') 36 | % Then we have to convert the python tuple into a matlab comprehensive 37 | % form. I chose a cell array. 38 | tree = tuple2cell(pytree); 39 | else 40 | tree = char(pytree); 41 | % ParseError handling 42 | if strfind(tree,'ParseError') 43 | throw(MException('ParseError:UnMatched','%s\n%s\n%s\n',... 44 | 'expr_parser encountered a ParseError,',... 45 | 'here is the original message :',tree)); 46 | end 47 | end 48 | 49 | end 50 | 51 | function cell_array = tuple2cell(pytuple) 52 | % TUPLE2CELL converts Python tuple objects into a matlab cell array. 53 | % This function requires Matlab R2014b featuring the python module to 54 | % work properly. 55 | 56 | function item = get_item(pytuple,index) 57 | item = py.operator.getitem(pytuple,int32(index-1)); 58 | end 59 | 60 | for i=1:py.len(pytuple) 61 | item = char(get_item(pytuple,i)); 62 | if isempty(regexp(item,'^(')) 63 | cell_array{i} = item; 64 | else 65 | cell_array{i} = tuple2cell(get_item(pytuple,i)); 66 | end 67 | end 68 | 69 | end -------------------------------------------------------------------------------- /src/utils/cprintf.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/src/utils/cprintf.m -------------------------------------------------------------------------------- /src/utils/display_msg.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | %% Displays a message differently according to its type 7 | % 8 | % str: the message to display. 9 | % 10 | % type: the type of message among INFO, WARNING, ERROR, DEBUG. These values 11 | % are declared in the Constant.m class. 12 | % 13 | % from_str: the name of the file/section of code from where the message is 14 | % launched. 15 | % 16 | % err_code: an additional error code to be displayed. 17 | % 18 | function display_msg(str, type, from_str, err_code) 19 | 20 | final_message = ''; 21 | 22 | if type == 1 23 | final_message = '(Info)'; 24 | elseif type == 2 25 | final_message = '(Warning)'; 26 | elseif type == 3 27 | final_message = '(Error)'; 28 | elseif type == 4 29 | final_message = '(Debug)'; 30 | elseif type == 5 31 | final_message = '(Result)'; 32 | end 33 | 34 | if not(strcmp(from_str, '')) 35 | final_message = [final_message '[' from_str ']']; 36 | end 37 | 38 | if not(strcmp(err_code, '')) 39 | final_message = [final_message '(code: ' err_code ')']; 40 | end 41 | 42 | str_sp = regexp(str, '\\n', 'split'); 43 | 44 | % disp([final_message ' ' str{1}]); 45 | 46 | msg = [final_message ' ' str_sp{1} '\n']; 47 | try 48 | tgroup = evalin('base','cocosim_tgroup_handle'); 49 | if (tgroup.isvalid) 50 | tgroup_found = true; 51 | else 52 | tgroup_found = false; 53 | end 54 | catch 55 | tgroup_found = false; 56 | end 57 | 58 | try 59 | cocosim_debug = evalin('base','cocosim_debug'); 60 | catch 61 | cocosim_debug = false; 62 | end 63 | % color = {'black','cyan','red','[1,0.5,0]','blue'}; 64 | if tgroup_found && isa(tgroup,'matlab.ui.container.TabGroup') 65 | msg = sprintf('%s %s\n',final_message, str); 66 | old_str = tgroup.Children(type).Children(1).String; 67 | splited_msg = regexp(msg,'\n','split'); 68 | htmlmsg = html_text(splited_msg,type); 69 | string = [old_str; htmlmsg']; 70 | tgroup.Children(type).Children(1).String = string; 71 | tgroup.Children(type).Children(1).Value = numel(string); 72 | if (type~=4 || cocosim_debug), tgroup.SelectedTab = tgroup.Children(type); end 73 | drawnow limitrate 74 | else 75 | if type == 1 76 | cprintf('black', msg); 77 | elseif type == 3 78 | cprintf('red', msg) 79 | elseif (type == 4 && cocosim_debug) 80 | cprintf([1,0.5,0], msg) 81 | elseif type == 2 82 | cprintf('cyan', msg) 83 | elseif type == 5 84 | cprintf('*blue', msg) 85 | end 86 | for idx_str=2:numel(str_sp) 87 | if ~strcmp(str_sp{idx_str}, '') 88 | disp(sprintf('\t %s',str_sp{idx_str})); 89 | end 90 | end 91 | end 92 | 93 | 94 | % if type == 3 95 | % warning off backtrace 96 | % error('The transformation process will now stop') 97 | % end 98 | 99 | end 100 | function htmlmsg = html_text(splited_msg, type) 101 | if type~=4 && type~=3 102 | htmlmsg = splited_msg; 103 | else 104 | htmlmsg = {}; 105 | for i=1:numel(splited_msg) 106 | if strfind(splited_msg{i},' href') 107 | htmlmsg{i} = sprintf('%s', splited_msg{i}); 108 | else 109 | htmlmsg{i} = splited_msg{i}; 110 | end 111 | end 112 | end 113 | end -------------------------------------------------------------------------------- /src/utils/get_full_name.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ object_full_name ] = get_full_name( object,isChart ) 7 | %GET_FULL_NAME Summary of this function goes here 8 | % Detailed explanation goes here 9 | if ~exist('isChart', 'var') 10 | isChart = false; 11 | end 12 | % object_full_name = regexprep(strcat(object.path,'_',object.Name),expression,replace); 13 | object_parent_name= regexp(object.Path, '/','split'); 14 | if isChart 15 | str = object_parent_name(1:end-1); 16 | object_parent_name = Utils.concat_delim(str, '_');%object_parent_name{1}; 17 | else 18 | object_parent_name = object_parent_name{end}; 19 | end 20 | expression = '(\s*|\-|/)'; 21 | replace = ''; 22 | try 23 | object_name = regexprep(object.Name,expression,replace); 24 | catch 25 | object_name = strcat('Junction',num2str(object.Id)); 26 | end 27 | object_parent_name = regexprep(object_parent_name,expression,replace); 28 | if isChart 29 | object_full_name = Utils.name_format(strcat(object_parent_name,'_',object_name)); 30 | else 31 | object_full_name = Utils.name_format(strcat(object_parent_name,'_',object_name,num2str(object.Id))); 32 | end 33 | end 34 | 35 | -------------------------------------------------------------------------------- /src/utils/messagetype.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | classdef messagetype 7 | enumeration 8 | Info 9 | Warning 10 | Error 11 | Debug 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /src/utils/sT2fT.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ Lustre_type, initial_value ] = sT2fT( stateflow_Type, data_name ) 7 | if strcmp(stateflow_Type, 'real') || strcmp(stateflow_Type, 'int') || strcmp(stateflow_Type, 'bool') 8 | Lustre_type = simulink_dt; 9 | else 10 | if strcmp(stateflow_Type, 'logical') || strcmp(stateflow_Type, 'boolean') 11 | Lustre_type = 'bool'; 12 | initial_value = 'false'; 13 | elseif strncmp(stateflow_Type, 'int', 3) || strncmp(stateflow_Type, 'uint', 4) || strncmp(stateflow_Type, 'fixdt(1,16,', 11) || strncmp(stateflow_Type, 'sfix64', 6) 14 | Lustre_type = 'int'; 15 | initial_value = '0'; 16 | elseif ~isempty(strfind(stateflow_Type,'Inherit')) 17 | try 18 | var = evalin('base',data_name); 19 | [ Lustre_type, initial_value ] = sT2fT( var.DataType, data_name ); 20 | catch ME 21 | msg = ['Parameter :' data_name ' declared as type :"' stateflow_Type '" does not exit in workspace base.\n',... 22 | 'Make sure you set all model parameters in workspace before you run the tool.\n']; 23 | causeException = MException('simulinkParameter:UnknownData',msg); 24 | ME = addCause(ME,causeException); 25 | rethrow(ME) 26 | end 27 | else 28 | Lustre_type = 'real'; 29 | initial_value = '0.0'; 30 | end 31 | end 32 | end 33 | 34 | -------------------------------------------------------------------------------- /src/utils/setdiff_struct.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function diff1in2 = setdiff_struct( node_struct2, node_struct1 ) 7 | %return the elements in node_struct2 that are not in node_struct1 8 | if isempty(node_struct2) 9 | diff1in2 = []; 10 | elseif isempty(node_struct1) 11 | diff1in2 = node_struct2; 12 | else 13 | AA = node_struct2(~cellfun(@isempty,{node_struct2.Name})); 14 | BB = node_struct1(~cellfun(@isempty,{node_struct1.Name})); 15 | A = {AA.Name} ; 16 | B = {BB.Name} ; 17 | [~,ia] = setdiff(A,B) ; 18 | diff1in2 = node_struct2(ia) ; 19 | end 20 | end 21 | 22 | -------------------------------------------------------------------------------- /src/utils/sort_by_order.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [ sorted_objects] = sort_by_order( objects, port_or_order, chart, isFunction ) 7 | %this function can be called also for states to sort them by their 8 | %execution order 9 | 10 | if ~exist('port_or_order','var') 11 | port_or_order = 'order'; 12 | end 13 | 14 | if ~exist('chart','var') 15 | chart = []; 16 | end 17 | 18 | 19 | if ~exist('isFunction','var') 20 | isFunction = false; 21 | end 22 | n = numel(objects); 23 | execution_order = zeros(n,1); 24 | sorted_objects = objects; 25 | if n>1 26 | if isFunction 27 | label = chart.LabelString; 28 | for i=1:n 29 | ind = strfind(label,objects(i).Name); 30 | if ~isempty(ind) 31 | execution_order(i) = ind(1); 32 | else 33 | execution_order(i) = Inf; 34 | end 35 | end 36 | [~, sorted_ind] = sort(execution_order); 37 | sorted_objects = objects(sorted_ind); 38 | else 39 | if strcmp(port_or_order,'port') 40 | 41 | for i=1:n 42 | execution_order(i) = objects(i).Port; 43 | end 44 | [~, sorted_ind] = sort(execution_order); 45 | sorted_objects = objects(sorted_ind); 46 | 47 | elseif strcmp(port_or_order,'name') 48 | % sorted_objects = sort(objects); 49 | names = cell(1,n); 50 | for i=1:n 51 | names{i} = objects(i).Name; 52 | end 53 | [~, sorted_ind] = sort(names); 54 | sorted_objects = objects(sorted_ind); 55 | 56 | elseif strcmp(port_or_order,'order') 57 | for i=1:n 58 | execution_order(i) = objects(i).ExecutionOrder; 59 | end 60 | [~, sorted_ind] = sort(execution_order); 61 | sorted_objects = objects(sorted_ind); 62 | 63 | elseif strcmp(port_or_order,'states') 64 | execution_order = zeros(n,2); 65 | for i=1:n 66 | execution_order(i,:) = objects(i).Position(1:2); 67 | end 68 | [~, sorted_ind] = sortrows(execution_order); 69 | sorted_objects = objects(sorted_ind); 70 | end 71 | end 72 | end 73 | 74 | 75 | end 76 | 77 | -------------------------------------------------------------------------------- /src/utils/to_XML.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function to_XML(out_file_name, origin_model, data) 7 | 8 | intDOM = com.mathworks.xml.XMLUtils.createDocument('CocoSimInternalStructure'); 9 | rootDoc = intDOM.getDocumentElement; 10 | rootDoc.setAttribute('model_file', origin_model); 11 | 12 | if strcmp(class(data), 'cell') 13 | cellElems = parseCell(data, rootDoc); 14 | for idx=1:numel(cellElems) 15 | rootDoc.appendChild(cellElems); 16 | end 17 | elseif strcmp(class(data), 'struct') 18 | structElem = parseStruct(data, rootDoc); 19 | rootDoc.appendChild(structElem); 20 | end 21 | 22 | xmlwrite(out_file_name, intDOM); 23 | 24 | end 25 | 26 | function cellElems = parseCell(data, rootDoc) 27 | 28 | 29 | 30 | end 31 | 32 | function structElem = parseStruct(data, rootDoc) 33 | 34 | structElem = rootDoc.createElement('Struct'); 35 | fields = filednames(data); 36 | for idx=1:numel(fields) 37 | value = data.(fields{idx}); 38 | nodeElem = parseValue(value, fields{idx}, rootDoc); 39 | end 40 | 41 | end 42 | 43 | function fieldElem = parseValue(value, name, rootDoc) 44 | 45 | 46 | if strcmp(name, '') 47 | fieldName = 'value'; 48 | else 49 | fieldElem = name; 50 | end 51 | % if strcmp(class(value), 'char') 52 | % fieldElem.appendChild(rootDoc.create_Text_Node( 53 | 54 | end 55 | 56 | function element = create_Struct_Element() 57 | element = obj.traceDOM.createElement('Node'); 58 | element.setAttribute('node_name', node_name); 59 | element.setAttribute('block_name', block_origin_name); 60 | obj.traceRootNode.appendChild(element); 61 | obj.current_node = element; 62 | end 63 | -------------------------------------------------------------------------------- /src/utils/traceability_annotation.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function [pre_annot post_annot] = traceability_annotation(inter_blk) 7 | 8 | pre_annot = '\t'; 9 | post_annot = '\t'; 10 | 11 | blk_name = ''; 12 | for idx_name=1:numel(inter_blk.name) 13 | blk_name = [blk_name inter_blk.name{idx_name}]; 14 | end 15 | 16 | pre_annot = [pre_annot '-- Trace_begin: ' blk_name ';\n']; 17 | post_annot = [post_annot '-- Trace_end: ' blk_name ';\n']; 18 | 19 | end 20 | -------------------------------------------------------------------------------- /start_cocosim.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is part of CoCoSim. 3 | % Copyright (C) 2014-2016 Carnegie Mellon University 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | 6 | function start_cocosim() 7 | warning ('off','all'); 8 | [cocoSim_path, function_name, ext] = fileparts(mfilename('fullpath')); 9 | disp('--------------------------') 10 | disp(' WELCOME TO COCOSIM ') 11 | disp('--------------------------') 12 | disp('... adding cocoSim path') 13 | addpath(fullfile(cocoSim_path, 'src')); 14 | addpath(fullfile(cocoSim_path, 'src','gui')); 15 | addpath(fullfile(cocoSim_path, 'src','utils')); 16 | config; 17 | if strcmp(ZUSTRE, 'PATH') 18 | disp('Warning: Path to Zustre is NOT configured in src/config.m') 19 | end 20 | if strcmp(LUSTREC, 'PATH') 21 | disp('Warning: Path to LUSTREC is NOT configured in src/config.m') 22 | end 23 | if strcmp(Z3, 'PATH') 24 | disp('Warning: Path to Z3 is NOT configured in src/config.m') 25 | end 26 | if strcmp(KIND2, 'PATH') 27 | disp('Warning: Path to KIND2 is NOT configured in src/config.m') 28 | end 29 | if strcmp(JKIND, 'PATH') 30 | disp('Warning: Path to JKIND is Not configured in src/config/m') 31 | end 32 | 33 | disp('... refreshing customizations') 34 | addpath(fullfile(cocoSim_path, '.')); 35 | sl_refresh_customizations; 36 | disp('... CoCoSim is Ready'); 37 | example_model = fullfile(cocoSim_path, 'test', 'properties', 'safe_1.mdl'); 38 | e_message = sprintf('\n\t Click here to start with a simple verification example.', example_model); 39 | disp('--------------------------') 40 | disp(e_message); 41 | clear; 42 | end 43 | -------------------------------------------------------------------------------- /test/Fcn/Fcn.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/Fcn/Fcn.slx -------------------------------------------------------------------------------- /test/Fcn/Fcn2.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/Fcn/Fcn2.slx -------------------------------------------------------------------------------- /test/Fcn/Fcn3.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/Fcn/Fcn3.slx -------------------------------------------------------------------------------- /test/StateFlow/tests_with_properties/MicrowaveCex.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/StateFlow/tests_with_properties/MicrowaveCex.slx -------------------------------------------------------------------------------- /test/StateFlow/tests_with_properties/set_up_parameters.m: -------------------------------------------------------------------------------- 1 | 2 | step_size = Simulink.Parameter; 3 | step_size.Value = 1.0; 4 | step_size.DataType = 'double'; 5 | 6 | dt = 0.01; 7 | 8 | Primary_Side = Simulink.Parameter; 9 | Primary_Side.Value = 0; 10 | Primary_Side.DataType = 'boolean'; 11 | 12 | MANUAL = Simulink.Parameter; 13 | MANUAL.Value = 1; 14 | MANUAL.DataType = 'uint8'; 15 | 16 | LO = Simulink.Parameter; 17 | LO.Value = 2; 18 | LO.DataType = 'uint8'; 19 | 20 | MED = Simulink.Parameter; 21 | MED.Value = 3; 22 | MED.DataType = 'uint8'; 23 | 24 | MAX = Simulink.Parameter; 25 | MAX.Value = 4; 26 | MAX.DataType = 'uint8'; 27 | 28 | BRAKE_PRESSURE_LO = Simulink.Parameter; 29 | BRAKE_PRESSURE_LO.Value = 170; 30 | BRAKE_PRESSURE_LO.DataType = 'int32'; 31 | 32 | BRAKE_PRESSURE_MED = Simulink.Parameter; 33 | BRAKE_PRESSURE_MED.Value = 340; 34 | BRAKE_PRESSURE_MED.DataType = 'int32'; 35 | 36 | BRAKE_PRESSURE_MAX = Simulink.Parameter; 37 | BRAKE_PRESSURE_MAX.Value = 510; 38 | BRAKE_PRESSURE_MAX.DataType = 'int32'; -------------------------------------------------------------------------------- /test/StateFlow/tests_without_properties/BSCU.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/StateFlow/tests_without_properties/BSCU.slx -------------------------------------------------------------------------------- /test/StateFlow/tests_without_properties/set_up_parameters.m: -------------------------------------------------------------------------------- 1 | 2 | step_size = Simulink.Parameter; 3 | step_size.Value = 1.0; 4 | step_size.DataType = 'double'; 5 | 6 | dt = 0.01; 7 | 8 | Primary_Side = Simulink.Parameter; 9 | Primary_Side.Value = 0; 10 | Primary_Side.DataType = 'boolean'; 11 | 12 | MANUAL = Simulink.Parameter; 13 | MANUAL.Value = 1; 14 | MANUAL.DataType = 'uint8'; 15 | 16 | LO = Simulink.Parameter; 17 | LO.Value = 2; 18 | LO.DataType = 'uint8'; 19 | 20 | MED = Simulink.Parameter; 21 | MED.Value = 3; 22 | MED.DataType = 'uint8'; 23 | 24 | MAX = Simulink.Parameter; 25 | MAX.Value = 4; 26 | MAX.DataType = 'uint8'; 27 | 28 | BRAKE_PRESSURE_LO = Simulink.Parameter; 29 | BRAKE_PRESSURE_LO.Value = 170; 30 | BRAKE_PRESSURE_LO.DataType = 'int32'; 31 | 32 | BRAKE_PRESSURE_MED = Simulink.Parameter; 33 | BRAKE_PRESSURE_MED.Value = 340; 34 | BRAKE_PRESSURE_MED.DataType = 'int32'; 35 | 36 | BRAKE_PRESSURE_MAX = Simulink.Parameter; 37 | BRAKE_PRESSURE_MAX.Value = 510; 38 | BRAKE_PRESSURE_MAX.DataType = 'int32'; -------------------------------------------------------------------------------- /test/cocospec/AltitudeControl_Demo.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/cocospec/AltitudeControl_Demo.slx -------------------------------------------------------------------------------- /test/cocospec/cocospec_3.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/cocospec/cocospec_3.slx -------------------------------------------------------------------------------- /test/properties/AltitudeControl_Demo.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/properties/AltitudeControl_Demo.slx -------------------------------------------------------------------------------- /test/properties/assertion.mdl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/properties/assertion.mdl -------------------------------------------------------------------------------- /test/properties/assumption.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/properties/assumption.slx -------------------------------------------------------------------------------- /test/properties/safe_math_functions.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coco-team/cocoSim-deprecated/10fa76fee83458ee1b699255182a4a62e16b9864/test/properties/safe_math_functions.slx --------------------------------------------------------------------------------