From 117e6473d59a9e4b7332004d1c4d0f0280444792 Mon Sep 17 00:00:00 2001
From: Sergey Zverlov <zverlov@fortiss.org>
Date: Tue, 3 May 2016 13:00:27 +0000
Subject: [PATCH] refs 2505

---
 .../trunk/META-INF/MANIFEST.MF                |  5 +-
 .../generator/executable/BusExecutable.java   | 81 ++++++++++---------
 .../raspberry/utils/RaspberryUtils.java       | 57 +++++++++++++
 3 files changed, 102 insertions(+), 41 deletions(-)
 create mode 100644 org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/utils/RaspberryUtils.java

diff --git a/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF b/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF
index e9168c2f..b43d25cf 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF
+++ b/org.fortiss.af3.platform.raspberry/trunk/META-INF/MANIFEST.MF
@@ -17,7 +17,10 @@ Require-Bundle: org.fortiss.af3.project,
  org.fortiss.af3.platform;bundle-version="2.5.0";visibility:=reexport,
  org.fortiss.tooling.base;visibility:=reexport,
  org.fortiss.af3.expression,
- org.eclipse.jface;bundle-version="3.9.1"
+ org.eclipse.jface;bundle-version="3.9.1",
+ org.fortiss.af3.deployment,
+ org.fortiss.af3.component,
+ org.fortiss.af3.analyses
 Export-Package: org.fortiss.af3.platform.raspberry.compositor,
  org.fortiss.af3.platform.raspberry.model,
  org.fortiss.af3.platform.raspberry.model.impl,
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/BusExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/BusExecutable.java
index 50c5d313..c78870b7 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/BusExecutable.java
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/BusExecutable.java
@@ -18,15 +18,20 @@ $Id$
 package org.fortiss.af3.platform.raspberry.generator.executable;
 
 import static org.fortiss.af3.generator.common.utils.SourceModelElementFactory.createStaticContentSourceUnit;
+import static org.fortiss.af3.platform.raspberry.utils.RaspberryUtils.getEcuForComponent;
+import static org.fortiss.af3.platform.raspberry.utils.RaspberryUtils.getTargetComponent;
+import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.findElementById;
 
 import java.util.List;
 import java.util.Map;
 
+import org.fortiss.af3.bounds.model.VariableBoundsSpecification;
 import org.fortiss.af3.component.model.Component;
-import org.fortiss.af3.component.model.InputPort;
 import org.fortiss.af3.component.model.OutputPort;
 import org.fortiss.af3.component.model.Port;
 import org.fortiss.af3.component.model.PortSpecification;
+import org.fortiss.af3.deployment.model.ComponentAllocation;
+import org.fortiss.af3.deployment.model.Deployment;
 import org.fortiss.af3.generator.common.model.source.SourcePackage;
 import org.fortiss.af3.platform.language.executable.TransmissionUnitExecutableBase;
 import org.fortiss.af3.platform.model.ExecutionUnit;
@@ -55,52 +60,48 @@ public class BusExecutable extends TransmissionUnitExecutableBase<TransmissionUn
 	public void createAllFiles(SourcePackage pack, Map<ExecutionUnit, List<Port>> euPortsPair,
 			Map<ExecutionUnit, List<Component>> euComponentList, Component topComponent,
 			int deploymentID) {
-		checkTypesOfOutputPorts(pack, euPortsPair);
+		findBusSignals(deploymentID, topComponent, pack);
 	}
 
