From 602e613bd8c16c65ed156a6863397ca32f7d58b8 Mon Sep 17 00:00:00 2001
From: Johannes Eder <eder@fortiss.org>
Date: Mon, 22 May 2017 13:16:32 +0000
Subject: [PATCH] specific sensor and actuator elements

---
 .../ui/prototype/ProtoypeProvider.java        |  28 +++-
 .../trunk/model/raspberry.ecore               |   5 +
 .../trunk/model/raspberry.genmodel            |   5 +
 .../trunk/plugin.xml                          |  16 +++
 .../compose/RaspberryPiCompositor.java        |   7 +-
 .../executable/RaspberryPIExecutable.java     | 123 ++++++++++++++++++
 .../transform/RaspberryPITransformation.java  |  59 +++++++++
 .../util/RaspberryModelElementFactory.java    |  36 +++++
 8 files changed, 276 insertions(+), 3 deletions(-)
 create mode 100644 org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java
 create mode 100644 org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/transform/RaspberryPITransformation.java

diff --git a/org.fortiss.af3.platform.raspberry.ui/trunk/src/org/fortiss/af3/platform/raspberry/ui/prototype/ProtoypeProvider.java b/org.fortiss.af3.platform.raspberry.ui/trunk/src/org/fortiss/af3/platform/raspberry/ui/prototype/ProtoypeProvider.java
index 50058c09..e5c96200 100644
--- a/org.fortiss.af3.platform.raspberry.ui/trunk/src/org/fortiss/af3/platform/raspberry/ui/prototype/ProtoypeProvider.java
+++ b/org.fortiss.af3.platform.raspberry.ui/trunk/src/org/fortiss/af3/platform/raspberry/ui/prototype/ProtoypeProvider.java
@@ -25,10 +25,14 @@ import static org.fortiss.tooling.base.utils.LayoutDataUtils.setNodePosition;
 import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createRectangle;
 
 import org.fortiss.af3.platform.raspberry.model.ActuatorConnector;
+import org.fortiss.af3.platform.raspberry.model.ActuatorPWM;
 import org.fortiss.af3.platform.raspberry.model.CanBus;
 import org.fortiss.af3.platform.raspberry.model.CanConnector;
 import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
 import org.fortiss.af3.platform.raspberry.model.SensorConnector;
+import org.fortiss.af3.platform.raspberry.model.SensorIMU;
+import org.fortiss.af3.platform.raspberry.model.SensorLaserRangeFinder;
+import org.fortiss.af3.platform.raspberry.model.SensorLaserScanner;
 import org.fortiss.af3.platform.raspberry.util.RaspberryModelElementFactory;
 import org.fortiss.tooling.kernel.extension.base.PrototypeProviderBase;
 
@@ -63,12 +67,32 @@ public class ProtoypeProvider extends PrototypeProviderBase {
 		SensorConnector sensor = RaspberryModelElementFactory.createSensorConnector();
 		setNodePosition(sensor, 0, 0);
 		setConnectorPosition(sensor, 0, 0);
-		registerPrototype("Sensor", sensor, CATEGORY_NAME);
+		registerPrototype("GenericPI_Sensor", sensor, CATEGORY_NAME);
+
+		SensorIMU imu = RaspberryModelElementFactory.createSensorIMU();
+		setNodePosition(imu, 0, 0);
+		setConnectorPosition(imu, 0, 0);
+		registerPrototype("IMU_Sensor", imu, CATEGORY_NAME);
+
+		SensorLaserRangeFinder slrf = RaspberryModelElementFactory.createSensorLaserRangeFinder();
+		setNodePosition(slrf, 0, 0);
+		setConnectorPosition(slrf, 0, 0);
+		registerPrototype("LaserRangeFinder_Sensor", slrf, CATEGORY_NAME);
+
+		SensorLaserScanner sls = RaspberryModelElementFactory.createSensorLaserScanner();
+		setNodePosition(sls, 0, 0);
+		setConnectorPosition(sls, 0, 0);
+		registerPrototype("LaserScanner_Sensor", sls, CATEGORY_NAME);
 
 		ActuatorConnector actuator = RaspberryModelElementFactory.createActuatorConnector();
 		setNodePosition(actuator, 0, 0);
 		setConnectorPosition(actuator, 0, 0);
-		registerPrototype("Actuator", actuator, CATEGORY_NAME);
+		registerPrototype("GenericPI_Actuator", actuator, CATEGORY_NAME);
+
+		ActuatorPWM pwm = RaspberryModelElementFactory.createActuatorPWM();
+		setNodePosition(pwm, 0, 0);
+		setConnectorPosition(pwm, 0, 0);
+		registerPrototype("PWM_Actuator", pwm, CATEGORY_NAME);
 
 	}
 }
