private void AddConnectedInputPorts(ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort port, ISet <ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort> visited) { visited.Add(port); if (port.Attributes.SimulinkPortDirection == ISIS.GME.Dsml.CyPhyML.Classes.SimulinkPort.AttributesClass.SimulinkPortDirection_enum.@in && port.ParentContainer is ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel) { var parentComponentName = SimulinkBlock.GetBlockName((ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel)port.ParentContainer); var portId = GetPortId(port); ConnectedInputPorts.Add(string.Format("{0}/{1}", parentComponentName, portId)); SimulinkGenerator.GMEConsole.Info.WriteLine("Connection: {0}/{1}", parentComponentName, portId); } foreach (var connection in port.SrcConnections.PortCompositionCollection) { var adjacent = connection.SrcEnd; if (adjacent is ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort && !visited.Contains(adjacent)) { AddConnectedInputPorts((ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort)adjacent, visited); } } foreach (var connection in port.DstConnections.PortCompositionCollection) { var adjacent = connection.DstEnd; if (adjacent is ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort && !visited.Contains(adjacent)) { AddConnectedInputPorts((ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkPort)adjacent, visited); } } }
public static void GenerateSimulink(TestBench selectedTestBench, string outputDirectory, string projectDirectory) { // Reset block name cache (interpreters don't necessarily get reloaded between executions, so // we need to reset any static variables ourselves that need to be reset between executions) SimulinkBlock.ResetBlockNameCache(); var model = new SimulinkModel(selectedTestBench); // Copy support files CopySupportFile(outputDirectory, "CreateOrOverwriteModel.m", Resources.CreateOrOverwriteModel); CopySupportFile(outputDirectory, "PopulateTestBenchParams.py", Resources.PopulateTestBenchParams); CopyCopyFiles(selectedTestBench, projectDirectory, outputDirectory); var postProcessScripts = GetAndCopyPostProcessScripts(selectedTestBench, projectDirectory, outputDirectory); using (var writer = File.CreateText(Path.Combine(outputDirectory, "build_simulink.m.in"))) { model.GenerateSimulinkModelCode(writer); } using (var writer = File.CreateText(Path.Combine(outputDirectory, "run_simulink.m"))) { model.GenerateSimulinkExecutionCode(writer); } using (var writer = File.CreateText(Path.Combine(outputDirectory, "run.cmd"))) { GenerateRunCmd(writer, postProcessScripts); } }
public SimulinkModel(TestBench testBench) : this() { //Iterate through TB to find blocks testBench.TraverseDFS(children => children, (child, i) => { if (child is ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel) { var block = SimulinkBlock.FromDomainModel((ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel)child); if (block != null) { SimulinkGenerator.GMEConsole.Info.Write("Added block {0} ({1})", block.Name, block.BlockType); Blocks.Add(block); } } }); foreach (var param in testBench.Children.ParameterCollection) { if (!param.AllDstConnections.Any() && !param.AllSrcConnections.Any()) { if (param.Name == "CopyFile") { //Ignore } else if (param.Name == "UserLibrary" && param.Attributes.Value != "") { var baseName = Path.GetFileNameWithoutExtension(param.Attributes.Value); UserLibraries.Add(baseName); } else { if (param.Attributes.Value != "") { SimulationParams[param.Name] = param.Attributes.Value; } } } } }
public static SimulinkBlock FromDomainModel(ISIS.GME.Dsml.CyPhyML.Interfaces.SimulinkModel domainModel) { var result = new SimulinkBlock(GetBlockName(domainModel), domainModel.Attributes.BlockType); foreach (var param in domainModel.Children.SimulinkParameterCollection) { var simulinkParam = SimulinkParameter.FromDomainParameter(param); if (simulinkParam != null) { result.Parameters.Add(simulinkParam); } } foreach (var port in domainModel.Children.SimulinkPortCollection) { var simulinkPort = SimulinkPort.FromDomainPort(port); if (simulinkPort != null) { result.OutgoingPorts.Add(simulinkPort); } } return(result); }