-	/** Collects the information about type and bounds of all OutputPorts. */
-	public void checkTypesOfOutputPorts(SourcePackage pack,
-			Map<ExecutionUnit, List<Port>> portsToCheck) {
-
-		// TODO: Look at all ports, which are OutputPorts (instanceof OutputPort)
-		// save for each port the type (i.e.: int) and the upper+lower bounds
-		// create a simple string template for the output
-		// String Keys;
-		String logPortSpecs = new String();
-		String portName = new String();
-		String portType = new String();
-
-		Object[] ecus = portsToCheck.keySet().toArray();
-		for(Object ecu : ecus) { // Iterate over number of Cores
-			for(Object port : portsToCheck.get(ecu)) { // Iterate over Number of Ports.
-				if(port instanceof InputPort) {
-					portName = ((InputPort)port).getName();
-					PortSpecification portSpecIn =
-							(PortSpecification)((InputPort)port).getSpecifications().get(0);
-					portType = portSpecIn.getType().toString();
-					// logPortSpecification(portName, portSpecIn, "Input");
-					logPortSpecs +=
-							"Input PortName:  " + portName + "\nType:      " + portType + "\n\n";
-
-				} else if(port instanceof OutputPort) {
-					portName = ((OutputPort)port).getName();
-					PortSpecification portSpecOut =
-							(PortSpecification)((OutputPort)port).getSpecifications().get(0);
-					portType = portSpecOut.getType().toString();
-					// logPortSpecification(portName, portSpecOut, "Output");
-					logPortSpecs +=
-							"Output PortName:  " + portName + "\nType:      " + portType + "\n\n";
-
-				} else {
-					System.out.println("Not a port!");
+	/** Finds Information about Signals that are transmitted over the Bus. */
+	public void findBusSignals(int deploymentID, Component topComponent, SourcePackage pack) {
+		String resultString = "";
+		Deployment currentDeployment =
+				(Deployment)findElementById(deploymentID, topComponent.eContainer().eContainer());
+		for(ComponentAllocation allocation : currentDeployment.getComponentAllocations()) {
+			Component c1 = allocation.getComponent();
+			for(Object port : c1.getConnectors()) {
+				if(port instanceof OutputPort) {
+					for(Component c2 : getTargetComponent((OutputPort)port)) {
+						if(getEcuForComponent(c1, currentDeployment) != getEcuForComponent(c2,
+								currentDeployment) &&
+								getEcuForComponent(c2, currentDeployment) != null) {
+							resultString += "Name: " + ((OutputPort)port).getName() + ", ";
+							for(Object specs : ((OutputPort)port).getSpecifications()) {
+								if(specs instanceof PortSpecification) {
+									PortSpecification portSpec = (PortSpecification)specs;
+									resultString += "Type: " + portSpec.getType() + ", ";
+								}
+								if(specs instanceof VariableBoundsSpecification) {
+									VariableBoundsSpecification varBoundSpec =
+											(VariableBoundsSpecification)specs;
+									resultString +=
+											"From: " + varBoundSpec.getLowerBound() + " To: " +
+													varBoundSpec.getUpperBound() + " ";
+								}
+							}
+							resultString += "\n";
+						}
+					}
 				}
 			}
+
 		}
-		RaspberryPortTypeGeneration rspPortInfoGen = new RaspberryPortTypeGeneration(logPortSpecs);
+
+		RaspberryPortTypeGeneration rspPortInfoGen = new RaspberryPortTypeGeneration(resultString);
 		rspPortInfoGen.createInfofile();
 		pack.addUnit(createStaticContentSourceUnit("PortSpecifications",
 				rspPortInfoGen.getContent(), false));
-
+		System.out.print(resultString);
 	}
-
 }
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/utils/RaspberryUtils.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/utils/RaspberryUtils.java
new file mode 100644
index 00000000..33791fab
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/utils/RaspberryUtils.java
@@ -0,0 +1,57 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2016 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.af3.platform.raspberry.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.fortiss.af3.component.model.Channel;
+import org.fortiss.af3.component.model.Component;
+import org.fortiss.af3.component.model.OutputPort;
+import org.fortiss.af3.deployment.model.ComponentAllocation;
+import org.fortiss.af3.deployment.model.Deployment;
+import org.fortiss.af3.platform.model.ExecutionUnit;
+
+/**
+ * 
+ * @author zverlov
+ * @author $Author$
+ * @version $Rev$
+ * @ConQAT.Rating RED Hash:
+ */
+public class RaspberryUtils {
+	/** Return the target @{link {@link Component} of the an {@link OutputPort}. */
+	public static List<Component> getTargetComponent(OutputPort out) {
+		ArrayList<Component> result = new ArrayList<Component>();
+		for(Channel chan : out.getOutgoingChannels()) {
+			result.add(chan.getTarget().getComponent());
+		}
+		return result;
+	}
+
+	/** Returns the @{link {@link ExecutionUnit} where a @{link {@link Component} is deployed. */
+	public static ExecutionUnit getEcuForComponent(Component c1, Deployment deploy) {
+		for(ComponentAllocation allocaitons : deploy.getComponentAllocations()) {
+			if(allocaitons.getComponent() == c1) {
+				return allocaitons.getExecutionUnit();
+			}
+		}
+
+		return null;
+	}
+}
-- 
GitLab