diff --git a/org.fortiss.af3.platform.raspberry/trunk/model/raspberry.ecore b/org.fortiss.af3.platform.raspberry/trunk/model/raspberry.ecore
index 53284dc1..e2825530 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/model/raspberry.ecore
+++ b/org.fortiss.af3.platform.raspberry/trunk/model/raspberry.ecore
@@ -7,4 +7,9 @@
   <eClassifiers xsi:type="ecore:EClass" name="CanConnector" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//generic/GenericTransceiver"/>
   <eClassifiers xsi:type="ecore:EClass" name="SensorConnector" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//generic/GenericReceiver"/>
   <eClassifiers xsi:type="ecore:EClass" name="ActuatorConnector" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//generic/GenericTransmitter"/>
+  <eClassifiers xsi:type="ecore:EClass" name="SensorGamepad" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//generic/GenericReceiver"/>
+  <eClassifiers xsi:type="ecore:EClass" name="SensorIMU" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//generic/GenericReceiver"/>
+  <eClassifiers xsi:type="ecore:EClass" name="SensorLaserRangeFinder" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//generic/GenericReceiver"/>
+  <eClassifiers xsi:type="ecore:EClass" name="SensorLaserScanner" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//generic/GenericReceiver"/>
+  <eClassifiers xsi:type="ecore:EClass" name="ActuatorPWM" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//generic/GenericTransmitter"/>
 </ecore:EPackage>
diff --git a/org.fortiss.af3.platform.raspberry/trunk/model/raspberry.genmodel b/org.fortiss.af3.platform.raspberry/trunk/model/raspberry.genmodel
index 6cd7d086..44dbaf53 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/model/raspberry.genmodel
+++ b/org.fortiss.af3.platform.raspberry/trunk/model/raspberry.genmodel
@@ -12,5 +12,10 @@
     <genClasses ecoreClass="raspberry.ecore#//CanConnector"/>
     <genClasses ecoreClass="raspberry.ecore#//SensorConnector"/>
     <genClasses ecoreClass="raspberry.ecore#//ActuatorConnector"/>
+    <genClasses ecoreClass="raspberry.ecore#//SensorGamepad"/>
+    <genClasses ecoreClass="raspberry.ecore#//SensorIMU"/>
+    <genClasses ecoreClass="raspberry.ecore#//SensorLaserRangeFinder"/>
+    <genClasses ecoreClass="raspberry.ecore#//SensorLaserScanner"/>
+    <genClasses ecoreClass="raspberry.ecore#//ActuatorPWM"/>
   </genPackages>
 </genmodel:GenModel>
diff --git a/org.fortiss.af3.platform.raspberry/trunk/plugin.xml b/org.fortiss.af3.platform.raspberry/trunk/plugin.xml
index 52892d06..a40d19b0 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/plugin.xml
+++ b/org.fortiss.af3.platform.raspberry/trunk/plugin.xml
@@ -61,6 +61,22 @@
          </target>
       </modelConnectionCompositor>
    </extension>
+   <extension
+         point="org.fortiss.tooling.kernel.transformationProvider">
+      <transformationProvider
+            transformationProvider="org.fortiss.af3.platform.raspberry.generator.transform.RaspberryPITransformation">
+         <source>
+            <objectClass
+                  objectClass="org.fortiss.af3.platform.raspberry.model.RaspberryPi">
+            </objectClass>
+         </source>
+         <target>
+            <objectClass
+                  objectClass="org.fortiss.af3.platform.raspberry.generator.executable.RaspberryPIExecutable">
+            </objectClass>
+         </target>
+      </transformationProvider>
+   </extension>
 
    
    
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/compose/RaspberryPiCompositor.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/compose/RaspberryPiCompositor.java
index 7b17eeb0..fd5561a6 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/compose/RaspberryPiCompositor.java
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/compose/RaspberryPiCompositor.java
@@ -23,9 +23,13 @@ import org.eclipse.emf.ecore.EObject;
 import org.fortiss.af3.platform.compose.PlatformArchitectureElementCompositorBase;
 import org.fortiss.af3.platform.model.IPlatformArchitectureElement;
 import org.fortiss.af3.platform.raspberry.model.ActuatorConnector;
+import org.fortiss.af3.platform.raspberry.model.ActuatorPWM;
 import org.fortiss.af3.platform.raspberry.model.CanConnector;
 import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
 import org.fortiss.af3.platform.raspberry.model.SensorConnector;
+import org.fortiss.af3.platform.raspberry.model.SensorGamepad;
+import org.fortiss.af3.platform.raspberry.model.SensorLaserRangeFinder;
+import org.fortiss.af3.platform.raspberry.model.SensorLaserScanner;
 
 /**
  * 
@@ -43,7 +47,8 @@ public class RaspberryPiCompositor extends
 			EObject contained) {
 		final boolean instanceOfAny2 =
 				isInstanceOfAny(contained, CanConnector.class, SensorConnector.class,
-						ActuatorConnector.class);
+						ActuatorConnector.class, ActuatorPWM.class, SensorLaserRangeFinder.class,
+						SensorGamepad.class, SensorLaserScanner.class);
 		if(container != null) {
 			final boolean instanceOfAny = isInstanceOfAny(container, RaspberryPi.class);
 			return instanceOfAny && instanceOfAny2;
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java
new file mode 100644
index 00000000..b653f55f
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/RaspberryPIExecutable.java
@@ -0,0 +1,123 @@
+/*--------------------------------------------------------------------------+
+$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+|                                                                          |
+| Copyright 2017 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.generator.executable;
+
+import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
+
+import java.util.List;
+import java.util.Set;
+
+import org.conqat.lib.commons.collections.Pair;
+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.generator.ComponentFunction;
+import org.fortiss.af3.component.model.generator.LocalFunction;
+import org.fortiss.af3.expression.model.terms.IExpressionTerm;
+import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
+import org.fortiss.af3.generator.common.model.c.CSourcePackage;
+import org.fortiss.af3.platform.generic.generator.executable.GenericExecutionUnitExecutable;
+import org.fortiss.af3.platform.language.executable.IReadableExecutable;
+import org.fortiss.af3.platform.language.executable.IWritableExecutable;
+import org.fortiss.af3.platform.model.ExecutionUnit;
+import org.fortiss.af3.platform.model.PlatformConnectorUnit;
+import org.fortiss.af3.platform.model.generic.GenericTransceiver;
+import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
+
+/**
+ * 
+ * @author eder
+ * @author $Author: hoelzl $
+ * @version $Rev: 18709 $
+ * @ConQAT.Rating RED Hash:
+ */
+public class RaspberryPIExecutable extends GenericExecutionUnitExecutable {
+
+	/** Constructor. */
+	public RaspberryPIExecutable(ExecutionUnit modelElement) {
+		super(modelElement);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected CSourcePackage createExecutionUnitSourcePackage(String name,
+			List<Pair<ExecutionUnit, Component>> deployedComponents,
+			List<Pair<PlatformConnectorUnit, Port>> deployedPorts, ITransformationContext context) {
+		return super.createExecutionUnitSourcePackage(name, deployedComponents, deployedPorts,
+				context);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected ComponentFunction createInitializeFunction(
+			List<Pair<ExecutionUnit, Component>> deployedComponents,
+			Set<PlatformConnectorUnit> usedUnits) {
+		return super.createInitializeFunction(deployedComponents, usedUnits);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected void
+			createReadAccess(IReadableExecutable exec, InputPort p, List<IStatementTerm> body) {
+		super.createReadAccess(exec, p, body);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected LocalFunction createReadInputFunction(
+			List<Pair<PlatformConnectorUnit, Port>> deployedPorts,
+			Set<GenericTransceiver> usedTransceivers) {
+		return super.createReadInputFunction(deployedPorts, usedTransceivers);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected ComponentFunction createStepFunction(
+			List<Pair<ExecutionUnit, Component>> deployedComponents,
+			List<Pair<PlatformConnectorUnit, Port>> deployedPorts,
+			Set<GenericTransceiver> usedTransceivers) {
+		return super.createStepFunction(deployedComponents, deployedPorts, usedTransceivers);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected LocalFunction createTerminationFunction(Set<PlatformConnectorUnit> usedUnits) {
+		return super.createTerminationFunction(usedUnits);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected void createWriteAccess(IWritableExecutable exec, OutputPort p,
+			List<IStatementTerm> body) {
+		super.createWriteAccess(exec, p, body);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public IExpressionTerm getInitialization() {
+		return funcCall("init_raspberryPI_ecu");
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public IExpressionTerm getTermination() {
+		return funcCall("term_raspberryPI_ecu");
+	}
+
+}
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/transform/RaspberryPITransformation.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/transform/RaspberryPITransformation.java
new file mode 100644
index 00000000..eb320f64
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/transform/RaspberryPITransformation.java
@@ -0,0 +1,59 @@
+/*--------------------------------------------------------------------------+
+$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+|                                                                          |
+| Copyright 2017 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.generator.transform;
+
+import org.fortiss.af3.platform.raspberry.generator.executable.RaspberryPIExecutable;
+import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
+import org.fortiss.tooling.kernel.extension.ITransformationProvider;
+import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
+
+/**
+ * 
+ * @author eder
+ * @author $Author: hoelzl $
+ * @version $Rev: 18709 $
+ * @ConQAT.Rating RED Hash:
+ */
+public class RaspberryPITransformation implements ITransformationProvider {
+
+	/** {@inheritDoc} */
+	@Override
+	public Class<?> getTargetClass() {
+		return RaspberryPIExecutable.class;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public boolean
+			canHandleChainTransformation(Class<?> sourceClass, ITransformationContext context) {
+		return RaspberryPi.class.isAssignableFrom(sourceClass);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public boolean canTransform(Object source, ITransformationContext context) {
+		return source instanceof RaspberryPi;
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public Object transform(Object source, ITransformationContext context) {
+		return new RaspberryPIExecutable((RaspberryPi)source);
+	}
+
+}
diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/util/RaspberryModelElementFactory.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/util/RaspberryModelElementFactory.java
index 3324c467..12c3f96e 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/util/RaspberryModelElementFactory.java
+++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/util/RaspberryModelElementFactory.java
@@ -20,11 +20,15 @@ package org.fortiss.af3.platform.raspberry.util;
 import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createConnectorLayout;
 
 import org.fortiss.af3.platform.raspberry.model.ActuatorConnector;
+import org.fortiss.af3.platform.raspberry.model.ActuatorPWM;
 import org.fortiss.af3.platform.raspberry.model.CanBus;
 import org.fortiss.af3.platform.raspberry.model.CanConnector;
 import org.fortiss.af3.platform.raspberry.model.ModelFactory;
 import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
 import org.fortiss.af3.platform.raspberry.model.SensorConnector;
+import org.fortiss.af3.platform.raspberry.model.SensorIMU;
+import org.fortiss.af3.platform.raspberry.model.SensorLaserRangeFinder;
+import org.fortiss.af3.platform.raspberry.model.SensorLaserScanner;
 import org.fortiss.tooling.base.utils.LayoutModelElementFactory;
 
 /**
@@ -69,6 +73,30 @@ public class RaspberryModelElementFactory {
 		return connector;
 	}
 
+	/** Creates a {@link SensorIMU}. */
+	public static SensorIMU createSensorIMU() {
+		SensorIMU connector = ModelFactory.eINSTANCE.createSensorIMU();
+		connector.setName("IMU_In");
+		createConnectorLayout(connector);
+		return connector;
+	}
+
+	/** Creates a {@link SensorLaserRangeFinder}. */
+	public static SensorLaserRangeFinder createSensorLaserRangeFinder() {
+		SensorLaserRangeFinder connector = ModelFactory.eINSTANCE.createSensorLaserRangeFinder();
+		connector.setName("LaserRangeFinder_In");
+		createConnectorLayout(connector);
+		return connector;
+	}
+
+	/** Creates a {@link SensorLaserScanner}. */
+	public static SensorLaserScanner createSensorLaserScanner() {
+		SensorLaserScanner connector = ModelFactory.eINSTANCE.createSensorLaserScanner();
+		connector.setName("LaserScanner_In");
+		createConnectorLayout(connector);
+		return connector;
+	}
+
 	/** Creates a {@link ActuatorConnector}. */
 	public static ActuatorConnector createActuatorConnector() {
 		ActuatorConnector connector = ModelFactory.eINSTANCE.createActuatorConnector();
@@ -76,4 +104,12 @@ public class RaspberryModelElementFactory {
 		createConnectorLayout(connector);
 		return connector;
 	}
+
+	/** Creates a {@link ActuatorPWM}. */
+	public static ActuatorPWM createActuatorPWM() {
+		ActuatorPWM connector = ModelFactory.eINSTANCE.createActuatorPWM();
+		connector.setName("PWM_Out");
+		createConnectorLayout(connector);
+		return connector;
+	}
 }
-- 
GitLab